You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
317 lines
6.2 KiB
C
317 lines
6.2 KiB
C
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <SDL/SDL.h>
|
|
|
|
#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<cpu.breakpoint_count; qi++)
|
|
printf("breakpoint %d: %x\n",qi,cpu.breakpoints[qi] & 0xffff);
|
|
|
|
ram[0x500] = 0x4c;
|
|
ram[0x501] = 0x00;
|
|
ram[0x502] = 0x05;
|
|
|
|
// printf("Loading program (if needed)...\n");
|
|
// loadprogram(loadfilename);
|
|
|
|
drawstring((C_SIZEX-sizeof(eloraam))/2, 53, eloraam, 0x0b, 0x00, rom_charset);
|
|
showall(cpu);
|
|
|
|
drawstring(0, 0, "\r", 0x05, 0x0b, rom_charset);
|
|
drawstring((C_SIZEX-sizeof(emuversion))/2, 0, emuversion, 0x05, 0x0b, rom_charset);
|
|
|
|
// printf("Emulation started\n");
|
|
// emulation_run = 1;
|
|
|
|
while (!quit)
|
|
{
|
|
for (qi=0; qi<256; qi++)
|
|
{
|
|
if ((peripherals[qi] == 1) || (peripherals[qi] == 2))
|
|
blitter(qi);
|
|
|
|
if (peripherals[qi] == 3)
|
|
drive(qi);
|
|
}
|
|
|
|
last_tick = timer_tick;
|
|
showall(cpu);
|
|
|
|
if (emulation_run)
|
|
{
|
|
emulateframe();
|
|
if (cpu.brk)
|
|
emulation_run = 0;
|
|
}
|
|
|
|
while (last_tick == timer_tick)
|
|
SDL_Delay(1);
|
|
|
|
while (getkeys())
|
|
{
|
|
if (lastkeysym >= 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();
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|