home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 303.lha / AssemTools / Asm65 / Asm65.asm < prev    next >
Assembly Source File  |  1980-12-03  |  95KB  |  4,324 lines

  1. ;
  2. ; ### 65c02 Cross Assembler by JM,TM v 2.352 ###
  3. ;
  4. ; - Created 880425 by JM -
  5. ;
  6. ;
  7. ; Quack!
  8. ;
  9. ; Bugs: Who knows...  Many, many fixed.
  10. ; * lda #-1-8 causes en ermsg: 8-bit value required
  11. ;
  12. ;
  13. ; Edited:    (Times and dates are UTC)
  14. ;=========
  15. ;
  16. ; - 880425 by JM    -> v0.00    - does not work
  17. ; - 880602 by JM    -> v0.01    - mnemonic table etc.
  18. ; - 880603 by JM,TM -> v0.02    - calc finished, seek_op, amode, slabel
  19. ;                  RELATIVE ADDRESSING???
  20. ; - 880604 by JM,TM -> v0.03    - seek_op finished   ### CPU CARD RUNS! ###
  21. ; - 880605 by JM,TM -> v0.04    - glabel&pass1 written, many Bugs fixed
  22. ; - 880606 by JM    -> v0.05    - pass2 written, many Bugs fixed
  23. ;                - IT COMPILES!!!
  24. ;                - DB, DW, DL
  25. ;                - z also accepted in symbol names
  26. ; - 880607 by JM,TM -> v1.00    - ';' works
  27. ; - 880608 by JM    -> v1.10    - listing file, conv_10
  28. ; - 880609 by JM    -> v1.11    - listing file improved, conv_16, dumplabels
  29. ; - 880610 by JM    -> v1.20    - dumplabels writes to listfile, too
  30. ;                - options allowed on cmd line
  31. ;                - MODE mnemonic added
  32. ;                - usage added
  33. ; - 880610 by JM    -> v1.30    - include added (well, that was a hard one...)
  34. ; - 880611 by JM    -> v1.34    - include edited (that took about one day)
  35. ; - 880611 by JM    -> v1.40    - conditional assembly added
  36. ; - 880611 by JM    -> v1.42    - conditional assembly improved (nesting allowed)
  37. ; - 880615 by JM    -> v1.46    - include nesting file names buffered
  38. ;                - maximum nesting level set to #INCNESTING
  39. ;                - label not found in abs or rel now only
  40. ;                  generates one error message
  41. ;                - started writing macro routines
  42. ; - 880616 by JM    -> v1.47    - FF added to the end of listfile
  43. ; - 880618 by JM    -> v1.48    - getlb written
  44. ;            -> v1.49    - macro routines continued
  45. ;            -> v1.50    - macro routines continued
  46. ;            -> v1.51    - macros work without parameters and nesting
  47. ;            -> v1.52    - macros improved
  48. ; - 880619 by JM    -> v1.57    - macros improved
  49. ;            -> v1.60    - macros: parameters
  50. ;            -> v1.62    - problems...
  51. ; - 880624 by JM,TM -> v1.65    - ifc/ifnc written
  52. ;                - ermsgs added
  53. ;                - ifi/ifni written (TM)
  54. ; - 880624 by JM    -> v1.67    - macros nesting without parameter nesting
  55. ; - 880625 by JM    -> v1.68    - macros nesting with parameter nesting
  56. ;            -> v1.74    - parameter nesting finished; errhandler
  57. ;                  edited
  58. ;            -> v1.75    - @MODE written; glabel now gives an ermsg if
  59. ;                  no symbol name is given
  60. ; - 880626 by JM    -> v1.77    - Big Params allowed in macros
  61. ;            -> v1.90    - It seems to work well.
  62. ;            -> v1.91    - Macros now accept four parameters
  63. ;                - Addresses > $ffff now generate an ermsg
  64. ;            -> v1.92    - Labels also processed on macro usage lines
  65. ; - 880814 by JM    -> v1.93    - Hex mode can now be set in source file
  66. ;                  using MODE directive - NOTE: No .hex extension
  67. ;                  will be added to output file in this case!
  68. ;                - CTRL+Z is added to end of hex output file
  69. ; - 880816 by JM    -> v1.95    - Fixed a bug in conditional assembly:
  70. ;                  Nested conditions should now work properly.
  71. ;                  A 'stack' for all condition levels added.
  72. ; - 880816 by JM    -> v1.97    - Stack now consists of bytes (no need to
  73. ;                  multiply index by two -> no guru3's on 68000)
  74. ;                - CTRL_C signals now checked in pass1, pass2
  75. ;                  and MainLoad.
  76. ; - 880816 by JM    -> v2.00    - CTRL_C checked also in dumplabels
  77. ;                - endc statements now allow for labels BUT:
  78. ;                  endm's DON'T!!!
  79. ; - 880817 by JM    -> v2.02    - SET and EQU should now work properly.
  80. ;                  There was a problem when SETting a label to
  81. ;                  value label+n because slabel corrupted
  82. ;                  the LINFO value before GLABEL read it.
  83. ; - 880817 by JM    -> v2.06    - Fixed a bug: MODE L produced 1006 bytes
  84. ;                  of object code when listfile was opened.
  85. ;                  Now none of pseudos should produce object
  86. ;                  code (=increment prgc) unintentionally.
  87. ;                - Listmode is now read from userlmode, whose
  88. ;                  value is derived from cmd line option -l.
  89. ;                  Now the default listmode at start of each
  90. ;                  pass is userlmode instead of the value of
  91. ;                  listmode inherited from previous pass.
  92. ;                - Mode l/L commands no longer written to
  93. ;                  listfile.
  94. ;                - <<>> now produces an ermsg in macro exps.
  95. ;                - Macro parameters no longer contain following
  96. ;                  blanks.
  97. ;                - Macro, include and conditional nesting levels
  98. ;                  raised.
  99. ;                - Symbol definitions using EQU or SET now
  100. ;                  generate listing according to the value
  101. ;                  assigned. '=' = EQU, '>' = SET.
  102. ;                  DOESN'T WORK YET!!!
  103. ; - 880818 by JM    -> v2.10    - Fixed a new bug: listfile now opened correctly
  104. ;                - dumplabels no longer crashes is odd number of
  105. ;                  labels is printed (a bug in nextlab fixed)
  106. ;                - '=' and '>' now work in listmode.
  107. ;                - MainLoad now tells us what it is doing.
  108. ; - 880818 by JM    -> v2.15    - Fixed an old bug which caused wrong filenames
  109. ;                  and lines to be printed if any of the files
  110. ;                  was not found.
  111. ; - 880818 by JM    -> v2.2    - Macro parameters containing blanks in ''
  112. ;                  now allowed.
  113. ;                - Quote error messages added.
  114. ; - 880819 by JM    -> v2.23    - Macro parameter errors now should only
  115. ;                  print one errormsg.
  116. ;                - Macro ermsgs contain error line instead of
  117. ;                  a null.
  118. ;                - SET symbols not show their correct values
  119. ;                  in listfile.
  120. ;                - MODulo operation added (\).  Only handles
  121. ;                  signed 16-bit values for now.
  122. ; - 880819 by JM    -> v2.24    - Still a bug fixed.  Now SET symbols really
  123. ;                  work fine (with abs values, too).
  124. ; - 880819 by JM    -> v2.25    - Nested conditional assembly with FALSE
  125. ;                  block now should work properly.  This one
  126. ;                  was hard to find but easy to fix (just one
  127. ;                  clr.b pat_pend needed)
  128. ; - 880907 by JM    -> v2.26    - BBR and BBS now don't check offset value
  129. ;                  during pass 1.  So forward jumps work.
  130. ; - 880907 by JM    -> v2.30    - Macros listed properly during false condition.
  131. ; - 880907 by JM    -> v2.32    - BBR and BBS now get right mem address
  132. ;                - Abs_Sym_Mism error printed only once
  133. ; - 881201 by JM    -> v2.33    - Now an error during seek_op() should not
  134. ;                  produce an extra long destination line.
  135. ;                  So the relative branches should no longer
  136. ;                  cause extra ermsgs after an unknown label.
  137. ; - 890125 by JM    -> v2.34    - Now flushes the output buffer ALWAYS at the
  138. ;                  end of assembly
  139. ;                - Several relative branches converted to short.
  140. ; - 890131 by JM    -> v2.35    - PAGE directive added.
  141. ; - 890310 by JM    -> v2.351    - All b???.l and b???.b instructions converted
  142. ;                  to b??? to allow compiling with A68k.
  143. ; - 890310 by JM    -> v2.352    - All PULL <onereg> checked because A68k
  144. ;                  changes these into MOVE.L -> flags change.
  145. ;                  -> seems to work even if compiled with
  146. ;                  A68k.
  147. ;
  148. ;
  149. ;------------------------------------------------------------------------
  150. ;
  151.  
  152. LABELLEN    equ    16            maximum length of label name
  153. LABELSPC    equ    LABELLEN+1+1+4+4    name,null,info,usage,value
  154. LINFO        equ    LABELLEN+1
  155. LUSAGE        equ    LABELLEN+1+1
  156. LVALUE        equ    LABELLEN+1+1+4
  157. NUMLAB        equ    5000            maximum number of label names
  158.  
  159. MAXLINE        equ    60            default value
  160. HUGELINE    equ    MAXLINE+10        higher than maxline
  161.  
  162. INCNESTING    equ    8            maximum level of nested includes
  163. MCNESTING    equ    8            maximum level of nested macros
  164. CONDNESTING    equ    16            maximum level of nested conditions
  165.  
  166.  
  167. NAME1BUF    equ    256            buffer sizes
  168. NAME2BUF    equ    256
  169. AUXBUF        equ    256
  170. LISTBUF        equ    512
  171. MULTIBUF    equ    NAME1BUF+NAME2BUF+AUXBUF+LISTBUF
  172. OBUF        equ    2048            output buffer size
  173. LABELBUF    equ    LABELSPC*NUMLAB        name,null,pad,info,value
  174. MINSOURCE    equ    10000            minimum buffer for source
  175.  
  176.  
  177. ;------------------------------------------------------------------------
  178.  
  179.  
  180. TAB        equ    9            some ASCII characters
  181. LF        equ    10
  182. FF        equ    12
  183. CR        equ    13
  184. CTRL_C        equ    12
  185. CTRL_Z        equ    26
  186. ESC        equ    27
  187. CSI        equ    128+ESC
  188. ID        equ    160            id byte for internal mnemonics
  189.  
  190.  
  191. ;------------------------------------------------------------------------
  192.  
  193.  
  194. IMM        equ    0            identifiers for addressing
  195. ABS        equ    1            modes
  196. ZP        equ    2
  197. ACC        equ    3
  198. IMP        equ    4
  199. INDX        equ    5
  200. INDY        equ    6
  201. ZPX        equ    7
  202. ABSX        equ    8
  203. ABSY        equ    9
  204. REL        equ    10
  205. IND        equ    11
  206. ZPY        equ    12
  207.  
  208.  
  209. ;------------------------------------------------------------------------
  210.  
  211.  
  212.         include    "exec.xref"
  213.         include    "dos.xref"
  214.         include "JMPLibs.i"
  215.  
  216. MEMF_PUBLIC    equ    1        no need of intuition.i
  217. MEMF_CHIP    equ    2
  218. MEMF_FAST    equ    4
  219. MEMF_CLEAR    equ    65536
  220.  
  221.  
  222. ;------------------------------------------------------------------------
  223.  
  224.  
  225. VERSION        macro
  226.         dc.b    'v2.352'
  227.         endm
  228.  
  229. otxt        macro
  230.         push    a0/d7
  231.         lea    otxtdat\@,a0
  232. otxtl\@        move.b    (a0)+,d7
  233.         beq    otxte\@
  234.         bsr    ochr
  235.         bra    otxtl\@
  236. otxtdat\@    dc.b    \1
  237.         dc.b    0
  238.         cnop    0,4
  239. otxte\@        pull    a0/d7
  240.         endm
  241.  
  242.  
  243. error        macro                calls error handler
  244.         push    all
  245.         ifnc    '\1',''
  246.         move.w    \1,d0
  247.         endc
  248.         bsr    errhandler
  249.         pull    all
  250.         endm
  251.  
  252.  
  253. ;------------------------------------------------------------------------
  254.  
  255.  
  256. Start        push    d2-d7/a2-a6        save regs
  257.         move.l    d0,_CMDLen        len of cmd line
  258.         move.l    a0,_CMDBuf        start addr of cmd line
  259.         clr.b    -1(a0,d0.l)        add null
  260.         openlib Dos,cleanup        open Dos library
  261.  
  262.         printa    #PAGEMSG        print starting msg
  263.         move.b    #' ',PAGENULL
  264.         printa    #LFLF
  265.  
  266.         lib    Dos,Output        get output file handle
  267.         move.l    d0,clifile
  268.  
  269.         move.l    #OBUF,d0        reserve output buffer
  270.         move.l    #MEMF_CLEAR,d1
  271.         lib    Exec,AllocMem
  272.         move.l    d0,obuf            save start addr
  273.         move.l    d0,opoi            set output buffer pointer
  274.         beq    mem_cleanup        no mem, exit
  275.  
  276.         move.l    #MULTIBUF,d0        several buffers
  277.         move.l    #MEMF_CLEAR,d1
  278.         lib    Exec,AllocMem        ask for mem
  279.         move.l    d0,multibuf        save start addr for FreeMem
  280.         beq    mem_cleanup        no mem, exit
  281.         add.l    #NAME1BUF+NAME2BUF,d0
  282.         move.l    d0,auxbuf        another buffer
  283.         add.l    #AUXBUF,d0
  284.         move.l    d0,libuf        buffer for listing
  285.  
  286.         move.l    #LABELBUF,d0        allocate mem for symbols
  287.         move.l    #MEMF_CLEAR,d1
  288.         lib    Exec,AllocMem
  289.         move.l    d0,labelbuf        save start addr
  290.         beq    mem_cleanup        no mem, exit
  291.  
  292.         bsr    OpenFiles        open files, read prg
  293.         bcs    cleanup
  294.  
  295.         move.l    errcnt(pc),d0        errors during macro/include pass?
  296.         bne    cleanup
  297.         bsr    pass1
  298.         bcs    cleanup
  299.         bsr    pass2
  300.  
  301.         move.w    hexmode(pc),d0
  302.         beq.s    noCTRLz
  303.         moveq.l    #CTRL_Z,d7        end-of-file mark
  304.         bsr    ochr
  305.  
  306. noCTRLz        moveq.l    #-1,d7            flush output buffer
  307.         bsr    ochr
  308.  
  309.         move.l    errcnt(pc),d0        no msg below if errors
  310.         bne.s    not_complete
  311.  
  312.         print    <'Object file complete.',LF>
  313. not_complete    bsr    dumplabels
  314.         bra.s    cleanup
  315.  
  316.  
  317. ;------------------------------------------------------------------------
  318.  
  319.  
  320. mem_cleanup    error    #41
  321. cleanup        move.w    broken(pc),d0
  322.         beq.s    nobreak
  323.         print    <'*** User break request ***',LF>
  324. nobreak        move.l    outfile(pc),d1
  325.         beq.s    cleanf1
  326.         lib    Dos,Close
  327.  
  328. cleanf1        move.l    listfile(pc),d1
  329.         beq.s    clean01
  330.         print    <FF>,d1            add final form feed
  331.         lib    Dos,Close
  332.  
  333. clean01        move.l    sourcebuf(pc),d0    if mem reserved release it
  334.         beq.s    clean02
  335.         move.l    d0,a1
  336.         move.l    SOURCEBUF(pc),d0
  337.         lib    Exec,FreeMem
  338.  
  339. clean02        move.l    obuf(pc),d0        if mem reserved release it
  340.         beq.s    clean03
  341.         move.l    d0,a1
  342.         move.l    #OBUF,d0
  343.         lib    Exec,FreeMem
  344.  
  345. clean03        move.l    multibuf(pc),d0        if mem reserved release it
  346.         beq.s    clean04
  347.         move.l    d0,a1
  348.         move.l    #MULTIBUF,d0
  349.         lib    Exec,FreeMem
  350.  
  351. clean04        move.l    labelbuf(pc),d0        if mem reserved release it
  352.         beq.s    clean90
  353.         move.l    d0,a1
  354.         move.l    #LABELBUF,d0
  355.         lib    Exec,FreeMem
  356.  
  357. clean90        closlib    Dos
  358.         pull    d2-d7/a2-a6
  359.         moveq.l    #0,d0
  360.         rts
  361.  
  362.  
  363.  
  364. ;========================================================================
  365.  
  366.  
  367. output        cmp.b    #2,pass            if pass#2, write to dest.
  368.         beq.s    output_y
  369.         rts
  370. output_y    push    d0-d1/a0-a1
  371.         move.w    listmode(pc),d0        if listmode
  372.         beq.s    output_no_b
  373.         move.w    hexbytcnt(pc),d0    if still bytes to buffer
  374.         beq.s    output_no_b        (writes only first 3 bytes)
  375.         subq.w    #1,d0            Outputs assembled bytes to libuf
  376.         move.w    d0,hexbytcnt        2.1.0
  377.         eor.w    #3,d0            1.2.3
  378.         mulu.w    #3,d0            3.6.9
  379.         lea    hextable(pc),a0
  380.         move.l    libuf(pc),a1
  381.         moveq.l    #0,d1
  382.         move.b    d7,d1
  383.         lsr.b    #4,d1
  384.         move.b    0(a0,d1.w),9(a1,d0.w)    high nybble
  385.         move.b    d7,d1
  386.         and.b    #15,d1
  387.         move.b    0(a0,d1.w),10(a1,d0.w)    low nybble
  388.  
  389. output_no_b    move.w    hexmode(pc),d0
  390.         bne.s    output_hex
  391.         bsr    ochr
  392.         bra.s    no_output
  393. output_hex    bsr    ohex
  394. no_output    pull    d0-d1/a0-a1
  395.         rts
  396.  
  397.  
  398. ;------------------------------------------------------------------------
  399.  
  400.  
  401. listout        push    d0-d3/a0-a1        write pc, line# & line in libuf
  402.         move.w    listmode(pc),d0
  403.         beq    listout_ex
  404.         move.w    no_list(pc),d0        if a special mnemonic, no listing
  405.         bne    listout_ex
  406.         cmp.b    #2,pass            if not pass#2, no listing
  407.         bne    listout_ex
  408.         move.l    libuf(pc),a1        listing linebuffer
  409.         lea    hextable(pc),a0        table of ASCII hex chars
  410.         move.w    hexbytcnt(pc),d0
  411.         subq.w    #3,d0
  412.         bne.s    listout_pc
  413.  
  414.         move.l    equset(pc),d1        label set/equted on this line?
  415.         beq.s    listout_noadr        no, output nothing
  416.         addq.l    #1,a1            tab one col right
  417.         btst    #31,d1
  418.         beq.s    listo1
  419.         move.b    #'=',6(a1)        flag user: symbol was EQUted
  420.         bra.s    listo2
  421. listo1        move.b    #'>',6(a1)        flag user: symbol was SET
  422. listo2        bsr    listout_prgc
  423.         subq.l    #1,a1            tab back to orig positing
  424.         clr.l    equset            operation performed -> clear
  425.         bra.s    listout_noadr
  426.  
  427. listout_pc    move.l    prgc(pc),d1        write pc value into buffer
  428.         bsr    listout_prgc
  429.  
  430. listout_noadr    move.w    idepth(pc),d0
  431.         beq.s    listout_noinc
  432.         move.b    #'I',5(a1)        code from include file
  433.  
  434. listout_noinc    cmp.w    #-2,incstrt        code from macro expansion?
  435.         bne.s    listout_nomac
  436.         move.b    #'M',5(a1)
  437.  
  438. listout_nomac    move.w    condstrt(pc),d0        check if TRUE or FALSE needed
  439.         beq.s    listout_nocond
  440.         lea    7(a1),a1        column
  441.         bmi.s    listout_false
  442.         lea    LO_TRUE(pc),a0
  443.         bra.s    listout_r_cond
  444. listout_false    lea    LO_FALSE(pc),a0
  445. listout_r_cond    bsr    copy_10            write string
  446.         clr.w    condstrt
  447.         move.l    libuf(pc),a1        get pointer back
  448.  
  449. listout_nocond    move.l    linnum(pc),d0
  450.         setc                no zero suppression
  451.         bsr    conv_10
  452.         lea    buf_10+7(pc),a0
  453.         moveq.l    #4,d1
  454. listout_line    move.b    (a0)+,(a1)+        copy line number
  455.         dbf    d1,listout_line
  456.  
  457.         move.l    linstrt(pc),a0        copy the line itself
  458.         move.l    libuf(pc),a1
  459.         add.l    #22,a1            tab to col 22
  460.         moveq.l    #0,d1            column counter
  461. listout_cpy    move.b    (a0)+,d0        copyloop
  462.         cmp.b    #TAB,d0
  463.         bne.s    listout_cpynt
  464. listout_tab    move.b    #' ',(a1)+        replace tabs with 1...8 spaces
  465.         addq.l    #1,d1
  466.         move.b    d1,d2
  467.         and.b    #7,d2
  468.         bne.s    listout_tab
  469.         bra.s    listout_cpy        continue with next char
  470. listout_cpynt    move.b    d0,(a1)+
  471.         addq.l    #1,d1            next column
  472.         cmp.b    #LF,d0
  473.         beq.s    listout_eol
  474.         cmp.b    #CR,d0
  475.         bne.s    listout_cpy
  476.  
  477. listout_eol    bsr    header            print page header if needed
  478.         move.l    listfile(pc),d1        write it out
  479.         move.l    libuf(pc),d2
  480.         move.l    a1,d3
  481.         sub.l    d2,d3
  482.         lib    Dos,Write
  483.         cmp.l    d3,d0            requested length written?
  484.         beq.s    listout_wrok
  485.         error    #62
  486.         bra.s    listout_err
  487. listout_wrok    addq.l    #5,d2            buffer start+5
  488.         move.l    d2,a1
  489.         moveq.l    #16,d0
  490.         moveq.l    #' ',d1
  491. listout_clr    move.b    d1,(a1)+        clear numeric bytes
  492.         dbf    d0,listout_clr
  493.         move.w    #3,hexbytcnt
  494. listout_ex    clr.w    no_list
  495.         pull    d0-d3/a0-a1
  496.         rts
  497. listout_err    clr.w    no_list
  498.         pull    d0-d3/a0-a1
  499.         setc
  500.         rts
  501.  
  502. listout_prgc    moveq.l    #0,d0            Writes a 16-bit value into buf
  503.         move.b    d1,d0            Value in d1.
  504.         and.b    #15,d0
  505.         move.b    0(a0,d0.w),10(a1)    lowest nybble
  506.         lsr.w    #4,d1
  507.         move.b    d1,d0
  508.         and.b    #15,d0
  509.         move.b    0(a0,d0.w),9(a1)
  510.         lsr.w    #4,d1
  511.         move.b    d1,d0
  512.         and.b    #15,d0
  513.         move.b    0(a0,d0.w),8(a1)
  514.         lsr.w    #4,d1
  515.         move.b    d1,d0
  516.         and.b    #15,d0
  517.         move.b    0(a0,d0.w),7(a1)    highest nybble
  518.         rts
  519.  
  520.  
  521. LO_TRUE        dc.b    'TRUE',0
  522. LO_FALSE    dc.b    'FALSE',0
  523.         cnop    0,4
  524.  
  525.  
  526. list_clr    push    d0/a0            clear numeric bytes in buffer
  527.         move.l    libuf(pc),a0
  528.         moveq.l    #22,d0
  529. list_clr1    move.b    #' ',(a0)+
  530.         dbf    d0,list_clr1
  531.         pull    d0/a0
  532.         rts
  533.  
  534.  
  535. ;------------------------------------------------------------------------
  536.  
  537.  
  538. ohex        push    d0/d7/a0        output a byte in d7 in hex
  539.         lea    hextable(pc),a0
  540.         move.b    d7,d0
  541.         lsr.b    #4,d7
  542.         and.w    #15,d7
  543.         move.b    0(a0,d7),d7
  544.         bsr.s    ochr
  545.         and.w    #15,d0
  546.         move.b    0(a0,d0),d7
  547.         bsr.s    ochr
  548.         pull    d0/d7/a0
  549.         rts
  550.  
  551.  
  552. ochr        push    d0-d3/a0-a1        * output one char.
  553.         move.l    obuf(pc),a1        * Uses buffering.
  554.         cmp.l    #-1,d7            * Buffer is written to disk
  555.         beq.s    ochrflush        * if it becomes full or if
  556.         add.l    #OBUF,a1        * the character ochr'ed is
  557.         move.l    opoi(pc),a0        * -1.
  558.         move.b    d7,(a0)+
  559.         cmp.l    a1,a0
  560.         blt.s    ochrok1
  561.         move.l    obuf(pc),a0
  562.         move.l    outfile(pc),d1
  563.         move.l    a0,d2
  564.         move.l    #OBUF,d3
  565. ochrout        lib    Dos,Write
  566.         move.l    d2,a0
  567.         cmp.l    d3,d0
  568.         beq.s    ochrok1
  569.         error    #61
  570. ochrok1        move.l    a0,opoi
  571.         pull    d0-d3/a0-a1
  572.         rts
  573.  
  574. ochrflush    move.l    opoi(pc),a0
  575.         sub.l    a1,a0
  576.         move.l    outfile(pc),d1
  577.         move.l    a1,d2
  578.         move.l    a0,d3
  579.         bra.s    ochrout
  580.  
  581.  
  582. chr        push    a0            read one byte
  583.         move.l    txtptr(pc),a0
  584.         moveq.l    #0,d0
  585.         move.b    (a0)+,d0
  586.         cmp.b    #CR,d0
  587.         beq.s    chr_eol
  588.         cmp.b    #LF,d0
  589.         beq.s    chr_eol
  590.         move.l    a0,txtptr
  591. chr_eol        pull    a0
  592.         tst.b    d0
  593.         rts
  594.  
  595.  
  596. gc        push    a0
  597.         move.l    txtptr(pc),a0        get txtptr
  598.         moveq.l    #0,d0
  599. gc_sk        move.b    (a0)+,d0        get a byte
  600.         beq.s    gc_e
  601.         cmp.b    #';',d0            ; = line end
  602.         beq.s    gc_e
  603.         cmp.b    #' ',d0            >' ', legal char
  604.         bhi.s    gc_ok
  605.         cmp.b    #CR,d0            CR means line end
  606.         beq.s    gc_e
  607.         cmp.b    #LF,d0            LF means line end
  608.         beq.s    gc_e
  609.         bra.s    gc_sk            try next char
  610. gc_ok        move.l    a0,txtptr
  611.         pull    a0
  612.         cmp.b    #0,d0
  613.         rts
  614. gc_e        addq.b    #1,pat_pend        one LF fetched
  615.         pull    a0
  616.         moveq.l    #0,d0
  617.         rts
  618.  
  619.  
  620. gec        push    a0
  621.         move.l    txtptr(pc),a0        get txtptr
  622.         moveq.l    #0,d0
  623. gec_sk        move.b    (a0)+,d0        get a byte
  624.         beq.s    gec_e
  625.         cmp.b    #';',d0            ; = line end
  626.         beq.s    gec_e
  627.         cmp.b    #' ',d0            >' ', legal char
  628.         bhi.s    gec_ok
  629.         cmp.b    #CR,d0            CR means line end
  630.         beq.s    gec_e
  631.         cmp.b    #LF,d0            LF means line end
  632.         beq.s    gec_e
  633. gec_ok        move.l    a0,txtptr
  634.         pull    a0
  635.         cmp.b    #0,d0
  636.         rts
  637. gec_e        addq.b    #1,pat_pend        one LF fetched
  638.         pull    a0
  639.         moveq.l    #0,d0
  640.         rts
  641.  
  642.  
  643. gpeek        push    a0
  644.         move.l    txtptr(pc),a0
  645.         moveq.l    #0,d0
  646.         move.b    (a0),d0
  647.         pull    a0
  648.         tst.b    d0
  649.         rts
  650.  
  651. cg        tst.b    pat_pend
  652.         beq.s    cg_ok
  653.         subq.b    #1,pat_pend        one LF backwards
  654.         rts
  655. cg_ok        subq.l    #1,txtptr
  656. cg_ex        rts
  657.  
  658.  
  659. ck_stop        push    d0-d1/a0-a1        check if CTRL_C pressed
  660.         moveq.l    #0,d0
  661.         moveq.l    #0,d1
  662.         lib    Exec,SetSignal
  663.         btst    #CTRL_C,d0
  664.         beq.s    ck_nostop
  665.         moveq.l    #0,d0
  666.         moveq.l    #0,d1
  667.         bset    #CTRL_C,d1
  668.         lib    Exec,SetSignal        clear signal
  669.         moveq.l    #1,d0            NE: STOP!!!
  670.         move.w    d0,broken        set flag: STOPPED!!
  671.         pull    d0-d1/a0-a1
  672.         rts
  673. ck_nostop    moveq.l    #0,d0            EQ: no stop
  674.         pull    d0-d1/a0-a1
  675.         rts
  676.  
  677.  
  678. ;------------------------------------------------------------------------
  679.  
  680.  
  681. mulmul        push    d0/d2-d4
  682.         bsr    SetSignMD    d1 = d0 * d1
  683.         move.l    d0,d4        multiplication HL * hl
  684.         mulu.w    d1,d0        L*l
  685.         move.l    d0,d3        low word
  686.         move.l    d4,d0
  687.         swap    d0        high word
  688.         mulu.w    d1,d0        L*h
  689.         swap    d0
  690.         tst.w    d0
  691.         bne.s    mulmuler    result bigger than 32 bits
  692.         add.l    d0,d3        d3 contains L*(hl)
  693.         swap    d1        get low word
  694.         move.w    d4,d0
  695.         mulu.w    d1,d0        H*l
  696.         swap    d0        result to high word
  697.         tst.w    d0         (hw of mulu must be zero)
  698.         bne.s    mulmuler
  699.         add.l    d0,d3        d3 contains L*(hl)+H*l
  700.         bcs.s    mulmuler
  701.  
  702.         move.l    d4,d0
  703.         swap    d0        get low word
  704.         mulu.w    d1,d0        H*h (must be always zero)
  705.         bne.s    mulmuler
  706.         btst    #31,d3        bit #31 must be zero (sign)
  707.         bne.s    mulmuler
  708.  
  709.         move.l    d3,d1
  710.         tst.l    d2        set appropriate sign
  711.         bpl.s    mulmula
  712.         neg.l    d1
  713. mulmula        pull    d0/d2-d4
  714.         clrc
  715.         rts
  716. mulmuler    setc
  717.         pull    d0/d2-d4
  718.         rts
  719.  
  720.  
  721. divdiv        push    d0/d2-d5    d1 = d1 / d0
  722.         tst.l    d0        divisor = 0?
  723.         bne.s    divdiv1
  724.         error    #131
  725.         pull    d0/d2-d5
  726.         rts
  727.  
  728. divdiv1        bsr.s    SetSignMD
  729.         moveq.l    #0,d3
  730.         moveq.l    #31,d5        bit counter
  731. divdivloop    roxl.l    #1,d1
  732.         roxl.l    #1,d3        d3 is a 'working accum'
  733.         cmp.l    d0,d3
  734.         blo.s    divdivless
  735.         sub.l    d0,d3
  736.         setx
  737.         roxl.l    #1,d4        if subtracted, set bit
  738.         dbf    d5,divdivloop
  739.         bra.s    divdivdone
  740. divdivless    asl.l    #1,d4
  741.         dbf    d5,divdivloop
  742.  
  743. divdivdone    move.l    d4,d1        set appropriate sign
  744.         tst.l    d2
  745.         bpl.s    divdiv2
  746.         neg.l    d1
  747. divdiv2        pull    d0/d2-d5
  748.         clrc
  749.         rts
  750.  
  751.  
  752. SetSignMD    move.l    d0,d2        get sign of result into d2[31]
  753.         eor.l    d1,d2
  754.         tst.l    d0        make d0 positive if necessary
  755.         bpl.s    SetSign1
  756.         neg.l    d0
  757. SetSign1    tst.l    d1        make d1 positive
  758.         bpl.s    SetSign2
  759.         neg.l    d1
  760. SetSign2    rts
  761.  
  762.  
  763. ;------------------------------------------------------------------------
  764.  
  765.  
  766. errhandler    and.l    #$ffff,d0
  767.         move.w    d0,errornum
  768.         clrc
  769.         bsr    conv_10
  770.         lea    buf_10+7(pc),a0
  771.         lea    ERROR_NUM(pc),a1
  772.         bsr    copy_10
  773.         cmp.w    #100,errornum
  774.         blo    errhand0
  775.         move.l    linnum(pc),d0
  776.         clrc
  777.         bsr    conv_10
  778.         lea    buf_10+7(pc),a0
  779.         lea    ERROR_LIN(pc),a1
  780.         bsr    copy_10
  781.         printa    #ERROR_SC
  782.         move.l    nameptr(pc),a0
  783.         move.l    auxbuf(pc),a1
  784.         move.l    linnum(pc),d0    don't print line if line# = 0
  785.         beq.s    errhand2a
  786. err_cpname    move.b    (a0)+,d0
  787.         beq.s    err_nameok
  788.         cmp.b    #39,d0
  789.         beq.s    err_nameok
  790.         cmp.b    #' ',d0
  791.         beq.s    err_nameok
  792.         move.b    d0,(a1)+
  793.         bra.s    err_cpname
  794.  
  795. err_nameok    move.l    linstrt(pc),a0
  796.         move.b    #':',(a1)+
  797.         move.b    #'"',(a1)+
  798.         move.w    #128,d1        max # of chars
  799. errhand1    move.b    (a0)+,d0    copy line
  800.         bsr    ck_eol
  801.         bvs.s    errhand2
  802.         move.b    d0,(a1)+
  803.         dbf    d1,errhand1
  804. errhand2    move.b    #'"',(a1)+
  805. errhand2a    move.b    #LF,(a1)+
  806.         clr.b    (a1)
  807.         printa    auxbuf(pc)
  808.         move.l    listfile(pc),d0
  809.         beq.s    errhand0
  810.         printa    #ERROR_SC,d0        error
  811.         printa    auxbuf(pc),d0        line
  812. errhand0    bsr.s    print_error        msg
  813.         addq.l    #1,errcnt
  814.         setc
  815.         rts
  816.  
  817. ERROR_SC    dc.b    LF,'*** Error '
  818. ERROR_NUM    dc.b    '      on line '
  819. ERROR_LIN    dc.b    '      ***',LF,0
  820.         cnop    0,4
  821.  
  822.  
  823. print_error    moveq.l    #0,d0        reset high word
  824.         move.w    errornum(pc),d0
  825.         divu.w    #10,d0        calc main error#
  826.         lea    ermsgs(pc),a0
  827. print_err_lp    subq.w    #1,d0        find ermsg#d0
  828.         beq.s    print_errf
  829. print_err_seek    tst.b    (a0)+        find end of this msg
  830.         bne.s    print_err_seek
  831.         tst.b    (a0)        last one?
  832.         bpl.s    print_err_lp    no, continue
  833. print_err_err    print    <'### INTERNAL ERROR #1: Please report ###',LF>
  834.         bra.s    print_err_ex
  835. print_errf    tst.b    (a0)        if no ermsg for this number
  836.         beq.s    print_err_err
  837.         printa    a0
  838.         move.l    listfile(pc),d0
  839.         beq.s    print_err_ex
  840.         printa    a0,d0
  841. print_err_ex    rts
  842.  
  843.  
  844. ;------------------------------------------------------------------------
  845.  
  846.  
  847. copy_10        push    d0
  848. copy_10_l    move.b    (a0)+,d0
  849.         beq.s    copy_10_e
  850.         move.b    d0,(a1)+
  851.         bra.s    copy_10_l
  852. copy_10_e    pull    d0
  853.         rts
  854.  
  855.  
  856. sign_10        btst    #31,d0
  857.         beq.s    conv_10
  858.         neg.l    d0
  859.         clrc
  860.         bsr.s    conv_10
  861.         push    a0
  862.         lea    buf_10(pc),a0
  863. sign_10_1    cmp.b    #' ',(a0)+
  864.         beq.s    sign_10_1
  865.         move.b    #'-',-2(a0)
  866.         pull    a0
  867.         rts
  868.  
  869. print10        setc
  870.         bsr.s    conv_10        for testing purposes only
  871.         printa    #buf_10
  872.         print    <LF>
  873.         rts
  874.  
  875.  
  876.  
  877. conv_10        push    all        if carry clear, leading zeroes blanked
  878.         bcs.s    conv_10_0
  879.         moveq.l    #' ',d2
  880.         bra.s    conv_10_spc
  881. conv_10_0    moveq.l    #'0',d2
  882. conv_10_spc    lea    bcd_10+6(pc),a0
  883.         lea    res_10+6(pc),a1
  884.         moveq.l    #0,d1            clear result first
  885.         move.l    d1,-6(a0)
  886.         move.l    d1,-2(a0)
  887.         move.l    d1,-6(a1)
  888.         move.l    d1,-2(a1)
  889.         move.b    #1,-1(a0)        seed value
  890. conv_10_main    lsr.l    #1,d0
  891.         bcc.s    conv_10_next
  892.         move.l    a0,a2
  893.         move.l    a1,a3
  894.         clrx
  895.         abcd    -(a2),-(a3)        add seed value to result
  896.         abcd    -(a2),-(a3)
  897.         abcd    -(a2),-(a3)
  898.         abcd    -(a2),-(a3)
  899.         abcd    -(a2),-(a3)
  900.         abcd    -(a2),-(a3)
  901.         tst.l    d0
  902. conv_10_next    beq.s    conv_10_asc
  903.         move.l    a0,a2            multiply seed value by 2
  904.         move.l    a0,a3
  905.         clrx
  906.         abcd    -(a2),-(a3)
  907.         abcd    -(a2),-(a3)
  908.         abcd    -(a2),-(a3)
  909.         abcd    -(a2),-(a3)
  910.         abcd    -(a2),-(a3)
  911.         abcd    -(a2),-(a3)
  912.         bra.s    conv_10_main
  913. conv_10_asc    lea    res_10(pc),a0        convert to ascii
  914.         lea    buf_10(pc),a1
  915.         moveq.l    #5,d1
  916. conv_10_al    move.b    (a0)+,d3
  917.         move.b    d3,d0
  918.         lsr.b    #4,d0
  919.         beq.s    conv_10_al1
  920.         moveq.l    #'0',d2
  921. conv_10_al1    or.b    d2,d0
  922.         move.b    d0,(a1)+
  923.         and.b    #15,d3
  924.         beq.s    conv_10_al2
  925.         moveq.l    #'0',d2
  926. conv_10_al2    or.b    d2,d3
  927.         move.b    d3,(a1)+
  928.         dbf    d1,conv_10_al
  929.         or.b    #'0',d3
  930.         move.b    d3,-1(a1)
  931.         move.b    #0,(a1)
  932.         pull    all
  933.         rts
  934.  
  935. bcd_10        ds.l    2
  936. res_10        ds.l    2
  937. buf_10        ds.l    4
  938.  
  939.  
  940. sign_16        btst    #31,d0
  941.         beq.s    sign_16_plus
  942.         neg.l    d0
  943.         bsr.s    conv_16
  944.         move.b    #'-',buf_16+3
  945.         rts
  946. sign_16_plus    bsr.s    conv_16
  947.         move.b    #' ',buf_16+3
  948.         rts
  949.  
  950.  
  951. conv_16        push    d0-d2/a0-a1
  952.         lea    buf_16+8(pc),a0
  953.         lea    hextable(pc),a1
  954.         moveq.l    #3,d2
  955.         moveq.l    #0,d1
  956. conv_16_lp    move.b    d0,d1
  957.         and.b    #15,d1
  958.         move.b    0(a1,d1),-(a0)
  959.         lsr.l    #4,d0
  960.         move.b    d0,d1
  961.         and.b    #15,d1
  962.         move.b    0(a1,d1),-(a0)
  963.         lsr.l    #4,d0
  964.         dbf    d2,conv_16_lp
  965.         pull    d0-d2/a0-a1
  966.         rts
  967.  
  968. buf_16        ds.l    2
  969.         dc.w    0
  970.  
  971.  
  972. ck_opt        move.l    _CMDBuf(pc),a0        check for options on cmd line
  973.         move.l    obuf(pc),a1        copy filename into obuf
  974. ck_opt_lp1    move.b    (a0)+,d0        search for end of filename
  975.         move.b    d0,(a1)+        copy filename
  976.         beq.s    ck_opt_ex
  977.         bsr    ck_blk
  978.         bcc.s    ck_opt_lp1
  979.         clr.b    -1(a1)            add null to filename
  980. ck_opt_lp2    move.b    (a0)+,d0        find '-opt'
  981.         beq.s    ck_opt_ex
  982.         bsr    ck_blk
  983.         bcs.s    ck_opt_lp2        skip blanks
  984.         cmp.b    #'-',d0
  985.         bne.s    ck_opt_er
  986.         move.b    (a0)+,d0
  987.         bsr    ucase
  988.         cmp.b    #'L',d0            listmode?
  989.         bne.s    ck_opt_l
  990.         move.w    #1,userlmode        set default: listmode ON
  991.         move.w    #1,listmode
  992.         bra.s    ck_opt_lp2
  993. ck_opt_l    cmp.b    #'H',d0            hexmode?
  994.         bne.s    ck_opt_h
  995.         move.w    #1,hexmode
  996.         bra    ck_opt_lp2
  997. ck_opt_h    cmp.b    #'S',d0            symbolmode?
  998.         bne.s    ck_opt_s
  999.         move.w    #1,symbolmode
  1000.         bra    ck_opt_lp2
  1001. ck_opt_s    cmp.b    #'C',d0            CMOSmode?
  1002.         bne    ck_opt_s
  1003.         move.w    #1,procmode
  1004.         bra    ck_opt_lp2
  1005. ck_opt_c
  1006.  
  1007. ck_opt_er    error    #91            option error
  1008.         rts
  1009. ck_opt_ex    clrc
  1010.         rts
  1011.  
  1012.  
  1013. ;------------------------------------------------------------------------
  1014.  
  1015.  
  1016. OpenFiles    bsr    ck_opt            parse options
  1017.         bcs    Open_err
  1018.         move.l    obuf(pc),a0        filename is here
  1019.         tst.b    (a0)
  1020.         bne    Open_name_ok
  1021.         error    #81
  1022.         printa    #USAGE
  1023.         bra    Open_err
  1024.  
  1025. USAGE        dc.b    CSI,'1mUsage: Asm65 ',60,'filename',62,' [-opt]'
  1026.         dc.b    CSI,'0m',LF
  1027.         dc.b    ' where -opt is:',LF
  1028.         dc.b    '  -c for 65c02 instruction set',LF
  1029.         dc.b    '  -s for symbol table listing',LF
  1030.         dc.b    '  -h for hexadecimal output file',LF
  1031.         dc.b    '  -l for listing file'
  1032. LFLF        dc.b    LF,LF,0
  1033.         cnop    0,4
  1034.  
  1035.  
  1036. Open_name_ok    move.l    _CMDBuf(pc),linstrt    addr of cmdline
  1037.         bsr    mkname            create output filenames
  1038.  
  1039.         print    <'Checking file lengths...',LF>
  1040.         move.l    auxbuf(pc),a0        main filename
  1041.         move.l    #0,a1            output ptr=0: check length
  1042.         moveq.l    #0,d7            nesting level
  1043.         bsr    MainLoad
  1044.         bcs    Open_err
  1045.  
  1046.         move.l    total_len(pc),d0    total length of files
  1047.         move.l    d0,d1
  1048.         asr.l    #1,d1            multiply by 1.5
  1049.         add.l    d1,d0            (allow 50% for macros)
  1050.         add.l    #MINSOURCE,d0        add minimum size
  1051.         move.l    d0,SOURCEBUF
  1052.  
  1053.         move.l    SOURCEBUF(pc),d0    this many RAM bytes needed
  1054.         move.l    d0,d2
  1055.         sub.l    #256,d2            for safety
  1056.         move.l    #MEMF_CLEAR,d1
  1057.         lib    Exec,AllocMem        ask for them
  1058.         move.l    d0,sourcebuf        save start addr
  1059.         beq    Open_mem_er        no mem, exit
  1060.         add.l    d2,d0
  1061.         move.l    d0,sourceend        end of buffer
  1062.  
  1063.         print    <'Processing macros...',LF>
  1064.         move.l    auxbuf(pc),a0        filename
  1065.         move.l    sourcebuf(pc),a1    output ptr
  1066.         moveq.l    #0,d7            nesting level
  1067.         bsr    MainLoad
  1068.         bcs    Open_err
  1069.  
  1070. Open_ok        move.l    multibuf(pc),d1        file to write
  1071.         move.l    #1006,d2        mode: create
  1072.         lib    Dos,Open        open it
  1073.         move.l    d0,outfile        save ptr
  1074.         bne.s    Open_list
  1075.         error    #51
  1076.         bra.s    Open_err
  1077.  
  1078. Open_list    move.w    listmode(pc),d0        if (listmode)
  1079.         beq.s    Open_l_ok
  1080.         move.l    listfile(pc),d0
  1081.         bne.s    Open_l_ok
  1082.         move.l    multibuf(pc),d1        listfile
  1083.         add.l    #NAME1BUF,d1
  1084.         move.l    #1006,d2        mode: create
  1085.         lib    Dos,Open        open it
  1086.         move.l    d0,listfile        save ptr
  1087.         bne.s    Open_l_ok
  1088.         error    #52
  1089.         bra.s    Open_err
  1090.  
  1091. Open_l_ok    clrc
  1092.         rts
  1093.  
  1094. Open_mem_er    error    #42            mem alloc error
  1095. Open_err    setc
  1096.         rts
  1097.  
  1098.  
  1099. mkname        push    d0/a0/a1        create in/output filename
  1100.         move.l    obuf(pc),a0
  1101.         move.l    auxbuf(pc),a1        filename.asm
  1102.         bsr    strcpy
  1103.         subq.l    #1,a1
  1104.         lea    ASM_EXT(pc),a0
  1105.         bsr    strcpy            appends '.asm'
  1106.         move.l    obuf(pc),a0
  1107.         move.l    multibuf(pc),a1
  1108.         bsr    strcpy
  1109.         move.w    hexmode(pc),d0        if not in hexmode, no '.hex'
  1110.         beq.s    mkname1
  1111.         subq.l    #1,a1
  1112.         lea    HEX_EXT(pc),a0
  1113.         bsr    strcpy            appends '.hex'
  1114. mkname1        move.l    obuf(pc),a0
  1115.         move.l    multibuf(pc),a1
  1116.         add.l    #NAME1BUF,a1
  1117.         bsr    strcpy
  1118.         subq.l    #1,a1
  1119.         lea    LST_EXT(pc),a0
  1120.         bsr    strcpy            appends '.lst'
  1121.         pull    d0/a0/a1
  1122.         rts
  1123. ASM_EXT        dc.b    '.asm',0
  1124. HEX_EXT        dc.b    '.hex',0
  1125. LST_EXT        dc.b    '.lst',0
  1126.         cnop    0,4
  1127.  
  1128.  
  1129. calc        clr.b    zpabs
  1130.         bsr.s    calcq
  1131.         bcs.s    calinaa
  1132.         cmp.l    #256,d0
  1133.         blo.s    calc0
  1134.         or.b    #1,zpabs
  1135. calc0        tst.l    d0
  1136. calinaa        rts
  1137.  
  1138. calcq        push    d1            calculates at (txtptr)
  1139.         bsr    gnumb            calc level #0
  1140.         bcs.s    calcqere
  1141.         move.l    d0,d1
  1142. calcq0        bsr    gc
  1143.         cmp.b    #'+',d0            addition
  1144.         bne.s    calcq1
  1145.         bsr    gnumb
  1146.         bcs.s    calcqere
  1147.         add.l    d0,d1
  1148.         bvc.s    calcq0
  1149.         moveq.l    #101,d0
  1150. calcqv        error
  1151. calcqere    pull    d1
  1152.         setc
  1153.         rts
  1154. calcq1        cmp.b    #'-',d0            subtraction
  1155.         bne.s    calcq2
  1156.         bsr.s    gnumb
  1157.         bcs.s    calcqere
  1158.         sub.l    d0,d1
  1159.         bvc.s    calcq0
  1160.         move.w    #102,d0
  1161.         bra.s    calcqv
  1162. calcq2        cmp.b    #'&',d0            andition
  1163.         bne.s    calcq3
  1164.         bsr.s    gnumb
  1165.         bcs.s    calcqere
  1166.         and.l    d0,d1
  1167.         bra    calcq0
  1168. calcq3        cmp.b    #'!',d0            orition
  1169.         bne.s    calcq4
  1170.         bsr.s    gnumb
  1171.         bcs    calcqere
  1172.         or.l    d0,d1
  1173.         bra    calcq0
  1174. calcq4        cmp.b    #'^',d0            xorition
  1175.         bne.s    calcq5
  1176.         bsr.s    gnumb
  1177.         bcs    calcqere
  1178.         eor.l    d0,d1
  1179.         bra    calcq0
  1180. calcq5        cmp.b    #'<',d0            leftertion
  1181.         bne.s    calcq6
  1182.         bsr.s    gnumb
  1183.         bcs    calcqere
  1184.         asl.l    d0,d1
  1185.         bvc    calcq0
  1186.         move.w    #103,d0
  1187.         bra    calcqv
  1188. calcq6        cmp.b    #'>',d0            rightertion
  1189.         bne.s    calcq7
  1190.         bsr.s    gnumb
  1191.         bcs    calcqere
  1192.         asr.l    d0,d1
  1193.         bra    calcq0
  1194. calcq7        bsr    cg
  1195.         move.l    d1,d0
  1196.         pull    d1
  1197.         clrc
  1198.         rts
  1199.  
  1200.  
  1201. gnumb        push    d1            calc level #1
  1202.         bsr    gnumbb
  1203.         bcs.s    gnumbere
  1204.         move.l    d0,d1
  1205. gnumb0        bsr    gc
  1206.         cmp.b    #'*',d0            multiplication
  1207.         bne.s    gnumb1
  1208.         bsr.s    gnumbb
  1209.         bcs.s    gnumbere
  1210.         bsr    mulmul
  1211.         bcc    gnumb0
  1212.         moveq.l    #111,d0
  1213. gnumbv        error
  1214. gnumbere    pull    d1
  1215.         setc
  1216.         rts
  1217. gnumb1        cmp.b    #'/',d0            division
  1218.         bne.s    gnumb2
  1219.         bsr.s    gnumbb
  1220.         bcs.s    gnumbere
  1221.         bsr    divdiv
  1222.         bcc    gnumb0
  1223.         move.w    #131,d0            div. by 0
  1224.         bra    gnumbv
  1225. gnumb2        cmp.b    #'\',d0            modulo-op
  1226.         bne.s    gnumb3
  1227.         bsr.s    gnumbb
  1228.         bcs    gnumbere
  1229.         tst.w    d0
  1230.         beq.s    modmoderr
  1231.         push    d2
  1232.         move.l    d1,d2
  1233.         divs.w    d0,d2
  1234.         bvs.s    modmodvs
  1235.         clr.w    d2
  1236.         swap    d2
  1237.         ext.l    d2
  1238.         move.l    d2,d1
  1239.         pull    d2
  1240.         bra    gnumb0
  1241. modmoderr    move.w    #132,d0
  1242.         bra    gnumbv
  1243. modmodvs    pull    d2
  1244.         move.w    #286,d0
  1245.         bra    gnumbv
  1246. gnumb3        bsr    cg
  1247.         move.l    d1,d0
  1248.         pull    d1
  1249.         clrc
  1250.         rts
  1251.  
  1252.  
  1253. gnumbb        push    d1
  1254.         bsr    gc
  1255.         cmp.b    #'-',d0
  1256.         bne.s    gnumbb1
  1257.         bsr    gnumbb
  1258.         bcs.s    gnumbbere
  1259.         neg.l    d0
  1260. gnumbbx        pull    d1
  1261.         clrc
  1262.         rts
  1263. gnumbbparmism    error    #141
  1264. gnumbbere    pull    d1
  1265.         setc
  1266.         rts
  1267. gnumbb1        cmp.b    #'~',d0
  1268.         bne.s    gnumbb1_5
  1269.         bsr    gnumbb
  1270.         bcs.s    gnumbbere
  1271.         not.l    d0
  1272.         bra.s    gnumbbx
  1273. gnumbb1_5    cmp.b    #'[',d0
  1274.         bne.s    gnumbb2
  1275.         bsr    calcq
  1276.         bcs    gnumbbere
  1277.         move.l    d0,d1
  1278.         bsr    gc
  1279.         cmp.b    #']',d0
  1280.         bne    gnumbbparmism
  1281.         move.l    d1,d0
  1282.         bra    gnumbbx
  1283. gnumbb2        cmp.b    #'<',d0
  1284.         bne.s    gnumbb3
  1285.         bsr    gnumbb
  1286.         bcs    gnumbbere
  1287.         and.l    #$ff,d0
  1288.         bra    gnumbbx
  1289. gnumbb3        cmp.b    #'>',d0
  1290.         bne.s    gnumbb3_5
  1291.         bsr    gnumbb
  1292.         bcs    gnumbbere
  1293.         lsr.l    #8,d0
  1294.         bra    gnumbbx
  1295. gnumbb3_5    cmp.b    #'@',d0
  1296.         bne.s    gnumbb4
  1297.         bsr    getmn
  1298.         bcc.s    gnumbb3_5b
  1299. gnumbb3_5c    error    #532
  1300.         bra    gnumbbere
  1301. gnumbb3_5b    cmp.l    #'MODE',d0
  1302.         bne.s    gnumbb3_5c
  1303.         bsr    getmode
  1304.         bra    gnumbbx
  1305. gnumbb4        cmp.b    #'$',d0
  1306.         bne.s    gnumbb5
  1307.         bsr.s    gethex
  1308.         bcs    gnumbbere
  1309.         bra    gnumbbx
  1310. gnumbb5        cmp.b    #'%',d0
  1311.         bne.s    gnumbb6
  1312.         bsr    getbin
  1313.         bcs    gnumbbere
  1314.         bra    gnumbbx
  1315. gnumbb6        cmp.b    #'&',d0
  1316.         bne.s    gnumbb6_5
  1317.         bsr    getoct
  1318.         bcs    gnumbbere
  1319.         bra    gnumbbx
  1320. gnumbb6_5    cmp.b    #'^',d0
  1321.         bne.s    gnumbb7
  1322.         bsr    getqui
  1323.         bcs    gnumbbere
  1324.         bra    gnumbbx
  1325. gnumbb7        cmp.b    #39,d0
  1326.         bne.s    gnumbb8
  1327.         bsr    getasc
  1328.         bcs    gnumbbere
  1329.         bra    gnumbbx
  1330. gnumbb8        cmp.b    #'0',d0
  1331.         blo.s    gnumbb9
  1332.         cmp.b    #'9',d0
  1333.         bhi.s    gnumbb9
  1334.         bsr    cg
  1335.         bsr    getdec
  1336.         bcs    gnumbbere
  1337.         bra    gnumbbx
  1338. gnumbb9        bsr    cg
  1339.         bsr    glabel
  1340.         bcs    gnumbbere
  1341.         bra    gnumbbx
  1342.  
  1343.  
  1344. gethex        push    d1
  1345.         moveq.l    #0,d1
  1346. gethex1        bsr    gc
  1347.         bsr    ucase
  1348.         cmp.b    #'F',d0
  1349.         bhi.s    gethexx
  1350.         sub.b    #'0',d0
  1351.         blo.s    gethexx
  1352.         cmp.b    #10,d0
  1353.         blo.s    gethex2
  1354.         sub.b    #7,d0
  1355. gethex2        asl.l    #4,d1
  1356.         bvs.s    gethexe
  1357.         or.b    d0,d1
  1358.         bra    gethex1
  1359. gethexx        bsr    cg
  1360.         move.l    d1,d0
  1361.         pull    d1
  1362.         clrc
  1363.         rts
  1364. gethexe        error    #121
  1365.         pull    d1/d1
  1366.         rts
  1367.  
  1368. getbin        push    d1
  1369.         moveq.l    #0,d1
  1370. getbin1        bsr    gc
  1371.         cmp.b    #'1',d0
  1372.         bhi.s    gethexx
  1373.         sub.b    #'0',d0
  1374.         blo.s    gethexx
  1375.         add.l    d1,d1
  1376.         bvs.s    getbine
  1377.         or.b    d0,d1
  1378.         bra.s    getbin1
  1379. getbine        error    #122
  1380.         pull    d1/d1
  1381.         rts
  1382.  
  1383. getoct        push    d1
  1384.         moveq.l    #0,d1
  1385. getoct1        bsr    gc
  1386.         cmp.b    #'7',d0
  1387.         bhi    gethexx
  1388.         sub.b    #'0',d0
  1389.         blo    gethexx
  1390.         asl.l    #3,d1
  1391.         bvs.s    getocte
  1392.         or.b    d0,d1
  1393.         bra.s    getoct1
  1394. getocte        error    #123
  1395.         pull    d1/d1
  1396.         rts
  1397.  
  1398. getqui        push    d1
  1399.         moveq.l    #0,d1
  1400. getqui1        bsr    gc
  1401.         cmp.b    #'3',d0
  1402.         bhi    gethexx
  1403.         sub.b    #'0',d0
  1404.         blo    gethexx
  1405.         asl.l    #2,d1
  1406.         bvs.s    getquie
  1407.         or.b    d0,d1
  1408.         bra.s    getqui1
  1409. getquie        error    #124
  1410.         pull    d1/d1
  1411.         rts
  1412.  
  1413.  
  1414. getdec        push    d1/d2        get a decimal number
  1415.         moveq.l    #0,d1        clear result
  1416.         bsr    gc        get a byte
  1417. getdecloop    and.b    #15,d0        convert to binary
  1418.         add.l    d1,d1        multiply old value by 10
  1419.         bvs.s    getdece        if overflow
  1420.         move.l    d1,d2
  1421.         asl.l    #2,d1
  1422.         bvs.s    getdece
  1423.         add.l    d2,d1
  1424.         bvs.s    getdece
  1425.         add.l    d0,d1        add new digit
  1426.         bvs.s    getdece
  1427.         bsr    gec        get next byte
  1428.         bsr.s    ck_dig        is it a digit?
  1429.         bcs.s    getdecloop
  1430.         bsr    cg        dec txtptr
  1431.         move.l    d1,d0
  1432.         clrc
  1433.         pull    d1/d2
  1434.         rts
  1435. getdece        error    #125
  1436.         pull    d1/d2
  1437.         rts
  1438.  
  1439.  
  1440. getasc        push    d1
  1441.         moveq.l    #0,d1
  1442. getasc1        bsr    chr
  1443.         cmp.b    #' ',d0
  1444.         blo    gethexe
  1445.         cmp.b    #39,d0
  1446.         beq.s    getascx
  1447.         asl.l    #8,d1
  1448.         bvs    gethexe
  1449.         or.b    d0,d1
  1450.         bra.s    getasc1
  1451. getascx        bsr    gc
  1452.         bra    gethexx
  1453.  
  1454.  
  1455. ck_dig        cmp.b    #'0',d0        is it a digit?
  1456.         blo.s    ck_dig_n
  1457.         cmp.b    #'9',d0
  1458.         bhi.s    ck_dig_n
  1459.         setc
  1460.         rts
  1461. ck_dig_n    clrc
  1462.         rts
  1463.  
  1464.  
  1465. ck_ap        cmp.b    #'A',d0        is it alpha?
  1466.         blo.s    ck_ap_n
  1467.         cmp.b    #'Z',d0
  1468.         bhi.s    ck_ap_n
  1469.         setc
  1470.         rts
  1471. ck_ap_n        clrc
  1472.         rts
  1473.  
  1474. gece        bsr    gec
  1475.         bra.s    ck_eol
  1476. gce        bsr    gc
  1477.  
  1478. ck_eol        tst.b    d0        is it end-of-line?
  1479.         beq.s    ck_eol_y
  1480.         cmp.b    #';',d0
  1481.         bhi.s    ck_eol_n
  1482.         beq.s    ck_eol_co
  1483.         cmp.b    #CR,d0
  1484.         beq.s    ck_eol_y
  1485.         cmp.b    #LF,d0
  1486.         beq.s    ck_eol_y
  1487. ck_eol_n    clrc
  1488.         clrv
  1489.         rts
  1490. ck_eol_y    setc
  1491.         setv            v=1: null/CR/LF
  1492.         rts
  1493. ck_eol_co    setc            c=1: ;/null/CR/LF
  1494.         clrv
  1495.         rts
  1496.  
  1497. ck_lc        cmp.b    #'A',d0        A...Z
  1498.         blo.s    ck_lc1
  1499.         cmp.b    #'Z',d0
  1500.         bls.s    ck_lc_y
  1501.         cmp.b    #'a',d0        a...z
  1502.         blo.s    ck_lc5
  1503.         cmp.b    #'z',d0
  1504.         bls.s    ck_lc_y
  1505. ck_lc_n        clrc            not a label char
  1506.         clrv
  1507.         rts
  1508. ck_lc1        cmp.b    #'0',d0        0...9
  1509.         blo.s    ck_lc2
  1510.         cmp.b    #'9',d0
  1511.         bls.s    ck_lc_yn
  1512. ck_lc2        cmp.b    #'.',d0        '.'
  1513.         bne.s    ck_lc_n
  1514. ck_lc_y        setc            label char, non-numeric
  1515.         clrv
  1516.         rts
  1517. ck_lc_yn    setc            label char, numeric
  1518.         setv
  1519.         rts
  1520. ck_lc5        cmp.b    #'_',d0        '_'
  1521.         beq.s    ck_lc_y
  1522.         bra.s    ck_lc_n
  1523.  
  1524.  
  1525. ck_blk        cmp.b    #' ',d0        check if blank
  1526.         beq.s    ck_blk_y
  1527.         cmp.b    #TAB,d0
  1528.         beq.s    ck_blk_y
  1529.         clrc
  1530.         rts
  1531. ck_blk_y    setc            blank detected!
  1532.         rts
  1533.  
  1534.  
  1535. ck_ibit        push    d1
  1536.         bsr    gc        check if '#0,'...'#7,'
  1537.         cmp.b    #'#',d0
  1538.         bne.s    ck_ibit_n    if not #
  1539.         bsr    gec
  1540.         cmp.b    #'0',d0        if not 0...7
  1541.         blo.s    ck_ibit_n
  1542.         cmp.b    #'7',d0
  1543.         bhi.s    ck_ibit_n
  1544.         and.b    #15,d0
  1545.         move.l    d0,d1
  1546.         bsr    gec
  1547.         cmp.b    #',',d0
  1548.         bne.s    ck_ibit_n    if not comma
  1549.         move.l    d1,d0
  1550.         pull    d1
  1551.         setc
  1552.         rts
  1553. ck_ibit_n    pull    d1
  1554.         clrc
  1555.         rts
  1556.  
  1557.  
  1558. ck_lim16    cmp.l    #-32768,d0    is it -32768...65535
  1559.         blt.s    ck_lim16_n
  1560.         cmp.l    #65535,d0
  1561.         bgt.s    ck_lim16_n
  1562.         setc            yes
  1563.         rts
  1564. ck_lim16_n    clrc            no
  1565.         rts
  1566.  
  1567.  
  1568. ck_lim8        cmp.l    #255,d0
  1569.         bgt.s    ck_lim8_n
  1570.         cmp.l    #-128,d0
  1571.         blt.s    ck_lim8_n
  1572.         setc
  1573.         rts
  1574. ck_lim8_n    clrc
  1575.         rts
  1576.  
  1577.  
  1578. ck_str        bsr    gce        get string addresses for ifc, ifnc
  1579.         bcs.s    ck_str_er    end of line
  1580.         cmp.b    #39,d0
  1581.         bne.s    ck_str_er
  1582.         move.l    txtptr(pc),a0    start of first string
  1583. ck_str_lp1    bsr    gce        search for end of string 1
  1584.         bcs.s    ck_str_er
  1585.         cmp.b    #39,d0
  1586.         bne.s    ck_str_lp1
  1587.         bsr    gce
  1588.         cmp.b    #',',d0        check for comma
  1589.         bne.s    ck_str_er
  1590.         bsr    gce
  1591.         cmp.b    #39,d0
  1592.         bne.s    ck_str_er
  1593.         move.l    txtptr(pc),a1
  1594. ck_str_lp2    bsr    gce        find final '
  1595.         bcs.s    ck_str_er
  1596.         cmp.b    #39,d0
  1597.         bne.s    ck_str_lp2
  1598.         clrc
  1599.         rts
  1600. ck_str_er    error    #531        sye
  1601.         rts
  1602.  
  1603.  
  1604. ck_ifc        push    a0-a1
  1605.         bsr    ck_str
  1606.         bcs.s    ck_ifc_er
  1607. ck_ifc_lp1    move.b    (a0)+,d0    compare until '
  1608.         cmp.b    (a1)+,d0
  1609.         bne.s    ck_ifc_nequ
  1610.         cmp.b    #39,d0
  1611.         bne.s    ck_ifc_lp1
  1612.         pull    a0-a1
  1613.         moveq.l    #0,d0        equal
  1614.         rts
  1615. ck_ifc_nequ    pull    a0-a1
  1616.         moveq.l    #1,d0        differ
  1617.         rts
  1618. ck_ifc_er    pull    a0-a1        error
  1619.         rts
  1620.  
  1621.  
  1622. ck_ifi        push    a0-a3/d1
  1623.         bsr    ck_str
  1624.         bcs    ck_ifc_er
  1625.         cmp.b    #39,(a0)
  1626.         beq.s    ck_ifif
  1627. ck_ifi0        move.l    a0,a2
  1628. ck_ifi1        move.b    (a1)+,d0
  1629.         cmp.b    #39,d0
  1630.         beq.s    ck_ifinf
  1631.         cmp.b    (a2)+,d0
  1632.         bne.s    ck_ifi0
  1633.         move.l    a1,a3
  1634. ck_ifi2        move.b    (a2)+,d1
  1635.         cmp.b    #39,d1
  1636.         beq.s    ck_ifif
  1637.         move.b    (a1)+,d0
  1638.         cmp.b    #39,d0
  1639.         beq.s    ck_ifinf
  1640.         cmp.b    d0,d1
  1641.         beq.s    ck_ifi2
  1642.         move.l    a3,a1
  1643.         bra.s    ck_ifi0
  1644. ck_ifinf    pull    a0-a3/d1
  1645.         moveq.l    #-1,d0
  1646.         rts
  1647. ck_ifif        pull    a0-a3/d1
  1648.         moveq.l    #0,d0
  1649.         rts
  1650.  
  1651. ck_ifi_er    pull    a0-a3/d1
  1652.         rts
  1653.  
  1654.  
  1655. ucase        cmp.b    #'a',d0
  1656.         blo.s    ucase1
  1657.         cmp.b    #'z',d0
  1658.         bhi.s    ucase1
  1659.         sub.b    #32,d0
  1660. ucase1        rts
  1661.  
  1662.  
  1663. strcmp        push    d1        check if s0 = s1
  1664. strcmp1        move.b    (a0)+,d0
  1665.         beq.s    strcmp_1e
  1666.         move.b    (a1)+,d1
  1667.         beq.s    strcmp_s1l    string 1 less
  1668.         cmp.b    d1,d0
  1669.         beq.s    strcmp1
  1670.         bhi.s    strcmp_s1l    string 1 less
  1671. strcmp_s0l    pull    d1
  1672.         moveq.l    #-1,d0
  1673.         setc
  1674.         rts            s0 < s1
  1675.  
  1676. strcmp_1e    move.b    (a1)+,d1
  1677.         bne.s    strcmp_s0l    string 0 less
  1678.         pull    d1
  1679.         moveq.l    #0,d0
  1680.         rts            s0 = s1
  1681.  
  1682. strcmp_s1l    pull    d1
  1683.         moveq.l    #1,d0
  1684.         clrc
  1685.         rts            s0 > s1
  1686.  
  1687.  
  1688. strcpy        move.b    (a0)+,(a1)+    copy s0 to s1
  1689.         bne.s    strcpy
  1690.         rts
  1691.  
  1692.  
  1693. pass1        push    all
  1694.         bsr    Clr_LBuf        clear labelbuf
  1695.         move.l    sourcebuf(pc),txtptr    set text pointer
  1696.         move.l    sourcebuf(pc),linstrt
  1697.         clr.b    pat_pend    no LF's fetched
  1698.         move.w    userlmode,listmode
  1699.         moveq.l    #0,d0
  1700.         move.l    d0,prgc
  1701.         move.w    d0,cond_level    no conditioning
  1702.         moveq.l    #1,d0
  1703.         move.l    d0,linnum
  1704.         move.l    _CMDBuf(pc),nameptr    main filename for errhandler()
  1705.         move.b    #1,pass
  1706.         print    <'Pass 1 - Creating Symbol Table',LF>
  1707.  
  1708. pass1_loop    bsr    ck_stop
  1709.         bne    pass1_stop
  1710.         bsr    gpeek
  1711.         beq.s    pass1_end
  1712.         cmp.w    #-1,incstrt    check if a macro starts
  1713.         bne.s    pass1_nomac
  1714.         bsr    slabel        save labels on macro usage lines
  1715.         bra.s    pass1_macskip
  1716. pass1_nomac    bsr    ck_eol
  1717.         bcs.s    pass1_next
  1718.         bsr    ck_blk        if blank: no label
  1719.         bcs.s    pass1_nolab
  1720.         bsr    slabel
  1721.         bcs.s    pass1_next
  1722.         bsr    gc
  1723.         bsr    ck_eol
  1724.         bcs.s    pass1_next
  1725.         bsr    cg
  1726.  
  1727. pass1_nolab    bsr    seek_op
  1728.         bcs.s    pass1_next
  1729.         add.l    d0,prgc
  1730.         move.l    prgc(pc),d0
  1731.         bsr    ck_lim16
  1732.         bcc    pass_pc_high
  1733.         bsr    gce        line end?
  1734.         bcs.s    pass1_next
  1735.         error    #201
  1736.         bra.s    pass1_next
  1737. pass1_macskip    move.w    #-2,incstrt
  1738. pass1_next    bsr    condition    check conditional assembly
  1739.         bsr    seek_nexl
  1740.         clr.b    pat_pend    no LF's fetched over line end
  1741.         bra    pass1_loop
  1742. pass1_end    move.l    errcnt(pc),d0
  1743.         beq    pass1_noer
  1744.         print    <'Assembly aborted...'>
  1745.         clrc
  1746.         bsr    conv_10
  1747.         printa    #buf_10
  1748.         print    <' error(s) detected.',LF>
  1749. pass1_stop    pull    all
  1750.         setc
  1751.         rts
  1752. pass1_noer    print    <'Symbol table complete.',LF>
  1753.         pull    all
  1754.         clrc
  1755.         rts
  1756.  
  1757. pass_pc_high    error    #291        pc > $ffff
  1758.         bra    pass1_end
  1759.  
  1760.  
  1761. pass2        push    all
  1762.         move.l    sourcebuf(pc),txtptr    set text pointer
  1763.         move.l    sourcebuf(pc),linstrt
  1764.         clr.b    pat_pend        no LF's fetched
  1765.         bsr    list_clr
  1766.         move.w    userlmode,listmode
  1767.         moveq.l    #0,d0
  1768.         move.l    d0,prgc            pc=0
  1769.         move.w    d0,idepth        no including done
  1770.         move.w    d0,no_list        listing allowed
  1771.         move.w    d0,cond_level        no conditions operative
  1772.         move.w    d0,condstrt        no conditions started
  1773.         moveq.l    #1,d0
  1774.         move.l    d0,linnum        line=1
  1775.         move.l    _CMDBuf(pc),nameptr    main filename for errhandler()
  1776.         move.b    #2,pass            pass=2
  1777.         print    <'Pass 2 - Assembling',LF>
  1778.  
  1779. pass2_loop    bsr    ck_stop
  1780.         bne    pass2_stop
  1781.         clr.l    equset        no labels set yet
  1782.         bsr    gpeek
  1783.         beq    pass2_end
  1784.         cmp.w    #-1,incstrt    check if start of a macro
  1785.         beq.s    pass2_macskip    if it is, skip this line
  1786.         bsr    ck_eol
  1787.         bcs.s    pass2_nxt
  1788.         bsr    ck_blk
  1789.         bcs.s    pass2_nolab
  1790.         bsr    slabel2
  1791.         bcs.s    pass2_nxt
  1792.         bsr    gc
  1793.         bsr    ck_eol
  1794.         bcs.s    pass2_nxt
  1795.         bsr    cg
  1796.  
  1797. pass2_nolab    bsr    seek_op
  1798.         bcs.s    pass2_next
  1799.         bsr    listout            write listing
  1800.         bcs.s    pass2_end
  1801.         add.l    d0,prgc
  1802.         add.l    d0,totalbyt        add to bytes of object
  1803.         move.l    prgc(pc),d0
  1804.         bsr    ck_lim16
  1805.         bcc    pass_pc_high
  1806.         bsr    gce            end of line?
  1807.         bcs.s    pass2_next
  1808.         error    #202
  1809.         bra.s    pass2_next
  1810. pass2_macskip    move.w    #-2,incstrt
  1811. pass2_nxt    bsr    listout
  1812. pass2_next    bsr    condition        check start of conditional assembly
  1813.         bsr    seek_nexl
  1814.         clr.b    pat_pend        no LF's fetched
  1815.         bra    pass2_loop
  1816. pass2_end    move.l    errcnt(pc),d0
  1817.         beq    pass2_noer
  1818.         print    <'Assembly incomplete...'>
  1819.         clrc
  1820.         bsr    conv_10
  1821.         printa    #buf_10
  1822.         print    <' error(s) detected.',LF>
  1823. pass2_stop    pull    all
  1824.         setc
  1825.         rts
  1826. pass2_noer    print    <'No errors detected during this assembly.',LF>
  1827.         pull    all
  1828.         clrc
  1829.         rts
  1830.  
  1831.  
  1832. seek_nexl    push    d0/a0        seek for next source line
  1833.         move.l    txtptr(pc),a0
  1834. seek_nexl1    move.b    (a0)+,d0    find next CR/LF/NULL
  1835.         beq.s    seek_nexlend
  1836.         cmp.b    #CR,d0
  1837.         beq.s    seek_nexlf
  1838.         cmp.b    #LF,d0
  1839.         bne    seek_nexl1
  1840.         bra.s    seek_nexlf
  1841. seek_nexlend    subq.l    #1,a0
  1842. seek_nexlf    move.l    a0,txtptr
  1843.         move.l    a0,linstrt
  1844.         move.w    incstrt(pc),d0    macro/include file flag
  1845.         bmi.s    seek_macro    if macro, don't increment linnum
  1846.         beq.s    seek_not_inc    start of a new include file? eq=no
  1847.         moveq.l    #0,d0
  1848.         move.w    d0,incstrt    clear flag
  1849.         move.l    d0,linnum    reset linenumber
  1850.         addq.w    #1,idepth    processing include file now
  1851. seek_not_inc    addq.l    #1,linnum    increment line number
  1852. seek_macro    pull    d0/a0
  1853.         rts
  1854.  
  1855.  
  1856. condition    move.w    cond_level(pc),d1
  1857.         lea    condflags(pc),a0 check current state: true/false
  1858.         move.b    0(a0,d1.w),d1
  1859.         bmi.s    condit_on    MI: no assembly!!
  1860.         move.w    incstrt(pc),d1
  1861.         bmi    mac_def
  1862.         rts
  1863.  
  1864. condit_on    bsr    seek_nexl    get next line
  1865.         clr.b    pat_pend    DO SOME PATENTING HERE if meant to work...
  1866.         move.l    txtptr(pc),a0
  1867.         move.b    (a0),d0
  1868.         beq    condit_end    end of program
  1869.  
  1870.         bsr    ck_eol
  1871.         bcs    condit_next    eol or comment -> next line!
  1872.  
  1873.         bsr    ck_blk        if blank, no label
  1874.         bcs.s    condit_nolbel    I SAID NO LABEL!
  1875.         move.l    txtptr(pc),a0
  1876.         bsr    getlb        skip label name
  1877.         move.l    a0,txtptr
  1878.  
  1879. condit_nolbel    bsr    gce        get char, skip blanks
  1880.         bcs.s    condit_next    if end/comment, next
  1881.         bsr    cg        one char backwards! Don't eat 'E' of ENDC
  1882.         bsr    getmn
  1883.         bsr    condit_ck_mi    check if macro/include
  1884.         cmp.l    #'ENDC',d0
  1885.         beq.s    condit_leave
  1886.         lea    PSEUDOS(pc),a0    check if new start of cond. assembly
  1887. condit_ck_ifany    move.l    (a0)+,d1    check if it is a PSEUDO
  1888.         beq.s    condit_next
  1889.         cmp.l    d0,d1
  1890.         beq.s    condit_ck_if
  1891.         addq.l    #4,a0
  1892.         bra.s    condit_ck_ifany
  1893. condit_ck_if    lsr.l    #8,d0        check if it starts with 'IF'
  1894.         cmp.l    #'IF',d0
  1895.         beq.s    condit_deeper
  1896.         lsr.l    #8,d0
  1897.         cmp.l    #'IF',d0
  1898.         bne.s    condit_next
  1899. condit_deeper    move.w    cond_level(pc),d0
  1900.         addq.w    #1,d0        one step deeper, please!
  1901.         move.w    d0,cond_level
  1902.         lea    condflags(pc),a0
  1903.         move.b    #-1,0(a0,d0.w)    condition: false!!
  1904.         bra.s    condit_next
  1905.  
  1906. condit_leave    bsr    gce        if not eol, error
  1907.         bcc.s    condit_sye
  1908.         move.w    cond_level(pc),d0
  1909.         beq.s    condit_interr    internal error, no active conditions
  1910.         subq.w    #1,d0        one step upwards
  1911.         beq.s    condit_ended    no more conditions in effect
  1912.         lea    condflags(pc),a0
  1913.         tst.b    0(a0,d0.w)
  1914.         bmi.s    condit_not_yet    still in FALSE block
  1915.  
  1916. condit_ended    move.w    d0,cond_level    turn on assembly
  1917.         bsr    listout
  1918.         rts
  1919.  
  1920. condit_not_yet    move.w    d0,cond_level    one step upwards
  1921. condit_next    bsr    listout
  1922.         bra    condit_on
  1923.  
  1924. condit_sye    error    #203        syntax error
  1925.         bra    condit_next
  1926. condit_interr    error    #512        ENDC without cond. Should never happen.
  1927.         rts
  1928. condit_end    error    #521        missing ENDC
  1929.         rts
  1930.  
  1931. mac_def        cmp.w    #-4,d1        macro definition?
  1932.         beq.s    mac_def_skip
  1933.         rts
  1934. mac_def_skip    bsr    seek_nexl
  1935.         move.l    txtptr(pc),a0
  1936.         tst.b    (a0)
  1937.         beq.s    mac_def_eop
  1938.         bsr    getlb
  1939.         move.l    a0,txtptr
  1940.         bsr    getmn
  1941.         cmp.l    #'ENDM',d0
  1942.         beq.s    mac_def_done
  1943.         bsr    listout
  1944.         addq.l    #1,linnum
  1945.         bra.s    mac_def_skip
  1946. mac_def_done    bsr    listout
  1947.         clr.w    incstrt
  1948. mac_def_eop    rts
  1949.  
  1950.  
  1951. ;------------------------------------------------------------------------
  1952.  
  1953.  
  1954. PSD1        equ    'INCL'
  1955. PSD2        equ    'I'<<24+ID<<16+'ND'
  1956. PSD3        equ    'M'<<24+ID<<16+'CD'
  1957. PSD4        equ    'M'<<24+ID<<16+'CU'
  1958. PSD5        equ    'ENDM'
  1959.  
  1960. condit_ck_mi    push    d0-d1/a0-a1        prevents internal mnemonics
  1961.         cmp.l    #PSD1,d0        and line number incrementing
  1962.         beq.s    eudo_IBEG        in macros if false condition
  1963.         cmp.l    #PSD2,d0
  1964.         beq.s    eudo_IEND
  1965.         cmp.l    #PSD3,d0
  1966.         beq.s    eudo_MACS1
  1967.         cmp.l    #PSD4,d0
  1968.         beq.s    eudo_MACS2
  1969.         cmp.l    #PSD5,d0
  1970.         beq.s    eudo_ENDM        k f p w b t y?
  1971. condit_ck_ok    pull    d0-d1/a0-a1
  1972.         rts
  1973.  
  1974. eudo_IBEG    bsr    cg
  1975.         bsr    getmn
  1976.         cmp.l    #'LUDE',d0        check the rest of the mnemonic
  1977.         bne.s    condit_ck_ok
  1978.         move.w    #1,incstrt        flag: include file starts
  1979.         bra.s    condit_ck_ok
  1980.  
  1981.  
  1982. eudo_IEND    move.w    #1,no_list        don't write this line into listfile!
  1983.         bra.s    condit_ck_ok
  1984.  
  1985.  
  1986. eudo_MACS1    move.w    #-4,incstrt        flag: macro definition starts
  1987.         move.w    #1,no_list
  1988.         bra.s    condit_ck_ok
  1989.  
  1990.  
  1991. eudo_MACS2    move.w    #-1,incstrt        flag: macro expansion starts
  1992.         move.w    #1,no_list
  1993.         bra.s    condit_ck_ok
  1994.  
  1995.  
  1996. eudo_ENDM    clr.w    incstrt            reset macro flag
  1997.         move.w    #1,no_list        if macro usage, don't list!
  1998.         bra.s    condit_ck_ok
  1999.  
  2000.  
  2001.  
  2002.  
  2003. *************************************************************************
  2004. *                                    *
  2005. * Uses this to evaluate symbol values during pass1 and to store symbols    *
  2006. * in buffer.                                *
  2007. *                                    *
  2008. *************************************************************************
  2009.  
  2010. slabel        push    all        save label in buffer
  2011.         bsr    gce        get char, check for line end
  2012.         bcs    slabel_okay    line end
  2013.         cmp.b    #'*',d0
  2014.         beq    slabel_star
  2015.  
  2016.         move.l    linstrt(pc),a0
  2017.         bsr    getlb
  2018.         bcs.s    slabel_err    illegal char
  2019.         bvs.s    slabel_err    too long name
  2020.         move.l    a0,txtptr
  2021.  
  2022.         moveq.l    #LABELSPC,d1    space needed for each symbol
  2023.         move.l    labelbuf(pc),a2    get buffer start addr
  2024.         move.l    a2,a3
  2025.         add.l    #LABELBUF-48,a3    end of buffer
  2026. slabel_seek    lea    tbuffer(pc),a1    symbol in program
  2027.         move.l    a2,a0        symbol in buffer
  2028.         tst.b    (a0)        no more labels in buffer?
  2029.         beq.s    slabel_ins    add new symbol here!
  2030.         bsr    strcmp        re-definition?
  2031.         beq.s    slabel_redef    yes, possible ermsg
  2032.         add.l    d1,a2        index to next symbol
  2033.         cmp.l    a3,a2        check if end of buffer
  2034.         blo.s    slabel_seek
  2035.         error    #301        out of symbol space
  2036. slabel_err    clr.w    sl_flag        not in slabel
  2037.         setc
  2038.         pull    all
  2039.         rts
  2040. slabel_redef    move.b    LINFO(a2),d0    get info byte
  2041.         btst    #0,d0        set by prgline? Then redefinition
  2042.         beq.s    slabel_noins    NOT allowed. Otherwise no need to insert name
  2043.         btst    #1,d0
  2044.         bne.s    slabel_noins    SET - no ermsg if redefined
  2045.  
  2046. slabel_re_err    error    #311        redefined
  2047.         bra.s    slabel_err
  2048. slabel_ins    move.l    a2,a1        copy name into buffer
  2049.         lea    tbuffer(pc),a0
  2050.         bsr    strcpy
  2051.         clr.b    LINFO(a2)    no flags set by default
  2052. slabel_noins    move.l    txtptr(pc),a5
  2053.         bsr    getmn        is it equ or set?
  2054.         bcs.s    slabel_nomnem    no mnemonic on this line
  2055.         beq.s    slabel_nomnem    no mnemonic on this line
  2056.         move.b    LINFO(a2),d2    Temporary LINFO for set/equ set here
  2057.         cmp.l    #'EQU',d0
  2058.         beq.s    slabel_iequ
  2059.         cmp.l    #'SET',d0
  2060.         beq.s    slabel_iset
  2061. slabel_nomnem    move.b    LINFO(a2),d0
  2062.         and.b    #%110,d0
  2063.         bne.s    slabel_eror1    set or equ used before -> error
  2064.         move.l    a5,txtptr
  2065.         move.l    prgc(pc),LVALUE(a2)
  2066.         bset    #0,LINFO(a2)    in prg: absolute value
  2067.         bra.s    slabel_okay    exit
  2068.  
  2069. slabel_iequ    bset    #2,d2        EQUted, temp flag because GLABEL still
  2070.         bra.s    slabel_ii     needs LINFO
  2071. slabel_iset    bset    #1,d2        SET
  2072. slabel_ii    btst    #2,LINFO(a2)
  2073.         bne.s    slabel_eror2    equ used before
  2074.         bset    #0,d2        set as ABSOLUTE for a while...
  2075.         move.w    #1,sl_flag    flag for glabel: equ or set
  2076.         bsr    calc
  2077.         bcs    slabel_err
  2078.         bsr    ck_lim16
  2079.         bcc.s    slabel_inv
  2080.         move.l    d0,LVALUE(a2)    save value!
  2081.         tst.b    zpabs
  2082.         bne.s    slabel_equset
  2083.         bclr    #0,d2        ... but reset if zp
  2084. slabel_equset    move.b    d2,LINFO(a2)    Set Real Label Info!
  2085. slabel_okay    clr.w    sl_flag        not in slabel
  2086.         pull    all
  2087.         rts
  2088.  
  2089. slabel_eror1    error    #361        illegal prg const
  2090.         bra    slabel_err
  2091. slabel_eror2    error    #351        EQU redefined
  2092.         bra    slabel_err
  2093. slabel_inv    error    #126        illegal value
  2094.         bra    slabel_err
  2095. slabel_pc_high    error    #292        pc > $ffff
  2096.         bra    slabel_err
  2097. slabel_sye    error    #204        syntax error
  2098.         bra    slabel_err
  2099. slabel_ste    error    #205        -  "  -
  2100.         bra    slabel_err
  2101. slabel_stnmn    error    #261        equ expected
  2102.         bra    slabel_err
  2103.  
  2104. slabel_star    bsr    getmn        must be 'equ'
  2105.         bcs    slabel_stnmn
  2106.         cmp.l    #'EQU',d0
  2107.         bne    slabel_ste
  2108.         move.w    #1,sl_flag    flag for glabel: equ or set
  2109.         bsr    calc
  2110.         bcs    slabel_err
  2111.         bsr    ck_lim16
  2112.         bcc    slabel_pc_high
  2113.         move.l    d0,prgc        set program counter
  2114.         bra    slabel_okay        
  2115.  
  2116.  
  2117.  
  2118. *************************************************************************
  2119. *                                    *
  2120. * Uses this to evaluate symbol values during pass2.            *
  2121. *                                    *
  2122. * Checks if non-equset values are same as during pass1.  Passes values    *
  2123. * to listing routines.                            *
  2124. *                                    *
  2125. *************************************************************************
  2126.  
  2127. slabel2        push    all        uses this during pass #2
  2128.         bsr    gce        get char, check for line end
  2129.         bcs    slabel2_okay    line end
  2130.         cmp.b    #'*',d0
  2131.         beq    slabel2_star
  2132.  
  2133.         move.l    linstrt(pc),a0
  2134.         bsr    getlb
  2135.         move.l    a0,txtptr
  2136.  
  2137.  
  2138. ; find old symbol, its value and LINFO:
  2139.  
  2140.         move.l    labelbuf(pc),a2
  2141.         moveq.l    #LABELSPC,d1    offset to next symbol
  2142. slabel2_seek    move.l    a2,a1        addr in symbol buffer
  2143.         lea    tbuffer(pc),a0    current name
  2144.         tst.b    (a1)        last label?
  2145.         beq    slabel2_nf    not found
  2146.         bsr    strcmp
  2147.         beq.s    slabel2_fnd    found
  2148.         add.l    d1,a2        get addr of next symbol in buffer
  2149.         bra.s    slabel2_seek
  2150.  
  2151. slabel2_fnd    move.b    LINFO(a2),d2    get old LINFO value for comparison
  2152.         move.l    LVALUE(a2),d3    get old LVALUE for comparison
  2153.  
  2154.         move.l    txtptr(pc),a5
  2155.         bsr    getmn        is it equ or set?
  2156.         bcs.s    slabel2_nomnem    no mnemonic on this line
  2157.         beq.s    slabel2_nomnem    no mnemonic on this line
  2158.         moveq.l    #0,d4        equset value for listing routines
  2159.         cmp.l    #'EQU',d0
  2160.         beq.s    slabel2_iequ
  2161.         cmp.l    #'SET',d0
  2162.         beq.s    slabel2_iset
  2163.  
  2164. slabel2_nomnem    move.l    a5,txtptr
  2165.         cmp.l    prgc(pc),d3    compare with old value
  2166.         bne.s    slabel2_a_mism    absolute address mismatch
  2167.         btst    #0,d2        check if absolute during pass1
  2168.         bne    slabel2_okay    if it was, then exit
  2169. slabel2_a_mism    move.w    absmism(pc),d0    print this message only once!
  2170.         bne    slabel2_err
  2171.         move.w    #1,absmism
  2172.         error    #381        abs addr mismatch
  2173.         bra.s    slabel2_err
  2174. slabel2_e_mism    error    #391        set/equ value mismatch
  2175.         bra.s    slabel2_err
  2176.  
  2177. slabel2_iequ    bset    #31,d4        needs the old value during calc()
  2178.         move.w    #1,sl_flag    flag for glabel: equ or set
  2179.         bsr    calc
  2180.         bcs.s    slabel2_err
  2181.         bsr    ck_lim16
  2182.         bcc    slabel_inv
  2183.         btst    #1,d2
  2184.         bne.s    slabel2_set_va    write pass2 value to SET symbols
  2185.         bra.s    slabel2_va_ck    check values
  2186.  
  2187. slabel2_iset    bset    #30,d4        equset may never be zero after EQU/SET
  2188.         move.w    #1,sl_flag    flag for glabel: equ or set
  2189.         bsr    calc
  2190.         bcs.s    slabel2_err
  2191.         bsr    ck_lim16
  2192.         bcc    slabel_inv
  2193. slabel2_set_va    move.l    d0,d3        use pass2 value for SET symbols
  2194.         move.l    d0,LVALUE(a2)    update SET value in pass2, too
  2195.  
  2196. slabel2_va_ck    cmp.l    d0,d3        compare pass1 and pass2 values
  2197.         bne    slabel2_e_mism     if <> -> error
  2198.         move.w    d3,d4        correct value for listing routines
  2199.         move.l    d4,equset    Pass the LVALUE and flags to lst rtns
  2200. slabel2_okay    clr.w    sl_flag        not in slabel2
  2201.         pull    all
  2202.         rts
  2203.  
  2204. slabel2_nf    error    #342        symbol not found in buffer
  2205. slabel2_err    clr.w    sl_flag        not in slabel2
  2206.         setc
  2207.         pull    all
  2208.         rts
  2209.  
  2210. slabel2_star    bsr    getmn        must be 'equ'
  2211.         move.w    #1,sl_flag    flag for glabel: equ or set
  2212.         bsr    calc
  2213.         bcs    slabel2_err
  2214.         bsr    ck_lim16
  2215.         bcc    slabel_pc_high
  2216.         move.l    d0,prgc        set program counter
  2217.         move.l    #$c0000000,d2
  2218.         move.w    d0,d2
  2219.         move.l    d2,equset
  2220.         bra    slabel2_okay
  2221.  
  2222.  
  2223.  
  2224. *************************************************************************
  2225. *                                    *
  2226. * Finds a symbol in buffer and get its value & zpabs.            *
  2227. *                                    *
  2228. *************************************************************************
  2229.  
  2230. glabel        push    d1-d2/a0-a2
  2231.         bsr    gce        is it '* + sth'?
  2232.         bcs    glabel_nam_miss    line end = error
  2233.         cmp.b    #'*',d0
  2234.         beq    glabel_star
  2235.  
  2236.         move.l    txtptr(pc),a0
  2237.         subq.l    #1,a0
  2238.         bsr    getlb
  2239.         bcs    glabel_nam_ierr    if not a legal label
  2240.         bvs    glabel_err    if name too long
  2241.         move.l    a0,txtptr
  2242.  
  2243. glabel_copied    move.l    labelbuf(pc),a2
  2244.         moveq.l    #LABELSPC,d1    offset to next symbol
  2245. glabel_seek    move.l    a2,a1        addr in symbol buffer
  2246.         lea    tbuffer(pc),a0    current name
  2247.         tst.b    (a1)        last label?
  2248.         beq.s    glabel_nf    not found
  2249.         bsr    strcmp
  2250.         beq.s    glabel_fnd    found
  2251.         add.l    d1,a2        get addr of next symbol in buffer
  2252.         bra.s    glabel_seek
  2253. glabel_nf    move.b    #1,zpabs    not zero page
  2254.         move.w    #1,lnf        label not found for ifd/ifnd
  2255.         moveq.l    #0,d0        return value zero
  2256.         move.w    sl_flag(pc),d1    if from slabel, must print error always
  2257.         bmi.s    glabel_ok    if from ifd/ifnd, never complain!
  2258.         bne.s    glabel_nf_e
  2259.         cmp.b    #1,pass        if pass#1, no error
  2260.         beq.s    glabel_ok
  2261. glabel_nf_e    error    #341        unknown symbol
  2262.         bra.s    glabel_err
  2263. glabel_fnd    move.l    LVALUE(a2),d0    get symbol value
  2264.         move.b    LINFO(a2),d1    get info
  2265.         and.b    #1,d1        only zpabs
  2266.         or.b    d1,zpabs
  2267.         cmp.b    #1,pass        if pass#1, don't increment lusage
  2268.         beq.s    glabel_ok
  2269.         addq.l    #1,LUSAGE(a2)
  2270. glabel_ok    clrc
  2271.         pull    d1-d2/a0-a2
  2272.         rts
  2273.  
  2274. glabel_nam_miss    error    #371
  2275.         bra.s    glabel_err
  2276. glabel_nam_ierr    error    #321
  2277. glabel_err    pull    d1-d2/a0-a2
  2278.         setc
  2279.         rts
  2280.  
  2281. glabel_star    move.l    prgc(pc),d0    current pc
  2282.         or.b    #1,zpabs
  2283.         bra    glabel_ok
  2284.  
  2285.  
  2286.  
  2287. *************************************************************************
  2288. *                                    *
  2289. * Print all symbol values in alphabetical order along their values.    *
  2290. * If listmode then print to listfile, too.                *
  2291. *                                    *
  2292. *************************************************************************
  2293.  
  2294. dumplabels    tst.w    symbolmode
  2295.         bne.s    dumplabels_y
  2296.         rts
  2297. dumplabels_y    push    all
  2298.         move.w    #100,prtline        change page!
  2299.         bsr    header
  2300.         printa    #DUMPL_HD
  2301. dumpl_hd    move.w    listmode(pc),d0
  2302.         beq.s    dumpl_loop
  2303.         printa    #DUMPL_HD,listfile(pc)
  2304. dumpl_loop    bsr    ck_stop            check if panic!
  2305.         bne.s    dumpl_exit
  2306.         move.l    libuf(pc),a1        write ptr
  2307.         move.l    a1,a2
  2308.         bsr    dump_one
  2309.         beq.s    dumpl_exit
  2310.         add.l    #17,a2
  2311.         bsr    fill_spc
  2312.         bsr    dump_one
  2313.         move.b    #LF,(a1)+
  2314.         clr.b    (a1)
  2315.         printa    libuf(pc)
  2316.         move.w    listmode(pc),d0
  2317.         beq.s    dumpl_nolist
  2318.         printa    libuf(pc),listfile(pc)
  2319. dumpl_nolist    bsr    header
  2320.         tst.w    prtline
  2321.         beq    dumpl_hd
  2322.         bra.s    dumpl_loop
  2323.  
  2324. dumpl_exit    pull    all
  2325.         rts
  2326.  
  2327. DUMPL_HD    dc.b    LF,'symbol_name      value type usage'
  2328.         dc.b    '           symbol_name      value type usage'
  2329.         dc.b    LF,0
  2330.         cnop    0,4
  2331.  
  2332.  
  2333. dump_one    bsr.s    next_lab        find smallest name
  2334.         beq.s    dump_onex
  2335.         move.l    a0,a3            save name ptr
  2336.         add.l    #17,a2
  2337.         bsr    strcpy            symbol name
  2338.         subq.l    #1,a1
  2339.         bsr    fill_spc
  2340.         move.l    LVALUE(a3),d0
  2341.         bsr    sign_16
  2342.         lea    buf_16+3(pc),a0
  2343.         bsr    strcpy            value
  2344.         moveq.l    #' ',d0
  2345.         move.b    d0,-1(a1)
  2346.         move.b    d0,(a1)+
  2347.         move.b    d0,(a1)+
  2348.         move.b    d0,(a1)+
  2349.         move.b    d0,(a1)+
  2350.         move.b    LINFO(a3),d0        info
  2351.         btst    #0,d0            zpabs
  2352.         bne.s    dumpo_nz
  2353.         move.b    #'z',-3(a1)        zero page
  2354. dumpo_nz    btst    #1,d0            set
  2355.         beq.s    dumpo_ns
  2356.         move.b    #'s',-1(a1)
  2357. dumpo_ns    btst    #2,d0            equ
  2358.         beq.s    dumpo_ne
  2359.         move.b    #'e',-2(a1)
  2360. dumpo_ne    add.l    #10,a2
  2361.         move.l    LUSAGE(a3),d0
  2362.         clrc
  2363.         bsr    conv_10
  2364.         lea    buf_10+6(pc),a0
  2365.         bsr    strcpy            usage
  2366.         subq.l    #1,a1
  2367.         moveq.l    #1,d0            clr z-flag
  2368. dump_onex    rts
  2369.  
  2370.  
  2371. next_lab    push    d0-d1/a1-a3
  2372.         move.l    labelbuf(pc),a2
  2373.         lea    VeryBIG(pc),a3        The biggest string in the world!
  2374.         moveq.l    #0,d1            d1 is flag: smaller found
  2375.         bra.s    next_lab1
  2376.  
  2377. next_lab_next    add.l    #LABELSPC,a2
  2378. next_lab1    move.l    a2,a0            labelbufptr
  2379.         move.l    a3,a1            smallestptr
  2380.         tst.b    (a0)
  2381.         beq.s    next_lext
  2382.         tst.b    LINFO(a0)
  2383.         bmi.s    next_lab_next
  2384.         bsr    strcmp
  2385.         tst.b    d0
  2386.         bpl.s    next_lab_next
  2387.         move.l    a2,a3            smaller found
  2388.         moveq.l    #1,d1            set flag
  2389.         bra.s    next_lab_next
  2390.  
  2391. next_lext    tst.l    d1            eq if no labels left
  2392.         beq.s    next_lexit        do NOT set LINFO of VeryBIG!!!
  2393.         move.l    a3,a0
  2394.         bset    #7,LINFO(a0)        this label used
  2395. next_lexit    tst.l    d1            eq if no labels left
  2396.         pull    d0-d1/a1-a3
  2397.         rts
  2398.  
  2399. VeryBIG        dc.w    $ffff,0
  2400.  
  2401.  
  2402. fill_spc    move.b    #' ',(a1)+
  2403.         cmp.l    a2,a1
  2404.         blo.s    fill_spc
  2405.         rts
  2406.  
  2407.  
  2408. header        tst.w    listmode
  2409.         beq.s    header_ex
  2410.         push    all
  2411.         move.w    prtline(pc),d0
  2412.         cmp.w    maxline(pc),d0
  2413.         bhi.s    header_new_pg
  2414.         addq.l    #1,d0
  2415.         move.w    d0,prtline
  2416.         pull    all
  2417. header_ex    rts
  2418. header_new_pg    move.w    prtpage(pc),d0        if first page, no FF
  2419.         beq.s    header_new
  2420.         lea    FFPAGEMSG(pc),a2
  2421. header_new_ex    addq.l    #1,d0
  2422.         move.w    d0,prtpage
  2423.         clr.w    prtline
  2424.         moveq.l    #0,d0
  2425.         move.w    prtpage(pc),d0
  2426.         clrc
  2427.         bsr    conv_10
  2428.         lea    buf_10+7(pc),a0
  2429.         lea    PAGENUM(pc),a1
  2430.         bsr    copy_10
  2431.         printa    a2,listfile(pc)
  2432.         pull    all
  2433.         rts
  2434. header_new    lea    PAGEMSG(pc),a2
  2435.         bra.s    header_new_ex
  2436.  
  2437. FFPAGEMSG    dc.b    FF
  2438. PAGEMSG        dc.b    ' 65c02 Cross Assembler '
  2439.         VERSION
  2440.         dc.b    '  (c) J. & T. Marin 1988 '
  2441. PAGENULL    dc.b    0,'                --  Page #'
  2442. PAGENUM        dc.b    '     '
  2443.         dc.b    '  --',LF,LF,0
  2444.         cnop    0,4
  2445.  
  2446.  
  2447.  
  2448. *************************************************************************
  2449. *                                    *
  2450. * Resolve mnemonic and addressing mode.  Calls PSEUDOS to handle pseudo    *
  2451. * mnemonics.                                *
  2452. *                                    *
  2453. *************************************************************************
  2454.  
  2455. seek_op        push    d1-d7/a0-a1        search for op codes
  2456.         lea    OpCodes(pc),a0        addr of table
  2457.         moveq.l    #Op_Codes-OpCodes,d2    bytes betw. mnemonics in table
  2458.         bsr    getmn
  2459.         beq    seek_end    line end gives zero bytes
  2460.         bcs    seek_op_e1
  2461.         move.l    d0,d1
  2462. seek_m_ok    move.l    (a0),d0        here d1/d0 contain current mnemonic
  2463.         beq    seek_nf        not found
  2464.         cmp.l    d1,d0
  2465.         beq.s    seek_found
  2466.         add.l    d2,a0        index to next entry in table
  2467.         bra.s    seek_m_ok    continue search
  2468. seek_found    clrx            not jmp-processing
  2469.         bsr    amode        resolve addressing mode (d0)
  2470.         bcs    seek_op_er
  2471.         move.b    4(a0,d0),d1    fetch opcode
  2472.         beq.s    seek_op_rel    if null, is it relative then? Or zp,y?
  2473.         moveq.l    #0,d2
  2474.         lea    OpLen(pc),a1
  2475.         move.b    0(a1,d0),d2    fetch byte#
  2476.         bra.s    seek_rdy
  2477.  
  2478. seek_op_rel    cmp.b    #ABS,d0        check if absolute (it could be relative)
  2479.         bne    seek_op_zpy    no, not abs/rel. Is it zp,y?
  2480.         move.b    4+REL(a0),d1    get relative opcode
  2481.         beq    seek_op_ae    if it's null, relative not available
  2482.         moveq.l    #2,d2        length is 2 bytes for rel
  2483.         cmp.b    #1,pass        don't test offset during pass#1
  2484.         beq.s    seek_rdy
  2485.         move.l    par1(pc),d3    get dest addr
  2486.         sub.l    prgc(pc),d3    substract current addr
  2487.         subq.l    #2,d3
  2488.         cmp.l    #-128,d3
  2489.         blt    seek_op_rele    offset too small
  2490.         cmp.l    #127,d3
  2491.         bgt    seek_op_rele    offset too large
  2492.         move.l    d3,par1        store actual parameter or offset
  2493. seek_rdy    moveq.l    #0,d3        calc index/bit into 65c02 check list
  2494.         move.b    d1,d3        opcode into d3
  2495.         move.l    d3,d4        and d4
  2496.         and.b    #15,d4
  2497.         eor.b    #15,d4        d4 = bit#
  2498.         lsr.b    #3,d3        d3 = index
  2499.         and.b    #%11111110,d3    address must be even
  2500.         lea    CPU(pc),a1
  2501.         move.w    0(a1,d3),d3
  2502.         btst    d4,d3
  2503.         beq.s    seek_write
  2504.         move.w    procmode(pc),d0    if CMOS mode, no error
  2505.         bne.s    seek_write
  2506.         error    #231        65c02 only
  2507. seek_write    move.l    par1(pc),d3    get possible parameter
  2508.         cmp.b    #1,pass
  2509.         beq.s    seek_done
  2510.         moveq.l    #0,d7
  2511.         move.b    d1,d7
  2512.         bsr    output        sends opcode
  2513.         cmp.b    #1,d2
  2514.         beq.s    seek_done
  2515.         move.b    d3,d7
  2516.         bsr    output        sends first param byte
  2517.         cmp.b    #2,d2
  2518.         beq.s    seek_done
  2519.         lsr.l    #8,d3
  2520.         move.b    d3,d7
  2521.         bsr    output        sends second param byte
  2522.  
  2523. seek_done    move.l    d2,d0        length
  2524.         clrc
  2525.         pull    d1-d7/a0-a1
  2526.         rts
  2527. seek_end    moveq.l    #0,d2        length zero
  2528.         bra    seek_done
  2529. seek_op_e1    error    #206        syntax error
  2530.         bra.s    seek_op_er
  2531. seek_op_e2    error    #207        syntax error
  2532.         bra.s    seek_op_er
  2533. seek_op_e3    error    #208        syntax error
  2534. seek_op_er    pull    d1-d7/a0-a1
  2535.         moveq.l    #0,d0        destination length: zero
  2536.         setc
  2537.         rts
  2538. seek_op_ae    error    #211        unknown addressing mode
  2539.         bra    seek_op_er
  2540. seek_op_zp    error    #221        zp expected
  2541.         bra    seek_op_er
  2542. seek_op_ie    error    #251        illegal addressing mode
  2543.         bra    seek_op_er
  2544. seek_op_rele    error    #241        offset too large
  2545.         bra    seek_op_er
  2546.  
  2547. seek_op_zpy    cmp.b    #ZPY,d0        if zpy, replace with abs,y
  2548.         bne    seek_op_ae
  2549.         move.b    4+ABSY(a0),d1    get abs,y opcode
  2550.         beq    seek_op_ae    if it's null, abs,y not available
  2551.         moveq.l    #3,d2        length is 3 bytes for abs,y
  2552.         bra    seek_rdy
  2553.  
  2554. seek_nf        move.l    d1,d7        preserve current mnemonic
  2555.         cmp.l    #'BRK',d1
  2556.         bne.s    seek_cJMP
  2557.         clrx            not jmp-processing
  2558.         bsr    amode
  2559.         bcs    seek_op_er
  2560.         cmp.b    #IMP,d0        BRK is always implied!
  2561.         bne    seek_op_ie
  2562.         moveq.l    #0,d1
  2563.         moveq.l    #1,d2        length
  2564.         bra    seek_write    d1 = opcode
  2565.  
  2566. seek_cJMP    cmp.l    #'JMP',d1
  2567.         bne.s    seek_cBBR
  2568.         setx            now processing a jmp instruction
  2569.         bsr    amode
  2570.         bcs    seek_op_er
  2571.         lea    OpJMP(pc),a1
  2572.         move.b    0(a1,d0),d1    fetch opcode
  2573.         beq    seek_op_ae    illegal addr mode
  2574.         moveq.l    #3,d2        length
  2575.         bra    seek_rdy
  2576.  
  2577. seek_cBBR    cmp.l    #'BBR',d1
  2578.         beq.s    seek_yBBR
  2579.         cmp.l    #'BBS',d1
  2580.         bne    seek_cRMB
  2581.         bsr    ck_ibit        check if immediate bit number
  2582.         bcc    seek_op_e2    sye
  2583.         move.l    d0,d1        bit#
  2584.         asl.b    #4,d1        into upper nybble
  2585.         or.b    #%10001111,d1    set opcode to $8f+bit
  2586.         bra.s    seek_yBBx
  2587. seek_yBBR    bsr    ck_ibit        check if immediate bit number
  2588.         bcc    seek_op_e2    sye
  2589.         move.l    d0,d1        bit#
  2590.         asl.b    #4,d1        into upper nybble
  2591.         or.b    #%00001111,d1    set opcode to $0f+bit
  2592. seek_yBBx    bsr    calc
  2593.         bcs    seek_op_er
  2594.         tst.b    zpabs        must be zero page
  2595.         bne    seek_op_zp
  2596.         move.l    d0,d3        mem loc addr into d3
  2597.         bsr    gc
  2598.         cmp.b    #',',d0
  2599.         bne    seek_op_e2
  2600.         bsr    calc        get dest addr
  2601.         bcs    seek_op_er
  2602.         moveq.l    #3,d2        length is 3 bytes for these
  2603.         cmp.b    #1,pass        don't test offset during pass#1
  2604.         beq    seek_rdy
  2605.         sub.l    prgc(pc),d0    subtract current addr
  2606.         subq.l    #3,d0
  2607.         cmp.l    #-128,d0
  2608.         blt    seek_op_rele    offset too small
  2609.         cmp.l    #127,d0
  2610.         bgt    seek_op_rele    offset too large
  2611.         asl.l    #8,d0        make space for mem loc addr
  2612.         or.b    d3,d0
  2613.         move.l    d0,par1        store actual parameter or offset
  2614.         moveq.l    #3,d2        length
  2615.         bra    seek_rdy    d1 contains opcode
  2616.  
  2617. seek_cRMB    cmp.l    #'RMB',d1
  2618.         beq.s    seek_yRMB
  2619.         cmp.l    #'SMB',d1
  2620.         bne.s    seek_PSEUDOS
  2621.         bsr    ck_ibit
  2622.         bcc    seek_op_e3    get bit#
  2623.         move.l    d0,d1
  2624.         asl.b    #4,d1        shift bit#
  2625.         or.b    #%10000111,d1    convert to opcode
  2626.         bra.s    seek_yxMB
  2627. seek_yRMB    bsr    ck_ibit
  2628.         bcc    seek_op_e3    get bit#
  2629.         move.l    d0,d1
  2630.         asl.b    #4,d1        shift bit# into right place
  2631.         or.b    #%00000111,d1    make it an opcode
  2632. seek_yxMB    bsr    calc        get addr for SMB/RMB
  2633.         bcs    seek_op_er
  2634.         tst.b    zpabs        must be on zp
  2635.         bne    seek_op_zp
  2636.         move.l    d0,par1        store it
  2637.         moveq.l    #2,d2        length
  2638.         bra    seek_rdy    d1 = opcode
  2639.  
  2640. seek_PSEUDOS    moveq.l    #0,d2        length: null
  2641.         lea    PSEUDOS(pc),a0    table
  2642. seek_PS_lp    move.l    (a0)+,d0
  2643.         beq.s    seek_PS_err
  2644.         cmp.l    d0,d1
  2645.         beq.s    seek_PS_found
  2646.         addq.l    #4,a0        skip address
  2647.         bra.s    seek_PS_lp
  2648.  
  2649. seek_PS_found    move.l    (a0),a0        get jump address
  2650.         jmp    (a0)
  2651.  
  2652. seek_PS_err    error    #271        unknown mnemonic
  2653.         setc
  2654.         bra    seek_op_er
  2655.  
  2656. PSEUDOS        dc.l    'DB',DB_main_loop
  2657.         dc.l    'DW',DW_loop
  2658.         dc.l    'DL',DL_loop
  2659.         dc.l    'MODE',MODE_loop
  2660.         dc.l    'INCL',pseudo_IBEG
  2661.  
  2662.         dc.b    'I',ID,'ND'
  2663.         dc.l    pseudo_IEND
  2664.  
  2665.         dc.l    'IFEQ',pseudo_IFEQ
  2666.         dc.l    'IFNE',pseudo_IFNE
  2667.         dc.l    'IFGT',pseudo_IFGT
  2668.         dc.l    'IFLT',pseudo_IFLT
  2669.         dc.l    'IFGE',pseudo_IFGE
  2670.         dc.l    'IFLE',pseudo_IFLE
  2671.         dc.l    'IFD',pseudo_IFD
  2672.         dc.l    'IFND',pseudo_IFND
  2673.         dc.l    'IFC',pseudo_IFC
  2674.         dc.l    'IFNC',pseudo_IFNC
  2675.         dc.l    'IFI',pseudo_IFI
  2676.         dc.l    'IFNI',pseudo_IFNI
  2677.         dc.l    'ENDC',pseudo_ENDC
  2678.         dc.l    'FAIL',pseudo_FAIL
  2679.         dc.l    'PAGE',pseudo_PAGE
  2680.  
  2681.         dc.b    'M',ID,'CD'
  2682.         dc.l    pseudo_MACS1
  2683.  
  2684.         dc.b    'M',ID,'CU'
  2685.         dc.l    pseudo_MACS2
  2686.  
  2687.         dc.l    'ENDM',pseudo_ENDM
  2688.         dc.l    0,0
  2689.  
  2690.  
  2691.  
  2692.  
  2693. DB_main_loop    bsr    gce        define 8-bit values
  2694.         bcs    DB_serr
  2695.         cmp.b    #39,d0
  2696.         bne.s    DB_nquo
  2697. DB_quotes    bsr    chr
  2698.         cmp.b    #39,d0
  2699.         beq.s    DB_double
  2700.         bsr    ck_eol
  2701.         bvs.s    DB_qerr        line end before closing '
  2702.         move.b    d0,d7
  2703.         bsr    output
  2704.         addq.l    #1,d2
  2705.         bra    DB_quotes
  2706. DB_double    move.l    txtptr(pc),a0    ''?
  2707.         cmp.b    #39,(a0)
  2708.         bne.s    DB_comma
  2709.         moveq.l    #39,d7
  2710.         bsr    output
  2711.         addq.l    #1,d2
  2712.         bsr    chr
  2713.         bra    DB_quotes
  2714. DB_nquo        bsr    cg        txtptr--
  2715.         bsr    calc
  2716.         bcs.s    DB_err        calc error
  2717.         bsr    ck_lim8
  2718.         bcc.s    DB_ierr        illegal value
  2719.         move.b    d0,d7
  2720.         bsr    output
  2721.         addq.l    #1,d2
  2722. DB_comma    bsr    gce
  2723.         bcs.s    DB_ok
  2724.         cmp.b    #',',d0
  2725.         bne.s    DB_serr        syntax
  2726.         bra    DB_main_loop
  2727. DB_ierr        error    #223
  2728.         bra.s    DB_err
  2729. DB_qerr        error    #151        quotes upset
  2730.         bra.s    DB_err
  2731. DB_serr        error    #209
  2732. DB_err        setc
  2733.         bra    seek_op_er
  2734. DB_ok0        moveq.l    #0,d2        Produce ZERO bytes of code!!!
  2735. DB_ok        bra    seek_done    normally bytecount in d2.
  2736.  
  2737.  
  2738. DW_loop        bsr    gce
  2739.         bcs    DB_serr
  2740.         bsr    cg
  2741.         bsr    calc
  2742.         bcs    DB_err
  2743.         bsr    ck_lim16
  2744.         bcc.s    DW_ierr
  2745.         move.l    d0,d7
  2746.         bsr    output
  2747.         lsr.w    #8,d7
  2748.         bsr    output
  2749.         addq.l    #2,d2
  2750.         bsr    gce
  2751.         bcs    DB_ok
  2752.         cmp.b    #',',d0
  2753.         beq    DW_loop
  2754.         bra    DB_serr
  2755. DW_ierr        error    #128
  2756.         bra    DB_err
  2757.  
  2758.  
  2759. DL_loop        bsr    gce
  2760.         bcs    DB_serr
  2761.         bsr    cg
  2762.         bsr    calc
  2763.         bcs    DB_err
  2764.         move.l    d0,d7
  2765.         bsr    output
  2766.         lsr.l    #8,d7
  2767.         bsr    output
  2768.         lsr.l    #8,d7
  2769.         bsr    output
  2770.         lsr.l    #8,d7
  2771.         bsr    output
  2772.         addq.l    #4,d2
  2773.         bsr    gce
  2774.         bcs    DB_ok
  2775.         cmp.b    #',',d0
  2776.         beq    DL_loop
  2777.         bra    DB_serr
  2778.  
  2779.  
  2780. MODE_loop    bsr    gce
  2781.         bcs    DB_ok0
  2782.         move.l    d0,d1
  2783.         lsr.l    #5,d1
  2784.         eor.b    #1,d1
  2785.         and.b    #1,d1        d1 = flag: 0=off, 1=on
  2786.         bsr    ucase
  2787.         cmp.b    #'C',d0        CMOS
  2788.         bne.s    MODE_1
  2789.         move.w    d1,procmode
  2790.         bra    MODE_loop
  2791. MODE_1        cmp.b    #'L',d0        LIST
  2792.         bne.s    MODE_2
  2793.         move.w    d1,no_list    don't write MODE l/L cmds into listfile
  2794.         beq.s    MODE_1a
  2795.         move.w    userlmode(pc),d1 get cmdline option value
  2796.         move.w    d1,listmode    turn on listing if -l option was used
  2797.         bsr    Open_list    open listfile if necessary
  2798.         bcs    seek_op_er
  2799.         bra    MODE_loop
  2800. MODE_1a        clr.w    listmode    turn off listing in any case
  2801.         bra    MODE_loop
  2802. MODE_2        cmp.b    #'S',d0        SYMBOL TABLE
  2803.         bne.s    MODE_3
  2804.         move.w    d1,symbolmode
  2805.         bra    MODE_loop
  2806. MODE_3        cmp.b    #'H',d0        HEX
  2807.         bne.s    MODE_4
  2808.         move.w    d1,hexmode
  2809.         bra    MODE_loop
  2810. MODE_4        bra    DB_serr
  2811.  
  2812.  
  2813.  
  2814. pseudo_IBEG    bsr    cg
  2815.         bsr    getmn
  2816.         cmp.l    #'LUDE',d0        check the rest of the mnemonic
  2817.         bne    seek_PS_err
  2818.         bsr    gc            skip '
  2819.         move.w    idepth(pc),d0        current nesting level
  2820.         add.w    d0,d0
  2821.         add.w    d0,d0            compute index into nameptr table
  2822.         lea    incnames(pc),a0        nameptr table
  2823.         move.l    nameptr(pc),0(a0,d0.w)    save current name
  2824.         move.l    txtptr(pc),nameptr    ptr to new name
  2825.         move.w    #1,incstrt        flag: include file starts
  2826. IBEG_skip    bsr    gce
  2827.         bcc    IBEG_skip
  2828.         bra    DB_ok0
  2829.  
  2830.  
  2831. pseudo_IEND    bsr    calc
  2832.         bcs.s    IEND_err
  2833.         move.l    d0,linnum    set linenumber for this file
  2834.         move.w    #1,no_list    don't write this line into listfile!
  2835.         move.w    idepth(pc),d0
  2836.         subq.w    #1,d0        stop processing this include file
  2837.         bpl.s    IEND_ok
  2838. IEND_err    error    #461
  2839.         bra    DB_err
  2840. IEND_ok        move.w    d0,idepth    save new depth
  2841.         add.w    d0,d0
  2842.         add.w    d0,d0
  2843.         lea    incnames(pc),a0
  2844.         move.l    0(a0,d0.w),nameptr    restore previous name
  2845.         bra    DB_ok0
  2846.  
  2847.  
  2848. pseudo_MACS1    move.w    #-4,incstrt        flag: macro definition starts
  2849.         move.w    #1,no_list
  2850.         bra    DB_ok0
  2851.  
  2852.  
  2853. pseudo_MACS2    move.w    #-1,incstrt        flag: macro expansion starts
  2854.         move.w    #1,no_list
  2855.         bra    DB_ok0
  2856.  
  2857.  
  2858. pseudo_ENDM    move.w    incstrt(pc),d0        if no macro, error!
  2859.         bpl.s    ENDM_err
  2860.         clr.w    incstrt            reset macro flag
  2861.         move.w    #1,no_list        if macro usage, don't list!
  2862.         bra    DB_ok0
  2863. ENDM_err    error    #601
  2864.         bra    DB_err
  2865.  
  2866.  
  2867. pseudo_PAGE    move.w    #HUGELINE,prtline    forced FF
  2868.         bra    DB_err
  2869.  
  2870.  
  2871. pseudo_IFEQ    move.w    cond_level(pc),d1    depth of conditions (norm. 0)
  2872.         bsr    calc
  2873.         bcs    DB_err
  2874.         tst.l    d0
  2875.         bne.s    COND_n
  2876. COND_y        addq.w    #1,d1            increase depth
  2877.         cmp.w    #CONDNESTING,d1
  2878.         bge.s    IFEQ_err        too deep
  2879.         move.w    #1,condstrt        new cond. part begins: true
  2880.  
  2881.         lea    condflags(pc),a0
  2882.         move.b    #1,0(a0,d1.w)        condition TRUE
  2883.         bra.s    IFEQ_ok
  2884.  
  2885. COND_n        addq.w    #1,d1            increase depth
  2886.         cmp.w    #CONDNESTING,d1
  2887.         bge.s    IFEQ_err        too deep
  2888.         move.w    #-1,condstrt        new cond. part begins: false
  2889.  
  2890.         lea    condflags(pc),a0    stop assembly, because
  2891.         move.b    #-1,0(a0,d1.w)        condition FALSE
  2892.  
  2893. IFEQ_ok        move.w    d1,cond_level        update depth
  2894.         bra    DB_ok0
  2895. IFEQ_err    error    #501
  2896.         bra    DB_err
  2897.  
  2898. pseudo_IFNE    move.w    cond_level(pc),d1
  2899.         bsr    calc
  2900.         bcs    DB_err
  2901.         tst.l    d0
  2902.         bne    COND_y
  2903.         bra    COND_n
  2904.  
  2905. pseudo_IFGT    move.w    cond_level(pc),d1
  2906.         bsr    calc
  2907.         bcs    DB_err
  2908.         cmp.l    #0,d0
  2909.         bgt    COND_y
  2910.         bra    COND_n
  2911.  
  2912. pseudo_IFLT    move.w    cond_level(pc),d1
  2913.         bsr    calc
  2914.         bcs    DB_err
  2915.         cmp.l    #0,d0
  2916.         blt    COND_y
  2917.         bra    COND_n
  2918.  
  2919. pseudo_IFGE    move.w    cond_level(pc),d1
  2920.         bsr    calc
  2921.         bcs    DB_err
  2922.         cmp.l    #0,d0
  2923.         bge    COND_y
  2924.         bra    COND_n
  2925.  
  2926. pseudo_IFLE    move.w    cond_level(pc),d1
  2927.         bsr    calc
  2928.         bcs    DB_err
  2929.         cmp.l    #0,d0
  2930.         ble    COND_y
  2931.         bra    COND_n
  2932.  
  2933. pseudo_IFD    move.w    cond_level(pc),d1
  2934.         clr.w    lnf
  2935.         move.w    #-1,sl_flag        prevents error msg if symbol
  2936.         bsr    glabel            not defined
  2937.         clr.w    sl_flag
  2938.         move.w    lnf(pc),d0        equ: defined
  2939.         beq    COND_y
  2940.         bra    COND_n
  2941.  
  2942. pseudo_IFND    move.w    cond_level(pc),d1
  2943.         clr.w    lnf
  2944.         move.w    #-1,sl_flag        prevents error msg if symbol
  2945.         bsr    glabel              not defined
  2946.         clr.w    sl_flag
  2947.         move.w    lnf(pc),d0        equ: defined
  2948.         bne    COND_y
  2949.         bra    COND_n
  2950.  
  2951.  
  2952. pseudo_IFC    move.w    cond_level(pc),d1
  2953.         bsr    ck_ifc            compare strings
  2954.         bcs    DB_err
  2955.         beq    COND_y
  2956.         bra    COND_n
  2957.  
  2958. pseudo_IFNC    move.w    cond_level(pc),d1
  2959.         bsr    ck_ifc            compare strings
  2960.         bcs    DB_err
  2961.         bne    COND_y
  2962.         bra    COND_n
  2963.  
  2964.  
  2965. pseudo_IFI    move.w    cond_level(pc),d1
  2966.         bsr    ck_ifi            INSTR strings (sub, main)
  2967.         bcs    DB_err
  2968.         beq    COND_y
  2969.         bra    COND_n
  2970.  
  2971. pseudo_IFNI    move.w    cond_level(pc),d1
  2972.         bsr    ck_ifi            INSTR strings
  2973.         bcs    DB_err
  2974.         bne    COND_y
  2975.         bra    COND_n
  2976.  
  2977.  
  2978. pseudo_ENDC    move.w    cond_level(pc),d0    if no cond active, error
  2979.         beq.s    ENDC_err
  2980.         subq.w    #1,d0            just decrement level
  2981.         move.w    d0,cond_level
  2982.         bra    DB_ok0
  2983. ENDC_err    error    #511            no condition
  2984.         bra    DB_err
  2985.  
  2986.  
  2987. pseudo_FAIL    error    #541            fail error
  2988.         bra    DB_err
  2989.  
  2990.  
  2991.  
  2992.  
  2993. getmode        push    d1
  2994.         moveq.l    #0,d0
  2995.         tst.w    idepth        into bit 4
  2996.         sne.b    d1
  2997.         lsr.b    #1,d1
  2998.         roxl.b    #1,d0
  2999.  
  3000.         tst.w    listmode    into bit 3
  3001.         sne.b    d1
  3002.         lsr.b    #1,d1
  3003.         roxl.b    #1,d0
  3004.  
  3005.         tst.w    symbolmode    into bit 2
  3006.         sne.b    d1
  3007.         lsr.b    #1,d1
  3008.         roxl.b    #1,d0
  3009.  
  3010.         tst.w    hexmode        into bit 1
  3011.         sne.b    d1
  3012.         lsr.b    #1,d1
  3013.         roxl.b    #1,d0
  3014.  
  3015.         tst.w    procmode    into bit 0
  3016.         sne.b    d1
  3017.         lsr.b    #1,d1
  3018.         roxl.b    #1,d0
  3019.  
  3020.         pull    d1
  3021.         rts
  3022.  
  3023.  
  3024. amode        push    d1-d4/a5
  3025.         moveq.l    #0,d4
  3026.         roxl.b    #1,d4        x->d4[0] flag: processing jmp
  3027.         move.l    txtptr(pc),a5    save txtptr
  3028.         bsr    gce        if no params, implied
  3029.         bcs    amode_imp    implied
  3030.  
  3031.         bsr    ucase
  3032.         cmp.b    #'A',d0
  3033.         bne.s    amode10
  3034.         bsr    gce        if a plain a, accum
  3035.         bcs    amode_acc    accum
  3036.  
  3037. amode10        move.l    a5,txtptr    back to start
  3038.         bsr    gc
  3039.         cmp.b    #'#',d0
  3040.         bne.s    amode11
  3041.         bsr    calc
  3042.         bcs    amodee
  3043.         move.l    d0,par1
  3044.         bsr    ck_lim8
  3045.         bcc    amodezpe
  3046.         bra    amode_imm    immediate if -129<value<256
  3047. amode11        cmp.b    #'(',d0
  3048.         bne    amode20        not indirect
  3049.         bsr    calc
  3050.         bcs.s    amodee        error?
  3051.         bsr    ck_lim16
  3052.         bcc    amodeabe
  3053.         move.l    d0,par1
  3054.         bsr    gc
  3055.         cmp.b    #')',d0
  3056.         beq.s    amode14        (ind) or (ind),y
  3057.         cmp.b    #',',d0
  3058.         bne.s    amodesye    syntax error
  3059.         bsr    gc
  3060.         bsr    ucase
  3061.         cmp.b    #'X',d0
  3062.         bne.s    amodesye
  3063.         bsr    gc
  3064.         cmp.b    #')',d0
  3065.         bne.s    amodesye
  3066.         tst.b    d4
  3067.         bne    amode_indx    if jmp (ind,x), absolute allowed
  3068.         tst.b    zpabs
  3069.         bne.s    amodezpe
  3070.         bra    amode_indx    (ind,x)
  3071.  
  3072. amode14        bsr    gce
  3073.         bcs.s    amode16        (ind) or (abs ind)
  3074.         cmp.b    #',',d0
  3075.         bne.s    amodesye
  3076.         bsr    gce
  3077.         bsr    ucase
  3078.         cmp.b    #'Y',d0
  3079.         beq.s    amode15
  3080. amodesye    error    #212        syntax terror
  3081. amodee        setc
  3082.         pull    d1-d4/a5
  3083.         rts
  3084. amodezpe    error    #222        zero page expected
  3085.         bra    amodee
  3086. amodeabe    error    #281
  3087.         bra    amodee
  3088.  
  3089. amode15        tst.b    zpabs        zero page?
  3090.         bne    amodezpe    if not, error
  3091.         bra    amode_indy    (ind),y
  3092.  
  3093. amode16        tst.b    zpabs        (ind) and (abs ind) processed here
  3094.         beq.s    amode_ind
  3095.         tst.b    d4
  3096.         bne.s    amode_ind    if jmp (ind), absolute allowed
  3097.         bra    amodezpe    otherwise must be zero page
  3098.  
  3099. amode20        move.l    a5,txtptr    not indirect or immediate, nor implied
  3100.         bsr    calc
  3101.         bcs    amodee        if calc error
  3102.         bsr    ck_lim16
  3103.         bcc    amodeabe
  3104.         move.l    d0,par1
  3105.         bsr    gce
  3106.         bcs.s    amode24        abs or zp
  3107.         cmp.b    #',',d0
  3108.         bne    amodesye
  3109.         bsr    gc
  3110.         bsr    ucase
  3111.         cmp.b    #'X',d0
  3112.         beq.s    amode26        abs,x or zp,x
  3113.  
  3114.         cmp.b    #'Y',d0
  3115.         bne    amodesye
  3116.         tst.b    zpabs
  3117.         beq.s    amode_zpy    zp,y
  3118. amode_absy    moveq.l    #ABSY,d0    abs,y
  3119.         bra.s    amodex
  3120. amode_zpy    moveq.l    #ZPY,d0
  3121.         bra.s    amodex
  3122.  
  3123. amode24        tst.b    zpabs
  3124.         beq.s    amode_zp    zp
  3125. amode_abs    moveq.l    #ABS,d0        abs
  3126.         bra.s    amodex
  3127. amode_zp    moveq.l    #ZP,d0
  3128.         bra.s    amodex
  3129.  
  3130. amode26        tst.b    zpabs
  3131.         beq.s    amode_zpx    zp,x
  3132. amode_absx    moveq.l    #ABSX,d0    abs,x
  3133.         bra.s    amodex
  3134. amode_zpx    moveq.l    #ZPX,d0
  3135.         bra.s    amodex
  3136.  
  3137. amode_ind    moveq.l    #IND,d0
  3138.         bra.s    amodex
  3139. amode_indx    moveq.l    #INDX,d0
  3140.         bra.s    amodex
  3141. amode_indy    moveq.l    #INDY,d0    
  3142.         bra.s    amodex
  3143.  
  3144. amode_imp    moveq.l    #IMP,d0
  3145.         bra.s    amodex
  3146. amode_acc    moveq.l    #ACC,d0
  3147.         bra.s    amodex
  3148. amode_imm    moveq.l    #IMM,d0
  3149.  
  3150. amodex        clrc
  3151.         pull    d1-d4/a5
  3152.         rts
  3153.  
  3154.  
  3155. getmn        push    d1        get mnemonic at (txtptr) into d0
  3156.         moveq.l    #0,d1        temp storage d1
  3157.         bsr    gce        get first char
  3158.         bcs.s    seek_mn_ok    line end causes no error
  3159.         bsr    ucase        convert to upper case
  3160.         bsr    ck_ap
  3161.         bcc.s    seek_mn_e    illegal char .c=0 if not alpha
  3162.         move.b    d0,d1
  3163.         bsr    gec        second char
  3164.         cmp.b    #ID,d0
  3165.         beq.s    getmn_id    identifier for internal reserved mns
  3166.         bsr    ucase
  3167.         bsr    ck_ap
  3168.         bcc.s    seek_mn_e
  3169. getmn_id    asl.l    #8,d1
  3170.         move.b    d0,d1
  3171.         bsr    gec        third char
  3172.         bsr    ucase
  3173.         bsr    ck_ap
  3174.         bcc.s    seek_mn_ok    mnemonic ready
  3175.         asl.l    #8,d1
  3176.         move.b    d0,d1
  3177.         bsr    gec        fourth char
  3178.         bsr    ucase
  3179.         bsr    ck_ap
  3180.         bcc.s    seek_mn_ok    mnemonic ready
  3181.         asl.l    #8,d1
  3182.         move.b    d0,d1
  3183.         bra.s    seek_mn_rdy
  3184. seek_mn_ok    bsr    cg
  3185. seek_mn_rdy    clrc
  3186.         move.l    d1,d0        result into d0
  3187.         pull    d1
  3188.         tst.l    d0
  3189.         rts
  3190. seek_mn_e    bsr    cg
  3191.         pull    d1
  3192.         setc
  3193.         rts
  3194.  
  3195.  
  3196.  
  3197. *************************************************************************
  3198. *                                    *
  3199. * Loads in the files and calculates total length.            *
  3200. *                                    *
  3201. * a0 points to filename                            *
  3202. * a1 points to sourcebuf (file is written there)            *
  3203. *    If a1=0, just checks total length of files.            *
  3204. *    Result in total_len.                        *
  3205. * d7 holds the including depth.                        *
  3206. *                                    *
  3207. *************************************************************************
  3208.  
  3209. MainLoad    push    d0-d7/a2-a6    save regs
  3210.         moveq.l    #0,d5
  3211.         move.l    d5,a5        no mem reserved
  3212.         move.l    d5,d6        no file opened
  3213.         move.l    a1,a4        writeptr
  3214.         move.l    txtptr(pc),a3    save txtptr
  3215.         move.l    a0,d1        nameptr
  3216.         move.l    a0,d3        save nameptr, use still prev. name
  3217.         move.l    #1005,d2    mode_oldfile
  3218.         lib    Dos,Open
  3219.         move.l    d0,d6        fileptr
  3220.         beq    ML_not_found
  3221.  
  3222.         move.l    d3,nameptr    set new nameptr for error()
  3223.  
  3224.         move.l    d6,d1        fileptr
  3225.         moveq.l    #0,d2        pos
  3226.         moveq.l    #1,d3        mode=end
  3227.         lib    Dos,Seek    seek for end of file
  3228.  
  3229.         move.l    d6,d1        file
  3230.         moveq.l    #0,d2        pos
  3231.         moveq.l    #-1,d3        mode=beg
  3232.         lib    Dos,Seek    seek for beginning
  3233.         move.l    d0,d5        bytes needed for buffer
  3234.         bne.s    ML_Fok
  3235.         move.l    d6,d1        if file is empty
  3236.         lib    Dos,Close
  3237.         bra    ML_exit
  3238.  
  3239. ML_Fok        add.l    d5,total_len    add to total source length
  3240.         move.l    d5,d0        allocate buffer
  3241.         addq.l    #4,d0
  3242.         move.l    #MEMF_PUBLIC,d1    no need for MEMF_CLR
  3243.         lib    Exec,AllocMem
  3244.         move.l    d0,a5        buffer addr
  3245.         tst.l    d0
  3246.         beq    ML_oom        out of memory
  3247.  
  3248.         move.l    d6,d1        fileptr
  3249.         move.l    a5,d2        buffer
  3250.         move.l    d5,d3        length
  3251.         lib    Dos,Read
  3252.         cmp.l    d0,d3
  3253.         bne    ML_read_er
  3254.         clr.b    0(a5,d0.l)    add null
  3255.  
  3256.         move.l    d6,d1        close file
  3257.         lib    Dos,Close
  3258.         moveq.l    #0,d6
  3259.  
  3260.         move.l    a5,txtptr    set txtptr to beg of buffer
  3261.         move.l    a5,linstrt
  3262.         clr.l    linnum        reset linenumber
  3263.  
  3264. ML_line        bsr    ck_stop        check if CTRL_C
  3265.         bne    ML_error     yes, exit immediately!
  3266.         move.l    txtptr(pc),a0    start addr of line into a0
  3267.         move.b    (a0),d0
  3268.         beq    ML_exit
  3269.         bsr    ck_blk
  3270.         bcc    ML_copy        if not blank, copy line
  3271.         bsr    getmn
  3272.         bcs    ML_copy        if not a mnemonic, copy line
  3273.         cmp.l    #'INCL',d0
  3274.         bne    ML_copy
  3275.         bsr    cg
  3276.         bsr    getmn
  3277.         cmp.l    #'LUDE',d0
  3278.         bne    ML_copy
  3279. ML_seek_fq    bsr    gce        seek for a '
  3280.         bcs    ML_sye
  3281.         cmp.b    #39,d0
  3282.         bne    ML_sye
  3283.         move.l    txtptr(pc),a2    a2 is a filename ptr
  3284. ML_seek_sq    bsr    gece        seek for another '
  3285.         bcs    ML_sye
  3286.         cmp.b    #39,d0
  3287.         bne    ML_seek_sq
  3288.  
  3289. ML_send        move.l    a4,d1
  3290.         beq.s    ML_no_send    just checking file length
  3291. ML_send_loop    move.b    (a0)+,d0    copy INCLUDE-line
  3292.         bsr    ck_eol
  3293.         bvs.s    ML_send_end
  3294.         move.b    d0,(a4)+
  3295.         bra    ML_send_loop
  3296. ML_send_end    move.b    #LF,(a4)+
  3297.  
  3298. ML_no_send    move.l    txtptr(pc),a0    ptr to end of filename'+1
  3299.         clr.b    -1(a0)        add null to filename in buffer
  3300.         bsr    seek_nexl    find end of line
  3301.  
  3302.         move.l    a2,a0        nameptr
  3303.         addq.l    #1,d7        increment depth
  3304.         cmp.w    #INCNESTING,d7    check depth
  3305.         bhi    ML_neste    too deep
  3306.         move.l    a4,a1        writeptr
  3307.         move.l    linnum(pc),d2    save linnum
  3308.         move.l    a2,linstrt    filename for the case it's not found
  3309.  
  3310.         bsr    MainLoad    gosub next level
  3311.         bcs    ML_error
  3312.  
  3313.         move.l    a1,a4        update writeptr
  3314.         move.l    d2,linnum    restore linenumber
  3315.         move.l    a4,d0
  3316.         beq    ML_line        if writeptr=0, do not send anything
  3317.         move.l    d2,d0
  3318.         clrc
  3319.         bsr    conv_10
  3320.         lea    buf_10+6(pc),a0    write current linenumber
  3321.         lea    ML_LINE(pc),a1
  3322.         bsr    copy_10
  3323.         lea    ML_PRUW(pc),a0
  3324.         bsr.s    ML_write    send 'PRUW linnum' (end of this include)
  3325.         bra    ML_line
  3326.  
  3327. ML_write    move.b    (a0)+,d0
  3328.         beq.s    ML_write_ex
  3329.         move.b    d0,(a4)+
  3330.         bra    ML_write
  3331. ML_write_ex    rts
  3332.  
  3333. ML_PRUW        dc.b    ' I',ID,'ND '
  3334. ML_LINE        dc.b    '      ',LF,0
  3335. ML_MACS1    dc.b    ' M',ID,'CD',LF,0    macro definition
  3336. ML_MACS2    dc.b    ' M',ID,'CU',LF,0    macro usage
  3337. ML_ENDM        dc.b    ' ENDM',LF
  3338. NULLSTR        dc.b    0,0            null string
  3339.         cnop    0,4
  3340.  
  3341. ML_copy        move.l    sourceend(pc),d1
  3342.         addq.l    #1,linnum
  3343.         move.l    a4,d2
  3344.         beq.s    ML_copy_lp
  3345.         bsr    ML_macros
  3346.         move.l    a0,txtptr
  3347.         bra    ML_line
  3348.  
  3349. ML_copy_lp    cmp.l    d1,a4
  3350.         bhs    ML_long        source too long
  3351.         move.b    (a0)+,d0
  3352.         beq    ML_exit
  3353.         bsr    ck_eol
  3354.         bvc    ML_copy_lp
  3355.         move.l    a0,txtptr
  3356.         bra    ML_line
  3357.  
  3358.  
  3359. ML_not_found    tst.l    d7        check if main level (main file)
  3360.         bne.s    ML_not_fnd1    no, include error
  3361.         error    #71        yes, main file not found
  3362.         bra.s    ML_not_f
  3363. ML_not_fnd1    error    #411        file not found
  3364.         bra.s    ML_not_f
  3365.  
  3366. ML_oom        error    #441        out of mem
  3367.         bra.s    ML_err
  3368. ML_read_er    error    #431        read error
  3369. ML_err        move.l    d6,d1        close file, too!
  3370.         lib    Dos,Close
  3371.         bra.s    ML_error
  3372.  
  3373. ML_sye        error    #401        incomplete
  3374.         bra.s    ML_error
  3375.  
  3376. ML_neste    error    #421        nesting error
  3377.         bra.s    ML_error
  3378.  
  3379. ML_long        error    #451        too long source
  3380.  
  3381. ML_error    bsr.s    ML_free
  3382. ML_not_f    move.l    a3,txtptr
  3383.         move.l    a4,a1
  3384.         pull    d0-d7/a2-a6
  3385.         subq.l    #1,d7        dec depth
  3386.         setc
  3387.         rts
  3388.  
  3389. ML_exit        bsr.s    ML_free
  3390.         move.l    a3,txtptr
  3391.         move.l    a4,a1
  3392.         pull    d0-d7/a2-a6
  3393.         subq.l    #1,d7        dec depth
  3394.         clrc
  3395.         rts
  3396.  
  3397. ML_free        move.l    a5,d0
  3398.         beq.s    ML_free_ex
  3399.         move.l    a5,a1
  3400.         move.l    d5,d0
  3401.         addq.l    #4,d0
  3402.         lib    Exec,FreeMem
  3403.         move.l    #0,a5
  3404. ML_free_ex    rts
  3405.  
  3406.  
  3407. ML_macros    push    d0-d7/a1-a3
  3408.         move.l    a0,a3        ptr to the start of line
  3409.         move.l    a0,txtptr
  3410.         move.l    a0,linstrt    line start for ermsgs
  3411.  
  3412.         bsr    getlb
  3413.         bvs    ML_nothing    too long symbol ***** - what to do?
  3414.         bcs    ML_no_lab    no label = no macro definition
  3415.         move.l    a0,txtptr
  3416.         bsr    ck_MACRO    mnemonic=MACRO?
  3417.         bcc    ML_no_def    not a macro definition
  3418.  
  3419.         bsr    ML_Redef    check if already defined
  3420.         bcs    ML_re_err
  3421.  
  3422. ML_save_macro    move.l    a0,a1        ptr to free storage
  3423.         lea    tbuffer(pc),a0    name
  3424.         bsr    strcpy        save name
  3425.         bsr    seek_nexl    get next line
  3426.  
  3427. ML_save_body    move.l    txtptr(pc),a0
  3428.         bsr    getlb        skip possible label
  3429.         move.l    a0,txtptr
  3430.         bsr    ck_MACRO
  3431.         bcs    ML_within    definition within definition
  3432.         bsr    getmn
  3433.         cmp.l    #'ENDM',d0
  3434.         beq.s    ML_body_saved
  3435.         move.l    linstrt(pc),a0
  3436. ML_copy_body    move.b    (a0)+,d0
  3437.         beq    ML_no_ENDM    ENDM missing
  3438.         move.b    d0,(a1)+
  3439.         bsr    ck_eol        copy until eol
  3440.         bvc    ML_copy_body
  3441.         addq.l    #1,linnum
  3442.         bsr    seek_nexl
  3443.         bra    ML_save_body
  3444.  
  3445. ML_body_saved    clr.b    (a1)+        add null = end of macro
  3446.         bsr    seek_nexl
  3447.         lea    ML_MACS1(pc),a0    mnem: macro definition
  3448.         bsr    ML_write
  3449.         move.l    txtptr(pc),a2
  3450.         move.l    a3,a1        start of a macro
  3451. ML_write_mac    move.b    (a1)+,(a4)+    copy into source buffer
  3452.         cmpa.l    a2,a1        all done?
  3453.         blo    ML_write_mac
  3454.         move.l    a2,a0
  3455.         pull    d0-d7/a1-a3
  3456.         clrc
  3457.         rts
  3458.  
  3459. ML_no_lab    bsr    ck_MACRO    if MACRO without name, error
  3460.         bcs    ML_no_name
  3461. ML_no_def    move.l    txtptr(pc),a0    get addr of mnemonic
  3462. ML_get_mnem    move.b    (a0)+,d0    skip until mnemonic starts
  3463.         bsr    ck_blk
  3464.         bcs    ML_get_mnem
  3465.  
  3466.         subq.l    #1,a0        starting position
  3467.         bsr    getlb        copies macro/mnem into tbuffer
  3468.         movea.l    a0,a2        start of parameters
  3469.         bcs.s    ML_nothing    ******* what to do?
  3470.         bsr    ML_Redef    check if macro defined
  3471.         bcc.s    ML_nothing    if not defined, it may be normal opcode
  3472.  
  3473.         move.l    a0,a1
  3474.         lea    ML_MACS2(pc),a0    mnem: macro usage
  3475.         bsr    ML_write
  3476.  
  3477.         move.l    a3,a0        start of macro usage line
  3478. ML_usage_cpy    move.b    (a0)+,d0
  3479.         move.b    d0,(a4)+
  3480.         bsr    ck_eol
  3481.         bvc    ML_usage_cpy
  3482.  
  3483. ML_us_copied    lea    NULLSTR(pc),a0
  3484.         move.l    a0,d0        reset parameter ptrs
  3485.         move.l    a0,d1
  3486.         move.l    a0,d2
  3487.         move.l    a0,d3
  3488.         move.l    a2,a0
  3489.         bsr    ML_blk
  3490.         move.l    a0,d0
  3491.         bsr    ML_nx_pr    search for next parameter
  3492.         bcs.s    ML_us_pok
  3493.         move.l    a0,d1
  3494.         bsr    ML_nx_pr    search for next parameter
  3495.         bcs.s    ML_us_pok
  3496.         move.l    a0,d2
  3497.         bsr    ML_nx_pr    search for next parameter
  3498.         bcs.s    ML_us_pok
  3499.         move.l    a0,d3
  3500.  
  3501. ML_us_pok    move.l    a1,a0
  3502.  
  3503. ML_expand    bsr    McExpand    expand!
  3504.  
  3505.         lea    ML_ENDM(pc),a0
  3506.         bsr    ML_write
  3507.  
  3508.         bsr    seek_nexl
  3509.         move.l    txtptr(pc),a0
  3510.         pull    d0-d7/a1-a3
  3511.         clrc
  3512.         rts
  3513.  
  3514. ML_nothing    move.b    (a3)+,d0    copy normal lines normally
  3515.         beq.s    ML_nothnull
  3516.         move.b    d0,(a4)+
  3517.         bsr    ck_eol
  3518.         bvc    ML_nothing
  3519.         bra.s    ML_noth_done
  3520. ML_nothnull    subq.l    #1,a3        don't eat nulls!
  3521. ML_noth_done    move.l    a3,a0
  3522.         pull    d0-d7/a1-a3
  3523.         clrc
  3524.         rts
  3525.  
  3526.  
  3527. ML_within    error    #621
  3528.         bra.s    ML_mac_err
  3529. ML_no_name    error    #631
  3530.         bra.s    ML_mac_err
  3531. ML_no_ENDM    error    #641
  3532.         bra.s    ML_mac_err
  3533. ML_re_err    error    #611        redefined
  3534. ML_mac_err    bsr    seek_nexl
  3535.         move.l    txtptr(pc),a0
  3536.         pull    d0-d7/a1-a3
  3537.         setc
  3538.         rts
  3539.  
  3540.  
  3541. ML_nx_pr    push    d0-d3
  3542. ML_nx_lp1    move.b    (a0)+,d0    skip current parameter
  3543.         beq.s    ML_nx_eol
  3544.         bsr    ck_eol
  3545.         bcs.s    ML_nx_eol
  3546.         cmp.b    #'<',d0
  3547.         beq.s    ML_nx_enc    many values as a single parameter
  3548.         cmp.b    #39,d0
  3549.         beq.s    ML_nx_enc
  3550.         cmp.b    #',',d0        comma as a separator
  3551.         bne    ML_nx_lp1
  3552. ML_nx_blk    move.b    (a0)+,d0
  3553.         beq.s    ML_nx_sye
  3554.         bsr    ck_eol
  3555.         bcs.s    ML_nx_sye
  3556.         bsr    ck_blk
  3557.         bcs    ML_nx_blk
  3558.         subq.l    #1,a0
  3559.         pull    d0-d3
  3560.         clrv
  3561.         rts
  3562.  
  3563. ML_nx_enc    move.b    d0,d1
  3564.         cmp.b    #'<',d0
  3565.         bne.s    ML_nx_lp2
  3566.         moveq.l    #'>',d1
  3567. ML_nx_lp2    move.b    (a0)+,d0
  3568.         beq.s    ML_nx_sye_a
  3569.         bsr    ck_eol
  3570.         bcs.s    ML_nx_sye_a
  3571.         cmp.b    d1,d0
  3572.         bne    ML_nx_lp2
  3573.         bra    ML_nx_lp1
  3574.  
  3575. ML_nx_sye    error    #651        param error
  3576. ML_nx_sye_a    subq.l    #1,a0
  3577.         pull    d0-d3
  3578.         setc
  3579.         setv            V=1: error
  3580.         rts
  3581.  
  3582. ML_nx_eol    subq.l    #1,a0
  3583.         pull    d0-d3
  3584.         setc
  3585.         clrv
  3586.         rts
  3587.  
  3588. ML_blk        push    d0
  3589. ML_blk_lp    move.b    (a0)+,d0
  3590.         bsr    ck_blk
  3591.         bcs    ML_blk_lp
  3592.         subq.l    #1,a0
  3593.         pull    d0
  3594.         rts
  3595.  
  3596.  
  3597. McExpand    push    d4-d7/a1-a3
  3598.         link    a5,#-16
  3599.         move.l    d3,-4(a5)
  3600.         move.l    d2,-8(a5)
  3601.         move.l    d1,-12(a5)
  3602.         move.l    d0,-16(a5)
  3603.         addq.l    #1,McExpCnt    add 1 to \@nnn cntr
  3604. McExMLp        move.l    a0,a3        startptr
  3605.         move.b    (a0),d0
  3606.         beq    McExEop
  3607.         bsr    ck_blk
  3608.         bcs.s    McEx_nolb
  3609.         bsr    McExpLab    expand a label
  3610.  
  3611. McEx_nolb    move.l    a4,a2        save write ptr
  3612. McEx_sk1    move.b    (a0)+,d0    copy blanks after label
  3613.         move.b    d0,(a4)+
  3614.         bsr    ck_blk
  3615.         bcs    McEx_sk1
  3616.         subq.l    #1,a0
  3617.         subq.l    #1,a4
  3618.         move.l    a0,a3        processed this far
  3619.         bsr    getlb        get mnemonic/macro name
  3620.         movea.l    a0,a1        save start of parameters
  3621.         bcs    McExNoMac    no mnemonic/macro
  3622.  
  3623.         bsr    ML_Redef    is it a macro?
  3624.         bcc    McExNoMac    no, branch.
  3625.  
  3626.         move.l    a2,a4        remove blanks if mac(mac)
  3627.         clr.b    (a4)        null for safety
  3628.  
  3629.         push    a0        save macro start addr in buffer
  3630.  
  3631.         push    a4        save output pointer
  3632.         move.l    obuf(pc),a4    buffer for parameters
  3633.         moveq.l    #0,d0
  3634.         move.w    McNesting(pc),d0
  3635.         asl.l    #8,d0
  3636.         add.l    d0,a4
  3637.         move.l    a4,a2        start of string in obuf
  3638.         move.l    a1,a0        start of parameters
  3639.         bsr    McCopy        expand parameters into obuf!
  3640.  
  3641.         pull    a4        restore output pointer
  3642.  
  3643.         lea    NULLSTR(pc),a0
  3644.         move.l    a0,d0        reset parameter ptrs
  3645.         move.l    a0,d1
  3646.         move.l    a0,d2
  3647.         move.l    a0,d3
  3648.         move.l    a2,a0        get param string address
  3649.         bsr    ML_blk
  3650.         move.l    a0,d0
  3651.         bsr    ML_nx_pr    search for next parameter
  3652.         bcs.s    ML_mac_pok
  3653.         move.l    a0,d1
  3654.         bsr    ML_nx_pr    search for next parameter
  3655.         bcs.s    ML_mac_pok
  3656.         move.l    a0,d2
  3657.         bsr    ML_nx_pr    search for next parameter
  3658.         bcs.s    ML_mac_pok
  3659.         move.l    a0,d3
  3660.  
  3661. ML_mac_pok    pull    a0        a0 points to a new macro in buffer
  3662.  
  3663.         addq.w    #1,McNesting
  3664.         cmp.w    #MCNESTING,McNesting
  3665.         bls.s    McExNestOk
  3666.         error    #661        macro nesting too deep
  3667.         bra.s    McEx_Xpanded
  3668. McExNestOk    bsr    McExpand
  3669. McEx_Xpanded    subq.w    #1,McNesting
  3670. McEx_sk2    move.b    (a3)+,d0    skip until end of line
  3671.         bsr    ck_eol
  3672.         bvc    McEx_sk2
  3673.         move.l    a3,a0
  3674.         tst.b    d0
  3675.         bne    McExMLp
  3676.         bra.s    McExEop
  3677.  
  3678. *
  3679. * handles a macro in macro -situation
  3680. *
  3681.  
  3682. McExNoMac    move.l    a3,a0
  3683.         bsr.s    McCopy
  3684.         tst.b    (a0)
  3685.         bne    McExMLp
  3686. McExEop        unlk    a5
  3687.         pull    d4-d7/a1-a3
  3688.         rts
  3689.  
  3690.  
  3691. McCopy        push    a1
  3692. McCopylp    move.b    (a0)+,d0
  3693.         beq.s    McCopy_eop
  3694.         cmp.b    #'\',d0
  3695.         beq.s    McCopy_par
  3696. McCopyw        move.b    d0,(a4)+
  3697.         bsr    ck_eol
  3698.         bcc    McCopylp
  3699.         bra.s    McCopy_e
  3700. McCopy_par    move.b    (a0),d0
  3701.  
  3702.         bsr.s    McExpander
  3703.         bra    McCopylp
  3704.  
  3705. McCopy_np    moveq.l    #'\',d0        write as it is
  3706.         bra    McCopyw
  3707.  
  3708. McCopy_eop    subq.l    #1,a0        don't eat nulls!
  3709. McCopy_e    pull    a1/a1
  3710.         rts
  3711.  
  3712.  
  3713. McExpander    cmp.b    #'@',d0
  3714.         beq    McExTail
  3715.         bsr    ck_dig
  3716.         bcc    McExp_np
  3717.         cmp.b    #'4',d0
  3718.         bhi    McExp_np
  3719.         addq.l    #1,a0        skip param number
  3720.         and.w    #15,d0
  3721.         add.w    d0,d0
  3722.         add.w    d0,d0
  3723.         move.l    -20(a5,d0.w),a1    get right param ptr here!!!!!
  3724.  
  3725. McExp_par_cpy    move.b    (a1)+,d0
  3726.         bsr    ck_eol
  3727.         bcs    McExpOk        end of param
  3728.         bsr    ck_blk
  3729.         bcs    McExpOk        end of param
  3730.         cmp.b    #',',d0
  3731.         beq    McExpOk        end of param
  3732.         cmp.b    #'<',d0
  3733.         beq.s    McExpBigPar    parameter enclosed in <>
  3734.         cmp.b    #39,d0
  3735.         beq.s    McExpQuote    string parameter within quotes
  3736.         move.b    d0,(a4)+    copy a char
  3737.         bra    McExp_par_cpy
  3738.  
  3739. McExpBigPar    move.b    (a1)+,d0
  3740.         bsr    ck_eol
  3741.         bvs.s    McExpBigEr    no line end allowed within <>
  3742.         cmp.b    #'>',d0
  3743.         beq.s    McExpOk        > ends this parameter
  3744.         cmp.b    #'<',d0
  3745.         beq.s    McExpBigNes    no <> nesting allowed!
  3746.         move.b    d0,(a4)+
  3747.         bra    McExpBigPar
  3748. McExpBigEr    error    #652
  3749.         bra.s    McExpOk
  3750. McExpBigNes    error    #671
  3751.         bra.s    McExpOk
  3752. McExpQuoterr    error    #681        missing quote
  3753.         bra.s    McExpOk
  3754.  
  3755.  
  3756. McExpQuote    move.b    d0,(a4)+    write opening quote
  3757. McExpQuotel    move.b    (a1)+,d0    blanks also allowed within ''
  3758.         bsr    ck_eol
  3759.         bvs    McExpQuoterr    no line end allowed within ''
  3760.         move.b    d0,(a4)+
  3761.         cmp.b    #39,d0        ' ends this parameter
  3762.         bne    McExpQuotel
  3763.         bra.s    McExpOk
  3764.  
  3765. McExTail    addq.l    #1,a0        skip @
  3766.         move.l    McExpCnt(pc),d0
  3767.         setc            zeroes needed, too!
  3768.         bsr    conv_10
  3769.         move.b    buf_10+8(pc),(a4)+
  3770.         move.b    buf_10+9(pc),(a4)+
  3771.         move.b    buf_10+10(pc),(a4)+
  3772.         move.b    buf_10+11(pc),(a4)+
  3773.         bra.s    McExpOk
  3774.  
  3775. McExp_np    move.b    #'\',(a4)+
  3776.         move.b    d0,(a4)+
  3777.         addq.l    #1,a0
  3778. McExpOk        rts
  3779.  
  3780.  
  3781.  
  3782. McExpLab    push    d0        expand a label with possible \@
  3783. McExpLabLp    move.b    (a0)+,d0
  3784.         cmp.b    #'\',d0
  3785.         beq.s    McExpLab_cka    test for @
  3786.         bsr    ck_lc
  3787.         bcc.s    McExpLab_e    end
  3788. McExpLab_cont    move.b    d0,(a4)+    copy a char
  3789.         bra    McExpLabLp
  3790. McExpLab_cka    move.b    (a0),d0
  3791.         bsr    McExpander
  3792.         bra    McExpLabLp
  3793.  
  3794. McExpLab_e    move.b    d0,(a4)+    don't eat this!
  3795.         pull    d0
  3796.         rts
  3797.  
  3798.  
  3799. ML_Redef    push    a1-a2        check if macro defined
  3800.         move.l    labelbuf(pc),a2
  3801. ML_R_search    lea    tbuffer(pc),a0    current name
  3802.         move.l    a2,a1        ptr into macrobuffer
  3803.         tst.b    (a1)
  3804.         beq.s    ML_R_notfound    name not found
  3805.         bsr    strcmp
  3806.         beq.s    ML_R_found
  3807.         moveq.l    #1,d0
  3808. ML_R_skip    tst.b    (a2)+        skip current name+macro in buffer
  3809.         bne    ML_R_skip
  3810.         dbf    d0,ML_R_skip
  3811.         bra    ML_R_search
  3812. ML_R_found    move.l    a1,a0        ptr to macro
  3813.         pull    a1-a2
  3814.         setc
  3815.         rts
  3816. ML_R_notfound    move.l    a1,a0        ptr to free macro space
  3817.         pull    a1-a2
  3818.         clrc
  3819.         rts
  3820.  
  3821.  
  3822. ck_MACRO    push    a5
  3823.         move.l    txtptr(pc),a5
  3824.         bsr    getmn        get mnemonic
  3825.         bcs.s    ck_MAC_n
  3826.         cmp.l    #'MACR',d0
  3827.         bne.s    ck_MAC_n    not 'MACRO'
  3828.         bsr    cg
  3829.         bsr    getmn
  3830.         cmp.l    #'RO',d0
  3831.         beq.s    ck_MAC_y    it is 'MACRO'
  3832.  
  3833. ck_MAC_n    move.l    a5,txtptr
  3834.         pull    a5
  3835.         clrc
  3836.         rts
  3837. ck_MAC_y    pull    a5
  3838.         setc
  3839.         rts
  3840.  
  3841.  
  3842. Clr_LBuf    move.l    labelbuf(pc),a0        fill labelbuf with nulls
  3843.         move.l    #LABELBUF,d0
  3844.         moveq.l    #0,d1
  3845. Clr_LBufLoop    move.b    d1,(a0)+
  3846.         subq.l    #1,d0
  3847.         bne    Clr_LBufLoop
  3848.         rts
  3849.  
  3850.  
  3851. getlb        push    d0-d1/a1    get label at a0
  3852.         move.b    (a0)+,d0    get a symbol name into tbuffer
  3853.         bsr    ck_lc        legal char for a label?
  3854.         bcc.s    getlb_ill    if not alphanumeric
  3855.         bvs.s    getlb_ill    if first char is numeric
  3856.         lea    tbuffer(pc),a1
  3857.         move.b    d0,(a1)+    save first char
  3858.         moveq.l    #LABELLEN-1,d1
  3859. getlb_cpy    move.b    (a0)+,d0    one char
  3860.         bsr    ck_lc        suitable for labels?
  3861.         bcc.s    getlb_copied
  3862.         move.b    d0,(a1)+
  3863.         dbf    d1,getlb_cpy
  3864.         error    #331        name too long
  3865.         bra.s    getlb_err
  3866. getlb_copied    clr.b    (a1)        add null
  3867.         subq.l    #1,a0        restore pointer at first char after label
  3868.         pull    d0-d1/a1
  3869.         clrc
  3870.         clrv
  3871.         rts
  3872.  
  3873. getlb_ill    subq.l    #1,a0        restore pointer at beginning
  3874.         pull    d0-d1/a1
  3875.         setc
  3876.         rts
  3877. getlb_err    pull    d0-d1/a1
  3878.         setv
  3879.         clrc
  3880.         rts
  3881.  
  3882.  
  3883.  
  3884.  
  3885.  
  3886.  
  3887.  
  3888.  
  3889.  
  3890. *****************************************************************
  3891. *                                *
  3892. *             MNEMONICS AND OPCODES            *
  3893. *             =====================            *
  3894. *                                *
  3895. * OpLen - Contains byte# for each addressing mode        *
  3896. *                                *
  3897. *                                *
  3898. * OpCodes - Table format:                    *
  3899. * mnemonic                            *
  3900. * imm; abs; zp; accum; implied; (ind,x); (ind),y; zpx        *
  3901. * absx; absy; rel; (ind); zp,y; (aind);                *
  3902. *                                *
  3903. *****************************************************************
  3904.  
  3905. OpLen        dc.b    2,3,2,1,1,2,2,2,3,3,2,2,2,0,0,0
  3906. OpJMP        dc.b    $00,$4c,$4c,$00,$00,$7c,$00,$00
  3907.         dc.b    $00,$00,$00,$6c,$00,$00
  3908.  
  3909. OpCodes        dc.l    'LDA'
  3910.         dc.b    $a9,$ad,$a5,$00,$00,$a1,$b1,$b5
  3911.         dc.b    $bd,$b9,$00,$b2,$00,$00
  3912.  
  3913. Op_Codes    dc.l    'STA'
  3914.         dc.b    $00,$8d,$85,$00,$00,$81,$91,$95
  3915.         dc.b    $9d,$99,$00,$92,$00,$00
  3916.  
  3917.         dc.l    'JSR'
  3918.         dc.b    $00,$20,$00,$00,$00,$00,$00,$00
  3919.         dc.b    $00,$00,$00,$00,$00,$00
  3920.  
  3921.         dc.l    'BRA'
  3922.         dc.b    $00,$00,$00,$00,$00,$00,$00,$00
  3923.         dc.b    $00,$00,$80,$00,$00,$00
  3924.  
  3925.         dc.l    'CMP'
  3926.         dc.b    $c9,$cd,$c5,$00,$00,$c1,$d1,$d5
  3927.         dc.b    $dd,$d9,$00,$d2,$00,$00
  3928.  
  3929.         dc.l    'BNE'
  3930.         dc.b    $00,$00,$00,$00,$00,$00,$00,$00
  3931.         dc.b    $00,$00,$d0,$00,$00,$00
  3932.  
  3933.         dc.l    'BEQ'
  3934.         dc.b    $00,$00,$00,$00,$00,$00,$00,$00
  3935.         dc.b    $00,$00,$f0,$00,$00,$00
  3936.  
  3937.         dc.l    'LDX'
  3938.         dc.b    $a2,$ae,$a6,$00,$00,$00,$00,$00
  3939.         dc.b    $00,$be,$00,$00,$b6,$00
  3940.  
  3941.         dc.l    'RTS'
  3942.         dc.b    $00,$00,$00,$00,$60,$00,$00,$00
  3943.         dc.b    $00,$00,$00,$00,$00,$00
  3944.  
  3945.         dc.l    'LDY'
  3946.         dc.b    $a0,$ac,$a4,$00,$00,$00,$00,$b4
  3947.         dc.b    $bc,$00,$00,$00,$00,$00
  3948.  
  3949.         dc.l    'INY'
  3950.         dc.b    $00,$00,$00,$00,$c8,$00,$00,$00
  3951.         dc.b    $00,$00,$00,$00,$00,$00
  3952.  
  3953.         dc.l    'STX'
  3954.         dc.b    $00,$8e,$86,$00,$00,$00,$00,$00
  3955.         dc.b    $00,$00,$00,$00,$96,$00
  3956.  
  3957.         dc.l    'BCC'
  3958.         dc.b    $00,$00,$00,$00,$00,$00,$00,$00
  3959.         dc.b    $00,$00,$90,$00,$00,$00
  3960.  
  3961.         dc.l    'BCS'
  3962.         dc.b    $00,$00,$00,$00,$00,$00,$00,$00
  3963.         dc.b    $00,$00,$b0,$00,$00,$00
  3964.  
  3965.         dc.l    'STY'
  3966.         dc.b    $00,$8c,$84,$00,$00,$00,$00,$94
  3967.         dc.b    $00,$00,$00,$00,$00,$00
  3968.  
  3969.         dc.l    'STZ'
  3970.         dc.b    $00,$9c,$64,$00,$00,$00,$00,$74
  3971.         dc.b    $9e,$00,$00,$00,$00,$00
  3972.  
  3973.         dc.l    'INX'
  3974.         dc.b    $00,$00,$00,$00,$e8,$00,$00,$00
  3975.         dc.b    $00,$00,$00,$00,$00,$00
  3976.  
  3977.         dc.l    'PHA'
  3978.         dc.b    $00,$00,$00,$00,$48,$00,$00,$00
  3979.         dc.b    $00,$00,$00,$00,$00,$00
  3980.  
  3981.         dc.l    'PHX'
  3982.         dc.b    $00,$00,$00,$00,$da,$00,$00,$00
  3983.         dc.b    $00,$00,$00,$00,$00,$00
  3984.  
  3985.         dc.l    'PHY'
  3986.         dc.b    $00,$00,$00,$00,$5a,$00,$00,$00
  3987.         dc.b    $00,$00,$00,$00,$00,$00
  3988.  
  3989.         dc.l    'ADC'
  3990.         dc.b    $69,$6d,$65,$00,$00,$61,$71,$75
  3991.         dc.b    $7d,$79,$00,$72,$00,$00
  3992.  
  3993.         dc.l    'PLA'
  3994.         dc.b    $00,$00,$00,$00,$68,$00,$00,$00
  3995.         dc.b    $00,$00,$00,$00,$00,$00
  3996.  
  3997.         dc.l    'PLX'
  3998.         dc.b    $00,$00,$00,$00,$fa,$00,$00,$00
  3999.         dc.b    $00,$00,$00,$00,$00,$00
  4000.  
  4001.         dc.l    'PLY'
  4002.         dc.b    $00,$00,$00,$00,$7a,$00,$00,$00
  4003.         dc.b    $00,$00,$00,$00,$00,$00
  4004.  
  4005.         dc.l    'INC'
  4006.         dc.b    $00,$ee,$e6,$1a,$1a,$00,$00,$f6
  4007.         dc.b    $fe,$00,$00,$00,$00,$00
  4008.  
  4009.         dc.l    'SEC'
  4010.         dc.b    $00,$00,$00,$00,$38,$00,$00,$00
  4011.         dc.b    $00,$00,$00,$00,$00,$00
  4012.  
  4013.         dc.l    'CLC'
  4014.         dc.b    $00,$00,$00,$00,$18,$00,$00,$00
  4015.         dc.b    $00,$00,$00,$00,$00,$00
  4016.  
  4017.         dc.l    'SBC'
  4018.         dc.b    $e9,$ed,$e5,$00,$00,$e1,$f1,$f5
  4019.         dc.b    $fd,$f9,$00,$f2,$00,$00
  4020.  
  4021.         dc.l    'ORA'
  4022.         dc.b    $09,$0d,$05,$00,$00,$01,$11,$15
  4023.         dc.b    $1d,$19,$00,$12,$00,$00
  4024.  
  4025.         dc.l    'AND'
  4026.         dc.b    $29,$2d,$25,$00,$00,$21,$31,$35
  4027.         dc.b    $3d,$39,$00,$32,$00,$00
  4028.  
  4029.         dc.l    'BMI'
  4030.         dc.b    $00,$00,$00,$00,$00,$00,$00,$00
  4031.         dc.b    $00,$00,$30,$00,$00,$00
  4032.  
  4033.         dc.l    'TAX'
  4034.         dc.b    $00,$00,$00,$00,$aa,$00,$00,$00
  4035.         dc.b    $00,$00,$00,$00,$00,$00
  4036.  
  4037.         dc.l    'CPX'
  4038.         dc.b    $e0,$ec,$e4,$00,$00,$00,$00,$00
  4039.         dc.b    $00,$00,$00,$00,$00,$00
  4040.  
  4041.         dc.l    'DEX'
  4042.         dc.b    $00,$00,$00,$00,$ca,$00,$00,$00
  4043.         dc.b    $00,$00,$00,$00,$00,$00
  4044.  
  4045.         dc.l    'ASL'
  4046.         dc.b    $00,$0e,$06,$0a,$0a,$00,$00,$16
  4047.         dc.b    $1e,$00,$00,$00,$00,$00
  4048.  
  4049.         dc.l    'LSR'
  4050.         dc.b    $00,$4e,$46,$4a,$4a,$00,$00,$46
  4051.         dc.b    $4e,$00,$00,$00,$00,$00
  4052.  
  4053.         dc.l    'TXA'
  4054.         dc.b    $00,$00,$00,$00,$8a,$00,$00,$00
  4055.         dc.b    $00,$00,$00,$00,$00,$00
  4056.  
  4057.         dc.l    'CPY'
  4058.         dc.b    $c0,$cc,$c4,$00,$00,$00,$00,$00
  4059.         dc.b    $00,$00,$00,$00,$00,$00
  4060.  
  4061.         dc.l    'BPL'
  4062.         dc.b    $00,$00,$00,$00,$00,$00,$00,$00
  4063.         dc.b    $00,$00,$10,$00,$00,$00
  4064.  
  4065.         dc.l    'TAY'
  4066.         dc.b    $00,$00,$00,$00,$a8,$00,$00,$00
  4067.         dc.b    $00,$00,$00,$00,$00,$00
  4068.  
  4069.         dc.l    'BIT'
  4070.         dc.b    $89,$2c,$24,$00,$00,$00,$00,$34
  4071.         dc.b    $3c,$00,$00,$00,$00,$00
  4072.  
  4073.         dc.l    'ROL'
  4074.         dc.b    $00,$2e,$26,$2a,$2a,$00,$00,$36
  4075.         dc.b    $3e,$00,$00,$00,$00,$00
  4076.  
  4077.         dc.l    'DEY'
  4078.         dc.b    $00,$00,$00,$00,$88,$00,$00,$00
  4079.         dc.b    $00,$00,$00,$00,$00,$00
  4080.  
  4081.         dc.l    'PHP'
  4082.         dc.b    $00,$00,$00,$00,$08,$00,$00,$00
  4083.         dc.b    $00,$00,$00,$00,$00,$00
  4084.  
  4085.         dc.l    'TRB'
  4086.         dc.b    $00,$1c,$14,$00,$00,$00,$00,$00
  4087.         dc.b    $00,$00,$00,$00,$00,$00
  4088.  
  4089.         dc.l    'TSB'
  4090.         dc.b    $00,$0c,$04,$00,$00,$00,$00,$00
  4091.         dc.b    $00,$00,$00,$00,$00,$00
  4092.  
  4093.         dc.l    'DEC'
  4094.         dc.b    $00,$ce,$c6,$3a,$3a,$00,$00,$d6
  4095.         dc.b    $de,$00,$00,$00,$00,$00
  4096.  
  4097.         dc.l    'TYA'
  4098.         dc.b    $00,$00,$00,$00,$98,$00,$00,$00
  4099.         dc.b    $00,$00,$00,$00,$00,$00
  4100.  
  4101.         dc.l    'PLP'
  4102.         dc.b    $00,$00,$00,$00,$28,$00,$00,$00
  4103.         dc.b    $00,$00,$00,$00,$00,$00
  4104.  
  4105.         dc.l    'EOR'
  4106.         dc.b    $49,$4d,$45,$00,$00,$41,$51,$55
  4107.         dc.b    $5d,$59,$00,$52,$00,$00
  4108.  
  4109.         dc.l    'NOP'
  4110.         dc.b    $00,$00,$00,$00,$ea,$00,$00,$00
  4111.         dc.b    $00,$00,$00,$00,$00,$00
  4112.  
  4113.         dc.l    'TXS'
  4114.         dc.b    $00,$00,$00,$00,$9a,$00,$00,$00
  4115.         dc.b    $00,$00,$00,$00,$00,$00
  4116.  
  4117.         dc.l    'SEI'
  4118.         dc.b    $00,$00,$00,$00,$78,$00,$00,$00
  4119.         dc.b    $00,$00,$00,$00,$00,$00
  4120.  
  4121.         dc.l    'CLI'
  4122.         dc.b    $00,$00,$00,$00,$58,$00,$00,$00
  4123.         dc.b    $00,$00,$00,$00,$00,$00
  4124.  
  4125.         dc.l    'ROR'
  4126.         dc.b    $00,$6e,$66,$6a,$6a,$00,$00,$76
  4127.         dc.b    $7e,$00,$00,$00,$00,$00
  4128.  
  4129.         dc.l    'BVS'
  4130.         dc.b    $00,$00,$00,$00,$00,$00,$00,$00
  4131.         dc.b    $00,$00,$70,$00,$00,$00
  4132.  
  4133.         dc.l    'BVC'
  4134.         dc.b    $00,$00,$00,$00,$00,$00,$00,$00
  4135.         dc.b    $00,$00,$50,$00,$00,$00
  4136.  
  4137.         dc.l    'SED'
  4138.         dc.b    $00,$00,$00,$00,$f8,$00,$00,$00
  4139.         dc.b    $00,$00,$00,$00,$00,$00
  4140.  
  4141.         dc.l    'CLD'
  4142.         dc.b    $00,$00,$00,$00,$d8,$00,$00,$00
  4143.         dc.b    $00,$00,$00,$00,$00,$00
  4144.  
  4145.         dc.l    'RTI'
  4146.         dc.b    $00,$00,$00,$00,$40,$00,$00,$00
  4147.         dc.b    $00,$00,$00,$00,$00,$00
  4148.  
  4149.         dc.l    'TSX'
  4150.         dc.b    $00,$00,$00,$00,$ba,$00,$00,$00
  4151.         dc.b    $00,$00,$00,$00,$00,$00
  4152.  
  4153.         dc.l    'CLV'
  4154.         dc.b    $00,$00,$00,$00,$b8,$00,$00,$00
  4155.         dc.b    $00,$00,$00,$00,$00,$00
  4156.  
  4157. ; JMP special case
  4158.  
  4159. ; BRK special case!
  4160.  
  4161. ; RMB, SMB special cases
  4162.  
  4163. ; BBR, BBS special cases
  4164.  
  4165.         dc.l    0,0
  4166.  
  4167. CPU        dc.w    %0000100100001001    ;00
  4168.         dc.w    %0010100100101001    ;01
  4169.         dc.w    %0000000100000001    ;02
  4170.         dc.w    %0010100100101001    ;03
  4171.         dc.w    %0000000100000001    ;04
  4172.         dc.w    %0010000100100001    ;05
  4173.         dc.w    %0000100100000001    ;06
  4174.         dc.w    %0010100100101001    ;07
  4175.         dc.w    %1000000101000001    ;08
  4176.         dc.w    %0010000100001011    ;09
  4177.         dc.w    %0000000100000001    ;10
  4178.         dc.w    %0010000100000001    ;11
  4179.         dc.w    %0000000100000001    ;12
  4180.         dc.w    %0010000100100001    ;13
  4181.         dc.w    %0000000100000001    ;14
  4182.         dc.w    %0010000100100001    ;15
  4183.  
  4184.  
  4185. ermsgs        dc.b    0        1
  4186.         dc.b    0        2
  4187.         dc.b    0        3
  4188.         dc.b    'Memory allocation error',LF,0        4
  4189.         dc.b    'Cannot create file',LF,0        5
  4190.         dc.b    'Error writing file',LF,0        6
  4191.         dc.b    'File not found',LF,0            7
  4192.         dc.b    'No filename',LF,0            8
  4193.         dc.b    'Options error',LF,0            9
  4194.         dc.b    'Level 0 calculation error',LF,0    10
  4195.         dc.b    'Level 1 calculation error',LF,0    11
  4196.         dc.b    'Illegal numeric value',LF,0        12
  4197.         dc.b    'Division by zero',LF,0            13
  4198.         dc.b    'Parenthesis mismatch',LF,0        14
  4199.         dc.b    'Quotes upset',LF,0            15
  4200.         dc.b    0        16
  4201.         dc.b    0        17
  4202.         dc.b    0        18
  4203.         dc.b    0        19
  4204.         dc.b    'Syntax error',LF,0            20
  4205.         dc.b    'Unknown addressing mode',LF,0        21
  4206.         dc.b    'An 8-bit value expected',LF,0        22
  4207.         dc.b    '65c02 mode only',LF,0            23
  4208.         dc.b    'Branch too long',LF,0            24
  4209.         dc.b    'Illegal adressing mode',LF,0        25
  4210.         dc.b    'EQU expected',LF,0            26
  4211.         dc.b    'Unknown mnemonic',LF,0            27
  4212.         dc.b    'A 16-bit value expected',LF,0        28
  4213.         dc.b    'PC-value too large',LF,0        29
  4214.         dc.b    'Out of symbol buffer',LF,0        30
  4215.         dc.b    'Redefined symbol',LF,0            31
  4216.         dc.b    'Illegal symbol name',LF,0        32
  4217.         dc.b    'Symbol too long',LF,0            33
  4218.         dc.b    'Undefined symbol',LF,0            34
  4219.         dc.b    'EQU symbol cannot be redefined',LF,0    35
  4220.         dc.b    'Symbol already set by SET/EQU',LF,0    36
  4221.         dc.b    'Missing symbol name',LF,0        37
  4222.         dc.b    'Absolute symbol value mismatch',LF,0    38
  4223.         dc.b    'SET/EQU symbol value mismatch',LF,0    39
  4224.         dc.b    'Incomplete statement',LF,0        40
  4225.         dc.b    'File not found',LF,0            41
  4226.         dc.b    'Include nesting too deep',LF,0        42
  4227.         dc.b    'Read error',LF,0            43
  4228.         dc.b    'Out of memory error',LF,0        44
  4229.         dc.b    'Source file too long',LF,0        45
  4230.         dc.b    'Illegal usage of IEND symbol',LF,0    46
  4231.         dc.b    0        47
  4232.         dc.b    0        48
  4233.         dc.b    0        49
  4234.         dc.b    'Condition level overflow',LF,0        50
  4235.         dc.b    'ENDC without condition',LF,0        51
  4236.         dc.b    'Missing ENDC',LF,0            52
  4237.         dc.b    'Syntax error',LF,0            53
  4238.         dc.b    'FAIL error',LF,0            54
  4239.         dc.b    0        55
  4240.         dc.b    0        56
  4241.         dc.b    0        57
  4242.         dc.b    0        58
  4243.         dc.b    0        59
  4244.         dc.b    'ENDM without MACRO',LF,0        60
  4245.         dc.b    'Redefined Macro',LF,0            61
  4246.         dc.b    'Illegal macro definition',LF,0        62
  4247.         dc.b    'Missing macro name',LF,0        63
  4248.         dc.b    'ENDM missing',LF,0            64
  4249.         dc.b    'Macro parameter mismatch',LF,0        65
  4250.         dc.b    'Macro nesting too deep',LF,0        66
  4251.         dc.b    'No <<>> nesting allowed',LF,0        67
  4252.         dc.b    'Missing quote or syntax error',LF,0    68
  4253.         dc.b    0        69
  4254.         dc.b    -1
  4255.  
  4256.  
  4257.  
  4258. hextable    dc.b    '0123456789abcdef'    needs no comments
  4259.         cnop    0,4
  4260.  
  4261. obuf        dc.l    0        output buffer start address
  4262. opoi        dc.l    0        output buffer pointer
  4263. _CMDLen        dc.l    0        command line length
  4264. _CMDBuf        dc.l    0        command line start address
  4265. outfile        dc.l    0        output filehandle
  4266. infile        dc.l    0        input filehandle
  4267. clifile        dc.l    0        clifilehandle
  4268. listfile    dc.l    0        listing filehandle
  4269. sourcebuf    dc.l    0        source buffer start address
  4270. sourceend    dc.l    $0fffffff    source buffer end address
  4271. total_len    dc.l    0        total length of all included files
  4272. SOURCEBUF    dc.l    1000        source buffer size
  4273. auxbuf        dc.l    0        auxiliary buffer start (filenames)
  4274. multibuf    dc.l    0        buffer for filenames & errhandler & listout
  4275. libuf        dc.l    0        start of list buffer
  4276. labelbuf    dc.l    0        start address of label buffer
  4277. txtptr        dc.l    0        pointer into source buffer
  4278. par1        dc.l    0        65c02 parameter storage
  4279. prgc        dc.l    0        65c02 program counter storage
  4280. totalbyt    dc.l    0        65c02 object length in bytes
  4281. checksum    dc.l    0        65c02 object checksum
  4282. tbuffer        ds.b    32        temp buffer
  4283. zpabs        dc.b    0        flag: zeropage/absolute
  4284. pass        dc.b    0        pass identifier
  4285. errcnt        dc.l    0        error counter
  4286. errornum    dc.w    0        current error number
  4287. linnum        dc.l    0        current linenumber
  4288. linstrt        dc.l    0        current line start address
  4289. nameptr        dc.l    0        current filename ptr
  4290. McExpCnt    dc.l    0        counts \@'s during macro processing
  4291. McNesting    dc.w    0        current macro nesting level
  4292. pat_pend    dc.w    0        helps cg()
  4293. hexmode        dc.w    0        flag: build hexadecimal output file
  4294. procmode    dc.w    0        flag: 65c02 mode
  4295. userlmode    dc.w    0        flag: listmode set using option -l
  4296. listmode    dc.w    0        flag: build listing file (taken from userlmode)
  4297. no_list        dc.w    0        flag: don't list this line
  4298. idepth        dc.w    0        flag: compiling an include file
  4299. incstrt        dc.w    0        flag: new include file starts (set by INCLUDE)
  4300. condstrt    dc.w    0        flag: new conditional part starts
  4301. symbolmode    dc.w    0        flag: print symbol table
  4302. cond_level    dc.w    0        current conditional assembly level
  4303. lnf        dc.w    0        flag: label not found (for ifd/ifnd)
  4304. hexbytcnt    dc.w    3        counter: 3 hexbytes/listing line
  4305. broken        dc.w    0        flag: program stopped by user
  4306. absmism        dc.w    0        flag: absolute value mism already printed
  4307.  
  4308. sl_flag        dc.w    0        flag: glabel called from slabel
  4309. equset        dc.l    0        flag/value: a symbol set/equted on this line
  4310.  
  4311. prtline        dc.w    HUGELINE    current printer line
  4312. maxline        dc.w    MAXLINE        maximum printer line
  4313. prtpage        dc.w    0        current printer page
  4314.  
  4315. incnames    ds.l    INCNESTING+1    nameptrs for including
  4316. condflags    ds.b    CONDNESTING+1    true/false flags for each level
  4317.         cnop    0,2
  4318.  
  4319.         libnames        library names & base pointers
  4320.  
  4321.         end
  4322.  
  4323.