1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-05 21:29:03 +00:00

Merge pull request #131 from greg-king5/refine-crt

Made the crt0.s source files comments be consistent with each other.
This commit is contained in:
Oliver Schmidt 2014-08-24 21:31:35 +02:00
commit 76283e1b45
15 changed files with 340 additions and 339 deletions

View File

@ -24,76 +24,76 @@
ldx #$FF ldx #$FF
txs ; Init stack pointer txs ; Init stack pointer
; Switch in LC bank 2 for W/O ; Switch in LC bank 2 for W/O.
bit $C081 bit $C081
bit $C081 bit $C081
; Set source start address ; Set the source start address.
lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__) lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__)
ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__) ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__)
sta $9B sta $9B
sty $9C sty $9C
; Set source last address ; Set the source last address.
lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__) lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__)
ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__) ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__)
sta $96 sta $96
sty $97 sty $97
; Set destination last address ; Set the destination last address.
lda #<__LC_LAST__ lda #<__LC_LAST__
ldy #>__LC_LAST__ ldy #>__LC_LAST__
sta $94 sta $94
sty $95 sty $95
; Call into Applesoft Block Transfer Utility - which handles zero ; Call into the Applesoft Block Transfer Utility -- which handles zero-
; sized blocks well - to move content of the LC memory area ; sized blocks well -- to move the content of the LC memory area.
jsr $D396 ; BLTU + 3 jsr $D396 ; BLTU + 3
; Set source start address ; Set the source start address.
lda #<__ZPSAVE_RUN__ lda #<__ZPSAVE_RUN__
ldy #>__ZPSAVE_RUN__ ldy #>__ZPSAVE_RUN__
sta $9B sta $9B
sty $9C sty $9C
; Set source last address ; Set the source last address.
lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__) lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__)
ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__) ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__)
sta $96 sta $96
sty $97 sty $97
; Set destination last address ; Set the destination last address.
lda #<(__INIT_RUN__ + __INIT_SIZE__) lda #<(__INIT_RUN__ + __INIT_SIZE__)
ldy #>(__INIT_RUN__ + __INIT_SIZE__) ldy #>(__INIT_RUN__ + __INIT_SIZE__)
sta $94 sta $94
sty $95 sty $95
; Call into Applesoft Block Transfer Utility - which handles moving ; Call into the Applesoft Block Transfer Utility -- which handles moving
; overlapping blocks upwards well - to move the INIT segment ; overlapping blocks upwards well -- to move the INIT segment.
jsr $D396 ; BLTU + 3 jsr $D396 ; BLTU + 3
; Delegate all further processing to keep the STARTUP segment small ; Delegate all further processing, to keep the STARTUP segment small.
jsr init jsr init
; Avoid re-entrance of donelib. This is also the _exit entry ; Avoid a re-entrance of donelib. This is also the exit() entry.
_exit: ldx #<exit _exit: ldx #<exit
lda #>exit lda #>exit
jsr reset ; Setup RESET vector jsr reset ; Setup RESET vector
; Switch in ROM in case it wasn't already switched in by a RESET ; Switch in ROM, in case it wasn't already switched in by a RESET.
bit $C082 bit $C082
; Call module destructors ; Call the module destructors.
jsr donelib jsr donelib
; Restore the original RESET vector ; Restore the original RESET vector.
exit: ldx #$02 exit: ldx #$02
: lda rvsave,x : lda rvsave,x
sta SOFTEV,x sta SOFTEV,x
dex dex
bpl :- bpl :-
; Copy back the zero page stuff ; Copy back the zero-page stuff.
ldx #zpspace-1 ldx #zpspace-1
: lda zpsave,x : lda zpsave,x
sta sp,x sta sp,x
@ -111,17 +111,17 @@ exit: ldx #$02
.segment "INIT" .segment "INIT"
; Save the zero page locations we need ; Save the zero-page locations that we need.
init: ldx #zpspace-1 init: ldx #zpspace-1
: lda sp,x : lda sp,x
sta zpsave,x sta zpsave,x
dex dex
bpl :- bpl :-
; Clear the BSS data ; Clear the BSS data.
jsr zerobss jsr zerobss
; Save the original RESET vector ; Save the original RESET vector.
ldx #$02 ldx #$02
: lda SOFTEV,x : lda SOFTEV,x
sta rvsave,x sta rvsave,x
@ -135,58 +135,58 @@ init: ldx #zpspace-1
lda #>_exit lda #>_exit
jsr reset ; Setup RESET vector jsr reset ; Setup RESET vector
; Check for ProDOS ; Check for ProDOS.
ldy $BF00 ; MLI call entry point ldy $BF00 ; MLI call entry point
cpy #$4C ; Is MLI present? (JMP opcode) cpy #$4C ; Is MLI present? (JMP opcode)
bne basic bne basic
; Check ProDOS system bit map ; Check the ProDOS system bit map.
lda $BF6F ; Protection for pages $B8 - $BF lda $BF6F ; Protection for pages $B8 - $BF
cmp #%00000001 ; Exactly system global page is protected cmp #%00000001 ; Exactly system global page is protected
bne basic bne basic
; No BASIC.SYSTEM so quit to ProDOS dispatcher instead ; No BASIC.SYSTEM; so, quit to the ProDOS dispatcher instead.
lda #<quit lda #<quit
ldx #>quit ldx #>quit
sta done+1 sta done+1
stx done+2 stx done+2
; No BASIC.SYSTEM so use addr of ProDOS system global page ; No BASIC.SYSTEM; so, use the addr of the ProDOS system global page.
lda #<$BF00 lda #<$BF00
ldx #>$BF00 ldx #>$BF00
bne :+ ; Branch always bne :+ ; Branch always
; Get highest available mem addr from BASIC interpreter ; Get the highest available mem addr from the BASIC interpreter.
basic: lda HIMEM basic: lda HIMEM
ldx HIMEM+1 ldx HIMEM+1
; Setup the C stack ; Set up the C stack.
: sta sp : sta sp
stx sp+1 stx sp+1
; Enable interrupts as old ProDOS versions (i.e. 1.1.1) ; Enable interrupts, as old ProDOS versions (i.e. 1.1.1)
; jump to SYS and BIN programs with interrupts disabled ; jump to SYS and BIN programs with interrupts disabled.
cli cli
; Call module constructors ; Call the module constructors.
jsr initlib jsr initlib
; Switch in LC bank 2 for R/O ; Switch in LC bank 2 for R/O.
bit $C080 bit $C080
; Push arguments and call main() ; Push the command-line arguments; and, call main().
jmp callmain jmp callmain
.code .code
; Setup RESET vector ; Set up the RESET vector.
reset: stx SOFTEV reset: stx SOFTEV
sta SOFTEV+1 sta SOFTEV+1
eor #$A5 eor #$A5
sta PWREDUP sta PWREDUP
return: rts return: rts
; Quit to ProDOS dispatcher ; Quit to the ProDOS dispatcher.
quit: jsr $BF00 ; MLI call entry point quit: jsr $BF00 ; MLI call entry point
.byte $65 ; Quit .byte $65 ; Quit
.word q_param .word q_param

View File

