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 / BEEHIVE / UTILITYS / PEEK22.ARC / PEEKBDOS.MAC < prev    next >
Text File  |  1992-05-28  |  10KB  |  393 lines

  1.     title    'PEEKBDOS v2.0 RSX for CP/M 2.x'
  2. ;
  3. ; Taken directly from PEEKBDOS v1.0 (C) by Ron Fowler.  Modifications for
  4. ; CP/M 2.x by Mark A. Howard.
  5. ;
  6. ; This program is an  RSX running under CP/M 2.x in conjunction with the
  7. ; RSX manager (SETRSX)  written by Jim Lopushinsky. It's purpose  is
  8. ; to trace  file-related BDOS calls,  and display information regarding each
  9. ; call on a selected device.  It must  be combined with  the companion module,
  10. ; "PEEK22.MAC" in the manner described in the comment section of that file.
  11. ;
  12. ; PEEK22's output device  defaults to  the system console,  and can be changed
  13. ; by doing  "peek a"  (aux), "peek l" (list), or  "peek c"  (console).  Note
  14. ; that  "peek p"  sets the pause flag, causing  the trace to pause after the
  15. ; call to bdos.   Note also that a "*" is printed at the pause;  the program
  16. ; then  waits for input.   Any character other than "Q" will simply cause  a
  17. ; return  to the caller.  A "Q" resets the pause flag, and the  program then
  18. ; displays without pausing.
  19. ;
  20. ; "PEEK22 Q" removes the RSX from memory.
  21. ;
  22. ; Note that  this RSX uses one level of caller's stack.  Also, if you modify
  23. ; this code, be VERY careful with the registers;  I save only what is absol-
  24. ; utely necessary, in order to conserve memory.
  25. ;
  26. ;            Ron Fowler
  27. ;            Fort Atkinson, WI
  28. ;            08/22/83
  29. ;
  30. ; UPDATE INFORMATION:
  31. ;
  32. ; -- if you update this program, please pass along a copy to Fort Fone File
  33. ;    Folder (FFFF) RCP/M, Fort Atkinson, WI: (414) 563-9932 (no ringback).
  34. ;    Please update the version number in both modules (PEEK22.MAC also).
  35. ;
  36. ; updates (in reverse order to minimize reading time):
  37. ;
  38. ; 1.0    originally written by Ron Fowler       08/22/83
  39. ; 2.0    modified for CP/M 2.x            09/12/84
  40. ;
  41. ;    Removed duplicate RSX check, as CP/M 2.2 does not return the
  42. ;    desired code in AC.  Moved check to TPA module, as that is
  43. ;    where RSX is loaded anyway.  -  Mark Howard - SYSOP
  44. ;                    CNY Technical RCP/M
  45. ;                    (315) 437-4890 300/1200
  46. ;
  47. ;------------------------------------------------------------
  48. ;
  49. ; CP/M equates
  50. ;
  51. conotf    equ    2        ;output character to console
  52. auxotf    equ    4        ;aux output
  53. lstotf    equ    5        ;list output
  54. diriof    equ    6        ;direct console i/o
  55. printf    equ    9        ;print string function
  56. openf    equ    15        ;open file
  57. closf    equ    16        ;close file
  58. srchf    equ    17        ;search for file 1st occurance
  59. srchn    equ    18        ;search for file next occurance
  60. erasf    equ    19        ;erase file
  61. readf    equ    20        ;read sequential
  62. writf    equ    21        ;write sequential
  63. creat    equ    22        ;create file
  64. renmf    equ    23        ;rename file
  65. sdmaf    equ    26        ;set transfer address
  66. rdran    equ    33        ;read random
  67. wrran    equ    34        ;write random
  68. ;
  69. ; character equates
  70. ;
  71. cr    equ    13        ;carriage-return code
  72. lf    equ    10        ;linefeed code
  73. ;
  74. ;
  75. ;
  76. ; RSX prefix
  77. ;
  78.     db    0,0,0,0,0,0    ;space for CPM3 to insert serial #
  79.     jmp    begin        ;jump to entry point
  80. next:    db    jmp        ;jump instruction op-code
  81.     dw    0        ;next RSX or loader
  82.     dw    0        ;previous RSX or 0
  83. rmvflg:    db    0        ;removes RSX when non-0
  84.     db    0        ;flag for non-banked only
  85. myname:    db    'PEEKBDOS'    ;our name
  86.     db    0        ;loader flag
  87.     db    0,0        ;reserved
  88. ;
  89. ; This is the BDOS call intercept.  Here we determine if the
  90. ; call is one of those we process.  If not, we simply pass
  91. ; control on to the next module.
  92. ;
  93. begin:    mov    a,c        ;get function code
  94.     cpi    60        ;for RSX's only?
  95.     jz    rsxfnc        ;go if so
  96.     lxi    h,fnctbl    ;nope, test for one of ours
  97. scan:    mov    a,m        ;get first/next table opcode
  98.     inx    h
  99.     ora    a        ;end-of-table?
  100.     jz    next        ;then quit now
  101.     cmp    c        ;ours?
  102.     jz    trap        ;go trap if so
  103.     mvi    a,6        ;nope, calculate next table entry
  104.     call    addha
  105.     jmp    scan        ;continue
  106. ;
  107. ; Here when we've determined that we must display the system call.
  108. ; First save caller's stackpointer and load a local stack.
  109. ;
  110. trap:    shld    tblptr        ;save pointer to function string
  111.     lxi    h,0        ;get user's sp
  112.     dad    sp
  113.     shld    spsave
  114.     lxi    sp,stack    ;load local stack
  115. ;
  116. ; begin the trace: do newline, then print the function string
  117. ;
  118.     mvi    a,cr        ;carriage
  119.     call    type
  120.     mvi    a,lf
  121.     call    type
  122.     lhld    tblptr        ;get string pointer
  123.     call    prathl        ;print it
  124.     call    ilprnt        ;colon, open paren
  125.     db    ': '
  126.     db    '('+80h
  127. ;
  128. ; print fcb address (or dma address)
  129. ;
  130.     mov    a,d        ;get parameter hi
  131.     call    hexout
  132.     mov    a,e        ;then lo
  133.     call    hexout
  134.     call    ilprnt        ;closing paren
  135.     db    ')',' '+80h
  136.     mov    a,c        ;get function code
  137.     cpi    sdmaf        ;set-dma?
  138.     jz    exit        ;then done
  139. ;
  140. ; Not setdma function.  Print out the FCB information
  141. ;
  142.     push    d        ;save fcb pointer
  143.     ldax    d        ;get drive code
  144.     inx    d
  145.     call    hexsp        ;print hex byte, space
  146. ;
  147. ; Print the file name
  148. ;
  149.     mvi    b,11        ;eleven characters
  150. fnprnt:    ldax    d        ;get first/next char
  151.     inx    d        ;advance fcb pointer
  152.     call    type        ;print it
  153.     dcr    b        ;all 11
  154.     jnz    fnprnt
  155.     mvi    a,' '        ;separate filename
  156.     call    type
  157. ;
  158. ; print ex,s1,s2,rc
  159. ;
  160.     mvi    b,4        ;four of these
  161.     lxi    h,idbase    ;ascii id's for each field
  162. idloop:    call    prathl        ;print id
  163.     ldax    d        ;get field
  164.     inx    d        ;advance fcb pointer
  165.     call    hexsp        ;print in hex, space
  166.     dcr    b        ;all 4
  167.     jnz    idloop
  168. ;
  169. ; print the nr field
  170. ;
  171.     call    prathl        ;last id string
  172.     lxi    h,16        ;offset to nr field
  173.     dad    d
  174.     mov    a,m        ;fetch it
  175.     call    hexout        ;print it
  176.     pop    d        ;restore fcb pointer
  177. ;
  178. ; here after fcb info printed.  Allow the call to pass upward,
  179. ; then print the returned value.
  180. ;
  181. exit:    call    next        ;give call to bdos
  182.     shld    hlsave        ;save returned registers
  183.     push    d
  184.     push    b
  185.     push    psw        ;save returned value
  186.     lxi    h,rtnmsg    ;print "Ret: "
  187.     call    prathl
  188.     pop    psw        ;restore, resave returned a
  189.     push    psw
  190.     call    hexout        ;print it in hex
  191.     lda    pause        ;do a pause?
  192.     ora    a
  193.     jz    nopaus        ;jump if not
  194.     call    ilprnt        ;yep, print prompt
  195.     db    ' ','*'+80h
  196.     mvi    c,diriof    ;get a character
  197.     mvi    e,0FDH        ;don't come back 'till we have one
  198.     call    next
  199.     ani    5fh        ;convert char to upper case
  200.     cpi    'Q'        ;quit-pause?
  201.     jnz    nopaus        ;no
  202.     xra    a        ;yes
  203.     sta    pause
  204. nopaus:    pop    psw        ;restore 'em all
  205.     pop    b
  206.     pop    d
  207.     lhld    spsave        ;restore stackpointer
  208.     sphl
  209.     lhld    hlsave
  210.     ret            ;back to caller
  211. ;
  212. ; Handler for function 60: call RSX. Here we insure that the
  213. ; call is for us.  The RSX parameter block passed in DE must
  214. ; contain two parameters, the first of which is a pointer to
  215. ; our name (near absolute insurance that there won't be any
  216. ; confusion).  The second parameter is a pointer to a request
  217. ; code (one of: "Q", quit, "C", console, "L", list, "A", aux).
  218. ;
  219. rsxfnc:    push    d        ;save user de
  220.     xchg            ;rsx pb pointer to hl
  221.     inx    h        ;ignore function code
  222.     mov    a,m        ;get # parameters
  223.     cpi    2        ;two?
  224.     jnz    pass        ;quit if not
  225.     inx    h        ;skip # of parameters
  226.     mov    e,m        ;fetch parameter #1
  227.     inx    h
  228.     mov    d,m
  229.     inx    h        ;hl points to 2nd parm
  230.     shld    spsave        ;save that pointer
  231.     lxi    h,myname    ;check for our name
  232.     mvi    b,8        ;8 characters
  233. ckname:    ldax    d        ;compare first/next character
  234.     inx    d
  235.     cmp    m        ;compare with our name
  236.     inx    h
  237.     jnz    pass        ;if fails, pass to next rsx
  238.     dcr    b        ;all 8
  239.     jnz    ckname
  240. ;
  241. ; rsx request is for us, get rsx pointer, load 2nd parameter
  242. ;
  243.     pop    d        ;recall passed parameter
  244.     lhld    spsave        ;get rsx pointer
  245.     mov    a,m        ;fetch next parameter
  246.     inx    h
  247.     mov    h,m        ;into hl
  248.     mov    l,a        ;hl points to request
  249.     inx    h        ;point to pause flag
  250.     mov    a,m        ;fetch it
  251.     cpi    0ffh        ;null? (don't alter pauseflag)
  252.     jz    pntreq        ;jump if so
  253.     sta    pause        ;no, stuff it
  254. pntreq:    dcx    h        ;point to request
  255.     mov    a,m        ;fetch request
  256. ;
  257. ; a now has the function request character passed from the tpa
  258. ;
  259.     cpi    'Q'        ;quit?
  260.     jz    quit
  261.     cpi    'A'        ;output to aux?
  262.     mvi    c,auxotf    ;prep function code
  263.     jz    setout
  264.     cpi    'C'        ;output to console?
  265.     mvi    c,conotf    ;prep code
  266.     jz    setout
  267.     mvi    c,lstotf    ;process of elimination (list)
  268. setout:    mov    a,c        ;get new output device code
  269.     sta    curdev        ;stuff it
  270.     xra    a        ;return a=0
  271.     ret
  272. ;
  273. ; here when call 60 is not for us
  274. ;
  275. pass:    pop    d        ;clear stack
  276.     jmp    next        ;to next rsx
  277. ;
  278. ; here to quit
  279. ;
  280. quit:    mvi    a,0ffh        ;flag loader to remove us
  281.     sta    rmvflg
  282.     xra    a        ;we still return 0
  283.     ret
  284. ;
  285. ;    ***************
  286. ;    * subroutines *
  287. ;    ***************
  288. ;
  289. ; print in-line message terminated by char w/bit7=1
  290. ;
  291. ilprnt:    xthl            ;msg pointer to hl
  292.     call    prathl        ;print it
  293.     xthl
  294.     ret
  295. ;
  296. ; print string pointed to by hl, until char w/bit7=1
  297. ;
  298. prathl:    mov    a,m        ;fetch first/next char
  299.     inx    h        ;advance pointer
  300.     call    type        ;print it
  301.     ani    80h        ;terminator?
  302.     jz    prathl        ;continue if not
  303.     ret
  304. ;
  305. ; output a in hex, followed by space
  306. ;
  307. hexsp:    call    hexout        ;print it
  308.     mvi    a,' '
  309.     jmp    type
  310. ;
  311. ; output a as 2 hex digits
  312. ;
  313. hexout:    push    psw        ;save it
  314.     rrc            ;hi nybble into lo
  315.     rrc
  316.     rrc
  317.     rrc
  318.     call    nybble        ;print it
  319.     pop    psw        ;now restore, fall into lo
  320. nybble:    ani    0fh        ;zap any garbage in hi nybble
  321.     adi    90h        ;this little beauty...
  322.     daa            ;...is from the old (and maybe
  323.     aci    40h        ;...still existing) Intel library
  324.     daa            ;fall into type
  325. ;
  326. ; type char in a on console via current output device.
  327. ;
  328. type:    push    psw        ;save all
  329.     push    h
  330.     push    d
  331.     push    b
  332.     ani    7fh        ;allow no parity bits to pass
  333.     mov    e,a        ;align character
  334.     lda    curdev        ;get device function code
  335.     mov    c,a
  336.     call    next        ;output the character
  337.     pop    b        ;clean up
  338.     pop    d
  339.     pop    h
  340.     pop    psw
  341.     ret
  342. ;
  343. ; add a to hl
  344. ;
  345. addha:    add    l
  346.     mov    l,a
  347.     rnc
  348.     inr    h
  349.     ret
  350. ;
  351. ; Table of locally-processed system function calls. Format  is function
  352. ; code  followed by id string. Note that more functions may be added to
  353. ; this table, but if they are not fcb-related functions, you'll have to
  354. ; modify the TRAP routine to process the new data types.
  355. ;
  356. fnctbl:    db    openf,'opnfi','l'+80H
  357.     db    closf,'clsfi','l'+80H
  358.     db    readf,'rd se','q'+80H
  359.     db    writf,'wr se','q'+80H
  360.     db    sdmaf,'setdm','a'+80H
  361.     db    srchf,'srch ','1'+80H
  362.     db    srchn,'srch ','n'+80H
  363.     db    renmf,'renam','e'+80H
  364.     db    erasf,'erase',' '+80H
  365.     db    rdran,'rd ra','n'+80H
  366.     db    wrran,'wr ra','n'+80H
  367.     db    creat,'creat','e'+80H
  368. ;
  369.     db    0
  370. ;
  371. ; table of fcb id strings
  372. ;
  373. idbase:    db    'ex','='+80h
  374.     db    's1','='+80h
  375.     db    's2','='+80h
  376.     db    'rc','='+80h
  377.     db    'nr','='+80h
  378. ;
  379. rtnmsg:    db    ' Ret:',' '+80h
  380. ;
  381. ; data area
  382. ;
  383. curdev:    db    auxotf        ;system-call # for output
  384. pause:    db    0        ;non-0 = pause after bdos calls
  385. tblptr:    dw    0        ;saved pointer into fnctbl
  386. hlsave:    dw    0        ;save for hl
  387. spsave:    dw    0        ;stackpointer save
  388.     ds    24        ;12-level stack
  389. stack:
  390. ;
  391. ;    
  392.     end
  393.