commit 51542bc
neauoire
·
2022-03-27 01:46:17 +0000 UTC
parent ac45af6
Removed uxncli
4 files changed,
+9,
-166
M
build.sh
+5,
-0
1@@ -7,7 +7,12 @@ rm -f ./bin/*
2
3 echo "Building.."
4 mkdir -p bin
5+
6+# Build(debug)
7 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
8
9+# Build(release)
10+# gcc src/uxn.c src/devices/system.c src/devices/screen.c src/uxn11.c -o bin/uxn11 -lX11
11+
12 echo "Running.."
13 bin/uxn11 etc/screen.rom
+0,
-4
1@@ -1,6 +1,3 @@
2-#ifndef UXN_UXN_H
3-#define UXN_UXN_H
4-
5 /*
6 Copyright (c) 2021 Devine Lu Linvega
7
8@@ -49,4 +46,3 @@ int uxn_boot(Uxn *u, Uint8 *ram);
9 int uxn_eval(Uxn *u, Uint16 pc);
10 int uxn_halt(Uxn *u, Uint8 error, Uint16 addr);
11 Device *uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *, Uint8), void (*deofn)(Device *, Uint8));
12-#endif /* UXN_UXN_H */
+4,
-14
1@@ -13,8 +13,6 @@
2 #include "devices/system.h"
3 #include "devices/screen.h"
4
5-static Device *devsystem, *devconsole, *devscreen;
6-
7 static int
8 error(char *msg, const char *err)
9 {
10@@ -22,13 +20,6 @@ error(char *msg, const char *err)
11 return 0;
12 }
13
14-static int
15-set_size(Uint16 width, Uint16 height, int is_resize)
16-{
17- screen_resize(&uxn_screen, width, height);
18- return 1;
19-}
20-
21 void
22 system_deo_special(Device *d, Uint8 port)
23 {
24@@ -92,9 +83,9 @@ start(Uxn *u)
25 {
26 if(!uxn_boot(u, (Uint8 *)calloc(0x10000, sizeof(Uint8))))
27 return error("Boot", "Failed");
28- /* system */ devsystem = uxn_port(u, 0x0, system_dei, system_deo);
29- /* console */ devconsole = uxn_port(u, 0x1, nil_dei, console_deo);
30- /* screen */ devscreen = uxn_port(u, 0x2, screen_dei, screen_deo);
31+ /* system */ uxn_port(u, 0x0, system_dei, system_deo);
32+ /* console */ uxn_port(u, 0x1, nil_dei, console_deo);
33+ /* screen */ uxn_port(u, 0x2, screen_dei, screen_deo);
34 /* empty */ uxn_port(u, 0x3, nil_dei, nil_deo);
35 /* empty */ uxn_port(u, 0x4, nil_dei, nil_deo);
36 /* empty */ uxn_port(u, 0x5, nil_dei, nil_deo);
37@@ -123,8 +114,7 @@ main(int argc, char **argv)
38 if(!load(&u, argv[1]))
39 return error("Load", "Failed");
40
41- if(!set_size(WIDTH, HEIGHT, 0))
42- return error("Window", "Failed to set window size.");
43+ screen_resize(&uxn_screen, WIDTH, HEIGHT);
44
45 if(!uxn_eval(&u, PAGE_PROGRAM))
46 return error("Boot", "Failed to start rom.");
+0,
-148
1@@ -1,148 +0,0 @@
2-#include <stdio.h>
3-#include <stdlib.h>
4-
5-#include "uxn.h"
6-#include "devices/system.h"
7-#include "devices/file.h"
8-#include "devices/datetime.h"
9-
10-/*
11-Copyright (c) 2021 Devine Lu Linvega
12-
13-Permission to use, copy, modify, and distribute this software for any
14-purpose with or without fee is hereby granted, provided that the above
15-copyright notice and this permission notice appear in all copies.
16-
17-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
18-WITH REGARD TO THIS SOFTWARE.
19-*/
20-
21-static Device *devfile0;
22-
23-static int
24-error(char *msg, const char *err)
25-{
26- fprintf(stderr, "Error %s: %s\n", msg, err);
27- return 0;
28-}
29-
30-void
31-system_deo_special(Device *d, Uint8 port)
32-{
33- (void)d;
34- (void)port;
35-}
36-
37-static void
38-console_deo(Device *d, Uint8 port)
39-{
40- FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr
41- : 0;
42- if(fd) {
43- fputc(d->dat[port], fd);
44- fflush(fd);
45- }
46-}
47-
48-static void
49-file_deo(Device *d, Uint8 port)
50-{
51- file_i_deo(d - devfile0, d, port);
52-}
53-
54-static Uint8
55-file_dei(Device *d, Uint8 port)
56-{
57- return file_i_dei(d - devfile0, d, port);
58-}
59-
60-static Uint8
61-nil_dei(Device *d, Uint8 port)
62-{
63- return d->dat[port];
64-}
65-
66-static void
67-nil_deo(Device *d, Uint8 port)
68-{
69- (void)d;
70- (void)port;
71-}
72-
73-static int
74-console_input(Uxn *u, char c)
75-{
76- Device *d = &u->dev[1];
77- d->dat[0x2] = c;
78- return uxn_eval(u, GETVECTOR(d));
79-}
80-
81-static void
82-run(Uxn *u)
83-{
84- Device *d = &u->dev[0];
85- while(!d->dat[0xf]) {
86- int c = fgetc(stdin);
87- if(c != EOF)
88- console_input(u, (Uint8)c);
89- }
90-}
91-
92-static int
93-load(Uxn *u, char *filepath)
94-{
95- FILE *f;
96- int r;
97- if(!(f = fopen(filepath, "rb"))) return 0;
98- r = fread(u->ram + PAGE_PROGRAM, 1, 0x10000 - PAGE_PROGRAM, f);
99- fclose(f);
100- if(r < 1) return 0;
101- fprintf(stderr, "Loaded %s\n", filepath);
102- return 1;
103-}
104-
105-static int
106-start(Uxn *u)
107-{
108- if(!uxn_boot(u, (Uint8 *)calloc(0x10000, sizeof(Uint8))))
109- return error("Boot", "Failed");
110- /* system */ uxn_port(u, 0x0, system_dei, system_deo);
111- /* console */ uxn_port(u, 0x1, nil_dei, console_deo);
112- /* empty */ uxn_port(u, 0x2, nil_dei, nil_deo);
113- /* empty */ uxn_port(u, 0x3, nil_dei, nil_deo);
114- /* empty */ uxn_port(u, 0x4, nil_dei, nil_deo);
115- /* empty */ uxn_port(u, 0x5, nil_dei, nil_deo);
116- /* empty */ uxn_port(u, 0x6, nil_dei, nil_deo);
117- /* empty */ uxn_port(u, 0x7, nil_dei, nil_deo);
118- /* empty */ uxn_port(u, 0x8, nil_dei, nil_deo);
119- /* empty */ uxn_port(u, 0x9, nil_dei, nil_deo);
120- /* file0 */ devfile0 = uxn_port(u, 0xa, file_dei, file_deo);
121- /* file1 */ uxn_port(u, 0xb, file_dei, file_deo);
122- /* datetime */ uxn_port(u, 0xc, datetime_dei, nil_deo);
123- /* empty */ uxn_port(u, 0xd, nil_dei, nil_deo);
124- /* empty */ uxn_port(u, 0xe, nil_dei, nil_deo);
125- /* empty */ uxn_port(u, 0xf, nil_dei, nil_deo);
126- return 1;
127-}
128-
129-int
130-main(int argc, char **argv)
131-{
132- Uxn u;
133- int i;
134- if(argc < 2)
135- return error("Usage", "uxncli game.rom args");
136- if(!start(&u))
137- return error("Start", "Failed");
138- if(!load(&u, argv[1]))
139- return error("Load", "Failed");
140- if(!uxn_eval(&u, PAGE_PROGRAM))
141- return error("Init", "Failed");
142- for(i = 2; i < argc; i++) {
143- char *p = argv[i];
144- while(*p) console_input(&u, *p++);
145- console_input(&u, '\n');
146- }
147- run(&u);
148- return 0;
149-}