#include #include #include #include #include "memory/memory.h" #include "cpu/65el02.h" #include "display/display.h" #include "video/gbuffer.h" #include "drive/drive.h" #include "emubase.h" #include "emuversion.h" #include "debug.h" #include "monitor.h" #include "options.h" #include "screen.h" int load_address = -1; //--------------------------------------------------------------------------- int start_pc = -1; int init_breakpoint = -1; int init_cycles_per_tick = -1; //--------------------------------------------------------------------------- char emulation_run = 1; void loadprogram(char *programname) { FILE *f; if (*programname) { if ((f = fopen(programname, "rb")) != NULL) { fseek(f, 0, SEEK_SET); fread(&load_address, 1, 2, f); fread(&ram[load_address], 1, (0x10000 - load_address), f); fclose(f); } else { printf("File open error! [%s]\n", programname); } } } //--------------------------------------------------------------------------- void showall(struct cpustruct cpu) { char tempstring[256]; displayscreen(cpu.byte1); showdebug(); showmemory(mempos); showinst(cpu.regPC,cpu); drawstring(0, C_SIZEY-1, "\r F1-Help F2-Options F3-Peripherals F4-IO extenders F6-Built-in monitor", 0x0f, 0x09, rom_charset); if (emulation_run) sprintf(tempstring, "F9-trace mode emulation running"); else sprintf(tempstring, "F9-run F11-step trace mode"); drawstring(C_SIZEX-strlen(tempstring)-2, C_SIZEY-1, tempstring, 0x0f, 0x09, rom_charset); updateptc(); } void reset() { coldBootCPU(); if (init_cycles_per_tick > 0) cpu.cycles_per_tick = init_cycles_per_tick; if (start_pc >= 0) cpu.regPC = start_pc; reset_display(cpu.byte1); ram[0] = cpu.byte0; ram[1] = cpu.byte1; memcpy(&ram[0x400],&bootcode,sizeof(bootcode)); } //--------------------------------------------------------------------------- void emulation() { int ch, np, mode; int qi, lastframe; char quit = 0, result; int tempreg, last_tick; char tempstring[64]; FILE *f; if ((f = fopen("/usr/share/rpc/roms/charset.rom", "rb")) != NULL) { fseek(f, 0, SEEK_SET); fread(rom_charset, 1, sizeof(rom_charset), f); fclose(f); } else { printf("missing charset rom (roms/charset.rom)\n"); return; } if ((f = fopen("/usr/share/rpc/roms/rpcboot.bin", "rb")) != NULL) { fseek(f, 0, SEEK_SET); fread(&bootcode, 1, sizeof(bootcode), f); fclose(f); } else { printf("missing bootcode (roms/rpcboot.bin)\n"); return; } memset(&cpu, 0x00, sizeof(cpu)); memset(&ioextender, 0x00, sizeof(ioextender)); memset(&peripherals, 0x00, sizeof(peripherals)); memset(&drives, 0x00, sizeof(drives)); readoptions(); coldBootCPU(); if (!peripherals[cpu.byte0]) peripherals[cpu.byte0] = 3; if (!peripherals[cpu.byte1]) peripherals[cpu.byte1] = 1; drive_set(cpu.byte0, defdiskname); drive_type(cpu.byte0, defdisktype); init_displays(); initscreen(); for (qi=0; qi<256; qi++) { if ((peripherals[qi] == 1) || (peripherals[qi] == 2)) { openscreen(qi); scrtype(qi, peripherals[qi]-1); } } reset(); moninit(); optinit(); memset(cpu.breakpoints, 0x00, sizeof(cpu.breakpoints)); cpu.breakpoint_count = 0; if (init_breakpoint >= 0) cpu.breakpoints[cpu.breakpoint_count++] = init_breakpoint | 0x10000; for (qi=0; qi= 0) { ch = lastkeysym; // sprintf(tempstring,"symkey: %04x mod: %04x",ch,lastkeymod); // drawstring(0, 52, tempstring, 0x01, 0x00, rom_charset); if ((ch == SDLK_PAUSE) || (ch == SDLK_F6)) { quit = monitor(); } if (ch == SDLK_F1) quit = help(); if (ch == SDLK_F2) quit = options(); if (ch == SDLK_F3) quit = optperipherals(); if (ch == SDLK_F4) quit = optiox(-1); if ((ch == SDLK_ESCAPE) && (lastkeymod & KMOD_SHIFT)) quit = 1; // shift+esc if ((ch == SDLK_x) && (lastkeymod & KMOD_LALT)) quit = 1; // alt-x if ((ch == SDLK_F4) && (lastkeymod & KMOD_LALT)) quit = 1; // alt-x if (ch == SDLK_F9) { // F9 emulation_run = emulation_run ^ 1; showall(cpu); } if ( (ch == SDLK_F11) && (!emulation_run) ) { executeInsn(); showall(cpu); } if ( (ch == SDLK_F12) && (!emulation_run) ) { mode = (cpu.flagX << 1) | cpu.flagM; cpu.breakpoints[0]=(cpu.regPC + codesizetable[addrmode[mode][mem_load(cpu.regPC)]]) | 0x10000; emulation_run=1; } if (ch == SDLK_PAGEUP) { // PAGEUP if ((lastkeymod & KMOD_SHIFT) != KMOD_SHIFT) { mempos = (mempos - 0x08) & 0xffff; showmemory(mempos); } else { mempos = (mempos - 0x80) & 0xffff; showmemory(mempos); } showall(cpu); } if (ch == SDLK_PAGEDOWN) { // PAGEDOWN if ((lastkeymod & KMOD_SHIFT) != KMOD_SHIFT) { mempos = (mempos + 0x08) & 0xffff; showmemory(mempos); } else { mempos = (mempos + 0x80) & 0xffff; showmemory(mempos); } showall(cpu); } if ((ch == SDLK_r) && (lastkeymod & KMOD_LALT)) { reset(); } ch = lastkey; if ((ch > 0) && (ch < 128) && !(lastkeymod & KMOD_LALT)) { if (ch != 27) // ignore ESC { disp_key(cpu.byte1, ch); } } } if (lastkey == -2) quit = 1; } } shutdownscreen(); } //---------------------------------------------------------------------------