From e81598e2b5ce850dec9cadc3bbc198493dd04a20 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sun, 1 Jul 2018 20:40:05 +0100 Subject: [PATCH] coco2cart: tidy up ready for next releases - Fix conversion error in the ide driver - Shrink by one buffer now we don't use one for paths - Add graphics support Which just about fits... we only have a few hundred bytes left at this point --- Kernel/platform-coco2cart/devices.c | 2 +- Kernel/platform-coco2cart/devtty.c | 130 ++++++++++++++++++++++++++- Kernel/platform-coco2cart/mini_ide.c | 1 - 3 files changed, 128 insertions(+), 5 deletions(-) diff --git a/Kernel/platform-coco2cart/devices.c b/Kernel/platform-coco2cart/devices.c index d0c5488b..f2093266 100644 --- a/Kernel/platform-coco2cart/devices.c +++ b/Kernel/platform-coco2cart/devices.c @@ -21,7 +21,7 @@ struct devsw dev_tab[] = /* The device driver switch table */ /* 1: /dev/fd Floppy disc block devices */ { no_open, no_close, no_rdwr, no_rdwr , no_ioctl }, /* 2: /dev/tty TTY devices */ - { tty_open, tty_close, tty_read, tty_write, vt_ioctl }, + { tty_open, tty_close, tty_read, tty_write, gfx_ioctl }, /* 3: /dev/lpr Printer devices */ { no_open, no_close, no_rdwr, no_rdwr, no_ioctl }, /* 4: /dev/mem etc System devices (one offs) */ diff --git a/Kernel/platform-coco2cart/devtty.c b/Kernel/platform-coco2cart/devtty.c index e13481e8..a8344eae 100644 --- a/Kernel/platform-coco2cart/devtty.c +++ b/Kernel/platform-coco2cart/devtty.c @@ -30,6 +30,7 @@ struct s_queue ttyinq[NUM_DEV_TTY + 1] = { /* ttyinq[0] is never used */ uint8_t vtattr_cap = 0; struct vt_repeat keyrepeat = { 40, 4 }; static uint8_t kbd_timer; +static uint8_t vmode; /* tty1 is the screen tty2 is the serial port */ @@ -54,9 +55,10 @@ ttyready_t tty_writeready(uint8_t minor) void tty_putc(uint8_t minor, unsigned char c) { - if (minor == 1) - vtoutput(&c, 1); - else + if (minor == 1) { + if (vmode < 2) + vtoutput(&c, 1); + } else *uart_data = c; /* Data */ } @@ -253,6 +255,128 @@ void platform_interrupt(void) } } +static struct display display[4] = { + /* Two variants of 256x192 with different palette */ + /* 256 x 192 */ + { + 0, + 256, 192, + 256, 192, + 0xFF, 0xFF, /* For now */ + FMT_MONO_WB, + HW_UNACCEL, + GFX_TEXT|GFX_MAPPABLE|GFX_VBLANK|GFX_MULTIMODE, + 0, + GFX_DRAW|GFX_READ|GFX_WRITE, + }, + { + 1, + 256, 192, + 256, 192, + 0xFF, 0xFF, /* For now */ + FMT_MONO_WB, + HW_UNACCEL, + GFX_TEXT|GFX_MAPPABLE|GFX_VBLANK|GFX_MULTIMODE, + 0, + GFX_DRAW|GFX_READ|GFX_WRITE, + }, + /* 128 x 192 four colour modes */ + { + 2, + 128, 192, + 128, 192, + 0xFF, 0xFF, /* For now */ + FMT_COLOUR4, + HW_UNACCEL, + GFX_MAPPABLE|GFX_VBLANK, + 0, + GFX_DRAW|GFX_READ|GFX_WRITE|GFX_MULTIMODE, + }, + { + 3, + 128, 192, + 128, 192, + 0xFF, 0xFF, /* For now */ + FMT_COLOUR4, + HW_UNACCEL, + GFX_MAPPABLE|GFX_VBLANK, + 0, + GFX_DRAW|GFX_READ|GFX_WRITE|GFX_MULTIMODE, + }, + /* Possibly we should also allow for SG6 and SG4 ?? */ +}; + +static struct videomap displaymap = { + 0, + 0, + VIDEO_BASE, + 6 * 1024, + 0, + 0, + 0, + MAP_FBMEM|MAP_FBMEM_SIMPLE +}; + +/* bit 7 - A/G 6 GM2 5 GM1 4 GM0 & INT/EXT 3 CSS */ +static uint8_t piabits[] = { 0xF0, 0xF8, 0xE0, 0xE8}; + +static struct fontinfo fontinfo = { + 32, 127, 0, 0, FONT_INFO_8X8 +}; + +#define pia1b ((volatile uint8_t *)0xFF22) +#define sam_v ((volatile uint8_t *)0xFFC0) + +int gfx_ioctl(uint8_t minor, uarg_t arg, char *ptr) +{ + extern unsigned char fontdata_8x8[]; + uint16_t size = 96 * 8; + uint16_t base = 32 * 8; + + if (minor != 1 || (arg >> 8 != 0x03)) + return vt_ioctl(minor, arg, ptr); + + switch (arg) { + case VTFONTINFO: + return uput(&fontinfo, ptr, sizeof(fontinfo)); + case VTSETFONT: +// size = base = 0; +// case VTSETUDG: + return uget(fontdata_8x8 + base, ptr, size); + case VTGETFONT: +// size = base = 0; +// case VTGETUDG: + return uput(fontdata_8x8 + base, ptr, size); + case GFXIOC_GETINFO: + return uput(&display[vmode], ptr, sizeof(struct display)); + case GFXIOC_MAP: + return uput(&displaymap, ptr, sizeof(displaymap)); + case GFXIOC_UNMAP: + return 0; + case GFXIOC_GETMODE: + case GFXIOC_SETMODE: + { + uint8_t m = ugetc(ptr); + if (m > 3) { + udata.u_error = EINVAL; + return -1; + } + if (arg == GFXIOC_GETMODE) + return uput(&display[m], ptr, sizeof(struct display)); + vmode = m; + *pia1b = (*pia1b & 0x07) | piabits[m]; + return 0; + } + case GFXIOC_WAITVB: + /* Our system clock is our vblank, use the standard timeout + to pause for one clock */ + udata.u_ptab->p_timeout = 2; + psleep(NULL); + return 0; + } + return -1; +} + /* This is used by the vt asm code, but needs to live at the top of the kernel */ uint16_t cursorpos; diff --git a/Kernel/platform-coco2cart/mini_ide.c b/Kernel/platform-coco2cart/mini_ide.c index aeb693a0..e7c9ef1a 100644 --- a/Kernel/platform-coco2cart/mini_ide.c +++ b/Kernel/platform-coco2cart/mini_ide.c @@ -34,7 +34,6 @@ static int ide_transfer(uint8_t minor, bool is_read, uint8_t rawflag) return -1; idepage = rawflag; - nb = udata.u_nblock; dptr = udata.u_dptr; while(*status & 0x80); /* Wait !BUSY */ -- 2.34.1