2023-10-13 06:37:55 +00:00
|
|
|
IF !DEF(INTERRUPTS_ASM)
|
|
|
|
DEF INTERRUPTS_ASM EQU 1
|
|
|
|
|
|
|
|
|
2023-10-16 05:47:11 +00:00
|
|
|
INCLUDE "globals.asm"
|
|
|
|
|
|
|
|
|
2023-10-13 09:20:28 +00:00
|
|
|
SECTION "Interrupt Variables", HRAM
|
|
|
|
hLCDCCtr:: ds 1
|
|
|
|
|
|
|
|
|
2023-10-10 08:32:24 +00:00
|
|
|
SECTION "Interrupt Initialization Functions", ROM0
|
2023-10-13 09:20:28 +00:00
|
|
|
IntrInit::
|
|
|
|
xor a, a
|
|
|
|
ldh [hLCDCCtr], a
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
2023-10-10 08:32:24 +00:00
|
|
|
InitializeLCDCInterrupt::
|
|
|
|
ld a, STATF_LYC
|
|
|
|
ldh [rSTAT], a
|
|
|
|
ld a, 6
|
|
|
|
ldh [rLYC], a
|
|
|
|
ld a, 0
|
|
|
|
ldh [rSCY], a
|
|
|
|
ld a, IEF_STAT
|
|
|
|
ldh [rIE], a
|
|
|
|
xor a, a
|
|
|
|
ldh [rIF], a
|
|
|
|
ei
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
2023-10-13 09:20:28 +00:00
|
|
|
SECTION "LCDC Interrupt", ROM0[INT_HANDLER_STAT]
|
2023-10-10 08:32:24 +00:00
|
|
|
LCDCInterrupt:
|
|
|
|
push af
|
|
|
|
push hl
|
|
|
|
|
|
|
|
ld hl, rSTAT
|
|
|
|
LCDCInterrupt_WaitUntilNotBusy:
|
|
|
|
bit STATB_BUSY, [hl]
|
|
|
|
jr nz, LCDCInterrupt_WaitUntilNotBusy
|
|
|
|
|
|
|
|
; Increment SCY
|
|
|
|
ldh a, [rSCY]
|
|
|
|
inc a
|
|
|
|
ldh [rSCY], a
|
|
|
|
|
|
|
|
; Increment LYC by 7
|
|
|
|
ldh a, [rLYC]
|
|
|
|
add a, 7
|
|
|
|
ldh [rLYC], a
|
|
|
|
|
|
|
|
; Check our interrupt counter
|
2023-10-13 09:20:28 +00:00
|
|
|
ldh a, [hLCDCCtr]
|
2023-10-10 08:32:24 +00:00
|
|
|
cp 21
|
2023-10-13 09:26:40 +00:00
|
|
|
jr nz, LCDCInterrupt_End
|
2023-10-10 08:32:24 +00:00
|
|
|
ld a, 255
|
2023-10-13 09:20:28 +00:00
|
|
|
ldh [hLCDCCtr], a
|
2023-10-10 08:32:24 +00:00
|
|
|
ld a, 6
|
|
|
|
ldh [rLYC], a
|
|
|
|
ld a, 0
|
|
|
|
ldh [rSCY], a
|
|
|
|
|
|
|
|
LCDCInterrupt_End:
|
|
|
|
inc a
|
2023-10-13 09:20:28 +00:00
|
|
|
ldh [hLCDCCtr], a
|
2023-10-10 08:32:24 +00:00
|
|
|
pop hl
|
|
|
|
pop af
|
|
|
|
reti
|
|
|
|
|
2023-10-13 06:37:55 +00:00
|
|
|
|
|
|
|
ENDC
|