@ -32,8 +32,8 @@
.segment "STARTUP" .segment "STARTUP"
rts ; fix for SpartaDOS / OS/A+ rts ; fix for SpartaDOS / OS/A+
; they first call the entry point from AUTOSTRT and ; They first call the entry point from AUTOSTRT; and
; then the load addess (this rts here). ; then, the load address (this rts here).
; We point AUTOSTRT directly after the rts. ; We point AUTOSTRT directly after the rts.
; Real entry point: ; Real entry point:
@ -44,11 +44,11 @@ start:
jsr sram_init jsr sram_init
.endif .endif
; Clear the BSS data ; Clear the BSS data.
jsr zerobss jsr zerobss
; Setup the stack ; Set up the stack.
tsx tsx
stx SP_save stx SP_save
@ -62,7 +62,7 @@ start:
.else .else
; Report memory usage ; Report the memory usage.
lda APPMHI lda APPMHI
sta APPMHI_save ; remember old APPMHI value sta APPMHI_save ; remember old APPMHI value
@ -73,60 +73,60 @@ start:
lda MEMTOP lda MEMTOP
sbc #<__RESERVED_MEMORY__ sbc #<__RESERVED_MEMORY__
sta APPMHI ; initialize our APPMHI value sta APPMHI ; initialize our APPMHI value
sta sp ; setup runtime stack part 1 sta sp ; set up runtime stack part 1
lda MEMTOP+1 lda MEMTOP+1
sbc #>__RESERVED_MEMORY__ sbc #>__RESERVED_MEMORY__
sta APPMHI+1 sta APPMHI+1
sta sp+1 ; setup runtime stack part 2 sta sp+1 ; set up runtime stack part 2
.endif .endif
; Call module constructors ; Call the module constructors.
jsr initlib jsr initlib
; Set left margin to 0 ; Set the left margin to 0.
lda LMARGN lda LMARGN
sta LMARGN_save sta LMARGN_save
ldy #0 ldy #0
sty LMARGN sty LMARGN
; Set keyb to upper/lowercase mode ; Set the keyboard to upper-/lower-case mode.
ldx SHFLOK ldx SHFLOK
stx SHFLOK_save stx SHFLOK_save
sty SHFLOK sty SHFLOK
; Initialize conio stuff ; Initialize the conio stuff.
dey ; Set Y to $FF dey ; Set Y to $FF
sty CH ; remove keypress which might be in the input buffer sty CH ; remove keypress which might be in the input buffer
; Push arguments and call main ; Push the command-line arguments; and, call main().
jsr callmain jsr callmain
; Call module destructors. This is also the _exit entry. ; Call the module destructors. This is also the exit() entry.
_exit: jsr donelib ; Run module destructors _exit: jsr donelib ; Run module destructors
; Restore system stuff ; Restore the system stuff.
ldx SP_save ldx SP_save
txs ; Restore stack pointer txs ; Restore stack pointer
; Restore left margin ; Restore the left margin.
lda LMARGN_save lda LMARGN_save
sta LMARGN sta LMARGN
; Restore kb mode ; Restore the kb mode.
lda SHFLOK_save lda SHFLOK_save
sta SHFLOK sta SHFLOK
; Restore APPMHI ; Restore APPMHI.
lda APPMHI_save lda APPMHI_save
sta APPMHI sta APPMHI
@ -147,8 +147,8 @@ _exit: jsr donelib ; Run module destructors
sta MEMTOP+1 sta MEMTOP+1
; Issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) in ; Issue a GRAPHICS 0 call (copied'n'pasted from the TGI drivers), in
; order to restore screen memory to its defailt location just ; order to restore screen memory to its default location just
; before the ROM. ; before the ROM.
jsr findfreeiocb jsr findfreeiocb
@ -169,7 +169,7 @@ _exit: jsr donelib ; Run module destructors
lda #0 lda #0
sta ICBLH,x sta ICBLH,x
jsr CIOV_org jsr CIOV_org
; No error checking here, shouldn't happen(tm), and no way to ; No error checking here, shouldn't happen(TM); and, no way to
; recover anyway. ; recover anyway.
lda #CLOSE lda #CLOSE
@ -178,12 +178,12 @@ _exit: jsr donelib ; Run module destructors
.endif .endif
; Turn on cursor ; Turn on the cursor.
ldx #0 ldx #0
stx CRSINH stx CRSINH
; Back to DOS ; Back to DOS.
rts rts

View File

@ -17,29 +17,29 @@
start: start:
; Clear the BSS data ; Clear the BSS data.
jsr zerobss jsr zerobss
; initialize data ; Initialize the data.
jsr copydata jsr copydata
; setup the stack ; Set up the stack.
lda #<(__RAM_START__ + __RAM_SIZE__ - __RESERVED_MEMORY__) lda #<(__RAM_START__ + __RAM_SIZE__ - __RESERVED_MEMORY__)
sta sp sta sp
lda #>(__RAM_START__ + __RAM_SIZE__ - __RESERVED_MEMORY__) lda #>(__RAM_START__ + __RAM_SIZE__ - __RESERVED_MEMORY__)
sta sp+1 ; Set argument stack ptr sta sp+1 ; Set argument stack ptr
; Call module constructors ; Call the module constructors.
jsr initlib jsr initlib
; Push arguments and call main() ; Push the command-line arguments; and, call main().
jsr callmain jsr callmain
; Call module destructors. This is also the _exit entry. ; Call the module destructors. This is also the exit() entry.
_exit: jsr donelib ; Run module destructors _exit: jsr donelib ; Run module destructors

View File

@ -22,21 +22,21 @@
Start: Start:
; Switch to the second charset ; Switch to the second charset.
lda #14 lda #14
jsr BSOUT jsr BSOUT
; Before doing anything else, we have to setup our banking configuration. ; Before doing anything else, we have to set up our banking configuration.
; Otherwise just the lowest 16K are actually RAM. Writing through the ROM ; Otherwise, just the lowest 16K are actually RAM. Writing through the ROM
; to the underlying RAM works, but it is bad style. ; to the underlying RAM works; but, it is bad style.
lda MMU_CR ; Get current memory configuration... lda MMU_CR ; Get current memory configuration...
pha ; ...and save it for later pha ; ...and save it for later
lda #MMU_CFG_CC65 ; Bank0 with kernal ROM lda #MMU_CFG_CC65 ; Bank0 with Kernal ROM
sta MMU_CR sta MMU_CR
; Save the zero page locations we need ; Save the zero-page locations that we need.
ldx #zpspace-1 ldx #zpspace-1
L1: lda sp,x L1: lda sp,x
@ -44,11 +44,11 @@ L1: lda sp,x
dex dex
bpl L1 bpl L1
; Clear the BSS data ; Clear the BSS data.
jsr zerobss jsr zerobss
; Save system stuff and setup the stack ; Save some system stuff; and, set up the stack.
pla ; Get MMU setting pla ; Get MMU setting
sta mmusave sta mmusave
@ -61,27 +61,27 @@ L1: lda sp,x
lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
sta sp+1 ; Set argument stack ptr sta sp+1 ; Set argument stack ptr
; Call module constructors ; Call the module constructors.
jsr initlib jsr initlib
; Set the bank for the file name to our execution bank. We must do this, ; Set the bank for the file name to our execution bank. We must do this
; *after* calling constructors, because some of them may depend on the ; *after* calling the constructors because some of them might depend on
; original value of this register. ; the original value of this register.
lda #0 lda #0
sta FNAM_BANK sta FNAM_BANK
; Push arguments and call main() ; Push the command-line arguments; and, call main().
jsr callmain jsr callmain
; Back from main (this is also the _exit entry). Run module destructors ; Back from main() [this is also the exit() entry]. Run the module destructors.
_exit: pha ; Save the return code on stack _exit: pha ; Save the return code on stack
jsr donelib jsr donelib
; Copy back the zero page stuff ; Copy back the zero-page stuff.
ldx #zpspace-1 ldx #zpspace-1
L2: lda zpsave,x L2: lda zpsave,x
@ -89,19 +89,19 @@ L2: lda zpsave,x
dex dex
bpl L2 bpl L2
; Place the program return code into ST ; Place the program return code into BASIC's status variable.
pla pla
sta ST sta ST
; Reset the stack and the memory configuration ; Reset the stack and the memory configuration.
ldx spsave ldx spsave
txs txs
ldx mmusave ldx mmusave
stx MMU_CR stx MMU_CR
; Done, return to BASIC ; Done, return to BASIC.
rts rts

View File

@ -1,8 +1,8 @@
; ;
; Startup code for cc65 (C16 version) ; Startup code for cc65 (C16 version)
; ;
; Note: The C16 is actually the Plus/4 with just 16KB of memory. So many ; Note: The C16 is actually the Plus/4 with just 16KB of memory. So, many
; things are similar here, and we even use the plus4.inc include file. ; things are similar here; and, we even use the plus4.inc include file.
; ;
.export _exit .export _exit
@ -22,7 +22,7 @@
Start: Start:
; Save the zero page locations we need ; Save the zero-page locations that we need.
ldx #zpspace-1 ldx #zpspace-1
L1: lda sp,x L1: lda sp,x
@ -30,16 +30,16 @@ L1: lda sp,x
dex dex
bpl L1 bpl L1
; Switch to second charset ; Switch to the second charset.
lda #14 lda #14
jsr BSOUT jsr BSOUT
; Clear the BSS data ; Clear the BSS data.
jsr zerobss jsr zerobss
; Save system stuff and setup the stack ; Save some system stuff; and, set up the stack.
tsx tsx
stx spsave ; save system stk ptr stx spsave ; save system stk ptr
@ -53,20 +53,20 @@ L1: lda sp,x
MemOk: stx sp MemOk: stx sp
sty sp+1 ; set argument stack ptr sty sp+1 ; set argument stack ptr
; Call module constructors ; Call the module constructors.
jsr initlib jsr initlib
; Push arguments and call main() ; Push the command-line arguments; and, call main().
jsr callmain jsr callmain
; Call module destructors. This is also the _exit entry. ; Call the module destructors. This is also the exit() entry.
_exit: pha ; Save the return code on stack _exit: pha ; Save the return code on stack
jsr donelib ; Run module destructors jsr donelib ; Run module destructors
; Copy back the zero page stuff ; Copy back the zero-page stuff.
ldx #zpspace-1 ldx #zpspace-1
L2: lda zpsave,x L2: lda zpsave,x
@ -74,17 +74,17 @@ L2: lda zpsave,x
dex dex
bpl L2 bpl L2
; Store the return code into ST ; Store the return code into BASIC's status variable.
pla pla
sta ST sta ST
; Restore the stack pointer ; Restore the stack pointer.
ldx spsave ldx spsave
txs txs
; Back to BASIC ; Back to BASIC.
rts rts

View File

