/[projet1]/users/coco/origa/rout_keyboard.s
Defence Force logotype

Contents of /users/coco/origa/rout_keyboard.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 719 - (show annotations)
Fri Nov 4 21:49:17 2011 UTC (8 years, 6 months ago) by coco
File size: 6797 byte(s)


1
2 ; Example program for reading the Oric's
3 ; keyboard. All keys are scanned and a
4 ; virtual matrix of 8 bytes is updated at
5 ; each IRQ.
6 ;
7 ; Idea: Dbug
8 ; Main code: Twiligthe
9 ; Adaptation & final implementation: Chema
10 ; Modification 2011 by Didier (coco.oric) to include a time counter
11 ;
12 ; 2010
13
14
15 #define via_portb $0300
16 #define via_ddrb $0302
17 #define via_ddra $0303
18 #define via_t1cl $0304
19 #define via_t1ch $0305
20 #define via_t1ll $0306
21 #define via_t1lh $0307
22 #define via_t2ll $0308
23 #define via_t2ch $0309
24 #define via_sr $030A
25 #define via_acr $030b
26 #define via_pcr $030c
27 #define via_ifr $030D
28 #define via_ier $030E
29 #define via_porta $030f
30
31
32 .zero
33 irq_A .byt 0
34 irq_X .byt 0
35 irq_Y .byt 0
36 zpTemp01 .byt 0
37 zpTemp02 .byt 0
38 tmprow .byt 0
39 _tmptime .byt 0
40
41 .text
42
43 #define ROM
44
45 #ifdef ROM
46 #define IRQ_ADDRLO $0245
47 #define IRQ_ADDRHI $0246
48 #else
49 #define IRQ_ADDRLO $fffe
50 #define IRQ_ADDRHI $ffff
51 #endif
52
53
54 _InitISR
55 .(
56 ;Since we are starting from when the standard irq has already been
57 ;setup, we need not worry about ensuring one irq event and/or right
58 ;timer period, only redirecting irq vector to our own irq handler.
59 sei
60 ; Mise a zero du tmptime
61 lda #0
62 sta _tmptime
63
64 ; Setup DDRA, DDRB and ACR
65 lda #%11111111
66 sta via_ddra
67 lda #%11110111 ; PB0-2 outputs, PB3 input.
68 sta via_ddrb
69 lda #%1000000
70 sta via_acr
71
72 ; Since this is an slow process, we set the VIA timer to
73 ; issue interrupts at 25Hz, instead of 100 Hz. This is
74 ; not necessary -- it depends on your needs
75 lda #<40000
76 sta via_t1ll
77 lda #>40000
78 sta via_t1lh
79
80 ; Patch IRQ vector
81 lda #<irq_routine
82 sta IRQ_ADDRLO
83 lda #>irq_routine
84 sta IRQ_ADDRHI
85 cli
86 rts
87 .)
88
89
90 ; The virtual Key Matrix
91 _KeyBank .dsb 8
92
93 irq_routine
94 .(
95 ;Preserve registers
96 sta irq_A
97 stx irq_X
98 sty irq_Y
99
100 ;Clear IRQ event
101 lda via_t1cl
102
103 ;Process keyboard
104 jsr ReadKeyboard
105
106 ; incrémenter le compteur de temps
107 inc _tmptime
108
109 ;Restore Registers
110 lda irq_A
111 ldx irq_X
112 ldy irq_Y
113
114 ;End of IRQ
115 rti
116 .)
117
118
119
120 ReadKeyboard
121 .(
122 ;Write Column Register Number to PortA
123 lda #$0E
124 sta via_porta
125
126 ;Tell AY this is Register Number
127 lda #$FF
128 sta via_pcr
129
130 ; Clear CB2, as keeping it high hangs on some orics.
131 ; Pitty, as all this code could be run only once, otherwise
132 ldy #$dd
133 sty via_pcr
134
135 ldx #7
136
137 loop2 ;Clear relevant bank
138 lda #00
139 sta _KeyBank,x
140
141 ;Write 0 to Column Register
142
143 sta via_porta
144 lda #$fd
145 sta via_pcr
146 lda #$dd
147 sta via_pcr
148
149
150 lda via_portb
151 and #%11111000
152 stx zpTemp02
153 ora zpTemp02
154 sta via_portb
155
156
157 ;Wait 10 cycles for circuit to settle on new row
158 ;Use time to load inner loop counter and load Bit
159
160 ; CHEMA: Fabrice Broche uses 4 cycles (lda #8:inx) plus
161 ; the four cycles of the and absolute. That is 8 cycles.
162 ; So I guess that I could do the same here (ldy,lda)
163
164 ldy #$80
165 lda #8
166
167 ;Sense Row activity
168 and via_portb
169 beq skip2
170
171 ;Store Column
172 tya
173 loop1
174 eor #$FF
175
176 sta via_porta
177 lda #$fd
178 sta via_pcr
179 lda #$dd
180 sta via_pcr
181
182 lda via_portb
183 and #%11111000
184 stx zpTemp02
185 ora zpTemp02
186 sta via_portb
187
188
189 ;Use delay(10 cycles) for setting up bit in _KeyBank and loading Bit
190 tya
191 ora _KeyBank,x
192 sta zpTemp01
193 lda #8
194
195 ;Sense key activity
196 and via_portb
197 beq skip1
198
199 ;Store key
200 lda zpTemp01
201 sta _KeyBank,x
202
203 skip1 ;Proceed to next column
204 tya
205 lsr
206 tay
207 bcc loop1
208
209 skip2 ;Proceed to next row
210 dex
211 bpl loop2
212
213 rts
214 .)
215
216
217 ; Some more routines, not actualy needed, but quite useful
218 ; for reading a single key (get the first active bit in
219 ; the virtual matrix) and returning his ASCII value.
220 ; Should serve as an example about how to handle the keymap.
221 ; Both _ReadKey and _ReadKeyNoBounce can be used directly from
222 ; C, declared as:
223 ; extern char ReadKey()
224 ; extern char ReadKeyNoBounce()
225
226
227 ; Usually it is a good idea to keep 0 all the unused
228 ; entries, as it speeds up things. Z=1 means no key
229 ; pressed and there is no need to look in tables later on.
230
231 ; This keys don't have an ASCII code assigned, so we will
232 ; use consecutive values outside the usual alphanumeric
233 ; space.
234
235 #define KEY_UP 1
236 #define KEY_LEFT 2
237 #define KEY_DOWN 3
238 #define KEY_RIGHT 4
239
240 #define KEY_LCTRL 5
241 #define KET_RCTRL 6
242 #define KEY_LSHIFT 7
243 #define KEY_RSHIFT 8
244 #define KEY_FUNCT 9
245
246
247 ; This keys do have ASCII values, let's use them
248
249 #define KEY_RETURN $0d
250 #define KEY_ESC $1b
251 #define KEY_DEL $7f
252
253
254 tab_ascii
255 .asc "7","N","5","V",KET_RCTRL,"1","X","3"
256 .asc "J","T","R","F",0,KEY_ESC,"Q","D"
257 .asc "M","6","B","4",KEY_LCTRL,"Z","2","C"
258 .asc "K","9",59,"-",0,0,92,39
259 .asc " ",",",".",KEY_UP,KEY_LSHIFT,KEY_LEFT,KEY_DOWN,KEY_RIGHT
260 .asc "U","I","O","P",KEY_FUNCT,KEY_DEL,"]","["
261 .asc "Y","H","G","E",0,"A","S","W"
262 .asc "8","L","0","/",KEY_RSHIFT,KEY_RETURN,0,"="
263
264
265 ; Reads a key (single press, but repeating) and returns his ASCII value in reg X.
266 ; Z=1 if no keypress detected.
267 _ReadKey
268 .(
269 ldx #7
270 loop
271 lda _KeyBank,x
272 beq skip
273
274 ldy #$ff
275 loop2
276 iny
277 lsr
278 bcc loop2
279 txa
280 asl
281 asl
282 asl
283 sty tmprow
284 clc
285 adc tmprow
286 tax
287 lda tab_ascii,x
288 tax
289 rts
290 skip
291 dex
292 bpl loop
293
294 ldx #0
295 rts
296 .)
297
298 ; Read a single key, same as before but no repeating.
299
300 _oldKey .byt 0
301 _ReadKeyNoBounce
302 .(
303 jsr _ReadKey
304 cpx _oldKey
305 beq retz
306 stx _oldKey
307 rts
308 retz
309 ldx #0
310 rts
311 .)
312
313

  ViewVC Help
Powered by ViewVC 1.1.26