ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
bar.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
51/* <usermanual>
52@keyword BAR
53
54@english
55
56The ''BAR'' instruction will draw a filled rectangle on the screen, specifying the
57coordinates of its opposite corners. The ''x1'' and ''y1'' are the left top
58coordinates, while the ''x2'' and ''y2'' are the right bottom coordinates.
59
60The fill color could be the one predefined, or specified by additional parameter.
61The start or the final coordinates can be omitted: in this case, ugBASIC will draw,
62respectively, starting from the last drawn position and arriving at the last drawn
63position.
64
65Drawing (and filling) rectangles is a common operation in graphics. A dedicated command would
66make the code more concise and readable. Filled rectangles can be used to create buttons,
67text boxes, and other interface elements. The ''BAR'' command could be used as a basis
68for creating more complex shapes.
69
70@italian
71
72L'istruzione ''BAR'' disegnerà un rettangolo pieno sullo schermo, specificando
73le coordinate dei suoi angoli opposti. ''x1'' e ''y1'' sono le coordinate in alto
74a sinistra, mentre ''x2'' e ''y2'' sono le coordinate in basso a destra.
75Il colore di riempimento potrebbe essere quello predefinito o specificato da un
76parametro aggiuntivo.
77
78Le coordinate di inizio o fine possono essere omesse: in questo caso, ugBASIC disegnerà,
79rispettivamente, partendo dall'ultima posizione disegnata e arrivando all'ultima posizione
80disegnata.
81
82Disegnare (e riempire) rettangoli è un'operazione comune nella grafica. Un comando
83dedicato renderebbe il codice più conciso e leggibile. I rettangoli pieni possono
84essere utilizzati per creare pulsanti, caselle di testo e altri elementi
85dell'interfaccia. Il comando ''BAR'' potrebbe essere utilizzato come base per
86creare forme più complesse.
87
88@syntax BAR [x1], [y1], [x2], [y2], [c]
89@syntax BAR [x1], [y1] TO [x2], [y2]
90@syntax BAR TO [x2], [y2][, c ]
91
92@example BAR 10,10,100,100,WHITE
93@example BAR TO 100,100
94@example BAR ,10 TO ,100
95
96@usedInExample graphics_lines_03.bas
97
98@target all
99</usermanual> */
100void bar( Environment * _environment, char * _x0, char * _y0, char * _x1, char * _y1, char * _c, int _preserve_color ) {
101
102 deploy_begin( bar );
103
105
106 Variable * x0 = variable_define( _environment, "bar__x0", VT_POSITION, 0 );
107 Variable * y0 = variable_define( _environment, "bar__y0", VT_POSITION, 0 );
108 Variable * x1 = variable_define( _environment, "bar__x1", VT_POSITION, 0 );
109 Variable * y1 = variable_define( _environment, "bar__y1", VT_POSITION, 0 );
110 Variable * c = variable_define( _environment, "bar__c", VT_COLOR, 0 );
111
112 Variable * yOrdered = variable_less_than( _environment, y0->name, y1->name, 1 );
113 Variable * y = variable_resident( _environment, VT_POSITION, "(y)" );
114
115 char labelOrdered[MAX_TEMPORARY_STORAGE]; sprintf(labelOrdered, "%slo", label );
116 char labelRepeat[MAX_TEMPORARY_STORAGE]; sprintf(labelRepeat, "%srp", label );
117
118 cpu_bvneq( _environment, yOrdered->realName, labelOrdered );
119
120 variable_move( _environment, y0->name, y->name );
121 variable_move( _environment, y1->name, y0->name );
122 variable_move( _environment, y->name, y1->name );
123
124 cpu_label( _environment, labelOrdered );
125
126 Variable * dy = variable_sub( _environment, y1->name, y0->name );
127
128 // If we are compiling "Beyond The Door" game with a recent
129 // version of the compiler (>1.17), we must guarantee that
130 // bar will be drawn with +1 pixel vertically.
131 if ( _environment->vestigialConfig.rchack_btd_1171 ) {
132 variable_increment( _environment, dy->name );
133 }
134
135 variable_move( _environment, y0->name, y->name );
136
137 cpu_label( _environment, labelRepeat );
138
139 draw( _environment, x0->name, y->name, x1->name, y->name, c->name, _preserve_color );
140 variable_increment( _environment, y->name );
141 variable_decrement( _environment, dy->name );
142 variable_compare_and_branch_const( _environment, dy->name, 0, labelRepeat, 0 );
143
144 cpu_return( _environment );
145
146 deploy_end( bar );
147
148 Variable * x0 = variable_retrieve_or_define( _environment, _x0, VT_POSITION, 0 );
149 Variable * y0 = variable_retrieve_or_define( _environment, _y0, VT_POSITION, 0 );
150 Variable * x1 = variable_retrieve_or_define( _environment, _x1, VT_POSITION, 0 );
151 Variable * y1 = variable_retrieve_or_define( _environment, _y1, VT_POSITION, 0 );
152 Variable * c = NULL;
153 if ( _c ) {
154 c = variable_retrieve_or_define( _environment, _c, VT_COLOR, 0 );
155 }
156
157 Variable * dx0 = variable_retrieve( _environment, "bar__x0" );
158 Variable * dy0 = variable_retrieve( _environment, "bar__y0" );
159 Variable * dx1 = variable_retrieve( _environment, "bar__x1" );
160 Variable * dy1 = variable_retrieve( _environment, "bar__y1" );
161 Variable * dc = variable_retrieve( _environment, "bar__c" );
162
163 variable_move( _environment, x0->name, dx0->name );
164 variable_move( _environment, y0->name, dy0->name );
165 variable_move( _environment, x1->name, dx1->name );
166 variable_move( _environment, y1->name, dy1->name );
167
168 if ( c ) {
169 variable_move( _environment, c->name, dc->name );
170 } else {
171 variable_move( _environment, "PEN", dc->name );
172 }
173
174 cpu_call( _environment, "lib_bar");
175
176}
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_call(Environment *_environment, char *_label)
Definition 6309.c:3755
void cpu_bvneq(Environment *_environment, char *_value, char *_label)
Definition 6309.c:345
void cpu_return(Environment *_environment)
Definition 6309.c:4030
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
void variable_decrement(Environment *_environment, char *_source)
Decrement a variable by one.
Variable * variable_less_than(Environment *_environment, char *_source, char *_destination, int _equal)
Compare two variable and return the result of comparation.
void variable_compare_and_branch_const(Environment *_environment, char *_source, int _destination, char *_name, int _positive)
Variable * variable_move(Environment *_environment, char *_source, char *_destination)
Store the value of a variable inside another variable by converting it.
void variable_increment(Environment *_environment, char *_source)
Increment a variable by one.
Variable * variable_resident(Environment *_environment, VariableType _type, char *_meaning)
Variable * variable_define(Environment *_environment, char *_name, VariableType _type, int _value)
Define a variable for the program.
Variable * variable_sub(Environment *_environment, char *_source, char *_dest)
Make a differenze between two variable and return the difference of them.
void bar(Environment *_environment, char *_x0, char *_y0, char *_x1, char *_y1, char *_c, int _preserve_color)
Emit ASM code to implement BAR command.
Definition bar.c:100
void draw(Environment *_environment, char *_x0, char *_y0, char *_x1, char *_y1, char *_c, int _preserve_color)
Emit ASM code to implement DRAW command.
Definition draw.c:153
VestigialConfig vestigialConfig
Definition ugbc.h:2442
char * name
Definition ugbc.h:979
char * realName
Definition ugbc.h:982
char rchack_btd_1171
Definition ugbc.h:2025
#define deploy_end(s)
Definition ugbc.h:4365
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_POSITION
Definition ugbc.h:468
@ VT_COLOR
Definition ugbc.h:471
#define deploy_begin(s)
Definition ugbc.h:4356
#define MAKE_LABEL
Definition ugbc.h:3351