From e11450fe148824b2c07947be924571ed1761a042 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 7 Jul 2018 00:39:02 +0100 Subject: [PATCH] utils: add joystick and graphics test code --- Applications/util/Makefile.z80 | 2 + Applications/util/gfxtest.c | 225 +++++++++++++++++++++++++++++++++ Applications/util/jstest.c | 35 +++++ 3 files changed, 262 insertions(+) create mode 100644 Applications/util/gfxtest.c create mode 100644 Applications/util/jstest.c diff --git a/Applications/util/Makefile.z80 b/Applications/util/Makefile.z80 index bb6b40d2..24d484ca 100644 --- a/Applications/util/Makefile.z80 +++ b/Applications/util/Makefile.z80 @@ -63,9 +63,11 @@ SRCS = banner.c \ fgrep.c \ free.c \ fsck.c \ + gfxtest.c \ gptparse.c \ grep.c \ id.c \ + jstest.c \ kbdrate.c \ ll.c \ ls.c \ diff --git a/Applications/util/gfxtest.c b/Applications/util/gfxtest.c new file mode 100644 index 00000000..599e0efd --- /dev/null +++ b/Applications/util/gfxtest.c @@ -0,0 +1,225 @@ +#include +#include +#include +#include +#include + +static struct display d; +static struct videomap v; + +__sfr __at 0x00 hrg1b_off; +__sfr __at 0x01 hrg1b_on; +__sfr __at 0x02 hrg1b_l; +__sfr __at 0x03 hrg1b_h; +__sfr __at 0x04 hrg1b_r; +__sfr __at 0x05 hrg1b_w; + +static int test_hrg1b(void) +{ + int line, col, row; + uint8_t c; + if (ioctl(0, GFXIOC_MAP, &v)) { + perror("GFXIOC_MAP"); + exit(1); + } + if (!(v.flags & MAP_PIO)) { + fprintf(stderr, "PIO map required.\n"); + exit(1); + } + if (d.format != FMT_MONO_WB) { + fprintf(stderr, "Format should be mono.\n"); + exit(1); + } + printf("HRG1 at 0x%02X\n", (unsigned int)v.pio); + if ((unsigned int)v.pio != 0) { + fprintf(stderr, "HR1G reported on wrong port.\n"); + exit(1); + } + hrg1b_on = 255; + for (col = 0; col < 64; col++) { + for (row = 0; row < 16; row ++) { + for (line = 0; line < 12; line += 2) { + uint16_t v = col | (row << 6) | (line << 10); + hrg1b_l = v; + hrg1b_h = (v >> 8); + hrg1b_w = 0x2A; + v += (1 << 10); + hrg1b_h = (v >> 8); + hrg1b_w = 0x15; + + } + } + } + c = hrg1b_r; + getchar(); + hrg1b_off = 255; + if (c != 0x15) { + fprintf(stderr, "hrg1: read fail.\n"); + exit(1); + } +} + +__sfr __at 0xFF microlabs_ctrl; +uint8_t *microlabs_fb = (uint8_t *)0x3C00; + +static void test_microlabs(void) +{ + int line, col, row; + if (ioctl(0, GFXIOC_MAP, &v)) { + perror("GFXIOC_MAP"); + exit(1); + } + if ((v.flags & (MAP_FBMEM|MAP_PIO)) != (MAP_FBMEM | MAP_PIO)) { + fprintf(stderr, "PIO and FBMEM map required.\n"); + exit(1); + } + if (d.format != FMT_MONO_WB) { + fprintf(stderr, "Format should be mono.\n"); + exit(1); + } + printf("Grafyx at 0x%02X\n", (unsigned int)v.pio); + if ((unsigned int)v.pio != 0xFF) { + fprintf(stderr, "Model 3 Grafyx reported on wrong port.\n"); + exit(1); + } + if (v.fbmem != microlabs_fb || v.fbsize != 0x0400) { + fprintf(stderr,"Model 3 Graftx fbmem should be 3C00-3FFF.\n"); + exit(1); + } + + for (col = 0; col < 64; col++) { + for (row = 0; row < 16; row ++) { + for (line = 0; line < 12; line ++) { + microlabs_ctrl = 0xE0 | (line << 1); + microlabs_fb[(row << 6) | col] = (line & 1) ? 0xAA : 0x55; + } + } + } + getchar(); + microlabs_ctrl = 0; +} + +__sfr __at 0x80 trs80_x; +__sfr __at 0x81 trs80_y; +__sfr __at 0x82 trs80_d; +__sfr __at 0x83 trs80_ctrl; + +void test_trs80gfx(void) +{ + int col, row; + uint8_t c; + if (ioctl(0, GFXIOC_MAP, &v)) { + perror("GFXIOC_MAP"); + exit(1); + } + if (!(v.flags & MAP_PIO)) { + fprintf(stderr, "PIO map required.\n"); + exit(1); + } + if (d.format != FMT_MONO_WB) { + fprintf(stderr, "Format should be mono.\n"); + exit(1); + } + printf("TRS80 Hi Res Graphics at 0x%02X\n", (unsigned int)v.pio); + if ((unsigned int)v.pio != 0x80) { + fprintf(stderr, "TRS80 HRG reported on wrong port.\n"); + exit(1); + } + trs80_ctrl = 0xB3; /* clock x on write */ + for (row = 0; row < 240; row++) { + trs80_y = row++; + trs80_x = 0; + /* The card is designed so you can effectively use otir and friends */ + for (col = 0; col < 80; col++) + trs80_d = 0xAA; + trs80_y = row; + trs80_x = 0; + for (col = 0; col < 80; col++) + trs80_d = 0x55; + } + trs80_y = 0; + trs80_x = 0; + c = trs80_d; + getchar(); + trs80_ctrl = 0; + if (c != 0xAA) { + fprintf(stderr, "trs80gfx: read fail.\n"); + exit(1); + } +} + +void test_mono(void) +{ + int x,y; + uint8_t c = 0xAA; + uint8_t *p = v.fbmem; + + for (y = 0; y < d.height; y++) { + uint8_t *r = p; + for (x = 0; x < d.width/8; x++) + *r++ = c; + p += d.stride; + c ^=255; + } + getchar(); +} + +void test_text(void) +{ + int x,y; + uint8_t c = '#'; + uint8_t *p = v.fbmem; + + for (y = 0; y < d.height; y++) { + uint8_t *r = p ; + for (x = 0; x < d.width; x++) + *r++ = c; + p += d.stride; + } + getchar(); +} + +void unaccelerated(void) +{ + if (ioctl(0, GFXIOC_MAP, &v)) { + fprintf(stderr, "Only mapped formats supported.\n"); + exit(1); + } + switch(d.format) { + case FMT_TEXT: + test_text(); + break; + case FMT_MONO_BW: + case FMT_MONO_WB: + test_mono(); + break; + default: + fprintf(stderr, "unsupported unaccelerated format %d.\n", d.format); + } +} + +int main(int argc, char *argv[]) +{ + if (ioctl(0, GFXIOC_GETINFO, &d)) { + perror("GFXIOC_GETINFO"); + exit(1); + } + switch(d.hardware) { + case HW_HRG1B: + test_hrg1b(); + break; + case HW_MICROLABS: + test_microlabs(); + break; + case HW_TRS80GFX: + test_trs80gfx(); + break; + case HW_UNACCEL: + unaccelerated(); + break; + default: + fprintf(stderr, "Hardware type %d not supported.\n", d.hardware); + exit(1); + } + exit(0); +} diff --git a/Applications/util/jstest.c b/Applications/util/jstest.c new file mode 100644 index 00000000..8f1af5b7 --- /dev/null +++ b/Applications/util/jstest.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + int fd = open("/dev/input", O_RDONLY); + char buf[2]; + int l; + + if (fd == -1) { + perror("/dev/input"); + exit(1); + } + while(1) { + l = read(fd, buf, 2); + if (l != 2) + continue; + if ((buf[0] & 0xF0) != STICK_DIGITAL) + continue; + printf("Joystick %d: %c%c%c%c%c%c%c%c\n", + buf[0] & 0x0F, + (buf[1]&STICK_DIGITAL_U)?'U':'-', + (buf[1]&STICK_DIGITAL_D)?'D':'-', + (buf[1]&STICK_DIGITAL_L)?'L':'-', + (buf[1]&STICK_DIGITAL_R)?'R':'-', + (buf[1]&BUTTON(0))?'0':'-', + (buf[1]&BUTTON(1))?'1':'-', + (buf[1]&BUTTON(2))?'2':'-', + (buf[1]&BUTTON(3))?'3':'-'); + fflush(stdout); + } +} -- 2.34.1