ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
to8.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 __to8__
43
44void to8_xpen( Environment * _environment, char * _destination ) {
45
47
48 outline0("LDA $FF60");
49 outline1("STA %s", address_displacement(_environment, _destination, "1"));
50 outline0("LDA #0");
51 outline1("STA %s", _destination);
52
53}
54
55void to8_ypen( Environment * _environment, char * _destination ) {
56
58
59 outline0("LDA $FF61");
60 outline1("STA %s", address_displacement(_environment, _destination, "1"));
61 outline0("LDA #0");
62 outline1("STA %s", _destination);
63
64}
65
66void to8_color_border( Environment * _environment, char * _color ) {
67
68}
69
70void to8_vscroll( Environment * _environment, int _displacement ) {
71
72}
73
74void to8_text_at( Environment * _environment, char * _text, char * _text_size, char * _pen, char * _paper ) {
75
76}
77
78void to8_cls( Environment * _environment, char * _pen, char * _paper ) {
79
80}
81
82void to8_inkey( Environment * _environment, char * _pressed, char * _key ) {
83
84 deploy_preferred( scancode, src_hw_to8_scancode_asm );
85
87
88 outline0("JSR INKEY" );
89 outline1("STB %s", _key );
90 outline1("STA %s", _pressed );
91}
92
93void to8_wait_key_or_fire( Environment * _environment, int _port, int _release ) {
94
95
96}
97
98void to8_wait_key_or_fire_semivar( Environment * _environment, char * _port, int _release ) {
99
100}
101
102void to8_wait_fire( Environment * _environment, int _port, int _release ) {
103
104 if ( _environment->joystickConfig.notEmulated ) {
105
106 } else {
107
108 _environment->bitmaskNeeded = 1;
109
110 deploy_preferred( keyboard, src_hw_to8_keyboard_asm );
111 deploy( joystick, src_hw_to8_joystick_asm );
112
113 if ( _port == -1 ) {
114 outline0("JSR WAITFIRE");
115 } else {
116 outline1("LDA #$%2.2x", (unsigned char)(_port&0xff) );
117 outline0("JSR WAITFIREX");
118 }
119 }
120
121}
122
123void to8_wait_fire_semivar( Environment * _environment, char * _port, int _release ) {
124
125 if ( _environment->joystickConfig.notEmulated ) {
126
127 } else {
128
129 _environment->bitmaskNeeded = 1;
130
131 deploy_preferred( keyboard, src_hw_to8_keyboard_asm );
132 deploy( joystick, src_hw_to8_joystick_asm );
133
134 if ( !_port ) {
135 outline0("JSR WAITFIRE");
136 } else {
137 outline1("LDA %s", _port );
138 outline0("JSR WAITFIREX");
139 }
140 }
141
142}
143
144void to8_scancode( Environment * _environment, char * _pressed, char * _scancode ) {
145
147
148 deploy_preferred( scancode, src_hw_to8_scancode_asm );
149
150 outline0("JSR SCANCODE" );
151 outline1("STB %s", _scancode );
152 outline1("STA %s", _pressed );
153
154}
155
156void to8_scanshift( Environment * _environment, char * _shifts ) {
157
158 to8_keyshift( _environment, _shifts );
159
160}
161
162void to8_keyshift( Environment * _environment, char * _shifts ) {
163
165
166 Variable * pressed = variable_temporary( _environment, VT_BYTE, "(pressed)" );
167 Variable * scancode = variable_temporary( _environment, VT_BYTE, "(scancode)" );
168
169 Variable * result = variable_temporary( _environment, VT_BYTE, "(result)");
170
171 to8_scancode( _environment, pressed->realName, scancode->realName );
172
173}
174
175void to8_clear_key( Environment * _environment ) {
176
177}
178
179void to8_initialization( Environment * _environment ) {
180
181}
182
183int to8_screen_mode_enable( Environment * _environment, ScreenMode * _screen_mode ) {
184
185}
186
187void to8_bitmap_enable( Environment * _environment, int _width, int _height, int _colors ) {
188
189}
190
191void to8_tilemap_enable( Environment * _environment, int _width, int _height, int _colors, int _tile_width, int _tile_height ) {
192
193}
194
195void to8_back( Environment * _environment ) {
196
197}
198
199void to8_busy_wait( Environment * _environment, char * _timing ) {
200
202
203 outline1("LDD %s", _timing );
204 outline0("LDX TO8TIMER");
205 outline0("LEAX D, X");
206 outhead1("%sfirst", label );
207 interleaved_instructions( _environment );
208 outline0("CMPX TO8TIMER");
209 outline1("BGT %sfirst", label);
210}
211
212void to8_key_pressed( Environment * _environment, char *_scancode, char * _result ) {
213
215
216 deploy_preferred( scancode, src_hw_to8_scancode_asm );
217
218 outline1("LDA %s", _scancode );
219 outline0("JSR KEYPRESSED");
220 outline1("BEQ %snopressed", label );
221 outline0("LDA #$ff" );
222 outline1("STA %s", _result );
223 outline1("BRA %sfinish", label );
224 outhead1("%snopressed", label );
225 outline0("LDA #0" );
226 outline1("STA %s", _result );
227 outhead1("%sfinish", label );
228
229}
230
231void to8_joystick_semivars( Environment * _environment, char * _joystick, char * _result ) {
232
233 if ( _environment->joystickConfig.notEmulated ) {
234 cpu_store_8bit( _environment, _result, 0 );
235 } else {
236
237 _environment->bitmaskNeeded = 1;
238
239 deploy_preferred( scancode, src_hw_to8_scancode_asm );
240 deploy( joystick, src_hw_to8_joystick_asm );
241
242 outline1("LDA %s", _joystick);
243 outline0("JSR JOYSTICK");
244 outline1("STA %s", _result);
245
246 }
247
248}
249
250void to8_joystick( Environment * _environment, int _joystick, char * _result ) {
251
252 if ( _environment->joystickConfig.notEmulated ) {
253 cpu_store_8bit( _environment, _result, 0 );
254 } else {
255
256 _environment->bitmaskNeeded = 1;
257
258 deploy_preferred( scancode, src_hw_to8_scancode_asm );
259 deploy( joystick, src_hw_to8_joystick_asm );
260
261 outline1("LDA #$%2.2x", _joystick);
262 outline0("JSR JOYSTICK");
263 outline1("STA %s", _result);
264
265 }
266
267}
268
269void to8_sys_call( Environment * _environment, int _destination ) {
270
271 _environment->sysCallUsed = 1;
272
273 outline0("PSHS D");
274 outline1("LDD #$%4.4x", _destination );
275 outline0("STD SYSCALL0+1");
276 outline0("PULS D");
277 outline0("JSR SYSCALL");
278
279}
280
281void to8_timer_set_status_on( Environment * _environment, char * _timer ) {
282
283 deploy( timer, src_hw_6809_timer_asm);
284
285 if ( _timer ) {
286 outline1("LDB %s", _timer );
287 } else {
288 outline0("LDB #0" );
289 }
290 outline0("LDA #$1" );
291 outline0("STA <MATHPTR0" );
292 outline0("JSR TIMERSETSTATUS" );
293
294}
295
296void to8_timer_set_status_off( Environment * _environment, char * _timer ) {
297
298 deploy( timer, src_hw_6809_timer_asm);
299
300 if ( _timer ) {
301 outline1("LDB %s", _timer );
302 } else {
303 outline0("LDB #0" );
304 }
305 outline0("LDA #$0" );
306 outline0("STA <MATHPTR0" );
307 outline0("JSR TIMERSETSTATUS" );
308
309}
310
311void to8_timer_set_counter( Environment * _environment, char * _timer, char * _counter ) {
312
313 deploy( timer, src_hw_6809_timer_asm);
314
315 if ( _counter ) {
316 outline1("LDD %s", _counter );
317 } else {
318 outline0("LDD #0" );
319 }
320 outline0("STD <MATHPTR2");
321 if ( _timer ) {
322 outline1("LDB %s", _timer );
323 } else {
324 outline0("LDB #0" );
325 }
326 outline0("JSR TIMERSETCOUNTER" );
327
328}
329
330void to8_timer_set_init( Environment * _environment, char * _timer, char * _init ) {
331
332 deploy( timer, src_hw_6809_timer_asm);
333
334 outline1("LDD %s", _init );
335 outline0("STD <MATHPTR2");
336 if ( _timer ) {
337 outline1("LDB %s", _timer );
338 } else {
339 outline0("LDB #0" );
340 }
341 outline0("JSR TIMERSETINIT" );
342
343}
344
345void to8_timer_set_address( Environment * _environment, char * _timer, char * _address ) {
346
347 deploy( timer, src_hw_6809_timer_asm);
348
349 outline1("LDD #%s", _address );
350 outline0("STD <MATHPTR2");
351 if ( _timer ) {
352 outline1("LDB %s", _timer );
353 } else {
354 outline0("LDB #0" );
355 }
356 outline0("JSR TIMERSETADDRESS" );
357
358}
359
360void to8_dload( Environment * _environment, char * _address, char * _bank, char * _size ) {
361
362 deploy( dload, src_hw_to8_dload_asm);
363
364 if ( _bank ) {
365 outline1("LDA %s", _bank );
366 } else {
367 outline0("CLRA" );
368 }
369 outline1("LDX %s", _address );
370 outline1("LDU %s", _size );
371 outline0("JSR DLOAD" );
372
373}
374
375#endif
void cpu_store_8bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 8 bit
Definition 6309.c:761
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
char * address_displacement(Environment *_environment, char *_address, char *_displacement)
void interleaved_instructions(Environment *_environment)
Definition _init.c:123
void dload(Environment *_environment, char *_filename, char *_offset, char *_address, char *_bank, char *_size)
Emit code for DLOAD(...).
Definition dload.c:60
Variable * scancode(Environment *_environment)
Definition scancode.c:43
JoystickConfig joystickConfig
Definition ugbc.h:2437
int bitmaskNeeded
Definition ugbc.h:2659
int sysCallUsed
Definition ugbc.h:3162
int notEmulated
Definition ugbc.h:1998
void to8_cls(Environment *_environment, char *_pen, char *_paper)
Definition to8.c:78
void to8_busy_wait(Environment *_environment, char *_timing)
Definition to8.c:199
void to8_wait_key_or_fire_semivar(Environment *_environment, char *_port, int _release)
Definition to8.c:98
void to8_back(Environment *_environment)
Definition to8.c:195
void to8_text_at(Environment *_environment, char *_text, char *_text_size, char *_pen, char *_paper)
Definition to8.c:74
void to8_timer_set_counter(Environment *_environment, char *_timer, char *_counter)
Definition to8.c:311
void to8_tilemap_enable(Environment *_environment, int _width, int _height, int _colors, int _tile_width, int _tile_height)
Definition to8.c:191
void to8_wait_key_or_fire(Environment *_environment, int _port, int _release)
Definition to8.c:93
void to8_ypen(Environment *_environment, char *_destination)
Definition to8.c:55
void to8_initialization(Environment *_environment)
Definition to8.c:179
void to8_clear_key(Environment *_environment)
Definition to8.c:175
void to8_timer_set_init(Environment *_environment, char *_timer, char *_init)
Definition to8.c:330
void to8_dload(Environment *_environment, char *_address, char *_bank, char *_size)
Definition to8.c:360
void to8_color_border(Environment *_environment, char *_color)
Definition to8.c:66
void to8_vscroll(Environment *_environment, int _displacement)
Definition to8.c:70
void to8_wait_fire_semivar(Environment *_environment, char *_port, int _release)
Definition to8.c:123
void to8_sys_call(Environment *_environment, int _destination)
Definition to8.c:269
void to8_bitmap_enable(Environment *_environment, int _width, int _height, int _colors)
Definition to8.c:187
void to8_timer_set_status_on(Environment *_environment, char *_timer)
Definition to8.c:281
void to8_keyshift(Environment *_environment, char *_shifts)
Definition to8.c:162
void to8_key_pressed(Environment *_environment, char *_scancode, char *_result)
Definition to8.c:212
void to8_timer_set_status_off(Environment *_environment, char *_timer)
Definition to8.c:296
void to8_joystick_semivars(Environment *_environment, char *_joystick, char *_result)
Definition to8.c:231
void to8_timer_set_address(Environment *_environment, char *_timer, char *_address)
Definition to8.c:345
void to8_xpen(Environment *_environment, char *_destination)
Definition to8.c:44
int to8_screen_mode_enable(Environment *_environment, ScreenMode *_screen_mode)
Definition to8.c:183
void to8_scanshift(Environment *_environment, char *_shifts)
Definition to8.c:156
void to8_inkey(Environment *_environment, char *_pressed, char *_key)
Definition to8.c:82
void to8_scancode(Environment *_environment, char *_pressed, char *_scancode)
Definition to8.c:144
void to8_joystick(Environment *_environment, int _joystick, char *_result)
Definition to8.c:250
void to8_wait_fire(Environment *_environment, int _port, int _release)
Definition to8.c:102
struct _ScreenMode ScreenMode
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_BYTE
Definition ugbc.h:450
#define deploy_preferred(s, e)
Definition ugbc.h:4299
#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