Files
gbemu/lib/dma.c

41 lines
648 B
C

#include <dma.h>
#include <ppu.h>
#include <bus.h>
static dma_context ctx;
void dma_start(u8 start) {
ctx.active = true;
ctx.byte = 0;
ctx.start_delay = 2;
ctx.value = start;
}
void dma_tick() {
if (!ctx.active) {
return;
}
if (ctx.start_delay) {
ctx.start_delay--;
return;
}
ppu_oam_write(ctx.byte, bus_read(((ctx.value << 8)) + ctx.byte));
ctx.byte++;
ctx.active = ctx.byte < 0xA0;
}
bool dma_transferring() {
return ctx.active;
}
void dma_save_state(dma_state* state) {
state->ctx = ctx;
}
void dma_load_state(const dma_state* state) {
ctx = state->ctx;
}