-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinterrupts.z80
111 lines (95 loc) · 1.83 KB
/
interrupts.z80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
INCLUDE "gbt_player/gbt_player.inc"
INCLUDE "Hardware.inc"
GLOBAL VBlank_Address
GLOBAL LCDC_Address
Section "RST 00",HOME[$00]
; This is called if an interrupt handler address is set to zero.
ret
Section "RST 08",HOME[$08]
; Jump to function in HL and return to caller of RST.
jp HL
Section "V-Blank ISR",HOME[$40]
jp VBlank
Section "Timer ISR",HOME[$50]
jp Timer
Section "LCDC ISR",HOME[$48]
jp LCDC
Section "Interrupt boilerplate",HOME
VBlank:
push AF
push BC
push DE
push HL
; Update music at V-blank
ld A, [music_playing]
cp $0
jr z, .after_gbt_update
call gbt_update
.after_gbt_update:
ld HL, VBlank_Address
jr interrupt_common
LCDC:
push AF
push BC
push DE
push HL
ld HL, LCDC_Address
jr interrupt_common
Timer:
push AF
push BC
push DE
push HL
ld HL, Timer_Address
jr interrupt_common
interrupt_common:
ld A, [HL+]
ld H, [HL]
ld L, A
; Call address at HL and return here
rst $08
pop HL
pop DE
pop BC
pop AF
reti
initialize_interrupts::
; Point all interrupt handlers to $00 so they do nothing.
; Disables interrupts, must be manually enabled again.
di
xor A
ld HL, VBlank_Address
ld [HL+], A
ld [HL], A
ld HL, LCDC_Address
ld [HL+], A
ld [HL], A
ld A, IEF_VBLANK
ld [rIE], A
ret
; BC = function pointer
set_vblank_interrupt::
ld HL, VBlank_Address
jr interrupt_setter_common
; BC = function pointer
set_lcdc_interrupt::
ld HL, LCDC_Address
jr interrupt_setter_common
; BC = funtion pointer
set_timer_interrupt::
ld HL, Timer_Address
jr interrupt_setter_common
interrupt_setter_common:
di
ld [HL], C
inc HL
ld [HL], B
ei
ret
Section "Interrupt handler addresses",BSS
VBlank_Address: DS 2
LCDC_Address: DS 2
Timer_Address: DS 2
; music_playing == 0, music not playing
; music_playing == 1, music is playing
music_playing:: DS 1