~rabbits/uxn-playdate

4793e86c78400bd5dd78bfa987e11d98fef4209c — neauoire 5 months ago eba9ba2
Load rom directly
3 files changed, 12 insertions(+), 65 deletions(-)

M Makefile
M build.sh
M src/main.c
M Makefile => Makefile +1 -0
@@ 46,5 46,6 @@ ULIBS =
include $(SDK)/C_API/buildsupport/common.mk

sim: all
	cp etc/boot.rom $(abspath $(PRODUCT))
	$(SDK)/bin/PlaydateSimulator $(abspath $(PRODUCT))


M build.sh => build.sh +3 -4
@@ 1,14 1,13 @@
#!/bin/sh -e

TARGET=etc/controller.tal
TARGET=etc/catclock.tal

rm -rf bin
mkdir bin

uxnasm $TARGET bin/program.rom
uxnasm etc/format-c.tal bin/format-c.rom
uxncli bin/format-c.rom bin/program.rom
uxnasm $TARGET etc/boot.rom

clang-format -i src/main.c
clang-format -i src/devices/ppu.c
clang-format -i src/devices/ppu.h


M src/main.c => src/main.c +8 -61
@@ 9,61 9,6 @@ static PlaydateAPI *pd = NULL;
Uxn u;
Ppu ppu;

