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 / makeloads.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  4.4 KB  |  116 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 <stdio.h>
  15. #include <stdlib.h>
  16.  
  17. static const char *str[] = { "op",  "op",  "op",  "op",  "op",  "op",  "op",  "op", "ix", "iy" };
  18. static int off[] = { 0,1,2,3,4,5,6,7,6,6 };
  19. static const char *fetch[] = { "", "", "", "", "", "", "", "", "GETIXOFF\n ", "GETIYOFF\n " };
  20.  
  21. #define CODE(i)    printf(" opcode (0x%02x)\nop%02x:\n ", i, i)
  22. #define CODEIX(i)  printf(" opcode (0x%02x)\nix%02x:\n ", i, i)
  23. #define CODEIY(i)  printf(" opcode (0x%02x)\niy%02x:\n ", i, i)
  24. #define ZCODE(j,i) printf(" opcode (0x%02x)\n%s%02x:\n ", j+i, str[i], j+off[i])
  25. static const char *fmt[] = {
  26. "%sandb $0xd5,%%ah\t/* ADD A,reg */\n addb %s,%%al\n jmp setaddadc\n",
  27. "%sandb $0xd5,%%ah\t/* ADC A,reg */\n sahf\n adcb %s,%%al\n jmp setaddadc\n",
  28. "%sorb $2,%%ah\t/* SUB reg */\n subb %s,%%al\n jmp setaddadc\n",
  29. "%sorb $2,%%ah\t/* SBC A,reg */\n sahf\n sbbb %s,%%al\n jmp setaddadc\n",
  30. "%sandb %s,%%al\t/* AND reg */\n lahf\n orb $0x10,%%ah\n andb $0xd4,%%ah\n dispatch\n",
  31. "%sxorb %s,%%al\t/* XOR reg */\n lahf\n andb $0xc4,%%ah\n dispatch\n",
  32. "%sorb %s,%%al\t/* OR reg */\n lahf\n andb $0xc4,%%ah\n dispatch\n",
  33. "%sorb $2,%%ah\t/* CP reg */\n cmpb %s,%%al\n jmp setaddadc\n" };
  34.  
  35. int main(void) {
  36.     static const char *regs[] = { "%ch", "%cl", "%dh", "%dl", "%bh", "%bl",
  37.           "(%ebx,%ebp)", "%al", "(%edi,%ebp)", "(%edi,%ebp)" };
  38.     static const char *cbregs[] = { "%ch", "%cl", "%dh", "%dl", "%bh", "%bl",
  39.           "(%edi,%ebp)", "%al" };
  40.     static const char *z80cc[] = { "NZ", "Z", "NC", "C", "PO", "PE", "P", "M" };
  41.     static const char *i386cc[] = { "nz", "z", "nc", "c", "po", "pe", "ns", "s" };
  42.  
  43.     int i;
  44.     printf("/* loads.s: DO NOT EDIT! Automatically generated by makeloads */\n");
  45.     for (i = 0; i < 64; ++i) {
  46.     if ((i & 7) != (i >> 3)) {
  47.         CODE(0x40+i);
  48.         printf("movb %s,%s\n dispatch\n", regs[i&7], regs[i>>3]);
  49.         if ((i & 7) == 6) {    /* do also ix, iy */
  50.         CODEIX(0x40+i);
  51.         printf("GETIXOFF\n movb (%%edi,%%ebp),%s\n dispatch\n", regs[i>>3]);
  52.         CODEIY(0x40+i);
  53.         printf("GETIYOFF\n movb (%%edi,%%ebp),%s\n dispatch\n", regs[i>>3]);
  54.         } else if ((i >> 3) == 6)  { /* do also ix, iy */
  55.         CODEIX(0x40+i);
  56.         printf("GETIXOFF\n movb %s,(%%edi,%%ebp)\n dispatch\n", regs[i&7]);
  57.         CODEIY(0x40+i);
  58.         printf("GETIYOFF\n movb %s,(%%edi,%%ebp)\n dispatch\n", regs[i&7]);
  59.         }
  60.     }
  61.     }
  62.     {   int j;
  63.     for (j = 0x80; j < 0xc0; j += 8) {
  64.         for (i = 0; i < 10; ++i) {
  65.         ZCODE(j,i);
  66.         printf(fmt[(j-0x80)>>3],  fetch[i], regs[i]);
  67.         }
  68.     }
  69.     }
  70.  
  71.     /* RST (nn) */
  72.     for (i = 1; i < 8; ++i) {
  73.     CODE(0xc7+8*i);
  74.     printf("movl $%d,%%edi\t/* RST %02x */\n jmp docall_di\n",
  75.            i*8, i*8);
  76.     }
  77.     /* JP cc,nnnn */
  78.     for (i = 0; i < 8; ++i) {
  79.     CODE(0xc2+8*i);
  80.     printf("sahf\t/* JP %s,nnnn */\n j%s opc3\n incl %%esi\n"
  81.            " incl %%esi\n dispatch\n", z80cc[i], i386cc[i]);
  82.     }
  83.     /* RET cc */
  84.     for (i = 0; i < 8; ++i) {
  85.     CODE(0xc0+8*i);
  86.     printf("sahf\t/* RET %s */\n j%s opc9\n dispatch\n",
  87.            z80cc[i], i386cc[i]);
  88.     }
  89.     /* CALL cc,nnnn */
  90.     for (i = 0; i < 8; ++i) {
  91.     CODE(0xc4+8*i);
  92.     printf("sahf\t/* CALL %s,nnnn */\n j%s opcd\n incl %%esi\n"
  93.            " incl %%esi\n dispatch\n", z80cc[i], i386cc[i]);
  94.     }
  95.  
  96.     /* Z80 extended commands with "cb" prefix */
  97.     for (i = 0; i < 64; ++i) {
  98.     static const char *rotcmds[] = {
  99.         "rolb", "rorb", "rclb", "rcrb", "shlb", "sarb", NULL, "shrb" };
  100.     if ((i >> 3) != 6)
  101.         printf(" .align NALIGN,0x90\ncb%02x: sahf\n"
  102.            " %s $1,%s\n movzbl %s,%%edi\n jmp set_SZV\n", i,
  103.            rotcmds[i>>3], cbregs[i&7], cbregs[i&7]);
  104.     }
  105.     for (i = 0; i < 64; ++i)    /* BIT n,r */
  106.     printf(" .align NALIGN,0x90\ncb%02x: testb $%d,%s\n jmp setbit\n",
  107.            i+0x40, 1 << (i>>3), cbregs[i&7]);
  108.     for (i = 0; i < 64; ++i)    /* RES n,r */
  109.     printf(" .align NALIGN,0x90\ncb%02x: andb $%d,%s\n dispatch\n",
  110.            i+0x80, 255-(1 << (i>>3)), cbregs[i&7]);
  111.     for (i = 0; i < 64; ++i)    /* SET n,r */
  112.     printf(" .align NALIGN,0x90\ncb%02x: orb $%d,%s\n dispatch\n",
  113.            i+0xc0, 1 << (i>>3), cbregs[i&7]);
  114.     return 0;
  115. }
  116.