Skip to content

Commit

Permalink
[Decompilation] [th01] REIIDEN.EXE: Out-of-memory handler
Browse files Browse the repository at this point in the history
Part of P0214, funded by Ember2528.
  • Loading branch information
nmlgc committed Aug 14, 2022
1 parent 44dbae8 commit ea8e2a2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 25 deletions.
8 changes: 8 additions & 0 deletions th01/main/debug.cpp
@@ -0,0 +1,8 @@
#include "th01/main/debug.hpp"
#include "th01/shiftjis/debug.hpp"

void out_of_memory_exit(void)
{
puts(ERROR_OUT_OF_MEMORY);
exit(1);
}
3 changes: 3 additions & 0 deletions th01/main/debug.hpp
Expand Up @@ -4,6 +4,9 @@ extern bool16 mode_test;
// Deals damage to every damageable object on screen if true.
extern bool16 test_damage;

// set_new_handler() that immediately exit()s the game with an error message.
void out_of_memory_exit(void);

/// Memory info screen
/// ------------------

Expand Down
2 changes: 2 additions & 0 deletions th01/main_01.cpp
Expand Up @@ -49,6 +49,7 @@
#include "th01/main/stage/stages.hpp"
#include "th01/main/stage/stageobj.hpp"
#include "th01/main/hud/hud.hpp"
#include "th01/shiftjis/debug.hpp"
#include "th01/shiftjis/entrance.hpp"
#include "th01/shiftjis/fns.hpp"

Expand Down Expand Up @@ -303,3 +304,4 @@ void stage_entrance(int stage_id, const char* bg_fn, bool16 clear_vram_page_0)
#include "th01/main/hud/menu.cpp"
#include "th01/main/player/gameover.cpp"
#include "th01/main/extend.cpp"
#include "th01/main/debug.cpp"
5 changes: 5 additions & 0 deletions th01/shiftjis/debug.hpp
@@ -0,0 +1,5 @@
// Errors
// ------

#define ERROR_OUT_OF_MEMORY "いやーん、ヒープがたんないわ"
// ------
2 changes: 1 addition & 1 deletion th01/shiftjis/fns.hpp
@@ -1,5 +1,5 @@
#define BINARY_OP "op"
#define BINARY_MAIN_CAPS "REIIDEN\0いやーん、ヒープがたんないわ"
#define BINARY_MAIN_CAPS "REIIDEN"

#define REGIST_BG_CLEARED "endm_a.grp"

Expand Down
26 changes: 2 additions & 24 deletions th01_reiiden.asm
Expand Up @@ -102,26 +102,7 @@ main_01_TEXT segment byte public 'CODE' use16
extern @continue_menu$qv:proc
extern @player_gameover_animate$qv:proc
extern @score_extend_update_and_render$qv:proc

; =============== S U B R O U T I N E =======================================

; Attributes: noreturn bp-based frame

sub_D07C proc near
push bp
mov bp, sp
push ds
push 029Bh ; "いやーん、ヒープがたんないわ"
call _puts
add sp, 4
push 1 ; status
call _exit
sub_D07C endp

; ---------------------------------------------------------------------------
pop cx
pop bp
retf
extern @out_of_memory_exit$qv:proc

; =============== S U B R O U T I N E =======================================

Expand Down Expand Up @@ -916,10 +897,7 @@ loc_D6EB:

loc_D6EE:
mov [bp+@@scene_id], ax
push seg main_01_TEXT
push offset sub_D07C
call @set_new_handler$qnqv$v ; set_new_handler(void (*)(void))
add sp, 4
call @set_new_handler$qnqv$v c, offset @out_of_memory_exit$qv, seg @out_of_memory_exit$qv
mov _arc_key, 76h
call @arc_load$qxnxc pascal, ds, offset aUmx ; "東方靈異.伝"
call @vram_planes_set$qv
Expand Down

0 comments on commit ea8e2a2

Please sign in to comment.