From 09c61204440ea7d23015b09f908e4105b68cc7b6 Mon Sep 17 00:00:00 2001 From: qwx Date: Wed, 13 Jun 2018 14:05:19 +0200 Subject: [PATCH] emulators ui: add option for fixed factor scaling and bound scale vertically --- sys/man/1/atari | 8 +++++++- sys/man/1/nintendo | 15 +++++++++++++++ sys/man/1/sega | 6 ++++++ sys/src/games/2600/2600.c | 19 +++++++++++++------ sys/src/games/c64/c64.c | 5 ++++- sys/src/games/eui.c | 17 +++++++++++------ sys/src/games/eui.h | 2 +- sys/src/games/gb/gb.c | 5 ++++- sys/src/games/gba/gba.c | 5 ++++- sys/src/games/md/md.c | 19 +++++++++++++------ sys/src/games/nes/nes.c | 20 +++++++++++++------- sys/src/games/snes/snes.c | 20 +++++++++++++------- 12 files changed, 104 insertions(+), 37 deletions(-) diff --git a/sys/man/1/atari b/sys/man/1/atari index 63e5e8193..f18731316 100644 --- a/sys/man/1/atari +++ b/sys/man/1/atari @@ -1,10 +1,13 @@ -.SH ATARI 1 +.TH ATARI 1 .SH NAME 2600 \- emulator .SH SYNOPSIS .B games/2600 [ .B -a +] [ +.B -x +.I scale ] .I romfile .SH DESCRIPTION @@ -26,6 +29,9 @@ Command line options: .TP .B -a Enable audio output. +.TP +.B -x +Scale the screen to a given factor regardless of the window's size. .SH SOURCE .B /sys/src/games/2600 .SH BUGS diff --git a/sys/man/1/nintendo b/sys/man/1/nintendo index b1ea5cc7c..d820b8c9c 100644 --- a/sys/man/1/nintendo +++ b/sys/man/1/nintendo @@ -9,6 +9,9 @@ gb, gba, nes, snes \- emulators [ .B -C .I ... +] [ +.B -x +.I scale ] .I romfile .br @@ -21,18 +24,27 @@ gb, gba, nes, snes \- emulators ] [ .B -s .I savetype +] [ +.B -x +.I scale ] .I romfile .br .B games/nes [ .B -aos +] [ +.B -x +.I scale ] .I romfile .br .B games/snes [ .B -ahmsT +] [ +.B -x +.I scale ] .I romfile .SH DESCRIPTION @@ -62,6 +74,9 @@ Command line options: .TP .B -a Enable audio output. +.TP +.B -x +Scale the screen to a given factor regardless of the window's size. .PP .B gb options: diff --git a/sys/man/1/sega b/sys/man/1/sega index 5b0714b35..6aa086ac6 100644 --- a/sys/man/1/sega +++ b/sys/man/1/sega @@ -5,6 +5,9 @@ md \- emulator .B games/md [ .B -a +] [ +.B -x +.I scale ] .I romfile .SH DESCRIPTION @@ -24,6 +27,9 @@ Command line options: .TP .B -a Enable audio output. +.TP +.B -x +Scale the screen to a given factor regardless of the window's size. .SH SOURCE .B /sys/src/games/md .SH BUGS diff --git a/sys/src/games/2600/2600.c b/sys/src/games/2600/2600.c index 728401d89..17f842ac5 100644 --- a/sys/src/games/2600/2600.c +++ b/sys/src/games/2600/2600.c @@ -49,6 +49,13 @@ loadrom(char *name) close(fd); } +void +usage(void) +{ + fprint(2, "usage: %s [-a] [-x scale] rom\n", argv0); + exits("usage"); +} + void threadmain(int argc, char **argv) { @@ -56,14 +63,14 @@ threadmain(int argc, char **argv) case 'a': initaudio(); break; + case 'x': + fixscale = strtol(EARGF(usage()), nil, 0); + break; default: - goto usage; + usage(); } ARGEND; - if(argc != 1){ - usage: - fprint(2, "usage: %s [ -23a ] rom\n", argv0); - exits("usage"); - } + if(argc != 1) + usage(); loadrom(argv[0]); initemu(PICW, PICH, 4, XRGB32, 1, nil); regkey("a", ' ', 1<<4); diff --git a/sys/src/games/c64/c64.c b/sys/src/games/c64/c64.c index 2ca976fe7..439688e8f 100644 --- a/sys/src/games/c64/c64.c +++ b/sys/src/games/c64/c64.c @@ -212,7 +212,7 @@ keyproc(void *) static void usage(void) { - fprint(2, "usage: %s [ -23a ] [ rom ]\n", argv0); + fprint(2, "usage: %s [-Nap] [-c cart] [-t tape] [-d bindir] [-x scale] rom\n", argv0); exits("usage"); } @@ -237,6 +237,9 @@ threadmain(int argc, char **argv) case 'd': bindir = strdup(EARGF(usage())); break; + case 'x': + fixscale = strtol(EARGF(usage()), nil, 0); + break; default: usage(); } ARGEND; diff --git a/sys/src/games/eui.c b/sys/src/games/eui.c index 8bd05e850..422d02d78 100644 --- a/sys/src/games/eui.c +++ b/sys/src/games/eui.c @@ -12,7 +12,7 @@ u64int keys, keys2; int trace, paused; int savereq, loadreq; QLock pauselock; -int scale, warp10; +int scale, fixscale, warp10; uchar *pic; Rectangle picr; Mousectl *mc; @@ -188,11 +188,15 @@ screeninit(void) { Point p; - scale = Dx(screen->r) / vwdx; - if(scale <= 0) - scale = 1; - else if(scale > 16) - scale = 16; + if(!fixscale){ + scale = Dx(screen->r) / vwdx; + if(Dy(screen->r) / vwdy < scale) + scale = Dy(screen->r) / vwdy; + 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))); @@ -319,5 +323,6 @@ initemu(int dx, int dy, int bpp, ulong chan, int dokey, void(*kproc)(void*)) if(kproc == nil) proccreate(joyproc, nil, mainstacksize); bg = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0xCCCCCCFF); + scale = fixscale; screeninit(); } diff --git a/sys/src/games/eui.h b/sys/src/games/eui.h index 949cf7cb2..89d6fafbb 100644 --- a/sys/src/games/eui.h +++ b/sys/src/games/eui.h @@ -7,7 +7,7 @@ extern u64int keys, keys2; extern int trace, paused; extern int savereq, loadreq; extern QLock pauselock; -extern int scale, warp10; +extern int scale, fixscale, warp10; extern uchar *pic; void* emalloc(ulong); diff --git a/sys/src/games/gb/gb.c b/sys/src/games/gb/gb.c index b82729023..5e038ddf4 100644 --- a/sys/src/games/gb/gb.c +++ b/sys/src/games/gb/gb.c @@ -221,7 +221,7 @@ flush(void) void usage(void) { - fprint(2, "usage: %s [-23aTcd] [-C col0,col1,col2,col3] rom\n", argv0); + fprint(2, "usage: %s [-aTcd] [-C col0,col1,col2,col3] [-x scale] rom\n", argv0); exits("usage"); } @@ -277,6 +277,9 @@ threadmain(int argc, char **argv) case 'C': colparse(EARGF(usage())); break; + case 'x': + fixscale = strtol(EARGF(usage()), nil, 0); + break; default: usage(); } ARGEND; diff --git a/sys/src/games/gba/gba.c b/sys/src/games/gba/gba.c index ec8c1bc7a..a306c756a 100644 --- a/sys/src/games/gba/gba.c +++ b/sys/src/games/gba/gba.c @@ -220,7 +220,7 @@ flush(void) void usage(void) { - fprint(2, "usage: %s [-aT] [-s savetype] [-b biosfile] rom\n", argv0); + fprint(2, "usage: %s [-a] [-s savetype] [-b biosfile] [-x scale] rom\n", argv0); exits("usage"); } @@ -243,6 +243,9 @@ threadmain(int argc, char **argv) case 'b': biosfile = strdup(EARGF(usage())); break; + case 'x': + fixscale = strtol(EARGF(usage()), nil, 0); + break; default: usage(); } ARGEND; diff --git a/sys/src/games/md/md.c b/sys/src/games/md/md.c index 2c0ed3fda..e9060e61c 100644 --- a/sys/src/games/md/md.c +++ b/sys/src/games/md/md.c @@ -102,6 +102,13 @@ loadrom(char *file) } } +void +usage(void) +{ + fprint(2, "usage: %s [-a] [-x scale] rom\n", argv0); + exits("usage"); +} + void threadmain(int argc, char **argv) { @@ -111,14 +118,14 @@ threadmain(int argc, char **argv) case 'a': initaudio(); break; + case 'x': + fixscale = strtol(EARGF(usage()), nil, 0); + break; default: - ; + usage(); } ARGEND; - - if(argc != 1){ - fprint(2, "usage: %s [-23a] rom\n", argv0); - threadexitsall("usage"); - } + if(argc < 1) + usage(); loadrom(*argv); initemu(320, 224, 4, XRGB32, 1, nil); regkey("a", 'c', 1<<5); diff --git a/sys/src/games/nes/nes.c b/sys/src/games/nes/nes.c index 38984efff..92c470f21 100644 --- a/sys/src/games/nes/nes.c +++ b/sys/src/games/nes/nes.c @@ -117,6 +117,13 @@ loadrom(char *file, int sflag) mapper[map](INIT, 0); } +void +usage(void) +{ + fprint(2, "usage: %s [-aos] [-x scale] rom\n", argv0); + exits("usage"); +} + void threadmain(int argc, char **argv) { @@ -133,15 +140,14 @@ threadmain(int argc, char **argv) case 's': sflag = 1; break; + case 'x': + fixscale = strtol(EARGF(usage()), nil, 0); + break; default: - goto usage; + usage(); } ARGEND; - - if(argc != 1){ - usage: - fprint(2, "usage: %s [-23aos] rom\n", argv0); - threadexitsall("usage"); - } + if(argc < 1) + usage(); loadrom(argv[0], sflag); initemu(256, 240 - oflag * 16, 4, XRGB32, 1, nil); regkey("b", 'z', 1<<1); diff --git a/sys/src/games/snes/snes.c b/sys/src/games/snes/snes.c index 7d37fcbc3..ba9040845 100644 --- a/sys/src/games/snes/snes.c +++ b/sys/src/games/snes/snes.c @@ -108,6 +108,13 @@ loadbat(char *file) } } +void +usage(void) +{ + fprint(2, "usage: %s [-23ahmsT] [-x scale] rom\n", argv0); + exits("usage"); +} + void threadmain(int argc, char **argv) { @@ -129,15 +136,14 @@ threadmain(int argc, char **argv) case 'h': hirom++; break; + case 'x': + fixscale = strtol(EARGF(usage()), nil, 0); + break; default: - goto usage; + usage(); } ARGEND; - - if(argc != 1){ -usage: - fprint(2, "usage: %s [-23ahmsT] rom\n", argv0); - threadexitsall("usage"); - } + if(argc < 1) + usage(); loadrom(argv[0]); initemu(256, 239, 2, RGB15, !mouse, nil); regkey("b", 'z', 1<<31);