unsigned char rom[] = {
	0xa0, 0x0f, 0xff, 0x80, 0x08, 0x37, 0xa0, 0x0f, 0x0f, 0x80, 0x0a, 0x37, 0xa0, 0x0f, 0x0f, 0x80, 
	0x0c, 0x37, 0x80, 0x22, 0x36, 0x80, 0x01, 0x3f, 0x80, 0x00, 0x31, 0x80, 0x24, 0x36, 0x80, 0x01, 
	0x3f, 0x80, 0x02, 0x31, 0xa0, 0x00, 0x68, 0x80, 0x04, 0x31, 0xa0, 0x00, 0x30, 0x80, 0x06, 0x31, 
	0x80, 0x00, 0x30, 0x80, 0x04, 0x30, 0x80, 0x01, 0x3f, 0x39, 0x80, 0x08, 0x31, 0x80, 0x02, 0x30, 
	0x80, 0x06, 0x30, 0x80, 0x01, 0x3f, 0x39, 0x80, 0x0a, 0x31, 0x80, 0x08, 0x30, 0x80, 0x04, 0x30, 
	0x38, 0x80, 0x0c, 0x31, 0x80, 0x0a, 0x30, 0x80, 0x06, 0x30, 0x38, 0x80, 0x0e, 0x31, 0xa0, 0x01, 
	0x7a, 0x80, 0x80, 0x37, 0x80, 0x08, 0x30, 0x80, 0x0a, 0x30, 0x80, 0x0c, 0x30, 0x80, 0x0e, 0x30, 
	0x80, 0x03, 0xa0, 0x03, 0x22, 0x2e, 0x80, 0x11, 0x0e, 0x00, 0x80, 0x0d, 0x0e, 0x80, 0x82, 0x16, 
	0x80, 0x08, 0x08, 0x0c, 0x00, 0xa0, 0x01, 0x0e, 0x17, 0x00, 0x80, 0x82, 0x16, 0x0f, 0x80, 0x08, 
	0x30, 0xa0, 0x00, 0x10, 0x38, 0x80, 0x28, 0x37, 0x80, 0x0a, 0x30, 0xa0, 0x00, 0x10, 0x38, 0x80, 
	0x2a, 0x37, 0xa0, 0x03, 0x8e, 0x80, 0x2c, 0x37, 0x80, 0x03, 0xcf, 0x80, 0x04, 0x1f, 0x80, 0x01, 
	0x1c, 0x19, 0x80, 0x2f, 0x17, 0x80, 0x2a, 0x36, 0xa0, 0x00, 0x10, 0x38, 0x80, 0x2a, 0x37, 0xa0, 
	0x03, 0x96, 0x80, 0x2c, 0x37, 0x80, 0x03, 0xcf, 0x80, 0x05, 0x1f, 0x80, 0x01, 0x1c, 0x19, 0x80, 
	0x2f, 0x17, 0x80, 0x2a, 0x36, 0xa0, 0x00, 0x08, 0x39, 0x80, 0x2a, 0x37, 0x80, 0x28, 0x36, 0xa0, 
	0x00, 0x08, 0x39, 0x80, 0x28, 0x37, 0xa0, 0x03, 0x9e, 0x80, 0x2c, 0x37, 0x80, 0x03, 0xcf, 0x80, 
	0x06, 0x1f, 0x80, 0x01, 0x1c, 0x19, 0x80, 0x2f, 0x17, 0x80, 0x28, 0x36, 0xa0, 0x00, 0x10, 0x38, 
	0x80, 0x28, 0x37, 0xa0, 0x03, 0xa6, 0x80, 0x2c, 0x37, 0x80, 0x03, 0xcf, 0x80, 0x07, 0x1f, 0x80, 
	0x01, 0x1c, 0x19, 0x80, 0x2f, 0x17, 0x80, 0x28, 0x36, 0xa0, 0x00, 0x08, 0x39, 0x80, 0x28, 0x37, 
	0xa0, 0x03, 0x86, 0x80, 0x2c, 0x37, 0x80, 0x03, 0x80, 0x2f, 0x17, 0x80, 0x02, 0x30, 0xa0, 0x00, 
	0x09, 0x38, 0x80, 0x2a, 0x37, 0x80, 0x00, 0x30, 0xa0, 0x00, 0x09, 0x39, 0x80, 0x28, 0x37, 0xa0, 
	0x03, 0xae, 0x80, 0x2c, 0x37, 0x80, 0x03, 0xcf, 0x80, 0x03, 0x1f, 0x80, 0x01, 0x1c, 0x19, 0x80, 
	0x2f, 0x17, 0x80, 0x00, 0x30, 0xa0, 0x00, 0x04, 0x38, 0x80, 0x28, 0x37, 0xa0, 0x03, 0xae, 0x80, 
	0x2c, 0x37, 0x80, 0x03, 0xcf, 0x80, 0x02, 0x1f, 0x80, 0x01, 0x1c, 0x19, 0x80, 0x2f, 0x17, 0x80, 
	0x02, 0x30, 0x80, 0x2a, 0x37, 0x80, 0x00, 0x30, 0xa0, 0x00, 0x18, 0x38, 0x80, 0x28, 0x37, 0xa0, 
	0x03, 0xb6, 0x80, 0x2c, 0x37, 0x80, 0x03, 0xcf, 0x80, 0x01, 0x1f, 0x80, 0x01, 0x1c, 0x19, 0x80, 
	0x2f, 0x17, 0x80, 0x2a, 0x36, 0xa0, 0x00, 0x0a, 0x38, 0x80, 0x2a, 0x37, 0xa0, 0x04, 0x16, 0x80, 
	0x2c, 0x37, 0x80, 0x03, 0x80, 0x2f, 0x17, 0x80, 0x02, 0x30, 0x80, 0x2a, 0x37, 0x80, 0x00, 0x30, 
	0xa0, 0x00, 0x24, 0x38, 0x80, 0x28, 0x37, 0xa0, 0x03, 0xb6, 0x80, 0x2c, 0x37, 0x80, 0x03, 0x4f, 
	0x80, 0x01, 0x1c, 0x19, 0x80, 0x2f, 0x17, 0x80, 0x2a, 0x36, 0xa0, 0x00, 0x0a, 0x38, 0x80, 0x2a, 
	0x37, 0xa0, 0x04, 0x0e, 0x80, 0x2c, 0x37, 0x80, 0x03, 0x80, 0x2f, 0x17, 0x80, 0x00, 0x30, 0xa0, 
	0x00, 0x10, 0x39, 0x80, 0x28, 0x37, 0x80, 0x02, 0x30, 0xa0, 0x00, 0x10, 0x39, 0x80, 0x2a, 0x37, 
	0x80, 0x01, 0x80, 0x26, 0x17, 0x80, 0x82, 0x36, 0x80, 0x06, 0x0e, 0x80, 0x00, 0x80, 0x26, 0x17, 
	0x6c, 0x04, 0x80, 0x00, 0x0e, 0x06, 0x80, 0x04, 0x1f, 0x80, 0x00, 0x0e, 0x80, 0x00, 0x04, 0x80, 
	0x0f, 0x1c, 0x80, 0x30, 0x3f, 0xa0, 0x03, 0xbe, 0x38, 0x80, 0x2c, 0x37, 0x80, 0x03, 0x80, 0x2f, 
	0x17, 0x6c, 0x0f, 0x26, 0x80, 0x3c, 0x33, 0x80, 0x2b, 0x33, 0x26, 0x80, 0x49, 0x33, 0x80, 0x0f, 
	0x33, 0x26, 0x80, 0x31, 0x33, 0x80, 0x13, 0x33, 0x26, 0x80, 0x31, 0x33, 0x80, 0x05, 0x33, 0xa0, 
	0x00, 0x00, 0x21, 0xa0, 0x00, 0x00, 0x26, 0x80, 0x28, 0x37, 0xa0, 0x00, 0x00, 0x80, 0x2a, 0x37, 
	0xcf, 0x80, 0x2e, 0x97, 0xa0, 0x00, 0x00, 0x80, 0x2a, 0x37, 0x17, 0x21, 0xaa, 0x80, 0xe6, 0x0d, 
	0x22, 0x22, 0xa0, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x26, 0x80, 0x2a, 0x37, 0xa0, 0x00, 0x00, 0x80, 
	0x28, 0x37, 0xcf, 0x80, 0x2e, 0x97, 0xa0, 0x00, 0x00, 0x80, 0x28, 0x37, 0x17, 0x21, 0xaa, 0x80, 
	0xe6, 0x0d, 0x22, 0x22, 0x42, 0x6c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7e, 0xff, 
	0xe7, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0xe7, 0xff, 0x7e, 0x7f, 0xff, 
	0xef, 0xcf, 0xcf, 0xef, 0xff, 0x7f, 0xfe, 0xff, 0xf7, 0xf3, 0xf3, 0xf7, 0xff, 0xfe, 0x00, 0x00, 
	0x7e, 0xff, 0xff, 0x7e, 0x00, 0x00, 0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x7c, 
	0x82, 0x82, 0x82, 0x82, 0x82, 0x7c, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x7c, 
	0x82, 0x02, 0x7c, 0x80, 0x80, 0xfe, 0x00, 0x7c, 0x82, 0x02, 0x1c, 0x02, 0x82, 0x7c, 0x00, 0x0c, 
	0x14, 0x24, 0x44, 0x84, 0xfe, 0x04, 0x00, 0xfe, 0x80, 0x80, 0x7c, 0x02, 0x82, 0x7c, 0x00, 0x7c, 
	0x82, 0x80, 0xfc, 0x82, 0x82, 0x7c, 0x00, 0xfe, 0x02, 0x02, 0x04, 0x08, 0x10, 0x10, 0x00, 0x7c, 
	0x82, 0x82, 0x7c, 0x82, 0x82, 0x7c, 0x00, 0x7c, 0x82, 0x82, 0x7e, 0x02, 0x82, 0x7c, 0x00, 0x7c, 
	0x82, 0x02, 0x7e, 0x82, 0x82, 0x7e, 0x00, 0xfc, 0x82, 0x82, 0xfc, 0x82, 0x82, 0xfc, 0x00, 0x7c, 
	0x82, 0x80, 0x80, 0x80, 0x82, 0x7c, 0x00, 0xfc, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfc, 0x00, 0xfe, 
	0x80, 0x80, 0xfe, 0x80, 0x80, 0xfe, 0x00, 0xfe, 0x80, 0x80, 0xf0, 0x80, 0x80, 0x80, 
};

