]> git.lizzy.rs Git - plan9front.git/commitdiff
demote libemu to common code
authorqwx <devnull@localhost>
Sun, 13 May 2018 05:01:47 +0000 (07:01 +0200)
committerqwx <devnull@localhost>
Sun, 13 May 2018 05:01:47 +0000 (07:01 +0200)
- too small, nothing else that won't be under /games will use it
- "libemu" as a name doesn't make sense here

45 files changed:
sys/man/2/emu [deleted file]
sys/src/games/2600/2600.c
sys/src/games/2600/cpu.c
sys/src/games/2600/mem.c
sys/src/games/2600/mkfile
sys/src/games/2600/tia.c
sys/src/games/c64/c64.c
sys/src/games/c64/cpu.c
sys/src/games/c64/mem.c
sys/src/games/c64/mkfile
sys/src/games/c64/vic.c
sys/src/games/eui.c [new file with mode: 0644]
sys/src/games/eui.h [new file with mode: 0644]
sys/src/games/gb/apu.c
sys/src/games/gb/cpu.c
sys/src/games/gb/gb.c
sys/src/games/gb/mem.c
sys/src/games/gb/mkfile
sys/src/games/gb/ppu.c
sys/src/games/gba/apu.c
sys/src/games/gba/cpu.c
sys/src/games/gba/gba.c
sys/src/games/gba/mem.c
sys/src/games/gba/mkfile
sys/src/games/gba/ppu.c
sys/src/games/md/cpu.c
sys/src/games/md/md.c
sys/src/games/md/mem.c
sys/src/games/md/mkfile
sys/src/games/md/vdp.c
sys/src/games/md/ym.c
sys/src/games/nes/apu.c
sys/src/games/nes/mem.c
sys/src/games/nes/mkfile
sys/src/games/nes/nes.c
sys/src/games/nes/ppu.c
sys/src/games/snes/cpu.c
sys/src/games/snes/dsp.c
sys/src/games/snes/mem.c
sys/src/games/snes/mkfile
sys/src/games/snes/ppu.c
sys/src/games/snes/snes.c
sys/src/games/snes/spc.c
sys/src/libemu/emu.c [deleted file]
sys/src/libemu/mkfile [deleted file]

diff --git a/sys/man/2/emu b/sys/man/2/emu
deleted file mode 100644 (file)
index 6802641..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-.TH EMU 2
-.SH NAME
-initemu, regkeyfn, flushmouse, flushscreen, flushaudio, screenwipe \- graphical emulator-like software scaffolding
-.SH SYNOPSIS
-.nf
-.ft L
-#include <u.h>
-#include <libc.h>
-#include <emu.h>
-.PP
-.ta +\w'\fLvoid fP'u
-.B
-void   flushmouse(int discard);
-.PP
-.B
-void   flushscreen(void);
-.PP
-.B
-void   flushaudio(int (*fn)(void));
-.PP
-.B
-void   regkeyfn(Rune r, void (*fn)(void));
-.PP
-.B
-void   regkey(char *joyk, Rune r, int k);
-.PP
-.B
-void   initemu(int dx, int dy, int bpp, ulong chan,
-.B
-          int dokey, void(*kproc)(void*));
-.SH DESCRIPTION
-.I Libemu
-implements common user interfaces for programs controlled
-with a joypad or a limited number of keys.
-.PP
-.B initemu
-initializes the display for the given internal screen size
-.B dx
-by
-.B dy
-and
-.B bpp
-bit depth.
-.B Chan
-is an
-.B Image
-pixel format descriptor to be used for an internal framebuffer (see
-.IR draw (2)).
-.PP
-If
-.B dokey
-is true,
-a keyboard process is started which sets a 64-bit wide bit vector for input keys.
-.PP
-Keys are set via
-.B regkey.
-Pressing the key corresponding to the
-.B r
-rune, or writing
-.B joyk
-to standard in will
-.L OR
-.B k
-with the key bit vector.
-.PP
-.B Regkeyfn
-registers an additional rune and a callback for the keyboard process.
-.PP
-Normally, a joypad process is also started, and parses standard input for key presses.
-If
-.B dokey
-is false, only the joypad process will be started.
-If
-.B kproc
-is a valid function pointer,
-it will be used for keyboard processing instead of the library-provided one,
-and no joypad process will be started.
-.PP
-.IP
-.EX
-.ta 6n
-uchar *pic;
-.EE
-.PP
-Once
-.B initemu
-is called, a framebuffer of the specifized size is allocated,
-and may be accessed via
-.BR pic .
-.L Libemu
-scales the framebuffer to fit the greatest multiple of the framebuffer's
-width in the window.
-The scaling is horizontal only and needs to be taken into account for drawing
-within the program.
-.PP
-Typically, mouse event handling is followed by drawing the final image from the
-internal framebuffer render and writing a constant amount of audio samples,
-thereby synchronizing the program's framerate to the audio writes.
-.IP
-.EX
-.ta 6n
-Mouse m;
-extern Mousectl *mc;
-
-flushmouse(0);
-while(nbrecv(mc->c, &m) > 0){
-       ...
-}
-flushscreen();
-flushaudio(audioout);
-.EE
-.PP
-Besides window resizing, mouse events are discarded by default.
-If
-.B discard
-is false
-.B flushmouse
-will let the user program handle mouse events prior to flushing the screen (see 
-.BR event (2)).
-.PP
-.B Flushscreen
-handles re-scaling and re-allocating the buffers used, as well as drawing to
-the screen, either directly, or by duplicating pre-scaled scanlines.
-.SH SOURCE
-.B /sys/src/libemu
-.SH "SEE ALSO"
-.IR draw (2),
-.IR event (2)
-.SH BUGS
-The semantics for
-.B initemu
-input selection are confusing.
-.PP
-A greater effort should be made to simplify automatic scaling for user programs.
-.SH HISTORY
-.I Libemu
-first appeared in 9front in May, 2018.
index 38d7c856fdab8913f8f4a29ee05a72abcc7efa24..728401d898792db5c0002a1a9305f0df41b9f75a 100644 (file)
@@ -3,7 +3,7 @@
 #include <thread.h>
 #include <draw.h>
 #include <keyboard.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 4dedfb9eb935c50e81d0c4b0d423017f1d0c101c..66842f292ce731ab633c978786a0fa50dc88f53b 100644 (file)
