mirror of https://git.cro.wtf/kip.git
restructure
This commit is contained in:
parent
c72b653b1a
commit
d3df23a43d
|
@ -1,3 +1,4 @@
|
|||
*.o
|
||||
*.rom
|
||||
/build
|
||||
/b
|
||||
|
|
16
README
16
README
|
@ -5,11 +5,13 @@ depends c11 compiler
|
|||
ninja
|
||||
sdl2
|
||||
build meson compile -C b
|
||||
test meson test -C b
|
||||
usage ./b/kip [ROM FILE]
|
||||
./b/t/kmm32-as [ASM FILE] [ROM FILE]
|
||||
test ./b/t/tt
|
||||
dirs ./d/ -- documentation
|
||||
./t/ -- tools
|
||||
./x/ -- examples
|
||||
contributions are welcome and encouraged
|
||||
patches, questions, comments --> kitty+kip@piapiac.org
|
||||
./b/as [ASM FILE] [ROM FILE]
|
||||
layout ./kip* -- sdl2-based emulator
|
||||
./as -- assembler
|
||||
./d/ -- documentation
|
||||
./t/ -- tests
|
||||
./x/ -- examples
|
||||
contributions, questions, comments are welcome and encouraged
|
||||
send --> kitty+kip@piapiac.org
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#include"a.h"
|
||||
#undef malloc
|
||||
#undef realloc
|
||||
#undef free
|
||||
NR V die(IM C*f,...)VA(f,vfprintf(stderr,f,ap),fputc('\n',stderr),exit(1))
|
||||
V asrt(B b,IM C*m){N(b,die(m))}
|
||||
V*mk(W sz){V*p;N(p=calloc(1,sz),die("oom"))R p;}
|
||||
V*remk(V*p,W sz){N(p=realloc(p,sz),die("oom"))R p;}
|
||||
V del(V*p){free(p);}
|
24
t/t.h → a.h
24
t/t.h → a.h
|
@ -12,7 +12,6 @@
|
|||
#define VA(a,...){va_list ap;va_start(ap,a);__VA_ARGS__;va_end(ap);}
|
||||
#define WH(a,...)while((a)){__VA_ARGS__;}
|
||||
#define _ static
|
||||
|
||||
typedef void V;
|
||||
typedef int I;
|
||||
typedef char C;
|
||||
|
@ -28,26 +27,3 @@ V del(V*);
|
|||
#define malloc B use_mk_instead[-1]
|
||||
#define realloc B use_remk_instead[-1]
|
||||
#define free B use_del_instead[-1]
|
||||
|
||||
typedef struct{W z,c,l;B*p;}Vec;
|
||||
#define Vget(T,v,i)*(T*)vget((v),i)
|
||||
#define Vfor(T,v,x,i,...)for(W i=0;i<(v).l;++i){T x=Vget(T,v,i);__VA_ARGS__;}
|
||||
V vini(Vec*,W,W);
|
||||
V vgrw(Vec*,W);
|
||||
V vput(Vec*,V*);
|
||||
V*vget(Vec,W);
|
||||
|
||||
typedef struct{W l;B*p;}S;
|
||||
#define Sl(s)(S){SZ(s)-1,(B*)(s)}
|
||||
#define Sfor(s,x,i,...)W i;for(i=0;i<(s).l;++i){B x=s.p[i];__VA_ARGS__;}
|
||||
B seql(S,S);
|
||||
W fnv1a(S);
|
||||
|
||||
typedef struct{W z,c,l;S*k;B*v;}Ht;
|
||||
#define Hget(T,h,i)(T*)hget((h),(i))
|
||||
#define Hfor(h,n,v,i,...)for(W i=0;i<(h).c;++i){S n=(h).k[i];Q(k.l,B*v=(B*)((h).v+i*(h).z);__VA_ARGS__;)}
|
||||
V hini(Ht*,W,W);
|
||||
V hgrw(Ht*,W);
|
||||
V hput(Ht*,S,V*);
|
||||
W hind(Ht,S);
|
||||
V*hget(Ht,S);
|
|
@ -1,4 +1,4 @@
|
|||
#include"t.h"
|
||||
#include"u.h"
|
||||
|
||||
#define MEMSZ 0x40000
|
||||
_ B*inb,meb[MEMSZ];
|
24
kip-sdl2.c
24
kip-sdl2.c
|
@ -1,17 +1,13 @@
|
|||
#include<SDL.h>
|
||||
#include"kip.h"
|
||||
#define hig 480
|
||||
#define wid 640
|
||||
|
||||
SDL_Window*win;
|
||||
SDL_Surface*surf;
|
||||
SDL_Renderer*ren;
|
||||
SDL_Texture*tex;
|
||||
|
||||
#define err printf("sdl:%s\n",SDL_GetError()),exit(1)
|
||||
#define hig 480
|
||||
#define wid 640
|
||||
#define use(x)(void)(x)
|
||||
#define sz sizeof
|
||||
|
||||
_ W palette[0x10]={0x212425,0x212425,0x86215f,0xc33479,0x392874,0x0a5c9f,0xa0c5c6,0x0e8743,
|
||||
0xe67216,0xe1202d,0xeb5b2b,0xed7275,0xb1739a,0xbf98ac,0xf3e46d,0xfef6dd};
|
||||
_ B layer[4][wid*hig]={0},redraw;
|
||||
|
@ -20,13 +16,15 @@ _ W computed[wid*hig]={0};
|
|||
_ Ws min(Ws x,Ws y){R x<y?x:y;}
|
||||
_ Ws max(Ws x,Ws y){R x>y?x:y;}
|
||||
|
||||
_ NR V err(V){die("sdl:%s\n",SDL_GetError());}
|
||||
|
||||
V front_init(V){
|
||||
Q(0!=SDL_Init(SDL_INIT_VIDEO),err)
|
||||
Q(SDL_Init(SDL_INIT_VIDEO),err())
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
Q(!(win=SDL_CreateWindow("kip emulator",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,wid,hig,0)),err)
|
||||
Q(!(ren=SDL_CreateRenderer(win,-1,0)),err)
|
||||
Q(0!=SDL_RenderSetLogicalSize(ren,wid,hig),err)
|
||||
Q(!(tex=SDL_CreateTexture(ren,SDL_PIXELFORMAT_XRGB8888,SDL_TEXTUREACCESS_STREAMING,wid,hig)),err)
|
||||
N(win=SDL_CreateWindow("kip emulator",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,wid,hig,0),err())
|
||||
N(ren=SDL_CreateRenderer(win,-1,0),err())
|
||||
Q(SDL_RenderSetLogicalSize(ren,wid,hig),err())
|
||||
N(tex=SDL_CreateTexture(ren,SDL_PIXELFORMAT_XRGB8888,SDL_TEXTUREACCESS_STREAMING,wid,hig),err())
|
||||
redraw=1;}
|
||||
|
||||
_ H mx,my,px,py;
|
||||
|
@ -42,7 +40,7 @@ V front_events(V){_ SDL_Event ev;W t;
|
|||
V front_redraw(V){W i,j,k;
|
||||
Q(redraw,for(i=0;i<wid*hig;++i)computed[i]=palette[0];
|
||||
for(i=0;i<4;++i)for(j=0;j<wid*hig;++j)Q(k=layer[i][j],computed[j]=palette[k]);
|
||||
SDL_UpdateTexture(tex,0,computed,wid*(sz(W)/sz(B))),
|
||||
SDL_UpdateTexture(tex,0,computed,wid*(SZ(W)/SZ(B))),
|
||||
SDL_RenderClear(ren),
|
||||
SDL_RenderCopy(ren,tex,0,0),
|
||||
SDL_RenderPresent(ren))
|
||||
|
@ -52,7 +50,7 @@ V front_deinit(V){SDL_DestroyTexture(tex),SDL_DestroyRenderer(ren),SDL_DestroyWi
|
|||
_ V out_pixel(B l,W c,H x,H y){Q(c,redraw=1,layer[l&3][x+wid*y]=(l>>2)?0:(B)c&0xf;)}
|
||||
_ V out_1bpp(B l,W c,H x,H y){W i,j,k;for(i=0;i<8;++i)for(j=0,k=lob(blit+1*i);j<8;k<<=1,++j)out_pixel(l,(c&0xf)*(1&(k>>7)),x+j,y+i);}
|
||||
_ V out_2bpp(B l,W c,H x,H y){W i,j,k;for(i=0;i<8;++i)for(j=0,k=loh(blit+2*i);j<8;k<<=2,++j)out_pixel(l,0xf&(c>>4*(3&(k>>14))),x+j,y+i);}
|
||||
_ V out_4bpp(B l,W c,H x,H y){W i,j,k;for(i=0;i<8;++i)for(j=0,k=low(blit+4*i);j<8;k<<=4,++j)out_pixel(l,(k>>28),x+j,y+i);use(c);}
|
||||
_ V out_4bpp(B l,W c,H x,H y){W i,j,k;for(i=0;i<8;++i)for(j=0,k=low(blit+4*i);j<8;k<<=4,++j)out_pixel(l,(k>>28),x+j,y+i);(V)c;}
|
||||
_ V(*outs[])(B,W,H,H)={out_pixel,out_1bpp,out_2bpp,out_4bpp};
|
||||
|
||||
DEV(display_pos,(px=x>>16,py=x),(R px<<16|py))
|
||||
|
|
2
kip.c
2
kip.c
|
@ -17,7 +17,7 @@ int main(int ac,char*av[]){
|
|||
#undef X
|
||||
|
||||
f=fopen(av[1],"rb"),fseek(f,0,SEEK_END),l=ftell(f),fseek(f,0,SEEK_SET),
|
||||
b=malloc(l+1),fread(b,1,l,f),fclose(f),b[l]=0,lod(b,l),front_init();
|
||||
b=mk(l+1),fread(b,1,l,f),fclose(f),b[l]=0,lod(b,l),front_init();
|
||||
for(;;)front_events(),emu(STEP),front_redraw();
|
||||
front_deinit();
|
||||
}
|
||||
|
|
13
kip.h
13
kip.h
|
@ -1,13 +1,12 @@
|
|||
#include"kmm32.h"
|
||||
|
||||
extern V front_init(V);
|
||||
extern V front_events(V);
|
||||
extern V front_redraw(V);
|
||||
extern V front_deinit(V);
|
||||
|
||||
#include"a.h"
|
||||
#define D(...){__VA_ARGS__;}
|
||||
#define DEV(n,i,o)_ V n##io(W x)D i _ W n##ii(V)D o IoDevice io_##n={n##io,n##ii};
|
||||
#define X(x)extern IoDevice x;
|
||||
#include"kip-io.def"
|
||||
#undef B
|
||||
#undef X
|
||||
V fatal(IM C*,...);
|
||||
V front_init(V);
|
||||
V front_events(V);
|
||||
V front_redraw(V);
|
||||
V front_deinit(V);
|
||||
|
|
11
kmm32.c
11
kmm32.c
|
@ -1,15 +1,17 @@
|
|||
#include"kmm32.h"
|
||||
#define A a=pop()
|
||||
#define AB b=pop(),A
|
||||
#define DS ((W*)(mem+(MEMSZ-0x800)))
|
||||
#define RS ((W*)(mem+(MEMSZ-0x400)))
|
||||
|
||||
B dp,rp,mem[MEMSZ];
|
||||
W ip;
|
||||
|
||||
#define DS ((W*)(mem+(MEMSZ-0x800)))
|
||||
#define RS ((W*)(mem+(MEMSZ-0x400)))
|
||||
|
||||
_ 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 mem[i];}
|
||||
H loh(W i){R lob(i)<<8|lob(i+1);}
|
||||
W low(W i){R loh(i)<<16|loh(i+2);}
|
||||
|
@ -19,8 +21,6 @@ V stw(W i,W w){sth(i,w>>16),sth(i+2,w);}
|
|||
V vec(W i){Q(0x100<(i=low(i)),pur(ip),ip=i)}
|
||||
|
||||
_ W a,b;
|
||||
#define A a=pop()
|
||||
#define AB b=pop(),A
|
||||
_ V np(V){}
|
||||
_ V ex(V){ip+=0x40001;}
|
||||
_ V pb(V){put(lob(ip)),ip+=1;}
|
||||
|
@ -65,6 +65,5 @@ _ 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 29 30 31 32 33 34 35 36 37*/
|
||||
{np,ex,pb,ph,pw,fb,fh,fw,mb,mh,mw,io,ii,md,mr,dd,dr,du,sw,ov,ad,su,mu,di,an,or,xr,sl,sr,sa,eq,lt,gt,no,ju,jc,ca,cc};
|
||||
|
||||
#include<stdio.h>
|
||||
V emu(W c){while(c--&&ip<0x40000)ops[mem[ip++]]();}
|
||||
V lod(B*c,W l){for(ip=0;ip<l;++ip)mem[ip+0x100]=c[ip];dp=rp=0,ip=0x100;}
|
||||
|
|
26
meson.build
26
meson.build
|
@ -1,17 +1,21 @@
|
|||
project('kip', 'c',
|
||||
version : '0.0.1',
|
||||
default_options : ['c_std=c11',
|
||||
'default_library=static',
|
||||
'warning_level=3'])
|
||||
|
||||
sdl2_dep = dependency('sdl2')
|
||||
|
||||
project('kip','c',version:'0.0.1',
|
||||
default_options:['c_std=c11',
|
||||
'default_library=static',
|
||||
'warning_level=3',
|
||||
'werror=true'])
|
||||
sdl2=dependency('sdl2')
|
||||
liba=library('a','a.c')
|
||||
libu=library('u','u.c',link_with:liba)
|
||||
executable('kip',
|
||||
'kip.c',
|
||||
'kip-io-term.c',
|
||||
'kip-sdl2.c',
|
||||
'kmm32.c',
|
||||
install : true,
|
||||
dependencies: sdl2_dep)
|
||||
install:true,
|
||||
dependencies:sdl2,
|
||||
link_with:liba)
|
||||
executable('as',
|
||||
'as.c',
|
||||
link_with:libu)
|
||||
|
||||
subdir('t')
|
||||
test('libu',executable('u','t/u.c',link_with:libu))
|
||||
|
|
5
t/README
5
t/README
|
@ -1,4 +1 @@
|
|||
tools
|
||||
libt - common tools library
|
||||
tt - libt tests
|
||||
kmm32-as - small assembler
|
||||
more extensive tests TODO
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
libt=library('libt','t.c')
|
||||
executable('kmm32-as','kmm32-as.c',link_with:libt)
|
||||
executable('tt','tt.c',link_with:libt)
|
|
@ -1,4 +1,4 @@
|
|||
#include"t.h"
|
||||
#include"../u.h"
|
||||
|
||||
#define AEQ(a,b)Q((a)!=(b),die("assertion failed at line %d",__LINE__))
|
||||
|
15
t/t.c → u.c
15
t/t.c → u.c
|
@ -1,23 +1,10 @@
|
|||
#include"t.h"
|
||||
#undef malloc
|
||||
#undef realloc
|
||||
#undef free
|
||||
NR V die(IM C*f,...)VA(f,vfprintf(stderr,f,ap),fputc('\n',stderr),exit(1))
|
||||
V asrt(B b,IM C*m){N(b,die(m))}
|
||||
|
||||
V*mk(W sz){V*p;N(p=calloc(1,sz),die("oom"))R p;}
|
||||
V*remk(V*p,W sz){N(p=realloc(p,sz),die("oom"))R p;}
|
||||
V del(V*p){free(p);}
|
||||
|
||||
#include"u.h"
|
||||
V vini(Vec*v,W c,W z){*v=(Vec){z,c,0,mk(c*z)};}
|
||||
V vgrw(Vec*v,W c){v->p=remk(v->p,c*v->z),v->c=c;}
|
||||
V vput(Vec*v,V*a){Q(v->l>=v->c,vgrw(v,(v->c*3)/2))memcpy(vget(*v,v->l++),a,v->z);}
|
||||
V*vget(Vec v,W i){R v.p+(v.z*i);}
|
||||
|
||||
B seql(S a,S b){Q(a.l!=b.l,R 0)Sfor(a,c,i,Q(c!=b.p[i],R 0))R 1;}
|
||||
|
||||
W fnv1a(S s){W h=16777619;Sfor(s,c,i,h^=c,c*=2166136261)R h;}
|
||||
|
||||
V hini(Ht*h,W c,W z){*h=(Ht){z,c,0,mk(c*SZ(S)),mk(c*z)};}
|
||||
V hgrw(Ht*h,W c){Ht j=*h;h->k=mk(c*SZ(S)),h->v=mk(c*h->z),h->c=c;Hfor(j,k,v,i,hput(h,k,v));del(j.k),del(j.v);}
|
||||
V hput(Ht*h,S k,V*v){W c;W i=hind(*h,k);Q((c=h->c*3/2)<h->l++,hgrw(h,c))h->k[i]=k,memcpy(h->v+i*h->z,v,h->z);}
|
|
@ -0,0 +1,24 @@
|
|||
#include"a.h"
|
||||
|
||||
typedef struct{W z,c,l;B*p;}Vec;
|
||||
#define Vget(T,v,i)*(T*)vget((v),i)
|
||||
#define Vfor(T,v,x,i,...)for(W i=0;i<(v).l;++i){T x=Vget(T,v,i);__VA_ARGS__;}
|
||||
V vini(Vec*,W,W);
|
||||
V vgrw(Vec*,W);
|
||||
V vput(Vec*,V*);
|
||||
V*vget(Vec,W);
|
||||
|
||||
typedef struct{W l;B*p;}S;
|
||||
#define Sl(s)(S){SZ(s)-1,(B*)(s)}
|
||||
#define Sfor(s,x,i,...)W i;for(i=0;i<(s).l;++i){B x=s.p[i];__VA_ARGS__;}
|
||||
B seql(S,S);
|
||||
W fnv1a(S);
|
||||
|
||||
typedef struct{W z,c,l;S*k;B*v;}Ht;
|
||||
#define Hget(T,h,i)(T*)hget((h),(i))
|
||||
#define Hfor(h,n,v,i,...)for(W i=0;i<(h).c;++i){S n=(h).k[i];Q(k.l,B*v=(B*)((h).v+i*(h).z);__VA_ARGS__;)}
|
||||
V hini(Ht*,W,W);
|
||||
V hgrw(Ht*,W);
|
||||
V hput(Ht*,S,V*);
|
||||
W hind(Ht,S);
|
||||
V*hget(Ht,S);
|
Loading…
Reference in New Issue