home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progasm / asca11.arj / AST05.ASM < prev    next >
Assembly Source File  |  1990-11-23  |  28KB  |  1,247 lines

  1.     .title    assist05E2 february 18, 1985
  2. ;*
  3. ;*        monitor for the MC146805E2 Evaluation Board
  4. ;*
  5. ;*     (c) copyright 1985 motorola, inc.
  6. ;*
  7. ;*
  8. ;*    the monitor has the following commands:
  9. ;*
  10. ;*    r        print registers
  11. ;*
  12. ;*    d        download from standard host
  13. ;*
  14. ;*    h        host communication
  15. ;*
  16. ;*    a        display/change a register
  17. ;*
  18. ;*    x        display/change x register
  19. ;*
  20. ;*    c        display/change condition codes
  21. ;*
  22. ;*    e        display/change timer data register
  23. ;*
  24. ;*    f        display/change timer control register
  25. ;*
  26. ;*    p        display/change program counter
  27. ;*
  28. ;*    i        display/change irq vector
  29. ;*
  30. ;*    j        display/change timer vector
  31. ;*
  32. ;*    k        display/change timer vector (wait mode)
  33. ;*
  34. ;*    b        display breakpoints
  35. ;*
  36. ;*    b n xxxx    set breakpoint n
  37. ;*
  38. ;*    b n 0        clear breakpoint 
  39. ;*
  40. ;*    t        trace one instruction
  41. ;* 
  42. ;*    t xxxx     trace xxxx instructions
  43. ;*
  44. ;*    m xxxx     memory examine/change
  45. ;*
  46. ;*        type    <cr>    to examine next
  47. ;*            ^    to eamine previous
  48. ;*            =    to examine same
  49. ;*            hh    to change hex data
  50. ;*            .    to terminate command
  51. ;*
  52. ;*    g        continue execution from current pc
  53. ;*
  54. ;*    g xxxx        go execute pgm at specified address
  55. ;*
  56. ;*
  57. ;*
  58. ;*
  59. ;*
  60. ;*
  61. ;*
  62. ;*
  63. monstr    =    0x1800    ; start of monitor
  64. workpg    =    0x0010    ; start of monitor variables
  65. numbkp    =    3    ; number of breakpoints
  66. duart    =    0x17f0    ; duart address
  67. prompt    =    '>    ; prompt character
  68. timer    =    8    ; timer data register
  69. timec    =    9    ; timer control register
  70. ;*
  71. ;*        equates
  72. ;*
  73. ;*
  74. eot    =    0x04    ; end of text
  75. cr    =    0x0d    ; carriage return
  76. lf    =    0x0a    ; line feed
  77. sp    =    0x20    ; space
  78. bell    =    0x07    ; control-g (bell)
  79. swiop    =    0x83    ; software interrupt op code
  80. jmpop    =    0xcc    ; extended jump op code
  81. ctla    =    0x01    ; host communications default terminator
  82. ;*
  83. ;*        work ram 
  84. ;*
  85. ;*
  86.     .area    ASST05    (ABS,OVR)
  87.  
  88.     .setdp
  89.  
  90.     .org    workpg
  91.  
  92. bkptbl:    .blkb  3*numbkp    ; breakpoint table
  93. asave:    .blkb    1    ; temp save for a 
  94. swiflg:    .blkb    1    ; swi function flag
  95. work1:    .blkb    1    ; chrin/load/store/putbyt
  96. work2:    .blkb    1    ; load/store/putbyte 
  97. addrh:    .blkb    1    ; high address byte
  98. addrl:    .blkb    1    ; low address byte
  99. work3:    .blkb    1    ; load/store/punch
  100. work4:    .blkb    1    ; store/punchpunch
  101. work5:    .blkb    1    ; trace/punch
  102. work6:    .blkb    1    ; trace
  103. work7:    .blkb    1    ; trace
  104. work8:    .blkb    1    ; timer restoration
  105. work9:    .blkb    1    ; timer restoration
  106. workd:    .blkb    1    ; timer restoration
  107. worke:    .blkb    1    ; timer restoration
  108. pncnt:    .blkb    1    ; punch breakpoint
  109. chksum:    .blkb    1    ; punch
  110. cmd:    .blkb    3
  111. total:    .blkb    1
  112. savea:    .blkb    1
  113. sava:    .blkb    1
  114. savex:    .blkb    1
  115. vecram:    .blkb    12    ; vectors
  116. ;*
  117. ;*
  118. ;*
  119. ;*
  120. ;*
  121.     .org    monstr    ; start of monitor
  122. ;*
  123. ;*        monitor base string/table page
  124. ;*        (must be at the begining of a page)
  125. ;*
  126. ;*
  127. ;*
  128. mbase    =    .    ; start of work page in rom
  129. ;*            ; msgup must be the first in the page
  130. msgup:    .ascii    /assist05E2 3.0/    ; fire-up message
  131. msgnul:    .byte    eot            ; end of string
  132. msgerr:    .ascii    /- error -/
  133.     .byte    bell
  134.     .byte    eot
  135. msgpc:    .ascii    /  Pc  A  X  Cc S/
  136.     .byte    eot
  137. vectab:    .byte    jmpop
  138.     .word    tirq
  139.     .byte    jmpop
  140.     .word    tirq 
  141.     .byte    jmpop
  142.     .word    irq
  143.     .byte    jmpop
  144.     .word    swi
  145. ;*
  146. ;*
  147. ;*    g - start execuction
  148. ;*        also used for p - display/set pc
  149. ;*
  150. ;*
  151. cmdg:    lda    *work4
  152.     bit    #0x80
  153.     bne    nodipc        ; don't display pc if a g command
  154.     jsr    putsp        ; send a space
  155.     jsr    locstk        ; obtain current sp-3
  156.     lda    7,x        ; current pc high
  157.     jsr    putbyt        ; print pc high in hex
  158.     lda    8,x        ; current pc low
  159.     jsr    putbyt        ; print pc low in hex
  160. nodipc:    jsr    getadr        ; obtain input address
  161.     bcc    next        ; do continue if done
  162. gaddr:    jsr    locstk        ; obtain current sp-3t-3
  163.     lda    *addrh        ; load pc high
  164.     sta    7,x        ; into stack
  165.     lda    *addrl        ; load pc low
  166.     sta    8,x        ; into stack also
  167. next:    lda    *work4
  168.     bit    #0x80
  169.     bne    cont        ; if g command then continue
  170.     jmp    cmdnnl        ; else just p command - don't continue
  171. cont:    jsr    scnbkp        ; init breakpoint scan parameters
  172. goinsb:    lda    *bkptbl,x     ; load high byte
  173.  
  174.     cmp    #0x00        ; check to see if empty
  175.     bne    gstore
  176.     lda    *bkptbl+1,x    ; get next byte
  177.     cmp    #0x00        ; really empty?
  178.     beq    gonob
  179.  
  180. gstore:    lda    *bkptbl,x    ; go get byte again
  181.     sta    *addrh        ; store high address
  182. sta:    lda    *bkptbl+1,x     ; load low address
  183.     sta    *addrl        ; load low
  184.     jsr    load        ; load opccode 
  185.     sta    *bkptbl+2,x    ; store into table
  186.     lda    #swiop    ;     replace with opcode
  187.     jsr    store        ; store in place
  188. gonob:    incx            ; to
  189.     incx            ; next
  190.     incx            ; breakpoint
  191.     lda    *pncnt        ; count low
  192.     deca
  193.     sta    *pncnt
  194.     bne    goinsb        ; loop if more
  195.     lda    *swiflg        ; flag breakpoints are in
  196.     coma
  197.     sta    *swiflg
  198.     lda    *work9        ; reset control register 
  199.     sta    *timec
  200.     lda    *work8
  201.     sta    *timer        ; then user enviornment
  202.     lda    *workd        ; then the user's vectors
  203.     sta    *vecram+4
  204.     lda    *worke
  205.     sta    *vecram+5
  206.     rti            ; restart program
  207. cmdmin:    jmp    cmderr
  208. ;*
  209. ;*
  210. ;*    m - examine/change memory
  211. ;*    mchnge - register change entry point
  212. ;*
  213. ;*
  214. ;*
  215. cmdm:    jsr    getadr        ; obtain address value
  216.     bcc    cmdmin        ; invalid if no address
  217. cmdmlp:    jsr    prtadr        ; print out address and space
  218. mchnge:    bsr    load        ; load acc w/byte
  219.     jsr    crbyts        ; print with a space
  220.     jsr    getnyb        ; see if change wanted
  221.     bcc    cmdmdl        ; branch no
  222.     jsr    getby2        ; obtain full byte
  223.     bne    cmdmin        ; terminate if invalid hex
  224.     bcc    cmdmdl        ; branch if other delimiter
  225.     bsr    store        ; store new value
  226.     bcs    cmdmin        ; branch of store fails
  227.     jsr    chrin        ; obtain delimiter
  228. ;*
  229. ;*    check out delimiters 
  230. cmdmdl:    cmp    #0x0d        ; ? to next byte
  231.     beq    cmdmlf        ; branch if so
  232.     cmp    #'^        ; ? to previous byte
  233.     beq    cmdmbk        ; branch if so
  234.     cmp    #'=        ; ? reexamine same byte
  235.     beq    cmcmpr        ; branch yes
  236.     cmp    #'.        ; ? carriage return
  237.     beq    cmdmen1        ; branch yes
  238.     jsr    pcrlf        ; all else: give new line
  239. cmdmen:    jmp    cmdnnl        ; enter command handler
  240. cmdmbk:    lda    *addrl        ; ? low byte zero?
  241.     bne    cmdmb2        ; no, just adjust it
  242.     lda    *addrh
  243.     deca
  244.     sta    *addrh        ; down high for carry
  245. cmdmb2:    lda    *addrl
  246.     deca
  247.     sta    *addrl        ; down low byte
  248.     bsr    pcrlf        ; to next line
  249.     bra    cmdmlp        ; to next byte
  250. cmcmpr:    bsr    pcrlf
  251.     bra    cmdmlp
  252. cmdmlf:    lda    #cr        ; send just a carriage return
  253.     jsr    chrou2        ; output it
  254.     bsr    ptrup1        ; up pointer by one
  255.     bra    cmdmlp        ; to next byte
  256.  
  257. cmdmen1:
  258.     jsr    pcrlf
  259.     bra    cmdmen        ; add crlf to the <.>
  260. ;*
  261. ;*
  262. ;*    load - load into a from address pointer addrh/addrl
  263. ;*
  264. ;*        input:    addrh/addrl = address
  265. ;*
  266. ;*        output: a=byte from pointed location
  267. ;*            x is transparent
  268. ;*            work1, work2, work3 used
  269. ;*
  270. ;*
  271. load:    stx    *work1        ; save x
  272.     ldx    #0xc6        ; c6=lda 2 byte extended
  273. ldstcm:    stx    *work2        ; put opcode in place
  274.     ldx    #0x81        ; 81=rts
  275.     stx    *work3        ; now the return
  276.     jsr    *work2        ; execute built in routine
  277.     ldx    *work1        ; restore x
  278.     rts            ; and exit
  279. ;*
  280. ;*
  281. ;*    store - store a at address in pointer addrh/addrl
  282. ;*
  283. ;*        input:    a=byte to store
  284. ;*            addrh/addrl= address
  285. ;*        output:    c=0 store went ok
  286. ;*            c=1 store did not take (not ram)
  287. ;*            registers transparent (a not transparent on
  288. ;*            invalid store) 
  289. ;*
  290. ;*
  291. store:    stx    *work1        ; save x
  292.     ldx    #0xc7        ; c7=sta 2 byte extended
  293.     bsr    ldstcm        ; call store routine
  294.     sta    *work4        ; save value stored
  295.     bsr    load        ; attempt load
  296.     cmp    *work4        ; valid store?
  297.     beq    strts        ; branch if valid
  298.     sec            ; show invalid store
  299. strts:    rts            ; return
  300. ;*
  301. ;*
  302. ;*    ptrup1 - increment memory pointer
  303. ;*
  304. ;*
  305. ptrup1:    lda    *addrl
  306.     inca
  307.     sta    *addrl        ; increment low byte
  308.     bne    prtrts        ; non zero means no carry
  309.     lda    *addrh
  310.     inca
  311.     sta    *addrh        ; increment high byte
  312. prtrts:    rts            ; return to caller
  313. ;*
  314. ;*
  315. ;*    putbyt - print a in hex
  316. ;*
  317. putbyt:    sta    *work1        ; save a
  318.     lsra            ; shift to 
  319.     lsra            ; left hex
  320.     lsra            ; digit
  321.     lsra            ; shift high nybble down
  322.     bsr    putnyb        ; print it
  323.     lda    *work1
  324. ;*
  325. ;*    fall into putnyb
  326. ;*
  327. ;*
  328. ;*    putnyb - print lower nybble of a in hex
  329. ;*        a,x transparent
  330. ;*
  331. ;*
  332. putnyb:    and    #0xf        ; mask off high nybble
  333.     add    #'0        ; add ascii zero
  334.     cmp    #'9        ; check for a-f
  335.     bhi    putny2
  336.     jmp    chrout        ; ok, send out
  337. putny2:    add    #'a-'9-1     ; adjustment for hex a-f
  338.     jmp    chrout        ; now send out
  339. ;*
  340. ;*
  341. ;*    pdata    - print monitor string after cr/lf
  342. ;*    pdata1    - print monitor string
  343. ;*    pcrlf    - print cr/lf
  344. ;*
  345. ;*    input: x=offset to string in base page
  346. ;*
  347. ;*
  348. pcrlf:    ldx    #msgnul-mbase    ; load null string address
  349. pdata:    lda    #cr        ; prepare carriage return
  350. pdloop:    jsr    chrout        ; send next character
  351. pdata1:    lda    mbase,x        ; load next character
  352.     incx            ; bump pointer up one
  353.     cmp    #eot        ; end of string?
  354.     bne    pdloop        ; branch no
  355.     rts            ; return done
  356. ;*
  357. ;*
  358. ;*    getnyb    - obtain next hex character
  359. ;*
  360. ;*        output:    c=0 not hex character,a=delimiter
  361. ;*             c=1 hex input, a=binary value
  362. ;*             work1 in use
  363. ;*
  364. getnyb    =    .
  365.     jsr    chrin        ; get char
  366. getnyb2:
  367.     cmp    #'0
  368.     blo    getnch        ; hex ?
  369.     ora    #0x20        ; mask for upper/lower case
  370.  
  371.     cmp    #'9
  372.     bls    getnhx
  373.     cmp    #'a
  374.     blo    getnch
  375.     cmp    #'f
  376.     bhi    getnch
  377.  
  378.     sub    #7
  379. getnhx:    and    #0x0f        ; clear ascii bits
  380.     sec 
  381.     rts
  382. getnch:    clc
  383.     rts
  384. ;*
  385. ;* getadr - build any size binary number from input
  386. ;*        leading blanks skipped
  387. ;*
  388. ;* output: cc = 0 no number entered
  389. ;*        1 addrh/addrl has number
  390. ;*        a = delimiter
  391. ;*     a,x volatile
  392. ;*
  393. ;* work1 used
  394. ;*
  395. getadr:    jsr    putsp
  396.     lda    #0x00
  397.     sta    *addrh        ; clear high byte
  398.     bsr    getnyb        ; obtain first hex value
  399.     bcs    getgtd        ; branch if got it
  400.     cmp    #0x20        ; is it a space?
  401.     beq    getadr        ; loop if so
  402.     clc            ; clear carry
  403.     rts            ; return    no number
  404. getgtd:    sta    *addrl        ; initialize low value
  405. getalp:    bsr    getnyb        ; obtain next hex
  406.     bcc    getarg        ; branch if none
  407.     asla            ; over
  408.     asla            ; four
  409.     asla            ; bits
  410.     asla            ; for shift
  411.     ldx    #4        ; loop four times
  412. getasf:    asla            ; shift next bit
  413.     sta    *asave
  414.     lda    *addrl
  415.     rola
  416.     sta    *addrl        ; into low byte
  417.     lda    *addrh
  418.     rola
  419.     sta    *addrh        ; into hi byte
  420.     lda    *asave
  421.     decx            ; count down
  422.     bne    getasf        ; loop until done
  423.     bra    getalp        ; do next hex
  424. getarg:    sec            ; show number obtained
  425.     rts
  426. ;*
  427. ;* chrin - obtain next input character
  428. ;*
  429. ;* output: a = character received
  430. ;*     x    is transparent
  431. ;*     nulls ignored
  432. ;*     all characters echoed out
  433. ;*
  434. ;* work1 used
  435. ;* 
  436. chrin:    lda    duart+1        ; get status
  437.     lsra            ; test rcvr reg flag
  438.     bcc    chrin        ; loop until char recvd
  439.     lda    duart+3        ; get character
  440.  
  441.     and    #0x7f        ; and off parity
  442.     beq    chrin        ; ignore nulls
  443.     sta    *work1
  444.     bsr    chrout        ; echo character
  445.     lda    *work1
  446.     rts
  447. ;*
  448. ;* hochrin - obtain next character from host port
  449. ;*        same characteristics as chrin
  450. ;*
  451. hochrin:
  452.     lda    duart+9        ; get status
  453.     lsra
  454.     bcc    hochrin        ; check rdrf
  455.     lda    duart+0x0b
  456.     and    #0x7f        ; off with the parity
  457.     rts
  458. ;*
  459. ;*
  460. ;* puts - print a space character
  461. ;* x unchanged
  462. ;*
  463. putsp:    lda    #sp        ; load a space char
  464. ;*
  465. ;* fall into chrout
  466. ;* * chrout - send a character to terminal
  467. ;*        cr has added line feed
  468. ;*
  469. ;* input: a = ascii char to send
  470. ;*
  471. ;* a nopt transparent
  472. ;*
  473. chrout:    cmp    #cr        ; cr to send ?
  474.     bne    chrou2
  475.     bsr    chrou2        ; recursive call for cr
  476.     lda    #lf        ; send lf char
  477.  
  478. chrou2:    sta    *savea 
  479. chrou3:    lda    duart+1        ; get status register
  480.     bit    #0x04        ; check tdre
  481.     beq    chrou3        ; branch till done
  482.     lda    *savea
  483.     sta    duart+3        ; write data register
  484.     rts
  485.  
  486. ;*
  487. ;*    hosout - send character to host
  488. ;*
  489. hosout:    sta    *savea
  490. chrouh:    lda    duart+9        ; get status
  491.     bit    #0x04        ; check tdre
  492.     beq    chrouh        ; branch till done
  493.     lda    *savea
  494.     sta    duart+0x0b    ; send character
  495.     rts
  496.  
  497. ;*
  498. ;* reset - power-on reset routine
  499. ;*
  500. ;* init duart (both sides), put out startup msg
  501. ;*
  502. reset:    clrx
  503.     clra
  504. clear:    sta    *bkptbl,x    ; clear breakpoint table
  505.     incx
  506.     cpx    #0x0a
  507.     bne    clear
  508.  
  509.     ldx    #11        ; move vector table to ram
  510. rst:    lda    vectab,x    ; to allow changes on fly
  511.     sta    *vecram,x
  512.     decx
  513.     bpl    rst
  514. ;*
  515.  
  516.     lda     #0x06        ; mode
  517.     sta     duart
  518.     sta    duart+8
  519.  
  520.     lda    #0xbb        ; baud
  521.     sta    duart+1
  522.     sta    duart+9
  523.  
  524.     lda    #0x07        ; one stopbit
  525.     sta    duart
  526.     sta    duart+8
  527.  
  528.     lda    #0x80        ; counter mode
  529.     sta    duart+4
  530.     sta    duart+0xc
  531.  
  532.     lda    #0x08
  533.     sta    duart+5
  534.     sta    duart+0xd
  535.  
  536.     lda    #0x15        ; init cmd register
  537.     sta    duart+2
  538.     sta    duart+0xa
  539.  
  540.     jsr    scnbkp        ; clear breakpoints
  541. ;*
  542. resren:    lda    #0x0
  543.     sta    *swiflg        ; setup monitor entrance value
  544.     swi            ; enter monitor
  545.     bra    resren        ; reenter if 'g'
  546. ;*
  547. ;* command handler
  548. ;*
  549. cmdpdt:    jsr    pdata        ; send msg out
  550. cmd1:    jsr    pcrlf        ; to new line
  551. cmdnnl:    lda    #prompt        ; ready prompt char
  552.     jsr    chrout        ; send it out
  553.     jsr    rembkp        ; remove breakpoints
  554.     jsr    chrin        ; get char from user
  555.     ora    #0x20        ; mask for uc or lc
  556.     clrx            ; zero for some commands
  557.     cmp    #0x0d        ; ignore a cr
  558.     beq    cmdnnl
  559.     cmp    #'c        ; dis/chg cc reg ?
  560.     beq    cmdc
  561.     cmp    #'x        ; dis/chg x reg ?
  562.     beq    cmdx
  563.     cmp    #'a        ; dis/chg a reg
  564.     beq    cmda
  565.     cmp    #'r        ; display all registers
  566.     bne    notv
  567.     jmp    regr
  568. notv:    cmp    #'g        ; go ?
  569.     bne    notg
  570.     lda    *work4
  571.     ora    #0x80
  572.     sta    *work4
  573. isp:    jmp    cmdg        ; go to it
  574. ;*
  575. notg:    cmp    #'m        ; memory display/change ?
  576.     bne    notm
  577.     jmp    cmdm
  578. notm:    cmp    #'t        ; trace ?
  579.     bne    notw
  580.     jmp    cmdt
  581. notw    = .
  582.     cmp    #'b        ; breakpoint command ?
  583.     beq    bpnt        ; yes
  584.     cmp    #'p        ; pc command ?
  585.     bne    notp
  586.     lda    *work4
  587.     and    #0x7f
  588.     sta    *work4
  589.     bra    isp
  590. ;*
  591. notp    = .
  592.     cmp    #'e        ; display/change timer data
  593.     beq    cmde
  594.     cmp    #'f        ; display/change timer control
  595.     beq    cmdf
  596.     cmp    #'i        ; displ/chng interrupt vector
  597.     beq    cmdi
  598.     cmp    #'j        ; displ/chng timer vector
  599.     beq    cmdj
  600.     cmp    #'d        ; download
  601.     beq    downld
  602.     cmp    #'h        ; host comm
  603.     beq    hostit
  604.     cmp    #'k        ; displ/chng timer wait vector 
  605.     bne    cmderr
  606.     jmp    cmdk
  607. ;*
  608. cmderr:    ldx    #msgerr-mbase    ; load error string
  609. tocpdt:    jmp    cmdpdt        ; and send it out
  610. regr:    jmp    cmdr
  611. bpnt:    jmp    cmdb
  612. downld:    jmp    down
  613. hostit:    jmp    host
  614. ;*
  615. ;* x - display/change x register
  616. ;*
  617. cmdx:    incx
  618. ;*
  619. ;* a - display change acc
  620. ;*
  621. cmda:    incx
  622. ;*
  623. ;* c - display/change cc register
  624. ;*
  625. cmdc:    jsr    putsp        ; space before value
  626.     stx    *work1        ; save index value
  627.     jsr    locstk        ; locate stack address
  628.     txa            ; stack-2 to a
  629.     add    *work1        ; add proper offset
  630.     add    #4        ; make up for address return difference
  631.     sta    *addrl        ; and set inlow
  632.     lda    #0x0
  633.     sta    *addrh
  634. tomchg:    jmp    mchnge        ; now enter memory change command
  635. ;*
  636. ;* e - display/change timer data register
  637. ;*
  638. cmde:    jsr    putsp        ; give a space
  639.     lda    #>(workpg+(work8-bkptbl))    ; high byte of work8 address
  640.     sta    *addrh        ; save in memory pointer
  641.     lda    #<(workpg+(work8-bkptbl))    ; low byte of work8 address
  642.     sta    *addrl        ; save in memory pointer
  643.     jmp    mchnge        ; handle as memory change
  644. ;*
  645. ;* f - display/change timer control register
  646. ;*
  647. cmdf:    jsr    putsp        ; give a space
  648.     lda    #>(workpg+(work9-bkptbl))    ; high byte of work9 address
  649.     sta    *addrh
  650.     lda    #<(workpg+(work9-bkptbl))    ; low byte of work9 address
  651.     sta    *addrl
  652.     jmp    mchnge        ; handle as memory change
  653. ;*
  654. ;* i - display/change interrupt vector
  655. ;*
  656. cmdi:    jsr    putsp        ; give a space
  657.     lda    *vecram+7    ; get current vector hi byte
  658.     jsr    putbyt        ; display it
  659.     lda    *vecram+8     ; get lo byte
  660.     jsr    putbyt        ; display it
  661.     jsr    putsp        ; separate with a space
  662.     jsr    getadr        ; get address from user
  663.     bcc    cmdinc        ; no number entered ?
  664. ;*
  665. cmdiok:    sta    *vecram+7     ; save hi byte of vector
  666.     lda    *addrl        ; get lo byte 
  667.     sta    *vecram+8     ; save lo byte of vector
  668. ;*
  669. cmdinc:    jmp    cmdnnl        ; return to command handler
  670. ;*
  671. ;* j - display/change timer interrupt vector
  672. ;*
  673. cmdj:    jsr    putsp        ; give a space
  674.     lda    *workd        ; get user vector hi byte
  675.     jsr    putbyt        ; display in hex
  676.     lda    *worke        ; get user vector lo byte
  677.     jsr    putbyt        ; display in hex
  678.     jsr    putsp        ; give a space
  679.     jsr    getadr        ; get address from user
  680.     bcc    cmdjnc        ; no number ?
  681. cmdjok    =    .
  682.     sta    *workd        ; save hi byte
  683.     lda    *addrl
  684.     sta    *worke
  685. cmdjnc:    jmp    cmdnnl        ; return to command handler
  686. ;*
  687. ;* k - display/change timer wait mode vector
  688. ;*
  689. cmdk:    jsr    putsp        ; give a space
  690.     lda    *vecram+1     ; get current vector hi byte
  691.     jsr    putbyt        ; display it in hex
  692.     lda    *vecram+2     ; getllo byte
  693.     jsr    putbyt        ; display in hex
  694.     jsr    putsp        ; give a space separation
  695.     jsr    getadr        ; get new vector from user
  696.     bcc    cmdknc        ; no number input ?
  697. ;*
  698. cmdkok    =    .
  699.     sta    *vecram+1     ; save hi byte of new vector
  700.     lda    *addrl        ; get lo byte
  701.     sta    *vecram+2     ; save lo byte
  702. ;*
  703. cmdknc:    jmp    cmdnnl        ; return to command handler
  704. ;*
  705. ;* swi handler
  706. ;*
  707. ;* determine processing swiflg value
  708. ;*
  709. swi:    lda    *timec        ; save user timer environemt
  710.     sta    *work9        ; first the control register
  711.     lda    #0x40        ; then mask timer
  712.     sta    *timec
  713.     lda    *timer        ; then save the timer register
  714.     sta    *work8
  715.     lda    *vecram+4     ; then save users vector
  716.     sta    *workd
  717.     lda    *vecram+5
  718.     sta    *worke
  719.     lda    #>(monstr+(tirq-mbase))    ; timer vector high address
  720.     sta    *vecram+4
  721.     lda    #<(monstr+(tirq-mbase))    ; timer vector low address
  722.     sta    *vecram+5
  723.     clrx            ; default to startup msg
  724.     lda    *swiflg        ; is this reset
  725.     bne    swichk        ; if not, remove breakpoints
  726.     inca
  727.     sta    *swiflg        ; show we are now initialized
  728.     jmp    cmdpdt        ; to command handler
  729. ;*
  730. swichk:    jsr    scnbkp
  731. swirep:    lda    *bkptbl,x     ; restore opcode
  732.     bmi    swinob
  733.     sta    *addrh
  734.     lda    *bkptbl+1,x
  735.     sta    *addrl
  736.     lda    *bkptbl+2,x
  737.     jsr    store
  738. ;*
  739. swinob:    incx
  740.     incx
  741.     incx
  742.     lda    *pncnt
  743.     deca
  744.     sta    *pncnt
  745.     bne    swirep
  746. ;*
  747. ;* trace one instruction if pc at a breakpoint
  748. ;*
  749.     jsr    locstk        ; findsstack
  750.     lda    8,x        ; get pc and adjust
  751.     sub    #1
  752.     sta    *work4        ; save pc low byte
  753.     lda    7,x
  754.     sbc    #0
  755.     sta    *work3        ; save pc hi byte
  756.     stx    *work5
  757.     jsr    scnbkp
  758. ;*
  759. switry:    lda    *bkptbl,x
  760.     bmi    swicmp
  761.     cmp    *work3
  762.     bne    swicmp
  763.     lda    *bkptbl+1,x
  764.     cmp    *work4
  765.     bne    swicmp
  766.     ldx    *work5
  767.     sta    8,x
  768.     lda    *work3
  769.     sta    7,x
  770.     lda    #0x0
  771.     sta    *work7
  772.     lda    #1
  773.     sta    *work6
  774.     jmp    trace
  775. ;*
  776. swicmp:    incx
  777.     incx
  778.     incx
  779.     lda    *pncnt
  780.     deca
  781.     sta    *pncnt
  782.     bne    switry
  783. ;*
  784. ;* fall into register display for breakpoint
  785. ;*
  786. ;* r - display registers
  787. ;*
  788. cmdr:    jsr    pcrlf        ; add text for register displays
  789.     stx    *savex
  790.     ldx    #msgpc-mbase
  791.     jsr    pdata
  792.     ldx    *savex
  793.     jsr    pcrlf
  794.  
  795.     jsr    putsp        ; give a space
  796.     bsr    locstk        ; locate stack-4
  797.     lda    7,x
  798.     sta    7,x
  799.     jsr    putbyt        ; display in hex
  800.     lda    8,x        ; offset into pc lo byte
  801.     bsr    crbyts        ; to hex and space
  802.     lda    5,x        ; offset to accc
  803.     bsr    crbyts        ; to hex and space
  804.     lda    6,x        ; offset to x reg
  805.     bsr    crbyts
  806.     lda    4,x        ; offset to cc reg
  807.     ora    #0xe0        ; set unused bits on
  808.     sta    4,x        ; restore
  809.     bsr    crbyts        ; hex and space
  810.     txa            ; stack pointer -3
  811.     add    #8        ; to users stack pointer
  812.     bsr    crbyts        ; hex and space
  813. gtocmd:    jmp    cmd1        ; return to command handler
  814. ;*
  815. ;* print address subroutine (x unchanged)
  816. ;*
  817. prtadr:    lda    *addrh        ; load hi byte
  818.     jsr    putbyt        ; displayphex
  819.     lda    *addrl        ; load lo byte
  820. crbyts:    jsr    putbyt        ; hex out
  821.     jmp    putsp        ; follow with a space
  822. ;*
  823. ;* locstk - locate callers stack pointer
  824. ;*
  825. ;* returns x=stack pointer-3
  826. ;*
  827. ;* a volatile
  828. ;*
  829. locstk:    bsr    locst2        ; leave address on stack
  830. stkhi    = >(monstr + (.-mbase))    ; hi byte on stack *******
  831. stklow    = <(monstr + (.-mbase))    ; low byte on stack
  832.     rts
  833. ;*
  834. locst2:    ldx    #0x7f        ; load high stack word address
  835. loclop:    lda    #stkhi        ; high byte for compare
  836. locdwn:    decx            ; to next lower byte in stack
  837.     cmp    ,x        ; this the same ?
  838.     bne    locdwn        ; if not, try next lower
  839.     lda    #stklow        ; compare with low address byte
  840.     cmp    1,x        ; found return address ?
  841.     bne    loclop        ; loop if not
  842.     rts
  843. ;*
  844. ;* b - breakpoint clear, set, or display
  845. ;*
  846. cmdb:    jsr    chrin        ; read next character
  847.     cmp    #0x20        ; display only ?
  848.     bne    bdsply        ; branch if so
  849.     bsr    pgtadr        ; obtain breakpoint number
  850.     tstx            ; any high byte value
  851.     bne    bkerr        ; if so, error
  852.     deca            ; down count by one
  853.     cmp    #numbkp        ; too high ?
  854.     bhs    bkerr        ; if so, error
  855.     asla            ; times two
  856.     add    *addrl        ; plus one for three times
  857.     deca
  858.     sta    *work2        ; save address
  859.     bsr    pgtadr        ; obtain address
  860.     ldx    *work2        ; reload entry pointer
  861.     sta    *bkptbl+1,x     ; save low address
  862.     bne    bknocl        ; branch if not zero
  863.     lda    *addrh        ; load high address
  864.     bne    bkncr        ; branch not null a
  865.     sta    *bkptbl,x     ; store as high byte
  866.     jmp    cmd1        ; end command
  867. ;*
  868. bknocl:    lda    *addrh        ; load high address
  869. bkncr:    sta    *bkptbl,x     ; store high byte
  870.     jsr    load        ; load byte at the address
  871.     coma            ; invert it
  872.     jsr    store        ; attempt store
  873.     bcs    bkerr1        ; error if did not store
  874.     coma            ; restore proper value
  875.     jsr    store        ; store it back
  876.     bra    gtocmd        ; end command
  877. ;*
  878. ;* display breakpoints
  879. ;*
  880. bdsply:    jsr    scnbkp        ; prepare scan of table
  881. bdsplp:    lda    *bkptbl,x     ; obtain high byte
  882.     cmp    #0x00        ; see if cleared
  883.     bne    godisp        ; it's not, go display em
  884.     lda    *bkptbl+1,x        ; what about lower byte
  885.     cmp    #0x00        ; is it a 00 also
  886.     beq    bdskp        ; yep, its unused slot
  887.  
  888. godisp:    lda    *bkptbl,x        ; go get 1st byte againo
  889.     jsr    putbyt        ; print out high byte
  890.     lda    *bkptbl+1,x     ; load low byte
  891.     bsr    crbyts        ; print it out with a space
  892. ;*
  893. bdskp:    incx            ; to next entry
  894.     incx
  895.     incx
  896.     lda    *pncnt
  897.     deca
  898.     sta    *pncnt        ; count down
  899.     bne    bdsplp        ; loop if more
  900.     jmp    cmd1        ; end command
  901. bkerr:    jmp    cmderr        ; give error response
  902.  
  903. bkerr1:    clra
  904.     sta    *bkptbl,x
  905.     sta    *bkptbl+1,x        ; clear out old stuff
  906.     bra    bkerr
  907. ;*
  908. pgtadr:    jsr    getadr        ; obtain input address
  909.     bcc    bkerr        ; abort if none
  910.     ldx    *addrh        ; ready high byte
  911.     lda    *addrl        ; ready low byte
  912.     rts
  913. ;*
  914. ;* t - trace instruction(s) command
  915. ;*
  916. cmdt:    lda    #1        ; default count
  917.     sta    *addrl        ; to one get adr clears addrh
  918.     jsr    getadr        ; build address if any
  919.     lda    *addrh        ; save value in temporary
  920.     sta    *work7        ; locations for later
  921.     lda    *addrl
  922.     sta    *work6
  923. ;*
  924. ;* setup timer to trigger interrupt
  925. ;*
  926. trace    =    .
  927.     jsr    locstk
  928.     lda    4,x        ; get current user i mask
  929.     and    #8
  930.     sta    *work5
  931.     lda    7,x        ; get current user pc
  932.     sta    *addrh
  933.     lda    8,x
  934.     sta    *addrl
  935.     jsr    load        ; get opcode
  936.     cmp    #0x83        ; swi ?
  937.     bne    trace3        ; if so, inc user pc
  938.     lda    *addrl
  939.     add    #1
  940.     sta    8,x
  941.     lda    *addrh
  942.     adc    #0
  943.     sta    7,x
  944.     bra    tirq        ; continue to trace
  945. ;*
  946. trace3:    cmp    #0x9b        ; sei ?
  947.     bne    trace2        ; if so, set it in the stack
  948.     lda    4,x
  949.     ora    #8
  950.     sta    4,x
  951.     lda    *addrl
  952.     add    #1
  953.     sta    8,x
  954.     lda    *addrh
  955.     adc    #0
  956.     sta    7,x
  957.     bra    tirq        ; continue to trace
  958. ;*
  959. trace2:    cmp    #0x9a        ; cli ?
  960.     bne    trace1
  961.     lda    #0x0
  962.     sta    *work5
  963. ;*
  964. trace1:    lda    4,x
  965.     and    #0xf7
  966.     sta    4,x
  967.     lda    #16        ; then setup timer
  968.     sta    *timer
  969.     lda    #8
  970.     sta    *timec
  971.     rti            ; execute one instruction
  972. ;*
  973. ;* tirq - timer interrupt routine
  974. ;*
  975. tirq    =    .
  976.     lda    #0x40        ; restore i mask to proper state
  977.     sta    *timec
  978.     jsr    locstk
  979.     lda    4,x
  980.     ora    *work5
  981.     sta    4,x
  982. ;*
  983. ;* see if more tracing is desired
  984. ;*
  985.     lda    *work6
  986.     deca
  987.     sta    *work6
  988.     bne    trace
  989.     lda    *work7
  990.     beq    disreg
  991.     deca
  992.     sta    *work7
  993.     bra    trace
  994. disreg:    jmp    cmdr
  995. ;*
  996. ;* int - interrupt routine
  997. ;*
  998. irq    =    .
  999.     jmp    cmderr        ; hardware interrupt unused
  1000. ;*
  1001. ;* twirq - timer interrupt routine - wait mode
  1002. ;*
  1003. twirq    =    .
  1004.     jmp    cmderr        ; timer wait interrupt unused
  1005. ;*
  1006. ;* delbpk - delete breakpoint subroutine
  1007. ;*
  1008. rembkp:    bsr    scnbkp        ; setup parameters
  1009.     bpl    remrts        ; return if not in
  1010. remlop:    lda    *bkptbl,x     ; load high address
  1011.     bmi    remnob        ; skip if null
  1012.     sta    *addrh
  1013.     lda    *bkptbl+1,x     ; load low address
  1014.     sta    *addrl
  1015.     lda    *bkptbl+2,x    ; load opcode
  1016.     jsr    store
  1017. ;*
  1018. remnob    =    .
  1019.     incx            ; to next entry
  1020.     incx
  1021.     incx
  1022.     lda    *pncnt
  1023.     deca
  1024.     sta    *pncnt        ; count down
  1025.     bne    remlop        ; loop if more
  1026.     lda    *swiflg        ; make positive to show removed
  1027.     coma
  1028.     sta    *swiflg
  1029. remrts:    rts
  1030. ;*
  1031. ;* setup for breakpoint table scan
  1032. ;*
  1033. scnbkp    =    .
  1034.     lda    #numbkp
  1035.     sta    *pncnt
  1036.     clrx
  1037.     lda    *swiflg
  1038.     rts
  1039.  
  1040. iserr0:    jmp    cmderr
  1041. ;*
  1042. ;********************************************************
  1043. ;*
  1044. ;*    download from standard host only
  1045. ;*        D <command> <cr>
  1046. ;*
  1047. ;********************************************************
  1048. ;*
  1049. down:    jsr    pcrlf        ; start new line on terminal
  1050.     jsr    chrin        ; get 1st char after "d"
  1051.  
  1052. load1:    cmp    #0x0d        ; is it <cr>?
  1053.     beq    iserr0        ; yes - error
  1054.     cmp    #0x20        ; no, is it a space?
  1055.     bne    load2        ; no, start of command
  1056.     jsr    chrin        ; yes, extract lead character
  1057.     bra    load1        ; test for valid start character
  1058.  
  1059. load0:    jsr    chrin        ; get next char in buffer from term
  1060. load2:    jsr    hosout        ; go send to host
  1061.     cmp    #0x0d        ; ready, at end of command?
  1062.     bne    load0        ; no, get next character
  1063.     jsr    pcrlf        ; clear line for him
  1064.     jmp    cmdlt        ; go check for s1-s9
  1065.  
  1066. ;*
  1067. ;*    clbyte -
  1068. ;*
  1069. ;*    load subroutne to read next byte, adjust
  1070. ;*    checksum, and decrement count
  1071.  
  1072. ;*    output:        A = Byte
  1073. ;*            cc = reflects count decrement
  1074. ;*
  1075.  
  1076. clbyte:    jsr    hgetbyt        ; obtain next byte from host
  1077.     bcs    clbyt1        ; if one
  1078.     jmp    cmdmin        ; error if none
  1079. clbyt1:    sta    *work2        ; save value
  1080.     add    *chksum        ; add to checksum
  1081.     sta    *chksum        ; replace
  1082.     lda    *work2        ; reload value
  1083.     decx            ; count down
  1084.     rts
  1085. ;*
  1086. ;*    hgetbyt - ready byte in hex subroutine gotten from host
  1087. ;*
  1088. ;*        output:    c=0,z=1    no number
  1089. ;*             c=0,z=0    invalid number
  1090. ;*             c=1,z=1    A=binary byte value
  1091. ;*
  1092. hgetbyt:
  1093.     jsr    getnyb1        ; get next hex digit
  1094.     bcc    hgetbrz        ; return no number
  1095. hgetby2:
  1096.     asla            ; shift
  1097.     asla            ; over
  1098.     asla            ; by
  1099.     asla            ; four
  1100.     sta    *work2
  1101.     jsr    getnyb1        ; getlow hex
  1102.     tsta            ; force z=0
  1103.     bcc    hgetbrt        ; return if invalid number
  1104.     ora    *work2        ; combine hex digits
  1105. hgetbrz:
  1106.     clr    *0x0f        ; set z=1
  1107. hgetbrt:
  1108.     rts            ; return to caller
  1109.  
  1110. getnyb1:
  1111.     jsr    hochrin        ; get input from host
  1112.     jsr    getnyb2        ; make sure it's ok
  1113.     rts
  1114.  
  1115.  
  1116. ;*
  1117. ;*    getbyt - same as above, but done for term port
  1118. ;*
  1119. getby2:    asla
  1120.     asla
  1121.     asla
  1122.     asla
  1123.     sta    *work2
  1124.     jsr    getnyb
  1125.     tsta
  1126.     bcc    getbrt
  1127.     ora    *work2
  1128. getbrz:    clr    *0x0f
  1129. getbrt:    rts
  1130.  
  1131.  
  1132.  
  1133.  
  1134. ;*
  1135. ;*
  1136. ;*    search for an 'S'
  1137. ;*
  1138. cmdlt:    jsr    hochrin        ; read a character from host
  1139. cmdlss:    cmp    #'S        ; is it an s?
  1140.     bne    cmdlt        ; loop if not
  1141.     jsr    hochrin        ; read second character
  1142.     cmp    #'9        ; is it a 9?
  1143.     beq    cleof        ; branch to end of file
  1144.     cmp    #'1        ; an s1 record?
  1145.     bne    cmdlss        ; nope, try again
  1146. ;*
  1147. ;*    read address and count
  1148. ;*
  1149.     lda    #0x00
  1150.     sta    *chksum        ; zer0 checksum
  1151.     jsr    clbyte        ; obtain size of record
  1152.     tax            ; start countdown in x reg
  1153.     jsr    clbyte        ; obtain start address
  1154.     sta    *addrh        ; store it
  1155.     jsr    clbyte        ; obtain low address
  1156.     sta    *addrl        ; store it
  1157. ;*
  1158. ;*    now load text
  1159. ;*
  1160. clload:    jsr    clbyte        ; next char
  1161.     beq    cleor        ; branch if count done
  1162.     jsr    store        ; store character
  1163.     jsr    ptrup1        ; up address pointer
  1164.     bra    clload        ; loop until count depleted
  1165. ;*
  1166. ;*    end of record
  1167. ;*
  1168. cleor:    lda    *chksum
  1169.     inca
  1170.     sta    *chksum
  1171.     beq    cmdlt
  1172.     jmp    cmderr
  1173. ;*
  1174. ;*    end of file
  1175. ;*
  1176. cleof:    jsr    clbyte        ; read s9 length
  1177.     tax            ; prepare s9 flush count
  1178. cleofl:    jsr    clbyte        ; skip hex pair
  1179.     bne    cleofl        ; branch more
  1180.     jmp    cmd1
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186. ;*
  1187. ;******************************************************************
  1188. ;*
  1189. ;*    "h"    host communications
  1190. ;*
  1191. ;*        h [<exit char>]
  1192. ;*
  1193. ;*****************************************************************
  1194. ;*
  1195. host:    ldx    #ctla        ; default terminator
  1196.     jsr    chrin        ; go get next character
  1197.     cmp    #0x0d        ; cr?
  1198.     beq    strm        ; yes, set default terminator
  1199.     tax
  1200. strm:    stx    *sava        ; save it
  1201.     jsr    pcrlf        ; new line
  1202. host1:    bsr    tsthst        ; test for host input
  1203. ;*
  1204. ;*    test for terminal input
  1205. ;*
  1206. tsttrm:    lda    duart+1        ; terminal input?
  1207.     rora            ; shift rxrdy to carry bit
  1208.     bcc    host1        ; nope, check host
  1209.     lda    duart+3        ; yep, get character
  1210.     tax            ; save it (parity unmasked)
  1211.     and    #0x7f        ; now mask
  1212.     cmp    *sava        ; char = terminator?
  1213.     beq    mtop        ; yep, terminate mode.
  1214. dowth:    lda    duart+9        ; get status of host mode
  1215.     bit    #0x04
  1216.     beq    dowth        ; wait till ready to xmit
  1217.     stx    duart+0x0b    ; send it!
  1218.     bra    host1        ; continue
  1219.  
  1220. mtop:    jmp    cmd1
  1221. ;*
  1222. ;*    test for host input
  1223. ;*
  1224. tsthst:    lda    duart+9        ; host input?
  1225.     rora            ; shift rxrdy to carry bit
  1226.     bcc    return        ; no char pending
  1227.     ldx    duart+0x0b    ; yep, get character
  1228. tstwait:
  1229.     lda    duart+01    ; status of terminal port?
  1230.     bit    #0x04        ; wait till txrdy
  1231.     beq    tstwait
  1232.     stx    duart+3        ; send the char to the terminal
  1233. return:    rts
  1234. ;*
  1235. ;* interrupt vectors
  1236. ;*
  1237.     .org    0x1ff6
  1238. ;*
  1239.     .word    vecram        ; timer interrupt wait mode
  1240.     .word    vecram+3    ; timer interrupt
  1241.     .word    vecram+6    ; external interrupt handler
  1242.     .word    vecram+9    ; swi handler
  1243.     .word    reset        ; power-on vector
  1244. ;*
  1245.  
  1246. ECUS C  (PDP-11)  compiler  (patch  level   9)   with
  1247.         RT-11/TSX+,  Eyri