summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-x.gitignore1
-rw-r--r--src/constants/card_data_constants.asm1
-rwxr-xr-xsrc/engine/bank1.asm28
-rwxr-xr-xsrc/engine/bank3.asm4
-rwxr-xr-xsrc/engine/bank4.asm2
-rwxr-xr-xsrc/engine/bank6.asm6
-rwxr-xr-xsrc/engine/home.asm60
-rw-r--r--src/hram.asm3
-rwxr-xr-xsrc/wram.asm11
9 files changed, 67 insertions, 49 deletions
diff --git a/.gitignore b/.gitignore
index af98acd..6c6ec0a 100755
--- a/.gitignore
+++ b/.gitignore
@@ -15,6 +15,7 @@
*.sgm
*.sav
*.sys
+*.sn*
# converted image/palette data
*.1bpp
diff --git a/src/constants/card_data_constants.asm b/src/constants/card_data_constants.asm
index 63e3a68..0b85773 100644
--- a/src/constants/card_data_constants.asm
+++ b/src/constants/card_data_constants.asm
@@ -1,4 +1,5 @@
CARD_DATA_LENGTH EQU $41
+DECK_SIZE EQU 60
;;; card types (byte 1 of every card data)
FIRE EQU $0
diff --git a/src/engine/bank1.asm b/src/engine/bank1.asm
index 364cbb6..77c9d3e 100755
--- a/src/engine/bank1.asm
+++ b/src/engine/bank1.asm
@@ -48,15 +48,15 @@ INCBIN "baserom.gbc",$406f,$409f - $406f
; graphics, name and deck have been introduced
Duel_Start: ; 409f (1:409f)
ld a, $c2
- ld [$ff97], a
+ ld [hWhoseTurn], a
ld a, $0
ld [$c2f1], a
ld a, [$cc19]
- ld [wOpponentDeck], a
+ ld [wOpponentDeckId], a
call $6793
- call Func_1c72
+ call GetOpposingTurnDuelistVariable_SwapTurn
call Duel_LoadDecks
- call Func_1c72
+ call GetOpposingTurnDuelistVariable_SwapTurn
jr .asm_40ca
ld a, MUSIC_DUELTHEME1
@@ -108,7 +108,7 @@ Duel_Start: ; 409f (1:409f)
cp $80
jr z, .asm_4126
.asm_4121
- call Func_1c72
+ call GetOpposingTurnDuelistVariable_SwapTurn
jr .mainDuelLoop
.asm_4126
@@ -130,14 +130,14 @@ Duel_Start: ; 409f (1:409f)
ld hl, $0076
call Func_2aab
call Func_04a2
- ld a, [$ff97]
+ ld a, [hWhoseTurn]
push af
ld a, $c2
- ld [$ff97], a
+ ld [hWhoseTurn], a
call $4a97
call $4ad6
pop af
- ld [$ff97], a
+ ld [hWhoseTurn], a
call $3b21
ld a, [$cc07]
cp $1
@@ -150,7 +150,7 @@ Duel_Start: ; 409f (1:409f)
jr .asm_4196
.asm_4171
- ld a, [$ff97]
+ ld a, [hWhoseTurn]
cp $c2
jr nz, .asm_418a
.asm_4177
@@ -162,7 +162,7 @@ Duel_Start: ; 409f (1:409f)
jr .asm_4196
.asm_4184
- ld a, [$ff97]
+ ld a, [hWhoseTurn]
cp $c2
jr nz, .asm_4177
@@ -178,7 +178,7 @@ Duel_Start: ; 409f (1:409f)
ld a, c
call PlaySong
ld a, $c3
- ld [$ff97], a
+ ld [hWhoseTurn], a
call Func_2a59
call EnableLCD
.asm_41a7
@@ -194,7 +194,7 @@ Duel_Start: ; 409f (1:409f)
call $3b31
call ResetSerial
ld a, $c2
- ld [$ff97], a
+ ld [hWhoseTurn], a
ret
.asm_41c8
@@ -211,7 +211,7 @@ Duel_Start: ; 409f (1:409f)
cp $1
jr z, .asm_41f3
ld a, $c2
- ld [$ff97], a
+ ld [hWhoseTurn], a
call $4b60
jp $40ee
@@ -225,7 +225,7 @@ Duel_Start: ; 409f (1:409f)
.asm_4201
ld a, h
- ld [$ff97], a
+ ld [hWhoseTurn], a
call $4b60
jp nc, $40ee
ret
diff --git a/src/engine/bank3.asm b/src/engine/bank3.asm
index 3ec9202..cee8c72 100755
--- a/src/engine/bank3.asm
+++ b/src/engine/bank3.asm
@@ -27,7 +27,7 @@ LoadMap: ; c000 (3:4000)
call Func_04a2
call Func_3ca0
ld a, $c2
- ld [$ff97], a
+ ld [hWhoseTurn], a
farcall Func_1c440
ld a, [$d0bb]
ld [wCurMap], a
@@ -392,7 +392,7 @@ Func_c2db: ; c2db (3:42db)
call Func_3ca0
farcall Func_12bcd
ld a, $c2
- ld [$ff97], a
+ ld [hWhoseTurn], a
call Func_c241
call Func_04a2
ld a, [$d111]
diff --git a/src/engine/bank4.asm b/src/engine/bank4.asm
index 8c4d39c..deeecf0 100755
--- a/src/engine/bank4.asm
+++ b/src/engine/bank4.asm
@@ -695,7 +695,7 @@ Func_126d1: ; 126d1 (4:66d1)
ld [$d627], a
.asm_126e1
ld a, $c2
- ld [$ff97], a
+ ld [hWhoseTurn], a
farcall Func_c1f8
farcall Func_1d078
ld a, [$d628]
diff --git a/src/engine/bank6.asm b/src/engine/bank6.asm
index 8d38e74..09bf69b 100755
--- a/src/engine/bank6.asm
+++ b/src/engine/bank6.asm
@@ -7,7 +7,7 @@ INCBIN "baserom.gbc",$18f9c,$1996e - $18f9c
Func_1996e: ; 1996e (6:596e)
call EnableExtRAM
ld a, $c2
- ld [$ff97], a
+ ld [hWhoseTurn], a
ld hl, $a100
ld bc, $1607
.asm_1997b
@@ -82,7 +82,7 @@ Func_199e0: ; 199e0 (6:59e0)
push hl
ld de, $0018
add hl, de
- ld de, $c400
+ ld de, wPlayerDeck
ld c, $3c
.asm_19a04
ld a, [de]
@@ -155,7 +155,7 @@ Func_1a61f: ; 1a61f (6:661f)
ld l, a
bank1call $2ebb
ld a, $c2
- ld [$ff97], a
+ ld [hWhoseTurn], a
pop hl
bank1call $5e5f
.asm_1a680
diff --git a/src/engine/home.asm b/src/engine/home.asm
index de9662d..8d64870 100755
--- a/src/engine/home.asm
+++ b/src/engine/home.asm
@@ -1198,7 +1198,7 @@ ClearExtRAMBank: ; 0863 (0:0863)
ret
; returns h * l in hl
-HtimesL:: ; 0879 (0:0879)
+HtimesL: ; 0879 (0:0879)
push de
ld a, h
ld e, l
@@ -2061,17 +2061,17 @@ ClearSerialData: ; 0eb1 (0:0eb1)
INCBIN "baserom.gbc",$0ebf,$1072 - $0ebf
-; copies the deck pointed to by de to $c400 or $c480
+; copies the deck pointed to by de to wPlayerDeck or wOpponentDeck
CopyDeckData: ; 1072 (0:1072)
- ld hl, $c400
- ld a, [$ff97]
+ ld hl, wPlayerDeck
+ ld a, [hWhoseTurn]
cp $c2
- jr z, .asm_107e
- ld hl, $c480
-.asm_107e
+ jr z, .copyDeckData
+ ld hl, wOpponentDeck
+.copyDeckData
; start by putting a terminator at the end of the deck
push hl
- ld bc, 59
+ ld bc, DECK_SIZE - 1
add hl, bc
ld [hl], $0
pop hl
@@ -2099,7 +2099,7 @@ CopyDeckData: ; 1072 (0:1072)
ld a, [de]
ld [hl], a
pop hl
- ld bc, 59
+ ld bc, DECK_SIZE - 1
add hl, bc
ld a, [hl]
or a
@@ -2111,21 +2111,24 @@ CopyDeckData: ; 1072 (0:1072)
INCBIN "baserom.gbc",$10aa,$160b - $10aa
-Func_160b: ; 160b (0:160b)
+; returns [[hWhoseTurn] * $100 + a] in a
+; i.e. variable a of the player whose turn it is
+GetTurnDuelistVariable: ; 160b (0:160b)
ld l, a
- ld a, [$ff97]
+ ld a, [hWhoseTurn]
ld h, a
ld a, [hl]
ret
-Func_1611: ; 1611 (0:1611)
+; returns [([hWhoseTurn] ^ $1) * $100 + a] in a
+; i.e. variable a of the player whose turn it is not
+GetOpposingTurnDuelistVariable: ; 1611 (0:1611)
ld l, a
- ld a, [$ff97]
+ ld a, [hWhoseTurn]
ld h, $c3
cp $c2
jr z, .asm_161c
ld h, $c2
-
.asm_161c
ld a, [hl]
ret
@@ -2133,12 +2136,15 @@ Func_1611: ; 1611 (0:1611)
INCBIN "baserom.gbc",$161e,$1c72 - $161e
-Func_1c72: ; 1c72 (0:1c72)
+; returns [([hWhoseTurn] ^ $1) * $100 + a] in a
+; i.e. variable a of the player whose turn it is not
+; Also: [hWhoseTurn] <-- [hWhoseTurn ^ $1]
+GetOpposingTurnDuelistVariable_SwapTurn: ; 1c72 (0:1c72)
push af
push hl
- call Func_1611
+ call GetOpposingTurnDuelistVariable
ld a, h
- ld [$ff97], a
+ ld [hWhoseTurn], a
pop hl
pop af
ret
@@ -3532,7 +3538,7 @@ INCBIN "baserom.gbc",$2b70,$2b78 - $2b70
Duel_LoadDecks: ; 2b78 (0:2b78)
xor a
ld [wIsPracticeDuel], a
- ld a, [wOpponentDeck]
+ ld a, [wOpponentDeckId]
cp SAMS_NORMAL_DECK - 2
jr z, .normalSamDuel
or a ; cp SAMS_PRACTICE_DECK - 2
@@ -3546,11 +3552,11 @@ Duel_LoadDecks: ; 2b78 (0:2b78)
.normalSamDuel
xor a
- ld [wOpponentDeck], a
- call Func_1c72
+ ld [wOpponentDeckId], a
+ call GetOpposingTurnDuelistVariable_SwapTurn
ld a, PRACTICE_PLAYER_DECK
call LoadDeck
- call Func_1c72
+ call GetOpposingTurnDuelistVariable_SwapTurn
ld hl, $caca
ld a, $57
ld [hli], a
@@ -3562,16 +3568,16 @@ Duel_LoadDecks: ; 2b78 (0:2b78)
inc a
inc a
call LoadDeck
- ld a, [wOpponentDeck]
+ ld a, [wOpponentDeckId]
cp NUMBER_OF_DECKS
jr c, .validDeck
ld a, PRACTICE_PLAYER_DECK - 2
- ld [wOpponentDeck], a
+ ld [wOpponentDeckId], a
.validDeck
ld a, $f1
- call Func_160b
- ld a, [wOpponentDeck]
+ call GetTurnDuelistVariable
+ ld a, [wOpponentDeckId]
or $80
ld [hl], a
ret
@@ -3826,7 +3832,7 @@ Func_2e12: ; 2e12 (0:2e12)
Func_2e2c: ; 2e2c (0:2e2c)
ld de, $caa0
push de
- ld a, [$ff97]
+ ld a, [hWhoseTurn]
cp $c3
jp z, .asm_2e3c
call Func_1c7d
@@ -3906,7 +3912,7 @@ PrintTextBoxBorderLabel: ; 2e89 (0:2e89)
dec de
ret
.done
- ld a, [$ff97]
+ ld a, [hWhoseTurn]
cp $c3
jp z, Func_1c8e
jp Func_1c7d
diff --git a/src/hram.asm b/src/hram.asm
index ebac5a9..9868486 100644
--- a/src/hram.asm
+++ b/src/hram.asm
@@ -14,3 +14,6 @@ hSCX EQU $FF92
hSCY EQU $FF93
hWX EQU $FF94
hWY EQU $FF95
+
+; $c2 = player ; $c3 = opponent
+hWhoseTurn EQU $FF97
diff --git a/src/wram.asm b/src/wram.asm
index 9aeac92..8ded548 100755
--- a/src/wram.asm
+++ b/src/wram.asm
@@ -3,7 +3,14 @@ INCLUDE "constants.asm"
;--- Bank 0: $Cxxx ----------------------------------------
SECTION "WRAM0", WRAM0
- ds $a00
+ ds $400
+
+wPlayerDeck:: ; c400
+ ds $80
+
+wOpponentDeck:: ; c480
+ ds $80
+ ds $500
wBufOAM:: ; ca00
ds $a0
@@ -125,7 +132,7 @@ wSerialRecvBuf:: ; $cba5 - $cbc4
; this seems to hold the current opponent's deck id - 2,
; perhaps to account for the two unused pointers at the
; beginning of DeckPointers
-wOpponentDeck:: ; cc0e
+wOpponentDeckId:: ; cc0e
ds $1
ds $4