gb-tarot/main.asm

162 lines
2.8 KiB
NASM

; FF80 CALL
; FF81 LOW
; FF82 HIGH
; FF83 RET
; pattern repeats for the first 16 bytes so we can have some call vectors for the scene system
DEF SCENE_SETUP EQU $FF81
DEF SCENE_UPDATE EQU SCENE_SETUP + 4 ; call then ret is 3+1 bytes
DEF SCENE_DRAW EQU SCENE_UPDATE + 4
DEF SCENE_TEARDOWN EQU SCENE_DRAW + 4
DEF INTERRUPT_LCD EQU $FF91
DEF rMYBTN EQU $FFA8
DEF rMYBTNP EQU rMYBTN + 1
INCLUDE "hardware.inc"
SECTION "Interrupts", ROM0[$0]
ds $48 - @, 0
call INTERRUPT_LCD - 1
ret
SECTION "Header", ROM0[$100]
jp EntryPoint
ds $150 - @, 0 ; Make room for the header
EntryPoint:
; Shut down audio circuitry
ld a, 0
ld [rNR52], a
ld a, [Instructions] ; get the value of a call instruction so we can shove it into our handles
ld hl, SCENE_SETUP - 1
ld [hl], a
ld hl, SCENE_UPDATE - 1
ld [hl], a
ld hl, SCENE_DRAW - 1
ld [hl], a
ld hl, SCENE_TEARDOWN - 1
ld [hl], a
ld hl, INTERRUPT_LCD - 1
ld [hl], a
ld a, [Instructions + 3] ; get the value of a ret instruction
ld hl, SCENE_SETUP + 2
ld [hl], a
ld hl, SCENE_UPDATE + 2
ld [hl], a
ld hl, SCENE_DRAW + 2
ld [hl], a
ld hl, SCENE_TEARDOWN + 2
ld [hl], a
ld hl, INTERRUPT_LCD + 2
ld [hl], a
; set up our scene vectors
ld hl, SCENE_SETUP
ld de, CardReadSetup
ld a, e
ld [hl+], a
ld a, d
ld [hl+], a
ld hl, SCENE_UPDATE
ld de, CardReadUpdate
ld a, e
ld [hl+], a
ld a, d
ld [hl+], a
ld hl, SCENE_DRAW
ld de, CardReadDraw
ld a, e
ld [hl+], a
ld a, d
ld [hl+], a
ld hl, SCENE_TEARDOWN
ld de, CardReadTeardown
ld a, e
ld [hl+], a
ld a, d
ld [hl+], a
; set up the interrupt vector to just be ret.
ld hl, INTERRUPT_LCD
ld de, INTERRUPT_LCD + 2
ld a, e
ld [hl+], a
ld a, d
ld [hl+], a
; Do not turn the LCD off outside of VBlank
WaitVBlank:
ld a, [rLY]
cp 144
jp c, WaitVBlank
call SCENE_SETUP - 1
Loop:
di
ld hl, rP1
ld [hl], P1F_GET_DPAD
ld a, [hl]
ld a, [hl]
ld a, [hl]
ld a, [hl]
cpl
and a, %00001111
ld b, a
ld [hl], P1F_GET_BTN
ld a, [hl]
ld a, [hl]
ld a, [hl]
ld a, [hl]
cpl
and a, %00001111
swap a
or a, b
ld b, a
ld a, [rMYBTN]
cpl
and a, b
ld [rMYBTNP], a
ld a, b
ld [rMYBTN], a
call SCENE_UPDATE - 1
ld b, 144
call AwaitLine
call SCENE_DRAW - 1
jp Loop
AwaitLine: ; put the line you want to reach in b
ld a, [rLY]
cp b
jp nz, AwaitLine
ret
PrintString: ; write ascii string which has been prefixed by its length.
ld b, [hl]
inc hl
PrintBChars: ;write ascii characters. will not respect newlines or anything like that
; hl should be the source of ascii text
; de should be the location in the tile map to start writing at
; b should be the length
ld a, [hli]
or a, %10000000
ld [de], a
inc de
dec b
jp nz, PrintBChars
ret
INCLUDE "CardReadScreen.inc"
Instructions:
call Instructions + 2
ret