;Code relocater (this code can run from any address)
;===================================================
*=$1220
RELOCATE
LDA $2C
;
CMP #$12
;
BEQ RELOCATE_DONE ;code already at the correct location
;program_size = END_OF_PROGRAM - INIT
;first byte in memory = contents of $2C + low byte of label MAIN
;last byte in memory = first byte in program_sizeRELOCATE_REQ
LDA #<END_OF_PROGRAM
;store destination address in zero-page variable
STA DEST_ADR
;===============================================
LDA #>END_OF_PROGRAM
;
STA D1
;high byte
LDA #<MAIN
;calculate first byte of code to be relocated in memory
STA SOURCE_ADR
;======================================================
LDA $2C
;
STA SOU1
;high byte
;------------------------------------------------------------------------------
;ATTENTION: make sure that the option "calc address first then high/low byte"
;in CBM program studio is selected. Otherwise the lines below WILL fail!!!!!!!
;------------------------------------------------------------------------------
CLC
;add program size to get to the last byte
LDA SOURCE_ADR
;========================================
ADC #<END_OF_PROGRAM-MAIN
;carry that we be used in the next addition
STA SOURCE_ADR
;
LDA #>END_OF_PROGRAM-MAIN
;
ADC SOU1
;add carry to high byte (if there was any)
STA SOU1
;
CLV
;clear flag here to keep the loop fast
LDY #$00
;clear reg here keeps the loop fast
RELOCATE_LP
LDA (SOURCE_ADR),Y
;the actual moving of the program (the copy loop)
STA (DEST_ADR),Y
;================================================
LDA D1
;check if last byte reached
CMP #>MAIN
;================================
BNE RELOCATE_00
;
LDA DEST_ADR
;low byte of last written address
CMP #<MAIN
;
BEQ RELOCATE_DONE
;
RELOCATE_00
DEC SOURCE_ADR
;calculate next addresses
LDA SOURCE_ADR
;
CMP #$FF
;
BNE RELOCATE_01
;========================
DEC SOU1
;overflow detected
RELOCATE_01
DEC DEST_ADR
;decrement low-byte
LDA DEST_ADR
;
CMP #$FF
;
BNE RELOCATE_02
;check for overflow of low byte
DEC D1
;overflow detected, so we must also decrement high-byte
RELOCATE_02 ;CLV
;force conditional branch because
BVC RELOCATE_LP
;absolute jumps are impossible
RELOCATE_DONE JMP MAIN
;code is at correct location, so we may start it
;Main program (the code that will be relocated), it may not exceed $1DFF
;This means that your own program may be bigger then approximately 3Kbyte
;========================================================================
MAIN
;;;write your own program here;;;
END_OF_PROGRAM ;this label indicates the absolute end of the program
2019-10-27
Page 38 of 76
CASSIOPEI v2.0
Содержание CASSIOPEI
Страница 1: ...CASSIOPEIv2 0 USER MANUAL this manual is intended for firmware version V20191027 or higher...
Страница 62: ......
Страница 69: ......