diff options
author | Bad Diode <bd@badd10de.dev> | 2022-03-04 18:20:16 +0100 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2022-03-04 18:20:16 +0100 |
commit | 87ce7bbb4b5812e672b4912cc0c981a8037c2cd6 (patch) | |
tree | 79deaebd1dce5b7ec3145acc206b68b66d2d1453 /src | |
parent | 43eaa37472551bf1f7d2d245d92a939bc428f016 (diff) | |
download | uxnfb-87ce7bbb4b5812e672b4912cc0c981a8037c2cd6.tar.gz uxnfb-87ce7bbb4b5812e672b4912cc0c981a8037c2cd6.zip |
Allow roms to be loaded by a given path
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 39 | ||||
-rw-r--r-- | src/ppu.c | 6 | ||||
-rw-r--r-- | src/rom.c | 52 |
3 files changed, 35 insertions, 62 deletions
@@ -11,7 +11,6 @@ | |||
11 | #include "shorthand.h" | 11 | #include "shorthand.h" |
12 | #include "ppu.c" | 12 | #include "ppu.c" |
13 | #include "uxn-fast.c" | 13 | #include "uxn-fast.c" |
14 | #include "rom.c" | ||
15 | 14 | ||
16 | static Uxn u; | 15 | static Uxn u; |
17 | static Device *devscreen; | 16 | static Device *devscreen; |
@@ -140,6 +139,7 @@ screen_talk(Device *d, u8 b0, u8 w) { | |||
140 | default: break; | 139 | default: break; |
141 | } | 140 | } |
142 | } | 141 | } |
142 | reqdraw = 1; | ||
143 | } | 143 | } |
144 | 144 | ||
145 | static void | 145 | static void |
@@ -166,15 +166,35 @@ file_talk(Device *d, u8 b0, u8 w) { | |||
166 | (void)w; | 166 | (void)w; |
167 | } | 167 | } |
168 | 168 | ||
169 | |||
170 | void | ||
171 | load_rom(char *file_name) { | ||
172 | FILE *file = fopen(file_name, "r"); | ||
173 | if (!file) { | ||
174 | fprintf(stderr, "error: couldn't open file: %s\n", file_name); | ||
175 | exit(EXIT_FAILURE); | ||
176 | } | ||
177 | |||
178 | fseek(file, 0, SEEK_END); | ||
179 | size_t rom_size = ftell(file); | ||
180 | fseek(file, 0, SEEK_SET); | ||
181 | char *uxn_rom = malloc(rom_size); | ||
182 | fread(uxn_rom, 1, rom_size, file); | ||
183 | memcpy(u.ram.dat + PAGE_PROGRAM, uxn_rom, rom_size); | ||
184 | fclose(file); | ||
185 | free(uxn_rom); | ||
186 | } | ||
187 | |||
169 | void | 188 | void |
170 | init_uxn() { | 189 | init_uxn(char *file_name) { |
171 | // Clear UXN memory. | 190 | // Clear UXN memory. |
172 | memset(&u, 0, sizeof(Uxn)); | 191 | memset(&u, 0, sizeof(Uxn)); |
173 | 192 | ||
174 | ppu_init(); | ||
175 | |||
176 | // Copy rom to VM. | 193 | // Copy rom to VM. |
177 | memcpy(u.ram.dat + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom)); | 194 | load_rom(file_name); |
195 | |||
196 | // Initialize framebuffer. | ||
197 | ppu_init(); | ||
178 | 198 | ||
179 | // Prepare devices. | 199 | // Prepare devices. |
180 | uxn_port(&u, 0x0, "system", system_talk); | 200 | uxn_port(&u, 0x0, "system", system_talk); |
@@ -198,8 +218,13 @@ init_uxn() { | |||
198 | } | 218 | } |
199 | 219 | ||
200 | int | 220 | int |
201 | main(void) { | 221 | main(int argc, char *argv[]) { |
202 | init_uxn(); | 222 | if (argc <= 1) { |
223 | // TODO: If no rom is given, embed the uxn compiler rom. | ||
224 | fprintf(stderr, "error: no rom selected\n"); | ||
225 | exit(EXIT_FAILURE); | ||
226 | } | ||
227 | init_uxn(argv[1]); | ||
203 | 228 | ||
204 | // Main loop. | 229 | // Main loop. |
205 | uxn_eval(&u, 0x0100); | 230 | uxn_eval(&u, 0x0100); |
@@ -88,12 +88,12 @@ ppu_init(void) { | |||
88 | // Open frambuffer and get the size. | 88 | // Open frambuffer and get the size. |
89 | int fb = open("/dev/fb0", O_RDWR); | 89 | int fb = open("/dev/fb0", O_RDWR); |
90 | if (fb <= 0) { | 90 | if (fb <= 0) { |
91 | fprintf(stderr, "couldn't open the framebuffer\n"); | 91 | fprintf(stderr, "error: couldn't open the framebuffer\n"); |
92 | exit(EXIT_FAILURE); | 92 | exit(EXIT_FAILURE); |
93 | } | 93 | } |
94 | struct fb_var_screeninfo info; | 94 | struct fb_var_screeninfo info; |
95 | if (ioctl(fb, FBIOGET_VSCREENINFO, &info) != 0) { | 95 | if (ioctl(fb, FBIOGET_VSCREENINFO, &info) != 0) { |
96 | fprintf(stderr, "couldn't get the framebuffer size\n"); | 96 | fprintf(stderr, "error: couldn't get the framebuffer size\n"); |
97 | exit(EXIT_FAILURE); | 97 | exit(EXIT_FAILURE); |
98 | } | 98 | } |
99 | 99 | ||
@@ -103,7 +103,7 @@ ppu_init(void) { | |||
103 | size_t len = 4 * screen_width * screen_height; | 103 | size_t len = 4 * screen_width * screen_height; |
104 | framebuffer = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0); | 104 | framebuffer = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0); |
105 | if (framebuffer == MAP_FAILED) { | 105 | if (framebuffer == MAP_FAILED) { |
106 | fprintf(stderr, "couldn't mmap the framebuffer\n"); | 106 | fprintf(stderr, "error: couldn't mmap the framebuffer\n"); |
107 | exit(EXIT_FAILURE); | 107 | exit(EXIT_FAILURE); |
108 | } | 108 | } |
109 | 109 | ||
diff --git a/src/rom.c b/src/rom.c deleted file mode 100644 index 419cad8..0000000 --- a/src/rom.c +++ /dev/null | |||
@@ -1,52 +0,0 @@ | |||
1 | const u16 uxn_rom[] = { | ||
2 | 0x0120, 0x8043, 0x3720, 0xf020, 0x807f, 0x3708, 0xf020, 0x80e0, | ||
3 | 0x370a, 0xf020, 0x80c0, 0x370c, 0x2280, 0x8036, 0x3f01, 0x0020, | ||
4 | 0x3920, 0x0280, 0x8031, 0x3624, 0x0180, 0x803f, 0x3104, 0x0120, | ||
5 | 0x2ed4, 0x0220, 0x2e2f, 0x0220, 0x2e71, 0x0220, 0x2eae, 0x0320, | ||
6 | 0x2e3a, 0x8000, 0x3000, 0x2321, 0x0080, 0x8031, 0x3002, 0x0020, | ||
7 | 0x3848, 0x2880, 0x8037, 0x3004, 0x0020, 0x3950, 0x2a80, 0x8037, | ||
8 | 0x0f01, 0x0305, 0x0480, 0x801f, 0x0500, 0x3080, 0x203f, 0x9103, | ||
9 | 0x8038, 0x372c, 0x80cf, 0x172f, 0x0f80, 0x801c, 0x0500, 0x3080, | ||
10 | 0x203f, 0x9103, 0x8038, 0x372c, 0x2880, 0x2036, 0x0800, 0x8038, | ||
11 | 0x3728, 0x80cf, 0x172f, 0x8003, 0x1f04, 0x0080, 0x8005, 0x3f30, | ||
12 | 0x0320, 0x3891, 0x2c80, 0x8037, 0x3628, 0x0020, 0x3808, 0x2880, | ||
13 | 0xcf37, 0x2f80, 0x8017, 0x1c0f, 0x0080, 0x8005, 0x3f30, 0x0320, | ||
14 | 0x3891, 0x2c80, 0x8037, 0x3628, 0x0020, 0x3808, 0x2880, 0x4f37, | ||
15 | 0x2f80, 0x0017, 0x1080, 0x0080, 0x8003, 0x1f30, 0x0080, 0x2005, | ||
16 | 0x9103, 0x8038, 0x372c, 0x8003, 0x1f30, 0x0080, 0x8005, 0x3002, | ||
17 | 0x0020, 0x3940, 0x8038, 0x3728, 0x0480, 0x2030, 0x5000, 0x8039, | ||
18 | 0x372a, 0x0180, 0x2f80, 0x0317, 0x3080, 0x801f, 0x0500, 0x0480, | ||
19 | 0x2030, 0x4000, 0x3839, 0x2a80, 0x8037, 0x3002, 0x0020, 0x3950, | ||
20 | 0x2880, 0x8037, 0x8001, 0x172f, 0x8a01, 0xab80, 0x220d, 0x206c, | ||
21 | 0x8103, 0x2c80, 0x8037, 0x8000, 0x0300, 0x0f80, 0x801c, 0x1f40, | ||
22 | 0x0180, 0x801f, 0x0500, 0x0280, 0x2030, 0x4000, 0x3839, 0x2880, | ||
23 | 0x0337, 0xf080, 0x801c, 0x1f01, 0x0080, 0x8005, 0x3004, 0x0020, | ||
24 | 0x3940, 0x8038, 0x372a, 0x8003, 0x172f, 0x8901, 0xca80, 0x220d, | ||
25 | 0x806c, 0x8010, 0x8f00, 0x8003, 0x1f02, 0x0080, 0x8005, 0x3f40, | ||
26 | 0x0480, 0x2030, 0x4000, 0x3839, 0x032f, 0x0380, 0x801c, 0x0500, | ||
27 | 0x4080, 0x203f, 0x4000, 0x8038, 0x3002, 0x0020, 0x3808, 0x6f38, | ||
28 | 0x804f, 0x2000, 0xe702, 0x012e, 0x808a, 0x0dc9, 0x6c22, 0x1080, | ||
29 | 0x0080, 0x038f, 0x0280, 0x801f, 0x0500, 0x4080, 0x803f, 0x3004, | ||
30 | 0x2f38, 0x8003, 0x1c03, 0x0080, 0x8005, 0x3f40, 0x0020, 0x3840, | ||
31 | 0x0280, 0x2030, 0x0800, 0x3838, 0x4f6f, 0x8080, 0x0220, 0x2ee7, | ||
32 | 0x8a01, 0xcd80, 0x220d, 0x186c, 0x200f, 0x8103, 0x2c80, 0x8037, | ||
33 | 0x372a, 0x2880, 0x8037, 0xcf00, 0x8018, 0x172f, 0x2880, 0x2036, | ||
34 | 0x0800, 0x8038, 0x3728, 0x1080, 0x18cf, 0x2f80, 0x8017, 0x3628, | ||
35 | 0x0020, 0x3908, 0x2880, 0x8037, 0x362a, 0x0020, 0x3808, 0x2a80, | ||
36 | 0x8037, 0xcf20, 0x8018, 0x172f, 0x2880, 0x2036, 0x0800, 0x8038, | ||
37 | 0x3728, 0x3080, 0x184f, 0x2f80, 0x6c17, 0x0480, 0x2030, 0x4000, | ||
38 | 0x8039, 0x372a, 0x0280, 0x2030, 0x4800, 0x8038, 0x3728, 0x0080, | ||
39 | 0x2e80, 0x8017, 0x3002, 0x0020, 0x3849, 0x2880, 0x8037, 0x8001, | ||
40 | 0x172e, 0x0280, 0x2030, 0x4a00, 0x8038, 0x3728, 0x0280, 0x2e80, | ||
41 | 0x8017, 0x3002, 0x0020, 0x384b, 0x2880, 0x8037, 0x8003, 0x172e, | ||
42 | 0x0f6c, 0x6738, 0xdf5f, 0xbfbf, 0x00bf, 0x1807, 0x2320, 0x4844, | ||
43 | 0x0048, 0x827c, 0x8282, 0x8282, 0x007c, 0x1030, 0x1010, 0x1010, | ||
44 | 0x0010, 0x827c, 0x7c02, 0x8080, 0x00fe, 0x827c, 0x1c02, 0x8202, | ||
45 | 0x007c, 0x140c, 0x4424, 0xfe84, 0x0004, 0x80fe, 0x7c80, 0x8202, | ||
46 | 0x007c, 0x827c, 0xfc80, 0x8282, 0x007c, 0x827c, 0x1e02, 0x0202, | ||
47 | 0x0002, 0x827c, 0x7c82, 0x8282, 0x007c, 0x827c, 0x7e82, 0x8202, | ||
48 | 0x007c, 0x827c, 0x7e02, 0x8282, 0x007e, 0x82fc, 0xfc82, 0x8282, | ||
49 | 0x00fc, 0x827c, 0x8080, 0x8280, 0x007c, 0x82fc, 0x8282, 0x8282, | ||
50 | 0x00fc, 0x827c, 0xf080, 0x8280, 0x007c, 0x827c, 0xf080, 0x8080, | ||
51 | 0x8080, | ||
52 | }; | ||