honeylisp/ssc/iigs/bootstub.fnl

48 lines
1.4 KiB
Plaintext
Raw Normal View History

(import-macros {:sss ! : compile} :ssc.macros)
#(compile $1
(start-symbol boot)
2021-08-20 03:51:12 +00:00
(org 0x1000)
(require ssc.iigs.toolbox)
2021-08-20 03:51:12 +00:00
(require ssc.task)
(global word BootUserID)
(global long BootHandle-00)
(global long BootHandle-01)
(global long BootHandle-e0)
(global long BootHandle-e1)
(fn boot ()
(asm (clc) (xce) (rep 0x30)) ; disable emulation mode, 16-bit index registers
(save-dp-sp 0x0800)
2021-08-20 03:51:12 +00:00
(set-task-base 0x0800) ; space for 8 tasks
(save-6502-stack)
; http://www.1000bit.it/support/manuali/apple/technotes/pdos/tn.pdos.27.html
; When bootstrapping with no OS, we must reserve
(TLStartUp)
(LoadOneTool ToolsetMisc 0x0100)
(MTStartUp)
(set! BootUserID (GetNewID 0x1f00))
(LoadOneTool ToolsetMemoryManager 0x0100)
(set! BootHandle-00 (NewHandle 0xb800 BootUserID 0xb017 0x000800))
(set! BootHandle-01 (NewHandle 0xb800 BootUserID 0xb017 0x010800))
(set! BootHandle-e0 (NewHandle 0x4000 BootUserID 0xb017 0xe02000))
(set! BootHandle-e1 (NewHandle 0x8000 BootUserID 0xb017 0xe12000))
(asm (jsr [(or $2 :main)]))
(DisposeHandle BootHandle-e1)
(DisposeHandle BootHandle-e0)
(DisposeHandle BootHandle-01)
(DisposeHandle BootHandle-00)
(DeleteID BootUserID)
(MTShutDown)
2021-08-20 03:51:12 +00:00
(restore-6502-stack)
2021-08-20 03:51:12 +00:00
(restore-dp-sp)
(asm (sec) (xce)) ; re-enter emulation mode
))