Skip to content

Commit

Permalink
Use the same Exomizer code for depacking the loader and for later fil…
Browse files Browse the repository at this point in the history
…e access.
  • Loading branch information
cadaver committed Dec 10, 2015
1 parent 9705af1 commit 8ad6f89
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 472 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ hessian.d64: loader.prg main.pak options.bin emptysave.bin savelist.bin logo.pak
hessian.d81: hessian.d64 hessiand81.seq
c1541 < hessiand81.seq

loader.prg: kernal.s loader.s loadsym.txt ldepack.s boot.s macros.s memory.s
loader.prg: kernal.s loader.s loadsym.txt ldepacksym.txt ldepack.s boot.s macros.s memory.s
dasm ldepack.s -oloader.prg -sldepack.tbl -f3
symbols ldepack.tbl ldepacksym.s ldepacksym.txt
dasm loader.s -oloader.bin -sloader.tbl -f3
symbols loader.tbl loadsym.s loadsym.txt
pack2 loader.bin loader.pak
dasm ldepack.s -oloader.prg -f3
dasm ldepack.s -oloader.prg -sldepack.tbl -f3
dasm boot.s -oboot.prg

sfx/pistol.sfx: sfx/pistol.ins
Expand Down
48 changes: 31 additions & 17 deletions boot.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

include memory.s
include kernal.s
include loadsym.s
include ldepacksym.s

org $032a

Expand All @@ -13,11 +13,12 @@

rorg $080d

BasicStart: ldx #AutoStartEnd-loaderFileName-1
Copy: lda BasicEnd+loaderFileName-AutoStart,x ;Just need to relocate data, not code
sta loaderFileName,x
BasicStart: ldx #AutoStartEnd-AutoStart
Copy: lda BasicEnd-1,x
sta AutoStart-1,x
dex
bpl Copy
bne Copy
jmp AutoStart
BasicEnd:
rend

Expand All @@ -43,23 +44,36 @@ ClearScreen: sta $2000,y ;Use another screen as $400 is t
bne ClearScreen
lda #$84
sta $d018
ldy #38
ldx #38
ShowMessage: lda #$0f
sta colors+12*40,y
lda message-1,y
sta colors+12*40,x
lda message-1,x
and #$3f
sta $2000+12*40,y
dey
sta $2000+12*40,x
dex
bne ShowMessage
MessageDone:
LoadLoop: jsr ChrIn
sta loaderInitEnd,y
iny
cpy #214 ;Load 214 bytes (loader depacker)
bne LoadLoop
jmp loaderInitEnd
MessageDone: ldx #LoadExomizerEnd-LoadExomizer-1
CopyToStack: lda LoadExomizer,x ;This code will be overwritten by loader, so copy elsewhere
sta $0100,x
dex
bpl CopyToStack
jmp $100

loaderFileName: dc.b "00"
message: dc.b "HOLD SPACE/FIRE TO DISABLE FAST LOADER"

LoadExomizer: ldy #$00
LoadExomizerLoop:
jsr ChrIn
sta exomizerCodeStart,y
iny
cpy #packedLoaderStart-exomizerCodeStart ;Load Exomizer
bne LoadExomizerLoop
lda #<loaderCodeStart
ldx #>loaderCodeStart
jsr LoadFile ;Load rest of code with Exomizer
inc $01 ;Kernal back on
jmp loaderCodeEnd ;Jump to InitLoader
LoadExomizerEnd:

AutoStartEnd:
165 changes: 99 additions & 66 deletions ldepack.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

include kernal.s
include memory.s
include loadsym.s

org loaderInitEnd
org exomizerCodeStart

tablBi = depackBuffer
tablLo = depackBuffer + 52
tablHi = depackBuffer + 104

; -------------------------------------------------------------------
; This source code is altered and is not the original version found on
Expand Down Expand Up @@ -41,22 +44,76 @@
; specific prior written permission.

