summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorxCrystal <rgr.crystal@gmail.com>2016-01-26 14:00:19 +0100
committerxCrystal <rgr.crystal@gmail.com>2016-01-26 14:00:19 +0100
commit5a33e213bf35bfb535443e078669877ca4c567f3 (patch)
tree17d942d61c4ef39cdd8edcb7a8913c7e0a009569 /src
parentffbb12fb97e689c20872ef3d1817e7d3ac3a95ba (diff)
more duel incbins
Diffstat (limited to 'src')
-rwxr-xr-xsrc/engine/bank1.asm31
-rwxr-xr-xsrc/engine/home.asm72
2 files changed, 95 insertions, 8 deletions
diff --git a/src/engine/bank1.asm b/src/engine/bank1.asm
index ad84579..90b2255 100755
--- a/src/engine/bank1.asm
+++ b/src/engine/bank1.asm
@@ -46,16 +46,16 @@ INCBIN "baserom.gbc",$406f,$409f - $406f
; this function begins the duel after the opponent's
; graphics, name and deck have been introduced
-Duel_Start: ; 409f (1:409f)
+StartDuel: ; 409f (1:409f)
ld a, $c2
ld [hWhoseTurn], a
ld a, $0
ld [$c2f1], a
ld a, [$cc19]
ld [wOpponentDeckId], a
- call $6793
+ call LoadPlayerDeck
call GetOpposingTurnDuelistVariable_SwapTurn
- call Duel_LoadDecks
+ call LoadOpponentDeck
call GetOpposingTurnDuelistVariable_SwapTurn
jr .asm_40ca
@@ -237,7 +237,30 @@ Func_5aeb: ; 5aeb (1:5aeb)
INCBIN "baserom.gbc",$5aeb,$6785 - $5aeb
Func_6785: ; 6785 (1:6785)
-INCBIN "baserom.gbc",$6785,$7107 - $6785
+INCBIN "baserom.gbc",$6785,$6793 - $6785
+
+; loads player deck from SRAM to wPlayerDeck
+LoadPlayerDeck: ; 6793 (1:6793)
+ call EnableExtRAM
+ ld a, [$b700]
+ ld l, a
+ ld h, $54
+ call HtimesL
+ ld de, $a218
+ add hl, de
+ ld de, wPlayerDeck
+ ld c, DECK_SIZE
+.nextCardLoop
+ ld a, [hli]
+ ld [de], a
+ inc de
+ dec c
+ jr nz, .nextCardLoop
+ call DisableExtRAM
+ ret
+; 0x67b2
+
+INCBIN "baserom.gbc",$67b2,$7107 - $67b2
InitializeDuelVariables: ; 7107 (1:7107)
ld a, [hWhoseTurn]
diff --git a/src/engine/home.asm b/src/engine/home.asm
index fa33edb..3d12777 100755
--- a/src/engine/home.asm
+++ b/src/engine/home.asm
@@ -2119,7 +2119,69 @@ CopyDeckData: ; 1072 (0:1072)
ret
; 0x10aa
-INCBIN "baserom.gbc",$10aa,$160b - $10aa
+INCBIN "baserom.gbc",$10aa,$10bc - $10aa
+
+; shuffles the deck specified by hWhoseTurn
+; if less than 60 cards remain in the deck, make sure the rest are ignored
+ShuffleDeck: ; 10bc (0:10bc)
+ ld a, [hWhoseTurn]
+ ld h, a
+ ld d, a
+ ld a, DECK_SIZE
+ ld l, wPlayerNumberOfCardsNotInDeck & $ff
+ sub [hl]
+ ld b, a
+ ld a, wPlayerDeckCards & $ff
+ add [hl]
+ ld l, a ; hl = position in the wPlayerDeckCards or wOpponentDeckCards array of the first (top) card in the deck
+ ld a, b ; a = number of cards in the deck
+ call ShuffleCards
+ ret
+; 0x10cf
+
+INCBIN "baserom.gbc",$10cf,$127f - $10cf
+
+; shuffles the deck by swapping the position of each card with the position of another random card
+; input:
+; - a = how many cards to shuffle
+; - hl = position of the first card within the wPlayerDeckCards or wOpponentDeckCards array
+ShuffleCards: ; 127f (0:127f)
+ or a
+ ret z ; return if deck is empty
+ push hl
+ push de
+ push bc
+ ld c, a
+ ld b, a
+ ld e, l
+ ld d, h
+.shuffleNextCardLoop
+ push bc
+ push de
+ ld a, c
+ call Random
+ add e
+ ld e, a
+ ld a, $0
+ adc d
+ ld d, a
+ ld a, [de]
+ ld b, [hl]
+ ld [hl], a
+ ld a, b
+ ld [de], a
+ pop de
+ pop bc
+ inc hl
+ dec b
+ jr nz, .shuffleNextCardLoop
+ pop bc
+ pop de
+ pop hl
+ ret
+; 0x12a3
+
+INCBIN "baserom.gbc",$12a3,$160b - $12a3
; returns [[hWhoseTurn] * $100 + a] in a
; i.e. variable a of the player whose turn it is
@@ -3568,7 +3630,8 @@ Func_2b66: ; 2b66 (0:2b66)
INCBIN "baserom.gbc",$2b70,$2b78 - $2b70
-Duel_LoadDecks: ; 2b78 (0:2b78)
+; loads opponent deck to wOpponentDeck
+LoadOpponentDeck: ; 2b78 (0:2b78)
xor a
ld [wIsPracticeDuel], a
ld a, [wOpponentDeckId]
@@ -3608,7 +3671,8 @@ Duel_LoadDecks: ; 2b78 (0:2b78)
ld [wOpponentDeckId], a
.validDeck
- ld a, $f1
+; set opponent as controlled by AI
+ ld a, wOpponentDuelistType & $ff
call GetTurnDuelistVariable
ld a, [wOpponentDeckId]
or $80
@@ -4639,7 +4703,7 @@ Func_38c0: ; 38c0 (0:38c0)
ld [$ba44], a
call DisableExtRAM
call Func_3a3b
- bank1call Duel_Start
+ bank1call StartDuel
scf
ret