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