diff --git a/cmd/go6502/main.go b/cmd/go6502/main.go index 7ed579c..e2a80d8 100644 --- a/cmd/go6502/main.go +++ b/cmd/go6502/main.go @@ -15,7 +15,7 @@ func run() { deviceMap, err := bus.New( bus.NewRam(0x0, 0x1000), - bus.NewRom(0x8000, "./code/blinkc"), + bus.NewRom(0x8000, "./code/graphics"), graphics.CreatePPU(0x1000), imu, ) diff --git a/code/Makefile b/code/Makefile index f5a0962..1ee2464 100644 --- a/code/Makefile +++ b/code/Makefile @@ -1,4 +1,7 @@ +GFX_FILES = gfx/gfx.c +GFX = $(patsubst %.c,%.o,$(GFX_FILES)) + %.o: %.s ca65 -o $@ $^ -t none @@ -9,5 +12,8 @@ cl65 -o $@ $^ -t none -c +graphics: graphics.o $(GFX) reset.o + ld65 -o $@ $^ none.lib -C link.ld + blinkc: blinkc.o reset.o ld65 -o $@ $^ -C link.ld diff --git a/code/gfx/gfx.c b/code/gfx/gfx.c new file mode 100644 index 0000000..e857267 --- /dev/null +++ b/code/gfx/gfx.c @@ -0,0 +1,27 @@ +#include "gfx.h" +#include + +char * video_buffer; +uint8_t width; +uint8_t height; + +void gfx_init(uintptr_t video_buffer_address, uint8_t w, uint8_t h) { + video_buffer = (char *)video_buffer_address; + width = w; + height = h; +} + +void clear(color_t color) { + uint8_t i; + uint8_t j; + + for (i = 0; i < width; ++i) { + for (j = 0; j < height; ++j) { + video_buffer[j * width + i] = color; + } + } +} + +color_t get_color(Palette p, uint8_t index) { + return (uint8_t) p << 5 | index && 0b11111; +} \ No newline at end of file diff --git a/code/gfx/gfx.h b/code/gfx/gfx.h new file mode 100644 index 0000000..29d8fe7 --- /dev/null +++ b/code/gfx/gfx.h @@ -0,0 +1,27 @@ + +#ifndef GFX_H +#define GFX_H + +#include + +extern char * video_buffer; +extern uint8_t width; +extern uint8_t height; + +typedef uint8_t color_t; + +void gfx_init(uintptr_t video_buffer_address, uint8_t w, uint8_t h); +void clear(color_t color); + +typedef enum { + Palette0 = 0, + Endesga = 1, + Clear = 2, + + GrayPalette = 7, +} Palette; + + +color_t get_color(Palette p, uint8_t index); + +#endif \ No newline at end of file diff --git a/code/graphics b/code/graphics index 084012b..b7ef519 100644 Binary files a/code/graphics and b/code/graphics differ diff --git a/code/graphics.c b/code/graphics.c new file mode 100644 index 0000000..29f646a --- /dev/null +++ b/code/graphics.c @@ -0,0 +1,10 @@ +#include "gfx/gfx.h" + +void reset() { + color_t red; + + gfx_init(0x1000, 64, 64); + + red = get_color(Endesga, 3); + clear(red); +} \ No newline at end of file diff --git a/code/link.ld b/code/link.ld index 753da7f..4fc530d 100644 --- a/code/link.ld +++ b/code/link.ld @@ -22,6 +22,10 @@ SEGMENTS { load = RAM1 type=bss define=yes; + ZEROPAGE: + load = RAM1 + type = zp + define = yes; RESET: load = ROM1 start = $fffa