From 789079709ab8640a3b7948613c35c9f01b89794f Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 3 Oct 2015 16:54:01 +0100 Subject: [PATCH] utils: add a "mode" command for mode setting Well it had to be called "mode" for an 8bit box 8) Also fix the header up --- Applications/util/Makefile | 1 + Applications/util/Makefile.6809 | 1 + Applications/util/mode.c | 224 ++++++++++++++++++++++++++++++++ Library/include/sys/graphics.h | 8 +- 4 files changed, 230 insertions(+), 4 deletions(-) create mode 100644 Applications/util/mode.c diff --git a/Applications/util/Makefile b/Applications/util/Makefile index 284e59e2..c26aadc4 100644 --- a/Applications/util/Makefile +++ b/Applications/util/Makefile @@ -78,6 +78,7 @@ SRCS = banner.c \ ls.c \ man.c \ mkfs.c \ + mode.c \ more.c \ mount.c \ od.c \ diff --git a/Applications/util/Makefile.6809 b/Applications/util/Makefile.6809 index 03d8a950..ec9d2806 100644 --- a/Applications/util/Makefile.6809 +++ b/Applications/util/Makefile.6809 @@ -56,6 +56,7 @@ SRCS = banner.c \ mkfs.c \ mkfifo.c \ mknod.c \ + mode.c \ more.c \ mount.c \ mv.c \ diff --git a/Applications/util/mode.c b/Applications/util/mode.c new file mode 100644 index 00000000..7b18766f --- /dev/null +++ b/Applications/util/mode.c @@ -0,0 +1,224 @@ +/* + * Video mode setting + */ + +#include +#include +#include +#include +#include + +#include +#include + +static struct display disp; +static char *appname; + +static int force; +static int list; +static int info; +static int set; + +static void format(int n) { + switch(n) { + case FMT_MONO_BW: + printf("mono black on white"); + break; + case FMT_MONO_WB: + printf("mono white on black"); + break; + case FMT_COLOUR4: + printf("four colour"); + break; + case FMT_COLOUR16: + printf("sixteen colour"); + break; + case FMT_SPECTRUM: + printf("Sinclair Spectrum"); + break; + case FMT_VDP: + printf("VDP"); + break; + default: + printf("Unknown(%d)", n); + } +} + +static void decode_mode_c(int c) +{ + if (!info) { + printf("%d\n", disp.mode); + return; + } + printf("Mode: %d%s\n", disp.mode, c == disp.mode ? " (Current)":""); + printf("Size: %d x %d (%d x %d)\n", + disp.width, disp.height, disp.stride, disp.lines); + printf("Format: "); + format(disp.format); + printf("\nHardware: "); + switch(disp.hardware) { + case HW_UNACCEL: + printf("unaccelerated framebuffer"); + break; + case HW_VDP_9918: + printf("9918"); + break; + case HW_VDP_9938: + printf("9938"); + break; + case HW_TRS80GFX: + printf("TRS80 Hi-Res Board"); + break; + default: + printf("Unknown (%d)", disp.hardware); + break; + } + printf("\nFeatures: "); + if (disp.features & GFX_MAPPABLE) + printf("mappable "); + if (disp.features & GFX_PALETTE) + printf("palette "); + if (disp.features & GFX_OFFSCREEN) + printf("offscreen "); + if (disp.features & GFX_VBLANK) + printf("vblank "); + if (disp.features & GFX_ENABLE) + printf("enable "); + if (disp.features & GFX_MULTIMODE) + printf("multimode "); + if (disp.features & GFX_PALETTE_SET) + printf("setpalette "); + if (disp.features & GFX_TEXT) + printf("text "); + printf("\n"); + if (disp.memory) + printf("Memory: %dK\n", disp.memory); + printf("Commands: "); + if (disp.commands & GFX_DRAW) + printf("draw "); + if (disp.commands & GFX_RAW) + printf("raw "); + if (disp.commands & GFX_ADRAW) + printf("adraw "); + if (disp.commands & GFX_CLIP) + printf("clip "); + if (disp.commands & GFX_BLIT) + printf("blit "); + if (disp.commands & GFX_READ) + printf("read "); + if (disp.commands & GFX_PDRAW) + printf("pdraw "); + if (disp.commands & GFX_WRITE) + printf("write "); + if (disp.commands & GFX_AWRITE) + printf("awrite "); + printf("\n"); +} + +static void decode_mode(void) +{ + decode_mode_c(-1); +} + +static void ioctl_err(void) +{ + if (errno == ENOTTY) + fprintf(stderr, "%s: not graphics capable.\n", appname); + else + fprintf(stderr, "%s: mode not supported.\n", appname); + exit(1); +} + +static void show_mode(int m) { + disp.mode = m; + + if (ioctl(0, GFXIOC_GETMODE, &disp) < 0) + ioctl_err(); + decode_mode(); +} + +static void show_current(void) { + if (ioctl(0, GFXIOC_GETINFO, &disp) < 0) + ioctl_err(); + decode_mode(); +} + +static void list_modes(void) { + int i = 0; + int c = disp.mode; + + if (ioctl(0, GFXIOC_GETINFO, &disp) < 0) + ioctl_err(); + + while(1) { + disp.mode = i; + if (ioctl(0, GFXIOC_GETMODE, &disp) < 0) + break; + decode_mode_c(c); + i++; + } +} + +static void set_mode(int m) { + disp.mode = m; + if (ioctl(0, GFXIOC_GETMODE, &disp)) + ioctl_err(); + if (!(disp.features & GFX_TEXT) && !force) { + fprintf(stderr, "%s: no text mode support, use -f to force set\n", + appname); + exit(1); + } + if (ioctl(0, GFXIOC_SETMODE, &disp) < 0) + ioctl_err(); +} + +static void error(void) +{ + fprintf(stderr, "%s: [-f] [-l] [-s mode] [-i mode mode ...]\n", appname); + exit(1); +} + +int main(int argc, char *argv[]) +{ + char **argp = argv; + appname = argv[0]; + + while(*++argp && (*argp)[0] == '-') { + switch((*argp)[1]) { + case 'f': + force = 1; + break; + case 's': + set = 1; + break; + case 'i': + info = 1; + break; + case 'l': + list = 1; + break; + default: + error(); + } + } + if (set) { + int f = atoi(*argp++); + if (*argp) + error(); + set_mode(f); + return 0; + } + if (list && !*argp) { + list_modes(); + return 0; + } + if (!*argp) + show_current(); + else while(*argp) { + int f = atoi(*argp++); + if (!list) + info = 1; + show_mode(f); + } + return 0; +} diff --git a/Library/include/sys/graphics.h b/Library/include/sys/graphics.h index 04734a61..857639f9 100644 --- a/Library/include/sys/graphics.h +++ b/Library/include/sys/graphics.h @@ -55,10 +55,10 @@ struct palette { /* Returned from a successful GFXIOC_MAP */ struct videomap { - uaddr_t mmio; /* Memory mapped register base */ - uaddr_t pio; /* I/O space register base */ - uaddr_t fbmem; /* Frame buffer memory */ - usize_t fbsize; + void * mmio; /* Memory mapped register base */ + void * pio; /* I/O space register base */ + void * fbmem; /* Frame buffer memory */ + size_t fbsize; uint8_t mmio_seg; /* For the 8086 */ uint8_t fbmem_seg; uint8_t spacing; /* Multiplier for non standard register spacing */ -- 2.34.1