ref: 29491679b891dd50b9921edd05093a71f17403aa
parent: eeac553c36e1cb1d7786115d7202bfe732deb54e
author: aiju <devnull@localhost>
date: Thu Feb 20 17:13:59 EST 2014
games/nes: cleanup and resize handling
--- a/sys/src/games/nes/cpu.c
+++ b/sys/src/games/nes/cpu.c
@@ -6,7 +6,6 @@
u16int pc, curpc;
u8int rA, rX, rY, rS, rP;
int nmi;
-extern int map;
static u8int
fetch8(void)
--- a/sys/src/games/nes/dat.h
+++ b/sys/src/games/nes/dat.h
@@ -1,9 +1,15 @@
extern u16int pc, curpc;
extern u8int rA, rX, rY, rS, rP;
-extern uchar mem[32768];
-extern int scale;
+extern uchar mem[32768], ppuram[16384], oam[256];
extern u16int pput, ppuv;
extern u8int ppusx;
+extern int mirr;
+
+extern int map, scale;
+extern uchar *prg, *chr;
+extern int nprg, nchr, nmi, map;
+
+extern int keys;
enum {
FLAGC = 1<<0,
--- a/sys/src/games/nes/mem.c
+++ b/sys/src/games/nes/mem.c
@@ -9,12 +9,9 @@
uchar ppuram[16384];
uchar oam[256];
uchar *prgb[2], *chrb[2];
-extern uchar *prg, *chr;
-extern int nprg, nchr;
u16int pput, ppuv;
u8int ppusx;
static int vramlatch = 1, keylatch = 0xFF;
-extern int keys, nmi, map, mirr;
static void
nrom(int p, u8int)
--- a/sys/src/games/nes/ppu.c
+++ b/sys/src/games/nes/ppu.c
@@ -2,12 +2,12 @@
#include <libc.h>
#include <thread.h>
#include <draw.h>
+#include <mouse.h>
#include "dat.h"
#include "fns.h"
int ppuy, ppux, odd;
uchar pic[256*240*4*9];
-extern uchar oam[256];
static void
pixel(int x, int y, int val, int back)
@@ -248,8 +248,21 @@
flush(void)
{
extern Rectangle picr;
- extern Image *tmp;
+ extern Image *tmp, *bg;
+ extern Mousectl *mc;
+ Mouse m;
+ Point p;
+ while(nbrecv(mc->c, &m) > 0)
+ ;
+ if(nbrecvul(mc->resizec) > 0){
+ if(getwindow(display, Refnone) < 0)
+ sysfatal("resize failed: %r");
+ p = divpt(addpt(screen->r.min, screen->r.max), 2);
+ picr = (Rectangle){subpt(p, Pt(scale * 128, scale * 120)), addpt(p, Pt(scale * 128, scale * 120))};
+ bg = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0xCCCCCCFF);
+ draw(screen, screen->r, bg, nil, ZP);
+ }
if(tmp){
loadimage(tmp, tmp->r, pic, 256*240*4*scale*scale);
draw(screen, picr, tmp, nil, ZP);