Skip to content
This repository was archived by the owner on Apr 24, 2023. It is now read-only.

Commit 167b9e6

Browse files
committed
14 bit working with PSRAM
1 parent 7809d70 commit 167b9e6

File tree

7 files changed

+114
-114
lines changed

7 files changed

+114
-114
lines changed

include/Emulator/Memory.h

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
//extern byte *rom0;
22

3-
extern volatile byte *rom0;
4-
extern volatile byte *rom1;
5-
extern volatile byte *rom2;
6-
extern volatile byte *rom3;
3+
extern byte *rom0;
4+
extern byte *rom1;
5+
extern byte *rom2;
6+
extern byte *rom3;
77

8-
extern volatile byte* ram0;
9-
extern volatile byte* ram1;
10-
extern volatile byte* ram2;
11-
extern volatile byte* ram3;
12-
extern volatile byte* ram4;
13-
extern volatile byte* ram5;
14-
extern volatile byte* ram6;
15-
extern volatile byte* ram7;
8+
extern byte* ram0;
9+
extern byte* ram1;
10+
extern byte* ram2;
11+
extern byte* ram3;
12+
extern byte* ram4;
13+
extern byte* ram5;
14+
extern byte* ram6;
15+
extern byte* ram7;
1616

17-
extern byte rom_latch,bank_latch,video_latch,paging_lock;
18-
extern byte sp3_mode, sp3_rom, rom_in_use;
19-
void alloc_memory();
17+
extern volatile byte rom_latch,bank_latch,video_latch,paging_lock;
18+
extern volatile byte sp3_mode, sp3_rom, rom_in_use;

include/OSD/osd.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ extern boolean cfg_demo_on;
2626
extern boolean cfg_demo_every;
2727
extern String cfg_arch;
2828
extern String cfg_rom_set;
29-
extern boolean xULAStop;
30-
extern boolean xULAStopped;
29+
extern volatile boolean xULAStop;
30+
extern volatile boolean xULAStopped;
3131

3232
// OSD Interface
3333
// Calc

include/machinedefs.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#define KEYBOARD_DATA 25
44
#define KEYBOARD_CLK 26
55

6-
#define COLOUR_8
7-
//#define COLOUR_16
6+
//#define COLOUR_8
7+
#define COLOUR_16
88

99
#ifdef COLOUR_8
1010
const int redPin = 14;
@@ -25,9 +25,13 @@ const int vsyncPin = 33;
2525
#endif
2626

2727
#ifdef COLOUR_16
28-
const int redPins[] = {2, 4, 12, 13, 14};
29-
const int greenPins[] = {15, 16, 17, 18, 19};
30-
const int bluePins[] = {21, 22, 23, 27};
28+
//const int redPins[] = {2, 4, 12, 13, 14};
29+
//const int greenPins[] = {15, 16, 17, 18, 19};
30+
//const int bluePins[] = {21, 22, 23, 27};
31+
const int redPins[] = {2, 2, 14, 14, 14};
32+
const int greenPins[] = {15, 15, 19, 19, 19};
33+
const int bluePins[] = {21, 21, 27, 27};
34+
3135
const int hsyncPin = 32;
3236
const int vsyncPin = 33;
3337

platformio.ini.linux

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ board_build.mcu = esp32
88

99
; change MCU frequency
1010
board_build.f_cpu = 240000000L
11+
; set frequency to 40MHz
12+
board_build.f_flash = 40000000L
13+
1114

1215
upload_port = /dev/ttyUSB0
1316
upload_protocol = esptool

src/Disk.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ unsigned short countFileEntriesFromDir(String path) {
249249
}
250250

