ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
vz200.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
38/****************************************************************************
39 * CODE SECTION
40 ****************************************************************************/
41
42#ifdef __vz200__
43
44void vz200_inkey( Environment * _environment, char * _key ) {
45
46 _environment->bitmaskNeeded = 1;
47
48 deploy_deferred( keyboard, src_hw_vz200_keyboard_asm);
49
50 outline0("CALL INKEY");
51 outline1("LD (%s), A", _key);
52
53}
54
55void vz200_wait_key( Environment * _environment, int _release ) {
56
57 _environment->bitmaskNeeded = 1;
58
59 deploy_deferred( keyboard, src_hw_vz200_keyboard_asm );
60
61 if ( _release ) {
62 outline0("CALL WAITKEYRELEASE");
63 } else {
64 outline0("CALL WAITKEY");
65 }
66
67}
68
69
70void vz200_wait_key_or_fire( Environment * _environment, int _port, int _release ) {
71
72 _environment->bitmaskNeeded = 1;
73
74 deploy( joystick, src_hw_vz200_joystick_asm );
75 deploy_deferred( keyboard, src_hw_vz200_keyboard_asm );
76 deploy( wait_key_or_fire, src_hw_vz200_wait_key_or_fire_asm );
77
78 if ( _port == -1 ) {
79 outline0("CALL WAITKEYFIRE");
80 } else {
81 outline1("LD A, %2.2x", _port);
82 outline0("CALL WAITKEYFIREA");
83 }
84
85}
86
87void vz200_wait_key_or_fire_semivar( Environment * _environment, char * _port, int _release ) {
88
89 _environment->bitmaskNeeded = 1;
90
91 deploy( joystick, src_hw_vz200_joystick_asm );
92 deploy_deferred( keyboard, src_hw_vz200_keyboard_asm );
93 deploy( wait_key_or_fire, src_hw_vz200_wait_key_or_fire_asm );
94
95 if ( ! _port ) {
96 outline0("CALL WAITKEYFIRE");
97 } else {
98 outline1("LD A, (%s)", _port);
99 outline0("CALL WAITKEYFIREA");
100 }
101
102}
103
104void vz200_wait_fire( Environment * _environment, int _port, int _release ) {
105
106 _environment->bitmaskNeeded = 1;
107
108 deploy( joystick, src_hw_vz200_joystick_asm );
109 deploy_deferred( keyboard, src_hw_vz200_keyboard_asm );
110
111 switch( _port ) {
112 case -1:
113 outline0("CALL WAITFIRE");
114 break;
115 case 0:
116 outline0("CALL WAITFIRE0");
117 break;
118 case 1:
119 outline0("CALL WAITFIRE1");
120 break;
121 }
122
123}
124
125void vz200_wait_fire_semivar( Environment * _environment, char * _port, int _release ) {
126
127 _environment->bitmaskNeeded = 1;
128
129 deploy( joystick, src_hw_vz200_joystick_asm );
130
131 if ( ! _port ) {
132 outline0("CALL WAITFIRE");
133 } else {
134 outline1("LD A, (%s)", _port);
135 outline0("CALL WAITKEYFIREA");
136 }
137
138}
139
140void vz200_key_state( Environment * _environment, char *_scancode, char * _result ) {
141
142 _environment->bitmaskNeeded = 1;
143
145
146 deploy_deferred( keyboard, src_hw_vz200_keyboard_asm );
147
148 outline1("LD A, (%s)", _scancode);
149 outline0("CALL KEYSTATE");
150 cpu_ctoa( _environment );
151 outline1("LD (%s), A", _result);
152
153}
154
155void vz200_scancode( Environment * _environment, char * _result ) {
156
158
159 _environment->bitmaskNeeded = 1;
160
161 deploy_deferred( keyboard, src_hw_vz200_keyboard_asm);
162
163 outline0("CALL SCANCODE");
164 if ( _environment->vestigialConfig.rchack_falling_balls_1163 ) {
165 outline0("CP $FF");
166 outline1("JR NZ, %s", label );
167 outline0("XOR $FF");
168 outhead1("%s:", label );
169 }
170 outline1("LD (%s), A", _result );
171
172}
173
174void vz200_asciicode( Environment * _environment, char * _result ) {
175
176 _environment->bitmaskNeeded = 1;
177
178 deploy_deferred( keyboard, src_hw_vz200_keyboard_asm);
179
180 outline0("CALL ASCIICODE");
181 outline1("LD (%s), A", _result );
182
183}
184
185void vz200_key_pressed( Environment * _environment, char *_scancode, char * _result ) {
186
187 _environment->bitmaskNeeded = 1;
188
190
191 deploy_deferred( keyboard, src_hw_vz200_keyboard_asm );
192
193 outline1("LD A, (%s)", _scancode);
194 outline0("CALL KEYPRESSED");
195 cpu_ctoa( _environment );
196 outline1("LD (%s), A", _result);
197
198}
199
200void vz200_scanshift( Environment * _environment, char * _shifts ) {
201
202}
203
204void vz200_keyshift( Environment * _environment, char * _shifts ) {
205
206 _environment->bitmaskNeeded = 1;
207
208 deploy_deferred( keyboard, src_hw_vz200_keyboard_asm );
209
210 outline0("CALL KEYSHIFT" );
211 outline1("LD (%s), A", _shifts );
212
213}
214
215void vz200_clear_key( Environment * _environment ) {
216
217 _environment->bitmaskNeeded = 1;
218
219 deploy_deferred( keyboard, src_hw_vz200_keyboard_asm );
220
221 outline0("CALL CLEARKEY" );
222
223}
224
225void vz200_joy_vars( Environment * _environment, char * _port, char * _value ) {
226
227 _environment->bitmaskNeeded = 1;
228
229 deploy_deferred( keyboard, src_hw_vz200_keyboard_asm );
230 deploy( joystick, src_hw_vz200_joystick_asm );
231
233
234 if ( _environment->keyboardConfig.sync ) {
235 outline0("CALL SCANCODERAW" );
236 }
237 outline1("LD A, (%s)", _port);
238 outline0("CP 0");
239 outline1("JR NZ, %spt1", label );
240 if ( _environment->joystickConfig.sync ) {
241 outline0("CALL JOYSTICKREAD0" );
242 } else {
243 outline0("LD A, (JOYSTICK0)" );
244 }
245 if ( _environment->joystickConfig.values ) {
246 outline0("CALL JOYSTICKTSB" );
247 }
248 outline1("LD (%s), A", _value);
249 outline1("JR %sptx", label );
250 outhead1("%spt1:", label);
251 if ( _environment->joystickConfig.sync ) {
252 outline0("CALL JOYSTICKREAD1" );
253 } else {
254 outline0("LD A, (JOYSTICK1)" );
255 }
256 if ( _environment->joystickConfig.values ) {
257 outline0("CALL JOYSTICKTSB" );
258 }
259 outline1("LD (%s), A", _value);
260 outline1("JR %sptx", label );
261 outhead1("%sptx:", label);
262
263}
264
265void vz200_joy( Environment * _environment, int _port, char * _value ) {
266
267 _environment->bitmaskNeeded = 1;
268
269 deploy_deferred( keyboard, src_hw_vz200_keyboard_asm );
270 deploy( joystick, src_hw_vz200_joystick_asm );
271 if ( _environment->keyboardConfig.sync ) {
272 outline0("CALL SCANCODERAW" );
273 }
274 switch ( _port ) {
275 case 0:
276 if ( _environment->joystickConfig.sync ) {
277 outline0("CALL JOYSTICKREAD0" );
278 } else {
279 outline0("LD A, (JOYSTICK0)" );
280 }
281 break;
282 case 1:
283 if ( _environment->joystickConfig.sync ) {
284 outline0("CALL JOYSTICKREAD0" );
285 } else {
286 outline0("LD A, (JOYSTICK0)" );
287 }
288 break;
289 }
290 if ( _environment->joystickConfig.values ) {
291 outline0("CALL JOYSTICKTSB" );
292 }
293 outline1("LD (%s), A", _value);
294
295}
296
297void vz200_bank_select( Environment * _environment, int _bank ) {
298
299}
300
301void vz200_busy_wait( Environment * _environment, char * _timing ) {
302
304
305 outline1("LD A, (%s)", _timing);
306 outline0("LD D, A");
307 outline0("LD B, 0xf5");
308 outline1("%swait", label );
309 outline0("IN A, (C)");
310 outline0("RRA");
311 outline1("JP NC, %swait", label);
312 outline0("DEC D");
313 outline1("JP NZ, %swait", label);
314
315}
316
317void vz200_initialization( Environment * _environment ) {
318
319 variable_import( _environment, "VZ200TIMER", VT_WORD, 0 );
320 variable_global( _environment, "VZ200TIMER" );
321 variable_import( _environment, "VZ200TIMER2", VT_BYTE, 6 );
322 variable_global( _environment, "VZ200TIMER2" );
323
324 variable_import( _environment, "EVERYCOUNTER", VT_BYTE, 0 );
325 variable_global( _environment, "EVERYCOUNTER" );
326 variable_import( _environment, "EVERYTIMING", VT_BYTE, 0 );
327 variable_global( _environment, "EVERYTIMING" );
328
329 variable_import( _environment, "FPSCRAP", VT_BUFFER, 16 );
330 variable_global( _environment, "FPSCRAP" );
331
332}
333
334void vz200_finalization( Environment * _environment ) {
335
336}
337
338void vz200_timer_set_status_on( Environment * _environment, char * _timer ) {
339
340 deploy( timer, src_hw_z80_timer_asm);
341
342 if ( _timer ) {
343 outline1("LD A, (%s)", _timer );
344 outline0("LD B, A" );
345 } else {
346 outline0("LD B, 0" );
347 }
348 outline0("LD A, 1" );
349 outline0("LD C, A" );
350 outline0("CALL TIMERSETSTATUS" );
351
352}
353
354void vz200_timer_set_status_off( Environment * _environment, char * _timer ) {
355
356 deploy( timer, src_hw_z80_timer_asm);
357
358 if ( _timer ) {
359 outline1("LD A, (%s)", _timer );
360 outline0("LD B, A" );
361 } else {
362 outline0("LD B, 0" );
363 }
364 outline0("LD A, 0" );
365 outline0("LD C, A" );
366 outline0("CALL TIMERSETSTATUS" );
367
368
369}
370
371void vz200_timer_set_counter( Environment * _environment, char * _timer, char * _counter ) {
372
373 deploy( timer, src_hw_z80_timer_asm);
374
375 if ( _counter ) {
376 outline1("LD A, (%s)", _counter );
377 outline0("LD IXL, A" );
378 outline1("LD A, (%s)", address_displacement( _environment, _counter, "1" ) );
379 outline0("LD IXH, A" );
380 } else {
381 outline0("LD IX, 0" );
382 }
383 if ( _timer ) {
384 outline1("LD A, (%s)", _timer );
385 outline0("LD B, A" );
386 } else {
387 outline0("LD B, 0" );
388 }
389 outline0("CALL TIMERSETCOUNTER" );
390
391}
392
393void vz200_timer_set_init( Environment * _environment, char * _timer, char * _init ) {
394
395 deploy( timer, src_hw_z80_timer_asm);
396
397 if ( _init ) {
398 outline1("LD A, (%s)", _init );
399 outline0("LD IXL, A" );
400 outline1("LD A, (%s)", address_displacement( _environment, _init, "1" ) );
401 outline0("LD IXH, A" );
402 } else {
403 outline0("LD IX, 0" );
404 }
405 if ( _timer ) {
406 outline1("LD A, (%s)", _timer );
407 outline0("LD B, A" );
408 } else {
409 outline0("LD B, 0" );
410 }
411 outline0("CALL TIMERSETINIT" );
412
413}
414
415void vz200_timer_set_address( Environment * _environment, char * _timer, char * _address ) {
416
417 deploy( timer, src_hw_z80_timer_asm);
418
419 if ( _address ) {
420 outline1("LD HL, %s", _address );
421 outline0("LD A, L" );
422 outline0("LD IXL, A" );
423 outline0("LD A, H" );
424 outline0("LD IXH, A" );
425 } else {
426 outline0("LD IX, 0" );
427 }
428 if ( _timer ) {
429 outline1("LD A, (%s)", _timer );
430 outline0("LD B, A" );
431 } else {
432 outline0("LD B, 0" );
433 }
434 outline0("CALL TIMERSETADDRESS" );
435
436}
437
438void vz200_dload( Environment * _environment, char * _filename, char * _offset, char * _address, char * _size ) {
439
440 deploy( dload, src_hw_vz200_dload_asm );
441
443
444 Variable * filename = variable_retrieve( _environment, _filename );
445 Variable * tnaddress = variable_temporary( _environment, VT_ADDRESS, "(address of target_name)");
446 Variable * tnsize = variable_temporary( _environment, VT_BYTE, "(size of target_name)");
447
448 Variable * address = NULL;
449 if ( _address ) {
450 address = variable_retrieve( _environment, _address );
451 }
452 Variable * size = NULL;
453 if ( _size ) {
454 size = variable_retrieve( _environment, _size );
455 }
456 Variable * offset = NULL;
457 if ( _offset ) {
458 offset = variable_retrieve( _environment, _offset );
459 }
460
461 switch( filename->type ) {
462 case VT_STRING:
463 cpu_move_8bit( _environment, filename->realName, tnsize->realName );
464 cpu_addressof_16bit( _environment, filename->realName, tnaddress->realName );
465 cpu_inc_16bit( _environment, tnaddress->realName );
466 break;
467 case VT_DSTRING:
468 cpu_dsdescriptor( _environment, filename->realName, tnaddress->realName, tnsize->realName );
469 break;
470 }
471
472 outline1("LD HL, (%s)", tnaddress->realName);
473 outline1("LD A, (%s)", tnsize->realName);
474 outline0("LD B, A");
475
476 if ( address ) {
477
478 outline1("LD DE, (%s)", address->realName);
479
480 }
481
482 outline0("CALL VZ200DLOAD");
483
484}
485
486void vz200_dsave( Environment * _environment, char * _filename, char * _offset, char * _address, char * _size ) {
487
488 deploy( dsave, src_hw_vz200_dsave_asm );
489
491
492 Variable * filename = variable_retrieve( _environment, _filename );
493 Variable * tnaddress = variable_temporary( _environment, VT_ADDRESS, "(address of target_name)");
494 Variable * tnsize = variable_temporary( _environment, VT_BYTE, "(size of target_name)");
495
496 Variable * address = NULL;
497 if ( _address ) {
498 address = variable_retrieve( _environment, _address );
499 }
500 Variable * size = NULL;
501 if ( _size ) {
502 size = variable_retrieve( _environment, _size );
503 }
504 Variable * offset = NULL;
505 if ( _offset ) {
506 offset = variable_retrieve( _environment, _offset );
507 }
508
509 switch( filename->type ) {
510 case VT_STRING:
511 cpu_move_8bit( _environment, filename->realName, tnsize->realName );
512 cpu_addressof_16bit( _environment, filename->realName, tnaddress->realName );
513 cpu_inc_16bit( _environment, tnaddress->realName );
514 break;
515 case VT_DSTRING:
516 cpu_dsdescriptor( _environment, filename->realName, tnaddress->realName, tnsize->realName );
517 break;
518 }
519
520 outline1("LD HL, (%s)", tnaddress->realName);
521 outline1("LD A, (%s)", tnsize->realName);
522 outline0("LD B, A");
523
524 if ( address ) {
525
526 outline1("LD DE, (%s)", address->realName);
527
528 }
529
530 if ( size ) {
531
532 outline1("LD IX, (%s)", size->realName);
533
534 }
535
536 outline0("CALL VZ200DSAVE");
537
538}
539
540void vz200_put_key( Environment * _environment, char *_string, char * _size ) {
541
542 _environment->bitmaskNeeded = 1;
543
544 deploy_deferred( keyboard, src_hw_vz200_keyboard_asm);
545
546 outline1("LD HL, (%s)", _string );
547 outline1("LD A, (%s)", _size );
548 outline0("LD C, A" );
549 outline0("CALL PUTKEY" );
550
551}
552
553void vz200_sys_call( Environment * _environment, int _destination ) {
554
555 _environment->sysCallUsed = 1;
556
557 outline0("PUSH HL" );
558 outline0("LD HL, SYSCALL0" );
559 outline0("INC HL" );
560 outline1("LD (HL), 0x%2.2x", (_destination & 0xff ) );
561 outline0("INC HL" );
562 outline1("LD (HL), 0x%2.2x", ((_destination>>8) & 0xff ) );
563 outline0("POP HL" );
564 outline0("CALL SYSCALL");
565
566}
567
568#endif
void cpu_addressof_16bit(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:1485
void cpu_inc_16bit(Environment *_environment, char *_variable)
Definition 6309.c:4565
void cpu_ctoa(Environment *_environment)
Definition 6309.c:279
void cpu_move_8bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 8 bit
Definition 6309.c:743
void cpu_dsdescriptor(Environment *_environment, char *_index, char *_address, char *_size)
Definition 6309.c:5977
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_import(Environment *_environment, char *_name, VariableType _type, int _size_or_value)
void variable_global(Environment *_environment, char *_pattern)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
char * address_displacement(Environment *_environment, char *_address, char *_displacement)
int size
Definition _optimizer.c:678
int offset
Definition _optimizer.c:681
void dload(Environment *_environment, char *_filename, char *_offset, char *_address, char *_bank, char *_size)
Emit code for DLOAD(...).
Definition dload.c:60
void dsave(Environment *_environment, char *_filename, char *_offset, char *_address, char *_size)
Emit code for DLOAD(...).
Definition dsave.c:58
void wait_key_or_fire(Environment *_environment, int _port, int _release)
JoystickConfig joystickConfig
Definition ugbc.h:2437
int bitmaskNeeded
Definition ugbc.h:2659
int sysCallUsed
Definition ugbc.h:3162
KeyboardConfig keyboardConfig
Definition ugbc.h:2435
VestigialConfig vestigialConfig
Definition ugbc.h:2442
char * realName
Definition ugbc.h:982
char rchack_falling_balls_1163
Definition ugbc.h:2052
struct _Variable Variable
Structure of a single variable.
#define deploy_deferred(s, e)
Definition ugbc.h:4302
struct _Environment Environment
Structure of compilation environment.
@ VT_WORD
Definition ugbc.h:455
@ VT_STRING
Definition ugbc.h:474
@ VT_BYTE
Definition ugbc.h:450
@ VT_BUFFER
Definition ugbc.h:477
@ VT_ADDRESS
Definition ugbc.h:465
@ VT_DSTRING
Definition ugbc.h:483
#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
void vz200_keyshift(Environment *_environment, char *_shifts)
Definition vz200.c:204
void vz200_clear_key(Environment *_environment)
Definition vz200.c:215
void vz200_inkey(Environment *_environment, char *_key)
Definition vz200.c:44
void vz200_wait_key_or_fire(Environment *_environment, int _port, int _release)
Definition vz200.c:70
void vz200_key_pressed(Environment *_environment, char *_scancode, char *_result)
Definition vz200.c:185
void vz200_sys_call(Environment *_environment, int _destination)
Definition vz200.c:553
void vz200_timer_set_status_off(Environment *_environment, char *_timer)
Definition vz200.c:354
void vz200_wait_fire_semivar(Environment *_environment, char *_port, int _release)
Definition vz200.c:125
void vz200_bank_select(Environment *_environment, int _bank)
Definition vz200.c:297
void vz200_finalization(Environment *_environment)
Definition vz200.c:334
void vz200_asciicode(Environment *_environment, char *_result)
Definition vz200.c:174
void vz200_joy(Environment *_environment, int _port, char *_value)
Definition vz200.c:265
void vz200_put_key(Environment *_environment, char *_string, char *_size)
Definition vz200.c:540
void vz200_scancode(Environment *_environment, char *_result)
Definition vz200.c:155
void vz200_timer_set_init(Environment *_environment, char *_timer, char *_init)
Definition vz200.c:393
void vz200_wait_key(Environment *_environment, int _release)
Definition vz200.c:55
void vz200_dsave(Environment *_environment, char *_filename, char *_offset, char *_address, char *_size)
Definition vz200.c:486
void vz200_joy_vars(Environment *_environment, char *_port, char *_value)
Definition vz200.c:225
void vz200_timer_set_address(Environment *_environment, char *_timer, char *_address)
Definition vz200.c:415
void vz200_dload(Environment *_environment, char *_filename, char *_offset, char *_address, char *_size)
Definition vz200.c:438
void vz200_timer_set_status_on(Environment *_environment, char *_timer)
Definition vz200.c:338
void vz200_wait_fire(Environment *_environment, int _port, int _release)
Definition vz200.c:104
void vz200_initialization(Environment *_environment)
Definition vz200.c:317
void vz200_wait_key_or_fire_semivar(Environment *_environment, char *_port, int _release)
Definition vz200.c:87
void vz200_timer_set_counter(Environment *_environment, char *_timer, char *_counter)
Definition vz200.c:371
void vz200_busy_wait(Environment *_environment, char *_timing)
Definition vz200.c:301
void vz200_scanshift(Environment *_environment, char *_shifts)
Definition vz200.c:200
void vz200_key_state(Environment *_environment, char *_scancode, char *_result)
Definition vz200.c:140