@@ -1,6 +1,6 @@
 #include <u.h>
 #include <libc.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index be24a17e10173ea6bfec3cf9a639e09ed6020f16..c521915b2c2eccedfafae52966e91104d9f8d5fc 100644 (file)
@@ -1,6 +1,6 @@
 #include <u.h>
 #include <libc.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index df08bd2d8c3286ae86beca5ee8b14b3c0308dd6f..1b1657e07495d088512dc194ce33de72f991dcf7 100644 (file)
@@ -8,7 +8,10 @@ OFILES=\
        cpu.$O\
        mem.$O\
        tia.$O\
+       eui.$O\
 
 HFILES=dat.h fns.h
 
 </sys/src/cmd/mkone
+eui.$O: ../eui.c
+       $CC $CFLAGS ../eui.c
index 3819fedaad09627a32636016964aab5704034e29..8c4902761cb7a324340e27d60509ea115ecbc173 100644 (file)
@@ -1,6 +1,6 @@
 #include <u.h>
 #include <libc.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 9b4e0504b30162460105b8371277d2ad7434d690..2ca976fe717c4ff8187e15bab3d95dcea3c39720 100644 (file)
@@ -4,7 +4,7 @@
 #include <draw.h>
 #include <mouse.h>
 #include <keyboard.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index cafd8e33328662b40532039dd1b9c05388dc1252..3a24e77831985c831d0d212c7360cbf2a2a76ad6 100644 (file)
@@ -1,6 +1,6 @@
 #include <u.h>
 #include <libc.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 8e00bec4bb9b89602b537936c38e566b06f888a8..6d0682b7a7ad184ad1feacfa48bd4282490191ba 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index af2ff29135158df1f0e3fe9a6109d7fa60397478..27d7f264178f42477fc5bcbcae0d129b84ef8e7d 100644 (file)
@@ -7,7 +7,10 @@ OFILES=\
        cpu.$O\
        mem.$O\
        vic.$O\
-       
+       eui.$O\
+
 HFILES=dat.h fns.h
 
 </sys/src/cmd/mkone
