Browse Source

Add signal handling, plus basic instruction fetch logic.

master
Ben Kurtovic 9 years ago
parent
commit
443fb46beb
2 changed files with 46 additions and 3 deletions
  1. +26
    -1
      src/iomanager.c
  2. +20
    -2
      src/z80.c

+ 26
- 1
src/iomanager.c View File

@@ -1,11 +1,24 @@
/* Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com> /* Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com>
Released under the terms of the MIT License. See LICENSE for details. */ Released under the terms of the MIT License. See LICENSE for details. */


#include <signal.h>
#include <stdbool.h>
#include <unistd.h> #include <unistd.h>


#include "iomanager.h" #include "iomanager.h"
#include "logging.h" #include "logging.h"


static volatile bool caught_signal;

/*
Signal handler for SIGINT.
*/
static void handle_sigint(int sig)
{
(void) sig; // We don't care
caught_signal = true;
}

/* /*
Emulate a Game Gear. Handle I/O with the host computer. Emulate a Game Gear. Handle I/O with the host computer.


@@ -13,11 +26,14 @@
*/ */
void iomanager_emulate(GameGear *gg) void iomanager_emulate(GameGear *gg)
{ {
caught_signal = false;
signal(SIGINT, handle_sigint);

DEBUG("IOManager powering GameGear") DEBUG("IOManager powering GameGear")
gamegear_power(gg, true); gamegear_power(gg, true);


// TODO: use SDL events // TODO: use SDL events
while (1) {
while (!caught_signal) {
if (gamegear_simulate(gg)) { if (gamegear_simulate(gg)) {
ERROR("caught exception: %s", gamegear_get_exception(gg)) ERROR("caught exception: %s", gamegear_get_exception(gg))
#ifdef DEBUG_MODE #ifdef DEBUG_MODE
@@ -28,6 +44,15 @@ void iomanager_emulate(GameGear *gg)
usleep(1000 * 1000 / 60); usleep(1000 * 1000 / 60);
} }


if (caught_signal) {
WARN("caught signal, stopping...")
#ifdef DEBUG_MODE
z80_dump_registers(&gg->cpu);
#endif
}

DEBUG("IOManager unpowering GameGear") DEBUG("IOManager unpowering GameGear")
gamegear_power(gg, false); gamegear_power(gg, false);

signal(SIGINT, SIG_DFL);
} }

+ 20
- 2
src/z80.c View File

@@ -86,6 +86,19 @@ static inline uint8_t get_interrupt_mode(Z80 *z80)
return 2; return 2;
} }


/* ------------------------------------------------------------------------- */

static uint8_t z80_inst_nop(Z80 *z80) {
z80->regfile.pc++;
return 4;
}

static uint8_t (*instruction_lookup_table[256])(Z80*) = {
z80_inst_nop
};

/* ------------------------------------------------------------------------- */

/* /*
Emulate the given number of cycles of the Z80, or until an exception. Emulate the given number of cycles of the Z80, or until an exception.


@@ -98,9 +111,14 @@ bool z80_do_cycles(Z80 *z80, double cycles)
if (z80->except) if (z80->except)
return true; return true;


z80->pending_cycles += cycles;
// TODO: fetch instruction...
cycles -= z80->pending_cycles;
while (cycles > 0) {
// uint8_t opcode = mmu_read_byte(&z80->mmu, z80->regfile.pc);
uint8_t opcode = 0x00;
cycles -= (*instruction_lookup_table[opcode])(z80) - 2;
}


z80->pending_cycles = -cycles;
return false; return false;
} }




Loading…
Cancel
Save