ref: e15d0126ad7e6f74150ae079daae33a961a4387b
parent: 763231588c971758d36c7c48cd073f2fa96f8f5a
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Nov 18 12:00:44 EST 2014
games/md: apply same screen flush changes from games/snes
--- a/sys/src/games/md/md.c
+++ b/sys/src/games/md/md.c
@@ -22,6 +22,7 @@
int scale, paused;
QLock pauselock;
Mousectl *mc;
+Channel *flushc;
Rectangle picr;
Image *tmp, *bg;
@@ -126,6 +127,51 @@
}
void
+screenproc(void *)
+{
+ extern u8int pic[320*224*4*3];
+ Rectangle r;
+ uchar *s;
+ int w;
+
+ enum { AMOUSE, ARESIZE, AFLUSH, AEND };
+ Alt a[AEND+1] = {
+ { mc->c, nil, CHANRCV },
+ { mc->resizec, nil, CHANRCV },
+ { flushc, nil, CHANRCV },
+ { nil, nil, CHANEND }
+ };
+
+ for(;;){
+ switch(alt(a)){
+ case ARESIZE:
+ if(getwindow(display, Refnone) < 0)
+ sysfatal("resize failed: %r");
+ screeninit();
+ /* wet floor */
+ case AFLUSH:
+ if(scale == 1){
+ loadimage(tmp, tmp->r, pic, 320*224*4);
+ draw(screen, picr, tmp, nil, ZP);
+ }else{
+ s = pic;
+ r = picr;
+ w = 320*4*scale;
+ while(r.min.y < picr.max.y){
+ loadimage(tmp, tmp->r, s, w);
+ s += w;
+ r.max.y = r.min.y+scale;
+ draw(screen, r, tmp, nil, ZP);
+ r.min.y = r.max.y;
+ }
+ }
+ flushimage(display, 1);
+ break;
+ }
+ }
+}
+
+void
keyproc(void *)
{
int fd, k;
@@ -202,13 +248,15 @@
threadexitsall("usage");
}
loadrom(*argv);
- if(initdraw(nil, nil, nil) < 0)
+ if(initdraw(nil, nil, argv0) < 0)
sysfatal("initdraw: %r");
- proccreate(keyproc, nil, 8192);
+ flushc = chancreate(sizeof(ulong), 1);
mc = initmouse(nil, screen);
if(mc == nil)
sysfatal("initmouse: %r");
screeninit();
+ proccreate(keyproc, nil, 8192);
+ proccreate(screenproc, nil, 8192);
cpureset();
vdpmode();
ymreset();
@@ -257,37 +305,10 @@
void
flush(void)
{
- extern uchar pic[320*224*2*3*3];
- Mouse m;
- Rectangle r;
- uchar *s;
- int w;
static vlong old, delta;
vlong new, diff;
- if(nbrecvul(mc->resizec) > 0){
- if(getwindow(display, Refnone) < 0)
- sysfatal("resize failed: %r");
- screeninit();
- }
- while(nbrecv(mc->c, &m) > 0)
- ;
- if(scale == 1){
- loadimage(tmp, tmp->r, pic, 320*224*4);
- draw(screen, picr, tmp, nil, ZP);
- }else{
- s = pic;
- r = picr;
- w = 320*4*scale;
- while(r.min.y < picr.max.y){
- loadimage(tmp, tmp->r, s, w);
- s += w;
- r.max.y = r.min.y+scale;
- draw(screen, r, tmp, nil, ZP);
- r.min.y = r.max.y;
- }
- }
- flushimage(display, 1);
+ sendul(flushc, 1); /* flush screen */
if(audioout() < 0){
new = nsec();
diff = 0;
--- a/sys/src/games/md/vdp.c
+++ b/sys/src/games/md/vdp.c
@@ -4,7 +4,7 @@
#include "dat.h"
#include "fns.h"
-u8int pic[320*224*4*3*3];
+u8int pic[320*224*4*3];
u16int vdpstat = 0x3400;
int vdpx, vdpy;
u16int hctr;