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 / EMULATOR / UNIX / CAIN1 / CPM-I386.H < prev    next >
C/C++ Source or Header  |  2000-06-30  |  4KB  |  170 lines

  1. /*
  2. cpm-i386
  3.  
  4. Written by D'Arcy J.M. Cain
  5. darcy@druid
  6.  
  7. This file is the header used by the CP/M emulator when running under
  8. the following machine(s):
  9.  
  10.     System V Rel 3.2 on Intel 80386 processor
  11.  
  12. Link this file to cpm.h on the above system.  Other entries will be added
  13. as they are tested.
  14.  
  15. To use this program on systems which differ from the above in significant
  16. ways, a header must be created such that the Z80 registers can be accessed
  17. using the following register names:
  18.     A, B, C, D, E, H, L, BC, DE, HL, IX, IY, SP, PC, AF and FLAGS
  19. In addition the following flags sould be available:
  20.     CARRY, BCD, PARITY, HALF_CARRY, ZERO and SIGN
  21. Also the HL, SP, IX and IY registers should have a H and L version for
  22. accessing half-words and TEMP should be a scratch variable accessed the
  23. same way.  See below for examples.
  24.  
  25. There should also be a variable IFF and an array of 0x10000 (65,536) bytes
  26. called ram.
  27.  
  28. The two variables psw_bank and gr_bank should allow register context
  29. switching for the AF register and the general registers
  30.  
  31. */
  32.  
  33. #ifdef    COMPILE_TEST
  34. #define    CPM_DEBUG
  35. #endif
  36.  
  37. typedef    unsigned char    byte;
  38. typedef unsigned short    word;
  39. /* We use unsigned short to guarantee two byte words and roll-over */
  40.  
  41. #define    lonyb(v)    (v & 0xf)
  42. #define    hinyb(v)    ((v >> 4) & 0xf)
  43. #define    when        break; case
  44.  
  45. typedef union {
  46.     word    af;
  47.     struct {
  48.         byte    flags, a;
  49.     } b;
  50.     struct {
  51.         unsigned int    carry:1;
  52.         unsigned int    bcd:1;
  53.         unsigned int    parity:1;
  54.         unsigned int    x1:1;
  55.         unsigned int    half:1;
  56.         unsigned int    x2:1;
  57.         unsigned int    zero:1;
  58.         unsigned int    sign:1;
  59.     } bits;
  60. } ACC;
  61.  
  62. typedef union {
  63.     struct {
  64.         word    bc;
  65.         word    de;
  66.         word    hl;
  67.     } w;
  68.     struct {
  69.         byte    c, b;
  70.         byte    e, d;
  71.         byte    l, h;
  72.     } b;
  73. } GR;
  74.  
  75. typedef union {
  76.     unsigned char    half[2];
  77.     unsigned short    whole;
  78. } REG;
  79.  
  80. #define    TEMPH    (reg.half[1])
  81. #define    TEMPL    (reg.half[0])
  82. #define    TEMP    (reg.whole)
  83. #define    SPH        (sp.half[1])
  84. #define    SPL        (sp.half[0])
  85. #define    SP        (sp.whole)
  86. #define IXH        (ix.half[1])
  87. #define IXL        (ix.half[0])
  88. #define IX        (ix.whole)
  89. #define IYH        (iy.half[1])
  90. #define IYL        (iy.half[0])
  91. #define IY        (iy.whole)
  92.  
  93. #ifdef    CPM_DATA
  94. ACC        acc[2];
  95. GR        gr[2];
  96. word    PC;
  97. byte    R, IV;
  98. int        gr_bank = 0, acc_bank = 0, IFF = 1;
  99. REG        reg, sp, ix, iy;
  100.  
  101. #ifdef    COMPILE_TEST
  102. byte    ram[0x10000] = {
  103.     0x00,                /* 0000: nop */
  104.     0x21, 0x00, 0x10,    /* 0001: ld hl, 1000h */
  105.     0xe5,                /* 0004: push hl */
  106.     0x3e, 0xbb,            /* 0005: ld a, 0bbh */
  107.     0x87,                /* 0007: add a, a */
  108.     0x8f,                /* 0008: adc a, a */
  109.     0x3d,                /* 0009: dec a */
  110.     0x2f,                /* 000a: cpl */
  111.     0xb8,                /* 000b: cp b */
  112.     0xcc, 0x14, 0x00,    /* 000c: call z, 0014h */
  113.     0xbf,                /* 000f: cp a */
  114.     0xcc, 0x14, 0x00,    /* 0010: call z, 0014h */
  115.     0x00,                /* 0013: nop */
  116.     0xc3, 0x19, 0x00,    /* 0014: jp 0019h */
  117.     0x18, 0x03,            /* 0x17: jr 001bh */
  118.     0x18, 0xfd,            /* 0x19: jr 0014h */
  119.     0xc9,                /* 001b: ret */
  120.     0x00 };                /* 0015: nop */
  121. #define        TEST_SIZE    24
  122. #else
  123. byte    ram[0x10000];
  124. #endif
  125.  
  126. byte    page_zero[] = {
  127.     0xc3, 0x03, 0xff,    /* JP BIOS+3 */
  128.     0x00, 0x00,            /* reserved */
  129.     0xc3, 0xc0, 0xfe,    /* JP BDOS */
  130. };
  131.  
  132. #else
  133. extern ACC    acc[];
  134. extern GR    gr[];
  135. extern word    PC;
  136. extern byte    R, IV, ram[];
  137. extern int    gr_bank, acc_bank, IFF;
  138. extern REG    reg, sp, ix, iy;
  139. #endif
  140.  
  141. #define        AF            (acc[acc_bank].af)
  142. #define        A            (acc[acc_bank].b.a)
  143. #define        FLAGS        (acc[acc_bank].b.flags)
  144. #define        CARRY        (acc[acc_bank].bits.carry)
  145. #define        BCD            (acc[acc_bank].bits.bcd)
  146. #define        PARITY        (acc[acc_bank].bits.parity)
  147. #define        OVERFLOW    (acc[acc_bank].bits.parity)
  148. #define        HALF_CARRY    (acc[acc_bank].bits.half)
  149. #define        ZERO        (acc[acc_bank].bits.zero)
  150. #define        SIGN        (acc[acc_bank].bits.sign)
  151.  
  152. #define        B            (gr[gr_bank].b.b)
  153. #define        C            (gr[gr_bank].b.c)
  154. #define        D            (gr[gr_bank].b.d)
  155. #define        E            (gr[gr_bank].b.e)
  156. #define        H            (gr[gr_bank].b.h)
  157. #define        L            (gr[gr_bank].b.l)
  158. #define        BC            (gr[gr_bank].w.bc)
  159. #define        DE            (gr[gr_bank].w.de)
  160. #define        HL            (gr[gr_bank].w.hl)
  161.  
  162. #define        BDOS        0xfec0
  163. #define        BIOS        0xff00
  164. #define        bios(x)        (BIOS + (x * 3))
  165.  
  166. #define        MAX_DRIVES    16
  167.  
  168. int            decode(void);
  169. const char    *dasm(const byte *buf);
  170.