-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
65 lines (51 loc) · 2.17 KB
/
main.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
// #include "stm32_ub_spectrum.h"
#include <string.h> // memcpy
#include <stdint.h>
#include "z80_lib/Z80.h"
extern uint8_t title_scr[];
extern const int title_scr_len;
void zx_keyboard(void);
//--------------------------------------------------------------
// 64K map of ZX-Spectrum (16k ROM + 48K RAM)
//
// 0x0000 - 0x3FFF : 0x4000 => ROM
// 0x4000 - 0x57FF : 0x1800 => Display RAM (pixels, no color)
// 0x5800 - 0x5AFF : 0x0300 => Attribute RAM (attributes)
// 0x5B00 - 0xFFFF : 0xA500 => Data RAM
//--------------------------------------------------------------
#define INT_TIME 30000/50 // 50Hz interrupts at 30kHz
uint8_t Z80_RAM[0xC000]; // 48k RAM
Z80 myCPU;
uint8_t key_ram[8]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; // Keyboard buffer
uint8_t out_ram; // Output (fe port)
uint8_t kempston_ram; // Kempston-Joystick Buffer
volatile int timer_sync; // synchronization timer
volatile int timer_interrupt; // 50Hz interrupt timer
int turbo=0; // set slow for games, by example, high in basic
uint8_t * volatile VRAM=Z80_RAM; // What will be displayed. Generally ZX VRAM, can be changed for alt screens.
// -------------------------------------------------------------------------------------------------
int bitbox_main(void)
{
// bitbox should already be initialized here
// show init screen art
VRAM = title_scr;
while (timer_interrupt<5*30000); // small delay
VRAM = Z80_RAM;
memset(Z80_RAM, 0, sizeof(Z80_RAM));
ResetZ80(&myCPU);
while (1) {
ExecZ80(&myCPU,3500*6/30); // 3.5MHz ticks for 6 lines @ 30 kHz = 700 cycles
// emulation sync every 6 lines
while (!turbo && timer_sync <= 6);
timer_sync=0;
if (timer_interrupt>INT_TIME) {
IntZ80(&myCPU,INT_IRQ); // must be called every 20ms
zx_keyboard();
// check menu
// refresh frame emu ?
timer_interrupt=0;
}
}
}
// if menu : ... display ce qu'il faut, loade, setup pointer/reset & "continue" ; mode turbo
// prendre la fonte en ROM :)