318 lines
9.8 KiB
C++
318 lines
9.8 KiB
C++
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include "zx_system.h"
|
|
#include "z80.h"
|
|
#include "z80dis.h"
|
|
#include "z80debug.h"
|
|
#include "zx_ula.h"
|
|
#include "zx_speaker.h"
|
|
#include "zx_screen.h"
|
|
#include "zx_tape.h"
|
|
#include <SDL2/SDL.h>
|
|
#include <string.h>
|
|
#include "ui.h"
|
|
#include "ui_menu.h"
|
|
#include "z80analyze.h"
|
|
#include "ui_window.h"
|
|
#include "zx_mem.h"
|
|
#include "z80viewer.h"
|
|
//#include "zx_128bankviewer.h"
|
|
//#include "zx_128pageviewer.h"
|
|
#include "ay-3-8912.h"
|
|
#include "ay_viewer.h"
|
|
#include "file.h"
|
|
#include "gamepad.h"
|
|
#include "zx_dialog_joystick.h"
|
|
|
|
uint32_t time = 0;
|
|
uint32_t t_states = 0;
|
|
|
|
namespace actions
|
|
{
|
|
void exitMenu()
|
|
{
|
|
const uint8_t dt = z80::step();
|
|
z80debug::cont();
|
|
zxscreen::refresh(dt);
|
|
}
|
|
|
|
void exitButNotContinue()
|
|
{
|
|
// do nothing
|
|
}
|
|
|
|
int fastload(int value)
|
|
{
|
|
zx_tape::toggleOption(ZXTAPE_OPTION_FAST_LOAD);
|
|
return zx_tape::getOption(ZXTAPE_OPTION_FAST_LOAD);
|
|
}
|
|
|
|
int stopatend(int value)
|
|
{
|
|
zx_tape::toggleOption(ZXTAPE_OPTION_STOP_AT_END);
|
|
return zx_tape::getOption(ZXTAPE_OPTION_STOP_AT_END);
|
|
}
|
|
|
|
int decZoom(int value)
|
|
{
|
|
zxscreen::decZoom();
|
|
return 0;
|
|
}
|
|
|
|
int incZoom(int value)
|
|
{
|
|
zxscreen::incZoom();
|
|
return 0;
|
|
}
|
|
|
|
int fullscreen(int value)
|
|
{
|
|
zxscreen::toggleFullscreen();
|
|
return zxscreen::getFullscreen();
|
|
}
|
|
|
|
int fullrefresh(int value)
|
|
{
|
|
zxscreen::toggleFullRefresh();
|
|
return zxscreen::getFullRefresh();
|
|
}
|
|
|
|
int showAnalyzer(int value)
|
|
{
|
|
z80analyze::show();
|
|
return 0;
|
|
}
|
|
|
|
int mode48K(int value)
|
|
{
|
|
zx_system::reset(ZX_48K);
|
|
return 0;
|
|
}
|
|
|
|
int mode128K(int value)
|
|
{
|
|
zx_system::reset(ZX_128K);
|
|
return 0;
|
|
}
|
|
|
|
int modePlus3(int value)
|
|
{
|
|
zx_system::reset(ZX_PLUS3);
|
|
return 0;
|
|
}
|
|
|
|
int reset(int value)
|
|
{
|
|
z80::reset();
|
|
return 0;
|
|
}
|
|
|
|
int exit(int value)
|
|
{
|
|
zx_system::shutdown();
|
|
return 0;
|
|
}
|
|
|
|
int configureJoysticks(int value)
|
|
{
|
|
ui::setDialog(dialogs::joysticks::show);
|
|
ui::menu::exitButNotContinue();
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
void init_menu()
|
|
{
|
|
ui::menu::init();
|
|
ui::menu::setexitcallback(actions::exitMenu);
|
|
|
|
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);
|
|
ui::menu::addseparator(menu);
|
|
ui::menu::addoption(menu, "EXIT", actions::exit);
|
|
|
|
menu = ui::menu::addsubmenu("SYSTEM");
|
|
ui::menu::addoption(menu, "ZX 48K", actions::mode48K);
|
|
ui::menu::addoption(menu, "ZX 128K/+2", actions::mode128K);
|
|
ui::menu::addoption(menu, "ZX +2A/+3", actions::modePlus3);
|
|
ui::menu::addseparator(menu);
|
|
ui::menu::addoption(menu, "RESET", actions::reset);
|
|
|
|
menu = ui::menu::addsubmenu("TAPE");
|
|
ui::menu::addbooloption(menu, "FAST LOAD", zx_tape::getOption(ZXTAPE_OPTION_FAST_LOAD), actions::fastload);
|
|
ui::menu::addbooloption(menu, "STOP AT END", zx_tape::getOption(ZXTAPE_OPTION_STOP_AT_END), actions::stopatend);
|
|
|
|
menu = ui::menu::addsubmenu("SCREEN");
|
|
ui::menu::addoption(menu, "DEC ZOOM", actions::decZoom);
|
|
ui::menu::addoption(menu, "INC ZOOM", actions::incZoom);
|
|
ui::menu::addbooloption(menu, "FULLSCREEN", zxscreen::getFullscreen(), actions::fullscreen);
|
|
ui::menu::addseparator(menu);
|
|
ui::menu::addbooloption(menu, "FULL REFRESH", zxscreen::getFullRefresh(), actions::fullrefresh);
|
|
|
|
menu = ui::menu::addsubmenu("EMULATION");
|
|
ui::menu::addbooloption(menu, "STOP ON INVALID OP", z80::getOption(Z80_OPTION_STOP_ON_INVALID), actions::decZoom);
|
|
ui::menu::addoption(menu, "SHOW ANALYZER", actions::showAnalyzer);
|
|
ui::menu::addoption(menu, "CONFIGURE JOYSTICKS", actions::configureJoysticks);
|
|
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
file::setConfigFolder("z80");
|
|
SDL_Init(SDL_INIT_EVERYTHING);
|
|
init_menu();
|
|
z80debug::init();
|
|
|
|
//uint32_t update_freq =
|
|
zx_system::init(ZX_48K);
|
|
gamepad::init();
|
|
zx_tape::load("ROBOCOP1.TAP");
|
|
|
|
//if (argc==3) { z80debug::loadngo(argv[1], argv[2]); }
|
|
|
|
//z80debug::stop();
|
|
|
|
SDL_Event e;
|
|
|
|
time = SDL_GetTicks();
|
|
t_states = 0;
|
|
bool first_time = true;
|
|
|
|
while (!zx_system::shuttingDown())
|
|
{
|
|
while (SDL_PollEvent(&e))
|
|
{
|
|
bool result = true;
|
|
|
|
if (e.type == SDL_QUIT) { zx_system::shutdown(); break; }
|
|
if (e.type == SDL_JOYDEVICEADDED) {
|
|
const uint8_t index = gamepad::add(e.jdevice.which, GAMEPAD_TYPE_ANY);
|
|
printf("JOYSTICK CONECTAT: %i\n", e.jdevice.which);
|
|
if (!first_time) dialogs::joysticks::init(index);
|
|
}
|
|
if (e.type == SDL_JOYDEVICEREMOVED) {
|
|
gamepad::remove(e.jdevice.which);
|
|
printf("JOYSTICK DESCONECTAT: %i\n", e.jdevice.which);
|
|
}
|
|
if (e.type == SDL_CONTROLLERBUTTONDOWN) {
|
|
gamepad::buttonDown(e.jbutton.which, e.jbutton.button);
|
|
}
|
|
if (e.type == SDL_CONTROLLERBUTTONUP) {
|
|
gamepad::buttonUp(e.jbutton.which, e.jbutton.button);
|
|
}
|
|
if (e.type == SDL_MOUSEBUTTONDOWN) result = ui::window::sendEvent(e.button.windowID, &e);
|
|
if (e.type == SDL_MOUSEBUTTONUP) result = ui::window::sendEvent(e.button.windowID, &e);
|
|
if (e.type == SDL_MOUSEMOTION) result = ui::window::sendEvent(e.motion.windowID, &e);
|
|
if (e.type == SDL_WINDOWEVENT) result = ui::window::sendEvent(e.window.windowID, &e);
|
|
if (e.type == SDL_MOUSEWHEEL) result = ui::window::sendEvent(e.wheel.windowID, &e);
|
|
if (e.type == SDL_TEXTINPUT) result = ui::window::sendEvent(e.text.windowID, &e);
|
|
if (e.type == SDL_KEYDOWN) {
|
|
if (e.key.keysym.scancode==SDL_SCANCODE_F5) {
|
|
if (z80debug::debugging()) {
|
|
z80debug::history::gototop();
|
|
const uint8_t dt = z80::step();
|
|
z80debug::cont();
|
|
zxscreen::refresh(dt);
|
|
}
|
|
} else if (e.key.keysym.scancode==SDL_SCANCODE_F8) {
|
|
if (!z80debug::debugging()) {
|
|
z80debug::stop();
|
|
zxscreen::redraw();
|
|
} else {
|
|
z80debug::show();
|
|
}
|
|
z80viewer::refreshAll();
|
|
} else if (e.key.keysym.scancode==SDL_SCANCODE_F10) {
|
|
if (z80debug::debugging()) {
|
|
z80debug::show();
|
|
z80debug::history::gototop();
|
|
const uint8_t dt = z80::step();
|
|
z80debug::refresh();
|
|
zxscreen::fullrefresh();
|
|
zxscreen::redraw();
|
|
z80analyze::refresh();
|
|
z80viewer::refreshAll();
|
|
}
|
|
} else if (e.key.keysym.scancode==SDL_SCANCODE_F11) {
|
|
if (z80debug::debugging()) {
|
|
z80debug::show();
|
|
z80debug::history::gototop();
|
|
const uint8_t dt = z80debug::next();
|
|
z80debug::refresh();
|
|
zxscreen::refresh(dt);
|
|
zxscreen::redraw();
|
|
z80analyze::refresh();
|
|
z80viewer::refreshAll();
|
|
}
|
|
} else if (e.key.keysym.scancode==SDL_SCANCODE_F12) {
|
|
if (z80debug::debugging()) {
|
|
z80debug::show();
|
|
z80debug::history::gototop();
|
|
const uint8_t dt = z80debug::stepout();
|
|
z80debug::refresh();
|
|
zxscreen::refresh(dt);
|
|
zxscreen::redraw();
|
|
z80analyze::refresh();
|
|
z80viewer::refreshAll();
|
|
}
|
|
}
|
|
result = ui::window::sendEvent(e.key.windowID, &e);
|
|
}
|
|
|
|
if (e.type == SDL_MOUSEBUTTONUP && e.button.button==1) ui::setClicked(true);
|
|
|
|
if (!result)
|
|
zx_system::shutdown(); break;
|
|
}
|
|
|
|
first_time = false;
|
|
if (!z80debug::debugging() && !z80debug::paused()) {
|
|
|
|
// En cada bucle fem 10 pasos de la CPU, sino s'ofega (jo en veig 5)
|
|
for (int i=0;i<5;++i) {
|
|
if (z80debug::isbreak(z80::getPC(), 9)) {
|
|
z80debug::stop();
|
|
zxscreen::redraw();
|
|
break;
|
|
} else {
|
|
uint8_t dt = z80::step();
|
|
t_states += dt;
|
|
zx_system::update(dt);
|
|
zxscreen::refresh(dt);
|
|
if (z80debug::debugging()) break;
|
|
}
|
|
}
|
|
|
|
uint32_t update_freq = z80::getClock()/10;
|
|
if (t_states>=update_freq)
|
|
{
|
|
// Esperem a que es compleixca el temps corresponent als t states executats
|
|
while (SDL_GetTicks()<time+100) {}
|
|
|
|
t_states -= update_freq;
|
|
time = SDL_GetTicks();
|
|
z80analyze::refresh();
|
|
z80viewer::refreshAll();
|
|
}
|
|
z80analyze::refresh(true);
|
|
|
|
|
|
} else if (z80debug::paused()) {
|
|
zxscreen::redraw(false);
|
|
|
|
if (ui::hasDialog())
|
|
ui::callDialog();
|
|
else
|
|
ui::menu::show();
|
|
|
|
zxscreen::present();
|
|
}
|
|
ui::setClicked(false);
|
|
}
|
|
|
|
return 0;
|
|
} |