;PROJECT: SONIX MUSIC SYSTEM
;FILE: SX.ASM

;COPYRIGHT 1986 BY MARK RILEY

;4/4/86: CREATED!

 INCLUDE "I:MACROS.ASM"
 DEFINE SERIALDEBUG ;,DEBUG ;???
 INCLUDE "I:DEBUG.ASM"
 INCLUDE "I:GRAPHICS.ASM"
 DEFINE MEMORY,MEMDEBUG
 INCLUDE "I:DOS.ASM"
 INCLUDE "I:INTUITION.ASM"
 INCLUDE "I:WORKBENCH.ASM"
 INCLUDE "I:SYSTEM.ASM"

;*** SONIX BOOTSTRAP ***

MAIN
 BUGMSGCR <SONIX RUNNING...>

 MOVE.L TASK,A1
 MOVE.L TASK.NODE+NODE.NAME(A1),OLDTASKNAME
 MOVE.L #SXTASK,TASK.NODE+NODE.NAME(A1)
 MOVE.L #-1,PROC.WINDOWPTR(A1)

 MOVE.L WBMSG,D0
 BEQ.S 1$
 MOVE.L D0,A1
 TST.L SM.PROCESS(A1)
 BNE.S 1$
 SYSLIB REPLYMSG
 LEA WBMSG,A0
 CLR.L (A0)

1$
 MOVE.L #SXNAME,A0
 MOVE.L #MEMF_PUBLIC!MEMF_CHIP,D0
 JSR LOADCODE
 MOVE.L A0,SONIX
 BEQ ERROR

 MOVE.L SONIX,A0
 MOVE.L DOSBASE,A1
 MOVE.L GFXBASE,A2
 MOVE.L INTBASE,A3
 MOVE.L FILEINFOBLOCK,A4
 MOVE.L TASK,A5
 MOVE.L #JUMPTABLE,A6
 JSR (A0)

;D0.L <- RETURN CODE

QUIT
 MOVE.L D0,-(SP)

 MOVE.L SONIX,A0
 JSR RELEASE

 MOVE.L TASK,A1
 MOVE.L OLDTASKNAME,TASK.NODE+NODE.NAME(A1)

 MOVE.L (SP)+,D0
 RTS

ERROR
 MOVEQ #22,D0
 BRA.S QUIT

;*** JUMP TABLE ***

JUMPTABLE
 DC.L LOADCODE
 DC.L ALLOCATE
 DC.L RELEASE
 DC.L DOLINE
 DC.L DOHLINE
 DC.L DOVLINE
 DC.L DORECTFILL
 DC.L DOFRAME
 DC.L DOLONG
 DC.L DOWORD
 DC.L DOBYTE
 DC.L DOCHAR
 DC.L DOSTRING
 DC.L DOBUGMSG

 IFND _DEBUG

DOLONG
DOWORD
DOBYTE
DOCHAR
DOSTRING
 RTS

DOBUGMSG
 MOVE.L A0,-(SP)
 MOVE.L 4(SP),A0
1$
 TST.B (A0)+
 BNE.S 1$
 MOVE.L A0,4(SP)
 BTST #0,7(SP)
 BEQ.S 2$
 ADDQ.L #1,4(SP)
2$
 MOVE.L (SP)+,A0
 RTS

 ENDC

;*** DATA AREA ***

SONIX DC.L 0
OLDTASKNAME DC.L 0

SXTASK DC.B 'Sonix.task',0
SXNAME DC.B 'Miscellaneous/Sonix.code',0
 FIXPC

 THEEND

