... | ... |
@@ -1,7 +1,9 @@ |
1 | 1 |
( dev/console ) |
2 | 2 |
|
3 |
-|00 @System $e &debug |
|
4 |
-|10 @Console $8 &write |
|
3 |
+%HALT { #010f DEO } |
|
4 |
+%EMIT { #18 DEO } |
|
5 |
+%DEBUG { ;print-hex/byte JSR2 #0a EMIT } |
|
6 |
+%DEBUG2 { ;print-hex JSR2 #0a EMIT } |
|
5 | 7 |
|
6 | 8 |
( init ) |
7 | 9 |
|
... | ... |
@@ -9,11 +11,28 @@ |
9 | 11 |
|
10 | 12 |
;hello-word |
11 | 13 |
&while |
12 |
- ( send ) LDAk .Console/write DEO |
|
14 |
+ ( send ) LDAk EMIT |
|
15 |
+ #20 EMIT |
|
16 |
+ DUP2 ;print-hex JSR2 |
|
17 |
+ #20 EMIT |
|
18 |
+ LDAk ;print-hex/byte JSR2 |
|
19 |
+ #0a EMIT |
|
13 | 20 |
INC2 LDAk ,&while JCN |
14 | 21 |
POP2 |
15 |
- ( show debugger ) #01 .System/debug DEO |
|
22 |
+ ( stop ) HALT |
|
16 | 23 |
|
17 | 24 |
BRK |
18 | 25 |
|
26 |
+@print-hex ( value* -- ) |
|
27 |
+ |
|
28 |
+ SWP ,&byte JSR |
|
29 |
+ &byte ( byte -- ) |
|
30 |
+ STHk #04 SFT ,&parse JSR #18 DEO |
|
31 |
+ STHr #0f AND ,&parse JSR #18 DEO |
|
32 |
+ JMP2r |
|
33 |
+ &parse ( byte -- char ) DUP #09 GTH ,&above JCN #30 ADD JMP2r |
|
34 |
+ &above #57 ADD JMP2r |
|
35 |
+ |
|
36 |
+JMP2r |
|
37 |
+ |
|
19 | 38 |
@hello-word "Hello 20 "Uxn! |
20 | 39 |
\ No newline at end of file |
... | ... |
@@ -4018,12 +4018,13 @@ error: |
4018 | 4018 |
} |
4019 | 4019 |
|
4020 | 4020 |
int |
4021 |
-uxn_boot(Uxn *u) |
|
4021 |
+uxn_boot(Uxn *u, Uint8 *memory) |
|
4022 | 4022 |
{ |
4023 | 4023 |
unsigned int i; |
4024 | 4024 |
char *cptr = (char *)u; |
4025 | 4025 |
for(i = 0; i < sizeof(*u); ++i) |
4026 | 4026 |
cptr[i] = 0x00; |
4027 |
+ u->ram.dat = memory; |
|
4027 | 4028 |
return 1; |
4028 | 4029 |
} |
4029 | 4030 |
|
... | ... |
@@ -136,12 +136,13 @@ uxn_eval(Uxn *u, Uint16 vec) |
136 | 136 |
/* clang-format on */ |
137 | 137 |
|
138 | 138 |
int |
139 |
-uxn_boot(Uxn *u) |
|
139 |
+uxn_boot(Uxn *u, Uint8 *memory) |
|
140 | 140 |
{ |
141 | 141 |
Uint32 i; |
142 | 142 |
char *cptr = (char *)u; |
143 | 143 |
for(i = 0; i < sizeof(*u); ++i) |
144 | 144 |
cptr[i] = 0x00; |
145 |
+ u->ram.dat = memory; |
|
145 | 146 |
return 1; |
146 | 147 |
} |
147 | 148 |
|
... | ... |
@@ -24,7 +24,7 @@ typedef struct { |
24 | 24 |
|
25 | 25 |
typedef struct { |
26 | 26 |
Uint16 ptr; |
27 |
- Uint8 dat[65536]; |
|
27 |
+ Uint8 *dat; |
|
28 | 28 |
} Memory; |
29 | 29 |
|
30 | 30 |
typedef struct Device { |
... | ... |
@@ -44,7 +44,7 @@ typedef struct Uxn { |
44 | 44 |
void poke16(Uint8 *m, Uint16 a, Uint16 b); |
45 | 45 |
Uint16 peek16(Uint8 *m, Uint16 a); |
46 | 46 |
|
47 |
-int uxn_boot(Uxn *c); |
|
47 |
+int uxn_boot(Uxn *c, Uint8 *memory); |
|
48 | 48 |
int uxn_eval(Uxn *u, Uint16 vec); |
49 | 49 |
int uxn_halt(Uxn *u, Uint8 error, char *name, int id); |
50 | 50 |
Device *uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *, Uint8), void (*deofn)(Device *, Uint8)); |
... | ... |
@@ -1,4 +1,5 @@ |
1 | 1 |
#include <stdio.h> |
2 |
+#include <stdlib.h> |
|
2 | 3 |
#include <unistd.h> |
3 | 4 |
#include <time.h> |
4 | 5 |
#include "uxn.h" |
... | ... |
@@ -147,7 +148,7 @@ load(Uxn *u, char *filepath) |
147 | 148 |
FILE *f; |
148 | 149 |
int r; |
149 | 150 |
if(!(f = fopen(filepath, "rb"))) return 0; |
150 |
- r = fread(u->ram.dat + PAGE_PROGRAM, 1, sizeof(u->ram.dat) - PAGE_PROGRAM, f); |
|
151 |
+ r = fread(u->ram.dat + PAGE_PROGRAM, 1, 0xffff - PAGE_PROGRAM, f); |
|
151 | 152 |
fclose(f); |
152 | 153 |
if(r < 1) return 0; |
153 | 154 |
fprintf(stderr, "Loaded %s\n", filepath); |
... | ... |
@@ -160,7 +161,7 @@ main(int argc, char **argv) |
160 | 161 |
Uxn u; |
161 | 162 |
int i, loaded = 0; |
162 | 163 |
|
163 |
- if(!uxn_boot(&u)) |
|
164 |
+ if(!uxn_boot(&u, (Uint8 *)calloc(0xffff, sizeof(Uint8)))) |
|
164 | 165 |
return error("Boot", "Failed"); |
165 | 166 |
|
166 | 167 |
/* system */ devsystem = uxn_port(&u, 0x0, system_dei, system_deo); |
... | ... |
@@ -273,7 +273,7 @@ load(Uxn *u, char *rom) |
273 | 273 |
SDL_RWops *f; |
274 | 274 |
int r; |
275 | 275 |
if(!(f = SDL_RWFromFile(rom, "rb"))) return 0; |
276 |
- r = f->read(f, u->ram.dat + PAGE_PROGRAM, 1, sizeof(u->ram.dat) - PAGE_PROGRAM); |
|
276 |
+ r = f->read(f, u->ram.dat + PAGE_PROGRAM, 1, 0xffff - PAGE_PROGRAM); |
|
277 | 277 |
f->close(f); |
278 | 278 |
if(r < 1) return 0; |
279 | 279 |
fprintf(stderr, "Loaded %s\n", rom); |
... | ... |
@@ -284,7 +284,8 @@ load(Uxn *u, char *rom) |
284 | 284 |
static int |
285 | 285 |
start(Uxn *u, char *rom) |
286 | 286 |
{ |
287 |
- if(!uxn_boot(u)) |
|
287 |
+ Uint8 *memory = (Uint8 *)calloc(0xffff, sizeof(Uint8)); |
|
288 |
+ if(!uxn_boot(u, memory)) |
|
288 | 289 |
return error("Boot", "Failed to start uxn."); |
289 | 290 |
if(!load(u, rom)) |
290 | 291 |
return error("Boot", "Failed to load rom."); |