home *** CD-ROM | disk | FTP | other *** search
- ; start.a
- ;──────────────────────────────────────────────────────────────────────────────
- ; LHARChive self extraction module for C64/C128 - Copyright 1990 - Chris Smeets
- ;──────────────────────────────────────────────────────────────────────────────
- ; Startup code
-
- INSTXT "sfx.i"
-
- PUBLIC _Dend_ ; Start of data segment
- PUBLIC _Dorg_ ; End of data segment
- PUBLIC _Corg_ ; Start of code segment
- PUBLIC _Cend_ ; End of code segment
-
- EXT Decode
- EXT GenTab
- EXT GenCRC
- EXT Portable
- EXT Romin
- EXT Romout
- EXT Prt
- EXT Message
- EXT Basic
- EXT clrchn
- EXT chrin
-
- Save_SP EQU $03d6 ; Not used in 64, INSTR work area in 128
-
- RelCount EQU $00bb ; Number of relocation items
- Offset EQU $00fa ; Save relocation offset here
- CP EQU $00fb ; Pointer into CSEG
- RP EQU $00fd ; Pointer into relocation info
-
- PUBLIC OutDrive
- PUBLIC OutUnit
- PUBLIC P_flag
- PUBLIC FirstTime
-
- BSS OutDrive,1
- BSS OutUnit,1
- BSS P_flag,1
- BSS FirstTime,1
-
- BSS Save_ZP,Z_high-Z_low
-
- ;───────────────────────────────────────────
- ; BASIC will sys(.begin) so this can't move
- ;───────────────────────────────────────────
- ; Start by relocating the program.
-
- PUBLIC .begin
- ENTRY .begin
-
- .begin lda #%00001110
- sta $ff00
- Relocate lda #$60 ; Store an RTS
- sta $fc
- jsr $fc ; push actual value of #>Rel0-1
- Rel0 tsx
- stx Save_SP
- dex
- txs
- pla
- sec
- sbc #>Rel0-1 ; Less what the linker thinks it is
- sta Offset ; Will be zero if run twice
-
- lda #<_Corg_ ; Compute true _Corg_
- sta CP
- lda #>_Corg_
- clc
- adc Offset
- sta CP+1
- lda #<_Dend_+2 ; and True _Dend_
- sta RP
- lda #>_Dend_+2
- clc
- adc Offset
- sta RP+1
-
- ldx #0
- ldy #1
- lda (RP,x)
- sta RelCount
- lda (RP),y
- sta RelCount+1
- lda #2
- fcb $2c
- Rel1 lda #1
- clc
- adc RP
- sta RP
- bcc Rel2
- inc RP+1
- Rel2 lda RelCount
- ora RelCount+1
- beq Done
- Rel3 lda (RP,x)
- pha
- clc
- adc CP
- sta CP
- bcc Rel4
- inc CP+1
- Rel4 pla
- cmp #$ff
- beq Rel1
- clc
- lda (CP,x)
- adc Offset
- sta (CP,x)
- lda RelCount
- bne Rel5
- dec RelCount+1
- Rel5 dec RelCount
- clc
- bcc Rel1
-
- ;─────────────────────────────────────────────
- ; Relocation Complete. Do some initialization
- ;─────────────────────────────────────────────
-
- Done jsr Portable ; Setup C64/C128 jumptable
- jsr Romout ; Run in all RAM configuration
- ldx RP ; Data starts where relocation info stops
- ldy RP+1
- stx IBUF
- sty IBUF+1
- ldx #Z_low ; Copy the zero page we need to BSS
- ldy #0
- sty FirstTime ; Flag 1st time for title display
- sty OutUnit ; Flag that we need to ask for output dev
- .SaveZ lda 0,x
- sta Save_ZP,y
- iny
- inx
- cpx #Z_high
- bne .SaveZ
-
- jsr GenTab ; Generate d_code and d_len tables
- jsr GenCRC ; Generate CRC calculation tables
-
- Again jsr Decode ; Decode one file
- cmp #NullFile ; Empty file, just try again
- beq Again
- cmp #DiskError ; Disk error? If so, abort
- bne E1
- ldx #<DiskMssg
- ldy #>DiskMssg
- jmp Abort
-
- E1 cmp #BadHeader ; Bad header, its the end of the SFX
- bne E2
- ldx #<DoneMssg
- ldy #>DoneMssg
- jmp Abort
-
- E2 cmp #CRCError
- bne E3
- ldx #<CRCMssg
- ldy #>CRCMssg
- GoAgain bit P_flag
- bmi NoMessage
- jsr Message
- NoMessage jmp Again
-
- E3 cmp #DecodeOK
- bne E4
- ldx #<OKMssg
- ldy #>OKMssg
- bne GoAgain
-
- E4 ldx #<ErrMssg ; Unknown return code? Assume its an error
- ldy #>ErrMssg
-
- PUBLIC Abort
-
- Abort jsr Message ; Print error message
-
- AllDone ldy #0 ; Restore zero page
- ldx #Z_low
- .RestZ lda Save_ZP,y
- sta 0,x
- iny
- inx
- cpx #Z_high
- bne .RestZ
- jsr Romin
- ldx Save_ZP ; Restore startup SP
- txs
- jmp Basic ; And back to BASIC ROM
-
- DSEG
-
- DiskMssg fcb 13
- fcc "DISK ERROR"
- fcb 13,0
- DoneMssg fcb 13
- fcc "ALL DONE"
- fcb 13,0
- CRCMssg fcc "CRC ERROR!"
- fcb 13,0
- OKMssg fcc "OK"
- fcb 13,0
- ErrMssg fcb 13
- fcc "DECODE ERROR"
- fcb 13,0
-
- PUBLIC CopyRight
-
- CopyRight fcb 13
- fcc "C64/C128 SELF EXTRACTING LHARCHIVE"
- fcb 13
- fcc "COPYRIGHT 1990 - C.SMEETS"
- fcb 13
- fcc "TORONTO,CANADA"
- fcb 13,13,0
- AskDrive fcc "DRIVE (0 OR 1) ? 0"
- fcb 157,0
- AskUnit fcc "UNIT (8,9...) ? 8"
- fcb 157,0
-
- CSEG
-
- PUBLIC CRLF
-
- GetNum jsr Message
- jsr clrchn
- lda #0
- sta T0
- sta T1
- jsr Digit
- bcs CRLF
- jsr Digit
- lda T0
- Tens dec T1
- bmi GotTens
- clc
- adc #10
- bcc Tens
- GotTens clc
- CRLF php
- pha
- lda #13
- jsr Prt
- pla
- plp
- rts
-
- Digit jsr chrin
- cmp #'0'
- bcc NoNum
- cmp #'9'+1
- bcs NoNum
- and #$0f
- ldx T0
- sta T0
- stx T1
- clc
- rts
-
- NoNum sec
- rts
-
- PUBLIC AskDrives
-
- AskDrives lda OutUnit
- bne GotDrives
- ldx #<CopyRight
- ldy #>CopyRight
- jsr Message
- ldx #<AskDrive
- ldy #>AskDrive
- jsr GetNum
- bcc SaveDrive
- BadInfo jmp AllDone
-
- SaveDrive sta OutDrive
- ldx #<AskUnit
- ldy #>AskUnit
- jsr GetNum
- bcs BadInfo
- sta OutUnit
- jsr CRLF
- GotDrives rts
-
- END
-
-