home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / enterprs / c128 / util / sfxsrc.arc / BITIO.A next >
Encoding:
Text File  |  1990-02-12  |  3.7 KB  |  153 lines

  1. ; bitio.a
  2. ;=============================================================================
  3. ; Bit I/O for LHARC self extract module
  4. ;=============================================================================
  5.  
  6.             INSTXT "sfx.i"
  7.  
  8.             PUBLIC GetChar          ; Buffer fetch char into .a
  9.             PUBLIC GetBit           ; Fetch single bit  into .c
  10.             PUBLIC DecChar
  11.             PUBLIC DecPosition
  12.  
  13.             EXT Update
  14.             EXT son
  15.             EXT d_code
  16.             EXT d_len
  17.  
  18. ;─────────────────────────────
  19. ; Character fetch from memory
  20. ;─────────────────────────────
  21.  
  22.             BSS save_x,1
  23.  
  24. GetChar     stx save_x
  25.             ldx #0
  26.             lda (IBUF,x)
  27.             inc IBUF
  28.             bne GetChar0
  29.             inc IBUF+1
  30. GetChar0    ldx save_x
  31.             rts
  32.  
  33.  
  34. ;──────────────────────────
  35. ; Fetch one bit into carry
  36. ;──────────────────────────
  37.  
  38. GetBit      asl BITBUF              ; Is this the last bit?
  39.             beq NewByte             ; Yes, get new byte
  40.             rts
  41.  
  42. NewByte     pha
  43.             jsr GetChar             ; Else get new character
  44.             sta BITBUF
  45.             pla
  46.             sec                     ; So that BEQ test will work
  47.             rol BITBUF              ; Return new bit in carry
  48.             rts            
  49.  
  50.  
  51. ;────────────────────
  52. ; Decode a character
  53. ;────────────────────
  54.  
  55. C           EQU T0
  56. PNT         EQU T1
  57.  
  58. DecChar     lda son+Rstar2          ; c=son[R]
  59.             asl a
  60.             sta C
  61.             lda son+Rstar2+1
  62.             rol a
  63.             sta C+1
  64.  
  65. While_1     lda C                   ; while(c<T)
  66.             cmp #<Tstar2
  67.             lda C+1
  68.             sbc #>Tstar2
  69.             bcs EndWhile_1
  70.             jsr GetBit              ; c += getbit()
  71.             bcc NoAdd
  72.             clc
  73.             lda C
  74.             adc #2
  75.             sta C
  76.             bcc NoAdd
  77.             inc C+1
  78. NoAdd       clc                     ; c = son[c]
  79.             lda C
  80.             adc #<son
  81.             sta PNT
  82.             lda C+1
  83.             adc #>son
  84.             sta PNT+1
  85.             ldy #0
  86.             lda (PNT),y
  87.             asl a
  88.             sta C
  89.             iny
  90.             lda (PNT),y
  91.             rol a
  92.             sta C+1
  93.             jmp While_1
  94.  
  95. EndWhile_1  lsr C+1                 ; c -= T
  96.             ror C
  97.             sec
  98.             lda C
  99.             sbc #<T
  100.             pha                     ; Save C since it will be the return value
  101.             tax
  102.             lda C+1
  103.             sbc #>T
  104.             pha
  105.             tay
  106.             jsr Update              ; Update(c)
  107.             pla
  108.             tay
  109.             pla
  110.             tax
  111.             rts
  112.  
  113. ;────────────────────────────────
  114. ; DecodePosition: Result in .x.y
  115. ;────────────────────────────────
  116.  
  117. CC          EQU T0
  118.  
  119. DecPosition ldx #8                  ; i (=.y) = GetByte()
  120. gb0         jsr GetBit
  121.             rol a
  122.             dex
  123.             bne gb0
  124.             tay
  125.             lda d_code,y            ; c (= CC) = word(d_code[i]) << 6
  126.             stx CC
  127.             lsr a
  128.             ror CC
  129.             lsr a
  130.             ror CC
  131.             sta CC+1
  132.             ldx d_len,y             ; j ( = .x) = d_len[i]
  133.             tya                     ; move I to .a for while loop
  134.             dex                     ; j -=2
  135.             dex
  136. While_2     cpx #0
  137.             php
  138.             dex
  139.             plp
  140.             beq EndWhile_2          ; while(j--)
  141.             jsr GetBit
  142.             rol a
  143.             jmp While_2
  144.  
  145. EndWhile_2  and #$3f                ; return C | (i & 0x3f)
  146.             ora CC
  147.             tax
  148.             ldy CC+1
  149.             rts
  150.  
  151.  
  152.             END
  153.