251251
void load_rom(String arch, String romset) {
252-
KB_INT_STOP;
252+
noInterrupts();
253253
String path = "/rom/" + arch + "/" + romset;
254254
Serial.printf("Loading ROMSET '%s'\n", path.c_str());
255255
byte n_roms = countFileEntriesFromDir(path);
@@ -263,27 +263,28 @@ void load_rom(String arch, String romset) {
263263
for (int i = 0; i < rom_f.size(); i++) {
264264
switch (f) {
265265
case 0:
266-
rom0[i] = (byte)rom_f.read();
266+
rom0[i] = rom_f.read();
267267
break;
268268
case 1:
269-
rom1[i] = (byte)rom_f.read();
269+
rom1[i] = rom_f.read();
270270
break;
271271

272272
#ifdef BOARD_HAS_PSRAM
273273

274274
case 2:
275-
rom2[i] = (byte)rom_f.read();
275+
rom2[i] = rom_f.read();
276276
break;
277277
case 3:
278-
rom3[i] = (byte)rom_f.read();
278+
rom3[i] = rom_f.read();
279279
break;
280280
#endif
281281
}
282282
}
283283
rom_f.close();
284+
284285
}
285-
vTaskDelay(2);
286-
KB_INT_START;
286+
287+
interrupts();
287288
}
288289

289290
// Get all sna files

src/Memory.cpp

+21-19
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,26 @@
55

66
void errorHalt(String);
77

8-
volatile byte *rom0;
9-
volatile byte *rom1;
10-
volatile byte *rom2;
11-
volatile byte *rom3;
128

13-
volatile byte *ram0 ;
14-
volatile byte *ram1 ;
15-
volatile byte *ram2 ;
16-
volatile byte *ram3 ;
17-
volatile byte *ram4 ;
18-
volatile byte *ram5 ;
19-
volatile byte *ram6 ;
20-
volatile byte *ram7 ;
219

22-
byte bank_latch=0;
23-
byte video_latch=0;
24-
byte rom_latch=0;
25-
byte paging_lock=0;
26-
byte sp3_mode=0;
27-
byte sp3_rom=0;
28-
byte rom_in_use =0;
10+
byte *rom0;
11+
byte *rom1;
12+
byte *rom2;
13+
byte *rom3;
14+
15+
byte *ram0;
16+
byte *ram1;
17+
byte *ram2;
18+
byte *ram3;
19+
byte *ram4;
20+
byte *ram5;
21+
byte *ram6;
22+
byte *ram7;
23+
24+
volatile byte bank_latch=0;
25+
volatile byte video_latch=0;
26+
volatile byte rom_latch=0;
27+
volatile byte paging_lock=0;
28+
volatile byte sp3_mode=0;
29+
volatile byte sp3_rom=0;
30+
volatile byte rom_in_use =0;

src/ZX-ESPectrum.ino

+57-66
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <esp_task_wdt.h>
2424

2525
// EXTERN VARS
26-
extern boolean writeScreen;
2726
extern boolean cfg_slog_on;
2827
extern String cfg_ram_file;
2928
extern String cfg_rom_set;
@@ -51,20 +50,15 @@ void errorHalt(String);
5150
void mount_spiffs();
5251

5352
// GLOBALS
54-
// volatile byte *bank0;
5553
volatile byte z80ports_in[128];
56-
byte borderTemp = 7;
57-
byte soundTemp = 0;
58-
unsigned int flashing = 0;
59-
byte lastAudio = 0;
60-
boolean xULAStop = false;
61-
boolean xULAStopped = false;
62-
boolean writeScreen = false;
63-
byte tick;
54+
volatile byte borderTemp = 7;
55+
volatile byte flashing = 0;
56+
volatile boolean xULAStop = false;
57+
volatile boolean xULAStopped = false;
58+
volatile boolean writeScreen = false;
59+
volatile byte tick;
6460
const int SAMPLING_RATE = 44100;
6561
const int BUFFER_SIZE = 2000;
66-
AudioSystem audioSystem(SAMPLING_RATE, BUFFER_SIZE);
67-
AudioOutput audioOutput;
6862

6963
// SETUP *************************************
7064

@@ -73,7 +67,7 @@ VGA3Bit vga;
7367
#endif
7468

7569
#ifdef COLOUR_16
76-
VGA14Bit vga;
70+
VGA14BitI vga;
7771
#endif
7872

