ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
color.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
47/* <usermanual>
48@keyword COLOR
49
50@english
51
52The ''COLOR'' command allows you to redefine the colors used by the graphics chipset,
53where this is possible. "Redefinition" means assigning one of the possible colors to
54specific registers called "palette registers".
55
56On some systems this is not possible at all, due to limitations of the chipset or
57the absence of registers: for this reason, in such cases the command is ignored.
58On other systems this corresponds to the modification of specific registers, to which
59one of the available colors is assigned. On others it is possible to assign certain
60shades, which therefore go beyond the number of available colors.
61
62Where it is possible to assign a shade, the value can range from ''0'' to the constant
63''SHADES''. However, it may be more practical to use the ''RGB'' function, which
64allows you to calculate the shade starting from the color components (red, green and blue).
65
66If compatibility with Tuned Simons' BASIC is active, the semantics of the command
67changes, to directly indicate some specific components through a series of syntax
68variants. With the three-parameter variant, you can directly set the colors of the
69border, background and text. With the two-parameter variant, it will be possible to
70indicate the border and the background. With a single parameter, it will be possible
71to indicate the color of the border only. There is also the format where the first
72parameter is omitted, in which case the second indicates the color of the text.
73
74Note that the syntax with one or three parameters is automatically considered as pertaining to TSB.
75
76@italian
77
78Il comando ''COLOR'' permette di ridefinire i colori utilizzati dal chipset grafico,
79laddove questo sia possibile. Per "ridefinizione" si intende l'assegnazione, a
80specifici registri chiamati "palette", di uno dei colori possibili.
81
82Su alcuni sistemi questo non è proprio possibile, a causa delle limitazioni del chipset
83o dell'assenza di registri: ragion per cui, in tali casi il comando viene ignorato.
84Su altri sistemi questo corrisponde alla modifica di specifici registri, a cui
85viene assegnato uno dei colori disponibili. Su altri ancora è possibile assegnare
86determinate sfumature, che vanno quindi oltre il numero di colori disponibili.
87
88Laddove sia possibile assegnare una sfumatura, il valore può andare da ''0'' alla costante
89''SHADES''. Tuttavia, può essere più pratico utilizzare la funzione ''RGB'', che
90permette di calcolare la sfumatura a partire dalle componenti di colore (rosso, verde e blu).
91
92Nel caso sia attiva la compatibilità con il Tuned Simons' BASIC, la semantica del comando
93varia, per indicare direttamente alcune componenti specifiche tramite una serie di varianti
94di sintassi. Con la variante a tre parametri, si possono impostare direttamente i colori
95del bordo, dello sfondo e del testo. Con quella a due parametri, sarà possibile indicare
96il bordo e lo sfondo. Con un singolo parametro, sarà possibile indicare il colore del
97solo bordo. Esiste anche il formato dove il primo parametro è omesso, nel qual caso
98il secondo indicherà il colore del testo.
99
100Da notare che la sintassi con uno o tre parametri è automaticamente considerata
101come afferente a TSB.
102
103@syntax COLOR index, shade
104@syntax COLOR border, background, foreground
105@syntax COLOR [border,][background] (if TSB is enabled)
106@syntax COLOR border
107@syntax COLOR ,foreground
108
109@example COLOR 0, $fff
110
111@alias COLOUR
112@seeAlso COLOR BORDER
113@seeAlso SHADES (constant)
114@seeAlso RGB
115@target c128
116</usermanual> */
117/* <usermanual>
118@keyword COLOUR
119
120@english
121
122@italian
123
124@syntax COLOUR index, shade
125
126@example COLOUR 0, $fff
127
128@alias COLOR
129@seeAlso SHADES (constant)
130@seeAlso RGB
131@target c128
132</usermanual> */
133
134void color( Environment * _environment, int _index, int _shade ) {
135
136 vic2_background_color( _environment, _index, _shade );
137
138}
139
150void color_semivars( Environment * _environment, int _index, char *_shade ) {
151
152 Variable * shade = variable_retrieve_or_define( _environment, _shade, VT_COLOR, 0 );
153
154 vic2_background_color_semivars( _environment, _index, shade->realName );
155
156}
157
168void color_vars( Environment * _environment, char *_index, char *_shade ) {
169
170 Variable * index = variable_retrieve_or_define( _environment, _index, VT_BYTE, 0 );
171 Variable * shade = variable_retrieve_or_define( _environment, _shade, VT_COLOR, 0 );
172
173 vic2_background_color_vars( _environment, index->realName, shade->realName );
174
175}
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
void color_vars(Environment *_environment, char *_index, char *_shade)
Emit ASM code for instruction COLOR [expression], [expression].
Definition color.c:93
void color(Environment *_environment, int _index, int _shade)
Emit ASM code for instruction COLOR [int], [int].
Definition color.c:59
void color_semivars(Environment *_environment, int _index, char *_shade)
Emit ASM code for instruction COLOR [expression], [expression].
Definition color.c:75
char * realName
Definition ugbc.h:982
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
void vic2_background_color_semivars(Environment *_environment, int _index, char *_background_color)
VIC-II: emit code to change background color
Definition vic2.c:719
void vic2_background_color(Environment *_environment, int _index, int _background_color)
VIC-II: emit code to change background color
Definition vic2.c:671
void vic2_background_color_vars(Environment *_environment, char *_index, char *_background_color)
VIC-II: emit code to change background color
Definition vic2.c:691