as:first -org sets output origin

should be #0100 for ROMs
This commit is contained in:
Kitty-Cricket Piapiac 2023-03-28 10:04:14 -07:00
parent d368a3be0f
commit 58ccad23c0
2 changed files with 9 additions and 8 deletions

12
as.c
View File

@ -1,9 +1,9 @@
#include"u.h"
#define MEMSZ 0x40000
_ B meb[MEMSZ];
_ W mel;
V mb(W i,B b){Q(i>=MEMSZ||i<0x100,die("memory overflow, or tried to write to IVT {ip=%x}",i))meb[i]=b;}
_ B orq=0,meb[MEMSZ];
_ W org=0,mel;
V mb(W i,B b){Q(i>=MEMSZ||i<org,die("memory overflow or underflow {ip=%x}",i))meb[i-org]=b;}
V mh(W i,H h){mb(i,h>>8),mb(i+1,h);}
V mw(W i,W w){mh(i,w>>16),mh(i+2,w);}
V mcpy(W dst,B*src,W l){for(W i=0;i<l;++i)mb(dst+i,src[i]);}
@ -40,7 +40,7 @@ _ V rini(Ref*r,S n){*r=(Ref){n,mel,label};}
#define BE(y,...)Q(seql(Sl(y),x),__VA_ARGS__)OR
_ V frun(F);
_ V builtin(S*t){FILE*f;S y,x=*t;++x.p,--x.l;
BE("org",tasrt(next(t),'#'),mel=tton(*t))
BE("org",tasrt(next(t),'#'),mel=tton(*t);N(orq,orq=1,org=mel))
BE("res",tasrt(next(t),'#'),mel+=tton(*t))
BE("emb",tasrt(y=next(t),'"'),y.p[y.l-1]=0;WIF(f,(C*)y.p+1,"rb",mel+=fread(meb+mel,1,(W)0-1,f)))
BE("inc",tasrt(y=next(t),'"'),y.p[y.l-1]=0;WIF(f,(C*)y.p+1,"rb",frun(f)))
@ -72,6 +72,6 @@ I main(I ac,C**av){FILE *f;
label=&(Label){0,0,{0}};
hini(&label->c,64,SZ(Label)),hini(&macros,64,SZ(Macro)),vini(&refs,64,SZ(Ref));
WIF(f,av[1],"rb",frun(f);)
WIF(f,av[2],"wb",fwrite(meb+0x100,1,mel-0x100,f))
printf("done: %d bytes wrote\n",mel-0x100);
WIF(f,av[2],"wb",fwrite(meb,1,mel-org,f))
printf("done: %d bytes wrote\n",mel-org);
R 0;}

View File

@ -40,8 +40,9 @@ SYNTAX
BUILTINS
Colour of arguments denoted with first character.
-org #; Sets the origin for labels. Output binaries are inserted at #100 in
the CPU's memory, so you generally start a program off with -org #100
-org #; Sets the origin for labels. The first -org is the entry point of the
output file. Output ROMs are inserted at #100 in the CPU's memory,
so you should generally start a program off with -org #0100.
-res #; Reserves some bytes in the output binary. Basically same as -org but
relative to current address.