Browse Source

Stub out MMU functions, opcodes; const fixes.

master
Ben Kurtovic 9 years ago
parent
commit
274b2eaa93
9 changed files with 336 additions and 27 deletions
  1. +1
    -1
      src/config.c
  2. +1
    -1
      src/config.h
  3. +9
    -7
      src/gamegear.c
  4. +1
    -1
      src/gamegear.h
  5. +51
    -4
      src/mmu.c
  6. +9
    -2
      src/mmu.h
  7. +6
    -7
      src/z80.c
  8. +1
    -1
      src/z80.h
  9. +257
    -3
      src/z80_instructions.inc

+ 1
- 1
src/config.c View File

@@ -364,7 +364,7 @@ void config_destroy(Config *config)
/* /*
DEBUG FUNCTION: Print out all config arguments to stdout. DEBUG FUNCTION: Print out all config arguments to stdout.
*/ */
void config_dump_args(Config* config)
void config_dump_args(const Config* config)
{ {
DEBUG("Dumping arguments:") DEBUG("Dumping arguments:")
DEBUG("- fullscreen: %s", config->fullscreen ? "true" : "false") DEBUG("- fullscreen: %s", config->fullscreen ? "true" : "false")


+ 1
- 1
src/config.h View File

@@ -38,5 +38,5 @@ int config_create(Config**, int, char*[]);
void config_destroy(Config*); void config_destroy(Config*);


#ifdef DEBUG_MODE #ifdef DEBUG_MODE
void config_dump_args(Config*);
void config_dump_args(const Config*);
#endif #endif

+ 9
- 7
src/gamegear.c View File

@@ -21,7 +21,8 @@ GameGear* gamegear_create()
if (!gg) if (!gg)
OUT_OF_MEMORY() OUT_OF_MEMORY()


// mmu_init(&gg->mmu, ...);
if (!mmu_init(&gg->mmu))
OUT_OF_MEMORY()
z80_init(&gg->cpu, &gg->mmu); z80_init(&gg->cpu, &gg->mmu);
gg->powered = false; gg->powered = false;
gg->exc_buffer[0] = '\0'; gg->exc_buffer[0] = '\0';
@@ -35,22 +36,23 @@ GameGear* gamegear_create()
*/ */
void gamegear_destroy(GameGear *gg) void gamegear_destroy(GameGear *gg)
{ {
// mmu_free(&gg->mmu);
mmu_free(&gg->mmu);
free(gg); free(gg);
} }


/* /*
Load a ROM image into the GameGear object. Load a ROM image into the GameGear object.


Does *not* steal a reference to the ROM object. Calling this function while
the GameGear is powered on has no effect.
Does *not* steal a reference to the ROM object, so it must be kept alive
until another ROM is loaded or the GameGear is destroyed. Calling this
function while the GameGear is powered on has no effect.
*/ */
void gamegear_load(GameGear *gg, ROM *rom)
void gamegear_load(GameGear *gg, const ROM *rom)
{ {
if (gg->powered) if (gg->powered)
return; return;


// mmu_hard_map(&gg->mmu, rom->data, ..., ...);
mmu_load_rom(&gg->mmu, rom->data, rom->size);
} }


/* /*
@@ -68,7 +70,7 @@ void gamegear_power(GameGear *gg, bool state)
return; return;


if (state) { if (state) {
// mmu_power(&gg->mmu);
mmu_power(&gg->mmu);
z80_power(&gg->cpu); z80_power(&gg->cpu);
gg->last_tick = get_time_ns(); gg->last_tick = get_time_ns();
} else { } else {


+ 1
- 1
src/gamegear.h View File

@@ -26,7 +26,7 @@ typedef struct {


GameGear* gamegear_create(); GameGear* gamegear_create();
void gamegear_destroy(GameGear*); void gamegear_destroy(GameGear*);
void gamegear_load(GameGear*, ROM*);
void gamegear_load(GameGear*, const ROM*);
void gamegear_power(GameGear*, bool); void gamegear_power(GameGear*, bool);
bool gamegear_simulate(GameGear*); bool gamegear_simulate(GameGear*);
const char* gamegear_get_exception(GameGear*); const char* gamegear_get_exception(GameGear*);

+ 51
- 4
src/mmu.c View File

@@ -5,8 +5,55 @@


/* /*
Initialize a MMU object. Initialize a MMU object.

Return true if initialization was successful, or false if the required
amount of memory could not be allocated.
*/
bool mmu_init(MMU *mmu)
{
// TODO
return true;
}

/*
Free memory previously allocated by the MMU.
*/
void mmu_free(MMU *mmu)
{
// TODO
}

/*
Load a block ROM into the MMU.

size should be a power of two.
*/
void mmu_load_rom(MMU *mmu, const uint8_t *data, size_t size)
{
// TODO
}

/*
Power on the MMU, setting initial memory values.
*/
void mmu_power(MMU *mmu)
{
// TODO
}

/*
Read a byte of memory.
*/
uint8_t mmu_read_byte(MMU *mmu, uint16_t addr)
{
// TODO
return 0x00;
}

/*
...
*/ */
// void mmu_init(MMU *mmu, ...)
// {
// //
// }
void mmu_write_byte(MMU *mmu, uint16_t addr, uint8_t value)
{
// TODO
}

+ 9
- 2
src/mmu.h View File

@@ -3,7 +3,9 @@


#pragma once #pragma once


// #include <>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>


/* Structs */ /* Structs */


@@ -13,4 +15,9 @@ typedef struct {


/* Functions */ /* Functions */


// void mmu_init(MMU*, ...);
bool mmu_init(MMU*);
void mmu_free(MMU*);
void mmu_load_rom(MMU*, const uint8_t*, size_t);
void mmu_power(MMU*);
uint8_t mmu_read_byte(MMU*, uint16_t);
void mmu_write_byte(MMU*, uint16_t, uint8_t);

+ 6
- 7
src/z80.c View File

@@ -63,7 +63,7 @@ void z80_power(Z80 *z80)
/* /*
Return whether a particular flag is set in the F register. Return whether a particular flag is set in the F register.
*/ */
static inline bool get_flag(Z80 *z80, uint8_t flag)
static inline bool get_flag(const Z80 *z80, uint8_t flag)
{ {
return z80->regfile.f & (1 << flag); return z80->regfile.f & (1 << flag);
} }
@@ -71,7 +71,7 @@ static inline bool get_flag(Z80 *z80, uint8_t flag)
/* /*
Return whether a particular flag is set in the F' register. Return whether a particular flag is set in the F' register.
*/ */
static inline bool get_shadow_flag(Z80 *z80, uint8_t flag)
static inline bool get_shadow_flag(const Z80 *z80, uint8_t flag)
{ {
return z80->regfile.f_ & (1 << flag); return z80->regfile.f_ & (1 << flag);
} }
@@ -79,7 +79,7 @@ static inline bool get_shadow_flag(Z80 *z80, uint8_t flag)
/* /*
Return the CPU's current interrupt mode. Return the CPU's current interrupt mode.
*/ */
static inline uint8_t get_interrupt_mode(Z80 *z80)
static inline uint8_t get_interrupt_mode(const Z80 *z80)
{ {
if (!z80->regfile.im_a) if (!z80->regfile.im_a)
return 0; return 0;
@@ -101,8 +101,7 @@ bool z80_do_cycles(Z80 *z80, double cycles)
{ {
cycles -= z80->pending_cycles; cycles -= z80->pending_cycles;
while (cycles > 0 && !z80->except) { while (cycles > 0 && !z80->except) {
// uint8_t opcode = mmu_read_byte(&z80->mmu, z80->regfile.pc);
uint8_t opcode = 0x00;
uint8_t opcode = mmu_read_byte(z80->mmu, z80->regfile.pc);
cycles -= (*instruction_lookup_table[opcode])(z80, opcode) - 2; cycles -= (*instruction_lookup_table[opcode])(z80, opcode) - 2;
} }


@@ -114,9 +113,9 @@ bool z80_do_cycles(Z80 *z80, double cycles)
/* /*
DEBUG FUNCTION: Print out all register values to stdout. DEBUG FUNCTION: Print out all register values to stdout.
*/ */
void z80_dump_registers(Z80 *z80)
void z80_dump_registers(const Z80 *z80)
{ {
Z80RegFile *regfile = &z80->regfile;
const Z80RegFile *regfile = &z80->regfile;
DEBUG("Dumping Z80 register values:") DEBUG("Dumping Z80 register values:")


DEBUG("- AF: 0x%02X%02X (C: %u, N: %u, P/V: %u, H: %u, Z: %u, S: %u)", DEBUG("- AF: 0x%02X%02X (C: %u, N: %u, P/V: %u, H: %u, Z: %u, S: %u)",


+ 1
- 1
src/z80.h View File

@@ -37,5 +37,5 @@ void z80_power(Z80*);
bool z80_do_cycles(Z80*, double); bool z80_do_cycles(Z80*, double);


#ifdef DEBUG_MODE #ifdef DEBUG_MODE
void z80_dump_registers(Z80*);
void z80_dump_registers(const Z80*);
#endif #endif

+ 257
- 3
src/z80_instructions.inc View File

@@ -20,7 +20,7 @@ static uint8_t z80_inst_nop(Z80 *z80, uint8_t opcode)
/* /*
Unimplemented opcode handler. Unimplemented opcode handler.
*/ */
static uint8_t z80_inst_ERR(Z80 *z80, uint8_t opcode)
static uint8_t z80_inst_unimplemented(Z80 *z80, uint8_t opcode)
{ {
z80->except = true; z80->except = true;
z80->exc_code = Z80_EXC_UNIMPLEMENTED_OPCODE; z80->exc_code = Z80_EXC_UNIMPLEMENTED_OPCODE;
@@ -29,6 +29,260 @@ static uint8_t z80_inst_ERR(Z80 *z80, uint8_t opcode)
} }


static uint8_t (*instruction_lookup_table[256])(Z80*, uint8_t) = { static uint8_t (*instruction_lookup_table[256])(Z80*, uint8_t) = {
z80_inst_nop,
z80_inst_ERR
/* 0x00 */ z80_inst_nop,
/* 0x01 */ z80_inst_unimplemented,
/* 0x02 */ z80_inst_unimplemented,
/* 0x03 */ z80_inst_unimplemented,
/* 0x04 */ z80_inst_unimplemented,
/* 0x05 */ z80_inst_unimplemented,
/* 0x06 */ z80_inst_unimplemented,
/* 0x07 */ z80_inst_unimplemented,
/* 0x08 */ z80_inst_unimplemented,
/* 0x09 */ z80_inst_unimplemented,
/* 0x0A */ z80_inst_unimplemented,
/* 0x0B */ z80_inst_unimplemented,
/* 0x0C */ z80_inst_unimplemented,
/* 0x0D */ z80_inst_unimplemented,
/* 0x0E */ z80_inst_unimplemented,
/* 0x0F */ z80_inst_unimplemented,
/* 0x10 */ z80_inst_unimplemented,
/* 0x11 */ z80_inst_unimplemented,
/* 0x12 */ z80_inst_unimplemented,
/* 0x13 */ z80_inst_unimplemented,
/* 0x14 */ z80_inst_unimplemented,
/* 0x15 */ z80_inst_unimplemented,
/* 0x16 */ z80_inst_unimplemented,
/* 0x17 */ z80_inst_unimplemented,
/* 0x18 */ z80_inst_unimplemented,
/* 0x19 */ z80_inst_unimplemented,
/* 0x1A */ z80_inst_unimplemented,
/* 0x1B */ z80_inst_unimplemented,
/* 0x1C */ z80_inst_unimplemented,
/* 0x1D */ z80_inst_unimplemented,
/* 0x1E */ z80_inst_unimplemented,
/* 0x1F */ z80_inst_unimplemented,
/* 0x20 */ z80_inst_unimplemented,
/* 0x21 */ z80_inst_unimplemented,
/* 0x22 */ z80_inst_unimplemented,
/* 0x23 */ z80_inst_unimplemented,
/* 0x24 */ z80_inst_unimplemented,
/* 0x25 */ z80_inst_unimplemented,
/* 0x26 */ z80_inst_unimplemented,
/* 0x27 */ z80_inst_unimplemented,
/* 0x28 */ z80_inst_unimplemented,
/* 0x29 */ z80_inst_unimplemented,
/* 0x2A */ z80_inst_unimplemented,
/* 0x2B */ z80_inst_unimplemented,
/* 0x2C */ z80_inst_unimplemented,
/* 0x2D */ z80_inst_unimplemented,
/* 0x2E */ z80_inst_unimplemented,
/* 0x2F */ z80_inst_unimplemented,
/* 0x30 */ z80_inst_unimplemented,
/* 0x31 */ z80_inst_unimplemented,
/* 0x32 */ z80_inst_unimplemented,
/* 0x33 */ z80_inst_unimplemented,
/* 0x34 */ z80_inst_unimplemented,
/* 0x35 */ z80_inst_unimplemented,
/* 0x36 */ z80_inst_unimplemented,
/* 0x37 */ z80_inst_unimplemented,
/* 0x38 */ z80_inst_unimplemented,
/* 0x39 */ z80_inst_unimplemented,
/* 0x3A */ z80_inst_unimplemented,
/* 0x3B */ z80_inst_unimplemented,
/* 0x3C */ z80_inst_unimplemented,
/* 0x3D */ z80_inst_unimplemented,
/* 0x3E */ z80_inst_unimplemented,
/* 0x3F */ z80_inst_unimplemented,
/* 0x40 */ z80_inst_unimplemented,
/* 0x41 */ z80_inst_unimplemented,
/* 0x42 */ z80_inst_unimplemented,
/* 0x43 */ z80_inst_unimplemented,
/* 0x44 */ z80_inst_unimplemented,
/* 0x45 */ z80_inst_unimplemented,
/* 0x46 */ z80_inst_unimplemented,
/* 0x47 */ z80_inst_unimplemented,
/* 0x48 */ z80_inst_unimplemented,
/* 0x49 */ z80_inst_unimplemented,
/* 0x4A */ z80_inst_unimplemented,
/* 0x4B */ z80_inst_unimplemented,
/* 0x4C */ z80_inst_unimplemented,
/* 0x4D */ z80_inst_unimplemented,
/* 0x4E */ z80_inst_unimplemented,
/* 0x4F */ z80_inst_unimplemented,
/* 0x50 */ z80_inst_unimplemented,
/* 0x51 */ z80_inst_unimplemented,
/* 0x52 */ z80_inst_unimplemented,
/* 0x53 */ z80_inst_unimplemented,
/* 0x54 */ z80_inst_unimplemented,
/* 0x55 */ z80_inst_unimplemented,
/* 0x56 */ z80_inst_unimplemented,
/* 0x57 */ z80_inst_unimplemented,
/* 0x58 */ z80_inst_unimplemented,
/* 0x59 */ z80_inst_unimplemented,
/* 0x5A */ z80_inst_unimplemented,
/* 0x5B */ z80_inst_unimplemented,
/* 0x5C */ z80_inst_unimplemented,
/* 0x5D */ z80_inst_unimplemented,
/* 0x5E */ z80_inst_unimplemented,
/* 0x5F */ z80_inst_unimplemented,
/* 0x60 */ z80_inst_unimplemented,
/* 0x61 */ z80_inst_unimplemented,
/* 0x62 */ z80_inst_unimplemented,
/* 0x63 */ z80_inst_unimplemented,
/* 0x64 */ z80_inst_unimplemented,
/* 0x65 */ z80_inst_unimplemented,
/* 0x66 */ z80_inst_unimplemented,
/* 0x67 */ z80_inst_unimplemented,
/* 0x68 */ z80_inst_unimplemented,
/* 0x69 */ z80_inst_unimplemented,
/* 0x6A */ z80_inst_unimplemented,
/* 0x6B */ z80_inst_unimplemented,
/* 0x6C */ z80_inst_unimplemented,
/* 0x6D */ z80_inst_unimplemented,
/* 0x6E */ z80_inst_unimplemented,
/* 0x6F */ z80_inst_unimplemented,
/* 0x70 */ z80_inst_unimplemented,
/* 0x71 */ z80_inst_unimplemented,
/* 0x72 */ z80_inst_unimplemented,
/* 0x73 */ z80_inst_unimplemented,
/* 0x74 */ z80_inst_unimplemented,
/* 0x75 */ z80_inst_unimplemented,
/* 0x76 */ z80_inst_unimplemented,
/* 0x77 */ z80_inst_unimplemented,
/* 0x78 */ z80_inst_unimplemented,
/* 0x79 */ z80_inst_unimplemented,
/* 0x7A */ z80_inst_unimplemented,
/* 0x7B */ z80_inst_unimplemented,
/* 0x7C */ z80_inst_unimplemented,
/* 0x7D */ z80_inst_unimplemented,
/* 0x7E */ z80_inst_unimplemented,
/* 0x7F */ z80_inst_unimplemented,
/* 0x80 */ z80_inst_unimplemented,
/* 0x81 */ z80_inst_unimplemented,
/* 0x82 */ z80_inst_unimplemented,
/* 0x83 */ z80_inst_unimplemented,
/* 0x84 */ z80_inst_unimplemented,
/* 0x85 */ z80_inst_unimplemented,
/* 0x86 */ z80_inst_unimplemented,
/* 0x87 */ z80_inst_unimplemented,
/* 0x88 */ z80_inst_unimplemented,
/* 0x89 */ z80_inst_unimplemented,
/* 0x8A */ z80_inst_unimplemented,
/* 0x8B */ z80_inst_unimplemented,
/* 0x8C */ z80_inst_unimplemented,
/* 0x8D */ z80_inst_unimplemented,
/* 0x8E */ z80_inst_unimplemented,
/* 0x8F */ z80_inst_unimplemented,
/* 0x90 */ z80_inst_unimplemented,
/* 0x91 */ z80_inst_unimplemented,
/* 0x92 */ z80_inst_unimplemented,
/* 0x93 */ z80_inst_unimplemented,
/* 0x94 */ z80_inst_unimplemented,
/* 0x95 */ z80_inst_unimplemented,
/* 0x96 */ z80_inst_unimplemented,
/* 0x97 */ z80_inst_unimplemented,
/* 0x98 */ z80_inst_unimplemented,
/* 0x99 */ z80_inst_unimplemented,
/* 0x9A */ z80_inst_unimplemented,
/* 0x9B */ z80_inst_unimplemented,
/* 0x9C */ z80_inst_unimplemented,
/* 0x9D */ z80_inst_unimplemented,
/* 0x9E */ z80_inst_unimplemented,
/* 0x9F */ z80_inst_unimplemented,
/* 0xA0 */ z80_inst_unimplemented,
/* 0xA1 */ z80_inst_unimplemented,
/* 0xA2 */ z80_inst_unimplemented,
/* 0xA3 */ z80_inst_unimplemented,
/* 0xA4 */ z80_inst_unimplemented,
/* 0xA5 */ z80_inst_unimplemented,
/* 0xA6 */ z80_inst_unimplemented,
/* 0xA7 */ z80_inst_unimplemented,
/* 0xA8 */ z80_inst_unimplemented,
/* 0xA9 */ z80_inst_unimplemented,
/* 0xAA */ z80_inst_unimplemented,
/* 0xAB */ z80_inst_unimplemented,
/* 0xAC */ z80_inst_unimplemented,
/* 0xAD */ z80_inst_unimplemented,
/* 0xAE */ z80_inst_unimplemented,
/* 0xAF */ z80_inst_unimplemented,
/* 0xB0 */ z80_inst_unimplemented,
/* 0xB1 */ z80_inst_unimplemented,
/* 0xB2 */ z80_inst_unimplemented,
/* 0xB3 */ z80_inst_unimplemented,
/* 0xB4 */ z80_inst_unimplemented,
/* 0xB5 */ z80_inst_unimplemented,
/* 0xB6 */ z80_inst_unimplemented,
/* 0xB7 */ z80_inst_unimplemented,
/* 0xB8 */ z80_inst_unimplemented,
/* 0xB9 */ z80_inst_unimplemented,
/* 0xBA */ z80_inst_unimplemented,
/* 0xBB */ z80_inst_unimplemented,
/* 0xBC */ z80_inst_unimplemented,
/* 0xBD */ z80_inst_unimplemented,
/* 0xBE */ z80_inst_unimplemented,
/* 0xBF */ z80_inst_unimplemented,
/* 0xC0 */ z80_inst_unimplemented,
/* 0xC1 */ z80_inst_unimplemented,
/* 0xC2 */ z80_inst_unimplemented,
/* 0xC3 */ z80_inst_unimplemented,
/* 0xC4 */ z80_inst_unimplemented,
/* 0xC5 */ z80_inst_unimplemented,
/* 0xC6 */ z80_inst_unimplemented,
/* 0xC7 */ z80_inst_unimplemented,
/* 0xC8 */ z80_inst_unimplemented,
/* 0xC9 */ z80_inst_unimplemented,
/* 0xCA */ z80_inst_unimplemented,
/* 0xCB */ z80_inst_unimplemented,
/* 0xCC */ z80_inst_unimplemented,
/* 0xCD */ z80_inst_unimplemented,
/* 0xCE */ z80_inst_unimplemented,
/* 0xCF */ z80_inst_unimplemented,
/* 0xD0 */ z80_inst_unimplemented,
/* 0xD1 */ z80_inst_unimplemented,
/* 0xD2 */ z80_inst_unimplemented,
/* 0xD3 */ z80_inst_unimplemented,
/* 0xD4 */ z80_inst_unimplemented,
/* 0xD5 */ z80_inst_unimplemented,
/* 0xD6 */ z80_inst_unimplemented,
/* 0xD7 */ z80_inst_unimplemented,
/* 0xD8 */ z80_inst_unimplemented,
/* 0xD9 */ z80_inst_unimplemented,
/* 0xDA */ z80_inst_unimplemented,
/* 0xDB */ z80_inst_unimplemented,
/* 0xDC */ z80_inst_unimplemented,
/* 0xDD */ z80_inst_unimplemented,
/* 0xDE */ z80_inst_unimplemented,
/* 0xDF */ z80_inst_unimplemented,
/* 0xE0 */ z80_inst_unimplemented,
/* 0xE1 */ z80_inst_unimplemented,
/* 0xE2 */ z80_inst_unimplemented,
/* 0xE3 */ z80_inst_unimplemented,
/* 0xE4 */ z80_inst_unimplemented,
/* 0xE5 */ z80_inst_unimplemented,
/* 0xE6 */ z80_inst_unimplemented,
/* 0xE7 */ z80_inst_unimplemented,
/* 0xE8 */ z80_inst_unimplemented,
/* 0xE9 */ z80_inst_unimplemented,
/* 0xEA */ z80_inst_unimplemented,
/* 0xEB */ z80_inst_unimplemented,
/* 0xEC */ z80_inst_unimplemented,
/* 0xED */ z80_inst_unimplemented,
/* 0xEE */ z80_inst_unimplemented,
/* 0xEF */ z80_inst_unimplemented,
/* 0xF0 */ z80_inst_unimplemented,
/* 0xF1 */ z80_inst_unimplemented,
/* 0xF2 */ z80_inst_unimplemented,
/* 0xF3 */ z80_inst_unimplemented,
/* 0xF4 */ z80_inst_unimplemented,
/* 0xF5 */ z80_inst_unimplemented,
/* 0xF6 */ z80_inst_unimplemented,
/* 0xF7 */ z80_inst_unimplemented,
/* 0xF8 */ z80_inst_unimplemented,
/* 0xF9 */ z80_inst_unimplemented,
/* 0xFA */ z80_inst_unimplemented,
/* 0xFB */ z80_inst_unimplemented,
/* 0xFC */ z80_inst_unimplemented,
/* 0xFD */ z80_inst_unimplemented,
/* 0xFE */ z80_inst_unimplemented,
/* 0xFF */ z80_inst_unimplemented
}; };

Loading…
Cancel
Save