Super Mario 64s source code (from a leak on 4chan so be careful)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
6.1 KiB

6 years ago
  1. /*
  2. * mem_error_screen.inc.c
  3. *
  4. * This enhancement should be used for ROM hacks that require the expansion pak.
  5. *
  6. * ----- Setup -----
  7. *
  8. * Make sure that USE_EXT_RAM is defined in include/segments.h
  9. #define USE_EXT_RAM
  10. *
  11. * There are 6 files you will need to edit:
  12. * src/game/main.c
  13. * src/engine/level_script.h
  14. * include/text_strings.h.in
  15. * levels/entry.s
  16. * levels/intro/script.s
  17. * levels/intro/geo.s
  18. *
  19. * First, in main.c, you will need to add this line below the includes:
  20. #include "../enhancements/mem_error_screen.inc.c"
  21. *
  22. * In the function AllocPool(), add these lines above main_pool_init():
  23. // Detect memory size
  24. if(does_pool_end_lie_out_of_bounds(end))
  25. {
  26. end = (void *)SEG_POOL_END_4MB;
  27. }
  28. *
  29. * Then in thread3_main(), replace the create_thread for thread 5 with this if/else statement:
  30. if(!gNotEnoughMemory)
  31. {
  32. create_thread(&gGameLoopThread, 5, thread5_game_loop, NULL, gThread5Stack + 0x2000, 10);
  33. }
  34. else
  35. {
  36. create_thread(&gGameLoopThread, 5, thread5_mem_error_message_loop, NULL, gThread5Stack + 0x2000, 10);
  37. }
  38. *
  39. * In src/engine/level_script.h, add this line below 'extern u8 level_script_entry[];'
  40. extern u8 level_script_entry_error_screen[];
  41. *
  42. * In include/text_strings.h.in, add these 3 lines at the top. You can also add more strings if you want.
  43. #define TEXT_CONSOLE_8MB _("If you're using an N64 console, then you will need to buy an\nExpansion Pak to play this ROM hack.")
  44. #define TEXT_PJ64 _("If you are using PJ64 1.6, go to:\nOptions > Settings > Rom Settings Tab > Memory Size\nthen select 8 MB from the drop-down box.")
  45. #define TEXT_PJ64_2 _("If you are using PJ64 2.X, go to:\nOptions > Settings > Config: > Memory Size, select 8 MB")
  46. *
  47. * In levels/entry.s, simply append the following to the file:
  48. glabel level_script_entry_error_screen
  49. init_level
  50. sleep 2
  51. blackout FALSE
  52. set_reg 0
  53. execute 0x14, _introSegmentRomStart, _introSegmentRomEnd, level_intro_entry_error_screen
  54. jump level_script_entry_error_screen
  55. .align 4
  56. *
  57. * In levels/intro/script.s, add the following to the top of the file:
  58. glabel level_intro_entry_error_screen
  59. init_level
  60. fixed_load _goddardSegmentStart, _goddardSegmentRomStart, _goddardSegmentRomEnd
  61. load_mio0 0x07, _intro_segment_7SegmentRomStart, _intro_segment_7SegmentRomEnd
  62. alloc_level_pool
  63. area 1, intro_geo_error_screen
  64. end_area
  65. free_level_pool
  66. load_area 1
  67. sleep 32767
  68. exit_and_execute 0x14, _introSegmentRomStart, _introSegmentRomEnd, level_intro_entry_error_screen
  69. *
  70. * Finally, add the following to the top of levels/intro/geo.s:
  71. glabel intro_geo_error_screen
  72. geo_node_screen_area 0, 160, 120, 160, 120
  73. geo_open_node
  74. geo_zbuffer 0
  75. geo_open_node
  76. geo_todo_09 100
  77. geo_open_node
  78. geo_background 0x0001
  79. geo_close_node
  80. geo_close_node
  81. geo_zbuffer 0
  82. geo_open_node
  83. geo_asm 0, geo18_display_error_message
  84. geo_close_node
  85. geo_close_node
  86. geo_end
  87. */
  88. // Ensure that USE_EXT_RAM is defined.
  89. #ifndef USE_EXT_RAM
  90. #error You have to define USE_EXT_RAM in 'include/segments.h'
  91. #endif
  92. #include <types.h>
  93. #include <text_strings.h>
  94. #include "../src/game/display.h"
  95. #include "../src/game/print.h"
  96. #include "../src/game/ingame_menu.h"
  97. #include "../src/game/segment2.h"
  98. #include "../src/engine/level_script.h"
  99. // Require 8 MB of RAM, even if the pool doesn't go into extended memory.
  100. // Change the '8' to whatever MB limit you want.
  101. // Note: only special emulators allow for RAM sizes above 8 MB.
  102. #define REQUIRED_MIN_MEM_SIZE 1048576 * 8
  103. u8 gNotEnoughMemory = FALSE;
  104. u8 gDelayForErrorMessage = 0;
  105. u8 does_pool_end_lie_out_of_bounds(void *end)
  106. {
  107. u32 endPhy = ((u32)end) & 0x1FFFFFFF;
  108. u32 memSize = *((u32*)0x80000318);
  109. if(endPhy > memSize)
  110. {
  111. gNotEnoughMemory = TRUE;
  112. return TRUE;
  113. }
  114. else
  115. {
  116. if(memSize < REQUIRED_MIN_MEM_SIZE)
  117. {
  118. gNotEnoughMemory = TRUE;
  119. }
  120. return FALSE;
  121. }
  122. }
  123. // If you're using an N64 console, then you will need to buy an\nexpansion pak to play this ROM hack.
  124. u8 text_console_8mb[] = { TEXT_CONSOLE_8MB };
  125. // If you are using PJ64 1.6, go to: Options ► Settings ► Rom Settings Tab ► Memory Size then select 8 MB from the drop-down box.
  126. u8 text_pj64[] = { TEXT_PJ64 };
  127. // If you are using PJ64 2.X, go to: Options ► Settings ► Config: ► Memory Size, select 8 MB
  128. u8 text_pj64_2[] = { TEXT_PJ64_2 };
  129. Gfx *geo18_display_error_message(u32 run, UNUSED struct GraphNode *sp44, UNUSED u32 sp48)
  130. {
  131. if (run)
  132. {
  133. if(gDelayForErrorMessage > 0)
  134. {
  135. // Draw color text title.
  136. print_text(10, 210, "ERROR Need more memory");
  137. // Init generic text rendering
  138. dl_add_new_ortho_matrix();
  139. gSPDisplayList(gDisplayListHead++, dl_ia8_text_begin); // Init rendering stuff for generic text
  140. // Set text color to white
  141. gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, 255);
  142. PrintGenericText(8, 170, text_console_8mb);
  143. PrintGenericText(8, 120, text_pj64);
  144. PrintGenericText(8, 54, text_pj64_2);
  145. // Cleanup
  146. gSPDisplayList(gDisplayListHead++, dl_ia8_text_end); // Reset back to default render settings.
  147. gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW);
  148. }
  149. else
  150. {
  151. gDelayForErrorMessage += 1;
  152. }
  153. }
  154. return 0;
  155. }
  156. // Basic main loop for the error screen. Note that controllers are not enabled here.
  157. void thread5_mem_error_message_loop(UNUSED void *arg)
  158. {
  159. struct LevelCommand *addr;
  160. setup_game_memory();
  161. set_vblank_handler(2, &gGameVblankHandler, &gGameVblankQueue, (OSMesg)1);
  162. addr = (struct LevelCommand *) segmented_to_virtual(level_script_entry_error_screen);
  163. func_80247ED8();
  164. while(1)
  165. {
  166. func_80247FAC();
  167. addr = level_script_execute(addr);
  168. display_and_vsync();
  169. }
  170. }