Skip to content

Commit 88a36ce

Browse files
Add support for REU/GeoRAM for targets c128 and c128z #1224
1 parent 54ada1b commit 88a36ce

File tree

18 files changed

+946
-11
lines changed

18 files changed

+946
-11
lines changed

ugbc/src/hw/c128z.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
#define DEFAULT_PAINT_BUCKET_SIZE 512
134134

135135
#define BANK_COUNT 1
136-
#define BANK_SIZE 4096
136+
#define BANK_SIZE 16384
137137
#define BANK_BASE_ADDRESS 0
138138

139139
#define MAX_AUDIO_CHANNELS 3

ugbc/src/hw/c128z/bank.asm

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
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+
;* BANK ROUTINE ON C=128 using geoRAM *
33+
;* *
34+
;* by Marco Spedaletti *
35+
;* *
36+
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
37+
38+
GEORAMBANK EQU $DFFF
39+
GEORAMPAGE EQU $DFFE
40+
GEORAMSWAP EQU $DE00
41+
42+
GEORAMSETBANK:
43+
PUSH BC
44+
LD BC, GEORAMBANK
45+
OUT (C), A
46+
POP BC
47+
RET
48+
49+
GEORAMSETPAGE:
50+
PUSH BC
51+
LD BC, GEORAMPAGE
52+
OUT (C), A
53+
POP BC
54+
RET
55+
56+
GEORAMWRITEBYTE:
57+
PUSH BC
58+
LD BC, DE
59+
OUT (C), A
60+
POP BC
61+
RET
62+
63+
GEORAMREADBYTE:
64+
PUSH BC
65+
LD BC, HL
66+
IN A, (C)
67+
POP BC
68+
RET
69+
70+
; General read data from geoRAM to memory
71+
; HL: source memory address (0...16KB)
72+
; DE: destination memory address (0...64KB)
73+
; BC: size of data to read (up to 16KB)
74+
BANKREADG:
75+
; First of all, reset the source address from expanded
76+
; memory, since we are going to refer to it in a relative way.
77+
BANKREADGB:
78+
LD A, 42
79+
CALL GEORAMSETBANK
80+
LD (GEORAMBANKSHADOW), A
81+
LD A, H
82+
CALL GEORAMSETPAGE
83+
LD (GEORAMPAGESHADOW), A
84+
85+
LD A, 42
86+
PUSH HL
87+
PUSH DE
88+
LD DE, GEORAMSWAP
89+
LD H, 0
90+
ADD HL, DE
91+
POP DE
92+
BANKREADGBHL1:
93+
BANKREADGBHL2:
94+
CALL GEORAMREADBYTE
95+
LD (DE), A
96+
DEC BC
97+
LD A, B
98+
OR C
99+
CP 0
100+
JR Z, BANKREADGBHDONE
101+
INC HL
102+
INC DE
103+
LD A, L
104+
CP 0
105+
JR NZ, BANKREADGBNSKIPPAGE
106+
LD A, (GEORAMPAGESHADOW)
107+
INC A
108+
LD (GEORAMPAGESHADOW), A
109+
CALL GEORAMSETPAGE
110+
BANKREADGBNSKIPPAGE:
111+
JP BANKREADGBHL1
112+
113+
BANKREADGBHDONE:
114+
RET
115+
116+
; Read 1 byte from geoRAM to memory
117+
; A : bank
118+
; HL: source memory address
119+
; DE: destination memory address
120+
BANKREAD1:
121+
LD (BANKREADGB+1), A
122+
LD BC, 1
123+
JP BANKREADG
124+
125+
; Read 2 byte(s) from geoRAM to memory
126+
; A : bank
127+
; HL: source memory address
128+
; DE: destination memory address
129+
BANKREAD2:
130+
LD (BANKREADGB+1), A
131+
LD BC, 2
132+
JP BANKREADG
133+
134+
; Read 4 byte(s) from geoRAM to memory
135+
; A : bank
136+
; HL: source memory address
137+
; DE: destination memory address
138+
BANKREAD4:
139+
LD (BANKREADGB+1), A
140+
LD BC, 4
141+
JP BANKREADG
142+
143+
; Read n byte(s) from geoRAM to memory
144+
; A : bank
145+
; HL: source memory address
146+
; DE: destination memory address
147+
; BC: size
148+
BANKREAD:
149+
LD (BANKREADGB+1), A
150+
LD A, B
151+
OR C
152+
CP 0
153+
JR Z, BANKREADX
154+
JP BANKREADG
155+
BANKREADX:
156+
RET
157+
158+
; General write data to geoRAM from memory
159+
; HL: source memory address (0...64KB)
160+
; DE: destination memory address (0...16KB)
161+
; BC: size of data to read (up to 16KB)
162+
BANKWRITEG:
163+
; First of all, reset the source address from expanded
164+
; memory, since we are going to refer to it in a relative way.
165+
BANKWRITEGB:
166+
LD A, 42
167+
CALL GEORAMSETBANK
168+
LD (GEORAMBANKSHADOW), A
169+
LD A, D
170+
CALL GEORAMSETPAGE
171+
LD (GEORAMPAGESHADOW), A
172+
173+
LD D, 0
174+
ADD DE, GEORAMSWAP
175+
BANKWRITEGBHL1:
176+
BANKWRITEGBHL2:
177+
LD A, (HL)
178+
CALL GEORAMWRITEBYTE
179+
DEC BC
180+
LD A, B
181+
OR C
182+
CP 0
183+
JR Z, BANKWRITEGBHDONE
184+
INC HL
185+
INC DE
186+
LD A, L
187+
CP 0
188+
JR NZ, BANKWRITEGBNSKIPPAGE
189+
LD A, (GEORAMPAGESHADOW)
190+
INC A
191+
LD (GEORAMPAGESHADOW), A
192+
CALL GEORAMSETPAGE
193+
BANKWRITEGBNSKIPPAGE:
194+
JP BANKWRITEGBHL1
195+
196+
BANKWRITEGBHDONE:
197+
RET
198+
199+
; Write 1 byte(s) to geoRAM from memory
200+
; A : bank
201+
; HL: source memory address
202+
; DE: destination memory address
203+
BANKWRITE1:
204+
LD (BANKWRITEGB+1), A
205+
LD BC, 1
206+
JP BANKWRITEG
207+
208+
; Write 2 byte(s) to geoRAM from memory
209+
; A : bank
210+
; HL: source memory address
211+
; DE: destination memory address
212+
BANKWRITE2:
213+
LD (BANKWRITEGB+1), A
214+
LD BC, 2
215+
JP BANKWRITEG
216+
217+
; Write 4 byte(s) to geoRAM from memory
218+
; A : bank
219+
; HL: source memory address
220+
; DE: destination memory address
221+
BANKWRITE4:
222+
LD (BANKWRITEGB+1), A
223+
LD BC, 4
224+
JP BANKWRITEG
225+
226+
; Write n byte(s) to geoRAM from memory
227+
; A : bank
228+
; TMPPTR: source memory address
229+
; TMPPTR2: destination memory address
230+
; MATHPTR0-MATHPTR1: size
231+
BANKWRITE:
232+
LD (BANKWRITEGB+1), A
233+
LD A, B
234+
OR C
235+
JR Z, BANKWRITEX
236+
JP BANKWRITEG
237+
BANKWRITEX:
238+
RET

