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

  1.     .title    assist09 - mc6809 monitor
  2.  
  3.     .module    assist09
  4.  
  5.     .radix    d
  6.  
  7.     ;*  Modification date:  November 23, 1988
  8.  
  9.     ;********************************************************
  10.     ;*  miscelaneous    equates
  11.     ;********************************************************
  12.  
  13. dftchp    =    0        ; default character pad count
  14. dftnlp    =    0        ; default new line pad count
  15. prompt    =    '>        ; prompt character
  16. numbkp    =    8        ; number of breakpoints
  17.  
  18. eot    =    0x04        ; end of transmission
  19. bell    =    0x07        ; bell character
  20. lf    =    0x0a        ; line feed
  21. cr    =    0x0d        ; carriage return
  22. can    =    0x18        ; cancel (ctl-x)
  23.  
  24.     .page
  25.     .sbttl    SWI Functions
  26.  
  27.     ;********************************************************
  28.     ;* assist09 monitor swi functions
  29.     ;*
  30.     ;*  the following equates define functions provided
  31.     ;*  by the assist09 monitor via the swi instruction.
  32.     ;********************************************************
  33.  
  34. inchnp    =    0        ; input char in a reg - no parity
  35. outch    =    1        ; output char from a reg
  36. pdata1    =    2        ; output string
  37. pdata    =    3        ; output cr/lf then string
  38. out2hs    =    4        ; output two hex and space
  39. out4hs    =    5        ; output four hex and space
  40. pcrlf    =    6        ; output cr/lf
  41. space    =    7        ; output a space
  42. monitr    =    8        ; enter assist09 monitor
  43. vctrsw    =    9        ; vector examine/switch
  44. brkpt    =    10        ; user program breakpoint
  45. pause    =    11        ; task pause function
  46. numfun    =    11        ; number of available functions
  47.  
  48.     ;* sub-codes for accessing the vector table.
  49.     ;* they are equivalent to offsets in the table.
  50.     ;* relative positioning must be maintained.
  51.  
  52. .avtbl    =    0        ; address of vector table
  53. .cmdl1    =    2        ; first command list
  54. .rsvd    =    4        ; reserved hardware vector
  55. .swi3    =    6        ; swi3 routine
  56. .swi2    =    8        ; swi2 routine
  57. .firq    =    10        ; firq routine
  58. .irq    =    12        ; irq routine
  59. .swi    =    14        ; swi routine
  60. .nmi    =    16        ; nmi routine
  61. .reset    =    18        ; reset routine
  62. .cion    =    20        ; console on
  63. .cidta    =    22        ; console input data
  64. .cioff    =    24        ; console input off
  65. .coon    =    26        ; console output on
  66. .codta    =    28        ; console output data
  67. .cooff    =    30        ; console output off
  68. .hsdta    =    32        ; high speed printdata
  69. .bson    =    34        ; punch/load on
  70. .bsdta    =    36        ; punch/load data
  71. .bsoff    =    38        ; punch/load off
  72. .pause    =    40        ; task pause routine
  73. .expan    =    42        ; expression analyzer
  74. .cmdl2    =    44        ; second command list
  75. .pad    =    46        ; character pad and new line pad
  76. .echo    =    48        ; echo/load and null bkpt flag
  77.  
  78. numvtr    =    48/2+1        ; number of vectors
  79. hivtr    =    48        ; highest vector offset
  80.  
  81.     .page
  82.     .sbttl    Work Area
  83.  
  84.     ;********************************************************
  85.     ;* work area
  86.     ;*
  87.     ;*  The direct page register during most routine
  88.     ;*  operations will point to this work area.  the Stack
  89.     ;*  initially starts under the reserved work areas as
  90.     ;*  defined herein.
  91.     ;********************************************************
  92.  
  93.     .area    WORKPG    (ABS,OVR)
  94.     .setdp    0
  95.  
  96. workpg:                ; beginning of work aera
  97.  
  98. .blkb    0d256-(endpg-astack)    ; stack space
  99.  
  100. astack:                ; top of assist09 stack
  101. tstack:    .blkb    0d21        ; temporary stack hold
  102. delim:    .blkb    1        ; expression delimiter/work byte
  103. misflg:    .blkb    1        ; load cmd/thru breakpoint flag
  104. swicnt:    .blkb    1        ; trace "swi" nest level count
  105. pcnter:    .blkb    2        ; last program counter
  106. pstack:    .blkb    2        ; command recovery stack
  107. rstack:    .blkb    2        ; reset stack pointer
  108. anumber:.blkb    2        ; binary build area
  109. basepg:    .blkb    1        ; base page value
  110. addr:    .blkb    2        ; address pointer value
  111. window:    .blkb    2        ; window
  112. bkptop:    .blkb    0x10        ; breakpoint opcode table
  113. bkptbl:    .blkb    0x10        ; breakpoint table
  114. vectab:    .blkb    0x32        ; vector table
  115. bkptct:    .blkb    1        ; breakpoint count
  116. swibfl:    .blkb    1        ; bypass swi as breakpoint flag
  117. pauser:    .blkb    4        ; pause routine
  118. endpg:
  119.  
  120.     .page
  121.     .sbttl    Assist09 Code
  122.  
  123.     .area    ASSIST09 (ABS,OVR)
  124.  
  125.     ;********************************************************
  126.     ;* bldvtr - build assist09 vector table
  127.     ;*
  128.     ;*  hardware reset calls this subroutine to build the
  129.     ;*  assist09 vector table.
  130.     ;*
  131.     ;*  input: s->valid stack ram
  132.     ;*  output: u->vector table address
  133.     ;*         dpr->assist09 work area page
  134.     ;*         the vector table and defaults are initialized
  135.     ;*
  136.     ;*  all registers volatile
  137.     ;********************************************************
  138.  
  139. bldvtr:    leax    vectab,pcr    ; address vector table
  140.     tfr    x,d        ; obtain base page address
  141.     tfr    a,dp        ; setup dpr
  142.     sta    *basepg        ; store for quick reference
  143.     leau    ,x        ; return table to caller
  144.     stu    ,x++        ; and init vector table address
  145.     ldb    #numvtr-3    ; number relocatable vectors
  146.     pshs    b        ; store index on stack
  147.     leay    initvt,pcr    ; load from addr
  148. 1$:    tfr    y,d        ; prepare address resolve
  149.     addd    ,y++        ; to absolute address
  150.     std    ,x++        ; into vector table
  151.     dec    ,s        ; count down
  152.     bne    1$        ; branch if more to insert
  153.     ldb    #intve-intvs    ; static value init length
  154. 2$:    lda    ,y+        ; load next byte
  155.     sta    ,x+        ; store into position
  156.     decb            ; count down
  157.     bne    2$        ; loop until done
  158.     puls    pc,b        ; return to initializer
  159.  
  160.     ;********************************************************
  161.     ;* reset entry point
  162.     ;*
  163.     ;*  hardware reset enters here if assist09 is enabled
  164.     ;*  to receive the mc6809 hardware vectors.  we call
  165.     ;*  the bldvtr subroutine to initialize the vector
  166.     ;*  table, stack, and then fireup the monitor via swi
  167.     ;*  call.
  168.     ;********************************************************
  169.  
  170. reset:    leas    astack,pcr    ; setup initial stack
  171.     bsr    bldvtr        ; build vector table
  172. 1$:    clra            ; issue startup message
  173.     tfr    a,dp        ; default to page zero
  174.     swi            ; perform monitor fireup
  175.     .byte    monitr        ; to enter command processing
  176.     bra    1$        ; reenter monitor if 'continue'
  177.  
  178.     .page
  179.     .sbttl    Vector Table
  180.  
  181.     ;********************************************************
  182.     ;* initvt - initialize vector table
  183.     ;*
  184.     ;*  this table is relocated to ram and represents the
  185.     ;*  initial state of the vector table. all addresses
  186.     ;*  are converted to absolute form.  this table starts
  187.     ;*  with the second entry, ends with static constant
  188.     ;*  initialization data which carries beyond the table.
  189.     ;********************************************************
  190.  
  191. initvt:    .word    cmdtb1-.    ; default first command table
  192.     .word    rsrvdr-.    ; default undefined hardware vector
  193.     .word    swi3r-.        ; default swi3
  194.     .word    swi2r-.        ; default swi2
  195.     .word    firqr-.        ; default firq
  196.     .word    irqr-.        ; default irq routine
  197.     .word    swir-.        ; default swi routine
  198.     .word    nmir-.        ; default nmi routine
  199.     .word    reset-.        ; restart vector
  200.     .word    cion-.        ; default cion
  201.     .word    cidta-.        ; default cidta
  202.     .word    cioff-.        ; default cioff
  203.     .word    coon-.        ; default coon
  204.     .word    codta-.        ; default codta
  205.     .word    cooff-.        ; default cooff
  206.     .word    hsdta-.        ; default hsdta
  207.     .word    bson-.        ; default bson
  208.     .word    bsdta-.        ; default bsdta
  209.     .word    bsoff-.        ; default bsoff
  210.     .word    cpause-.    ; default pause routine
  211.     .word    exp1-.        ; default expression analyzer
  212.     .word    cmdtb2-.    ; default second command table
  213.  
  214.     ;* constants
  215.     ;*
  216. intvs:    .byte    dftchp,dftnlp    ; default null padds
  217.     .word    0        ; default echo
  218.     .byte    0        ; initial breakpoint count
  219.     .byte    0        ; swi breakpoint level
  220.     rts            ; default pause routine
  221. intve    =    .
  222.  
  223.     .page
  224.     .sbttl    SWI Handler
  225.  
  226.     ;********************************************************
  227.     ;* assist09 swi handler
  228.     ;*
  229.     ;*  the swi handler provides all interfacing necessary
  230.     ;*  for a user program.  a function byte is assumed to
  231.     ;*  follow the swi instruction.  it is bound checked
  232.     ;*  and the proper routine is given control.  this
  233.     ;*  invocation may also be a breakpoint interrupt.
  234.     ;*  if so, the breakpoint handler is entered.
  235.     ;*
  236.     ;* input: machine state defined for swi
  237.     ;* output: varies according to function called. pc on
  238.     ;*
  239.     ;*     callers stack incremented by one if valid call.
  240.     ;* volatile registers: see functions called
  241.     ;*
  242.     ;* state: runs disabled unless function clears i flag.
  243.     ;********************************************************
  244.  
  245.     ;* swi function vector table
  246.  
  247. swivtb:    .word     zinch-swivtb    ; inchnp
  248.     .word    zotch1-swivtb    ; outch
  249.     .word    zpdta1-swivtb    ; pdata1
  250.     .word    zpdata-swivtb    ; pdata
  251.     .word    zot2hs-swivtb    ; out2hs
  252.     .word    zot4hs-swivtb    ; out4hs
  253.     .word    zpcrlf-swivtb    ; pcrlf
  254.     .word    zspace-swivtb    ; space
  255.     .word    zmontr-swivtb    ; monitr
  256.     .word    zvswth-swivtb    ; vctrsw
  257.     .word    zbkpnt-swivtb    ; breakpoint
  258.     .word    zpause-swivtb    ; task pause
  259.  
  260. swir:    dec    swicnt,pcr    ; up "swi" level for trace
  261.     lbsr    lddp        ; setup page and verify stack
  262.  
  263.     ;* check for breakpoint trap
  264.  
  265.     ldu    10,s        ; load program counter
  266.     leau    -1,u        ; back to swi address
  267.     tst    *swibfl        ; this "swi" breakpoint ?
  268.     bne    2$        ; no - branch to let through
  269.     lbsr    cbkldr        ; obtain breakpoint pointers
  270.     negb            ; obtain positive count
  271. 1$:    decb            ; count down
  272.     bmi    2$        ; branch when done
  273.     cmpu    ,y++        ; ?  was this a breakpoint
  274.     bne    1$        ; branch if not
  275.     stu    10,s        ; set program counter back
  276.     lbra    zbkpnt        ; go do breakpoint
  277.  
  278. 2$:    clr    *swibfl        ; clear in case set
  279.     pulu    d        ; obtain function byte, up pc
  280.     cmpb    #numfun        ; ? too high
  281.     lbhi    error        ; yes, do breakpoint
  282.     stu    10,s        ; bump program counter past swi
  283.     aslb            ; function code times two
  284.     leau    swivtb,pcr    ; obtain vector branch address
  285.     ldd    b,u        ; load offset
  286.     jmp    d,u        ; jump to routine
  287.  
  288.     .page
  289.     .sbttl    Monitor Entry
  290.  
  291.     ;********************************************************
  292.     ;* registers to function routines:
  293.     ;*  dp-> work area page
  294.     ;*  d,y,u=unreliable           x=as called from user
  295.     ;*  s=as from swi interrupt
  296.     ;********************************************************
  297.  
  298.     ;********************************************************
  299.     ;* [swi function 8]
  300.     ;*  monitor entry
  301.     ;*
  302.     ;*  fireup the assist09 monitor.
  303.     ;*  the stack with its values for the direct page
  304.     ;*  register and condition code flags are used as is.
  305.     ;*   1) initialize console i/o
  306.     ;*   2) optionally print signon
  307.     ;*   3) enter command processor
  308.     ;*
  309.     ;* input: a=0 init console and print startup message
  310.     ;*        a#0 omit console init and startup message
  311.     ;********************************************************
  312.  
  313. signon:    .ascii    /Assist09 -- 6809 Monitor/    ; signon eye-catcher
  314.     .byte    eot
  315.  
  316. zmontr:    sts    *rstack        ; save for bad stack recovery
  317.     tst    1,s        ; ? init console and send msg
  318.     bne    1$        ; branch if not
  319.     jsr [vectab+.cion,pcr]    ; ready console input
  320.     jsr [vectab+.coon,pcr]    ; ready console output
  321.     leax    signon,pcr    ; ready signon eye-catcher
  322.     swi            ; perform
  323.     .byte    pdata        ; print string
  324. 1$:                ; fall through to cmd
  325.  
  326.     .page
  327.     .sbttl    Command Processor
  328.  
  329.     ;********************************************************
  330.     ;* command handler
  331.     ;*
  332.     ;*  breakpoints are removed at this time.
  333.     ;*  prompt for a command, and store all characters
  334.     ;*  until a separator on the stack.
  335.     ;*  search for first matching command subset,
  336.     ;*  call it or give '?' response.
  337.     ;*
  338.     ;*  during command search:
  339.     ;*      b=offset to next entry on x
  340.     ;*      u=saved s
  341.     ;*      u-1=entry size+2
  342.     ;*      u-2=valid number flag (>=0 valid)/compare cnt
  343.     ;*      u-3=carriage return flag (0=cr has been done)
  344.     ;*      u-4=start of command store
  345.     ;*      s+0=end of command store
  346.     ;********************************************************
  347.  
  348.     ;********************************************************
  349.     ;* commands are entered as a subroutine with:
  350.     ;*    dpr->assist09 direct page work area
  351.     ;*    z=1 carriage return entered
  352.     ;*    z=0 non carriage return delimiter
  353.     ;*    s=normal return address
  354.     ;*
  355.     ;*  the label "cmdbad" may be entered to issue an
  356.     ;*  an error flag (?).
  357.     ;********************************************************
  358.  
  359. cmd:    swi            ; to new line
  360.     .byte    pcrlf        ; function
  361.  
  362.     ;* disarm the breakpoints
  363.  
  364. cmdnep:    lbsr    cbkldr        ; obtain breakpoint pointers
  365.     bpl    2$        ; branch if not armed or none
  366.     negb            ; make positive
  367.     stb    *bkptct        ; flag as disarmed
  368. 1$:    decb            ; ?  finished
  369.     bmi    2$        ; branch if so
  370.     lda    -numbkp*2,y    ; load opcode stored
  371.     sta    [,y++]        ; store back over "swi"
  372.     bra    1$        ; loop until done
  373. 2$:    ldx    10,s        ; load users program counter
  374.     stx    *pcnter        ; save for expression analyzer
  375.     lda    #prompt        ; load prompt character
  376.     swi            ; send to output handler
  377.     .byte    outch        ; function
  378.     leau    ,s        ; remember stack restore address
  379.     stu    *pstack        ; remember stack for error use
  380.     clra            ; prepare zero
  381.     clrb            ; prepare zero
  382.     std    *anumber    ; clear number build area
  383.     std    *misflg        ; clear miscel. and swicnt flags
  384.     ldb    #2         ; set d to two
  385.     pshs    d,cc        ; place defaults onto stack
  386.  
  387.     ;* check for "quick" commands.
  388.  
  389.     lbsr    read        ; obtain first character
  390.     leax    cmpadp+2,pcr    ; ready memory entry point
  391.     cmpa    #'/        ; open last used memory ?
  392.     beq    11$        ; yes - doit
  393.  
  394.     ;* process next character
  395.  
  396. 3$:    cmpa    #'         ; ? blank or delimiter
  397.     bls    5$        ; branch yes, we have it
  398.     pshs    a        ; build onto stack
  399.     inc    -1,u        ; count this character
  400.     cmpa    #'/        ; ? memory command
  401.     beq    12$        ; branch if so
  402.     lbsr    bldhxc        ; treat as hex value
  403.     beq    4$        ; branch if still valid number
  404.     dec    -2,u        ; flag as invalid number
  405. 4$:    lbsr    read        ; obtain next character
  406.     bra    3$        ; test next character
  407.  
  408.     ;* got command, now search tables
  409.  
  410. 5$:    suba    #cr        ; set zero if carriage return
  411.     sta    -3,u        ; setup flag
  412.     ldx    *vectab+.cmdl1    ; start with first cmd list
  413. 6$:    ldb    ,x+        ; load entry length
  414.     bpl    7$        ; branch if not list end
  415.     ldx    *vectab+.cmdl2    ; now to second cmd list
  416.     incb            ; ? to continue to default list
  417.     beq    6$        ; branch if so
  418. cmdbad=.
  419.     lds    *pstack        ; restore stack
  420.     leax    errmsg,pcr    ; point to error string
  421.     swi            ; send out
  422.     .byte    pdata1        ; to console
  423.     bra    cmd        ; and try again
  424.  
  425.     ;* search next entry
  426.  
  427. 7$:    decb            ; take account of length byte
  428.     cmpb    -1,u        ; ? entered longer than entry
  429.     bhs    9$        ; branch if not too long
  430. 8$:    abx            ; skip to next entry
  431.     bra    6$        ; and try next
  432. 9$:    leay    -3,u        ; prepare to compare
  433.     lda    -1,u        ; load size+2
  434.     suba    #2        ; to actual size entered
  435.     sta    -2,u        ; save size for countdown
  436. 10$:    decb            ; down one byte
  437.     lda    ,x+        ; next command character
  438.     cmpa    ,-y        ; ? same as that entered
  439.     bne    8$        ; branch to flush  if not
  440.     dec    -2,u        ; count down length of entry
  441.     bne    10$        ; branch if more to test
  442.     abx            ; to next entry
  443.     ldd    -2,x        ; load offset
  444.     leax    d,x        ; compute routine address+2
  445. 11$:    tst    -3,u        ; set cc for carriage return test
  446.     leas    ,u        ; delete stack work area
  447.     jsr    -2,x        ; call command
  448.     lbra    2$        ; go get next command
  449. 12$:    tst    -2,u        ; ? valid hex number entered
  450.     bmi    cmdbad        ; branch error if not
  451.     leax    cmemn-cmpadp,x    ; to different entry
  452.     ldd    *anumber    ; load number entered
  453.     bra    11$        ; and enter memory command
  454.  
  455.     .page
  456.     .sbttl    assist09 Command Tables
  457.  
  458.     ;********************************************************
  459.     ;* assist09 command tables
  460.     ;*
  461.     ;*  these are the default command tables.  external
  462.     ;*  tables of the same format may extend/replace
  463.     ;*  these by using the vector swap function.
  464.     ;*
  465.     ;* entry format:
  466.     ;*     +0...total size of entry (including this byte)
  467.     ;*     +1...command string
  468.     ;*     +n...two byte offset to command (entryaddr-.)
  469.     ;*
  470.     ;*  the tables terminate with a one byte -1 or -2.
  471.     ;*  the -1 continues the command search with the
  472.     ;*         second command table.
  473.     ;*  the -2 terminates command searches.
  474.     ;********************************************************
  475.  
  476.     ;* this is the default list for the second command
  477.     ;* list entry.
  478.  
  479. cmdtb2:    .byte    -2        ; stop command searches
  480.  
  481.     ;* this is the default list for the first command
  482.     ;* list entry.
  483.  
  484. cmdtb1:                ; monitor command table
  485.     .byte    4
  486.     .ascii    /B/        ; 'breakpoint' command
  487.     .word    cbkpt-.
  488.     .byte    4
  489.     .ascii    /C/        ; 'call' command
  490.     .word    ccall-.
  491.     .byte    4
  492.     .ascii    /D/        ; 'display' command
  493.     .word    cdi-.
  494.     .byte    4
  495.     .ascii    /E/        ; 'encode' command
  496.     .word    cencde-.
  497.     .byte    4
  498.     .ascii    /G/        ; 'go' command
  499.     .word    cgo-.
  500.     .byte    4
  501.     .ascii    /L/        ; 'load' command
  502.     .word    cload-.
  503.     .byte    4
  504.     .ascii    /M/        ; 'memory' command
  505.     .word    cmem-.
  506.     .byte    4
  507.     .ascii    /N/        ; 'nulls' command
  508.     .word    cnulls-.
  509.     .byte    4
  510.     .ascii    /O/        ; 'offset' command
  511.     .word    coffs-.
  512.     .byte    4
  513.     .ascii    /P/        ; 'punch' command
  514.     .word    cpunch-.
  515.     .byte    4
  516.     .ascii    /R/        ; 'registers' command
  517.     .word    creg-.
  518.     .byte    4
  519.     .ascii    /V/        ; 'verify' command
  520.     .word    cver-.
  521.     .byte    4
  522.     .ascii    /W/        ; 'window' command
  523.     .word    cwindo-.
  524.     .byte    -1        ; end, continue with the second
  525.  
  526.     .page
  527.     .sbttl    SWI Functions
  528.  
  529.     ;********************************************************
  530.     ;* [swi functions 4 and 5]
  531.     ;*
  532.     ;*  4 - out2hs - decode byte to hex and add space
  533.     ;*  5 - out4hs - decode word to hex and add space
  534.     ;*
  535.     ;*  input: x->byte or word to decode
  536.     ;*  output: characters sent to output handler
  537.     ;*         x->next byte or word
  538.     ;********************************************************
  539.  
  540. zout2h:    lda    ,x+        ; load next byte
  541.     pshs    d        ; save - do not reread
  542.     ldb    #16        ; shift by 4 bits
  543.     mul            ; with multiply
  544.     bsr    zouthx        ; send out as hex
  545.     puls    d        ; restore bytes
  546.     anda    #0x0f        ; isolate right hex
  547. zouthx:    adda    #0x90        ; prepare a-f adjust
  548.     daa            ; adjust
  549.     adca    #0x40        ; prepare character bits
  550.     daa             ; adjust
  551. send:    jmp [vectab+.codta,pcr]    ; send to out handler
  552.  
  553. zot4hs:    bsr    zout2h        ; convert first byte
  554. zot2hs:    bsr    zout2h        ; convert byte to hex
  555.     stx    4,s        ; update users x register
  556.  
  557.     ;* fall into space routine
  558.  
  559.     ;********************************************************
  560.     ;* [swi function 7]
  561.     ;*  ace - send blank to output handler
  562.     ;*
  563.     ;*  input: none
  564.     ;*  output: blank send to console handler
  565.     ;********************************************************
  566.  
  567. zspace:    lda    #'         ; load blank
  568.     bra    zotch2        ; send and return
  569.       
  570.     ;********************************************************
  571.     ;* [swi function 9]
  572.     ;*  swap vector table entry
  573.     ;*
  574.     ;*  input:  a=vector table code (offset)
  575.     ;*          x=0 or replacement value
  576.     ;*  output: x=previous value
  577.     ;********************************************************
  578.  
  579. zvswth:    lda    1,s        ; load requesters a
  580.     cmpa    #hivtr        ; ? sub-code too high
  581.     bhi    zotch3        ; ignore call if so
  582.     ldy    *vectab+.avtbl    ; load vector table address
  583.     ldu    a,y        ; u=old entry
  584.     stu    4,s        ; return old value to callers x
  585.     stx    -2,s        ; ? x=0
  586.     beq    zotch3        ; yes, do not change entry
  587.     stx    a,y        ; replace entry
  588.     bra    zotch3        ; return from swi
  589.  
  590.     .page
  591.  
  592.     ;********************************************************
  593.     ;* [swi function 0]
  594.     ;*  inchnp - obtain input char in a (no parity)
  595.     ;*
  596.     ;*  nulls and rubouts are ignored.
  597.     ;*  automatic line feed is sent upon recieving a
  598.     ;*      carriage return.
  599.     ;*  unless we are loading from tape.
  600.     ;********************************************************
  601.  
  602. zinchp:    bsr    xqpaus        ; release processor
  603. zinch:    bsr    xqcidt        ; call input data appendage
  604.     bcc    zinchp        ; loop if none available
  605.     tsta             ; test for null
  606.     beq    zinch        ; ignore null
  607.     cmpa    #0x7f        ; ? rubout
  608.     beq    zinch        ; branch yes to ignore
  609.     sta    1,s        ; store into callers a
  610.     tst    *misflg        ; ? load in progress
  611.     bne    zotch3        ; branch if so to not echo
  612.     cmpa    #cr        ; ? carriage return
  613.     bne    1$        ; no, test echo byte
  614.     lda    #lf        ; load line feed
  615.     bsr    send        ; always echo line feed
  616. 1$:    tst    *vectab+.echo    ; ? echo desired
  617.     bne    zotch3        ; no, return
  618.  
  619.     ;* fall through to outch
  620.  
  621.     ;********************************************************
  622.     ;* [swi function 1]
  623.     ;*  outch - output character from a
  624.     ;*
  625.     ;*  input:  none
  626.     ;*  output: if linefeed is the output character then
  627.     ;*           c=0 no ctl-x recieved, c=1 ctl-x recieved
  628.     ;********************************************************
  629.  
  630. zotch1:    lda    1,s        ; load character to send
  631.     leax    zpcrls,pcr    ; default for line feed
  632.     cmpa    #lf        ; ? line feed
  633.     beq    zpdtlp        ; branch to check pause if so
  634. zotch2:    bsr    send        ; send to output routine
  635. zotch3:    inc    *swicnt        ; bump up "swi" trace nest level
  636.     rti            ; return from "swi" function
  637.  
  638.     ;********************************************************
  639.     ;* [swi function 6]
  640.     ;*  pcrlf - send cr/lf to console handler
  641.     ;*
  642.     ;*  input: none
  643.     ;*  output: cr and lf sent to handler
  644.     ;*          c=0 no ctl-x, c=1 ctl-x recieved
  645.     ;********************************************************
  646.  
  647. zpcrls:    .byte    eot        ; null string
  648.  
  649. zpcrlf:    leax    zpcrls,pcr    ; ready cr,lf string
  650.  
  651.     ;* fall into cr/lf code
  652.  
  653.     ;********************************************************
  654.     ;* [swi function 3]
  655.     ;*  pdata - output cr/lf and string
  656.     ;*
  657.     ;*  input: x->string
  658.     ;*  output: cr/lf and string sent to output console
  659.     ;*         handler.
  660.     ;*     c=0 no ctl-x, c=1 ctl-x recieved
  661.     ;*
  662.     ;*  note: line feed must follow carriage return for
  663.     ;*       proper punch data.
  664.     ;********************************************************
  665.  
  666. zpdata:    lda    #cr        ; load carriage return
  667.     bsr    send        ; send it
  668.     lda    #lf        ; load line feed
  669.  
  670.     ;* fall into    pdata1
  671.  
  672.     ;********************************************************
  673.     ;* [swi function 2]
  674.     ;*  pdata1 - output string till eot (0x04)
  675.     ;*
  676.     ;*  this routine pauses if an input byte becomes
  677.     ;*  available during output transmission until a
  678.     ;*  second is recieved.
  679.     ;*
  680.     ;*  input: x->string
  681.     ;*  output: string sent to output console driver
  682.     ;*         c=0 no ctl-x, c=1 ctl-x recieved
  683.     ;********************************************************
  684.  
  685. zpdtlp:    bsr    send        ; send character to driver
  686. zpdta1:    lda    ,x+        ; load next character
  687.     cmpa    #eot        ; ? eot
  688.     bne    zpdtlp        ; loop if not
  689.  
  690.     ;* fall into pause check function
  691.  
  692.     ;********************************************************
  693.     ;* [swi function 12]
  694.     ;*  pause - return to task dispatching and check
  695.     ;*
  696.     ;*  for freeze condition or ctl-x break
  697.     ;*  this function enters the task pause handler so
  698.     ;*  optionally other 6809 processes may gain control.
  699.     ;*  upon return, check for a 'freeze' condition
  700.     ;*  with a resulting wait loop, or condition code
  701.     ;*  return if a control-x is entered from the input
  702.     ;*  handler.
  703.     ;*
  704.     ;*  output: c=1 if ctl-x has entered, c=0 otherwise
  705.     ;********************************************************
  706.  
  707. zpause:    bsr    xqpaus        ; release control at every line
  708.     bsr    chkabt        ; check for freeze or abort
  709.     tfr    cc,b        ; prepare to replace cc
  710.     stb    ,s        ; overlay old one on stack
  711.     bra    zotch3        ; return from "swi"
  712.  
  713.     ;* chkabt - scan for input pause/abort during output
  714.     ;* output: c=0 ok, c=1 abort (ctl-x issued)
  715.     ;* volatile: u,x,d
  716.  
  717. chkabt:    bsr    xqcidt        ; attempt input
  718.     bcc    2$        ; branch no to return
  719.     cmpa    #can        ; ? ctl-x for abort
  720.     bne    3$        ; branch no to pause
  721. 1$:    comb            ; set carry
  722. 2$:    rts            ; return to caller with cc set
  723.  
  724. 3$:    bsr    xqpaus        ; pause for a moment
  725.     bsr    xqcidt        ; ? key for start
  726.     bcc    3$        ; loop until recieved
  727.     cmpa    #can        ; ? abort signaled from wait
  728.     beq    1$        ; branch yes
  729.     clra            ; set c=0 for no abort
  730.     rts            ; and return
  731.  
  732.     ;* save memory with jumps
  733.  
  734. xqpaus:    jmp [vectab+.pause,pcr]    ; to pause routine
  735. xqcidt:    jsr [vectab+.cidta,pcr]    ; to input routine
  736.     anda    #0x7f        ; strip parity
  737.     rts            ; return to caller
  738.  
  739.  
  740.     ;* lddp - setup direct page register, verify stack.
  741.     ;* an invalid stack causes a return to the command
  742.     ;* handler.
  743.     ;* input: fully stacked registers from an interrupt
  744.     ;* output: dpr loaded to work page
  745.  
  746. errmsg:    .byte    '?,bell,0x20,eot ; error response
  747.  
  748. ldrtn:    rts
  749. lddp:    ldb    basepg,pcr    ; load direct page high byte
  750.     tfr    b,dp        ; setup direct page register
  751.     cmpa    3,s        ; ? is stack valid
  752.     beq    ldrtn        ; yes, return
  753.     lds    *rstack        ; reset to initial stack pointer
  754. error:    leax    errmsg,pcr    ; load error report
  755.     swi            ; send out before registers
  756.     .byte    pdata        ; on next line
  757.  
  758.     ;* fall into breakpoint handler
  759.  
  760.     ;********************************************************
  761.     ;* [swi function 10]
  762.     ;*  breakpoint program function
  763.     ;*
  764.     ;*  print registers and go to command handler
  765.     ;********************************************************
  766.  
  767. zbkpnt:    bsr    zbkstk        ; stack an extra word
  768. zbkcmd:    lbra    cmdnep        ; now enter command handler
  769. zbkstk:    lbsr    regprt        ; print out registers
  770.     rts
  771.  
  772.     ;********************************************************
  773.     ;*    irq, reserved, swi2 and swi3 interrupt handlers
  774.     ;*  the default handling is to cause a breakpoint.
  775.     ;********************************************************
  776.  
  777. swi2r:                ; swi2 entry
  778. swi3r:                ; swi3 entry
  779. irqr:                ; irq entry
  780. nmir:                ; nmi entry
  781. rsrvdr:    bsr    lddp        ; set base page, validate stack
  782.     bra    zbkpnt         ; force a breakpoint
  783.  
  784.     ;********************************************************
  785.     ;*        firq handler
  786.     ;*  just return for the firq interrupt
  787.     ;********************************************************
  788.  
  789. firqr:        rti        ; immediate return
  790.  
  791.     .page
  792.     .sbttl    Read / Verify / Punch Routines
  793.  
  794.     ;* bson - turn on read/verify/punch mechanism
  795.  
  796. bson:    inc    *misflg        ; set load in progress flag
  797.     rts            ; return to caller
  798.  
  799.     ;* bsoff - turn off read/verify/punch mechanism
  800.     ;* a,x volatile
  801.  
  802. bsoff:    dec    *misflg        ; clear load in progress flag
  803.     rts            ; return to caller
  804.  
  805.     ;* bsdta - read/verify/punch handler
  806.     ;* input: s+6=code byte, verify(-1),punch(0),load(1)
  807.     ;*        s+4=start address
  808.     ;*        s+2=stop address
  809.     ;*        s+0=return address
  810.     ;* output: z=1 normal completion, z=0 invalid load/ver
  811.     ;* registers are volatile
  812.  
  813. bsdta:    ldu    2,s        ; u=to address or offset
  814.     tst    6,s        ; ? punch
  815.     beq    10$        ; branch yes
  816.  
  817.     ;* during read/verify: s+2=msb address save byte
  818.     ;*                     s+1=byte counter
  819.     ;*                     s+0=checksum
  820.     ;*                     u holds offset
  821.  
  822.     leas    -3,s        ; room for work/counter/checksum
  823. 1$:    swi            ; get next character
  824.     .byte    inchnp        ; function
  825. 2$:    cmpa    #'S        ; ? start of s1/s9
  826.     bne    1$        ; branch not
  827.     swi            ; get next character
  828.     .byte    inchnp        ; function
  829.     cmpa    #'9        ; ? have s9
  830.     beq    5$        ; yes, return good code
  831.     cmpa    #'1        ; ? have new record
  832.     bne    2$        ; branch if not
  833.     clr    ,s        ; clear checksum
  834.     bsr    9$        ; obtain byte count
  835.     stb    1,s        ; save for decrement
  836.  
  837.     ;* read address
  838.  
  839.     bsr    9$        ; obtain high value
  840.     stb    2,s        ; save it
  841.     bsr    9$        ; obtain low value
  842.     lda    2,s        ; make d=value
  843.     leay    d,u        ; y=address+offset
  844.  
  845.     ;* store text
  846.  
  847. 3$:    bsr    9$        ; next byte
  848.     beq    6$        ; branch if checksum
  849.     tst    9,s        ; ? verify only
  850.     bmi    4$        ; yes, only compare
  851.     stb    ,y        ; store into memory
  852. 4$:    cmpb    ,y+        ; ? valid ram
  853.     beq    3$        ; yes, continue reading
  854. 5$:    puls    pc,x,a        ; return with z set proper
  855.  
  856. 6$:    inca            ; ? valid checksum
  857.     beq    1$        ; branch yes
  858.     bra    5$        ; return z=0 invalid
  859.  
  860.     ;* byte builds 8 bit value from two hex digits in
  861.  
  862. 7$:    bsr    9$        ; obtain first hex
  863.     ldb    #16        ; prepare shift
  864.     mul            ; over to a
  865.     bsr    9$        ; obtain second hex
  866.     pshs    b        ; save high hex
  867.     adda    ,s+        ; combine both sides
  868.     tfr    a,b        ; send back in b
  869.     adda    2,s        ; compute new checksum
  870.     sta    2,s        ; store back
  871.     dec    3,s        ; decrement byte count
  872. 8$:    rts            ; return to caller
  873.  
  874. 9$:    swi            ; get next hex
  875.     .byte    inchnp        ; character
  876.     lbsr    cnvhex        ; convert to hex
  877.     beq    8$        ; return if valid hex
  878.     puls    pc,u,y,x,a    ; return to caller with z=0
  879.  
  880.     ;* punch stack use: s+8=to address
  881.     ;*                  s+6=return address
  882.     ;*                  s+4=saved padding values
  883.     ;*                  s+2 from address
  884.     ;*                  s+1=frame count/checksum
  885.     ;*                  s+0=byte count
  886.  
  887. 10$:    ldu    *vectab+.pad    ; load padding values
  888.     ldx    4,s        ; x=from address
  889.     pshs    u,x,d        ; create stack work area
  890.     ldd    #24        ; set a=0, b=24
  891.     stb    *vectab+.pad    ; setup 24 character pads
  892.     swi            ; send nulls out
  893.     .byte    outch        ; function
  894.     ldb    #4        ; setup new line pad to 4
  895.     std    *vectab+.pad    ; setup punch padding
  896.  
  897.     ;* calculate size
  898.  
  899. 11$:    ldd    8,s        ; load to
  900.     subd    2,s        ; minus from=length
  901.     cmpd    #24        ; ? more than 23
  902.     blo    12$        ; no, ok
  903.     ldb    #23        ; force to 23 max
  904. 12$:    incb            ; prepare counter
  905.     stb    ,s        ; store byte count
  906.     addb    #3        ; adjust to frame count
  907.     stb    1,s        ; save
  908.  
  909.     ;*punch cr,lf,nuls,s,1
  910.  
  911.     leax    16$,pcr        ; load start record header
  912.     swi            ; send out
  913.     .byte    pdata        ; function
  914.  
  915.     ;* send frame count
  916.  
  917.     clrb            ; initialize checksum
  918.     leax    1,s        ; point to frame count and addr
  919.     bsr    14$        ; send frame count
  920.  
  921.     ;*data address
  922.  
  923.     bsr    14$        ; send address hi
  924.     bsr    14$        ; send address low
  925.  
  926.     ;*punch data
  927.  
  928.     ldx    2,s        ; load start data address
  929. 13$:    bsr    14$        ; send out next byte
  930.     dec    ,s        ; ? final byte
  931.     bne    13$        ; loop if not done
  932.     stx    2,s        ; update from address value
  933.  
  934.     ;*punch checksum
  935.  
  936.     comb            ; complement
  937.     stb    1,s        ; store for sendout
  938.     leax    1,s        ; point to it
  939.     bsr    15$        ; send out as hex
  940.     ldx    8,s        ; load top address
  941.     cmpx    2,s        ; ? done
  942.     bhs    11$        ; branch not
  943.     leax    17$,pcr        ; prepare end of file
  944.     swi            ; send out string
  945.     .byte    pdata        ; function
  946.     ldd    4,s        ; recover pad counts
  947.     std    *vectab+.pad    ; restore
  948.     clra            ; set z=1 for ok return
  949.     puls    pc,u,x,d    ; return with ok code
  950.  
  951. 14$:    addb    ,x        ; add to checksum
  952. 15$:    lbra    zout2h        ; send out as hex and return
  953.  
  954. 16$:    .byte    'S,'1,eot     ; cr,lf,nulls,S,1
  955. 17$:    .ascii    /S9030000FC/    ; eof string
  956.     .byte    cr,lf,eot
  957.  
  958.     ;* hsdta - high  speed print memory
  959.     ;* input: s+4=start address
  960.     ;*        s+2=stop address
  961.     ;*        s+0=return address
  962.     ;* x,d volatile
  963.     ;*  send title
  964.  
  965. hsdta:    swi            ; send new line
  966.     .byte    pcrlf        ; function
  967.     ldb    #6        ; prepare 6 spaces
  968. 1$:    swi            ; send blank
  969.     .byte   space        ; function
  970.     decb            ; count down
  971.     bne    1$        ; loop if more
  972.     clrb            ; setup byte count
  973. 2$:    tfr    b,a        ; prepare for convert
  974.     lbsr    zouthx        ; convert to a hex digit
  975.     swi            ; send blank
  976.     .byte    space        ; function
  977.     swi            ; send another
  978.     .byte    space        ; blank
  979.     incb            ; up another
  980.     cmpb    #0x10        ; ? past 'f'
  981.     blo    2$        ; loop until so
  982. 3$:    swi            ; to next line
  983.     .byte    pcrlf        ; function
  984.     bcs    8$        ; return if user entered ctl-x
  985.     leax    4,s        ; point at address to convert
  986.     swi            ; print out address
  987.     .byte    out4hs        ; function
  988.     ldx    4,s        ; load address proper
  989.     ldb    #16        ; next sixteen
  990. 4$:    swi            ; convert byte to hex and send
  991.     .byte    out2hs        ; function
  992.     decb            ; count down
  993.     bne    4$        ; loop if not sixteenth
  994.     swi            ; send blank
  995.     .byte    space        ; function
  996.     ldx    4,s        ; reload from address
  997.     ldb    #16        ; count
  998. 5$:    lda    ,x+        ; next byte
  999.     bmi    6$        ; too large, to a dot
  1000.     cmpa    #'         ; ? lower than a blank
  1001.     bhs    7$        ; no, branch ok
  1002. 6$:    lda    #'.        ; convert invalid to a blank
  1003. 7$:    swi            ; send character
  1004.     .byte    outch        ; function
  1005.     decb            ; ? done
  1006.     bne    5$        ; branch no
  1007.     cpx    2,s        ; ? past last address
  1008.     bhs    8$        ; quit if so
  1009.     stx    4,s        ; update from address
  1010.     lda    5,s        ; load low byte address
  1011.     asla            ; ? to section boundry
  1012.     bne    3$        ; branch if not
  1013.     bra    hsdta        ; branch if so
  1014. 8$:    swi            ; send new line
  1015.     .byte    pcrlf        ; function
  1016.     rts            ; return to caller
  1017.  
  1018.     ;********************************************************
  1019.     ;*     a s s i s t 0 9    c o m m a n d s
  1020.     ;********************************************************
  1021.  
  1022.     ;**********   registers - display and change registers
  1023.  
  1024. creg:    bsr    regprt        ; print registers
  1025.     inca            ; set for change function
  1026.     bsr    regchg        ; go change, display registers
  1027.     rts            ; return to command processor
  1028.  
  1029.     ;********************************************************
  1030.     ;*      regprt - print/change registers subroutine
  1031.     ;*  will abort to 'cmdbad' if overflow detected during
  1032.     ;*  a change operation.  change displays registers when
  1033.     ;*  done.
  1034.     ;*
  1035.     ;* register mask list consists of:
  1036.     ;*  a) characters denoting register
  1037.     ;*  b) zero for one byte, -1 for two
  1038.     ;*  c) offset on stack to register position
  1039.     ;*
  1040.     ;* input:    +4=stacked registers
  1041.     ;*        a=0 print, a#0 print and change
  1042.     ;* output: (only for register display)
  1043.     ;*         c=1 control-x entered, c=0 otherwise
  1044.     ;*
  1045.     ;* volatile: d,x (change)
  1046.     ;*           b,x (display)
  1047.     ;********************************************************
  1048.  
  1049. regmsk:    .byte    'P,'C,-1,19    ; pc reg
  1050.     .byte    'A,0,10        ; a reg
  1051.     .byte    'B,0,11        ; b reg
  1052.     .byte    'X,-1,13    ; x reg
  1053.     .byte    'Y,-1,15    ; y reg
  1054.     .byte    'U,-1,17    ; u reg
  1055.     .byte    'S,-1,1        ; s reg
  1056.     .byte    'C,'c,0,9    ; cc reg
  1057.     .byte    'D,'p,0,12    ; dp reg
  1058.     .byte    0        ; end of list
  1059.  
  1060. regprt:    clra            ; setup print only flag
  1061. regchg:    leax    4+12,s        ; ready stack value
  1062.     pshs    y,x,a        ; save on stack with option
  1063.     leay    regmsk,pcr    ; load register mask
  1064. 1$:    ldd    ,y+        ; load next char or <=0
  1065.     tsta            ; ? end of characters
  1066.     ble    2$        ; branch not character
  1067.     swi            ; send to console
  1068.     .byte    outch        ; function byte
  1069.     bra    1$        ; check next
  1070. 2$:    lda    #'-        ;  ready '-'
  1071.     swi            ; send out
  1072.     .byte    outch        ; with outch
  1073.     leax    b,s        ; x->register to print
  1074.     tst    ,s        ; ? change option
  1075.     bne    5$        ; branch yes
  1076.     tst    -1,y        ; ? one or two bytes
  1077.     beq    3$        ; branch zero means one
  1078.     swi            ; perform word hex
  1079.     .byte    out4hs        ; function
  1080.     bra    4$
  1081.  
  1082. 3$:    swi            ; perform byte hex
  1083.     .byte    out2hs        ; function
  1084. 4$:    ldd    ,y+        ; to front of next entry
  1085.     tstb            ; ? end of entries
  1086.     bne    1$        ; loop if more
  1087.     swi            ; force new line
  1088.     .byte    pcrlf        ; function
  1089.     puls    pc,y,x,a    ; restore stack and return
  1090.  
  1091. 5$:    bsr    bldnnb        ; input binary number
  1092.     beq    7$        ; if change then jump
  1093.     cmpa    #cr        ; ? no more desired
  1094.     beq    9$        ; branch nope
  1095.     ldb    -1,y        ; load size flag
  1096.     decb            ; minus one
  1097.     negb            ; make positive
  1098.     aslb            ; times two (=2 or =4)
  1099. 6$:    swi            ; perform spaces
  1100.     .byte    space        ; function
  1101.     decb
  1102.     bne    6$        ; loop if more
  1103.     bra    4$        ; continue with next register
  1104. 7$:    sta    ,s        ; save delimiter in option
  1105.  
  1106.     ;*                     (always > 0)
  1107.  
  1108.     ldd    *anumber    ; obtain binary result
  1109.     tst    -1,y        ; ? two bytes worth
  1110.     bne    8$        ; branch yes
  1111.     lda    ,-x        ; setup for two
  1112. 8$:    std    ,x        ; store in new value
  1113.     lda    ,s        ; recover delimiter
  1114.     cmpa    #cr        ; ? end of changes
  1115.     bne    4$        ; no, keep on truck'n
  1116.  
  1117.     ;* move stacked data to new stack in case stack
  1118.     ;* pointer has changed
  1119.  
  1120. 9$:    leax    tstack,pcr    ; load temp area
  1121.     ldb    #21        ; load count
  1122. 10$:    puls    a        ; next byte
  1123.     sta    ,x+        ; store into temp
  1124.     decb            ; count down
  1125.     bne    10$        ; loop if more
  1126.     lds    -20,x        ; load new stack pointer
  1127.     ldb    #21        ; load count again
  1128. 11$:    lda    ,-x        ; next to store
  1129.     pshs    a        ; back onto new stack
  1130.     decb            ; count down
  1131.     bne    11$        ; loop if more
  1132.     puls    pc,y,x,a    ; restore stack and return
  1133.  
  1134.     ;********************************************************
  1135.     ;*  bldnum - builds binary value from input hex
  1136.     ;*  the active expression handler is used.
  1137.     ;*
  1138.     ;* input: s=return address
  1139.     ;* output: a=delimiter which terminated value
  1140.     ;*                            (if delm not zero)
  1141.     ;*         "number"=word binary result
  1142.     ;*         z=1 if input recieved, z=0 if no hex recieved
  1143.     ;*
  1144.     ;*  registers are transparent
  1145.     ;********************************************************
  1146.  
  1147.     ;* execute single or extended rom expression handler
  1148.     ;*
  1149.     ;* the flag "delim" is used as follows:
  1150.     ;*   delim=0  no leading blanks, no forced terminator
  1151.     ;*   delim=chr  accept leading 'chr's, forced terminator
  1152.  
  1153. bldnnb:    clra            ; no dynamic delimiter
  1154.     sta    *delim        ; store as delimiter
  1155.     jmp [vectab+.expan,pcr]    ; to exp analyzer
  1156.  
  1157.     ;* build with leading blanks
  1158.  
  1159. bldnum:    lda    #'         ; allow leading blanks
  1160.     sta    *delim        ; store as delimiter
  1161.     jmp [vectab+.expan,pcr]    ; to exp analyzer
  1162.     
  1163.     ;* this is the default single rom analyzer. we accept:
  1164.     ;*    1) hex input
  1165.     ;*    2) 'M' for last memory examine address
  1166.     ;*    3) 'P' for program counter address
  1167.     ;*    4) 'W' for window value
  1168.     ;*    5) '@' for indirect value
  1169.  
  1170. exp1:    pshs    x,b        ; save registers
  1171. 1$:    bsr    bldhxi        ; clear number, check first char
  1172.     beq    3$        ; if hex digit continue building
  1173.  
  1174.     ;* skip blanks if desired
  1175.  
  1176.     cmpa    *delim        ; ? correct delimiter
  1177.     beq    1$        ; yes, ignore it
  1178.  
  1179.     ;* test for m or p
  1180.  
  1181.     ldx    *addr        ; default for 'm'
  1182.     cmpa    #'M        ; ? memory examine addr wanted
  1183.     beq    5$        ; branch if so
  1184.     ldx    *pcnter        ; default for 'p'
  1185.     cmpa    #'P        ; ? last program counter wanted
  1186.     beq    5$        ; branch if so
  1187.     ldx    *window        ; default to window
  1188.     cmpa    #'W        ; ? window wanted
  1189.     beq    5$
  1190. 2$:    puls    pc,x,b        ; return and restore registers
  1191.  
  1192.     ;* got hex, now continue building
  1193.  
  1194. 3$:    bsr    bldhex        ; compute next digit
  1195.     beq    3$        ; continue if more
  1196.     bra    6$        ; search for +/-
  1197.  
  1198.     ;* store value and check if need delimiter
  1199.  
  1200. 4$:    ldx    ,x        ; indirection desired
  1201. 5$:    stx    *anumber    ; store result
  1202.     tst    *delim        ; ? to force a delimiter
  1203.     beq    2$        ; return if not with value
  1204.     bsr    read        ; obtain next character
  1205.  
  1206.     ;* test for + or -
  1207.  
  1208. 6$:    ldx    *anumber    ; load last value
  1209.     cmpa    #'+        ; ? add operator
  1210.     bne    8$        ; branch not
  1211.     bsr    10$        ; compute next term
  1212.     pshs    a        ; save delimiter
  1213.     ldd    *anumber    ; load new term
  1214. 7$:    leax    d,x        ; add to x
  1215.     stx    *anumber    ; store as new result
  1216.     puls    a        ; restore delimiter
  1217.     bra    6$        ; now test it
  1218. 8$:    cmpa    #'-        ; ? subtract operator
  1219.     beq    9$        ; branch if so
  1220.     cmpa    #'@        ; ? indirection desired
  1221.     beq    4$        ; branch if so
  1222.     clrb            ; set delimiter return
  1223.     bra    2$        ; and return to caller
  1224. 9$:    bsr    10$        ; obtain next term
  1225.     pshs    a        ; save delimiter
  1226.     ldd    *anumber    ; load up next term
  1227.     nega            ; negate a
  1228.     negb            ; negate b
  1229.     sbca    #0        ; correct for a
  1230.     bra    7$        ; go add to expresion
  1231.  
  1232.     ;* compute next expression term
  1233.     ;* output: x=old value
  1234.     ;*         'number'=next term
  1235.  
  1236. 10$:    bsr    bldnum        ; obtain next value
  1237.     lbne    cmdbad        ; abort command if invalid
  1238.     rts            ; return if valid number
  1239.  
  1240.     ;********************************************************
  1241.     ;*  build binary value using input characters.
  1242.     ;*
  1243.     ;* input: a=ascii hex value or delimiter
  1244.     ;*           +0=return address
  1245.     ;*           +2=16 bit result area
  1246.     ;* output: z=1 a=binary value
  1247.     ;*         z=0 if invalid hex character (a unchanged)
  1248.     ;*
  1249.     ;* volatile: d
  1250.     ;********************************************************
  1251.  
  1252. bldhxi:    clr    *anumber    ; clear number
  1253.     clr    *anumber+1    ; clear number
  1254. bldhex:    bsr    read        ; get input character
  1255. bldhxc:    bsr    cnvhex        ; convert and test character
  1256.     bne    cnvrts        ; return if not a number
  1257.     ldb    #16        ; prepare shift
  1258.     mul            ; by four places
  1259.     lda    #4        ; rotate binary into value
  1260. 1$:    aslb            ; obtain next bit
  1261.     rol    *anumber+1    ; into low byte
  1262.     rol    *anumber    ; into hi byte
  1263.     deca            ; count down
  1264.     bne    1$        ; branch if more to do
  1265.     bra    cnvok        ; set good return code
  1266.  
  1267.     ;********************************************************
  1268.     ;* convert ascii character to binary byte
  1269.     ;*
  1270.     ;* input: a=ascii
  1271.     ;* output: z=1 a=binary value
  1272.     ;*         z=0 if invalid
  1273.     ;*
  1274.     ;* all registers transparent
  1275.     ;* (a unaltered if invalid hex)
  1276.     ;********************************************************
  1277.  
  1278. cnvhex:    cmpa    #'0        ; ? lower tigh hex
  1279.     blo    cnvrts        ; branch not value
  1280.     cmpa    #'9        ; ? possible a-f
  1281.     ble    cnvgot        ; branch no to accept
  1282.     cmpa    #'A        ; ? less than ten
  1283.     blo    cnvrts        ; return if minus (invalid)
  1284.     cmpa    #'F        ; ? not too large
  1285.     bhi    cnvrts        ; no, return too large
  1286.     suba    #7        ; down to binary
  1287. cnvgot:    anda    #0x0f        ; clear high byte
  1288. cnvok:    orcc    #4        ; force zero on for valid hex
  1289. cnvrts:    rts            ; return to caller
  1290.  
  1291.     ;* get input char, abort command if control-x (cancel)
  1292.  
  1293. read:    swi            ; get next character
  1294.     .byte    inchnp        ; function
  1295.     cmpa    #can        ; ? abort command
  1296.     lbeq    cmdbad        ; branch to abort if so
  1297.     rts            ; return to caller
  1298.  
  1299.  
  1300.     ;************    console - dumby routines
  1301.  
  1302. cidta:    clc            ; never a character
  1303. codta:                ; dumby character out
  1304. cion:                ; input console initialization
  1305. coon:                ; output console initialization
  1306. cioff:                ; console input off
  1307. cooff:                ; console output off
  1308. cirtn:    rts
  1309.  
  1310.     ;************    pause - process pause routine
  1311.  
  1312. cpause:    jmp    pauser        ; go to default pause routine
  1313.  
  1314.  
  1315.     ;************    go - start program execution
  1316.  
  1317. cgo:    bsr    goaddr        ; build address if needed
  1318.     rti            ; start executing
  1319.  
  1320.     ;* find optional new program counter. also arm the
  1321.     ;* breakpoints.
  1322.  
  1323. goaddr:    puls    y,x        ; pop return addresses from cmd and cgo
  1324.     pshs    x        ; restore return from cgo
  1325.     beq    1$        ; <cr> ? yes - use current pc
  1326.  
  1327.     ;* obtain new program counter
  1328.  
  1329.     lbsr    cdnum        ; obtain new program counter
  1330.     std    12,s        ; store into stack
  1331.  
  1332. 1$:    ldx    12,s        ; load program counter
  1333.     lbsr    cbkldr        ; obtain table
  1334.     neg    *bkptct        ; complement to show armed
  1335. 2$:    decb            ; ? done
  1336.     bmi    5$        ; return when done
  1337.     lda    [,y]        ; load opcode
  1338.     sta    -numbkp*2,y    ; store into opcode table
  1339.     lda    #0x3f        ; ready "swi" opcode
  1340.     cmpx    ,y        ; starting at a breakpoint ?
  1341.     bne    4$        ; no - go set breakpoint
  1342.  
  1343.     cmpa    [,y++]        ; ? swi breakpointed
  1344.     bne    2$        ; no, skip setting of flag
  1345.     sta    *swibfl        ; show upcomming swi not brkpnt
  1346.     bra    2$        ; check others
  1347.  
  1348. 4$:    sta    [,y++]        ; store and move up table
  1349.     bra    2$        ; and continue
  1350.  
  1351. 5$:    rts
  1352.  
  1353.     ;************    call - call address as subroutine
  1354.  
  1355. ccall:    bsr    goaddr        ; fetch address if needed
  1356.     puls    u,y,x,dp,d,cc    ; restore users registers
  1357.     jsr    [,s++]        ; call user subroutine
  1358. 1$:    swi            ; perform breakpoint
  1359.     .byte    brkpt        ; function
  1360.     bra    1$        ; loop until user changes pc
  1361.  
  1362.     ;************    memory - display/change memory
  1363.     ;*    cmem and cmpadp are direct entry points from
  1364.     ;*    the command handler for quick commands
  1365.  
  1366. cmem:    lbsr    cdnum        ; obtain address
  1367. cmemn:    std    *addr        ; store default
  1368. 1$:    ldx    *addr        ; load pointer
  1369.     lbsr    zout2h        ; send out hex value of byte
  1370.     lda    #'-        ; load delimiter
  1371.     swi            ; send out
  1372.     .byte    outch        ; function
  1373. 2$:    lbsr    bldnnb        ; obtain new byte value
  1374.     beq    3$        ; branch if number
  1375.  
  1376.     ;* coma - skip byte
  1377.  
  1378.     cmpa    #',        ; ? comma
  1379.     bne    4$        ; branch not
  1380.     stx    *addr        ; update pointer
  1381.     leax    1,x        ; to next byte
  1382.     bra    2$        ; and input it
  1383. 3$:    ldb    *anumber+1    ; load low byte value
  1384.     bsr    13$        ; go overlay memory byte
  1385.     cmpa    #',        ; ? continue with no display
  1386.     beq    2$        ; branch yes
  1387.  
  1388.     ;* quoted string
  1389.  
  1390. 4$:    cmpa    #''        ; ? quoted string
  1391.     bne    6$        ; branch no
  1392. 5$:    bsr    read        ; obtain next character
  1393.     cmpa    #''        ; ? end of quoted string
  1394.     beq    7$        ; yes, quit string mode
  1395.     tfr    a,b        ; to b for subroutine
  1396.     bsr    13$        ; go update byte
  1397.     bra    5$        ; get next character
  1398.  
  1399.     ;* blank - next byte
  1400.  
  1401. 6$:    cmpa    #0x20        ; ? blank for next byte
  1402.     bne    8$        ; branch not
  1403.     stx    *addr        ; update pointer
  1404. 7$:    swi            ; give space
  1405.     .byte    space        ; function
  1406.     bra    1$
  1407.  
  1408.     ;* dot - next byte with address
  1409.  
  1410. 8$:    cmpa    #'.        ; ? dot for next byte
  1411.     bne    9$        ; branch no
  1412.     swi            ; force new line
  1413.     .byte    pcrlf        ; function
  1414.     stx    *addr        ; store next address
  1415.     bra    cmpadp        ; branch to show
  1416.  
  1417.     ;* up arrow - previous byte and address
  1418.  
  1419. 9$:    cmpa    #'^        ; ? up arrow for previous byte
  1420.     bne    11$        ; branch not
  1421.     leax    -2,x        ; down to previous byte
  1422.     stx    *addr        ; store new pointer
  1423. 10$:    swi            ; force new line
  1424.     .byte    pcrlf        ; function
  1425. cmpadp=.
  1426.     bsr    12$        ; go print its value
  1427.     bra    1$        ; then prompt for input
  1428.  
  1429.     ;* slash - for current byte with address
  1430.  
  1431. 11$:    cmpa    #'/        ; ? slash for current display
  1432.     beq    10$        ; yes, send address
  1433.     rts            ; return from command
  1434.  
  1435.     ;* print current address
  1436.  
  1437. 12$:    ldx    *addr        ; load pointer value
  1438.     pshs    x        ; save x on stack
  1439.     leax    ,s        ; point to it for display
  1440.     swi            ; display pointer in hex
  1441.     .byte    out4hs        ; function
  1442.     puls    pc,x        ; recover pointer and return
  1443.  
  1444.     ;* update byte
  1445.  
  1446. 13$:    ldx    *addr        ; load next byte pointer
  1447.     stb    ,x+        ; store and increment x
  1448.     cmpb    -1,x        ; ?  successfull store
  1449.     bne    14$        ; branch for '?'  if not
  1450.     stx    *addr        ; store new pointer value
  1451.     rts            ; back to caller
  1452.  
  1453. 14$:    pshs    a        ; save a register
  1454.     lda    #'?        ; show invalid
  1455.     swi            ; send out
  1456.     .byte    outch        ; function
  1457.     puls    pc,a        ; return to caller
  1458.  
  1459.     ;************    window  -  set window value
  1460.  
  1461. cwindo:    bsr    cdnum        ; obtain window value
  1462.     std    *window        ; store it in
  1463.     rts            ; end command
  1464.  
  1465.     ;************    display - high speed display memory
  1466.  
  1467. cdi:    bsr    cdnum        ; fetch address
  1468.     andb    #0xf0        ; force to 16 boundry
  1469.     tfr    d,y        ; save in y
  1470.     leax    15,y        ; default length
  1471.     bcs    1$        ; branch if end of input
  1472.     bsr    cdnum        ; obtain count
  1473.     leax    d,y        ; assume count, compute end addr
  1474. 1$:    pshs    y,x        ; setup parameters for hsdata
  1475.     cmpd    2,s        ; ? was it count
  1476.     bls    2$        ; branch yes
  1477.     std    ,s        ; store high address
  1478. 2$:    jsr [vectab+.hsdta,pcr]    ; call print routine
  1479.     puls    pc,u,y        ; clean stack and end command
  1480.  
  1481.     ;* obtain number - abort if none
  1482.     ;* only delimiters of cr, blank, or '/' are accepted
  1483.     ;* output: d=value, c=1 if carriage return delmiter,
  1484.     ;*                                  else c=0
  1485. cdnum:    lbsr    bldnum        ; obtain number
  1486.     lbne    cmdbad        ; branch if invalid
  1487.     cmpa    #'/        ; ? valid delimiter
  1488.     lbhi    cmdbad        ; branch if not for error
  1489.     cmpa    #cr+1        ; leave compare for carriage ret
  1490.     ldd    *anumber    ; load number
  1491.     rts
  1492.  
  1493.     ;************    punch - punch memory in s1-s9 format
  1494.  
  1495. cpunch:    bsr    cdnum        ; obtain start address
  1496.     tfr    d,y        ; save in y
  1497.     bsr    cdnum        ; obtain end address
  1498.     clr    ,-s        ; setup punch function code
  1499.     pshs    y,d        ; store values on stack
  1500. ccalbs:    jsr [vectab+.bson,pcr]    ; initialize handler
  1501.     jsr [vectab+.bsdta,pcr]    ; perform function
  1502.     pshs    cc        ; save return code
  1503.     jsr [vectab+.bsoff,pcr]    ; turn off handler
  1504.     puls    cc        ; obtain condition code saved
  1505.     lbne    cmdbad        ; branch if error
  1506.     puls    pc,y,x,a    ; return from command
  1507.  
  1508.     ;************    load - load memory from s1-s9 format
  1509.  
  1510. cload:    bsr    clvofs        ; call setup and pass code
  1511.     .byte    1        ; load function code for packet
  1512.  
  1513. clvofs:    leau    [,s++]        ; load code in high byte of u
  1514.     leau    [,u]        ; not changing cc and restore s
  1515.     beq    1$        ; branch if carriage return next
  1516.     bsr    cdnum        ; obtain offset
  1517.     bra    2$
  1518.  
  1519. 1$:    clra            ; create zero offset
  1520.     clrb            ; as default
  1521. 2$:    pshs    u,dp,d        ; setup code, null word, offset
  1522.     bra    ccalbs        ; enter call to bs routines
  1523.  
  1524.     ;************    verify - compare memory with files
  1525.  
  1526. cver:    bsr    clvofs        ; compute offset if any
  1527.     .byte    -1        ; verify fnctn code for packet
  1528.  
  1529.     ;************    nulls  -  set new line and char padding
  1530.  
  1531. cnulls:    bsr    cdnum        ; obtain new line pad
  1532.     std    *vectab+.pad    ; reset values
  1533.     rts            ; end command
  1534.  
  1535.     ;************    offset - compute short and long
  1536.     ;*                branch offsets
  1537.  
  1538. coffs:    bsr    cdnum        ; obtain instruction address
  1539.     tfr    d,x        ; use as from address
  1540.     bsr    cdnum        ; obtain to address
  1541.  
  1542.     ;* d=to instruction, x=from instruction offset byte(s)
  1543.  
  1544.     leax    1,x        ; adjust for *+2 short branch
  1545.     pshs    y,x        ; store work word and value on s
  1546.     subd    ,s        ; find offset
  1547.     std    ,s        ; save over stack
  1548.     leax    1,s        ; point for one byte display
  1549.     sex            ; sign extend low byte
  1550.     cmpa    ,s        ; ? valid one byte offset
  1551.     bne    1$        ; branch if not
  1552.     swi            ; show one byte offset
  1553.     .byte    out2hs        ; function
  1554. 1$:    ldu    ,s        ; reload offset
  1555.     leau    -1,u        ; convert to long branch offset
  1556.     stu    ,x        ; store back where x points now
  1557.     swi            ; show two byte offset
  1558.     .byte    out4hs        ; function
  1559.     swi            ; force new line
  1560.     .byte    pcrlf        ; function
  1561.     puls    pc,x,d        ; restore stack and end command
  1562.  
  1563.     ;************    breakpoint - display/enter/delete/clear
  1564.     ;*                breakpoints
  1565.  
  1566. cbkpt:    beq    5$        ; branch display of just 'b'
  1567.     lbsr    bldnum        ; attempt value entry
  1568.     beq    7$        ; branch to add if so
  1569.     cmpa    #'-        ; ? correct delimiter
  1570.     bne    9$        ; no, branch for error
  1571.     lbsr    bldnum        ; attempt delete value
  1572.     beq    2$        ; got one, go delete it
  1573.     clr    *bkptct        ; was 'b -', so zero count
  1574. 1$:    rts            ; end command
  1575.  
  1576.     ;* delete the entry
  1577.  
  1578. 2$:    bsr    11$        ; setup registers and value
  1579. 3$:    decb            ; ? any entries in table
  1580.     bmi    9$        ; branch no, error
  1581.     cmpx    ,y++        ; ? is this the entry
  1582.     bne    3$        ; no, try next
  1583.  
  1584.     ;* found, now move others up in its place
  1585.  
  1586. 4$:    ldx    ,y++        ; load next one up
  1587.     stx    -4,y        ; move down by one
  1588.     decb            ; ? done
  1589.     bpl    4$        ; no, continue move
  1590.     dec    *bkptct        ; decrement breakpoint count
  1591. 5$:    bsr    11$        ; setup registers and load value
  1592.     beq    1$        ; return if none to delete
  1593. 6$:    leax    ,y++        ; point to next entry
  1594.     swi            ; display in hex
  1595.     .byte    out4hs        ; function
  1596.     decb            ; count down
  1597.     bne    6$        ; loop if more to do
  1598.     swi            ; skip to new line
  1599.     .byte    pcrlf        ; function
  1600.     rts            ; return to end command
  1601.  
  1602.     ;* add new entry
  1603.  
  1604. 7$:    bsr    11$        ; setup registers
  1605.     cmpb    #numbkp        ; ? already full
  1606.     beq    9$        ; branch error if so
  1607.     lda    ,x        ; load byte to trap
  1608.     stb    ,x        ; try to change
  1609.     cmpb    ,x        ; ? changable ram
  1610.     bne    9$        ; branch error if not
  1611.     sta    ,x        ; restore byte
  1612. 8$:    decb            ; count down
  1613.     bmi    10$        ; branch if done to add it
  1614.     cmpx    ,y++        ; ? entry already here
  1615.     bne    8$        ; loop if not
  1616. 9$:    lbra    cmdbad        ; exit with error
  1617.  
  1618. 10$:    stx    ,y        ; add this entry
  1619.     clr    -numbkp*2+1,y    ; clear optional byte
  1620.     inc    *bkptct        ; add one to count
  1621.     bra    5$        ; and now display all of 'em
  1622.  
  1623.     ;* setup registers for scan
  1624.  
  1625. 11$:    ldx    *anumber    ; load value desired
  1626. cbkldr:    leay    bkptbl,pcr    ; load start of table
  1627.     ldb    *bkptct        ; load entry count
  1628.     rts            ; return
  1629.  
  1630.     ;************    encode  -  encode a postbyte
  1631.  
  1632. cencde:    clr    ,-s        ; default to not indirect
  1633.     clrb            ; zero postbyte value
  1634.     leax    conv1,pcr    ; start table search
  1635.     swi            ; obtain first character
  1636.     .byte    inchnp        ; function
  1637.     cmpa    #'[        ; ? indirect here
  1638.     bne    2$        ; branch if not
  1639.     lda    #0x10        ; set indirect bit on
  1640.     sta    ,s        ; save for later
  1641. 1$:    swi            ; obtain next character
  1642.     .byte    inchnp        ; function
  1643. 2$:    cmpa    #cr        ; ? end of entry
  1644.     beq    4$        ; branch yes
  1645. 3$:    tst    ,x        ; ? end of table
  1646.     lbmi    cmdbad        ; exit with error
  1647.     cmpa    ,x++        ; ? this the character
  1648.     bne    3$        ; branch if not
  1649.     addb    -1,x        ; add this value
  1650.     bra    1$        ; get next input
  1651. 4$:    leax    conv2,pcr    ; point at table 2
  1652.     tfr    b,a        ; save copy in a
  1653.     anda    #0x60        ; isolate register mask
  1654.     ora    ,s        ; add in indirection bit
  1655.     sta    ,s        ; save back as postbyte skeleton
  1656.     andb    #0x9f        ; clear register bits
  1657. 5$:    tst    ,x        ; ? end of table
  1658.     lbeq    cmdbad        ; exit with error
  1659.     cmpb    ,x++        ; ? same value
  1660.     bne    5$        ; loop if not
  1661.     ldb    -1,x        ; load result value
  1662.     orb    ,s        ; add to base skeleton
  1663.     stb    ,s        ; save postbyte on stack
  1664.     leax    ,s        ; point to it
  1665.     swi            ; send out as hex
  1666.     .byte    out2hs        ; function
  1667.     swi            ; to next line
  1668.     .byte    pcrlf        ; function
  1669.     puls    pc,b        ; end of command
  1670.        
  1671.     ;* table one defines valid input in sequence
  1672. conv1:    .byte    'A,0x04,'B,0x05,'D,0x06,'H,0x01
  1673.     .byte    'H,0x01,'H,0x01,'H,0x00,',,0x00
  1674.     .byte    '-,0x09,'-,0x01,'S,0x70,'Y,0x30
  1675.     .byte    'U,0x50,'X,0x10,'+,0x07,'+,0x01
  1676.     .byte    'P,0x80,'C,0x00,'R,0x00,'],0x00
  1677.     .byte    0xff        ; end of table
  1678.  
  1679.     ;*conv2 uses above conversion to set postbyte
  1680.     ;*                             bit skeleton.
  1681.  
  1682. conv2:    .word    0x1084,0x1100    ; R,        H,R
  1683.     .word    0x1288,0x1389    ; HH,R      HHHH,R
  1684.     .word    0x1486,0x1585    ; A,R       B,R
  1685.     .word    0x168b,0x1780    ; D,R       ,R+
  1686.     .word    0x1881,0x1982    ; ,R++      ,-R
  1687.     .word    0x1a83,0x828c    ; ,--R      HH,pcr
  1688.     .word    0x838d,0x039f    ; HHHH,pcr  [HHHH]
  1689.     .byte    0        ; end of table
  1690.  
  1691.     ;****************************************************
  1692.     ;*            default interrupt transfers           *
  1693.     ;****************************************************
  1694.  
  1695. rsrvd:    jmp    [vectab+.rsvd,pcr]    ; reserved vector
  1696. swi3:    jmp    [vectab+.swi3,pcr]    ; swi3 vector
  1697. swi2:    jmp    [vectab+.swi2,pcr]    ; swi2 vector
  1698. firq:    jmp    [vectab+.firq,pcr]    ; firq vector
  1699. irq:    jmp    [vectab+.irq,pcr]    ; irq vector
  1700. swi:    jmp    [vectab+.swi,pcr]    ; swi vector
  1701. nmi:    jmp    [vectab+.nmi,pcr]    ; nmi vector
  1702.  
  1703.     .page
  1704.     .sbttl    Hardware Interrupt Tables
  1705.  
  1706.     ;********************************************************
  1707.     ;*             assist09 hardware vector table
  1708.     ;*
  1709.     ;*  this table is used if the assist09 rom addresses
  1710.     ;*  the mc6809 hardware vectors.
  1711.     ;********************************************************
  1712.  
  1713.     .=  bldvtr+0d2048-0d16    ; assume 2K ROM
  1714.  
  1715.     .word    rsrvd        ; reserved slot
  1716.     .word    swi3        ; software interrupt 3
  1717.     .word    swi2        ; software interrupt 2
  1718.     .word    firq        ; fast interrupt request
  1719.     .word    irq        ; interrupt request
  1720.     .word    swi        ; software interrupt
  1721.     .word    nmi        ; non-maskable interrupt
  1722.     .word    reset        ; restart
  1723.  
  1724.            beq     label
  1725.                 bhcc    label           bhcs    label
  1726.