Added uxncli and uxnasm for bootstrap

This commit is contained in:
neauoire 2023-12-15 11:31:57 -08:00
parent 6bf8b7b3ac
commit a2463d9b70
3 changed files with 92 additions and 4 deletions

View File

@ -1,11 +1,11 @@
SRC=src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c
SRC=src/uxn.c src/devices/system.c src/devices/console.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c
RELEASE_flags=-std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas
DEBUG_flags=-std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined
ASM=bin/uxnasm
.PHONY: all dest run install uninstall format clean
all: dest bin/uxnasm bin/porporo bin/menu.rom bin/potato.rom bin/wallpaper.rom bin/log.rom
all: dest bin/uxnasm bin/uxncli bin/porporo bin/menu.rom bin/potato.rom bin/wallpaper.rom bin/log.rom
dest:
@ mkdir -p bin
@ -20,8 +20,10 @@ format:
clean:
@ rm -f bin/*
bin/uxnasm: etc/uxnasm.c
@ cc ${RELEASE_flags} etc/uxnasm.c -o bin/uxnasm
bin/uxnasm: src/uxnasm.c
@ cc ${RELEASE_flags} src/uxnasm.c -o bin/uxnasm
bin/uxncli: src/uxncli.c
@ cc ${RELEASE_flags} ${SRC} src/uxncli.c -o bin/uxncli
bin/porporo: ${SRC} src/porporo.c
@ cc ${DEBUG_flags} ${SRC} src/porporo.c -L/usr/local/lib -lSDL2 -o bin/porporo

86
src/uxncli.c Normal file
View File

@ -0,0 +1,86 @@
#include <stdio.h>
#include <stdlib.h>
#include "uxn.h"
#include "devices/system.h"
#include "devices/console.h"
#include "devices/file.h"
#include "devices/datetime.h"
/*
Copyright (c) 2021-2023 Devine Lu Linvega, Andrew Alderwick
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
static Varvara varvara;
Uint8
emu_dei(Uxn *u, Uint8 addr)
{
switch(addr & 0xf0) {
case 0x00: return system_dei(u, addr);
case 0xc0: return datetime_dei(u, addr);
}
return u->dev[addr];
}
void
emu_deo(Uxn *u, Uint8 addr, Uint8 value)
{
Uint8 p = addr & 0x0f, d = addr & 0xf0;
u->dev[addr] = value;
switch(d) {
case 0x00: system_deo(u, &u->dev[d], p); break;
case 0x10: console_deo(&u->dev[d], p); break;
case 0xa0: file_deo(0, u->ram, &u->dev[d], p); break;
case 0xb0: file_deo(1, u->ram, &u->dev[d], p); break;
}
}
static void
emu_run(Uxn *u)
{
while(!u->dev[0x0f]) {
int c = fgetc(stdin);
if(c == EOF) {
console_input(u, 0x00, CONSOLE_END);
break;
}
console_input(u, (Uint8)c, CONSOLE_STD);
}
}
static int
emu_end(Uxn *u)
{
free(u->ram);
return u->dev[0x0f] & 0x7f;
}
int
main(int argc, char **argv)
{
int i = 1;
if(i == argc)
return system_error("usage", "uxncli [-v] file.rom [args..]");
/* Read flags */
if(argv[i][0] == '-' && argv[i][1] == 'v')
return !fprintf(stdout, "Porporo - Console Varvara Emulator, 15 Dec 2023.\n");
varvara.u.ram = (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8));
system_boot(&varvara.u, 0);
if(!system_load(&varvara, &varvara.u, argv[i++]))
return system_error("Init", "Failed to initialize uxn.");
/* Game Loop */
varvara.u.dev[0x17] = argc - i;
if(uxn_eval(&varvara.u, PAGE_PROGRAM)) {
console_listen(&varvara.u, i, argc, argv);
emu_run(&varvara.u);
}
return emu_end(&varvara.u);
}