Added some sample code to show how to access the bottom row of the keyboard while handling simultaneous key presses (so we can detect the four arrow keys, plus the space bar, simultaneously)
@@ -0,0 +1,16 @@ | ||
1 | + | |
2 | +// The values and order of these defines match the column register | |
3 | +// values in the keyboard matrix. | |
4 | +// | |
5 | +// If you want other values, then you need to modify the keyboard | |
6 | +// reading code. | |
7 | + | |
8 | +#define SPACE 1 | |
9 | +#define UNUSED_1 2 | |
10 | +#define UNUSED_2 4 | |
11 | +#define UP_ARROW 8 | |
12 | +#define LEFT_SHIFT 16 | |
13 | +#define LEFT_ARROW 32 | |
14 | +#define DOWN_ARROW 64 | |
15 | +#define RIGHT_ARROW 128 | |
16 | + |
@@ -0,0 +1,143 @@ | ||
1 | + | |
2 | +#include "defines.h" | |
3 | + | |
4 | +#define ROM | |
5 | + | |
6 | +#ifdef ROM | |
7 | +#define IRQ_ADDRLO $0245 | |
8 | +#define IRQ_ADDRHI $0246 | |
9 | +#else | |
10 | +#define IRQ_ADDRLO $fffe | |
11 | +#define IRQ_ADDRHI $ffff | |
12 | +#endif | |
13 | + | |
14 | +#define via_portb $0300 | |
15 | +#define via_ddrb $0302 | |
16 | +#define via_ddra $0303 | |
17 | +#define via_t1cl $0304 | |
18 | +#define via_t1ch $0305 | |
19 | +#define via_t1ll $0306 | |
20 | +#define via_t1lh $0307 | |
21 | +#define via_t2ll $0308 | |
22 | +#define via_t2ch $0309 | |
23 | +#define via_sr $030A | |
24 | +#define via_acr $030b | |
25 | +#define via_pcr $030c | |
26 | +#define via_ifr $030D | |
27 | +#define via_ier $030E | |
28 | +#define via_porta $030f | |
29 | + | |
30 | + .zero | |
31 | + | |
32 | +_gKey .dsb 1 | |
33 | + | |
34 | +irq_A .dsb 1 | |
35 | +irq_X .dsb 1 | |
36 | +irq_Y .dsb 1 | |
37 | + | |
38 | + .text | |
39 | + | |
40 | +_InitIRQ | |
41 | +.( | |
42 | + ;Since we are starting from when the standard irq has already been | |
43 | + ;setup, we need not worry about ensuring one irq event and/or right | |
44 | + ;timer period, only redirecting irq vector to our own irq handler. | |
45 | + sei | |
46 | + | |
47 | + ; Setup DDRA, DDRB and ACR | |
48 | + lda #%11111111 | |
49 | + sta via_ddra | |
50 | + lda #%11110111 ; PB0-2 outputs, PB3 input. | |
51 | + sta via_ddrb | |
52 | + lda #%1000000 | |
53 | + sta via_acr | |
54 | + | |
55 | + ; Since we have only IRQ handler for everything, it is generally | |
56 | + ; more useful to run at 50Hz, instead of 100 Hz. | |
57 | + lda #<20000 | |
58 | + sta via_t1ll | |
59 | + lda #>20000 | |
60 | + sta via_t1lh | |
61 | + | |
62 | + ; Patch IRQ vector | |
63 | + lda #<irq_routine | |
64 | + sta IRQ_ADDRLO | |
65 | + lda #>irq_routine | |
66 | + sta IRQ_ADDRHI | |
67 | + cli | |
68 | + rts | |
69 | +.) | |
70 | + | |
71 | + | |
72 | +irq_routine | |
73 | +.( | |
74 | + ;Preserve registers | |
75 | + sta irq_A | |
76 | + stx irq_X | |
77 | + sty irq_Y | |
78 | + | |
79 | + ;Clear IRQ event | |
80 | + lda via_t1cl | |
81 | + | |
82 | + ;Process keyboard | |
83 | + jsr ReadKeyboard | |
84 | + | |
85 | + ;Restore Registers | |
86 | + lda irq_A | |
87 | + ldx irq_X | |
88 | + ldy irq_Y | |
89 | + | |
90 | + ;End of IRQ | |
91 | + rti | |
92 | +.) | |
93 | + | |
94 | + | |
95 | +values_code .byt $df,$7f,$f7,$bf,$fe,$ef | |
96 | + | |
97 | +ReadKeyboard | |
98 | +.( | |
99 | + lda #00 | |
100 | + sta _gKey | |
101 | + | |
102 | + ; Select the bottom row of the keyboard | |
103 | + ldy #04 | |
104 | + sty via_portb | |
105 | + | |
106 | + ldx #5 | |
107 | +loop_read | |
108 | + | |
109 | + ; Write Column Register Number to PortA | |
110 | + ldy #$0e | |
111 | + sty via_porta | |
112 | + | |
113 | + ; Tell AY this is Register Number | |
114 | + ldy #$ff | |
115 | + sty via_pcr | |
116 | + | |
117 | + ; Clear CB2, as keeping it high hangs on some orics. | |
118 | + ; Pitty, as all this code could be run only once, otherwise | |
119 | + ldy #$dd | |
120 | + sty via_pcr | |
121 | + | |
122 | + ; Write to Column Register | |
123 | + lda values_code,x | |
124 | + sta via_porta | |
125 | + lda #$fd | |
126 | + sta via_pcr | |
127 | + sty via_pcr | |
128 | + | |
129 | + lda via_portb | |
130 | + and #08 | |
131 | + beq key_not_pressed | |
132 | + | |
133 | + lda values_code,x | |
134 | + eor #$ff | |
135 | + ora _gKey | |
136 | + sta _gKey | |
137 | + | |
138 | +key_not_pressed | |
139 | + dex | |
140 | + bpl loop_read | |
141 | + rts | |
142 | +.) | |
143 | + |
@@ -0,0 +1,52 @@ | ||
1 | +// -------------------------------------- | |
2 | +// Single Row Keyboard Read | |
3 | +// -------------------------------------- | |
4 | +// (c) 2010-2020 Defence Force | |
5 | +// Authors: Twilighte, Chema and Dbug | |
6 | +// -------------------------------------- | |
7 | +// This code is provided as-is: | |
8 | +// We do not assume any responsability concerning the fact this is a bug-free software !!! | |
9 | +// You can use this example code without any limitation, but if you do, it would be nice | |
10 | +// if you could mention the origin somewhere and inform us :) | |
11 | +// -------------------------------------- | |
12 | +// For more information, please contact us on internet: | |
13 | +// e-mail: mike@defence-force.org | |
14 | +// URL: http://www.defence-force.org | |
15 | +// -------------------------------------- | |
16 | +// Note: This text was typed with a Win32 editor. So perhaps the text will not be | |
17 | +// displayed correctly with other OS. | |
18 | + | |
19 | + | |
20 | +#include <stdio.h> | |
21 | + | |
22 | +#include "defines.h" | |
23 | + | |
24 | +// Initialization of ISR | |
25 | +extern void InitIRQ(); | |
26 | +extern unsigned char gKey; // One bit per key pressed | |
27 | + | |
28 | +void main() | |
29 | +{ | |
30 | + cls(); | |
31 | + printf("Single Row Keyboard Read demo program\n"); | |
32 | + printf("Left Arrow\n"); | |
33 | + printf("Right Arrow\n"); | |
34 | + printf("Up Arrow\n"); | |
35 | + printf("Down Arrow\n"); | |
36 | + printf("Space\n"); | |
37 | + printf("Left Shift\n"); | |
38 | + | |
39 | + InitIRQ(); | |
40 | + while (1) | |
41 | + { | |
42 | + poke(0xbb80+40*2,(gKey & LEFT_ARROW)?16+1:16+2); | |
43 | + poke(0xbb80+40*3,(gKey & RIGHT_ARROW)?16+1:16+2); | |
44 | + poke(0xbb80+40*4,(gKey & UP_ARROW)?16+1:16+2); | |
45 | + poke(0xbb80+40*5,(gKey & DOWN_ARROW)?16+1:16+2); | |
46 | + poke(0xbb80+40*6,(gKey & SPACE)?16+1:16+2); | |
47 | + poke(0xbb80+40*7,(gKey & LEFT_SHIFT)?16+1:16+2); | |
48 | + | |
49 | + sprintf((char *)(0xbb80+40*8),"%c gKey=%u ",16+4,gKey); | |
50 | + } | |
51 | +} | |
52 | + |
@@ -0,0 +1,35 @@ | ||
1 | +@ECHO OFF | |
2 | + | |
3 | + | |
4 | +:: | |
5 | +:: Initial check. | |
6 | +:: Verify if the SDK is correctly configurated | |
7 | +:: | |
8 | +IF "%OSDK%"=="" GOTO ErCfg | |
9 | + | |
10 | + | |
11 | +:: | |
12 | +:: Set the build paremeters | |
13 | +:: | |
14 | +CALL osdk_config.bat | |
15 | + | |
16 | + | |
17 | +:: | |
18 | +:: Launch the compilation of files | |
19 | +:: | |
20 | +CALL %OSDK%\bin\make.bat %OSDKFILE% | |
21 | +GOTO End | |
22 | + | |
23 | + | |
24 | +:: | |
25 | +:: Outputs an error message | |
26 | +:: | |
27 | +:ErCfg | |
28 | +ECHO == ERROR == | |
29 | +ECHO The Oric SDK was not configured properly | |
30 | +ECHO You should have a OSDK environment variable setted to the location of the SDK | |
31 | +GOTO End | |
32 | + | |
33 | + | |
34 | +:End | |
35 | +pause | |
\ No newline at end of file |
@@ -0,0 +1,9 @@ | ||
1 | +@ECHO OFF | |
2 | + | |
3 | +:: | |
4 | +:: Set the build paremeters | |
5 | +:: | |
6 | +SET OSDKADDR=$600 | |
7 | +SET OSDKNAME=KEYBOARD | |
8 | +SET OSDKFILE=main keyboard | |
9 | + |
@@ -0,0 +1,34 @@ | ||
1 | +@ECHO OFF | |
2 | + | |
3 | + | |
4 | +:: | |
5 | +:: Initial check. | |
6 | +:: Verify if the SDK is correctly configurated, | |
7 | +:: | |
8 | +IF "%OSDK%"=="" GOTO ErCfg | |
9 | + | |
10 | +:: | |
11 | +:: Set the build paremeters | |
12 | +:: | |
13 | +CALL osdk_config.bat | |
14 | + | |
15 | + | |
16 | +:: | |
17 | +:: Run Euphoric using the common batch | |
18 | +:: | |
19 | +CALL %OSDK%\bin\execute.bat | |
20 | +GOTO End | |
21 | + | |
22 | + | |
23 | +:: | |
24 | +:: Outputs an error message about configuration | |
25 | +:: | |
26 | +:ErCfg | |
27 | +ECHO == ERROR == | |
28 | +ECHO The Oric SDK was not configured properly | |
29 | +ECHO You should have a OSDK environment variable setted to the location of the SDK | |
30 | +ECHO =========== | |
31 | +IF "%OSDKBRIEF%"=="" PAUSE | |
32 | +GOTO End | |
33 | + | |
34 | +:End |