diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 39 |
1 files changed, 32 insertions, 7 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); |