; -------------------------------------------------------------------
; get bits (29 bytes)
;
; args:
; x = number of bits to get
; returns:
; a = #bits_lo
; x = #0
; c = 0
; z = 1
; zpBitsHi = #bits_hi
; notes:
; y is untouched
; -------------------------------------------------------------------
get_bits:
lda #$00
sta zpBitsHi
cpx #$01
bcc bits_done
bits_next:
lsr zpBitBuf
bne bits_ok
pha
stx loadTempReg
jsr GetByte
ldx loadTempReg
bcs loaderror3
sec
ror
sta zpBitBuf
pla
bits_ok:
rol
rol zpBitsHi
dex
bne bits_next
bits_done:
rts

Depacker:
ldx #3
ldy #0
loaderror3:
pla
pla
pla
loaderror:
rts

; Load file packed with Exomizer 2 forward mode
;
; Parameters: A,X load address, fileNumber
; Returns: C=0 if loaded OK, or C=1 and error code in A (see GetByte)
; Modifies: A,X,Y

LoadFile: sta zpDestLo
stx zpDestHi
jsr OpenFile

; -------------------------------------------------------------------
; init zeropage, x and y regs.
;
init_zp:
jsr getbyte
sta zpBitBuf-1,x
dex
bne init_zp
jsr GetByte
;bcs loaderror ;Error will be caught later
sta zpBitBuf
ldy #0

; -------------------------------------------------------------------
; calculate tables
; x and y must be #0 when entering
;
nextone:
inx
ldx #1
tya
and #$0f
beq shortcut ; start with new sequence
Expand Down Expand Up @@ -86,23 +143,29 @@ shortcut:
iny
cpy #52
bne nextone

begin:
ldy #$ff

; -------------------------------------------------------------------
; decruncher entry point, needs calculated tables
;
getgamma:
iny
begin:
inx
jsr bits_next
lsr zpBitBuf
bne norefill
jsr GetByte
bcs loaderror
sec
ror
sta zpBitBuf
norefill:
iny
bcc getgamma
tya
bne sequence

literal:
jsr getbyte
jsr GetByte
;bcs loaderror ;Error will be caught later
sta (zpDestLo),y
inc zpDestLo
bne begin
Expand All @@ -112,7 +175,7 @@ inchi:

sequence:
cpy #$11
beq ready ; gamma = 17 : end of file
beq eof ; gamma = 17 : end of file

; -------------------------------------------------------------------
; calculate length of sequence (zp_len)
Expand Down Expand Up @@ -167,65 +230,35 @@ copy_next:
cpy zpLenLo
bne copy_next
tya
ldy #$00
clc
adc zpDestLo
sta zpDestLo
bcc begin
bcs inchi

ready:
jmp InitLoader

; -------------------------------------------------------------------
; get bits (29 bytes)
;
; args:
; x = number of bits to get
; returns:
; a = #bits_lo
; x = #0
; c = 0
; z = 1
; zpBitsHi = #bits_hi
; notes:
; y is untouched
; -------------------------------------------------------------------
get_bits:
lda #$00
sta zpBitsHi
cpx #$01
bcc bits_done
bits_next:
lsr zpBitBuf
bne bits_ok
pha
jsr getbyte
sec
ror
sta zpBitBuf
pla
bits_ok:
rol
rol zpBitsHi
dex
bne bits_next
bits_done:
rts

getbyte:
stx loadTempReg
jsr ChrIn
ldx loadTempReg
eof:
clc
rts

tablBit: dc.b 2,4,4 ;Exomizer static tables
tablOff: dc.b 48,32,16

tablBi = *
tablLo = * + 52
tablHi = * + 104
; -------------------------------------------------------------------
; end of decruncher
; -------------------------------------------------------------------

OpenFile: rts
dc.b 0,0
SaveFile: rts
dc.b 0,0
GetByte: lda #$36
sta $01
cli
jsr ChrIn
sei
dec $01
clc
rts

dc.b >mainCodeStart ;This will be read next from the file
dc.b <mainCodeStart
packedLoaderStart:
incbin loader.pak
5 changes: 5 additions & 0 deletions ldepacksym.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
GetByte
OpenFile
SaveFile
LoadFile
packedLoaderStart
Loading

0 comments on commit 8ad6f89

Please sign in to comment.