diff options
Diffstat (limited to 'src/engine')
| -rw-r--r-- | src/engine/bank01.asm | 94 | ||||
| -rw-r--r-- | src/engine/bank03.asm | 4 | ||||
| -rw-r--r-- | src/engine/bank04.asm | 4 | ||||
| -rw-r--r-- | src/engine/bank06.asm | 20 | ||||
| -rw-r--r-- | src/engine/home.asm | 31 | 
5 files changed, 121 insertions, 32 deletions
| diff --git a/src/engine/bank01.asm b/src/engine/bank01.asm index 0b288b8..85bf0c8 100644 --- a/src/engine/bank01.asm +++ b/src/engine/bank01.asm @@ -7,9 +7,9 @@ GameLoop: ; 4000 (1:4000)  	call EnableInt_VBlank  	call EnableInt_Timer  	call EnableSRAM -	ld a, [sa006] +	ld a, [s0a006]  	ld [wTextSpeed], a -	ld a, [sa009] +	ld a, [s0a009]  	ld [wccf2], a  	call DisableSRAM  	ld a, 1 @@ -30,7 +30,7 @@ GameLoop: ; 4000 (1:4000)  ; erase sram  	call EnableSRAM  	xor a -	ld [sa000], a +	ld [s0a000], a  	call DisableSRAM  .reset_game  	jp Reset @@ -360,7 +360,7 @@ PrintDuelMenu: ; 4295 (1:4295)  	ld hl, DuelMenuData  	call PlaceTextItems  .asm_429e -	call $669d +	call SaveDuelData  	ld a, [wDuelFinished]  	or a  	ret nz @@ -3847,7 +3847,91 @@ Func_6673: ; 6673 (1:6673)  	ret  ; 0x669d -	INCROM $669d, $6785 +; save data of the current duel to sCurrentDuelData +; byte 0 is $01, bytes 1 and 2 are the checksum, byte 3 is [wDuelType] +; next $33a bytes come from DuelDataToSave +SaveDuelData: ; 669d (1:669d) +	farcall CommentedOut_1a6cc +	ld de, sCurrentDuelData +;	fallthrough + +; save data of the current duel to de (in SRAM) +; byte 0 is $01, bytes 1 and 2 are the checksum, byte 3 is [wDuelType] +; next $33a bytes come from DuelDataToSave +SaveDuelDataToDE: ; 66a4 (1:66a4) +	call EnableSRAM +	push de +	inc de +	inc de +	inc de +	inc de +	ld hl, DuelDataToSave +	push de +.save_duel_data_loop +	; start copying data to de = sCurrentDuelData + 4 +	ld c, [hl] +	inc hl +	ld b, [hl] +	inc hl +	ld a, c +	or b +	jr z, .asm_66c7 +	push hl +	push bc +	ld c, [hl] +	inc hl +	ld b, [hl] +	inc hl +	pop hl +	call CopyDataHLtoDE +	pop hl +	inc hl +	inc hl +	jr .save_duel_data_loop +.asm_66c7 +	pop hl +	; hl = sCurrentDuelData + 4 +	lb de, $23, $45 +	ld bc, $334 ; misses last 6 bytes to calculate checksum +.checksum_loop +	ld a, e +	sub [hl] +	ld e, a +	ld a, [hli] +	xor d +	ld d, a +	dec bc +	ld a, c +	or b +	jr nz, .checksum_loop +	pop hl +	ld a, $01 +	ld [hli], a ; sCurrentDuelData +	ld [hl], e ; sCurrentDuelData + 1 +	inc hl +	ld [hl], d ; sCurrentDuelData + 2 +	inc hl +	ld a, [wDuelType] +	ld [hl], a ; sCurrentDuelData + 3 +	call DisableSRAM +	ret +; 0x66e9 + +	INCROM $66e9, $6729 + +DuelDataToSave: ; 6729 (1:6729) +;	dw address, number_of_bytes_to_copy +	dw wPlayerDuelVariables, wOpponentDuelVariables - wPlayerDuelVariables +	dw wOpponentDuelVariables, wPlayerDeck - wOpponentDuelVariables +	dw wPlayerDeck, wc500 + $10 - wPlayerDeck +	dw wcc05, wDuelTheme + $1 - wcc05 +	dw hWhoseTurn, $1 +	dw wRNG1, wRNGCounter + $1 - wRNG1 +	dw wcda5, $0010 +	dw $0000 +; 0x6747 + +	INCROM $6747, $6785  Func_6785: ; 6785 (1:6785)  	call EnableSRAM diff --git a/src/engine/bank03.asm b/src/engine/bank03.asm index 218be30..7ad9a33 100644 --- a/src/engine/bank03.asm +++ b/src/engine/bank03.asm @@ -267,9 +267,9 @@ Func_c1f8: ; c1f8 (3:41f8)  	ld [wd112], a  	ld [wd3b8], a  	call EnableSRAM -	ld a, [sa007] +	ld a, [s0a007]  	ld [wd421], a -	ld a, [sa006] +	ld a, [s0a006]  	ld [wTextSpeed], a  	call DisableSRAM  	farcall Func_10756 diff --git a/src/engine/bank04.asm b/src/engine/bank04.asm index 55657db..da12df8 100644 --- a/src/engine/bank04.asm +++ b/src/engine/bank04.asm @@ -1113,9 +1113,9 @@ MainMenu_NewGame: ; 12704 (4:6704)  	call Func_128a9  	farcall Func_1996e  	call EnableSRAM -	ld a, [sa007] +	ld a, [s0a007]  	ld [wd421], a -	ld a, [sa006] +	ld a, [s0a006]  	ld [wTextSpeed], a  	call DisableSRAM  	ld a, MUSIC_STOP diff --git a/src/engine/bank06.asm b/src/engine/bank06.asm index fc5e5c4..bc38b82 100644 --- a/src/engine/bank06.asm +++ b/src/engine/bank06.asm @@ -167,13 +167,13 @@ Func_1996e: ; 1996e (6:596e)  	or b  	jr nz, .asm_1997b  	ld a, $5 -	ld hl, sa350 +	ld hl, s0a350  	call Func_199e0  	ld a, $7 -	ld hl, sa3a4 +	ld hl, s0a3a4  	call Func_199e0  	ld a, $9 -	ld hl, sa3f8 +	ld hl, s0a3f8  	call Func_199e0  	call EnableSRAM  	ld hl, sCardCollection @@ -196,16 +196,16 @@ Func_1996e: ; 1996e (6:596e)  	dec c  	jr nz, .asm_199b2  	ld a, $2 -	ld [sa003], a +	ld [s0a003], a  	ld a, $2 -	ld [sa006], a +	ld [s0a006], a  	ld [wTextSpeed], a  	xor a -	ld [sa007], a -	ld [sa009], a -	ld [sa004], a -	ld [sa005], a -	ld [sa00a], a +	ld [s0a007], a +	ld [s0a009], a +	ld [s0a004], a +	ld [s0a005], a +	ld [s0a00a], a  	farcall Func_8cf9  	call DisableSRAM  	ret diff --git a/src/engine/home.asm b/src/engine/home.asm index 79bdf8c..05c6d21 100644 --- a/src/engine/home.asm +++ b/src/engine/home.asm @@ -1394,7 +1394,7 @@ CGBSpeedSwitch: ; 07f1 (0:07f1)  	ret  ; validate the saved data in SRAM -; it must contain with the sequence $04, $21, $05 at sa000 +; it must contain with the sequence $04, $21, $05 at s0a000  ValidateSRAM: ; 080b (0:080b)  	xor a  	call BankswitchSRAM @@ -1417,7 +1417,7 @@ ValidateSRAM: ; 080b (0:080b)  	call DisableSRAM  	ret  .check_sequence -	ld hl, sa000 +	ld hl, s0a000  	ld a, [hli]  	cp $04  	jr nz, .restart_sram @@ -1435,7 +1435,7 @@ ValidateSRAM: ; 080b (0:080b)  	call DisableSRAM  	ret -; zero all SRAM banks and set sa000 to $04, $21, $05 +; zero all SRAM banks and set s0a000 to $04, $21, $05  RestartSRAM: ; 084d (0:084d)  	ld a, 3  .clear_loop @@ -1443,7 +1443,7 @@ RestartSRAM: ; 084d (0:084d)  	dec a  	cp -1  	jr nz, .clear_loop -	ld hl, sa000 +	ld hl, s0a000  	ld [hl], $04  	inc hl  	ld [hl], $21 @@ -2584,7 +2584,7 @@ SerialRecvByte: ; 0e39 (0:0e39)  	or a  	ret -; exchange c bytes. send bytes at hl and store received bytes at de +; exchange c bytes. send bytes at hl and store received bytes in de  SerialExchangeBytes: ; 0e63 (0:0e63)  	ld b, c  .asm_e64 @@ -2815,7 +2815,7 @@ ExchangeRNG: ; 0f58 (0:0f58)  ; sets hAIActionTableIndex to an AI action specified in register a.  ; send 10 bytes of data to the other game from hAIActionTableIndex, hTempCardIndex_ff9f,  ; hTemp_ffa0, and hTempPlayAreaLocationOffset_ffa1, and hTempRetreatCostCards. -; finally exchange RNG data +; finally exchange RNG data.  SetAIAction_SerialSendDuelData: ; 0f7f (0:0f7f)  	push hl  	push bc @@ -2835,7 +2835,8 @@ SetAIAction_SerialSendDuelData: ; 0f7f (0:0f7f)  ; 0xf9b  ; receive 10 bytes of data from wSerialRecvBuf and store them into hAIActionTableIndex, -; hTempCardIndex_ff9f, hTemp_ffa0, and hTempPlayAreaLocationOffset_ffa1, and hTempRetreatCostCards +; hTempCardIndex_ff9f, hTemp_ffa0, and hTempPlayAreaLocationOffset_ffa1, +; and hTempRetreatCostCards. also exchange RNG data.  SerialRecvDuelData: ; 0f9b (0:0f9b)  	push hl  	push bc @@ -2932,20 +2933,23 @@ SerialRecv8Bytes: ; 0fe9 (0:0fe9)  ; 0x100b  ; save duel state to SRAM -; called between each two-player turn, just after player draws card +; called between each two-player turn, just after player draws card (bank 1 loaded)  SaveDuelStateToSRAM: ; 100b (0:100b)  	ld a, $2  	call BankswitchSRAM -	call $669d +	; save duel data to sCurrentDuelData +	call SaveDuelData  	xor a  	call BankswitchSRAM  	call EnableSRAM -	ld hl, sa008 +	ld hl, s0a008  	ld a, [hl]  	inc [hl]  	call DisableSRAM +	; select hl = SRAM3:(a000 + $400 * [s0a008] & $3) +	; save wDuelTurns, non-turn holder's arena card ID, turn holder's arena card ID  	and $3 -	add $28 +	add HIGH($a000) / 4  	ld l, $0  	ld h, a  	add hl, hl @@ -2974,13 +2978,14 @@ SaveDuelStateToSRAM: ; 100b (0:100b)  	ld [hli], a  	ld a, [wTempTurnDuelistCardID]  	ld [hli], a +	; save duel data to SRAM3:(a000 + $400 * [s0a008] & $3) + $0010  	pop hl  	ld de, $0010  	add hl, de  	ld e, l  	ld d, h  	call DisableSRAM -	bank1call $66a4 +	bank1call SaveDuelDataToDE  	xor a  	call BankswitchSRAM  	ret @@ -10660,7 +10665,7 @@ Func_3917: ; 3917 (0:3917)  	ld a, $22  	farcall CheckIfEventFlagSet  	call EnableSRAM -	ld [sa00a], a +	ld [s0a00a], a  	call DisableSRAM  	ret | 
