home *** CD-ROM | disk | FTP | other *** search
- ; bitio.a
- ;=============================================================================
- ; Bit I/O for LHARC self extract module
- ;=============================================================================
-
- INSTXT "sfx.i"
-
- PUBLIC GetChar ; Buffer fetch char into .a
- PUBLIC GetBit ; Fetch single bit into .c
- PUBLIC DecChar
- PUBLIC DecPosition
-
- EXT Update
- EXT son
- EXT d_code
- EXT d_len
-
- ;─────────────────────────────
- ; Character fetch from memory
- ;─────────────────────────────
-
- BSS save_x,1
-
- GetChar stx save_x
- ldx #0
- lda (IBUF,x)
- inc IBUF
- bne GetChar0
- inc IBUF+1
- GetChar0 ldx save_x
- rts
-
-
- ;──────────────────────────
- ; Fetch one bit into carry
- ;──────────────────────────
-
- GetBit asl BITBUF ; Is this the last bit?
- beq NewByte ; Yes, get new byte
- rts
-
- NewByte pha
- jsr GetChar ; Else get new character
- sta BITBUF
- pla
- sec ; So that BEQ test will work
- rol BITBUF ; Return new bit in carry
- rts
-
-
- ;────────────────────
- ; Decode a character
- ;────────────────────
-
- C EQU T0
- PNT EQU T1
-
- DecChar lda son+Rstar2 ; c=son[R]
- asl a
- sta C
- lda son+Rstar2+1
- rol a
- sta C+1
-
- While_1 lda C ; while(c<T)
- cmp #<Tstar2
- lda C+1
- sbc #>Tstar2
- bcs EndWhile_1
- jsr GetBit ; c += getbit()
- bcc NoAdd
- clc
- lda C
- adc #2
- sta C
- bcc NoAdd
- inc C+1
- NoAdd clc ; c = son[c]
- lda C
- adc #<son
- sta PNT
- lda C+1
- adc #>son
- sta PNT+1
- ldy #0
- lda (PNT),y
- asl a
- sta C
- iny
- lda (PNT),y
- rol a
- sta C+1
- jmp While_1
-
- EndWhile_1 lsr C+1 ; c -= T
- ror C
- sec
- lda C
- sbc #<T
- pha ; Save C since it will be the return value
- tax
- lda C+1
- sbc #>T
- pha
- tay
- jsr Update ; Update(c)
- pla
- tay
- pla
- tax
- rts
-
- ;────────────────────────────────
- ; DecodePosition: Result in .x.y
- ;────────────────────────────────
-
- CC EQU T0
-
- DecPosition ldx #8 ; i (=.y) = GetByte()
- gb0 jsr GetBit
- rol a
- dex
- bne gb0
- tay
- lda d_code,y ; c (= CC) = word(d_code[i]) << 6
- stx CC
- lsr a
- ror CC
- lsr a
- ror CC
- sta CC+1
- ldx d_len,y ; j ( = .x) = d_len[i]
- tya ; move I to .a for while loop
- dex ; j -=2
- dex
- While_2 cpx #0
- php
- dex
- plp
- beq EndWhile_2 ; while(j--)
- jsr GetBit
- rol a
- jmp While_2
-
- EndWhile_2 and #$3f ; return C | (i & 0x3f)
- ora CC
- tax
- ldy CC+1
- rts
-
-
- END
-