ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
fill.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
41/* <usermanual>
42@keyword FILL SCREEN (instruction)
43
44@english
45
46The ''FILL SCREEN'' command allows you to fill the screen with a particular character.
47
48@italian
49
50Il comando ''FILL SCREEN'' permette di riempire lo schermo con un carattere specifico.
51
52@syntax FILL SCREEN x,y,w,h,char,color
53
54@example FILL SCREEN 0, 0, COLUMNS / 2, ROWS / 2, ASC('A'), RED
55
56@target all
57</usermanual> */
58void fill( Environment * _environment, char * _x, char * _y, char * _w, char * _h, char * _char, char * _color ) {
59
61
62 char emptyLabel[MAX_TEMPORARY_STORAGE]; sprintf( emptyLabel, "%sempty", label );
63 char topLabel[MAX_TEMPORARY_STORAGE]; sprintf( topLabel, "%stop", label );
64 char lineLabel[MAX_TEMPORARY_STORAGE]; sprintf( lineLabel, "%sline", label );
65 char edgeLabel[MAX_TEMPORARY_STORAGE]; sprintf( edgeLabel, "%sedge", label );
66 char bottomLabel[MAX_TEMPORARY_STORAGE]; sprintf( bottomLabel, "%sbottom", label );
67
68 Variable * x = variable_retrieve_or_define( _environment, _x, VT_BYTE, 0 );
69 Variable * y = variable_retrieve_or_define( _environment, _y, VT_BYTE, 0 );
70 Variable * w = variable_retrieve_or_define( _environment, _w, VT_BYTE, 0 );
71 Variable * h = variable_retrieve_or_define( _environment, _h, VT_BYTE, 0 );
72 Variable * c = variable_retrieve_or_define( _environment, _color, VT_COLOR, 0 );
73 Variable * ch = variable_string_chr(_environment, variable_retrieve_or_define( _environment, _char, VT_BYTE, 0 )->name );
74
75 Variable * i = variable_temporary( _environment, VT_BYTE, "(i)" );
76 Variable * j = variable_temporary( _environment, VT_BYTE, "(j)" );
77
78 pen( _environment, c->name );
79
80 cpu_compare_and_branch_8bit_const( _environment, h->realName, 0, emptyLabel, 1 );
81 cpu_compare_and_branch_8bit_const( _environment, w->realName, 0, emptyLabel, 1 );
82
83 locate( _environment, x->name, y->name );
84
85 variable_move( _environment, h->name, j->name );
86 cpu_label( _environment, lineLabel );
87 locate( _environment, x->name, NULL );
88 variable_move( _environment, w->name, i->name );
89 cpu_label( _environment, edgeLabel );
90 print( _environment, ch->name, 0, _environment->printRaw );
91 variable_decrement( _environment, i->name );
92 variable_compare_and_branch_const( _environment, i->name, 0, edgeLabel, 0 );
93 print( _environment, NULL, 1, _environment->printRaw );
94 variable_decrement( _environment, j->name );
95 variable_compare_and_branch_const( _environment, j->name, 0, lineLabel, 0 );
96
97 cpu_label( _environment, emptyLabel );
98
99}
100
101
102
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
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.
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.
Variable * variable_string_chr(Environment *_environment, char *_ascii)
Emit code for = CHR( ... ).
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
char * name
Definition _optimizer.c:672
void pen(Environment *_environment, char *_color)
Emit code for PEN ... command.
Definition pen.c:47
void fill(Environment *_environment, char *_x, char *_y, char *_w, char *_h, char *_char, char *_color)
Definition fill.c:58
void locate(Environment *_environment, char *_x, char *_y)
Emit code for LOCATE ...,....
Definition locate.c:110
void print(Environment *_environment, char *_value, int _new_line, int _raw)
Emit code for PRINT... instruction.
Definition print.c:141
int printRaw
Definition ugbc.h:3274
char * name
Definition ugbc.h:979
char * realName
Definition ugbc.h:982
#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
@ VT_COLOR
Definition ugbc.h:471
#define MAKE_LABEL
Definition ugbc.h:3351