-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibInput.asm
139 lines (101 loc) · 3.74 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
;===============================================================================
; Constants
AKeyRow = %11111101
AKeyBit = %00000100
DKeyRow = %11111011
DKeyBit = %00000100
SKeyRow = %11111101
SKeyBit = %00100000
SpcKeyRow = %01111111
SpcKeyBit = %00010000
; use joystick 2, change to CIAPRB for joystick 1
JoystickRegister = CIAPRA
GameportUpMask = %00000001
GameportDownMask = %00000010
GameportLeftMask = %00000100
GameportRightMask = %00001000
GameportFireMask = %00010000
FireDelayMax = 10
;===============================================================================
; Variables
gameportLastFrame byte 0
gameportThisFrame byte 0
gameportDiff byte 0
fireDelay byte 0
fireBlip byte 1 ; reversed logic to match other input
;===============================================================================
; Macros/Subroutines
defm LIBINPUT_GETKEYPRESSED
; /1 = row (see https://dustlayer.com/c64-coding-tutorials/2013/5/24/episode-3-5-taking-command-of-the-ship-controls)
; /2 = bit/column
lda #%11111111 ; CIA#1 Port A needs to be set to output
sta $dc02
lda #%00000000 ; CIA#1 Port B needs to be set to input
sta $dc03
lda #/1 ; select row
sta CIAPRA ; by storing into $dc00
lda CIAPRB ; load current column information
ldx #0 ; CIA#1 Port A back to input
stx $dc02 ; for joystick
and #/2 ; isolate key Bit
endm ; test with beq on return
;===============================================================================
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 space held?
lda #%11111111 ; CIA#1 Port A needs to be set to output
sta $dc02
lda #%00000000 ; CIA#1 Port B needs to be set to input
sta $dc03
lda #SpcKeyRow ; select eigth row
sta CIAPRA ; by storing $0b into $dc00
lda CIAPRB ; load current column information
ldx #0
stx $dc02
and #SpcKeyBit ; isolate 'Space' key Bit
beq @held
; 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