1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-11-16 21:10:58 +00:00
r65emu/hardware.cpp

63 lines
1.2 KiB
C++
Raw Normal View History

2014-10-19 14:19:06 +00:00
#include <UTFT.h>
#include <SD.h>
#include "ps2drv.h"
#include "memory.h"
#include "spiram.h"
2014-10-21 18:41:44 +00:00
#include "cpu.h"
2014-10-19 14:19:06 +00:00
#include "hardware.h"
Memory memory;
PS2Driver ps2;
spiram sram(SPIRAM_SIZE);
UTFT utft(TFT_MODEL, TFT_RS, TFT_WR, TFT_CS, TFT_RST);
2014-10-21 18:41:44 +00:00
static CPU *_cpu;
2014-10-19 14:19:06 +00:00
2014-10-21 18:41:44 +00:00
bool hardware_init(CPU &cpu) {
_cpu = &cpu;
2014-10-19 14:19:06 +00:00
ps2.begin(KBD_DATA, KBD_IRQ);
pinMode(SD_CS, OUTPUT);
bool sd = SD.begin(SD_CS, 3, SD_SPI);
#if defined(TFT_BACKLIGHT)
pinMode(TFT_BACKLIGHT, OUTPUT);
digitalWrite(TFT_BACKLIGHT, HIGH);
#endif
utft.InitLCD();
extern uint8_t SmallFont[];
utft.setFont(SmallFont);
sram.begin(SPIRAM_CS, SPIRAM_SPI);
2014-10-21 18:41:44 +00:00
cpu.reset();
2014-10-19 14:19:06 +00:00
return sd;
}
2014-10-21 18:41:44 +00:00
void hardware_checkpoint(Stream &s) {
2014-10-22 18:47:06 +00:00
unsigned ds = 0;
for (unsigned i = 0; i < 0x10000; i += ds) {
2014-10-21 18:41:44 +00:00
Memory::Device *dev = memory.get(i);
2014-10-22 18:47:06 +00:00
if (dev) {
dev->checkpoint(s);
ds = dev->pages() * Memory::page_size;
} else
ds = Memory::page_size;
2014-10-21 18:41:44 +00:00
}
2014-10-22 18:47:06 +00:00
_cpu->checkpoint(s);
2014-10-21 18:41:44 +00:00
}
void hardware_restore(Stream &s) {
2014-10-22 18:47:06 +00:00
unsigned ds = 0;
for (unsigned i = 0; i < 0x10000; i += ds) {
2014-10-21 18:41:44 +00:00
Memory::Device *dev = memory.get(i);
2014-10-22 18:47:06 +00:00
if (dev) {
dev->restore(s);
ds = dev->pages() * Memory::page_size;
} else
ds = Memory::page_size;
2014-10-21 18:41:44 +00:00
}
2014-10-22 18:47:06 +00:00
_cpu->restore(s);
2014-10-21 18:41:44 +00:00
}