• R/O
  • SSH
  • HTTPS

oricsdk: Commit


Commit MetaInfo

Revision1554 (tree)
Time2021-01-04 03:08:03
Authordbug

Log Message

New OSDK Sample code to test the various joystick interfaces.
Natively supports IJK, PASE, Telestrat, OPEL, and partially Dk'Tronics (need more work)
Requires OSDK 1.18 or later

Change Summary

Incremental Difference

--- public/pc/tools/osdk/main/Osdk/_final_/sample/c/joystick/main.c (nonexistent)
+++ public/pc/tools/osdk/main/Osdk/_final_/sample/c/joystick/main.c (revision 1554)
@@ -0,0 +1,160 @@
1+//
2+// This programs shows how to use the various joystick interfaces
3+//
4+// This is a complete for the OSDK article and Oriclopedia video:
5+// - https://osdk.org/index.php?page=articles&ref=ART17
6+// - https://www.youtube.com/watch?v=_xfpVoIJbSw
7+//
8+#include <lib.h>
9+
10+
11+char FlipFlop=1;
12+
13+void NewHandler()
14+{
15+ SAVE_COMPILER_REGISTERS;
16+
17+ FlipFlop=-FlipFlop;
18+ if (FlipFlop)
19+ {
20+ if (OsdkJoystickType==JOYSTICK_INTERFACE_NOTHING)
21+ {
22+ // Pretend we are a joystick by converting keyboard key codes
23+ OsdkJoystick_0=0;
24+ OsdkJoystick_1=0;
25+
26+ // The system keyboard handler only support one key press at a time,
27+ // but custom keyboard handler can handle multiple key presses, so this
28+ // is a viable option.
29+ //
30+ // See: https://osdk.org/index.php?page=articles&ref=ART16#title8
31+ //
32+ switch (peek(0x208))
33+ {
34+ case 172:
35+ OsdkJoystick_0 |= JOYSTICK_LEFT;
36+ break;
37+ case 180:
38+ OsdkJoystick_0 |= JOYSTICK_DOWN;
39+ break;
40+ case 132:
41+ OsdkJoystick_0 |= JOYSTICK_FIRE;
42+ break;
43+ case 156:
44+ OsdkJoystick_0 |= JOYSTICK_UP;
45+ break;
46+ case 188:
47+ OsdkJoystick_0 |= JOYSTICK_RIGHT;
48+ break;
49+ }
50+ }
51+ else
52+ {
53+ // Read the joystick interface
54+ joystick_read();
55+ }
56+ }
57+
58+ RESTORE_COMPILER_REGISTER;
59+}
60+
61+
62+
63+char* GetInterfaceName(unsigned char interfaceName)
64+{
65+ switch (interfaceName)
66+ {
67+ case JOYSTICK_INTERFACE_NOTHING: return "Arrows + Space bar";
68+ case JOYSTICK_INTERFACE_IJK: return "IJK/Stingy/Egoist";
69+ case JOYSTICK_INTERFACE_PASE: return "PASE/Altai/Mageco";
70+ case JOYSTICK_INTERFACE_TELESTRAT: return "Telestrat/Twilighte";
71+ case JOYSTICK_INTERFACE_OPEL: return "OPEL";
72+ case JOYSTICK_INTERFACE_DKTRONICS: return "Dk'Tronics";
73+ default: return "<Unknown>";
74+ }
75+}
76+
77+
78+void PrintInterfaces()
79+{
80+ int interface;
81+
82+ for (interface=0;interface<_JOYSTICK_INTERFACE_COUNT_;interface++)
83+ {
84+ sprintf((char*)(0xbb80+40*(3+interface)),"%c%c- #%d: %s ",16+6,(interface==OsdkJoystickType)?1:4,interface+1,GetInterfaceName(interface));
85+ }
86+}
87+
88+void PrintDirections(char* screen,unsigned char mask,char* label)
89+{
90+ sprintf(screen+40*0,"%c%s",3,label);
91+
92+ sprintf(screen+40*2+2,"%cLeft %c",(mask & JOYSTICK_LEFT)?16+1:16+2,16+4);
93+ sprintf(screen+40*3+2,"%cRight %c",(mask & JOYSTICK_RIGHT)?16+1:16+2,16+4);
94+ sprintf(screen+40*4+2,"%cUp %c",(mask & JOYSTICK_UP)?16+1:16+2,16+4);
95+ sprintf(screen+40*5+2,"%cDown %c",(mask & JOYSTICK_DOWN)?16+1:16+2,16+4);
96+ sprintf(screen+40*6+2,"%cFire %c",(mask & JOYSTICK_FIRE)?16+1:16+2,16+4);
97+ sprintf(screen+40*7+2,"%cValue%c%c%d%c ",16+3,7,16+4,mask,0);
98+}
99+
100+void main()
101+{
102+ setflags(SCREEN); // So we don't get the blinking cursor frozen after we disabled the IRQ
103+
104+ paper(4);
105+ ink(0);
106+ cls();
107+ sprintf((char*)(0xbb80),"%c%c OSDK Joystick Interface Test 1.2%c ",16+3,1,3);
108+ sprintf((char*)(0xbb80+40*2),"%c%cUse 1/2/3/4/5/6 to select",16+6,4);
109+
110+ OsdkJoystickType=JOYSTICK_INTERFACE_IJK;
111+
112+ chain_irq_handler(NewHandler);
113+ while (1)
114+ {
115+ char k;
116+ char v;
117+ PrintInterfaces();
118+
119+ k=key();
120+ switch (k)
121+ {
122+ case '1':
123+ case '!':
124+ OsdkJoystickType=JOYSTICK_INTERFACE_NOTHING;
125+ break;
126+
127+ case '2':
128+ case '@':
129+ OsdkJoystickType=JOYSTICK_INTERFACE_IJK;
130+ break;
131+
132+ case '3':
133+ case '#':
134+ OsdkJoystickType=JOYSTICK_INTERFACE_PASE;
135+ break;
136+
137+ case '4':
138+ case '$':
139+ OsdkJoystickType=JOYSTICK_INTERFACE_TELESTRAT;
140+ break;
141+
142+ case '5':
143+ case '%':
144+ OsdkJoystickType=JOYSTICK_INTERFACE_OPEL;
145+ break;
146+
147+ case '6':
148+ case '^':
149+ OsdkJoystickType=JOYSTICK_INTERFACE_DKTRONICS;
150+ break;
151+ }
152+
153+ joystick_type_select(OsdkJoystickType);
154+
155+ PrintDirections((char*)(0xbb80+40*10+4),OsdkJoystick_0,"Left Port");
156+ PrintDirections((char*)(0xbb80+40*10+4+20),OsdkJoystick_1,"Right Port");
157+ }
158+ uninstall_irq_handler();
159+}
160+
--- public/pc/tools/osdk/main/Osdk/_final_/sample/c/joystick/osdk_build.bat (nonexistent)
+++ public/pc/tools/osdk/main/Osdk/_final_/sample/c/joystick/osdk_build.bat (revision 1554)
@@ -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+IF "%OSDKBRIEF%"=="" PAUSE
32+GOTO End
33+
34+
35+:End
--- public/pc/tools/osdk/main/Osdk/_final_/sample/c/joystick/osdk_config.bat (nonexistent)
+++ public/pc/tools/osdk/main/Osdk/_final_/sample/c/joystick/osdk_config.bat (revision 1554)
@@ -0,0 +1,8 @@
1+@ECHO OFF
2+
3+::
4+:: Set the build paremeters
5+::
6+SET OSDKADDR=$500
7+SET OSDKNAME=OsdkJoyTest
8+SET OSDKFILE=main
--- public/pc/tools/osdk/main/Osdk/_final_/sample/c/joystick/osdk_execute.bat (nonexistent)
+++ public/pc/tools/osdk/main/Osdk/_final_/sample/c/joystick/osdk_execute.bat (revision 1554)
@@ -0,0 +1,31 @@
1+@ECHO OFF
2+
3+::
4+:: Initial check.
5+:: Verify if the SDK is correctly configurated,
6+::
7+IF "%OSDK%"=="" GOTO ErCfg
8+
9+::
10+:: Set the build paremeters
11+::
12+CALL osdk_config.bat
13+
14+::
15+:: Run the emulator using the common batch
16+::
17+CALL %OSDK%\bin\execute.bat
18+GOTO End
19+
20+::
21+:: Outputs an error message about configuration
22+::
23+:ErCfg
24+ECHO == ERROR ==
25+ECHO The Oric SDK was not configured properly
26+ECHO You should have a OSDK environment variable setted to the location of the SDK
27+ECHO ===========
28+IF "%OSDKBRIEF%"=="" PAUSE
29+GOTO End
30+
31+:End
Show on old repository browser