ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
insert.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 INSERT (instruction)
43
44@english
45
46The ''INSERT'' command can draw frames on the screen in text mode. The appearance
47of the frame is determined by the first parameter ''string''. It must contain a
48character string that is exactly nine characters long and consists of the characters
49that define the frame: top left corner, top edge, top right corner, left edge,
50fill character, right edge, bottom left corner, bottom edge, bottom right corner.
51If this string is too long or too short, the behaviour is undefined.
52
53@italian
54
55Il comando ''INSERT'' può disegnare cornici sullo schermo in modalità testo.
56L'aspetto della cornice è determinato dal primo parametro ''string''. Deve contenere
57una stringa di caratteri lunga esattamente nove caratteri e composta dai caratteri
58che definiscono la cornice: angolo in alto a sinistra, bordo in alto, angolo in alto
59a destra, bordo sinistro, carattere di riempimento, bordo destro, angolo in basso a
60sinistra, bordo in basso, angolo in basso a destra. Se questa stringa è troppo lunga
61o troppo corta, il comportamento non è definito.
62
63@syntax INSERT string, x, y, w, h, c
64
65@example INSERT "+-+| |+-+", 0, 0, 10, 10, RED
66
67@usedInExample tsb_insert_01.bas
68
69</usermanual> */
70
71void insert( Environment * _environment, char * _string, char * _x, char * _y, char * _w, char * _h, char * _c ) {
72
74
75 char topLabel[MAX_TEMPORARY_STORAGE]; sprintf( topLabel, "%stop", label );
76 char lineLabel[MAX_TEMPORARY_STORAGE]; sprintf( lineLabel, "%sline", label );
77 char edgeLabel[MAX_TEMPORARY_STORAGE]; sprintf( edgeLabel, "%sedge", label );
78 char bottomLabel[MAX_TEMPORARY_STORAGE]; sprintf( bottomLabel, "%sbottom", label );
79
80 Variable * string = variable_retrieve( _environment, _string );
81 Variable * x = variable_retrieve_or_define( _environment, _x, VT_BYTE, 0 );
82 Variable * y = variable_retrieve_or_define( _environment, _y, VT_BYTE, 0 );
83 Variable * w = variable_retrieve_or_define( _environment, _w, VT_BYTE, 0 );
84 Variable * h = variable_retrieve_or_define( _environment, _h, VT_BYTE, 0 );
85 Variable * c = variable_retrieve_or_define( _environment, _c, VT_COLOR, 0 );
86
87 Variable * tl = variable_string_pick( _environment, _string, 0 );
88 Variable * te = variable_string_pick( _environment, _string, 1 );
89 Variable * tr = variable_string_pick( _environment, _string, 2 );
90 Variable * le = variable_string_pick( _environment, _string, 3 );
91 Variable * fi = variable_string_pick( _environment, _string, 4 );
92 Variable * re = variable_string_pick( _environment, _string, 5 );
93 Variable * bl = variable_string_pick( _environment, _string, 6 );
94 Variable * be = variable_string_pick( _environment, _string, 7 );
95 Variable * br = variable_string_pick( _environment, _string, 8 );
96
97 // With INSERT you can draw frames on the screen in text mode. The appearance of the frame
98 // is determined by the first parameter <string>. It must contain a character string that is
99 // exactly nine characters long and consists of the characters that define the frame: top left corner,
100 // top edge, top right corner, left edge, fill character, right edge, bottom left corner, bottom edge,
101 // bottom right corner. If this string is too long or too short, TSB reports an ILLEGAL QUANTITY ERROR.
102
103 Variable * i = variable_temporary( _environment, VT_BYTE, "(i)" );
104 Variable * j = variable_temporary( _environment, VT_BYTE, "(j)" );
105
106 pen( _environment, c->name );
107
108 locate( _environment, x->name, y->name );
109 print( _environment, tl->name, 0, _environment->printRaw );
110 variable_move( _environment, w->name, i->name );
111 variable_decrement( _environment, i->name );
112 variable_decrement( _environment, i->name );
113 cpu_label( _environment, topLabel );
114 print( _environment, te->name, 0, _environment->printRaw );
115 variable_decrement( _environment, i->name );
116 variable_compare_and_branch_const( _environment, i->name, 0, topLabel, _environment->printRaw );
117 print( _environment, tr->name, 1, _environment->printRaw );
118
119 variable_move( _environment, h->name, j->name );
120 variable_decrement( _environment, j->name );
121 variable_decrement( _environment, j->name );
122 cpu_label( _environment, lineLabel );
123 locate( _environment, x->name, NULL );
124 variable_move( _environment, w->name, i->name );
125 variable_decrement( _environment, i->name );
126 variable_decrement( _environment, i->name );
127 print( _environment, le->name, 0, _environment->printRaw );
128 cpu_label( _environment, edgeLabel );
129 print( _environment, fi->name, 0, _environment->printRaw );
130 variable_decrement( _environment, i->name );
131 variable_compare_and_branch_const( _environment, i->name, 0, edgeLabel, 0 );
132 print( _environment, re->name, 1, _environment->printRaw );
133 variable_decrement( _environment, j->name );
134 variable_compare_and_branch_const( _environment, j->name, 0, lineLabel, 0 );
135
136 locate( _environment, x->name, NULL );
137 print( _environment, bl->name, 0, _environment->printRaw );
138 variable_move( _environment, w->name, i->name );
139 variable_decrement( _environment, i->name );
140 variable_decrement( _environment, i->name );
141 cpu_label( _environment, bottomLabel );
142 print( _environment, be->name, 0, _environment->printRaw );
143 variable_decrement( _environment, i->name );
144 variable_compare_and_branch_const( _environment, i->name, 0, bottomLabel, 0 );
145 print( _environment, br->name, 1, _environment->printRaw );
146
147 // The next two parameters specify the location of the top left corner of the frame: <zl> = line
148 // (value range 0 to 23) and <sp> = column (value range 0 to 38).
149 // The following two determine its size: <bt> = width (value range 2 to 40) and <ho> = height (value range 2 to 25). If one of these values ​​is exceeded or undershot, the interpreter reports a BAD MODE ERROR. A width or height of 1 is still possible, but is automatically increased to 2 because otherwise no box can be created. A width or height of 2 omits the edges and only outputs the corners. The last parameter (<f>) defines the color of the frames (value range: 0..15).
150
151}
152
153
154
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
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.
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_pick(Environment *_environment, char *_string, int _position)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
void pen(Environment *_environment, char *_color)
Emit code for PEN ... command.
Definition pen.c:47
void insert(Environment *_environment, char *_string, char *_x, char *_y, char *_w, char *_h, char *_c)
Definition insert.c:71
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
#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