ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
c128.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#ifdef __c128__
36
37#include "../ugbc.h"
38
39/****************************************************************************
40 * CODE SECTION
41 ****************************************************************************/
42
43void c128_xpen( Environment * _environment, char * _destination ) {
44
46
47 outline0("LDA $D013");
48 outline0("ASL" );
49 outline1("STA %s", _destination);
50 outline1("BCC %s", label );
51 outline0("LDA #1");
52 outline1("STA _%s", address_displacement(_environment, _destination, "1"));
53 outhead1("%s:", label );
54
55}
56
57void c128_ypen( Environment * _environment, char * _destination ) {
58
60
61 outline0("LDA $d014");
62 outline1("STA %s", _destination);
63 outline0("LDA #0");
64 outline1("STA %s", address_displacement(_environment, _destination, "1"));
65
66}
67
68
69void c128_sys_call( Environment * _environment, int _destination ) {
70
71 _environment->sysCallUsed = 1;
72
73 deploy_preferred( syscall, src_hw_c128_syscall_asm);
74
75 outline0("PHA");
76 outline1("LDA #$%2.2x", (_destination & 0xff ) );
77 outline0("STA SYSCALL0+1");
78 outline1("LDA #$%2.2x", ((_destination>>8) & 0xff ) );
79 outline0("STA SYSCALL0+2");
80 outline0("PLA");
81 outline0("JSR SYSCALL");
82
83}
84
85void c128_timer_set_status_on( Environment * _environment, char * _timer ) {
86
88
89 if ( _timer ) {
90 outline1("LDX %s", _timer );
91 } else {
92 outline0("LDX #0" );
93 }
94 outline0("LDY #$1" );
95 outline0("JSR TIMERSETSTATUS" );
96
97}
98
99void c128_timer_set_status_off( Environment * _environment, char * _timer ) {
100
102
103 if ( _timer ) {
104 outline1("LDX %s", _timer );
105 } else {
106 outline0("LDX #0" );
107 }
108 outline0("LDY #$0" );
109 outline0("JSR TIMERSETSTATUS" );
110
111}
112
113void c128_timer_set_counter( Environment * _environment, char * _timer, char * _counter ) {
114
116
117 if ( _timer ) {
118 outline1("LDX %s", _timer );
119 } else {
120 outline0("LDX #0" );
121 }
122 if ( _counter ) {
123 outline1("LDA %s", _counter );
124 } else {
125 outline0("LDA #0" );
126 }
127 outline0("STA MATHPTR2");
128 if ( _counter ) {
129 outline1("LDA %s", address_displacement( _environment, _counter, "1" ) );
130 }
131 outline0("STA MATHPTR3");
132 outline0("JSR TIMERSETCOUNTER" );
133
134}
135
136void c128_timer_set_init( Environment * _environment, char * _timer, char * _init ) {
137
139
140 if ( _timer ) {
141 outline1("LDX %s", _timer );
142 } else {
143 outline0("LDX #0" );
144 }
145 outline1("LDA %s", _init );
146 outline0("STA MATHPTR2");
147 outline1("LDA %s", address_displacement( _environment, _init, "1" ) );
148 outline0("STA MATHPTR3");
149 outline0("JSR TIMERSETINIT" );
150
151}
152
153void c128_timer_set_address( Environment * _environment, char * _timer, char * _address ) {
154
156
157 if ( _timer ) {
158 outline1("LDX %s", _timer );
159 } else {
160 outline0("LDX #0" );
161 }
162 outline1("LDA #<%s", _address );
163 outline0("STA MATHPTR2");
164 outline1("LDA #>%s", _address );
165 outline0("STA MATHPTR3");
166 outline0("JSR TIMERSETADDRESS" );
167
168}
169
170void c128_dload( Environment * _environment, char * _filename, char * _offset, char * _address, char * _size ) {
171
172 _environment->sysCallUsed = 1;
173
174 deploy_preferred( syscall, src_hw_c128_syscall_asm);
175 deploy_preferred( dcommon, src_hw_c128_dcommon_asm);
176 deploy_preferred( dload, src_hw_c128_dload_asm);
177
179
180 Variable * filename = variable_retrieve( _environment, _filename );
181 Variable * tnaddress = variable_temporary( _environment, VT_ADDRESS, "(address of target_name)");
182 Variable * tnsize = variable_temporary( _environment, VT_BYTE, "(size of target_name)");
183
184 Variable * address = NULL;
185 if ( _address ) {
186 address = variable_retrieve( _environment, _address );
187 }
188 Variable * size = NULL;
189 if ( _size ) {
190 size = variable_retrieve( _environment, _size );
191 }
192
193 switch( filename->type ) {
194 case VT_STRING:
195 cpu_move_8bit( _environment, filename->realName, tnsize->realName );
196 cpu_addressof_16bit( _environment, filename->realName, tnaddress->realName );
197 cpu_inc_16bit( _environment, tnaddress->realName );
198 break;
199 case VT_DSTRING:
200 cpu_dsdescriptor( _environment, filename->realName, tnaddress->realName, tnsize->realName );
201 break;
202 }
203
204 outline1("LDA %s", tnaddress->realName);
205 outline0("STA DCOMMONP1");
206 outline1("LDA %s", address_displacement(_environment, tnaddress->realName, "1"));
207 outline0("STA DCOMMONP1+1");
208 outline1("LDA %s", tnsize->realName);
209 outline0("STA DCOMMON0");
210
211 if ( address ) {
212
213 outline1("LDA %s", address->realName);
214 outline0("STA DCOMMONP2");
215 outline1("LDA %s", address_displacement(_environment, address->realName, "1"));
216 outline0("STA DCOMMONP2+1");
217 outline0("LDA #0");
218 outline0("STA DCOMMON1");
219
220 }
221
222 outline0("JSR C128DLOAD");
223
224}
225
226void c128_dsave( Environment * _environment, char * _filename, char * _offset, char * _address, char * _size ) {
227
228 _environment->sysCallUsed = 1;
229
230 deploy_preferred( syscall, src_hw_c128_syscall_asm);
231 deploy_preferred( dcommon, src_hw_c128_dcommon_asm);
232 deploy_preferred( dsave, src_hw_c128_dsave_asm);
233
235
236 Variable * filename = variable_retrieve( _environment, _filename );
237 Variable * tnaddress = variable_temporary( _environment, VT_ADDRESS, "(address of target_name)");
238 Variable * tnsize = variable_temporary( _environment, VT_BYTE, "(size of target_name)");
239
240 Variable * address = NULL;
241 if ( _address ) {
242 address = variable_retrieve( _environment, _address );
243 }
244 Variable * size = NULL;
245 if ( _size ) {
246 size = variable_retrieve( _environment, _size );
247 }
248
249 switch( filename->type ) {
250 case VT_STRING:
251 cpu_move_8bit( _environment, filename->realName, tnsize->realName );
252 cpu_addressof_16bit( _environment, filename->realName, tnaddress->realName );
253 cpu_inc_16bit( _environment, tnaddress->realName );
254 break;
255 case VT_DSTRING:
256 cpu_dsdescriptor( _environment, filename->realName, tnaddress->realName, tnsize->realName );
257 break;
258 }
259
260 outline1("LDA %s", tnaddress->realName);
261 outline0("STA DCOMMONP1");
262 outline1("LDA %s", address_displacement(_environment, tnaddress->realName, "1"));
263 outline0("STA DCOMMONP1+1");
264 outline1("LDA %s", tnsize->realName);
265 outline0("STA DCOMMON0");
266
267 if ( address ) {
268
269 outline1("LDA %s", address->realName);
270 outline0("STA DCOMMONP2");
271 outline1("LDA %s", address_displacement(_environment, address->realName, "1"));
272 outline0("STA DCOMMONP2+1");
273 outline0("LDA #0");
274 outline0("STA DCOMMON1");
275
276 }
277
278 if ( size ) {
279
280 outline1("LDA %s", size->realName);
281 outline0("STA DCOMMON4");
282 outline1("LDA %s", address_displacement(_environment, size->realName, "1"));
283 outline0("STA DCOMMON5");
284
285 } else {
286
287 outline0("LDA #$ff");
288 outline0("STA DCOMMON4");
289 outline0("STA DCOMMON5");
290
291 }
292
293 outline0("JSR C128DSAVE");
294
295}
296
297void c128_chain( Environment * _environment, char * _filename ) {
298
299 _environment->sysCallUsed = 1;
300 _environment->chainUsed = 1;
301
302 deploy_preferred( syscall, src_hw_c128_syscall_asm);
303 deploy_preferred( dcommon, src_hw_c128_dcommon_asm );
304 deploy_preferred( dload, src_hw_c128_dload_asm );
305 deploy_preferred( chain, src_hw_c128_chain_asm );
306
307 Variable * filename = variable_retrieve( _environment, _filename );
308 Variable * tnaddress = variable_temporary( _environment, VT_ADDRESS, "(address of target_name)");
309 Variable * tnsize = variable_temporary( _environment, VT_BYTE, "(size of target_name)");
310
311 switch( filename->type ) {
312 case VT_STRING:
313 cpu_move_8bit( _environment, filename->realName, tnsize->realName );
314 cpu_addressof_16bit( _environment, filename->realName, tnaddress->realName );
315 cpu_inc_16bit( _environment, tnaddress->realName );
316 break;
317 case VT_DSTRING:
318 cpu_dsdescriptor( _environment, filename->realName, tnaddress->realName, tnsize->realName );
319 break;
320 }
321
322 outline1("LDA %s", tnaddress->realName);
323 outline0("STA DCOMMONP1");
324 outline1("LDA %s", address_displacement(_environment, tnaddress->realName, "1"));
325 outline0("STA DCOMMONP1+1");
326 outline1("LDA %s", tnsize->realName);
327 outline0("STA DCOMMON0");
328 outline0("JMP CHAIN");
329
330}
331
332#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_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
unsigned char src_hw_6502_timer_asm[]
Definition 6502_timer.c:1
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
void chain(Environment *_environment, char *_filename)
Definition chain.c:101
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 c128_dsave(Environment *_environment, char *_filename, char *_offset, char *_address, char *_size)
Definition c128.c:226
void c128_chain(Environment *_environment, char *_filename)
Definition c128.c:297
void c128_timer_set_address(Environment *_environment, char *_timer, char *_address)
Definition c128.c:153
void c128_dload(Environment *_environment, char *_filename, char *_offset, char *_address, char *_size)
Definition c128.c:170
void c128_timer_set_init(Environment *_environment, char *_timer, char *_init)
Definition c128.c:136
void c128_ypen(Environment *_environment, char *_destination)
Definition c128.c:57
void c128_timer_set_counter(Environment *_environment, char *_timer, char *_counter)
Definition c128.c:113
void c128_timer_set_status_on(Environment *_environment, char *_timer)
Definition c128.c:85
void c128_timer_set_status_off(Environment *_environment, char *_timer)
Definition c128.c:99
void c128_sys_call(Environment *_environment, int _destination)
Definition c128.c:69
void c128_xpen(Environment *_environment, char *_destination)
Definition c128.c:43
int chainUsed
Definition ugbc.h:3287
int sysCallUsed
Definition ugbc.h:3162
VariableType type
Definition ugbc.h:988
char * realName
Definition ugbc.h:982
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 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