2020-11-08 16:32:57 -08:00
|
|
|
_MemoryGame:
|
2015-12-28 14:09:53 -08:00
|
|
|
call .LoadGFXAndPals
|
2015-11-11 20:38:57 -08:00
|
|
|
call DelayFrame
|
2015-12-28 14:09:53 -08:00
|
|
|
.loop
|
|
|
|
call .JumptableLoop
|
|
|
|
jr nc, .loop
|
2015-11-11 20:38:57 -08:00
|
|
|
ret
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.LoadGFXAndPals:
|
2015-11-11 20:38:57 -08:00
|
|
|
call DisableLCD
|
2023-07-26 08:01:20 -07:00
|
|
|
ld b, CGB_DIPLOMA
|
|
|
|
call GetCGBLayout
|
2017-12-24 09:47:30 -08:00
|
|
|
callfar ClearSpriteAnims
|
2020-11-08 16:32:57 -08:00
|
|
|
ld hl, MemoryGameLZ
|
2017-12-28 04:32:33 -08:00
|
|
|
ld de, vTiles2 tile $00
|
2015-11-11 20:38:57 -08:00
|
|
|
call Decompress
|
2020-11-08 16:32:57 -08:00
|
|
|
ld hl, MemoryGameGFX
|
2017-12-28 04:32:33 -08:00
|
|
|
ld de, vTiles0 tile $00
|
2015-12-28 14:09:53 -08:00
|
|
|
ld bc, 4 tiles
|
2020-11-08 16:32:57 -08:00
|
|
|
ld a, BANK(MemoryGameGFX)
|
2015-11-11 20:38:57 -08:00
|
|
|
call FarCopyBytes
|
2020-10-30 12:39:08 -07:00
|
|
|
ld a, SPRITE_ANIM_DICT_ARROW_CURSOR
|
2020-10-26 12:45:57 -07:00
|
|
|
ld hl, wSpriteAnimDict
|
2015-11-11 20:38:57 -08:00
|
|
|
ld [hli], a
|
2020-10-30 12:39:08 -07:00
|
|
|
ld [hl], $00
|
2015-11-11 20:38:57 -08:00
|
|
|
hlcoord 0, 0
|
|
|
|
ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
|
|
|
|
xor a
|
|
|
|
call ByteFill
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSCY], a
|
|
|
|
ldh [hSCX], a
|
|
|
|
ldh [rWY], a
|
2015-11-11 20:38:57 -08:00
|
|
|
ld [wJumptableIndex], a
|
|
|
|
ld a, $1
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hBGMapMode], a
|
2017-12-29 10:22:33 -08:00
|
|
|
ld a, LCDC_DEFAULT
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rLCDC], a
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, $e4
|
|
|
|
call DmgToCgbBGPals
|
|
|
|
ld a, $e0
|
2015-12-09 08:38:40 -08:00
|
|
|
call DmgToCgbObjPal0
|
2015-11-11 20:38:57 -08:00
|
|
|
ret
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.JumptableLoop:
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, [wJumptableIndex]
|
|
|
|
bit 7, a
|
2015-12-28 14:09:53 -08:00
|
|
|
jr nz, .quit
|
|
|
|
call .ExecuteJumptable
|
2017-12-24 09:47:30 -08:00
|
|
|
callfar PlaySpriteAnimations
|
2015-11-11 20:38:57 -08:00
|
|
|
call DelayFrame
|
|
|
|
and a
|
|
|
|
ret
|
2015-12-28 14:09:53 -08:00
|
|
|
|
|
|
|
.quit
|
2015-11-11 20:38:57 -08:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.ExecuteJumptable:
|
2015-12-28 14:09:53 -08:00
|
|
|
jumptable .Jumptable, wJumptableIndex
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.Jumptable:
|
2015-12-28 14:09:53 -08:00
|
|
|
dw .RestartGame
|
|
|
|
dw .ResetBoard
|
|
|
|
dw .InitBoardTilemapAndCursorObject
|
|
|
|
dw .CheckTriesRemaining
|
|
|
|
dw .PickCard1
|
|
|
|
dw .PickCard2
|
|
|
|
dw .DelayPickAgain
|
|
|
|
dw .RevealAll
|
|
|
|
dw .AskPlayAgain
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.RestartGame:
|
2020-11-08 16:32:57 -08:00
|
|
|
call MemoryGame_InitStrings
|
2015-11-11 20:38:57 -08:00
|
|
|
ld hl, wJumptableIndex
|
|
|
|
inc [hl]
|
|
|
|
ret
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.ResetBoard:
|
2020-10-22 07:54:53 -07:00
|
|
|
call UnusedCursor_InterpretJoypad_AnimateCursor
|
2015-12-28 14:09:53 -08:00
|
|
|
jr nc, .proceed
|
2015-11-11 20:38:57 -08:00
|
|
|
ld hl, wJumptableIndex
|
|
|
|
set 7, [hl]
|
|
|
|
ret
|
|
|
|
|
2015-12-28 14:09:53 -08:00
|
|
|
.proceed
|
2020-11-08 16:32:57 -08:00
|
|
|
call MemoryGame_InitBoard
|
2015-11-11 20:38:57 -08:00
|
|
|
ld hl, wJumptableIndex
|
|
|
|
inc [hl]
|
|
|
|
xor a
|
2020-11-08 16:32:57 -08:00
|
|
|
ld [wMemoryGameCounter], a
|
|
|
|
ld hl, wMemoryGameLastMatches
|
2015-11-11 20:38:57 -08:00
|
|
|
rept 4
|
|
|
|
ld [hli], a
|
|
|
|
endr
|
|
|
|
ld [hl], a
|
2020-11-08 16:32:57 -08:00
|
|
|
ld [wMemoryGameNumCardsMatched], a
|
2016-04-10 11:42:14 -07:00
|
|
|
.InitBoardTilemapAndCursorObject:
|
2020-11-08 16:32:57 -08:00
|
|
|
ld hl, wMemoryGameCounter
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, [hl]
|
2015-12-28 14:09:53 -08:00
|
|
|
cp 45
|
|
|
|
jr nc, .spawn_object
|
2015-11-11 20:38:57 -08:00
|
|
|
inc [hl]
|
2020-11-08 16:32:57 -08:00
|
|
|
call MemoryGame_Card2Coord
|
2015-11-11 20:38:57 -08:00
|
|
|
xor a
|
2020-11-08 16:32:57 -08:00
|
|
|
ld [wMemoryGameLastCardPicked], a
|
|
|
|
call MemoryGame_PlaceCard
|
2015-11-11 20:38:57 -08:00
|
|
|
ret
|
|
|
|
|
2015-12-28 14:09:53 -08:00
|
|
|
.spawn_object
|
|
|
|
depixel 6, 3, 4, 4
|
2023-09-24 06:06:19 -07:00
|
|
|
ld a, SPRITE_ANIM_OBJ_MEMORY_GAME_CURSOR
|
2020-02-11 04:42:36 -08:00
|
|
|
call InitSpriteAnimStruct
|
2015-12-28 14:09:53 -08:00
|
|
|
ld a, 5
|
2020-11-08 16:32:57 -08:00
|
|
|
ld [wMemoryGameNumberTriesRemaining], a
|
2015-11-11 20:38:57 -08:00
|
|
|
ld hl, wJumptableIndex
|
|
|
|
inc [hl]
|
|
|
|
ret
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.CheckTriesRemaining:
|
2020-11-08 16:32:57 -08:00
|
|
|
ld a, [wMemoryGameNumberTriesRemaining]
|
2015-11-11 20:38:57 -08:00
|
|
|
hlcoord 17, 0
|
2015-12-28 14:09:53 -08:00
|
|
|
add "0"
|
2015-11-11 20:38:57 -08:00
|
|
|
ld [hl], a
|
2020-11-08 16:32:57 -08:00
|
|
|
ld hl, wMemoryGameNumberTriesRemaining
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, [hl]
|
|
|
|
and a
|
2015-12-28 14:09:53 -08:00
|
|
|
jr nz, .next_try
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, $7
|
|
|
|
ld [wJumptableIndex], a
|
|
|
|
ret
|
|
|
|
|
2015-12-28 14:09:53 -08:00
|
|
|
.next_try
|
2015-11-11 20:38:57 -08:00
|
|
|
dec [hl]
|
|
|
|
xor a
|
2020-11-08 16:32:57 -08:00
|
|
|
ld [wMemoryGameCardChoice], a
|
2015-11-11 20:38:57 -08:00
|
|
|
ld hl, wJumptableIndex
|
|
|
|
inc [hl]
|
2016-04-10 11:42:14 -07:00
|
|
|
.PickCard1:
|
2020-11-08 16:32:57 -08:00
|
|
|
ld a, [wMemoryGameCardChoice]
|
2015-11-11 20:38:57 -08:00
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
dec a
|
|
|
|
ld e, a
|
2015-12-28 14:09:53 -08:00
|
|
|
ld d, 0
|
2020-11-08 16:32:57 -08:00
|
|
|
ld hl, wMemoryGameCards
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
2015-12-28 14:09:53 -08:00
|
|
|
cp -1
|
2015-11-11 20:38:57 -08:00
|
|
|
ret z
|
2020-11-08 16:32:57 -08:00
|
|
|
ld [wMemoryGameLastCardPicked], a
|
|
|
|
ld [wMemoryGameCard1], a
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, e
|
2020-11-08 16:32:57 -08:00
|
|
|
ld [wMemoryGameCard1Location], a
|
|
|
|
call MemoryGame_Card2Coord
|
|
|
|
call MemoryGame_PlaceCard
|
2015-11-11 20:38:57 -08:00
|
|
|
xor a
|
2020-11-08 16:32:57 -08:00
|
|
|
ld [wMemoryGameCardChoice], a
|
2015-11-11 20:38:57 -08:00
|
|
|
ld hl, wJumptableIndex
|
|
|
|
inc [hl]
|
|
|
|
ret
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.PickCard2:
|
2020-11-08 16:32:57 -08:00
|
|
|
ld a, [wMemoryGameCardChoice]
|
2015-11-11 20:38:57 -08:00
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
dec a
|
2020-11-08 16:32:57 -08:00
|
|
|
ld hl, wMemoryGameCard1Location
|
2015-11-11 20:38:57 -08:00
|
|
|
cp [hl]
|
|
|
|
ret z
|
|
|
|
ld e, a
|
2015-12-28 14:09:53 -08:00
|
|
|
ld d, 0
|
2020-11-08 16:32:57 -08:00
|
|
|
ld hl, wMemoryGameCards
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
2015-12-28 14:09:53 -08:00
|
|
|
cp -1
|
2015-11-11 20:38:57 -08:00
|
|
|
ret z
|
2020-11-08 16:32:57 -08:00
|
|
|
ld [wMemoryGameLastCardPicked], a
|
|
|
|
ld [wMemoryGameCard2], a
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, e
|
2020-11-08 16:32:57 -08:00
|
|
|
ld [wMemoryGameCard2Location], a
|
|
|
|
call MemoryGame_Card2Coord
|
|
|
|
call MemoryGame_PlaceCard
|
2015-12-28 14:09:53 -08:00
|
|
|
ld a, 64
|
2020-11-08 16:32:57 -08:00
|
|
|
ld [wMemoryGameCounter], a
|
2015-11-11 20:38:57 -08:00
|
|
|
ld hl, wJumptableIndex
|
|
|
|
inc [hl]
|
2016-04-10 11:42:14 -07:00
|
|
|
.DelayPickAgain:
|
2020-11-08 16:32:57 -08:00
|
|
|
ld hl, wMemoryGameCounter
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, [hl]
|
|
|
|
and a
|
2015-12-28 14:09:53 -08:00
|
|
|
jr z, .PickAgain
|
2015-11-11 20:38:57 -08:00
|
|
|
dec [hl]
|
|
|
|
ret
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.PickAgain:
|
2020-11-08 16:32:57 -08:00
|
|
|
call MemoryGame_CheckMatch
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, $3
|
|
|
|
ld [wJumptableIndex], a
|
|
|
|
ret
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.RevealAll:
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hJoypadPressed]
|
2015-11-11 20:38:57 -08:00
|
|
|
and A_BUTTON
|
|
|
|
ret z
|
|
|
|
xor a
|
2020-11-08 16:32:57 -08:00
|
|
|
ld [wMemoryGameCounter], a
|
2016-04-10 11:42:14 -07:00
|
|
|
.RevelationLoop:
|
2020-11-08 16:32:57 -08:00
|
|
|
ld hl, wMemoryGameCounter
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, [hl]
|
2015-12-28 14:09:53 -08:00
|
|
|
cp 45
|
|
|
|
jr nc, .finish_round
|
2015-11-11 20:38:57 -08:00
|
|
|
inc [hl]
|
|
|
|
push af
|
2020-11-08 16:32:57 -08:00
|
|
|
call MemoryGame_Card2Coord
|
2015-11-11 20:38:57 -08:00
|
|
|
pop af
|
|
|
|
push hl
|
|
|
|
ld e, a
|
2020-11-09 12:17:03 -08:00
|
|
|
ld d, 0
|
2020-11-08 16:32:57 -08:00
|
|
|
ld hl, wMemoryGameCards
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
|
|
|
pop hl
|
2015-12-28 14:09:53 -08:00
|
|
|
cp -1
|
|
|
|
jr z, .RevelationLoop
|
2020-11-08 16:32:57 -08:00
|
|
|
ld [wMemoryGameLastCardPicked], a
|
|
|
|
call MemoryGame_PlaceCard
|
2015-12-28 14:09:53 -08:00
|
|
|
jr .RevelationLoop
|
2015-11-11 20:38:57 -08:00
|
|
|
|
2015-12-28 14:09:53 -08:00
|
|
|
.finish_round
|
2015-11-11 20:38:57 -08:00
|
|
|
call WaitPressAorB_BlinkCursor
|
|
|
|
ld hl, wJumptableIndex
|
|
|
|
inc [hl]
|
2016-04-10 11:42:14 -07:00
|
|
|
.AskPlayAgain:
|
2020-10-22 07:54:53 -07:00
|
|
|
call UnusedCursor_InterpretJoypad_AnimateCursor
|
2015-12-28 14:09:53 -08:00
|
|
|
jr nc, .restart
|
2015-11-11 20:38:57 -08:00
|
|
|
ld hl, wJumptableIndex
|
|
|
|
set 7, [hl]
|
|
|
|
ret
|
|
|
|
|
2015-12-28 14:09:53 -08:00
|
|
|
.restart
|
2015-11-11 20:38:57 -08:00
|
|
|
xor a
|
|
|
|
ld [wJumptableIndex], a
|
|
|
|
ret
|
2015-12-28 14:09:53 -08:00
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
MemoryGame_CheckMatch:
|
|
|
|
ld hl, wMemoryGameCard1
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, [hli]
|
|
|
|
cp [hl]
|
2015-12-28 14:09:53 -08:00
|
|
|
jr nz, .no_match
|
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
ld a, [wMemoryGameCard1Location]
|
|
|
|
call MemoryGame_Card2Coord
|
|
|
|
call MemoryGame_DeleteCard
|
2015-12-28 14:09:53 -08:00
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
ld a, [wMemoryGameCard2Location]
|
|
|
|
call MemoryGame_Card2Coord
|
|
|
|
call MemoryGame_DeleteCard
|
2015-12-28 14:09:53 -08:00
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
ld a, [wMemoryGameCard1Location]
|
2015-11-11 20:38:57 -08:00
|
|
|
ld e, a
|
2020-11-09 12:17:03 -08:00
|
|
|
ld d, 0
|
2020-11-08 16:32:57 -08:00
|
|
|
ld hl, wMemoryGameCards
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, de
|
2015-12-28 14:09:53 -08:00
|
|
|
ld [hl], -1
|
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
ld a, [wMemoryGameCard2Location]
|
2015-11-11 20:38:57 -08:00
|
|
|
ld e, a
|
2015-12-28 14:09:53 -08:00
|
|
|
ld d, 0
|
2020-11-08 16:32:57 -08:00
|
|
|
ld hl, wMemoryGameCards
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, de
|
2015-12-28 14:09:53 -08:00
|
|
|
ld [hl], -1
|
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
ld hl, wMemoryGameLastMatches
|
2015-12-28 14:09:53 -08:00
|
|
|
.find_empty_slot
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, [hli]
|
|
|
|
and a
|
2015-12-28 14:09:53 -08:00
|
|
|
jr nz, .find_empty_slot
|
2015-11-11 20:38:57 -08:00
|
|
|
dec hl
|
2020-11-08 16:32:57 -08:00
|
|
|
ld a, [wMemoryGameCard1]
|
2015-11-11 20:38:57 -08:00
|
|
|
ld [hl], a
|
2020-11-08 16:32:57 -08:00
|
|
|
ld [wMemoryGameLastCardPicked], a
|
|
|
|
ld hl, wMemoryGameNumCardsMatched
|
2015-11-11 20:38:57 -08:00
|
|
|
ld e, [hl]
|
|
|
|
inc [hl]
|
2015-12-28 14:09:53 -08:00
|
|
|
inc [hl]
|
|
|
|
ld d, 0
|
2015-11-11 20:38:57 -08:00
|
|
|
hlcoord 5, 0
|
|
|
|
add hl, de
|
2020-11-08 16:32:57 -08:00
|
|
|
call MemoryGame_PlaceCard
|
2015-12-28 14:09:53 -08:00
|
|
|
ld hl, .VictoryText
|
2023-08-11 03:28:14 -07:00
|
|
|
call PrintText1bpp
|
2015-11-11 20:38:57 -08:00
|
|
|
ret
|
|
|
|
|
2015-12-28 14:09:53 -08:00
|
|
|
.no_match
|
2015-11-11 20:38:57 -08:00
|
|
|
xor a
|
2020-11-08 16:32:57 -08:00
|
|
|
ld [wMemoryGameLastCardPicked], a
|
2015-12-28 14:09:53 -08:00
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
ld a, [wMemoryGameCard1Location]
|
|
|
|
call MemoryGame_Card2Coord
|
|
|
|
call MemoryGame_PlaceCard
|
2015-12-28 14:09:53 -08:00
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
ld a, [wMemoryGameCard2Location]
|
|
|
|
call MemoryGame_Card2Coord
|
|
|
|
call MemoryGame_PlaceCard
|
2015-12-28 14:09:53 -08:00
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
ld hl, MemoryGameDarnText
|
2023-08-11 03:28:14 -07:00
|
|
|
call PrintText1bpp
|
2015-11-11 20:38:57 -08:00
|
|
|
ret
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.VictoryText:
|
2018-11-17 10:33:03 -08:00
|
|
|
text_asm
|
2015-11-11 20:38:57 -08:00
|
|
|
push bc
|
|
|
|
hlcoord 2, 13
|
2020-11-08 16:32:57 -08:00
|
|
|
call MemoryGame_PlaceCard
|
|
|
|
ld hl, MemoryGameYeahText
|
2015-11-11 20:38:57 -08:00
|
|
|
pop bc
|
|
|
|
inc bc
|
2015-12-28 14:09:53 -08:00
|
|
|
inc bc
|
|
|
|
inc bc
|
2015-11-11 20:38:57 -08:00
|
|
|
ret
|
2015-12-28 14:09:53 -08:00
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
MemoryGameYeahText:
|
|
|
|
text_far _MemoryGameYeahText
|
2018-11-17 10:33:03 -08:00
|
|
|
text_end
|
2015-11-11 20:38:57 -08:00
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
MemoryGameDarnText:
|
|
|
|
text_far _MemoryGameDarnText
|
2018-11-17 10:33:03 -08:00
|
|
|
text_end
|
2015-11-11 20:38:57 -08:00
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
MemoryGame_InitBoard:
|
|
|
|
ld hl, wMemoryGameCards
|
|
|
|
ld bc, wMemoryGameCardsEnd - wMemoryGameCards
|
2015-11-11 20:38:57 -08:00
|
|
|
xor a
|
|
|
|
call ByteFill
|
2020-11-08 16:32:57 -08:00
|
|
|
call MemoryGame_GetDistributionOfTiles
|
2015-12-28 14:09:53 -08:00
|
|
|
|
|
|
|
ld c, 2
|
2015-11-11 20:38:57 -08:00
|
|
|
ld b, [hl]
|
2020-11-08 16:32:57 -08:00
|
|
|
call MemoryGame_SampleTilePlacement
|
2015-12-28 14:09:53 -08:00
|
|
|
|
|
|
|
ld c, 8
|
2015-11-11 20:38:57 -08:00
|
|
|
ld b, [hl]
|
2020-11-08 16:32:57 -08:00
|
|
|
call MemoryGame_SampleTilePlacement
|
2015-12-28 14:09:53 -08:00
|
|
|
|
|
|
|
ld c, 4
|
2015-11-11 20:38:57 -08:00
|
|
|
ld b, [hl]
|
2020-11-08 16:32:57 -08:00
|
|
|
call MemoryGame_SampleTilePlacement
|
2015-12-28 14:09:53 -08:00
|
|
|
|
|
|
|
ld c, 7
|
2015-11-11 20:38:57 -08:00
|
|
|
ld b, [hl]
|
2020-11-08 16:32:57 -08:00
|
|
|
call MemoryGame_SampleTilePlacement
|
2015-12-28 14:09:53 -08:00
|
|
|
|
|
|
|
ld c, 3
|
2015-11-11 20:38:57 -08:00
|
|
|
ld b, [hl]
|
2020-11-08 16:32:57 -08:00
|
|
|
call MemoryGame_SampleTilePlacement
|
2015-12-28 14:09:53 -08:00
|
|
|
|
|
|
|
ld c, 6
|
2015-11-11 20:38:57 -08:00
|
|
|
ld b, [hl]
|
2020-11-08 16:32:57 -08:00
|
|
|
call MemoryGame_SampleTilePlacement
|
2015-12-28 14:09:53 -08:00
|
|
|
|
|
|
|
ld c, 1
|
2015-11-11 20:38:57 -08:00
|
|
|
ld b, [hl]
|
2020-11-08 16:32:57 -08:00
|
|
|
call MemoryGame_SampleTilePlacement
|
2015-12-28 14:09:53 -08:00
|
|
|
|
|
|
|
ld c, 5
|
2020-11-08 16:32:57 -08:00
|
|
|
ld hl, wMemoryGameCards
|
|
|
|
ld b, wMemoryGameCardsEnd - wMemoryGameCards
|
2015-12-28 14:09:53 -08:00
|
|
|
.loop
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, [hl]
|
|
|
|
and a
|
2015-12-28 14:09:53 -08:00
|
|
|
jr nz, .no_load
|
2015-11-11 20:38:57 -08:00
|
|
|
ld [hl], c
|
2015-12-28 14:09:53 -08:00
|
|
|
.no_load
|
2015-11-11 20:38:57 -08:00
|
|
|
inc hl
|
|
|
|
dec b
|
2015-12-28 14:09:53 -08:00
|
|
|
jr nz, .loop
|
2015-11-11 20:38:57 -08:00
|
|
|
ret
|
2015-12-28 14:09:53 -08:00
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
MemoryGame_SampleTilePlacement:
|
2015-11-11 20:38:57 -08:00
|
|
|
push hl
|
2020-11-08 16:32:57 -08:00
|
|
|
ld de, wMemoryGameCards
|
2015-12-28 14:09:53 -08:00
|
|
|
.loop
|
2015-11-11 20:38:57 -08:00
|
|
|
call Random
|
2015-12-28 14:09:53 -08:00
|
|
|
and %00111111
|
|
|
|
cp 45
|
|
|
|
jr nc, .loop
|
2015-11-11 20:38:57 -08:00
|
|
|
ld l, a
|
2015-12-28 14:09:53 -08:00
|
|
|
ld h, 0
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
2015-12-28 14:09:53 -08:00
|
|
|
jr nz, .loop
|
2015-11-11 20:38:57 -08:00
|
|
|
ld [hl], c
|
|
|
|
dec b
|
2015-12-28 14:09:53 -08:00
|
|
|
jr nz, .loop
|
2015-11-11 20:38:57 -08:00
|
|
|
pop hl
|
|
|
|
inc hl
|
|
|
|
ret
|
2015-12-28 14:09:53 -08:00
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
MemoryGame_GetDistributionOfTiles:
|
2015-12-15 15:59:49 -08:00
|
|
|
ld a, [wMenuCursorY]
|
2015-11-11 20:38:57 -08:00
|
|
|
dec a
|
|
|
|
ld l, a
|
|
|
|
ld h, 0
|
|
|
|
add hl, hl
|
2015-12-28 14:09:53 -08:00
|
|
|
add hl, hl
|
|
|
|
add hl, hl
|
|
|
|
ld de, .distributions
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, de
|
|
|
|
ret
|
|
|
|
|
2015-12-28 14:09:53 -08:00
|
|
|
.distributions
|
2015-11-11 20:38:57 -08:00
|
|
|
db $02, $03, $06, $06, $06, $08, $08, $06
|
|
|
|
db $02, $02, $04, $06, $06, $08, $08, $09
|
|
|
|
db $02, $02, $02, $04, $07, $08, $08, $0c
|
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
MemoryGame_PlaceCard:
|
|
|
|
ld a, [wMemoryGameLastCardPicked]
|
2015-11-11 20:38:57 -08:00
|
|
|
sla a
|
|
|
|
sla a
|
2015-12-28 14:09:53 -08:00
|
|
|
add 4
|
2015-11-11 20:38:57 -08:00
|
|
|
ld [hli], a
|
|
|
|
inc a
|
|
|
|
ld [hld], a
|
|
|
|
inc a
|
|
|
|
ld bc, SCREEN_WIDTH
|
|
|
|
add hl, bc
|
|
|
|
ld [hli], a
|
|
|
|
inc a
|
|
|
|
ld [hl], a
|
|
|
|
ld c, 3
|
|
|
|
call DelayFrames
|
|
|
|
ret
|
2015-12-28 14:09:53 -08:00
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
MemoryGame_DeleteCard:
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, $1
|
|
|
|
ld [hli], a
|
|
|
|
ld [hld], a
|
|
|
|
ld bc, SCREEN_WIDTH
|
|
|
|
add hl, bc
|
|
|
|
ld [hli], a
|
|
|
|
ld [hl], a
|
|
|
|
ld c, 3
|
|
|
|
call DelayFrames
|
|
|
|
ret
|
2015-12-28 14:09:53 -08:00
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
MemoryGame_InitStrings:
|
2015-11-11 20:38:57 -08:00
|
|
|
hlcoord 0, 0
|
|
|
|
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
|
|
|
|
ld a, $1
|
|
|
|
call ByteFill
|
|
|
|
hlcoord 0, 0
|
2015-12-28 14:09:53 -08:00
|
|
|
ld de, .japstr1
|
2015-11-11 20:38:57 -08:00
|
|
|
call PlaceString
|
|
|
|
hlcoord 15, 0
|
2015-12-28 14:09:53 -08:00
|
|
|
ld de, .japstr2
|
2015-11-11 20:38:57 -08:00
|
|
|
call PlaceString
|
2015-12-28 14:09:53 -08:00
|
|
|
ld hl, .dummy_text
|
2023-08-11 03:28:14 -07:00
|
|
|
call PrintText1bpp
|
2015-11-11 20:38:57 -08:00
|
|
|
ret
|
|
|
|
|
2015-12-28 14:09:53 -08:00
|
|
|
.dummy_text
|
2015-11-11 20:38:57 -08:00
|
|
|
db "@"
|
2015-12-28 14:09:53 -08:00
|
|
|
.japstr1
|
2023-08-02 09:21:34 -07:00
|
|
|
db "?????@"
|
2015-12-28 14:09:53 -08:00
|
|
|
.japstr2
|
2023-08-02 09:21:34 -07:00
|
|
|
db "?? ??@"
|
2015-11-11 20:38:57 -08:00
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
MemoryGame_Card2Coord:
|
2015-12-28 14:09:53 -08:00
|
|
|
ld d, 0
|
|
|
|
.find_row
|
|
|
|
sub 9
|
|
|
|
jr c, .found_row
|
2015-11-11 20:38:57 -08:00
|
|
|
inc d
|
2015-12-28 14:09:53 -08:00
|
|
|
jr .find_row
|
2015-11-11 20:38:57 -08:00
|
|
|
|
2015-12-28 14:09:53 -08:00
|
|
|
.found_row
|
|
|
|
add 9
|
2015-11-11 20:38:57 -08:00
|
|
|
ld e, a
|
|
|
|
hlcoord 1, 2
|
2015-12-28 14:09:53 -08:00
|
|
|
ld bc, 2 * SCREEN_WIDTH
|
|
|
|
.loop2
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, d
|
|
|
|
and a
|
2015-12-28 14:09:53 -08:00
|
|
|
jr z, .done
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, bc
|
|
|
|
dec d
|
2015-12-28 14:09:53 -08:00
|
|
|
jr .loop2
|
2015-11-11 20:38:57 -08:00
|
|
|
|
2015-12-28 14:09:53 -08:00
|
|
|
.done
|
2015-11-11 20:38:57 -08:00
|
|
|
sla e
|
|
|
|
add hl, de
|
|
|
|
ret
|
2015-12-28 14:09:53 -08:00
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
MemoryGame_InterpretJoypad_AnimateCursor:
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, [wJumptableIndex]
|
|
|
|
cp $7
|
|
|
|
jr nc, .quit
|
|
|
|
call JoyTextDelay
|
2018-08-25 11:39:24 -07:00
|
|
|
ld hl, hJoypadPressed
|
2015-11-11 20:38:57 -08:00
|
|
|
ld a, [hl]
|
|
|
|
and A_BUTTON
|
|
|
|
jr nz, .pressed_a
|
|
|
|
ld a, [hl]
|
|
|
|
and D_LEFT
|
|
|
|
jr nz, .pressed_left
|
|
|
|
ld a, [hl]
|
|
|
|
and D_RIGHT
|
|
|
|
jr nz, .pressed_right
|
|
|
|
ld a, [hl]
|
|
|
|
and D_UP
|
|
|
|
jr nz, .pressed_up
|
|
|
|
ld a, [hl]
|
|
|
|
and D_DOWN
|
|
|
|
jr nz, .pressed_down
|
|
|
|
ret
|
|
|
|
|
|
|
|
.quit
|
2015-12-28 14:09:53 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_INDEX
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, bc
|
|
|
|
ld [hl], $0
|
|
|
|
ret
|
|
|
|
|
|
|
|
.pressed_a
|
2020-08-22 07:22:37 -07:00
|
|
|
ld hl, SPRITEANIMSTRUCT_VAR1
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
inc a
|
2020-11-08 16:32:57 -08:00
|
|
|
ld [wMemoryGameCardChoice], a
|
2015-11-11 20:38:57 -08:00
|
|
|
ret
|
|
|
|
|
|
|
|
.pressed_left
|
2015-12-28 14:09:53 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_XOFFSET
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
ret z
|
2015-12-28 14:09:53 -08:00
|
|
|
sub 1 tiles
|
2015-11-11 20:38:57 -08:00
|
|
|
ld [hl], a
|
2020-08-22 07:22:37 -07:00
|
|
|
ld hl, SPRITEANIMSTRUCT_VAR1
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, bc
|
|
|
|
dec [hl]
|
|
|
|
ret
|
|
|
|
|
|
|
|
.pressed_right
|
2015-12-28 14:09:53 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_XOFFSET
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-12-28 14:09:53 -08:00
|
|
|
cp (9 - 1) tiles
|
2015-11-11 20:38:57 -08:00
|
|
|
ret z
|
2015-12-28 14:09:53 -08:00
|
|
|
add 1 tiles
|
2015-11-11 20:38:57 -08:00
|
|
|
ld [hl], a
|
2020-08-22 07:22:37 -07:00
|
|
|
ld hl, SPRITEANIMSTRUCT_VAR1
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, bc
|
|
|
|
inc [hl]
|
|
|
|
ret
|
|
|
|
|
|
|
|
.pressed_up
|
2015-12-28 14:09:53 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_YOFFSET
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
ret z
|
2015-12-28 14:09:53 -08:00
|
|
|
sub 1 tiles
|
2015-11-11 20:38:57 -08:00
|
|
|
ld [hl], a
|
2020-08-22 07:22:37 -07:00
|
|
|
ld hl, SPRITEANIMSTRUCT_VAR1
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-12-28 14:09:53 -08:00
|
|
|
sub 9
|
2015-11-11 20:38:57 -08:00
|
|
|
ld [hl], a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.pressed_down
|
2015-12-28 14:09:53 -08:00
|
|
|
ld hl, SPRITEANIMSTRUCT_YOFFSET
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-12-28 14:09:53 -08:00
|
|
|
cp (5 - 1) tiles
|
2015-11-11 20:38:57 -08:00
|
|
|
ret z
|
2015-12-28 14:09:53 -08:00
|
|
|
add 1 tiles
|
2015-11-11 20:38:57 -08:00
|
|
|
ld [hl], a
|
2020-08-22 07:22:37 -07:00
|
|
|
ld hl, SPRITEANIMSTRUCT_VAR1
|
2015-11-11 20:38:57 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-12-28 14:09:53 -08:00
|
|
|
add 9
|
2015-11-11 20:38:57 -08:00
|
|
|
ld [hl], a
|
|
|
|
ret
|
2015-12-28 14:09:53 -08:00
|
|
|
|
2020-11-08 16:32:57 -08:00
|
|
|
MemoryGameLZ:
|
|
|
|
INCBIN "gfx/memory_game/memory_game.2bpp.lz"
|