@ -23,7 +23,7 @@
Start: Start:
; Save the zero page locations we need ; Save the zero-page locations that we need.
ldx #zpspace-1 ldx #zpspace-1
L1: lda sp,x L1: lda sp,x
@ -31,24 +31,24 @@ L1: lda sp,x
dex dex
bpl L1 bpl L1
; Switch to second charset ; Switch to the second charset.
lda #14 lda #14
jsr BSOUT jsr BSOUT
; Switch off the BASIC ROM ; Switch off the BASIC ROM.
lda $01 lda $01
pha ; Remember the value pha ; Remember the value
and #$F8 and #$F8
ora #$06 ; Enable kernal+I/O, disable basic ora #$06 ; Enable Kernal+I/O, disable BASIC
sta $01 sta $01
; Clear the BSS data ; Clear the BSS data.
jsr zerobss jsr zerobss
; Save system settings and setup the stack ; Save some system settings; and, set up the stack.
pla pla
sta mmusave ; Save the memory configuration sta mmusave ; Save the memory configuration
@ -61,20 +61,20 @@ L1: lda sp,x
lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
sta sp+1 ; Set argument stack ptr sta sp+1 ; Set argument stack ptr
; Call module constructors ; Call the module constructors.
jsr initlib jsr initlib
; Push arguments and call main ; Push the command-line arguments; and, call main().
jsr callmain jsr callmain
; Back from main (This is also the _exit entry). Run module destructors ; Back from main() [this is also the exit() entry]. Run the module destructors.
_exit: pha ; Save the return code on stack _exit: pha ; Save the return code on stack
jsr donelib jsr donelib
; Copy back the zero page stuff ; Copy back the zero-page stuff.
ldx #zpspace-1 ldx #zpspace-1
L2: lda zpsave,x L2: lda zpsave,x
@ -82,19 +82,19 @@ L2: lda zpsave,x
dex dex
bpl L2 bpl L2
; Place the program return code into ST ; Place the program return code into BASIC's status variable.
pla pla
sta ST sta ST
; Restore system stuff ; Restore the system stuff.
ldx spsave ldx spsave
txs ; Restore stack pointer txs ; Restore stack pointer
ldx mmusave ldx mmusave
stx $01 ; Restore memory configuration stx $01 ; Restore memory configuration
; Back to basic ; Back to BASIC.
rts rts

View File

