-
Notifications
You must be signed in to change notification settings - Fork 1
/
pause.asm
114 lines (99 loc) · 2.19 KB
/
pause.asm
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
112
113
114
;====
; Pause handler
;====
.define pause.ENABLED 1
;====
; Dependencies
;====
.ifndef utils.ram
.include "utils/ram.asm"
utils.ram.assertRamSlot
.endif
.ifndef utils.assert
.include "utils/assert.asm"
.endif
;====
; RAM
;
; Flag is set when the pause button has been pressed
;====
.ramsection "pause.ram.pauseFlag" slot utils.ram.SLOT
pause.ram.pauseFlag: db
.ends
;====
; Code
;====
;====
; Pause handler
;
; Toggles a flag in RAM which can be detected when appropriate
;====
.macro "pause.handler"
push af
ld a, (pause.ram.pauseFlag) ; read flag
xor 1 ; toggle flag
ld (pause.ram.pauseFlag), a ; store
pop af
retn
.endm
;====
; Pause handler sequence at ROM address $66. The SMS will jump to this location
; when the pause button is pressed
;====
.ifndef pause.DISABLE_HANDLER
.bank 0 slot 0
.orga $66
.section "pause.handler" force
pause.handler
.ends
.endif
;====
; Initialises the pause handler in RAM
;====
.macro "pause.init"
xor a
ld (pause.ram.pauseFlag), a
.endm
;====
; If pause activated, waits until pause button is pressed again before
; continuing
;====
.macro "pause.waitIfPaused"
-:
ld a, (pause.ram.pauseFlag) ; read pauseFlag
or a ; analyse flag
jp z, + ; jp if not paused
halt ; wait for an interrupt (pause, vBlank, hBlank)
jp - ; check again
+:
.endm
;====
; Check if the pause button has been pressed.
;
; @out f z flag will be reset if pause has been pressed, otherwise it will
; be set
;====
.macro "pause.checkPause"
ld a, (pause.ram.pauseFlag)
or a ; analyse a
.endm
;====
; Jumps to the given address if the pause button has been pressed
;
; @in address address to jump to
;====
.macro "pause.jpIfPaused" args address
utils.assert.label address "pause.asm \.: Invalid address argument"
pause.checkPause
jp nz, address
.endm
;====
; Calls the given address if the pause button has been pressed
;
; @in address address to call
;====
.macro "pause.callIfPaused" args address
utils.assert.label address "pause.asm \.: Invalid address argument"
pause.checkPause
call nz, address
.endm