23
23
#include < esp_task_wdt.h>
24
24
25
25
// EXTERN VARS
26
- extern boolean writeScreen;
27
26
extern boolean cfg_slog_on;
28
27
extern String cfg_ram_file;
29
28
extern String cfg_rom_set;
@@ -51,20 +50,15 @@ void errorHalt(String);
51
50
void mount_spiffs ();
52
51
53
52
// GLOBALS
54
- // volatile byte *bank0;
55
53
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;
64
60
const int SAMPLING_RATE = 44100 ;
65
61
const int BUFFER_SIZE = 2000 ;
66
- AudioSystem audioSystem (SAMPLING_RATE, BUFFER_SIZE);
67
- AudioOutput audioOutput;
68
62
69
63
// SETUP *************************************
70
64
@@ -73,7 +67,7 @@ VGA3Bit vga;
73
67
#endif
74
68
75
69
#ifdef COLOUR_16
76
- VGA14Bit vga;
70
+ VGA14BitI vga;
77
71
#endif
78
72
79
73
void setup () {
@@ -91,51 +85,51 @@ void setup() {
91
85
vga.init (vga.MODE360x200 , redPin, greenPin, bluePin, hsyncPin, vsyncPin);
92
86
#endif
93
87
94
- #ifdef COLOUR_16
95
- vga.init (vga.MODE360x200 , redPins, greenPins, bluePins, hsyncPin, vsyncPin);
96
- #endif
97
-
98
- vga.clear (0 );
99
-
100
88
Serial.printf (" HEAP BEGIN %d\n " , ESP.getFreeHeap ());
101
89
102
- // rom0= (byte *)malloc(16384);
103
90
#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 );
104
104
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);
109
105
#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
+
114
120
#endif
115
121
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
117
125
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);
136
128
#endif
137
129
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 );
139
133
140
134
mount_spiffs ();
141
135
config_read ();
@@ -174,6 +168,7 @@ void setup() {
174
168
if (cfg_ram_file.compareTo (NO_RAM_FILE) < 0 ) {
175
169
load_ram (" /sna/" + cfg_ram_file);
176
170
}
171
+ Serial.println (" End of setup" );
177
172
}
178
173
179
174
// VIDEO core 0 *************************************
@@ -186,9 +181,14 @@ void videoTask(void *parameter) {
186
181
unsigned int ts1, ts2;
187
182
word zx_fore_color, zx_back_color, tmp_color;
188
183
byte active_latch;
189
-
184
+ byte *video_ram = (byte *) malloc ( 16384 );
190
185
while (1 ) {
191
186
187
+ if (video_latch)
188
+ memcpy (video_ram,ram7,16384 );
189
+ else
190
+ memcpy (video_ram,ram5,16384 );
191
+
192
192
while (xULAStop) {
193
193
xULAStopped = true ;
194
194
delay (5 );
@@ -212,20 +212,14 @@ void videoTask(void *parameter) {
212
212
vga.dotFast (bor + 276 , vga_lin, zxcolor (borderTemp, 0 ));
213
213
}
214
214
215
- active_latch = video_latch;
216
215
217
216
for (ff = 0 ; ff < 32 ; ff++) // foreach byte in line
218
217
{
219
218
220
219
byte_offset = (vga_lin - 3 ) * 32 + ff; // *2+1;
221
220
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];
229
223
calc_y = calcY (byte_offset);
230
224
231
225
for (i = 0 ; i < 8 ; i++) // foreach pixel within a byte
@@ -255,19 +249,15 @@ void videoTask(void *parameter) {
255
249
}
256
250
tick = 1 ;
257
251
ts2 = millis ();
252
+
253
+
258
254
TIMERG0.wdt_wprotect = TIMG_WDT_WKEY_VALUE;
259
255
TIMERG0.wdt_feed = 1 ;
260
256
TIMERG0.wdt_wprotect = 0 ;
261
257
// Serial.printf("ULA: %d\n", ts2 - ts1);
262
258
if (ts2 - ts1 < 20 )
263
- delay (20 - (ts2 - ts1));
259
+ delay (20 - (ts2 - ts1));
264
260
}
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));
271
261
}
272
262
273
263
// SPECTRUM SCREEN DISPLAY
@@ -389,7 +379,8 @@ void do_keyboard() {
389
379
+-------------+
390
380
*/
391
381
void loop () {
392
- while (1 ) {
382
+
383
+ // Serial.println("Loop");
393
384
do_keyboard ();
394
385
do_OSD ();
395
386
// Z80Emulate(&_zxCpu, _next_total - _total, &_zxContext);
@@ -398,5 +389,5 @@ void loop() {
398
389
TIMERG0.wdt_feed = 1 ;
399
390
TIMERG0.wdt_wprotect = 0 ;
400
391
vTaskDelay (0 ); // important to avoid task watchdog timeouts - change this to slow down emu
401
- }
392
+
402
393
}
0 commit comments