@ -18,14 +18,14 @@
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; BASIC header and a small BASIC program. Since it is not possible to start ; The BASIC header and a small BASIC program. Since it isn't possible to start
; programs in other banks using SYS, the BASIC program will write a small ; programs in other banks using SYS, the BASIC program will write a small
; machine code program into memory at $100 and start that machine code ; machine code program into memory at $100; and, start that machine code
; program. The machine code program will then start the machine language ; program. The machine code program will then start the machine language
; code in bank 0, which will initialize the system by copying stuff from ; code in bank 0, which will initialize the system by copying stuff from
; the system bank, and start the application. ; the system bank, and start the application.
; ;
; Here's the basic program that's in the following lines: ; Here's the BASIC program that's in the following lines:
; ;
; 10 for i=0 to 4 ; 10 for i=0 to 4
; 20 read j ; 20 read j
@ -40,9 +40,9 @@
; lda #$00 ; lda #$00
; sta $00 <-- Switch to bank 0 after this command ; sta $00 <-- Switch to bank 0 after this command
; ;
; Initialization is not only complex because of the jumping from one bank ; Initialization is complex not only because of the jumping from one bank
; into another. but also because we want to save memory, and because of ; into another, but also because we want to save memory; and because of
; this, we will use the system memory ($00-$3FF) for initialization stuff ; that, we will use the system memory ($00-$3FF) for initialization stuff
; that is overwritten later. ; that is overwritten later.
; ;
@ -55,13 +55,15 @@
.byte $30,$2c,$31,$36,$39,$2c,$30,$2c,$31,$33,$33,$2c,$30,$00,$00,$00 .byte $30,$2c,$31,$36,$39,$2c,$30,$2c,$31,$33,$33,$2c,$30,$00,$00,$00
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; A table that contains values that must be transfered from the system zero ; A table that contains values that must be transferred from the system zero-
; page into our zero page. Contains pairs of bytes; first one is the address ; page into our zero-page. Contains pairs of bytes; first one is the address
; in the system ZP, second one is our ZP address. The table goes into page 2, ; in the system ZP, second one is our ZP address. The table goes into page 2;
; but is declared here because it is needed earlier. ; but, is declared here because it is needed earlier.
.SEGMENT "PAGE2" .SEGMENT "PAGE2"
; (We use .proc because we need both a label and a scope.)
.proc transfer_table .proc transfer_table
.byte $9F, DEVNUM .byte $9F, DEVNUM
@ -78,7 +80,7 @@
; Page 3 data. This page contains the break vector and the bankswitch ; Page 3 data. This page contains the break vector and the bankswitch
; subroutine that is copied into high memory on startup. The space occupied by ; subroutine that is copied into high memory on startup. The space occupied by
; this routine will later be used for a copy of the bank 15 stack. It must be ; this routine will later be used for a copy of the bank 15 stack. It must be
; saved, since we're going to destroy it when calling bank 15. ; saved since we're going to destroy it when calling bank 15.
.segment "PAGE3" .segment "PAGE3"
@ -92,7 +94,7 @@ BRKVec: .addr _exit ; BRK indirect vector
entry: php entry: php
pha pha
lda #$0F ; Bank 15 lda #$0F ; Bank 15
sta IndReg sta IndReg
txa txa
pha pha
@ -115,7 +117,7 @@ entry: php
tya tya
sec sec
sbc #7 sbc #7
sta $1FF ; Save new sp sta $1FF ; Save new sp
tay tay
tsx tsx
@ -143,7 +145,7 @@ entry: php
iny iny
sta (sysp1),y sta (sysp1),y
ldy $1FF ; Restore sp in bank 15 ldy $1FF ; Restore sp in bank 15
lda #.hibyte(expull-1) lda #.hibyte(expull-1)
sta (sysp1),y sta (sysp1),y
@ -170,7 +172,7 @@ expull: pla
rts rts
.if (expull <> $FF26) .if (expull <> $FF26)
.error "Symbol expull must be aligned with kernal in bank 15" .error "Symbol expull must be aligned with Kernal in bank 15"
.endif .endif
.reloc .reloc
@ -180,15 +182,15 @@ expull: pla
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; The code in the target bank when switching back will be put at the bottom ; The code in the target bank when switching back will be put at the bottom
; of the stack. We will jump here to switch segments. The range $F2..$FF is ; of the stack. We will jump here to switch segments. The range $F2..$FF is
; not used by any kernal routine. ; not used by any Kernal routine.
.segment "STARTUP" .segment "STARTUP"
Back: sta ExecReg Back: sta ExecReg
; We are at $100 now. The following snippet is a copy of the code that is poked ; We are at $100 now. The following snippet is a copy of the code that is poked
; in the system bank memory by the basic header program, it's only for ; in the system bank memory by the BASIC header program; it's only for
; documentation and not actually used here: ; documentation, and not actually used here:
sei sei
lda #$00 lda #$00
@ -196,23 +198,23 @@ Back: sta ExecReg
; This is the actual starting point of our code after switching banks for ; This is the actual starting point of our code after switching banks for
; startup. Beware: The following code will get overwritten as soon as we ; startup. Beware: The following code will get overwritten as soon as we
; use the stack (since it's in page 1)! We jump to another location, since ; use the stack (since it's in page 1)! We jump to another location since
; we need some space for subroutines that aren't used later. ; we need some space for subroutines that aren't used later.
jmp Origin jmp Origin
; Hardware vectors, copied to $FFFA ; Hardware vectors, copied to $FFF6
.proc vectors .proc vectors
sta ExecReg sta ExecReg
rts rts
nop nop
.word nmi ; NMI vector .word nmi ; NMI vector
.word 0 ; Reset - not used .word 0 ; Reset -- not used
.word irq ; IRQ vector .word irq ; IRQ vector
.endproc .endproc
; Initializers for the extended zeropage. See extzp.s ; Initializers for the extended zero-page. See "extzp.s".
.proc extzp .proc extzp
.word $0100 ; sysp1 .word $0100 ; sysp1
@ -230,12 +232,12 @@ Back: sta ExecReg
.word $ebd1 ; ktab4 .word $ebd1 ; ktab4
.endproc .endproc
; Switch the indirect segment to the system bank ; Switch the indirect segment to the system bank.
Origin: lda #$0F Origin: lda #$0F
sta IndReg sta IndReg
; Initialize the extended zeropage ; Initialize the extended zero-page.
ldx #.sizeof(extzp)-1 ldx #.sizeof(extzp)-1
L1: lda extzp,x L1: lda extzp,x
@ -243,16 +245,16 @@ L1: lda extzp,x
dex dex
bpl L1 bpl L1
; Save the old stack pointer from the system bank and setup our hw sp ; Save the old stack pointer from the system bank; and, set up our hw sp.
tsx tsx
txa txa
ldy #$FF ldy #$FF
sta (sysp1),y ; Save system stack point into $F:$1FF sta (sysp1),y ; Save system stack point into $F:$1FF
ldx #$FE ; Leave $1FF untouched for cross bank calls ldx #$FE ; Leave $1FF untouched for cross-bank calls
txs ; Set up our own stack txs ; Set up our own stack
; Copy stuff from the system zeropage to ours ; Copy stuff from the system zero-page to ours.
lda #.sizeof(transfer_table) lda #.sizeof(transfer_table)
sta ktmp sta ktmp
@ -266,7 +268,7 @@ L2: ldx ktmp
dec ktmp dec ktmp
bne L2 bne L2
; Set the interrupt, NMI and other vectors ; Set the interrupt, NMI, and other vectors.
ldx #.sizeof(vectors)-1 ldx #.sizeof(vectors)-1
L3: lda vectors,x L3: lda vectors,x
@ -274,14 +276,14 @@ L3: lda vectors,x
dex dex
bpl L3 bpl L3
; Setup the C stack ; Set up the C stack.
lda #.lobyte(callbank15::entry) lda #.lobyte(callbank15::entry)
sta sp sta sp
lda #.hibyte(callbank15::entry) lda #.hibyte(callbank15::entry)
sta sp+1 sta sp+1
; Setup the subroutine and jump vector table that redirects kernal calls to ; Set up the subroutine and jump vector table that redirects Kernal calls to
; the system bank. ; the system bank.
ldy #.sizeof(callbank15) ldy #.sizeof(callbank15)
@ -290,10 +292,10 @@ L3: lda vectors,x
dey dey
bne @L1 bne @L1
; Setup the jump vector table. Y is zero on entry. ; Set up the jump vector table. Y is zero on entry.
ldx #45-1 ; Number of vectors ldx #45-1 ; Number of vectors
@L2: lda #$20 ; JSR opcode @L2: lda #$20 ; JSR opcode
sta $FF6F,y sta $FF6F,y
iny iny
lda #.lobyte(callbank15::entry) lda #.lobyte(callbank15::entry)
@ -305,13 +307,13 @@ L3: lda vectors,x
dex dex
bpl @L2 bpl @L2
; Set the indirect segment to bank we're executing in ; Set the indirect segment to the bank that we're executing in.
lda ExecReg lda ExecReg
sta IndReg sta IndReg
; Zero the BSS segment. We will do that here instead calling the routine ; Zero the BSS segment. We will do that here instead of calling the routine
; in the common library, since we have the memory anyway, and this way, ; in the common library, since we have the memory anyway; and this way,
; it's reused later. ; it's reused later.
lda #<__BSS_RUN__ lda #<__BSS_RUN__
@ -321,18 +323,18 @@ L3: lda vectors,x
lda #0 lda #0
tay tay
; Clear full pages ; Clear full pages.
ldx #>__BSS_SIZE__ ldx #>__BSS_SIZE__
beq Z2 beq Z2
Z1: sta (ptr1),y Z1: sta (ptr1),y
iny iny
bne Z1 bne Z1
inc ptr1+1 ; Next page inc ptr1+1 ; Next page
dex dex
bne Z1 bne Z1
; Clear the remaining page ; Clear the remaining page.
Z2: ldx #<__BSS_SIZE__ Z2: ldx #<__BSS_SIZE__
beq Z4 beq Z4
@ -343,12 +345,12 @@ Z3: sta (ptr1),y
Z4: jmp Init Z4: jmp Init
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; We are at $200 now. We may now start calling subroutines safely, since ; We are at $200 now. We may now start calling subroutines safely since
; the code we execute is no longer in the stack page. ; the code we execute is no longer in the stack page.
.segment "PAGE2" .segment "PAGE2"
; Copy the character rom from the system bank into the execution bank ; Copy the character ROM from the system bank into the execution bank.
Init: lda #<$C000 Init: lda #<$C000
sta ptr1 sta ptr1
@ -362,7 +364,7 @@ Init: lda #<$C000
sta tmp1 sta tmp1
ldy #$00 ldy #$00
ccopy: lda #$0F ccopy: lda #$0F
sta IndReg ; Access the system bank sta IndReg ; Access the system bank
ccopy1: lda (ptr1),y ccopy1: lda (ptr1),y
sta __VIDRAM_START__,y sta __VIDRAM_START__,y
iny iny
@ -374,22 +376,22 @@ ccopy2: lda __VIDRAM_START__,y
iny iny
bne ccopy2 bne ccopy2
inc ptr1+1 inc ptr1+1
inc ptr2+1 ; Bump high pointer bytes inc ptr2+1 ; Bump high pointer bytes
dec tmp1 dec tmp1
bne ccopy bne ccopy
; Clear the video memory. We will do this before switching the video to bank 0 ; Clear the video memory. We will do this before switching the video to bank 0,
; to avoid garbage when doing so. ; to avoid garbage when doing so.
jsr _clrscr jsr _clrscr
; Reprogram the VIC so that the text screen and the character ROM is in the ; Reprogram the VIC so that the text screen and the character ROM are in the
; execution bank. This is done in three steps: ; execution bank. This is done in three steps:
lda #$0F ; We need access to the system bank lda #$0F ; We need access to the system bank
sta IndReg sta IndReg
; Place the VIC video RAM into bank 0 ; Place the VIC video RAM into bank 0.
; CA (STATVID) = 0 ; CA (STATVID) = 0
; CB (VICDOTSEL) = 0 ; CB (VICDOTSEL) = 0
@ -400,7 +402,7 @@ ccopy2: lda __VIDRAM_START__,y
ora #%10100000 ora #%10100000
sta (tpi1),y sta (tpi1),y
; Set bit 14/15 of the VIC address range to the high bits of __VIDRAM_START__ ; Set bit 14/15 of the VIC address range to the high bits of __VIDRAM_START__.
; PC6/PC7 (VICBANKSEL 0/1) = 11 ; PC6/PC7 (VICBANKSEL 0/1) = 11
ldy #TPI::PRC ldy #TPI::PRC
@ -422,12 +424,12 @@ ccopy2: lda __VIDRAM_START__,y
; ora #<(((>__VIDRAM_START__) << 2) & $F0) ; ora #<(((>__VIDRAM_START__) << 2) & $F0)
sta (vic),y sta (vic),y
; Switch back to the execution bank ; Switch back to the execution bank.
lda ExecReg lda ExecReg
sta IndReg sta IndReg
; Activate chained interrupt handlers, then enable interrupts. ; Activate the chained interrupt handlers; then, enable interrupts.
lda #.lobyte(__INTERRUPTOR_COUNT__*2) lda #.lobyte(__INTERRUPTOR_COUNT__*2)
sta irqcount sta irqcount
@ -437,11 +439,11 @@ ccopy2: lda __VIDRAM_START__,y
jsr initlib jsr initlib
; Push arguments and call main() ; Push the command-line arguments; and, call main().
jsr callmain jsr callmain
; Call module destructors. This is also the _exit entry and the default entry ; Call the module destructors. This is also the exit() entry and the default entry
; point for the break vector. ; point for the break vector.
_exit: pha ; Save the return code on stack _exit: pha ; Save the return code on stack
@ -449,12 +451,12 @@ _exit: pha ; Save the return code on stack
lda #$00 lda #$00
sta irqcount ; Disable custom irq handlers sta irqcount ; Disable custom irq handlers
; Address the system bank ; Address the system bank.
lda #$0F lda #$0F
sta IndReg sta IndReg
; Switch back the video to the system bank ; Switch back the video to the system bank.
ldy #TPI::CR ldy #TPI::CR
lda vidsave+0 lda vidsave+0
@ -468,7 +470,7 @@ _exit: pha ; Save the return code on stack
lda vidsave+2 lda vidsave+2
sta (vic),y sta (vic),y
; Copy stuff back from our zeropage to the systems ; Copy stuff back from our zero-page to the system's.
.if 0 .if 0
lda #.sizeof(transfer_table) lda #.sizeof(transfer_table)
@ -484,13 +486,13 @@ _exit: pha ; Save the return code on stack
bne @L0 bne @L0
.endif .endif
; Place the program return code into ST ; Place the program return code into BASIC's status variable.
pla pla
ldy #$9C ; ST ldy #$9C ; ST
sta (sysp0),y sta (sysp0),y
; Setup the welcome code at the stack bottom in the system bank. ; Set up the welcome code at the stack bottom in the system bank.
ldy #$FF ldy #$FF
lda (sysp1),y ; Load system bank sp lda (sysp1),y ; Load system bank sp
@ -511,14 +513,14 @@ _exit: pha ; Save the return code on stack
; easier chaining, we do handle the IRQs in the execution bank (instead of ; easier chaining, we do handle the IRQs in the execution bank (instead of
; passing them to the system bank). ; passing them to the system bank).
; This is the mapping of the active irq register of the 6525 (tpi1): ; This is the mapping of the active IRQ register of the 6525 (tpi1):
; ;
; Bit 7 6 5 4 3 2 1 0 ; Bit 7 6 5 4 3 2 1 0
; | | | | ^ 50 Hz ; | | | | ^ 50 Hz.
; | | | ^ SRQ IEEE 488 ; | | | ^ SRQ IEEE 488
; | | ^ cia ; | | ^ CIA
; | ^ IRQB ext. Port ; | ^ IRQB ext. Port
; ^ acia ; ^ ACIA
irq: pha irq: pha
txa txa
@ -528,41 +530,41 @@ irq: pha
lda IndReg lda IndReg
pha pha
lda ExecReg lda ExecReg
sta IndReg ; Be sure to address our segment sta IndReg ; Be sure to address our segment
tsx tsx
lda $105,x ; Get the flags from the stack lda $105,x ; Get the flags from the stack
and #$10 ; Test break flag and #$10 ; Test break flag
bne dobrk bne dobrk
; It's an IRQ ; It's an IRQ.
cld cld
; Call chained IRQ handlers ; Call the chained IRQ handlers.
ldy irqcount ldy irqcount
beq irqskip beq irqskip
jsr callirq_y ; Call the functions jsr callirq_y ; Call the functions
; Done with chained IRQ handlers, check the TPI for IRQs and handle them ; Done with the chained IRQ handlers; check the TPI for IRQs, and handle them.
irqskip:lda #$0F irqskip:lda #$0F
sta IndReg sta IndReg
ldy #TPI::AIR ldy #TPI::AIR
lda (tpi1),y ; Interrupt Register 6525 lda (tpi1),y ; Interrupt Register 6525
beq noirq beq noirq
; 50/60Hz interrupt ; 50/60Hz. interrupt
cmp #%00000001 ; ticker irq? cmp #%00000001 ; ticker IRQ?
bne irqend bne irqend
jsr scnkey ; Poll the keyboard jsr scnkey ; Poll the keyboard
jsr UDTIM ; Bump the time jsr UDTIM ; Bump the time
; Done ; Done.
irqend: ldy #TPI::AIR irqend: ldy #TPI::AIR
sta (tpi1),y ; Clear interrupt sta (tpi1),y ; Clear interrupt
noirq: pla noirq: pla
sta IndReg sta IndReg
@ -583,5 +585,3 @@ vidsave:.res 3
.bss .bss
irqcount: .byte 0 irqcount: .byte 0

