mirror of https://git.cro.wtf/kip.git
static,header,new ints
This commit is contained in:
parent
ab70608a77
commit
1e72d2f89d
101
kmm32.c
101
kmm32.c
|
@ -1,62 +1,59 @@
|
|||
#include<stdint.h>
|
||||
#define td(a,b)typedef a b
|
||||
#define r return
|
||||
#define $(a,...)if((a)){__VA_ARGS__;}
|
||||
|
||||
td(void,V);
|
||||
td(uint8_t,B); td(int8_t,Ib);
|
||||
td(uint16_t,S); td(int16_t,Is);
|
||||
td(uint32_t,W); td(int32_t,Iw);
|
||||
#include"kmm32.h"
|
||||
|
||||
W ds[0xff],rs[0xff],ip,a,b,c;
|
||||
B m[0x40000],dp,rp;
|
||||
IoDevice*ios;
|
||||
|
||||
B lob(W i){r m[i];}
|
||||
S los(W i){r m[i]<<8||m[i+1];}
|
||||
W low(W i){r los(i)<<16||los(i+2);}
|
||||
V stb(W i,B b){m[i]=b;}
|
||||
V sts(W i,S s){m[i]=s>>8,m[i+1]=s;}
|
||||
V stw(W i,W w){sts(i,w>>16),sts(i+2,w);}
|
||||
W pop(V){r ds[--dp];}
|
||||
W por(V){r rs[--rp];}
|
||||
V put(W i){ds[dp++]=i;}
|
||||
V pur(W i){rs[rp++]=i;}
|
||||
_ B lob(W i){r m[i];}
|
||||
_ S los(W i){r m[i]<<8||m[i+1];}
|
||||
_ W low(W i){r los(i)<<16||los(i+2);}
|
||||
_ V stb(W i,B b){m[i]=b;}
|
||||
_ V sts(W i,S s){m[i]=s>>8,m[i+1]=s;}
|
||||
_ V stw(W i,W w){sts(i,w>>16),sts(i+2,w);}
|
||||
_ W pop(V){r ds[--dp];}
|
||||
_ W por(V){r rs[--rp];}
|
||||
_ V put(W i){ds[dp++]=i;}
|
||||
_ V pur(W i){rs[rp++]=i;}
|
||||
|
||||
#define A a=pop()
|
||||
#define AB b=pop(),A
|
||||
V np(V){}
|
||||
V ex(V){ip+=0x40001;}
|
||||
V bp(V){put(lob(ip)),ip+=1;}
|
||||
V sp(V){put(los(ip)),ip+=2;}
|
||||
V wp(V){put(low(ip)),ip+=4;}
|
||||
V dd(V){--dp;}
|
||||
V mr(V){pur(pop());}
|
||||
V md(V){put(por());}
|
||||
V du(V){put(ds[dp]);}
|
||||
V sw(V){AB,put(b),put(a);}
|
||||
V ov(V){put(ds[dp-1]);}
|
||||
V ad(V){AB,put(a+b);}
|
||||
V su(V){AB,put(a-b);}
|
||||
V mu(V){AB,put(a*b);}
|
||||
V di(V){AB,put(a/b),put(a%b);}
|
||||
V eq(V){AB,put(a==b);}
|
||||
V lt(V){AB,put(a<b);}
|
||||
V gt(V){AB,put(a>b);}
|
||||
V no(V){put(!pop());}
|
||||
V ju(V){ip=pop();}
|
||||
V jc(V){$(pop(),ju())}
|
||||
V cu(V){pur(ip),ip=pop();}
|
||||
V cc(V){$(pop(),cu())}
|
||||
V bl(V){put(lob(pop()));}
|
||||
V sl(V){put(los(pop()));}
|
||||
V wl(V){put(low(pop()));}
|
||||
V bs(V){AB,stb(a,b);}
|
||||
V ss(V){AB,sts(a,b);}
|
||||
V ws(V){AB,stw(a,b);}
|
||||
_ V np(V){}
|
||||
_ V ex(V){ip+=0x40001;}
|
||||
_ V pb(V){put(lob(ip)),ip+=1;}
|
||||
_ V ph(V){put(los(ip)),ip+=2;}
|
||||
_ V pw(V){put(low(ip)),ip+=4;}
|
||||
_ V fb(V){put(lob(pop()));}
|
||||
_ V fh(V){put(los(pop()));}
|
||||
_ V fw(V){put(low(pop()));}
|
||||
_ V mb(V){AB,stb(a,b);}
|
||||
_ V mh(V){AB,sts(a,b);}
|
||||
_ V mw(V){AB,stw(a,b);}
|
||||
_ V io(V){AB,ios[b].io(a);}
|
||||
_ V ii(V){put(ios[pop()].oi());}
|
||||
_ V od(V){pur(pop());}
|
||||
_ V or(V){put(por());}
|
||||
_ V dd(V){--dp;}
|
||||
_ V dr(V){--rp;}
|
||||
_ V du(V){put(ds[dp]);}
|
||||
_ V sw(V){AB,put(b),put(a);}
|
||||
_ V ov(V){put(ds[dp-1]);}
|
||||
_ V ad(V){AB,put(a+b);}
|
||||
_ V su(V){AB,put(a-b);}
|
||||
_ V mu(V){AB,put(a*b);}
|
||||
_ V di(V){AB,put(a/b),put(a%b);}
|
||||
_ V eq(V){AB,put(a==b);}
|
||||
_ V lt(V){AB,put(a<b);}
|
||||
_ V gt(V){AB,put(a>b);}
|
||||
_ V no(V){put(!pop());}
|
||||
_ V ju(V){ip=pop();}
|
||||
_ V jc(V){AB;$(a,ip=b)}
|
||||
_ V cu(V){pur(ip),ip=pop();}
|
||||
_ V cc(V){AB;$(a,ip=b)}
|
||||
|
||||
V(*ops[])(V)=
|
||||
/*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28*/
|
||||
{np,ex,bp,sp,wp,dd,mr,md,du,sw,ov,ad,su,mu,di,eq,lt,gt,no,ju,jc,cu,cc,bl,sl,wl,bs,ss,ws};
|
||||
_ V(*ops[])(V)=
|
||||
/*0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f*/
|
||||
/*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31*/
|
||||
{np,ex,pb,ph,pw,fb,fh,fw,mb,mh,mw,io,ii,od,or,dd,dr,du,sw,ov,ad,su,mu,di,eq,lt,gt,no,ju,jc,cu,cc};
|
||||
|
||||
V emu(V){for(;;){$(ip>0x40000,r)ops[m[ip++]]();}}
|
||||
V lod(B*c,W l){for(ip=0;ip<=l;++ip)m[ip]=c[ip];ip=0;}
|
||||
|
@ -68,7 +65,7 @@ main(V)
|
|||
B meo[]={
|
||||
2,1,
|
||||
2,7,
|
||||
11,
|
||||
20,
|
||||
1
|
||||
};
|
||||
lod(meo,sizeof(meo));
|
||||
|
|
Loading…
Reference in New Issue