home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / UTILS / ARC-LBR / USQBASE.MAC < prev    next >
Text File  |  2000-06-30  |  4KB  |  268 lines

  1. ;*******************************************************
  2. ;* USQ support code                      *
  3. ;* 10/12/83 by Dave Rand                      *
  4. ;*******************************************************
  5. ;
  6. ; Changes made by S. Kluger to allow use under SYSLIB.
  7. ; The following SYSLIB routines are used:
  8. ;
  9.     extrn    bdos        ;BDOS call routine
  10.     extrn    print        ;In place of ILPRT
  11.     extrn    cout        ;Character out routine
  12. ;
  13. ; The following labels must be defined in the calling program:
  14. ;
  15.     extrn    fcb        ;file control block addr
  16.     extrn    buff        ;ram buffer start
  17.     extrn    topram        ;end of buffer (hi byte only)
  18.     extrn    erext        ;error exit routine
  19.     extrn    table        ;pointer to 1032 bytes
  20.     extrn    bufull        ;called when buffer full
  21.                 ;(this routine processes the filled
  22.                 ; buffer and then returns for more.)
  23. ;
  24.     public    usq        ;unsqueeze entry point
  25. ;
  26. eof    equ    1ah
  27. dle    equ    090h
  28. ;
  29. ;this is start of baseline USQ code
  30. ;
  31. usq:    xra    a        ;force init char read
  32.     sta    numlft
  33.     sta    rcnt        ;and zero repeats
  34.     lhld    lastmem
  35.     shld    sob
  36.     shld    eob
  37.     call    getw
  38. usq1:    call    getw        ;get cksum, and store
  39.     shld    filecrc
  40. usq2:    call    get1
  41.     jnz    erext
  42.     ora    a
  43.     jnz    usq2
  44. usq3a:    call    getw
  45.     shld    numvals
  46.     lxi    d,258
  47.     call    cmpdehl
  48.     jc    usq3b
  49.     call    errext
  50.     db    13,10,'File has illegal decode size. Aborting.',0
  51. ;
  52. usq3b:    lxi    d,table
  53. usq4:    shld    max
  54.     mov    a,h
  55.     ora    l
  56.     jz    usq5
  57.     push    d
  58.     call    getw
  59.     pop    d
  60.     xchg
  61.     mov    m,e
  62.     inx    h
  63.     mov    m,d
  64.     inx    h
  65.     push    h
  66.     call    getw
  67.     xchg
  68.     pop    h
  69.     mov    m,e
  70.     inx    h
  71.     mov    m,d
  72.     inx    h
  73.     xchg
  74.     lhld    max
  75.     dcx    h
  76.     jmp    usq4
  77. ;
  78. usq5:    lxi    h,0
  79. usq6:    push    h
  80.     call    getnxt
  81.     pop    h
  82.     jnz    usq8
  83.     mov    e,a
  84.     mvi    d,0
  85.     dad    d
  86.     push    h
  87.     push    psw
  88.     LHLD    nextadr        ; PT TO LOAD ADDRESS
  89.     LDA    topram        ; CHECK AGAINST END PAGE OF TPA
  90.     CMP    H        ; IF AT SAME PAGE, YES
  91.     jnz    nofull        ;buffer is not full yet
  92.     call    bufull        ;buffer full, process buffer
  93.     lxi    h,buff        ;reset buffer pointer
  94. nofull:    pop    psw
  95.     mov    m,a
  96.     inx    h
  97.     shld    nextadr
  98.     pop    h
  99.     jmp    usq6
  100. ;
  101. usq8:    xchg
  102.     lhld    filecrc
  103.     call    cmpdehl
  104. usq9:    rz
  105.     call    print
  106.     db    13,10,'ERROR - Checksum error in file ',0
  107.     jmp    erext
  108. ;
  109. errext:    pop    h
  110.     mov    a,m
  111.     ora    a
  112.     jz    erext
  113.     inx    h
  114.     push    h
  115.     call    cout
  116.     jmp    errext
  117. ;
  118. cmpdehl:
  119.     mov    a,h
  120.     cmp    d
  121.     rnz
  122.     mov    a,l
  123.     cmp    e
  124.     ret
  125. ;
  126. get1:    lhld    eob
  127.     xchg
  128.     lhld    sob
  129.     call    cmpdehl
  130.     jz    get1r
  131.     mov    a,m
  132.     inx    h
  133.     shld    sob
  134.     cmp    a
  135.     ret
  136. ;
  137. get1r:    lhld    lastmem
  138.     shld    sob
  139.     shld    eob
  140. get1r1:    push    h
  141.     xchg
  142.     mvi    c,26
  143.     call    bdos
  144.     lxi    d,fcb
  145.     mvi    c,20
  146.     call    bdos
  147.     pop    h
  148.     ora    a
  149.     jnz    get1r2
  150.     lxi    d,128
  151.     dad    d
  152.     xchg
  153.     lhld    endmem
  154.     call    cmpdehl
  155.     xchg
  156.     jnc    get1r1
  157. get1r2:    shld    eob
  158.     xchg
  159.     lhld    sob
  160.     call    cmpdehl
  161.     jnz    get1
  162.     mvi    a,255
  163.     ora    a
  164.     ret
  165. ;
  166. getw:    call    get1
  167.     jnz    badr
  168.     push    psw
  169.     call    get1
  170.     jnz    badr
  171.     mov    h,a
  172.     pop    psw
  173.     mov    l,a
  174.     ret
  175. ;
  176. badr:    call    print
  177.     db    13,10,'Premature EOF on file... aborted.',0
  178.     jmp    0
  179. ;
  180. getnxt:    lda    rcnt        ;see if in the middle of
  181.     ora    a        ;repeat sequence...
  182.     jz    getn7
  183.     dcr    a
  184.     sta    rcnt
  185.     lda    last
  186.     cmp    a
  187.     ret
  188. getn7:    call    getn4
  189.     cpi    dle
  190.     jnz    getn5
  191.     call    getn4
  192.     ora    a
  193.     jnz    getn6
  194.     mvi    a,dle        ;dle is encoded as dle,0
  195.     cmp    a
  196.     ret
  197. getn6:    dcr    a
  198.     dcr    a
  199.     sta    rcnt
  200.     lda    last
  201.     cmp    a
  202.     ret
  203. getn5:    sta    last
  204.     cmp    a
  205.     ret
  206. ;
  207. getn4:    lxi    d,0        ;pointer @ sot
  208.     lda    char
  209.     mov    c,a
  210. getn1:    lda    numlft
  211.     ora    a
  212.     jnz    getn2
  213.     push    d
  214.     call    get1
  215.     jnz    badr
  216.     pop    d
  217.     mov    c,a
  218.     mvi    a,8
  219. getn2:    dcr    a
  220.     sta    numlft
  221.     mov    a,c
  222.     rrc
  223.     mov    c,a
  224.     lxi    h,table
  225.     jnc    getn3
  226.     inx    h
  227.     inx    h        ;add 2 to point to right node
  228. getn3:    dad    d
  229.     dad    d
  230.     dad    d
  231.     dad    d        ;ok.. pointing close to right plc..
  232.     mov    e,m
  233.     inx    h
  234.     mov    d,m
  235.     mov    a,d
  236.     ani    128
  237.     jz    getn1
  238.     mov    a,c
  239.     sta    char
  240.     mov    a,d
  241.     cpi    254        ;is special eof?
  242.     mvi    a,eof
  243.     jz    geteof        ;yup
  244.     mov    a,e
  245.     cma
  246.     cmp    a
  247.     ret
  248. ;
  249. geteof:    pop    h
  250.     ora    a
  251.     ret
  252. ;
  253. ;end of baseline USQ code
  254. ;
  255. lastmem:dw    80h
  256. endmem:    dw    80h+127
  257. sob:    dw    80h
  258. eob:    dw    80h
  259. ;
  260. nextadr:dw    buff
  261. numlft:    ds    1
  262. rcnt:    ds    1
  263. filecrc:ds    2
  264. last:    ds    1
  265. char:    ds    1
  266. numvals:ds    2
  267. max:    ds    2
  268.