From 23650a74a173f000b0d4014db1273df99869e4fa Mon Sep 17 00:00:00 2001 From: rgl Date: Wed, 5 Feb 2020 10:35:54 +0100 Subject: let's get started. --- assets/bob.pic | Bin 0 -> 3132 bytes assets/bob.spr | 33 ++++++++ assets/sod.pal | 257 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ assets/wl3d.pal | 257 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ dat.h | 8 ++ fns.h | 1 + main.c | 202 ++++++++++++++++++++++++++++++++++++++++++++ mkfile | 10 +++ 8 files changed, 768 insertions(+) create mode 100644 assets/bob.pic create mode 100644 assets/bob.spr create mode 100644 assets/sod.pal create mode 100644 assets/wl3d.pal create mode 100644 dat.h create mode 100644 fns.h create mode 100644 main.c create mode 100644 mkfile diff --git a/assets/bob.pic b/assets/bob.pic new file mode 100644 index 0000000..5ab4759 Binary files /dev/null and b/assets/bob.pic differ diff --git a/assets/bob.spr b/assets/bob.spr new file mode 100644 index 0000000..c9fd8d8 --- /dev/null +++ b/assets/bob.spr @@ -0,0 +1,33 @@ +sprite 32 32 sod.pal +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 202 202 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 202 202 0 0 0 0 0 0 0 202 48 48 202 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 202 48 48 202 0 0 0 0 0 0 202 48 48 202 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 202 202 48 202 0 0 0 0 0 202 202 48 202 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 202 202 0 0 0 0 0 202 202 202 202 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 202 202 202 202 202 0 202 202 202 15 15 202 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 202 202 15 15 15 202 202 202 15 15 15 15 15 202 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 202 202 15 15 15 202 202 202 15 15 0 15 15 202 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 202 202 15 0 15 202 202 202 15 15 0 15 15 202 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 202 202 15 0 15 202 202 202 15 15 0 15 15 202 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 202 202 15 15 15 202 202 15 15 0 15 15 202 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 202 202 202 15 15 202 202 202 202 15 15 15 15 202 202 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 202 202 47 202 202 15 202 202 202 202 15 15 15 202 202 202 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 202 202 47 48 202 202 202 202 202 202 202 202 202 202 47 202 202 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 202 202 47 47 48 15 15 15 49 15 15 48 47 47 47 202 202 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 202 202 47 47 47 64 64 64 47 64 64 47 47 47 47 202 202 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 202 202 47 47 47 42 64 64 64 40 40 40 42 47 47 47 202 202 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 202 202 47 47 42 42 41 35 35 35 35 41 42 42 47 47 202 202 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 202 202 47 47 42 42 35 32 32 32 32 41 42 42 47 47 202 202 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 202 202 47 47 42 42 41 41 32 32 32 32 42 42 47 47 202 202 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 202 202 202 47 47 42 40 40 64 32 32 32 42 47 47 202 202 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 202 202 202 47 64 40 64 64 40 64 40 64 47 202 202 202 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 202 202 202 64 64 64 64 64 64 64 64 202 202 202 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 202 202 202 202 49 202 202 202 202 202 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 210 210 210 202 202 210 210 210 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 210 210 210 0 0 0 0 210 210 210 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 210 210 210 0 0 0 0 0 0 210 210 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 diff --git a/assets/sod.pal b/assets/sod.pal new file mode 100644 index 0000000..c589b72 --- /dev/null +++ b/assets/sod.pal @@ -0,0 +1,257 @@ +pal 256 +0x000000 +0x0000aa +0x00aa00 +0x00aaaa +0xaa0000 +0xaa00aa +0xaa5500 +0xaaaaaa +0x555555 +0x5555ff +0x55ff55 +0x55ffff +0xff5555 +0xff55ff +0xffff55 +0xffffff +0xeeeeee +0xdedede +0xd2d2d2 +0xc2c2c2 +0xb6b6b6 +0xaaaaaa +0x999999 +0x8d8d8d +0x7d7d7d +0x717171 +0x656565 +0x555555 +0x484848 +0x383838 +0x2c2c2c +0x202020 +0xff0000 +0xee0000 +0xe20000 +0xd60000 +0xca0000 +0xbe0000 +0xb20000 +0xa50000 +0x990000 +0x890000 +0x7d0000 +0x710000 +0x650000 +0x590000 +0x4c0000 +0x400000 +0xffdada +0xffbaba +0xff9d9d +0xff7d7d +0xff5d5d +0xff4040 +0xff2020 +0xff0000 +0xffaa5d +0xff9940 +0xff8920 +0xff7900 +0xe66d00 +0xce6100 +0xb65500 +0x9d4c00 +0xffffda +0xffffba +0xffff9d +0xffff7d +0xfffa5d +0xfff640 +0xfff620 +0xfff600 +0xe6da00 +0xcec600 +0xb6ae00 +0x9d9d00 +0x858500 +0x716d00 +0x595500 +0x404000 +0xd2ff5d +0xc6ff40 +0xb6ff20 +0xa1ff00 +0x91e600 +0x81ce00 +0x75b600 +0x619d00 +0xdaffda +0xbeffba +0x9dff9d +0x81ff7d +0x61ff5d +0x40ff40 +0x20ff20 +0x00ff00 +0x00ff00 +0x00ee00 +0x00e200 +0x00d600 +0x04ca00 +0x04be00 +0x04b200 +0x04a500 +0x049900 +0x048900 +0x047d00 +0x047100 +0x046500 +0x045900 +0x044c00 +0x044000 +0xdaffff +0xbaffff +0x9dffff +0x7dfffa +0x5dffff +0x40ffff +0x20ffff +0x00ffff +0x00e6e6 +0x00cece +0x00b6b6 +0x009d9d +0x008585 +0x007171 +0x005959 +0x004040 +0x5dbeff +0x40b2ff +0x20aaff +0x009dff +0x008de6 +0x007dce +0x006db6 +0x005d9d +0xdadaff +0xbabeff +0x9d9dff +0x7d81ff +0x5d61ff +0x4040ff +0x2024ff +0x0004ff +0x0000ff +0x0000ee +0x0000e2 +0x0000d6 +0x0000ca +0x0000be +0x0000b2 +0x0000a5 +0x000099 +0x000089 +0x00007d +0x000071 +0x000065 +0x000059 +0x00004c +0x000040 +0x282828 +0xffe234 +0xffd624 +0xffce18 +0xffc208 +0xffb600 +0x003800 +0x002800 +0x9900e6 +0x8100ce +0x7500b6 +0x61009d +0x500085 +0x440071 +0x340059 +0x280040 +0xffdaff +0xffbaff +0xff9dff +0xff7dff +0xff5dff +0xff40ff +0xff20ff +0xff00ff +0xe200e6 +0xca00ce +0xb600b6 +0x9d009d +0x850085 +0x6d0071 +0x590059 +0x400040 +0xffeade +0xffe2d2 +0xffdac6 +0xffd6be +0xffceb2 +0xffc6a5 +0xffbe9d +0xffba91 +0xffb281 +0xffa571 +0xff9d61 +0xf2955d +0xea8d59 +0xde8955 +0xd28150 +0xca7d4c +0xbe7948 +0xb67144 +0xaa6940 +0xa1653c +0x9d6138 +0x915d34 +0x895930 +0x81502c +0x754c28 +0x6d4824 +0x5d4020 +0x553c1c +0x483818 +0x403018 +0x382c14 +0x28200c +0x610065 +0x006565 +0x006161 +0x00001c +0x00002c +0x302410 +0x480048 +0x500050 +0x000034 +0x1c1c1c +0x4c4c4c +0x5d5d5d +0x404040 +0x303030 +0x343434 +0xdaf6f6 +0xbaeaea +0x9ddede +0x75caca +0x48c2c2 +0x20b6b6 +0x20b2b2 +0x00a5a5 +0x009999 +0x008d8d +0x008585 +0x007d7d +0x007979 +0x007575 +0x007171 +0x006d6d +0x990089 diff --git a/assets/wl3d.pal b/assets/wl3d.pal new file mode 100644 index 0000000..1b79ccf --- /dev/null +++ b/assets/wl3d.pal @@ -0,0 +1,257 @@ +pal 256 +0x000000 +0x0000aa +0x00aa00 +0x00aaaa +0xaa0000 +0xaa00aa +0xaa5500 +0xaaaaaa +0x555555 +0x5555ff +0x55ff55 +0x55ffff +0xff5555 +0xff55ff +0xffff55 +0xffffff +0xeeeeee +0xdedede +0xd2d2d2 +0xc2c2c2 +0xb6b6b6 +0xaaaaaa +0x999999 +0x8d8d8d +0x7d7d7d +0x717171 +0x656565 +0x555555 +0x484848 +0x383838 +0x2c2c2c +0x202020 +0xff0000 +0xee0000 +0xe20000 +0xd60000 +0xca0000 +0xbe0000 +0xb20000 +0xa50000 +0x990000 +0x890000 +0x7d0000 +0x710000 +0x650000 +0x590000 +0x4c0000 +0x400000 +0xffdada +0xffbaba +0xff9d9d +0xff7d7d +0xff5d5d +0xff4040 +0xff2020 +0xff0000 +0xffaa5d +0xff9940 +0xff8920 +0xff7900 +0xe66d00 +0xce6100 +0xb65500 +0x9d4c00 +0xffffda +0xffffba +0xffff9d +0xffff7d +0xfffa5d +0xfff640 +0xfff620 +0xfff600 +0xe6da00 +0xcec600 +0xb6ae00 +0x9d9d00 +0x858500 +0x716d00 +0x595500 +0x404000 +0xd2ff5d +0xc6ff40 +0xb6ff20 +0xa1ff00 +0x91e600 +0x81ce00 +0x75b600 +0x619d00 +0xdaffda +0xbeffba +0x9dff9d +0x81ff7d +0x61ff5d +0x40ff40 +0x20ff20 +0x00ff00 +0x00ff00 +0x00ee00 +0x00e200 +0x00d600 +0x04ca00 +0x04be00 +0x04b200 +0x04a500 +0x049900 +0x048900 +0x047d00 +0x047100 +0x046500 +0x045900 +0x044c00 +0x044000 +0xdaffff +0xbaffff +0x9dffff +0x7dfffa +0x5dffff +0x40ffff +0x20ffff +0x00ffff +0x00e6e6 +0x00cece +0x00b6b6 +0x009d9d +0x008585 +0x007171 +0x005959 +0x004040 +0x5dbeff +0x40b2ff +0x20aaff +0x009dff +0x008de6 +0x007dce +0x006db6 +0x005d9d +0xdadaff +0xbabeff +0x9d9dff +0x7d81ff +0x5d61ff +0x4040ff +0x2024ff +0x0004ff +0x0000ff +0x0000ee +0x0000e2 +0x0000d6 +0x0000ca +0x0000be +0x0000b2 +0x0000a5 +0x000099 +0x000089 +0x00007d +0x000071 +0x000065 +0x000059 +0x00004c +0x000040 +0x282828 +0xffe234 +0xffd624 +0xffce18 +0xffc208 +0xffb600 +0xb620ff +0xaa00ff +0x9900e6 +0x8100ce +0x7500b6 +0x61009d +0x500085 +0x440071 +0x340059 +0x280040 +0xffdaff +0xffbaff +0xff9dff +0xff7dff +0xff5dff +0xff40ff +0xff20ff +0xff00ff +0xe200e6 +0xca00ce +0xb600b6 +0x9d009d +0x850085 +0x6d0071 +0x590059 +0x400040 +0xffeade +0xffe2d2 +0xffdac6 +0xffd6be +0xffceb2 +0xffc6a5 +0xffbe9d +0xffba91 +0xffb281 +0xffa571 +0xff9d61 +0xf2955d +0xea8d59 +0xde8955 +0xd28150 +0xca7d4c +0xbe7948 +0xb67144 +0xaa6940 +0xa1653c +0x9d6138 +0x915d34 +0x895930 +0x81502c +0x754c28 +0x6d4824 +0x5d4020 +0x553c1c +0x483818 +0x403018 +0x382c14 +0x28200c +0x610065 +0x006565 +0x006161 +0x00001c +0x00002c +0x302410 +0x480048 +0x500050 +0x000034 +0x1c1c1c +0x4c4c4c +0x5d5d5d +0x404040 +0x303030 +0x343434 +0xdaf6f6 +0xbaeaea +0x9ddede +0x75caca +0x48c2c2 +0x20b6b6 +0x20b2b2 +0x00a5a5 +0x009999 +0x008d8d +0x008585 +0x007d7d +0x007979 +0x007575 +0x007171 +0x006d6d +0x990089 diff --git a/dat.h b/dat.h new file mode 100644 index 0000000..0ccea6f --- /dev/null +++ b/dat.h @@ -0,0 +1,8 @@ +enum +{ + K↑, + K↓, + K←, + K→, + Ke +}; diff --git a/fns.h b/fns.h new file mode 100644 index 0000000..44e0892 --- /dev/null +++ b/fns.h @@ -0,0 +1 @@ +#define FPS2MS(fps) (1000/(fps)) diff --git a/main.c b/main.c new file mode 100644 index 0000000..244097c --- /dev/null +++ b/main.c @@ -0,0 +1,202 @@ +#include +#include +#include +#include +#include +#include +#include +#include "dat.h" +#include "fns.h" + +Mousectl *mctl; +ulong kdown; +double Δt; +Image *screenb; +Memimage *fb; +Memimage *bg, *fg; + +Rune keys[Ke] = { + [K↑] Kup, + [K↓] Kdown, + [K←] Kleft, + [K→] Kright +}; + +Memimage* +eallocmemimage(Rectangle r, ulong chan) +{ + Memimage *i; + + i = allocmemimage(r, chan); + if(i == nil) + sysfatal("allocmemimage: %r"); + memfillcolor(i, DTransparent); + return i; +} + +Memimage* +rgb(ulong c) +{ + Memimage *i; + + i = eallocmemimage(Rect(0,0,1,1), screen->chan); + i->flags |= Frepl; + i->clipr = Rect(-1e6, -1e6, 1e6, 1e6); + memfillcolor(i, c); + return i; +} + +void +kbdproc(void*) +{ + Rune r, *a; + char buf[128], *s; + int fd, n; + + threadsetname("kbdproc"); + if((fd = open("/dev/kbd", OREAD)) < 0) + sysfatal("kbdproc: %r"); + memset(buf, 0, sizeof buf); + for(;;){ + if(buf[0] != 0){ + n = strlen(buf)+1; + memmove(buf, buf+n, sizeof(buf)-n); + } + if(buf[0] == 0){ + if((n = read(fd, buf, sizeof(buf)-1)) <= 0) + break; + buf[n-1] = 0; + buf[n] = 0; + } + if(buf[0] == 'c'){ + if(utfrune(buf, Kdel)){ + close(fd); + threadexitsall(nil); + } + } + if(buf[0] != 'k' && buf[0] != 'K') + continue; + s = buf+1; + kdown = 0; + while(*s){ + s += chartorune(&r, s); + for(a = keys; a < keys+Ke; a++) + if(r == *a){ + kdown |= 1 << a-keys; + break; + } + } + } +} + +void +drawproc(void *arg) +{ + Channel *c; + + c = arg; + for(;;){ + send(c, nil); + sleep(FPS2MS(60)); + } +} + +void +resetfb(void) +{ + freeimage(screenb); + screenb = allocimage(display, Rect(0,0,Dx(screen->r),Dy(screen->r)), screen->chan, 0, DNofill); + freememimage(fb); + fb = eallocmemimage(Rect(0,0,Dx(screen->r),Dy(screen->r)), screen->chan); +} + +void +redraw(void) +{ + Rectangle r; + Point p; + static Point incp = {1,1}; + + memimagedraw(fb, fb->r, bg, ZP, nil, ZP, SoverD); + for(p.y = 0; p.y < Dy(fb->r); p.y++) + for(p.x = 0; p.x < Dx(fb->r); p.x++) + if(p.x%15 == 0 || p.y%15 == 0) + memimagedraw(fb, Rpt(p, addpt(p, incp)), fg, ZP, nil, ZP, SoverD); + /*for(p = ZP; ptinrect(p, fb->r); p.x++, p.y++) + memimagedraw(fb, Rpt(p, addpt(p, Pt(1,1))), fg, ZP, nil, ZP, SoverD);*/ + for(r = fb->r; r.min.y < fb->r.max.y; r.min.y++){ + r.max.y = r.min.y+1; + loadimage(screenb, r, byteaddr(fb, r.min), bytesperline(r, fb->depth)); + } + lockdisplay(display); + draw(screen, screen->r, screenb, nil, ZP); + flushimage(display, 1); + unlockdisplay(display); +} + + +void +mouse(void) +{ +} + +void +resize(void) +{ + if(getwindow(display, Refnone) < 0) + fprint(2, "can't reattach to window\n"); + resetfb(); + redraw(); +} + +void +usage(void) +{ + fprint(2, "usage: %s\n", argv0); + exits("usage"); +} + +void +threadmain(int argc, char *argv[]) +{ + vlong t0, t; + Channel *drawc; + + ARGBEGIN{ + default: usage(); + }ARGEND; + if(argc) + usage(); + if(initdraw(nil, nil, nil) < 0) + sysfatal("initdraw: %r"); + if(memimageinit() < 0) + sysfatal("memimageinit: %r"); + if((mctl = initmouse(nil, screen)) == nil) + sysfatal("initmouse: %r"); + resetfb(); + bg = rgb(DWhite); + fg = rgb(DBlack); + drawc = chancreate(1, 0); + display->locking = 1; + unlockdisplay(display); + proccreate(kbdproc, nil, mainstacksize); + proccreate(drawproc, drawc, mainstacksize); + t0 = nsec(); + for(;;){ + enum {MOUSE, RESIZE, DRAW}; + Alt a[] = { + {mctl->c, &mctl->Mouse, CHANRCV}, + {mctl->resizec, nil, CHANRCV}, + {drawc, nil, CHANRCV}, + {nil, nil, CHANEND} + }; + switch(alt(a)){ + case MOUSE: mouse(); break; + case RESIZE: resize(); break; + case DRAW: redraw(); break; + } + t = nsec(); + Δt = (t-t0)/1e9; + t0 = t; + } +} diff --git a/mkfile b/mkfile new file mode 100644 index 0000000..53debf1 --- /dev/null +++ b/mkfile @@ -0,0 +1,10 @@ +