home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / beehive / program / jmon.arc / JMON.DOC < prev    next >
Encoding:
Text File  |  1990-07-22  |  9.6 KB  |  333 lines

  1.  
  2.  
  3.  
  4. JMON-monitor for banked BIOS
  5. Vers 1.00 88Jan22 by Julian Loke
  6.  
  7.      This is a simple Z80 breakpoint debugger which I use to 
  8. trace  through  my CP/M banked BIOS.   During the  bootstrap 
  9. procedure,  as many as five bank swaps are made.  This means 
  10. that I can't use a standard debugger or even my ROM  monitor 
  11. since there is no fixed stack segment.   This self-modifying 
  12. debugger  code  lives in common memory (in my system  COLOUR 
  13. RAM at 0F800h).
  14.  
  15.      The  ZASM source code is supplied,  and overlays for  a 
  16. MicroBee 56 are included.   These include keyboard scan code 
  17. and  code for a hardware scroll VDU driver using  the  6545.  
  18. As is, the code can be shoehorned into just under 4k.
  19.  
  20.  
  21. Introduction
  22.  
  23.      After  I piggy-backed the second 56k bank of RAM on  my 
  24. Z80  MicroBee computer,  I felt it was rather a waste to use 
  25. it all as a RAM disk.   I had a terrible sinking feeling  in 
  26. the pit of my stomach when I realized I would write a banked 
  27. memory  BIOS.   I didn't feel any better when I had to debug 
  28. the beast.
  29.  
  30.      This  is  one of the more useful tools I  developed  to 
  31. help  me trace through my XBIOS,  which sits in a  different 
  32. bank from the TPA.
  33.  
  34.      The design criteria were simple:
  35.           Z80 breakpoint debugger with multiple breakpoints
  36.           Memory monitor
  37.           Port monitor
  38.           Keyboard and VDU routines independent of ROM
  39.           MUST fit in common memory (2k)
  40.           Transparent to XBIOS (i.e. no shared memory)
  41.  
  42. The Monitor
  43.  
  44.      Those of you familiar with DDT will feel right at home.  
  45. Single  letter  commands are typed on a short command  line.  
  46. Parameters follow, and are separated by commas.  There is NO 
  47. help facility.
  48.  
  49.      Being  only  a  tiny  monitor,   JMON  does  not  allow 
  50. disassembly.   You will need to manually trace through  your 
  51. code,  armed  with a list of Z80 opcodes and mnemonics,  and 
  52. with a printed listing of your .PRN file.
  53.  
  54.      I  found  this  quite adequate  for  my  purposes.   Of 
  55. course,  if  you  insist on being able  to  disassemble  and 
  56. trace,  I'd be very grateful if you could add the code to do 
  57. this.
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. Assembling JMON
  71.  
  72.      This  program  is  NOT an example of  elegant  assembly 
  73. language programming.   As is,  it is intended for use  with 
  74. ZASM  and LOAD via a .HEX file.   It produces a file for use 
  75. with a MicroBee.
  76.  
  77.      The  keyboard and VDU I/O routines (see below) for  the 
  78. MicroBee are rather large.  Consequently, there was not much 
  79. left for a decent monitor unless I used self-modifying code.
  80.  
  81.      A  major stumbling block (which still remains)  is  the 
  82. lack  of a PHASE directive in ZASM.   Being an ASM user from 
  83. way  back,  I used offsets at EVERY ABSOLUTE  address.   So, 
  84. instead of:
  85.  
  86.         ld      sp,stk          ;new stack
  87.         ld      a,(lbl5)        ;absolute address
  88.         jr      nz,lbl1         ;relative address
  89.  
  90. I have to put
  91.  
  92.         ld      sp,stk+poff     ;new stack + offset
  93.         ld      a,(lbl5+poff)   ;absolute address + offset
  94.         jr      nz,lbl1         ;relative address
  95.  
  96. where poff is defined earlier in the program.   Look through 
  97. the source code for more examples.
  98.  
  99.      If your assembler has a PHASE directive,  put that into 
  100. the file, and EQUate poff to zero.
  101.         poff    equ     0       ;offset for patch
  102.  
  103.  
  104. I/O interfacing
  105.  
  106.      To assemble JMON for a non-MicroBee system, you MUST to 
  107. provide TWO include files:
  108.  
  109.        file    entry point  function
  110.      JVDU.Z80     wr$a      write  ASCII char in register  A 
  111.                             to  VDU.   Preserves  all  other 
  112.                             registers.
  113.  
  114.      JKBDST.Z80   kbdst     Keyboard  status/input  routine. 
  115.                             Return ASCII key in register  A, 
  116.                             and  NZ  flag.   If no keys  are 
  117.                             pressed, return A=0, Z status.
  118.  
  119.      Beware!   See the section above on producing PHASE code 
  120. with an assembler without a PHASE directive.   You MUST  get 
  121. this correct, or you will wind up in terrible trouble!
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. Using JMON
  137.  
  138.      There  is  a  small loader supplied with  JMON.Z80  for 
  139. loading  the  program into the correct  address.   I  put  a 
  140. couple of options for my system,  but this may or may not be 
  141. suitable for you.
  142.  
  143.      A>JMON         load and install JMON in the COLOUR RAM
  144.                     at 0F800h.  Return to CP/M, ready for
  145.                     JUMP 0F800 from ZCPR, or following DDT.
  146.      A>JMON X       load, install, then run JMON
  147.      A>JMON X.1     as above, but stores JMON in the PCG RAM
  148.                     instead of the colour RAM.
  149.  
  150.  
  151. Command         Short Description
  152.  
  153. B               display all breakpoints
  154. Bxxxx           toggle breakpoint at xxxx
  155.  
  156. C               clear all breakpoints
  157.  
  158. D               dump 128 bytes from current pointer
  159. Dxxxx           dump 128 bytes from xxxx
  160. Dxxxx,yyyy      dump from xxxx to yyyy
  161. D,yyyy          dump from last addr to yyyy
  162.  
  163. Fxxxx,yyyy      fill from xxxx to yyyy with 00
  164. Fxxxx,yyyy,nn   fill from xxxx to yyyy with nn
  165.  
  166. G               go to PC
  167. Gxxxx           go to xxxx
  168. Gxxxx,yyyy      go to PC, temporary breakpoint at yyyy
  169.  
  170. Hxxxx,yyyy      display sum and difference (hexadecimal)
  171.  
  172. Inn             input from port nn
  173. Inn,oo          input from port nn, put oo on A8..A15
  174.  
  175. Mxxxx,yyyy,zzzz move memory from xxxx..yyyy to zzzz
  176.  
  177. Onn,oo          output value oo to port nn
  178.  
  179. Q               quit to ROM monitor
  180. Qxxxx           quit to address xxxx
  181.  
  182. R               display registers
  183. Rrxxxx          set register r to xxxxx, r in [ABDHXYSPZ]
  184. RFfff           set flag(s) in flag register, f in [SZHPNC]
  185.  
  186. S               substitute memory contents from last address
  187. Sxxxx           substitute memory contents at xxxx
  188.  
  189. Z               display current PAGE register
  190. Zxxxx           set PAGE register to xxxx
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. Notes on commands
  203.  field description     example notes
  204.  
  205.   nn   hex number      I0      input from port 00h
  206.  
  207.   xxxx hex number      G,0DF3  go with temp brkpt at 0DF3h
  208.        or PC spec      D.      dump from PC onwards
  209.        or PC relative  B.r     brkpt assuming PC at JR
  210.        or PC absolute  B.a     brkpt e.g. with PC at CALL
  211.  
  212.   rr   register name   RA38    set A to 38h
  213.                        RH1234  set HL to 1234h
  214.  
  215.   ffff flag name       RFZPS   set FLAGS Z P and S
  216.  
  217.  
  218.      The  S  command  allows you to  put  several  bytes  in 
  219. sequence  (separated  by commas) on the same line.   If  you 
  220. start  with a comma,  the rest of the line is stored  as  an 
  221. ASCII string verbatim.
  222.  
  223.  
  224.  
  225. How I use JMON
  226.  
  227.      Let's  say  I am debugging the SELECT DISK XBIOS  CODE. 
  228. This lives in a bank separate from the TPA,  which can  only 
  229. be accessed when the stack has been set to common memory.
  230.  
  231.      I  have  a printed listing of the region of code  under 
  232. test, and select a suitable location for a breakpoint.
  233.  
  234.      Using JMON, I can change banks using the Z command, and 
  235. examine  memory with the D dump command.   I usually  change 
  236. some memory with the S command, then issue a GO command with 
  237. temporary breakpoint.   The registers are displayed, and may 
  238. be redisplayed and modified with the R command.
  239.  
  240.      In this way I can successfully trace through my  XBIOS.  
  241. Many  a  bug,  hidden stealthily in obscure source code  has 
  242. been revealed to me by this method.
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. Sample JMON run                 with comments
  269.  
  270.      A>JMON X                   invoke jmon
  271.      JMON v1.00 by J.Loke 88Jan22
  272.      $z1                        select XBIOS bank
  273.      $dc84e                     dump memory in bank 1,C84E
  274.      01:C84E  7A 2E...
  275.      01:C85E  5F 73...
  276.      ...
  277.      $bc84e                     set a permanent breakpoint
  278.      $b                         display all breakpoints
  279.      $z2                        select TPA bank
  280.      $g0                        start, breakpoints active
  281.      A>dir b:                   invoke test function
  282.      ...                        XBIOS breakpoint reached
  283.                                 registers are displayed
  284.      c                          clear all breakpoints
  285.      $d.                        dump at PC
  286.      $g,c854                    go with temporary brkpnt
  287.      ...                        breakpoint reached
  288.                                 registers are displayed
  289.      $rfz                       set ZERO flag
  290.      $ra0                       set accumulator zero
  291.      $h.,5                      display PC+5,PC-5
  292.      $g,.r                      trace past relative jump
  293.      $d.                        dump instruction LD HL,LBL
  294.      $d.a                       dump LBL
  295.                                 EUREKA I found the error!
  296.      $z2                        select TPA bank
  297.      $q0                        quit with a warm boot
  298.  
  299.  
  300.  
  301.  
  302. Any more?
  303.  
  304.      JMON  is not a fully featured monitor.   It is not even 
  305. the  debugger I use within CP/M.   I only use  JMON  because 
  306. there is nothing else that could handle the banked memory in 
  307. my computer.
  308.  
  309.      Think of it as a kludge, and you won't be disappointed.  
  310. You  might even be pleasantly surprised how useful JMON  can 
  311. be.
  312.  
  313.      For more extensive documentation, or to return comments 
  314. or  criticisms,  please  get in contact with me on 
  315. EASTWOOD R/ZSYS (03) 870 4623,
  316. or after your International access code, 61-3-870-4623. V22 or Bell 212
  317.  
  318. Copyright
  319.  
  320.      Released to the public domain to be freely  distributed.  
  321. May not be sold or included in a package which is sold.
  322.  
  323. Julian Loke
  324. Melbourne,  Australia.
  325. 1988 Jan 22
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332. d.  
  333. May not be sold or included in a package which is sold.