Refined the comments in the target start-up files.
Fixed typo errors. Made the comments consistent across all those files.
This commit is contained in:
@@ -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
|
||||
; 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
|
||||
; code in bank 0, which will initialize the system by copying stuff from
|
||||
; 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
|
||||
; 20 read j
|
||||
@@ -40,9 +40,9 @@
|
||||
; lda #$00
|
||||
; sta $00 <-- Switch to bank 0 after this command
|
||||
;
|
||||
; Initialization is not only complex because of the jumping from one bank
|
||||
; 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
|
||||
; 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
|
||||
; that, we will use the system memory ($00-$3FF) for initialization stuff
|
||||
; 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
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; A table that contains values that must be transfered from the system zero
|
||||
; 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,
|
||||
; but is declared here because it is needed earlier.
|
||||
; 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
|
||||
; 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.
|
||||
|
||||
.SEGMENT "PAGE2"
|
||||
|
||||
; (We use .proc because we need both a label and a scope.)
|
||||
|
||||
.proc transfer_table
|
||||
|
||||
.byte $9F, DEVNUM
|
||||
@@ -78,7 +80,7 @@
|
||||
; 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
|
||||
; 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"
|
||||
|
||||
@@ -92,7 +94,7 @@ BRKVec: .addr _exit ; BRK indirect vector
|
||||
|
||||
entry: php
|
||||
pha
|
||||
lda #$0F ; Bank 15
|
||||
lda #$0F ; Bank 15
|
||||
sta IndReg
|
||||
txa
|
||||
pha
|
||||
@@ -115,7 +117,7 @@ entry: php
|
||||
tya
|
||||
sec
|
||||
sbc #7
|
||||
sta $1FF ; Save new sp
|
||||
sta $1FF ; Save new sp
|
||||
tay
|
||||
|
||||
tsx
|
||||
@@ -143,7 +145,7 @@ entry: php
|
||||
iny
|
||||
sta (sysp1),y
|
||||
|
||||
ldy $1FF ; Restore sp in bank 15
|
||||
ldy $1FF ; Restore sp in bank 15
|
||||
|
||||
lda #.hibyte(expull-1)
|
||||
sta (sysp1),y
|
||||
@@ -170,7 +172,7 @@ expull: pla
|
||||
rts
|
||||
|
||||
.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
|
||||
|
||||
.reloc
|
||||
@@ -180,15 +182,15 @@ expull: pla
|
||||
;------------------------------------------------------------------------------
|
||||
; 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
|
||||
; not used by any kernal routine.
|
||||
; not used by any Kernal routine.
|
||||
|
||||
.segment "STARTUP"
|
||||
|
||||
Back: sta ExecReg
|
||||
|
||||
; 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
|
||||
; documentation and not actually used here:
|
||||
; in the system bank memory by the BASIC header program; it's only for
|
||||
; documentation, and not actually used here:
|
||||
|
||||
sei
|
||||
lda #$00
|
||||
@@ -196,23 +198,23 @@ Back: sta ExecReg
|
||||
|
||||
; 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
|
||||
; 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.
|
||||
|
||||
jmp Origin
|
||||
|
||||
; Hardware vectors, copied to $FFFA
|
||||
; Hardware vectors, copied to $FFF6
|
||||
|
||||
.proc vectors
|
||||
sta ExecReg
|
||||
rts
|
||||
nop
|
||||
.word nmi ; NMI vector
|
||||
.word 0 ; Reset - not used
|
||||
.word 0 ; Reset -- not used
|
||||
.word irq ; IRQ vector
|
||||
.endproc
|
||||
|
||||
; Initializers for the extended zeropage. See extzp.s
|
||||
; Initializers for the extended zero-page. See "extzp.s".
|
||||
|
||||
.proc extzp
|
||||
.word $0100 ; sysp1
|
||||
@@ -230,12 +232,12 @@ Back: sta ExecReg
|
||||
.word $ebd1 ; ktab4
|
||||
.endproc
|
||||
|
||||
; Switch the indirect segment to the system bank
|
||||
; Switch the indirect segment to the system bank.
|
||||
|
||||
Origin: lda #$0F
|
||||
sta IndReg
|
||||
|
||||
; Initialize the extended zeropage
|
||||
; Initialize the extended zero-page.
|
||||
|
||||
ldx #.sizeof(extzp)-1
|
||||
L1: lda extzp,x
|
||||
@@ -243,16 +245,16 @@ L1: lda extzp,x
|
||||
dex
|
||||
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
|
||||
txa
|
||||
ldy #$FF
|
||||
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
|
||||
|
||||
; Copy stuff from the system zeropage to ours
|
||||
; Copy stuff from the system zero-page to ours.
|
||||
|
||||
lda #.sizeof(transfer_table)
|
||||
sta ktmp
|
||||
@@ -266,7 +268,7 @@ L2: ldx ktmp
|
||||
dec ktmp
|
||||
bne L2
|
||||
|
||||
; Set the interrupt, NMI and other vectors
|
||||
; Set the interrupt, NMI, and other vectors.
|
||||
|
||||
ldx #.sizeof(vectors)-1
|
||||
L3: lda vectors,x
|
||||
@@ -274,14 +276,14 @@ L3: lda vectors,x
|
||||
dex
|
||||
bpl L3
|
||||
|
||||
; Setup the C stack
|
||||
; Set up the C stack.
|
||||
|
||||
lda #.lobyte(callbank15::entry)
|
||||
sta sp
|
||||
lda #.hibyte(callbank15::entry)
|
||||
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.
|
||||
|
||||
ldy #.sizeof(callbank15)
|
||||
@@ -290,10 +292,10 @@ L3: lda vectors,x
|
||||
dey
|
||||
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
|
||||
@L2: lda #$20 ; JSR opcode
|
||||
ldx #45-1 ; Number of vectors
|
||||
@L2: lda #$20 ; JSR opcode
|
||||
sta $FF6F,y
|
||||
iny
|
||||
lda #.lobyte(callbank15::entry)
|
||||
@@ -305,13 +307,13 @@ L3: lda vectors,x
|
||||
dex
|
||||
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
|
||||
sta IndReg
|
||||
|
||||
; Zero the BSS segment. We will do that here instead calling the routine
|
||||
; in the common library, since we have the memory anyway, and this way,
|
||||
; 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,
|
||||
; it's reused later.
|
||||
|
||||
lda #<__BSS_RUN__
|
||||
@@ -321,18 +323,18 @@ L3: lda vectors,x
|
||||
lda #0
|
||||
tay
|
||||
|
||||
; Clear full pages
|
||||
; Clear full pages.
|
||||
|
||||
ldx #>__BSS_SIZE__
|
||||
beq Z2
|
||||
Z1: sta (ptr1),y
|
||||
iny
|
||||
bne Z1
|
||||
inc ptr1+1 ; Next page
|
||||
inc ptr1+1 ; Next page
|
||||
dex
|
||||
bne Z1
|
||||
|
||||
; Clear the remaining page
|
||||
; Clear the remaining page.
|
||||
|
||||
Z2: ldx #<__BSS_SIZE__
|
||||
beq Z4
|
||||
@@ -343,12 +345,12 @@ Z3: sta (ptr1),y
|
||||
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.
|
||||
|
||||
.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
|
||||
sta ptr1
|
||||
@@ -362,7 +364,7 @@ Init: lda #<$C000
|
||||
sta tmp1
|
||||
ldy #$00
|
||||
ccopy: lda #$0F
|
||||
sta IndReg ; Access the system bank
|
||||
sta IndReg ; Access the system bank
|
||||
ccopy1: lda (ptr1),y
|
||||
sta __VIDRAM_START__,y
|
||||
iny
|
||||
@@ -374,22 +376,22 @@ ccopy2: lda __VIDRAM_START__,y
|
||||
iny
|
||||
bne ccopy2
|
||||
inc ptr1+1
|
||||
inc ptr2+1 ; Bump high pointer bytes
|
||||
inc ptr2+1 ; Bump high pointer bytes
|
||||
dec tmp1
|
||||
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.
|
||||
|
||||
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:
|
||||
|
||||
lda #$0F ; We need access to the system bank
|
||||
lda #$0F ; We need access to the system bank
|
||||
sta IndReg
|
||||
|
||||
; Place the VIC video RAM into bank 0
|
||||
; Place the VIC video RAM into bank 0.
|
||||
; CA (STATVID) = 0
|
||||
; CB (VICDOTSEL) = 0
|
||||
|
||||
@@ -400,7 +402,7 @@ ccopy2: lda __VIDRAM_START__,y
|
||||
ora #%10100000
|
||||
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
|
||||
|
||||
ldy #TPI::PRC
|
||||
@@ -422,12 +424,12 @@ ccopy2: lda __VIDRAM_START__,y
|
||||
; ora #<(((>__VIDRAM_START__) << 2) & $F0)
|
||||
sta (vic),y
|
||||
|
||||
; Switch back to the execution bank
|
||||
; Switch back to the execution bank.
|
||||
|
||||
lda ExecReg
|
||||
sta IndReg
|
||||
|
||||
; Activate chained interrupt handlers, then enable interrupts.
|
||||
; Activate the chained interrupt handlers; then, enable interrupts.
|
||||
|
||||
lda #.lobyte(__INTERRUPTOR_COUNT__*2)
|
||||
sta irqcount
|
||||
@@ -437,11 +439,11 @@ ccopy2: lda __VIDRAM_START__,y
|
||||
|
||||
jsr initlib
|
||||
|
||||
; Push arguments and call main()
|
||||
; Push the command-line arguments; and, call main().
|
||||
|
||||
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.
|
||||
|
||||
_exit: pha ; Save the return code on stack
|
||||
@@ -449,12 +451,12 @@ _exit: pha ; Save the return code on stack
|
||||
lda #$00
|
||||
sta irqcount ; Disable custom irq handlers
|
||||
|
||||
; Address the system bank
|
||||
; Address the system bank.
|
||||
|
||||
lda #$0F
|
||||
sta IndReg
|
||||
|
||||
; Switch back the video to the system bank
|
||||
; Switch back the video to the system bank.
|
||||
|
||||
ldy #TPI::CR
|
||||
lda vidsave+0
|
||||
@@ -468,7 +470,7 @@ _exit: pha ; Save the return code on stack
|
||||
lda vidsave+2
|
||||
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
|
||||
lda #.sizeof(transfer_table)
|
||||
@@ -484,13 +486,13 @@ _exit: pha ; Save the return code on stack
|
||||
bne @L0
|
||||
.endif
|
||||
|
||||
; Place the program return code into ST
|
||||
; Place the program return code into BASIC's status variable.
|
||||
|
||||
pla
|
||||
ldy #$9C ; ST
|
||||
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
|
||||
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
|
||||
; 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
|
||||
; | | | | ^ 50 Hz
|
||||
; | | | | ^ 50 Hz.
|
||||
; | | | ^ SRQ IEEE 488
|
||||
; | | ^ cia
|
||||
; | | ^ CIA
|
||||
; | ^ IRQB ext. Port
|
||||
; ^ acia
|
||||
; ^ ACIA
|
||||
|
||||
irq: pha
|
||||
txa
|
||||
@@ -528,41 +530,41 @@ irq: pha
|
||||
lda IndReg
|
||||
pha
|
||||
lda ExecReg
|
||||
sta IndReg ; Be sure to address our segment
|
||||
sta IndReg ; Be sure to address our segment
|
||||
tsx
|
||||
lda $105,x ; Get the flags from the stack
|
||||
and #$10 ; Test break flag
|
||||
lda $105,x ; Get the flags from the stack
|
||||
and #$10 ; Test break flag
|
||||
bne dobrk
|
||||
|
||||
; It's an IRQ
|
||||
; It's an IRQ.
|
||||
|
||||
cld
|
||||
|
||||
; Call chained IRQ handlers
|
||||
; Call the chained IRQ handlers.
|
||||
|
||||
ldy irqcount
|
||||
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
|
||||
sta IndReg
|
||||
ldy #TPI::AIR
|
||||
lda (tpi1),y ; Interrupt Register 6525
|
||||
lda (tpi1),y ; Interrupt Register 6525
|
||||
beq noirq
|
||||
|
||||
; 50/60Hz interrupt
|
||||
; 50/60Hz. interrupt
|
||||
|
||||
cmp #%00000001 ; ticker irq?
|
||||
cmp #%00000001 ; ticker IRQ?
|
||||
bne irqend
|
||||
jsr scnkey ; Poll the keyboard
|
||||
jsr UDTIM ; Bump the time
|
||||
jsr scnkey ; Poll the keyboard
|
||||
jsr UDTIM ; Bump the time
|
||||
|
||||
; Done
|
||||
; Done.
|
||||
|
||||
irqend: ldy #TPI::AIR
|
||||
sta (tpi1),y ; Clear interrupt
|
||||
sta (tpi1),y ; Clear interrupt
|
||||
|
||||
noirq: pla
|
||||
sta IndReg
|
||||
@@ -583,5 +585,3 @@ vidsave:.res 3
|
||||
|
||||
.bss
|
||||
irqcount: .byte 0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user