View File

@ -17,14 +17,14 @@
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; BASIC header and a small BASIC program. Since it is not possible to start ; The BASIC header and a small BASIC program. Since it isn't possible to start
; programs in other banks using SYS, the BASIC program will write a small ; programs in other banks using SYS, the BASIC program will write a small
; machine code program into memory at $100 and start that machine code ; machine code program into memory at $100; and, start that machine code
; program. The machine code program will then start the machine language ; program. The machine code program will then start the machine language
; code in bank 1, which will initialize the system by copying stuff from ; code in bank 1, which will initialize the system by copying stuff from
; the system bank, and start the application. ; the system bank, and start the application.
; ;
; Here's the basic program that's in the following lines: ; Here's the BASIC program that's in the following lines:
; ;
; 10 for i=0 to 4 ; 10 for i=0 to 4
; 20 read j ; 20 read j
@ -39,9 +39,9 @@
; lda #$01 ; lda #$01
; sta $00 <-- Switch to bank 1 after this command ; sta $00 <-- Switch to bank 1 after this command
; ;
; Initialization is not only complex because of the jumping from one bank ; Initialization is complex not only because of the jumping from one bank
; into another. but also because we want to save memory, and because of ; into another. but also because we want to save memory; and because of
; this, we will use the system memory ($00-$3FF) for initialization stuff ; that, we will use the system memory ($00-$3FF) for initialization stuff
; that is overwritten later. ; that is overwritten later.
; ;
@ -54,13 +54,15 @@
.byte $30,$2c,$31,$36,$39,$2c,$31,$2c,$31,$33,$33,$2c,$30,$00,$00,$00 .byte $30,$2c,$31,$36,$39,$2c,$31,$2c,$31,$33,$33,$2c,$30,$00,$00,$00
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; A table that contains values that must be transfered from the system zero ; A table that contains values that must be transferred from the system zero-
; page into out zero page. Contains pairs of bytes, first one is the address ; page into our zero-page. Contains pairs of bytes, first one is the address
; in the system ZP, second one is our ZP address. The table goes into page 2, ; in the system ZP, second one is our ZP address. The table goes into page 2;
; but is declared here, because it is needed earlier. ; but, is declared here because it is needed earlier.
.SEGMENT "PAGE2" .SEGMENT "PAGE2"
; (We use .proc because we need both a label and a scope.)
.proc transfer_table .proc transfer_table
.byte $9F, DEVNUM .byte $9F, DEVNUM
@ -76,7 +78,7 @@
; Page 3 data. This page contains the break vector and the bankswitch ; Page 3 data. This page contains the break vector and the bankswitch
; subroutine that is copied into high memory on startup. The space occupied by ; subroutine that is copied into high memory on startup. The space occupied by
; this routine will later be used for a copy of the bank 15 stack. It must be ; this routine will later be used for a copy of the bank 15 stack. It must be
; saved, since we're going to destroy it when calling bank 15. ; saved since we're going to destroy it when calling bank 15.
.segment "PAGE3" .segment "PAGE3"
@ -84,13 +86,13 @@ BRKVec: .addr _exit ; BRK indirect vector
.proc callbank15 .proc callbank15
excrts := $FF05 ; In bank 15 rom excrts := $FF05 ; In bank 15 ROM
.org $FECB .org $FECB
entry: php entry: php
pha pha
lda #$0F ; Bank 15 lda #$0F ; Bank 15
sta IndReg sta IndReg
txa txa
pha pha
@ -113,7 +115,7 @@ entry: php
tya tya
sec sec
sbc #7 sbc #7
sta $1FF ; Save new sp sta $1FF ; Save new sp
tay tay
tsx tsx
@ -141,7 +143,7 @@ entry: php
iny iny
sta (sysp1),y sta (sysp1),y
ldy $1FF ; Restore sp in bank 15 ldy $1FF ; Restore sp in bank 15
lda #.hibyte(expull-1) lda #.hibyte(expull-1)
sta (sysp1),y sta (sysp1),y
@ -168,7 +170,7 @@ expull: pla
rts rts
.if (expull <> $FF2E) .if (expull <> $FF2E)
.error "Symbol expull must be aligned with kernal in bank 15" .error "Symbol expull must be aligned with Kernal in bank 15"
.endif .endif
.reloc .reloc
@ -178,15 +180,15 @@ expull: pla
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; The code in the target bank when switching back will be put at the bottom ; The code in the target bank when switching back will be put at the bottom
; of the stack. We will jump here to switch segments. The range $F2..$FF is ; of the stack. We will jump here to switch segments. The range $F2..$FF is
; not used by any kernal routine. ; not used by any Kernal routine.
.segment "STARTUP" .segment "STARTUP"
Back: sta ExecReg Back: sta ExecReg
; We are at $100 now. The following snippet is a copy of the code that is poked ; We are at $100 now. The following snippet is a copy of the code that is poked
; in the system bank memory by the basic header program, it's only for ; in the system bank memory by the BASIC header program; it's only for
; documentation and not actually used here: ; documentation, and not actually used here:
sei sei
lda #$01 lda #$01
@ -194,7 +196,7 @@ Back: sta ExecReg
; This is the actual starting point of our code after switching banks for ; This is the actual starting point of our code after switching banks for
; startup. Beware: The following code will get overwritten as soon as we ; startup. Beware: The following code will get overwritten as soon as we
; use the stack (since it's in page 1)! We jump to another location, since ; use the stack (since it's in page 1)! We jump to another location since
; we need some space for subroutines that aren't used later. ; we need some space for subroutines that aren't used later.
jmp Origin jmp Origin
@ -206,11 +208,11 @@ Back: sta ExecReg
rts rts
nop nop
.word nmi ; NMI vector .word nmi ; NMI vector
.word 0 ; Reset - not used .word 0 ; Reset -- not used
.word irq ; IRQ vector .word irq ; IRQ vector
.endproc .endproc
; Initializers for the extended zeropage. See extzp.s ; Initializers for the extended zero-page. See "extzp.s".
.proc extzp .proc extzp
.word $0100 ; sysp1 .word $0100 ; sysp1
@ -228,12 +230,12 @@ Back: sta ExecReg
.word $eb49 ; ktab4 .word $eb49 ; ktab4
.endproc .endproc
; Switch the indirect segment to the system bank ; Switch the indirect segment to the system bank.
Origin: lda #$0F Origin: lda #$0F
sta IndReg sta IndReg
; Initialize the extended zeropage ; Initialize the extended zero-page.
ldx #.sizeof(extzp)-1 ldx #.sizeof(extzp)-1
L1: lda extzp,x L1: lda extzp,x
@ -241,16 +243,16 @@ L1: lda extzp,x
dex dex
bpl L1 bpl L1
; Save the old stack pointer from the system bank and setup our hw sp ; Save the old stack pointer from the system bank; and, set up our hw sp.
tsx tsx
txa txa
ldy #$FF ldy #$FF
sta (sysp1),y ; Save system stack point into $F:$1FF sta (sysp1),y ; Save system stack point into $F:$1FF
ldx #$FE ; Leave $1FF untouched for cross bank calls ldx #$FE ; Leave $1FF untouched for cross-bank calls
txs ; Set up our own stack txs ; Set up our own stack
; Copy stuff from the system zeropage to ours ; Copy stuff from the system zero-page to ours.
lda #.sizeof(transfer_table) lda #.sizeof(transfer_table)
sta ktmp sta ktmp
@ -264,7 +266,7 @@ L2: ldx ktmp
dec ktmp dec ktmp
bne L2 bne L2
; Set the interrupt, NMI and other vectors ; Set the interrupt, NMI, and other vectors.
ldx #.sizeof(vectors)-1 ldx #.sizeof(vectors)-1
L3: lda vectors,x L3: lda vectors,x
@ -272,14 +274,14 @@ L3: lda vectors,x
dex dex
bpl L3 bpl L3
; Setup the C stack ; Set up the C stack.
lda #.lobyte(callbank15::entry) lda #.lobyte(callbank15::entry)
sta sp sta sp
lda #.hibyte(callbank15::entry) lda #.hibyte(callbank15::entry)
sta sp+1 sta sp+1
; Setup the subroutine and jump vector table that redirects kernal calls to ; Set up the subroutine and jump vector table that redirects Kernal calls to
; the system bank. ; the system bank.
ldy #.sizeof(callbank15) ldy #.sizeof(callbank15)
@ -288,10 +290,10 @@ L3: lda vectors,x
dey dey
bne @L1 bne @L1
; Setup the jump vector table. Y is zero on entry. ; Set up the jump vector table. Y is zero on entry.
ldx #45-1 ; Number of vectors ldx #45-1 ; Number of vectors
@L2: lda #$20 ; JSR opcode @L2: lda #$20 ; JSR opcode
sta $FF6F,y sta $FF6F,y
iny iny
lda #.lobyte(callbank15::entry) lda #.lobyte(callbank15::entry)
@ -303,13 +305,13 @@ L3: lda vectors,x
dex dex
bpl @L2 bpl @L2
; Set the indirect segment to bank we're executing in ; Set the indirect segment to the bank that we're executing in.
lda ExecReg lda ExecReg
sta IndReg sta IndReg
; Zero the BSS segment. We will do that here instead calling the routine ; Zero the BSS segment. We will do that here instead of calling the routine
; in the common library, since we have the memory anyway, and this way, ; in the common library, since we have the memory anyway; and this way,
; it's reused later. ; it's reused later.
lda #<__BSS_RUN__ lda #<__BSS_RUN__
@ -319,18 +321,18 @@ L3: lda vectors,x
lda #0 lda #0
tay tay
; Clear full pages ; Clear full pages.
ldx #>__BSS_SIZE__ ldx #>__BSS_SIZE__
beq Z2 beq Z2
Z1: sta (ptr1),y Z1: sta (ptr1),y
iny iny
bne Z1 bne Z1
inc ptr1+1 ; Next page inc ptr1+1 ; Next page
dex dex
bne Z1 bne Z1
; Clear the remaining page ; Clear the remaining page.
Z2: ldx #<__BSS_SIZE__ Z2: ldx #<__BSS_SIZE__
beq Z4 beq Z4
@ -341,12 +343,12 @@ Z3: sta (ptr1),y
Z4: jmp Init Z4: jmp Init
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; We are at $200 now. We may now start calling subroutines safely, since ; We are at $200 now. We may now start calling subroutines safely since
; the code we execute is no longer in the stack page. ; the code we execute is no longer in the stack page.
.segment "PAGE2" .segment "PAGE2"
; Activate chained interrupt handlers, then enable interrupts. ; Activate the chained interrupt handlers; then, enable interrupts.
Init: lda #.lobyte(__INTERRUPTOR_COUNT__*2) Init: lda #.lobyte(__INTERRUPTOR_COUNT__*2)
sta irqcount sta irqcount
@ -356,11 +358,11 @@ Init: lda #.lobyte(__INTERRUPTOR_COUNT__*2)
jsr initlib jsr initlib
; Push arguments and call main() ; Push the command-line arguments; and, call main().
jsr callmain jsr callmain
; Call module destructors. This is also the _exit entry and the default entry ; Call the module destructors. This is also the exit() entry and the default entry
; point for the break vector. ; point for the break vector.
_exit: pha ; Save the return code _exit: pha ; Save the return code
@ -368,12 +370,12 @@ _exit: pha ; Save the return code
lda #$00 lda #$00
sta irqcount ; Disable custom irq handlers sta irqcount ; Disable custom irq handlers
; Address the system bank ; Address the system bank.
lda #$0F lda #$0F
sta IndReg sta IndReg
; Copy stuff back from our zeropage to the systems ; Copy stuff back from our zero-page to the system's.
.if 0 .if 0
lda #.sizeof(transfer_table) lda #.sizeof(transfer_table)
@ -389,13 +391,13 @@ _exit: pha ; Save the return code
bne @L0 bne @L0
.endif .endif
; Place the program return code into ST ; Place the program return code into BASIC's status variable.
pla pla
ldy #$9C ; ST ldy #$9C ; ST
sta (sysp0),y sta (sysp0),y
; Setup the welcome code at the stack bottom in the system bank. ; Set up the welcome code at the stack bottom in the system bank.
ldy #$FF ldy #$FF
lda (sysp1),y ; Load system bank sp lda (sysp1),y ; Load system bank sp
@ -416,14 +418,14 @@ _exit: pha ; Save the return code
; easier chaining, we do handle the IRQs in the execution bank (instead of ; easier chaining, we do handle the IRQs in the execution bank (instead of
; passing them to the system bank). ; passing them to the system bank).
; This is the mapping of the active irq register of the 6525 (tpi1): ; This is the mapping of the active IRQ register of the 6525 (tpi1):
; ;
; Bit 7 6 5 4 3 2 1 0 ; Bit 7 6 5 4 3 2 1 0
; | | | | ^ 50 Hz ; | | | | ^ 50 Hz.
; | | | ^ SRQ IEEE 488 ; | | | ^ SRQ IEEE 488
; | | ^ cia ; | | ^ CIA
; | ^ IRQB ext. Port ; | ^ IRQB ext. Port
; ^ acia ; ^ ACIA
irq: pha irq: pha
txa txa
@ -433,41 +435,41 @@ irq: pha
lda IndReg lda IndReg
pha pha
lda ExecReg lda ExecReg
sta IndReg ; Be sure to address our segment sta IndReg ; Be sure to address our segment
tsx tsx
lda $105,x ; Get the flags from the stack lda $105,x ; Get the flags from the stack
and #$10 ; Test break flag and #$10 ; Test break flag
bne dobrk bne dobrk
; It's an IRQ ; It's an IRQ.
cld cld
; Call chained IRQ handlers ; Call the chained IRQ handlers.
ldy irqcount ldy irqcount
beq irqskip beq irqskip
jsr callirq_y ; Call the functions jsr callirq_y ; Call the functions
; Done with chained IRQ handlers, check the TPI for IRQs and handle them ; Done with the chained IRQ handlers; check the TPI for IRQs, and handle them.
irqskip:lda #$0F irqskip:lda #$0F
sta IndReg sta IndReg
ldy #TPI::AIR ldy #TPI::AIR
lda (tpi1),y ; Interrupt Register 6525 lda (tpi1),y ; Interrupt Register 6525
beq noirq beq noirq
; 50/60Hz interrupt ; 50/60Hz. interrupt
cmp #%00000001 ; ticker irq? cmp #%00000001 ; ticker IRQ?
bne irqend bne irqend
jsr scnkey ; Poll the keyboard jsr scnkey ; Poll the keyboard
jsr UDTIM ; Bump the time jsr UDTIM ; Bump the time
; Done ; Done.
irqend: ldy #TPI::AIR irqend: ldy #TPI::AIR
sta (tpi1),y ; Clear interrupt sta (tpi1),y ; Clear interrupt
noirq: pla noirq: pla
sta IndReg sta IndReg
@ -481,8 +483,7 @@ nmi: rti
dobrk: jmp (BRKVec) dobrk: jmp (BRKVec)
; ------------------------------------------------------------------------- ; -------------------------------------------------------------------------
; Data area. ; Data area
.bss .bss
irqcount: .byte 0 irqcount: .byte 0

View File

@ -1,5 +1,5 @@
; ;
; Startup code for geos ; Startup code for GEOS
; ;
; Maciej 'YTM/Elysium' Witkowiak ; Maciej 'YTM/Elysium' Witkowiak
; 26.10.99, 10.3.2000, 15.8.2001, 23.12.2002 ; 26.10.99, 10.3.2000, 15.8.2001, 23.12.2002
@ -23,9 +23,9 @@
.segment "STARTUP" .segment "STARTUP"
; GEOS 64/128 initializes the screen before starting an application while ; GEOS 64/128 initializes the screen before starting an application while
; Apple GEOS does not. In order to provide identical startup conditions ; Apple GEOS does not. In order to provide identical startup conditions,
; we initialize the screen here on Apple GEOS. For the same reason we set ; we initialize the screen here, on Apple GEOS. For the same reason, we set
; the pattern and dispBufferOn even on GEOS 64/128 although we don't use ; the pattern and dispBufferOn, even on GEOS 64/128, although we don't use
; them here. ; them here.
lda #2 ; Checkerboard pattern lda #2 ; Checkerboard pattern
@ -44,23 +44,23 @@
jsr zerobss jsr zerobss
; Setup stack. ; Set up the stack.
lda #<(__STACKADDR__ + __STACKSIZE__) lda #<(__STACKADDR__ + __STACKSIZE__)
ldx #>(__STACKADDR__ + __STACKSIZE__) ldx #>(__STACKADDR__ + __STACKSIZE__)
sta sp sta sp
stx sp+1 stx sp+1
; Call module constructors. ; Call the module constructors.
jsr initlib jsr initlib
; Push arguments and call main(). ; Push the command-line arguments; and, call main().
cli cli
jsr callmain jsr callmain
; Call module destructors. ; Call the module destructors.
_exit: jsr donelib _exit: jsr donelib

View File

@ -9,9 +9,9 @@
; ;
; *** ; ***
; ;
; Startup code for cc65 (Lynx version). Based on Atari 8-bit startup ; Startup code for cc65 (Lynx version). Based on the Atari 8-bit startup
; code structure. The C stack is located at the end of the RAM memory ; code structure. The C stack is located at the end of the RAM memory
; segment and grows downward. Bastian Schick's executable header is put ; segment, and grows downward. Bastian Schick's executable header is put
; on the front of the fully linked binary (see EXEHDR segment.) ; on the front of the fully linked binary (see EXEHDR segment.)
; ;
@ -44,19 +44,19 @@ MikeyInitData: .byte $9e,$18,$68,$1f,$00,$00,$00,$00,$00,$ff,$1a,$1b,$04,$0d,$2
.segment "STARTUP" .segment "STARTUP"
; set up system ; Set up the system.
sei sei
cld cld
ldx #$FF ldx #$FF
txs txs
; init bank switching ; Init the bank switching.
lda #$C lda #$C
sta MAPCTL ; $FFF9 sta MAPCTL ; $FFF9
; disable all timer interrupts ; Disable all timer interrupts.
lda #$80 lda #$80
trb TIM0CTLA trb TIM0CTLA
@ -67,24 +67,24 @@ MikeyInitData: .byte $9e,$18,$68,$1f,$00,$00,$00,$00,$00,$ff,$1a,$1b,$04,$0d,$2
trb TIM6CTLA trb TIM6CTLA
trb TIM7CTLA trb TIM7CTLA
; disable TX/RX IRQ, set to 8E1 ; Disable the TX/RX IRQ; set to 8E1.
lda #%11101 lda #%11101
sta SERCTL sta SERCTL
; clear all pending interrupts ; Clear all pending interrupts.
lda INTSET lda INTSET
sta INTRST sta INTRST
; setup the stack ; Set up the stack.
lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
sta sp sta sp
lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
sta sp+1 sta sp+1
; Init Mickey ; Init Mickey.
ldx #.sizeof(MikeyInitReg)-1 ldx #.sizeof(MikeyInitReg)-1
mloop: ldy MikeyInitReg,x mloop: ldy MikeyInitReg,x
@ -93,7 +93,7 @@ mloop: ldy MikeyInitReg,x
dex dex
bpl mloop bpl mloop
; these are RAM-shadows of read only regs ; These are RAM-shadows of read-only regs.
ldx #$1b ldx #$1b
stx __iodat stx __iodat
@ -102,7 +102,7 @@ mloop: ldy MikeyInitReg,x
ldx #$d ldx #$d
stx __viddma stx __viddma
; Init Suzy ; Init Suzy.
ldx #.sizeof(SuzyInitReg)-1 ldx #.sizeof(SuzyInitReg)-1
sloop: ldy SuzyInitReg,x sloop: ldy SuzyInitReg,x
@ -115,19 +115,19 @@ sloop: ldy SuzyInitReg,x
sta __sprsys sta __sprsys
cli cli
; Clear the BSS data ; Clear the BSS data.
jsr zerobss jsr zerobss
; Call module constructors ; Call the module constructors.
jsr initlib jsr initlib
; Push arguments and call main ; Push the command-line arguments; and, call main().
jsr callmain jsr callmain
; Call module destructors. This is also the _exit entry. ; Call the module destructors. This is also the exit() entry.
_exit: jsr donelib ; Run module destructors _exit: jsr donelib ; Run module destructors

View File

@ -70,7 +70,7 @@
start: start:
; setup the CPU and System-IRQ ; Set up the CPU and System-IRQ.
sei sei
cld cld
@ -90,40 +90,40 @@ start:
inx inx
bne @l bne @l
; Clear the BSS data ; Clear the BSS data.
jsr zerobss jsr zerobss
; initialize data ; Initialize the data.
jsr copydata jsr copydata
; setup the stack ; Set up the stack.
lda #<(__SRAM_START__ + __SRAM_SIZE__) lda #<(__SRAM_START__ + __SRAM_SIZE__)
sta sp sta sp
lda #>(__SRAM_START__ + __SRAM_SIZE__) lda #>(__SRAM_START__ + __SRAM_SIZE__)
sta sp+1 ; Set argument stack ptr sta sp+1 ; Set argument stack ptr
; Call module constructors ; Call the module constructors.
jsr initlib jsr initlib
; Push arguments and call main() ; Push the command-line arguments; and, call main().
jsr callmain jsr callmain
; Call module destructors. This is also the _exit entry. ; Call the module destructors. This is also the exit() entry.
_exit: jsr donelib ; Run module destructors _exit: jsr donelib ; Run module destructors
; Reset the NES ; Reset the NES.
jmp start jmp start
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; System V-Blank Interupt ; System V-Blank Interrupt
; updates PPU Memory (buffered) ; Updates PPU Memory (buffered).
; updates VBLANK_FLAG and tickcount ; Updates VBLANK_FLAG and tickcount.
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
nmi: pha nmi: pha
@ -141,13 +141,13 @@ nmi: pha
@s: jsr ppubuf_flush @s: jsr ppubuf_flush
; reset the video counter ; Reset the video counter.
lda #$20 lda #$20
sta PPU_VRAM_ADDR2 sta PPU_VRAM_ADDR2
lda #$00 lda #$00
sta PPU_VRAM_ADDR2 sta PPU_VRAM_ADDR2
; reset scrolling ; Reset scrolling.
sta PPU_VRAM_ADDR1 sta PPU_VRAM_ADDR1
sta PPU_VRAM_ADDR1 sta PPU_VRAM_ADDR1

View File

@ -21,7 +21,7 @@
Start: Start:
; Save the zero page locations we need ; Save the zero-page locations that we need.
ldx #zpspace-1 ldx #zpspace-1
L1: lda sp,x L1: lda sp,x
@ -29,9 +29,9 @@ L1: lda sp,x
dex dex
bpl L1 bpl L1
; Switch to second charset. The routine that is called by BSOUT to switch the ; Switch to the second charset. The routine that is called by BSOUT to switch the
; character set will use FNLEN as temporary storage - YUCK! Since the ; character set will use FNLEN as temporary storage -- YUCK! Since the
; initmainargs routine, which parses the command line for arguments needs this ; initmainargs routine, which parses the command line for arguments, needs that
; information, we need to save and restore it here. ; information, we need to save and restore it here.
; Thanks to Stefan Haubenthal for this information! ; Thanks to Stefan Haubenthal for this information!
@ -43,11 +43,11 @@ L1: lda sp,x
pla pla
sta FNLEN ; Restore FNLEN sta FNLEN ; Restore FNLEN
; Clear the BSS data ; Clear the BSS data.
jsr zerobss jsr zerobss
; Save system stuff and setup the stack ; Save some system stuff; and, set up the stack.
tsx tsx
stx spsave ; Save the system stack ptr stx spsave ; Save the system stack ptr
@ -57,20 +57,20 @@ L1: lda sp,x
lda MEMSIZE+1 lda MEMSIZE+1
sta sp+1 ; Set argument stack ptr sta sp+1 ; Set argument stack ptr
; Call module constructors ; Call the module constructors.
jsr initlib jsr initlib
; Push arguments and call main() ; Push the command-line arguments; and, call main().
jsr callmain jsr callmain
; Call module destructors. This is also the _exit entry. ; Call the module destructors. This is also the exit() entry.
_exit: pha ; Save the return code on stack _exit: pha ; Save the return code on stack
jsr donelib jsr donelib
; Copy back the zero page stuff ; Copy back the zero-page stuff.
ldx #zpspace-1 ldx #zpspace-1
L2: lda zpsave,x L2: lda zpsave,x
@ -78,17 +78,17 @@ L2: lda zpsave,x
dex dex
bpl L2 bpl L2
; Store the program return code into ST ; Store the program return code into BASIC's status variable.
pla pla
sta ST sta ST
; Restore the stack pointer ; Restore the stack pointer.
ldx spsave ldx spsave
txs ; Restore stack pointer txs ; Restore stack pointer
; Back to basic ; Back to BASIC.
rts rts

