Added wrappers for the kernal functions

git-svn-id: svn://svn.cc65.org/cc65/trunk@1587 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2002-11-22 22:16:20 +00:00
parent df42c5943d
commit b7e7864fc5
28 changed files with 595 additions and 113 deletions

View File

@@ -7,61 +7,71 @@
.export _exit
.import initlib, donelib
.import push0, _main, zerobss
.import MEMTOP, RESTOR, BSOUT, CLRCH
.import __IRQFUNC_TABLE__, __IRQFUNC_COUNT__
.include "zeropage.inc"
.include "plus4.inc"
; ------------------------------------------------------------------------
; BASIC header with a SYS call
; Place the startup code in a special segment to cope with the quirks of
; plus/4 banking.
.code
.segment "STARTUP"
.org $0FFF
.word Head ; Load address
Head: .word @Next
.word 1000 ; Line number
.byte $9E,"4109" ; SYS 4109
.byte $00 ; End of BASIC line
@Next: .word 0 ; BASIC end marker
.reloc
; ------------------------------------------------------------------------
; Actual code
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
dex
bpl L1
sta ENABLE_ROM
cli
; Close open files
jsr CLRCH
jsr $FFCC ; CLRCH
; Switch to second charset
lda #14
jsr BSOUT
jsr $FFD2 ; BSOUT
; Setup the IRQ vector in the banked RAM and switch off the ROM
sei ; No ints, handler not yet in place
sta ENABLE_RAM
lda #<IRQ
sta $FFFE ; Install interrupt handler
lda #>IRQ
sta $FFFF
cli ; Allow interrupts
; Clear the BSS data
jsr zerobss
; Save system stuff and setup the stack
; Save system stuff and setup the stack. The stack starts at the top of the
; usable RAM.
tsx
stx spsave ; save system stk ptr
sec
jsr MEMTOP ; Get top memory
cpy #$80 ; We can only use the low 32K :-(
bcc MemOk
ldy #$80
ldx #$00
MemOk: stx sp
sty sp+1 ; set argument stack ptr
lda #<$FD00
sta sp
lda #>$FD00
sta sp+1
; Call module constructors
@@ -92,11 +102,41 @@ L2: lda zpsave,x
dex
bpl L2
; Reset changed vectors
; Enable the ROM, reset changed vectors and return to BASIC
jmp RESTOR
sta ENABLE_ROM
jmp $FF8A ; RESTOR
; ------------------------------------------------------------------------
; IRQ handler
.segment "LOWCODE"
IRQ: pha
txa
pha
tsx ; Get the stack pointer
lda $0103,x ; Get the saved status register
tax
lda #>irqret ; Push new return address
pha
lda #<irqret
pha
txa
pha
sta ENABLE_ROM ; Switch to ROM
jmp ($FFFE) ; Jump to kernal irq handler
irqret: sta ENABLE_RAM ; Switch back to RAM
pla
tax
pla
rti
; ------------------------------------------------------------------------
; Data
.data
zpsave: .res zpspace