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 / disneu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  4.5 KB  |  154 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. /* this module is inoperable */
  15.  
  16. #include "cpmemu.h"
  17.  
  18. static int numbytes;
  19.  
  20. static void byte(char *s, unsigned o) {
  21.     static char hextab[] = "0123456789abcdef";
  22.     s[0] = hextab[o >> 4];
  23.     s[1] = hextab[o & 15];
  24. }
  25.  
  26. #define NBIOSCALLS    17
  27.  
  28. static int dis_sub(unsigned pc, char *s) {
  29.  
  30.     if (pc >= BIOS) {
  31.     static const char *biosfunc[] = {
  32.         "COLDBOOT", "WARMBOOT", "Console Status", "Console Input",
  33.         "Console Output", "List Output", "Punch Output", "Reader Input",
  34.         "Home", "Select Disk", "Set Track", "Set Sector", "Set DMA",
  35.         "Read", "Write", "List Status", "Sector Translate" };
  36. #if 0    /* here are jumps which may lead elsewhere */
  37.     if (pc < BIOS + 3 * NBIOSCALLS && !((pc-BIOS) % 3)) {
  38.         sprintf(s, "BIOS %s\n", biosfunc[(pc-BIOS)/3]);
  39.         return 3;
  40.     }
  41. #endif
  42.     if (pc >= 0xff6cU && pc < 0xff6cU+NBIOSCALLS) {
  43.         sprintf(s, "BIOS %s", biosfunc[pc-0xff6cU]);
  44.         return 1;
  45.     }
  46.     if (pc < BIOS + 3 * NBIOSCALLS && !((pc-BIOS) % 3))
  47.         ;
  48.     else {
  49.         sprintf(s, "BIOS (illegal place)");
  50.         return 1;
  51.     }
  52.     }
  53.  
  54.     if ((pc == BDOS || pc == 5) && z80regs.pc == pc) {
  55.     static const char *bdosfunc[] = {
  56.     /* 00 */ "System Reset", "Console Input", "Console Output",
  57.     /* 03 */ "Aux. Input", "Aux. Output", "List Output",
  58.     /* 06 */ "Direct I/O", "Aux. Input Status", "Aux. Output Status",
  59.     /* 09 */ "Print String", "Read Console Buffer", "Get Console Status",
  60.     /* 12 */ "Return Version Number", "Reset Disk System",
  61.     /* 14 */ "Select Disk", "Open File", "Close File",
  62.     /* 17 */ "Search for First", "Search for Next", "Delete File",
  63.     /* 20 */ "Read Sequential", "Write Sequential", "Make File",
  64.     /* 23 */ "Rename File",    "Return Login Vector", "Return Current Disk",
  65.     /* 26 */ "Set DMA Address", "Get Addr(Alloc)", "Write Protect Disk",
  66.     /* 29 */ "Get R/O-Vector", "Set File Attributes", "Get Addr. of DPB",
  67.     /* 32 */ "Set/Get User Code", "Read Random", "Write Random",
  68.     /* 35 */ "Compute File Size", "Set Random Record", "Reset Drive",
  69.     /* 38 */ "Access Drive", "Free Drive", "Write Random with Zero Fill",
  70.     /* 41 */ "Change directory (extension)" };
  71.  
  72.     if ((z80regs.bc & 0xff) < sizeof(bdosfunc) / sizeof(bdosfunc[0]))
  73.             sprintf(s, "BDOS %s, arg %04x", bdosfunc[z80regs.bc & 0xff],
  74.             z80regs.de);
  75.         else
  76.             sprintf(s, "BDOS (0x%02x), arg %04x", z80regs.bc & 0xff,
  77.             z80regs.de);
  78.         return 3;
  79.     }
  80.     {   unsigned const char *PC;
  81.     PC = disz80(z80mem+pc, s, pc);
  82.     if (!(PC - z80mem - pc)) {
  83.         sprintf(s, "unknown");
  84.         return 1;
  85.     }
  86.     return PC - z80mem - pc;
  87.     }
  88. }
  89.  
  90. static char *disassemble(unsigned pc) {
  91.     static char s[60];
  92.     int i;
  93.     numbytes = dis_sub(pc, s+12);
  94.     memset(s, ' ', 12);
  95.     for (i = 0; i < numbytes; ++i)
  96.     byte(s+3*i, z80mem[pc+i]);
  97.     return s;
  98. }
  99.  
  100. void disassem(unsigned *loc, int num) {
  101.     while (num--) {
  102.     printf("%04x %s\n", *loc, disassemble(*loc));
  103.     *loc = (*loc + numbytes) & 0xffff;
  104.     }
  105. }
  106.  
  107. static char *flags(unsigned f) {
  108.     static char s[10];
  109.     const char *fl = "SZ0H0VNC";
  110.     int i;
  111.     strcpy(s, "        ");
  112.     for (i = 0; i < 8; ++i) {
  113.         if (f & 0x80)
  114.             s[i] = fl[i];
  115.         f <<= 1;
  116.     }
  117.     return s;
  118. }
  119.  
  120. void dispregs(unsigned pc) {
  121.     printf("%s A=%02x BC=%04x DE=%04x HL=%04x SP=%04x PC=%04x  %s\n",
  122.        flags(z80regs.af >> 8), z80regs.af & 0xff,
  123.        z80regs.bc, z80regs.de, z80regs.hl, z80regs.sp,
  124.        pc, disassemble(pc));
  125.     fflush(stdout);
  126. }
  127.  
  128. void dispregs2(void) {
  129.     printf("%s a=%02x bc=%04x de=%04x hl=%04x IX=%04x IY=%04x  I=%02x R=%02x\n",
  130.        flags(z80regs.af2 >> 8), z80regs.af2 & 0xff,
  131.        z80regs.bc2, z80regs.de2, z80regs.hl2, z80regs.ix, z80regs.iy, z80regs.ir >> 8, z80regs.ir & 0xff);
  132.     fflush(stdout);
  133. }
  134.  
  135. void memdump(unsigned addr, int lines) {
  136.     int i, j;
  137.     for (i = 0; i < lines; ++i) {
  138.     printf("%04x ", addr);
  139.     for (j = 0; j < 16; ++j) {
  140.         if (j == 8)
  141.         printf(" -");
  142.         printf(" %02x", z80mem[addr+j]);
  143.     }
  144.     printf("  ");
  145.     for (j = 0; j < 16; ++j) {
  146.         if (j == 8)
  147.         printf(" ");
  148.         printf("%c", z80mem[addr+j] < ' ' ? '.' : z80mem[addr+j]);
  149.     }
  150.     printf("\n");
  151.     addr += 16;
  152.     }
  153. }
  154.