ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
vg5000.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 __vg5000__
54
55void vg5000_inkey( Environment * _environment, char * _pressed, char * _key ) {
56
58
59 deploy( scancode, src_hw_vg5000_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 vg5000_joy_vars( Environment * _environment, char * _port, char * _result ) {
75
77
78 deploy( joystick, src_hw_vg5000_joystick_asm );
79
80 outline1("LD A, (%s)", _port );
81 outline0("LD B, A");
82 outline0("CALL JOYSTICK");
83 outline1("LD (%s), A", _result );
84
85}
86
87void vg5000_joy( Environment * _environment, int _port, char * _result ) {
88
90
91 deploy( joystick, src_hw_vg5000_joystick_asm );
92
93 outline1("LD A, $%2.2x", _port );
94 outline0("LD B, A");
95 outline0("CALL JOYSTICK");
96 outline1("LD (%s), A", _result );
97
98}
99
100void vg5000_scancode( Environment * _environment, char * _pressed, char * _scancode ) {
101
103
104 deploy( scancode, src_hw_vg5000_scancode_asm );
105
106 outline0("LD A, 0");
107 outline1("LD (%s), A", _scancode );
108 outline1("LD (%s), A", _pressed );
109 outline0("CALL SCANCODE");
110 outline0("CP 0");
111 outline1("JR Z,%snokey", label);
112 outline1("LD (%s), A", _scancode );
113 outline0("LD A, $FF");
114 outline1("LD (%s), A", _pressed );
115 outhead1("%snokey:", label );
116
117}
118
119void vg5000_key_pressed( Environment * _environment, char *_scancode, char * _result ) {
120
122
123 char nokeyLabel[MAX_TEMPORARY_STORAGE];
124 sprintf( nokeyLabel, "%slabel", label );
125
126 Variable * temp = variable_temporary( _environment, VT_BYTE, "(pressed)" );
127
128 vg5000_scancode( _environment, temp->realName, _result );
129 cpu_compare_8bit( _environment, _result, _scancode, temp->realName, 1 );
130 cpu_compare_and_branch_8bit_const( _environment, temp->realName, 0, nokeyLabel, 1 );
131 cpu_store_8bit( _environment, _result, 0xff );
132 cpu_jump( _environment, label );
133 cpu_label( _environment, nokeyLabel );
134 cpu_store_8bit( _environment, _result, 0x00 );
135 cpu_label( _environment, label );
136
137}
138
139void vg5000_scanshift( Environment * _environment, char * _shifts ) {
140
141 outline0("LD A, ($FBEB)");
142 outline1("LD (%s), A", _shifts );
143
144}
145
146void vg5000_keyshift( Environment * _environment, char * _shifts ) {
147
148 outline0("LD A, ($FBEB)");
149 outline1("LD (%s), A", _shifts );
150
151}
152
153void vg5000_clear_key( Environment * _environment ) {
154
155}
156
157void vg5000_sys_call( Environment * _environment, int _destination ) {
158
159 outline1("CALL $%4.4x", _destination );
160
161}
162
163void vg5000_timer_set_status_on( Environment * _environment, char * _timer ) {
164
165 deploy( timer, src_hw_z80_timer_asm);
166
167 if ( _timer ) {
168 outline1("LD A, (%s)", _timer );
169 outline0("LD B, A" );
170 } else {
171 outline0("LD B, 0" );
172 }
173 outline0("LD A, 1" );
174 outline0("LD C, A" );
175 outline0("CALL TIMERSETSTATUS" );
176
177}
178
179void vg5000_timer_set_status_off( Environment * _environment, char * _timer ) {
180
181 deploy( timer, src_hw_z80_timer_asm);
182
183 if ( _timer ) {
184 outline1("LD A, (%s)", _timer );
185 outline0("LD B, A" );
186 } else {
187 outline0("LD B, 0" );
188 }
189 outline0("LD A, 0" );
190 outline0("LD C, A" );
191 outline0("CALL TIMERSETSTATUS" );
192
193
194}
195
196void vg5000_timer_set_counter( Environment * _environment, char * _timer, char * _counter ) {
197
198 deploy( timer, src_hw_z80_timer_asm);
199
200 if ( _counter ) {
201 outline1("LD A, (%s)", _counter );
202 outline0("LD IXL, A" );
203 outline1("LD A, (%s)", address_displacement( _environment, _counter, "1" ) );
204 outline0("LD IXH, A" );
205 } else {
206 outline0("LD IX, 0" );
207 }
208 if ( _timer ) {
209 outline1("LD A, (%s)", _timer );
210 outline0("LD B, A" );
211 } else {
212 outline0("LD B, 0" );
213 }
214 outline0("CALL TIMERSETCOUNTER" );
215
216}
217
218void vg5000_timer_set_init( Environment * _environment, char * _timer, char * _init ) {
219
220 deploy( timer, src_hw_z80_timer_asm);
221
222 if ( _init ) {
223 outline1("LD A, (%s)", _init );
224 outline0("LD IXL, A" );
225 outline1("LD A, (%s)", address_displacement( _environment, _init, "1" ) );
226 outline0("LD IXH, A" );
227 } else {
228 outline0("LD IX, 0" );
229 }
230 if ( _timer ) {
231 outline1("LD A, (%s)", _timer );
232 outline0("LD B, A" );
233 } else {
234 outline0("LD B, 0" );
235 }
236 outline0("CALL TIMERSETINIT" );
237
238}
239
240void vg5000_timer_set_address( Environment * _environment, char * _timer, char * _address ) {
241
242 deploy( timer, src_hw_z80_timer_asm);
243
244 if ( _address ) {
245 outline1("LD HL, %s", _address );
246 outline0("LD A, L" );
247 outline0("LD IXL, A" );
248 outline0("LD A, H" );
249 outline0("LD IXH, A" );
250 } else {
251 outline0("LD IX, 0" );
252 }
253 if ( _timer ) {
254 outline1("LD A, (%s)", _timer );
255 outline0("LD B, A" );
256 } else {
257 outline0("LD B, 0" );
258 }
259 outline0("CALL TIMERSETADDRESS" );
260
261}
262
263#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
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
void vg5000_key_pressed(Environment *_environment, char *_scancode, char *_result)
Definition vg5000.c:119
void vg5000_timer_set_status_on(Environment *_environment, char *_timer)
Definition vg5000.c:163
void vg5000_inkey(Environment *_environment, char *_pressed, char *_key)
Definition vg5000.c:55
void vg5000_sys_call(Environment *_environment, int _destination)
Definition vg5000.c:157
void vg5000_joy(Environment *_environment, int _port, char *_result)
Definition vg5000.c:87
void vg5000_scanshift(Environment *_environment, char *_shifts)
Definition vg5000.c:139
void vg5000_clear_key(Environment *_environment)
Definition vg5000.c:153
void vg5000_timer_set_address(Environment *_environment, char *_timer, char *_address)
Definition vg5000.c:240
void vg5000_timer_set_counter(Environment *_environment, char *_timer, char *_counter)
Definition vg5000.c:196
void vg5000_scancode(Environment *_environment, char *_pressed, char *_scancode)
Definition vg5000.c:100
void vg5000_timer_set_status_off(Environment *_environment, char *_timer)
Definition vg5000.c:179
void vg5000_keyshift(Environment *_environment, char *_shifts)
Definition vg5000.c:146
void vg5000_joy_vars(Environment *_environment, char *_port, char *_result)
Definition vg5000.c:74
void vg5000_timer_set_init(Environment *_environment, char *_timer, char *_init)
Definition vg5000.c:218