/* Varvara */

static const char *errors[] = {


@@ 86,11 31,13 @@ emu_error(char *msg, const char *err)
}

static int
emu_load(unsigned char *r)
load(Uxn *u, char *filepath)
{
	int i, len = sizeof(rom);
	for(i = 0; i < len; i++)
		u.ram[PAGE_PROGRAM + i] = rom[i];
	SDFile *f = pd->file->open(filepath, kFileRead | kFileReadData);
	if(f == NULL)
		return emu_error("Load failed", filepath);
	pd->file->read(f, u->ram + PAGE_PROGRAM, sizeof(u->ram) - PAGE_PROGRAM);
	pd->system->logToConsole("Loaded %s\n", filepath);
	return 1;
}



@@ 178,12 125,12 @@ emu_deo(Uxn *u, Uint8 addr, Uint8 v)
}

static int
emu_start(Uxn*u, char *filename)
emu_start(Uxn *u, char *filename)
{
	free(u->ram);
	if(!uxn_boot(u, (Uint8 *)calloc(0x10300, sizeof(Uint8)), emu_dei, emu_deo))
		return emu_error("Boot", "Failed");
	if(!emu_load(rom))
	if(!load(u, filename))
		return emu_error("Load", "Failed");
	if(!uxn_eval(u, PAGE_PROGRAM))
		return emu_error("Boot", "Failed to start rom.");