home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / atarist / astuud.asm < prev    next >
Assembly Source File  |  2020-01-01  |  8KB  |  308 lines

  1. *  This is a UUDECODE program for the ATARI ST.
  2. *  It can be assembled using the public domain assembler, AS68;
  3. *  since this assembler does NOT assemble register shifts and rotates,
  4. *  all such shifts and rotates have been pre-assembled by hand.
  5. * Disassemble a file....
  6. *  ... print an explanatory message ...
  7. pfile   pea     openm
  8.         move.w  #pline, -(a7)
  9.         trap    #1
  10.         addq.l  #6, a7
  11. * ... get the line ...
  12.         lea     buffer, a1
  13.         move.l  #blen, d2
  14.         bsr     getln
  15. * Open file!
  16.         clr.w   -(a7)           Open for reading
  17.         pea     buffer
  18.         move.w  #fopen, -(a7)
  19.         trap    #1
  20.         addq.l  #8, a7
  21. * Check for error...
  22.         tst.w   d0
  23.         bmi     error
  24.         move.w  d0, d1          Save handle number
  25. * Skip over first 10 characters ('begin xxx ')
  26.         clr.w   -(a7)
  27.         move.w  d1, -(a7)
  28.         move.l  #10, -(a7)
  29.         move.w  #lseek, -(a7)
  30.         trap    #1
  31.         add.l   #10, a7
  32.         tst.l   d0
  33.         bmi     erroro
  34. * Initialize I/O pointers
  35.         bsr     init
  36. * Get filename (terminated with CR/LF)
  37.         lea     buf2, a1
  38. gfloop  bsr     getch
  39.         cmp.b   #$0d, d7
  40.         beq     gfdone
  41.         move.b  d7, (a1)+
  42.         bra     gfloop
  43. gfdone  clr.b   (a1)
  44.         bsr     getch           Discard $0a
  45. *
  46. * Open file!
  47. *
  48.         clr.w   -(a7)           R/W file will be created
  49.         pea     buf2
  50.         move.w  #fcreat, -(a7)
  51.         trap    #1
  52.         addq.l  #8, a7
  53. * Check for error...
  54.         tst.w   d0
  55.         bmi     erroro
  56.         move.w  d0, d2          Save handle number
  57. * ... now the fun begins ...
  58. * GEM uses a0; input buffer pointers a2-a3; output ptrs a4-a5; stack ptr a7
  59. * GEM uses d0; d3=byte count in this line; d4=byte count in this 4-character
  60. * group -or- char count while reading;
  61. *  d5=group of 4 characters -or- 3 bytes.
  62. * Scratch in d7.
  63. *
  64. * LINE LOOP
  65. *
  66. * Get count.  If 0, we are done.
  67. loop    bsr     getnn
  68.         sub.b   #$20, d7        Subtract space
  69.         beq     done
  70. * Otherwise, get that many characters.
  71.         clr.w   d3              High byte 0 for "dbf"
  72.         move.b  d7, d3
  73.         subq.w  #1, d3          Correct for "dbf"
  74.         bsr     init3           Reset counters
  75. loop3   bsr     getch3
  76.         bsr     prtch
  77.         dbf     d3, loop3
  78.         bsr     skipnl          Skip over junk + $0d/$0a
  79.         bra     loop
  80. *
  81. *  Initialize state of 3-characters.
  82. *
  83. init3   clr.w   d4
  84.         rts
  85. *
  86. *  Get another character from a group of 3.
  87. *
  88. getch3  tst.w   d4
  89.         bne     get32
  90. * Read in another group of 4 into d3; reset count to 3.
  91.         move.w  #3, d4
  92.         clr.l   d5
  93. *et3l   lsl.l   #6, d5
  94. get3l   dc.w    $ed8d
  95.         bsr     getnn
  96.         sub.b   #$20, d7
  97.         or.b    d7, d5
  98.         dbf     d4, get3l
  99.         move.w  #3, d4          Set byte count
  100.         swap    d5              Pattern from [0123] to [2301]
  101. * Get a character out of d3, decrement count in d2, & return!
  102. get32   move.b  d5, d7
  103. *       rol.l   #8, d5
  104.         dc.w    $e19d
  105.         subq.w  #1, d4
  106.         rts
  107. * Read until we come to a newline; then skip over $0d/$0a.
  108. skipnl  bsr     getch
  109.         cmp.b   #$0d, d7
  110.         bne     skipnl
  111.         bra     getch
  112. *
  113. *  Buffered I/O subroutines.  Input buffer pointer a2, end ptr in a3;
  114. *                             output buffer pointer a4, end prt a5.
  115. *
  116. *  Sets up.
  117. init    lea     inpend, a2
  118.         lea     inpend, a3
  119.         lea     outbuf, a4
  120.         lea     outend, a5
  121.         rts
  122. *  Get a character in d7.b, EXCEPT that if we are at a newline, get a blank
  123. *  instead.
  124. getnn   cmp.l   a3, a2
  125.         bcc     getrn
  126.         cmp.b   #$0d, (a2)
  127.         beq     getsn
  128.         move.b  (a2)+, d7
  129.         rts
  130. getsn   move.b  #$20, d7
  131.         rts
  132. getrn   bsr     getrec
  133.         bra     getnn
  134. *  Gets a character in d7.b.
  135. getch   cmp.l   a3, a2
  136.         bcc     getr
  137.         move.b  (a2)+, d7
  138.         rts
  139. getr    bsr     getrec
  140.         bra     getch
  141. *
  142. * Get a new record into the buffer.
  143. getrec  pea     inpbuf
  144.         move.l  #inplen, -(a7)
  145.         move.w  d1, -(a7)
  146.         move.w  #fread, -(a7)
  147.         trap    #1
  148.         add.l   #12, a7
  149.         tst.l   d0
  150.         bmi     error2
  151.         beq     done            No bytes read, file over, done.
  152. * Actual number of bytes read in d0!
  153.         lea     inpbuf, a2
  154.         lea     0(a2, d0.l), a3
  155.         rts
  156. *
  157. *  Prints byte in d7.b.
  158. prtch   cmp.l   a5, a4
  159.         bcc     putr
  160.         move.b  d7, (a4)+
  161.         rts
  162. putr    bsr     putrec
  163.         bra     prtch
  164. *
  165. * Dump buffer out.
  166. * Compute number of bytes to put out.
  167. putrec  lea     outbuf, a5
  168.         move.l  a5, -(a7)
  169.         sub.l   a5, a4
  170.         move.l  a4, -(a7)
  171.         move.w  d2, -(a7)
  172.         move.w  #fwrite, -(a7)
  173.         trap    #1
  174.         add.l   #12, a7
  175.         tst.l   d0
  176.         bmi     error2
  177.         lea     outbuf, a4
  178.         lea     outend, a5
  179.         rts
  180. *
  181. *
  182. *   We come here in case of error.
  183. error   bsr     pmsg
  184.         bra     xit
  185. * Here for error after opening 1 file.
  186. erroro  bsr     pmsg
  187.         bsr     close1
  188.         bra     xit
  189. * Here for error after opening  2 files.
  190. error2  bsr     pmsg
  191.         bsr     close1
  192.         bsr     close2
  193.         bra     xit
  194. * Here for normal end.  Notice that we flush output buffer.
  195. done    bsr     putrec
  196.         bsr     close1
  197.         bsr     close2
  198. xit     clr.w   -(a7)
  199.         trap    #1
  200. *
  201. pmsg    pea     msg
  202.         move.w  #pline,-(a7)
  203.         trap    #1
  204.         addq.l  #6,a7
  205.         rts
  206. *
  207. close1  move.w  d1, -(a7)
  208.         move.w  #fclose, -(a7)
  209.         trap    #1
  210.         addq.l  #4, a7
  211.         rts
  212. *
  213. close2  move.w  d2, -(a7)
  214.         move.w  #fclose, -(a7)
  215.         trap    #1
  216.         addq.l  #4, a7
  217.         rts
  218. *
  219. *
  220. *
  221. *   This subroutine reads a line of input into the buffer at a1.
  222. *   Maximum buffer length should be passed in d2.  Actual count is
  223. *   returned in d1.  The buffer should have one more byte than d2
  224. *   (to allow for a zero at the end.)
  225. getln   movem.l d0/a0, -(a7)
  226. * Clear char count
  227.         clr.l   d1
  228. glloop  move.w  #conine,-(a7)
  229.         trap    #1
  230.         addq.l  #2, a7
  231. * A BS?
  232.         cmp.b   #$08, d0
  233.         beq     bs
  234. * A CR?
  235.         cmp.b   #$0d, d0
  236.         beq     crret
  237. * Just a plain character ... are we at EOL?
  238.         cmp.l   d1, d2
  239. * Yes, ignore it.
  240.         beq     glloop
  241. *  Otherwise, store it...
  242.         move.b  d0, 0(a1, d1.l)
  243.         addq.l  #1, d1
  244. * ... and echo.
  245.         bsr     echo
  246.         bra     glloop
  247. * A BS --- are we at start of line?
  248. bs      tst.l   d1
  249. *  If so, ignore keystroke.
  250.         beq     glloop
  251. * Otherwise, decrement counter...
  252.         subq.l  #1, d1
  253. * ... print BS, space, BS to wipe out char
  254.         move.b  #$08, d0
  255.         bsr     echo
  256.         move.b  #$20, d0
  257.         bsr     echo
  258.         move.b  #$08, d0
  259.         bsr     echo
  260.         bra     glloop
  261. * A CR --- echo & return.
  262. crret   bsr     echo
  263.         move.b  #$0a, d0
  264.         bsr     echo
  265.         clr.b   0(a1, d1.l)
  266.         movem.l (a7)+, d0/a0
  267.         rts
  268. *
  269. *
  270. *   Echo --- echoes a character in d0 to the screen.  Destroys d0 & a0.
  271. echo    move.w  d0, -(a7)
  272.         move.w  #conout, -(a7)
  273.         trap    #1
  274.         addq.l  #4, a7
  275.         rts
  276. *
  277. *
  278. *
  279. openm   dc.b    'Enter filename to read: '
  280.         dc.b    0
  281. msg     dc.b    'TOS error occurred!', 13, 10
  282.         dc.b    0
  283. buffer  ds.b    51
  284. buf2    ds.b    51
  285. blen    equ     50
  286. * Buffer for reading from file
  287. inpbuf  ds.b    $400
  288. inpend  ds.b    0
  289. inplen  equ     $400
  290. * ... and for writing ...
  291. outbuf  ds.b    $400
  292. outend  ds.b    0
  293. outlen  equ     $400
  294. * Codes for GEMDOS
  295. conout  equ     $02
  296. rawcon  equ     $06
  297. conine  equ     $07
  298. pline   equ     $09
  299. fcreat  equ     $3c
  300. fopen   equ     $3d
  301. fclose  equ     $3e
  302. fread   equ     $3f
  303. fwrite  equ     $40
  304. lseek   equ     $42
  305.         end
  306.  
  307.  
  308.