From 17f6ac7d1d5f5bde08bc183663d2c46fbd505ea4 Mon Sep 17 00:00:00 2001
From: nmlgc <nmlgc@nmlgc.net>
Date: Thu, 3 Jul 2014 16:10:24 +0200
Subject: [PATCH] th02/main: Identify stage and BGM title pointers

---
 th02_main.asm | 178 +++++++++++++++++++++++---------------------------
 1 file changed, 80 insertions(+), 98 deletions(-)

diff --git a/th02_main.asm b/th02_main.asm
index 41cb4dbc..f06f37e1 100644
--- a/th02_main.asm
+++ b/th02_main.asm
@@ -26312,37 +26312,37 @@ loc_B1CD:				; CODE XREF: _main+FCj
 		les	bx, dword_2026C
 		cmp	byte ptr es:[bx+27h], 0
 		jnz	short loc_B237
-		mov	al, byte_1E365
+		mov	al, stage_id
 		cbw
 		cmp	ax, 5
 		jnz	short loc_B202
 		push	large 10000Ch
 		push	ds
-		push	offset aOKKO	; "®Á½»ªÏÏ¼½ª°®"
+		push	offset aExtra_Gaiji	; "®Á½»ªÏÏ¼½ª°®"
 		jmp	short loc_B213
 ; ---------------------------------------------------------------------------
 
 loc_B202:				; CODE XREF: _main+90j
-		mov	al, byte_1F467
+		mov	al, stage1_gaiji_halflen
 		mov	ah, 0
 		mov	dx, 1Ch
 		sub	dx, ax
 		push	dx
 		push	0Ch
 		push	ds
-		push	offset aKOb	; "¼½ª°®¡"
+		push	offset aStage1_Gaiji	; "¼½ª°®¡"
 
 loc_B213:				; CODE XREF: _main+9Cj
 		push	0C1h ; 'Á'
 		call	sub_145A
-		mov	al, byte_1F468
+		mov	al, stage_title_halflen
 		mov	ah, 0
 		mov	dx, 1Ch
 		sub	dx, ax
 		push	dx
 		push	0Dh
 		push	ds
-		push	word_1F46A
+		push	stage_title_str
 		push	0E1h ; 'á'
 		call	sub_26CA
 		jmp	short loc_B249
@@ -26381,7 +26381,7 @@ loc_B263:				; CODE XREF: _main+F1j
 
 loc_B27A:				; CODE XREF: _main+10Fj
 		les	bx, dword_2026C
-		mov	al, byte_1E365
+		mov	al, stage_id
 		mov	es:[bx+0Bh], al
 		jmp	short loc_B290
 ; ---------------------------------------------------------------------------
@@ -26466,7 +26466,7 @@ loc_B32B:				; CODE XREF: sub_B2AB+79j
 loc_B333:				; CODE XREF: sub_B2AB+7Ej
 		movzx	eax, ax
 		mov	dword_1E598, eax
-		mov	al, byte_1E365
+		mov	al, stage_id
 		cbw
 		mov	bx, 5
 		cwd
@@ -26540,7 +26540,7 @@ arg_0		= dword	ptr  4
 		mov	byte ptr es:[bx+2], 61h	; 'a'
 		mov	byte ptr es:[bx+3], 67h	; 'g'
 		mov	byte ptr es:[bx+4], 65h	; 'e'
-		mov	al, byte_1E365
+		mov	al, stage_id
 		add	al, 30h	; '0'
 		mov	es:[bx+5], al
 		mov	byte ptr es:[bx+6], 2Eh	; '.'
@@ -26619,10 +26619,10 @@ var_C		= byte ptr -0Ch
 		cmp	byte ptr es:[bx+27h], 0
 		jnz	short loc_B4BB
 		mov	byte_1F46C, 1
-		mov	al, byte_1E365
+		mov	al, stage_id
 		add	al, al
 		mov	byte_1F46D, al
-		mov	al, byte_1E365
+		mov	al, stage_id
 		add	al, al
 		inc	al
 		mov	byte_1F46E, al
@@ -26651,25 +26651,25 @@ loc_B4D6:				; CODE XREF: sub_B3DA+F4j
 loc_B4D7:				; CODE XREF: sub_B3DA+E9j
 		cmp	si, 80h	; '€'
 		jge	short loc_B4C5
