/
bank_read.c
executable file
·155 lines (132 loc) · 6.38 KB
/
bank_read.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*****************************************************************************
* ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
*****************************************************************************
* Copyright 2021-2023 Marco Spedaletti (asimov@mclink.it)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*----------------------------------------------------------------------------
* Concesso in licenza secondo i termini della Licenza Apache, versione 2.0
* (la "Licenza"); è proibito usare questo file se non in conformità alla
* Licenza. Una copia della Licenza è disponibile all'indirizzo:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Se non richiesto dalla legislazione vigente o concordato per iscritto,
* il software distribuito nei termini della Licenza è distribuito
* "COSÌ COM'È", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o
* implicite. Consultare la Licenza per il testo specifico che regola le
* autorizzazioni e le limitazioni previste dalla medesima.
****************************************************************************/
/****************************************************************************
* INCLUDE SECTION
****************************************************************************/
#include "../../ugbc.h"
/**
* @brief Emit ASM code for instruction <b>BANK READ ...</b>
*
* This function outputs the ASM code to read data from
* a specific bank into the RAM.
*
* @param _environment Current calling environment
* @param _bank bank from read from
* @param _address1 address to read from (0 based)
* @param _address2 address to write to (RAM)
* @param _size size of memory to read/write
*/
/* <usermanual>
@keyword BANK READ
@english
This instruction can be used to read a number of bytes from an
out-of-memory bank in main memory. You must therefore indicate
one of the available banks, the memory address from which you
want to copy (the $0000 implies the beginning of the bank),
the size in bytes and finally the destination address,
which will be the RAM memory.
@italian
Questa istruzione può essere utilizzata per leggere un certo
numero di byte da un banco fuori memoria nella memoria centrale.
Si deve quindi indicare uno dei banchi disponibili, l'indirizzo
di memoria dal quale si vuole copiare (lo $0000 implica l'inizio
del banco), la dimensione in byte ed infine l'indirizzo di
destinazione, che sarà la memoria RAM.
@syntax BANK READ [bank] FROM [address1] TO [address2] SIZE [size]
@example BANK READ 1 FROM $0100 TO $2000 SIZE 128
@target pc128op
</usermanual> */
void bank_read_semi_var( Environment * _environment, int _bank, int _address1, char * _address2, int _size ) {
outline0("; bank read")
Variable * previous = bank_get( _environment );
bank_set( _environment, _bank );
int realAddress = 0x6000 + _address1;
char realAddressAsString[MAX_TEMPORARY_STORAGE];
sprintf(realAddressAsString, "$%4.4x", realAddress);
cpu_mem_move_direct_size( _environment, realAddressAsString, _address2, _size );
bank_set_var( _environment, previous->name );
outline0("; end bank read")
}
/**
* @brief Emit ASM code for instruction <b>BANK READ ...</b>
*
* This function outputs the ASM code to read data from
* a specific bank into the RAM.
*
* @param _environment Current calling environment
* @param _bank bank from read from
* @param _address1 address to read from (0 based)
* @param _address2 address to write to (RAM)
* @param _size size of memory to read/write
*/
/* <usermanual>
@keyword BANK READ
@english
This instruction can be used to read a number of bytes from an
out-of-memory bank in main memory. You must therefore indicate
one of the available banks, the memory address from which you
want to copy (the $0000 implies the beginning of the bank),
the size in bytes and finally the destination address,
which will be the RAM memory.
@italian
Questa istruzione può essere utilizzata per leggere un certo
numero di byte da un banco fuori memoria nella memoria centrale.
Si deve quindi indicare uno dei banchi disponibili, l'indirizzo
di memoria dal quale si vuole copiare (lo $0000 implica l'inizio
del banco), la dimensione in byte ed infine l'indirizzo di
destinazione, che sarà la memoria RAM.
@syntax BANK READ [bank] FROM [address1] TO [address2] SIZE [size]
@example BANK READ 1 FROM $0100 TO $2000 SIZE 128
@target pc128op
</usermanual> */
void bank_read_vars( Environment * _environment, char * _bank, char * _address1, char * _address2, char * _size ) {
outline0("; bank read")
Variable * previous = bank_get( _environment );
bank_set_var( _environment, _bank );
Variable * bankAddress = bank_get_address_var( _environment, _bank );
Variable * address1 = variable_retrieve_or_define( _environment, _address1, VT_ADDRESS, 0 );
Variable * realAddress = variable_add( _environment, bankAddress->name, address1->name );
Variable * address2 = variable_retrieve_or_define( _environment, _address2, VT_ADDRESS, 0 );
mmove_memory_memory( _environment, realAddress->name, address2->name, _size );
bank_set_var( _environment, previous->name );
outline0("; end bank read")
}
void bank_read_vars_direct( Environment * _environment, char * _bank, char * _address1, char * _address2, char * _size ) {
outline0("; bank read direct")
Variable * previous = bank_get( _environment );
bank_set_var( _environment, _bank );
Variable * bankAddress = bank_get_address_var( _environment, _bank );
Variable * address1 = variable_retrieve_or_define( _environment, _address1, VT_ADDRESS, 0 );
Variable * realAddress = variable_add( _environment, bankAddress->name, address1->name );
Variable * size = variable_retrieve_or_define( _environment, _size, VT_WORD, 0 );
cpu_mem_move_direct2( _environment, realAddress->realName, _address2, size->realName );
bank_set_var( _environment, previous->name );
outline0("; end bank read direct")
}