- Enorme reestructuració del codi per a que el fluxe comence a ser mes racional
- [NEW] mòdul zx_system per a gestionar la vida i canvi de systemes (48K, 128K...)
This commit is contained in:
101
zx_system.cpp
Normal file
101
zx_system.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
#include "zx_system.h"
|
||||
#include "z80.h"
|
||||
#include "zx_mem.h"
|
||||
#include "zx_ula.h"
|
||||
#include "zx_screen.h"
|
||||
#include "zx_tape.h"
|
||||
#include "zx_speaker.h"
|
||||
#include "ay-3-8912.h"
|
||||
#include <vector>
|
||||
|
||||
namespace zx_system
|
||||
{
|
||||
bool resetting = true;
|
||||
bool shutting_down = false;
|
||||
uint8_t current_mode = ZX_48K;
|
||||
uint8_t new_mode = ZX_48K;
|
||||
std::vector<void(*)(uint32_t)> updatables;
|
||||
|
||||
int init(const uint8_t mode)
|
||||
{
|
||||
updatables.clear();
|
||||
z80::clearPorts();
|
||||
resetting = false;
|
||||
switch(mode)
|
||||
{
|
||||
case ZX_NOCHANGE:
|
||||
{
|
||||
z80::reset();
|
||||
break;
|
||||
|
||||
}
|
||||
case ZX_48K:
|
||||
{
|
||||
const uint32_t clock = 3500000;
|
||||
z80::init(clock);
|
||||
z80::connect_port(0xfe, 0x0001, zx_ula::port_in, zx_ula::port_out);
|
||||
mem::init(ZX_48K);
|
||||
zxscreen::init(SCREEN_MODE_48K);
|
||||
speaker::init();
|
||||
speaker::register_source(zx_ula::get_sample);
|
||||
|
||||
registerUpdatable(zx_tape::update);
|
||||
registerUpdatable(speaker::update);
|
||||
//registerUpdatable(zxscreen::refresh);
|
||||
|
||||
return clock / 10;
|
||||
break;
|
||||
}
|
||||
case ZX_128K:
|
||||
{
|
||||
const uint32_t clock = 3546900;
|
||||
z80::init(clock);
|
||||
z80::connect_port(0xfe, 0x0001, zx_ula::port_in, zx_ula::port_out);
|
||||
mem::init(ZX_128K);
|
||||
zxscreen::init(SCREEN_MODE_128K);
|
||||
audio::init();
|
||||
speaker::init();
|
||||
speaker::register_source(zx_ula::get_sample);
|
||||
speaker::register_source(audio::get_sample);
|
||||
|
||||
registerUpdatable(zx_tape::update);
|
||||
registerUpdatable(audio::update);
|
||||
registerUpdatable(speaker::update);
|
||||
//registerUpdatable(zxscreen::refresh);
|
||||
|
||||
return clock / 10;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void reset(const uint8_t mode)
|
||||
{
|
||||
new_mode = mode;
|
||||
resetting = true;
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
shutting_down = true;
|
||||
}
|
||||
|
||||
const bool shuttingDown()
|
||||
{
|
||||
if (resetting) init(new_mode);
|
||||
return shutting_down;
|
||||
}
|
||||
|
||||
void registerUpdatable(void(*callback)(uint32_t))
|
||||
{
|
||||
updatables.push_back(callback);
|
||||
}
|
||||
|
||||
void update(uint32_t dt)
|
||||
{
|
||||
for (auto& call : updatables) call(dt);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user