Removed uxncli
This commit is contained in:
parent
ac45af6746
commit
51542bc5ef
5
build.sh
5
build.sh
|
@ -7,7 +7,12 @@ rm -f ./bin/*
|
|||
|
||||
echo "Building.."
|
||||
mkdir -p bin
|
||||
|
||||
# Build(debug)
|
||||
gcc -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 src/uxn.c src/devices/system.c src/devices/screen.c src/uxn11.c -o bin/uxn11 -lX11
|
||||
|
||||
# Build(release)
|
||||
# gcc src/uxn.c src/devices/system.c src/devices/screen.c src/uxn11.c -o bin/uxn11 -lX11
|
||||
|
||||
echo "Running.."
|
||||
bin/uxn11 etc/screen.rom
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
#ifndef UXN_UXN_H
|
||||
#define UXN_UXN_H
|
||||
|
||||
/*
|
||||
Copyright (c) 2021 Devine Lu Linvega
|
||||
|
||||
|
@ -49,4 +46,3 @@ int uxn_boot(Uxn *u, Uint8 *ram);
|
|||
int uxn_eval(Uxn *u, Uint16 pc);
|
||||
int uxn_halt(Uxn *u, Uint8 error, Uint16 addr);
|
||||
Device *uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *, Uint8), void (*deofn)(Device *, Uint8));
|
||||
#endif /* UXN_UXN_H */
|
||||
|
|
18
src/uxn11.c
18
src/uxn11.c
|
@ -13,8 +13,6 @@
|
|||
#include "devices/system.h"
|
||||
#include "devices/screen.h"
|
||||
|
||||
static Device *devsystem, *devconsole, *devscreen;
|
||||
|
||||
static int
|
||||
error(char *msg, const char *err)
|
||||
{
|
||||
|
@ -22,13 +20,6 @@ error(char *msg, const char *err)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
set_size(Uint16 width, Uint16 height, int is_resize)
|
||||
{
|
||||
screen_resize(&uxn_screen, width, height);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
system_deo_special(Device *d, Uint8 port)
|
||||
{
|
||||
|
@ -92,9 +83,9 @@ start(Uxn *u)
|
|||
{
|
||||
if(!uxn_boot(u, (Uint8 *)calloc(0x10000, sizeof(Uint8))))
|
||||
return error("Boot", "Failed");
|
||||
/* system */ devsystem = uxn_port(u, 0x0, system_dei, system_deo);
|
||||
/* console */ devconsole = uxn_port(u, 0x1, nil_dei, console_deo);
|
||||
/* screen */ devscreen = uxn_port(u, 0x2, screen_dei, screen_deo);
|
||||
/* system */ uxn_port(u, 0x0, system_dei, system_deo);
|
||||
/* console */ uxn_port(u, 0x1, nil_dei, console_deo);
|
||||
/* screen */ uxn_port(u, 0x2, screen_dei, screen_deo);
|
||||
/* empty */ uxn_port(u, 0x3, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0x4, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0x5, nil_dei, nil_deo);
|
||||
|
@ -123,8 +114,7 @@ main(int argc, char **argv)
|
|||
if(!load(&u, argv[1]))
|
||||
return error("Load", "Failed");
|
||||
|
||||
if(!set_size(WIDTH, HEIGHT, 0))
|
||||
return error("Window", "Failed to set window size.");
|
||||
screen_resize(&uxn_screen, WIDTH, HEIGHT);
|
||||
|
||||
if(!uxn_eval(&u, PAGE_PROGRAM))
|
||||
return error("Boot", "Failed to start rom.");
|
||||
|
|
148
src/uxncli.c
148
src/uxncli.c
|
@ -1,148 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "uxn.h"
|
||||
#include "devices/system.h"
|
||||
#include "devices/file.h"
|
||||
#include "devices/datetime.h"
|
||||
|
||||
/*
|
||||
Copyright (c) 2021 Devine Lu Linvega
|
||||
|
||||
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 Device *devfile0;
|
||||
|
||||
static int
|
||||
error(char *msg, const char *err)
|
||||
{
|
||||
fprintf(stderr, "Error %s: %s\n", msg, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
system_deo_special(Device *d, Uint8 port)
|
||||
{
|
||||
(void)d;
|
||||
(void)port;
|
||||
}
|
||||
|
||||
static void
|
||||
console_deo(Device *d, Uint8 port)
|
||||
{
|
||||
FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr
|
||||
: 0;
|
||||
if(fd) {
|
||||
fputc(d->dat[port], fd);
|
||||
fflush(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
file_deo(Device *d, Uint8 port)
|
||||
{
|
||||
file_i_deo(d - devfile0, d, port);
|
||||
}
|
||||
|
||||
static Uint8
|
||||
file_dei(Device *d, Uint8 port)
|
||||
{
|
||||
return file_i_dei(d - devfile0, d, port);
|
||||
}
|
||||
|
||||
static Uint8
|
||||
nil_dei(Device *d, Uint8 port)
|
||||
{
|
||||
return d->dat[port];
|
||||
}
|
||||
|
||||
static void
|
||||
nil_deo(Device *d, Uint8 port)
|
||||
{
|
||||
(void)d;
|
||||
(void)port;
|
||||
}
|
||||
|
||||
static int
|
||||
console_input(Uxn *u, char c)
|
||||
{
|
||||
Device *d = &u->dev[1];
|
||||
d->dat[0x2] = c;
|
||||
return uxn_eval(u, GETVECTOR(d));
|
||||
}
|
||||
|
||||
static void
|
||||
run(Uxn *u)
|
||||
{
|
||||
Device *d = &u->dev[0];
|
||||
while(!d->dat[0xf]) {
|
||||
int c = fgetc(stdin);
|
||||
if(c != EOF)
|
||||
console_input(u, (Uint8)c);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
load(Uxn *u, char *filepath)
|
||||
{
|
||||
FILE *f;
|
||||
int r;
|
||||
if(!(f = fopen(filepath, "rb"))) return 0;
|
||||
r = fread(u->ram + PAGE_PROGRAM, 1, 0x10000 - PAGE_PROGRAM, f);
|
||||
fclose(f);
|
||||
if(r < 1) return 0;
|
||||
fprintf(stderr, "Loaded %s\n", filepath);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
start(Uxn *u)
|
||||
{
|
||||
if(!uxn_boot(u, (Uint8 *)calloc(0x10000, sizeof(Uint8))))
|
||||
return error("Boot", "Failed");
|
||||
/* system */ uxn_port(u, 0x0, system_dei, system_deo);
|
||||
/* console */ uxn_port(u, 0x1, nil_dei, console_deo);
|
||||
/* empty */ uxn_port(u, 0x2, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0x3, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0x4, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0x5, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0x6, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0x7, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0x8, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0x9, nil_dei, nil_deo);
|
||||
/* file0 */ devfile0 = uxn_port(u, 0xa, file_dei, file_deo);
|
||||
/* file1 */ uxn_port(u, 0xb, file_dei, file_deo);
|
||||
/* datetime */ uxn_port(u, 0xc, datetime_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0xd, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0xe, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0xf, nil_dei, nil_deo);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
Uxn u;
|
||||
int i;
|
||||
if(argc < 2)
|
||||
return error("Usage", "uxncli game.rom args");
|
||||
if(!start(&u))
|
||||
return error("Start", "Failed");
|
||||
if(!load(&u, argv[1]))
|
||||
return error("Load", "Failed");
|
||||
if(!uxn_eval(&u, PAGE_PROGRAM))
|
||||
return error("Init", "Failed");
|
||||
for(i = 2; i < argc; i++) {
|
||||
char *p = argv[i];
|
||||
while(*p) console_input(&u, *p++);
|
||||
console_input(&u, '\n');
|
||||
}
|
||||
run(&u);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue