home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / EXTRA-ST / CPM-80-E / CPM-0.2 / CPM-0 / cpm-0.2 / running.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  2.9 KB  |  103 lines

  1. /*****************************************************************************/
  2. /*                                         */
  3. /*                                         */
  4. /*    CP/M emulator version 0.1                         */
  5. /*                                         */
  6. /*    written by Michael Bischoff (mbi@mo.math.nat.tu-bs.de)             */
  7. /*    June-1994                                 */
  8. /*                                         */
  9. /*    This file is distributed under the GNU COPYRIGHT             */
  10. /*    see COPYRIGHT.GNU for Copyright details                     */
  11. /*                                         */
  12. /*                                         */
  13. /*****************************************************************************/
  14. #include "cpmemu.h"
  15.  
  16. /* run z80 a single instruction */
  17.  
  18. void z80step(int extracond) {    
  19.     if (bdos_emulate && z80regs.pc == BDOS)
  20.     check_BDOS_hook();
  21.     else if (extracond && z80regs.pc >= BIOS) {
  22.     if (!check_BIOS_hook())        /* perform any I/O? */
  23.         return;                /* invalid here! */
  24.     }
  25.     singlestep();    /* if bios: perform return. else: do a step */
  26. }
  27.  
  28. struct breakpoint breakpoint[NBREAKS+1];
  29. int break_at_BIOS = 0;
  30.  
  31. /* run z80 with breakpoints on */
  32. /* a breakpoint or listpoint sets either docontinue of mustbreak */
  33. /* another breaking reason is a BIOS trap. BIOS traps break only */
  34. /* if there is a breakpoint at the same location */
  35.  
  36. void z80run(void) {    
  37.     int i, docontinue, mustbreak;
  38.     struct breakpoint *bp;
  39.  
  40.     /* special case to allow continuous pressing of 'b' */
  41.     z80step(break_at_BIOS);
  42.  
  43.     do {
  44.     if (bdos_emulate && z80regs.pc == BDOS)
  45.         check_BDOS_hook();
  46.     else if (z80regs.pc >= BIOS) {
  47.         if (break_at_BIOS) {    /* run until next BIOS call? */
  48.         break_at_BIOS = 0;
  49.         return;
  50.         }
  51.         if (!check_BIOS_hook())        /* perform any I/O? */
  52.         return;                /* invalid here! */
  53.     }
  54.     docontinue = 0;
  55.     mustbreak = 0;
  56.     singlestep();    /* step over possible breakpoint */
  57.     bp = breakpoint;    /* insert breakpoints */
  58.     for (i = 0; i <= NBREAKS; ++i, ++bp)
  59.         if (bp->action) {
  60.         bp->where &= 0xffff;
  61.         bp->byte = z80mem[bp->where];
  62.         z80mem[bp->where] = 0x76;        /* HALT instruction */
  63.         }
  64.     if (bdos_emulate)
  65.         z80mem[BDOS] = 0x76;
  66.     emulate();        /* RUN! */
  67.     
  68.     bp = breakpoint;    /* remove breakpoints */
  69.     for (i = 0; i <= NBREAKS; ++i, ++bp)
  70.         if (bp->action)
  71.         z80mem[bp->where] = bp->byte;    /* restore */
  72.     
  73.     /* check for multi-breakpoints or different actions */
  74.     bp = breakpoint;    /* remove breakpoints */
  75.     for (i = 0; i <= NBREAKS; ++i, ++bp)
  76.         if (bp->action)
  77.         if (z80regs.pc == bp->where)    /* here we are */
  78.             if (++bp->curcnt == bp->maxcnt) {
  79.             bp->curcnt = 0;
  80.             switch (bp->action) {
  81.             case AC_BREAK:
  82.                 mustbreak = 1;
  83.                 if (i != NBREAKS)
  84.                 printf("\r\nStopped at breakpoint %d\n",
  85.                    bp-breakpoint+1);
  86.                 break;
  87.             case AC_LIST:
  88.                 dispregs(z80regs.pc);
  89.                 docontinue = 1;
  90.                 break;
  91.             }
  92.             } else
  93.             docontinue = 1;    /* count not reached */
  94.     if (!docontinue && !mustbreak) {
  95.         /* reason code: TRAP or BIOS hook or BDOS hook */
  96.         if ((bdos_emulate && z80regs.pc == BDOS) || z80regs.pc >= BIOS)
  97.         docontinue = 1;
  98.         else
  99.         debug = 2;    /* TRAP */
  100.     }
  101.     } while (docontinue);
  102. }
  103.