ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
coleco.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2026 Marco Spedaletti (asimov@mclink.it)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *----------------------------------------------------------------------------
18 * Concesso in licenza secondo i termini della Licenza Apache, versione 2.0
19 * (la "Licenza"); è proibito usare questo file se non in conformità alla
20 * Licenza. Una copia della Licenza è disponibile all'indirizzo:
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Se non richiesto dalla legislazione vigente o concordato per iscritto,
25 * il software distribuito nei termini della Licenza è distribuito
26 * "COSì COM'è", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o
27 * implicite. Consultare la Licenza per il testo specifico che regola le
28 * autorizzazioni e le limitazioni previste dalla medesima.
29 ****************************************************************************/
30
31/****************************************************************************
32 * INCLUDE SECTION
33 ****************************************************************************/
34
35#include "../ugbc.h"
36#include <math.h>
37
38static RGBi SYSTEM_PALETTE[] = {
39 { 0x00, 0x00, 0x00, 0xff, 0, "BLACK" },
40 { 0x00, 0x00, 0xff, 0xff, 1, "BLUE" },
41 { 0x88, 0x00, 0x00, 0xff, 2, "RED" },
42 { 0xff, 0x00, 0xff, 0xff, 3, "MAGENTA" },
43 { 0x00, 0xcc, 0x00, 0xff, 4, "GREEN" },
44 { 0xaa, 0xff, 0xe6, 0xff, 5, "CYAN" },
45 { 0xee, 0xee, 0x77, 0xff, 6, "YELLOW" },
46 { 0xff, 0xff, 0xff, 0xff, 7, "WHITE" }
47};
48
49/****************************************************************************
50 * CODE SECTION
51 ****************************************************************************/
52
53#ifdef __coleco__
54
55void coleco_inkey( Environment * _environment, char * _pressed, char * _key ) {
56
58
59 deploy( scancode, src_hw_coleco_scancode_asm );
60
61 outline0("LD A, 0");
62 outline1("LD (%s), A", _pressed );
63 outline1("LD (%s), A", _key );
64 outline0("CALL SCANCODE");
65 outline0("CP 0");
66 outline1("JR Z, %snokey", label );
67 outline1("LD (%s), a", _key );
68 outline0("LD A, $FF");
69 outline1("LD (%s), A", _pressed );
70 outhead1("%snokey:", label );
71
72}
73
74void coleco_wait_key_or_fire( Environment * _environment, int _port, int _release ) {
75
76 coleco_wait_fire( _environment, _port, _release );
77
78}
79
80void coleco_wait_key_or_fire_semivar( Environment * _environment, char * _port, int _release ) {
81
82 coleco_wait_fire_semivar( _environment, _port, _release );
83
84}
85
86void coleco_wait_fire( Environment * _environment, int _port, int _release ) {
87
88 _environment->bitmaskNeeded = 1;
89
90 deploy( joystick, src_hw_coleco_joystick_asm );
91
92 switch( _port ) {
93 case -1:
94 outline0("CALL WAITFIRE");
95 break;
96 case 0:
97 outline0("CALL WAITFIRE0");
98 break;
99 case 1:
100 outline0("CALL WAITFIRE1");
101 break;
102 }
103
104}
105
106void coleco_wait_fire_semivar( Environment * _environment, char * _port, int _release ) {
107
108 _environment->bitmaskNeeded = 1;
109
110 deploy( joystick, src_hw_coleco_joystick_asm );
111
112 if ( ! _port ) {
113 outline0("CALL WAITFIRE");
114 } else {
115 outline1("LD A, (%s)", _port );
116 outline0("CALL WAITFIREA");
117 }
118
119}
120
121void coleco_scancode( Environment * _environment, char * _pressed, char * _scancode ) {
122
124
125 deploy( scancode, src_hw_coleco_scancode_asm );
126
127 outline0("LD A, 0");
128 outline1("LD (%s), A", _scancode );
129 outline1("LD (%s), A", _pressed );
130 outline0("CALL SCANCODE");
131 outline0("CP 0");
132 outline1("JR Z,%snokey", label);
133 outline1("LD (%s), A", _scancode );
134 outline0("LD A, $FF");
135 outline1("LD (%s), A", _pressed );
136 outhead1("%snokey:", label );
137
138}
139
140void coleco_key_pressed( Environment * _environment, char *_scancode, char * _result ) {
141
143
144 char nokeyLabel[MAX_TEMPORARY_STORAGE];
145 sprintf( nokeyLabel, "%slabel", label );
146
147 Variable * temp = variable_temporary( _environment, VT_BYTE, "(pressed)" );
148
149 coleco_scancode( _environment, temp->realName, _result );
150 cpu_compare_8bit( _environment, _result, _scancode, temp->realName, 1 );
151 cpu_compare_and_branch_8bit_const( _environment, temp->realName, 0, nokeyLabel, 1 );
152 cpu_store_8bit( _environment, _result, 0xff );
153 cpu_jump( _environment, label );
154 cpu_label( _environment, nokeyLabel );
155 cpu_store_8bit( _environment, _result, 0x00 );
156 cpu_label( _environment, label );
157
158}
159
160void coleco_scanshift( Environment * _environment, char * _shifts ) {
161
162 outline0("LD A, ($FBEB)");
163 outline1("LD (%s), A", _shifts );
164
165}
166
167void coleco_keyshift( Environment * _environment, char * _shifts ) {
168
169 outline0("LD A, ($FBEB)");
170 outline1("LD (%s), A", _shifts );
171
172}
173
174void coleco_clear_key( Environment * _environment ) {
175
176}
177
178void coleco_joy_vars( Environment * _environment, char * _port, char * _value ) {
179
180 deploy( joystick, src_hw_coleco_joystick_asm );
181
183
184 outline1("LD A, (%s)", _port);
185 outline0("CP 0");
186 outline1("JR NZ, %spt1", label );
187 if ( _environment->joystickConfig.sync ) {
188 outline0("CALL JOYSTICKREAD0" );
189 } else {
190 outline0("LD A, (JOYSTICK0)" );
191 }
192 if ( _environment->joystickConfig.values ) {
193 outline0("CALL JOYSTICKTSB" );
194 }
195 outline1("LD (%s), A", _value);
196 outline1("JR %sptx", label );
197 outhead1("%spt1:", label);
198 if ( _environment->joystickConfig.sync ) {
199 outline0("CALL JOYSTICKREAD1" );
200 } else {
201 outline0("LD A, (JOYSTICK1)" );
202 }
203 if ( _environment->joystickConfig.values ) {
204 outline0("CALL JOYSTICKTSB" );
205 }
206 outline1("LD (%s), A", _value);
207 outline1("JR %sptx", label );
208 outhead1("%sptx:", label);
209
210}
211
212void coleco_joy( Environment * _environment, int _port, char * _value ) {
213
214 deploy( joystick, src_hw_coleco_joystick_asm );
215
216 switch ( _port ) {
217 case 0:
218 if ( _environment->joystickConfig.sync ) {
219 outline0("CALL JOYSTICKREAD0" );
220 } else {
221 outline0("LD A, (JOYSTICK0)" );
222 }
223 break;
224 case 1:
225 if ( _environment->joystickConfig.sync ) {
226 outline0("CALL JOYSTICKREAD1" );
227 } else {
228 outline0("LD A, (JOYSTICK1)" );
229 }
230 break;
231 }
232 if ( _environment->joystickConfig.values ) {
233 outline0("CALL JOYSTICKTSB" );
234 }
235 outline1("LD (%s), A", _value);
236
237}
238
239void coleco_sys_call( Environment * _environment, int _destination ) {
240
241 outline1("CALL $%4.4x", _destination );
242
243}
244
245void coleco_timer_set_status_on( Environment * _environment, char * _timer ) {
246
247 deploy( timer, src_hw_z80_timer_asm);
248
249 if ( _timer ) {
250 outline1("LD A, (%s)", _timer );
251 outline0("LD A, B" );
252 } else {
253 outline0("LD B, 0" );
254 }
255 outline0("LD A, 1" );
256 outline0("LD C, A" );
257 outline0("CALL TIMERSETSTATUS" );
258
259}
260
261void coleco_timer_set_status_off( Environment * _environment, char * _timer ) {
262
263 deploy( timer, src_hw_z80_timer_asm);
264
265 if ( _timer ) {
266 outline1("LD A, (%s)", _timer );
267 outline0("LD A, B" );
268 } else {
269 outline0("LD B, 0" );
270 }
271 outline0("LD A, 0" );
272 outline0("LD C, A" );
273 outline0("CALL TIMERSETSTATUS" );
274
275
276}
277
278void coleco_timer_set_counter( Environment * _environment, char * _timer, char * _counter ) {
279
280 deploy( timer, src_hw_z80_timer_asm);
281
282 if ( _counter ) {
283 outline1("LD A, (%s)", _counter );
284 outline0("LD IXL, A" );
285 outline1("LD A, (%s)", address_displacement( _environment, _counter, "1" ) );
286 outline0("LD IXH, A" );
287 } else {
288 outline0("LD IX, 0" );
289 }
290 if ( _timer ) {
291 outline1("LD A, (%s)", _timer );
292 outline0("LD B, A" );
293 } else {
294 outline0("LD B, 0" );
295 }
296 outline0("CALL TIMERSETCOUNTER" );
297
298}
299
300void coleco_timer_set_init( Environment * _environment, char * _timer, char * _init ) {
301
302 deploy( timer, src_hw_z80_timer_asm);
303
304 if ( _init ) {
305 outline1("LD A, (%s)", _init );
306 outline0("LD IXL, A" );
307 outline1("LD A, (%s)", address_displacement( _environment, _init, "1" ) );
308 outline0("LD IXH, A" );
309 } else {
310 outline0("LD IX, 0" );
311 }
312 if ( _timer ) {
313 outline1("LD A, (%s)", _timer );
314 outline0("LD B, A" );
315 } else {
316 outline0("LD B, 0" );
317 }
318 outline0("CALL TIMERSETINIT" );
319
320}
321
322void coleco_timer_set_address( Environment * _environment, char * _timer, char * _address ) {
323
324 deploy( timer, src_hw_z80_timer_asm);
325
326 if ( _address ) {
327 outline1("LD HL, %s", _address );
328 outline0("LD A, L" );
329 outline0("LD IXL, A" );
330 outline0("LD A, H" );
331 outline0("LD IXH, A" );
332 } else {
333 outline0("LD IX, 0" );
334 }
335 if ( _timer ) {
336 outline1("LD A, (%s)", _timer );
337 outline0("LD B, A" );
338 } else {
339 outline0("LD B, 0" );
340 }
341 outline0("CALL TIMERSETADDRESS" );
342
343}
344
345#endif
void cpu_compare_8bit(Environment *_environment, char *_source, char *_destination, char *_other, int _positive)
CPU 6309: emit code to compare two 8 bit values
Definition 6309.c:811
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_store_8bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 8 bit
Definition 6309.c:761
void cpu_jump(Environment *_environment, char *_label)
Definition 6309.c:3739
void cpu_compare_and_branch_8bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6309: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6309.c:876
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
char * address_displacement(Environment *_environment, char *_address, char *_displacement)
Variable * scancode(Environment *_environment)
Definition scancode.c:43
void coleco_wait_fire(Environment *_environment, int _port, int _release)
void coleco_key_pressed(Environment *_environment, char *_scancode, char *_result)
void coleco_keyshift(Environment *_environment, char *_shifts)
void coleco_joy(Environment *_environment, int _port, char *_value)
void coleco_scanshift(Environment *_environment, char *_shifts)
void coleco_inkey(Environment *_environment, char *_pressed, char *_key)
void coleco_sys_call(Environment *_environment, int _destination)
void coleco_timer_set_status_off(Environment *_environment, char *_timer)
void coleco_timer_set_init(Environment *_environment, char *_timer, char *_init)
void coleco_clear_key(Environment *_environment)
void coleco_scancode(Environment *_environment, char *_pressed, char *_scacode)
void coleco_joy_vars(Environment *_environment, char *_port, char *_value)
void coleco_timer_set_status_on(Environment *_environment, char *_timer)
void coleco_wait_fire_semivar(Environment *_environment, char *_port, int _release)
void coleco_wait_key_or_fire(Environment *_environment, int _port, int _release)
void coleco_timer_set_address(Environment *_environment, char *_timer, char *_address)
void coleco_wait_key_or_fire_semivar(Environment *_environment, char *_port, int _release)
void coleco_timer_set_counter(Environment *_environment, char *_timer, char *_counter)
JoystickConfig joystickConfig
Definition ugbc.h:2437
int bitmaskNeeded
Definition ugbc.h:2659
char * realName
Definition ugbc.h:982
struct _RGBi RGBi
Structure to store color components (red, green and blue).
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_BYTE
Definition ugbc.h:450
#define outline0(s)
Definition ugbc.h:4252
#define outline1(s, a)
Definition ugbc.h:4253
#define deploy(s, e)
Definition ugbc.h:4288
#define MAKE_LABEL
Definition ugbc.h:3351
#define outhead1(s, a)
Definition ugbc.h:4247