ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
bank_read.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2025 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
49
50void bank_read_semi_var( Environment * _environment, int _bank, int _address1, char * _address2, int _size ) {
51
52 deploy_preferred( bank, src_hw_c128z_bank_asm );
53
54 outline1("LD HL, $%4.4x", (unsigned char) ( _address1 & 0xffff ) );
55 outline1("LD DE, %s", _address2 );
56
57 switch( _size ) {
58 case 1:
59 outline1("LD A, $%2.2x", _bank );
60 outline0("CALL BANKREAD1");
61 _environment->bankAccessOptimization.read1 = 1;
62 break;
63 case 2:
64 outline1("LD A, $%2.2x", _bank );
65 outline0("CALL BANKREAD2");
66 _environment->bankAccessOptimization.read2 = 1;
67 break;
68 case 4:
69 outline1("LD A, $%2.2x", _bank );
70 outline0("CALL BANKREAD4");
71 _environment->bankAccessOptimization.read4 = 1;
72 break;
73 default:
74 outline1("LD BC, $%4.4x", (unsigned short) (_size&0xffff) );
75 outline0("CALL BANKREAD");
76 _environment->bankAccessOptimization.readn = 1;
77 break;
78
79 }
80 outline0("; end bank read");
81
82}
83
96void bank_read_vars( Environment * _environment, char * _bank, char * _address1, char * _address2, char * _size ) {
97
98 deploy_preferred( bank, src_hw_c128z_bank_asm );
99
100 Variable * bank = variable_retrieve_or_define( _environment, _bank, VT_BYTE, 0 );
101 Variable * address1 = variable_retrieve_or_define( _environment, _address1, VT_ADDRESS, 0 );
102 Variable * address2 = variable_retrieve_or_define( _environment, _address2, VT_ADDRESS, 0 );
103 Variable * size = variable_retrieve_or_define( _environment, _size, VT_WORD, 0 );
104
105 outline1("LD HL, (%s)", address1->realName );
106 outline1("LD DE, (%s)", address2->realName );
107 outline1("LD BC, (%s)", size->realName );
108 outline1("LD A, (%s)", bank->realName );
109 outline0("CALL BANKREAD");
110 _environment->bankAccessOptimization.readn = 1;
111
112 outline0("; end bank read");
113
114}
115
116void bank_read_vars_direct( Environment * _environment, char * _bank, char * _address1, char * _address2, char * _size ) {
117
118 deploy_preferred( bank, src_hw_c128z_bank_asm );
119
120 Variable * bank = variable_retrieve_or_define( _environment, _bank, VT_BYTE, 0 );
121 Variable * address1 = variable_retrieve_or_define( _environment, _address1, VT_ADDRESS, 0 );
122 Variable * address2 = variable_retrieve_or_define( _environment, _address2, VT_ADDRESS, 0 );
123 Variable * size = variable_retrieve_or_define( _environment, _size, VT_WORD, 0 );
124
125 outline1("LD HL, (%s)", address1->realName );
126 outline1("LD DE, %s", address2->realName );
127 outline1("LD BC, (%s)", size->realName );
128 outline1("LD A, (%s)", bank->realName );
129 outline0("CALL BANKREAD");
130
131 outline0("; end bank read");
132
133}
134
135void bank_read_vars_direct_size( Environment * _environment, char * _bank, char * _address1, char * _address2, int _size ) {
136
137 deploy_preferred( bank, src_hw_c128z_bank_asm );
138
139 Variable * bank = variable_retrieve_or_define( _environment, _bank, VT_BYTE, 0 );
140 Variable * address1 = variable_retrieve_or_define( _environment, _address1, VT_ADDRESS, 0 );
141 Variable * address2 = variable_retrieve( _environment, _address2 );
142
143 outline1("LD HL, (%s)", address1->realName );
144
145 outline1("LD DE, %s", address2->realName );
146
147 switch( _size ) {
148 case 1:
149 outline1("LD A, (%s)", bank->realName );
150 outline0("CALL BANKREAD1");
151 _environment->bankAccessOptimization.read1 = 1;
152 break;
153 case 2:
154 outline1("LD A, (%s)", bank->realName );
155 outline0("CALL BANKREAD2");
156 _environment->bankAccessOptimization.read2 = 1;
157 break;
158 case 4:
159 outline1("LD A, (%s)", bank->realName );
160 outline0("CALL BANKREAD4");
161 _environment->bankAccessOptimization.read4 = 1;
162 break;
163 default:
164 outline1("LD BC, $%4.4x", (unsigned short) ( _size & 0xffff ) );
165 outline1("LD A, (%s)", bank->realName );
166 outline0("CALL BANKREAD");
167 _environment->bankAccessOptimization.readn = 1;
168 break;
169
170 }
171 outline0("; end bank read");
172
173}
174
175void bank_read_vars_bank_direct_size( Environment * _environment, int _bank, char * _address1, char * _address2, int _size ) {
176
177 deploy_preferred( bank, src_hw_c128z_bank_asm );
178
179 Variable * address1 = variable_retrieve_or_define( _environment, _address1, VT_ADDRESS, 0 );
180 Variable * address2 = variable_retrieve_or_define( _environment, _address2, VT_ADDRESS, 0 );
181
182 outline1("LD HL, (%s)", address1->realName );
183 outline1("LD DE, %s", address2->realName );
184
185 switch( _size ) {
186 case 1:
187 outline1("LD A, $%2.2x", _bank );
188 outline0("CALL BANKREAD1");
189 _environment->bankAccessOptimization.read1 = 1;
190 break;
191 case 2:
192 outline1("LD A, $%2.2x", _bank );
193 outline0("CALL BANKREAD2");
194 _environment->bankAccessOptimization.read2 = 1;
195 break;
196 case 4:
197 outline1("LD A, $%2.2x", _bank );
198 outline0("CALL BANKREAD4");
199 _environment->bankAccessOptimization.read4 = 1;
200 break;
201 default:
202 outline1("LD BC, $%4.4x", (unsigned short) ( _size & 0xffff ) );
203 outline1("LD A, $%2.2x", _bank );
204 outline0("CALL BANKREAD");
205 _environment->bankAccessOptimization.readn = 1;
206 break;
207
208 }
209 outline0("; end bank read");
210
211}
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
int size
Definition _optimizer.c:678
void bank_read_semi_var(Environment *_environment, int _bank, int _address1, char *_address2, int _size)
Emit ASM code for instruction BANK READ ....
Definition bank_read.c:50
void bank_read_vars_bank_direct_size(Environment *_environment, int _bank, char *_address1, char *_address2, int _size)
Definition bank_read.c:218
void bank_read_vars_direct_size(Environment *_environment, char *_bank, char *_address1, char *_address2, int _size)
Definition bank_read.c:169
void bank_read_vars(Environment *_environment, char *_bank, char *_address1, char *_address2, char *_size)
Emit ASM code for instruction BANK READ ....
Definition bank_read.c:107
void bank_read_vars_direct(Environment *_environment, char *_bank, char *_address1, char *_address2, char *_size)
Definition bank_read.c:138
BankAccessOptimization bankAccessOptimization
Definition ugbc.h:3269
char * realName
Definition ugbc.h:982
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_WORD
Definition ugbc.h:455
@ VT_BYTE
Definition ugbc.h:450
@ VT_ADDRESS
Definition ugbc.h:465
#define deploy_preferred(s, e)
Definition ugbc.h:4299
#define outline0(s)
Definition ugbc.h:4252
#define outline1(s, a)
Definition ugbc.h:4253