-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmacros.asm
162 lines (150 loc) · 3.97 KB
/
macros.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
.MACRO setdmapos _x,_y
.LOCAL _scnadd
_scnadd = SCREEN+(_y*$20)+_x
lda #>_scnadd
sta $2006
lda #<_scnadd
sta $2006
.ENDMACRO
;------------------------------------------------------------------------------
; Reset stub goes at end of every PRG bank
;------------------------------------------------------------------------------
.MACRO resetStub
.word 0,0,0, NMI, RESET, IRQ
;lda #$80
;sta $8000
;jmp RESET
;dw NMI,$FFF2,IRQ
.ENDMACRO
;------------------------------------------------------------------------------
; Print an "empty" cell i.e. "--"
;------------------------------------------------------------------------------
.MACRO printEmptyCell
lda #CHR_EMPTY
sta windowBuffer,x
inx
sta windowBuffer,x
inx
.ENDMACRO
;------------------------------------------------------------------------------
; Update Sprite Cursor based on current editor X/Y position
;------------------------------------------------------------------------------
.MACRO updateCursor _cursorX,_cursorY,_cursorColumns,_cursorRows,_cursorType
lda _cursorX
tax
lda _cursorColumns,x
sta tmp0
sta SPR00_X ;update sprite position
ldy #$01
lda _cursorType,x
bne @b
lda #$FF
sta SPR00_CHAR
sta SPR01_CHAR
bne @a
@b: tax
sty SPR00_CHAR
iny
iny
sty SPR01_CHAR
lda tmp0
clc
adc cursorTypeOffsetX0,x
sta SPR00_X
lda tmp0
clc
adc cursorTypeOffsetX1,x
sta SPR01_X
lda _cursorY
tax
lda _cursorRows,x
sec
sbc #$01
sta SPR00_Y
sta SPR01_Y
@a:
.ENDMACRO
;------------------------------------------------------------------------------
; Process hold and double tap for any button
;------------------------------------------------------------------------------
.MACRO checkHoldTapAndDoubleTap _button,_buttonOld,_hold,_holdCounter,_tap,_doubleTap,_tapCounter
lda #$00 ;clear button status
sta _doubleTap
sta _tap
;sta _hold
lda _button ;is it pressed?
bne @a
lda #$00 ;no, clear hold counter
sta _holdCounter
lda _hold
beq @d
dec _hold
bne @d
; lda _holdCounter
; beq @d
; dec _holdCounter
@d: lda _buttonOld ;pressed last frame too?
beq @a
lda _hold
bne @c0
lda _tapCounter ;no, has been released. In time for double?
beq @c
inc _doubleTap ;yes, set double tap flag
lda #$00 ;clear up some flags
sta _tapCounter
sta _buttonOld
beq @b ;exit
@c: inc _tap ;not double tap set single tap flag
lda #KEYS_DOUBLE_TAP_SPEED ;and double tap catch counter
sta _tapCounter
@c0: lda #$00 ;clear/set old button
@a: sta _buttonOld ;jump here if button pressed
clc
adc _holdCounter ;increment hold counter
cmp #KEYS_REPEAT_DELAY
bcs @holdMax ;reached limit at which key is determined held?
sta _holdCounter ;no, update hold count
bcc @skipMax
@holdMax: ;inc _hold ;yes, set hold flag
lda #$02
sta _hold
@skipMax: ;lda _hold
;beq @e
;lda #$00
;sta _tapCounter
@e: lda _tapCounter ;update tap (release) counter
beq @b
dec _tapCounter
bne @b
;inc _tap
@b: rts
.ENDMACRO
;------------------------------------------------------------------------------
; Process hold and double tapp for any button
;------------------------------------------------------------------------------
.MACRO checkKeyHoldAndDoubleTap button, debounced, doubleTap, tapCounter, hold, holdCounter
lda #$00 ;clear hold and tap flags every refresh
sta doubleTap
sta hold
lda button ;B held down?
bne @a
sta holdCounter ;no, clear hold counter (A=0)
beq @doTap ;nothing to do
@a: lda holdCounter ;has hold counter reached threshold?
cmp #KEYS_HOLD_TIME
bcs @b ;yes
inc holdCounter ;no, increment hold counter
bne @doTap ;nothing else to do yet
@b: inc hold ;hold threshold reached, set hold flag
@doTap: lda debounced ;button B tapped?
beq @d ;no
lda tapCounter ;yes, still counting from last tap?
beq @e ;no
inc doubleTap ;yes, so this is double tap, set flag
@e: lda #KEYS_DOUBLE_TAP_SPEED ;set
sta tapCounter
@d: lda tapCounter
beq @f
dec tapCounter
@f rts
.ENDMACRO