interrupt: first-pass implementation of interrupts

Only manual and V-blank interrupts work, for now. This implements
enough to make the EI and DI parts of Blargg's Interrupt test pass.
This commit is contained in:
2018-09-20 20:55:51 -07:00
parent 593d9d3600
commit 1076d02638
10 changed files with 240 additions and 23 deletions

View File

@@ -1,5 +1,6 @@
#include "gbemu/video.h"
#include "gbemu/memory.h"
#include "gbemu/interrupt.h"
#include "common/common.h"
#include "common/bmp.h"
@@ -9,7 +10,6 @@
/* TODO: This whole implementation is very simple.*/
/* TODO: Actual graphics output */
/* TODO: Implementation of most registers */
/* TODO: Interrupts */
static struct bmp *bmp;
@@ -28,12 +28,13 @@ static uint8_t color_tbl[4] = {
0,
};
void gb_video_init(struct gb_video *video, struct gb_memory *memory)
void gb_video_init(struct gb_video *video, struct gb_memory *memory, struct gb_interrupt *interrupt)
{
memset(video, 0, sizeof(*video));
video->debug_logging = 0;
video->memory = memory;
video->interrupt = interrupt;
bmp = bmp_new(BMP_GRAYSCALE, BUFFER_WIDTH, BUFFER_HEIGHT);
}
@@ -114,12 +115,15 @@ void gb_video_cycle(struct gb_video *video, int cycles)
video->curline += 1;
if (video->curline > LCD_Y_MAX) {
video->curline = 0;
gb_interrupt_clear(video->interrupt, GB_INT_VBLANK);
if (video->lcdcont & (1 << 7)) {
screenshot_count++;
if (screenshot_count % 30 == 0) {
gb_video_screenshot(video);
}
}
} else if (video->curline == 144) {
gb_interrupt_set(video->interrupt, GB_INT_VBLANK);
}
}
}