#include #include #include "z80.h" #include "z80dis.h" #include "z80debug.h" #include "zx_ula.h" #include "zx_screen.h" #include "zx_tape.h" #include #include #include "ui.h" #include "ui_menu.h" #include "z80analyze.h" uint8_t memory[65536]; uint32_t time = 0; uint32_t t_states = 0; namespace actions { void exitMenu() { const uint8_t dt = z80::step(); z80debug::cont(); zxscreen::refresh(dt); } 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 showAnalyzer(int value) { z80analyze::show(); return 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(); 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); menu = ui::menu::addsubmenu("TAPE"); ui::menu::addbooloption(menu, "BERSERK MODE", 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); 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); zx_ula::sound_init(); zx_tape::load("fernandomartin.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_MOUSEBUTTONUP && e.button.button==1) ui::setClicked(true); 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_MOUSEWHEEL) { if (e.wheel.mouseX<46*CHR_W && e.wheel.mouseY<20*CHR_H) { if (e.wheel.y>0) { z80debug::cursorback(); z80debug::refresh(); } else if (e.wheel.y<0) { z80debug::cursorfwd(); z80debug::refresh(); } } } 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) { z80debug::history::gototop(); const uint8_t dt = z80::step(); z80debug::refresh(); zxscreen::refresh(dt); zxscreen::redraw(); } else if (e.key.keysym.scancode==SDL_SCANCODE_F11) { z80debug::history::gototop(); const uint8_t dt = z80debug::next(); zxscreen::refresh(dt); zxscreen::redraw(); } else if (e.key.keysym.scancode==SDL_SCANCODE_F1) { z80debug::history::gototop(); z80debug::refresh(); } else if (e.key.keysym.scancode==SDL_SCANCODE_F2) { z80debug::history::goback(); z80debug::refresh(); } else if (e.key.keysym.scancode==SDL_SCANCODE_F3) { z80debug::history::goforward(); z80debug::refresh(); } else if (e.key.keysym.scancode==SDL_SCANCODE_F5) { z80debug::history::gototop(); const uint8_t dt = z80::step(); z80debug::cont(); zxscreen::refresh(dt); /*} else if (e.key.keysym.scancode==SDL_SCANCODE_F6) { z80debug::history::gototop(); const uint8_t dt = z80::step(); z80debug::refresh(); zxscreen::refresh(dt);*/ } else if (e.key.keysym.scancode==SDL_SCANCODE_UP) { z80debug::cursorback(); z80debug::refresh(); } else if (e.key.keysym.scancode==SDL_SCANCODE_DOWN) { z80debug::cursorfwd(); z80debug::refresh(); } 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::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(); bool fastload=false; if (zx_tape::getplaying() && zx_tape::getOption(ZXTAPE_OPTION_FAST_LOAD)) { fastload=true; time = SDL_GetTicks(); } while (zx_tape::getplaying() && zx_tape::getOption(ZXTAPE_OPTION_FAST_LOAD)) { // zx_tape::update(z80::step()); uint8_t dt = z80::step(); t_states += dt; zx_tape::update(dt); if (SDL_GetTicks()-time>=1000) { time = SDL_GetTicks(); zx_tape::report(); } //zx_ula::sound_update(dt); //zxscreen::refresh(dt); } if (fastload) { printf("%i\n", SDL_GetTicks()-time); t_states=0; } // En cada bucle fem 10 pasos de la CPU, sino s'ofega for (int i=0;i<5;++i) { uint8_t dt = z80::step(); t_states += dt; zx_tape::update(dt); zx_ula::sound_update(dt); zxscreen::refresh(dt); } if (t_states>=350000) { //if (SDL_GetTicks()>=time+1000) //printf("%i\n", SDL_GetTicks()-(time+1000)); //else // printf("%i\n", SDL_GetTicks()-(time+1000)); //t_states = 0; //printf("%i: %i\n", SDL_GetTicks()-(time+1000), t_states); while (SDL_GetTicks()