From 35fc43f862d6bb541639f334c519627cd7a451af Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Thu, 23 Oct 2025 13:30:39 -0500 Subject: [PATCH] initial --- .gitignore | 6 ++++++ Makefile | 37 ++++++++++++++++++++++++++++++++++ gba-lib | 1 + main.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ palette.py | 7 +++++++ 5 files changed, 110 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 120000 gba-lib create mode 100644 main.c create mode 100644 palette.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..522c166 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.sav +*.map +*.o + +*.elf +*.gba diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..43e2db1 --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +all: main.gba + +CFLAGS += -falign-functions=16 + +LIB = $(PWD)/gba-lib + +include $(LIB)/common.mk + +AFLAGS += -I$(LIB) +CFLAGS += -I$(LIB) + +OBJS = $(LIB)/header.o $(LIB)/load.o $(LIB)/copy.o +OBJS += main.o +OBJS += DSC09311_256.data.o +OBJS += DSC09311_256.data.pal.o + +HEADERS = $(wildcard *.h) + +main.elf: $(OBJS) | $(LIB)/main.lds + $(call LINK_ELF,$(LIB)/main.lds) + +# external + +make-tools: + $(MAKE) -C tools + +%.glyph: %.otb | make-tools + ./tools/otb-convert $< > $@ + +%.glyph.o: %.glyph + $(BUILD_BINARY_O) + +%.data.o: %.data + $(BUILD_BINARY_IMAGE_O) + +%.data.pal.o: %.data.pal + $(BUILD_BINARY_IMAGE_O) diff --git a/gba-lib b/gba-lib new file mode 120000 index 0000000..2d8868e --- /dev/null +++ b/gba-lib @@ -0,0 +1 @@ +../gba-lib \ No newline at end of file diff --git a/main.c b/main.c new file mode 100644 index 0000000..ad5e46e --- /dev/null +++ b/main.c @@ -0,0 +1,59 @@ +extern unsigned int _binary_DSC09311_256_data_pal_start; +extern unsigned int _binary_DSC09311_256_data_pal_end; +extern unsigned int _binary_DSC09311_256_data_pal_size; + +extern unsigned int _binary_DSC09311_256_data_start; +extern unsigned int _binary_DSC09311_256_data_end; +extern unsigned int _binary_DSC09311_256_data_size; + +#include "io_reg.h" +#include "vram.h" +#include "register_values.h" +#include "copy.h" +#include "nib.h" +#include "type.h" +#include "oam.h" + +void _start(void) +{ + int height = 240; + int width = 160; + + u8 * pal = (u8*)&_binary_DSC09311_256_data_pal_start; + u16 * _pram = (u16 *)&pram.bg[0][0]; + for (int color = 0; color < 256; color++) { + int r = pal[color * 3 + 0] >> 3; + int g = pal[color * 3 + 1] >> 3; + int b = pal[color * 3 + 2] >> 3; + _pram[color] = PRAM_RGB15(r, g, b); + } + + u32 _vram; + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + u8 index = ((u8 *)(&_binary_DSC09311_256_data_start))[y * width + x]; + + switch (x & 0x3) { + case 0: _vram = index; break; + case 1: _vram |= index << 8; break; + case 2: _vram |= index << 16; break; + case 3: _vram |= index << 24; + *((u32 *)(0x6000000 + (y * width + x))) = _vram; + break; + } + } + } + + while ((io_reg.VCOUNT & 0xff) < 161); + + io_reg.DISPCNT = + ( DISPCNT__BG2 + | DISPCNT__BG_MODE_4 + | DISPCNT__FRAMEBUFFER(0) + ); + + while (1) { + io_reg.HALTCNT = 0; + }; +} diff --git a/palette.py b/palette.py new file mode 100644 index 0000000..6727deb --- /dev/null +++ b/palette.py @@ -0,0 +1,7 @@ +f = open("DSC09311-256.data.pal", 'rb') +b = f.read() + + +def grouper(iterable, n): + args = [iter(iterable)] * n + return zip(*args, strict=True)