# HG changeset patch # User Michael Pavone # Date 1459125362 25200 # Node ID 04d8efe7a1f04051d297b378c8668b7a0aa53bd4 # Parent 9f575f77a157f58560707a72df858a75c7cb2736 Initial stab at video output and background color rendering. Fixed address decoding in address port write handler. diff -r 9f575f77a157 -r 04d8efe7a1f0 Makefile --- a/Makefile Sun Mar 27 17:32:09 2016 -0700 +++ b/Makefile Sun Mar 27 17:36:02 2016 -0700 @@ -7,7 +7,10 @@ TARGETDIR:=release endif #DEBUG -all : $(TARGETDIR)/s16 +CFLAGS:=$(shell pkg-config --cflags-only-I sdl2) $(CFLAGS) +LDFLAGS:=$(shell pkg-config --libs sdl2) + +all : $(TARGETDIR) $(TARGETDIR)/s16 $(TARGETDIR)/asm clean : rm -f $(TARGETDIR)/*.o $(TARGETDIR)/s16 $(TARGETDIR)/asm @@ -15,11 +18,11 @@ $(TARGETDIR) : mkdir $(TARGETDIR) -$(TARGETDIR)/s16 : $(TARGETDIR)/main.o $(TARGETDIR)/cpu.o $(TARGETDIR)/vdp.o +$(TARGETDIR)/s16 : $(TARGETDIR)/main.o $(TARGETDIR)/cpu.o $(TARGETDIR)/vdp.o $(TARGETDIR)/system_sdl.o $(CC) -o $@ $^ $(LDFLAGS) $(TARGETDIR)/asm : $(TARGETDIR)/asm.o $(TARGETDIR)/cpu.o $(CC) -o $@ $^ $(LDFLAGS) -$(TARGETDIR)/%.o : src/%.c $(TARGETDIR) +$(TARGETDIR)/%.o : src/%.c $(CC) $(CFLAGS) -c -o $@ $< diff -r 9f575f77a157 -r 04d8efe7a1f0 bgcolor.s16 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bgcolor.s16 Sun Mar 27 17:36:02 2016 -0700 @@ -0,0 +1,7 @@ + ldim 0, r0 + ldimh $FF, r0 + outi 14, r0 + ldim $F, r0 + outi 15, r0 +done + bra done diff -r 9f575f77a157 -r 04d8efe7a1f0 src/main.c --- a/src/main.c Sun Mar 27 17:32:09 2016 -0700 +++ b/src/main.c Sun Mar 27 17:36:02 2016 -0700 @@ -4,6 +4,7 @@ #include #include "cpu.h" #include "vdp.h" +#include "system.h" #define CYCLES_PER_FRAME (832*262) @@ -140,6 +141,11 @@ context.proc->port_handlers[PORT_VRAM_ADDRESS].write = address_port_write; context.proc->port_handlers[PORT_VRAM_ADDRESS].read = address_port_read; context.proc->port_handlers[PORT_VRAM_DATA].write = data_port_write; + + if (!system_init(640, 480)) { + return 1; + } + run_console(&context); return 0; } diff -r 9f575f77a157 -r 04d8efe7a1f0 src/vdp.c --- a/src/vdp.c Sun Mar 27 17:32:09 2016 -0700 +++ b/src/vdp.c Sun Mar 27 17:36:02 2016 -0700 @@ -1,18 +1,23 @@ #include #include #include "vdp.h" +#include "system.h" void vdp_init(vdp *context, uint32_t clock_div) { memset(context, 0, sizeof(vdp)); - context->clock_inc = clock_div; + //clock div specifies the pixel clock divider + //but our emulation step is half that fast + context->clock_inc = clock_div*2; + context->drawbuffer = context->linebuffers; + context->readbuffer = context->linebuffers+320; } void vdp_run(vdp *context, uint32_t target) { while (context->cycles < target) { - context->hcounter++; + context->hcounter+=2; if (context->hcounter == 416) { context->hcounter = 0; context->vcounter++; @@ -21,6 +26,29 @@ } } //TODO: do rendering stuff here + //Draw to framebuffer + if (context->vcounter > 8 && context->vcounter < 249 && context->hcounter < 320) { + if (!context->hcounter && context->vcounter == 9) { + context->framebuffer = system_get_framebuffer(&context->pitch); + //pitch is in terms of bytes, but we want it in terms of pixels + context->pitch /= sizeof(uint16_t); + } + uint16_t *dest = context->framebuffer + (context->vcounter - 9) * context->pitch + context->hcounter; + if (context->status & VDP_STATUS_ENABLED && context->vcounter > 16 && context->vcounter < 241) { + *dest = context->cram[0x3F & context->readbuffer[context->hcounter]]; + dest++; + *dest = context->cram[0x3F & context->readbuffer[context->hcounter+1]]; + } else { + //Display is disabled or we're in the border area, draw the background color + *dest = *context->cram; + dest++; + *dest = *context->cram; + } + } else if(!context->hcounter && context->vcounter == 249) { + system_framebuffer_updated(); + context->framebuffer = NULL; + } + //Handle the FIFO if (context->status & VDP_STATUS_FIFO) { switch (context->fifo_dest) { @@ -51,13 +79,13 @@ void vdp_write_address(vdp *context, uint16_t value) { context->status &= ~VDP_STATUS_FIFO; - if (value & 0x8000) { + if (!(value & 0x8000)) { context->fifo_dest = FIFO_DEST_VRAM; context->dest_offset = (value & (sizeof(context->vram) -1))/2; - } else if (value & 0xFF00 == 0xFE00) { + } else if ((value & 0xFF00) == 0xFE00) { context->fifo_dest = FIFO_DEST_SRAM; context->dest_offset = (value & (sizeof(context->sram) -1))/2; - } else if (value & 0xFF00 == 0xFF00) { + } else if ((value & 0xFF00) == 0xFF00) { context->fifo_dest = FIFO_DEST_CRAM; context->dest_offset = (value & (sizeof(context->cram) -1))/2; } diff -r 9f575f77a157 -r 04d8efe7a1f0 src/vdp.h --- a/src/vdp.h Sun Mar 27 17:32:09 2016 -0700 +++ b/src/vdp.h Sun Mar 27 17:36:02 2016 -0700 @@ -2,8 +2,12 @@ #define VDP_H_ typedef struct { + uint16_t *framebuffer; + uint8_t *drawbuffer; + uint8_t *readbuffer; uint32_t cycles; uint32_t clock_inc; + int pitch; uint16_t fifo; uint16_t dest_offset; @@ -16,6 +20,7 @@ uint16_t hscroll; uint16_t vram[32*512]; + uint8_t linebuffers[320*2]; uint16_t sram[64*2]; uint16_t cram[64]; @@ -29,9 +34,10 @@ FIFO_DEST_CRAM }; -#define VDP_STATUS_FIFO 1 -#define VDP_STATUS_VRAM 2 -#define VDP_STATUS_SRAM 4 +#define VDP_STATUS_FIFO 1 +#define VDP_STATUS_VRAM 2 +#define VDP_STATUS_SRAM 4 +#define VDP_STATUS_ENABLED 8 void vdp_init(vdp *context, uint32_t clock_div); void vdp_run(vdp *context, uint32_t target);