+eui.$O: ../eui.c
+       $CC $CFLAGS ../eui.c
index c181b24468b30f466bbba71cc9c9bfb90113083b..eba6178434fc2922db85e56ea554c7f51ae55d7c 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
diff --git a/sys/src/games/eui.c b/sys/src/games/eui.c
new file mode 100644 (file)
index 0000000..d462c76
--- /dev/null
@@ -0,0 +1,316 @@
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+#include <draw.h>
+#include <keyboard.h>
+#include <mouse.h>
+#include "eui.h"
+
+typedef struct Kfn Kfn;
+
+u64int keys, keys2;
+int trace, paused;
+int savereq, loadreq;
+QLock pauselock;
+int scale, warp10;
+uchar *pic;
+Rectangle picr;
+Mousectl *mc;
+Image *bg;
+
+static int profile, framestep;
+static int vwdx, vwdy, vwbpp;
+static ulong vwchan;
+static Image *fb;
+
+struct Kfn{
+       Rune r;
+       int k;
+       char joyk[16];
+       void(*fn)(void);
+       Kfn *n;
+};
+Kfn kfn, kkn;
+
+void *
+emalloc(ulong sz)
+{
+       void *v;
+
+       v = mallocz(sz, 1);
+       if(v == nil)
+               sysfatal("malloc: %r");
+       setmalloctag(v, getcallerpc(&sz));
+       return v;
+}
+
+static void
+joyproc(void *)
+{
+       char *s, *down[9];
+       static char buf[64];
+       int n, k, j;
+       Kfn *kp;
+
+       j = 1;
+
+       for(;;){
+               n = read(0, buf, sizeof(buf) - 1);
+               if(n <= 0)
+                       sysfatal("read: %r");
+               buf[n] = 0;
+               n = getfields(buf, down, nelem(down), 1, " ");
+               k = 0;
+               for(n--; n >= 0; n--){
+                       s = down[n];
+                       if(strcmp(s, "joy1") == 0)
+                               j = 1;
+                       else if(strcmp(s, "joy2") == 0)
+                               j = 2;
+                       for(kp=kkn.n; kp!=nil; kp=kp->n){
+                               if(strcmp(kp->joyk, s) == 0)
+                                       k |= kp->k;
+                       }
+               }
+               if(j == 2)
+                       keys2 = k;
+               else
+                       keys = k;
+       }
+}
+
+static void
+keyproc(void *)
+{
+       int fd, n, k;
+       static char buf[256];
+       char *s;
+       Rune r;
+       Kfn *kp;
+
+       fd = open("/dev/kbd", OREAD);
+       if(fd < 0)
+               sysfatal("open: %r");
+       for(;;){
+               if(buf[0] != 0){
+                       n = strlen(buf)+1;
+                       memmove(buf, buf+n, sizeof(buf)-n);
+               }
+               if(buf[0] == 0){
+                       n = read(fd, buf, sizeof(buf)-1);
+                       if(n <= 0)
+                               sysfatal("read /dev/kbd: %r");
+                       buf[n-1] = 0;
+                       buf[n] = 0;
+               }
+               if(buf[0] == 'c'){
+                       if(utfrune(buf, Kdel)){
+                               close(fd);
+                               threadexitsall(nil);
+                       }
+                       if(utfrune(buf, KF|5))
+                               savereq = 1;
+                       if(utfrune(buf, KF|6))
+                               loadreq = 1;
+                       if(utfrune(buf, KF|12))
+                               profile ^= 1;
+                       if(utfrune(buf, 't'))
+                               trace = !trace;
+                       for(kp=kfn.n; kp!=nil; kp=kp->n){
+                               if(utfrune(buf, kp->r))
+                                       kp->fn();
+                       }
+               }
+               if(buf[0] != 'k' && buf[0] != 'K')
+                       continue;
+               s = buf + 1;
+               k = 0;
+               while(*s != 0){
+                       s += chartorune(&r, s);
+                       switch(r){
+                       case Kdel: close(fd); threadexitsall(nil);
+                       case Kesc:
+                               if(paused)
+                                       qunlock(&pauselock);
+                               else
+                                       qlock(&pauselock);
+                               paused = !paused;
+                               break;
+                       case KF|1:      
+                               if(paused){
+                                       qunlock(&pauselock);
+                                       paused=0;
+                               }
+                               framestep = !framestep;
+                               break;
+                       case '`':
+                               warp10 = !warp10;
+                               break;
+                       }
+                       for(kp=kkn.n; kp!=nil; kp=kp->n){
+                               if(utfrune(buf, kp->r))
+                                       k |= kp->k;
+                       }
+               }
+               k &= ~(k << 1 & 0xa0 | k >> 1 & 0x50);
+               keys = k;
+       }
+}
+
+static void
+timing(void)
+{
+       static int fcount;
+       static vlong old;
+       static char buf[32];
+       vlong new;
+
+       if(++fcount == 60)
+               fcount = 0;
+       else
+               return;
+       new = nsec();
+       if(new != old)
+               sprint(buf, "%6.2f%%", 1e11 / (new - old));
+       else
+               buf[0] = 0;
+       draw(screen, rectaddpt(Rect(10, 10, vwdx-40, 30), screen->r.min), bg, nil, ZP);
+       string(screen, addpt(screen->r.min, Pt(10, 10)), display->black, ZP, display->defaultfont, buf);
+       old = nsec();
+}
+
+static void
+screeninit(void)
+{
+       Point p;
+
+       scale = Dx(screen->r) / vwdx;
+       if(scale <= 0)
+               scale = 1;
+       else if(scale > 16)
+               scale = 16;
+       p = divpt(addpt(screen->r.min, screen->r.max), 2);
+       picr = Rpt(subpt(p, Pt(scale * vwdx/2, scale * vwdy/2)),
+               addpt(p, Pt(scale * vwdx/2, scale * vwdy/2)));
+       freeimage(fb);
+       fb = allocimage(display, Rect(0, 0, scale * vwdx, scale > 1 ? 1 : scale * vwdy),
+               vwchan, scale > 1, 0);
+       free(pic);
+       pic = emalloc(vwdx * vwdy * vwbpp * scale);
+       draw(screen, screen->r, bg, nil, ZP);   
+}
+
+void
+flushmouse(int discard)
+{
+       Mouse m;
+
+       if(nbrecvul(mc->resizec) > 0){
+               if(getwindow(display, Refnone) < 0)
+                       sysfatal("resize failed: %r");
+               screeninit();
+       }
+       if(discard)
+               while(nbrecv(mc->c, &m) > 0)
+                       ;
+}
+
+void
+flushscreen(void)
+{
+       flushmouse(1);
+       if(scale == 1){
+               loadimage(fb, fb->r, pic, vwdx * vwdy * vwbpp);
+               draw(screen, picr, fb, nil, ZP);
+       } else {
+               Rectangle r;
+               uchar *s;
+               int w;
+
+               s = pic;
+               r = picr;
+               w = vwdx * vwbpp * scale;
+               while(r.min.y < picr.max.y){
+                       loadimage(fb, fb->r, s, w);
+                       s += w;
+                       r.max.y = r.min.y+scale;
+                       draw(screen, r, fb, nil, ZP);
+                       r.min.y = r.max.y;
+               }
+       }
+       flushimage(display, 1);
+       if(profile)
+               timing();
+}
+
+void
+flushaudio(int (*audioout)(void))
+{
+       static vlong old, delta;
+       vlong new, diff;
+
+       if(audioout == nil || audioout() < 0 && !warp10){
+               new = nsec();
+               diff = 0;
+               if(old != 0){
+                       diff = BILLION/60 - (new - old) - delta;
+                       if(diff >= MILLION)
+                               sleep(diff/MILLION);
+               }
+               old = nsec();
+               if(diff > 0){
+                       diff = (old - new) - (diff / MILLION) * MILLION;
+                       delta += (diff - delta) / 100;
+               }
+       }
+       if(framestep){
+               paused = 1;
+               qlock(&pauselock);
+               framestep = 0;
+       }
+}
+
+void
+regkeyfn(Rune r, void (*fn)(void))
+{
+       Kfn *kp;
+
+       for(kp=&kfn; kp->n!=nil; kp=kp->n)
+               ;
+       kp->n = emalloc(sizeof *kp);
+       kp->n->r = r;
+       kp->n->fn = fn;
+}
+
+void
+regkey(char *joyk, Rune r, int k)
+{
+       Kfn *kp;
+
+       for(kp=&kkn; kp->n!=nil; kp=kp->n)
+               ;
+       kp->n = emalloc(sizeof *kp);
+       strncpy(kp->n->joyk, joyk, sizeof(kp->n->joyk)-1);
+       kp->n->r = r;
+       kp->n->k = k;
+}
+
+void
+initemu(int dx, int dy, int bpp, ulong chan, int dokey, void(*kproc)(void*))
+{
+       vwdx = dx;
+       vwdy = dy;
+       vwchan = chan;
+       vwbpp = bpp;
+       if(initdraw(nil, nil, nil) < 0)
+               sysfatal("initdraw: %r");
+       mc = initmouse(nil, screen);
+       if(mc == nil)
+               sysfatal("initmouse: %r");
+       if(dokey)
+               proccreate(kproc != nil ? kproc : keyproc, nil, mainstacksize);
+       if(kproc == nil)
+               proccreate(joyproc, nil, mainstacksize*2);
+       bg = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0xCCCCCCFF);
+       screeninit();
+}
diff --git a/sys/src/games/eui.h b/sys/src/games/eui.h
new file mode 100644 (file)
index 0000000..949cf7c
--- /dev/null
@@ -0,0 +1,19 @@
+enum{
+       MILLION = 1000000,
+       BILLION = 1000000000,
+};
+
+extern u64int keys, keys2;
+extern int trace, paused;
+extern int savereq, loadreq;
+extern QLock pauselock;
+extern int scale, warp10;
+extern uchar *pic;
+
+void*  emalloc(ulong);
+void   flushmouse(int);
+void   flushscreen(void);
+void   flushaudio(int(*)(void));
+void   regkeyfn(Rune, void(*)(void));
+void   regkey(char*, Rune, int);
+void   initemu(int, int, int, ulong, int, void(*)(void*));
index dc78992ace3f3aad65cb5e4bb9fa21103186c62e..900f7e79306c5cf00999b6f0114c25c4a37ff534 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 81c45a0344882cae44c4e2330a2e3b2c7f210f90..bff692d0257d1a08de7228ea2b8b75468bf10b12 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 55ced730a7fd7fa5e6240d2765f190f04b38120a..b82729023b002070bd8775445669ac70ab283b64 100644 (file)
@@ -3,7 +3,7 @@
 #include <thread.h>
 #include <draw.h>
 #include <keyboard.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index a6c6c7599994d033a258cb3800116b2dfb0348d2..44a10820c7d79a1c5164e784a9d5b836fb143cb0 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index b9e767497f36c10de060600d6d32d8c68daeb8e4..80f1d0110fcb8329e064a98d6a0dad2b1274b369 100644 (file)
