shithub: riscv

Download patch

ref: f62e54b13dc36753e09645de993946f878e68533
parent: 59d4a6261f42044f3c6ba340fc9844524afa1983
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Jan 1 21:06:08 EST 2024

sgi: make newport graphics work in MAME

MAME doesnt support RGB Map 1 mode so use RGB Map 0 instead.

Hardware cursor is screwed up too, so just implement
software cursor for now.

--- a/sys/src/9/sgi/indy
+++ b/sys/src/9/sgi/indy
@@ -16,7 +16,7 @@
 	cap
 	kprof
 #	sd
-	draw screen
+	draw screen swcursor
 	mouse
 	kbd
 	
--- a/sys/src/9/sgi/screen.c
+++ b/sys/src/9/sgi/screen.c
@@ -13,6 +13,12 @@
 #include "screen.h"
 
 /*
+ * MAME screws up hardware cursor,
+ * so use software cursor for now.
+ */
+#define SWCURSOR 1
+
+/*
  * Register constant below from XFree86 driver.
  */ 
 
@@ -431,7 +437,6 @@
 static Newport *regsgo = IO(Newport, GIO_NEWPORT|0x800);
 
 Memimage *gscreen;
-static Point curoff;
 
 static void 
 vc2set(uchar r, ushort val)
@@ -452,10 +457,75 @@
 	return regs->dcbdata0 >> 16;
 }
 
+static void
+hwcursoroff(void)
+{
+	int s;
 
+	s = splhi();
+	vc2set(VC2_IREG_CONTROL, vc2get(VC2_IREG_CONTROL) & ~VC2_CTRL_ECDISP);
+	splx(s);
+}
+
+#ifdef SWCURSOR
+
+/* swcursor.c */
+extern void	swcursorhide(int);
+extern void	swcursoravoid(Rectangle);
+extern void	swcursordraw(Point);
+extern void	swcursorload(Cursor *);
+extern void	swcursorinit(void);
+
 void
 cursoron(void)
 {
+	swcursorhide(0);
+	swcursordraw(mousexy());
+}
+
+void
+cursoroff(void)
+{
+	swcursorhide(0);
+}
+
+void
+setcursor(Cursor* curs)
+{
+	swcursorload(curs);
+}
+
+int
+hwdraw(Memdrawparam *par)
+{
+	Memimage *dst, *src, *mask;
+	uchar *scrd;
+
+	if((dst = par->dst) == nil || dst->data == nil)
+		return 0;
+	if((src = par->src) && src->data == nil)
+		src = nil;
+	if((mask = par->mask) && mask->data == nil)
+		mask = nil;
+
+	scrd = gscreen->data->bdata;
+	if(dst->data->bdata == scrd)
+		swcursoravoid(par->r);
+	if(src && src->data->bdata == scrd)
+		swcursoravoid(par->sr);
+	if(mask && mask->data->bdata == scrd)
+		swcursoravoid(par->mr);
+
+	return 0;
+}
+
+#else
+
+static Point curoff;
+
+void
+cursoron(void)
+{
 	Point xy;
 	int s;
 
@@ -471,11 +541,7 @@
 void
 cursoroff(void)
 {
-	int s;
-
-	s = splhi();
-	vc2set(VC2_IREG_CONTROL, vc2get(VC2_IREG_CONTROL) & ~VC2_CTRL_ECDISP);
-	splx(s);
+	hwcursoroff();
 }
 
 void
@@ -515,8 +581,10 @@
 		regs->dcbdata0 = *(ushort*)(&mem[i]) << 16;
 	}
 	splx(s);
-}	
+}
 
+#endif	
+
 static void
 setmode(void)
 {
@@ -531,7 +599,7 @@
 	regs->dcbmode = (DCB_XMAP_ALL | W_DCB_XMAP9_PROTOCOL |
 		XM9_CRS_MODE_REG_DATA | NPORT_DMODE_W4);
 	regs->dcbdata0 = (XM9_MREG_PIX_SIZE_24BPP | 
-		XM9_MREG_PIX_MODE_RGB1 | XM9_MREG_GAMMA_BYPASS);
+		XM9_MREG_PIX_MODE_RGB0 | XM9_MREG_GAMMA_BYPASS);
 
 	while(regs->stat & NPORT_STAT_BBUSY)
 		;
@@ -568,6 +636,10 @@
 		modeset = 1;
 		arcsoff();
 		setmode();
+#ifdef SWCURSOR
+		hwcursoroff();
+		swcursorinit();
+#endif
 	}
 
 	while(regs->stat & NPORT_STAT_GBUSY)