home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / enterprs / c128 / text / examples.arc / DA.A < prev    next >
Text File  |  1989-12-01  |  60KB  |  1,496 lines

  1. ;da.asm                                        (C)1987 - Ampere Metal
  2. ;====================================================================
  3. ; ARCmodem download.Simultaneously downloads and dissolves an archive.
  4. ;====================================================================
  5.  
  6.  
  7. stkptr      =      $0024            ;lz stack pointer
  8. check       =      $0026            ;table entry to check
  9. poker       =      $0016            
  10. ibuf        =      $0057            ;indirect pointer into RAM
  11. fnlen       =      $00b7            
  12. la          =      $00b8            
  13. sa          =      $00b9            
  14. dv          =      $00ba            
  15. fnadr       =      $00bb            
  16. status      =      $0090            
  17. ndx         =      $00d0            
  18. pntr        =      $00ec            
  19. sclf        =      $00e6            
  20. scrt        =      $00e7            
  21. bpntr       =      $00fe            ;buffer pointer save area (put y reg. here)
  22.  
  23. fn          =      $0100            ;where to put filename
  24. keyd        =      $034a            
  25. txttop      =      $1210            
  26. basic       =      $4003            
  27. hexa        =      $b8c2            
  28. primm       =      $ff7d            
  29. open        =      $ffc0            
  30. close       =      $ffc3            
  31. chkin       =      $ffc6            
  32. chkout      =      $ffc9            
  33. clrchn      =      $ffcc            
  34. chrin       =      $ffcf            
  35. getin       =      $ffe4            
  36. chrout      =      $ffd2            
  37. settim      =      $ffdb            ;set the software clock
  38. rdtim       =      $ffde            ;read the software clock
  39.  
  40. int01       =      $1701            
  41. int04       =      $1704            
  42. int05       =      $1705            
  43. int09       =      $1709            
  44. int0c       =      $170c            
  45. int0d       =      $170d            
  46. int0e       =      $170e            
  47. comout      =      $1306            
  48. comin       =      $1303            
  49. term        =      $1300            ;terminal main loop
  50. flush       =      $1309            ;Flush RS232 recieve buffer
  51. enable      =      $130c            ;enable RS232
  52. disabl      =      $130f            ;disable RS232
  53.  
  54. ack         =      $06              ;ctrl - f
  55. nak         =      $15              ;ctrl - u
  56. can         =      $18              ;ctrl - x
  57. cpm         =      $1a              ;xmodem padding character
  58. eot         =      $04              ;ctrl - d
  59. soh         =      $01              ;ctrl - a
  60. sstx        =      $02              ;ctrl - b
  61. xon         =      $11              
  62. xoff        =      $13              
  63. syn         =      $16              
  64.  
  65.  
  66. star        =      $3000            
  67.             .wor   star             
  68.             *      = star           
  69.  
  70.             ldx    #1               ;check for d:
  71.             jsr    int04            
  72.             bcs    df               
  73.             cmp    #"a"             
  74.             bcc    df               
  75.             cmp    #"m"             
  76.             bcs    df               
  77.             pha                     ;just save it for now
  78.             jsr    int05            
  79.             cmp    #":"             ;colon has got to be there
  80.             beq    used             ;its ok
  81.             pla                     
  82. df          jsr    int01            
  83.             pha                     
  84. used        pla                     
  85.             sta    writdv           
  86. main        lda    #%00001110       
  87.             sta    $ff00            
  88.             lda    #0               
  89.             sta    xmoflg           
  90.             sta    bcount           
  91.             sta    ibyt             
  92.             sta    size+1           
  93.             dec    size+1           
  94.             tsx                     
  95.             stx    svstk            
  96. main0       jsr    get1st           ;get archive entry header
  97.             bcs    skpad            ;bad header...end of archive
  98.             jmp    get1ok           
  99.  
  100. skpad       jsr    xmo2             ;get padding or EOT
  101.             bcc    skpad            
  102.             jsr    primm            
  103.             .asc   13,13,"Transfer successfully completed.",13, 0
  104.             jmp    abor             
  105.  
  106. noteot      jsr    primm            
  107.             .asc   13,"File is not an archive, or"
  108.             .asc   " is corrupt.",13, 0
  109. ccc         lda    #can             
  110.             jsr    comout           
  111.             lda    #can             
  112.             jsr    comout           
  113.             lda    #can             
  114.             jsr    comout           
  115.             jsr    clrchn           
  116.             jsr    primm            
  117.             .asc   13,"Download aborted",13, 0
  118.             jmp    abor             
  119.  
  120. ex          jsr    primm            
  121.             .asc   "File Exists! ", 0
  122.             lda    #$ff             
  123.             sta    exists           
  124.             bmi    g10              
  125.  
  126. exists      .byt   0                
  127.  
  128. get1ok      jsr    open             ;otherwise open the disk file
  129.             jsr    int0c            
  130.             sta    exists           
  131.             cmp    #20              
  132.             bcc    g10              
  133.             cmp    #63              
  134.             beq    ex               
  135.             jsr    primm            
  136.             .asc   13,"Error opening disk file...", 0
  137. pds         jsr    int0c            
  138.             jsr    int0d            
  139.             jmp    ccc              
  140.  
  141. g10         ldx    #8               ;and setup CHROUT
  142.             jsr    chkout           
  143. main1       jsr    getnxt           ;unsqueeze a byte
  144.             bcc    mai1             
  145.             jmp    noteot           ;error with huffman code...abort
  146.  
  147. mai1        bit    arcst            ;input past end?
  148.             bmi    main2            ;yes..next file
  149.             bit    exists           
  150.             bmi    main1            
  151.             jsr    chrout           ;otherwise send to output
  152.             bit    status           
  153.             bpl    main1            
  154.             jsr    clrchn           
  155.             jsr    primm            
  156.             .asc   13,"Error writing to disk. ", 0
  157.             jmp    pds              
  158.  
  159. main2       jsr    clrchn           ;done with this file...close it
  160.             lda    #8               
  161.             jsr    close            
  162.             jmp    skpah            
  163. skpahd      jsr    bytin            
  164. skpah       lda    bcount           
  165.             bne    skpahd           
  166.             lda    chkcrc           ;check if checksum is ok
  167.             cmp    crc              
  168.             bne    crcerr           
  169.             lda    chkcrc+1         
  170.             cmp    crc+1            
  171.             bne    crcerr           
  172.             jsr    primm            
  173.             .asc   "ok.", 0         
  174.             jmp    ggmain           
  175.  
  176. crcerr      jsr    primm            
  177.             .asc   "Checksum error?", 0 
  178. ggmain      jmp    main0            ;next file
  179.  
  180. abor        jsr    clrchn           ;exit...return to BASIC READY. prompt
  181.             lda    #8               
  182.             jsr    close            
  183.             lda    #0               
  184.             sta    $ff00            
  185.             ldx    svstk            
  186.             txs                     
  187.             jmp    term             
  188.  
  189. bcount      .byt   0                ;position within CBM block
  190. svstk       .byt   0                ;save stack pointer from entry
  191.  
  192. ;==============================================
  193. ; Read in archive header & initialize usq etc.
  194. ;==============================================
  195.  
  196. get1st      ldx    #cmsk-code       ;zero a bunch of things
  197.             lda    #0               
  198. g1st        sta    code,x           
  199.             dex                     
  200.             bpl    g1st             
  201.             lda    #0               
  202.             sta    ibit             
  203.             lda    writdv           ; d: for filename
  204.             sta    fn               
  205.             lda    #":"             
  206.             sta    fn+1             
  207.             jsr    bytin            ;get version
  208.             cmp    #2               ;must be 2
  209.             beq    been             ;abort if version isn't 2
  210. eoa         pla                     
  211.             pla                     
  212.             jmp    skpad            
  213.  
  214. been        inx                     ;.x=0
  215. newb1       jsr    bytin            ;get 1st part of header
  216.             sta    sqtyp,x          
  217.             inx                     
  218.             cpx    #9               
  219.             bne    newb1            
  220.             jsr    prtyp            
  221.             jsr    bytin            ;get fnlen
  222.             cmp    #17              ;check for bad filename length
  223.             bcs    eoa              ;its bad ... eof
  224.             tax                     ;save length
  225.             clc                     
  226.             adc    #4               
  227.             sta    fnlen            ;save length (+4 for 0: and ,type)
  228.             lda    #<unc            
  229.             sta    ucr+1            
  230.             lda    #<rl1            
  231.             sta    rlout+1          
  232.             lda    #>unc            
  233.             sta    ucr+2            
  234.             lda    #>rl1            
  235.             sta    rlout+2          
  236.             ldy    #0               
  237.             lda    #<fn             ;setup filename pointer for OPEN
  238.             sta    fnadr            
  239.             lda    #>fn             
  240.             sta    fnadr+1          
  241. gth2        jsr    bytin            ;continue getting filename
  242.             sta    fn+2,y           
  243.             jsr    chrout           
  244.             iny                     
  245.             dex                     
  246.             bne    gth2             
  247.             lda    #34              
  248.             jsr    chrout           
  249.             lda    #","             ;tag on ,type
  250.             sta    fn+2,y           
  251.             iny                     
  252.             lda    filtyp           
  253.             sta    fn+2,y           
  254.             pha                     
  255. tab18       lda    #" "             
  256.             jsr    chrout           
  257.             iny                     
  258.             cpy    #18              
  259.             bne    tab18            
  260.             pla                     
  261.             ldy    #4               
  262. tb18        cmp    spur,y           
  263.             beq    tb180            
  264.             dey                     
  265.             bne    tb18             
  266. tb180       lda    spur,y           
  267.             jsr    chrout           
  268.             lda    spur+5,y         
  269.             jsr    chrout           
  270.             lda    spur+10,y        
  271.             jsr    chrout           
  272.             lda    #" "             
  273.             jsr    chrout           
  274.             jsr    h2a              
  275.             lda    #8               ;open 8,8,1
  276.             tax                     
  277.             ldy    #1               ;sa=1 for write
  278.             sta    la               
  279.             stx    dv               
  280.             sty    sa               
  281.             jsr    bytin            ;ignore record length
  282.             jsr    bytin            ;and date
  283.             jsr    bytin            
  284. nou         jsr    chkhdr           ;abort to BASIC if error in header
  285.             bcc    nuo              
  286.             jmp    eoa              
  287.  
  288. spur        .asc   "?spur"          
  289.             .asc   "?erse"          
  290.             .asc   "?qgrl"          
  291.  
  292. nuo         ldy    sqtyp            
  293.             cpy    #5               ;pass 1 crunch?
  294.             bne    tpsq             ;no
  295.             lda    #$ff             ;yes...make length non zero
  296.             sta    len+2            
  297. tpsq        cpy    #2               ;squeezed file?
  298.             beq    dousq            ;yes-get encoding table
  299.             cpy    #4               ;squeezed+packed?
  300.             beq    dousq            ;yes-get encoding table
  301.             cpy    #1               ;packed?
  302.             bne    gth8             ;no stored or crunched
  303.             jsr    bytin            ;packed...ignore control character (always $fe)
  304. gth8        clc                     ;got header...return
  305.             rts                     
  306.  
  307. dousq       ldy    #0               ;get huffman encoding table
  308.             tya                     
  309. gth3        sta    c0,y             ;zero huffman codes and lengths
  310.             sta    c1,y             
  311.             sta    c2,y             
  312.             sta    l0,y             
  313.             iny                     
  314.             bne    gth3             
  315.             tax                     
  316. gth6        lda    #0               
  317.             sta    tmp1             
  318.             sta    tmp1+1           
  319.             sta    tmp1+2           
  320.             ldy    #5               
  321. gth4        jsr    bitin            ;get 5 bits (code length)
  322.             ror    a                
  323.             dey                     
  324.             bne    gth4             
  325.             ror    a                ;right justify
  326.             ror    a                
  327.             ror    a                
  328.             sta    ltmp             ;save code length
  329.             cmp    #25              ;code length > 24?
  330.             bcs    badcd            ;yes...bad encoding table
  331.             cmp    #0               ;length=0?
  332.             beq    gth7             ;yes then no code to get
  333.             tay                     
  334. gth5        jsr    bitin            ;else get Huffman code
  335.             rol    tmp              
  336.             rol    tmp+1            
  337.             rol    tmp+2            
  338.             dey                     
  339.             bne    gth5             
  340.             tay                     
  341. gth9        ror    tmp+2            ;justify it
  342.             ror    tmp+1            
  343.             ror    tmp              
  344.             rol    tmp1             
  345.             rol    tmp1+1           
  346.             rol    tmp1+2           
  347.             dey                     
  348.             bne    gth9             
  349.             jsr    sert             ;insert in table (sorted on code length)
  350. gth7        inx                     
  351.             bne    gth6             ;and repeat 256 times
  352.             dec    ncodsq           
  353.             clc                     
  354. badcd       rts                     ;got header
  355.  
  356. ;---------------------
  357. ; verify header is ok
  358. ;---------------------
  359.  
  360. abort       sec                     
  361.             rts                     
  362.  
  363. chkhdr      lda    sqtyp            ;must be 0-4
  364.             cmp    #6               
  365.             bcs    abort            
  366.             lda    filtyp           ;must be p,s, or u
  367.             cmp    #"p"             
  368.             beq    chok             
  369.             cmp    #"s"             
  370.             beq    chok             
  371.             cmp    #"u"             
  372.             bne    abort            
  373. chok        clc                     
  374.             rts                     
  375.  
  376. ;----------------------------------------------------------------
  377. ; subroutine. add huffman code to table sorted by length of code
  378. ;----------------------------------------------------------------
  379.  
  380. sert        stx    srtx+1           ;save .x=ascii for this code
  381.             ldy    #0               
  382.             lda    ltmp             ;code length read from header
  383. srt0        cpy    ncodsq           ;y=# of codes?
  384.             bne    srt1             ;no-maybe insert it
  385. srt00       sta    l0,y             ;else store it at end of table
  386.             lda    tmp1             ;code
  387.             sta    c0,y             
  388.             lda    tmp1+1           
  389.             sta    c1,y             
  390.             lda    tmp1+2           
  391.             sta    c2,y             
  392.             inc    ncodsq           
  393. srtx        ldx    #1               
  394.             txa                     
  395.             sta    g0,y             ;save ascii
  396.             rts                     
  397.  
  398. srt1        cmp    l0,y             
  399.             bcc    srt2             ;new code is smaller. insert it
  400.             iny                     
  401.             bne    srt0             ;always
  402.  
  403. srt2        sty    srt3+1           
  404.             ldy    #$fe             
  405. srt4        jsr    srt8             
  406.             dey                     
  407. srt3        cpy    #0               
  408.             bne    srt4             
  409.             jsr    srt8             
  410.             lda    ltmp             
  411.             jmp    srt00            
  412.  
  413. srt8        lda    l0,y             
  414.             sta    l0+1,y           
  415.             lda    g0,y             
  416.             sta    g0+1,y           
  417.             lda    c0,y             
  418.             sta    c0+1,y           
  419.             lda    c1,y             
  420.             sta    c1+1,y           
  421.             lda    c2,y             
  422.             sta    c2+1,y           
  423.             rts                     
  424.  
  425. sqtxt       .asc   "  stoR"         
  426.             .asc   "  pacK"         
  427.             .asc   "squee", $da     
  428.             .asc   "cruncH"         
  429.             .asc   "squasH"         
  430.             .asc   "cruncH"         
  431.  
  432. prtyp       jsr    primm            
  433.             .asc   13,"Un-", 0
  434.             ldy    #0               
  435.             ldx    sqtyp            
  436. pt1         dex                     
  437.             bmi    pt9              
  438. pt0         lda    sqtxt,y          
  439.             bmi    pt8              
  440.             iny                     
  441.             bne    pt0              
  442.  
  443. pt8         iny                     
  444.             bne    pt1              
  445.  
  446. pt9         lda    sqtxt,y          
  447.             pha                     
  448.             and    #$7f             
  449.             jsr    chrout           
  450.             iny                     
  451.             pla                     
  452.             bpl    pt9              
  453.             jsr    primm            
  454.             .asc   "ing ",34, 0
  455.             rts                     
  456.  
  457. ;-----------------------------
  458. ; Unsqueeze a byte subroutine
  459. ;-----------------------------
  460.  
  461. ; Use this routine to get one byte at a time from the archived file.
  462. ; The overflow flag, if set, indicates that there are no more bytes
  463. ;     to get from this archive entry. The previous one was the last
  464. ;     character of the squeezed file.
  465. ; The x and y registers are not affected by this routine
  466.  
  467. getnxt      stx    bast+1           
  468.             sty    basty+1          
  469.             jsr    dcln             ;check for end of file
  470.             bit    arcst            
  471.             bmi    bast0            ;eof...don't input past end
  472.  
  473. gxt         ldx    count            ;on a run?
  474.             beq    gnxt             ;no
  475.             jsr    rl33             ;yes - get repeated character
  476.             jmp    usq89            
  477.  
  478. gnxt        ldx    sqtyp            ;what type of file?
  479.             beq    usq88            ;stored..get byte
  480.             cpx    #1               
  481.             beq    usq88            ;same if packed
  482.             cpx    #5               
  483.             beq    crnch            
  484.             cpx    #3               
  485.             bne    sq               
  486. crnch       jsr    ucr              ;uncrunch a byte
  487.             bcs    bast0            ;end of file
  488.             ldx    sqtyp            
  489.             bcc    usq80            
  490.  
  491. sq          jsr    hufin            ;else get huffman code
  492.             bcs    bast             ;error reading huffman code
  493.             bcc    usq80            
  494. usq88       jsr    bytin            
  495. usq80       cpx    #0               ;was it stored?
  496.             beq    usq89            ;yes then we've got a byte
  497.             cpx    #2               ;was it squeezed?
  498.             beq    usq89            ;yes then we've got a byte
  499.             jsr    rlout            ;otherwise it might need to be un-packed
  500. usq89       jsr    dcbo             ;update checksum
  501. bast0       clc                     
  502. bast        ldx    #0               
  503. basty       ldy    #0               
  504.             bit    arcst            
  505.             rts                     
  506.  
  507. dcln        ldx    len              ;check for end of file
  508.             bne    dl0              
  509.             ldx    len+1            
  510.             bne    dl1              
  511.             ldx    len+2            
  512.             bne    dl2              
  513.             lda    #$ff             ;len is zero. flag eof
  514.             sta    arcst            
  515.             rts                     
  516.  
  517. dl2         dec    len+2            
  518. dl1         dec    len+1            
  519. dl0         dec    len              
  520.             rts                     
  521.  
  522. dcbo        pha                     ;update checksum
  523.             inc    crc2             
  524.             eor    crc2             
  525.             clc                     
  526.             adc    crc              
  527.             sta    crc              
  528.             bcc    dcbo1            
  529.             inc    crc+1            
  530. dcbo1       pla                     
  531.             rts                     
  532.  
  533. ;----------------------------------
  534. ; run-length byte output for arc/x
  535. ;----------------------------------
  536.  
  537. rlout       jmp    rl1              ;changes
  538.  
  539. rl1         cmp    #254             ;is it a control character?
  540.             beq    contrl           ;yes-get count,char
  541.             rts                     ;else send to output
  542.  
  543. contrl      lda    #<rl2            ;setup for count
  544.             sta    rlout+1          
  545.             lda    #>rl2            
  546.             sta    rlout+2          
  547. gnx         pla                     
  548.             pla                     
  549.             jmp    gnxt             
  550.  
  551. rl2         sta    prev             ;save count
  552.             lda    #<rl3            ;and setup for char
  553.             sta    rlout+1          
  554.             lda    #>rl3            
  555.             sta    rlout+2          
  556.             jmp    gnx              
  557.  
  558. rl3         sty    rl3y+1           ;save .y
  559.             ldy    #<rl33           
  560.             sty    rlout+1          
  561.             ldy    #>rl33           
  562.             sty    rlout+2          
  563.             ldy    prev             ;recall count
  564.             sty    count            
  565.             sta    prev             ;save char
  566. rl33        dec    count            ;send char count times
  567.             beq    rl3y             ;last one. reset rlout
  568.             bne    rl44             
  569.  
  570. rl3y        ldy    #0               
  571. rl0         lda    #<rl1            ;reset rlout
  572.             sta    rlout+1          
  573.             lda    #>rl1            
  574.             sta    rlout+2          
  575. rl44        lda    prev             
  576.             rts                     
  577.  
  578. ;----------------------------------------------
  579. ;read single byte from a file as a huffman code
  580. ;----------------------------------------------
  581.  
  582. hufin       lda    #0               ;reset length of code
  583.             sta    clen             
  584.             sta    hfi1+1           
  585.             sta    coff             
  586.             sta    cmsk             
  587.             inc    cmsk             
  588.             sta    hcode            
  589.             sta    hcode+1          
  590.             sta    hcode+2          
  591.             sty    hfiy+1           
  592.             stx    hfix+1           
  593. hfilp       jsr    bitin            ;get a bit
  594.             bcc    zbit             ;zero bit-just bump length
  595.             ldy    coff             ;else adjust code as well
  596.             lda    cmsk             
  597.             ora    hcode,y          
  598.             sta    hcode,y          
  599. zbit        asl    cmsk             ;adjust mask for next time
  600.             bcc    zb2              
  601.             rol    cmsk             
  602.             inc    coff             
  603. zb2         inc    clen             ;check if code length >23
  604.             lda    clen             
  605.             cmp    #24              
  606.             bcc    hfi1             
  607. nts         sec                     ;code too long...bad file
  608.             jmp    hfix             
  609.  
  610. hfi1        ldy    #0               
  611. hfi3        cmp    l0,y             ;check code length ok
  612.             beq    hfi9             ;length the same check it
  613.             bcc    hfilp            ;less-get another bit
  614.             bcs    nts              ;length > ... must be an error
  615. hfi9        ldx    c0,y             ;length ok. check if code is
  616.             cpx    hcode            
  617.             bne    hfi2             ;no
  618.             ldx    c1,y             
  619.             cpx    hcode+1          
  620.             bne    hfi2             
  621.             ldx    c2,y             
  622.             cpx    hcode+2          
  623.             bne    hfi2             
  624.             lda    g0,y             ;got it
  625.             clc                     
  626. hfix        ldx    #0               
  627. hfiy        ldy    #0               
  628.             rts                     
  629.  
  630. hfi2        iny                     ;try again for this length
  631.             beq    nts              ;error.. no code
  632.             sty    hfi1+1           
  633.             cpy    ncodsq           
  634.             bcc    hfi3             
  635.             beq    hfi3             
  636.             jmp    nts              ;none-error
  637.  
  638. ;-------
  639. ; bitin
  640. ;-------
  641.  
  642. bitin       dec    ibit             
  643.             bpl    bti1             
  644.             pha                     
  645.             lda    #7               
  646.             sta    ibit             
  647.             jsr    bytin            
  648.             sta    bite             
  649.             pla                     
  650. bti1        ror    bite             ;put bit in carry
  651.             rts                     
  652.  
  653. ;-------
  654. ; bytin
  655. ;-------
  656.  
  657. bytin       sty    biy+1            
  658.             stx    bix+1            
  659.             ldy    ibyt             ;offset into file
  660.             bne    bi1              ;buffer is full
  661.             bit    size+1           
  662.             bpl    bi1              
  663.             bit    xmoflg           ;first time?
  664.             bmi    xm1              ;no
  665.             dec    xmoflg           
  666.             jsr    xmo1             ;start Xmodem going
  667.             jmp    gotxmo           
  668.  
  669. xm1         jsr    xmo2             ;get subsequent blocks
  670. gotxmo      bcs    xmoerr           ;Xmodem error
  671.             lda    #<buffer         
  672.             sta    bi1+1            
  673.             lda    #>buffer         
  674.             sta    bi1+2            
  675.             lda    size             
  676.             sta    size+1           
  677.             ldy    #0               
  678. bi1         lda    buffer,y         
  679.             iny                     
  680.             bpl    dbc              
  681.             pha                     
  682.             dec    size+1           
  683.             clc                     
  684.             lda    bi1+1            
  685.             adc    #$80             
  686.             sta    bi1+1            
  687.             bcc    y0               
  688.             inc    bi1+2            
  689. y0          ldy    #0               
  690.             pla                     
  691. dbc         sty    ibyt             
  692.             inc    bcount           
  693.             ldy    bcount           
  694.             cpy    #254             
  695.             bne    biy              
  696.             ldy    #0               
  697.             sty    bcount           
  698. biy         ldy    #0               
  699. bix         ldx    #0               
  700.             rts                     
  701.  
  702. xmoerr      pha                     
  703.             jsr    clrchn           
  704.             pla                     
  705.             asl    a                
  706.             asl    a                
  707.             asl    a                
  708.             asl    a                
  709.             tay                     
  710.             ldx    #16              
  711. errlp       lda    errmsg,y         
  712.             jsr    chrout           
  713.             iny                     
  714.             dex                     
  715.             bne    errlp            
  716.             cpy    #16              
  717.             bne    gpl              
  718.             lda    #"e"             
  719.             jsr    chrout           
  720. gpl         pla                     
  721.             pla                     
  722.             jmp    abor             
  723.  
  724. errmsg      .asc   "Transfer Complet" 
  725.             .asc   "Lost Synch.     " 
  726.             .asc   "Remote Timed Out" 
  727.             .asc   "Remote Cancelled" 
  728.             .asc   "Too Many Errors " 
  729.  
  730. ;-------------------------
  731. ; lempel-zev decompressor
  732. ;-------------------------
  733.  
  734. ucr         jmp    unc              ;first time in
  735.  
  736. unc         jsr    lzwrst           ;reset string table
  737.             jsr    resstk           ;reset stack
  738.             jsr    codein           ;get 'code'
  739.             sta    oldcod           ;codein returns code in .a
  740.             sta    kay              ;first code is a byte
  741.             sta    finchr           
  742.             lda    code+1           ;oldcod=code
  743.             sta    oldcod+1         
  744.             lda    #<nxtcod         
  745.             sta    ucr+1            
  746.             lda    #>nxtcod         
  747.             sta    ucr+2            
  748.             lda    kay              
  749.             clc                     
  750.             rts                     
  751.  
  752. nxtcod      jsr    codein           ;next code
  753.             sec                     ;setup. test if code is defined (< ncodes)
  754.             sta    incode           ;incode=code
  755.             sbc    ncodes           
  756.             lda    code+1           
  757.             sta    incode+1         
  758.             sbc    ncodes+1         
  759.             bcc    nxtsym           ;carry clear. code was smaller.
  760.             lda    finchr           ;undefined code - special case.
  761.             sta    kay              
  762.             jsr    push             
  763.             lda    oldcod           
  764.             sta    code             
  765.             sta    omega            
  766.             lda    oldcod+1         
  767.             sta    code+1           
  768.             sta    omega+1          
  769.             lda    ncodes           
  770.             sta    incode           
  771.             lda    ncodes+1         
  772.             sta    incode+1         
  773. nxtsym      lda    code+1           ;is it just a byte?
  774.             beq    kaybyt           ;yes-end of string
  775.             lda    code             ;else extension(code) to stack
  776.             sta    poker            
  777.             lda    code+1           
  778.             ora    #>ext            
  779.             sta    poker+1          
  780.             jsr    peek             
  781.             jsr    push             
  782.             lda    poker+1          ;and code=prefix(code)
  783.             and    #$0f             
  784.             ora    #>pfxlo          
  785.             sta    poker+1          
  786.             jsr    peek             
  787.             sta    code             
  788.             lda    poker+1          
  789.             and    #$0f             
  790.             ora    #>pfxhi          
  791.             sta    poker+1          
  792.             jsr    peek             
  793.             sta    code+1           
  794.             bne    nxtsym           ;until just a byte
  795.  
  796. kaybyt      lda    #<eps            
  797.             sta    ucr+1            
  798.             lda    #>eps            
  799.             sta    ucr+2            
  800.             lda    code             ;code is now only a single byte
  801.             sta    kay              
  802.             sta    finchr           
  803.             clc                     
  804.             rts                     
  805.  
  806. eps         jsr    pull             ;get from top of stack
  807.             bcs    sie              ;stack is empty
  808.             rts                     
  809.  
  810. sie         lda    oldcod           
  811.             sta    omega            
  812.             lda    oldcod+1         
  813.             sta    omega+1          
  814.             jsr    lzadd            ;add omega,kay to table
  815.             lda    incode           ;oldcode=incode
  816.             sta    oldcod           
  817.             lda    incode+1         
  818.             sta    oldcod+1         
  819.             jmp    nxtcod           
  820.  
  821.  
  822. ;--------------------------------------
  823. ; subroutine. get code from input file
  824. ;--------------------------------------
  825.  
  826. codein      lda    #0               
  827.             sta    code             
  828.             ldy    cdlen            ;bit length of code
  829. ci0         jsr    bitin            ;read in code bitwise
  830.             rol    code             
  831.             rol    code+1           
  832.             dey                     
  833.             bne    ci0              
  834.             lda    code             ;test eof
  835.             bne    ci3              ;not 256
  836.             lda    code+1           
  837.             cmp    #>256            
  838.             bne    ci3              
  839.             pla                     ;else kill jsr & return to main loop
  840.             pla                     
  841.             lda    #0               
  842.             sta    len              
  843.             sta    len+1            
  844.             sta    len+2            
  845.             lda    #$ff             
  846.             sta    arcst            
  847.             lda    sqtyp            ;crunched in one pass?
  848.             cmp    #5               
  849.             bne    nt5              
  850.             ldy    #16              
  851. gchk        jsr    bitin            ;get checksum
  852.             rol    chkcrc           
  853.             rol    chkcrc+1         
  854.             dey                     
  855.             bne    gchk             
  856.             ldy    #40              
  857. gchk2       jsr    bitin            ;ignore length,user
  858.             dey                     
  859.             bne    gchk2            
  860. nt5         sec                     
  861.             rts                     
  862.  
  863. ci3         lda    code             ;and bump code length
  864.             jmp         bcl
  865.  
  866. ;------------------------------------------
  867. ; subroutine. push/pull char to/from stack
  868. ;------------------------------------------
  869.  
  870. push        ldy    #0               
  871.             sta    (stkptr),y       ;stkptr must be initialized
  872.             inc    stkptr           
  873.             bne    push0            
  874.             inc    stkptr+1         
  875. push0       rts                     
  876.  
  877. pull        lda    stkptr           ;check for empty stack
  878.             cmp    #<stack          
  879.             bne    pull0            
  880.             lda    stkptr+1         
  881.             cmp    #>stack          
  882.             bne    pull0            ;not empty
  883.             sec                     ;empty
  884.             rts                     
  885.  
  886. resstk      lda    #<stack          ;reset stack
  887.             sta    stkptr           
  888.             lda    #>stack          
  889.             sta    stkptr+1         
  890.             rts                     
  891.  
  892. pull0       lda    stkptr           
  893.             bne    pull1            
  894.             dec    stkptr+1         
  895. pull1       dec    stkptr           
  896.             ldx    #0               
  897.             lda    (stkptr,x)       
  898.             clc                     
  899.             rts                     
  900.  
  901. ;-----------------------------------
  902. ; lempel zev table reset subroutine
  903. ;-----------------------------------
  904.  
  905. lzwrst      lda    #<258            ;set number of codes to 258
  906.             ldy    #>258            ;(codes 256 and 257 are reserved)
  907.             sta    ncodes           
  908.             sty    ncodes+1         
  909. ;ldy #>256          ;256 of length 9 then 512 of length 10 etc.
  910.             sty    wtcl1            
  911.             lda    #<254            ;first time only 254 due to reserved codes.
  912.             ldy    #>254            
  913.             sta    wtcl             
  914.             sty    wtcl+1           
  915.             lda    #9               ;code length=9
  916.             sta    cdlen            
  917.             rts                     ;done
  918.  
  919. ;-------------------------------------------
  920. ; lempel-zev add string to table subroutine
  921. ;-------------------------------------------
  922.  
  923. lzadd       lda    ncodes+1         ;don't add if table is full
  924.             cmp    #$10             
  925.             bcc    lza1             ;its ok-add it
  926.             rts                     
  927.  
  928. lza1        sta    poker+1          ;prefix(ncodes)=omega
  929.             lda    ncodes           
  930.             sta    poker            
  931.             ldy    omega+1          
  932.             lda    #>pfxhi          
  933.             jsr    poke             
  934.             ldy    omega            
  935.             lda    #>pfxlo          
  936.             jsr    poke             
  937.             ldy    kay              ;extension(ncodes)=kay
  938.             lda    #>ext            
  939.             jsr    poke             
  940. lza3        inc    ncodes           ;and finally bump number of codes
  941.             bne    lza4             
  942.             inc    ncodes+1         
  943. lza4        rts                     
  944.  
  945. poke        sta    pk1+1            ;store .y in table .a at offset in poker
  946.             lda    #<poker          
  947.             sta    $02b9            
  948.             lda    poker+1          
  949.             and    #$0f             
  950. pk1         ora    #0               
  951.             sta    poker+1          
  952.             tya                     
  953.             ldy    #0               
  954.             ldx    #1               
  955.             jmp    $ff77            
  956.  
  957. ;-------------------------------
  958. ; subroutines. get/put pointers
  959. ;-------------------------------
  960.  
  961. getexc      lda    check+1          ;get extension(check)
  962.             and    #$0f             
  963.             ora    #>ext            
  964.             sta    poker+1          
  965.             lda    check            
  966.             sta    poker            
  967. peek        ldy    #0               
  968.             lda    #<poker          
  969.             ldx    #1               
  970.             jmp    $ff74            
  971.  
  972.  
  973. bcl         pha                     
  974.             lda    cdlen            ;is code 12 bits?
  975.             cmp    #12              
  976.             bcs    bclrt            ;if so don't adjust length
  977.             lda    wtcl             ;else count down
  978.             bne    bcl0             
  979.             dec    wtcl+1           
  980. bcl0        dec    wtcl             
  981.             lda    wtcl             
  982.             ora    wtcl+1           
  983.             bne    bclrt            
  984.             inc    cdlen            ;counted to zero. bump code length
  985.             asl    wtcl1            ;and do twice as many next time
  986.             lda    wtcl1            
  987.             sta    wtcl+1           
  988. bclrt       pla                     
  989.             rts                     
  990.  
  991. ;-------------------------------
  992. ;output a hex # in ascii decimal
  993. ;-------------------------------
  994. ; (3 byte number in 'len')
  995.  
  996. h2a         lda    len              
  997.             pha                     
  998.             lda    len+1            
  999.             pha                     
  1000.             lda    len+2            
  1001.             pha                     
  1002.             ldx    #0               ;initialize indexes
  1003.             ldy    #0               
  1004.             sty    h2atmp           
  1005. loop        lda    #"0"             ;initialize digit
  1006.             sta    ascii,x          
  1007. loop2       sec                     
  1008.             lda    len              
  1009.             sbc    table,y          
  1010.             pha                     ;increment the digit?
  1011.             lda    len+1            
  1012.             sbc    table+1,y        
  1013.             pha                     
  1014.             lda    len+2            
  1015.             sbc    table+2,y        
  1016.             bcc    nxdigt           ;branch if 'no'
  1017.             sta    len+2            
  1018.             pla                     
  1019.             sta    len+1            
  1020.             pla                     ;adjust the hex value
  1021.             sta    len              ;and increment the digit
  1022.             lda    #$ff             
  1023.             sta    h2atmp           
  1024.             inc    ascii,x          
  1025.             bne    loop2            
  1026.  
  1027. nxdigt      pla                     
  1028.             pla                     
  1029.             iny                     ;prepare for next digit
  1030.             iny                     
  1031.             iny                     
  1032.             iny                     
  1033.             inx                     
  1034.             bit    h2atmp           
  1035.             bmi    nadj             
  1036.             lda    #" "             
  1037.             sta    ascii-1,x        
  1038. nadj        cpx    #8               
  1039.             bcc    loop             
  1040. npr         nop                     
  1041.             ldy    #0               ;prepare to send number
  1042.             ldx    #0               
  1043. loop3       cpy    #2               
  1044.             beq    pcom             
  1045.             cpy    #5               
  1046.             bne    nocom            
  1047. pcom        lda    ascii-1,y        
  1048.             cmp    #" "             
  1049.             beq    nocom            
  1050.             lda    #","             
  1051. ppcom       pha                     
  1052.             inx                     
  1053. nocom       lda    ascii,y          
  1054.             cmp    #" "             
  1055.             beq    skpsp            
  1056.             pha                     
  1057.             inx                     
  1058. skpsp       iny                     
  1059.             cpy    #8               
  1060.             bcc    loop3            
  1061.             ldy    #8               
  1062. tp          lda    #" "             
  1063.             sta    pasc,y           
  1064.             dey                     
  1065.             bpl    tp               
  1066.             ldy    #8               
  1067. stp         pla                     
  1068.             sta    pasc,y           
  1069.             dey                     
  1070.             dex                     
  1071.             bne    stp              
  1072.             jsr    primm            
  1073. pasc        .asc   "1,234,567 bytes. ", 0 
  1074.             pla                     
  1075.             sta    len+2            
  1076.             pla                     
  1077.             sta    len+1            
  1078.             pla                     
  1079.             sta    len              
  1080.             rts                     ;done, return
  1081.  
  1082.  
  1083. table       .wor   38528, 152       
  1084.             .wor   16960, 15        
  1085.             .wor   34464, 1         
  1086.             .wor   10000, 0         
  1087.             .wor   1000, 0          
  1088.             .wor   100, 0           
  1089.             .wor   10, 0            
  1090.             .wor   1, 0             
  1091.  
  1092.  
  1093. h2atmp      .byt   0                
  1094.  
  1095. ;----------------------------------------------------------------------------
  1096. ; Xmodem Routines for ARCmodem
  1097. ;----------------------------------------------------------------------------
  1098.  
  1099. msg         .byt   0                ;error return. 0=ok 1=lost sync 3=aborted 4=to many err
  1100. block       .wor   0                ;expected block number
  1101. compl       .wor   0                ;expected block complement
  1102. chk         .wor   0                ;expected checksum or CRC
  1103. mychk       .wor   0                ;calculated checksum or CRC
  1104. error       .byt   0                ;error count
  1105. tries       .byt   0                ;retry counter
  1106. cancan      .byt   0                ;can counter
  1107.  
  1108. ;---------------------------------------------------
  1109. ; Initialize Xmodem download. Get the ball rolling.
  1110. ;---------------------------------------------------
  1111.  
  1112. xmo1        ldy    #1               ;block=buffer pointer=1
  1113.             sty    block            
  1114.             dey                     
  1115.             sty    error            
  1116.             sty    mode             ;mode. $ff=checksum 0=crc
  1117.             jsr    $130c            ;turn on RS232
  1118.             lda    #"c"             ;request CRC mode
  1119.             jsr    wait             
  1120.             bcc    got1             ;got something. Go on
  1121.             dec    mode             ;else revert to checksum mode
  1122. sendnk      lda    #nak             ;send NAK and wait for start
  1123.             jsr    wait             
  1124.             bcc    got1             ;got something
  1125. nrsp        jsr    primm            ;else timeout
  1126.             .asc   13,"No response from remote...aborting",13,0
  1127.             jmp    int0e            
  1128.  
  1129. got1        pha                     
  1130.             lda    size             
  1131.             cmp    #7               
  1132.             beq    nt7              
  1133.             lda    #"X"             
  1134.             .byt   $2c              
  1135. nt7         lda    #"Y"             
  1136.             sta    xmt+1            
  1137.             jsr    primm            
  1138. xmt         .asc   13,"Xmodem transfer...", 0
  1139.             bit    mode             
  1140.             bmi    ckmode           
  1141.             jsr    primm            
  1142.             .asc   "CRC mode.",13,0
  1143.             jmp    got11            
  1144.  
  1145. ckmode      jsr    primm            
  1146.             .asc   "Checksum mode.",13,0
  1147. got11       pla                     
  1148.             cmp    #soh             
  1149.             bne    nrsp             
  1150. ag          ldx    #1               ;got SOH. Get block and complement
  1151.             jsr    getcom           
  1152.             bcs    short            ;timeout
  1153.             sta    block+1          
  1154.             jsr    getcom           
  1155.             bcs    short            
  1156.             sta    compl+1          
  1157.             ldy    #0               
  1158.             sty    mychk            
  1159.             sty    mychk+1          
  1160.             lda    #<buffer         
  1161.             sta    stb+1            
  1162.             lda    #>buffer         
  1163.             sta    stb+2            
  1164.             lda    size             
  1165.             sta    size+1           
  1166. rchar0      ldy    #0               
  1167. rchar       jsr    getcom           
  1168.             bcs    short            
  1169. stb         sta    buffer,y         
  1170.             bit    mode             
  1171.             bmi    updchk           
  1172.             jsr    updcrc           
  1173.             jmp    mr               
  1174.  
  1175. updchk      clc                     
  1176.             adc    mychk            
  1177.             sta    mychk            
  1178. mr          iny                     
  1179.             bpl    rchar            
  1180.             dec    size+1           
  1181.             bmi    btg              
  1182.             clc                     
  1183.             lda    stb+1            
  1184.             adc    #$80             
  1185.             sta    stb+1            
  1186.             bcc    rchar0           
  1187.             inc    stb+2            
  1188.             jmp    rchar0           
  1189.  
  1190. btg         jsr    getcom           ;get checksum
  1191.             bit    mode             ;or is it CRC?
  1192.             bmi    short            ;its checksum. Only one then
  1193.             bcs    short            ;nothing there..short block
  1194.             sta    chk              ;save CRC high
  1195.             jsr    getcom           ;and get low
  1196.             sta    chk+1            
  1197.             lda    chk              
  1198. short       bcs    badblk           ;short block
  1199.             cmp    chk              ;checksum ok?
  1200.             bne    badblk           ;no. retransmit
  1201.             bit    mode             
  1202.             bmi    notcrc           
  1203.             lda    chk+1            
  1204.             cmp    mychk+1          
  1205.             bne    badblk           
  1206. notcrc      lda    block+1          ;block/complement ok?
  1207.             clc                     
  1208.             adc    compl+1          
  1209.             cmp    #$ff             
  1210.             beq    next2            ;maybe
  1211. badblk      inc    error            ;bump error count
  1212.             lda    error            
  1213.             cmp    #11              ;and abort if too many
  1214.             beq    bad4             
  1215.             lda    #nak             ;else try again
  1216. gwait       jsr    wait             
  1217.             bcs    bad2             
  1218.             cmp    #soh             
  1219.             bne    nag              
  1220.             jmp    ag               
  1221.  
  1222. nag         cmp    #can             
  1223.             beq    bad3             
  1224.             lda    #0               ;otherwise gotta be EOT
  1225.             .byt   $2c              
  1226. bad1        lda    #1               ;Error 1=lost synch
  1227.             .byt   $2c              
  1228. bad2        lda    #2               ;Error 2=time out
  1229.             .byt   $2c              
  1230. bad3        lda    #3               ;Error 3=cancel
  1231.             .byt   $2c              
  1232. bad4        lda    #4               ;Error 4=too many errors
  1233.             sec                     
  1234.             rts                     
  1235.  
  1236. next2       lda    block+1          ;make sure block is correct one
  1237.             cmp    block            
  1238.             bne    cant             ;it is...use this block
  1239.             clc                     
  1240.             rts                     
  1241.  
  1242. cant        ldx    block            ;is it the previous block?
  1243.             dex                     
  1244.             cpx    block+1          
  1245.             beq    blkerr           ;yes. ACK musta got hit..re-ACK it
  1246.             lda    #can             ;otherwise lost sync...gotta abort
  1247.             jsr    comout           
  1248.             jmp    bad1             
  1249.  
  1250. ; Re-enter Xmodem
  1251.  
  1252. xmo2        inc    block            
  1253.             lda    #0               
  1254.             sta    error            
  1255. blkerr      lda    #ack             ;re-ack block and try again
  1256.             jmp    gwait            
  1257.  
  1258. xmoflg      .byt   0                ;0=first, $ff=subsequent blocks
  1259.  
  1260. ;---------------------------------------------------------------
  1261. ; Subroutine: wait for char from RS232.
  1262. ;             .x=bcd number of seconds before timeout
  1263. ;             carry=0 if char is ok, or 1 if timeout has occured
  1264. ;---------------------------------------------------------------
  1265.  
  1266. getcom      lda    $dc0b            ;stop clock
  1267.             lda    #0               ;reset seconds
  1268.             sta    $dc09            
  1269.             sta    $dc08            ;resumes clock
  1270.             sty    gcy+1            
  1271. gc0         jsr    comin            ;get from RS232
  1272.             bcc    gcy              ;got something. RTS
  1273.             cpx    $dc09            ;time out?
  1274.             bne    gc0              ;not yet. try again
  1275. gcy         ldy    #0               ;done
  1276.             rts                     
  1277.  
  1278. ;------------------------------------------------------
  1279. ; Subroutine: wait for SOH, CAN-CAN or EOT
  1280. ;------------------------------------------------------
  1281. ; Carry = 1 if 3 second time out occurs (resend ACK)
  1282. ;         0 if SOH was recieved
  1283. ; Otherwise the transfer is aborted with CAN-CAN or EOT
  1284.  
  1285. wait        sta    acknak           ;save ACK or NAK
  1286. wagin       lda    acknak           ;send it
  1287.             jsr    comout           
  1288.             jsr    flush            
  1289.             lda    #2               
  1290.             sta    tries            
  1291. waitso      ldx    #1               ;reset can-can counter
  1292.             stx    cancan           
  1293. wso0        ldx    #3               ;wait 3 seconds for a response
  1294.             jsr    getcom           
  1295.             bcs    tryagn           ;timeout...try again maybe
  1296.             cmp    #can             
  1297.             beq    wso1             
  1298.             cmp    #eot             
  1299.             beq    wso2             
  1300.             cmp    #sstx            
  1301.             beq    set7             
  1302.             cmp    #soh             
  1303.             bne    waitso           ;ignore anything else
  1304.             lda    #0               
  1305.             .byt   $2c              
  1306. set7        lda    #7               
  1307.             sta    size             
  1308.             lda    #soh             
  1309.             clc                     
  1310.             rts                     
  1311.  
  1312.  
  1313. wso1        dec    cancan           ;was previous char a can?
  1314.             bpl    wso0             ;no
  1315. wso2        pha                     
  1316.             lda    #ack             ;yes. ACK the CAN
  1317.             jsr    comout           
  1318.             pla                     
  1319.             clc                     
  1320.             rts                     
  1321.  
  1322. tryagn      dec    tries            ;try up to 3 times
  1323.             bpl    wagin            
  1324.             lda    #can             ;tried 3 times...abort
  1325.             jsr    comout           
  1326.             sec                     
  1327.             rts                     
  1328.  
  1329. ;------------------------
  1330. ; subroutine: Update CRC
  1331. ;------------------------
  1332.  
  1333. updcrc      pha                     ;save char
  1334.             sty    uc+1             ;save .y
  1335.             eor    mychk            
  1336.             tay                     
  1337.             lda    crclo,y          
  1338.             eor    mychk+1          
  1339.             sta    mychk            
  1340.             lda    crchi,y          
  1341.             sta    mychk+1          
  1342. uc          ldy    #0               
  1343.             pla                     
  1344.             rts                     
  1345.  
  1346.  
  1347. ;CRC table. High bytes.
  1348.  
  1349. crchi       .byt   $00, $21, $42, $63, $84, $a5, $c6, $e7 
  1350.             .byt   $08, $29, $4a, $6b, $8c, $ad, $ce, $ef 
  1351.             .byt   $31, $10, $73, $52, $b5, $94, $f7, $d6 
  1352.             .byt   $39, $18, $7b, $5a, $bd, $9c, $ff, $de 
  1353.             .byt   $62, $43, $20, $01, $e6, $c7, $a4, $85 
  1354.             .byt   $6a, $4b, $28, $09, $ee, $cf, $ac, $8d 
  1355.             .byt   $53, $72, $11, $30, $d7, $f6, $95, $b4 
  1356.             .byt   $5b, $7a, $19, $38, $df, $fe, $9d, $bc 
  1357.             .byt   $c4, $e5, $86, $a7, $40, $61, $02, $23 
  1358.             .byt   $cc, $ed, $8e, $af, $48, $69, $0a, $2b 
  1359.             .byt   $f5, $d4, $b7, $96, $71, $50, $33, $12 
  1360.             .byt   $fd, $dc, $bf, $9e, $79, $58, $3b, $1a 
  1361.             .byt   $a6, $87, $e4, $c5, $22, $03, $60, $41 
  1362.             .byt   $ae, $8f, $ec, $cd, $2a, $0b, $68, $49 
  1363.             .byt   $97, $b6, $d5, $f4, $13, $32, $51, $70 
  1364.             .byt   $9f, $be, $dd, $fc, $1b, $3a, $59, $78 
  1365.             .byt   $88, $a9, $ca, $eb, $0c, $2d, $4e, $6f 
  1366.             .byt   $80, $a1, $c2, $e3, $04, $25, $46, $67 
  1367.             .byt   $b9, $98, $fb, $da, $3d, $1c, $7f, $5e 
  1368.             .byt   $b1, $90, $f3, $d2, $35, $14, $77, $56 
  1369.             .byt   $ea, $cb, $a8, $89, $6e, $4f, $2c, $0d 
  1370.             .byt   $e2, $c3, $a0, $81, $66, $47, $24, $05 
  1371.             .byt   $db, $fa, $99, $b8, $5f, $7e, $1d, $3c 
  1372.             .byt   $d3, $f2, $91, $b0, $57, $76, $15, $34 
  1373.             .byt   $4c, $6d, $0e, $2f, $c8, $e9, $8a, $ab 
  1374.             .byt   $44, $65, $06, $27, $c0, $e1, $82, $a3 
  1375.             .byt   $7d, $5c, $3f, $1e, $f9, $d8, $bb, $9a 
  1376.             .byt   $75, $54, $37, $16, $f1, $d0, $b3, $92 
  1377.             .byt   $2e, $0f, $6c, $4d, $aa, $8b, $e8, $c9 
  1378.             .byt   $26, $07, $64, $45, $a2, $83, $e0, $c1 
  1379.             .byt   $1f, $3e, $5d, $7c, $9b, $ba, $d9, $f8 
  1380.             .byt   $17, $36, $55, $74, $93, $b2, $d1, $f0 
  1381.  
  1382. ;CRC table. Low bytes.
  1383.  
  1384. crclo       .byt   $00, $10, $20, $30, $40, $50, $60, $70 
  1385.             .byt   $81, $91, $a1, $b1, $c1, $d1, $e1, $f1 
  1386.             .byt   $12, $02, $32, $22, $52, $42, $72, $62 
  1387.             .byt   $93, $83, $b3, $a3, $d3, $c3, $f3, $e3 
  1388.             .byt   $24, $34, $04, $14, $64, $74, $44, $54 
  1389.             .byt   $a5, $b5, $85, $95, $e5, $f5, $c5, $d5 
  1390.             .byt   $36, $26, $16, $06, $76, $66, $56, $46 
  1391.             .byt   $b7, $a7, $97, $87, $f7, $e7, $d7, $c7 
  1392.             .byt   $48, $58, $68, $78, $08, $18, $28, $38 
  1393.             .byt   $c9, $d9, $e9, $f9, $89, $99, $a9, $b9 
  1394.             .byt   $5a, $4a, $7a, $6a, $1a, $0a, $3a, $2a 
  1395.             .byt   $db, $cb, $fb, $eb, $9b, $8b, $bb, $ab 
  1396.             .byt   $6c, $7c, $4c, $5c, $2c, $3c, $0c, $1c 
  1397.             .byt   $ed, $fd, $cd, $dd, $ad, $bd, $8d, $9d 
  1398.             .byt   $7e, $6e, $5e, $4e, $3e, $2e, $1e, $0e 
  1399.             .byt   $ff, $ef, $df, $cf, $bf, $af, $9f, $8f 
  1400.             .byt   $91, $81, $b1, $a1, $d1, $c1, $f1, $e1 
  1401.             .byt   $10, $00, $30, $20, $50, $40, $70, $60 
  1402.             .byt   $83, $93, $a3, $b3, $c3, $d3, $e3, $f3 
  1403.             .byt   $02, $12, $22, $32, $42, $52, $62, $72 
  1404.             .byt   $b5, $a5, $95, $85, $f5, $e5, $d5, $c5 
  1405.             .byt   $34, $24, $14, $04, $74, $64, $54, $44 
  1406.             .byt   $a7, $b7, $87, $97, $e7, $f7, $c7, $d7 
  1407.             .byt   $26, $36, $06, $16, $66, $76, $46, $56 
  1408.             .byt   $d9, $c9, $f9, $e9, $99, $89, $b9, $a9 
  1409.             .byt   $58, $48, $78, $68, $18, $08, $38, $28 
  1410.             .byt   $cb, $db, $eb, $fb, $8b, $9b, $ab, $bb 
  1411.             .byt   $4a, $5a, $6a, $7a, $0a, $1a, $2a, $3a 
  1412.             .byt   $fd, $ed, $dd, $cd, $bd, $ad, $9d, $8d 
  1413.             .byt   $7c, $6c, $5c, $4c, $3c, $2c, $1c, $0c 
  1414.             .byt   $ef, $ff, $cf, $df, $af, $bf, $8f, $9f 
  1415.             .byt   $6e, $7e, $4e, $5e, $2e, $3e, $0e, $1e 
  1416.  
  1417. ;====================================
  1418. ; Data tables for ARC modem download
  1419. ;====================================
  1420.  
  1421.  
  1422. ; These bytes get set to zero at each entry header
  1423.  
  1424. code        *=*+2                   ;input code
  1425. oldcod      *=*+2                   ;previous code
  1426. finchr      *=*+1                   
  1427. incode      *=*+2                   ;2 bytes
  1428. wtcl        *=*+2                   ;2 bytes ... when to change code length
  1429. ncodes      *=*+2                   ;2 bytes ... number of codes in string table
  1430. wtcl1       *=*+1                   ;copy of wtcl+1
  1431. cdlen       *=*+1                   ;length of lzw code in bits
  1432. omega       *=*+2                   ;temp ... current prefix
  1433. kay         *=*+1                   ;temp ... current extension
  1434. sqtyp       *=*+1                   ;0=store 1=pack 2=squeeze 3,5=crunch 4=squash
  1435. chkcrc      *=*+2                   ;checksum read from archive
  1436. len         *=*+3                   ;unsqueezed length in bytes (lo-high)
  1437. sqb         *=*+2                   ;squeezed length in 254 byte blocks
  1438. filtyp      *=*+1                   ;file type (p,s,u or r)
  1439. crc         *=*+2                   ;new calculated checksum
  1440. hcode       *=*+3                   ;huffman code
  1441. ncodsq      *=*+1                   ;number of huffman codes
  1442. tmp1        *=*+3                   ;temp for hufin
  1443. tmp         *=*+3                   ;temp
  1444. ibit        *=*+1                   ;input bit
  1445. ibytx       *=*+1                   ;input byte
  1446. arcst       *=*+1                   ;eof flag
  1447. count       *=*+1                   ;run length coding count
  1448. crc2        *=*+1                   ;temp
  1449. coff        *=*+1                   ;bit offset
  1450. prev        *=*+1                   ;rl char for output
  1451. clen        *=*+1                   ;hufman code length
  1452.  
  1453.  
  1454. bite        *=*+1                   ;bitin buffer
  1455. ltmp        *=*+1                   
  1456. cmsk        *=*+1                   
  1457. fnl         *=*+7                   
  1458. ftyp        *=*+1                   
  1459. ldad        *=*+2                   
  1460. prtflg      *=*+1                   
  1461. hex         *=*+3                   ;misc for 'dodir'
  1462. sqqb        *=*+2                   
  1463. ascii       *=*+8                   
  1464.             *=*+2                   
  1465. hexx        *=*+2                   
  1466.             *=*+1                   
  1467. delta       *=*+2                   
  1468. width       *=*+1                   
  1469. acknak      *=*+1                   
  1470. ibyt        *=*+1                   
  1471. mode        *=*+1                   ;xmodem 0=CRC $ff=Checksum
  1472. writdv      *=*+1                   ;save destination drive
  1473. size        *=*+2                   ;packet size 0 or 7
  1474.  
  1475.             *      = $4000          
  1476.  
  1477. ; Lempel Zev Decompressor tables
  1478.  
  1479. pfxlo       *=*+4096                  ;lempel-zev lo byte of prefix
  1480. pfxhi       *=*+4096                  ;lempel-zev hi byte of prefix
  1481. ext         *=*+4096                  ;lempel-zev extension
  1482.  
  1483. ;USQ stuff
  1484.  
  1485. l0          *=*+256                  
  1486. c0          *=*+256                  
  1487. c1          *=*+256                  
  1488. c2          *=*+256                  
  1489. g0          *=*+256                  
  1490. buffer      *=*+1024                  
  1491.  
  1492. stack       *=*+256                  ;lz decompressor stack
  1493.  
  1494.             .end                    
  1495.  
  1496.