- [NEW] Afegit modul debug
- [NEW] Afegit tagging de memòria - [NEW] modul mbc_none funcional - [NEW] Afegit modul main base del programa - [NEW] Afegits Makefile i .gitignore - Primera execució. No arriba a 0x0100 - [FIX] Corregida la representació del ensamblador cap enrere
This commit is contained in:
218
main.cpp
218
main.cpp
@@ -1,9 +1,221 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "sm83.h"
|
||||
#include "mem.h"
|
||||
#include "sm83dis.h"
|
||||
#include "debug.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"
|
||||
//#include "z80analyze.h"
|
||||
#include "ui_window.h"
|
||||
|
||||
uint32_t time = 0;
|
||||
uint32_t t_states = 0;
|
||||
|
||||
namespace actions
|
||||
{
|
||||
void exitMenu()
|
||||
{
|
||||
const uint8_t dt = sm83::step();
|
||||
debug::cont();
|
||||
//zxscreen::refresh(dt);
|
||||
}
|
||||
|
||||
int decZoom(int value)
|
||||
{
|
||||
//zxscreen::decZoom();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int incZoom(int value)
|
||||
{
|
||||
//zxscreen::incZoom();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fullscreen(int value)
|
||||
{
|
||||
//zxscreen::toggleFullscreen();
|
||||
return 0; //zxscreen::getFullscreen();
|
||||
}
|
||||
|
||||
int fullrefresh(int value)
|
||||
{
|
||||
//zxscreen::toggleFullRefresh();
|
||||
return 0; //zxscreen::getFullRefresh();
|
||||
}
|
||||
|
||||
int showAnalyzer(int value)
|
||||
{
|
||||
//z80analyze::show();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
mem::init(nullptr, 0);
|
||||
|
||||
if (argc < 2) { printf("ABORTING: No rom specified.\n"); exit(1); }
|
||||
|
||||
const uint32_t clock = 4194304;
|
||||
const uint32_t update_freq = clock / 10;
|
||||
|
||||
FILE *f = fopen(argv[1], "rb");
|
||||
if (!f) { printf("ABORTING: Rom not found.\n"); exit(1); }
|
||||
fseek(f, 0, SEEK_END);
|
||||
const int filesize = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
uint8_t *buffer = (uint8_t*)malloc(filesize);
|
||||
fread(buffer, filesize, 1, f);
|
||||
fclose(f);
|
||||
mem::init(buffer, filesize);
|
||||
|
||||
sm83dis::loadSymbols();
|
||||
sm83::reset();
|
||||
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
debug::init();
|
||||
//zxscreen::init(SCREEN_MODE_48K);
|
||||
|
||||
ui::menu::init();
|
||||
ui::menu::setexitcallback(actions::exitMenu);
|
||||
|
||||
int menu = ui::menu::addsubmenu("FILE");
|
||||
ui::menu::addoption(menu, "LOAD ROM", nullptr);
|
||||
ui::menu::addoption(menu, "SAVE ROM", nullptr);
|
||||
ui::menu::addseparator(menu);
|
||||
ui::menu::addoption(menu, "LOAD STATE", nullptr);
|
||||
ui::menu::addoption(menu, "SAVE STATE", nullptr);
|
||||
|
||||
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", false /*zxscreen::getFullscreen()*/, actions::fullscreen);
|
||||
ui::menu::addseparator(menu);
|
||||
ui::menu::addbooloption(menu, "FULL REFRESH", false /*zxscreen::getFullRefresh()*/, actions::fullrefresh);
|
||||
|
||||
menu = ui::menu::addsubmenu("EMULATION");
|
||||
ui::menu::addbooloption(menu, "STOP ON INVALID OP", sm83::getOption(SM83_OPTION_STOP_ON_INVALID), actions::decZoom);
|
||||
ui::menu::addoption(menu, "SHOW ANALYZER", actions::showAnalyzer);
|
||||
|
||||
//zx_ula::sound_init();
|
||||
|
||||
debug::stop();
|
||||
|
||||
bool should_exit = false;
|
||||
SDL_Event e;
|
||||
|
||||
time = SDL_GetTicks();
|
||||
t_states = 0;
|
||||
|
||||
while (!should_exit)
|
||||
{
|
||||
while (SDL_PollEvent(&e))
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
if (e.type == SDL_QUIT) { should_exit=true; break; }
|
||||
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 (debug::debugging()) {
|
||||
debug::history::gototop();
|
||||
const uint8_t dt = sm83::step();
|
||||
debug::cont();
|
||||
//zxscreen::refresh(dt);
|
||||
}
|
||||
} else if (e.key.keysym.scancode==SDL_SCANCODE_F8) {
|
||||
if (!debug::debugging()) {
|
||||
debug::stop();
|
||||
//zxscreen::redraw();
|
||||
} else {
|
||||
debug::show();
|
||||
}
|
||||
} else if (e.key.keysym.scancode==SDL_SCANCODE_F10) {
|
||||
if (debug::debugging()) {
|
||||
debug::show();
|
||||
debug::history::gototop();
|
||||
const uint8_t dt = sm83::step();
|
||||
debug::refresh();
|
||||
//zxscreen::fullrefresh();
|
||||
//zxscreen::redraw();
|
||||
//z80analyze::refresh();
|
||||
}
|
||||
} else if (e.key.keysym.scancode==SDL_SCANCODE_F11) {
|
||||
if (debug::debugging()) {
|
||||
debug::show();
|
||||
debug::history::gototop();
|
||||
const uint8_t dt = debug::next();
|
||||
debug::refresh();
|
||||
//zxscreen::refresh(dt);
|
||||
//zxscreen::redraw();
|
||||
//z80analyze::refresh();
|
||||
}
|
||||
} else if (e.key.keysym.scancode==SDL_SCANCODE_F12) {
|
||||
if (debug::debugging()) {
|
||||
debug::show();
|
||||
debug::history::gototop();
|
||||
const uint8_t dt = debug::stepout();
|
||||
debug::refresh();
|
||||
//zxscreen::refresh(dt);
|
||||
//zxscreen::redraw();
|
||||
//z80analyze::refresh();
|
||||
}
|
||||
}
|
||||
result = ui::window::sendEvent(e.key.windowID, &e);
|
||||
}
|
||||
|
||||
if (e.type == SDL_MOUSEBUTTONUP && e.button.button==1) ui::setClicked(true);
|
||||
|
||||
if (!result)
|
||||
should_exit = true; break;
|
||||
}
|
||||
|
||||
if (!debug::debugging() && !debug::paused()) {
|
||||
bool fastload=false;
|
||||
|
||||
// En cada bucle fem 10 pasos de la CPU, sino s'ofega
|
||||
for (int i=0;i<5;++i) {
|
||||
if (debug::isbreak(sm83::getPC(), 9)) {
|
||||
debug::stop();
|
||||
//zxscreen::redraw();
|
||||
break;
|
||||
} else {
|
||||
uint8_t dt = sm83::step();
|
||||
t_states += dt;
|
||||
//zx_ula::sound_update(dt);
|
||||
//zxscreen::refresh(dt);
|
||||
if (debug::debugging()) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (t_states>=update_freq)
|
||||
{
|
||||
while (SDL_GetTicks()<time+100) {}
|
||||
t_states -= update_freq;
|
||||
time = SDL_GetTicks();
|
||||
//z80analyze::refresh();
|
||||
}
|
||||
//z80analyze::refresh(true);
|
||||
|
||||
|
||||
} else if (!debug::debugging() && debug::paused()) {
|
||||
//zxscreen::redraw(false);
|
||||
ui::menu::show();
|
||||
//zxscreen::present();
|
||||
}
|
||||
ui::setClicked(false);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user