@@ -10,7 +10,10 @@ OFILES=\
        ev.$O\
        state.$O\
        apu.$O\
+       eui.$O\
 
 HFILES=dat.h fns.h
 
 </sys/src/cmd/mkone
+eui.$O: ../eui.c
+       $CC $CFLAGS ../eui.c
index 3895816219dd3d38902a2d5d18dccb2d5a5bea9a..433c12270bcbd3f7fd05488e2e083e6abe6e7e3e 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 4858aced95795f94f269cf29d0b902db1882117c..31c0f76822a2770362c098d967ceea62fde50cbe 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index a8354324f748be29a717e70403d9734b6be8b628..e4f42542e810a7e2bf0adae17ed88d84d55fa166 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 06e90b998b551c35c01f9964ddf51a9152adcf50..ec8c1bc7a183d9dfe830274eabe1095f177be177 100644 (file)
@@ -3,7 +3,7 @@
 #include <thread.h>
 #include <draw.h>
 #include <keyboard.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 032f35eae2f7f821ca516b7f6db929c42cd5bbec..c5a56abbb6d0ca368e93c47fdb265ab0d3be8087 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index b519b2376b0a74dd4c278fc348e656461670954e..0d12ae9439ee558b94efd1fb9383a0645bb1b8cf 100644 (file)
