home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / hd64180a.lbr / EXECMON.AZM / EXECMON.ASM
Encoding:
Assembly Source File  |  1991-08-04  |  30.4 KB  |  1,405 lines

  1.     title    'Core Board Monitor - EXEC Version'
  2. ;****************************************************************
  3. ;
  4. ;    Dicko's Universal Monitor Program.
  5. ;
  6. ; This version has been tricked up for CORE BOARD.
  7. ; Notables are:
  8. ;
  9. ;    Written     by Richard Holmes    24-05-86
  10. ;    Last update by Richard Holmes    24-01-89
  11. ;
  12. ; Make it run any program located at 02000h        24/01/1989
  13. ;****************************************************************
  14. ;
  15.     name    'ExecMon'
  16.     public    cmon
  17. ; Exec Equates.
  18.     extrn    exec
  19. ;
  20.     extrn    bel$cnt                ; Bell down counter
  21. ;
  22.     extrn    con$out, con$inp, con$ist
  23.     extrn    prn$out
  24. ;
  25.     public    ?time                ; Base of time parameter table
  26.     public    ksec,kmin,khrs
  27.     public    kdow,kdom,kmth
  28.     public    kyrs
  29. ;
  30.     extrn    ext$ldr
  31. ;
  32.     maclib    z80
  33.     maclib    core
  34.     maclib    exec
  35. ;
  36. ;
  37. ilhlp    equ    false            ; Inline help
  38. ;
  39. cpos1    equ    01bh            ; Cursor positioning lead in code
  40. cpos2    equ    '='
  41. offset    equ    020h            ; Offset for vdu cursor positioning
  42. cscrn    equ    01ah            ; Clear screen code
  43. ;
  44. pgm$base equ    02000h
  45. ;
  46. ;++++++++++++++++++++++++++++++++
  47. ;
  48. ;    Start of program
  49. ;
  50. ;++++++++++++++++++++++++++++++++
  51. ;
  52. cmon:
  53.     jmp    start$mon        ; Leap over interrupt table
  54. ;
  55. ; Restart 1 address.
  56.     org    8
  57.     jmp    exec
  58. ; Restart 2 address.
  59.     org    16            ; Restart 2 address
  60. ;
  61. int$tbl:
  62.     dw    int$ctc0
  63.     dw    int$ctc1
  64.     dw    int$ctc2
  65.     dw    int$ctc3
  66. ;
  67.     db    'Copyright (C) 1986 Richard C Holmes'
  68. ;
  69. ;++++++++++++++++++++++++++++++++
  70. ;   Power fail detect handler
  71. ;++++++++++++++++++++++++++++++++
  72. ;
  73.     org    066h            ; NMI location
  74. ;
  75.     xra    a
  76.     out    046h            ; Turn OFF the memory
  77. ; Stop any IORAM boards
  78.     out    04eh            ; Clear control port to ioram
  79.  
  80.     hlt                ; HALT the processor
  81. ;
  82. ;++++++++++++++++++++++++++++++++
  83. ;  ---- Interrupt drivers ----
  84. ;++++++++++++++++++++++++++++++++
  85. ;
  86. int$ctc0:
  87. int$ctc1:
  88.     ei
  89.     reti
  90. ;
  91. ;----------------------------------------------------------------
  92. ;               ---- Real time clock ----
  93. ;
  94. ; Port 30h will tell of the clock interrupt that occured and 
  95. ; reset the source of interrupts.
  96. ;----------------------------------------------------------------
  97. ;
  98. int$ctc3:
  99.     push    psw
  100.     in    030h        ; Read clock int. status to reset interrupt
  101.     mvi    a,'K'        ; Indicate a clock output
  102.     call    coe
  103.     pop    psw
  104.     ei
  105.     reti
  106. ;
  107. ;----------------------------------------------------------------
  108. ; This is the 1ms periodic interrupt handler. It will decrement the
  109. ; prescaler till it hits ZERO then reload, decrement the bell timer
  110. ; and then when this hits 0, turn OFF the buzzer. This is good for
  111. ; implimenting an interrupt driven buzzer.
  112. ;----------------------------------------------------------------
  113. ;
  114. int$ctc2:
  115.     push    psw
  116. ;
  117.     lda    prescale
  118.     dcr    a
  119.     sta    prescale
  120.     jnz    skip$int2
  121. ; At 0. Reload the prescaler
  122.     mvi    a,10
  123.     sta    prescale
  124. ;
  125. ; Save other used registers
  126.     push    h
  127. ; See if the bell counter is greater than 0.
  128.     lhld    bel$cnt
  129.     mov    a,l
  130.     ora    h
  131.     jz    end$int2        ; Exit if < 1. Dead now.
  132. ;
  133. ; Greater than 0. Hmm.
  134.     dcx    h
  135.     shld    bel$cnt
  136.     mov    a,l
  137.     ora    h            ; Hit 0 now ????
  138.     jnz    end$int2        ; Non zero and skip
  139. ; Stop the bell
  140.     xra    a
  141.     out    @buz            ; Turns off bell
  142. ;
  143. ;
  144. end$int2:
  145.     pop    h
  146. skip$int2:
  147.     pop    psw
  148.     ei
  149.     reti
  150. ;
  151. ;
  152. ;****************************************************************
  153. ;*          Start of the main program here            * 
  154. ;*            Setups and initializations                        *
  155. ;****************************************************************
  156. ;
  157. start$mon:
  158.     lxi    sp,stack
  159. ;
  160.     mvi    a,080h            ; Port C outputs, A&B outputs
  161.     out    047h
  162.     mvi    a,040h
  163.     out    046h
  164. ;
  165. ; Initialize EXEC System
  166.     mvi    c,0
  167.     rst    1
  168. ;
  169. ; Setup interrupts on the CTC
  170. ; Load vector
  171. ; Load down counter
  172. ;
  173.     di
  174.     xra    a
  175.     sta    int$cnt            ; Clear an interrupt counter
  176. ;
  177.     lxi    h,int$tbl        ; HL -> interrupt vectors
  178.     mov    a,l
  179.     out    @ctc0            ; Bit 0 = 0 means a vector
  180. ;
  181.     mov    a,h            ; Get high table address
  182.     stai
  183. ;
  184. ; Clear the interrupt out line from the clock.
  185. ;
  186.     xra    a
  187.     out    31h            ; Stop interrupts from the clock
  188.     in    30h            ; Clear any pending.
  189.     sta    dump$lst
  190.     sta    dump$lst + 1
  191. ;
  192. ; Select a 1 count on the CTC from the clock. Any other count will hang 
  193. ; because the interrupt out line is only cleared when the 30h port is read.
  194. ;
  195.     mvi    a,0D5h            ; Counter mode, interrupts, tc follows
  196.     out    @ctc3
  197. ;
  198.     mvi    a,1            ; Trigger on a 1 count.
  199.     out    @ctc3            ; Last CTC
  200. ;
  201.     in    030h            ; Clear any interrupt pending again.
  202. ;
  203. ; Setup a periodic interrupt for CTC 2
  204. ;
  205.     mvi    a,085h            ; Interrupt enable, Timer, 16 prescale
  206.     out    @ctc2
  207.     mvi    a,0fdh            ; This gives accurate 1khz interrupt
  208.     out    @ctc2
  209.     mvi    a,10
  210.     sta    prescale
  211. ;
  212.     im2                ; Interrupt mode 2
  213.     ei
  214. ;
  215. ;+--------------------------------+
  216. ;|     Actual monitor start       |
  217. ;+--------------------------------+
  218. ;
  219. amon:    ; Start off
  220. ;
  221.     lda    pgm$base
  222.     cpi    0ffh
  223.     jnz    pgm$base        ; Run any program at 2000h.
  224. ;
  225. amon1:
  226.     lxi    d,signon        ; Go print the message
  227.     call    ptxt
  228. ;
  229. ; Warm1 is the restart address after all routines are finished.
  230. ;
  231. warm:    
  232.     Lxi     sp,stack        ; Re-set the stack
  233.     lxi    d,signon2
  234.     call    ptxt            ; Print the M> message
  235.     call    echo            ; Get character and echo it
  236. ;
  237.     cpi    cr
  238.     jrz    warm
  239.     cpi    lf
  240.     jrz    warm
  241.     cpi    ' '
  242.     jrz    warm
  243.     cpi    '@'
  244.     jz    code$load
  245. ;
  246.  
  247.     cpi    esc
  248.     jrz    warm
  249.     mov    c,a
  250.     push    b            ; Save character
  251.     call    space            ; Space across 1
  252.     call    gaddr            ; Get operands
  253.         pop    b
  254.     mov    a,c            ; Restore first command
  255.     lxi    h,warm            ; Save address of re-entry
  256.     push    h            ; On stack
  257.     lded    opr1             ; Operand 1
  258.      lxiy    stcktop            ; Set iy to stack top
  259. ;
  260. ;****************************************************************
  261. ;*            Check key against table            *
  262. ;****************************************************************
  263. ;
  264.     if    ilhlp            ; If help is allowed, check for it
  265.     cpi    '?'
  266.     jz    help
  267.     endif
  268. ;
  269.     sui    'A'
  270.     jrc    erdisp            ; Incorrect command
  271.     cpi    'Z'-'A'+1        ; Only A to Z allowed.
  272.     jrnc    erdisp
  273.     add    a            ; *2
  274.     push    d            ; Save it
  275.     mov    e,a
  276.     mvi    d,0            ; Index into table
  277.     lxi    h,jmptbl        ; Table of routines
  278.     dad    d            ; Point to it
  279.     mov    e,m
  280.     inx    h
  281.     mov    d,m
  282.     xchg
  283.     pop    d            ; Restore
  284.     push    h            ; Load stack with routine address
  285.     lhld    opr2
  286.     ret                ; To the routine
  287. ;
  288. code$load:
  289.     call    ext$ldr
  290.     jmp    warm
  291. ;
  292. ;****************************************************************
  293. ;*         Display a ? for an error prompt            *
  294. ;****************************************************************
  295. ;
  296. erdisp:
  297.     mvi    a,'?'            ; ? = illegal data
  298.     call    coe
  299.     jmp    warm            ; Re-enter monitor
  300. ;
  301. ;*******************************************************
  302. ; Inline help screen. Pressing a '?' displays this lot *
  303. ;*******************************************************
  304. ;
  305. help:
  306.     if    ilhlp
  307. ;
  308.     lxi    d,help$text
  309.     call    ptxt
  310.     jmp    warm
  311. help$text:
  312.     db    0dh,0ah,'A = Ascii Dump of memory        A 5000<cr>'
  313.     db    0dh,0ah,'D = Display memory              D 5000<cr>'
  314.     db    0dh,0ah,'E = Examine memory              E 5000<cr>'
  315.     db    0dh,0ah,'F = Fill memory                 F 5000 5010 FF<cr>'
  316.     db    0dh,0ah,'G = Goto and execute memory     G 100<cr>'
  317.     db    0dh,0ah,'H = Hex sum and difference      H 4000 5000<cr>'
  318.     db    0dh,0ah,'I = Input from a port           I 68<cr>'
  319.     db    0dh,0ah,'I = Multiple input from a port  I 88 n<cr>'
  320.     db    0dh,0ah,'K = Read clock                  K<cr>'
  321.     db    0dh,0ah,'K y m d w m h s Set Clock'
  322.     db    0dh,0ah,'L = Locate a string of bytes    L 0 100 1 2 3 4 5<cr>'
  323.     db    0dh,0ah,'M = Move memory                 M 5000 5010 6000<cr>'
  324.     db    0dh,0ah,'O = Output to a port            O 88 55<cr>'
  325.     db    0dh,0ah,'O = Multiple port output        O 88 55 n<cr>'
  326.     db    0dh,0ah,'P = Examine a port              P 88<cr>'
  327.     db    0dh,0ah,'P = Port map                    P ^<cr>'
  328.     db    0dh,0ah,'Q = Quit this program           Q<cr>'
  329.     db    0dh,0ah,'S = Substitute memory           S 5000<cr>'
  330.     db    0dh,0ah,'T = Test memory                 T 5000 6000<cr>'
  331.     db    0dh,0ah,'U = Write console to ram        U 5000<cr>...^Z'
  332.     db    0dh,0ah,'V = Verify memory               V 4000 5000 5001<cr>'
  333.     db    03
  334.     endif
  335.     ret
  336. ;
  337. ;****************************************************************
  338. ; Display memory as if it were a page of text. Hex data is not  *
  339. ; displayed, it is converted into a '.' to be comaptible with   *
  340. ; the dump command.                        *
  341. ;****************************************************************
  342. ;
  343. adump:
  344.     lda    opcnt
  345.     ora    a
  346.     jz    erdisp            ; No operands cause an error
  347.     cpi    1            ; 1 operand gives a screen full
  348.     jrz    scrnful
  349. ; Display from start to a finish. Start is in de, finish in hl
  350.     call    rngchk            ; Check end is after the start
  351.     lhld    opr2            ; Re-load ending address if ok.
  352. adump1:
  353.     push    h            ; Save ending address
  354.     ldax    d            ; Get the character
  355.     call    makasc            ; make it ascii into C
  356.     call    coe
  357.     inx    d            ; Bump memory source address
  358.     ora    a            ; Clear carry
  359.     dsbc    d            ; Subtract current address from end 
  360.     pop    h            ; Restore the ending address
  361.     jrnz    adump1            ; When equal, next page is asked for
  362. ;
  363. ; Here we read the console for an escape or a space
  364. adwait:    ; Wait for a legitimate ascii dump command
  365.     call    cie
  366.     cpi    esc
  367.     jz    warm
  368.     cpi    ' '            ; next K ?
  369.     jrz    adump2
  370.     cpi    '^'            ; Previous K ?
  371.     jrz    adump3
  372.     cpi    '?'            ; Do you want to know the address ??
  373.     jrnz    adwait            ; If not this then keep on waiting
  374.     call    prhl            ; Print the current ending address
  375.     jr    adwait            ; Wait on Norelle, all things come....
  376. ;
  377. adump2:    ; Add the standard screen display amount to the end address
  378.     lxi    b,1024            ; Dsiplay the next 1k
  379.     dad    b            ; End address is now 1k on
  380.     call    crlf
  381.     jr    adump1
  382. ;
  383. adump3:    ; Display the previous k to the one on the screen
  384.     ora    a            ; Clear carry
  385.     lxi    b,2048            ; A sort of double back up is required
  386.     dsbc    b            ; HL & DE point to 2 k back
  387.     push    h
  388.     pop    d            ; Copy end into start
  389.     jr    adump2            ; Load the new end address
  390. ;
  391. ; Here the user entered only one operand so he wants a standard screenfull
  392. scrnful:
  393.     push    d
  394.     pop    h            ; Copy start address into end
  395.     jr    adump2
  396. ;
  397. ;****************************************************************
  398. ;     Execute a program at an optional address        *
  399. ;****************************************************************
  400. ;
  401. go:    lda    opcnt             ; See if operands entered
  402.     ana    a
  403.     jrz    go1            ; Use last given address
  404.     sded    temp8
  405. go1:
  406.     lhld    temp8
  407.     pchl                ; Start execution at the address
  408. ;
  409. ;****************************************************************
  410. ;*        Block move memory routine            *
  411. ;****************************************************************
  412. ;
  413. move:    call    rngchk            ; See that end > start
  414.     mov    b,h
  415.     mov    c,l            ; Bc = count of bytes
  416.     xchg        
  417.     lded    opr3            ; Get destination
  418.     ora    a
  419.     dsbc    d            ; Check no everlay
  420.     jrnc    move2            ; Skip if likely
  421.     lhld    opr3            ; Get back dest
  422.     dad    b            ; Add to byte count
  423.     dcx    h            ; Less 1
  424.     mov    d,h
  425.     mov    e,l            ; Copy to de
  426.     lhld    opr2            ; Get end
  427.     lddr                ; Fill backwards
  428.     ret
  429. ;
  430. move2:    lhld    opr1            ; Forward block move
  431.     ldir
  432. move1:    ret
  433. ;
  434. ;****************************************************************
  435. ;*        This is the hexadecimal calculator        *
  436. ;****************************************************************
  437. ;
  438. hexad:    
  439.     push    h
  440.     dad    d            ; Add opr1 and opr2
  441.     mvi    a,'+'             ; Display sum
  442.     call    coe
  443.     call    prhl            ; Display contents hl
  444.     call    space            ; Space
  445.     pop    h            ; Restore opr2
  446.     xchg                ; Swap opr1 and opr2
  447.     ora    a            ; Clear flags
  448.     dsbc    d            ; Subtract other way
  449.     mvi    a,'-' 
  450.     call    coe            ; Display difference
  451.     jmp    prhl
  452. ;
  453. ;****************************************************************
  454. ;*        Exam port contents                *
  455. ;*        cmd => i pp (x) where x means forever        *
  456. ;****************************************************************
  457. ;
  458. portin:
  459. ;****************************************************************
  460. ;*        Exam port contents                *
  461. ;*        cmd => i pp (x) where x means forever        *
  462. ;****************************************************************
  463. ;
  464. portin:
  465. ; Get the port number into C
  466.     lda    opr1
  467.     mov    c,a            ; Save port number
  468.     mvi    b,0            ; Upper low to read internal/external
  469.     inp    a            ; Read port
  470.     cma
  471.     mov    e,a            ; Ensure impossible value in E 1st time
  472.     mvi    d,0            ; Load count before a CR,LF
  473. ;
  474.     lxi    h,1            ; Default count into HL
  475.     lda    opcnt            ; How many operands
  476. ; Specified opcode count ?
  477.     cpi    2            ; 2 ?
  478.     jrc    porti1            ; Skip if less
  479.     lhld    opr2            ; Get operand 2 (no.Displays)
  480. ;
  481. ; First time round we need a heading
  482. porti1:
  483.     call    crlf
  484.     mov    a,c
  485.     call    phacc            ; Display port no.+ space
  486.     call    space
  487.     mvi    a,'-'
  488.     call    coe
  489. ;
  490. ;----------------------------------------------------------------
  491. ; Port input loop. Wait for a port change then display it. If
  492. ; decremented number of displays required = 0 then exit.
  493. ;
  494. ; -- Use registers as --
  495. ;  HL = count of items printed total
  496. ;   D = count of items printed on a line 0..7
  497. ;   E = the previous port image
  498. ;   C = port number
  499. ;----------------------------------------------------------------
  500. ;
  501. portin$loop:
  502.     call    clrwdt            ; Clear watchdog
  503.     mvi    b,0
  504.     inp    a
  505. ;
  506.     cmp    e
  507.     jrz    porti3
  508. ;
  509. ; Else if not equal, display the new value
  510. ;
  511.     mov    e,a            ; Save new value port image
  512.     call    space
  513.     mov    a,e
  514.     call    phacc            ; Go display value
  515.     inr    d            ; One more displayed
  516.     mov    a,d
  517.     cpi    8
  518.     jrnz    porti2
  519. ; End of line, cr/lf and port address
  520.     mvi    d,0
  521.     call    crlf
  522.     mov    a,c            ; Port number
  523.     call    phacc            ; Display port no.+ space
  524.     call    space
  525.     mvi    a,'-'
  526.     call    coe
  527. ;
  528. ; Decrement the HL count and if 0 then exit.
  529. porti2:
  530.     dcx    h
  531.     mov    a,l
  532.     ora    h            ; Does H = L = 0 ????
  533.     rz                ; Exit if end
  534. ;
  535. ; If port is same as previous image then come to this routine 
  536. ; and check for an escape key.
  537. ;
  538. porti3:
  539.     call    cst
  540.     jrz    portin$loop
  541.     call    cie
  542.     cpi    esc
  543.     jrnz    portin$loop
  544.     ret
  545. ;
  546. ;****************************************************************
  547. ;*        Output a value to a port            *
  548. ;*        cmd => o pp (xx) (yy)                *
  549. ;*    xx= data yy = optional count, 0 = forever        *
  550. ;****************************************************************
  551. ;
  552. portout:
  553.     lda    opr2            ; Get data
  554.     mov    d,a            ; Into d
  555.     lxi    b,1            ; Default count = 1
  556.     lda    opcnt            ; See how many operands
  557.     cpi    3
  558.     jrc    pout1            ; Skip if < 3
  559.     lbcd    opr3            ; Get loop count
  560. pout1:
  561.     push    b
  562.     lda    opr1            ; Get port no.
  563.     mov    c,a            ; To c
  564.     outp    d            ; Send data in D to port in A
  565.     pop    b
  566.     call    chkabrt            ; See if abort wanted
  567.     dcx    b
  568.     mov    a,c
  569.     ora    b
  570.     jrnz    pout1            ; Counter - 1
  571.     ret
  572. ;
  573. ;****************************************************************
  574. ;*        Fill memory with data                *
  575. ;*        cmd => f ssss ffff dd                *
  576. ;****************************************************************
  577. ;
  578. fill:    lda    opr3            ; Get data to fill with
  579.     push    h            ; Save hl
  580.     call    rngchk            ; Check de < hl
  581.     pop    h
  582. fill1:    stax    d            ; Save data
  583.     push    h
  584.     ora    a            ; Clear flags leave acc.
  585.     dsbc    d            ; See if address match
  586.     pop    h            ; Restore end address
  587.     inx    d            ; Next location
  588.     jrnz    fill1            ; Skip if no match
  589.     ret
  590. ;
  591. ;****************************************************************
  592. ;*        Locate a string in memory            *
  593. ;*        cmd => l ssss ffff b1 b2 b3... B5        *
  594. ;****************************************************************
  595. ;
  596. locat:    
  597.     call    rngchk            ; Make sure end > start
  598.     lda    opcnt            ; How many operands
  599.     sui    3            ; Subtract 3
  600.     jc    erdisp            ; Error 3 minimum
  601.     mov    b,a            ; Save difference
  602.     inr    a            ; Add 1
  603.     sta    opcnt           ; Save operand count
  604.     lxi    h,opr4-1
  605.     lxi    d,opr4
  606. locat1:    ldax    d            ; Get data
  607.     mov    m,a            ; Save it
  608.     inx    h            ; Next location
  609.     inx    d
  610.     inx    d
  611.     djnz    locat1            ; Loop till all operands crushed
  612. locat2:    lda    opcnt
  613.     mov    b,a            ; Save opcount
  614.     lhld    opr1            ; Get start address
  615.     lxi    d,opr3
  616. locat3:    ldax    d            ; Get operand
  617.     cmp    m            ; Compare to memory
  618.     jrnz    locat4            ; Skip if no match
  619.     inx    h            ; Next memory location
  620.     inx    d            ; Next operand
  621.     djnz    locat3            ; Opcount - 1
  622.     lhld    opr1
  623.     call    prhl            ; Memory address
  624.     call    crlf            ; New line
  625.     call    chkabrt            ; See if abort wanted
  626. locat4:    lhld    opr2            ; Get end address
  627.     lded    opr1             ; Get start address
  628.     ora    a
  629.     dsbc    d            ; Compare them
  630.     rz                ; If same, exit
  631.     inx    d            ; Next location
  632.     sded    opr1            ; Update start address
  633.     jr    locat2            ; Loop around
  634. ;
  635. ;****************************************************************
  636. ;*        Verify 2 blocks of memory            *
  637. ;*        cmd => v ssss ffff ssss                *
  638. ;****************************************************************
  639. ;
  640. verify:    
  641.     call    rngchk            ; Check start and end address
  642.     push    h            ; Save difference
  643.     pop    b            ; Count into bc
  644.     xchg                ; Swap start and end
  645.     lded    opr3             ; Get destination block
  646. verif1:    ldax    d            ; Byte from dest
  647.     cci                ; Block compare with increment
  648.     inx    d            ; Next locat for test
  649.     jrnz    verif2            ; If no match skip
  650.     rpo                ; End of compare, exit
  651.     jr    verif1            ; Loop
  652. ;
  653. verif2:    push    psw            ; No match
  654.     push    b
  655.     push    d            ; Save all regs
  656.     dcx    h            ; Go back one location
  657.     call    prhl            ; Display pointer
  658.     mov    a,m            ; Get contents
  659.     inx    h            ; Increment pointer
  660.     call    pracc            ; Print value
  661.     pop    d
  662.     push    d
  663.     push    h
  664.     xchg                ; Get dest block
  665.     dcx    h            ; Back one
  666.     call    prhl            ; Print pointer
  667.     mov    a,m            ; Get data
  668.     call    phacc            ; Display it also
  669.     call    crlf            ; New line
  670.     pop    h
  671.     pop    d
  672.     pop    b
  673.     pop    psw            ; Restore regs
  674.     rpo
  675.     call    chkabrt            ; Test for abort key
  676.     jr    verif1            ; Then loop
  677. ;
  678. ;****************************************************************
  679. ;*        Test memory for errors                *
  680. ;*        cmd => t ssss ffff                *
  681. ;****************************************************************
  682. ;
  683. mtest:    
  684.     xchg                ; Swap start and end
  685.     inx    d            ; De = start+1
  686.     mvi    b,0            ; Count = 256
  687. mtest1:    lhld    opr1            ; Get start address
  688. mtest2:    mov    a,l
  689.     xra    h            ; Compare to h
  690.     xra    b            ; Then count
  691.     mov    m,a            ; Save in memory (auto change)
  692.     inx    h            ; Next location
  693.     push    h            ; Save pointer
  694.     ora    a            ; Clear flags
  695.     dsbc    d            ; Start - dest
  696.     pop    h            ; Restore pointer
  697.     jnz    mtest2            ; Loop if not finished
  698. ;
  699.     call    clrwdt
  700.     call    clrwdt
  701.     lhld    opr1            ; Get back start address
  702. mtest3:    
  703.     mov    a,l
  704.     out    @wdt
  705.     xra    h
  706.     xra    b            ; Reconstruct data to test
  707.     cmp    m
  708.     cnz    mtest4            ; If no match, display error
  709.     inx    h            ; Next loc
  710.     push    h            ; Save it
  711.     ora    a
  712.     dsbc    d            ; See if end of test
  713.     pop    h
  714.     jnz    mtest3            ; Skip if not
  715.     inr    b            ; Bit count done
  716.     call    chkabrt            ; See if abort wanted
  717.     mvi    a,'P'            ; Indicate 1 pass
  718.     call    coe
  719.     call    clrwdt
  720.     call    clrwdt
  721.     jr    mtest1            ; Loop to restart
  722. ;
  723. mtest4:    push    psw            ; Save test byte
  724.     call    clrwdt
  725.     call    prhl            ; Print address
  726.     pop    psw
  727.     call    pracc            ; Print test byte
  728.     mov    a,m            ; Get invalid data
  729.     call    pracc            ; Print it also
  730.     jmp    crlf            ; Display crlf, then return
  731. ;
  732. ;****************************************************************
  733. ;*        Dump memory contents                *
  734. ;*        cmd => d ssss                    *
  735. ;****************************************************************
  736. ;
  737. dump:
  738.     lda    opcnt            ; Get count
  739.     ora    a
  740.     jrz    dump$again        ; Dump from previous use address
  741. ;
  742.     cpi    1            ; See if < 2
  743.     jnz    erdisp            ; One operand = start address ONLY
  744.     lded    opr1            ; Get the start address
  745.     sded    dump$lst        ; Save dump start address for next time
  746. dump$again:
  747.     lded    dump$lst
  748. ;
  749. ; 16 lines to dispplay
  750. dsp$mem:
  751.     call    crlf
  752.     mvi    b,16            ; Lines to display
  753. dsp$mem$loop:
  754.     call    dsp$line
  755.     call    crlf
  756.     djnz    dsp$mem$loop
  757. ;
  758.     call    cie
  759.     cpi    01bh
  760.     rz
  761.     cpi    cr
  762.     jrz    dsp$mem            ; Display the next page a CR
  763.     cpi    ' '
  764.     jrz    dsp$mem            ; Display next page if a space
  765.     cpi    lf
  766.     jrz    dsp$mem            ; Next page if a lf
  767.     cpi    '+'
  768.     jrz    next$k
  769.     cpi    '-'
  770.     jrz    lst$k
  771.     ret
  772. ;
  773. next$k:
  774.     lxi    h,1024            ; 1k
  775.     dad    d
  776.     xchg
  777.     jr    dsp$mem
  778. ;
  779. lst$k:
  780.     xchg
  781.     lxi    d,1024
  782.     ora    a
  783.     dsbc    d
  784.     xchg
  785.     jr    dsp$mem
  786. ;
  787. ;------------------------------------
  788. ; ---- Display a line of memory ----
  789. ;------------------------------------
  790. ;
  791. dsp$line:
  792.     push    b            ; Save external counters
  793. ; Now the address from DE
  794.     call    phde            ; Print as hex
  795.     call    space
  796. ;
  797.     push    d            ; Save the address also
  798.     mvi    b,16            ; 16 bytes
  799. dl1:
  800.     ldax    d
  801.     inx    d
  802.     call    phacc            ; Print as hex
  803.     inx    h
  804.     call    space            ; Separator
  805. ; Middle ?
  806.     mov    a,b
  807.     cpi    9
  808.     jnz    dl11
  809.     mvi    a,'-'
  810.     call    coe
  811.     call    space
  812. dl11:
  813.     call    clrwdt            ; Stop the dog
  814.     djnz    dl1
  815. ;
  816.     call    space2
  817.     pop    d            ; Restore the memory address
  818.     mvi    b,16
  819. dl2:
  820.     ldax    d
  821.     inx    d
  822.     call    makasc
  823.     call    coe
  824.     call    clrwdt
  825.     djnz    dl2
  826. ;
  827.     pop    b            ; Restore counters
  828.     ret
  829. ;
  830. ;****************************************************************
  831. ;*        Examine / alter memory locations        *
  832. ;*        cmd => e llll (xx)                *
  833. ;****************************************************************
  834. ;
  835. exmem:    
  836.     xchg                ; Hl gets start
  837. exmem1:    call    prhl            ; Display pointer
  838.     mov    a,m            ; Get byte
  839.     call    phacc            ; Print hex value
  840.     mvi    a,'-'
  841.     call    coe            ; Then marker
  842.     push    h
  843.     call    gaddr            ; Get data from user
  844.     pop    h
  845.     lda    opcnt            ; Get bytes entered
  846.     ani    3
  847.     jrz    exmem3            ; If none, skip
  848.     lda    opr1            ; Get data
  849.     mov    m,a            ; Copy to memory
  850.     inx    h            ; Next location
  851.     lda    lastchr
  852.     cpi    00dh            ; Was it a carriage ret ?
  853.     jrz    exmem1            ; Skip if so
  854. exmem2:    dcx    h            ; Restore pointer
  855.     jr    exmem1            ; Loop
  856. ;
  857. exmem3:    lda    lastchr            ; Get back last char
  858.     cpi    '^'            ; Was it an up-carrot
  859.     jrz    exmem2            ; If so, stay on this location
  860.     inx    h            ; Else next location
  861.     jr    exmem1            ; Loop around
  862. ;
  863. ;****************************************************************
  864. ;*        Port examine / modify command            *
  865. ;*        cmd => p pp                     *
  866. ;****************************************************************
  867. ;
  868. port:    ; See if display whole port space
  869.     lda    lastchr            ; Get the character
  870.     cpi    '^'            ; Carrot causes whole page
  871.     jrz    pmap
  872.     cpi    '&'
  873.     jrnz    porta
  874. ; Do a repeated port map display with cursor positioning. An escape ends it.
  875. cport:
  876.     mvi    a,cscrn            ; Erase screen code
  877.     call    coe
  878. cport1:
  879. ; DO a cursor position to line 5 column 1
  880.     mvi    a,cpos1            ; First cursor position code
  881.     call    coe
  882.     mvi    a,cpos2            ; Second cursor position code
  883.     call    coe
  884.     mvi    a,3+offset        ; Row + offset first
  885.     call    coe
  886.     mvi    a,1+offset        ; Column next
  887.     call    coe
  888.     call    pmap            ; Display the port map
  889.     jr    cport1
  890. ;
  891. pmap:
  892. ; This section causes the whole port address space to be displayed
  893.     mvi    e,16            ; Number of 16 port lines
  894.     mvi    c,00            ; Start at port 00
  895. pm1:
  896.     mvi    b,16            ; 16 ports per line displayed
  897.     mov    l,c            ; Get start port #
  898.     mvi    h,00
  899.     push    b
  900.     call    crlf            ; Space apart
  901.     call    prhl2            ; Print port #
  902.     pop    b
  903. pm2:
  904.     inp    a            ; Get the port from (c)
  905.     push    b            ; Save the counters
  906.     call    pracc            ; Print a port & a space
  907.     call    prsep            ; Check if we need a line separator
  908.     call    chkabrt            ; Detect if we need to quit-a-motto
  909.     pop    b
  910.     inr    c            ; Next port next time
  911.     djnz    pm2
  912. ; Detect if all lines have been sent to screen ( = all ports done)
  913.     dcr    e            ; Decrement line counter
  914.     mov    a,e
  915.     ora    a            ; End of the lines ?
  916.     jrnz    pm1
  917.     ret
  918. ;
  919. porta:
  920.     lda    opr1            ; Get port no
  921.     mov    c,a            ; Into c
  922. port1:    mov    a,c            ; Get back port no
  923.     call    pracc            ; Display it
  924.     inp    a            ; Get contents
  925.     call    pracc            ; Print also
  926.     push    b
  927.     call    gaddr            ; See if data to be altered
  928.     pop    b
  929.     lda    lastchr            ; Get character entered
  930.     mov    h,a
  931.     lda    opcnt            ; Get opcount
  932.     ana    a
  933.     jrz    port3            ; If none, skip
  934.     lda    opr1
  935.     outp    a            ; Send data out
  936.     mvi    a,'^'            ; Test for carrot
  937.     cmp    h
  938.     jrz    port1            ; Skip if so
  939. port2:    inr    c            ; Next port number
  940.     jr    port1            ; Loop
  941. ;
  942. port3:    mvi    a,'^'
  943.     cmp    h
  944.     jrnz    port2            ; Skip if not carrot
  945.     dcr    c            ; Port no.- 1
  946.     jr    port1
  947. ;
  948. ;****************************************************************
  949. ;
  950. ;         Quit the monitor                *
  951. ;                                *
  952. ;****************************************************************
  953. ;
  954. quit:
  955.     lhld    usr$stk
  956.     sphl
  957.     ret
  958. ;
  959. ;****************************************************************
  960. ;      Enter a string into memory at opr1 till an escape.       *    
  961. ;****************************************************************
  962. ;
  963. string:
  964.     lda    opcnt
  965.     cpi    1
  966.     jnz    warm            ; Only one operand allowed
  967.     xchg                ; Put the destination address in hl
  968. ; Do a crlf then enter text till a control Z
  969.     lxi    d,00            ; Set up a character counter
  970. string1:
  971.     call    cie            ; Get a character
  972.     cpi    01ah            ; Control Z
  973.     jrz    string2            ; End of the command.
  974.     cpi    esc
  975.     cnz    coe            ; No echo of control codes.
  976.     mov    m,a            ; Put into memory
  977.     inx    h
  978.     inx    d            ; Bump pointers
  979.     jr    string1
  980. string2:    ; Here when the user has had enough and entered a control Z
  981.     call    crlf
  982.     xchg                ; Put character counter into hl
  983.     mvi    a,'>'
  984.     call    coe
  985.     call    prhl            ; Print the number of characters
  986.     jmp    warm            ; Process next command
  987. ;
  988. ;****************************************************************
  989. ;*    Clock routines to set and clear the clock registers    *
  990. ;****************************************************************
  991. ;
  992. clock:
  993.     lxi    h,?time            ; Clock string
  994.     lda    opcnt
  995.     ora    a            ; See if set/display
  996.     jrz    readit
  997. ;
  998. writit:
  999.     cpi    6            ; Should be 7 operands (0-6)
  1000.     jc    erdisp            ; Error not enough
  1001.     lda    opr1
  1002.     sta    kdom            ; Day of month
  1003.     lda    opr2
  1004.     sta    kmth            ; Month number
  1005.     lda    opr3
  1006.     sta    kyrs            ; Year number
  1007.     lda    opr4
  1008.     sta    kdow            ; Day of week
  1009. ;
  1010.     lda    opr5
  1011.     sta    khrs            ; Hours
  1012.     lda    opr6
  1013.     sta    kmin            ; Minutes
  1014.     lda    opr7
  1015.     sta    ksec            ; Seconds
  1016.     lxi    d,?time
  1017.     jmp    clkwr            ; Go write clock from ?time
  1018. ;
  1019. readit:
  1020.     lxi    d,?time
  1021.     call    clkrd            ; Go read clock string
  1022.     call    crlf            ; Select next line
  1023. ; Dat in format dd/mm/yy
  1024.     lda    kdom            ; Day of month
  1025.     call    phacc            ; Print date
  1026.     mvi    a,'/'
  1027.     call    coe
  1028.     lda    kmth            ; Month
  1029.     call    phacc
  1030.     mvi    a,'/'
  1031.     call    coe
  1032.     lda    kyrs
  1033.     call    phacc
  1034.     mvi    a,' '
  1035.     call    coe
  1036.     call    coe
  1037. ; Now time in format hh:mm:ss
  1038.     lda    khrs            ; Seconds
  1039.     call    phacc
  1040.     mvi    a,':'
  1041.     call    coe
  1042.     lda    kmin
  1043.     call    phacc
  1044.     mvi    a,':'
  1045.     call    coe
  1046.     lda    ksec
  1047.     call    phacc
  1048.     jmp    crlf
  1049. ;
  1050. ;
  1051. chkabrt:    ; Detect if the user wanted to quit or not
  1052.     call    cst            ; See if abort pressed
  1053.     rz                ; Return if no character pending
  1054.     call    cie            ; Get the character, conin handles esc
  1055.     cpi    esc
  1056.     jz    warm
  1057.     cpi    '.'
  1058.     jz    warm
  1059.     ret
  1060. ;
  1061. ;****************************************************************
  1062. ;*        See if de less than hl                *
  1063. ;****************************************************************
  1064. ;
  1065. rngchk:
  1066.     ora    a            ; Clear flags
  1067.     dsbc    d
  1068.     jc    erdisp
  1069.     inx    h
  1070.     ret
  1071. ;
  1072. pracc:    
  1073.     call    phacc
  1074.     jmp    space
  1075. ;
  1076. ;
  1077. makhex:
  1078.     sui    '0'            ; Remove ascii bias
  1079.     cpi    10            ; If 0 - 9, return
  1080.     rm
  1081.     sui    7            ; Else make a - f = 10 - 15
  1082.     ret
  1083. ;
  1084. valnum:
  1085.     cpi    '0'
  1086.     jrc    valbad            ; Check = '0' - '9'
  1087.     cpi    '9'+1
  1088.     jrc    valnok
  1089.     cpi    'A'-1            ; Check = 'A' - 'F'
  1090.     jrc    valbad
  1091.     cpi    'G'
  1092.     jrnc    valbad
  1093. valnok:
  1094.     xra    a            ; Set zero flag for good exit
  1095.     ret
  1096. ;
  1097. valbad:
  1098.     xra    a            ; Set acc = 1
  1099.     inr    a
  1100.     ret
  1101. ;
  1102. ;****************************************************************
  1103. ;*        Checks for end of numeric entry            *
  1104. ;****************************************************************
  1105. ;
  1106. valdm:    cpi    ' '            ; valid delim
  1107.     rz    
  1108.     cpi    '^'            ; Alternate code for cr (*)
  1109.     jrz    valdm1
  1110.     cpi    '&'            ; This is allowed for cont' commands
  1111.     jrz    valdm1
  1112.     cpi    cr            ; End of command
  1113.     rnz                ; Exit if not a one of these
  1114. ;
  1115. valdm1:
  1116.     call    crlf            ; Issue a carriage return
  1117.     xra    a            ; Set zero flag = valid delim
  1118.     ret
  1119. ;
  1120. ghex:
  1121.     lxi    h,00
  1122.     mov    b,l
  1123. ghex1:
  1124.     call    echo
  1125.     inr    b
  1126.     call    valdm
  1127.     rz
  1128.     call    valnum
  1129.     rnz
  1130.     mov    a,c
  1131.     call    makhex
  1132.     dad    h
  1133.     dad    h
  1134.     dad    h
  1135.     dad    h
  1136.     add    l            ; add in lower digit
  1137.     mov    l,a            ; put back in
  1138.     jr    ghex1
  1139. ;
  1140. echo:    call    cie
  1141.     ani    07fh
  1142.     cpi    'a'            ; Ensure in upper case
  1143.     jrc    noconv
  1144.     cpi    'z'+1
  1145.     jrnc    noconv
  1146.     ani    05fh
  1147. noconv:
  1148.     mov    c,a            ; save
  1149.     cpi    esc
  1150.     jnz    coe
  1151.     ret
  1152. ;
  1153. ;****************************************************************
  1154. ;*    Collect up to 9 bytes of numeric data            *
  1155. ;*    separated by spaces if entered                *
  1156. ;****************************************************************
  1157. ;
  1158. gaddr:
  1159.     xra    a
  1160.     lxi    h,opr1
  1161.     push    h
  1162.     popix
  1163.     mov    m,a
  1164.     lxi    b,13
  1165.     lxi    d,opr1+1
  1166.     ldir                ; Clear 13 bytes of ram
  1167.     sta    opcnt
  1168. ;
  1169. ;
  1170. gaddr1:
  1171.     call    ghex
  1172.     jnz    erdisp
  1173.     mov    a,c
  1174.     sta    lastchr
  1175.     cpi    ' '
  1176.     jrz    gaddr2
  1177.     dcr    b
  1178.     rz
  1179. ;
  1180. ;
  1181. gaddr2:
  1182.     stx    l,000h
  1183.     stx    h,001h
  1184.     lda    opcnt
  1185.     inr    a
  1186.     sta    opcnt
  1187.     inxix
  1188.     inxix
  1189.     mov    a,c
  1190.     cpi    ' '
  1191.     jrz    gaddr1
  1192.     ret
  1193. ;
  1194. prhl:
  1195.     mov    a,h
  1196.     call    phacc
  1197.     mov    a,l
  1198.     jmp    pracc
  1199. ;
  1200. prhl2:    ; Print contents of hl and also extra spaces 
  1201.     call    prhl    
  1202.     jr    prsep2            ; Send an additional space
  1203. ;
  1204. prsep:    ; If b = 8 then print a '- ' else return
  1205.     mov    a,b
  1206.     cpi    9            ; Already done 8 characters ??
  1207.     rnz                ; Return if not at exact match
  1208.     mvi    a,'-'
  1209.     call    coe
  1210. prsep2:
  1211.     jmp    space            ; Print a space
  1212. ;
  1213. ;****************************************************************
  1214. ;*        Printer output routine                *
  1215. ;****************************************************************
  1216. ;
  1217. poe:    
  1218.     ret
  1219. ;
  1220. ;
  1221. ; Small I/O Deiver interfaces 
  1222. ;
  1223. phde:
  1224.     push    b
  1225.     mvi    c,19            ; HEX DE  Print code
  1226.     rst    1
  1227.     pop    b
  1228.     ret
  1229. ;
  1230. pdde:
  1231.     push    b
  1232.     mvi    c,20            ; Decimal DE  Print code
  1233.     rst    1
  1234.     pop    b
  1235.     ret
  1236. ;
  1237. phacc:
  1238.     push    b
  1239.     mvi    c,17            ; HEX Psw Print code
  1240.     rst    1
  1241.     pop    b
  1242.     ret
  1243. ;
  1244. ptxt:
  1245.     ldax    d
  1246.     ora    a
  1247.     rz
  1248.     cpi    '$'
  1249.     rz
  1250.     call    coe
  1251.     inx    d
  1252.     jr    ptxt
  1253. ;
  1254. ;
  1255. bell:
  1256.     mvi    a,7
  1257.     jmp    coe
  1258. ;
  1259. space2:
  1260.     call    space
  1261. space:
  1262.     mvi    a,' '
  1263.     jmp    coe
  1264. ;
  1265. crlf:
  1266.     mvi    a,cr
  1267.     call    coe
  1268.     mvi    a,lf
  1269.     jmp    coe
  1270. ;
  1271. caps:
  1272.     push    b
  1273.     mvi    c,55            ; CAPS code
  1274.     rst    1
  1275.     pop    b
  1276.     ret
  1277. ;
  1278. ClrWdt:
  1279.     push    b
  1280.     push    psw
  1281.     mvi    c,40            ; Watchdog clear
  1282.     rst    1
  1283.     pop    psw
  1284.     pop    b
  1285.     ret
  1286. ;
  1287. makasc:
  1288.     ani    07fh            ; Make in the range
  1289.     cpi    020h            ; Lower than a space is illegal
  1290.     jrc    noasc            ; Not ascii
  1291.     cpi    07bh            ; Higher than upper case is illegal too
  1292.     rc                ; return with ascii character in C
  1293. noasc:    mvi    A,02eh            ; Replace with a '.'
  1294.     ret
  1295. ;
  1296. coe:
  1297.     jmp    con$out
  1298. cie:
  1299.     jmp    con$inp
  1300. cst:
  1301.     jmp    con$ist
  1302. ;
  1303. clkrd:
  1304.     push    b
  1305.     mvi    c,get$clk
  1306.     rst    1
  1307.     pop    b
  1308.     ret
  1309. ;
  1310. ;
  1311. ;
  1312. clkwr:            ; Real time clock routines
  1313.     push    b
  1314.     mvi    c,put$clk
  1315.     rst    1
  1316.     pop    b
  1317.     ret
  1318. ;
  1319. ;************************************************
  1320. ;*    Table of routines for indirect jump    *
  1321. ;************************************************
  1322. ;
  1323. jmptbl:
  1324.     dw    adump            ; A Ascii display of memory
  1325.     dw    erdisp             ; B 
  1326.     dw    erdisp            ; C 
  1327.     dw    dump            ; D display memory
  1328.     dw    exmem            ; E examine memory
  1329.     dw    fill            ; F fill memory
  1330.     dw    go            ; G go to program
  1331.     dw    hexad            ; H hex sum and difference
  1332.     dw    portin            ; I input from port
  1333.     dw    erdisp             ; J 
  1334.     dw    clock            ; K read/write clock
  1335.     dw    locat            ; L locate string
  1336.     dw    move            ; M move memory
  1337.     dw    erdisp            ; N
  1338.     dw    portout            ; O output to a port
  1339.     dw    port            ; P examine port
  1340.     dw    quit              ; Q quit this monitor
  1341.     dw    erdisp            ; R 
  1342.     dw    exmem            ; S Substitute memory duplicate
  1343.     dw    mtest            ; T test ram
  1344.     dw    string            ; U Use console for writing to ram
  1345.     dw    verify            ; V verify ram
  1346.     dw    erdisp            ; W 
  1347.     dw    erdisp            ; X 
  1348.     dw    erdisp            ; Y 
  1349.     dw    erdisp            ; Z 
  1350. ;
  1351. signon:
  1352.     db    cr,lf
  1353. signon1:
  1354.     db    'ExecMon - CORE BOARD Monitor With EXEC Processor 25/10/88'
  1355.     db    cr,lf,0
  1356. signon2:
  1357.     db    cr,lf
  1358.     db    'M>'
  1359.     db    0
  1360. ;
  1361.     dseg
  1362. ;
  1363. prescale:
  1364.     ds    1            ; 1mS interrupt prescaler
  1365. ;
  1366. ;
  1367.     ds    128
  1368. stack:
  1369.  
  1370.     ds    10
  1371. stcktop
  1372.     ds    10
  1373. ;
  1374. dump$lst ds    2
  1375. ;
  1376. int$cnt    db    00,00            ; Interrupt counter
  1377. opcnt    db    00
  1378. lastchr    db    00
  1379. opr1    db    00,00
  1380. opr2    db    00,00
  1381. opr3    db    00,00
  1382. opr4    db    00,00
  1383. opr5    db    00,00
  1384. opr6    db    00,00
  1385. opr7    db    00,00
  1386. temp2    db    00,00
  1387. temp6    db    00,00
  1388. temp8    db    00,00
  1389. ?time:
  1390. ksec:    db    00            ; Seconds
  1391. kmin:    db    00            ; Minutes
  1392. khrs:    db    00            ; Hours
  1393. kdow:    db    00            ; Day of week
  1394. kdom:    db    00            ; Day of month
  1395. kmth:    db    00            ; Month number
  1396. kyrs:    db    00            ; Years
  1397. ;
  1398. usr$stk    db    00,00
  1399. ;
  1400.     end
  1401.  
  1402.  
  1403. ;