-		mov	byte_1F467, 6
-		mov	al, byte_1E365
+		mov	stage1_gaiji_halflen, 6
+		mov	al, stage_id
 		cbw
 		mov	bx, 5
 		cwd
 		idiv	bx
 		add	dl, 0A1h ; '¡'
-		mov	byte ptr aKOb+5, dl
-		mov	al, byte_1E365
+		mov	byte ptr aStage1_Gaiji+5, dl
+		mov	al, stage_id
 		cbw
 		add	ax, ax
 		mov	bx, ax
-		mov	ax, [bx+0C8h]
-		mov	word_1F46A, ax
-		mov	al, byte_1E365
+		mov	ax, STAGE_TITLE[bx]
+		mov	stage_title_str, ax
+		mov	al, stage_id
 		cbw
 		mov	bx, ax
 		mov	al, [bx+0D4h]
-		mov	byte_1F468, al
+		mov	stage_title_halflen, al
 		push	ss
 		lea	ax, [bp+var_C]
 		push	ax
@@ -26750,7 +26750,7 @@ loc_B4D7:				; CODE XREF: sub_B3DA+E9j
 		call	sub_C5B0
 		mov	byte_20342, 1
 		mov	byte_1E500, 4
-		mov	al, byte_1E365
+		mov	al, stage_id
 		cbw
 		mov	bx, ax
 		cmp	bx, 5
@@ -27642,7 +27642,7 @@ sub_BF9C	proc far		; DATA XREF: sub_BFD0+75o
 		mov	bp, sp
 		cmp	byte_1F466, 2
 		jnz	short loc_BFCC
-		mov	al, byte_1E365
+		mov	al, stage_id
 		cbw
 		cmp	ax, 2
 		jnz	short loc_BFC3
@@ -27675,7 +27675,7 @@ sub_BFD0	proc far		; DATA XREF: sub_B3DA+223o
 		cmp	byte_1E501, 1
 		jnz	loc_C05B
 		mov	byte_1F466, 1
-		mov	al, byte_1E365
+		mov	al, stage_id
 		cbw
 		cmp	ax, 3
 		jnz	short loc_BFF8
@@ -27685,7 +27685,7 @@ sub_BFD0	proc far		; DATA XREF: sub_B3DA+223o
 ; ---------------------------------------------------------------------------
 
 loc_BFF8:				; CODE XREF: sub_BFD0+18j
-		mov	al, byte_1E365
+		mov	al, stage_id
 		cbw
 		cmp	ax, 2
 		jnz	short loc_C015
@@ -27770,7 +27770,7 @@ sub_C0A8	proc near		; CODE XREF: sub_BCB1+1Bp
 		mov	ah, 0
 		add	ax, ax
 		mov	bx, ax
-		push	word ptr [bx+0B0h]
+		push	word ptr BGM_TITLE[bx]
 		push	0E1h ; 'á'
 		call	sub_26CA
 
@@ -27840,7 +27840,7 @@ sub_C13E	proc far		; CODE XREF: _main+63p
 		mov	dword ptr es:[bx+1Ch], 12h
 		cmp	byte ptr es:[bx+27h], 1
 		jnz	short loc_C18A
-		mov	byte_1E365, 3
+		mov	stage_id, 3
 		push	ds
 		push	offset aDemo1_rec ; "DEMO1.REC"
 		call	sub_950
@@ -27853,7 +27853,7 @@ loc_C18A:				; CODE XREF: sub_C13E+31j
 		les	bx, dword_2026C
 		cmp	byte ptr es:[bx+27h], 2
 		jnz	short loc_C1AE
-		mov	byte_1E365, 2
+		mov	stage_id, 2
 		push	ds
 		push	offset aDemo2_rec ; "DEMO2.REC"
 		call	sub_950
@@ -27866,7 +27866,7 @@ loc_C1AE:				; CODE XREF: sub_C13E+55j
 		les	bx, dword_2026C
 		cmp	byte ptr es:[bx+27h], 3
 		jnz	short loc_C1D0
-		mov	byte_1E365, 1
+		mov	stage_id, 1
 		push	ds
 		push	offset aDemo3_rec ; "DEMO3.REC"
 		call	sub_950
