home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / emulator / unix / z80pack / z80sim / simglb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-11  |  7.6 KB  |  197 lines

  1. /*
  2.  * Z80SIM  -  a    Z80-CPU    simulator
  3.  *
  4.  * Copyright (C) 1987-92 by Udo Munk
  5.  *
  6.  * This module of the Z80-CPU simulator must not be modified by a user,
  7.  * see license agreement!
  8.  *
  9.  * History:
  10.  * 28-SEP-87 Development on TARGON/35 with AT&T Unix System V.3
  11.  * 11-JAN-89 Release 1.1
  12.  * 08-FEB-89 Release 1.2
  13.  * 13-MAR-89 Release 1.3
  14.  * 09-FEB-90 Release 1.4 Ported to TARGON/31 M10/30
  15.  * 20-DEC-90 Release 1.5 Ported to COHERENT
  16.  * 10-JUN-92 Release 1.6 long casting problem solved with COHERENT 3.2
  17.  *             and some optimization
  18.  * 25-JUN-92 Release 1.7 comments in english and ported to COHERENT 4.0
  19.  */
  20.  
  21. /*
  22.  *    This modul contains all the global variables
  23.  */
  24.  
  25. #include "sim.h"
  26.  
  27. /*
  28.  *    CPU-Register
  29.  */
  30. BYTE A,B,C,D,E,H,L;        /* Z80 primary registers */
  31. int  F;                /* normaly 8-Bit, but int is faster */
  32. WORD IX, IY;
  33. BYTE A_,B_,C_,D_,E_,H_,L_;    /* Z80 secoundary registers */
  34. int  F_;
  35. BYTE *PC;            /* Z80 programm counter */
  36. BYTE *STACK;            /* Z80 stackpointer */
  37. BYTE I;                /* Z80 interrupt register */
  38. BYTE IFF;            /* Z80 interrupt flags */
  39. long R;                /* Z80 refresh register */
  40.                 /* is normaly a 8 bit register    */
  41.                 /* the 32 bits are used to measure the */
  42.                 /* clock frequency */
  43.  
  44. /*
  45.  *    Variables for memory of the emulated CPU
  46.  */
  47. #if defined(COHERENT) && !defined(_I386)
  48. BYTE ram[32767];        /* only 32KB under COHERENT 3.x */
  49. #else
  50. BYTE ram[65536L];        /* 64KB for all other OS's */
  51. #endif
  52. BYTE *wrk_ram;            /* workpointer into memory for dump etc. */
  53.  
  54. /*
  55.  *    Variables for history memory
  56.  */
  57. #ifdef HISIZE
  58. struct history his[HISIZE];    /* memory to hold trace informations */
  59. int h_next;            /* index into trace memory */
  60. int h_flag;            /* flag for trace memory overrun */
  61. #endif
  62.  
  63. /*
  64.  *    Variables for breakpoint memory
  65.  */
  66. #ifdef SBSIZE
  67. struct softbreak soft[SBSIZE];    /* memory to hold breakpoint informations */
  68. int sb_next;            /* index into breakpoint memory */
  69. #endif
  70.  
  71. /*
  72.  *    Variables for runtime measurement
  73.  */
  74. #ifdef WANT_TIM
  75. long t_states;            /* number of counted T states */
  76. int t_flag;            /* flag, 1 = on, 0 = off */
  77. #if !defined(COHERENT) || defined(_I386)
  78. BYTE *t_start =    ram + 65535;    /* start address for measurement */
  79. BYTE *t_end = ram + 65535;    /* end address for measurement */
  80. #else
  81. BYTE *t_start =    ram + 32767;
  82. BYTE *t_end = ram + 32767;
  83. #endif
  84. #endif
  85.  
  86. /*
  87.  *    Flag to controll operation of simulation
  88.  */
  89. int s_flag;            /* flag    for -s option */
  90. int l_flag;            /* flag    for -l option */
  91. int m_flag;            /* flag    for -m option */
  92. int x_flag;            /* flag    for -x option */
  93. char xfn[LENCMD];        /* buffer for filename (option -x) */
  94. int break_flag = 1;        /* 1 = break at HALT, 0 = execute HALT */
  95. int cpu_state;            /* status of CPU emulation */
  96. int cpu_error;            /* error status of CPU emulation */
  97. int int_type;            /* type    of interrupt */
  98. int int_mode;            /* CPU interrupt mode (IM 0, IM 1, IM 2) */
  99. int cntl_c;            /* flag    for cntl-c entered */
  100. int cntl_bs;            /* flag    for cntl-\ entered */
  101.  
  102. /*
  103.  *    Table to get parritys as fast as possible
  104.  */
  105. int parrity[256] = {
  106.         0 /* 00000000 */, 1 /* 00000001    */, 1 /* 00000010 */,
  107.         0 /* 00000011 */, 1 /* 00000100    */, 0 /* 00000101 */,
  108.         0 /* 00000110 */, 1 /* 00000111    */, 1 /* 00001000 */,
  109.         0 /* 00001001 */, 0 /* 00001010    */, 1 /* 00001011 */,
  110.         0 /* 00001100 */, 1 /* 00001101    */, 1 /* 00001110 */,
  111.         0 /* 00001111 */, 1 /* 00010000    */, 0 /* 00010001 */,
  112.         0 /* 00010010 */, 1 /* 00010011    */, 0 /* 00010100 */,
  113.         1 /* 00010101 */, 1 /* 00010110    */, 0 /* 00010111 */,
  114.         0 /* 00011000 */, 1 /* 00011001    */, 1 /* 00011010 */,
  115.         0 /* 00011011 */, 1 /* 00011100    */, 0 /* 00011101 */,
  116.         0 /* 00011110 */, 1 /* 00011111    */, 1 /* 00100000 */,
  117.         0 /* 00100001 */, 0 /* 00100010    */, 1 /* 00100011 */,
  118.         0 /* 00100100 */, 1 /* 00100101    */, 1 /* 00100110 */,
  119.         0 /* 00100111 */, 0 /* 00101000    */, 1 /* 00101001 */,
  120.         1 /* 00101010 */, 0 /* 00101011    */, 1 /* 00101100 */,
  121.         0 /* 00101101 */, 0 /* 00101110    */, 1 /* 00101111 */,
  122.         0 /* 00110000 */, 1 /* 00110001    */, 1 /* 00110010 */,
  123.         0 /* 00110011 */, 1 /* 00110100    */, 0 /* 00110101 */,
  124.         0 /* 00110110 */, 1 /* 00110111    */, 1 /* 00111000 */,
  125.         0 /* 00111001 */, 0 /* 00111010    */, 1 /* 00111011 */,
  126.         0 /* 00111100 */, 1 /* 00111101    */, 1 /* 00111110 */,
  127.         0 /* 00111111 */, 1 /* 01000000    */, 0 /* 01000001 */,
  128.         0 /* 01000010 */, 1 /* 01000011    */, 0 /* 01000100 */,
  129.         1 /* 01000101 */, 1 /* 01000110    */, 0 /* 01000111 */,
  130.         0 /* 01001000 */, 1 /* 01001001    */, 1 /* 01001010 */,
  131.         0 /* 01001011 */, 1 /* 01001100    */, 0 /* 01001101 */,
  132.         0 /* 01001110 */, 1 /* 01001111    */, 0 /* 01010000 */,
  133.         1 /* 01010001 */, 1 /* 01010010    */, 0 /* 01010011 */,
  134.         1 /* 01010100 */, 0 /* 01010101    */, 0 /* 01010110 */,
  135.         1 /* 01010111 */, 1 /* 01011000    */, 0 /* 01011001 */,
  136.         0 /* 01011010 */, 1 /* 01011011    */, 0 /* 01011100 */,
  137.         1 /* 01011101 */, 1 /* 01011110    */, 0 /* 01011111 */,
  138.         0 /* 01100000 */, 1 /* 01100001    */, 1 /* 01100010 */,
  139.         0 /* 01100011 */, 1 /* 01100100    */, 0 /* 01100101 */,
  140.         0 /* 01100110 */, 1 /* 01100111    */, 1 /* 01101000 */,
  141.         0 /* 01101001 */, 0 /* 01101010    */, 1 /* 01101011 */,
  142.         0 /* 01101100 */, 1 /* 01101101    */, 1 /* 01101110 */,
  143.         0 /* 01101111 */, 1 /* 01110000    */, 0 /* 01110001 */,
  144.         0 /* 01110010 */, 1 /* 01110011    */, 0 /* 01110100 */,
  145.         1 /* 01110101 */, 1 /* 01110110    */, 0 /* 01110111 */,
  146.         0 /* 01111000 */, 1 /* 01111001    */, 1 /* 01111010 */,
  147.         0 /* 01111011 */, 1 /* 01111100    */, 0 /* 01111101 */,
  148.         0 /* 01111110 */, 1 /* 01111111    */,
  149.         1 /* 10000000 */, 0 /* 10000001    */, 0 /* 10000010 */,
  150.         1 /* 10000011 */, 0 /* 10000100    */, 1 /* 10000101 */,
  151.         1 /* 10000110 */, 0 /* 10000111    */, 0 /* 10001000 */,
  152.         1 /* 10001001 */, 1 /* 10001010    */, 0 /* 10001011 */,
  153.         1 /* 10001100 */, 0 /* 10001101    */, 0 /* 10001110 */,
  154.         1 /* 10001111 */, 0 /* 10010000    */, 1 /* 10010001 */,
  155.         1 /* 10010010 */, 0 /* 10010011    */, 1 /* 10010100 */,
  156.         0 /* 10010101 */, 0 /* 10010110    */, 1 /* 10010111 */,
  157.         1 /* 10011000 */, 0 /* 10011001    */, 0 /* 10011010 */,
  158.         1 /* 10011011 */, 0 /* 10011100    */, 1 /* 10011101 */,
  159.         1 /* 10011110 */, 0 /* 10011111    */, 0 /* 10100000 */,
  160.         1 /* 10100001 */, 1 /* 10100010    */, 0 /* 10100011 */,
  161.         1 /* 10100100 */, 0 /* 10100101    */, 0 /* 10100110 */,
  162.         1 /* 10100111 */, 1 /* 10101000    */, 0 /* 10101001 */,
  163.         0 /* 10101010 */, 1 /* 10101011    */, 0 /* 10101100 */,
  164.         1 /* 10101101 */, 1 /* 10101110    */, 0 /* 10101111 */,
  165.         1 /* 10110000 */, 0 /* 10110001    */, 0 /* 10110010 */,
  166.         1 /* 10110011 */, 0 /* 10110100    */, 1 /* 10110101 */,
  167.         1 /* 10110110 */, 0 /* 10110111    */, 0 /* 10111000 */,
  168.         1 /* 10111001 */, 1 /* 10111010    */, 0 /* 10111011 */,
  169.         1 /* 10111100 */, 0 /* 10111101    */, 0 /* 10111110 */,
  170.         1 /* 10111111 */, 0 /* 11000000    */, 1 /* 11000001 */,
  171.         1 /* 11000010 */, 0 /* 11000011    */, 1 /* 11000100 */,
  172.         0 /* 11000101 */, 0 /* 11000110    */, 1 /* 11000111 */,
  173.         1 /* 11001000 */, 0 /* 11001001    */, 0 /* 11001010 */,
  174.         1 /* 11001011 */, 0 /* 11001100    */, 1 /* 11001101 */,
  175.         1 /* 11001110 */, 0 /* 11001111    */, 1 /* 11010000 */,
  176.         0 /* 11010001 */, 0 /* 11010010    */, 1 /* 11010011 */,
  177.         0 /* 11010100 */, 1 /* 11010101    */, 1 /* 11010110 */,
  178.         0 /* 11010111 */, 0 /* 11011000    */, 1 /* 11011001 */,
  179.         1 /* 11011010 */, 0 /* 11011011    */, 1 /* 11011100 */,
  180.         0 /* 11011101 */, 0 /* 11011110    */, 1 /* 11011111 */,
  181.         1 /* 11100000 */, 0 /* 11100001    */, 0 /* 11100010 */,
  182.         1 /* 11100011 */, 0 /* 11100100    */, 1 /* 11100101 */,
  183.         1 /* 11100110 */, 0 /* 11100111    */, 0 /* 11101000 */,
  184.         1 /* 11101001 */, 1 /* 11101010    */, 0 /* 11101011 */,
  185.         1 /* 11101100 */, 0 /* 11101101    */, 0 /* 11101110 */,
  186.         1 /* 11101111 */, 0 /* 11110000    */, 1 /* 11110001 */,
  187.         1 /* 11110010 */, 0 /* 11110011    */, 1 /* 11110100 */,
  188.         0 /* 11110101 */, 0 /* 11110110    */, 1 /* 11110111 */,
  189.         1 /* 11111000 */, 0 /* 11111001    */, 0 /* 11111010 */,
  190.         1 /* 11111011 */, 0 /* 11111100    */, 1 /* 11111101 */,
  191.         1 /* 11111110 */, 0 /* 11111111    */
  192. };
  193.  
  194. #if defined(COHERENT) && !defined(_I386)
  195. char adr_err[] = "address out of range";
  196. #endif
  197.