home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / language / asxbin / buf25.asm < prev    next >
Encoding:
Assembly Source File  |  1993-10-23  |  98.6 KB  |  4,989 lines

  1. ;*            buffalo
  2. ;*
  3. ;*  (c) copyright Motorola, Inc
  4. ;*
  5. ;* "bit user's fast friendly aid to logical operation"
  6. ;*
  7. ;* rev 2.0 - 4/23/85    - added disassembler.
  8. ;*            - variables now ptrn and tmpn.
  9. ;* rev 2.1 - 4/29/85    - added byte erase to chgbyt routine.
  10. ;* rev 2.2 - 5/16/85    - added hooks for evb board - acia
  11. ;*              drivers, init and host routines.
  12. ;*         7/8/85     - fixed dump wraparound problem.
  13. ;*         7/10/85    - added evm board commands.
  14. ;*            - added fill instruction.
  15. ;*         7/18/85    - added jump to eeprom.
  16. ;* rev 2.3 - 8/22/85     - call targco to disconnect sci from host
  17. ;*              in reset routine for evb board.
  18. ;*         10/3/85    - modified load for download through terminal.
  19. ;* rev 2.4 - 7/1/86    - changed dflop address to fix conflicts with
  20. ;*              eeprom.  (was at a000)
  21. ;* rev 2.5 - 9/8/86    - modified to provide additional protection from
  22. ;*              program run-away on power down.  also fixed bugs
  23. ;*              in mm and move.  changed to 1 stop bit from 2.
  24. ;*
  25. ;********************************************************
  26. ;*    although the information contained herein,    *
  27. ;*    as well as any information provided relative    *
  28. ;*    thereto, has been carefully reviewed and is    *
  29. ;*    believed accurate, motorola assumes no        *
  30. ;*    liability arising out of its application or    *
  31. ;*    use, neither does it convey any license under    *
  32. ;*    its patent rights nor the rights of others.    *
  33. ;********************************************************
  34.  
  35.     .area    BUF25    (ABS,OVR)
  36.  
  37.     .setdp
  38.  
  39. ;************************
  40. ;*    equates        *
  41. ;************************
  42.  
  43. rambs    =    0x0000        ; start of ram
  44. regbs    =    0x1000        ; start of registers
  45. rombs    =    0xe000        ; start of rom
  46. porte    =    regbs+0x0a    ; port e
  47. tcnt    =    regbs+0x0e    ; timer count
  48. toc5    =    regbs+0x1e    ; oc5 reg
  49. tctl1    =    regbs+0x20    ; timer control 1
  50. tmsk1    =    regbs+0x22    ; timer mask 1
  51. tflg1    =    regbs+0x23    ; timer flag 1
  52. tmsk2    =    regbs+0x24    ; timer mask 2
  53. baud    =    regbs+0x2b    ; sci baud reg
  54. sccr1    =    regbs+0x2c    ; sci control1 reg
  55. sccr2    =    regbs+0x2d    ; sci control2 reg
  56. scsr    =    regbs+0x2e    ; sci status reg
  57. scdat    =    regbs+0x2f    ; sci data reg
  58. option    =    regbs+0x39    ; option reg
  59. coprst    =    regbs+0x3a    ; cop reset reg
  60. pprog    =    regbs+0x3b    ; ee prog reg
  61. hprio    =    regbs+0x3c    ; hprio reg
  62. config    =    regbs+0x3f    ; config register
  63. dflop    =    0x4000        ; evb d flip flop
  64. duart    =    0xd000        ; duart address
  65. porta    =    duart
  66. portb    =    duart+8
  67. acia    =    0x9800        ; acia address
  68. prompt    =    '>
  69. bufflng    =    35
  70. ctla    =    0x01        ; exit host or assembler
  71. ctlb    =    0x02        ; send break to host
  72. ctlw    =    0x17        ; wait
  73. ctlx    =    0x18        ; abort
  74. del    =    0x7f        ; abort
  75. eot    =    0x04        ; end of text/table
  76. swi    =    0x3f
  77.  
  78. ;***************
  79. ;*     ram     *
  80. ;***************
  81.  
  82.     .org    0x36
  83.  
  84. ;*** buffalo ram space ***
  85.  
  86.     .blkb    20    ; user stack area
  87. ustack:    .blkb    30    ; monitor stack area
  88. stack:    .blkb    1
  89. inbuff:    .blkb    bufflng    ; input buffer
  90. endbuff    = .
  91. combuff:
  92.     .blkb    8    ; command buffer
  93. shftreg:
  94.     .blkb    2    ; input shift register
  95. brktabl:
  96.     .blkb    8    ; breakpoint table
  97. regs:    .blkb    9    ; user's pc,y,x,a,b,c
  98. sp:    .blkb    2    ; user's sp
  99. autolf:    .blkb    1    ; auto lf flag for i/o
  100. iodev:    .blkb    1    ; 0=sci,  1=acia, 2=duarta, 3=duartb
  101. extdev:    .blkb    1    ; 0=none, 1=acia, 2=duart,
  102. hostdev:
  103.     .blkb    1    ; 0=sci,  1=acia,        3=duartb
  104. count:    .blkb    1    ; # characters read
  105. ptrmem:    .blkb    2    ; current memory location
  106.  
  107. ;*** buffalo variables - used by: ***
  108. ptr0:    .blkb    2    ; main,readbuff,incbuff,as
  109. ptr1:    .blkb    2    ; main,br,du,mo,as
  110. ptr2:    .blkb    2    ; du,go,mo,as
  111. ptr3:    .blkb    2    ; ho,mo,as
  112. ptr4:    .blkb    2    ; go,as
  113. ptr5:    .blkb    2    ; as
  114. ptr6:    .blkb    2    ; go,as
  115. ptr7:    .blkb    2    ; go,as
  116. tmp1:    .blkb    1    ; main,hexbin,buffarg,termarg
  117. tmp2:    .blkb    1    ; go,ho,as
  118. tmp3:    .blkb    1    ; as
  119. tmp4:    .blkb    1    ; go,ho,me,as
  120.  
  121. ;*** vector jump table ***
  122. jsci:    .blkb    3
  123. jspi:    .blkb    3
  124. jpaie:    .blkb    3
  125. jpao:    .blkb    3
  126. jtof:    .blkb    3
  127. jtoc5:    .blkb    3
  128. jtoc4:    .blkb    3
  129. jtoc3:    .blkb    3
  130. jtoc2:    .blkb    3
  131. jtoc1:    .blkb    3
  132. jtic3:    .blkb    3
  133. jtic2:    .blkb    3
  134. jtic1:    .blkb    3
  135. jrti:    .blkb    3
  136. jirq:    .blkb    3
  137. jxirq:    .blkb    3
  138. jswi:    .blkb    3
  139. jillop:    .blkb    3
  140. jcop:    .blkb    3
  141. jclm:    .blkb    3
  142.  
  143. ;*****************
  144. ;*
  145. ;* rom starts here *
  146. ;*
  147. ;*****************
  148.  
  149.     .org    rombs
  150.  
  151. ;*****************
  152. ;**    buffalo - this is where buffalo starts
  153. ;** out of reset.  all initialization is done
  154. ;** here including determination of where the
  155. ;** user terminal is (sci,acia, or duart).
  156. ;*****************
  157.  
  158. buffalo:
  159.     ldx    #porte
  160.     brclr 0,x,#0x01,bufisit    ; if bit 0 of port e is 1
  161.     jmp    0xb600        ; then jump to the start of eeprom
  162. bufisit:
  163.     ldaa    #0x93
  164.     staa    option        ; adpu, dly, irqe, cop
  165.     ldaa    #0x00
  166.     staa    tmsk2        ; timer pre = %1 for trace
  167.     lds    #stack        ; monitor stack pointer
  168.     jsr    vecinit
  169.     ldx    #ustack
  170.     stx    *sp        ; default user stack
  171.     ldaa    #0xd0
  172.     staa    *regs+8        ; default user ccr
  173.     ldd    #0x3f0d        ; initial command is ?
  174.     std    *inbuff
  175.     jsr    bpclr        ; clear breakpoints
  176.     clr    *autolf
  177.     inc    *autolf        ; auto cr/lf = on
  178.  
  179. ;* determine type of external comm device - none, or acia *
  180.  
  181.     clr    *extdev        ; default is none
  182.     ldaa    hprio
  183.     anda    #0x20
  184.     beq    buff2        ; jump if single chip mode
  185.     ldaa    #0x03        ; see if external acia exists
  186.     staa    acia        ; master reset
  187.     ldaa    acia
  188.     anda    #0x7f        ; mask irq bit from status register
  189.     bne    buff1        ; jump if status reg not 0
  190.     ldaa    #0x12
  191.     staa    acia        ; turn on acia
  192.     ldaa    acia
  193.     anda    #0x02
  194.     beq    buff1        ; jump if tdre not set
  195.     ldaa    #0x01
  196.     staa    *extdev        ; external device is acia
  197.     bra    buff2
  198.  
  199. buff1    = .            ; see if duart exists
  200.     ldaa    duart+0x0c    ; read irq vector register
  201.     cmpa    #0x0f        ; should be out of reset
  202.     bne    buff2
  203.     ldaa    #0xaa
  204.     staa    duart+0x0c    ; write irq vector register
  205.     ldaa    duart+0x0c    ; read irq vector register
  206.     cmpa    #0xaa
  207.     bne    buff2
  208.     ldaa    #0x02
  209.     staa    *extdev        ; external device is duart a
  210.  
  211. ;* find terminal port - sci or external. *
  212.  
  213. buff2:    clr    *iodev
  214.     jsr    targco        ; disconnect sci for evb board
  215.     jsr    signon        ; initialize sci
  216.     ldaa    *extdev
  217.     beq    buff3        ; jump if no external device
  218.     staa    *iodev
  219.     jsr    signon        ; initialize external device
  220. buff3:    clr    *iodev
  221.     jsr    input        ; get input from sci port
  222.     cmpa    #0x0d
  223.     beq    buff4        ; jump if cr - sci is terminal port
  224.     ldaa    *extdev
  225.     beq    buff3        ; jump if no external device
  226.     staa    *iodev
  227.     jsr    input        ; get input from external device
  228.     cmpa    #0x0d
  229.     beq    buff4        ; jump if cr - terminal found ext
  230.     bra    buff3
  231.  
  232. signon:    jsr    init        ; initialize device
  233.     ldx    #msg1        ; buffalo message
  234.     jsr    outstrg
  235.     rts
  236.  
  237. ;* determine where host port should be.
  238.  
  239. buff4:    clr    *hostdev        ; default - host = sci port
  240.     ldaa    *iodev
  241.     cmpa    #0x01
  242.     beq    buff5        ; default host if term = acia
  243.     ldaa    #0x03
  244.     staa    *hostdev        ; else host is duart port b
  245. buff5    = .
  246.  
  247. ;*****************
  248. ;**    main - this module reads the user's input into
  249. ;** a buffer called inbuff.  the first field (assumed
  250. ;** to be the command field) is then parsed into a
  251. ;** second buffer called combuff.  the command table
  252. ;** is then searched for the contents of combuff and
  253. ;** if found, the address of the corresponding task
  254. ;** routine is fetched from the command table.  the
  255. ;** task is then called as a subroutine so that
  256. ;** control returns back to here upon completion of
  257. ;** the task.  buffalo expects the following format
  258. ;** for commands:
  259. ;**    <cmd>[<wsp><arg><wsp><arg>...]<cr>
  260. ;** [] implies contents optional.
  261. ;** <wsp> means whitespace character (space,comma,tab).
  262. ;** <cmd> = command string of 1-8 characters.
  263. ;** <arg> = argument particular to the command.
  264. ;** <cr> = carriage return signifying end of input string.
  265. ;*****************
  266. ;* prompt user
  267. ;*do
  268. ;*    a=input();
  269. ;*    if(a==(cntlx or del)) continue;
  270. ;*    elseif(a==backspace)
  271. ;*    b--;
  272. ;*    if(b<0) b=0;
  273. ;*    else
  274. ;*    if(a==cr && buffer empty)
  275. ;*        repeat last command;
  276. ;*    else put a into buffer;
  277. ;*        check if buffer full;
  278. ;*while(a != (cr or /)
  279.  
  280. main:    lds    #stack        ; initialize sp every time
  281.     clr    *autolf
  282.     inc    *autolf        ; auto cr/lf = on
  283.     jsr    outcrlf
  284.     ldaa    #prompt        ; prompt user
  285.     jsr    output
  286.     clrb
  287. main1:    jsr    inchar        ; read terminal
  288.     ldx    #inbuff
  289.     abx            ; pointer into buffer
  290.     cmpa    #ctlx
  291.     beq    main        ; jump if cntl x
  292.     cmpa    #del
  293.     beq    main        ; jump if del
  294.     cmpa    #0x08
  295.     bne    main2        ; jump if not bckspc
  296.     decb
  297.     blt    main        ; jump if buffer empty
  298.     bra    main1
  299. main2:    cmpa    #0xd
  300.     bne    main3        ; jump if not cr
  301.     tstb
  302.     beq    comm0        ; jump if buffer empty
  303.     staa    ,x        ; put a in buffer
  304.     bra    comm0
  305. main3:    staa    ,x        ; put a in buffer
  306.     incb
  307.     cmpb    #bufflng
  308.     ble    main4        ; jump if not long
  309.     ldx    #msg3        ; "long"
  310.     jsr    outstrg
  311.     bra    main
  312. main4:    cmpa    #'/
  313.     bne    main1        ; jump if not "/"
  314. ;*    *******************
  315.  
  316. ;*****************
  317. ;*    parse out and evaluate the command field.
  318. ;*****************
  319. ;*initialize
  320.  
  321. comm0    = .
  322.     clr    *tmp1        ; enable "/" command
  323.     clr    *shftreg
  324.     clr    *shftreg+1
  325.     clrb
  326.     ldx    #inbuff        ; ptrbuff[] = inbuff[]
  327.     stx    *ptr0
  328.     jsr    wskip        ; find first char
  329.  
  330. ;*while((a=readbuff) != (cr or wspace))
  331. ;*    upcase(a);
  332. ;*    buffptr[b] = a
  333. ;*    b++
  334. ;*    if (b > 8) error(too long);
  335. ;*    if(a == "/")
  336. ;*        if(enabled) mslash();
  337. ;*        else error(command?);
  338. ;*    else hexbin(a);
  339.  
  340. comm1    = .
  341.     jsr    readbuff    ; read from buffer
  342.     ldx    #combuff
  343.     abx
  344.     jsr    upcase        ; convert to upper case
  345.     staa    ,x        ; put in command buffer
  346.     cmpa    #0x0d
  347.     beq    srch        ; jump if cr
  348.     jsr    wchek
  349.     beq    srch        ; jump if wspac
  350.     jsr    incbuff        ; move buffer pointer
  351.     incb
  352.     cmpb    #0x8
  353.     ble    comm2
  354.     ldx    #msg3        ; "long"
  355.     jsr    outstrg
  356.     jmp    main
  357.  
  358. comm2    = .
  359.     cmpa    #'/
  360.     bne    comm4        ; jump if not "/"
  361.     tst    *tmp1
  362.     bne    comm3        ; jump if not enabled
  363.     stab    *count
  364.     ldx    #mslash
  365.     jmp    exec        ; execute "/"
  366. comm3:    ldx    #msg8        ; "command?"
  367.     jsr    outstrg
  368.     jmp    main
  369. comm4    = .
  370.     jsr    hexbin
  371.     bra    comm1
  372.  
  373. ;*****************
  374. ;*    search tables for command.    at this point,
  375. ;* combuff holds the command field to be executed,
  376. ;* and b =    # of characters in the command field.
  377. ;* the command table holds the whole command name
  378. ;* but only the first n characters of the command
  379. ;* must match what is in combuff where n is the
  380. ;* number of characters entered by the user.
  381. ;*****************
  382. ;*count = b;
  383. ;*ptr1 = comtabl;
  384. ;*while(ptr1[0] != end of table)
  385. ;*    ptr1 = next entry
  386. ;*    for(b=1; b=count; b++)
  387. ;*    if(ptr1[b] == combuff[b]) continue;
  388. ;*    else error(not found);
  389. ;*    execute task;
  390. ;*    return();
  391. ;*return(command not found);
  392.  
  393. srch:    stab    *count        ; size of command entered
  394.     ldx    #comtabl    ; pointer to table
  395.     stx    *ptr1        ; pointer to next entry
  396. srch1:    ldx    *ptr1
  397.     ldy    #combuff    ; pointer to command buffer
  398.     ldab    0,x
  399.     cmpb    #0xff
  400.     bne    srch2
  401.     ldx    #msg2        ; "command not found"
  402.     jsr    outstrg
  403.     jmp    main
  404. srch2:    pshx            ; compute next table entry
  405.     addb    #0x3
  406.     abx
  407.     stx    *ptr1
  408.     pulx
  409.     clrb
  410. srchlp:    incb            ; match characters loop
  411.     ldaa    1,x        ; read table
  412.     cmpa    0,y        ; compare to combuff
  413.     bne    srch1        ; try next entry
  414.     inx            ; move pointers
  415.     iny
  416.     cmpb    *count
  417.     blt    srchlp        ; loop countu1 times
  418.     ldx    *ptr1
  419.     dex
  420.     dex
  421.     ldx    0,x        ; jump address from table
  422. exec:    jsr    0,x        ; call task as subroutine
  423.     jmp    main
  424. ;*
  425. ;*****************
  426. ;*    utility subroutines - these routines
  427. ;* are called by any of the task routines.
  428. ;*****************
  429. ;*****************
  430. ;*    upcase(a) - if the contents of a is alpha,
  431. ;* returns a converted to uppercase.
  432. ;*****************
  433. upcase:    cmpa    #'a
  434.     blt    upcase1        ; jump if < a
  435.     cmpa    #'z
  436.     bgt    upcase1        ; jump if > z
  437.     suba    #0x20        ; convert
  438. upcase1:
  439.     rts
  440.  
  441. ;*****************
  442. ;*    bpclr() - clear all entries in the
  443. ;* table of breakpoints.
  444. ;*****************
  445. bpclr:    ldx    #brktabl
  446.     ldab    #8
  447. bpclr1:    clr    0,x
  448.     inx
  449.     decb
  450.     bgt    bpclr1        ; loop 8 times
  451.     rts
  452.  
  453. ;*****************
  454. ;*    rprnt1(x) - prints name and contents of a single
  455. ;* user register. on entry x points to name of register
  456. ;* in reglist.  on exit, a=register name.
  457. ;*****************
  458. reglist:
  459.     .ascii    'PYXABCS'    ; names
  460.     .byte    0,2,4,6,7,8,9    ; offset
  461.     .byte    1,1,1,0,0,0,1    ; size
  462.  
  463. rprnt1:    ldaa    0,x
  464.     psha
  465.     pshx
  466.     jsr    output        ; name
  467.     ldaa    #'-
  468.     jsr    output        ; dash
  469.     ldab    7,x        ; contents offset
  470.     ldaa    14,x        ; bytesize
  471.     ldx    #regs        ; address
  472.     abx
  473.     tsta
  474.     beq    rprn2        ; jump if 1 byte
  475.     jsr    out1byt        ; 2 bytes
  476. rprn2:    jsr    out1bsp
  477.     pulx
  478.     pula
  479.     rts
  480.  
  481. ;*****************
  482. ;*    rprint() - print the name and contents
  483. ;* of all the user registers.
  484. ;*****************
  485. rprint:    pshx
  486.     ldx    #reglist
  487. rpri1:    jsr    rprnt1        ; print name
  488.     inx
  489.     cmpa    #'S        ; s is last register
  490.     bne    rpri1        ; jump if not done
  491.     pulx
  492.     rts
  493.  
  494. ;*****************
  495. ;*    hexbin(a) - convert the ascii character in a
  496. ;* to binary and shift into shftreg.  returns value
  497. ;* in tmp1 incremented if a is not hex.
  498. ;*****************
  499. hexbin:    psha
  500.     pshb
  501.     pshx
  502.     jsr    upcase        ; convert to upper case
  503.     cmpa    #'0
  504.     blt    hexnot        ; jump if a < 0x30
  505.     cmpa    #'9
  506.     ble    hexnmb        ; jump if 0-9
  507.     cmpa    #'A
  508.     blt    hexnot        ; jump if 0x39> a <0x41
  509.     cmpa    #'F
  510.     bgt    hexnot        ; jump if a > 0x46
  511.     adda    #0x9        ; convert 0xa-0xf
  512. hexnmb:    anda    #0x0f        ; convert to binary
  513.     ldx    #shftreg
  514.     ldab    #4
  515. hexshft:
  516.     asl    1,x        ; 2 byte shift through
  517.     rol    0,x        ; carry bit
  518.     decb
  519.     bgt    hexshft        ; shift 4 times
  520.     oraa    1,x
  521.     staa    1,x
  522.     bra    hexrts
  523. hexnot:    inc    *tmp1        ; indicate not hex
  524. hexrts:    pulx
  525.     pulb
  526.     pula
  527.     rts
  528.  
  529. ;*****************
  530. ;*    buffarg() - build a hex argument from the
  531. ;* contents of the input buffer. characters are
  532. ;* converted to binary and shifted into shftreg
  533. ;* until a non-hex character is found.  on exit
  534. ;* shftreg holds the last four digits read, count
  535. ;* holds the number of digits read, ptrbuff points
  536. ;* to the first non-hex character read, and a holds
  537. ;* that first non-hex character.
  538. ;*****************
  539. ;*initialize
  540. ;*while((a=readbuff()) not hex)
  541. ;*    hexbin(a);
  542. ;*return();
  543.  
  544. buffarg:
  545.     clr    *tmp1        ; not hex indicator
  546.     clr    *count        ; # or digits
  547.     clr    *shftreg
  548.     clr    *shftreg+1
  549.     jsr    wskip
  550. bufflp:    jsr    readbuff    ; read char
  551.     jsr    hexbin
  552.     tst    *tmp1
  553.     bne    buffrts        ; jump if not hex
  554.     inc    *count
  555.     jsr    incbuff        ; move buffer pointer
  556.     bra    bufflp
  557. buffrts:
  558.     rts
  559.  
  560. ;*****************
  561. ;*    termarg() - build a hex argument from the
  562. ;* terminal.  characters are converted to binary
  563. ;* and shifted into shftreg until a non-hex character
  564. ;* is found.  on exit shftreg holds the last four
  565. ;* digits read, count holds the number of digits
  566. ;* read, and a holds the first non-hex character.
  567. ;*****************
  568. ;*initialize
  569. ;*while((a=inchar()) == hex)
  570. ;*    if(a = cntlx or del)
  571. ;*        abort;
  572. ;*    else
  573. ;*        hexbin(a); countu1++;
  574. ;*return();
  575.  
  576. termarg:
  577.     clr    *count
  578.     clr    *shftreg
  579.     clr    *shftreg+1
  580. term0:    jsr    inchar
  581.     cmpa    #ctlx
  582.     beq    term1        ; jump if controlx
  583.     cmpa    #del
  584.     bne    term2        ; jump if not delete
  585. term1:    jmp    main        ; abort
  586. term2:    clr    *tmp1        ; hex indicator
  587.     jsr    hexbin
  588.     tst    *tmp1
  589.     bne    term3        ; jump if not hex
  590.     inc    *count
  591.     bra    term0
  592. term3:    rts
  593.  
  594. ;*****************
  595. ;*    chgbyt() - if shftreg is not empty, put
  596. ;* contents of shftreg at address in x.    if x
  597. ;* is an address in eeprom then program it.
  598. ;*****************
  599. ;*if(count != 0)
  600. ;*    (x) = a;
  601. ;*    if(((x) != a) && (x == eeprom location))
  602. ;*    if((x) != 0xff) byte erase (x);
  603. ;*    if(a != 0xff) program(x) = a);
  604. ;*    if((x) != a) error(rom)
  605. ;*return;
  606.  
  607. chgbyt:    tst    *count
  608.     beq    chgbyt4        ; jump if shftreg empty
  609.     ldaa    *shftreg+1
  610.     staa    0,x        ; attempt to write
  611.     ldaa    0,x
  612.     cmpa    *shftreg+1
  613.     beq    chgbyt3        ; jump if it worked
  614.     cpx    #config
  615.     beq    chgbyt1        ; jump if config reg
  616.     cpx    #0xb600
  617.     blo    chgbyt3        ; jump if not ee
  618.     cpx    #0xb7ff
  619.     bhi    chgbyt3        ; jump if not ee
  620. chgbyt1    = .
  621.     ldaa    0,x
  622.     cmpa    #0xff
  623.     beq    chgbyt2        ; jump if already erased
  624.     ldaa    #0x16        ; do byte erase
  625.     staa    pprog
  626.     ldaa    #0xff
  627.     staa    0,x
  628.     ldaa    #0x17
  629.     bne    acl1
  630.     clra            ; fail safe
  631. acl1:    staa    pprog
  632.     bsr    chgwait
  633.     ldaa    #0x00
  634.     staa    pprog        ; end of byte erase
  635. chgbyt2    = .
  636.     ldaa    *shftreg+1
  637.     cmpa    #0xff
  638.     beq    chgbyt3        ; jump if no need to program
  639.     ldaa    #0x02        ; do byte program
  640.     staa    pprog
  641.     ldaa    *shftreg+1
  642.     staa    0,x
  643.     ldaa    #0x03
  644.     bne    acl2
  645.     clra            ; fail safe
  646. acl2:    staa    pprog
  647.     bsr    chgwait
  648.     ldaa    #0x00
  649.     staa    pprog        ; end of byte program
  650. chgbyt3    = .
  651.     ldaa    ,x
  652.     cmpa    *shftreg+1
  653.     beq    chgbyt4
  654.     pshx
  655.     ldx    #msg6        ; "rom"
  656.     jsr    outstrg
  657.     jsr    outcrlf
  658.     pulx
  659. chgbyt4    = .
  660.     rts
  661.  
  662. chgwait    = .         ; delay 10 ms at E = 2mhz
  663.     pshx
  664.     ldx    #0x0d06
  665. chgwait1:
  666.     dex
  667.     bne    chgwait1
  668.     pulx
  669.     rts
  670.  
  671. ;*****************
  672. ;*    readbuff() -  read the character in inbuff
  673. ;* pointed at by ptrbuff into a.  returns ptrbuff
  674. ;* unchanged.
  675. ;*****************
  676. readbuff:
  677.     pshx
  678.     ldx    *ptr0
  679.     ldaa    0,x
  680.     pulx
  681.     rts
  682.  
  683. ;*****************
  684. ;*    incbuff(), decbuff() - increment or decrement
  685. ;* ptrbuff.
  686. ;*****************
  687. incbuff:
  688.     pshx
  689.     ldx    *ptr0
  690.     inx
  691.     bra    incdec
  692. decbuff:
  693.     pshx
  694.     ldx    *ptr0
  695.     dex
  696. incdec:    stx    *ptr0
  697.     pulx
  698.     rts
  699.  
  700. ;*****************
  701. ;*    wskip() - read from the inbuff until a
  702. ;* non whitespace (space, comma, tab) character
  703. ;* is found.  returns ptrbuff pointing to the
  704. ;* first non-whitespace character and a holds
  705. ;* that character.
  706. ;*****************
  707. wskip:    jsr    readbuff    ; read character
  708.     jsr    wchek
  709.     bne    wskip1        ; jump if not wspc
  710.     jsr    incbuff        ; move pointer
  711.     bra    wskip        ; loop
  712. wskip1:    rts
  713.  
  714. ;*****************
  715. ;*    wchek(a) - returns z=1 if a holds a
  716. ;* whitespace character, else z=0.
  717. ;*****************
  718. wchek:    cmpa    #0x2c        ; comma
  719.     beq    wchek1
  720.     cmpa    #0x20        ; space
  721.     beq    wchek1
  722.     cmpa    #0x09        ; tab
  723. wchek1:    rts
  724.  
  725. ;*****************
  726. ;*    dchek(a) - returns z=1 if a = whitespace
  727. ;* or carriage return.    else returns z=0.
  728. ;*****************
  729. dchek:    jsr    wchek
  730.     beq    dchek1        ; jump if whitespace
  731.     cmpa    #0x0d
  732. dchek1:    rts
  733.  
  734. ;*****************
  735. ;*    chkabrt() - checks for a control x or delete
  736. ;* from the terminal.  if found, the stack is
  737. ;* reset and the control is transferred to main.
  738. ;* note that this is an abnormal termination.
  739. ;*    if the input from the terminal is a control w
  740. ;* then this routine keeps waiting until any other
  741. ;* character is read.
  742. ;*****************
  743. ;*a=input();
  744. ;*if(a=cntl w) wait until any other key;
  745. ;*if(a = cntl x or del) abort;
  746.  
  747. chkabrt:
  748.     jsr    input
  749.     beq    chk4        ; jump if no input
  750.     cmpa    #ctlw
  751.     bne    chk2        ; jump in not cntlw
  752. chkabrt1:
  753.     jsr    input
  754.     beq    chkabrt1    ; jump if no input
  755. chk2:    cmpa    #del
  756.     beq    chk3        ; jump if delete
  757.     cmpa    #ctlx
  758.     beq    chk3        ; jump if control x
  759.     cmpa    #ctla
  760.     bne    chk4        ; jump not control a
  761. chk3:    jmp    main        ; abort
  762. chk4:    rts            ; return
  763.  
  764. ;***********************
  765. ;*    hostco - connect sci to host for evb board.
  766. ;*    targco - connect sci to target for evb board.
  767. ;***********************
  768. hostco:    psha
  769.     ldaa    #0x01
  770.     staa    dflop        ; send 1 to d-flop
  771.     pula
  772.     rts
  773.  
  774. targco:    psha
  775.     ldaa    #0x00
  776.     staa    dflop        ; send 0 to d-flop
  777.     pula
  778.     rts
  779.  
  780. ;*
  781. ;**********
  782. ;*
  783. ;*    vecinit - this routine checks for
  784. ;*    vectors in the ram table.    all
  785. ;*    uninitialized vectors are programmed
  786. ;*    to jmp stopit
  787. ;*
  788. ;**********
  789. ;*
  790. vecinit:
  791.     ldx    #jsci        ; point to first ram vector
  792.     ldy    #stopit        ; pointer to stopit routine
  793.     ldd    #0x7e03        ; a=jmp opcode; b=offset
  794. vecloop:
  795.     cmpa    0,x
  796.     beq    vecnext        ; if vector already in
  797.     staa    0,x        ; install jmp
  798.     sty    1,x        ; to stopit routine
  799. vecnext:
  800.     abx            ; add 3 to point at next vector
  801.     cpx    #jclm+3        ; done?
  802.     bne    vecloop        ; if not, continue loop
  803.     rts
  804. ;*
  805. stopit:    ldaa    #0x50        ; stop-enable; irq, xirq-off
  806.     tap
  807.     stop            ; you are lost!    shut down
  808.     jmp    stopit        ; in case continue by xirq
  809.  
  810. ;**********
  811. ;*
  812. ;*    i/o module
  813. ;*    communications with the outside world.
  814. ;* 3 i/o routines (init, input, and output) call
  815. ;* drivers specified by iodev (0=sci, 1=acia,
  816. ;* 2=duarta, 3=duartb).
  817. ;*
  818. ;**********
  819. ;*    init() - initialize device specified by iodev.
  820. ;*********
  821. ;*
  822. init    = .
  823.     psha            ; save registers
  824.     pshx
  825.     ldaa    *iodev
  826.     cmpa    #0x00
  827.     bne    init1        ; jump not sci
  828.     jsr    onsci        ; initialize sci
  829.     bra    init4
  830. init1:    cmpa    #0x01
  831.     bne    init2        ; jump not acia
  832.     jsr    onacia        ; initialize acia
  833.     bra    init4
  834. init2:    ldx    #porta
  835.     cmpa    #0x02
  836.     beq    init3        ; jump duart a
  837.     ldx    #portb
  838. init3:    jsr    onuart        ; initialize duart
  839. init4:    pulx            ; restore registers
  840.     pula
  841.     rts
  842.  
  843. ;**********
  844. ;*    input() - read device. returns a=char or 0.
  845. ;*    this routine also disarms the cop.
  846. ;**********
  847. input    = .
  848.     pshx
  849.     ldaa    #0x55        ; reset cop
  850.     staa    coprst
  851.     ldaa    #0xaa
  852.     staa    coprst
  853.     ldaa    *iodev
  854.     bne    input1        ; jump not sci
  855.     jsr    insci        ; read sci
  856.     bra    input4
  857. input1:    cmpa    #0x01
  858.     bne    input2        ; jump not acia
  859.     jsr    inacia        ; read acia
  860.     bra    input4
  861. input2:    ldx    #porta
  862.     cmpa    #0x02
  863.     beq    input3        ; jump if duart a
  864.     ldx    #portb
  865. input3:    jsr    inuart        ; read uart
  866. input4:    pulx
  867.     rts
  868.  
  869. ;**********
  870. ;*    output() - output character in a.
  871. ;**********
  872.  
  873. output    = .
  874.     psha            ; save registers
  875.     pshb
  876.     pshx
  877.     ldab    *iodev
  878.     bne    output1        ; jump not sci
  879.     jsr    outsci        ; write sci
  880.     bra    output4
  881. output1:
  882.     cmpb    #0x01
  883.     bne    output4        ; jump not acia
  884.     jsr    outacia        ; write acia
  885.     bra    output4
  886. output2:
  887.     ldx    #porta
  888.     cmpb    #0x02
  889.     beq    output3        ; jump if duart a
  890.     ldx    #portb
  891. output3:
  892.     jsr    outuart        ; write uart
  893. output4:
  894.     pulx
  895.     pulb
  896.     pula
  897.     rts
  898.  
  899. ;**********
  900. ;*    onuart(port) - initialize a duart port.
  901. ;* sets duart to internal clock, divide by 16,
  902. ;* 8 data + 1 stop bits.
  903. ;**********
  904.  
  905. onuart:    ldaa    #0x22
  906.     staa    2,x        ; reset receiver
  907.     ldaa    #0x38
  908.     staa    2,x        ; reset transmitter
  909.     ldaa    #0x40
  910.     staa    2,x        ; reset error status
  911.     ldaa    #0x10
  912.     staa    2,x        ; reset pointer
  913.     ldaa    #0x00
  914.     staa    duart+4        ; clock source
  915.     ldaa    #0x00
  916.     staa    duart+5        ; interrupt mask
  917.     ldaa    #0x13
  918.     staa    0,x        ; 8 data, no parity
  919.     ldaa    #0x07
  920.     staa    0,x        ; 1 stop bits
  921.     ldaa    #0xbb        ; baud rate (9600)
  922.     staa    1,x        ; tx and rcv baud rate
  923.     ldaa    #0x05
  924.     staa    2,x        ; enable tx and rcv
  925.     rts
  926.  
  927. ;**********
  928. ;*    inuart(port) - check duart for any input.
  929. ;**********
  930.  
  931. inuart:    ldaa    1,x        ; read status
  932.     anda    #0x01        ; check rdrf
  933.     beq    inuart1        ; jump if no data
  934.     ldaa    3,x        ; read data
  935.     anda    #0x7f        ; to mask parity
  936. inuart1:
  937.     rts
  938.  
  939. ;**********
  940. ;*    outuart(port) - output the character in a.
  941. ;*    if autolf=1, transmits cr or lf as crlf.
  942. ;**********
  943. outuart:
  944.     tst    *autolf
  945.     beq    outuart2    ; jump if no autolf
  946.     bsr    outuart2
  947.     cmpa    #0x0d
  948.     bne    outuart1
  949.     ldaa    #0x0a        ; if cr, output lf
  950.     bra    outuart2
  951. outuart1:
  952.     cmpa    #0x0a
  953.     bne    outuart3
  954.     ldaa    #0x0d        ; if lf, output cr
  955. outuart2:
  956.      ldab    1,x        ; check status
  957.     andb    #0x4
  958.     beq    outuart2    ; loop until tdre=1
  959.     anda    #0x7f        ; mask parity
  960.     staa    3,x        ; send character
  961. outuart3:
  962.     rts
  963.  
  964. ;**********
  965. ;*    onsci() - initialize the sci for 9600
  966. ;*            baud at 8 mhz extal.
  967. ;**********
  968. onsci:    ldaa    #0x30
  969.     staa    baud        ; baud register
  970.     ldaa    #0x00
  971.     staa    sccr1
  972.     ldaa    #0x0c
  973.     staa    sccr2        ; enable
  974.     rts
  975.  
  976. ;**********
  977. ;*    insci() - read from sci.    return a=char or 0.
  978. ;**********
  979. insci:    ldaa    scsr        ; read status reg
  980.     anda    #0x20
  981.     beq    insci1        ; jump if rdrf=0
  982.     ldaa    scdat        ; read data register
  983.     anda    #0x7f        ; mask parity
  984. insci1:    rts
  985.  
  986. ;**********
  987. ;*    outsci() - output a to sci. if autolf = 1,
  988. ;*        cr and lf sent as crlf.
  989. ;**********
  990. outsci:    tst    *autolf
  991.     beq    outsci2        ; jump if autolf=0
  992.     bsr    outsci2
  993.     cmpa    #0x0d
  994.     bne    outsci1
  995.     ldaa    #0x0a        ; if cr, send lf
  996.     bra    outsci2
  997. outsci1:
  998.     cmpa    #0x0a
  999.     bne    outsci3
  1000.     ldaa    #0x0d        ; if lf, send cr
  1001. outsci2:
  1002.     ldab    scsr        ; read status
  1003.     bitb    #0x80
  1004.     beq    outsci2        ; loop until tdre=1
  1005.     anda    #0x7f        ; mask parity
  1006.     staa    scdat        ; send character
  1007. outsci3:
  1008.     rts
  1009.  
  1010. ;**********
  1011. ;*    onacia - initialize the acia for
  1012. ;* 8 data bits, 1 stop bit, divide by 64 clock.
  1013. ;**********
  1014. onacia:    ldx    #acia
  1015.     ldaa    #0x03
  1016.     staa    0,x        ; master reset
  1017.     ldaa    #0x16
  1018.     staa    0,x        ; setup
  1019.     rts
  1020.  
  1021. ;**********
  1022. ;*    inacia - read from the acia, return a=char or 0.
  1023. ;**********
  1024. inacia:    ldx    #acia
  1025.     ldaa    0,x        ; status
  1026.     psha
  1027.     anda    #0x70        ; check pe, ov, fe
  1028.     pula
  1029.     beq    inacia1        ; jump - no error
  1030.     bsr    onacia        ; reinitialize and try again
  1031.     bra    inacia
  1032. inacia1:
  1033.     lsra            ; check rdrf
  1034.     bcs    inacia2        ; jump if data
  1035.     clra            ; return(no data)
  1036.     rts
  1037. inacia2:
  1038.     ldaa    1,x        ; read data
  1039.     anda    #0x7f        ; mask parity
  1040.     rts
  1041.  
  1042. ;**********
  1043. ;*    outacia - output a to acia. if autolf = 1,
  1044. ;*        cr or lf sent as crlf.
  1045. ;**********
  1046. outacia:
  1047.     bsr    outacia3    ; output char
  1048.     tst    *autolf
  1049.     beq    outacia2    ; jump no autolf
  1050.     cmpa    #0x0d
  1051.     bne    outacia1
  1052.     ldaa    #0x0a
  1053.     bsr    outacia3    ; if cr, output lf
  1054.     bra    outacia2
  1055. outacia1:
  1056.     cmpa    #0x0a
  1057.     bne    outacia2
  1058.     ldaa    #0x0d
  1059.     bsr    outacia3    ; if lf, output cr
  1060. outacia2:
  1061.     rts
  1062.  
  1063. outacia3:
  1064.     ldx    #acia
  1065.     ldab    0,x
  1066.     bitb    #0x2
  1067.     beq    outacia3    ; loop until tdre
  1068.     anda    #0x7f        ; mask parity
  1069.     staa    1,x        ; output
  1070.     rts
  1071. ;*
  1072. ;*    space for modifying outacia routine
  1073. ;*
  1074.     .word    0xffff,0xffff,0xffff,0xffff
  1075. ;*******************************
  1076. ;*** i/o utility subroutines ***
  1077. ;***these subroutines perform the neccesary
  1078. ;* data i/o operations.
  1079. ;* outlhlf-convert left 4 bits of a from binary
  1080. ;*        to ascii and output.
  1081. ;* outrhlf-convert right 4 bits of a from binary
  1082. ;*        to ascii and output.
  1083. ;* out1byt-convert byte addresed by x from binary
  1084. ;*        to ascii and output.
  1085. ;* out1bsp-convert byte addressed by x from binary
  1086. ;*        to ascii and output followed by a space.
  1087. ;* out2bsp-convert 2 bytes addressed by x from binary
  1088. ;*        to ascii and  output followed by a space.
  1089. ;* outspac-output a space.
  1090. ;*
  1091. ;* outcrlf-output a line feed and carriage return.
  1092. ;*
  1093. ;* outstrg-output the string of ascii bytes addressed
  1094. ;*        by x until 0x04.
  1095. ;* outa-output the ascii character in a.
  1096. ;*
  1097. ;* inchar-input to a and echo one character.  loops
  1098. ;*        until character read.
  1099. ;********************
  1100.  
  1101. ;**********
  1102. ;*    outrhlf(), outlhlf(), outa()
  1103. ;*convert a from binary to ascii and output.
  1104. ;*contents of a are destroyed..
  1105. ;**********
  1106. outlhlf:
  1107.     lsra            ; shift data to right
  1108.     lsra
  1109.     lsra
  1110.     lsra
  1111. outrhlf:
  1112.     anda    #0x0f        ; mask top half
  1113.     adda    #0x30        ; convert to ascii
  1114.     cmpa    #0x39
  1115.     ble    outa        ; jump if 0-9
  1116.     adda    #0x07        ; convert to hex a-f
  1117. outa:    jsr    output        ; output character
  1118.     rts
  1119.  
  1120. ;**********
  1121. ;*    out1byt(x) - convert the byte at x to two
  1122. ;* ascii characters and output. return x pointing
  1123. ;* to next byte.
  1124. ;**********
  1125. out1byt:
  1126.     psha
  1127.     ldaa    0,x        ; get data in a
  1128.     psha            ; save copy
  1129.     bsr    outlhlf        ; output left half
  1130.     pula            ; retrieve copy
  1131.     bsr    outrhlf        ; output right half
  1132.     pula
  1133.     inx
  1134.     rts
  1135.  
  1136. ;**********
  1137. ;*    out1bsp(x), out2bsp(x) - output 1 or 2 bytes
  1138. ;* at x followed by a space.  returns x pointing to
  1139. ;* next byte.
  1140. ;**********
  1141. out2bsp:
  1142.     jsr    out1byt        ; do first byte
  1143. out1bsp:
  1144.     jsr    out1byt        ; do next byte
  1145. outspac:
  1146.     ldaa    #0x20        ; output a space
  1147.     jsr    output
  1148.     rts
  1149.  
  1150. ;**********
  1151. ;*    outcrlf() - output a carriage return and
  1152. ;* a line feed.    returns a = cr.
  1153. ;**********
  1154. outcrlf:
  1155.     ldaa    #0x0d        ; cr
  1156.     jsr    output        ; output a
  1157.     ldaa    #0x00
  1158.     jsr    output        ; output padding
  1159.     ldaa    #0x0d
  1160.     rts
  1161.  
  1162. ;**********
  1163. ;*    outstrg(x) - output string of ascii bytes
  1164. ;* starting at x until end of text (0x04).    can
  1165. ;* be paused by control w (any char restarts).
  1166. ;**********
  1167. outstrg:
  1168.     jsr    outcrlf
  1169. outstrg0:
  1170.     psha
  1171. outstrg1:
  1172.     ldaa    0,x        ; read char into a
  1173.     cmpa    #eot
  1174.     beq    outstrg3    ; jump if eot
  1175.     jsr    output        ; output character
  1176.     inx
  1177.     jsr    input
  1178.     beq    outstrg1    ; jump if no input
  1179.     cmpa    #ctlw
  1180.     bne    outstrg1    ; jump if not cntlw
  1181. outstrg2:
  1182.     jsr    input
  1183.     beq    outstrg2    ; jump if any input
  1184.     bra    outstrg1
  1185. outstrg3:
  1186.     pula
  1187.     rts
  1188.  
  1189. ;**********
  1190. ;*    inchar() - reads input until character sent.
  1191. ;*    echoes char and returns with a = char.
  1192. inchar:    jsr    input
  1193.     tsta
  1194.     beq    inchar        ; jump if no input
  1195.     jsr    output        ; echo
  1196.     rts
  1197.  
  1198. ;*********************
  1199. ;*** command table ***
  1200. comtabl    = .
  1201.     .byte    5
  1202.     .ascii    'ASSEM'
  1203.     .word    #assem
  1204.     .byte    5
  1205.     .ascii    'BREAK'
  1206.     .word    #break
  1207.     .byte    4
  1208.     .ascii    'BULK'
  1209.     .word    #bulk
  1210.     .byte    7
  1211.     .ascii    'BULKALL'
  1212.     .word    #bulkall
  1213.     .byte    4
  1214.     .ascii    'CALL'
  1215.     .word    #call
  1216.     .byte    4
  1217.     .ascii    'DUMP'
  1218.     .word    #dump
  1219.     .byte    4
  1220.     .ascii    'FILL'
  1221.     .word    #fill
  1222.     .byte    2
  1223.     .ascii    'GO'
  1224.     .word    #go
  1225.     .byte    4
  1226.     .ascii    'HELP'
  1227.     .word    #help
  1228.     .byte    4
  1229.     .ascii    'HOST'
  1230.     .word    #host
  1231.     .byte    4
  1232.     .ascii    'LOAD'
  1233.     .word    #load
  1234.     .byte    6         ; length of command
  1235.     .ascii    'MEMORY'    ; ascii command
  1236.     .word    #memory        ; command address
  1237.     .byte    4
  1238.     .ascii    'MOVE'
  1239.     .word    #move
  1240.     .byte    7
  1241.     .ascii    'PROCEED'
  1242.     .word    #proceed
  1243.     .byte    8
  1244.     .ascii    'REGISTER'
  1245.     .word    #register
  1246.     .byte    5
  1247.     .ascii    'TRACE'
  1248.     .word    #trace
  1249.     .byte    6
  1250.     .ascii    'VERIFY'
  1251.     .word    #verify
  1252.     .byte    1
  1253.     .ascii    '?'        ; initial command
  1254.     .word    #help
  1255.     .byte    5
  1256.     .ascii    'XBOOT'
  1257.     .word    #boot
  1258. ;*
  1259. ;*** command names for evm compatability ***
  1260. ;*
  1261.     .byte    3
  1262.     .ascii    'ASM'
  1263.     .word    #assem
  1264.     .byte    2
  1265.     .ascii    'BF'
  1266.     .word    #fill
  1267.     .byte    4
  1268.     .ascii    'COPY'
  1269.     .word    #move
  1270.     .byte    5
  1271.     .ascii    'ERASE'
  1272.     .word    #bulk
  1273.     .byte    2
  1274.     .ascii    'MD'
  1275.     .word    #dump
  1276.     .byte    2
  1277.     .ascii    'MM'
  1278.     .word    #memory
  1279.     .byte    2
  1280.     .ascii    'RD'
  1281.     .word    #register
  1282.     .byte    2
  1283.     .ascii    'RM'
  1284.     .word    #register
  1285.     .byte    4
  1286.     .ascii    'READ'
  1287.     .word    #move
  1288.     .byte    2
  1289.     .ascii    'TM'
  1290.     .word    #host
  1291.     .byte    4
  1292.     .ascii    'TEST'
  1293.     .word    #evbtest
  1294.     .byte    -1
  1295.  
  1296. ;*******************
  1297. ;*** text tables ***
  1298.  
  1299. msg1:    .ascii    'BUFFALO 2.5 (ext) - '
  1300.     .ascii    'Bit User Fast Friendly Aid to Logical Operation'
  1301.     .byte    eot
  1302. msg2:    .ascii    'What?'
  1303.     .byte    eot
  1304. msg3:    .ascii    'Too Long'
  1305.     .byte    eot
  1306. msg4:    .ascii    'Full'
  1307.     .byte    eot
  1308. msg5:    .ascii    'Op- '
  1309.     .byte    eot
  1310. msg6:    .ascii    'rom-'
  1311.     .byte    eot
  1312. msg8:    .ascii    'Command?'
  1313.     .byte    eot
  1314. msg9:    .ascii    'Bad argument'
  1315.     .byte    eot
  1316. msg10:    .ascii    'No host port available'
  1317.     .byte    eot
  1318. msg11:    .ascii    'done'
  1319.     .byte    eot
  1320. msg12:    .ascii    'checksum error'
  1321.     .byte    eot
  1322. msg13:    .ascii    'error addr '
  1323.     .byte    eot
  1324.  
  1325. ;**********
  1326. ;*    break [-][<addr>] . . .
  1327. ;* modifies the breakpoint table.  more than
  1328. ;* one argument can be entered on the command
  1329. ;* line but the table will hold only 4 entries.
  1330. ;* 4 types of arguments are implied above:
  1331. ;* break         prints table contents.
  1332. ;* break <addr>        inserts <addr>.
  1333. ;* break -<addr>    deletes <addr>.
  1334. ;* break -        clears all entries.
  1335. ;**********
  1336. ;* while 1
  1337. ;*    a = wskip();
  1338. ;*    switch(a)
  1339. ;*        case(cr):
  1340. ;*        bprint(); return;
  1341.  
  1342. break:    jsr    wskip
  1343.     cmpa    #0x0d
  1344.     bne    brkdel        ; jump if not cr
  1345.     jsr    bprint        ; print table
  1346.     rts
  1347.  
  1348. ;*        case("-"):
  1349. ;*        incbuff(); readbuff();
  1350. ;*        if(dchek(a))        /* look for wspac or cr */
  1351. ;*            bpclr();
  1352. ;*            breaksw;
  1353. ;*        a = buffarg();
  1354. ;*        if( !dchek(a) ) return(bad argument);
  1355. ;*        b = bpsrch();
  1356. ;*        if(b >= 0)
  1357. ;*            brktabl[b] = 0;
  1358. ;*        breaksw;
  1359.  
  1360. brkdel:    cmpa    #'-
  1361.     bne    brkdef        ; jump if not -
  1362.     jsr    incbuff
  1363.     jsr    readbuff
  1364.     jsr    dchek
  1365.     bne    brkdel1        ; jump if not delimeter
  1366.     jsr    bpclr        ; clear table
  1367.     jmp    break        ; do next argument
  1368. brkdel1:
  1369.     jsr    buffarg        ; get address to delete
  1370.     jsr    dchek
  1371.     beq    brkdel2        ; jump if delimeter
  1372.     ldx    #msg9        ; "bad argument"
  1373.     jsr    outstrg
  1374.     rts
  1375. brkdel2:
  1376.     jsr    bpsrch        ; look for addr in table
  1377.     tstb
  1378.     bmi    brkdel3        ; jump if not found
  1379.     ldx    #brktabl
  1380.     abx
  1381.     clr    0,x        ; clear entry
  1382.     clr    1,x
  1383. brkdel3:
  1384.     jmp    break        ; do next argument
  1385.  
  1386. ;*        default:
  1387. ;*        a = buffarg();
  1388. ;*        if( !dchek(a) ) return(bad argument);
  1389. ;*        b = bpsrch();
  1390. ;*        if(b < 0)        /* not already in table */
  1391. ;*            x = shftreg;
  1392. ;*            shftreg = 0;
  1393. ;*            a = x[0]; x[0] = 0x3f
  1394. ;*            b = x[0]; x[0] = a;
  1395. ;*            if(b != 0x3f) return(rom);
  1396. ;*            b = bpsrch();    /* look for hole */
  1397. ;*            if(b >= 0) return(table full);
  1398. ;*            brktabl[b] = x;
  1399. ;*        breaksw;
  1400.  
  1401. brkdef:    jsr    buffarg        ; get argument
  1402.     jsr    dchek
  1403.     beq    brkdef1        ; jump if delimiter
  1404.     ldx    #msg9        ; "bad argument"
  1405.     jsr    outstrg
  1406.     rts
  1407. brkdef1:
  1408.     jsr    bpsrch        ; look for entry in table
  1409.     tstb
  1410.     bge    break        ; jump if already in table
  1411.     ldx    *shftreg    ; x = new entry
  1412.     ldaa    0,x
  1413.     ldab    #swi
  1414.     stab    0,x
  1415.     ldab    0,x
  1416.     staa    0,x
  1417.     cmpb    #swi
  1418.     beq    brkdef2        ; jump if writes ok
  1419.     stx    *ptr1        ; save address
  1420.     ldx    #msg6        ; "rom-"
  1421.     jsr    outstrg
  1422.     ldx    #ptr1
  1423.     jsr    out2bsp        ; print address
  1424.     jsr    bprint
  1425.     rts
  1426. brkdef2:
  1427.     clr    *shftreg
  1428.     clr    *shftreg+1
  1429.     pshx
  1430.     jsr    bpsrch        ; look for 0 entry
  1431.     pulx
  1432.     tstb
  1433.     bpl    brkdef3        ; jump if table not full
  1434.     ldx    #msg4        ; "full"
  1435.     jsr    outstrg
  1436.     jsr    bprint
  1437.     rts
  1438. brkdef3:
  1439.  
  1440.     ldy    #brktabl
  1441.     aby
  1442.     stx    0,y        ; put new entry in
  1443.     jmp    break        ; do next argument
  1444.  
  1445. ;**********
  1446. ;*    bprint() - print the contents of the table.
  1447. ;**********
  1448. bprint:    jsr    outcrlf
  1449.     ldx    #brktabl
  1450.     ldab    #4
  1451. bprint1:
  1452.     jsr    out2bsp
  1453.     decb
  1454.     bgt    bprint1        ; loop 4 times
  1455.     rts
  1456.  
  1457. ;**********
  1458. ;*    bpsrch() - search table for address in
  1459. ;* shftreg. returns b = index to entry or
  1460. ;* b = -1 if not found.
  1461. ;**********
  1462. ;*for(b=0; b=6; b=+2)
  1463. ;*    x[] = brktabl + b;
  1464. ;*    if(x[0] = shftreg)
  1465. ;*        return(b);
  1466. ;*return(-1);
  1467.  
  1468. bpsrch:    clrb
  1469. bpsrch1:
  1470.     ldx    #brktabl
  1471.     abx
  1472.     ldx    0,x        ; get table entry
  1473.     cpx    *shftreg
  1474.     bne    bpsrch2        ; jump if no match
  1475.     rts
  1476. bpsrch2:
  1477.     incb
  1478.     incb
  1479.     cmpb    #0x6
  1480.     ble    bpsrch1        ; loop 4 times
  1481.     ldab    #0xff
  1482.     rts
  1483.  
  1484.  
  1485. ;**********
  1486. ;*    bulk - bulk erase the eeprom except the
  1487. ;* config register.
  1488. ;**********
  1489. bulk:
  1490.     clr    *tmp2
  1491.     bra    bulk1
  1492.  
  1493. ;**********
  1494. ;*    bulkall - bulk erase the eeprom and the
  1495. ;* config register.
  1496. ;**********
  1497. bulkall:
  1498.     clr    *tmp2
  1499.     inc    *tmp2
  1500.  
  1501. ;*set up pprog register for erase
  1502. bulk1:    psha
  1503.     ldaa    #0x06
  1504.     staa    pprog        ; set eelat, erase bits
  1505.  
  1506. ;*if (ee only) write to 0xb600
  1507. ;*else write to config register
  1508.     ldaa    #0xff
  1509.     tst    *tmp2
  1510.     bne    bulk2        ; jump if config
  1511.     staa    0xb600        ; write to 0xb600
  1512.     bra    bulk3
  1513. bulk2:    staa    config
  1514. bulk3    = .
  1515.  
  1516. ;*start erasing
  1517.     ldaa    #0x07
  1518.     bne    acl3
  1519.     clra            ; fail safe
  1520. acl3:    staa    pprog
  1521.  
  1522. ;*delay for 10 ms at E = 2 mhz
  1523.     pshx
  1524.     ldx    #0x0d06        ; 6~ * 3334 = 20,004 * 0.5 mhz
  1525. bulkdly:
  1526.     dex            ; 2~
  1527.     bne    bulkdly        ; 3~
  1528.     pulx
  1529.  
  1530. ;*stop programming
  1531.     clr    pprog
  1532.     pula
  1533.     rts
  1534.  
  1535. ;**********
  1536. ;*    dump [<addr1> [<addr2>]]  - dump memory
  1537. ;* in 16 byte lines from <addr1> to <addr2>.
  1538. ;*    default starting address is "current
  1539. ;* location" and default number of lines is 8.
  1540. ;**********
  1541. ;*ptr1 = ptrmem;    /* default start address */
  1542. ;*ptr2 = ptr1 + 0x80;    /* default end address */
  1543. ;*a = wskip();
  1544. ;*if(a != cr)
  1545. ;*    a = buffarg();
  1546. ;*    if(countu1 = 0) return(bad argument);
  1547. ;*    if( !dchek(a) ) return(bad argument);
  1548. ;*    ptr1 = shftreg;
  1549. ;*    ptr2 = ptr1 + 0x80;    /* default end address */
  1550. ;*    a = wskip();
  1551. ;*    if(a != cr)
  1552. ;*        a = buffarg();
  1553. ;*        if(countu1 = 0) return(bad argument);
  1554. ;*        a = wskip();
  1555. ;*        if(a != cr) return(bad argument);
  1556. ;*        ptr2 = shftreg;
  1557.  
  1558. dump:    ldx    *ptrmem        ; current location
  1559.     stx    *ptr1        ; default start
  1560.     ldab    #0x80
  1561.     abx
  1562.     stx    *ptr2        ; default end
  1563.     jsr    wskip
  1564.     cmpa    #0xd
  1565.     beq    dump1        ; jump - no arguments
  1566.     jsr    buffarg        ; read argument
  1567.     tst    *count
  1568.     beq    dumperr        ; jump if no argument
  1569.     jsr    dchek
  1570.     bne    dumperr        ; jump if delimiter
  1571.     ldx    *shftreg
  1572.     stx    *ptr1
  1573.     ldab    #0x80
  1574.     abx
  1575.     stx    *ptr2        ; default end address
  1576.     jsr    wskip
  1577.     cmpa    #0xd
  1578.     beq    dump1        ; jump - 1 argument
  1579.     jsr    buffarg        ; read argument
  1580.     tst    *count
  1581.     beq    dumperr        ; jump if no argument
  1582.     jsr    wskip
  1583.     cmpa    #0x0d
  1584.     bne    dumperr        ; jump if not cr
  1585.     ldx    *shftreg
  1586.     stx    *ptr2
  1587.     bra    dump1        ; jump - 2 arguments
  1588. dumperr:
  1589.     ldx    #msg9        ; "bad argument"
  1590.     jsr    outstrg
  1591.     rts
  1592.  
  1593. ;*ptrmem = ptr1;
  1594. ;*ptr1 = ptr1 & 0xfff0;
  1595.  
  1596. dump1:    ldd    *ptr1
  1597.     std    *ptrmem        ; new current location
  1598.     andb    #0xf0
  1599.     std    *ptr1        ; start dump at 16 byte boundary
  1600.  
  1601. ;*** dump loop starts here ***
  1602. ;*do:
  1603. ;*    output address of first byte;
  1604.  
  1605. dumplp:    jsr    outcrlf
  1606.     ldx    #ptr1
  1607.     jsr    out2bsp        ; first address
  1608.  
  1609. ;*    x = ptr1;
  1610. ;*    for(b=0; b=16; b++)
  1611. ;*        output contents;
  1612.  
  1613.     ldx    *ptr1        ; base address
  1614.     clrb            ; loop counter
  1615. dumpdat:
  1616.     jsr    out1bsp        ; hex value loop
  1617.     incb
  1618.     cmpb    #0x10
  1619.     blt    dumpdat        ; loop 16 times
  1620.  
  1621. ;*    x = ptr1;
  1622. ;*    for(b=0; b=16; b++)
  1623. ;*        a = x[b];
  1624. ;*        if(0x7a < a < 0x20)  a = 0x20;
  1625. ;*        output ascii contents;
  1626.  
  1627.     clrb            ; loop counter
  1628. dumpasc:
  1629.     ldx    *ptr1        ; base address
  1630.     abx
  1631.     ldaa    ,x        ; ascii value loop
  1632.     cmpa    #0x20
  1633.     blo    dump3        ; jump if non printable
  1634.     cmpa    #0x7a
  1635.     bls    dump4        ; jump if printable
  1636. dump3:    ldaa    #0x20        ; space for non printables
  1637. dump4:    jsr    output        ; output ascii value
  1638.     incb
  1639.     cmpb    #0x10
  1640.     blt    dumpasc        ; loop 16 times
  1641.  
  1642. ;*    chkabrt();
  1643. ;*    ptr1 = ptr1 + 0x10;
  1644. ;*while(ptr1 <= ptr2);
  1645. ;*return;
  1646.  
  1647.     jsr    chkabrt        ; check abort or wait
  1648.     ldd    *ptr1
  1649.     addd    #0x10        ; point to next 16 byte bound
  1650.     std    *ptr1        ; update ptr1
  1651.     cpd    *ptr2
  1652.     bhi    dump5        ; quit if ptr1 > ptr2
  1653.     cpd    #0x00        ; check wraparound at 0xffff
  1654.     bne    dumplp        ; jump - no wraparound
  1655.     ldd    *ptr2
  1656.     cpd    #0xfff0
  1657.     blo    dumplp        ; upper bound not at top
  1658. dump5:    rts            ; quit
  1659.  
  1660. ;**********
  1661. ;*    fill <addr1> <addr2> [<data>]  - block fill
  1662. ;*memory from addr1 to addr2 with data.    data
  1663. ;*defaults to 0xff.
  1664. ;**********
  1665. ;*get addr1 and addr2
  1666.  
  1667. fill    = .
  1668.     jsr    wskip
  1669.     jsr    buffarg
  1670.     tst    *count
  1671.     beq    fillerr        ; jump if no argument
  1672.     jsr    wchek
  1673.     bne    fillerr        ; jump if bad argument
  1674.     ldx    *shftreg
  1675.     stx    *ptr1        ; address1
  1676.     jsr    wskip
  1677.     jsr    buffarg
  1678.     tst    *count
  1679.     beq    fillerr        ; jump if no argument
  1680.     jsr    dchek
  1681.     bne    fillerr        ; jump if bad argument
  1682.     ldx    *shftreg
  1683.     stx    *ptr2        ; address2
  1684.  
  1685. ;*get data if it exists
  1686.     ldaa    #0xff
  1687.     staa    *tmp2        ; default data
  1688.     jsr    wskip
  1689.     cmpa    #0x0d
  1690.     beq    fill1        ; jump if default data
  1691.     jsr    buffarg
  1692.     tst    *count
  1693.     beq    fillerr        ; jump if no argument
  1694.     jsr    wskip
  1695.     cmpa    #0x0d
  1696.     bne    fillerr        ; jump if bad argument
  1697.     ldaa    *shftreg+1
  1698.     staa    *tmp2
  1699.  
  1700. ;*while(ptr1 <= ptr2)
  1701. ;*    *ptr1 = data
  1702. ;*    if(*ptr1 != data) abort
  1703.  
  1704. fill1    = .
  1705.     jsr    chkabrt        ; check for abort
  1706.     ldx    *ptr1        ; starting address
  1707.     ldaa    *tmp2        ; data
  1708.     staa    0,x
  1709.     cmpa    0,x
  1710.     bne    fillbad        ; jump if no write
  1711.     cpx    *ptr2
  1712.     beq    fill2        ; quit yet?
  1713.     inx
  1714.     stx    *ptr1
  1715.     bra    fill1        ; loop
  1716. fill2:    rts
  1717.  
  1718. fillerr:
  1719.     ldx    #msg9        ; "bad argument"
  1720.     jsr    outstrg
  1721.     rts
  1722.  
  1723. fillbad:
  1724.     ldx    #msg6        ; "rom -"
  1725.     jsr    outstrg
  1726.     ldx    #ptr1
  1727.     jsr    out2bsp
  1728.     rts
  1729.  
  1730. ;**********
  1731. ;*    call [<addr>] - execute a jsr to addr or
  1732. ;*user's pc value.  return to monitor by rts
  1733. ;*or breakpoint.
  1734. ;**********
  1735. ;*a = wskip();
  1736. ;*if(a != cr)
  1737. ;*    a = buffarg();
  1738. ;*    a = wskip();
  1739. ;*    if(a != cr) return(bad argument)
  1740. ;*    pc = shftreg;
  1741.  
  1742. call:    jsr    wskip
  1743.     cmpa    #0xd
  1744.     beq    call3        ; jump if no arg
  1745.     jsr    buffarg
  1746.     jsr    wskip
  1747.     cmpa    #0xd
  1748.     beq    call2        ; jump if cr
  1749.     ldx    #msg9        ; "bad argument"
  1750.     jsr    outstrg
  1751.     rts
  1752. call2:    ldx    *shftreg
  1753.     stx    *regs        ; pc = <addr>
  1754.  
  1755. ;*user_stack[0] = return_to_monitor;
  1756. ;*setbps();
  1757. ;*restack();    /* restack and go*/
  1758.  
  1759. call3:    ldx    *sp
  1760.     dex            ; user stack pointer
  1761.     ldd    #return        ; return address
  1762.     std    0,x
  1763.     dex
  1764.     stx    *sp        ; new user stack pointer
  1765.     jsr    setbps
  1766.     clr    *tmp2        ; flag for breakpoints
  1767.     jmp    restack        ; executes an rti
  1768.  
  1769. ;**********
  1770. ;*    return() - return here from rts after
  1771. ;*call command.
  1772. ;**********
  1773. return:    psha            ; save a register
  1774.     tpa
  1775.     staa    *regs+8        ; cc register
  1776.     pula
  1777.     std    *regs+6        ; a and b registers
  1778.     stx    *regs+4        ; x register
  1779.     sty    *regs+2        ; y register
  1780.     sts    *sp        ; user stack pointer
  1781.     lds    #stack        ; monitor stack pointer
  1782.     jsr    rembps        ; remove breakpoints
  1783.     jsr    outcrlf
  1784.     jsr    rprint        ; print user registers
  1785.     jmp    main
  1786.  
  1787. ;**********
  1788. ;*    go [<addr>] - execute starting at <addr> or
  1789. ;*user's pc value.  executes an rti to user code.
  1790. ;*returns to monitor via an swi through swiin.
  1791. ;**********
  1792. ;*a = wskip();
  1793. ;*if(a != cr)
  1794. ;*    a = buffarg();
  1795. ;*    a = wskip();
  1796. ;*    if(a != cr) return(bad argument)
  1797. ;*    pc = shftreg;
  1798. ;*setbps();
  1799. ;*restack();    /* restack and go*/
  1800.  
  1801. go:    jsr    wskip
  1802.     cmpa    #0x0d
  1803.     beq    go2        ; jump if no arg
  1804.     jsr    buffarg
  1805.     jsr    wskip
  1806.     cmpa    #0x0d
  1807.     beq    go1        ; jump if cr
  1808.     ldx    #msg9        ; "bad argument"
  1809.     jsr    outstrg
  1810.     rts
  1811. go1:    ldx    *shftreg
  1812.     stx    *regs        ; pc = <addr>
  1813. go2:    clr    *tmp2        ; flag for breakpoints
  1814.     inc    *tmp2        ; (1=go, 0=call)
  1815.     jsr    setbps
  1816.     jmp    restack        ; execute an rti
  1817.  
  1818. ;**********
  1819. ;*    swiin() - return from swi.    set up
  1820. ;*stack pointers, save user registers, and
  1821. ;*return to main.
  1822. ;**********
  1823. swiin:    tsx            ; swi entry point
  1824.     lds    #stack
  1825.     jsr    savstack    ; save user regs
  1826.     ldx    *regs
  1827.     dex
  1828.     stx    *regs        ; save user pc
  1829.     ldx    *ptr4        ; restore user swi vector
  1830.     stx    *jswi+1
  1831.  
  1832. ;*if(flagt1 = 0) remove return addr from stack;
  1833.  
  1834.     tst    *tmp2        ; 0=call, 1=go
  1835.     bne    go3        ; jump if go command
  1836.     ldx    *sp        ; remove return address
  1837.     inx
  1838.     inx
  1839.     stx    *sp
  1840. go3:    jsr    outcrlf        ; print register values
  1841.     jsr    rprint
  1842.     jsr    rembps
  1843.     jmp    main        ; return to monitor
  1844. ;*                ; (sp destroyed above)
  1845.  
  1846. ;**********
  1847. ;*    proceed - same as go except it ignores
  1848. ;*a breakpoint at the first opcode.  calls
  1849. ;*trace once and the go.
  1850. ;**********
  1851. proceed:
  1852.     clr    *tmp2        ; flag for breakpoints
  1853.     inc    *tmp2        ; 0=trace, 1=proceed
  1854.     jmp    trace3
  1855.  
  1856. ;**********
  1857. ;*    trace <n> - trace n instructions starting
  1858. ;*at user's pc value. n is a hex number less than
  1859. ;*0xff (defaults to 1).
  1860. ;**********
  1861. ;*countt1 = 1
  1862. ;*a = wskip();
  1863. ;*if(a != cr)
  1864. ;*    a = buffarg(); a = wskip();
  1865. ;*    if(a != cr) return(bad argument);
  1866. ;*    countt1 = n
  1867.  
  1868. trace:    clr    *tmp4
  1869.     inc    *tmp4        ; default countt1 = 1
  1870.     clr    *tmp2        ; 0 = trace
  1871.     jsr    wskip
  1872.     cmpa    #0x0d
  1873.     beq    trace2        ; jump if cr
  1874.     jsr    buffarg
  1875.     jsr    wskip
  1876.     cmpa    #0x0d
  1877.     beq    trace1        ; jump if cr
  1878.     ldx    #msg9        ; "bad argument"
  1879.     jsr    outstrg
  1880.     rts
  1881. trace1:    ldaa    *shftreg+1    ; n
  1882.     staa    *tmp4
  1883.  
  1884. ;*print opcode
  1885. trace2:    jsr    outcrlf
  1886.     ldx    #msg5        ; "op-"
  1887.     jsr    outstrg
  1888.     ldx    *regs
  1889.     jsr    out1bsp        ; opcode
  1890.  
  1891. ;*save user oc5 regs, setup monitor oc5 regs
  1892. trace3:    ldaa    tctl1
  1893.     staa    *ptr2        ; save user mode/level
  1894.     anda    #0xfc
  1895.     staa    tctl1        ; disable oc5 output
  1896.     ldaa    tmsk1
  1897.     staa    *ptr2+1        ; save user int masks
  1898.     clr    tmsk2        ; disable tof and pac ints
  1899.  
  1900. ;*put monitor toc5 vector into jump table
  1901.     ldx    *jtoc5+1
  1902.     stx    *ptr4        ; save user's vector
  1903.     ldaa    #0x7e        ; jmp opcode
  1904.     staa    *jtoc5
  1905.     ldx    #tracein
  1906.     stx    *jtoc5+1    ; monitor toc5 vector
  1907.  
  1908. ;*unmask i bit in user ccr
  1909.     ldaa    *regs+8        ; user ccr
  1910.     anda    #0xef        ; clear i bit
  1911.     staa    *regs+8
  1912.  
  1913. ;*arm oc5 interrupt
  1914.     ldab    #87        ; cycles to end of rti
  1915.     ldx    tcnt        ; timer count value
  1916.     abx            ;             3~ )
  1917.     stx    toc5        ; oc5 match register    5~  )
  1918.     ldaa    #0x08        ;             2~    )
  1919.     staa    tflg1        ; clear oc5 int flag    4~    ) 86~
  1920.     staa    tmsk1        ; enable oc5 interrupt    4~    )
  1921.     cli            ;             2~  )
  1922.     jmp    restack        ; execute an rti     66~ )
  1923.  
  1924. ;**********
  1925. ;*    tracein - return from toc5 interrupt.
  1926. ;**********
  1927. ;*disable toc5 interrupt
  1928. ;*replace user's toc5 vector
  1929. tracein:
  1930.     sei
  1931.     clr    tmsk1        ; disable timer ints
  1932.     tsx
  1933.     lds    #stack
  1934.     jsr    savstack    ; save user regs
  1935.     ldx    *ptr4
  1936.     stx    *jtoc5+1
  1937.     jsr    chkabrt        ; check for abort
  1938.  
  1939. ;*if(flagt1 = 1) jump to go command ( proceed )
  1940.     tst    *tmp2
  1941.     beq    trace9        ; jump if trace command
  1942.     jmp    go2
  1943.  
  1944. ;*rprint();
  1945. ;*while(countt1 >= 0) continue trace;
  1946.  
  1947. trace9:    jsr    outcrlf        ; print registers for
  1948.     jsr    rprint        ; trace only.
  1949.     dec    *tmp4
  1950.     bhi    trace2        ; jump if countt1 >= 0
  1951.     jmp    main        ; return to monitor
  1952. ;*                ; (sp destroyed above)
  1953.  
  1954. ;**********
  1955. ;*    setbps - replace user code with swi's at
  1956. ;*breakpoint addresses.
  1957. ;**********
  1958. ;*for(b=0; b=6; b =+ 2)
  1959. ;*    x = brktabl[b];
  1960. ;*    if(x != 0)
  1961. ;*        optabl[b] = x[0];
  1962. ;*        x[0] = 0x3f;
  1963.  
  1964. setbps:    clrb
  1965. setbps1:
  1966.     ldx    #brktabl
  1967.     ldy    #ptr6
  1968.     abx
  1969.     aby
  1970.     ldx    0,x        ; breakpoint table entry
  1971.     beq    setbps2        ; jump if 0
  1972.     ldaa    0,x        ; save user opcode
  1973.     staa    0,y
  1974.     ldaa    #swi        ; insert swi into code
  1975.     staa    0,x
  1976. setbps2:
  1977.     addb    #0x2
  1978.     cmpb    #0x6
  1979.     ble    setbps1        ; loop 4 times
  1980.  
  1981. ;*put monitor swi vector into jump table
  1982.     ldx    *jswi+1
  1983.     stx    *ptr4        ; save user swi vector
  1984.     ldaa    #0x7e        ; jmp opcode
  1985.     staa    *jswi
  1986.     ldx    #swiin
  1987.     stx    *jswi+1        ; monitor swi vector
  1988.     rts
  1989.  
  1990. ;**********
  1991. ;*    rembps - remove breakpoints from user code.
  1992. ;**********
  1993. ;*for(b=0; b=6; b =+ 2)
  1994. ;*    x = brktabl[b];
  1995. ;*    if(x != 0)
  1996. ;*        x[0] = optabl[b];
  1997.  
  1998. rembps:    clrb
  1999. rembps1:
  2000.     ldx    #brktabl
  2001.     ldy    #ptr6
  2002.     abx
  2003.     aby
  2004.     ldx    0,x        ; breakpoint table entry
  2005.     beq    rembps2        ; jump if 0
  2006.     ldaa    0,y        ; restore user's opcode
  2007.     staa    0,x
  2008. rembps2:
  2009.     addb    #0x2
  2010.     cmpb    #0x6
  2011.     ble    rembps1        ; loop 4 times
  2012.  
  2013. ;*replace user's swi vector
  2014.     ldx    *ptr4
  2015.     stx    *jswi+1
  2016.     rts
  2017.  
  2018. ;**********
  2019. ;*    restack() - restore user stack and
  2020. ;*execute an rti. extended addressing forced
  2021. ;*to ensure count value for trace.
  2022. ;**********
  2023. restack:
  2024.     lds    sp        ; stack pointer
  2025.     ldx    regs
  2026.     pshx            ; pc
  2027.     ldx    regs+2
  2028.     pshx            ; y
  2029.     ldx    regs+4
  2030.     pshx            ; x
  2031.     ldd    regs+6
  2032.     psha            ; a
  2033.     pshb            ; b
  2034.     ldaa    regs+8
  2035.     psha            ; ccr
  2036. restack1:
  2037.     rti
  2038.  
  2039. ;**********
  2040. ;*    savstack() -    save user's registers.
  2041. ;**********
  2042. savstack:
  2043.     ldaa    0,x
  2044.     staa    *regs+8        ; ccr
  2045.     ldd    1,x
  2046.     staa    *regs+7        ; b
  2047.     stab    *regs+6        ; a
  2048.     ldd    3,x
  2049.     std    *regs+4        ; x
  2050.     ldd    5,x
  2051.     std    *regs+2        ; y
  2052.     ldd    7,x
  2053.     std    *regs        ; pc
  2054.     ldab    #8
  2055.     abx
  2056.     stx    *sp        ; stack pointer
  2057.     rts
  2058.  
  2059. ;**********
  2060. ;*    help  -  list buffalo commands to terminal.
  2061. ;**********
  2062. help    = .
  2063.     ldx    #helpmsg1
  2064.     jsr    outstrg        ; print help screen
  2065.     rts
  2066.  
  2067. helpmsg1    = .
  2068.     .ascii    'ASM [<addr>]  Line assembler/disassembler.'
  2069.     .byte    0x0d
  2070.     .ascii    '    /        Do same address.'
  2071.     .ascii    '           ^        Do previous address.'
  2072.     .byte    0x0d
  2073.     .ascii    '    CTRL-J   Do next address.'
  2074.     .ascii    '           RETURN   Do next opcode.'
  2075.     .byte    0x0d
  2076.     .ascii    '    CTRL-A   Quit.'
  2077.     .byte    0x0d
  2078.     .ascii    'BF <addr1> <addr2> [<data>]  Block fill.'
  2079.     .byte    0x0d
  2080.     .ascii    'BR [-][<addr>]  Set up breakpoint table.'
  2081.     .byte    0x0d
  2082.     .ascii    'BULK  Erase the EEPROM.'
  2083.     .ascii    '                   BULKALL  Erase EEPROM and CONFIG.'
  2084.     .byte    0x0d
  2085.     .ascii    'CALL [<addr>]  Call user subroutine.'
  2086.     .ascii    '      G [<addr>]  Execute user code.'
  2087.     .byte    0x0d
  2088.     .ascii    'LOAD, VERIFY [T] <host download command>'
  2089.     .ascii    '  Load or verify S-records.'
  2090.     .byte    0x0d
  2091.     .ascii    'MD [<addr1> [<addr2>]]  Memory dump.'
  2092.     .byte    0x0d
  2093.     .ascii    'MM [<addr>]  Memory modify.'
  2094.     .byte    0x0d
  2095.     .ascii    '    /        Open same address.         CTRL-H'
  2096.     .ascii    ' or ^   Open previous address.'
  2097.     .byte    0x0d
  2098.     .ascii    '    CTRL-J   Open next address.         SPACE'
  2099.     .ascii    '         Open next address.'
  2100.     .byte    0x0d
  2101.     .ascii    '    RETURN   Quit.                      <addr>O'
  2102.     .ascii    '       Compute offset to <addr>.'
  2103.     .byte    0x0d
  2104.     .ascii    'MOVE <s1> <s2> [<d>]  Block move.'
  2105.     .byte    0x0d
  2106.     .ascii    'P  Proceed/continue execution.'
  2107.     .byte    0x0d
  2108.     .ascii    'RM [P, Y, X, A, B, C, or S]  Register modify.'
  2109.     .byte    0x0d
  2110.     .ascii    'T [<n>]  Trace n instructions.'
  2111.     .byte    0x0d
  2112.     .ascii    'TM  Transparent mode (CTRL-A = exit, CTRL-B = send break).'
  2113.     .byte    0x0d
  2114.     .ascii    'CTRL-H  Backspace.'
  2115.     .ascii    '                      CTRL-W  Wait for any key.'
  2116.     .byte    0x0d
  2117.     .ascii    'CTRL-X or DELETE  Abort/cancel command.'
  2118.     .byte    0x0d
  2119.     .ascii    'RETURN  Repeat last command.'
  2120.     .byte    4
  2121.  
  2122. ;**********
  2123. ;*    host() - establishes transparent link between
  2124. ;*    terminal and host.  port used for host is
  2125. ;*    determined in the reset initialization routine
  2126. ;*    and stored in hostdev.
  2127. ;*        to exit type control a.
  2128. ;*        to send break to host type control b.
  2129. ;*if(no external device) return;
  2130. ;*initialize host port;
  2131. ;*while( !(control a))
  2132. ;*    input(terminal); output(host);
  2133. ;*    input(host); output(terminal);
  2134.  
  2135. host:    ldaa    *extdev
  2136.     bne    host0        ; jump if host port avail.
  2137.     ldx    #msg10        ; "no host port avail"
  2138.     jsr    outstrg
  2139.     rts
  2140. host0:    clr    *autolf        ; turn off autolf
  2141.     jsr    hostco        ; connect sci (evb board)
  2142.     jsr    hostinit    ; initialize host port
  2143. host1:    jsr    input        ; read terminal
  2144.     tsta
  2145.     beq    host3        ; jump if no char
  2146.     cmpa    #ctla
  2147.     beq    hostend        ; jump if control a
  2148.     cmpa    #ctlb
  2149.     bne    host2        ; jump if not control b
  2150.     jsr    txbreak        ; send break to host
  2151.     bra    host3
  2152. host2:    jsr    hostout        ; echo to host
  2153. host3:    jsr    hostin        ; read host
  2154.     tsta
  2155.     beq    host1        ; jump if no char
  2156.     jsr    output        ; echo to terminal
  2157.     bra    host1
  2158. hostend:
  2159.     inc    *autolf        ; turn on autolf
  2160.     jsr    targco        ; disconnect sci (evb board)
  2161.     rts            ; return
  2162.  
  2163. ;**********
  2164. ;* txbreak() - transmit break to host port.
  2165. ;* the duration of the transmitted break is
  2166. ;* approximately 200,000 e-clock cycles, or
  2167. ;* 100ms at 2.0 mhz.
  2168. ;***********
  2169. txbreak    = .
  2170.     ldaa    *hostdev
  2171.     cmpa    #0x03
  2172.     beq    txbdu        ; jump if duartb is host
  2173.  
  2174. txbsci:    ldx    #sccr2        ; sci is host
  2175.     bset    0,x ,#0x01    ; set send break bit
  2176.     bsr    txbwait
  2177.     bclr    0,x ,#0x01    ; clear send break bit
  2178.     bra txb1
  2179.  
  2180. txbdu:    ldx    #portb        ; duart host port
  2181.     ldaa    #0x60        ; start break cmd
  2182.     staa    2,x        ; port b command register
  2183.     bsr    txbwait
  2184.     ldaa    #0x70        ; stop break cmd
  2185.     staa    2,x        ; port b command register
  2186.  
  2187. txb1:    ldaa    #0x0d
  2188.     jsr    hostout        ; send carriage return
  2189.     ldaa    #0x0a
  2190.     jsr    hostout        ; send linefeed
  2191.     rts
  2192.  
  2193. txbwait:
  2194.     ldy    #0x6f9b        ; loop count = 28571
  2195. txbwait1:
  2196.     dey            ; 7 cycle loop
  2197.     bne    txbwait1
  2198.     rts
  2199.  
  2200.  
  2201. ;**********
  2202. ;*    hostinit(), hostin(), hostout() - host i/o
  2203. ;*routines.  restores original terminal device.
  2204. ;**********
  2205. hostinit:
  2206.     ldab    *iodev        ; save terminal
  2207.     pshb
  2208.     ldab    *hostdev
  2209.     stab    *iodev        ; point to host
  2210.     jsr    init        ; initialize host
  2211.     bra    termres        ; restore terminal
  2212. hostin:    ldab    *iodev        ; save terminal
  2213.     pshb
  2214.     ldab    *hostdev
  2215.     stab    *iodev        ; point to host
  2216.     jsr    input        ; read host
  2217.     bra    termres        ; restore terminal
  2218. hostout:
  2219.     ldab    *iodev        ; save terminal
  2220.     pshb
  2221.     ldab    *hostdev
  2222.     stab    *iodev        ; point to host
  2223.     jsr    output        ; write to host
  2224. termres:
  2225.     pulb            ; restore terminal device
  2226.     stab    *iodev
  2227.     rts
  2228.  
  2229.  
  2230. ;**********
  2231. ;*    load(ptrbuff[]) - load s1/s9 records from
  2232. ;*host to memory.  ptrbuff[] points to string in
  2233. ;*input buffer which is a command to output s1/s9
  2234. ;*records from the host ("cat filename" for unix).
  2235. ;*    returns error and address if it can't write
  2236. ;*to a particular location.
  2237. ;**********
  2238. ;*    verify(ptrbuff[]) - verify memory from load
  2239. ;*command.  ptrbuff[] is same as for load.
  2240. ;**********
  2241. verify:    clr    *tmp2
  2242.     inc    *tmp2        ; flagt1 = 1 = verify
  2243.     bra    load1
  2244. load:    clr    *tmp2        ; flagt1 = 0 = load
  2245.  
  2246.  
  2247. ;*a=wskip();
  2248. ;*if(a = cr) goto transparent mode;
  2249. ;*if(t option) hostdev = iodev;
  2250.  
  2251. load1:    jsr    wskip
  2252.     cmpa    #0x0d
  2253.     bne    load1a
  2254.     jmp    host        ; go to host if no args
  2255. load1a:    jsr    upcase
  2256.     cmpa    #'T        ; look for t option
  2257.     bne    load1b        ; jump not t option
  2258.     jsr    incbuff
  2259.     jsr    readbuff    ; get next character
  2260.     jsr    decbuff
  2261.     cmpa    #0x0d
  2262.     bne    load1b        ; jump if not t option
  2263.     clr    *autolf
  2264.     ldaa    *iodev
  2265.     staa    *hostdev        ; set host port = terminal
  2266.     bra    load6        ; go wait for s1 records
  2267.  
  2268. ;*else while(not cr)
  2269. ;*    read character from input buffer;
  2270. ;*    send character to host;
  2271.  
  2272. load1b:    clr    *autolf
  2273.     jsr    hostco        ; connect sci (evb board)
  2274.     jsr    hostinit    ; initialize host port
  2275. load2:    jsr    readbuff    ; get next char
  2276.     jsr    incbuff
  2277.     psha            ; save char
  2278.     jsr    hostout        ; output to host
  2279.     jsr    output        ; echo to terminal
  2280.     pula
  2281.     cmpa    #0x0d
  2282.     bne    load2        ; jump if not cr
  2283.  
  2284. ;*repeat:
  2285. ;*    if(hostdev != iodev) check abort;
  2286. ;*    a = hostin();
  2287. ;*    if(a = 's')
  2288. ;*        a = hostin;
  2289. ;*        if(a = '9')
  2290. ;*        read rest of record;
  2291. ;*        return(done);
  2292. ;*        if(a = '1')
  2293. ;*        checksum = 0;
  2294. ;*        byte(); b = shftreg+1;    /* byte count */
  2295. ;*        byte(); byte(); x = shftreg; /* base addr*/
  2296. ;*        do
  2297. ;*            byte();
  2298. ;*            if(flagt1 = 0)
  2299. ;*            x[0] = shftreg+1
  2300. ;*            if(x[0] != shftreg+1)
  2301. ;*                return("rom-(x)");
  2302. ;*            x++; b--;
  2303. ;*        until(b = 0)
  2304.  
  2305. load6    = .
  2306.     ldaa    *hostdev
  2307.     cmpa    *iodev
  2308.     beq    load65        ; jump if hostdev=iodev
  2309.     jsr    chkabrt        ; check for abort
  2310. load65:    jsr    hostin        ; read host
  2311.     tsta
  2312.     beq    load6        ; jump if no input
  2313.     cmpa    #'S
  2314.     bne    load6        ; jump if not s
  2315. load7:    jsr    hostin        ; read host
  2316.     tsta
  2317.     beq    load7        ; jump if no input
  2318.     cmpa    #'9
  2319.     bne    load8        ; jump if not s9
  2320.     jsr    byte
  2321.     ldab    *shftreg+1    ; b = byte count
  2322. load75:    jsr    byte
  2323.     decb
  2324.     bne    load75        ; loop until end of record
  2325.     inc    *autolf        ; turn on autolf
  2326.     jsr    targco        ; disconnect sci (evb)
  2327.     ldx    #msg11        ; "done"
  2328.     jsr    outstrg
  2329.     rts
  2330. load8:    cmpa    #'1
  2331.     bne    load6        ; jump if not s1
  2332.     clr    *tmp4        ; clear checksum
  2333.     jsr    byte
  2334.     ldab    *shftreg+1
  2335.     subb    #0x2        ; b = byte count
  2336.     jsr    byte
  2337.     jsr    byte
  2338.     ldx    *shftreg    ; x = base address
  2339.     dex
  2340. load10:    jsr    byte        ; get next byte
  2341.     inx
  2342.     decb            ; check byte count
  2343.     beq    load12        ; if 0, go do checksum
  2344.     ldaa    *shftreg+1
  2345.     tst    *tmp2
  2346.     bne    load11        ; jump if verify
  2347.     staa    0,x        ; load only
  2348. load11:    cmpa    0,x        ; verify ram location
  2349.     beq    load10        ; jump if ram ok
  2350.     stx    *ptr3        ; save error address
  2351.     inc    *autolf        ; turn on autolf
  2352.     jsr    targco        ; disconnect sci(evb)
  2353.     jsr    outcrlf
  2354.     ldx    #msg13        ; "error addr"
  2355.     jsr    outstrg
  2356.     ldx    #ptr3
  2357.     jsr    out2bsp        ; address
  2358.     rts
  2359. load12:    ldaa    *tmp4
  2360.     inca            ; do checksum
  2361.     bne    load13        ; jump if s1 record okay
  2362.     jmp    load6
  2363. load13:    inc    *autolf
  2364.     jsr    targco        ; disconnect sci(evb)
  2365.     jsr    outcrlf
  2366.     ldx    #msg12        ; "checksum error"
  2367.     jsr    outstrg
  2368.     rts
  2369.  
  2370. ;**********
  2371. ;*    byte() -  read 2 ascii bytes from host and
  2372. ;*convert to one hex byte.  returns byte
  2373. ;*shifted into shftreg and added to tmp4.
  2374. ;**********
  2375. byte:    pshb
  2376.     pshx
  2377. byte0:    jsr    hostin        ; read host (1st byte)
  2378.     tsta
  2379.     beq    byte0        ; loop until input
  2380.     jsr    hexbin
  2381. byte1:    jsr    hostin        ; read host (2nd byte)
  2382.     tsta
  2383.     beq    byte1        ; loop until input
  2384.     jsr    hexbin
  2385.     ldaa    *shftreg+1
  2386.     adda    *tmp4
  2387.     staa    *tmp4        ; add to checksum
  2388.     pulx
  2389.     pulb
  2390.     rts
  2391.  
  2392.  
  2393. ;*******************************************
  2394. ;*    memory [<addr>]
  2395. ;*    [<addr>]/
  2396. ;* opens memory and allows user to modify the
  2397. ;*contents at <addr> or the last opened location.
  2398. ;*    subcommands:
  2399. ;* [<data>]<cr> - close current location and exit.
  2400. ;* [<data>]<lf> - close current and open next.
  2401. ;* [<data>]<^> - close current and open previous.
  2402. ;* [<data>]<sp> - close current and open next.
  2403. ;* [<data>]/ - reopen current location.
  2404. ;*    the contents of the current location is only
  2405. ;*    changed if valid data is entered before each
  2406. ;*  subcommand.
  2407. ;* [<addr>]o - compute relative offset from current
  2408. ;*    location to <addr>.  the current location must
  2409. ;*    be the address of the offset byte.
  2410. ;**********
  2411. ;*a = wskip();
  2412. ;*if(a != cr)
  2413. ;*    a = buffarg();
  2414. ;*    if(a != cr) return(bad argument);
  2415. ;*    if(countu1 != 0) ptrmem[] = shftreg;
  2416.  
  2417. memory:    jsr    wskip
  2418.     cmpa    #0xd
  2419.     beq    mem1        ; jump if cr
  2420.     jsr    buffarg
  2421.     jsr    wskip
  2422.     cmpa    #0xd
  2423.     beq    mslash        ; jump if cr
  2424.     ldx    #msg9        ; "bad argument"
  2425.     jsr    outstrg
  2426.     rts
  2427. mslash:    tst    *count
  2428.     beq    mem1        ; jump if no argument
  2429.     ldx    *shftreg
  2430.     stx    *ptrmem        ; update "current location"
  2431.  
  2432. ;**********
  2433. ;* subcommands
  2434. ;**********
  2435. ;*outcrlf();
  2436. ;*out2bsp(ptrmem[]);
  2437. ;*out1bsp(ptrmem[0]);
  2438.  
  2439. mem1:    jsr    outcrlf
  2440. mem2:    ldx    #ptrmem
  2441.     jsr    out2bsp        ; output address
  2442. mem3:    ldx    *ptrmem
  2443.     jsr    out1bsp        ; output contents
  2444.     clr    *shftreg
  2445.     clr    *shftreg+1
  2446. ;*while 1
  2447. ;*a = termarg();
  2448. ;*    switch(a)
  2449. ;*        case(space):
  2450. ;*        chgbyt();
  2451. ;*        ptrmem[]++;
  2452. ;*        case(linefeed):
  2453. ;*        chgbyt();
  2454. ;*        ptrmem[]++;
  2455. ;*        case(up arrow):
  2456. ;*        case(backspace):
  2457. ;*        chgbyt();
  2458. ;*        ptrmem[]--;
  2459. ;*        case("/"):
  2460. ;*        chgbyt();
  2461. ;*        outcrlf();
  2462. ;*        case(o):
  2463. ;*        d = ptrmem[0] - (shftreg);
  2464. ;*        if(0x80 < d < 0xff81)
  2465. ;*            print(out of range);
  2466. ;*        countt1 = d-1;
  2467. ;*        out1bsp(countt1);
  2468. ;*        case(carriage return):
  2469. ;*        chgbyt();
  2470. ;*        return;
  2471. ;*        default: return(command?)
  2472.  
  2473. mem4:    jsr    termarg
  2474.     jsr    upcase
  2475.     ldx    *ptrmem
  2476.     cmpa    #0x20
  2477.     beq    memsp        ; jump if space
  2478.     cmpa    #0x0a
  2479.     beq    memlf        ; jump if linefeed
  2480.     cmpa    #0x5e
  2481.     beq    memua        ; jump if up arrow
  2482.     cmpa    #0x08
  2483.     beq    membs        ; jump if backspace
  2484.     cmpa    #'/
  2485.     beq    memsl        ; jump if /
  2486.     cmpa    #'O
  2487.     beq    memoff        ; jump if o
  2488.     cmpa    #0x0d
  2489.     beq    memcr        ; jump if carriage ret
  2490.     ldx    #msg8        ; "command?"
  2491.     jsr    outstrg
  2492.     jmp    mem1
  2493. memsp:    jsr    chgbyt
  2494.     inx
  2495.     stx    *ptrmem
  2496.     jmp    mem3        ; output contents
  2497. memlf:    jsr    chgbyt
  2498.     inx
  2499.     stx    *ptrmem
  2500.     jmp    mem2        ; output addr, contents
  2501. memua    = .
  2502. membs:    jsr    chgbyt
  2503.     dex
  2504.     stx    *ptrmem
  2505.     jmp    mem1        ; output cr, addr, contents
  2506. memsl:    jsr    chgbyt
  2507.     jmp    mem1        ; output cr, addr, contents
  2508. memoff:    ldd    *shftreg    ; destination addr
  2509.     subd    *ptrmem
  2510.     cmpa    #0x0
  2511.     bne    memoff1        ; jump if not 0
  2512.     cmpb    #0x80
  2513.     bls    memoff3        ; jump if in range
  2514.     bra    memoff2        ; out of range
  2515. memoff1:
  2516.     cmpa    #0xff
  2517.     bne    memoff2        ; out of range
  2518.     cmpb    #0x81
  2519.     bhs    memoff3        ; in range
  2520. memoff2:
  2521.     ldx    #msg3        ; "too long"
  2522.     jsr    outstrg
  2523.     jmp    mem1        ; output cr, addr, contents
  2524. memoff3:
  2525.     subd    #0x1        ; b now has offset
  2526.     stab    *tmp4
  2527.     jsr    outspac
  2528.     ldx    #tmp4
  2529.     jsr    out1bsp        ; output offset
  2530.     jmp    mem1        ; output cr, addr, contents
  2531. memcr:    jsr    chgbyt
  2532.     rts            ; exit task
  2533.  
  2534.  
  2535. ;**********
  2536. ;*    move <src1> <src2> [<dest>]    - move
  2537. ;*block at <src1> to <src2> to <dest>.
  2538. ;*    moves block 1 byte up if no <dest>.
  2539. ;**********
  2540. ;*a = buffarg();
  2541. ;*if(countu1 = 0) return(bad argument);
  2542. ;*if( !wchek(a) ) return(bad argument);
  2543. ;*ptr1 = shftreg;    /* src1 */
  2544.  
  2545. move    = .
  2546.     jsr    buffarg
  2547.     tst    *count
  2548.     beq    moverr        ; jump if no arg
  2549.     jsr    wchek
  2550.     bne    moverr        ; jump if no delim
  2551.     ldx    *shftreg    ; src1
  2552.     stx    *ptr1
  2553.  
  2554. ;*a = buffarg();
  2555. ;*if(countu1 = 0) return(bad argument);
  2556. ;*if( !dchek(a) ) return(bad argument);
  2557. ;*ptr2 = shftreg;    /* src2 */
  2558.  
  2559.     jsr    buffarg
  2560.     tst    *count
  2561.     beq    moverr        ; jump if no arg
  2562.     jsr    dchek
  2563.     bne    moverr        ; jump if no delim
  2564.     ldx    *shftreg    ; src2
  2565.     stx    *ptr2
  2566.  
  2567. ;*a = buffarg();
  2568. ;*a = wskip();
  2569. ;*if(a != cr) return(bad argument);
  2570. ;*if(countu1 != 0) tmp2 = shftreg;  /* dest */
  2571. ;*else tmp2 = ptr1 + 1;
  2572.  
  2573.     jsr    buffarg
  2574.     jsr    wskip
  2575.     cmpa    #0x0d
  2576.     bne    moverr        ; jump if not cr
  2577.     tst    *count
  2578.     beq    move1        ; jump if no arg
  2579.     ldx    *shftreg    ; dest
  2580.     bra    move2
  2581. moverr:    ldx    #msg9        ; "bad argument"
  2582.     jsr    outstrg
  2583.     rts
  2584. move1:    ldx    *ptr1
  2585.     inx            ; default dest
  2586. move2:    stx    *ptr3
  2587.  
  2588. ;*if(src1 < dest <= src2)
  2589. ;*    dest = dest+(src2-src1);
  2590. ;*    for(x = src2; x = src1; x--)
  2591. ;*        dest[0]-- = x[0]--;
  2592.  
  2593.     ldx    *ptr3        ; dest
  2594.     cpx    *ptr1        ; src1
  2595.     bls    move3        ; jump if dest =< src1
  2596.     cpx    *ptr2        ; src2
  2597.     bhi    move3        ; jump if dest > src2
  2598.     ldd    *ptr2
  2599.     subd    *ptr1
  2600.     addd    *ptr3
  2601.     std    *ptr3        ; dest = dest+(src2-src1)
  2602.     ldx    *ptr2
  2603. movelp1:
  2604.     jsr    chkabrt        ; check for abort
  2605.     ldaa    ,x        ; char at src2
  2606.     pshx
  2607.     ldx    *ptr3
  2608.     cpx    #0xb600        ; jump if not eeprom
  2609.     blo    movea
  2610.     cpx    #0xb7ff        ; jump if not eeprom
  2611.     bhi    movea
  2612.     jsr    movprog        ; program eeprom
  2613. movea:    staa    ,x        ; dest
  2614.     dex
  2615.     stx    *ptr3
  2616.     pulx
  2617.     cpx    *ptr1
  2618.     beq    movrts
  2619.     dex
  2620.     bra    movelp1        ; loop src2 - src1 times
  2621. ;*
  2622. ;* else
  2623. ;*    for(x=src1; x=src2; x++)
  2624. ;*        dest[0]++ = x[0]++;
  2625.  
  2626.  
  2627. move3:    ldx    *ptr1        ; srce1
  2628. movelp2:
  2629.     jsr    chkabrt        ; check for abort
  2630.     ldaa    ,x
  2631.     pshx
  2632.     ldx    *ptr3        ; dest
  2633.     cpx    #0xb600        ; jump if not eeprom
  2634.     blo    moveb
  2635.     cpx    #0xb7ff        ; jump if not eeprom
  2636.     bhi    moveb
  2637.     jsr    movprog        ; program eeprom
  2638. moveb:    staa    ,x
  2639.     inx
  2640.     stx    *ptr3
  2641.     pulx
  2642.     cpx    *ptr2
  2643.     beq    movrts
  2644.     inx
  2645.     bra    movelp2        ; loop src2-src1 times
  2646. movrts:    rts
  2647.  
  2648. ;*************
  2649. ;*    movprog - program eeprom location in x with
  2650. ;*    data in a.
  2651. ;*************
  2652. movprog:
  2653.     pshb
  2654.     pshx
  2655.     ldab    #0x02
  2656.     stab    pprog        ; set eelat
  2657.     staa    ,x
  2658.     ldab    #0x03
  2659.     bne    acl4
  2660.     clrb            ; fail safe
  2661. acl4:    stab    pprog        ; set pgm
  2662.     ldx    #0x0d06
  2663. movedly:
  2664.     dex
  2665.     bne    movedly        ; delay 10 ms at E = 2 mhz
  2666.     ldab    #0x00
  2667.     stab    pprog
  2668.     pulx
  2669.     pulb
  2670.     rts
  2671.  
  2672.  
  2673. ;**********
  2674. ;*    register [<name>]    - prints the user regs
  2675. ;*and opens them for modification.    <name> is
  2676. ;*the first register opened (default = p).
  2677. ;*    subcommands:
  2678. ;* [<nn>]<space>    opens the next register.
  2679. ;* [<nn>]<cr>    return.
  2680. ;*    the register value is only changed if
  2681. ;*    <nn> is entered before the subcommand.
  2682. ;**********
  2683. ;*x[] = reglist
  2684. ;*a = wskip(); a = upcase(a);
  2685. ;*if(a != cr)
  2686. ;*    while( a != x[0] )
  2687. ;*        if( x[0] = "s") return(bad argument);
  2688. ;*        x[]++;
  2689. ;*    incbuff(); a = wskip();
  2690. ;*    if(a != cr) return(bad argument);
  2691.  
  2692. register:
  2693.     ldx    #reglist
  2694.     jsr    wskip        ; a = first char of arg
  2695.     jsr    upcase        ; convert to upper case
  2696.     cmpa    #0xd
  2697.     beq    reg4        ; jump if no argument
  2698. reg1:    cmpa    0,x
  2699.     beq    reg3
  2700.     ldab    0,x
  2701.     inx
  2702.     cmpb    #'S
  2703.     bne    reg1        ; jump if not "s"
  2704. reg2:    ldx    #msg9        ; "bad argument"
  2705.     jsr    outstrg
  2706.     rts
  2707. reg3:    pshx
  2708.     jsr    incbuff
  2709.     jsr    wskip        ; next char after arg
  2710.     cmpa    #0xd
  2711.     pulx
  2712.     bne    reg2        ; jump if not cr
  2713.  
  2714. ;*rprint();
  2715. ;*    while(x[0] != "s")
  2716. ;*        rprnt1(x);
  2717. ;*        a = termarg();    /* read from terminal */
  2718. ;*        if( ! dchek(a) ) return(bad argument);
  2719. ;*        if(countu1 != 0)
  2720. ;*        if(x[14] = 1)
  2721. ;*            regs[x[7]++ = shftreg;
  2722. ;*        regs[x[7]] = shftreg+1;
  2723. ;*        if(a = cr) break;
  2724. ;*return;
  2725.  
  2726. reg4:    jsr    rprint        ; print all registers
  2727. reg5:    jsr    outcrlf
  2728.     jsr    rprnt1        ; print reg name
  2729.     clr    *shftreg
  2730.     clr    *shftreg+1
  2731.     jsr    termarg        ; read subcommand
  2732.     jsr    dchek
  2733.     beq    reg6        ; jump if delimeter
  2734.     ldx    #msg9        ; "bad argument"
  2735.     jsr    outstrg
  2736.     rts
  2737. reg6:    psha
  2738.     pshx
  2739.     tst    *count
  2740.     beq    reg8        ; jump if no input
  2741.     ldab    7,x        ; get reg offset
  2742.     ldaa    14,x        ; byte size
  2743.     ldx    #regs        ; user registers
  2744.     abx
  2745.     tsta
  2746.     beq    reg7        ; jump if 1 byte reg
  2747.     ldaa    *shftreg
  2748.     staa    0,x        ; put in top byte
  2749.     inx
  2750. reg7:    ldaa    *shftreg+1
  2751.     staa    0,x        ; put in bottom byte
  2752. reg8:    pulx
  2753.     pula
  2754.     ldab    0,x        ; check for register s
  2755.     cmpb    #'S
  2756.     beq    reg9        ; jump if "s"
  2757.     inx            ; point to next register
  2758.     cmpa    #0xd
  2759.     bne    reg5        ; jump if not cr
  2760. reg9:    rts
  2761.  
  2762. page1    =    0x00        ; values for page opcodes
  2763. page2    =    0x18
  2764. page3    =    0x1a
  2765. page4    =    0xcd
  2766. immed    =    0x0        ; addressing modes
  2767. indx    =    0x1
  2768. indy    =    0x2
  2769. limmed    =    0x3        ; (long immediate)
  2770. other    =    0x4
  2771.  
  2772. ;*** rename variables for assem/disassem ***
  2773. amode    =    tmp2        ; addressing mode
  2774. yflag    =    tmp3
  2775. pnorm    =    tmp4        ; page for normal opcode
  2776. oldpc    =    ptrmem
  2777. pc    =    ptr1        ; program counter
  2778. px    =    ptr2        ; page for x indexed
  2779. py    =    ptr2+1        ; page for y indexed
  2780. baseop    =    ptr3        ; base opcode
  2781. class    =    ptr3+1        ; class
  2782. dispc    =    ptr4        ; pc for disassembler
  2783. braddr    =    ptr5        ; relative branch offset
  2784. mneptr    =    ptr6        ; pointer to table for dis
  2785. asscomm    =    ptr7        ; subcommand for assembler
  2786.  
  2787. ;*** error messages for assembler ***
  2788. msgdir:    .word    #msga1        ; message table index
  2789.     .word    #msga2
  2790.     .word    #msga3
  2791.     .word    #msga4
  2792.     .word    #msga5
  2793.     .word    #msga6
  2794.     .word    #msga7
  2795.     .word    #msga8
  2796.     .word    #msga9
  2797. msga1:    .ascii    'Immediate mode illegal'
  2798.     .byte    eot
  2799. msga2:    .ascii    'Error in mnemonic table'
  2800.     .byte    eot
  2801. msga3:    .ascii    'Illegal bit op'
  2802.     .byte    eot
  2803. msga4:    .ascii    'Bad argument'
  2804.     .byte    eot
  2805. msga5:    .ascii    'Mnemonic not found'
  2806.     .byte    eot
  2807. msga6:    .ascii    'Unknown addressing mode'
  2808.     .byte    eot
  2809. msga7:    .ascii    'Indexed addressing assumed'
  2810.     .byte    eot
  2811. msga8:    .ascii    'Syntax error'
  2812.     .byte    eot
  2813. msga9:    .ascii    'Branch out of range'
  2814.     .byte    eot
  2815.  
  2816. ;****************
  2817. ;*    assem(addr) -68hc11 line assembler/disassembler.
  2818. ;*    this routine will disassemble the opcode at
  2819. ;*<addr> and then allow the user to enter a line for
  2820. ;*assembly. rules for assembly are as follows:
  2821. ;* -a '#' sign indicates immediate addressing.
  2822. ;* -a ',' (comma) indicates indexed addressing
  2823. ;*    and the next character must be x or y.
  2824. ;* -all arguments are assumed to be hex and the
  2825. ;*    '$' sign shouldn't be used.
  2826. ;* -arguments should be separated by 1 or more
  2827. ;*    spaces or tabs.
  2828. ;* -any input after the required number of
  2829. ;*    arguments is ignored.
  2830. ;* -upper or lower case makes no difference.
  2831. ;*
  2832. ;*    to signify end of input line, the following
  2833. ;*commands are available and have the indicated action:
  2834. ;*    <cr>  -carriage return finds the next opcode for
  2835. ;*        assembly.  if there was no assembly input,
  2836. ;*        the next opcode disassembled is retrieved
  2837. ;*        from the disassembler.
  2838. ;*    <lf>  -linefeed works the same as carriage return
  2839. ;*        except if there was no assembly input, the
  2840. ;*        <addr> is incremented and the next <addr> is
  2841. ;*        disassembled.
  2842. ;*    '^'  -up arrow decrements <addr> and the previous
  2843. ;*        address is then disassembled.
  2844. ;*    '/'  -slash redisassembles the current address.
  2845. ;*
  2846. ;*    to exit the assembler use control a.  of course
  2847. ;*control x and del will also allow you to abort.
  2848. ;**********
  2849. ;*oldpc = rambase;
  2850. ;*a = wskip();
  2851. ;*if (a != cr)
  2852. ;*    buffarg()
  2853. ;*    a = wskip();
  2854. ;*    if ( a != cr ) return(error);
  2855. ;*    oldpc = a;
  2856.  
  2857. assem    = .
  2858.     ldx    #rambs
  2859.     stx    *oldpc
  2860.     jsr    wskip
  2861.     cmpa    #0x0d
  2862.     beq    assloop     ; jump if no argument
  2863.     jsr    buffarg
  2864.     jsr    wskip
  2865.     cmpa    #0x0d
  2866.     beq    assem1        ; jump if argument ok
  2867.     ldx    #msga4        ; "bad argument"
  2868.     jsr    outstrg
  2869.     rts
  2870. assem1:    ldx    *shftreg
  2871.     stx    *oldpc
  2872.  
  2873. ;*repeat
  2874. ;*    pc = oldpc;
  2875. ;*    out2bsp(pc);
  2876. ;*    disassem();
  2877. ;*    a=readln();
  2878. ;*    asscomm = a;    /* save command */
  2879. ;*    if(a == ('^' or '/')) outcrlf;
  2880. ;*    if(a == 0) return(error);
  2881.  
  2882. assloop:
  2883.     ldx    *oldpc
  2884.     stx    *pc
  2885.     jsr    outcrlf
  2886.     ldx    #pc
  2887.     jsr    out2bsp        ; output the address
  2888.     jsr    disassm        ; disassemble opcode
  2889.     jsr    outcrlf
  2890.     jsr    outspac
  2891.     jsr    outspac
  2892.     jsr    outspac
  2893.     jsr    outspac
  2894.     ldaa    #prompt        ; prompt user
  2895.     jsr    outa        ; output prompt character
  2896.     jsr    readln        ; read input for assembly
  2897.     staa    *asscomm
  2898.     cmpa    #'^
  2899.     beq    asslp0        ; jump if up arrow
  2900.     cmpa    #'/
  2901.     beq    asslp0        ; jump if slash
  2902.     cmpa    #0x00
  2903.     bne    asslp1        ; jump if none of above
  2904.     rts            ; return if bad input
  2905. asslp0:    jsr    outcrlf
  2906. asslp1    = .
  2907.     jsr    outspac
  2908.     jsr    outspac
  2909.     jsr    outspac
  2910.     jsr    outspac
  2911.     jsr    outspac
  2912.  
  2913. ;*    b = parse(input); /* get mnemonic */
  2914. ;*    if(b > 5) print("not found"); asscomm='/';
  2915. ;*    elseif(b >= 1)
  2916. ;*    msrch();
  2917. ;*    if(class==0xff)
  2918. ;*    print("not found"); asscomm='/';
  2919. ;*    else
  2920. ;*    a = doop(opcode,class);
  2921. ;*    if(a == 0) dispc=0;
  2922. ;*    else process error; asscomm='/';
  2923.  
  2924.     jsr    parse
  2925.     cmpb    #0x5
  2926.     ble    asslp2        ; jump if mnemonic <= 5 chars
  2927.     ldx    #msga5        ; "mnemonic not found"
  2928.     jsr    outstrg
  2929.     bra    asslp5
  2930. asslp2    = .
  2931.     cmpb    #0x0
  2932.     beq    asslp10     ; jump if no input
  2933.     jsr    msrch
  2934.     ldaa    *class
  2935.     cmpa    #0xff
  2936.     bne    asslp3
  2937.     ldx    #msga5        ; "mnemonic not found"
  2938.     jsr    outstrg
  2939.     bra    asslp5
  2940. asslp3:    jsr    doop
  2941.     cmpa    #0x00
  2942.     bne    asslp4        ; jump if doop error
  2943.     ldx    #0x00
  2944.     stx    *dispc        ; indicate good assembly
  2945.     bra    asslp10
  2946. asslp4:    deca            ; a = error message index
  2947.     tab
  2948.     ldx    #msgdir
  2949.     abx
  2950.     abx
  2951.     ldx    0,x
  2952.     jsr    outstrg     ; output error message
  2953. asslp5:    clr    *asscomm     ; error command
  2954.  
  2955. ;*    /* compute next address - asscomm holds subcommand
  2956. ;*    and dispc indicates if valid assembly occured. */
  2957. ;*  if(asscomm=='^') oldpc -= 1;
  2958. ;*  if(asscomm==(lf or cr)
  2959. ;*    if(dispc==0) oldpc=pc;
  2960. ;*    else
  2961. ;*    if(asscomm==lf) dispc=oldpc+1;
  2962. ;*    oldpc=dispc;
  2963. ;*until(eot)
  2964.  
  2965.  
  2966. asslp10    = .
  2967.     ldaa    *asscomm
  2968.     cmpa    #'^
  2969.     bne    asslp11        ; jump if not up arrow
  2970.     ldx    *oldpc
  2971.     dex
  2972.     stx    *oldpc        ; back up
  2973.     bra    asslp15
  2974. asslp11:
  2975.     cmpa    #0x0a
  2976.     beq    asslp12        ; jump if linefeed
  2977.     cmpa    #0x0d
  2978.     bne    asslp15        ; jump if not cr
  2979. asslp12:
  2980.     ldx    *dispc
  2981.     bne    asslp13        ; jump if dispc != 0
  2982.     ldx    *pc
  2983.     stx    *oldpc
  2984.     bra    asslp15
  2985. asslp13:
  2986.     cmpa    #0x0a
  2987.     bne    asslp14        ; jump if not linefeed
  2988.     ldx    *oldpc
  2989.     inx
  2990.     stx    *dispc
  2991. asslp14:
  2992.     ldx    *dispc
  2993.     stx    *oldpc
  2994. asslp15:
  2995.     jmp    assloop
  2996.  
  2997. ;****************
  2998. ;*    readln() --- read input from terminal into buffer
  2999. ;* until a command character is read (cr,lf,/,^).
  3000. ;* if more chars are typed than the buffer will hold,
  3001. ;* the extra characters are overwritten on the end.
  3002. ;*  on exit: b=number of chars read, a=0 if quit,
  3003. ;* else a=next command.
  3004. ;****************
  3005. ;*for(b==0;b<=bufflng;b++) inbuff[b] = cr;
  3006.  
  3007. readln:    clrb
  3008.     ldaa    #0x0d        ; carriage ret
  3009. rln0:    ldx    #inbuff
  3010.     abx
  3011.     staa    0,x        ; initialize input buffer
  3012.     incb
  3013.     cmpb    #bufflng
  3014.     blt    rln0
  3015. ;*b=0;
  3016. ;*repeat
  3017. ;*    if(a == (ctla, cntlc, cntld, cntlx, del))
  3018. ;*    return(a=0);
  3019. ;*  if(a == backspace)
  3020. ;*    if(b > 0) b--;
  3021. ;*    else b=0;
  3022. ;*  else  inbuff[b] = upcase(a);
  3023. ;*  if(b < bufflng) b++;
  3024. ;*until (a == (cr,lf,^,/))
  3025. ;*return(a);
  3026.  
  3027.     clrb
  3028. rln1:    jsr    inchar
  3029.     cmpa    #del        ; delete
  3030.     beq    rlnquit
  3031.     cmpa    #ctlx        ; control x
  3032.     beq    rlnquit
  3033.     cmpa    #ctla        ; control a
  3034.     beq    rlnquit
  3035.     cmpa    #0x03        ; control c
  3036.     beq    rlnquit
  3037.     cmpa    #0x04        ; control d
  3038.     beq    rlnquit
  3039.     cmpa    #0x08        ; backspace
  3040.     bne    rln2
  3041.     decb
  3042.     bgt    rln1
  3043.     bra    readln        ; start over
  3044. rln2:    ldx    #inbuff
  3045.     abx
  3046.     jsr    upcase
  3047.     staa    0,x        ; put char in buffer
  3048.     cmpb    #bufflng    ; max buffer length
  3049.     bge    rln3        ; jump if buffer full
  3050.     incb            ; move buffer pointer
  3051. rln3:    jsr    asschek     ; check for subcommand
  3052.     bne    rln1
  3053.     rts
  3054. rlnquit:
  3055.     clra            ; quit
  3056.     rts            ; return
  3057.  
  3058.  
  3059. ;**********
  3060. ;*    parse() -parse out the mnemonic from inbuff
  3061. ;* to combuff. on exit: b=number of chars parsed.
  3062. ;**********
  3063. ;*combuff[3] = <space>;    initialize 4th character to space.
  3064. ;*ptrbuff[] = inbuff[];
  3065. ;*a=wskip();
  3066. ;*for (b = 0; b = 5; b++)
  3067. ;*    a=readbuff(); incbuff();
  3068. ;*    if (a = (cr,lf,^,/,wspace)) return(b);
  3069. ;*    combuff[b] = upcase(a);
  3070. ;*return(b);
  3071.  
  3072. parse:    ldaa    #0x20
  3073.     staa    *combuff+3
  3074.     ldx    #inbuff        ; initialize buffer ptr
  3075.     stx    *ptr0
  3076.     jsr    wskip        ; find first character
  3077.     clrb
  3078. parslp:    jsr    readbuff    ; read character
  3079.     jsr    incbuff
  3080.     jsr    wchek
  3081.     beq    parsrt        ; jump if whitespace
  3082.     jsr    asschek
  3083.     beq    parsrt        ; jump if end of line
  3084.     jsr    upcase        ; convert to upper case
  3085.     ldx    #combuff
  3086.     abx
  3087.     staa    0,x        ; store in combuff
  3088.     incb
  3089.     cmpb    #0x5
  3090.     ble    parslp        ; loop 6 times
  3091. parsrt:    rts
  3092.  
  3093.  
  3094. ;****************
  3095. ;*    asschek() -perform compares for
  3096. ;* cr, lf, ^, /
  3097. ;****************
  3098. asschek:
  3099.     cmpa    #0x0a        ; linefeed
  3100.     beq    asschk1
  3101.     cmpa    #0x0d        ; carriage ret
  3102.     beq    asschk1
  3103.     cmpa    #'^        ; up arrow
  3104.     beq    asschk1
  3105.     cmpa    #'/        ; slash
  3106. asschk1:
  3107.     rts
  3108.  
  3109.  
  3110. ;*********
  3111. ;*    msrch() --- search mnetabl for mnemonic in combuff.
  3112. ;*stores base opcode at baseop and class at class.
  3113. ;*  class = ff if not found.
  3114. ;**********
  3115. ;*while ( != eof )
  3116. ;*    if (combuff[0-3] = mnetabl[0-3])
  3117. ;*    return(mnetabl[4],mnetabl[5]);
  3118. ;*    else *mnetabl =+ 6
  3119.  
  3120. msrch:    ldx    #mnetabl    ; pointer to mnemonic table
  3121.     ldy    #combuff    ; pointer to string
  3122.     bra    msrch1
  3123. msnext    = .
  3124.     ldab    #6
  3125.     abx            ; point to next table entry
  3126. msrch1:    ldaa    0,x        ; read table
  3127.     cmpa    #eot
  3128.     bne    msrch2        ; jump if not end of table
  3129.     ldaa    #0xff
  3130.     staa    *class        ; ff = not in table
  3131.     rts
  3132. msrch2:    cmpa    0,y        ; op[0] = tabl[0] ?
  3133.     bne    msnext
  3134.     ldaa    1,x
  3135.     cmpa    1,y        ; op[1] = tabl[1] ?
  3136.     bne    msnext
  3137.     ldaa    2,x
  3138.     cmpa    2,y        ; op[2] = tabl[2] ?
  3139.     bne    msnext
  3140.     ldaa    3,x
  3141.     cmpa    3,y        ; op[2] = tabl[2] ?
  3142.     bne    msnext
  3143.     ldd    4,x        ; opcode, class
  3144.     staa    *baseop
  3145.     stab    *class
  3146.     rts
  3147.  
  3148. ;**********
  3149. ;**    doop(baseop,class) --- process mnemonic.
  3150. ;**    on exit: a=error code corresponding to error
  3151. ;**                    messages.
  3152. ;**********
  3153. ;*amode = other; /* addressing mode */
  3154. ;*yflag = 0;    /* ynoimm, nlimm, and cpd flag */
  3155. ;*x[] = ptrbuff[]
  3156.  
  3157. doop    = .
  3158.     ldaa    #other
  3159.     staa    *amode        ; mode
  3160.     clr    *yflag
  3161.     ldx    *ptr0
  3162.  
  3163. ;*while (*x != end of buffer)
  3164. ;*    if (x[0]++ == ',')
  3165. ;*    if (x[0] == 'y') amode = indy;
  3166. ;*    else amod = indx;
  3167. ;*    break;
  3168. ;*a = wskip()
  3169. ;*if( a == '#' ) amode = immed;
  3170.  
  3171. doplp1:    cpx    #endbuff    ; (end of buffer)
  3172.     beq    doop1        ; jump if end of buffer
  3173.     ldd    0,x        ; read 2 chars from buffer
  3174.     inx            ; move pointer
  3175.     cmpa    #',
  3176.     bne    doplp1
  3177.     cmpb    #'Y        ; look for ",y"
  3178.     bne    doplp2
  3179.     ldaa    #indy
  3180.     staa    *amode
  3181.     bra    doop1
  3182. doplp2:    cmpb    #'X        ; look for ",x"
  3183.     bne    doop1        ; jump if not x
  3184.     ldaa    #indx
  3185.     staa    *amode
  3186.     bra    doop1
  3187. doop1:    jsr    wskip
  3188.     cmpa    #'#        ; look for immediate mode
  3189.     bne    doop2
  3190.     jsr    incbuff     ; point at argument
  3191.     ldaa    #immed
  3192.     staa    *amode
  3193. doop2    = .
  3194.  
  3195. ;*switch(class)
  3196.     ldab    *class
  3197.     cmpb    #p2inh
  3198.     bne    dosw1
  3199.     jmp    dop2i
  3200. dosw1:    cmpb    #inh
  3201.     bne    dosw2
  3202.     jmp    doinh
  3203. dosw2:    cmpb    #rel
  3204.     bne    dosw3
  3205.     jmp    dorel
  3206. dosw3:    cmpb    #limm
  3207.     bne    dosw4
  3208.     jmp    dolim
  3209. dosw4:    cmpb    #nimm
  3210.     bne    dosw5
  3211.     jmp    donoi
  3212. dosw5:    cmpb    #gen
  3213.     bne    dosw6
  3214.     jmp    dogene
  3215. dosw6:    cmpb    #grp2
  3216.     bne    dosw7
  3217.     jmp    dogrp
  3218. dosw7:    cmpb    #cpd
  3219.     bne    dosw8
  3220.     jmp    docpd
  3221. dosw8:    cmpb    #xnimm
  3222.     bne    dosw9
  3223.     jmp    doxnoi
  3224. dosw9:    cmpb    #xlimm
  3225.     bne    dosw10
  3226.     jmp    doxli
  3227. dosw10:    cmpb    #ynimm
  3228.     bne    dosw11
  3229.     jmp    doynoi
  3230. dosw11:    cmpb    #ylimm
  3231.     bne    dosw12
  3232.     jmp    doyli
  3233. dosw12:    cmpb    #btb
  3234.     bne    dosw13
  3235.     jmp    dobtb
  3236. dosw13:    cmpb    #setclr
  3237.     bne    dodef
  3238.     jmp    doset
  3239.  
  3240. ;*    default: return("error in mnemonic table");
  3241.  
  3242. dodef:    ldaa    #0x2
  3243.     rts
  3244.  
  3245. ;*  case p2inh: emit(page2)
  3246.  
  3247. dop2i:    ldaa    #page2
  3248.     jsr    emit
  3249.  
  3250. ;*  case inh: emit(baseop);
  3251. ;*    return(0);
  3252.  
  3253. doinh:    ldaa    *baseop
  3254.     jsr    emit
  3255.     clra
  3256.     rts
  3257.  
  3258. ;*  case rel: a = assarg();
  3259. ;*        if(a=4) return(a);
  3260. ;*        d = address - pc + 2;
  3261. ;*        if (0x7f >= d >= 0xff82)
  3262. ;*        return (out of range);
  3263. ;*        emit(opcode);
  3264. ;*        emit(offset);
  3265. ;*        return(0);
  3266.  
  3267. dorel:    jsr    assarg
  3268.     cmpa    #0x04
  3269.     bne    dorel1        ; jump if arg ok
  3270.     rts
  3271. dorel1:    ldd    *shftreg     ; get branch address
  3272.     ldx    *pc        ; get program counter
  3273.     inx
  3274.     inx            ; point to end of opcode
  3275.     stx    *braddr
  3276.     subd    *braddr        ; calculate offset
  3277.     std    *braddr        ; save result
  3278.     cmpd    #0x7f        ; in range ?
  3279.     bls    dorel2        ; jump if in range
  3280.     cmpd    #0xff80
  3281.     bhs    dorel2        ; jump if in range
  3282.     ldaa    #0x09        ; 'out of range'
  3283.     rts
  3284. dorel2:    ldaa    *baseop
  3285.     jsr    emit        ; emit opcode
  3286.     ldaa    *braddr+1
  3287.     jsr    emit        ; emit offset
  3288.     clra            ; normal return
  3289.     rts
  3290.  
  3291. ;*    case limm: if (amode == immed) amode = limmed;
  3292.  
  3293. dolim:    ldaa    *amode
  3294.     cmpa    #immed
  3295.     bne    donoi
  3296.     ldaa    #limmed
  3297.     staa    *amode
  3298.  
  3299. ;*    case nimm: if (amode == immed)
  3300. ;*        return("immediate mode illegal");
  3301.  
  3302. donoi:    ldaa    *amode
  3303.     cmpa    #immed
  3304.     bne    dogene        ; jump if not immediate
  3305.     ldaa    #0x1        ; "immediate mode illegal"
  3306.     rts
  3307.  
  3308. ;*  case gen: dogen(baseop,amode,page1,page1,page2);
  3309. ;*        return;
  3310.  
  3311. dogene:    ldaa    #page1
  3312.     staa    *pnorm
  3313.     staa    *px
  3314.     ldaa    #page2
  3315.     staa    *py
  3316.     jsr    dogen
  3317.     rts
  3318.  
  3319. ;*  case grp2: if (amode == indy)
  3320. ;*        emit(page2);
  3321. ;*        amode = indx;
  3322. ;*        if( amode == indx )
  3323. ;*        doindx(baseop);
  3324. ;*        else a = assarg();
  3325. ;*        if(a=4) return(a);
  3326. ;*        emit(opcode+0x10);
  3327. ;*        emit(extended address);
  3328. ;*        return;
  3329.  
  3330. dogrp:    ldaa    *amode
  3331.     cmpa    #indy
  3332.     bne    dogrp1
  3333.     ldaa    #page2
  3334.     jsr    emit
  3335.     ldaa    #indx
  3336.     staa    *amode
  3337. dogrp1    = .
  3338.     ldaa    *amode
  3339.     cmpa    #indx
  3340.     bne    dogrp2
  3341.     jsr    doindex
  3342.     rts
  3343. dogrp2    = .
  3344.     ldaa    *baseop
  3345.     adda    #0x10
  3346.     jsr    emit
  3347.     jsr    assarg
  3348.     cmpa    #0x04
  3349.     beq    dogrprt     ; jump if bad arg
  3350.     ldd    *shftreg     ; extended address
  3351.     jsr    emit
  3352.     tba
  3353.     jsr    emit
  3354.     clra
  3355. dogrprt:
  3356.     rts
  3357.  
  3358. ;*  case cpd: if (amode == immed)
  3359. ;*        amode = limmed; /* cpd */
  3360. ;*        if( amode == indy ) yflag = 1;
  3361. ;*        dogen(baseop,amode,page3,page3,page4);
  3362. ;*        return;
  3363.  
  3364. docpd:    ldaa    *amode
  3365.     cmpa    #immed
  3366.     bne    docpd1
  3367.     ldaa    #limmed
  3368.     staa    *amode
  3369. docpd1:    ldaa    *amode
  3370.     cmpa    #indy
  3371.     bne    docpd2
  3372.     inc    *yflag
  3373. docpd2:    ldaa    #page3
  3374.     staa    *pnorm
  3375.     staa    *px
  3376.     ldaa    #page4
  3377.     staa    *py
  3378.     jsr    dogen
  3379.     rts
  3380.  
  3381. ;*    case xnimm: if (amode == immed)    /* stx */
  3382. ;*            return("immediate mode illegal");
  3383.  
  3384. doxnoi:    ldaa    *amode
  3385.     cmpa    #immed
  3386.     bne    doxli
  3387.     ldaa    #0x1        ; "immediate mode illegal"
  3388.     rts
  3389.  
  3390. ;*    case xlimm: if (amode == immed)    /* cpx, ldx */
  3391. ;*            amode = limmed;
  3392. ;*        dogen(baseop,amode,page1,page1,page4);
  3393. ;*        return;
  3394.  
  3395. doxli:    ldaa    *amode
  3396.     cmpa    #immed
  3397.     bne    doxli1
  3398.     ldaa    #limmed
  3399.     staa    *amode
  3400. doxli1:    ldaa    #page1
  3401.     staa    *pnorm
  3402.     staa    *px
  3403.     ldaa    #page4
  3404.     staa    *py
  3405.     jsr    dogen
  3406.     rts
  3407.  
  3408. ;*    case ynimm: if (amode == immed)    /* sty */
  3409. ;*            return("immediate mode illegal");
  3410.  
  3411. doynoi:    ldaa    *amode
  3412.     cmpa    #immed
  3413.     bne    doyli
  3414.     ldaa    #0x1        ; "immediate mode illegal"
  3415.     rts
  3416.  
  3417. ;*    case ylimm: if (amode == indy) yflag = 1;/* cpy, ldy */
  3418. ;*        if(amode == immed) amode = limmed;
  3419. ;*        dogen(opcode,amode,page2,page3,page2);
  3420. ;*        return;
  3421.  
  3422. doyli:    ldaa    *amode
  3423.     cmpa    #indy
  3424.     bne    doyli1
  3425.     inc    *yflag
  3426. doyli1:    cmpa    #immed
  3427.     bne    doyli2
  3428.     ldaa    #limmed
  3429.     staa    *amode
  3430. doyli2:    ldaa    #page2
  3431.     staa    *pnorm
  3432.     staa    *py
  3433.     ldaa    #page3
  3434.     staa    *px
  3435.     jsr    dogen
  3436.     rts
  3437.  
  3438. ;*    case btb:        /* bset, bclr */
  3439. ;*    case setclr: a = bitop(baseop,amode,class);
  3440. ;*        if(a=0) return(a = 3);
  3441. ;*        if( amode == indy )
  3442. ;*            emit(page2);
  3443. ;*            amode = indx;
  3444.  
  3445. dobtb    = .
  3446. doset:    jsr    bitop
  3447.     cmpa    #0x00
  3448.     bne    doset1
  3449.     ldaa    #0x3        ; "illegal bit op"
  3450.     rts
  3451. doset1:    ldaa    *amode
  3452.     cmpa    #indy
  3453.     bne    doset2
  3454.     ldaa    #page2
  3455.     jsr    emit
  3456.     ldaa    #indx
  3457.     staa    *amode
  3458. doset2    = .
  3459.  
  3460. ;*        emit(baseop);
  3461. ;*        a = assarg();
  3462. ;*        if(a = 4) return(a);
  3463. ;*        emit(index offset);
  3464. ;*        if( amode == indx )
  3465. ;*            buffptr += 2;    /* skip ,x or ,y */
  3466.  
  3467.     ldaa    *baseop
  3468.     jsr    emit
  3469.     jsr    assarg
  3470.     cmpa    #0x04
  3471.     bne    doset22        ; jump if arg ok
  3472.     rts
  3473. doset22:
  3474.     ldaa    *shftreg+1    ; index offset
  3475.     jsr    emit
  3476.     ldaa    *amode
  3477.     cmpa    #indx
  3478.     bne    doset3
  3479.     jsr    incbuff
  3480.     jsr    incbuff
  3481. doset3    = .
  3482.  
  3483. ;*        a = assarg();
  3484. ;*        if(a = 4) return(a);
  3485. ;*        emit(mask);    /* mask */
  3486. ;*        if( class == setclr )
  3487. ;*            return;
  3488.  
  3489.     jsr    assarg
  3490.     cmpa    #0x04
  3491.     bne    doset33        ; jump if arg ok
  3492.     rts
  3493. doset33:
  3494.     ldaa    *shftreg+1    ; mask
  3495.     jsr    emit
  3496.     ldaa    *class
  3497.     cmpa    #setclr
  3498.     bne    doset4
  3499.     clra
  3500.     rts
  3501. doset4    = .
  3502.  
  3503. ;*        a = assarg();
  3504. ;*        if(a = 4) return(a);
  3505. ;*        d = (pc+1) - shftreg;
  3506. ;*        if (0x7f >= d >= 0xff82)
  3507. ;*            return (out of range);
  3508. ;*        emit(branch offset);
  3509. ;*        return(0);
  3510.  
  3511.     jsr    assarg
  3512.     cmpa    #0x04
  3513.     bne    doset5        ; jump if arg ok
  3514.     rts
  3515. doset5:    ldx    *pc         ; program counter
  3516.     inx            ; point to next inst
  3517.     stx    *braddr        ; save pc value
  3518.     ldd    *shftreg        ; get branch address
  3519.     subd    *braddr        ; calculate offset
  3520.     cmpd    #0x7f
  3521.     bls    doset6        ; jump if in range
  3522.     cmpd    #0xff80
  3523.     bhs    doset6        ; jump if in range
  3524.     clra
  3525.     jsr    emit
  3526.     ldaa    #0x09        ; 'out of range'
  3527.     rts
  3528. doset6:    tba            ; offset
  3529.     jsr    emit
  3530.     clra
  3531.     rts
  3532.  
  3533.  
  3534. ;**********
  3535. ;**    bitop(baseop,amode,class) --- adjust opcode on bit
  3536. ;**    manipulation instructions.  returns opcode in a
  3537. ;**    or a = 0 if error
  3538. ;**********
  3539. ;*if( amode == indx || amode == indy ) return(op);
  3540. ;*if( class == setclr ) return(op-8);
  3541. ;*else if(class==btb) return(op-12);
  3542. ;*else fatal("bitop");
  3543.  
  3544. bitop    = .
  3545.     ldaa    *amode
  3546.     ldab    *class
  3547.     cmpa    #indx
  3548.     bne    bitop1
  3549.     rts
  3550. bitop1:    cmpa    #indy
  3551.     bne    bitop2        ; jump not indexed
  3552.     rts
  3553. bitop2:    cmpb    #setclr
  3554.     bne    bitop3        ; jump not bset,bclr
  3555.     ldaa    *baseop        ; get opcode
  3556.     suba    #8
  3557.     staa    *baseop
  3558.     rts
  3559. bitop3:    cmpb    #btb
  3560.     bne    bitop4        ; jump not bit branch
  3561.     ldaa    *baseop        ; get opcode
  3562.     suba    #12
  3563.     staa    *baseop
  3564.     rts
  3565. bitop4:    clra            ; 0 = fatal bitop
  3566.     rts
  3567.  
  3568. ;**********
  3569. ;**    dogen(baseop,mode,pnorm,px,py) - process
  3570. ;** general addressing modes. returns a = error    #.
  3571. ;**********
  3572. ;*pnorm = page for normal addressing modes: imm,dir,ext
  3573. ;*px = page for indx addressing
  3574. ;*py = page for indy addressing
  3575. ;*switch(amode)
  3576. dogen:    ldaa    *amode
  3577.     cmpa    #limmed
  3578.     beq    doglim
  3579.     cmpa    #immed
  3580.     beq    dogimm
  3581.     cmpa    #indy
  3582.     beq    dogindy
  3583.     cmpa    #indx
  3584.     beq    dogindx
  3585.     cmpa    #other
  3586.     beq    dogoth
  3587.  
  3588. ;*default: error("unknown addressing mode");
  3589.  
  3590. dogdef:    ldaa    #0x06        ; unknown addre...
  3591.     rts
  3592.  
  3593. ;*case limmed: epage(pnorm);
  3594. ;*        emit(baseop);
  3595. ;*        a = assarg();
  3596. ;*        if(a = 4) return(a);
  3597. ;*        emit(2 bytes);
  3598. ;*        return(0);
  3599.  
  3600. doglim:    ldaa    *pnorm
  3601.     jsr    epage
  3602. doglim1:
  3603.     ldaa    *baseop
  3604.     jsr    emit
  3605.     jsr    assarg        ; get next argument
  3606.     cmpa    #0x04
  3607.     bne    doglim2        ; jump if arg ok
  3608.     rts
  3609. doglim2:
  3610.     ldd    *shftreg
  3611.     jsr    emit
  3612.     tba
  3613.     jsr    emit
  3614.     clra
  3615.     rts
  3616.  
  3617. ;*case immed: epage(pnorm);
  3618. ;*        emit(baseop);
  3619. ;*        a = assarg();
  3620. ;*        if(a = 4) return(a);
  3621. ;*        emit(lobyte);
  3622. ;*        return(0);
  3623.  
  3624. dogimm:    ldaa    *pnorm
  3625.     jsr    epage
  3626.     ldaa    *baseop
  3627.     jsr    emit
  3628.     jsr    assarg
  3629.     cmpa    #0x04
  3630.     bne    dogimm1        ; jump if arg ok
  3631.     rts
  3632. dogimm1:
  3633.     ldaa    *shftreg+1
  3634.     jsr    emit
  3635.     clra
  3636.     rts
  3637.  
  3638. ;*case indy: epage(py);
  3639. ;*        a=doindex(op+0x20);
  3640. ;*        return(a);
  3641.  
  3642. dogindy:
  3643.     ldaa    *py
  3644.     jsr    epage
  3645.     ldaa    *baseop
  3646.     adda    #0x20
  3647.     staa    *baseop
  3648.     jsr    doindex
  3649.     rts
  3650.  
  3651. ;*case indx: epage(px);
  3652. ;*        a=doindex(op+0x20);
  3653. ;*        return(a);
  3654.  
  3655. dogindx:
  3656.     ldaa    *px
  3657.     jsr    epage
  3658.     ldaa    *baseop
  3659.     adda    #0x20
  3660.     staa    *baseop
  3661.     jsr    doindex
  3662.     rts
  3663.  
  3664. ;*case other: a = assarg();
  3665. ;*        if(a = 4) return(a);
  3666. ;*        epage(pnorm);
  3667. ;*        if(countu1 <= 2 digits)    /* direct */
  3668. ;*        emit(op+0x10);
  3669. ;*        emit(lobyte(result));
  3670. ;*        return(0);
  3671. ;*        else    emit(op+0x30);    /* extended */
  3672. ;*        eword(result);
  3673. ;*        return(0)
  3674.  
  3675. dogoth:    jsr    assarg
  3676.     cmpa    #0x04
  3677.     bne    dogoth0        ; jump if arg ok
  3678.     rts
  3679. dogoth0:
  3680.     ldaa    *pnorm
  3681.     jsr    epage
  3682.     ldaa    *count
  3683.     cmpa    #0x2
  3684.     bgt    dogoth1
  3685.     ldaa    *baseop
  3686.     adda    #0x10        ; direct mode opcode
  3687.     jsr    emit
  3688.     ldaa    *shftreg+1
  3689.     jsr    emit
  3690.     clra
  3691.     rts
  3692. dogoth1:
  3693.     ldaa    *baseop
  3694.     adda    #0x30        ; extended mode opcode
  3695.     jsr    emit
  3696.     ldd    *shftreg
  3697.     jsr    emit
  3698.     tba
  3699.     jsr    emit
  3700.     clra
  3701.     rts
  3702.  
  3703. ;**********
  3704. ;**    doindex(op) --- handle all wierd stuff for
  3705. ;**    indexed addressing. returns a = error number.
  3706. ;**********
  3707. ;*emit(baseop);
  3708. ;*a=assarg();
  3709. ;*if(a = 4) return(a);
  3710. ;*if( a != ',' ) return("syntax");
  3711. ;*buffptr++
  3712. ;*a=readbuff()
  3713. ;*if( a != 'x' && != 'y') warn("ind addr assumed");
  3714. ;*emit(lobyte);
  3715. ;*return(0);
  3716.  
  3717. doindex:
  3718.     ldaa    *baseop
  3719.     jsr    emit
  3720.     jsr    assarg
  3721.     cmpa    #0x04
  3722.     bne    doindx0        ; jump if arg ok
  3723.     rts
  3724. doindx0:
  3725.     cmpa    #',
  3726.     beq    doindx1
  3727.     ldaa    #0x08        ; "syntax error"
  3728.     rts
  3729. doindx1:
  3730.     jsr    incbuff
  3731.     jsr    readbuff
  3732.     cmpa    #'Y
  3733.     beq    doindx2
  3734.     cmpa    #'X
  3735.     beq    doindx2
  3736.     ldx    msga7        ; "index addr assumed"
  3737.     jsr    outstrg
  3738. doindx2:
  3739.     ldaa    *shftreg+1
  3740.     jsr    emit
  3741.     clra
  3742.     rts
  3743.  
  3744. ;**********
  3745. ;**    assarg(); - get argument.    returns a = 4 if bad
  3746. ;** argument, else a = first non hex char.
  3747. ;**********
  3748. ;*a = buffarg()
  3749. ;*if(asschk(aa) && countu1 != 0) return(a);
  3750. ;*return(bad argument);
  3751.  
  3752. assarg:    jsr    buffarg
  3753.     jsr    asschek        ; check for command
  3754.     beq    assarg1        ; jump if ok
  3755.     jsr    wchek        ; check for whitespace
  3756.     bne    assarg2        ; jump if not ok
  3757. assarg1:
  3758.     tst    *count
  3759.     beq    assarg2        ; jump if no argument
  3760.     rts
  3761. assarg2:
  3762.     ldaa    #0x04        ; bad argument
  3763.     rts
  3764.  
  3765. ;**********
  3766. ;**  epage(a) --- emit page prebyte
  3767. ;**********
  3768. ;*if( a != page1 ) emit(a);
  3769.  
  3770. epage:    cmpa    #page1
  3771.     beq    epagrt        ; jump if page 1
  3772.     jsr    emit
  3773. epagrt:    rts
  3774.  
  3775. ;**********
  3776. ;*    emit(a) --- emit contents of a
  3777. ;**********
  3778. emit:    ldx    *pc
  3779.     staa    0,x
  3780.     jsr    out1bsp
  3781.     stx    *pc
  3782.     rts
  3783.  
  3784. ;*mnemonic table for hc11 line assembler
  3785. null    =    0x0        ; nothing
  3786. inh    =    0x1        ; inherent
  3787. p2inh    =    0x2        ; page 2 inherent
  3788. gen    =    0x3        ; general addressing
  3789. grp2    =    0x4        ; group 2
  3790. rel    =    0x5        ; relative
  3791. imm    =    0x6        ; immediate
  3792. nimm    =    0x7        ; general except for immediate
  3793. limm    =    0x8        ; 2 byte immediate
  3794. xlimm    =    0x9        ; longimm for x
  3795. xnimm    =    0x10        ; no immediate for x
  3796. ylimm    =    0x11        ; longimm for y
  3797. ynimm    =    0x12        ; no immediate for y
  3798. btb    =    0x13        ; bit test and branch
  3799. setclr    =    0x14        ; bit set or clear
  3800. cpd    =    0x15        ; compare d
  3801. btbd    =    0x16        ; bit test and branch direct
  3802. setclrd    =    0x17        ; bit set or clear direct
  3803.  
  3804. ;**********
  3805. ;*    mnetabl - includes all '11 mnemonics, base opcodes,
  3806. ;* and type of instruction.  the assembler search routine
  3807. ;*depends on 4 characters for each mnemonic so that 3 char
  3808. ;*mnemonics are extended with a space and 5 char mnemonics
  3809. ;*are truncated.
  3810. ;**********
  3811.  
  3812. mnetabl    = .
  3813.     .ascii    'ABA '        ; mnemonic
  3814.     .byte    0x1b        ; base opcode
  3815.     .byte    inh        ; class
  3816.     .ascii    'ABX '
  3817.     .byte    0x3a
  3818.     .byte    inh
  3819.     .ascii    'ABY '
  3820.     .byte    0x3a
  3821.     .byte    p2inh
  3822.     .ascii    'ADCA'
  3823.     .byte    0x89
  3824.     .byte    gen
  3825.     .ascii    'ADCB'
  3826.     .byte    0xc9
  3827.     .byte    gen
  3828.     .ascii    'ADDA'
  3829.     .byte    0x8b
  3830.     .byte    gen
  3831.     .ascii    'ADDB'
  3832.     .byte    0xcb
  3833.     .byte    gen
  3834.     .ascii    'ADDD'
  3835.     .byte    0xc3
  3836.     .byte    limm
  3837.     .ascii    'ANDA'
  3838.     .byte    0x84
  3839.     .byte    gen
  3840.     .ascii    'ANDB'
  3841.     .byte    0xc4
  3842.     .byte    gen
  3843.     .ascii    'ASL '
  3844.     .byte    0x68
  3845.     .byte    grp2
  3846.     .ascii    'ASLA'
  3847.     .byte    0x48
  3848.     .byte    inh
  3849.     .ascii    'ASLB'
  3850.     .byte    0x58
  3851.     .byte    inh
  3852.     .ascii    'ASLD'
  3853.     .byte    0x05
  3854.     .byte    inh
  3855.     .ascii    'ASR '
  3856.     .byte    0x67
  3857.     .byte    grp2
  3858.     .ascii    'ASRA'
  3859.     .byte    0x47
  3860.     .byte    inh
  3861.     .ascii    'ASRB'
  3862.     .byte    0x57
  3863.     .byte    inh
  3864.     .ascii    'BCC '
  3865.     .byte    0x24
  3866.     .byte    rel
  3867.     .ascii    'BCLR'
  3868.     .byte    0x1d
  3869.     .byte    setclr
  3870.     .ascii    'BCS '
  3871.     .byte    0x25
  3872.     .byte    rel
  3873.     .ascii    'BEQ '
  3874.     .byte    0x27
  3875.     .byte    rel
  3876.     .ascii    'BGE '
  3877.     .byte    0x2c
  3878.     .byte    rel
  3879.     .ascii    'BGT '
  3880.     .byte    0x2e
  3881.     .byte    rel
  3882.     .ascii    'BHI '
  3883.     .byte    0x22
  3884.     .byte    rel
  3885.     .ascii    'BHS '
  3886.     .byte    0x24
  3887.     .byte    rel
  3888.     .ascii    'BITA'
  3889.     .byte    0x85
  3890.     .byte    gen
  3891.     .ascii    'BITB'
  3892.     .byte    0xc5
  3893.     .byte    gen
  3894.     .ascii    'BLE '
  3895.     .byte    0x2f
  3896.     .byte    rel
  3897.     .ascii    'BLO '
  3898.     .byte    0x25
  3899.     .byte    rel
  3900.     .ascii    'BLS '
  3901.     .byte    0x23
  3902.     .byte    rel
  3903.     .ascii    'BLT '
  3904.     .byte    0x2d
  3905.     .byte    rel
  3906.     .ascii    'BMI '
  3907.     .byte    0x2b
  3908.     .byte    rel
  3909.     .ascii    'BNE '
  3910.     .byte    0x26
  3911.     .byte    rel
  3912.     .ascii    'BPL '
  3913.     .byte    0x2a
  3914.     .byte    rel
  3915.     .ascii    'BRA '
  3916.     .byte    0x20
  3917.     .byte    rel
  3918.     .ascii    'BRCL'        ; (brclr)
  3919.     .byte    0x1f
  3920.     .byte    btb
  3921.     .ascii    'BRN '
  3922.     .byte    0x21
  3923.     .byte    rel
  3924.     .ascii    'BRSE'        ; (brset)
  3925.     .byte    0x1e
  3926.     .byte    btb
  3927.     .ascii    'BSET'
  3928.     .byte    0x1c
  3929.     .byte    setclr
  3930.     .ascii    'BSR '
  3931.     .byte    0x8d
  3932.     .byte    rel
  3933.     .ascii    'BVC '
  3934.     .byte    0x28
  3935.     .byte    rel
  3936.     .ascii    'BVS '
  3937.     .byte    0x29
  3938.     .byte    rel
  3939.     .ascii    'CBA '
  3940.     .byte    0x11
  3941.     .byte    inh
  3942.     .ascii    'CLC '
  3943.     .byte    0x0c
  3944.     .byte    inh
  3945.     .ascii    'CLI '
  3946.     .byte    0x0e
  3947.     .byte    inh
  3948.     .ascii    'CLR '
  3949.     .byte    0x6f
  3950.     .byte    grp2
  3951.     .ascii    'CLRA'
  3952.     .byte    0x4f
  3953.     .byte    inh
  3954.     .ascii    'CLRB'
  3955.     .byte    0x5f
  3956.     .byte    inh
  3957.     .ascii    'CLV '
  3958.     .byte    0x0a
  3959.     .byte    inh
  3960.     .ascii    'CMPA'
  3961.     .byte    0x81
  3962.     .byte    gen
  3963.     .ascii    'CMPB'
  3964.     .byte    0xc1
  3965.     .byte    gen
  3966.     .ascii    'COM '
  3967.     .byte    0x63
  3968.     .byte    grp2
  3969.     .ascii    'COMA'
  3970.     .byte    0x43
  3971.     .byte    inh
  3972.     .ascii    'COMB'
  3973.     .byte    0x53
  3974.     .byte    inh
  3975.     .ascii    'CPD '
  3976.     .byte    0x83
  3977.     .byte    cpd
  3978.     .ascii    'CPX '
  3979.     .byte    0x8c
  3980.     .byte    xlimm
  3981.     .ascii    'CPY '
  3982.     .byte    0x8c
  3983.     .byte    ylimm
  3984.     .ascii    'DAA '
  3985.     .byte    0x19
  3986.     .byte    inh
  3987.     .ascii    'DEC '
  3988.     .byte    0x6a
  3989.     .byte    grp2
  3990.     .ascii    'DECA'
  3991.     .byte    0x4a
  3992.     .byte    inh
  3993.     .ascii    'DECB'
  3994.     .byte    0x5a
  3995.     .byte    inh
  3996.     .ascii    'DES '
  3997.     .byte    0x34
  3998.     .byte    inh
  3999.     .ascii    'DEX '
  4000.     .byte    0x09
  4001.     .byte    inh
  4002.     .ascii    'DEY '
  4003.     .byte    0x09
  4004.     .byte    p2inh
  4005.     .ascii    'EORA'
  4006.     .byte    0x88
  4007.     .byte    gen
  4008.     .ascii    'EORB'
  4009.     .byte    0xc8
  4010.     .byte    gen
  4011.     .ascii    'FDIV'
  4012.     .byte    0x03
  4013.     .byte    inh
  4014.     .ascii    'IDIV'
  4015.     .byte    0x02
  4016.     .byte    inh
  4017.     .ascii    'INC '
  4018.     .byte    0x6c
  4019.     .byte    grp2
  4020.     .ascii    'INCA'
  4021.     .byte    0x4c
  4022.     .byte    inh
  4023.     .ascii    'INCB'
  4024.     .byte    0x5c
  4025.     .byte    inh
  4026.     .ascii    'INS '
  4027.     .byte    0x31
  4028.     .byte    inh
  4029.     .ascii    'INX '
  4030.     .byte    0x08
  4031.     .byte    inh
  4032.     .ascii    'INY '
  4033.     .byte    0x08
  4034.     .byte    p2inh
  4035.     .ascii    'JMP '
  4036.     .byte    0x6e
  4037.     .byte    grp2
  4038.     .ascii    'JSR '
  4039.     .byte    0x8d
  4040.     .byte    nimm
  4041.     .ascii    'LDAA'
  4042.     .byte    0x86
  4043.     .byte    gen
  4044.     .ascii    'LDAB'
  4045.     .byte    0xc6
  4046.     .byte    gen
  4047.     .ascii    'LDD '
  4048.     .byte    0xcc
  4049.     .byte    limm
  4050.     .ascii    'LDS '
  4051.     .byte    0x8e
  4052.     .byte    limm
  4053.     .ascii    'LDX '
  4054.     .byte    0xce
  4055.     .byte    xlimm
  4056.     .ascii    'LDY '
  4057.     .byte    0xce
  4058.     .byte    ylimm
  4059.     .ascii    'LSL '
  4060.     .byte    0x68
  4061.     .byte    grp2
  4062.     .ascii    'LSLA'
  4063.     .byte    0x48
  4064.     .byte    inh
  4065.     .ascii    'LSLB'
  4066.     .byte    0x58
  4067.     .byte    inh
  4068.     .ascii    'LSLD'
  4069.     .byte    0x05
  4070.     .byte    inh
  4071.     .ascii    'LSR '
  4072.     .byte    0x64
  4073.     .byte    grp2
  4074.     .ascii    'LSRA'
  4075.     .byte    0x44
  4076.     .byte    inh
  4077.     .ascii    'LSRB'
  4078.     .byte    0x54
  4079.     .byte    inh
  4080.     .ascii    'LSRD'
  4081.     .byte    0x04
  4082.     .byte    inh
  4083.     .ascii    'MUL '
  4084.     .byte    0x3d
  4085.     .byte    inh
  4086.     .ascii    'NEG '
  4087.     .byte    0x60
  4088.     .byte    grp2
  4089.     .ascii    'NEGA'
  4090.     .byte    0x40
  4091.     .byte    inh
  4092.     .ascii    'NEGB'
  4093.     .byte    0x50
  4094.     .byte    inh
  4095.     .ascii    'NOP '
  4096.     .byte    0x01
  4097.     .byte    inh
  4098.     .ascii    'ORAA'
  4099.     .byte    0x8a
  4100.     .byte    gen
  4101.     .ascii    'ORAB'
  4102.     .byte    0xca
  4103.     .byte    gen
  4104.     .ascii    'PSHA'
  4105.     .byte    0x36
  4106.     .byte    inh
  4107.     .ascii    'PSHB'
  4108.     .byte    0x37
  4109.     .byte    inh
  4110.     .ascii    'PSHX'
  4111.     .byte    0x3c
  4112.     .byte    inh
  4113.     .ascii    'PSHY'
  4114.     .byte    0x3c
  4115.     .byte    p2inh
  4116.     .ascii    'PULA'
  4117.     .byte    0x32
  4118.     .byte    inh
  4119.     .ascii    'PULB'
  4120.     .byte    0x33
  4121.     .byte    inh
  4122.     .ascii    'PULX'
  4123.     .byte    0x38
  4124.     .byte    inh
  4125.     .ascii    'PULY'
  4126.     .byte    0x38
  4127.     .byte    p2inh
  4128.     .ascii    'ROL '
  4129.     .byte    0x69
  4130.     .byte    grp2
  4131.     .ascii    'ROLA'
  4132.     .byte    0x49
  4133.     .byte    inh
  4134.     .ascii    'ROLB'
  4135.     .byte    0x59
  4136.     .byte    inh
  4137.     .ascii    'ROR '
  4138.     .byte    0x66
  4139.     .byte    grp2
  4140.     .ascii    'RORA'
  4141.     .byte    0x46
  4142.     .byte    inh
  4143.     .ascii    'RORB'
  4144.     .byte    0x56
  4145.     .byte    inh
  4146.     .ascii    'RTI '
  4147.     .byte    0x3b
  4148.     .byte    inh
  4149.     .ascii    'RTS '
  4150.     .byte    0x39
  4151.     .byte    inh
  4152.     .ascii    'SBA '
  4153.     .byte    0x10
  4154.     .byte    inh
  4155.     .ascii    'SBCA'
  4156.     .byte    0x82
  4157.     .byte    gen
  4158.     .ascii    'SBCB'
  4159.     .byte    0xc2
  4160.     .byte    gen
  4161.     .ascii    'SEC '
  4162.     .byte    0x0d
  4163.     .byte    inh
  4164.     .ascii    'SEI '
  4165.     .byte    0x0f
  4166.     .byte    inh
  4167.     .ascii    'SEV '
  4168.     .byte    0x0b
  4169.     .byte    inh
  4170.     .ascii    'STAA'
  4171.     .byte    0x87
  4172.     .byte    nimm
  4173.     .ascii    'STAB'
  4174.     .byte    0xc7
  4175.     .byte    nimm
  4176.     .ascii    'STD '
  4177.     .byte    0xcd
  4178.     .byte    nimm
  4179.     .ascii    'STOP'
  4180.     .byte    0xcf
  4181.     .byte    inh
  4182.     .ascii    'STS '
  4183.     .byte    0x8f
  4184.     .byte    nimm
  4185.     .ascii    'STX '
  4186.     .byte    0xcf
  4187.     .byte    xnimm
  4188.     .ascii    'STY '
  4189.     .byte    0xcf
  4190.     .byte    ynimm
  4191.     .ascii    'SUBA'
  4192.     .byte    0x80
  4193.     .byte    gen
  4194.     .ascii    'SUBB'
  4195.     .byte    0xc0
  4196.     .byte    gen
  4197.     .ascii    'SUBD'
  4198.     .byte    0x83
  4199.     .byte    limm
  4200.     .ascii    'SWI '
  4201.     .byte    0x3f
  4202.     .byte    inh
  4203.     .ascii    'TAB '
  4204.     .byte    0x16
  4205.     .byte    inh
  4206.     .ascii    'TAP '
  4207.     .byte    0x06
  4208.     .byte    inh
  4209.     .ascii    'TBA '
  4210.     .byte    0x17
  4211.     .byte    inh
  4212.     .ascii    'TPA '
  4213.     .byte    0x07
  4214.     .byte    inh
  4215.     .ascii    'TEST'
  4216.     .byte    0x00
  4217.     .byte    inh
  4218.     .ascii    'TST '
  4219.     .byte    0x6d
  4220.     .byte    grp2
  4221.     .ascii    'TSTA'
  4222.     .byte    0x4d
  4223.     .byte    inh
  4224.     .ascii    'TSTB'
  4225.     .byte    0x5d
  4226.     .byte    inh
  4227.     .ascii    'TSX '
  4228.     .byte    0x30
  4229.     .byte    inh
  4230.     .ascii    'TSY '
  4231.     .byte    0x30
  4232.     .byte    p2inh
  4233.     .ascii    'TXS '
  4234.     .byte    0x35
  4235.     .byte    inh
  4236.     .ascii    'TYS '
  4237.     .byte    0x35
  4238.     .byte    p2inh
  4239.     .ascii    'WAI '
  4240.     .byte    0x3e
  4241.     .byte    inh
  4242.     .ascii    'XGDX'
  4243.     .byte    0x8f
  4244.     .byte    inh
  4245.     .ascii    'XGDY'
  4246.     .byte    0x8f
  4247.     .byte    p2inh
  4248.     .ascii    'BRSE'        ; bit direct modes for
  4249.     .byte    0x12        ; disassembler.
  4250.     .byte    btbd
  4251.     .ascii    'BRCL'
  4252.     .byte    0x13
  4253.     .byte    btbd
  4254.     .ascii    'BSET'
  4255.     .byte    0x14
  4256.     .byte    setclrd
  4257.     .ascii    'BCLR'
  4258.     .byte    0x15
  4259.     .byte    setclrd
  4260.     .byte    eot        ; end of table
  4261.  
  4262. ;**********************************************
  4263. pg1    =    0x0
  4264. pg2    =    0x1
  4265. pg3    =    0x2
  4266. pg4    =    0x3
  4267.  
  4268. ;******************
  4269. ;*disassem() - disassemble the opcode.
  4270. ;******************
  4271. ;*(check for page prebyte)
  4272. ;*baseop=pc[0];
  4273. ;*pnorm=pg1;
  4274. ;*if(baseop==0x18) pnorm=pg2;
  4275. ;*if(baseop==0x1a) pnorm=pg3;
  4276. ;*if(baseop==0xcd) pnorm=pg4;
  4277. ;*if(pnorm != pg1) dispc=pc+1;
  4278. ;*else dispc=pc; (dispc points to next byte)
  4279.  
  4280. disassm    = .
  4281.     ldx    *pc         ; address
  4282.     ldaa    0,x        ; opcode
  4283.     ldab    #pg1
  4284.     cmpa    #0x18
  4285.     beq    disp2        ; jump if page2
  4286.     cmpa    #0x1a
  4287.     beq    disp3        ; jump if page3
  4288.     cmpa    #0xcd
  4289.     bne    disp1        ; jump if not page4
  4290. disp4:    incb            ; set up page value
  4291. disp3:    incb
  4292. disp2:    incb
  4293.     inx
  4294. disp1:    stx    *dispc        ; point to opcode
  4295.     stab    *pnorm        ; save page
  4296.  
  4297. ;*if(opcode == (0x00-0x5f or 0x8d or 0x8f or 0xcf))
  4298. ;*    if(pnorm == (pg3 or pg4))
  4299. ;*    disillop(); return();
  4300. ;*  b=disrch(opcode,null);
  4301. ;*  if(b==0) disillop(); return();
  4302.  
  4303.     ldaa    0,x        ; get current opcode
  4304.     staa    *baseop
  4305.     inx
  4306.     stx    *dispc        ; point to next byte
  4307.     cmpa    #0x5f
  4308.     bls    dis1        ; jump if in range
  4309.     cmpa    #0x8d
  4310.     beq    dis1        ; jump if bsr
  4311.     cmpa    #0x8f
  4312.     beq    dis1        ; jump if xgdx
  4313.     cmpa    #0xcf
  4314.     beq    dis1        ; jump if stop
  4315.     jmp    disgrp        ; try next part of map
  4316. dis1:    ldab    *pnorm
  4317.     cmpb    #pg3
  4318.     blo    dis2        ; jump if page 1 or 2
  4319.     jsr    disillop    ; "illegal opcode"
  4320.     rts
  4321. dis2:    ldab    *baseop        ; opcode
  4322.     clrb            ; class=null
  4323.     jsr    disrch
  4324.     tstb
  4325.     bne    dispec        ; jump if opcode found
  4326.     jsr    disillop    ; "illegal opcode"
  4327.     rts
  4328.  
  4329. ;*    if(opcode==0x8d) dissrch(opcode,rel);
  4330. ;*    if(opcode==(0x8f or 0xcf)) disrch(opcode,inh);
  4331.  
  4332. dispec:    ldaa    *baseop
  4333.     cmpa    #0x8d
  4334.     bne    dispec1
  4335.     ldab    #rel
  4336.     bra    dispec3        ; look for bsr opcode
  4337. dispec1:
  4338.     cmpa    #0x8f
  4339.     beq    dispec2        ; jump if xgdx opcode
  4340.     cmpa    #0xcf
  4341.     bne    disinh        ; jump not stop opcode
  4342. dispec2:
  4343.     ldab    #inh
  4344. dispec3:
  4345.     jsr    disrch        ; find other entry in table
  4346.  
  4347. ;*    if(class==inh)        /* inh */
  4348. ;*    if(pnorm==pg2)
  4349. ;*    b=disrch(baseop,p2inh);
  4350. ;*    if(b==0) disillop(); return();
  4351. ;*    prntmne();
  4352. ;*    return();
  4353.  
  4354. disinh    = .
  4355.     ldab    *class
  4356.     cmpb    #inh
  4357.     bne    disrel        ; jump if not inherent
  4358.     ldab    *pnorm
  4359.     cmpb    #pg1
  4360.     beq    disinh1        ; jump if page1
  4361.     ldaa    *baseop        ; get opcode
  4362.     ldab    #p2inh        ; class=p2inh
  4363.     jsr    disrch
  4364.     tstb
  4365.     bne    disinh1        ; jump if found
  4366.     jsr    disillop    ; "illegal opcode"
  4367.     rts
  4368. disinh1:
  4369.     jsr    prntmne
  4370.     rts
  4371.  
  4372. ;*    elseif(class=rel)        /* rel */
  4373. ;*    if(pnorm != pg1)
  4374. ;*    disillop(); return();
  4375. ;*    prntmne();
  4376. ;*    disrelad();
  4377. ;*    return();
  4378.  
  4379. disrel    = .
  4380.     ldab    *class
  4381.     cmpb    #rel
  4382.     bne    disbtd
  4383.     tst    *pnorm
  4384.     beq    disrel1        ; jump if page1
  4385.     jsr    disillop    ; "illegal opcode"
  4386.     rts
  4387. disrel1:
  4388.     jsr    prntmne        ; output mnemonic
  4389.     jsr    disrelad    ; compute relative address
  4390.     rts
  4391.  
  4392. ;*    else        /* setclr,setclrd,btb,btbd */
  4393. ;*    if(class == (setclrd or btbd))
  4394. ;*        if(pnorm != pg1)
  4395. ;*        disillop(); return();    /* illop */
  4396. ;*        prntmne();        /* direct */
  4397. ;*        disdir();        /* output 0xbyte */
  4398. ;*    else (class == (setclr or btb))
  4399. ;*        prntmne();        /* indexed */
  4400. ;*        disindx();
  4401. ;*    outspac();
  4402. ;*    disdir();
  4403. ;*    outspac();
  4404. ;*    if(class == (btb or btbd))
  4405. ;*        disrelad();
  4406. ;*    return();
  4407.  
  4408. disbtd    = .
  4409.     ldab    *class
  4410.     cmpb    #setclrd
  4411.     beq    disbtd1
  4412.     cmpb    #btbd
  4413.     bne    disbit        ; jump not direct bitop
  4414. disbtd1:
  4415.     tst    *pnorm
  4416.     beq    disbtd2        ; jump if page 1
  4417.     jsr    disillop
  4418.     rts
  4419. disbtd2:
  4420.     jsr    prntmne
  4421.     jsr    disdir        ; operand(direct)
  4422.     bra    disbit1
  4423. disbit    = .
  4424.     jsr    prntmne
  4425.     jsr    disindx        ; operand(indexed)
  4426. disbit1:
  4427.     jsr    outspac
  4428.     jsr    disdir        ; mask
  4429.     ldab    *class
  4430.     cmpb    #btb
  4431.     beq    disbit2        ; jump if btb
  4432.     cmpb    #btbd
  4433.     bne    disbit3        ; jump if not bit branch
  4434. disbit2:
  4435.     jsr    disrelad    ; relative address
  4436. disbit3:
  4437.     rts
  4438.  
  4439.  
  4440. ;*elseif(0x60 <= opcode <= 0x7f)  /*  grp2 */
  4441. ;*    if(pnorm == (pg3 or pg4))
  4442. ;*    disillop(); return();
  4443. ;*    if((pnorm==pg2) and (opcode != 0x6x))
  4444. ;*    disillop(); return();
  4445. ;*    b=disrch(baseop & 0x6f,null);
  4446. ;*    if(b==0) disillop(); return();
  4447. ;*    prntmne();
  4448. ;*    if(opcode == 0x6x)
  4449. ;*    disindx();
  4450. ;*    else
  4451. ;*    disext();
  4452. ;*    return();
  4453.  
  4454. disgrp    = .
  4455.     cmpa    #0x7f        ; a=opcode
  4456.     bhi    disnext        ; try next part of map
  4457.     ldab    *pnorm
  4458.     cmpb    #pg3
  4459.     blo    disgrp2        ; jump if page 1 or 2
  4460.     jsr    disillop    ; "illegal opcode"
  4461.     rts
  4462. disgrp2:
  4463.     anda    #0x6f        ; mask bit 4
  4464.     clrb            ; class=null
  4465.     jsr    disrch
  4466.     tstb
  4467.     bne    disgrp3        ; jump if found
  4468.     jsr    disillop    ; "illegal opcode"
  4469.     rts
  4470. disgrp3:
  4471.     jsr    prntmne
  4472.     ldaa    *baseop        ; get opcode
  4473.     anda    #0xf0
  4474.     cmpa    #0x60
  4475.     bne    disgrp4        ; jump if not 6x
  4476.     jsr    disindx        ; operand(indexed)
  4477.     rts
  4478. disgrp4:
  4479.     jsr    disext        ; operand(extended)
  4480.     rts
  4481.  
  4482. ;*else    (0x80 <= opcode <= 0xff)
  4483. ;*    if(opcode == (0x87 or 0xc7))
  4484. ;*    disillop(); return();
  4485. ;*    b=disrch(opcode&0xcf,null);
  4486. ;*    if(b==0) disillop(); return();
  4487.  
  4488. disnext    = .
  4489.     cmpa    #0x87        ; a=opcode
  4490.     beq    disnex1
  4491.     cmpa    #0xc7
  4492.     bne    disnex2
  4493. disnex1:
  4494.     jsr    disillop    ; "illegal opcode"
  4495.     rts
  4496. disnex2:
  4497.     anda    #0xcf
  4498.     clrb            ; class=null
  4499.     jsr    disrch
  4500.     tstb
  4501.     bne    disnew        ; jump if mne found
  4502.     jsr    disillop    ; "illegal opcode"
  4503.     rts
  4504.  
  4505. ;*    if(opcode&0xcf==0x8d) disrch(baseop,nimm; (jsr)
  4506. ;*    if(opcode&0xcf==0x8f) disrch(baseop,nimm; (sts)
  4507. ;*    if(opcode&0xcf==0xcf) disrch(baseop,xnimm; (stx)
  4508. ;*    if(opcode&0xcf==0x83) disrch(baseop,limm); (subd)
  4509.  
  4510. disnew:    ldaa    *baseop
  4511.     anda    #0xcf
  4512.     cmpa    #0x8d
  4513.     bne    disnew1        ; jump not jsr
  4514.     ldab    #nimm
  4515.     bra    disnew4
  4516. disnew1:
  4517.     cmpa    #0x8f
  4518.     bne    disnew2        ; jump not sts
  4519.     ldab    #nimm
  4520.     bra    disnew4
  4521. disnew2:
  4522.     cmpa    #0xcf
  4523.     bne    disnew3        ; jump not stx
  4524.     ldab    #xnimm
  4525.     bra    disnew4
  4526. disnew3:
  4527.     cmpa    #0x83
  4528.     bne    disgen        ; jump not subd
  4529.     ldab    #limm
  4530. disnew4:
  4531.     jsr    disrch
  4532.     tstb
  4533.     bne    disgen        ; jump if found
  4534.     jsr    disillop    ; "illegal opcode"
  4535.     rts
  4536.  
  4537. ;*    if(class == (gen or nimm or limm    ))    /* gen,nimm,limm,cpd */
  4538. ;*    if(opcode&0xcf==0x83)
  4539. ;*        if(pnorm==(pg3 or pg4)) disrch(opcode#0xcf,cpd)
  4540. ;*        class=limm;
  4541. ;*    if((pnorm == (pg2 or pg4) and (opcode != (0xax or 0xex)))
  4542. ;*        disillop(); return();
  4543. ;*    disgenrl();
  4544. ;*    return();
  4545.  
  4546. disgen:    ldab    *class        ; get class
  4547.     cmpb    #gen
  4548.     beq    disgen1
  4549.     cmpb    #nimm
  4550.     beq    disgen1
  4551.     cmpb    #limm
  4552.     bne    disxln        ; jump if other class
  4553. disgen1:
  4554.     ldaa    *baseop
  4555.     anda    #0xcf
  4556.     cmpa    #0x83
  4557.     bne    disgen3        ; jump if not    #0x83
  4558.     ldab    *pnorm
  4559.     cmpb    #pg3
  4560.     blo    disgen3        ; jump not pg3 or 4
  4561.     ldab    #cpd
  4562.     jsr    disrch        ; look for cpd mne
  4563.     ldab    #limm
  4564.     stab    *class        ; set class to limm
  4565. disgen3:
  4566.     ldab    *pnorm
  4567.     cmpb    #pg2
  4568.     beq    disgen4        ; jump if page 2
  4569.     cmpb    #pg4
  4570.     bne    #disgen5    ; jump not page 2 or 4
  4571. disgen4:
  4572.     ldaa    *baseop
  4573.     anda    #0xb0        ; mask bits 6,3-0
  4574.     cmpa    #0xa0
  4575.     beq    disgen5        ; jump if 0xax or 0xex
  4576.     jsr    disillop    ; "illegal opcode"
  4577.     rts
  4578. disgen5:
  4579.     jsr    disgenrl    ; process general class
  4580.     rts
  4581.  
  4582. ;*    else    /* xlimm,xnimm,ylimm,ynimm */
  4583. ;*    if(pnorm==(pg2 or pg3))
  4584. ;*    if(class==xlimm) disrch(opcode&0xcf,ylimm);
  4585. ;*    else disrch(opcode&0xcf,ynimm);
  4586. ;*    if((pnorm == (pg3 or pg4))
  4587. ;*    if(opcode != (0xax or 0xex))
  4588. ;*        disillop(); return();
  4589. ;*    class=limm;
  4590. ;*    disgen();
  4591. ;*    return();
  4592.  
  4593. disxln:    ldab    *pnorm
  4594.     cmpb    #pg2
  4595.     beq    disxln1        ; jump if page2
  4596.     cmpb    #pg3
  4597.     bne    disxln4        ; jump not page3
  4598. disxln1:
  4599.     ldaa    *baseop
  4600.     anda    #0xcf
  4601.     ldab    *class
  4602.     cmpb    #xlimm
  4603.     bne    disxln2
  4604.     ldab    #ylimm
  4605.     bra    disxln3        ; look for ylimm
  4606. disxln2:
  4607.     ldab    #ynimm        ; look for ynimm
  4608. disxln3:
  4609.     jsr    disrch
  4610. disxln4:
  4611.     ldab    *pnorm
  4612.     cmpb    #pg3
  4613.     blo    disxln5        ; jump if page 1 or 2
  4614.     ldaa    *baseop        ; get opcode
  4615.     anda    #0xb0        ; mask bits 6,3-0
  4616.     cmpa    #0xa0
  4617.     beq    disxln5        ; jump opcode = 0xax or 0xex
  4618.     jsr    disillop    ; "illegal opcode"
  4619.     rts
  4620. disxln5:
  4621.     ldab    #limm
  4622.     stab    *class
  4623.     jsr    disgenrl    ; process general class
  4624.     rts
  4625.  
  4626.  
  4627. ;******************
  4628. ;*disrch(a=opcode,b=class)
  4629. ;*return b=0 if not found
  4630. ;*    else mneptr=points to mnemonic
  4631. ;*    class=class of opcode
  4632. ;******************
  4633. ;*x=#mnetabl
  4634. ;*while(x[0] != eot)
  4635. ;*    if((opcode==x[4]) && ((class=null) || (class=x[5])))
  4636. ;*    mneptr=x;
  4637. ;*    class=x[5];
  4638. ;*    return(1);
  4639. ;*    x += 6;
  4640. ;*return(0);    /* not found */
  4641.  
  4642. disrch    = .
  4643.     ldx    #mnetabl    ; point to top of table
  4644. disrch1:
  4645.     cmpa    4,x        ; test opcode
  4646.     bne    disrch3        ; jump not this entry
  4647.     tstb
  4648.     beq    disrch2        ; jump if class=null
  4649.     cmpb    5,x        ; test class
  4650.     bne    disrch3        ; jump not this entry
  4651. disrch2:
  4652.     ldab    5,x
  4653.     stab    *class
  4654.     stx    *mneptr        ; return ptr to mnemonic
  4655.     incb
  4656.     rts            ; return found
  4657. disrch3:
  4658.     pshb            ; save class
  4659.     ldab    #6
  4660.     abx
  4661.     ldab    0,x
  4662.     cmpb    #eot        ; test end of table
  4663.     pulb
  4664.     bne    disrch1
  4665.     clrb
  4666.     rts            ; return not found
  4667.  
  4668. ;******************
  4669. ;*prntmne() - output the mnemonic pointed
  4670. ;*at by mneptr.
  4671. ;******************
  4672. ;*outa(mneptr[0-3]);
  4673. ;*outspac;
  4674. ;*return();
  4675.  
  4676. prntmne    = .
  4677.     ldx    *mneptr
  4678.     ldaa    0,x
  4679.     jsr    outa        ; output char1
  4680.     ldaa    1,x
  4681.     jsr    outa        ; output char2
  4682.     ldaa    2,x
  4683.     jsr    outa        ; output char3
  4684.     ldaa    3,x
  4685.     jsr    outa        ; output char4
  4686.     jsr    outspac
  4687.     rts
  4688.  
  4689. ;******************
  4690. ;*disindx() - process indexed mode
  4691. ;******************
  4692. ;*disdir();
  4693. ;*outa(',');
  4694. ;*if(pnorm == (pg2 or pg4)) outa('y');
  4695. ;*else outa('x');
  4696. ;*return();
  4697.  
  4698. disindx    = .
  4699.     jsr    disdir        ; output 0xbyte
  4700.     ldaa    #',
  4701.     jsr    outa        ; output ,
  4702.     ldab    *pnorm
  4703.     cmpb    #pg2
  4704.     beq    disind1        ; jump if page2
  4705.     cmpb    #pg4
  4706.     bne    disind2        ; jump if not page4
  4707. disind1:
  4708.     ldaa    #'Y
  4709.     bra disind3
  4710. disind2:
  4711.     ldaa    #'X
  4712. disind3:
  4713.     jsr    outa        ; output x or y
  4714.     rts
  4715.  
  4716. ;******************
  4717. ;*disrelad() - compute and output relative address.
  4718. ;******************
  4719. ;* braddr = dispc[0] + (dispc++);( 2's comp arith)
  4720. ;*outa('$');
  4721. ;*out2bsp(braddr);
  4722. ;*return();
  4723.  
  4724. disrelad    = .
  4725.     ldx    *dispc
  4726.     ldab    0,x        ; get relative offset
  4727.     inx
  4728.     stx    *dispc
  4729.     tstb
  4730.     bmi    disrld1        ; jump if negative
  4731.     abx
  4732.     bra    disrld2
  4733. disrld1:
  4734.     dex
  4735.     incb
  4736.     bne    disrld1        ; subtract
  4737. disrld2:
  4738.     stx    *braddr        ; save address
  4739.     jsr    outspac
  4740.     ldaa    #'$
  4741.     jsr    outa
  4742.     ldx    #braddr
  4743.     jsr    out2bsp        ; output address
  4744.     rts
  4745.  
  4746.  
  4747. ;******************
  4748. ;*disgenrl() - output data for the general cases which
  4749. ;*includes immediate, direct, indexed, and extended modes.
  4750. ;******************
  4751. ;*prntmne();
  4752. ;*if(baseop == (0x8x or 0xcx))    /* immediate */
  4753. ;*    outa('#');
  4754. ;*    disdir();
  4755. ;*    if(class == limm)
  4756. ;*    out1byt(dispc++);
  4757. ;*elseif(baseop == (0x9x or 0xdx))    /* direct */
  4758. ;*    disdir();
  4759. ;*elseif(baseop == (0xax or 0xex)) /* indexed */
  4760. ;*    disindx();
  4761. ;*else    (baseop == (0xbx or 0xfx)) /* extended */
  4762. ;*    disext();
  4763. ;*return();
  4764.  
  4765. disgenrl    = .
  4766.     jsr    prntmne        ; print mnemonic
  4767.     ldaa    *baseop        ; get opcode
  4768.     anda    #0xb0        ; mask bits 6,3-0
  4769.     cmpa    #0x80
  4770.     bne    disgrl2        ; jump if not immed
  4771.     ldaa    #'#        ; do immediate
  4772.     jsr    outa
  4773.     jsr    disdir
  4774.     ldab    *class
  4775.     cmpb    #limm
  4776.     beq    disgrl1        ; jump class = limm
  4777.     rts
  4778. disgrl1:
  4779.     ldx    *dispc
  4780.     jsr    out1byt
  4781.     stx    *dispc
  4782.     rts
  4783. disgrl2:
  4784.     cmpa    #0x90
  4785.     bne    disgrl3        ; jump not direct
  4786.     jsr    disdir        ; do direct
  4787.     rts
  4788. disgrl3:
  4789.     cmpa    #0xa0
  4790.     bne    disgrl4        ; jump not indexed
  4791.     jsr    disindx        ; do extended
  4792.     rts
  4793. disgrl4:
  4794.     jsr    disext        ; do extended
  4795.     rts
  4796.  
  4797. ;*****************
  4798. ;*disdir() - output "$ next byte"
  4799. ;*****************
  4800. disdir    = .
  4801.     ldaa    #'$
  4802.     jsr    outa
  4803.     ldx    *dispc
  4804.     jsr    out1byt
  4805.     stx    *dispc
  4806.     rts
  4807.  
  4808. ;*****************
  4809. ;*disext() - output "$ next 2 bytes"
  4810. ;*****************
  4811. disext    = .
  4812.     ldaa    #'$
  4813.     jsr    outa
  4814.     ldx    *dispc
  4815.     jsr    out2bsp
  4816.     stx    *dispc
  4817.     rts
  4818.  
  4819.  
  4820. ;*****************
  4821. ;*disillop() - output "illegal opcode"
  4822. ;*****************
  4823. dismsg1:
  4824.     .ascii    'ILLOP'
  4825.     .byte    eot
  4826. disillop    = .
  4827.     pshx
  4828.     ldx    #dismsg1
  4829.     jsr    outstrg0    ; no cr
  4830.     pulx
  4831.     rts
  4832.  
  4833. ;* equates
  4834. jportd    =    0x08
  4835. jddrd    =    0x09
  4836. jbaud    =    0x2b
  4837. jsccr1    =    0x2c
  4838. jsccr2    =    0x2d
  4839. jscsr    =    0x2e
  4840. jscdat    =    0x2f
  4841. ;*
  4842.  
  4843. ;************
  4844. ;*    boot [<addr>] - use sci to talk to an 'hc11 in
  4845. ;* boot mode.  downloads 256 bytes starting at addr.
  4846. ;* default addr = 0x2000.
  4847. ;************
  4848.  
  4849. ;*get arguments
  4850. ;*if no args, default 0x2000
  4851. boot:    jsr    wskip
  4852.     cmpa    #0x0d
  4853.     bne    bot1        ; jump if arguments
  4854.     ldy    #0x2000
  4855.     bra    bot2        ; go - use default address
  4856.  
  4857. ;*else get arguments
  4858. bot1:    jsr    buffarg
  4859.     tst    *count
  4860.     beq    boterr        ; jump if no address
  4861.     jsr    wskip
  4862.     ldy    *shftreg    ; start address
  4863.     cmpa    #0xd
  4864.     beq    bot2        ; go - use arguments
  4865. boterr:    ldx    #msg9        ; "bad argument"
  4866.     jsr    outstrg
  4867.     rts
  4868.  
  4869. ;*boot routine
  4870. bot2:    ldab    #0xff        ; control character (0xff -> download)
  4871.     jsr    btsub        ; set up sci and send control char
  4872.  
  4873. ;*download 256 byte block
  4874.     clrb            ; counter
  4875. blop:    ldaa    0,y
  4876.     staa    jscdat,x    ; write to transmitter
  4877.     iny
  4878.     brclr jscsr,x ,#0x80, .    ; wait for tdre
  4879.     decb
  4880.     bne    blop
  4881.     rts
  4882.  
  4883. ;************************************************
  4884. ;*subroutine
  4885. ;*    btsub    - sets up sci and outputs control character
  4886. ;* on entry, b = control character
  4887. ;* on exit,  x = 0x1000
  4888. ;*        a = 0x0c
  4889. ;***************************
  4890.  
  4891. btsub    = .
  4892.     ldx    #0x1000        ; to use indexed addressing
  4893.     ldaa    #0x02
  4894.     staa    jportd,x    ; drive transmitter line
  4895.     staa    jddrd,x        ; high
  4896.     clr    jsccr2,x    ; turn off xmtr and rcvr
  4897.     ldaa    #0x22        ; baud = /16
  4898.     staa    jbaud,x
  4899.     ldaa    #0x0c        ; turn on xmtr & rcvr
  4900.     staa    jsccr2,x
  4901.     stab    jscdat,x
  4902.     brclr jscsr,x ,#0x80, .    ; wait for tdre
  4903.     rts
  4904.  
  4905. ;******************
  4906. ;*
  4907. ;*    evbtest - this routine makes it a little easier
  4908. ;*    on us to test this board.
  4909. ;*
  4910. ;******************
  4911.  
  4912. evbtest:
  4913.     ldaa    #0xff
  4914.  
  4915.     staa    0x1000        ; write ones to port a
  4916.  
  4917.     clr    *autolf        ; turn off auto lf
  4918.     jsr    hostco        ; connect host
  4919.     jsr    hostinit    ; initialize host
  4920.  
  4921.     ldaa    #0x7f
  4922.     jsr    hostout        ; send delete to altos
  4923.     ldaa    #0x0d
  4924.     jsr    hostout        ; send <cr>
  4925.     inc    *autolf        ; turn on auto lf
  4926.     ldx    #inbuff+5    ; point at load message
  4927.     stx    *ptr0        ; set pointer for load command
  4928.     ldy    #msgevb        ; point at cat line
  4929. loop:    ldaa    0,y        ; loop to xfer command line
  4930.     cmpa    #04        ; into buffalo line buffer
  4931.     beq    done        ; quit on 0x04
  4932.     staa    0,x
  4933.     inx            ; next character
  4934.     iny
  4935.     bra    loop
  4936. done:    clr    *tmp2        ; set load vs. verify
  4937.     jsr    load1b        ; jmp into middle of load
  4938.     lds    #stack        ; reset stack
  4939.     jmp    0xc0b3        ; jump to downloaded code
  4940.  
  4941. msgevb:    .ascii    /cat evbtest.out/
  4942.     .byte    0x0d
  4943.     .byte    0x04
  4944.  
  4945.     .org    rombs+0x1fa0
  4946. ;*** jump table ***
  4947. .upcase:jmp    upcase
  4948. .wchek:    jmp    wchek
  4949. .dchek:    jmp    dchek
  4950. .init:    jmp    init
  4951. .input:    jmp    input
  4952. .output:jmp    output
  4953. .outlhl:jmp    outlhlf
  4954. .outrhl:jmp    outrhlf
  4955. .outa:    jmp    outa
  4956. .out1by:jmp    out1byt
  4957. .out1bs:jmp    out1bsp
  4958. .out2bs:jmp    out2bsp
  4959. .outcrl:jmp    outcrlf
  4960. .outstr:jmp    outstrg
  4961. .outst0:jmp    outstrg0
  4962. .inchar:jmp    inchar
  4963. .vecint:jmp    vecinit
  4964.  
  4965.     .org    rombs+0x1fd6
  4966. ;*** vectors ***
  4967. vsci:    .word    jsci
  4968. vspi:    .word    jspi
  4969. vpaie:    .word    jpaie
  4970. vpao:    .word    jpao
  4971. vtof:    .word    jtof
  4972. vtoc5:    .word    jtoc5
  4973. vtoc4:    .word    jtoc4
  4974. vtoc3:    .word    jtoc3
  4975. vtoc2:    .word    jtoc2
  4976. vtoc1:    .word    jtoc1
  4977. vtic3:    .word    jtic3
  4978. vtic2:    .word    jtic2
  4979. vtic1:    .word    jtic1
  4980. vrti:    .word    jrti
  4981. virq:    .word    jirq
  4982. vxirq:    .word    jxirq
  4983. vswi:    .word    jswi
  4984. villop:    .word    jillop
  4985. vcop:    .word    jcop
  4986. vclm:    .word    jclm
  4987. vrst:    .word    buffalo
  4988.  
  4989.