@@ -28011,7 +28011,7 @@ var_2		= word ptr -2
 		mov	word ptr dword_2026C, 0
 		les	bx, dword_2026C
 		mov	al, es:[bx+0Bh]
-		mov	byte_1E365, al
+		mov	stage_id, al
 		mov	al, es:[bx+1Ah]
 		mov	byte_1E59C, al
 		mov	al, es:[bx+19h]
@@ -28283,7 +28283,7 @@ loc_C516:				; CODE XREF: sub_C31F+1ECj
 		mov	byte_1E516, 1
 		inc	word ptr es:[bx+12h]
 		call	sub_DD1B
-		mov	al, byte_1E365
+		mov	al, stage_id
 		cbw
 		mov	bx, 5
 		cwd
@@ -41242,7 +41242,7 @@ sub_1273B	proc far		; DATA XREF: sub_B3DA+357o
 		call	sub_1310B
 		call	sub_FC53
 		call	sub_E162
-		inc	byte_1E365
+		inc	stage_id
 		pop	bp
 		retf
 sub_1273B	endp
@@ -41960,7 +41960,7 @@ var_4		= dword	ptr -4
 		mov	word ptr [bp+var_4+2], ds
 		mov	word ptr [bp+var_4], 12FBh
 		les	bx, [bp+var_4]
-		mov	al, byte_1E365
+		mov	al, stage_id
 		add	al, 30h	; '0'
 		mov	es:[bx+5], al
 		push	word ptr [bp+var_4+2]
@@ -42587,7 +42587,7 @@ arg_0		= word ptr  4
 		push	si
 		push	di
 		mov	di, [bp+arg_0]
-		mov	al, byte_1E365
+		mov	al, stage_id
 		cbw
 		add	ax, ax
 		add	ax, di
@@ -42606,7 +42606,7 @@ loc_13123:				; CODE XREF: sub_1310B+39j
 		inc	si
 
 loc_13134:				; CODE XREF: sub_1310B+16j
-		mov	al, byte_1E365
+		mov	al, stage_id
 		cbw
 		add	ax, ax
 		mov	bx, ax
@@ -43958,7 +43958,7 @@ sub_13B8B	proc far		; DATA XREF: sub_B3DA+292o
 		call	sub_FC53
 		call	sub_F4BC
 		call	sub_E162
-		inc	byte_1E365
+		inc	stage_id
 		mov	word_1EB0A, 0
 		mov	word_1EDA4, 0
 		pop	bp
@@ -46710,7 +46710,7 @@ sub_15218	proc far		; DATA XREF: sub_B3DA+2EEo
 		call	sub_FC53
 		call	sub_F4BC
 		call	sub_E162
-		inc	byte_1E365
+		inc	stage_id
 		mov	word_1EB0A, 0
 		pop	bp
 		retf
@@ -59600,7 +59600,7 @@ sub_1C270	proc far		; DATA XREF: sub_B3DA+3C0o
 
 loc_1C27C:
 		call	sub_E162
-		inc	byte_1E365
+		inc	stage_id
 		pop	bp
 
 locret_1C286:
@@ -59818,7 +59818,7 @@ var_2		= word ptr -2
 		mov	word ptr [bp-0Ch], ds
 		mov	word ptr [bp+dest+2], 111Ah
 		les	bx, [bp+dest+2]
-		mov	al, byte_1E365
+		mov	al, stage_id
 		add	al, 30h	; '0'
 		mov	es:[bx+5], al
 		push	word ptr [bp-0Ch]
@@ -60735,7 +60735,7 @@ loc_1CB0C:				; CODE XREF: sub_1C9FE+79j
 		mov	eax, dword_1E598
 		mov	[bx+7890h], eax
 		mov	bx, [bp+var_2]
-		mov	al, byte_1E365
+		mov	al, stage_id
 		inc	al
 		mov	[bx+7903h], al
 		mov	ax, [bp+var_2]
@@ -62497,50 +62497,32 @@ word_1DAF8	dw 0			; DATA XREF: sub_5A20+6Ew __sbrk+12r ...
 word_1DAFA	dw 0			; DATA XREF: start+8Bw	sub_5A20+6Aw ...
 word_1DAFC	dw 0			; DATA XREF: sub_5A20+7Ew __brk+1Cr ...
 word_1DAFE	dw 0			; DATA XREF: start+21w	start+F5w ...
