ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
inkb.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
47/* <usermanual>
48@keyword INKB
49
50@english
51
52The ''INKB'' command is used to select one of two colors as the ink color,
53alternatively. If ''value'' is ''TRUE'', ''color1'' will be chosen as the
54color to use. On the contrary, if the ''value'' is ''FALSE'', ''color2''
55will be chosen as the color. If any color is omitted, the color will be not
56changed.
57
58@italian
59
60Il comando ''INKB'' ha lo scopo di selezionare come colore dell'inchiostro
61uno tra due colori, in alternativa. Se il valore di ''value'' è ''TRUE'',
62sarà scelto color1 come colore da utilizzare. Al contrario, se il valore
63è ''FALSE'', sarà scelto ''color2'' come colore. Se uno dei colori viene
64omesso, il colore non sarà comunque modificato.
65
66@syntax INKB value,color1,color2
67
68@example INKB bool,YELLOW,RED
69
70@target all
71</usermanual> */
72
73void inkb( Environment * _environment, char * _value, char * _color1, char * _color2 ) {
74
75 Variable * value = variable_retrieve_or_define( _environment, _value, VT_SBYTE, 0 );
76
77 Variable * color1 = NULL;
78 if ( _color1 ) {
79 color1 = variable_retrieve_or_define( _environment, _color1, VT_COLOR, 0 );
80 };
81
82 Variable * color2 = NULL;
83 if ( _color2 ) {
84 color2 = variable_retrieve_or_define( _environment, _color2, VT_COLOR, 0 );
85 };
86
88
89 char trueColorLabel[MAX_TEMPORARY_STORAGE]; sprintf( trueColorLabel, "%struec", label );
90 char doneColorLabel[MAX_TEMPORARY_STORAGE]; sprintf( doneColorLabel, "%sdone", label );
91
92 cpu_compare_and_branch_8bit_const( _environment, value->realName, 0xff, trueColorLabel, 1 );
93 if ( color2 ) {
94 ink( _environment, color2->name );
95 }
96 cpu_jump( _environment, doneColorLabel );
97
98 cpu_label( _environment, trueColorLabel );
99 if ( color1 ) {
100 ink( _environment, color1->name );
101 }
102
103 cpu_label( _environment, doneColorLabel );
104
105}
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
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_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
void ink(Environment *_environment, char *_color)
Emit code for INK ... command.
Definition ink.c:69
void inkb(Environment *_environment, char *_value, char *_color1, char *_color2)
Emit code for INKB ... command.
Definition inkb.c:73
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_SBYTE
Definition ugbc.h:452
@ VT_COLOR
Definition ugbc.h:471
#define MAKE_LABEL
Definition ugbc.h:3351