Ported left to new asm syntax

This commit is contained in:
neauoire 2021-03-13 20:51:43 -08:00
parent b4e766fd52
commit a1b2a00adb
4 changed files with 44 additions and 52 deletions

View File

@ -16,23 +16,20 @@ typedef signed char Sint8;
typedef unsigned short Uint16;
typedef signed short Sint16;
typedef struct
{
typedef struct {
char name[64];
unsigned int size;
} Map;
typedef struct {
char name[64];
Uint8 len, offset, refs;
Uint8 refs, maps;
Uint16 addr;
/* map */
Map map[16];
Uint8 maps;
} Label;
typedef struct {
Uint8 data[256 * 256], tlen, llen;
Uint8 data[256 * 256], llen;
Uint16 ptr;
Label labels[256];
} Program;
@ -122,7 +119,7 @@ findlabellen(char *s)
char *param;
Label *l = findlabel(s);
if(scin(s, '.') < 1)
return l->len;
return l->map[0].size;
param = s + scin(s, '.') + 1;
for(i = 0; i < l->maps; ++i)
if(scmp(l->map[i].name, param, 64))
@ -183,7 +180,7 @@ makelabel(char *name, Uint16 addr)
l->addr = addr;
l->refs = 0;
scpy(name, l->name, 64);
printf("New label: %s, at 0x%04x[%d]\n", l->name, l->addr, l->len);
printf("New label: %s, at 0x%04x\n", l->name, l->addr);
return 1;
}
@ -302,12 +299,18 @@ pass2(FILE *f)
if(off < -126 || off > 126){ printf("Address %s is too far(%d).\n", w, off); return 0; }
pushbyte((Sint8)(l->addr - p.ptr - 3), 1); l->refs++;
}
else if(w[0] == '=' && (l = findlabel(w + 1))) {
if(!findlabellen(w + 1) || findlabellen(w + 1) > 2)
return error("Invalid load helper", w);
pushshort(findlabeladdr(w + 1), 1); pushbyte(findopcode(findlabellen(w + 1) == 2 ? "STR2" : "STR"), 0); l->refs++;}
else if(w[0] == '~' && (l = findlabel(w + 1))) {
if(!findlabellen(w + 1) || findlabellen(w + 1) > 2)
return error("Invalid load helper", w);
pushshort(findlabeladdr(w + 1), 1); pushbyte(findopcode(findlabellen(w + 1) == 2 ? "LDR2" : "LDR"), 0); l->refs++;}
else if(w[0] == '|') p.ptr = shex(w + 1);
else if((op = findopcode(w)) || scmp(w, "BRK", 4)) pushbyte(op, 0);
else if(w[0] == '.' && (l = findlabel(w + 1))) { pushshort(findlabeladdr(w + 1), 0); l->refs++; }
else if(w[0] == ',' && (l = findlabel(w + 1))) { pushshort(findlabeladdr(w + 1), 1); l->refs++; }
else if(w[0] == '=' && (l = findlabel(w + 1))) { pushshort(findlabeladdr(w + 1), 1); pushbyte(findopcode(findlabellen(w + 1) == 2 ? "STR2" : "STR"), 0); l->refs++;}
else if(w[0] == '~' && (l = findlabel(w + 1))) { pushshort(findlabeladdr(w + 1), 1); pushbyte(findopcode(findlabellen(w + 1) == 2 ? "LDR2" : "LDR"), 0); l->refs++;}
else if(w[0] == '#' && sihx(w + 1) && slen(w + 1) == 2) pushbyte(shex(w + 1), 1);
else if(w[0] == '#' && sihx(w + 1) && slen(w + 1) == 4) pushshort(shex(w + 1), 1);
else if(w[0] == '+' && sihx(w + 1) && slen(w + 1) == 2) pushbyte((Sint8)shex(w + 1), 1);
@ -324,7 +327,7 @@ void
cleanup(char *filename)
{
int i;
printf("Assembled %s.\n\n", filename);
printf("Assembled %s, %d labels.\n\n", filename, p.llen);
for(i = 0; i < p.llen; ++i)
if(!p.labels[i].refs)
printf("--- Unused label: %s\n", p.labels[i].name);

View File

@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr
# cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator
# run
./bin/assembler projects/examples/win.editor.usm bin/boot.rom
./bin/assembler projects/software/left.usm bin/boot.rom
./bin/emulator bin/boot.rom

View File

@ -26,11 +26,6 @@ BRK
@FRAME
~pointer.x ~Mouse.x NEQU2
~pointer.y ~Mouse.y NEQU2
#0000 EQU2 BRK? ( Return if unchanged )
,no-ctrl ~Controller.buttons #00 EQU JMP2? POP2
,no-ctrl-up ~Controller.buttons #10 EQU JMP2? POP2
@ -161,6 +156,11 @@ RTS
@draw-cursor
~pointer.x ~Mouse.x NEQU2
~pointer.y ~Mouse.y NEQU2
#0000 EQU2 BRK? ( Return if unchanged )
( clear last cursor )
,clear_icn =Sprite.addr
~pointer.x =Sprite.x

View File

@ -15,30 +15,20 @@
- Real scrolling distance
)
&Console { pad 8 char 1 byte 1 short 2 }
&Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
&Sprite { pad 8 x 2 y 2 addr 2 color 1 }
&Controller { buttons 1 }
&Keyboard { key 1 }
&Mouse { x 2 y 2 state 1 chord 1 xt 1 yt 1 }
&File { pad 8 name 2 length 2 load 2 save 2 }
&Document { eof 2 body 8000 }
&Clip { len 2 body 256 }
&Range2d { from 2 to 2 }
&Point2d { x 2 y 2 }
&Label2d { x 2 y 2 color 1 addr 2 }
&Textarea2d { x1 2 y1 2 x2 2 y2 2 addr 2 cursor 1 }
&Touch2d { x1 2 y1 2 x2 2 y2 2 state 1 }
;lock 1
;i 2 ;j 2 ;k 1 ;l 1 ;addr 2
;selection Range2d ;position Point2d ;scroll Point2d
;pt Point2d ;mouse Point2d ;touch Touch2d
;textarea Textarea2d
;label Label2d ( remove )
;lock { byte 1 }
;k { byte 1 }
;l { byte 1 }
;i { short 2 }
;j { short 2 }
;addr { short 2 }
;selection { from 2 to 2 }
;position { x 2 y 2 }
;scroll { x 2 y 2 }
;pt { x 2 y 2 }
;mouse { x 2 y 2 }
;touch { x1 2 y1 2 x2 2 y2 2 state 1 }
;textarea { x1 2 y1 2 x2 2 y2 2 addr 2 cursor 1 }
;label { x 2 y 2 color 1 addr 2 } ( remove )
|0100 @RESET
@ -125,7 +115,6 @@ BRK
,$no-backspace ~KEYS #08 NEQ JMP2? POP2
( erase )
,$erase-multiple ~selection.to ~selection.from SUB2 #0001 NEQ2 JMP2? POP2
$erase-single
~selection.to ~selection.from SUB2 ,shift-left JSR2
,$erase-end JMP2
$erase-multiple
@ -703,18 +692,18 @@ RTS
@filepath1 [ projects/examples/gui.hover.usm 00 ]
@filepath [ projects/software/left.usm 00 ]
|3000 ;document Document
|c000 ;clip Clip
|3000 ;document { eof 2 body 8000 }
|c000 ;clip { len 2 body 256 }
|d000 @ERROR BRK
|FF00 ;CNSL Console
|FF10 ;SCRN Screen
|FF20 ;SPRT Sprite
|FF30 ;CTRL Controller
|FF40 ;KEYS Keyboard
|FF50 ;MOUS Mouse
|FF60 ;FILE File
|FF00 ;CNSL { pad 8 char 1 byte 1 short 2 }
|FF10 ;SCRN { width 2 height 2 pad 4 x 2 y 2 color 1 }
|FF20 ;SPRT { pad 8 x 2 y 2 addr 2 color 1 }
|FF30 ;CTRL { buttons 1 }
|FF40 ;KEYS { key 1 }
|FF50 ;MOUS { x 2 y 2 state 1 chord 1 xt 1 yt 1 }
|FF60 ;FILE { pad 8 name 2 length 2 load 2 save 2 }
|FFF0 .RESET .FRAME .ERROR ( vectors )
|FFF8 [ 30ff e0f3 b0f3 ] ( palette )