@@ -10,7 +10,10 @@ OFILES=\
        ev.$O\
        apu.$O\
        state.$O\
+       eui.$O\
 
 HFILES=dat.h fns.h
 
 </sys/src/cmd/mkone
+eui.$O: ../eui.c
+       $CC $CFLAGS ../eui.c
index 7de5a1e7b6887e6f29e4cc162480c653c4a1769d..b70aba8fbaaef9a77067dfcc7cd92309f12f18a7 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 1a0325f52996e0c1deaeca4bb9c605a66c1e96a1..6a223c3b1fe6ad4541b38640fdd275c2dd2cf548 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 557668dc7b01bc539227d83f1da99c557e53f9ae..2c0ed3fda978ac6543815d780fb253f4f2a981c2 100644 (file)
@@ -3,7 +3,7 @@
 #include <thread.h>
 #include <draw.h>
 #include <keyboard.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 083abaa29b042af991bae6367734d978c6391ffc..323632d120bf84a57a9f7a6a281014aa181a0415 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index b8363745aa70a9039e9677cc84b4eee11c154a89..7cad014fc969037fdc79035b81b636ffa696a486 100644 (file)
@@ -9,7 +9,10 @@ OFILES=\
        vdp.$O\
        z80.$O\
        ym.$O\
+       eui.$O\
 
 HFILES=dat.h fns.h
 
 </sys/src/cmd/mkone
