More interrupt stuff

This commit is contained in:
condret 2024-11-07 18:06:27 +01:00
parent e40c6ef069
commit 27bc6bcc39
4 changed files with 34 additions and 15 deletions

View File

@ -32,7 +32,6 @@ typedef struct gb_timers_t {
} GBTimers; } GBTimers;
bool gb_timers_init(GBTimers *timers, RIO *io); bool gb_timers_init(GBTimers *timers, RIO *io);
void gb_timers_continue(GBTimers *timers, ut32 cycles);
void gb_timers_fini(GBTimers *timers, RIO *io); void gb_timers_fini(GBTimers *timers, RIO *io);
typedef struct gb_joypad_t { typedef struct gb_joypad_t {
@ -51,7 +50,6 @@ typedef struct gb_joypad_t {
} GBJoypad; } GBJoypad;
bool gb_joypad_init(GBJoypad *joypad, RIO *io); bool gb_joypad_init(GBJoypad *joypad, RIO *io);
void gb_joypad_continue(GBJoypad *joypad);
void gb_joypad_fini(GBJoypad *joypad, RIO *io); void gb_joypad_fini(GBJoypad *joypad, RIO *io);
typedef struct gb_interrupts_t { typedef struct gb_interrupts_t {
@ -60,11 +58,11 @@ typedef struct gb_interrupts_t {
} GBInterrupts; } GBInterrupts;
enum { enum {
GB_INTERRUPTS_VBLANK_PENDING = 0, GB_INTERRUPTS_VBLANK = 0,
GB_INTERRUPTS_STAT_PENDING, GB_INTERRUPTS_STAT,
GB_INTERRUPTS_TIMER_PENDING, GB_INTERRUPTS_TIMER,
GB_INTERRUPTS_SERIAL_PENDING, GB_INTERRUPTS_SERIAL,
GB_INTERRUPTS_JOYPAD_PENDING, GB_INTERRUPTS_JOYPAD,
GB_INTERRUPTS_N, //number of interrupts GB_INTERRUPTS_N, //number of interrupts
GB_INTERRUPTS_VBLANK_ENABLED = GB_INTERRUPTS_N, GB_INTERRUPTS_VBLANK_ENABLED = GB_INTERRUPTS_N,
GB_INTERRUPTS_STAT_ENABLED, GB_INTERRUPTS_STAT_ENABLED,
@ -74,10 +72,9 @@ enum {
GB_INTERRUPTS_ENABLED, //general enable of all interrupts GB_INTERRUPTS_ENABLED, //general enable of all interrupts
GB_INTERRUPTS_ENABLE_WAIT, //wait 1 instruction befor enabling interrupts GB_INTERRUPTS_ENABLE_WAIT, //wait 1 instruction befor enabling interrupts
GB_INTERRUPTS_SEEK, //2 bits for seek GB_INTERRUPTS_SEEK, //2 bits for seek
} };
;
bool gb_interrupts_init(GBInterrupts *ints, RIO *io); bool gb_interrupts_init(GBInterrupts *ints, RIO *io);
void gb_interrupts_continue(GBInterrupts *ints);
void gb_interrupts_fini(GBInterrupts *ints, RIO *io); void gb_interrupts_fini(GBInterrupts *ints, RIO *io);
typedef struct gb_dma_t { typedef struct gb_dma_t {
@ -227,6 +224,11 @@ typedef struct gameboy_t {
bool double_speed; bool double_speed;
} GB; } GB;
void gb_interrupts_request(GB *gb, int interrupt);
void gb_interrupts_continue(GB *gb);
void gb_timers_continue(GB *gb, ut32 cycles);
void gb_joypad_continue(GB *gb);
GBPPU *gb_ppu_open (RIO *io, SDL_Renderer *renderer); GBPPU *gb_ppu_open (RIO *io, SDL_Renderer *renderer);
void gb_ppu_continue (GB *gb, ut32 cycles); void gb_ppu_continue (GB *gb, ut32 cycles);
void gb_ppu_close (GBPPU *ppu, RIO *io); void gb_ppu_close (GBPPU *ppu, RIO *io);

View File

@ -114,6 +114,21 @@ void gb_interrupts_fini(GBInterrupts *ints, RIO *io) {
r_io_fd_close (io, ints->fd); r_io_fd_close (io, ints->fd);
} }
void gb_interrupts_continue(GBInterrupts *ints) { void gb_interrupts_continue(GB *gb) {
//TODO //TODO
} }
void gb_interrupts_request (GB *gb, int interrupt) {
switch (interrupt) {
case GB_INTERRUPTS_VBLANK:
case GB_INTERRUPTS_STAT:
case GB_INTERRUPTS_TIMER:
case GB_INTERRUPTS_SERIAL:
case GB_INTERRUPTS_JOYPAD:
gb->interrupts.flags |= interrupt;
break;
default:
break;
}
}

View File

@ -107,7 +107,8 @@ bool gb_joypad_init (GBJoypad *joypad, RIO *io) {
return true;; return true;;
} }
void gb_joypad_continue(GBJoypad *joypad) { void gb_joypad_continue(GB *gb) {
GBJoypad *joypad = &gb->joypad;
joypad->odata &= 0xc0; joypad->odata &= 0xc0;
joypad->odata |= joypad->data & 0x3f; joypad->odata |= joypad->data & 0x3f;
SDL_PumpEvents (); SDL_PumpEvents ();
@ -134,7 +135,7 @@ void gb_joypad_continue(GBJoypad *joypad) {
} }
joypad->data = (joypad->data & 0x30) | (ndata ^ 0xf); joypad->data = (joypad->data & 0x30) | (ndata ^ 0xf);
if (joypad->odata & ndata) { if (joypad->odata & ndata) {
//TODO: request interrupt gb_interrupts_request (gb, GB_INTERRUPTS_JOYPAD);
} }
} }

View File

@ -125,7 +125,8 @@ void gb_timers_fini (GBTimers *timers, RIO *io) {
r_io_fd_close (io, timers->fd); r_io_fd_close (io, timers->fd);
} }
void gb_timers_continue (GBTimers *timers, ut32 cycles) { void gb_timers_continue (GB *gb, ut32 cycles) {
GBTimers *timers = &gb->timers;
bool request_interrupt = false; bool request_interrupt = false;
do { do {
//ensure all falling edges are detected //ensure all falling edges are detected
@ -173,6 +174,6 @@ void gb_timers_continue (GBTimers *timers, ut32 cycles) {
cycles -= _cycles; cycles -= _cycles;
} while (cycles); } while (cycles);
if (request_interrupt) { if (request_interrupt) {
//TODO gb_interrupts_request (gb, GB_INTERRUPTS_TIMER);
} }
} }