; ------------------------------------------------------------------------
; Place the startup code in a special segment to cope with the quirks of
-; c128 banking. Do also create an empty segment named "NMI" to avoid
-; warnings if the rs232 routines are not used.
-
-.segment "NMI"
-; empty
+; c128 banking.
.segment "STARTUP"
-; ------------------------------------------------------------------------
; BASIC header with a SYS call
.org $1BFF
; above will change this setting so that we have RAM from $0000-$BFFF. This
; works quite well with the exception of interrupts: The interrupt handler
; is in ROM, and the ROM switches back to the ROM configuration, which means
-; that parts of our program may not be accessible. Since the crt0 module is
-; the first module in the program, it will always be below $4000 and always
-; in RAM. So we place several short stubs here that switch back our ROM
-; config before calling our user defined handlers. These stubs are only
-; used if any other code uses the interrupt or break vectors. They are dead
-; code otherwise, but since there is no other way to keep them in low memory,
-; they have to go here.
+; that parts of our program may not be accessible. To solve this, we place
+; the following code into a special segment called "LOWCODE" which will be
+; placed just above the startup code, so it goes into a RAM area that is
+; not banked.
+
+.segment "LOWCODE"
IRQStub:
cld ; Just to be sure
jsr condes ; Call the functions
pla ; Get old register value
sta MMU_CR
- jmp IRQInd ; Jump to the save IRQ vector
+ jmp IRQInd ; Jump to the saved IRQ vector
BRKStub:
; Because of the C128 banking, the NMI handler must go into the non banked
; memory, since the ROM NMI entry point will switch to a configuration where
; only the lowest 16K of RAM are visible. We will place the NMI handler into
-; it's own segment and map this segment into the lower 16K in the linker
+; the LOWCODE segment and map this segment into the lower 16K in the linker
; config.
-.segment "NMI"
+.segment "LOWCODE"
NmiHandler:
lda #CC65_MMU_CFG ;(2)
- sta MMU_CR ;(4)
+ sta MMU_CR ;(4)
lda ACIA+RegStatus ;(4) ;status ;check for byte received
and #$08 ;(2)
- beq @L9 ;(2*)
+ beq @L9 ;(2*)
lda ACIA+RegStatus ;(4) opt ;status ;check for receive errors
and #$07 ;(2) opt
beq @L1 ;(3*)opt
@L1: lda ACIA+RegData ;(4) ;data ;get byte and put into receive buffer
ldy RecvTail ;(4)
ldx RecvFreeCnt ;(4)
- beq @L3 ;(2*)
+ beq @L3 ;(2*)
sta RecvBuf,y ;(5)
inc RecvTail ;(6)
dec RecvFreeCnt ;(6)
; Try to send a byte. Internal routine. A = TryHard
TryToSend:
- sta tmp1 ; Remember tryHard flag
+ sta tmp1 ; Remember tryHard flag
@L0: lda SendFreeCnt
cmp #$ff
- beq @L3 ; Bail out
+ beq @L3 ; Bail out
; Check for flow stopped
@L1: lda Stopped
- bne @L3 ; Bail out
+ bne @L3 ; Bail out
;** check that swiftlink is ready to send