home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / ZCPR33 / Z3-33 / Z33RCP02.LBR / RCPIOM.LZB / RCPIOM.LIB
Text File  |  2000-06-30  |  6KB  |  297 lines

  1.     page
  2.  
  3. ; RCP-IOM.Z80
  4.  
  5. ; Command:    PEEK
  6. ; Function:    Display memory contents
  7. ;
  8. ; Form:
  9. ;        PEEK startadr        256 bytes displayed
  10. ;        PEEK startadr endadr    range of bytes displayed
  11.  
  12.      if    peekon
  13.  
  14. peek:
  15.     call    retsave
  16.  
  17.     ld    hl,tbuff+1    ; Find first number
  18. nxtpeek    equ    $+1        ; Pointer for in-the-code modification
  19.     ld    de,100h        ; Default peek address if none
  20.     call    sksp        ; Skip to first token (if any)
  21.     call    nz,hexnum    ; Get start address if any
  22.  
  23.     push    de        ; Save starting address
  24.     ld    bc,255        ; Compute default ending address
  25.     ex    de,hl
  26.     add    hl,bc
  27.  
  28.      if    peekchk        ; Check for overflow
  29.     jr    nc,peek0    ; If no overflow past FFFF, go on
  30.     ld    hl,0ffffh    ; Else use FFFF as ending address
  31. peek0:
  32.      endif    ;peekchk
  33.  
  34.     ex    de,hl        ; End address in DE
  35.     call    sksp        ; Skip to next token (if any)
  36.     call    nz,hexnum    ; Get 2nd number in DE (else default)
  37.  
  38. peek1:
  39.     pop    hl        ; HL is start address, DE is end address
  40.  
  41.      if    peekhdr
  42.  
  43.     push    hl        ; Save starting address again
  44.     ld    b,8        ; Output leading spaces
  45. peek0a:
  46.     call    print
  47.     db    ' '+80h
  48.     djnz    peek0a
  49.  
  50.     ld    b,16        ; Display 16 column headers
  51. peek0b:
  52.     ld    a,l        ; Get low byte of address
  53.     and    0fh        ; Display low hex digit
  54.     call    pashc
  55.     inc    hl
  56.     djnz    peek0b
  57.  
  58.      if    peekbdr
  59.     call    crlf
  60.     ld    b,8
  61. peek0c:
  62.     call    print
  63.     db    ' '+80h
  64.     djnz    peek0c
  65.     ld    b,16
  66. peek0d:
  67.     call    print
  68.     db    ' -', '-'+80h
  69.     djnz    peek0d
  70.      endif    ;peekbdr
  71.  
  72.     pop    hl        ; Restore starting address
  73.  
  74.      endif    ;peekhdr
  75.  
  76.     ld    c,0ffh        ; Use C as continue flag
  77.     call    peek2        ; Do peek
  78.     ld    (nxtpeek),hl    ; Set continued peek address
  79.     jp    exit
  80.  
  81. peek2:
  82.     ld    a,c        ; Check continuation flag <jps>
  83.     or    a        ; <jps>
  84.     ret    z        ; <jps>
  85.  
  86. ; Print line header
  87.  
  88. peek2a:
  89.     call    crlf        ; New line
  90.     ld    a,h        ; Print address
  91.     call    pashc
  92.     ld    a,l
  93.     call    pahc
  94.     call    dash        ; Print leader
  95.     ld    b,16        ; 16 bytes to display
  96.     push    hl        ; Save start address
  97.  
  98.                 ; Print hex values for 16 bytes
  99.  
  100. peek3:
  101.     ld    a,(hl)        ; Get next byte
  102.     call    pashc        ; Print with leading space
  103.  
  104.                 ; Check for last address <jps>
  105.                 ; If c is already 0, leave it that way.
  106.                 ; Otherwise check for end address and if so
  107.                 ; Set c to zero.
  108.  
  109.     ld    a,c        ; See if continue flag already cleared
  110.     or    a
  111.     jr    z,peek3a    ; If so, skip test
  112.     ld    a,h
  113.     sub    a,d        ; See if h = d
  114.     ld    c,a
  115.     ld    a,l
  116.     sub    a,e        ; See if l = e
  117.     or    c        ; Combine two tests
  118.     ld    c,a
  119.  
  120. peek3a:    inc    hl        ; Pt to next
  121.     djnz    peek3
  122.  
  123.                 ; Print ascii equivalents for 16 bytes
  124.  
  125.     pop    hl        ; Pt to first address again
  126.     ld    b,16        ; 16 bytes
  127.     call    print        ; Space and fence
  128.     db    ' '
  129.     db    fence+80h
  130.     push    bc        ; Save flag in c
  131. peek4:
  132.     ld    a,(hl)        ; Get next byte
  133.     ld    c,'.'        ; Assume dot
  134.     and    7fh        ; Mask it
  135.     cp    ' '        ; Dot if less than space
  136.     jr    c,peek5
  137.     cp    7fh        ; Don't print del
  138.     jr    z,peek5
  139.     ld    c,a        ; Char in c
  140. peek5:
  141.     ld    a,c        ; Get char
  142.     call    conout        ; Send it
  143.     inc    hl        ; Pt to next
  144.     djnz    peek4
  145.  
  146.     call    print        ; Closing fence
  147.     db    fence+80h
  148.     pop    bc        ; Get flag in c back
  149.     call    break        ; Allow abort
  150.     jr    peek2
  151.  
  152.      endif            ; Peekon
  153.  
  154. ; PRINT A AS 2 HEX CHARS
  155. ;   PASHC - LEADING SPACE
  156.  
  157.      if    peekon or [pokeon and not pokeq] or porton
  158. pashc:
  159.     push    af        ; Save a
  160.     call    print
  161.     db    ' '+80h
  162.     pop    af
  163. pahc:
  164.     push    bc        ; Save bc
  165.     ld    c,a        ; Byte in c
  166.     rrca            ; Exchange nybbles
  167.     rrca
  168.     rrca
  169.     rrca
  170.     call    pah        ; Print hex char
  171.     ld    a,c        ; Get low
  172.     pop    bc        ; Restore bc and fall thru to pah
  173. pah:
  174.     and    0fh        ; Mask
  175.     add    '0'        ; Convert to ascii
  176.     cp    '9'+1        ; Letter?
  177.     jr    c,pah1
  178.     add    7        ; Adjust to letter
  179. pah1:
  180.     jp    conout
  181. ;
  182.      endif            ; Peekon or [pokeon and not pokeq] or porton
  183. ;
  184. ;Section 5I
  185. ;Command: POKE
  186. ;Function:  Place Values into Memory
  187. ;
  188. ;Form:
  189. ;    POKE startadr val1 val2 ...
  190. ;
  191.      if    pokeon
  192. poke:
  193.     call    retsave
  194.     ld    hl,tbuff+1    ; Pt to first char
  195.     call    sksp        ; Skip to non-blank
  196.     jr    z,noargs    ; Arg error
  197.     call    hexnum        ; Convert to number
  198.  
  199.      if    not pokeq
  200.     call    print
  201.     db    ' Pok','e'+80h
  202.     call    adrat        ; Print at message
  203.      endif
  204.  
  205. ; LOOP FOR STORING HEX VALUES SEQUENTIALLY VIA POKE
  206.  
  207. poke1:
  208.     push    de        ; Save address
  209.     call    sksp        ; Skip to non-blank
  210.     jp    z,exit        ; Done
  211.     cp    '"'        ; Quoted text?
  212.     jr    z,poke2
  213.     call    hexnum        ; Get number
  214.     ld    a,e        ; Get low
  215.     pop    de        ; Get address
  216.     ld    (de),a        ; Store number
  217.     inc    de        ; Pt to next
  218.     jr    poke1
  219. ;
  220. ; STORE ASCII CHARS
  221. ;
  222. poke2:
  223.     pop    de        ; Get next address
  224.     inc    hl        ; Pt to next char
  225. poke3:
  226.     ld    a,(hl)        ; Get next char
  227.     or    a        ; Done?
  228.     jp    z,exit
  229.     ld    (de),a        ; Put char
  230.     inc    hl        ; Pt to next
  231.     inc    de
  232.     jr    poke3
  233.  
  234.      endif            ; Pokeon
  235. ;
  236. ; No Argument Error
  237. ;
  238.  
  239.      if    pokeon or porton
  240.  
  241. noargs:
  242.     call    print
  243.     db    ' Arg','?'+80h
  244.     jp    exit
  245. ;
  246.      endif            ; Pokeon or porton
  247.  
  248. ;
  249. ;Section 5I+
  250. ;Command: PORT
  251. ;Function:  Display or Set I/O Port Data
  252. ;
  253. ;Form:
  254. ;    PORT addr        - read port and display value
  255. ;    PORT addr value     - output value to port
  256. ;
  257.      if    porton
  258. port:
  259.     call    retsave
  260.     ld    hl,tbuff+1    ; Find first number
  261.     call    sksp        ; Skip to first command-line token
  262.     jr    z,noargs    ; Abort if no port address given
  263.     call    hexnum        ; Get port address into DE
  264.     ld    b,d        ; Copy it into BC
  265.     ld    c,e        ; ..for I/O operation later
  266.     call    print        ; Print header
  267.     db    ' Por','t'+80h
  268.     ld    a,b        ; Print high byte of port address
  269.     call    pashc
  270.     ld    a,c        ; Print low byte of port address
  271.     call    pahc
  272.     call    sksp        ; Skip to possible second value
  273.     jr    z,portin    ; Proceed with port input
  274.  
  275. portout:
  276.     call    print        ; Print header
  277.     db    ': OU','T'+80h
  278.     push    bc        ; Preserve port number
  279.     call    hexnum        ; Get 2nd number in DE
  280.     pop    bc
  281.     ld    a,e
  282.     out    (c),a
  283.     jr    pexit
  284.  
  285. portin:
  286.     call    print
  287.     db    ': I','N'+80h
  288.     in    a,(c)
  289. pexit:
  290.     call    pashc
  291.     jp    exit
  292.  
  293.      endif            ; Porton
  294.  
  295. ; End RCP-IOM.Z80
  296.  
  297.