ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
console.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
37/****************************************************************************
38 * CODE SECTION
39 ****************************************************************************/
40
41void console_init( Environment * _environment ) {
42
43 if (
44 _environment->activeConsole.x1 ||
45 _environment->activeConsole.y1 ||
46 (_environment->activeConsole.x2 != _environment->screenTilesWidth-1) ||
47 (_environment->activeConsole.y2 != _environment->screenTilesHeight-1) ||
48 (_environment->activeConsole.width != _environment->screenTilesWidth) ||
49 (_environment->activeConsole.height != _environment->screenTilesHeight)
50 ) {
51
52 _environment->activeConsole.x1 = 0;
53 _environment->activeConsole.y1 = 0;
54 _environment->activeConsole.x2 = _environment->screenTilesWidth-1;
55 _environment->activeConsole.y2 = _environment->screenTilesHeight-1;
56 _environment->activeConsole.width = _environment->screenTilesWidth;
57 _environment->activeConsole.height = _environment->screenTilesHeight;
58
59 for( int i=0; i<MAX_CONSOLES; ++i ) {
60 _environment->activeConsole.id = i;
61 memcpy( &_environment->consoles[i], &_environment->activeConsole, sizeof( Console ) );
62 }
63
64 _environment->activeConsole.id = 0;
65
66 variable_store( _environment, "XCURSYS", _environment->activeConsole.x1 );
67 variable_store( _environment, "YCURSYS", _environment->activeConsole.y1 );
68
69 console_calculate( _environment );
70
71 variable_store( _environment, "CONSOLEX1", _environment->activeConsole.x1 );
72 variable_store( _environment, "CONSOLEY1", _environment->activeConsole.y1 );
73 variable_store( _environment, "CONSOLEX2", _environment->activeConsole.x2);
74 variable_store( _environment, "CONSOLEY2", _environment->activeConsole.y2 );
75 variable_store( _environment, "CONSOLEW", _environment->activeConsole.width );
76 variable_store( _environment, "CONSOLEH", _environment->activeConsole.height );
77
78 console_calculate( _environment );
79
80 }
81
82}
83
89/* <usermanual>
90@keyword CONSOLE
91
92@english
93The ''CONSOLE'' command allows you to define an area of the screen where the
94text output will take place. This area can be defined in both text and graphical
95mode. Normally, it is set to the entire screen surface, but can be limited with this
96command. This command works only with texts. The parameters describe the four vertices.
97
98Note that the number of rows (''ROWS'') and columns (''COLUMNS'') will be updated conseguently.
99If you need the screen rows and columns, you need to use ''SCREEN ROWS'' and ''SCREEN COLUMNS''.
100
101@italian
102Il comando ''CONSOLE'' permette di define un'area dello schermo dove avverrà
103l'output dei testi. Quest'area può essere definita sia in modalità testuale che grafica.
104Normalmente, viene impostata sull'intera superficie dello schermo, ma può essere
105limitato con questo comando. Questo comando lavora solo con i testi.
106I parametri descrivono i quattro vertici.
107
108Nota che il numero di righe (''ROWS'') e di colonne (''COLUMNS'') saranno di conseguenza allineate.
109Se hai bisogno di avere le righe e le colonne dell'intero schermo, devi usare i comandi
110''SCREEN ROWS'' e ''SCREEN COLUMNS''.
111
112@syntax CONSOLE x1, y1 TO x2, y2
113
114@example CONSOLE 0,0,SCREEN COLUMNS-1,2
115
116@target all
117</usermanual> */
118void console( Environment * _environment, int _x1, int _y1, int _x2, int _y2 ) {
119
120 // - CONSOLE ASSIGNMENT
121 // - X1 = x1
122 // - X2 = x2
123 // - Y1 = y1
124 // - Y2 = y2
125
126 _environment->activeConsole.x1 = _x1;
127 _environment->activeConsole.y1 = _y1;
128 _environment->activeConsole.x2 = _x2;
129 _environment->activeConsole.y2 = _y2;
130
131 // - CONSOLE NORMALIZATION
132 // RULE 1) x2 <> x1 -> X2 = ( SW - 1 )
133
134 if ( _environment->activeConsole.x1 == _environment->activeConsole.x2 ) {
135 _environment->activeConsole.x2 = _environment->screenTilesWidth - 1;
136 }
137
138 // RULE 2) x2 > x1 -> X2 = ( SW - 1 )
139
140 if ( _environment->activeConsole.x1 >= _environment->activeConsole.x2 ) {
141 _environment->activeConsole.x2 = _environment->screenTilesWidth - 1;
142 }
143
144 // RULE 3) x2 < SW -> X2 = ( SW - 1 )
145
146 if ( _environment->activeConsole.x2 >= _environment->screenTilesWidth ) {
147 _environment->activeConsole.x2 = _environment->screenTilesWidth - 1;
148 }
149
150 // RULE 4) ( y2 >= y1 ) -> Y2 = y1
151
152 if ( _environment->activeConsole.y2 < _environment->activeConsole.y1 ) {
153 _environment->activeConsole.y2 = _environment->activeConsole.y1;
154 }
155
156 // - CONSOLE COMPUTATION
157 // - W = ( ( X2 - X1 ) + 1 )
158
159 _environment->activeConsole.width = ( _environment->activeConsole.x2 - _environment->activeConsole.x1 ) + 1;
160
161 // - H = ( ( y2 - y1 ) + 1 )
162
163 _environment->activeConsole.height = ( _environment->activeConsole.y2 - _environment->activeConsole.y1 ) + 1;
164
165 // (+ graphical if needed)
166
167 variable_store( _environment, "XCURSYS", _environment->activeConsole.x1 );
168 variable_store( _environment, "YCURSYS", _environment->activeConsole.y1 );
169
170 console_calculate( _environment );
171
172 variable_store( _environment, "CONSOLEX1", _environment->activeConsole.x1 );
173 variable_store( _environment, "CONSOLEY1", _environment->activeConsole.y1 );
174 variable_store( _environment, "CONSOLEX2", _environment->activeConsole.x2);
175 variable_store( _environment, "CONSOLEY2", _environment->activeConsole.y2 );
176 variable_store( _environment, "CONSOLEW", _environment->activeConsole.width );
177 variable_store( _environment, "CONSOLEH", _environment->activeConsole.height );
178
179}
180
181void console_vars( Environment * _environment, char * _x1, char * _y1, char * _x2, char * _y2 ) {
182
184
185 char consoleX1X2DifferentLabel[MAX_TEMPORARY_STORAGE]; sprintf( consoleX1X2DifferentLabel, "%sx1x2diff", label );
186 char consoleX1LTX2Label[MAX_TEMPORARY_STORAGE]; sprintf( consoleX1LTX2Label, "%sx1ltx2", label );
187 char consoleX1LTSWLabel[MAX_TEMPORARY_STORAGE]; sprintf( consoleX1LTSWLabel, "%sx1ltsw", label );
188 char consoleY2LTY1Label[MAX_TEMPORARY_STORAGE]; sprintf( consoleY2LTY1Label, "%sy2lty1", label );
189
190 Variable * x1 = variable_retrieve_or_define( _environment, _x1, VT_SBYTE, 0 );
191 Variable * y1 = variable_retrieve_or_define( _environment, _y1, VT_SBYTE, 0 );
192 Variable * x2 = variable_retrieve_or_define( _environment, _x2, VT_SBYTE, 0 );
193 Variable * y2 = variable_retrieve_or_define( _environment, _y2, VT_SBYTE, 0 );
194
195 // _environment->consoleSA = 0;
196 // _environment->activeConsole.widthB = 0;
197 // _environment->activeConsole.heightB = 0;
198
199 // - CONSOLE ASSIGNMENT
200 // - X1 = x1
201 // - X2 = x2
202 // - Y1 = y1
203 // - Y2 = y2
204
205 // _environment->activeConsole.x1 = _x1;
206
207 variable_move( _environment, x1->name, "CONSOLEX1" );
208
209 // _environment->activeConsole.y1 = _y1;
210
211 variable_move( _environment, y1->name, "CONSOLEY1" );
212
213 // _environment->activeConsole.x2 = _x2;
214
215 variable_move( _environment, x2->name, "CONSOLEX2" );
216
217 // _environment->activeConsole.y2 = _y2;
218
219 variable_move( _environment, y2->name, "CONSOLEY2" );
220
221 // - CONSOLE NORMALIZATION
222 // RULE 1) x2 <> x1 -> X2 = ( SW - 1 )
223
224 // if ( _environment->activeConsole.x1 == _environment->activeConsole.x2 ) {
225 // _environment->activeConsole.x2 = _environment->screenTilesWidth - 1;
226 // }
227
228 outline0("; compare (a)");
229
231 _environment,
232 variable_compare( _environment, "CONSOLEX1", "CONSOLEX2" )->realName,
233 0,
234 consoleX1X2DifferentLabel,
235 1
236 );
238 _environment,
240 _environment,
241 "CURRENTTILESWIDTH",
242 1 )->name,
243 "CONSOLEX2" );
244 cpu_label( _environment, consoleX1X2DifferentLabel );
245
246 outline0("; compare (b)");
247
248 // RULE 2) x2 > x1 -> X2 = ( SW - 1 )
249
250 // if ( _environment->activeConsole.x1 >= _environment->activeConsole.x2 ) {
251 // _environment->activeConsole.x2 = _environment->screenTilesWidth - 1;
252 // }
253
255 _environment,
256 variable_greater_than( _environment, "CONSOLEX1", "CONSOLEX2", 1 )->realName,
257 0,
258 consoleX1LTX2Label,
259 1
260 );
262 _environment,
264 _environment,
265 "CURRENTTILESWIDTH",
266 1 )->name,
267 "CONSOLEX2" );
268 cpu_label( _environment, consoleX1LTX2Label );
269
270 // RULE 3) x2 < SW -> X2 = ( SW - 1 )
271
272 // if ( _environment->activeConsole.x2 >= _environment->screenTilesWidth ) {
273 // _environment->activeConsole.x2 = _environment->screenTilesWidth - 1;
274 // }
275
277 _environment,
278 variable_greater_than( _environment, "CONSOLEX2", "CURRENTTILESWIDTH", 1 )->realName,
279 0,
280 consoleX1LTSWLabel,
281 1
282 );
284 _environment,
286 _environment,
287 "CURRENTTILESWIDTH",
288 1 )->name,
289 "CONSOLEX2" );
290 cpu_label( _environment, consoleX1LTSWLabel );
291
292 // RULE 4) ( y2 >= y1 ) -> Y2 = y1
293
294 // if ( _environment->activeConsole.y2 > _environment->activeConsole.y1 ) {
295 // _environment->activeConsole.y2 = _environment->activeConsole.y1;
296 // }
297
299 _environment,
300 variable_less_than( _environment, "CONSOLEY2", "CONSOLEY1", 1 )->realName,
301 0,
302 consoleY2LTY1Label,
303 1
304 );
306 _environment,
307 "CONSOLEY1",
308 "CONSOLEY2" );
309 cpu_label( _environment, consoleY2LTY1Label );
310
311 // - CONSOLE COMPUTATION
312 // - W = ( ( X2 - X1 ) + 1 )
313
314 // _environment->activeConsole.width = ( _environment->activeConsole.x2 - _environment->activeConsole.x1 ) + 1;
315
317 _environment,
318 variable_sub( _environment,
319 "CONSOLEX2",
320 "CONSOLEX1" )->name,
321 "CONSOLEW" );
322 cpu_inc( _environment, "CONSOLEW" );
323
324 // - H = ( ( y2 - y1 ) + 1 )
325
326 // _environment->activeConsole.height = ( _environment->activeConsole.y2 - _environment->activeConsole.y1 ) + 1;
327
329 _environment,
330 variable_sub( _environment,
331 "CONSOLEY2",
332 "CONSOLEY1" )->name,
333 "CONSOLEH" );
334 cpu_inc( _environment, "CONSOLEH" );
335
336 // (+ graphical if needed)
337
338 variable_move( _environment, "CONSOLEX1", "XCURSYS" );
339 variable_move( _environment, "CONSOLEY1", "YCURSYS" );
340
341 console_calculate_vars( _environment );
342
343}
void cpu_inc(Environment *_environment, char *_variable)
Definition 6309.c:4555
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
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
void console_calculate_vars(Environment *_environment)
Definition 6847.c:316
void console_calculate(Environment *_environment)
Definition 6847.c:262
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
Variable * variable_less_than(Environment *_environment, char *_source, char *_destination, int _equal)
Compare two variable and return the result of comparation.
Variable * variable_greater_than(Environment *_environment, char *_source, char *_destination, int _equal)
Compare two variable and return the result of comparation.
Variable * variable_move(Environment *_environment, char *_source, char *_destination)
Store the value of a variable inside another variable by converting it.
Variable * variable_sub_const(Environment *_environment, char *_source, int _destination)
Make a differenze between a variable a constant, and return the difference of them.
Variable * variable_sub(Environment *_environment, char *_source, char *_dest)
Make a differenze between two variable and return the difference of them.
Variable * variable_compare(Environment *_environment, char *_source, char *_destination)
Compare two variable and return the result of comparation.
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
char * name
Definition _optimizer.c:672
void console_vars(Environment *_environment, char *_x1, char *_y1, char *_x2, char *_y2)
Definition console.c:181
void console(Environment *_environment, int _x1, int _y1, int _x2, int _y2)
Emit code for CONSOLE.
Definition console.c:118
void console_init(Environment *_environment)
Definition console.c:41
int width
Definition ugbc.h:2209
int id
Definition ugbc.h:2204
int y1
Definition ugbc.h:2206
int x1
Definition ugbc.h:2205
int y2
Definition ugbc.h:2208
int height
Definition ugbc.h:2210
int x2
Definition ugbc.h:2207
int screenTilesWidth
Definition ugbc.h:2880
Console activeConsole
Definition ugbc.h:2910
Console consoles[MAX_CONSOLES]
Definition ugbc.h:2916
int screenTilesHeight
Definition ugbc.h:2885
char * name
Definition ugbc.h:979
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_SBYTE
Definition ugbc.h:452
#define MAX_CONSOLES
Definition ugbc.h:565
struct _Console Console
#define outline0(s)
Definition ugbc.h:4252
#define MAKE_LABEL
Definition ugbc.h:3351