-aKOb		db '¼½ª°®¡',0           ; DATA XREF: _main+ACo sub_B3DA+115w
+aStage1_Gaiji		db '¼½ª°®¡',0           ; DATA XREF: _main+ACo sub_B3DA+115w
 		dd 0
 		dd 0
 		db    0
-aOKKO		db '®Á½»ªÏÏ¼½ª°®',0     ; DATA XREF: _main+99o
+aExtra_Gaiji		db '®Á½»ªÏÏ¼½ª°®',0     ; DATA XREF: _main+99o
 		db 0
 		db    0
 		db    0
-		db  18h
-		db    1
-		db  31h	; 1
-		db    1
-		db  4Ah	; J
-		db    1
-		db  63h	; c
-		db    1
-		db  7Ch	; |
-		db    1
-		db  95h	; •
-		db    1
-		db 0AEh	; ®
-		db    1
-		db 0C7h	; Ç
-		db    1
-		db 0E0h	; à
-		db    1
-		db 0F9h	; ù
-		db    1
-		db  12h
-		db    2
-		db  2Bh	; +
-		db    2
-		db  44h	; D
-		db    2
-		db  59h	; Y
-		db    2
-		db  74h	; t
-		db    2
-		db  8Bh	; ‹
-		db    2
-		db 0A4h	; ¤
-		db    2
-		db 0BFh	; ¿
-		db    2
+BGM_TITLE		dw offset aTH02_02
+		dw offset aTH02_03
+		dw offset aTH02_04
+		dw offset aTH02_05
+		dw offset aTH02_06
+		dw offset aTH02_07
+		dw offset aTH02_08
+		dw offset aTH02_09
+		dw offset aTH02_10
+		dw offset aTH02_11
+		dw offset aTH02_12
+		dw offset aTH02_13
+STAGE_TITLE		dw offset aSTAGE1_TITLE
+		dw offset aSTAGE2_TITLE
+		dw offset aSTAGE3_TITLE
+		dw offset aSTAGE4_TITLE
+		dw offset aSTAGE5_TITLE
+		dw offset aEXTRA_TITLE
 		db  0Ah
 		db  0Dh
 		db  0Bh
@@ -62568,24 +62550,24 @@ off_1DB7E	dd aB@b@vVvbavtvVV	; DATA XREF: sub_B9E2+12Dr
 					; "�@�@‚Í‚¢�A‚â‚ß‚Ü‚·�B�@"
 dword_1DB82	dd 0			; DATA XREF: sub_BCB1+7r
 word_1DB86	dw 0			; DATA XREF: sub_C1E4+Ar sub_C1E4+1Bw	...