+eui.$O: ../eui.c
+       $CC $CFLAGS ../eui.c
index 51d5f20a17c790012b6ecebf9d1cc1056ba16963..b3b7553f8859a1b2c64fb436ed0a489f2d4b2fce 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index ca39884337e0ae4e08dfce169534ef6cd852c672..6d603195844edcec929de5b9267d1789a844f92e 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 52e8e36b534ee768b4d31518d06fc48986b01b7f..1db370fdec4f440b7ad590c830ece890f631a817 100644 (file)
@@ -2,7 +2,7 @@
 #include <libc.h>
 #include <thread.h>
 #include <draw.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 52e3162ba3ce657cb9d3f613ea9390cc21070e17..cfa71a987473687c84974e656aba09bd49883473 100644 (file)
@@ -2,7 +2,7 @@
 #include <libc.h>
 #include <thread.h>
 #include <draw.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 98c8a14e0e327484c86f893af0513f3c6aca6c40..d658229b40d2a3b77150b371de2f63c387334126 100644 (file)
@@ -9,7 +9,10 @@ OFILES=\
        ppu.$O\
        state.$O\
        apu.$O\
+       eui.$O\
        
 HFILES=dat.h fns.h
 
 </sys/src/cmd/mkone
+eui.$O: ../eui.c
+       $CC $CFLAGS ../eui.c
index 2b4988aec974bcacb7a5eb6e5b3899cb00458a19..38984efff30a9cb71103065541f323e3bfba228b 100644 (file)
@@ -3,7 +3,7 @@
 #include <draw.h>
 #include <thread.h>
 #include <keyboard.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 498c20082fa7dcc1eedb2d134fd769aae30bc43f..0f7010198b6112111337105a8509c5be09b8e465 100644 (file)
@@ -3,7 +3,7 @@
 #include <thread.h>
 #include <draw.h>
 #include <mouse.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index dbec220a456bde0b2a4de577f8d62b6acc8eba46..7bdc95df9b9c1be920c1720c46a7c5ffe2f96138 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 991c45316272c4a08320d383e174c567b3f481ac..d3a03028fd6e862e44a9b4f652319e577c7b7a8b 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 885713a85274a4a9429fa571c9c6075e7aa87184..6afb3a9efa150922651f51363d63ef2c332abafe 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 6171c70ac58d0f825fceeb56b758f0278896198c..6cd40ba38ebeef36488f3f31ff40e46390797f03 100644 (file)
@@ -10,7 +10,10 @@ OFILES=\
        spc.$O\
        dsp.$O\
        state.$O\
+       eui.$O\
 
 HFILES=dat.h fns.h
 
 </sys/src/cmd/mkone
+eui.$O: ../eui.c
+       $CC $CFLAGS ../eui.c
index 5819e032c10b30de478675dc4ed3bdb6bd6c3563..cc1a82af808959e4c350a216f224a910eba3dbaa 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index 3e43b631d760ff00fb9d1597702b92be594baf6a..769ecb4734834c3e370a79a6df36ec351594913a 100644 (file)
@@ -4,7 +4,7 @@
 #include <draw.h>
 #include <keyboard.h>
 #include <mouse.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
index a5fc7ab8ae8fc4afef0cd60eb05b48a6d4880495..d00d58efa3cd7730dc9833c9e0cb1ef2ed088f21 100644 (file)
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <thread.h>
-#include <emu.h>
+#include "../eui.h"
 #include "dat.h"
 #include "fns.h"
 
