165 lines
5.7 KiB
C++
165 lines
5.7 KiB
C++
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include "z80.h"
|
|
#include "z80dis.h"
|
|
#include "z80debug.h"
|
|
#include "zx_ula.h"
|
|
#include "zx_screen.h"
|
|
#include "zx_tape.h"
|
|
#include <SDL2/SDL.h>
|
|
#include <string.h>
|
|
#include "ui.h"
|
|
#include "ui_menu.h"
|
|
|
|
uint8_t memory[65536];
|
|
uint32_t time = 0;
|
|
uint32_t t_states = 0;
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
FILE* f = fopen("48.rom", "rb");
|
|
fread(memory, 1024, 16, f);
|
|
fclose(f);
|
|
|
|
z80::reset(memory);
|
|
z80::connect_port(0xfe, zx_ula::port_in, zx_ula::port_out);
|
|
|
|
SDL_Init(SDL_INIT_EVERYTHING);
|
|
z80debug::init();
|
|
zxscreen::init();
|
|
|
|
ui::menu::init();
|
|
int menu = ui::menu::addsubmenu("FILE");
|
|
ui::menu::addoption(menu, "LOAD TAPE", nullptr);
|
|
ui::menu::addoption(menu, "SAVE TAPE", nullptr);
|
|
ui::menu::addseparator(menu);
|
|
ui::menu::addoption(menu, "LOAD STATE", nullptr);
|
|
ui::menu::addoption(menu, "SAVE STATE", nullptr);
|
|
menu = ui::menu::addsubmenu("OPTIONS");
|
|
ui::menu::addbooloption(menu, "BERSERK MODE", false, nullptr);
|
|
|
|
zx_ula::sound_init();
|
|
|
|
zx_tape::load("alien8.tap");
|
|
|
|
if (argc==3) { z80debug::loadngo(argv[1], argv[2]); }
|
|
|
|
bool should_exit = false;
|
|
SDL_Event e;
|
|
|
|
time = SDL_GetTicks();
|
|
t_states = 0;
|
|
|
|
while (!should_exit)
|
|
{
|
|
while (SDL_PollEvent(&e))
|
|
{
|
|
if (e.type == SDL_QUIT) { should_exit=true; break; }
|
|
if ((e.type==SDL_WINDOWEVENT) && (e.window.event==SDL_WINDOWEVENT_CLOSE)) {
|
|
should_exit=true; break;
|
|
}
|
|
|
|
if (z80debug::debugging()) {
|
|
if ((e.type==SDL_WINDOWEVENT) && ((e.window.event==SDL_WINDOWEVENT_SHOWN) || (e.window.event==SDL_WINDOWEVENT_EXPOSED))) {
|
|
z80debug::refresh();
|
|
zxscreen::redraw();
|
|
}
|
|
if (e.type == SDL_KEYDOWN) {
|
|
if (e.key.keysym.scancode==SDL_SCANCODE_ESCAPE) {
|
|
should_exit=true; break;
|
|
} else if (e.key.keysym.scancode==SDL_SCANCODE_F10) {
|
|
const uint8_t dt = z80::step();
|
|
z80debug::refresh();
|
|
zxscreen::refresh(dt);
|
|
zxscreen::redraw();
|
|
} else if (e.key.keysym.scancode==SDL_SCANCODE_F11) {
|
|
const uint8_t dt = z80debug::next();
|
|
zxscreen::refresh(dt);
|
|
zxscreen::redraw();
|
|
} else if (e.key.keysym.scancode==SDL_SCANCODE_F5) {
|
|
const uint8_t dt = z80::step();
|
|
z80debug::cont();
|
|
zxscreen::refresh(dt);
|
|
} else if (e.key.keysym.scancode==SDL_SCANCODE_RETURN) {
|
|
z80debug::executeConsole();
|
|
} else if (e.key.keysym.scancode==SDL_SCANCODE_BACKSPACE) {
|
|
z80debug::DeleteCharConsole();
|
|
}
|
|
}
|
|
if (e.type == SDL_TEXTINPUT) {
|
|
z80debug::sendToConsole(e.text.text);
|
|
}
|
|
|
|
} else if (z80debug::paused()) {
|
|
if (e.type == SDL_KEYDOWN) {
|
|
if (e.key.keysym.scancode==SDL_SCANCODE_ESCAPE) {
|
|
const uint8_t dt = z80::step();
|
|
z80debug::cont();
|
|
zxscreen::refresh(dt);
|
|
}
|
|
}
|
|
|
|
} else {
|
|
if (e.type == SDL_KEYDOWN) {
|
|
if (e.key.keysym.scancode==SDL_SCANCODE_ESCAPE) {
|
|
z80debug::pause();
|
|
ui::setrenderer(zxscreen::getrenderer());
|
|
zxscreen::redraw();
|
|
} else if (e.key.keysym.scancode==SDL_SCANCODE_F1) {
|
|
zxscreen::decZoom();
|
|
} else if (e.key.keysym.scancode==SDL_SCANCODE_F2) {
|
|
zxscreen::incZoom();
|
|
} else if (e.key.keysym.scancode==SDL_SCANCODE_F3) {
|
|
zxscreen::toggleFullscreen();
|
|
} else if (e.key.keysym.scancode==SDL_SCANCODE_F8) {
|
|
z80debug::stop();
|
|
zxscreen::redraw();
|
|
} else if (e.key.keysym.scancode==SDL_SCANCODE_F12) {
|
|
zx_tape::go_berserk();
|
|
zx_tape::play();
|
|
} else if (e.key.keysym.scancode==SDL_SCANCODE_F11) {
|
|
zx_tape::rewind();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!z80debug::debugging() && !z80debug::paused()) {
|
|
if (z80debug::isbreak(z80::getPC(), 9)) {
|
|
z80debug::stop();
|
|
zxscreen::redraw();
|
|
} else {
|
|
//if (z80::getPC()==0x05C8) zx_tape::go_berserk();
|
|
uint8_t dt = z80::step();
|
|
t_states += dt;
|
|
zx_tape::update(dt);
|
|
|
|
while (zx_tape::berserk())
|
|
{
|
|
zx_tape::update(z80::step());
|
|
}
|
|
|
|
zx_ula::sound_update(dt);
|
|
zxscreen::refresh(dt);
|
|
|
|
if (t_states>=3500000)
|
|
{
|
|
//if (SDL_GetTicks()>=time+1000)
|
|
//printf("%i\n", SDL_GetTicks()-(time+1000));
|
|
//else
|
|
// printf("%i\n", SDL_GetTicks()-(time+1000));
|
|
//t_states = 0;
|
|
while (SDL_GetTicks()<time+100) {}
|
|
t_states -= 350000;
|
|
time = SDL_GetTicks();
|
|
}
|
|
}
|
|
} else if (z80debug::paused()) {
|
|
zxscreen::redraw(false);
|
|
ui::menu::show();
|
|
zxscreen::present();
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
} |