-aB@Focab@bEaste	db '�@ ”Ž—í�@�`Eastern Wind ',0
-aB@SheSInATempe	db '�@  She',27h,'s in a temper!! ',0
-aB@EndOfDayligh	db '�@   End of Daylight�@  ',0
-aB@VtvVVVivcb@b	db '   �@ ‚â‚Ý‚Ì‚¿‚©‚ç�@�@  ',0
-aB@b@b@b@b@mCKe	db '�@�@�@�@�@Œ¶–²ŠE�@�@�@�@',0
-aB@b@b@oav	db ' �@�@�@Ž€‚ð“q‚µ‚Ä�@�@�@ ',0
-aVVrvivmbavVcvV	db '‚Ð‚à‚ë‚¬�A‚Þ‚ç‚³‚«‚É‚à‚¦',0
-aB@C		db '   �@ —ö�Fƒ}ƒWƒbƒN �@   ',0
-aB@umx		db '�@“Œ•û••–‚˜^�@�`—HŒ¶—�•‘',0
-aCompleteDarkne	db '   Complete Darkness    ',0
-aB@Ggglgxgggigi	db '   �@ ƒGƒLƒXƒgƒ‰ƒ‰ƒu    ',0
-aRaoVVVVVVsvfv	db '  �íŽÔ‚Þ‚·‚ß‚Ì‚Ý‚é‚ä‚ß  ',0
-aOzcB@bPurpleDa	db 'Ž‡–ì�@�` Purple Dawn',0
-aClpbb@bMidnigh	db '—‹�b�@�`Midnight Rainstorm',0
-aNgcB@bScarletD	db '�g–²�@�` Scarlet Dream',0
-aCCvb@bRevengef	db '—ì–‚�@�`Revengeful Ghost',0
-aXxcvb@bUmx	db '••–‚�@�`“Œ•û••–‚˜^ and ...',0
-aIL		db 'ˆÙ‹ó�@�`for Lunatic Gamers',0
+aTH02_02	db '�@ ”Ž—í�@�`Eastern Wind ',0
+aTH02_03	db '�@  She',27h,'s in a temper!! ',0
+aTH02_04	db '�@   End of Daylight�@  ',0
+aTH02_05	db '   �@ ‚â‚Ý‚Ì‚¿‚©‚ç�@�@  ',0
+aTH02_06	db '�@�@�@�@�@Œ¶–²ŠE�@�@�@�@',0
+aTH02_07	db ' �@�@�@Ž€‚ð“q‚µ‚Ä�@�@�@ ',0
+aTH02_08	db '‚Ð‚à‚ë‚¬�A‚Þ‚ç‚³‚«‚É‚à‚¦',0
+aTH02_09		db '   �@ —ö�Fƒ}ƒWƒbƒN �@   ',0
+aTH02_10		db '�@“Œ•û••–‚˜^�@�`—HŒ¶—�•‘',0
+aTH02_11	db '   Complete Darkness    ',0
+aTH02_12	db '   �@ ƒGƒLƒXƒgƒ‰ƒ‰ƒu    ',0
+aTH02_13	db '  �íŽÔ‚Þ‚·‚ß‚Ì‚Ý‚é‚ä‚ß  ',0
+aSTAGE1_TITLE	db 'Ž‡–ì�@�` Purple Dawn',0
+aSTAGE2_TITLE	db '—‹�b�@�`Midnight Rainstorm',0
+aSTAGE3_TITLE	db '�g–²�@�` Scarlet Dream',0
+aSTAGE4_TITLE	db '—ì–‚�@�`Revengeful Ghost',0
+aSTAGE5_TITLE	db '••–‚�@�`“Œ•û••–‚˜^ and ...',0
+aEXTRA_TITLE		db 'ˆÙ‹ó�@�`for Lunatic Gamers',0
 ; char arg0[3]
 arg0		db 'op',0               ; DATA XREF: _main+138o
 aHuuma_efc	db 'huuma.efc',0        ; DATA XREF: sub_B2AB+8o
@@ -63785,7 +63767,7 @@ byte_1E35D	db 0			; DATA XREF: sub_FA46w	sub_FA52+31w ...
 		db 0F8h	; ø
 byte_1E364	db 1			; DATA XREF: sub_B2AB:loc_B34Cr
 					; sub_C273+57w	...
-byte_1E365	db 0			; DATA XREF: _main+89r	_main+11Ar ...
+stage_id	db 0			; DATA XREF: _main+89r	_main+11Ar ...
 aHuuma_cfg	db 'huuma.cfg',0        ; DATA XREF: sub_C273+5o
 		db '<',0
 		db '~',0
@@ -67208,11 +67190,11 @@ aC		db '/c',0
 		dd loc_501D
 byte_1F466	db ?			; DATA XREF: sub_B3DA+B3w
 					; sub_BCB1+129w ...
-byte_1F467	db ?			; DATA XREF: _main:loc_B202r
+stage1_gaiji_halflen	db ?			; DATA XREF: _main:loc_B202r
 					; sub_B3DA+103w
-byte_1F468	db ?			; DATA XREF: _main+B7r	sub_B3DA+132w
+stage_title_halflen	db ?			; DATA XREF: _main+B7r	sub_B3DA+132w
 		db ?
-word_1F46A	dw ?			; DATA XREF: _main+C5r	sub_B3DA+125w
+stage_title_str	dw ?			; DATA XREF: _main+C5r	sub_B3DA+125w
 byte_1F46C	db ?			; DATA XREF: sub_B3DA+C8w
 					; sub_B3DA:loc_B4BBw ...
 byte_1F46D	db ?			; DATA XREF: sub_B3DA+D2w sub_BFD0+88w ...