View File

@ -29,7 +29,7 @@ IRQInd = $500 ; JMP $0000 - used as indirect IRQ vector
Start: Start:
; Save the zero page locations we need ; Save the zero-page locations that we need.
sei ; No interrupts since we're banking out the ROM sei ; No interrupts since we're banking out the ROM
sta ENABLE_RAM sta ENABLE_RAM
@ -41,13 +41,13 @@ L1: lda sp,x
sta ENABLE_ROM sta ENABLE_ROM
cli cli
; Switch to second charset ; Switch to the second charset.
lda #14 lda #14
jsr $FFD2 ; BSOUT jsr $FFD2 ; BSOUT
; Save system stuff and setup the stack. The stack starts at the top of the ; Save some system stuff; and, set up the stack. The stack starts at the top
; usable RAM. ; of the usable RAM.
tsx tsx
stx spsave ; save system stk ptr stx spsave ; save system stk ptr
@ -57,7 +57,7 @@ L1: lda sp,x
lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
sta sp+1 sta sp+1
; Setup the IRQ vector in the banked RAM and switch off the ROM ; Set up the IRQ vector in the banked RAM; and, switch off the ROM.
ldx #<IRQ ldx #<IRQ
ldy #>IRQ ldy #>IRQ
@ -67,35 +67,35 @@ L1: lda sp,x
sty $FFFF sty $FFFF
cli ; Allow interrupts cli ; Allow interrupts
; Clear the BSS data ; Clear the BSS data.
jsr zerobss jsr zerobss
; Initialize irqcount, which means that from now own custom linked in IRQ ; Initialize irqcount, which means that, from now on, custom linked-in IRQ
; handlers (via condes) will be called. ; handlers will be called (via condes).
lda #.lobyte(__INTERRUPTOR_COUNT__*2) lda #.lobyte(__INTERRUPTOR_COUNT__*2)
sta irqcount sta irqcount
; Call module constructors ; Call the module constructors.
jsr initlib jsr initlib
; Push arguments and call main() ; Push the command-line arguments; and, call main().
jsr callmain jsr callmain
; Back from main (this is also the _exit entry). Run module destructors. ; Back from main() [this is also the exit() entry]. Run the module destructors.
_exit: pha ; Save the return code _exit: pha ; Save the return code
jsr donelib ; Run module destructors jsr donelib ; Run module destructors
; Disable chained IRQ handlers ; Disable the chained IRQ handlers.
lda #0 lda #0
sta irqcount ; Disable custom IRQ handlers sta irqcount ; Disable custom IRQ handlers
; Copy back the zero page stuff ; Copy back the zero-page stuff.
ldx #zpspace-1 ldx #zpspace-1
L2: lda zpsave,x L2: lda zpsave,x
@ -103,28 +103,28 @@ L2: lda zpsave,x
dex dex
bpl L2 bpl L2
; Place the program return code into ST ; Place the program return code into BASIC's status variable.
pla pla
sta ST sta ST
; Restore the stack pointer ; Restore the stack pointer.
ldx spsave ldx spsave
txs txs
; Enable the ROM and return to BASIC ; Enable the ROM; and, return to BASIC.
sta ENABLE_ROM sta ENABLE_ROM
rts rts
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; IRQ handler. The handler in the ROM enables the kernal and jumps to ; IRQ handler. The handler in the ROM enables the Kernal, and jumps to
; $CE00, where the ROM code checks for a BRK or IRQ and branches via the ; $CE00, where the ROM code checks for a BRK or IRQ, and branches via the
; indirect vectors at $314/$316. ; indirect vectors at $314/$316.
; To make our stub as fast as possible, we skip the whole part of the ROM ; To make our stub as fast as possible, we skip the whole part of the ROM
; handler and jump to the indirect vectors directly. We do also call our ; handler, and jump to the indirect vectors directly. We do also call our
; own interrupt handlers if we have any, so they need not use $314. ; own interrupt handlers if we have any; so, they need not use $314.
.segment "LOWCODE" .segment "LOWCODE"
@ -139,7 +139,7 @@ IRQ: cld ; Just to be sure
and #$10 ; Test for BRK bit and #$10 ; Test for BRK bit
bne dobreak bne dobreak
; It's an IRQ and RAM is enabled. If we have handlers, call them. We will use ; It's an IRQ; and, RAM is enabled. If we have handlers, call them. We will use
; a flag here instead of loading __INTERRUPTOR_COUNT__ directly, since the ; a flag here instead of loading __INTERRUPTOR_COUNT__ directly, since the
; condes function is not reentrant. The irqcount flag will be set/reset from ; condes function is not reentrant. The irqcount flag will be set/reset from
; the main code, to avoid races. ; the main code, to avoid races.
@ -149,8 +149,8 @@ IRQ: cld ; Just to be sure
jsr callirq_y ; 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 ; 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 ; on the stack, so that we get control of the CPU after the ROM handler,
; back to RAM. ; and can switch back to RAM.
@L1: lda #>irq_ret ; Push new return address @L1: lda #>irq_ret ; Push new return address
pha pha
@ -161,7 +161,7 @@ IRQ: cld ; Just to be sure
pha ; Push faked X register pha ; Push faked X register
pha ; Push faked Y register pha ; Push faked Y register
sta ENABLE_ROM ; Switch to ROM sta ENABLE_ROM ; Switch to ROM
jmp (IRQVec) ; Jump indirect to kernal irq handler jmp (IRQVec) ; Jump indirect to Kernal IRQ handler
irq_ret: irq_ret:
sta ENABLE_RAM ; Switch back to RAM sta ENABLE_RAM ; Switch back to RAM
@ -177,7 +177,7 @@ dobreak:
beq nohandler beq nohandler
jmp brk_jmp ; Jump to the handler jmp brk_jmp ; Jump to the handler
; No break handler installed, jump to ROM ; No break handler installed, jump to ROM.
nohandler: nohandler:
sta ENABLE_ROM sta ENABLE_ROM

View File

@ -28,7 +28,7 @@ _sv_nmi_counter: .byte 0
reset: reset:
jsr zerobss jsr zerobss
; initialize data ; Initialize data.
jsr copydata jsr copydata
lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
@ -63,12 +63,12 @@ not_dma:
rti rti
.endproc .endproc
; removing this segment gives only a warning ; Removing this segment gives only a warning.
.segment "FFF0" .segment "FFF0"
.proc reset32kcode .proc reset32kcode
lda #(6<<5) lda #(6<<5)
sta sv_bank sta sv_bank
; now the 32kbyte image can reside in the top of 64kbyte, 128kbyte roms ; Now, the 32Kbyte image can reside in the top of 64Kbyte and 128Kbyte ROMs.
jmp reset jmp reset
.endproc .endproc

View File

@ -22,7 +22,7 @@
Start: Start:
; Save the zero page locations we need ; Save the zero-page locations that we need.
ldx #zpspace-1 ldx #zpspace-1
L1: lda sp,x L1: lda sp,x
@ -30,16 +30,16 @@ L1: lda sp,x
dex dex
bpl L1 bpl L1
; Switch to second charset ; Switch to the second charset.
lda #14 lda #14
jsr BSOUT jsr BSOUT
; Clear the BSS data ; Clear the BSS data.
jsr zerobss jsr zerobss
; Save system stuff and setup the stack ; Save some system stuff; and, set up the stack.
tsx tsx
stx spsave ; Save the system stack ptr stx spsave ; Save the system stack ptr
@ -49,20 +49,20 @@ L1: lda sp,x
lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
sta sp+1 ; Set argument stack ptr sta sp+1 ; Set argument stack ptr
; Call module constructors ; Call the module constructors.
jsr initlib jsr initlib
; Push arguments and call main() ; Push the command-line arguments; and, call main().
jsr callmain jsr callmain
; Back from main (This is also the _exit entry). Run module destructors ; Back from main() [this is also the exit() entry]. Run the module destructors.
_exit: pha ; Save the return code on stack _exit: pha ; Save the return code on stack
jsr donelib jsr donelib
; Copy back the zero page stuff ; Copy back the zero-page stuff.
ldx #zpspace-1 ldx #zpspace-1
L2: lda zpsave,x L2: lda zpsave,x
@ -70,17 +70,17 @@ L2: lda zpsave,x
dex dex
bpl L2 bpl L2
; Place the program return code into ST ; Place the program return code into BASIC's status variable.
pla pla
sta ST sta ST
; Restore the stack pointer ; Restore the stack pointer.
ldx spsave ldx spsave
txs txs
; Back to basic ; Back to BASIC.
rts rts