utils: add a "mode" command for mode setting
authorAlan Cox <alan@linux.intel.com>
Sat, 3 Oct 2015 15:54:01 +0000 (16:54 +0100)
committerAlan Cox <alan@linux.intel.com>
Sat, 3 Oct 2015 15:54:01 +0000 (16:54 +0100)
Well it had to be called "mode" for an 8bit box 8)

Also fix the header up

Applications/util/Makefile
Applications/util/Makefile.6809
Applications/util/mode.c [new file with mode: 0644]
Library/include/sys/graphics.h

index 284e59e..c26aadc 100644 (file)
@@ -78,6 +78,7 @@ SRCS  = banner.c \
        ls.c \
        man.c \
        mkfs.c \
+       mode.c \
        more.c \
        mount.c \
        od.c \
index 03d8a95..ec9d280 100644 (file)
@@ -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 (file)
index 0000000..7b18766
--- /dev/null
@@ -0,0 +1,224 @@
+/*
+ *     Video mode setting
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <sys/types.h>
+#include <sys/graphics.h>
+
+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;
+}
index 04734a6..857639f 100644 (file)
@@ -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 */