;
; Startup code for cc65 (Plus/4 version)
-;
-; This must be the *first* file on the linker command line
;
.export _exit
.export brk_jmp
+ .export __STARTUP__ : absolute = 1 ; Mark as startup
- .import condes, initlib, donelib
- .import push0, callmain, zerobss
- .import __IRQFUNC_TABLE__, __IRQFUNC_COUNT__
+ .import callirq_y, initlib, donelib
+ .import callmain, zerobss
+ .import __INTERRUPTOR_COUNT__
.include "zeropage.inc"
.include "plus4.inc"
IRQInd = $500 ; JMP $0000 - used as indirect IRQ vector
; ------------------------------------------------------------------------
-; Place the startup code in a special segment to cope with the quirks of
-; plus/4 banking.
+; BASIC header with a SYS call
-.segment "STARTUP"
+.segment "EXEHDR"
.word Head ; Load address
Head: .word @Next
.word .version ; Line number
- .byte $9E,"4109" ; SYS 4109
+ .byte $9E ; SYS token
+ .byte <(((Start / 1000) .mod 10) + '0')
+ .byte <(((Start / 100) .mod 10) + '0')
+ .byte <(((Start / 10) .mod 10) + '0')
+ .byte <(((Start / 1) .mod 10) + '0')
.byte $00 ; End of BASIC line
@Next: .word 0 ; BASIC end marker
; ------------------------------------------------------------------------
-; Actual code
+; Startup code
+
+.segment "STARTUP"
+
+Start:
+
+; Save the zero page locations we need
sei ; No interrupts since we're banking out the ROM
sta ENABLE_RAM
ldx #zpspace-1
L1: lda sp,x
- sta zpsave,x ; save the zero page locations we need
+ sta zpsave,x
dex
bpl L1
sta ENABLE_ROM
cli
-; Close open files
-
- jsr $FFCC ; CLRCH
-
; Switch to second charset
lda #14
; usable RAM.
tsx
- stx spsave ; save system stk ptr
+ stx spsave ; save system stk ptr
lda #<$FD00
sta sp
jsr zerobss
-; Call module constructors
-
- jsr initlib
-
; Initialize irqcount, which means that from now own custom linked in IRQ
; handlers (via condes) will be called.
- lda #.lobyte(__IRQFUNC_COUNT__*2)
+ lda #.lobyte(__INTERRUPTOR_COUNT__*2)
sta irqcount
+; Call module constructors
+
+ jsr initlib
+
; Push arguments and call main()
jsr callmain
; Back from main (this is also the _exit entry). Run module destructors.
-_exit: pha ; Save the return code
- lda #0
- sta irqcount ; Disable custom IRQ handlers
+_exit: pha ; Save the return code
jsr donelib ; Run module destructors
-; Restore system stuff
+; Disable chained IRQ handlers
- ldx spsave
- txs
+ lda #0
+ sta irqcount ; Disable custom IRQ handlers
; Copy back the zero page stuff
pla
sta ST
+; Restore the stack pointer
+
+ ldx spsave
+ txs
+
; Enable the ROM, reset changed vectors and return to BASIC
sta ENABLE_ROM
bne dobreak
; It's an IRQ and RAM is enabled. If we have handlers, call them. We will use
-; a flag here instead of loading __IRQFUNC_COUNT__ directly, since the condes
-; function is not reentrant. The irqcount flag will be set/reset from the main
-; code, to avoid races.
+; a flag here instead of loading __INTERRUPTOR_COUNT__ directly, since the
+; condes function is not reentrant. The irqcount flag will be set/reset from
+; the main code, to avoid races.
ldy irqcount
beq @L1
- lda #<__IRQFUNC_TABLE__
- ldx #>__IRQFUNC_TABLE__
- jsr condes ; Call the IRQ functions
+ jsr callirq_y ; Call the IRQ functions
; Since the ROM handler will end with an RTI, we have to fake an IRQ return
; on stack, so we get control of the CPU after the ROM handler and can switch
pha
lda #<irq_ret
pha
- php ; Push faked IRQ frame on stack
- pha ; Push faked A register
- pha ; Push faked X register
- pha ; Push faked Y register
+ php ; Push faked IRQ frame on stack
+ pha ; Push faked A register
+ pha ; Push faked X register
+ pha ; Push faked Y register
sta ENABLE_ROM ; Switch to ROM
jmp (IRQVec) ; Jump indirect to kernal irq handler
; Data
.data
-zpsave: .res zpspace
; BRK handling
brk_jmp: jmp $0000
spsave: .res 1
-.bss
irqcount: .byte 0
+.segment "ZPSAVE"
+
+zpsave: .res zpspace
+
+