From: brix@plush.de (Onkel Wanja)

hi Steve!
I had a look at the fridge and noticed maybe you could love my PAck-Routine for the SCPU, and the routine to find the best packbyte.
All of them are coded in the ACME-Assembler by Marco Baye.

here are the lsourcecodes.. have fun (hope you like 'em)

-Wanja (Brix/Plush)-


!macro sxya .adress {	stx .adress
			sty .adress+1
                        sta .adress+2 }

!macro lxya .value {	ldx #<.value
			ldy #>.value
                        lda #^.value }

!macro trinc .adress {inc .adress
                     bne .over
                     inc .adress+1
                     bne .over
                     inc .adress+2
                    .over } ;triple increase (24 bit)

!macro trequal adress,adress2	{lda adress:cmp adress2:bne .out
			lda adress+1:cmp adress2+1:bne .out
			lda adress+2:cmp adress2+2:
			.out } ;compare if equal 24 bit


zeroload = $fa
zeroput = $fd
zeroend = $57

loadto = $030000
packto = $020000
packbyte = $02

!zone

packroutine
         sei
         lda #^loadto
         ldy #>loadto
         ldx #<loadto
         sta zeroload+2
         sty zeroload+1
         stx zeroload

         lda #^packto
         ldy #>packto
         ldx #<packto
         sta zeroput+2
         sty zeroput+1
         stx zeroput
         ldy #0
         lda [zeroend],y
         eor #$ff
         iny
         sta [zeroend],y

.packloop jsr .getbyte
         ldy #$ff
.search
         iny
         cpy #$fe
         beq .sequence
         cmp [zeroload],y
         beq .search
         cpy #3
         bcs .sequence
         cmp packbyte
         beq .sequence
         jsr .putbyte
         bra .packloop
.sequence
         iny
         pha
         lda packbyte
         jsr .putbyte
         tya
         jsr .putbyte
         pla
         jsr .putbyte
         dey
         bne .loopinc
         jsr .readinc
         bra .packloop
.loopinc  jsr .readinc
         dey
         bne .loopinc
         bra .packloop

.endpack
         pla
         pla
         pla
         lda packbyte
         jsr .putbyte
         lda #0
         jsr .putbyte
         ldx zeroput
         ldy zeroput+1
         lda zeroput+2
         cli
         rts

.getbyte  lda [zeroload]
.readinc  pha
	 +trinc zeroload

.geti
         lda zeroload
         cmp zeroend
         bne .noendpack
         lda zeroload+1
         cmp zeroend+1
         bne .noendpack
         lda zeroload+2
         cmp zeroend+2
         beq .endpack
.noendpack pla
         rts

.putbyte  sta [zeroput]
	 +trinc zeroput
.endput   rts


;----------

lowbytes = $0400
highbytes = $0500


!zone
searchpackbyte
        sei
	ldx #0
	lda #1
.clloop	sta highbytes,x
	stz lowbytes,x
        dex
	bne .clloop

        +lxya loadto
        +sxya zeroload

.loop	lda [zeroload]
	tax
	inc lowbytes,x
	bne .over
	inc highbytes,x
	bne .over
	dec highbytes,x
.over	+trinc zeroload
	+trequal zeroload,zeroend  ;A is lost after compare
	bne .loop

	clc
	ldx #$00
.loop3	dec highbytes,x
        bne .nzer
	sec
.nzer   inx
	bne .loop3
	bcc .loop3

.foundhigh
.loop4	lda highbytes,x
	bne .over2
        lda lowbytes,x
        beq .found
	dec lowbytes,x
.over2	inx
	bra .loop4
	
.found	txa
	sta packbyte

        cli
	rts



