1+ #include "task_cst.h"
2+
13.section .text .keepboot
24
35*-------------------------------------------------------
1719
1820_Start_Of_Rom:
1921_Vecteurs_68K:
20- dc.l 0x00000000 /* Stack address */
22+ dc.l __stack /* Stack address */
2123 dc.l _Entry_Point /* Program start address */
2224 dc.l _Bus_Error
2325 dc.l _Address_Error
@@ -32,18 +34,22 @@ _Vecteurs_68K:
3234 dc.l _Error_Exception, _Error_Exception, _Error_Exception, _Error_Exception
3335 dc.l _Error_Exception, _Error_Exception, _Error_Exception, _Error_Exception
3436 dc.l _Error_Exception, _Error_Exception, _Error_Exception, _Error_Exception
35- dc.l _Error_Exception, _INT, _EXTINT, _INT
36- dc.l _HINT
37+ dc.l _Error_Exception
38+ dc.l _INT
39+ dc.l _EXTINT
40+ dc.l _INT
41+ dc.l hintCaller
3742 dc.l _INT
3843 dc.l _VINT
3944 dc.l _INT
40- dc.l _INT,_INT,_INT,_INT,_INT,_INT,_INT,_INT
45+ dc.l _trap_0 /* Resume supervisor task */
46+ dc.l _INT,_INT,_INT,_INT,_INT,_INT,_INT
4147 dc.l _INT,_INT,_INT,_INT,_INT,_INT,_INT,_INT
4248 dc.l _INT,_INT,_INT,_INT,_INT,_INT,_INT,_INT
4349 dc.l _INT,_INT,_INT,_INT,_INT,_INT,_INT,_INT
4450
4551rom_header:
46- .incbin "out/rom_head.bin" , 0x10 , 0x100
52+ .incbin "out/rom_head.bin" , 0 , 0x100
4753
4854_Entry_Point:
4955 move #0x2700,%sr
@@ -66,10 +72,13 @@ SkipJoyDetect:
6672* Sega Security Code (SEGA)
6773 move.l #0x53454741,0x2f00(%a1 )
6874WrongVersion:
75+ * Read from the control port to cancel any pending read/write command
6976 move.w (%a4 ),%d0
70- moveq #0x00,%d0
71- movea.l %d0 ,%a6
72- move %a6 ,%usp
77+
78+ * Configure a USER_STACK_LENGTH bytes user stack at bottom, and system stack on top of it
79+ move %sp , %usp
80+ sub #USER_STACK_LENGTH, %sp
81+
7382 move.w %d7 ,(%a1 )
7483 move.w %d7 ,(%a2 )
7584
@@ -226,36 +235,60 @@ _EXTINT:
226235 movem .l (%sp )+,%d0 -%d1 /%a0 -%a1
227236 rte
228237
229- _HINT:
230- movem .l %d0 -%d1 /%a0 -%a1 ,-(%sp )
231- move.l hintCB, %a0
232- jsr (%a0 )
233- movem .l (%sp )+,%d0 -%d1 /%a0 -%a1
234- rte
235-
236238_VINT:
239+ btst #5 , (%sp ) /* Skip context switch if not in user task */
240+ bne.s no_user_task
241+
242+ tst .w task_lock
243+ bne.s 1f
244+ move.w #0 , -(%sp ) /* TSK_superPend() will return 0 */
245+ bra.s unlock /* If lock == 0, supervisor task is not locked */
246+
247+ 1 :
248+ bcs.s no_user_task /* If lock < 0, super is locked with infinite wait */
249+ subq.w #1 , task_lock /* Locked with wait, subtract 1 to the frame count */
250+ bne.s no_user_task /* And do not unlock if we did not reach 0 */
251+ move.w #1 , -(%sp ) /* TSK_superPend() will return 1 */
252+
253+ unlock:
254+ /* Save bg task registers (excepting a7, that is stored in usp) */
255+ move.l %a0 , task_regs
256+ lea (task_regs + UTSK_REGS_LEN), %a0
257+ movem .l %d0 -%d7 /%a1 -%a6 , -(%a0 )
258+
259+ move.w (%sp )+, %d0 /* Load return value previously pushed to stack */
260+
261+ move.w (%sp )+, task_sr /* Pop user task sr and pc, and save them, */
262+ move.l (%sp )+, task_pc /* so they can be restored later. */
263+ movem .l (%sp )+, %d2 -%d7 /%a2 -%a6 /* Restore non clobberable registers */
264+
265+ no_user_task:
266+ /* At this point, we always have in the stack the SR and PC of the task */
267+ /* we want to jump after processing the interrupt, that might be the */
268+ /* point where we came from (if there is no context switch) or the */
269+ /* supervisor task (if we unlocked it). */
270+
237271 movem .l %d0 -%d1 /%a0 -%a1 ,-(%sp )
238272 ori.w #0x0001, intTrace /* in V-Int */
239273 addq.l #1 , vtimer /* increment frame counter (more a vint counter) */
240274 btst #3 , VBlankProcess+1 /* PROCESS_XGM_TASK ? (use VBlankProcess+1 as btst is a byte operation) */
241- beq.s _no_xgm_task
275+ beq.s no_xgm_task
242276
243277 jsr XGM_doVBlankProcess /* do XGM vblank task */
244278
245- _no_xgm_task :
279+ no_xgm_task :
246280 btst #1 , VBlankProcess+1 /* PROCESS_BITMAP_TASK ? (use VBlankProcess+1 as btst is a byte operation) */
247- beq.s _no_bmp_task
281+ beq.s no_bmp_task
248282
249283 jsr BMP_doVBlankProcess /* do BMP vblank task */
250284
251- _no_bmp_task :
285+ no_bmp_task :
252286 move.l vintCB, %a0 /* load user callback */
253287 jsr (%a0 ) /* call user callback */
254288 andi.w #0xFFFE, intTrace /* out V-Int */
255289 movem .l (%sp )+,%d0 -%d1 /%a0 -%a1
256290 rte
257291
258-
259292*------------------------------------------------
260293*
261294* Copyright (c) 1988 by Sozobon, Limited. Author: Johann Ruegg
0 commit comments