ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
colormap.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
57/* <usermanual>
58@keyword COLORMAP AT
59</usermanual> */
60void colormap_at( Environment * _environment, int _address ) {
61
62
63
64 // Let's define the special variable and fill up with the value.
65 Variable * colormapAddress = variable_retrieve_or_define( _environment, "COLORMAPADDRESS", VT_ADDRESS, _address );
66
67 // TODO: colormapAddress must be retrieved by a cpc_get_colormapAddress()
68
69 variable_store( _environment, colormapAddress->name, 0x5800 );
70
71}
72
88void colormap_at_var( Environment * _environment, char * _address ) {
89
90
91
92 // Let's define the special variable and fill up with the value.
93 // TODO: colormapAddress must be retrieved by a cpc_get_colormapAddress()
94 Variable * colormapAddress = variable_retrieve_or_define( _environment, "COLORMAPADDRESS", VT_ADDRESS, 0x5800 );
95 Variable * address = variable_retrieve_or_define( _environment, _address, VT_ADDRESS, 0x0000 );
96
97 // variable_store( _environment, colormapAddress->name, ( ( ( _address >> 10 ) & 0x0f ) * 0x0400 ) );
98
99}
100
115void colormap_clear_with( Environment * _environment, int _foreground, int _background ) {
116
117 Variable * colormapAddress = variable_retrieve( _environment, "COLORMAPADDRESS" );
118
119 Variable * value = variable_temporary( _environment, VT_BYTE, "(background + foreground)" );
120 Variable * blocks = variable_temporary( _environment, VT_BYTE, "(blocks)" );
121
122 variable_store( _environment, blocks->name, 3 );
123
124 variable_store( _environment, value->name, ( ( _background & 0x07 ) << 3 ) | ( _foreground & 0x07 ) );
125
126 cpu_fill_blocks( _environment, colormapAddress->realName, blocks->realName, value->realName );
127
128}
129
144void colormap_clear_with_vars( Environment * _environment, char * _foreground, char * _background ) {
145
146 Variable * colormapAddress = variable_retrieve_or_define( _environment, "COLORMAPADDRESS", VT_ADDRESS, 0x0400 );
147
148 Variable * foreground = variable_retrieve_or_define( _environment, _foreground, VT_COLOR, COLOR_WHITE );
149
150 Variable * background = variable_retrieve_or_define( _environment, _background, VT_COLOR, COLOR_BLACK );
151
152 Variable * pattern = variable_temporary( _environment, VT_BYTE, "(pattern)" );
153 Variable * blocks = variable_temporary( _environment, VT_BYTE, "(blocks)" );
154
155 variable_store( _environment, blocks->name, 3 );
156
157 outline1("LD A, (%s)", background->realName );
158 outline0("RL A" );
159 outline0("RL A" );
160 outline0("RL A" );
161 outline0("LD B, A" );
162 outline1("LD A, (%s)", foreground->realName );
163 outline0("AND $07" );
164 outline0("OR B" );
165 outline1("LD (%s), A", pattern->realName );
166
167 cpu_fill_blocks( _environment, colormapAddress->realName, blocks->realName, pattern->realName );
168
169}
170
182void colormap_clear( Environment * _environment ) {
183
184 // Equals to: "COLORMAP CLEAR WITH 0 AND 1"
186
187}
void cpu_fill_blocks(Environment *_environment, char *_address, char *_blocks, char *_pattern)
CPU 6309: emit code to fill up a memory area
Definition 6309.c:484
#define COLOR_WHITE
Definition 6847.h:39
#define COLOR_BLACK
Definition 6847.h:36
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
void colormap_clear_with(Environment *_environment, int _foreground, int _background)
Emit ASM implementation for COLORMAP CLEAR WITH [int]x ON [int]x instruction.
Definition colormap.c:115
void colormap_clear_with_vars(Environment *_environment, char *_foreground, char *_background)
Emit ASM implementation for COLORMAP CLEAR WITH [expression] ON [expression] instruction.
Definition colormap.c:145
void colormap_clear(Environment *_environment)
Emit ASM implementation for COLORMAP CLEAR instruction.
Definition colormap.c:184
void colormap_at_var(Environment *_environment, char *_address)
Emit ASM implementation for COLORMAP AT [expression] instruction.
Definition colormap.c:88
void colormap_at(Environment *_environment, int _address)
Emit ASM implementation for COLORMAP AT [int]x instruction.
Definition colormap.c:60
char * name
Definition ugbc.h:979
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_ADDRESS
Definition ugbc.h:465
@ VT_COLOR
Definition ugbc.h:471
#define outline0(s)
Definition ugbc.h:4252
#define outline1(s, a)
Definition ugbc.h:4253