... | ... |
@@ -16,23 +16,20 @@ typedef signed char Sint8; |
16 | 16 |
typedef unsigned short Uint16; |
17 | 17 |
typedef signed short Sint16; |
18 | 18 |
|
19 |
-typedef struct |
|
20 |
-{ |
|
19 |
+typedef struct { |
|
21 | 20 |
char name[64]; |
22 | 21 |
unsigned int size; |
23 | 22 |
} Map; |
24 | 23 |
|
25 | 24 |
typedef struct { |
26 | 25 |
char name[64]; |
27 |
- Uint8 len, offset, refs; |
|
26 |
+ Uint8 refs, maps; |
|
28 | 27 |
Uint16 addr; |
29 |
- /* map */ |
|
30 | 28 |
Map map[16]; |
31 |
- Uint8 maps; |
|
32 | 29 |
} Label; |
33 | 30 |
|
34 | 31 |
typedef struct { |
35 |
- Uint8 data[256 * 256], tlen, llen; |
|
32 |
+ Uint8 data[256 * 256], llen; |
|
36 | 33 |
Uint16 ptr; |
37 | 34 |
Label labels[256]; |
38 | 35 |
} Program; |
... | ... |
@@ -122,7 +119,7 @@ findlabellen(char *s) |
122 | 119 |
char *param; |
123 | 120 |
Label *l = findlabel(s); |
124 | 121 |
if(scin(s, '.') < 1) |
125 |
- return l->len; |
|
122 |
+ return l->map[0].size; |
|
126 | 123 |
param = s + scin(s, '.') + 1; |
127 | 124 |
for(i = 0; i < l->maps; ++i) |
128 | 125 |
if(scmp(l->map[i].name, param, 64)) |
... | ... |
@@ -183,7 +180,7 @@ makelabel(char *name, Uint16 addr) |
183 | 180 |
l->addr = addr; |
184 | 181 |
l->refs = 0; |
185 | 182 |
scpy(name, l->name, 64); |
186 |
- printf("New label: %s, at 0x%04x[%d]\n", l->name, l->addr, l->len); |
|
183 |
+ printf("New label: %s, at 0x%04x\n", l->name, l->addr); |
|
187 | 184 |
return 1; |
188 | 185 |
} |
189 | 186 |
|
... | ... |
@@ -302,12 +299,18 @@ pass2(FILE *f) |
302 | 299 |
if(off < -126 || off > 126){ printf("Address %s is too far(%d).\n", w, off); return 0; } |
303 | 300 |
pushbyte((Sint8)(l->addr - p.ptr - 3), 1); l->refs++; |
304 | 301 |
} |
302 |
+ else if(w[0] == '=' && (l = findlabel(w + 1))) { |
|
303 |
+ if(!findlabellen(w + 1) || findlabellen(w + 1) > 2) |
|
304 |
+ return error("Invalid load helper", w); |
|
305 |
+ pushshort(findlabeladdr(w + 1), 1); pushbyte(findopcode(findlabellen(w + 1) == 2 ? "STR2" : "STR"), 0); l->refs++;} |
|
306 |
+ else if(w[0] == '~' && (l = findlabel(w + 1))) { |
|
307 |
+ if(!findlabellen(w + 1) || findlabellen(w + 1) > 2) |
|
308 |
+ return error("Invalid load helper", w); |
|
309 |
+ pushshort(findlabeladdr(w + 1), 1); pushbyte(findopcode(findlabellen(w + 1) == 2 ? "LDR2" : "LDR"), 0); l->refs++;} |
|
305 | 310 |
else if(w[0] == '|') p.ptr = shex(w + 1); |
306 | 311 |
else if((op = findopcode(w)) || scmp(w, "BRK", 4)) pushbyte(op, 0); |
307 | 312 |
else if(w[0] == '.' && (l = findlabel(w + 1))) { pushshort(findlabeladdr(w + 1), 0); l->refs++; } |
308 | 313 |
else if(w[0] == ',' && (l = findlabel(w + 1))) { pushshort(findlabeladdr(w + 1), 1); l->refs++; } |
309 |
- else if(w[0] == '=' && (l = findlabel(w + 1))) { pushshort(findlabeladdr(w + 1), 1); pushbyte(findopcode(findlabellen(w + 1) == 2 ? "STR2" : "STR"), 0); l->refs++;} |
|
310 |
- else if(w[0] == '~' && (l = findlabel(w + 1))) { pushshort(findlabeladdr(w + 1), 1); pushbyte(findopcode(findlabellen(w + 1) == 2 ? "LDR2" : "LDR"), 0); l->refs++;} |
|
311 | 314 |
else if(w[0] == '#' && sihx(w + 1) && slen(w + 1) == 2) pushbyte(shex(w + 1), 1); |
312 | 315 |
else if(w[0] == '#' && sihx(w + 1) && slen(w + 1) == 4) pushshort(shex(w + 1), 1); |
313 | 316 |
else if(w[0] == '+' && sihx(w + 1) && slen(w + 1) == 2) pushbyte((Sint8)shex(w + 1), 1); |
... | ... |
@@ -324,7 +327,7 @@ void |
324 | 327 |
cleanup(char *filename) |
325 | 328 |
{ |
326 | 329 |
int i; |
327 |
- printf("Assembled %s.\n\n", filename); |
|
330 |
+ printf("Assembled %s, %d labels.\n\n", filename, p.llen); |
|
328 | 331 |
for(i = 0; i < p.llen; ++i) |
329 | 332 |
if(!p.labels[i].refs) |
330 | 333 |
printf("--- Unused label: %s\n", p.labels[i].name); |
... | ... |
@@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr |
20 | 20 |
# cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator |
21 | 21 |
|
22 | 22 |
# run |
23 |
-./bin/assembler projects/examples/win.editor.usm bin/boot.rom |
|
23 |
+./bin/assembler projects/software/left.usm bin/boot.rom |
|
24 | 24 |
./bin/emulator bin/boot.rom |
... | ... |
@@ -25,11 +25,6 @@ |
25 | 25 |
BRK |
26 | 26 |
|
27 | 27 |
@FRAME |
28 |
- |
|
29 |
- ~pointer.x ~Mouse.x NEQU2 |
|
30 |
- ~pointer.y ~Mouse.y NEQU2 |
|
31 |
- |
|
32 |
- #0000 EQU2 BRK? ( Return if unchanged ) |
|
33 | 28 |
|
34 | 29 |
,no-ctrl ~Controller.buttons #00 EQU JMP2? POP2 |
35 | 30 |
|
... | ... |
@@ -161,6 +156,11 @@ RTS |
161 | 156 |
|
162 | 157 |
@draw-cursor |
163 | 158 |
|
159 |
+ ~pointer.x ~Mouse.x NEQU2 |
|
160 |
+ ~pointer.y ~Mouse.y NEQU2 |
|
161 |
+ |
|
162 |
+ #0000 EQU2 BRK? ( Return if unchanged ) |
|
163 |
+ |
|
164 | 164 |
( clear last cursor ) |
165 | 165 |
,clear_icn =Sprite.addr |
166 | 166 |
~pointer.x =Sprite.x |
... | ... |
@@ -13,32 +13,22 @@ |
13 | 13 |
- Don't scroll past oef |
14 | 14 |
- Hor scroll |
15 | 15 |
- Real scrolling distance |
16 |
-) |
|
17 |
- |
|
18 |
-&Console { pad 8 char 1 byte 1 short 2 } |
|
19 |
-&Screen { width 2 height 2 pad 4 x 2 y 2 color 1 } |
|
20 |
-&Sprite { pad 8 x 2 y 2 addr 2 color 1 } |
|
21 |
-&Controller { buttons 1 } |
|
22 |
-&Keyboard { key 1 } |
|
23 |
-&Mouse { x 2 y 2 state 1 chord 1 xt 1 yt 1 } |
|
24 |
-&File { pad 8 name 2 length 2 load 2 save 2 } |
|
25 |
- |
|
26 |
-&Document { eof 2 body 8000 } |
|
27 |
-&Clip { len 2 body 256 } |
|
28 |
- |
|
29 |
-&Range2d { from 2 to 2 } |
|
30 |
-&Point2d { x 2 y 2 } |
|
31 |
-&Label2d { x 2 y 2 color 1 addr 2 } |
|
32 |
-&Textarea2d { x1 2 y1 2 x2 2 y2 2 addr 2 cursor 1 } |
|
33 |
-&Touch2d { x1 2 y1 2 x2 2 y2 2 state 1 } |
|
34 |
- |
|
35 |
-;lock 1 |
|
36 |
-;i 2 ;j 2 ;k 1 ;l 1 ;addr 2 |
|
37 |
- |
|
38 |
-;selection Range2d ;position Point2d ;scroll Point2d |
|
39 |
-;pt Point2d ;mouse Point2d ;touch Touch2d |
|
40 |
-;textarea Textarea2d |
|
41 |
-;label Label2d ( remove ) |
|
16 |
+) |
|
17 |
+ |
|
18 |
+;lock { byte 1 } |
|
19 |
+;k { byte 1 } |
|
20 |
+;l { byte 1 } |
|
21 |
+;i { short 2 } |
|
22 |
+;j { short 2 } |
|
23 |
+;addr { short 2 } |
|
24 |
+;selection { from 2 to 2 } |
|
25 |
+;position { x 2 y 2 } |
|
26 |
+;scroll { x 2 y 2 } |
|
27 |
+;pt { x 2 y 2 } |
|
28 |
+;mouse { x 2 y 2 } |
|
29 |
+;touch { x1 2 y1 2 x2 2 y2 2 state 1 } |
|
30 |
+;textarea { x1 2 y1 2 x2 2 y2 2 addr 2 cursor 1 } |
|
31 |
+;label { x 2 y 2 color 1 addr 2 } ( remove ) |
|
42 | 32 |
|
43 | 33 |
|0100 @RESET |
44 | 34 |
|
... | ... |
@@ -125,7 +115,6 @@ BRK |
125 | 115 |
,$no-backspace ~KEYS #08 NEQ JMP2? POP2 |
126 | 116 |
( erase ) |
127 | 117 |
,$erase-multiple ~selection.to ~selection.from SUB2 #0001 NEQ2 JMP2? POP2 |
128 |
- $erase-single |
|
129 | 118 |
~selection.to ~selection.from SUB2 ,shift-left JSR2 |
130 | 119 |
,$erase-end JMP2 |
131 | 120 |
$erase-multiple |
... | ... |
@@ -703,18 +692,18 @@ RTS |
703 | 692 |
@filepath1 [ projects/examples/gui.hover.usm 00 ] |
704 | 693 |
@filepath [ projects/software/left.usm 00 ] |
705 | 694 |
|
706 |
-|3000 ;document Document |
|
707 |
-|c000 ;clip Clip |
|
695 |
+|3000 ;document { eof 2 body 8000 } |
|
696 |
+|c000 ;clip { len 2 body 256 } |
|
708 | 697 |
|
709 | 698 |
|d000 @ERROR BRK |
710 | 699 |
|
711 |
-|FF00 ;CNSL Console |
|
712 |
-|FF10 ;SCRN Screen |
|
713 |
-|FF20 ;SPRT Sprite |
|
714 |
-|FF30 ;CTRL Controller |
|
715 |
-|FF40 ;KEYS Keyboard |
|
716 |
-|FF50 ;MOUS Mouse |
|
717 |
-|FF60 ;FILE File |
|
700 |
+|FF00 ;CNSL { pad 8 char 1 byte 1 short 2 } |
|
701 |
+|FF10 ;SCRN { width 2 height 2 pad 4 x 2 y 2 color 1 } |
|
702 |
+|FF20 ;SPRT { pad 8 x 2 y 2 addr 2 color 1 } |
|
703 |
+|FF30 ;CTRL { buttons 1 } |
|
704 |
+|FF40 ;KEYS { key 1 } |
|
705 |
+|FF50 ;MOUS { x 2 y 2 state 1 chord 1 xt 1 yt 1 } |
|
706 |
+|FF60 ;FILE { pad 8 name 2 length 2 load 2 save 2 } |
|
718 | 707 |
|
719 | 708 |
|FFF0 .RESET .FRAME .ERROR ( vectors ) |
720 | 709 |
|FFF8 [ 30ff e0f3 b0f3 ] ( palette ) |