diff --git a/sys/src/libemu/emu.c b/sys/src/libemu/emu.c
deleted file mode 100644 (file)
index 908727b..0000000
+++ /dev/null
@@ -1,316 +0,0 @@
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <draw.h>
-#include <keyboard.h>
-#include <mouse.h>
-#include <emu.h>
-
-typedef struct Kfn Kfn;
-
-u64int keys, keys2;
-int trace, paused;
-int savereq, loadreq;
-QLock pauselock;
-int scale, warp10;
-uchar *pic;
-Rectangle picr;
-Mousectl *mc;
-Image *bg;
-
-static int profile, framestep;
-static int vwdx, vwdy, vwbpp;
-static ulong vwchan;
-static Image *fb;
-
-struct Kfn{
-       Rune r;
-       int k;
-       char joyk[16];
-       void(*fn)(void);
-       Kfn *n;
-};
-Kfn kfn, kkn;
-
-void *
-emalloc(ulong sz)
-{
-       void *v;
-
-       v = mallocz(sz, 1);
-       if(v == nil)
-               sysfatal("malloc: %r");
-       setmalloctag(v, getcallerpc(&sz));
-       return v;
-}
-
-static void
-joyproc(void *)
-{
-       char *s, *down[9];
-       static char buf[64];
-       int n, k, j;
-       Kfn *kp;
-
-       j = 1;
-
-       for(;;){
-               n = read(0, buf, sizeof(buf) - 1);
-               if(n <= 0)
-                       sysfatal("read: %r");
-               buf[n] = 0;
-               n = getfields(buf, down, nelem(down), 1, " ");
-               k = 0;
-               for(n--; n >= 0; n--){
-                       s = down[n];
-                       if(strcmp(s, "joy1") == 0)
-                               j = 1;
-                       else if(strcmp(s, "joy2") == 0)
-                               j = 2;
-                       for(kp=kkn.n; kp!=nil; kp=kp->n){
-                               if(strcmp(kp->joyk, s) == 0)
-                                       k |= kp->k;
-                       }
-               }
-               if(j == 2)
-                       keys2 = k;
-               else
-                       keys = k;
-       }
-}
-
-static void
-keyproc(void *)
-{
-       int fd, n, k;
-       static char buf[256];
-       char *s;
-       Rune r;
-       Kfn *kp;
-
-       fd = open("/dev/kbd", OREAD);
-       if(fd < 0)
-               sysfatal("open: %r");
-       for(;;){
-               if(buf[0] != 0){
-                       n = strlen(buf)+1;
-                       memmove(buf, buf+n, sizeof(buf)-n);
-               }
-               if(buf[0] == 0){
-                       n = read(fd, buf, sizeof(buf)-1);
-                       if(n <= 0)
-                               sysfatal("read /dev/kbd: %r");
-                       buf[n-1] = 0;
-                       buf[n] = 0;
-               }
-               if(buf[0] == 'c'){
-                       if(utfrune(buf, Kdel)){
-                               close(fd);
-                               threadexitsall(nil);
-                       }
-                       if(utfrune(buf, KF|5))
-                               savereq = 1;
-                       if(utfrune(buf, KF|6))
-                               loadreq = 1;
-                       if(utfrune(buf, KF|12))
-                               profile ^= 1;
-                       if(utfrune(buf, 't'))
-                               trace = !trace;
-                       for(kp=kfn.n; kp!=nil; kp=kp->n){
-                               if(utfrune(buf, kp->r))
-                                       kp->fn();
-                       }
-               }
-               if(buf[0] != 'k' && buf[0] != 'K')
-                       continue;
-               s = buf + 1;
-               k = 0;
-               while(*s != 0){
-                       s += chartorune(&r, s);
-                       switch(r){
-                       case Kdel: close(fd); threadexitsall(nil);
-                       case Kesc:
-                               if(paused)
-                                       qunlock(&pauselock);
-                               else
-                                       qlock(&pauselock);
-                               paused = !paused;
-                               break;
-                       case KF|1:      
-                               if(paused){
-                                       qunlock(&pauselock);
-                                       paused=0;
-                               }
-                               framestep = !framestep;
-                               break;
-                       case '`':
-                               warp10 = !warp10;
-                               break;
-                       }
-                       for(kp=kkn.n; kp!=nil; kp=kp->n){
-                               if(utfrune(buf, kp->r))
-                                       k |= kp->k;
-                       }
-               }
-               k &= ~(k << 1 & 0xa0 | k >> 1 & 0x50);
-               keys = k;
-       }
-}
-
-static void
-timing(void)
-{
-       static int fcount;
-       static vlong old;
-       static char buf[32];
-       vlong new;
-
-       if(++fcount == 60)
-               fcount = 0;
-       else
-               return;
-       new = nsec();
-       if(new != old)
-               sprint(buf, "%6.2f%%", 1e11 / (new - old));
-       else
-               buf[0] = 0;
-       draw(screen, rectaddpt(Rect(10, 10, vwdx-40, 30), screen->r.min), bg, nil, ZP);
-       string(screen, addpt(screen->r.min, Pt(10, 10)), display->black, ZP, display->defaultfont, buf);
-       old = nsec();
-}
-
-static void
-screeninit(void)
-{
-       Point p;
-
-       scale = Dx(screen->r) / vwdx;
-       if(scale <= 0)
-               scale = 1;
-       else if(scale > 16)
-               scale = 16;
-       p = divpt(addpt(screen->r.min, screen->r.max), 2);
-       picr = Rpt(subpt(p, Pt(scale * vwdx/2, scale * vwdy/2)),
-               addpt(p, Pt(scale * vwdx/2, scale * vwdy/2)));
-       freeimage(fb);
-       fb = allocimage(display, Rect(0, 0, scale * vwdx, scale > 1 ? 1 : scale * vwdy),
-               vwchan, scale > 1, 0);
-       free(pic);
-       pic = emalloc(vwdx * vwdy * vwbpp * scale);
-       draw(screen, screen->r, bg, nil, ZP);   
-}
-
-void
-flushmouse(int discard)
-{
-       Mouse m;
-
-       if(nbrecvul(mc->resizec) > 0){
-               if(getwindow(display, Refnone) < 0)
-                       sysfatal("resize failed: %r");
-               screeninit();
-       }
-       if(discard)
-               while(nbrecv(mc->c, &m) > 0)
-                       ;
-}
-
-void
-flushscreen(void)
-{
-       flushmouse(1);
-       if(scale == 1){
-               loadimage(fb, fb->r, pic, vwdx * vwdy * vwbpp);
-               draw(screen, picr, fb, nil, ZP);
-       } else {
-               Rectangle r;
-               uchar *s;
-               int w;
-
-               s = pic;
-               r = picr;
-               w = vwdx * vwbpp * scale;
-               while(r.min.y < picr.max.y){
-                       loadimage(fb, fb->r, s, w);
-                       s += w;
-                       r.max.y = r.min.y+scale;
-                       draw(screen, r, fb, nil, ZP);
-                       r.min.y = r.max.y;
-               }
-       }
-       flushimage(display, 1);
-       if(profile)
-               timing();
-}
-
-void
-flushaudio(int (*audioout)(void))
-{
-       static vlong old, delta;
-       vlong new, diff;
-
-       if(audioout == nil || audioout() < 0 && !warp10){
-               new = nsec();
-               diff = 0;
-               if(old != 0){
-                       diff = BILLION/60 - (new - old) - delta;
-                       if(diff >= MILLION)
-                               sleep(diff/MILLION);
-               }
-               old = nsec();
-               if(diff > 0){
-                       diff = (old - new) - (diff / MILLION) * MILLION;
-                       delta += (diff - delta) / 100;
-               }
-       }
-       if(framestep){
-               paused = 1;
-               qlock(&pauselock);
-               framestep = 0;
-       }
-}
-
-void
-regkeyfn(Rune r, void (*fn)(void))
-{
-       Kfn *kp;
-
-       for(kp=&kfn; kp->n!=nil; kp=kp->n)
-               ;
-       kp->n = emalloc(sizeof *kp);
-       kp->n->r = r;
-       kp->n->fn = fn;
-}
-
-void
-regkey(char *joyk, Rune r, int k)
-{
-       Kfn *kp;
-
-       for(kp=&kkn; kp->n!=nil; kp=kp->n)
-               ;
-       kp->n = emalloc(sizeof *kp);
-       strncpy(kp->n->joyk, joyk, sizeof(kp->n->joyk)-1);
-       kp->n->r = r;
-       kp->n->k = k;
-}
-
-void
-initemu(int dx, int dy, int bpp, ulong chan, int dokey, void(*kproc)(void*))
-{
-       vwdx = dx;
-       vwdy = dy;
-       vwchan = chan;
-       vwbpp = bpp;
-       if(initdraw(nil, nil, nil) < 0)
-               sysfatal("initdraw: %r");
-       mc = initmouse(nil, screen);
-       if(mc == nil)
-               sysfatal("initmouse: %r");
-       if(dokey)
-               proccreate(kproc != nil ? kproc : keyproc, nil, mainstacksize);
-       if(kproc == nil)
-               proccreate(joyproc, nil, mainstacksize*2);
-       bg = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0xCCCCCCFF);
-       screeninit();
-}
diff --git a/sys/src/libemu/mkfile b/sys/src/libemu/mkfile
deleted file mode 100644 (file)
index f436124..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-</$objtype/mkfile
-
-LIB=/$objtype/lib/libemu.a
-
-OFILES=\
-       emu.$O\
-
-HFILES=\
-       /sys/include/draw.h\
-       /sys/include/emu.h\
-       /sys/include/mouse.h\
-       /sys/include/keyboard.h
-
-UPDATE=\
-       mkfile\
-       $HFILES\
-       ${OFILES:%.$O=%.c}\
-       ${LIB:/$objtype/%=/386/%}\
-
-</sys/src/cmd/mksyslib