ugbc/src/targets/c128z/_init.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,44 @@ void target_initialization( Environment * _environment ) {
4646

4747
// MEMORY_AREA_DEFINE( MAT_RAM, 0xd000, 0xdff0 );
4848

49-
banks_init( _environment );
49+
int bankCount = 0;
50+
int * bankIds = NULL;
51+
int bankSize = 0x4000;
52+
53+
// 512 kB 0–31 $00–$1f
54+
// 1024 kB 0–63 $00–$3f
55+
// 2048 kB 0–127 $00–$7f
56+
// 4096 kB 0–255 $00–$ff
57+
58+
switch( _environment->ramSize ) {
59+
case 512:
60+
bankCount = 32;
61+
break;
62+
case 1024:
63+
bankCount = 64;
64+
break;
65+
case 2048:
66+
bankCount = 128;
67+
break;
68+
case 4096:
69+
bankCount = 256;
70+
break;
71+
default:
72+
bankCount = 0;
73+
break;
74+
}
75+
76+
if ( bankCount ) {
77+
bankIds = malloc( sizeof( int ) * bankCount );
78+
79+
for( int i=0; i<bankCount; ++i ) {
80+
bankIds[i] = bankCount-i-1;
81+
}
82+
83+
_environment->compressionForbidden = 1;
84+
85+
banks_init_extended( _environment, bankIds, bankCount, bankSize );
86+
}
5087

5188
// _environment->audioConfig.async = 1;
5289

@@ -101,6 +138,13 @@ void target_initialization( Environment * _environment ) {
101138
variable_import( _environment, "DOJOERROR", VT_BYTE, 0 );
102139
variable_global( _environment, "DOJOERROR" );
103140

141+
variable_import( _environment, "GEORAMBANKSHADOW", VT_BYTE, 0 );
142+
variable_global( _environment, "GEORAMBANKSHADOW" );
143+
variable_import( _environment, "GEORAMSWAPSHADOW", VT_BYTE, 0 );
144+
variable_global( _environment, "GEORAMSWAPSHADOW" );
145+
variable_import( _environment, "GEORAMPAGESHADOW", VT_BYTE, 0 );
146+
variable_global( _environment, "GEORAMPAGESHADOW" );
147+
104148
bank_define( _environment, "VARIABLES", BT_VARIABLES, 0x5000, NULL );
105149
bank_define( _environment, "TEMPORARY", BT_TEMPORARY, 0x5100, NULL );
106150

ugbc/src/targets/c128z/_var.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,6 @@ void variable_cleanup( Environment * _environment ) {
439439

440440
generate_cgoto_address_table( _environment );
441441

442-
banks_generate( _environment );
443-
444442
for(i=0; i<BANK_TYPE_COUNT; ++i) {
445443
Bank * actual = _environment->banks[i];
446444
while( actual ) {

ugbc/src/targets/c128z/bank_get.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
37+
#if defined(__c128z__)
38+
39+
/**
40+
* @brief Emit ASM code for instruction <b>= BANK( )</b>
41+
*
42+
* This function outputs the ASM code to get the current
43+
* expansion bank index.
44+
*
45+
* @param _environment Current calling environment
46+
* @return Current number of the bank selected
47+
*/
48+
Variable * bank_get( Environment * _environment ) {
49+
50+
Variable * result = variable_temporary( _environment, VT_BYTE, "(bank number)" );
51+
52+
variable_move( _environment, "GEORAMBANKSHADOW", result->name );
53+
54+
return result;
55+
56+
}
57+
58+
#endif

0 commit comments

Comments
 (0)