7973
void setup() {
@@ -91,51 +85,51 @@ void setup() {
9185
vga.init(vga.MODE360x200, redPin, greenPin, bluePin, hsyncPin, vsyncPin);
9286
#endif
9387

94-
#ifdef COLOUR_16
95-
vga.init(vga.MODE360x200, redPins, greenPins, bluePins, hsyncPin, vsyncPin);
96-
#endif
97-
98-
vga.clear(0);
99-
10088
Serial.printf("HEAP BEGIN %d\n", ESP.getFreeHeap());
10189

102-
// rom0= (byte *)malloc(16384);
10390
#ifdef BOARD_HAS_PSRAM
91+
rom0=(byte*) ps_malloc(16384);
92+
rom1=(byte*) ps_malloc(16384);
93+
rom2=(byte*) ps_malloc(16384);
94+
rom3=(byte*) ps_malloc(16384);
95+
96+
ram0=(byte*) ps_malloc(16384);
97+
ram1=(byte*) ps_malloc(16384);
98+
ram2=(byte*) ps_malloc(16384);
99+
ram3=(byte*) ps_malloc(16384);
100+
ram4=(byte*) ps_malloc(16384);
101+
ram5=(byte*) ps_malloc(16384);
102+
ram6=(byte*) ps_malloc(16384);
103+
ram7=(byte*) ps_malloc(16384);
104104

105-
rom0 = (byte *)heap_caps_malloc(16384, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
106-
rom1 = (byte *)heap_caps_malloc(16384, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
107-
rom2 = (byte *)heap_caps_malloc(16384, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
108-
rom3 = (byte *)heap_caps_malloc(16384, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
109105
#else
110-
rom0 = (byte *)malloc(16384);
111-
rom1 = (byte *)malloc(16384);
112-
//rom2 = (byte *)malloc(16384);
113-
//rom3 = (byte *)malloc(16384);
106+
rom0=(byte*) malloc(16384);
107+
rom1=(byte*) malloc(16384);
108+
//rom2=(byte*) malloc(16384);
109+
//rom3=(byte*) malloc(16384);
110+
111+
ram0=(byte*) malloc(16384);
112+
ram1=(byte*) malloc(16384);
113+
ram2=(byte*) malloc(16384);
114+
ram3=(byte*) malloc(16384);
115+
ram4=(byte*) malloc(16384);
116+
ram5=(byte*) malloc(16384);
117+
ram6=(byte*) malloc(16384);
118+
ram7=(byte*) malloc(16384);
119+
114120
#endif
115121

116-
Serial.printf("HEAP after rom: %d\n", ESP.getFreeHeap());
122+
#ifdef COLOUR_8
123+
vga.init(vga.MODE360x200, redPin, greenPin, bluePin, hsyncPin, vsyncPin);
124+
#endif
117125

118-
#ifdef BOARD_HAS_PSRAM
119-
ram0 = (byte *)heap_caps_malloc(16384, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
120-
ram1 = (byte *)heap_caps_malloc(16384, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
121-
ram2 = (byte *)heap_caps_malloc(16384, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
122-
ram3 = (byte *)heap_caps_malloc(16384, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
123-
ram4 = (byte *)heap_caps_malloc(16384, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
124-
ram5 = (byte *)heap_caps_malloc(16384, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
125-
ram6 = (byte *)heap_caps_malloc(16384, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
126-
ram7 = (byte *)heap_caps_malloc(16384, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
127-
#else
128-
ram0 = (byte *)malloc(16384);
129-
ram1 = (byte *)malloc(16384);
130-
ram2 = (byte *)malloc(16384);
131-
ram3 = (byte *)malloc(16384);
132-
ram4 = (byte *)malloc(16384);
133-
ram5 = (byte *)malloc(16384);
134-
ram6 = (byte *)malloc(16384);
135-
ram7 = (byte *)malloc(16384);
126+
#ifdef COLOUR_16
127+
vga.init(vga.MODE360x200, redPins, greenPins, bluePins, hsyncPin, vsyncPin);
136128
#endif
137129

138-
Serial.printf("HEAP after ram %d \n", ESP.getFreeHeap());
130+
Serial.printf("HEAP after vga %d \n", ESP.getFreeHeap());
131+
132+
vga.clear(0);
139133

140134
mount_spiffs();
141135
config_read();
@@ -174,6 +168,7 @@ void setup() {
174168
if (cfg_ram_file.compareTo(NO_RAM_FILE) < 0) {
175169
load_ram("/sna/" + cfg_ram_file);
176170
}
171+
Serial.println("End of setup");
177172
}
178173

179174
// VIDEO core 0 *************************************
@@ -186,9 +181,14 @@ void videoTask(void *parameter) {
186181
unsigned int ts1, ts2;
187182
word zx_fore_color, zx_back_color, tmp_color;
188183
byte active_latch;
189-
184+
byte *video_ram = (byte *) malloc(16384);
190185
while (1) {
191186

187+
if (video_latch)
188+
memcpy(video_ram,ram7,16384);
189+
else
190+
memcpy(video_ram,ram5,16384);
191+
192192
while (xULAStop) {
193193
xULAStopped = true;
194194
delay(5);
@@ -212,20 +212,14 @@ void videoTask(void *parameter) {
212212
vga.dotFast(bor + 276, vga_lin, zxcolor(borderTemp, 0));
213213
}
214214

215-
active_latch = video_latch;
216215

217216
for (ff = 0; ff < 32; ff++) // foreach byte in line
218217
{
219218

220219
byte_offset = (vga_lin - 3) * 32 + ff; //*2+1;
221220

222-
if (!active_latch) {
223-
color_attrib = ram5[0x1800 + (calcY(byte_offset) / 8) * 32 + ff]; // get 1 of 768 attrib values
224-
pixel_map = ram5[byte_offset];
225-
} else {
226-
color_attrib = ram7[0x1800 + (calcY(byte_offset) / 8) * 32 + ff]; // get 1 of 768 attrib values
227-
pixel_map = ram7[byte_offset];
228-
}
221+
color_attrib = video_ram[0x1800 + (calcY(byte_offset) / 8) * 32 + ff]; // get 1 of 768 attrib values
222+
pixel_map = video_ram[byte_offset];
229223
calc_y = calcY(byte_offset);
230224

231225
for (i = 0; i < 8; i++) // foreach pixel within a byte
@@ -255,19 +249,15 @@ void videoTask(void *parameter) {
255249
}
256250
tick = 1;
257251
ts2 = millis();
252+
253+
258254
TIMERG0.wdt_wprotect = TIMG_WDT_WKEY_VALUE;
259255
TIMERG0.wdt_feed = 1;
260256
TIMERG0.wdt_wprotect = 0;
261257
//Serial.printf("ULA: %d\n", ts2 - ts1);
262258
if (ts2 - ts1 < 20)
263-
delay(20 - (ts2 - ts1));
259+
delay(20 - (ts2 - ts1));
264260
}
265-
TIMERG0.wdt_wprotect = TIMG_WDT_WKEY_VALUE;
266-
TIMERG0.wdt_feed = 1;
267-
TIMERG0.wdt_wprotect = 0;
268-
Serial.printf("ULA: %d\n", ts2 - ts1);
269-
if (ts2 - ts1 < 20)
270-
delay(20 - (ts2 - ts1));
271261
}
272262

273263
// SPECTRUM SCREEN DISPLAY
@@ -389,7 +379,8 @@ void do_keyboard() {
389379
+-------------+
390380
*/
391381
void loop() {
392-
while (1) {
382+
383+
//Serial.println("Loop");
393384
do_keyboard();
394385
do_OSD();
395386
// Z80Emulate(&_zxCpu, _next_total - _total, &_zxContext);
@@ -398,5 +389,5 @@ void loop() {
398389
TIMERG0.wdt_feed = 1;
399390
TIMERG0.wdt_wprotect = 0;
400391
vTaskDelay(0); // important to avoid task watchdog timeouts - change this to slow down emu
401-
}
392+
402393
}

0 commit comments

Comments
 (0)