[Freemint-list] [PATCH] Non-Atari hardware 2/3

Vincent Rivière vincent.riviere at freesbee.fr
Mon Jun 13 23:37:56 MSD 2016


On 07/06/2016 à 23:19, Vincent Rivière wrote:
> I have patched FreeMiNT to run on non-Atari hardware.

Here is the second batch.
It is composed of 3 patches.

Alan, please commit!

-- 2_mfp.patch --------------------

Do not use the MFP registers on non-Atari hardware.
Contributed by Vincent Riviere.

-- 3_st_escc.patch --------------------

Do not try to detect ST-ESCC on non-Atari hardware.
Contributed by Vincent Riviere.

-- 4_keyboard.patch --------------------

Hook keyboard using TOS >= 2.0 method on non-Atari hardware.
Contributed by Vincent Riviere.

-- 
Vincent Rivière
-------------- next part --------------
diff -aurN -x CVS -x .compile_030 -x .deps -x genmagic -x magic.i -x mkbuild.exe freemint.orig/sys/bios.c freemint/sys/bios.c
--- freemint.orig/sys/bios.c	2013-02-07 23:04:14.640625000 +0100
+++ freemint/sys/bios.c	2016-06-13 18:39:55.968750000 +0200
@@ -615,8 +615,16 @@
 	{
 		/* modem1 */
 
-		/* CD is !bit 1 on the 68901 GPIP port */
-		return (1 << 1) & ~(_mfpregs->gpip);
+		if (machine == machine_unknown)
+		{
+			/* unknown hardware, assume CD always on. */
+			return 1;
+		}
+		else
+		{
+			/* CD is !bit 1 on the 68901 GPIP port */
+			return (1 << 1) & ~(_mfpregs->gpip);
+		}
 	}
 	else if (b->tty == &sccb_tty)
 	{
@@ -672,8 +680,16 @@
 	{
 		/* modem1 */
 
-		/* break is bit 3 in the 68901 RSR */
-		return (1 << 3) & _mfpregs->rsr;
+		if (machine == machine_unknown)
+		{
+			/* unknown hardware, cannot detect breaks... */
+			return 0;
+		}
+		else
+		{
+			/* break is bit 3 in the 68901 RSR */
+			return (1 << 3) & _mfpregs->rsr;
+		}
 	}
 	else if (b->tty == &sccb_tty)
 	{
diff -aurN -x CVS -x .compile_030 -x .deps -x genmagic -x magic.i -x mkbuild.exe freemint.orig/sys/time.c freemint/sys/time.c
--- freemint.orig/sys/time.c	2013-01-29 19:39:39.468750000 +0100
+++ freemint/sys/time.c	2016-06-13 18:42:04.093750000 +0200
@@ -35,6 +35,7 @@
  */
 
 # include "time.h"
+# include "global.h"
 
 # include "libkern/libkern.h"
 # include "mint/arch/mfp.h"
@@ -366,7 +367,12 @@
 void
 init_time (void)
 {
-	long value = _mfpregs->tbdr;
+	long value;
+
+	if (machine == machine_unknown)
+		value = 0;
+	else
+		value = _mfpregs->tbdr;
 
 # if 0
 	/* See, a piece of code is a function, not just a long integer */
@@ -453,7 +459,11 @@
 			 * to care to much about overflows.
 			 */
 
-	timerc = _mfpregs->tbdr;
+	if (machine == machine_unknown)
+		timerc = 0;
+	else
+		timerc = _mfpregs->tbdr;
+
 	current_ticks = *hz_200;
 
 	/* Make sure that the clock runs monotonic.  */
-------------- next part --------------
diff -aurN -x CVS -x .compile_030 -x .deps -x genmagic -x magic.i -x mkbuild.exe freemint.orig/sys/arch/init_mach.c freemint/sys/arch/init_mach.c
--- freemint.orig/sys/arch/init_mach.c	2016-03-08 20:40:21.843750000 +0100
+++ freemint/sys/arch/init_mach.c	2016-06-13 20:58:08.171875000 +0200
@@ -260,7 +260,7 @@
 
 	DEBUG (("detecting hardware ... "));
 	/* at the moment only detection of ST-ESCC */
-	if (mcpu < 40 && detect_hardware ())
+	if (machine != machine_unknown && mcpu < 40 && detect_hardware ())
 		boot_print ("ST-ESCC extension detected\r\n");
 	DEBUG (("ok!\r\n"));
 
-------------- next part --------------
diff -aurN -x CVS -x .compile_030 -x .deps -x genmagic -x magic.i -x mkbuild.exe freemint.orig/sys/arch/init_intr.c freemint/sys/arch/init_intr.c
--- freemint.orig/sys/arch/init_intr.c	2007-07-13 23:32:49.000000000 +0200
+++ freemint/sys/arch/init_intr.c	2016-06-13 20:57:10.296875000 +0200
@@ -95,23 +95,29 @@
 	oldkey = *syskey;
 
 # ifndef NO_AKP_KEYBOARD
+	/* Hook the keyboard interrupt to call ikbd_scan() on keyboard data */
+	if (machine == machine_milan || machine == machine_unknown)
 	{
-#ifndef MILAN
+		/* Assume that TOS >= 2.0. In this case, there is an undocumented
+		 * vector just before the KBDVEC structure. This vector is called
+		 * by the TOS ikbdsys routine to process keyboard-only data.
+		 * It is exactly what we need to hook. */
+		long *kbdvec = ((long *)syskey)-1;
+		new_xbra_install (&oldkeys, (long)kbdvec, newkeys);
+	}
+	else
+	{
+		/* We need to hook the ikbdsys vector. Our handler will have to deal
+		 * with ACIA registers, and to call the appropriate KBDVEC vectors
+		 * for keyboard, mouse, joystick, status and time packets. */
 		savesr = splhigh();
 		syskey->ikbdsys = (long)ikbdsys_handler;
 #ifndef M68000
 		cpush(&syskey->ikbdsys, sizeof(long));
 #endif
+		/* Also hook the whole ACIA interrupt (why??) */
 		new_xbra_install(&old_acia, 0x0118L, new_acia);
 		spl(savesr);
-#else
-		long *syskey_aux;
-
-		syskey_aux = (long *)syskey;
-		syskey_aux--;
-
-		new_xbra_install (&oldkeys, (long)syskey_aux, newkeys);
-#endif
 	}
 # endif
 	old_term = (long) TRAP_Setexc (0x102, -1UL);
@@ -228,16 +234,14 @@
 	*syskey = oldkey;	/* restore keyboard vectors */
 
 # ifndef NO_AKP_KEYBOARD
+	if (machine == machine_milan || machine == machine_unknown)
+	{
+		long *kbdvec = ((long *)syskey)-1;
+		*kbdvec = (long) oldkeys;
+	}
+	else
 	{
-#ifdef MILAN
-		long *syskey_aux;
-
-		syskey_aux = (long *)syskey;
-		syskey_aux--;
-		*syskey_aux = (long) oldkeys;
-#else
 		*((long *) 0x0118L) = old_acia;
-#endif
 	}
 # endif
 
diff -aurN -x CVS -x .compile_030 -x .deps -x genmagic -x magic.i -x mkbuild.exe freemint.orig/sys/arch/intr.S freemint/sys/arch/intr.S
--- freemint.orig/sys/arch/intr.S	2016-06-13 18:31:11.875000000 +0200
+++ freemint/sys/arch/intr.S	2016-06-13 20:59:07.062500000 +0200
@@ -595,11 +595,12 @@
 // keyboard scancode. The scancode byte is in d0, IOREC struct
 // pointer in a0.
 //
-// BUG: will not work on TOS < 2.0. The vector used is available
-//	since TOS 2.0.
+// Note: this vector has only been available since TOS 2.0.
+// For TOS 1.x compatible method, the ikbdsys vector must be hooked.
+// See _ikbdsys_handler and _new_acia for that alternate method.
+// In both cases, the goal is to call _ikbd_scan with keyboard bytes.
 
 #ifndef NO_AKP_KEYBOARD
-#ifdef MILAN
 	.globl	_newkeys
 	.globl	_oldkeys
 	.globl	_ikbd_scan
@@ -630,7 +631,6 @@
 	movem.l	(sp)+,d1-d2/a0-a2
 #endif
 	rts
-#endif
 
 // Calling the keyclick routines. This is a helper for keyboard driver.
 
diff -aurN -x CVS -x .compile_030 -x .deps -x genmagic -x magic.i -x mkbuild.exe freemint.orig/sys/arch/intr.h freemint/sys/arch/intr.h
--- freemint.orig/sys/arch/intr.h	2007-07-13 23:32:49.000000000 +0200
+++ freemint/sys/arch/intr.h	2016-06-13 20:58:39.468750000 +0200
@@ -43,10 +43,8 @@
 /* old ikbd vector */
 extern long old_ikbd;
 
-#ifdef MILAN
 /* old ikbd vector (other way) */
 extern long oldkeys;
-#endif
 
 /* BIOS disk vectors */
 extern long old_mediach, old_getbpb, old_rwabs;


More information about the Freemint-list mailing list