dmgtris/src/interrupts.asm

93 lines
2.0 KiB
NASM
Raw Normal View History

2023-10-21 15:28:38 +00:00
; DMGTRIS
; Copyright (C) 2023 - Randy Thiemann <randy.thiemann@gmail.com>
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <https://www.gnu.org/licenses/>.
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-11-01 19:04:54 +00:00
DEF INIT_SCY EQU 3
DEF INIT_LYC EQU 3
2023-10-21 18:49:52 +00:00
SECTION "High Interrupt Variables", HRAM
2023-10-13 09:20:28 +00:00
hLCDCCtr:: ds 1
2023-10-10 08:32:24 +00:00
SECTION "Interrupt Initialization Functions", ROM0
2023-10-27 19:37:32 +00:00
; Zeroes out the interrupt counter.
2023-10-13 09:20:28 +00:00
IntrInit::
xor a, a
ldh [hLCDCCtr], a
ret
2023-10-27 19:37:32 +00:00
; Sets up the STAT interrupt.
2023-10-10 08:32:24 +00:00
InitializeLCDCInterrupt::
ld a, STATF_LYC
ldh [rSTAT], a
2023-11-01 19:04:54 +00:00
ld a, INIT_LYC
2023-10-10 08:32:24 +00:00
ldh [rLYC], a
2023-11-01 19:04:54 +00:00
ld a, INIT_SCY
2023-10-10 08:32:24 +00:00
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-27 19:37:32 +00:00
; This interrupt handler will be called every 7 scanlines, scrolling up the tile map by 1 line. This has the
; effect of making the tiles appear as 8x7 pixels, and making 20 rows fit on the screen.
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-11-01 19:04:54 +00:00
cp a, 144
jr c, LCDCInterrupt_End
ld a, INIT_LYC
2023-10-10 08:32:24 +00:00
ldh [rLYC], a
2023-11-01 19:04:54 +00:00
ld a, INIT_SCY
2023-10-10 08:32:24 +00:00
ldh [rSCY], a
LCDCInterrupt_End:
pop hl
pop af
reti
2023-10-13 06:37:55 +00:00
ENDC