home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 116.lha / Web / atow.w < prev    next >
Encoding:
Text File  |  1986-11-20  |  7.8 KB  |  462 lines

  1.  
  2.     idnt  Atow
  3.  
  4.     section  one
  5.  
  6. 1. This little utility partially converts assembly
  7.    programs to web format.
  8.                          --- Greg Lee, July 1, 1986
  9.  
  10.     --Macro definitions for assembler
  11.     --EQU statements for assembler
  12.     --Definitions of library references
  13.  
  14. 2. Here is where execution starts.
  15.  
  16. Main
  17.  
  18.        define   push  -(SP).L
  19.        define   pop    (SP)+
  20.        define   chr    D0.B
  21.  
  22.     --Get file name from input line
  23.     --Open input and output files
  24.  
  25.  {
  26.     --Read a line
  27.     tst.l     l_length
  28.     beq      windup
  29.  
  30.     a1    =    ^obuf
  31.     a2.l    =    input_line
  32.  
  33.     chr    =    (input_line)+
  34.     chr    ?    9
  35.     = «    chr  =  ' '  »
  36.  
  37.     chr    ?    ' '
  38.     = {    {  (input_line)+.b  ?  ' '
  39.            beq    }
  40.  
  41.         input_line    -=    1
  42.         --Check for equals instruction
  43.         bne    ¶
  44.         d2.b    =    chr
  45.  
  46.         d4.b    =    (input_line)
  47.         d4.b    ?    'q'
  48.         = «    input_line    +=    1    »
  49.  
  50.         d1    =    0
  51.         (input_line).b  ?  '.'
  52.         = {    input_line    +=    1
  53.             d1.b    =    (input_line)+
  54.         }
  55.  
  56.         chr    =    (input_line)+
  57.         chr    ?    9
  58.         != [    chr    ?    ' '
  59.             bne    ¶
  60.         ]
  61.         {  (input_line)+.b  ?  ' '
  62.            beq    }
  63.  
  64.         a3.l    =    ^-1(input_line)
  65.  
  66.         [  chr    =    (input_line)+
  67.            chr    ?  10;    beq  ¶
  68.            chr  ?  ''''
  69.            = «    input_line  +=  2  »
  70.            chr  ?  ','
  71.            bne    ]
  72.         
  73.         (a1)+.b        =    9
  74.         l_length    =    5
  75.  
  76.         (input_line).b    ?    'D'
  77.         = «    (input_line).b    =    'd'    »
  78.         (input_line).b    ?    'A'
  79.         = «    (input_line).b    =    'a'    »
  80.         (input_line).b    ?    'S'
  81.         = {    1(input_line).b    ?    'P'
  82.             = {    (input_line).b    =    'a'
  83.                 1(input_line).b    =    '7'
  84.             }
  85.         }
  86.  
  87.         {  chr    =  (input_line)+
  88.            chr  ?  9;    beq    ¶
  89.            chr  ?  10;    beq    ¶
  90.            chr  ?  ' '
  91.            = [    -2(input_line).b  ?  ''''
  92.             bne    ¶
  93.            ]
  94.            (a1)+.b    =    chr
  95.            l_length    +=    1
  96.            ->    }
  97.  
  98.         d4.b    ?    'q'
  99.         = {    d1.b    ?    'l'
  100.             = «    clr.b    d1    »
  101.         }
  102.  
  103.         tst.b    d1
  104.         != {    (a1)+.b    =    '.'
  105.             (a1)+.b    =    d1
  106.             l_length  +=     2
  107.         }
  108.  
  109.         (a1)+.b        =    9
  110.         d2.b    ?    'a'
  111.         = {    (a1)+.b    =    '+'
  112.             l_length  +=  1
  113.         }
  114.         d2.b    ?    's'
  115.         = {    (a1)+.b    =    '-'
  116.             l_length  +=  1
  117.         }
  118.  
  119.         (a1)+.b        =    '='
  120.         d2.b    ?    'c'
  121.         = «    -1(a1).b   =    '?'    »
  122.         (a1)+.b        =    9
  123.         d2.b    ?    'l'
  124.         = {    (a1)+.b  =  '^'
  125.             l_length  +=  1
  126.         }
  127.  
  128.         d4.b    ?    'q'
  129.         = «    clr.b    d1    »
  130.  
  131.         {  chr        =    (a3)+
  132.            chr  ?  ',';    beq    ¶
  133.            (a1)+.b    =    chr
  134.            l_length    +=    1
  135.            chr    ?  '#'
  136.            = {    tst.b    d1
  137.             != [    (a3).b    ?  ''''
  138.                 bne    ¶
  139.             ]
  140.             a1    -=    1
  141.             l_length  -=    1
  142.            }
  143.            ->    }
  144.  
  145.         (a1)+.b        =    10
  146.         a2        =    ^ obuf
  147.  
  148.     }
  149.  
  150.  
  151.     arg`a     =  ohandle
  152.     arg`b     =  a2
  153.     call    Write
  154.     l_length  ?  d0
  155.   beq     }
  156.  
  157.     print     prob
  158.  
  159. windup         · finished output
  160.     chr    =  infname
  161.     !=     {
  162.       arg`a  =  ohandle; call     Close
  163.       arg`a  =  ihandle; call     Close
  164.       ->   {
  165.        abort1:  arg`a  =  ihandle;    call     Close
  166.        abort:   print    nogo
  167.        }
  168.     }
  169.     d0 =  0
  170.  
  171.  
  172. --Check for equals instruction
  173.     chr    =    (input_line)+
  174.     chr    ?    'm'
  175.     != {    chr    ?    'l'
  176.         != {    chr    ?    'c'
  177.             != {    chr    ?    'a'
  178.                 != {    chr    ?    's'
  179.                     bne    §
  180.                     (input_line)+.b  ?  'u'
  181.                     bne    §
  182.                     (input_line)+.b  ?  'b'
  183.                     ->    §
  184.                 }
  185.                 (input_line)+.b  ?  'd'
  186.                 bne    §
  187.                 (input_line)+.b  ?  'd'
  188.                 ->    §
  189.             }
  190.             (input_line)+.b  ?  'm'
  191.             bne    §
  192.             (input_line)+.b  ?  'p'
  193.             ->    §
  194.         }
  195.         (input_line)+.b  ?  'e'
  196.         bne    §
  197.         (input_line)+.b  ?  'a'
  198.         ->    §
  199.     }
  200.     (input_line)+.b  ?  'o'
  201.     bne    §
  202.     (input_line)+.b  ?  'v'
  203.     bne    §
  204.     (input_line)+.b  ?  'e'
  205.     = {    (input_line).b  ?  ' ';    beq    §
  206.         (input_line).b  ?  9;    beq    §
  207.         (input_line).b  ?  '.'; beq    §
  208.         (input_line)+.b  ?  'q'
  209.     }
  210.  
  211.  
  212. ¶ We make two copies of the name given in the command tail.
  213.   The last character of the second copy is changed to 'a', and
  214.   this second copy is used as the name of the output file.
  215.  
  216. --Get file name from input line
  217.  
  218.     define     command_tail    A0.L
  219.     define     tail_length    D0
  220.     define     input_name    A1.L
  221.     define     output_name    A2.L
  222.     define     fn_char    D1.B
  223.  
  224.     input_name     =  ^infname
  225.     output_name  =    input_name
  226.     ->         next_fname_char
  227.     {  fn_char  =  (command_tail)+
  228.        fn_char  ?  ' ' + 1;   blt    ¶
  229.        (input_name)+.b  =  fn_char
  230.        tail_length -= 1
  231. next_fname_char
  232.        tst.l    tail_length
  233.        bne     }
  234.     clr.b     (input_name)
  235.  
  236.     exg      input_name,output_name
  237.     output_name     =  ^outfname
  238.     {    (output_name)+.b  =  (input_name)+;   =  }
  239.     output_name    -=  1
  240.  
  241.     -1(output_name).b    ?    'a'
  242.     = {    -2(output_name).b    ?    '.'
  243.         = {    -1(output_name).b  =  'w'
  244.             ->    §
  245.         }
  246.     }
  247.  
  248.     (output_name)+.b = '.';  (output_name)+.b = 'n'
  249.     clr.b     (output_name)
  250.  
  251. ¶ AmigaDOS stuff.
  252.  
  253. --Open input and output files
  254.  
  255.        define   arg`a  D1.L    · first argument to AmigaDOS function
  256.        define   arg`b  D2.L    · second argument
  257.  
  258.        long  ohandle
  259.        long  chandle
  260.        long  ihandle
  261.  
  262.     --Initialize standard input and output
  263.  
  264.     a1       = ^infname
  265.     tst.b     (A1)
  266.     beq      abort
  267.  
  268.     arg`a  =  a1
  269.     arg`b  =  #1005
  270.     call     Open; tst.l  D0; beq  abort
  271.     ihandle  =  d0
  272.  
  273.     arg`a  =  #outfname
  274.     arg`b  =  #1006
  275.     call     Open; tst.l  D0; beq  abort1
  276.     ohandle  =  d0
  277.  
  278.     ¶ Buffer is refilled whenever we can't find a complete line
  279. (ending in newline). The count in D3 includes the final newline.
  280. Thus returning a count of zero can be used as the signal that
  281. the file is exhausted.
  282.  
  283. --Read a line
  284.  
  285.     define     input_line     A0.L
  286.     define     l_length     D3.L
  287.     define     new_line    #10
  288.     define     chars_remaining D2.B
  289.     define     partial_line     A1.L
  290.     byte     bufchcount
  291.  
  292. · return input_line pointing to line and l_length length of line
  293.     input_line  =  bufptr
  294.     push        =  input_line
  295.     l_length    =  0      · no chars in line yet
  296. · back to here when was necessary to read more from file
  297. .rdln.cont
  298.     moveq  #0,chars_remaining
  299.     chars_remaining   = bufchcount
  300.     bmi      rdln.keep.info  · this means file is exhausted
  301.     beq      .rdln.more
  302.  
  303.     chars_remaining.l  -= 1
  304.     { chr    =    (input_line)+
  305.       chr    ?  new_line
  306.       beq       rdln.keep.one
  307. ·      chr    ?    9
  308. ·      = «  -1(input_line).b  =  ' '  »
  309.       l_length.b += 1
  310.       l_length.b  ?  #ibufLen
  311.       beq       rdln.keep.info
  312.       dbra       chars_remaining,}
  313. · ran out of chars -- go get more
  314.     ->     .rdln.more
  315. · have one line -- check not empty
  316. rdln.keep.one
  317.     l_length.b  += 1
  318. rdln.keep.info
  319.     bufptr.l     =    input_line
  320.     bufchcount   =    chars_remaining
  321.     input_line   =    pop
  322.     ->       §
  323.  
  324. .rdln.more
  325. · have partial line in buffer with l_length chars in it
  326.     partial_line = pop   · beginning of partial line
  327. · while l_length > 0 move chars back to beginning of buffer
  328.     input_line  =  ^ibuf
  329.     push        =  input_line    · for ret.
  330.     push        =  l_length
  331.     l_length.b -= 1
  332.     +{ {  (input_line)+.b =  (partial_line)+
  333.           dbra     l_length,}
  334.      }
  335. · fill remainder of buffer with 80-(l_length) chars
  336.     l_length    =  80
  337.     d0.l        =  pop
  338.     l_length.b -=  d0
  339.     push        =  d0
  340.  
  341.     partial_line  = ^ibuf
  342.     partial_line += d0
  343.     push          =   partial_line     · save where to continue processing line
  344.     arg`a  =   ihandle
  345.     arg`b  =   partial_line
  346.     call     Read
  347.  
  348.     tst.b     D0
  349.     = «  st   D0 »
  350.     bufchcount    = d0
  351.     input_line    = pop      · continue processing here
  352.     l_length    = pop      · chars scanned so far
  353.     ->      .rdln.cont
  354.  
  355.  
  356. Display string
  357. ·    message to console
  358. msg
  359.     arg`a       =  chandle
  360.     l_length   = 0
  361.     l_length.b = (a0)+
  362.     arg`b       =  a0
  363.     call     Write
  364.  
  365.        ¶ AmigaDos stuff.
  366.  
  367. --Initialize standard input and output
  368. ioinit
  369.     move.l     sysBase,A6       · ready call to OpenLibrary
  370.     lea      libname,A1
  371.     moveq     #0,D0
  372.     call     OpenLibrary
  373.     move.l     D0,A6
  374. · obtain file handles for output and input opened by CLI
  375.     call     Output
  376.     ohandle  =  d0
  377.     chandle  =  d0
  378.     call     Input
  379.     ihandle  =  d0
  380.  
  381.  
  382.  
  383.        ¶
  384.  
  385. Data sections
  386.  
  387.     section  three,bss
  388.  
  389. olen         ds.b  1
  390. obuf         ds.b  80
  391. ilen         ds.b  1
  392. ibuf         ds.b  ibufLen
  393. · now on word boundary
  394.  
  395. infname     ds.b  30
  396. outfname     ds.b  30
  397.  
  398.  
  399.  
  400.     section two,data
  401.  
  402.  
  403.  
  404. libname  dc.b  'dos.library',0
  405. bufptr         dc.l  ibuf
  406.     cnop     0,2
  407.  
  408.           bstr  nogo,<couldn''t open file>
  409.           bstr  prob,<problem with output file>
  410.  
  411.     section  one
  412.  
  413.  
  414.        ¶
  415.  
  416. --EQU statements for assembler
  417. sysBase     equ   4
  418. ibufLen     equ   80
  419.  
  420.        ¶
  421.  
  422. --Macro definitions for assembler
  423.  
  424. lref  macro
  425. _LVO\1      equ  -6*(\2+4)
  426.        endm
  427.  
  428. call  macro
  429.        jsr     _LVO\1(A6)
  430.        endm
  431.  
  432. print macro
  433.        lea     \1,A0
  434.        bsr     msg
  435.        endm
  436.  
  437. bstr  macro
  438. \1    dc.b  1$-*-1
  439.        dc.b  '\2',10
  440. 1$
  441.        endm
  442.  
  443. ¶ Following to avoid slow linking with amiga.lib
  444.  
  445. --Definitions of library references
  446.  
  447.     lref     OpenLibrary,88
  448.  
  449.     lref     Output,6
  450.     lref     Input,5
  451.     lref     Write,4
  452.     lref     Read,3
  453.     lref     DeleteFile,8
  454.     lref     Open,1
  455.     lref     Close,2
  456.     lref     IoErr,18
  457.     lref     LoadSeg,21
  458.     lref     UnLoadSeg,22
  459.     lref     IsInteractive,32
  460.  
  461.  
  462.