[Freemint-list] [PATCH] _5MS cookie (non-Atari 3/3)

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


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

And here is the last patch.

FreeMiNT needs to hook the 200 Hz system timer. On Atari hardware, that 
timer is implemented using the MFP Timer C, using the interrupt vector at 
address 0x114. However, on non-Atari hardware a different vector may be 
used. In that case, the _5MS cookie indicates the address of that vector. 
That _5MS cookie is set by EmuTOS starting with 20160606 snapshot.

Alan, please commit!

-- 5_5ms.patch --------------------

Use the _5MS cookie when available.
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 -x .compile_col -x .compile_v4e -x build.h -x cdef.h -x .compile_000 -x xconout2.xdd -x buildserial freemint/sys/cookie.h freemint.work/sys/cookie.h
--- freemint/sys/cookie.h	2016-03-08 20:39:05.187500000 +0100
+++ freemint.work/sys/cookie.h	2016-06-04 17:21:53.109375000 +0200
@@ -75,6 +75,7 @@
 # define COOKIE_FSEL	0x4653454CL
 # define COOKIE_HBFS	0x48424653L /* BoxKite File Selector */
 # define COOKIE_DMAC	0x444D4143L /* FireTOS DMA API */
+# define COOKIE__5MS	0x5f354d53L /* 200 Hz system timer alternate vector */
 
 /* Not that we want to support these below ... */
 # define COOKIE_STiK	0x5354694bL
diff -aurN -x CVS -x .compile_030 -x .deps -x genmagic -x magic.i -x mkbuild.exe -x .compile_col -x .compile_v4e -x build.h -x cdef.h -x .compile_000 -x xconout2.xdd -x buildserial freemint/sys/arch/init_intr.c freemint.work/sys/arch/init_intr.c
--- freemint/sys/arch/init_intr.c	2016-06-13 20:57:10.296875000 +0200
+++ freemint.work/sys/arch/init_intr.c	2016-06-04 17:52:44.984375000 +0200
@@ -27,6 +27,7 @@
 # include "arch/init_intr.h"
 
 # include "global.h"
+# include "cookie.h"
 
 /* magic number to show that we have captured the reset vector */
 # define RES_MAGIC	0x31415926L
@@ -39,6 +40,8 @@
 long old_resval;	/* old reset validation */
 long olddrvs;		/* BIOS drive map */
 
+static long *p5msvec; /* pointer to vector used by 200 Hz system timer */
+
 /* table of processor frame sizes in _words_ (not used on MC68000) */
 uchar framesizes[16] =
 {
@@ -161,7 +164,20 @@
 	}
 
 	new_xbra_install (&old_criticerr, 0x404L, new_criticerr);
-	new_xbra_install (&old_5ms, 0x114L, mint_5ms);
+
+	/* Hook the 200 Hz system timer. Our handler will do its job,
+	 * then call the previous handler. Every four interrupts, our handler will
+	 * push a fake additional exception stack frame, so when the previous
+	 * 200 Hz handler returns with RTE, it will actually call _mint_vbl
+	 * to mimic a 50 Hz VBL interrupt.
+	 *
+	 * On Atari hardware, the 200 Hz system timer is implemented with the MFP
+	 * Timer C. On non-Atari hardware supported by EmuTOS, the 200 Hz system
+	 * timer may be implemented differently. In that case, the _5MS cookie
+	 * indicates the address of the vector used by the 200 Hz system timer */
+	if (get_cookie(NULL, COOKIE__5MS, (ulong *)&p5msvec) != E_OK)
+		p5msvec = (long *)0x114L; /* Default to Timer C vector */
+	new_xbra_install (&old_5ms, (long)p5msvec, mint_5ms);
 
 #if 0	/* this should really not be necessary ... rincewind */
 	new_xbra_install (&old_resvec, 0x042aL, reset);
@@ -279,7 +295,7 @@
 	*((long *) 0x0b8L) = old_xbios;
 	*((long *) 0x408L) = old_term;
 	*((long *) 0x404L) = old_criticerr;
-	*((long *) 0x114L) = old_5ms;
+	*p5msvec = old_5ms;
 #if 0	//
 	*((long *) 0x426L) = old_resval;
 	*((long *) 0x42aL) = old_resvec;


More information about the Freemint-list mailing list