-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlibInput.asm
171 lines (131 loc) · 3.78 KB
/
libInput.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
163
164
165
166
167
168
169
170
171
;===============================================================================
; Constants
; use joystick 2, change to CIAPRB for joystick 1
JoystickRegister = CIAPRA
GameportUpMask = %00000001
GameportDownMask = %00000010
GameportLeftMask = %00000100
GameportRightMask = %00001000
GameportFireMask = %00010000
GameportNoInputMask = %00011111
FireDelayMax = 30
;===============================================================================
; Variables
gameportLastFrame byte 0
gameportThisFrame byte 0
gameportDiff byte 0
fireDelay byte 0
fireBlip byte 1 ; reversed logic to match other input
keyboardScanByte
byte 0,0,0,0,0,0,0,0,0
;===============================================================================
; Macros/Subroutines
defm LIBINPUT_GETHELD ; (buttonMask)
lda gameportThisFrame
and #/1
endm ; test with bne on return
;===============================================================================
defm LIBINPUT_GETFIREPRESSED
lda #1
sta fireBlip ; clear Fire flag
; is fire held?
lda gameportThisFrame
and #GameportFireMask
bne @notheld
@held
; is this 1st frame?
lda gameportDiff
and #GameportFireMask
beq @notfirst
lda #0
sta fireBlip ; Fire
; reset delay
lda #FireDelayMax
sta fireDelay
@notfirst
; is the delay zero?
lda fireDelay
bne @notheld
lda #0
sta fireBlip ; Fire
; reset delay
lda #FireDelayMax
sta fireDelay
@notheld
lda fireBlip
endm ; test with bne on return
;===============================================================================
libInputUpdate
lda JoystickRegister
sta GameportThisFrame
eor GameportLastFrame
sta GameportDiff
lda FireDelay
beq lIUDelayZero
dec FireDelay
lIUDelayZero
lda GameportThisFrame
sta GameportLastFrame
rts
; ==============================================================================
defm LIBINPUT_DELAY_V ; no. of y loops
ldy #/1
@loopy
ldx #$FF
@loopx
dex
bne @loopx
dey
bne @loopy
endm
;=============================================================================
defm LIBINPUT_SCANKEYBRD_BIT ; Acc = Bit To scan, Y = Result
; Parameters /1 = ResultLocation
rol
sta $DC00
ldy $DC01
sty /1
endm
libInput_ScanKeyboardMatrix
ldy #0
lda #$FF
@ClearMatrix
sta keyboardScanByte,y
iny
cpy #9
bne @ClearMatrix
ldx #$FF
stx $DC02 ; Set Port A for Output
ldy #$00
sty $DC03 ; Set Port B for Input
sty $DC00 ; Key For Activity
cpx $DC01
beq @NoKeyboardActivity
; stx $DC00
; cpx $DC01
; bne @NoKeyboardActivity
clc
lda #%11111111
LIBINPUT_SCANKEYBRD_BIT keyboardScanByte
LIBINPUT_SCANKEYBRD_BIT keyboardScanByte + 1
LIBINPUT_SCANKEYBRD_BIT keyboardScanByte + 2
LIBINPUT_SCANKEYBRD_BIT keyboardScanByte + 3
LIBINPUT_SCANKEYBRD_BIT keyboardScanByte + 4
LIBINPUT_SCANKEYBRD_BIT keyboardScanByte + 5
LIBINPUT_SCANKEYBRD_BIT keyboardScanByte + 6
LIBINPUT_SCANKEYBRD_BIT keyboardScanByte + 7
lda #$FF
and keyboardScanByte
and keyboardScanByte + 1
and keyboardScanByte + 2
and keyboardScanByte + 3
and keyboardScanByte + 4
and keyboardScanByte + 5
and keyboardScanByte + 6
and keyboardScanByte + 7
sta keyboardScanByte + 8
; stx $DC00
; cpx $DC01
; bne @NoKeyboardActivity
@NoKeyboardActivity
rts