ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
blit_define.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2024 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
41extern char DATATYPE_AS_STRING[][16];
42
43static void blit_define_bltu( Environment * _environment, int _op, char * _a, char * _c ) {
44
45 if ( _op == ( 1 << _environment->currentModeBW ) + 3 ) {
46
48 outline0("; bltu C = (2^bpp-1) if A > 0 (threshold)");
49 switch( _environment->currentModeBW ) {
50 case 1:
51 outline1("LD A, %s", _a );
52 outline1("LD %s, A", _c );
53 break;
54 }
55 } else if ( _op == ( 1 << _environment->currentModeBW ) + 2 ) {
56 outline0("; bltu C = 0 (ignore)");
57 outline0("LD A, 0" );
58 outline1("LD %s, A", _c );
59 } else if ( _op == ( 1 << _environment->currentModeBW ) + 1 ) {
60 outline0("; bltu C = !A (not)");
61 outline1("LD A, %s", _a );
62 outline0("XOR $ff");
63 outline1("LD %s, A", _c );
64 } else if ( _op == ( 1 << _environment->currentModeBW ) ) {
65 outline0("; bltu C = A (copy)");
66 outline1("LD A, %s", _a );
67 outline1("LD %s, A", _c );
68 } else if ( _op < ( 1 << _environment->currentModeBW ) ) {
69 unsigned char value = 0;
70 switch( _environment->currentModeBW ) {
71 case 1:
72 if ( _op ) {
73 value = 0xff;
74 } else {
75 value = 0x00;
76 }
77 break;
78 }
79 outline0("; bltu C = value");
80 outline1("LD A, $%2.2x", value );
81 outline1("LD %s, A", _c );
82 }
83
84}
85
86static void blit_define_bltb( Environment * _environment, int _op, char * _a, char * _b, char * _d ) {
87
88 if ( _op == 0 ) {
89 outline0("; bltb C = A and B");
90 outline1("LD A, %s", _a );
91 outline1("LD %s, A", _d );
92 outline1("LD A, %s", _b );
93 outline1("AND %s", _d );
94 outline1("LD %s, A", _d );
95 } else if ( _op == 1 ) {
96 outline0("; bltb C = A or B");
97 outline1("LD A, %s", _a );
98 outline1("LD %s, A", _d );
99 outline1("LD A, %s", _b );
100 outline1("OR %s", _d );
101 outline1("LD %s, A", _d );
102 } else if ( _op == 2 ) {
103 outline0("; bltb C = A xor B");
104 outline1("LD A, %s", _a );
105 outline1("LD %s, A", _d );
106 outline1("LD A, %s", _b );
107 outline1("XOR %s", _d );
108 outline1("LD %s, A", _d );
109 } else if ( _op == 3 ) {
110 outline0("; bltb C = A");
111 outline1("LD A, %s", _a );
112 outline1("LD %s, A", _d );
113 } else if ( _op == 4 ) {
114 outline0("; bltb C = B");
115 outline1("LD A, %s", _b );
116 outline1("LD %s, A", _d );
117 } else if ( _op == 5 ) {
118 outline0("; bltb C = A if B>0, 0 if B=0");
120 switch( _environment->currentModeBW ) {
121 case 1:
122 outline1("LD A, %s", _a );
123 outline1("AND %s", _b );
124 outline1("LD %s, A", _d );
125 break;
126 }
127 }
128
129}
130
141void blit_define( Environment * _environment, char * _name, int _sop, int _mop, int _smop, int _iop, int _dop, int _idop, int _top ) {
142
143 char blitLabel[MAX_TEMPORARY_STORAGE]; sprintf( blitLabel, "_%sblit", _name );
144 char skipLabel[MAX_TEMPORARY_STORAGE]; sprintf( skipLabel, "_%sskip", _name );
145
146 cpu_jump( _environment, skipLabel );
147 cpu_label( _environment, blitLabel );
148
149 cpu_return( _environment );
150 cpu_label( _environment, skipLabel );
151
152}
153
154static const char BLIT_SOURCES_REGISTER[][4] = {
155 "IYL", // destination
156 "B", // source 1
157 "IYH", // source 2
158};
159
160void blit_define_begin_compound( Environment * _environment, char * _name ) {
161
162 char blitLabel[MAX_TEMPORARY_STORAGE]; sprintf( blitLabel, "_%sblit", _name );
163 char skipLabel[MAX_TEMPORARY_STORAGE]; sprintf( skipLabel, "_%sskip", _name );
164
165 if ( variable_exists( _environment, _name ) ) {
167 }
168 Variable * var = variable_define( _environment, _name, VT_BLIT, 0 );
169
170 memset( &_environment->blit, 0, sizeof( Blit ) );
171
172 _environment->blit.name = strdup( _name );
173 _environment->blit.realName = strdup( var->realName );
174
175 cpu_jump( _environment, skipLabel );
176 cpu_label( _environment, blitLabel );
177
178 cpu_blit_initialize( _environment );
179
180}
181
182void blit_define_compound_operand_to_register( Environment * _environment, int _register, int _source ) {
183
184 char * reg = cpu_blit_register_name( _environment, _register ) ;
185
186}
187
188void blit_define_compound_unary( Environment * _environment, int _operation, int _operand, int _result ) {
189
190 blit_define_bltu( _environment, _operation, cpu_blit_register_name( _environment, _operand ), cpu_blit_register_name( _environment, _result ) );
191
192}
193
194void blit_define_compound_binary( Environment * _environment, int _operation, int _operand1, int _operand2, int _result ) {
195
196 blit_define_bltb( _environment, _operation, cpu_blit_register_name( _environment, _operand1 ), cpu_blit_register_name( _environment, _operand2 ), cpu_blit_register_name( _environment, _result ) );
197
198}
199
200void blit_define_end_compound( Environment * _environment, int _result ) {
201
202 char skipLabel[MAX_TEMPORARY_STORAGE]; sprintf( skipLabel, "_%sskip", _environment->blit.name );
203 char blitStageAreaName[MAX_TEMPORARY_STORAGE]; sprintf( blitStageAreaName, "%sbs", _environment->blit.name );
204
205 Variable * blitStageArea = variable_define( _environment, blitStageAreaName, VT_BUFFER, 0 );
206 variable_resize_buffer( _environment, blitStageArea->name, _environment->blit.usedMemory );
207
208 char * reg = cpu_blit_register_name( _environment, _result ) ;
209
210 cpu_blit_finalize( _environment );
211
212 cpu_return( _environment );
213 cpu_label( _environment, skipLabel );
214
215}
char * cpu_blit_register_name(Environment *_environment, int _register)
Definition 6309.c:6417
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_blit_finalize(Environment *_environment)
Definition 6309.c:6410
void cpu_jump(Environment *_environment, char *_label)
Definition 6309.c:3739
void cpu_return(Environment *_environment)
Definition 6309.c:4030
void cpu_blit_initialize(Environment *_environment)
Definition 6309.c:6403
int variable_exists(Environment *_environment, char *_name)
Variable * variable_resize_buffer(Environment *_environment, char *_destination, int _size)
Resize the (static) size of a buffer.
Variable * variable_define(Environment *_environment, char *_name, VariableType _type, int _value)
Define a variable for the program.
void blit_define(Environment *_environment, char *_name, int _sop, int _mop, int _smop, int _iop, int _dop, int _idop, int _top)
Emit ASM code for BLIT IMAGE [image] AT [int],[int].
void blit_define_compound_binary(Environment *_environment, int _operation, int _operand1, int _operand2, int _result)
void blit_define_compound_unary(Environment *_environment, int _operation, int _operand, int _result)
void blit_define_begin_compound(Environment *_environment, char *_name)
void blit_define_compound_operand_to_register(Environment *_environment, int _register, int _source)
void blit_define_end_compound(Environment *_environment, int _result)
int usedMemory
Definition ugbc.h:2167
char * name
Definition ugbc.h:2164
char * realName
Definition ugbc.h:2165
Blit blit
Definition ugbc.h:2474
int currentModeBW
Definition ugbc.h:2701
char * name
Definition ugbc.h:979
char * realName
Definition ugbc.h:982
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Blit Blit
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_BLIT
Definition ugbc.h:519
@ VT_BUFFER
Definition ugbc.h:477
#define outline0(s)
Definition ugbc.h:4252
#define CRITICAL_BLIT_ALREADY_DEFINED(n)
Definition ugbc.h:3615
#define outline1(s, a)
Definition ugbc.h:4253
#define MAKE_LABEL
Definition ugbc.h:3351
char DATATYPE_AS_STRING[][16]