ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
msx1.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 __msx1__
54
55void msx1_joy( Environment * _environment, int _port, char * _value ) {
56
57 deploy( joystick, src_hw_msx1_joystick_asm );
58
59 switch ( _port ) {
60 case 0:
61 if ( _environment->joystickConfig.sync ) {
62 outline0("CALL JOYSTICKREAD0" );
63 } else {
64 outline0("LD A, (JOYSTICK0)" );
65 }
66 if ( _environment->joystickConfig.values ) {
67 outline0("CALL JOYSTICKTSB" );
68 }
69 outline1("LD (%s), A", _value);
70 break;
71 case 1:
72 if ( _environment->joystickConfig.sync ) {
73 outline0("CALL JOYSTICKREAD1" );
74 } else {
75 outline0("LD A, (JOYSTICK1)" );
76 }
77 if ( _environment->joystickConfig.values ) {
78 outline0("CALL JOYSTICKTSB" );
79 }
80 outline1("LD (%s), A", _value);
81 break;
82 }
83
84}
85
86void msx1_joy_vars( Environment * _environment, char * _port, char * _value ) {
87
88 deploy( joystick, src_hw_msx1_joystick_asm );
89
91
92 outline1("LD A, (%s)", _port);
93 outline0("CP 0");
94 outline1("JR NZ, %spt1", label );
95 if ( _environment->joystickConfig.sync ) {
96 outline0("CALL JOYSTICKREAD0" );
97 } else {
98 outline0("LD A, (JOYSTICK0)" );
99 }
100 if ( _environment->joystickConfig.values ) {
101 outline0("CALL JOYSTICKTSB" );
102 }
103 outline1("LD (%s), A", _value);
104 outline1("JR %sptx", label );
105 outhead1("%spt1:", label);
106 if ( _environment->joystickConfig.sync ) {
107 outline0("CALL JOYSTICKREAD1" );
108 } else {
109 outline0("LD A, (JOYSTICK1)" );
110 }
111 if ( _environment->joystickConfig.values ) {
112 outline0("CALL JOYSTICKTSB" );
113 }
114 outline1("LD (%s), A", _value);
115 outline1("JR %sptx", label );
116 outhead1("%sptx:", label);
117
118}
119
120void msx1_inkey( Environment * _environment, char * _key ) {
121
122 _environment->bitmaskNeeded = 1;
123
124 deploy( keyboard, src_hw_msx1_keyboard_asm);
125
126 outline0("CALL INKEY");
127 outline1("LD (%s), A", _key);
128
129}
130
131void msx1_wait_key( Environment * _environment, int _release ) {
132
133 _environment->bitmaskNeeded = 1;
134
135 deploy( keyboard, src_hw_msx1_keyboard_asm );
136
137 if ( _release ) {
138 outline0("CALL WAITKEYRELEASE");
139 } else {
140 outline0("CALL WAITKEY");
141 }
142
143}
144
145void msx1_wait_key_or_fire( Environment * _environment, int _port, int _release ) {
146
147 _environment->bitmaskNeeded = 1;
148
149 deploy( joystick, src_hw_msx1_joystick_asm );
150 deploy( keyboard, src_hw_msx1_keyboard_asm );
151 deploy( wait_key_or_fire, src_hw_msx1_wait_key_or_fire_asm );
152
153 if ( _port == -1 ) {
154 outline0("CALL WAITKEYFIRE");
155 } else {
156 outline1("LD A, %2.2x", _port );
157 outline0("CALL WAITKEYFIREA");
158 }
159
160}
161
162void msx1_wait_key_or_fire_semivar( Environment * _environment, char * _port, int _release ) {
163
164 _environment->bitmaskNeeded = 1;
165
166 deploy( joystick, src_hw_msx1_joystick_asm );
167 deploy( keyboard, src_hw_msx1_keyboard_asm );
168 deploy( wait_key_or_fire, src_hw_msx1_wait_key_or_fire_asm );
169
170 if ( !_port ) {
171 outline0("CALL WAITKEYFIRE");
172 } else {
173 outline1("LD A, (%s)", _port );
174 outline0("CALL WAITKEYFIREA");
175 }
176
177}
178
179void msx1_wait_fire( Environment * _environment, int _port, int _release ) {
180
181 _environment->bitmaskNeeded = 1;
182
183 deploy( joystick, src_hw_msx1_joystick_asm );
184
185 outline1("LD B, $%2.2x", _release );
186 if ( _port == -1 ) {
187 outline0("CALL WAITFIRE");
188 } else {
189 outline1("LD A, $%2.2x", _port );
190 outline0("CALL WAITFIRE");
191 }
192
193}
194
195void msx1_wait_fire_semivar( Environment * _environment, char * _port, int _release ) {
196
197 _environment->bitmaskNeeded = 1;
198
199 deploy( joystick, src_hw_msx1_joystick_asm );
200
201 outline1("LD B, $%2.2x", _release );
202 if ( ! _port ) {
203 outline0("CALL WAITFIRE");
204 } else {
205 outline1("LD A, (%s)", _port );
206 outline0("CALL WAITFIRE");
207 }
208
209}
210
211void msx1_key_state( Environment * _environment, char *_scancode, char * _result ) {
212
213 _environment->bitmaskNeeded = 1;
214
216
217 deploy( keyboard, src_hw_msx1_keyboard_asm );
218
219 outline1("LD A, (%s)", _scancode);
220 outline0("CALL KEYSTATE");
221 cpu_ctoa( _environment );
222 outline1("LD (%s), A", _result);
223
224}
225
226void msx1_scancode( Environment * _environment, char * _result ) {
227
228 _environment->bitmaskNeeded = 1;
229
230 deploy( keyboard, src_hw_msx1_keyboard_asm);
231
232 outline0("CALL SCANCODE");
233 outline1("LD (%s), A", _result );
234
235}
236
237void msx1_asciicode( Environment * _environment, char * _result ) {
238
239 deploy( keyboard, src_hw_msx1_keyboard_asm);
240
241 outline0("CALL ASCIICODE");
242 outline1("LD A, (%s)", _result );
243
244}
245
246void msx1_key_pressed( Environment * _environment, char *_scancode, char * _result ) {
247
248 _environment->bitmaskNeeded = 1;
249
251
252 deploy( keyboard, src_hw_msx1_keyboard_asm );
253
254 outline1("LD A, (%s)", _scancode);
255 outline0("CALL KEYPRESSED");
256 cpu_ctoa( _environment );
257 outline1("LD (%s), A", _result);
258
259}
260
261
262void msx1_scanshift( Environment * _environment, char * _shifts ) {
263
264 msx1_keyshift( _environment, _shifts );
265
266
267}
268
269void msx1_keyshift( Environment * _environment, char * _shifts ) {
270
271 _environment->bitmaskNeeded = 1;
272
273 deploy( keyboard, src_hw_msx1_keyboard_asm );
274
275 outline0("CALL KEYSHIFT" );
276 outline1("LD (%s), A", _shifts );
277
278}
279
280void msx1_clear_key( Environment * _environment ) {
281
282 _environment->bitmaskNeeded = 1;
283
284 deploy( keyboard, src_hw_msx1_keyboard_asm );
285
286 outline0("CALL CLEARKEY" );
287
288}
289
290void msx1_sys_call( Environment * _environment, int _destination ) {
291
292 outline1("CALL $%4.4x", _destination );
293
294}
295
296void msx1_timer_set_status_on( Environment * _environment, char * _timer ) {
297
298 deploy( timer, src_hw_z80_timer_asm);
299
300 if ( _timer ) {
301 outline1("LD A, (%s)", _timer );
302 outline0("LD B, A" );
303 } else {
304 outline0("LD B, 0" );
305 }
306 outline0("LD A, 1" );
307 outline0("LD C, A" );
308 outline0("CALL TIMERSETSTATUS" );
309
310}
311
312void msx1_timer_set_status_off( Environment * _environment, char * _timer ) {
313
314 deploy( timer, src_hw_z80_timer_asm);
315
316 if ( _timer ) {
317 outline1("LD A, (%s)", _timer );
318 outline0("LD B, A" );
319 } else {
320 outline0("LD B, 0" );
321 }
322 outline0("LD A, 0" );
323 outline0("LD C, A" );
324 outline0("CALL TIMERSETSTATUS" );
325
326
327}
328
329void msx1_timer_set_counter( Environment * _environment, char * _timer, char * _counter ) {
330
331 deploy( timer, src_hw_z80_timer_asm);
332
333 if ( _counter ) {
334 outline1("LD A, (%s)", _counter );
335 outline0("LD IXL, A" );
336 outline1("LD A, (%s)", address_displacement( _environment, _counter, "1" ) );
337 outline0("LD IXH, A" );
338 } else {
339 outline0("LD IX, 0" );
340 }
341 if ( _timer ) {
342 outline1("LD A, (%s)", _timer );
343 outline0("LD B, A" );
344 } else {
345 outline0("LD B, 0" );
346 }
347 outline0("CALL TIMERSETCOUNTER" );
348
349}
350
351void msx1_timer_set_init( Environment * _environment, char * _timer, char * _init ) {
352
353 deploy( timer, src_hw_z80_timer_asm);
354
355 if ( _init ) {
356 outline1("LD A, (%s)", _init );
357 outline0("LD IXL, A" );
358 outline1("LD A, (%s)", address_displacement( _environment, _init, "1" ) );
359 outline0("LD IXH, A" );
360 } else {
361 outline0("LD IX, 0" );
362 }
363 if ( _timer ) {
364 outline1("LD A, (%s)", _timer );
365 outline0("LD B, A" );
366 } else {
367 outline0("LD B, 0" );
368 }
369 outline0("CALL TIMERSETINIT" );
370
371}
372
373void msx1_timer_set_address( Environment * _environment, char * _timer, char * _address ) {
374
375 deploy( timer, src_hw_z80_timer_asm);
376
377 if ( _address ) {
378 outline1("LD HL, %s", _address );
379 outline0("LD A, L" );
380 outline0("LD IXL, A" );
381 outline0("LD A, H" );
382 outline0("LD IXH, A" );
383 } else {
384 outline0("LD IX, 0" );
385 }
386 if ( _timer ) {
387 outline1("LD A, (%s)", _timer );
388 outline0("LD B, A" );
389 } else {
390 outline0("LD B, 0" );
391 }
392 outline0("CALL TIMERSETADDRESS" );
393
394}
395
396void msx1_dload( Environment * _environment, char * _filename, char * _offset, char * _address, char * _size ) {
397
398 deploy( dcommon, src_hw_msx1_dcommon_asm );
399 deploy( dload, src_hw_msx1_dload_asm );
400
402
403 Variable * filename = variable_retrieve( _environment, _filename );
404 Variable * tnaddress = variable_temporary( _environment, VT_ADDRESS, "(address of target_name)");
405 Variable * tnsize = variable_temporary( _environment, VT_BYTE, "(size of target_name)");
406
407 Variable * address = NULL;
408 if ( _address ) {
409 address = variable_retrieve( _environment, _address );
410 }
411 Variable * size = NULL;
412 if ( _size ) {
413 size = variable_retrieve( _environment, _size );
414 }
415 Variable * offset = NULL;
416 if ( _offset ) {
417 offset = variable_retrieve( _environment, _offset );
418 }
419
420 switch( filename->type ) {
421 case VT_STRING:
422 cpu_move_8bit( _environment, filename->realName, tnsize->realName );
423 cpu_addressof_16bit( _environment, filename->realName, tnaddress->realName );
424 cpu_inc_16bit( _environment, tnaddress->realName );
425 break;
426 case VT_DSTRING:
427 cpu_dsdescriptor( _environment, filename->realName, tnaddress->realName, tnsize->realName );
428 break;
429 }
430
431 outline1("LD HL, (%s)", tnaddress->realName);
432 outline1("LD A, (%s)", tnsize->realName);
433 outline0("LD B, A");
434
435 if ( address ) {
436
437 outline1("LD DE, (%s)", address->realName);
438
439 }
440
441 outline0("CALL MSX1DLOAD");
442
443}
444
445void msx1_dsave( Environment * _environment, char * _filename, char * _offset, char * _address, char * _size ) {
446
447 deploy( dcommon, src_hw_msx1_dcommon_asm );
448 deploy( dsave, src_hw_msx1_dsave_asm );
449
451
452 Variable * filename = variable_retrieve( _environment, _filename );
453 Variable * tnaddress = variable_temporary( _environment, VT_ADDRESS, "(address of target_name)");
454 Variable * tnsize = variable_temporary( _environment, VT_BYTE, "(size of target_name)");
455
456 Variable * address = NULL;
457 if ( _address ) {
458 address = variable_retrieve( _environment, _address );
459 }
460 Variable * size = NULL;
461 if ( _size ) {
462 size = variable_retrieve( _environment, _size );
463 }
464 Variable * offset = NULL;
465 if ( _offset ) {
466 offset = variable_retrieve( _environment, _offset );
467 }
468
469 switch( filename->type ) {
470 case VT_STRING:
471 cpu_move_8bit( _environment, filename->realName, tnsize->realName );
472 cpu_addressof_16bit( _environment, filename->realName, tnaddress->realName );
473 cpu_inc_16bit( _environment, tnaddress->realName );
474 break;
475 case VT_DSTRING:
476 cpu_dsdescriptor( _environment, filename->realName, tnaddress->realName, tnsize->realName );
477 break;
478 }
479
480 outline1("LD HL, (%s)", tnaddress->realName);
481 outline1("LD A, (%s)", tnsize->realName);
482 outline0("LD B, A");
483
484 if ( address ) {
485
486 outline1("LD DE, (%s)", address->realName);
487
488 }
489
490 if ( size ) {
491
492 outline1("LD IX, (%s)", size->realName);
493
494 }
495
496 outline0("CALL MSX1DSAVE");
497
498}
499
500
501void msx1_put_key( Environment * _environment, char *_string, char * _size ) {
502
503 _environment->bitmaskNeeded = 1;
504
505 deploy( keyboard, src_hw_msx1_keyboard_asm);
506
507 outline1("LD HL, (%s)", _string );
508 outline1("LD A, (%s)", _size );
509 outline0("LD C, A" );
510 outline0("CALL PUTKEY" );
511
512}
513
514#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_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)
void msx1_timer_set_address(Environment *_environment, char *_timer, char *_address)
Definition msx1.c:373
void msx1_asciicode(Environment *_environment, char *_result)
Definition msx1.c:237
void msx1_put_key(Environment *_environment, char *_string, char *_size)
Definition msx1.c:501
void msx1_key_pressed(Environment *_environment, char *_scancode, char *_result)
Definition msx1.c:246
void msx1_timer_set_status_off(Environment *_environment, char *_timer)
Definition msx1.c:312
void msx1_wait_key(Environment *_environment, int _release)
Definition msx1.c:131
void msx1_keyshift(Environment *_environment, char *_shifts)
Definition msx1.c:269
void msx1_dsave(Environment *_environment, char *_filename, char *_offset, char *_address, char *_size)
Definition msx1.c:445
void msx1_key_state(Environment *_environment, char *_scancode, char *_result)
Definition msx1.c:211
void msx1_timer_set_counter(Environment *_environment, char *_timer, char *_counter)
Definition msx1.c:329
void msx1_wait_key_or_fire_semivar(Environment *_environment, char *_port, int _release)
Definition msx1.c:162
void msx1_scanshift(Environment *_environment, char *_shifts)
Definition msx1.c:262
void msx1_inkey(Environment *_environment, char *_key)
Definition msx1.c:120
void msx1_wait_key_or_fire(Environment *_environment, int _port, int _release)
Definition msx1.c:145
void msx1_timer_set_status_on(Environment *_environment, char *_timer)
Definition msx1.c:296
void msx1_scancode(Environment *_environment, char *_result)
Definition msx1.c:226
void msx1_dload(Environment *_environment, char *_filename, char *_offset, char *_address, char *_size)
Definition msx1.c:396
void msx1_wait_fire(Environment *_environment, int _port, int _release)
Definition msx1.c:179
void msx1_timer_set_init(Environment *_environment, char *_timer, char *_init)
Definition msx1.c:351
void msx1_joy_vars(Environment *_environment, char *_port, char *_value)
Definition msx1.c:86
void msx1_clear_key(Environment *_environment)
Definition msx1.c:280
void msx1_joy(Environment *_environment, int _port, char *_value)
Definition msx1.c:55
void msx1_sys_call(Environment *_environment, int _destination)
Definition msx1.c:290
void msx1_wait_fire_semivar(Environment *_environment, char *_port, int _release)
Definition msx1.c:195
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).
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_STRING
Definition ugbc.h:474
@ VT_BYTE
Definition ugbc.h:450
@ 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