-/* Multi-Z80 32 Bit emulator */\r
-\r
-/* Copyright 1996, 1997, 1998, 1999, 2000 Neil Bradley, All rights reserved\r
- *\r
- * License agreement:\r
- *\r
- * (MZ80 Refers to both the assembly and C code emitted by makeZ80.c and \r
- * makeZ80.c itself)\r
- *\r
- * MZ80 May be distributed in unmodified form to any medium.\r
- *\r
- * MZ80 May not be sold, or sold as a part of a commercial package without\r
- * the express written permission of Neil Bradley (neil@synthcom.com). This\r
- * includes shareware.\r
- *\r
- * Modified versions of MZ80 may not be publicly redistributed without author\r
- * approval (neil@synthcom.com). This includes distributing via a publicly\r
- * accessible LAN. You may make your own source modifications and distribute\r
- * MZ80 in source or object form, but if you make modifications to MZ80\r
- * then it should be noted in the top as a comment in makeZ80.c.\r
- *\r
- * MZ80 Licensing for commercial applications is available. Please email\r
- * neil@synthcom.com for details.\r
- *\r
- * Synthcom Systems, Inc, and Neil Bradley will not be held responsible for\r
- * any damage done by the use of MZ80. It is purely "as-is".\r
- *\r
- * If you use MZ80 in a freeware application, credit in the following text:\r
- *\r
- * "Multi-Z80 CPU emulator by Neil Bradley (neil@synthcom.com)"\r
- *\r
- * must accompany the freeware application within the application itself or\r
- * in the documentation.\r
- *\r
- * Legal stuff aside:\r
- *\r
- * If you find problems with MZ80, please email the author so they can get\r
- * resolved. If you find a bug and fix it, please also email the author so\r
- * that those bug fixes can be propogated to the installed base of MZ80\r
- * users. If you find performance improvements or problems with MZ80, please\r
- * email the author with your changes/suggestions and they will be rolled in\r
- * with subsequent releases of MZ80.\r
- *\r
- * The whole idea of this emulator is to have the fastest available 32 bit\r
- * Multi-Z80 emulator for the PC, giving maximum performance. \r
- *\r
- */ \r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <assert.h>\r
-\r
-#define VERSION "3.4"\r
-\r
-#define TRUE 0xff\r
-#define FALSE 0x0\r
-#define INVALID 0xff\r
-\r
-#define UINT32 unsigned long int\r
-#define UINT8 unsigned char\r
-\r
-#define TIMING_REGULAR 0x00\r
-#define TIMING_XXCB 0x01\r
-#define TIMING_CB 0xcb\r
-#define TIMING_DDFD 0xdd\r
-#define TIMING_ED 0xed\r
-#define TIMING_EXCEPT 0x02\r
-\r
-FILE *fp = NULL;\r
-char string[150];\r
-char cpubasename[150];\r
-static char mz80Index[50];\r
-static char mz80IndexHalfHigh[50];\r
-static char mz80IndexHalfLow[50];\r
-char majorOp[50];\r
-char procname[150];\r
-UINT32 dwGlobalLabel = 0;\r
-\r
-enum\r
-{\r
- MZ80_ASSEMBLY_X86,\r
- MZ80_C,\r
- MZ80_UNKNOWN\r
-};\r
-\r
-UINT8 bPlain = FALSE;\r
-UINT8 bNoTiming = FALSE;\r
-UINT8 bUseStack = 0;\r
-UINT8 bCurrentMode = TIMING_REGULAR; // Current timing mode\r
-UINT8 b16BitIo = FALSE;\r
-UINT8 bThroughCallHandler = FALSE;\r
-UINT8 bOS2 = FALSE;\r
-UINT8 bWhat = MZ80_UNKNOWN;\r
-\r
-void ProcBegin(UINT32 dwOpcode);\r
-\r
-UINT8 *pbLocalReg[8] =\r
-{\r
- "ch",\r
- "cl",\r
- "dh",\r
- "dl",\r
- "bh",\r
- "bl",\r
- "dl",\r
- "al"\r
-};\r
-\r
-UINT8 *pbLocalRegC[8] =\r
-{\r
- "cpu.z80B",\r
- "cpu.z80C",\r
- "cpu.z80D",\r
- "cpu.z80E",\r
- "cpu.z80H",\r
- "cpu.z80L",\r
- "barf",\r
- "cpu.z80A"\r
-};\r
-\r
-UINT8 *pbPushReg[8] = \r
-{\r
- "cl",\r
- "ch",\r
- "byte [_z80de]",\r
- "byte [_z80de + 1]",\r
- "bl",\r
- "bh",\r
- "ah",\r
- "al"\r
-};\r
-\r
-UINT8 *pbFlags[8] =\r
-{\r
- "nz",\r
- "z",\r
- "nc",\r
- "c",\r
- "po",\r
- "pe",\r
- "ns",\r
- "s"\r
-};\r
-\r
-UINT8 *pbRegPairC[] =\r
-{\r
- "cpu.z80BC",\r
- "cpu.z80DE",\r
- "cpu.z80HL",\r
- "cpu.z80sp"\r
-};\r
-\r
-UINT8 *pbFlagsC[8] =\r
-{\r
- "(!(cpu.z80F & Z80_FLAG_ZERO))",\r
- "(cpu.z80F & Z80_FLAG_ZERO)",\r
- "(!(cpu.z80F & Z80_FLAG_CARRY))",\r
- "(cpu.z80F & Z80_FLAG_CARRY)",\r
- "(!(cpu.z80F & Z80_FLAG_OVERFLOW_PARITY))",\r
- "(cpu.z80F & Z80_FLAG_OVERFLOW_PARITY)",\r
- "(!(cpu.z80F & Z80_FLAG_SIGN))",\r
- "(cpu.z80F & Z80_FLAG_SIGN)"\r
-};\r
-\r
-UINT8 *pbMathReg[8] =\r
-{\r
- "ch",\r
- "cl",\r
- "byte [_z80de + 1]",\r
- "byte [_z80de]",\r
- "bh",\r
- "bl",\r
- "INVALID",\r
- "al"\r
-};\r
-\r
-UINT8 *pbMathRegC[8] =\r
-{\r
- "cpu.z80B",\r
- "cpu.z80C",\r
- "cpu.z80D",\r
- "cpu.z80E",\r
- "cpu.z80H",\r
- "cpu.z80L",\r
- "bTemp",\r
- "cpu.z80A"\r
-};\r
-\r
-UINT8 *pbRegPairs[4] = \r
-{\r
- "cx", // BC\r
- "word [_z80de]", // DE\r
- "bx", // HL\r
- "word [_z80sp]" // SP\r
-};\r
-\r
-UINT8 *pbRegPairsC[4] = \r
-{\r
- "cpu.z80BC", // BC\r
- "cpu.z80DE", // DE\r
- "cpu.z80HL", // HL\r
- "cpu.z80sp" // SP\r
-};\r
-\r
-UINT8 *pbPopRegPairs[4] = \r
-{\r
- "cx", // BC\r
- "word [_z80de]", // DE\r
- "bx", // HL\r
- "ax" // SP\r
-};\r
-\r
-UINT8 *pbPopRegPairC[4] = \r
-{\r
- "cpu.z80BC",\r
- "cpu.z80DE",\r
- "cpu.z80HL",\r
- "cpu.z80AF"\r
-};\r
-\r
-UINT8 *pbIndexedRegPairs[4] = \r
-{\r
- "cx", // BC\r
- "word [_z80de]", // DE\r
- "di", // IX/IY\r
- "word [_z80sp]" // SP\r
-};\r
-\r
-// Timing tables\r
-\r
-UINT8 bTimingRegular[0x100] =\r
-{\r
- 0x04, 0x0a, 0x07, 0x06, 0x04, 0x04, 0x07, 0x04, 0x04, 0x0b, 0x07, 0x06, 0x04, 0x04, 0x07, 0x04,\r
- 0x08, 0x0a, 0x07, 0x06, 0x04, 0x04, 0x07, 0x04, 0x0c, 0x0b, 0x07, 0x06, 0x04, 0x04, 0x07, 0x04,\r
- 0x07, 0x0a, 0x10, 0x06, 0x04, 0x04, 0x07, 0x04, 0x07, 0x0b, 0x10, 0x06, 0x04, 0x04, 0x07, 0x04,\r
- 0x07, 0x0a, 0x0d, 0x06, 0x0b, 0x0b, 0x0a, 0x04, 0x07, 0x0b, 0x0d, 0x06, 0x04, 0x04, 0x07, 0x04,\r
-\r
- 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x04,\r
- 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x04,\r
- 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x04,\r
- 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x04, 0x07, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x04,\r
-\r
- 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x04,\r
- 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x04,\r
- 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x04,\r
- 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x04,\r
-\r
- 0x05, 0x0a, 0x0a, 0x0a, 0x0a, 0x0b, 0x07, 0x0b, 0x05, 0x0a, 0x0a, 0x00, 0x0a, 0x11, 0x07, 0x0b,\r
- 0x05, 0x0a, 0x0a, 0x0b, 0x0a, 0x0b, 0x07, 0x0b, 0x05, 0x04, 0x0a, 0x0b, 0x0a, 0x00, 0x07, 0x0b,\r
- 0x05, 0x0a, 0x0a, 0x13, 0x0a, 0x0b, 0x07, 0x0b, 0x05, 0x04, 0x0a, 0x04, 0x0a, 0x00, 0x07, 0x0b,\r
- 0x05, 0x0a, 0x0a, 0x04, 0x0a, 0x0b, 0x07, 0x0b, 0x05, 0x06, 0x0a, 0x04, 0x0a, 0x00, 0x07, 0x0b\r
-};\r
-\r
-UINT8 bTimingCB[0x100] =\r
-{\r
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, \r
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, \r
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, \r
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, \r
-\r
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0c, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0c, 0x08, \r
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0c, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0c, 0x08, \r
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0c, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0c, 0x08, \r
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0c, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0c, 0x08, \r
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, \r
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, \r
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, \r
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, \r
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, \r
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, \r
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, \r
- 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08\r
-};\r
-\r
-UINT8 bTimingXXCB[0x100] =\r
-{\r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, \r
- 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,\r
- 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,\r
- 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,\r
- 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,\r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00\r
-};\r
-\r
-UINT8 bTimingDDFD[0x100] =\r
-{\r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
- 0x00, 0x0e, 0x14, 0x0a, 0x09, 0x09, 0x09, 0x00, 0x00, 0x0f, 0x14, 0x0a, 0x09, 0x09, 0x09, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x17, 0x17, 0x13, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
-\r
- 0x00, 0x00, 0x00, 0x00, 0x09, 0x09, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09, 0x13, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x09, 0x09, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09, 0x13, 0x00, \r
-\r
- 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x13, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x13, 0x09,\r
- 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09, 0x13, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x09, 0x09, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09, 0x13, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x09, 0x09, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09, 0x13, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x09, 0x09, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09, 0x13, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x09, 0x09, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09, 0x13, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
- 0x00, 0x0e, 0x00, 0x17, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\r
-};\r
-\r
-UINT8 bTimingED[0x100] = \r
-{\r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
-\r
- 0x0c, 0x0c, 0x0f, 0x14, 0x08, 0x0e, 0x08, 0x09, 0x0c, 0x0c, 0x0f, 0x14, 0x08, 0x0e, 0x08, 0x09,\r
- 0x0c, 0x0c, 0x0f, 0x14, 0x08, 0x08, 0x08, 0x09, 0x0c, 0x0c, 0x0f, 0x14, 0x08, 0x08, 0x08, 0x09,\r
- 0x0c, 0x0c, 0x0f, 0x14, 0x08, 0x08, 0x08, 0x12, 0x0c, 0x0c, 0x0f, 0x14, 0x08, 0x08, 0x08, 0x12,\r
- 0x0c, 0x0c, 0x0f, 0x14, 0x08, 0x08, 0x08, 0x00, 0x0c, 0x0c, 0x0f, 0x14, 0x08, 0x08, 0x08, 0x00,\r
-\r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
- 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, \r
- 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, \r
-\r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 \r
-};\r
-\r
-void EDHandler(UINT32 dwOpcode);\r
-void DDHandler(UINT32 dwOpcode);\r
-void FDHandler(UINT32 dwOpcode);\r
-void CBHandler(UINT32 dwOpcode);\r
-\r
-void PushPopOperations(UINT32 dwOpcode);\r
-void AddRegpairOperations(UINT32 dwOpcode);\r
-void CallHandler(UINT32 dwOpcode);\r
-void MiscHandler(UINT32 dwOpcode);\r
-void IMHandler(UINT32 dwOpcode);\r
-void IRHandler(UINT32 dwOpcode);\r
-void LdRegPairImmediate(UINT32 dwOpcode);\r
-void LoadImmediate(UINT32 dwOpcode);\r
-void LdRegpairPtrByte(UINT32 dwOpcode);\r
-void MathOperation(UINT32 dwOpcode);\r
-void RegIntoMemory(UINT32 dwOpcode);\r
-void JpHandler(UINT32 dwOpcode);\r
-void LdRegImmediate(UINT32 dwOpcode);\r
-void IncRegister(UINT32 dwOpcode);\r
-void DecRegister(UINT32 dwOpcode);\r
-void IncDecRegpair(UINT32 dwOpcode);\r
-void LdRegReg(UINT32 dwOpcode);\r
-void MathOperationDirect(UINT32 dwOpcode);\r
-void JrHandler(UINT32 dwOpcode);\r
-void RetHandler(UINT32 dwOpcode);\r
-void RestartHandler(UINT32 dwOpcode);\r
-void ToRegFromHl(UINT32);\r
-void RraRlaHandler(UINT32);\r
-void LdByteRegpair(UINT32);\r
-void IncDecHLPtr(UINT32 dwOpcode);\r
-void InOutHandler(UINT32 dwOpcode);\r
-void RLCRRCRLRRSLASRASRLHandler(UINT32 dwOpcode);\r
-void BITHandler(UINT32 dwOpcode);\r
-void RESSETHandler(UINT32 dwOpcode);\r
-void PushPopOperationsIndexed(UINT32 dwOpcode);\r
-void LDILDRLDIRLDDRHandler(UINT32);\r
-void LdRegpair(UINT32 dwOpcode);\r
-void ExtendedRegIntoMemory(UINT32 dwOpcode);\r
-void NegHandler(UINT32 dwOpcode);\r
-void ExtendedInHandler(UINT32 dwOpcode);\r
-void ExtendedOutHandler(UINT32 dwOpcode);\r
-void RetIRetNHandler(UINT32 dwOcode);\r
-void AdcSbcRegpair(UINT32 dwOpcode);\r
-void CPICPDCPIRCPDRHandler(UINT32 dwOpcode);\r
-void RRDRLDHandler(UINT32 dwOpcode);\r
-void UndocRegToIndex(UINT32 dwOpcode);\r
-void UndocIndexToReg(UINT32 dwOpcode);\r
-void MathOperationIndexed(UINT32 dwOpcode);\r
-void IncDecIndexed(UINT32 dwOpcode);\r
-void DDFDCBHandler(UINT32 dwOpcode);\r
-void JPIXIYHandler(UINT32 dwOpcode);\r
-void AddIndexHandler(UINT32 dwOpcode);\r
-void SPToIndex(UINT32 dwOpcode);\r
-void LdByteToIndex(UINT32 dwOpcode);\r
-void LdRegIndexOffset(UINT32 dwOpcode);\r
-void IncDecIndexReg(UINT32 dwOpcode);\r
-void ExIndexed(UINT32 dwOpcode);\r
-void UndocIncDecIndexReg(UINT32 dwOpcode);\r
-void UndocLoadHalfIndexReg(UINT32 dwOpcode);\r
-void UndocMathIndex(UINT32 dwOpcode);\r
-void ddcbBitWise(UINT32 dwOpcode);\r
-void LdIndexPtrReg(UINT32 dwOpcode);\r
-void StoreIndexReg(UINT32 dwOpcode);\r
-void LoadIndexReg(UINT32 dwOpcode);\r
-void OTIROTDROUTIOUTDHandler(UINT32 dwOpcode);\r
-void INIRINDRINIINDHandler(UINT32 dwOpcode);\r
-\r
-struct sOp\r
-{\r
- UINT32 bOpCode;\r
- void (*Emitter)(UINT32);\r
-};\r
-\r
-struct sOp StandardOps[] =\r
-{\r
- {0xd3, InOutHandler}, // V\r
- {0xdb, InOutHandler}, // V\r
-\r
- {0x0a, LdByteRegpair}, // V\r
- {0x1a, LdByteRegpair}, // V\r
-\r
- {0x17, RraRlaHandler}, // V\r
- {0x1f, RraRlaHandler}, // V\r
-\r
- {0x05, DecRegister}, // V\r
- {0x0d, DecRegister}, // V\r
- {0x15, DecRegister}, // V\r
- {0x1d, DecRegister}, // V\r
- {0x25, DecRegister}, // V\r
- {0x2d, DecRegister}, // V\r
- {0x3d, DecRegister}, // V\r
-\r
- {0x04, IncRegister}, // V\r
- {0x0c, IncRegister}, // V\r
- {0x14, IncRegister}, // V\r
- {0x1c, IncRegister}, // V\r
- {0x24, IncRegister}, // V\r
- {0x2c, IncRegister}, // V\r
- {0x3c, IncRegister}, // V\r
-\r
- {0x32, RegIntoMemory}, // V\r
- {0x22, RegIntoMemory}, // V\r
-\r
- {0xc3, JpHandler}, // V\r
- {0xc2, JpHandler}, // V\r
- {0xca, JpHandler}, // V\r
- {0xd2, JpHandler}, // V\r
- {0xda, JpHandler}, // V\r
- {0xe2, JpHandler}, // V\r
- {0xea, JpHandler}, // V\r
- {0xf2, JpHandler}, // V\r
- {0xfa, JpHandler}, // V\r
-\r
-\r
- {0x06, LdRegImmediate}, // V\r
- {0x0e, LdRegImmediate}, // V\r
- {0x16, LdRegImmediate}, // V\r
- {0x1e, LdRegImmediate}, // V\r
- {0x26, LdRegImmediate}, // V\r
- {0x2e, LdRegImmediate}, // V\r
- {0x3e, LdRegImmediate}, // V\r
-\r
- {0x0b, IncDecRegpair}, // V\r
- {0x1b, IncDecRegpair}, // V\r
- {0x2b, IncDecRegpair}, // V\r
- {0x3b, IncDecRegpair}, // V\r
-\r
- {0x03, IncDecRegpair}, // V\r
- {0x13, IncDecRegpair}, // V\r
- {0x23, IncDecRegpair}, // V\r
- {0x33, IncDecRegpair}, // V\r
-\r
- {0x34, IncDecHLPtr}, // V\r
- {0x35, IncDecHLPtr}, // V\r
-\r
- {0xcb, CBHandler},\r
- {0xdd, DDHandler},\r
- {0xed, EDHandler},\r
- {0xfd, FDHandler},\r
-\r
- {0x01, LdRegPairImmediate}, // V\r
- {0x11, LdRegPairImmediate}, // V\r
- {0x21, LdRegPairImmediate}, // V\r
- {0x31, LdRegPairImmediate}, // V\r
-\r
- {0xe3, MiscHandler}, // V\r
- {0x2a, MiscHandler}, // V\r
- {0xfb, MiscHandler}, // V\r
- {0xf9, MiscHandler}, // V\r
- {0xd9, MiscHandler}, // V\r
- {0x76, MiscHandler}, // V\r
- {0x3f, MiscHandler}, // V\r
- {0x37, MiscHandler}, // V\r
- {0x27, MiscHandler}, // V\r
- {0x07, MiscHandler}, // V\r
- {0x08, MiscHandler}, // V\r
- {0x00, MiscHandler}, // V\r
- {0xe9, MiscHandler}, // V\r
- {0xeb, MiscHandler}, // V\r
- {0xf3, MiscHandler}, // V\r
- {0x3a, MiscHandler}, // V\r
- {0x10, MiscHandler}, // V\r
- {0x2f, MiscHandler}, // V\r
- {0x0f, MiscHandler}, // V\r
-\r
- {0x02, LdRegpairPtrByte}, // V\r
- {0x12, LdRegpairPtrByte}, // V\r
-\r
- {0x70, LdRegpairPtrByte}, // V\r
- {0x71, LdRegpairPtrByte}, // V\r
- {0x72, LdRegpairPtrByte}, // V\r
- {0x73, LdRegpairPtrByte}, // V\r
- {0x74, LdRegpairPtrByte}, // V\r
- {0x75, LdRegpairPtrByte}, // V\r
- {0x77, LdRegpairPtrByte}, // V\r
-\r
- {0x36, LdRegpairPtrByte}, // V\r
-\r
- {0x80, MathOperation}, // V\r
- {0x81, MathOperation}, // V\r
- {0x82, MathOperation}, // V\r
- {0x83, MathOperation}, // V\r
- {0x84, MathOperation}, // V\r
- {0x85, MathOperation}, // V\r
- {0x86, MathOperation}, // V\r
- {0x87, MathOperation}, // V\r
- {0x88, MathOperation}, // V\r
- {0x89, MathOperation}, // V\r
- {0x8a, MathOperation}, // V\r
- {0x8b, MathOperation}, // V\r
- {0x8c, MathOperation}, // V\r
- {0x8d, MathOperation}, // V\r
- {0x8e, MathOperation}, // V\r
- {0x8f, MathOperation}, // V\r
- {0x90, MathOperation}, // V\r
- {0x91, MathOperation}, // V\r
- {0x92, MathOperation}, // V\r
- {0x93, MathOperation}, // V\r
- {0x94, MathOperation}, // V\r
- {0x95, MathOperation}, // V\r
- {0x96, MathOperation}, // V\r
- {0x97, MathOperation}, // V\r
- {0x98, MathOperation}, // V\r
- {0x99, MathOperation}, // V\r
- {0x9a, MathOperation}, // V\r
- {0x9b, MathOperation}, // V\r
- {0x9c, MathOperation}, // V\r
- {0x9d, MathOperation}, // V\r
- {0x9e, MathOperation}, // V\r
- {0x9f, MathOperation}, // V\r
- {0xa0, MathOperation}, // V\r
- {0xa1, MathOperation}, // V\r
- {0xa2, MathOperation}, // V\r
- {0xa3, MathOperation}, // V\r
- {0xa4, MathOperation}, // V\r
- {0xa5, MathOperation}, // V\r
- {0xa6, MathOperation}, // V\r
- {0xa7, MathOperation}, // V\r
- {0xa8, MathOperation}, // V\r
- {0xa9, MathOperation}, // V\r
- {0xaa, MathOperation}, // V\r
- {0xab, MathOperation}, // V\r
- {0xac, MathOperation}, // V\r
- {0xad, MathOperation}, // V\r
- {0xae, MathOperation}, // V\r
- {0xaf, MathOperation}, // V\r
- {0xb0, MathOperation}, // V\r
- {0xb1, MathOperation}, // V\r
- {0xb2, MathOperation}, // V\r
- {0xb3, MathOperation}, // V\r
- {0xb4, MathOperation}, // V\r
- {0xb5, MathOperation}, // V\r
- {0xb6, MathOperation}, // V\r
- {0xb7, MathOperation}, // V\r
- {0xb8, MathOperation}, // V\r
- {0xb9, MathOperation}, // V\r
- {0xba, MathOperation}, // V\r
- {0xbb, MathOperation}, // V\r
- {0xbc, MathOperation}, // V\r
- {0xbd, MathOperation}, // V\r
- {0xbe, MathOperation}, // V\r
- {0xbf, MathOperation}, // V\r
-\r
- {0x40, LdRegReg}, // V\r
- {0x41, LdRegReg}, // V\r
- {0x42, LdRegReg}, // V\r
- {0x43, LdRegReg}, // V\r
- {0x44, LdRegReg}, // V\r
- {0x45, LdRegReg}, // V\r
- {0x47, LdRegReg}, // V\r
- {0x48, LdRegReg}, // V\r
- {0x49, LdRegReg}, // V\r
- {0x4a, LdRegReg}, // V\r
- {0x4b, LdRegReg}, // V\r
- {0x4c, LdRegReg}, // V\r
- {0x4d, LdRegReg}, // V\r
- {0x4f, LdRegReg}, // V\r
- {0x50, LdRegReg}, // V\r
- {0x51, LdRegReg}, // V\r
- {0x52, LdRegReg}, // V\r
- {0x53, LdRegReg}, // V\r
- {0x54, LdRegReg}, // V\r
- {0x55, LdRegReg}, // V\r
- {0x57, LdRegReg}, // V\r
- {0x58, LdRegReg}, // V\r
- {0x59, LdRegReg}, // V\r
- {0x5a, LdRegReg}, // V\r
- {0x5b, LdRegReg}, // V\r
- {0x5c, LdRegReg}, // V\r
- {0x5d, LdRegReg}, // V\r
- {0x5f, LdRegReg}, // V\r
- {0x60, LdRegReg}, // V\r
- {0x61, LdRegReg}, // V\r
- {0x62, LdRegReg}, // V\r
- {0x63, LdRegReg}, // V\r
- {0x64, LdRegReg}, // V\r
- {0x65, LdRegReg}, // V\r
- {0x67, LdRegReg}, // V\r
- {0x68, LdRegReg}, // V\r
- {0x69, LdRegReg}, // V\r
- {0x6a, LdRegReg}, // V\r
- {0x6b, LdRegReg}, // V\r
- {0x6c, LdRegReg}, // V\r
- {0x6d, LdRegReg}, // V\r
- {0x6f, LdRegReg}, // V\r
- {0x78, LdRegReg}, // V\r
- {0x79, LdRegReg}, // V\r
- {0x7a, LdRegReg}, // V\r
- {0x7b, LdRegReg}, // V\r
- {0x7c, LdRegReg}, // V\r
- {0x7d, LdRegReg}, // V\r
- {0x7f, LdRegReg}, // V\r
-\r
- {0xc6, MathOperationDirect}, // V\r
- {0xce, MathOperationDirect}, // V\r
- {0xd6, MathOperationDirect}, // V\r
- {0xde, MathOperationDirect}, // V\r
- {0xe6, MathOperationDirect}, // V\r
- {0xee, MathOperationDirect}, // V\r
- {0xf6, MathOperationDirect}, // V\r
- {0xfe, MathOperationDirect}, // V\r
-\r
- {0x18, JrHandler}, // V\r
- {0x20, JrHandler}, // V\r
- {0x28, JrHandler}, // V\r
- {0x30, JrHandler}, // V\r
- {0x38, JrHandler},\r
-\r
- {0xc4, CallHandler}, // V\r
- {0xcc, CallHandler}, // V\r
- {0xcd, CallHandler}, // V\r
- {0xd4, CallHandler}, // V\r
- {0xdc, CallHandler}, // V\r
- {0xe4, CallHandler}, // V\r
- {0xec, CallHandler}, // V\r
- {0xf4, CallHandler}, // V\r
- {0xfc, CallHandler}, // V\r
-\r
- {0xc9, RetHandler}, // V\r
- {0xc0, RetHandler}, // V\r
- {0xc8, RetHandler}, // V\r
- {0xd0, RetHandler}, // V\r
- {0xd8, RetHandler}, // V\r
- {0xe0, RetHandler}, // V\r
- {0xe8, RetHandler}, // V\r
- {0xf0, RetHandler}, // V\r
- {0xf8, RetHandler}, // V\r
-\r
- {0xc7, RestartHandler}, // V\r
- {0xcf, RestartHandler}, // V\r
- {0xd7, RestartHandler}, // V\r
- {0xdf, RestartHandler}, // V\r
- {0xe7, RestartHandler}, // V\r
- {0xef, RestartHandler}, // V\r
- {0xf7, RestartHandler}, // V\r
- {0xff, RestartHandler}, // V\r
-\r
- {0x46, ToRegFromHl}, // V\r
- {0x4e, ToRegFromHl}, // V\r
- {0x56, ToRegFromHl}, // V\r
- {0x5e, ToRegFromHl}, // V\r
- {0x66, ToRegFromHl}, // V\r
- {0x6e, ToRegFromHl}, // V\r
- {0x7e, ToRegFromHl},\r
-\r
- {0x09, AddRegpairOperations}, // V\r
- {0x19, AddRegpairOperations}, // V\r
- {0x29, AddRegpairOperations}, // V\r
- {0x39, AddRegpairOperations}, // V\r
-\r
- {0xc5, PushPopOperations}, // V\r
- {0xd5, PushPopOperations}, // V\r
- {0xe5, PushPopOperations}, // V\r
- {0xf5, PushPopOperations}, // V\r
- {0xc1, PushPopOperations}, // V\r
- {0xd1, PushPopOperations}, // V\r
- {0xe1, PushPopOperations}, // V\r
- {0xf1, PushPopOperations}, // V\r
-\r
- // Terminator\r
-\r
- {0xffffffff, NULL} \r
-};\r
-\r
-struct sOp CBOps[] =\r
-{\r
- {0x00, RLCRRCRLRRSLASRASRLHandler},\r
- {0x01, RLCRRCRLRRSLASRASRLHandler},\r
- {0x02, RLCRRCRLRRSLASRASRLHandler},\r
- {0x03, RLCRRCRLRRSLASRASRLHandler},\r
- {0x04, RLCRRCRLRRSLASRASRLHandler},\r
- {0x05, RLCRRCRLRRSLASRASRLHandler},\r
- {0x06, RLCRRCRLRRSLASRASRLHandler},\r
- {0x07, RLCRRCRLRRSLASRASRLHandler},\r
- {0x08, RLCRRCRLRRSLASRASRLHandler},\r
- {0x09, RLCRRCRLRRSLASRASRLHandler},\r
- {0x0a, RLCRRCRLRRSLASRASRLHandler},\r
- {0x0b, RLCRRCRLRRSLASRASRLHandler},\r
- {0x0c, RLCRRCRLRRSLASRASRLHandler},\r
- {0x0d, RLCRRCRLRRSLASRASRLHandler},\r
- {0x0e, RLCRRCRLRRSLASRASRLHandler},\r
- {0x0f, RLCRRCRLRRSLASRASRLHandler},\r
-\r
- {0x10, RLCRRCRLRRSLASRASRLHandler},\r
- {0x11, RLCRRCRLRRSLASRASRLHandler},\r
- {0x12, RLCRRCRLRRSLASRASRLHandler},\r
- {0x13, RLCRRCRLRRSLASRASRLHandler},\r
- {0x14, RLCRRCRLRRSLASRASRLHandler},\r
- {0x15, RLCRRCRLRRSLASRASRLHandler},\r
- {0x16, RLCRRCRLRRSLASRASRLHandler},\r
- {0x17, RLCRRCRLRRSLASRASRLHandler},\r
- {0x18, RLCRRCRLRRSLASRASRLHandler},\r
- {0x19, RLCRRCRLRRSLASRASRLHandler},\r
- {0x1a, RLCRRCRLRRSLASRASRLHandler},\r
- {0x1b, RLCRRCRLRRSLASRASRLHandler},\r
- {0x1c, RLCRRCRLRRSLASRASRLHandler},\r
- {0x1d, RLCRRCRLRRSLASRASRLHandler},\r
- {0x1e, RLCRRCRLRRSLASRASRLHandler},\r
- {0x1f, RLCRRCRLRRSLASRASRLHandler},\r
-\r
- {0x20, RLCRRCRLRRSLASRASRLHandler},\r
- {0x21, RLCRRCRLRRSLASRASRLHandler},\r
- {0x22, RLCRRCRLRRSLASRASRLHandler},\r
- {0x23, RLCRRCRLRRSLASRASRLHandler},\r
- {0x24, RLCRRCRLRRSLASRASRLHandler},\r
- {0x25, RLCRRCRLRRSLASRASRLHandler},\r
- {0x26, RLCRRCRLRRSLASRASRLHandler},\r
- {0x27, RLCRRCRLRRSLASRASRLHandler},\r
- {0x28, RLCRRCRLRRSLASRASRLHandler},\r
- {0x29, RLCRRCRLRRSLASRASRLHandler},\r
- {0x2a, RLCRRCRLRRSLASRASRLHandler},\r
- {0x2b, RLCRRCRLRRSLASRASRLHandler},\r
- {0x2c, RLCRRCRLRRSLASRASRLHandler},\r
- {0x2d, RLCRRCRLRRSLASRASRLHandler},\r
- {0x2e, RLCRRCRLRRSLASRASRLHandler},\r
- {0x2f, RLCRRCRLRRSLASRASRLHandler},\r
-\r
- {0x30, RLCRRCRLRRSLASRASRLHandler},\r
- {0x31, RLCRRCRLRRSLASRASRLHandler},\r
- {0x32, RLCRRCRLRRSLASRASRLHandler},\r
- {0x33, RLCRRCRLRRSLASRASRLHandler},\r
- {0x34, RLCRRCRLRRSLASRASRLHandler},\r
- {0x35, RLCRRCRLRRSLASRASRLHandler},\r
- {0x36, RLCRRCRLRRSLASRASRLHandler},\r
- {0x37, RLCRRCRLRRSLASRASRLHandler},\r
-\r
- {0x38, RLCRRCRLRRSLASRASRLHandler},\r
- {0x39, RLCRRCRLRRSLASRASRLHandler},\r
- {0x3a, RLCRRCRLRRSLASRASRLHandler},\r
- {0x3b, RLCRRCRLRRSLASRASRLHandler},\r
- {0x3c, RLCRRCRLRRSLASRASRLHandler},\r
- {0x3d, RLCRRCRLRRSLASRASRLHandler},\r
- {0x3e, RLCRRCRLRRSLASRASRLHandler},\r
- {0x3f, RLCRRCRLRRSLASRASRLHandler},\r
-\r
- {0x40, BITHandler},\r
- {0x41, BITHandler},\r
- {0x42, BITHandler},\r
- {0x43, BITHandler},\r
- {0x44, BITHandler},\r
- {0x45, BITHandler},\r
- {0x46, BITHandler},\r
- {0x47, BITHandler},\r
- {0x48, BITHandler},\r
- {0x49, BITHandler},\r
- {0x4a, BITHandler},\r
- {0x4b, BITHandler},\r
- {0x4c, BITHandler},\r
- {0x4d, BITHandler},\r
- {0x4e, BITHandler},\r
- {0x4f, BITHandler},\r
-\r
- {0x50, BITHandler},\r
- {0x51, BITHandler},\r
- {0x52, BITHandler},\r
- {0x53, BITHandler},\r
- {0x54, BITHandler},\r
- {0x55, BITHandler},\r
- {0x56, BITHandler},\r
- {0x57, BITHandler},\r
- {0x58, BITHandler},\r
- {0x59, BITHandler},\r
- {0x5a, BITHandler},\r
- {0x5b, BITHandler},\r
- {0x5c, BITHandler},\r
- {0x5d, BITHandler},\r
- {0x5e, BITHandler},\r
- {0x5f, BITHandler},\r
-\r
- {0x60, BITHandler},\r
- {0x61, BITHandler},\r
- {0x62, BITHandler},\r
- {0x63, BITHandler},\r
- {0x64, BITHandler},\r
- {0x65, BITHandler},\r
- {0x66, BITHandler},\r
- {0x67, BITHandler},\r
- {0x68, BITHandler},\r
- {0x69, BITHandler},\r
- {0x6a, BITHandler},\r
- {0x6b, BITHandler},\r
- {0x6c, BITHandler},\r
- {0x6d, BITHandler},\r
- {0x6e, BITHandler},\r
- {0x6f, BITHandler},\r
-\r
- {0x70, BITHandler},\r
- {0x71, BITHandler},\r
- {0x72, BITHandler},\r
- {0x73, BITHandler},\r
- {0x74, BITHandler},\r
- {0x75, BITHandler},\r
- {0x76, BITHandler},\r
- {0x77, BITHandler},\r
- {0x78, BITHandler},\r
- {0x79, BITHandler},\r
- {0x7a, BITHandler},\r
- {0x7b, BITHandler},\r
- {0x7c, BITHandler},\r
- {0x7d, BITHandler},\r
- {0x7e, BITHandler},\r
- {0x7f, BITHandler},\r
-\r
- // RES\r
-\r
- {0x80, RESSETHandler},\r
- {0x81, RESSETHandler},\r
- {0x82, RESSETHandler},\r
- {0x83, RESSETHandler},\r
- {0x84, RESSETHandler},\r
- {0x85, RESSETHandler},\r
- {0x86, RESSETHandler},\r
- {0x87, RESSETHandler},\r
- {0x88, RESSETHandler},\r
- {0x89, RESSETHandler},\r
- {0x8a, RESSETHandler},\r
- {0x8b, RESSETHandler},\r
- {0x8c, RESSETHandler},\r
- {0x8d, RESSETHandler},\r
- {0x8e, RESSETHandler},\r
- {0x8f, RESSETHandler},\r
-\r
- {0x90, RESSETHandler},\r
- {0x91, RESSETHandler},\r
- {0x92, RESSETHandler},\r
- {0x93, RESSETHandler},\r
- {0x94, RESSETHandler},\r
- {0x95, RESSETHandler},\r
- {0x96, RESSETHandler},\r
- {0x97, RESSETHandler},\r
- {0x98, RESSETHandler},\r
- {0x99, RESSETHandler},\r
- {0x9a, RESSETHandler},\r
- {0x9b, RESSETHandler},\r
- {0x9c, RESSETHandler},\r
- {0x9d, RESSETHandler},\r
- {0x9e, RESSETHandler},\r
- {0x9f, RESSETHandler},\r
-\r
- {0xa0, RESSETHandler},\r
- {0xa1, RESSETHandler},\r
- {0xa2, RESSETHandler},\r
- {0xa3, RESSETHandler},\r
- {0xa4, RESSETHandler},\r
- {0xa5, RESSETHandler},\r
- {0xa6, RESSETHandler},\r
- {0xa7, RESSETHandler},\r
- {0xa8, RESSETHandler},\r
- {0xa9, RESSETHandler},\r
- {0xaa, RESSETHandler},\r
- {0xab, RESSETHandler},\r
- {0xac, RESSETHandler},\r
- {0xad, RESSETHandler},\r
- {0xae, RESSETHandler},\r
- {0xaf, RESSETHandler},\r
-\r
- {0xb0, RESSETHandler},\r
- {0xb1, RESSETHandler},\r
- {0xb2, RESSETHandler},\r
- {0xb3, RESSETHandler},\r
- {0xb4, RESSETHandler},\r
- {0xb5, RESSETHandler},\r
- {0xb6, RESSETHandler},\r
- {0xb7, RESSETHandler},\r
- {0xb8, RESSETHandler},\r
- {0xb9, RESSETHandler},\r
- {0xba, RESSETHandler},\r
- {0xbb, RESSETHandler},\r
- {0xbc, RESSETHandler},\r
- {0xbd, RESSETHandler},\r
- {0xbe, RESSETHandler},\r
- {0xbf, RESSETHandler},\r
-\r
- // SET\r
-\r
- {0xc0, RESSETHandler},\r
- {0xc1, RESSETHandler},\r
- {0xc2, RESSETHandler},\r
- {0xc3, RESSETHandler},\r
- {0xc4, RESSETHandler},\r
- {0xc5, RESSETHandler},\r
- {0xc6, RESSETHandler},\r
- {0xc7, RESSETHandler},\r
- {0xc8, RESSETHandler},\r
- {0xc9, RESSETHandler},\r
- {0xca, RESSETHandler},\r
- {0xcb, RESSETHandler},\r
- {0xcc, RESSETHandler},\r
- {0xcd, RESSETHandler},\r
- {0xce, RESSETHandler},\r
- {0xcf, RESSETHandler},\r
-\r
- {0xd0, RESSETHandler},\r
- {0xd1, RESSETHandler},\r
- {0xd2, RESSETHandler},\r
- {0xd3, RESSETHandler},\r
- {0xd4, RESSETHandler},\r
- {0xd5, RESSETHandler},\r
- {0xd6, RESSETHandler},\r
- {0xd7, RESSETHandler},\r
- {0xd8, RESSETHandler},\r
- {0xd9, RESSETHandler},\r
- {0xda, RESSETHandler},\r
- {0xdb, RESSETHandler},\r
- {0xdc, RESSETHandler},\r
- {0xdd, RESSETHandler},\r
- {0xde, RESSETHandler},\r
- {0xdf, RESSETHandler},\r
-\r
- {0xe0, RESSETHandler},\r
- {0xe1, RESSETHandler},\r
- {0xe2, RESSETHandler},\r
- {0xe3, RESSETHandler},\r
- {0xe4, RESSETHandler},\r
- {0xe5, RESSETHandler},\r
- {0xe6, RESSETHandler},\r
- {0xe7, RESSETHandler},\r
- {0xe8, RESSETHandler},\r
- {0xe9, RESSETHandler},\r
- {0xea, RESSETHandler},\r
- {0xeb, RESSETHandler},\r
- {0xec, RESSETHandler},\r
- {0xed, RESSETHandler},\r
- {0xee, RESSETHandler},\r
- {0xef, RESSETHandler},\r
-\r
- {0xf0, RESSETHandler},\r
- {0xf1, RESSETHandler},\r
- {0xf2, RESSETHandler},\r
- {0xf3, RESSETHandler},\r
- {0xf4, RESSETHandler},\r
- {0xf5, RESSETHandler},\r
- {0xf6, RESSETHandler},\r
- {0xf7, RESSETHandler},\r
- {0xf8, RESSETHandler},\r
- {0xf9, RESSETHandler},\r
- {0xfa, RESSETHandler},\r
- {0xfb, RESSETHandler},\r
- {0xfc, RESSETHandler},\r
- {0xfd, RESSETHandler},\r
- {0xfe, RESSETHandler},\r
- {0xff, RESSETHandler},\r
-\r
- // Terminator\r
-\r
- {0xffffffff, NULL} \r
-};\r
-\r
-struct sOp EDOps[] =\r
-{\r
- {0x67, RRDRLDHandler},\r
- {0x6f, RRDRLDHandler},\r
- {0x42, AdcSbcRegpair},\r
- {0x4a, AdcSbcRegpair},\r
- {0x52, AdcSbcRegpair},\r
- {0x5a, AdcSbcRegpair},\r
- {0x62, AdcSbcRegpair},\r
- {0x6a, AdcSbcRegpair},\r
- {0x72, AdcSbcRegpair},\r
- {0x7a, AdcSbcRegpair}, \r
- {0x45, RetIRetNHandler},\r
- {0x4d, RetIRetNHandler},\r
- {0x44, NegHandler},\r
- {0xa0, LDILDRLDIRLDDRHandler},\r
- {0xa8, LDILDRLDIRLDDRHandler},\r
- {0xb0, LDILDRLDIRLDDRHandler},\r
- {0xb8, LDILDRLDIRLDDRHandler},\r
- {0x57, IRHandler},\r
- {0x5F, IRHandler},\r
- {0x47, IRHandler},\r
- {0x4F, IRHandler},\r
- {0x46, IMHandler},\r
- {0x56, IMHandler},\r
- {0x5e, IMHandler},\r
- {0x4b, LdRegpair},\r
- {0x5b, LdRegpair},\r
- {0x7b, LdRegpair},\r
- {0x43, ExtendedRegIntoMemory},\r
- {0x53, ExtendedRegIntoMemory},\r
- {0x63, ExtendedRegIntoMemory},\r
- {0x73, ExtendedRegIntoMemory},\r
- {0x40, ExtendedInHandler},\r
- {0x48, ExtendedInHandler},\r
- {0x50, ExtendedInHandler},\r
- {0x58, ExtendedInHandler},\r
- {0x60, ExtendedInHandler},\r
- {0x68, ExtendedInHandler},\r
- {0x78, ExtendedInHandler},\r
- {0x41, ExtendedOutHandler},\r
- {0x49, ExtendedOutHandler},\r
- {0x51, ExtendedOutHandler},\r
- {0x59, ExtendedOutHandler},\r
- {0x61, ExtendedOutHandler},\r
- {0x69, ExtendedOutHandler},\r
- {0x79, ExtendedOutHandler}, \r
- {0xa1, CPICPDCPIRCPDRHandler},\r
- {0xa9, CPICPDCPIRCPDRHandler},\r
- {0xb1, CPICPDCPIRCPDRHandler},\r
- {0xb9, CPICPDCPIRCPDRHandler},\r
-\r
- {0xbb, OTIROTDROUTIOUTDHandler}, // OTDR\r
- {0xb3, OTIROTDROUTIOUTDHandler}, // OTIR\r
- {0xab, OTIROTDROUTIOUTDHandler}, // OUTD\r
- {0xa3, OTIROTDROUTIOUTDHandler}, // OUTI\r
-\r
- {0xb2, INIRINDRINIINDHandler}, // INIR\r
- {0xba, INIRINDRINIINDHandler}, // INDR\r
- {0xa2, INIRINDRINIINDHandler}, // INI\r
- {0xaa, INIRINDRINIINDHandler}, // IND\r
-\r
- // Terminator\r
-\r
- {0xffffffff, NULL} \r
-};\r
-\r
-struct sOp DDFDOps[] =\r
-{\r
- {0x35, IncDecIndexed},\r
- {0x34, IncDecIndexed},\r
- {0xcb, DDFDCBHandler},\r
- {0x86, MathOperationIndexed},\r
- {0x8e, MathOperationIndexed},\r
- {0x96, MathOperationIndexed},\r
- {0x9e, MathOperationIndexed},\r
- {0xa6, MathOperationIndexed},\r
- {0xae, MathOperationIndexed},\r
- {0xb6, MathOperationIndexed},\r
- {0xbe, MathOperationIndexed},\r
-\r
- {0xe1, PushPopOperationsIndexed},\r
- {0xe5, PushPopOperationsIndexed},\r
- {0x21, LoadImmediate},\r
- {0xe9, JPIXIYHandler},\r
- {0x09, AddIndexHandler},\r
- {0x19, AddIndexHandler},\r
- {0x29, AddIndexHandler},\r
- {0x39, AddIndexHandler},\r
- {0xf9, SPToIndex},\r
- {0x36, LdByteToIndex},\r
- {0x46, LdRegIndexOffset},\r
- {0x4e, LdRegIndexOffset},\r
- {0x56, LdRegIndexOffset},\r
- {0x5e, LdRegIndexOffset},\r
- {0x66, LdRegIndexOffset},\r
- {0x6e, LdRegIndexOffset},\r
- {0x7e, LdRegIndexOffset}, \r
-\r
- {0x70, LdIndexPtrReg},\r
- {0x71, LdIndexPtrReg},\r
- {0x72, LdIndexPtrReg},\r
- {0x73, LdIndexPtrReg},\r
- {0x74, LdIndexPtrReg},\r
- {0x75, LdIndexPtrReg},\r
- {0x77, LdIndexPtrReg},\r
-\r
- {0x23, IncDecIndexReg},\r
- {0x2b, IncDecIndexReg},\r
-\r
- {0x22, StoreIndexReg},\r
- {0x2a, LoadIndexReg},\r
- {0xe3, ExIndexed},\r
-\r
- {0x44, UndocRegToIndex},\r
- {0x45, UndocRegToIndex},\r
- {0x4c, UndocRegToIndex},\r
- {0x4d, UndocRegToIndex},\r
- {0x54, UndocRegToIndex},\r
- {0x55, UndocRegToIndex},\r
- {0x5c, UndocRegToIndex},\r
- {0x5d, UndocRegToIndex},\r
- {0x7c, UndocRegToIndex},\r
- {0x7d, UndocRegToIndex},\r
-\r
- {0x60, UndocIndexToReg},\r
- {0x61, UndocIndexToReg},\r
- {0x62, UndocIndexToReg},\r
- {0x63, UndocIndexToReg},\r
- {0x64, UndocIndexToReg},\r
- {0x65, UndocIndexToReg},\r
- {0x67, UndocIndexToReg},\r
- {0x68, UndocIndexToReg},\r
- {0x69, UndocIndexToReg},\r
- {0x6a, UndocIndexToReg},\r
- {0x6b, UndocIndexToReg},\r
- {0x6c, UndocIndexToReg},\r
- {0x6d, UndocIndexToReg},\r
- {0x6f, UndocIndexToReg},\r
-\r
- {0x24, UndocIncDecIndexReg},\r
- {0x25, UndocIncDecIndexReg},\r
- {0x2c, UndocIncDecIndexReg},\r
- {0x2d, UndocIncDecIndexReg},\r
-\r
- {0x26, UndocLoadHalfIndexReg},\r
- {0x2e, UndocLoadHalfIndexReg},\r
-\r
- {0x84, UndocMathIndex},\r
- {0x85, UndocMathIndex},\r
- {0x8c, UndocMathIndex},\r
- {0x8d, UndocMathIndex},\r
-\r
- {0x94, UndocMathIndex},\r
- {0x95, UndocMathIndex},\r
- {0x9c, UndocMathIndex},\r
- {0x9d, UndocMathIndex},\r
-\r
- {0xa4, UndocMathIndex},\r
- {0xa5, UndocMathIndex},\r
- {0xac, UndocMathIndex},\r
- {0xad, UndocMathIndex},\r
-\r
- {0xb4, UndocMathIndex},\r
- {0xb5, UndocMathIndex},\r
- {0xbc, UndocMathIndex},\r
- {0xbd, UndocMathIndex},\r
-\r
- // Terminator\r
-\r
- {0xffffffff, NULL}\r
-};\r
-\r
-struct sOp DDFDCBOps[] =\r
-{\r
- {0x06, ddcbBitWise},\r
- {0x0e, ddcbBitWise},\r
- {0x16, ddcbBitWise},\r
- {0x1e, ddcbBitWise},\r
- {0x26, ddcbBitWise},\r
- {0x2e, ddcbBitWise},\r
- {0x3e, ddcbBitWise},\r
- {0x46, ddcbBitWise},\r
- {0x4e, ddcbBitWise},\r
- {0x56, ddcbBitWise},\r
- {0x5e, ddcbBitWise},\r
- {0x66, ddcbBitWise},\r
- {0x6e, ddcbBitWise},\r
- {0x76, ddcbBitWise},\r
- {0x7e, ddcbBitWise},\r
- {0x86, ddcbBitWise},\r
- {0x8e, ddcbBitWise},\r
- {0x96, ddcbBitWise},\r
- {0x9e, ddcbBitWise},\r
- {0xa6, ddcbBitWise},\r
- {0xae, ddcbBitWise},\r
- {0xb6, ddcbBitWise},\r
- {0xbe, ddcbBitWise},\r
- {0xc6, ddcbBitWise},\r
- {0xce, ddcbBitWise},\r
- {0xd6, ddcbBitWise},\r
- {0xde, ddcbBitWise},\r
- {0xe6, ddcbBitWise},\r
- {0xee, ddcbBitWise},\r
- {0xf6, ddcbBitWise},\r
- {0xfe, ddcbBitWise},\r
-\r
- // Terminator\r
-\r
- {0xffffffff, NULL}\r
-};\r
-\r
-void InvalidInstructionC(UINT32 dwCount)\r
-{\r
- fprintf(fp, " InvalidInstruction(%ld);\n", dwCount);\r
-}\r
-\r
-UINT32 Timing(UINT8 bWho, UINT32 dwOpcode)\r
-{\r
- UINT32 dwTiming = 0;\r
-\r
- assert(dwOpcode < 0x100);\r
-\r
- if (TIMING_REGULAR == bWho) // Regular?\r
- dwTiming = bTimingRegular[dwOpcode];\r
- else\r
- if (TIMING_CB == bWho)\r
- dwTiming = bTimingCB[dwOpcode];\r
- else\r
- if (TIMING_DDFD == bWho)\r
- dwTiming = bTimingDDFD[dwOpcode];\r
- else\r
- if (TIMING_ED == bWho)\r
- dwTiming = bTimingED[dwOpcode];\r
- else\r
- if (TIMING_XXCB == bWho)\r
- dwTiming = bTimingXXCB[dwOpcode];\r
- else\r
- if (TIMING_EXCEPT == bWho)\r
- dwTiming = dwOpcode;\r
- else\r
- assert(0);\r
-\r
- if (0 == dwTiming)\r
- { \r
- fprintf(stderr, "Opcode: %.2x:%.2x - Not zero!\n", bWho, dwOpcode);\r
- fclose(fp);\r
- exit(1);\r
- }\r
-\r
- return(dwTiming);\r
-}\r
-\r
-void IndexedOffset(UINT8 *Localmz80Index)\r
-{\r
- fprintf(fp, " mov dl, [esi] ; Fetch our offset\n");\r
- fprintf(fp, " inc esi ; Move past the offset\n");\r
- fprintf(fp, " or dl, dl ; Is this bad boy signed?\n");\r
- fprintf(fp, " jns notSigned%ld ; Nope!\n", dwGlobalLabel);\r
- fprintf(fp, " dec dh ; Make it FFable\n");\r
- fprintf(fp, "notSigned%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " add dx, [_z80%s] ; Our offset!\n", Localmz80Index);\r
- ++dwGlobalLabel;\r
-}\r
-\r
-void CBHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, ";\n");\r
- fprintf(fp, "; Handler for all CBxx instructions\n");\r
- fprintf(fp, ";\n");\r
- sprintf(string, "RegInst%.2x", dwOpcode);\r
- ProcBegin(0xffffffff);\r
- fprintf(fp, " mov dl, [esi]\n");\r
- fprintf(fp, " inc esi\n");\r
- fprintf(fp, " jmp dword [z80PrefixCB+edx*4]\n\n");\r
- fprintf(fp, "\n\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " CBHandler();\n");\r
- }\r
- else\r
- {\r
- assert(0); \r
- }\r
-}\r
-\r
-void EDHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, ";\n");\r
- fprintf(fp, "; Handler for all EDxx instructions\n");\r
- fprintf(fp, ";\n");\r
- sprintf(string, "RegInst%.2x", dwOpcode);\r
- ProcBegin(0xffffffff);\r
- fprintf(fp, " mov dl, [esi]\n");\r
- fprintf(fp, " inc esi\n");\r
- fprintf(fp, " jmp dword [z80PrefixED+edx*4]\n\n");\r
- fprintf(fp, "\n\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " EDHandler();\n");\r
- }\r
- else\r
- {\r
- assert(0); \r
- }\r
-}\r
-\r
-void DDHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, ";\n");\r
- fprintf(fp, "; Handler for all DDxx instructions\n");\r
- fprintf(fp, ";\n");\r
- sprintf(string, "RegInst%.2x", dwOpcode);\r
- ProcBegin(0xffffffff);\r
- fprintf(fp, " mov dl, [esi]\n");\r
- fprintf(fp, " inc esi\n");\r
- fprintf(fp, " jmp dword [z80PrefixDD+edx*4]\n\n");\r
- fprintf(fp, "\n\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " DDHandler();\n");\r
- }\r
- else\r
- {\r
- assert(0); \r
- }\r
-}\r
-\r
-void FDHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, ";\n");\r
- fprintf(fp, "; Handler for all FDxx instructions\n");\r
- fprintf(fp, ";\n");\r
- sprintf(string, "RegInst%.2x", dwOpcode);\r
- ProcBegin(0xffffffff);\r
- fprintf(fp, " mov dl, [esi]\n");\r
- fprintf(fp, " inc esi\n");\r
- fprintf(fp, " jmp dword [z80PrefixFD+edx*4]\n\n");\r
- fprintf(fp, "\n\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " FDHandler();\n");\r
- }\r
- else\r
- {\r
- assert(0); \r
- }\r
-}\r
-\r
-StandardHeader()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp,"; For assembly by NASM only\n");\r
- fprintf(fp,"bits 32\n\n");\r
-\r
- fprintf(fp,"; Theory of operation\n\n");\r
- fprintf(fp,"; EDI=General purpose\n");\r
- fprintf(fp,"; ESI=Program counter + base address\n");\r
- fprintf(fp,"; EBP=z80Base\n");\r
- fprintf(fp,"; AX=AF\n");\r
- fprintf(fp,"; BX=HL\n");\r
- fprintf(fp,"; CX=BC\n");\r
- fprintf(fp,"; DX=General purpose\n\n"); \r
-\r
- if (bUseStack)\r
- fprintf(fp, "; Using stack calling conventions\n");\r
- else\r
- fprintf(fp, "; Using register calling conventions\n");\r
-\r
- if (b16BitIo)\r
- fprintf(fp, "; Extended input/output instructions treat (BC) as I/O address\n");\r
- else\r
- fprintf(fp, "; Extended input/output instructions treat (C) as I/O address\n\n");\r
-\r
- fprintf(fp, "IFF1 equ 01h\n");\r
- fprintf(fp, "IFF2 equ 02h\n");\r
-\r
- fprintf(fp, "CPUREG_PC equ 00h\n");\r
- fprintf(fp, "CPUREG_SP equ 01h\n");\r
- fprintf(fp, "CPUREG_AF equ 02h\n");\r
- fprintf(fp, "CPUREG_BC equ 03h\n");\r
- fprintf(fp, "CPUREG_DE equ 04h\n");\r
- fprintf(fp, "CPUREG_HL equ 05h\n");\r
- fprintf(fp, "CPUREG_AFPRIME equ 06h\n");\r
- fprintf(fp, "CPUREG_BCPRIME equ 07h\n");\r
- fprintf(fp, "CPUREG_DEPRIME equ 08h\n");\r
- fprintf(fp, "CPUREG_HLPRIME equ 09h\n");\r
- fprintf(fp, "CPUREG_IX equ 0ah\n");\r
- fprintf(fp, "CPUREG_IY equ 0bh\n");\r
- fprintf(fp, "CPUREG_I equ 0ch\n");\r
- fprintf(fp, "CPUREG_A equ 0dh\n");\r
- fprintf(fp, "CPUREG_F equ 0eh\n");\r
- fprintf(fp, "CPUREG_B equ 0fh\n");\r
- fprintf(fp, "CPUREG_C equ 10h\n");\r
- fprintf(fp, "CPUREG_D equ 11h\n");\r
- fprintf(fp, "CPUREG_E equ 12h\n");\r
- fprintf(fp, "CPUREG_H equ 13h\n");\r
- fprintf(fp, "CPUREG_L equ 14h\n");\r
- fprintf(fp, "CPUREG_IFF1 equ 15h\n");\r
- fprintf(fp, "CPUREG_IFF2 equ 16h\n");\r
- fprintf(fp, "CPUREG_CARRY equ 17h\n");\r
- fprintf(fp, "CPUREG_NEGATIVE equ 18h\n");\r
- fprintf(fp, "CPUREG_PARITY equ 19h\n");\r
- fprintf(fp, "CPUREG_OVERFLOW equ 1ah\n");\r
- fprintf(fp, "CPUREG_HALFCARRY equ 1bh\n");\r
- fprintf(fp, "CPUREG_ZERO equ 1ch\n");\r
- fprintf(fp, "CPUREG_SIGN equ 1dh\n");\r
- fprintf(fp, "CPUREG_MAXINDEX equ 1eh\n\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "/* Multi-Z80 32 Bit emulator */\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, "/* Copyright 1996-2000 Neil Bradley, All rights reserved\n");\r
- fprintf(fp, " *\n");\r
- fprintf(fp, " * License agreement:\n");\r
- fprintf(fp, " *\n");\r
- fprintf(fp, " * (MZ80 Refers to both the assembly code emitted by makeZ80.c and makeZ80.c\n");\r
- fprintf(fp, " * itself)\n");\r
- fprintf(fp, " *\n");\r
- fprintf(fp, " * MZ80 May be distributed in unmodified form to any medium.\n");\r
- fprintf(fp, " *\n");\r
- fprintf(fp, " * MZ80 May not be sold, or sold as a part of a commercial package without\n");\r
- fprintf(fp, " * the express written permission of Neil Bradley (neil@synthcom.com). This\n");\r
- fprintf(fp, " * includes shareware.\n");\r
- fprintf(fp, " *\n");\r
- fprintf(fp, " * Modified versions of MZ80 may not be publicly redistributed without author\n");\r
- fprintf(fp, " * approval (neil@synthcom.com). This includes distributing via a publicly\n");\r
- fprintf(fp, " * accessible LAN. You may make your own source modifications and distribute\n");\r
- fprintf(fp, " * MZ80 in source or object form, but if you make modifications to MZ80\n");\r
- fprintf(fp, " * then it should be noted in the top as a comment in makeZ80.c.\n");\r
- fprintf(fp, " *\n");\r
- fprintf(fp, " * MZ80 Licensing for commercial applications is available. Please email\n");\r
- fprintf(fp, " * neil@synthcom.com for details.\n");\r
- fprintf(fp, " *\n");\r
- fprintf(fp, " * Synthcom Systems, Inc, and Neil Bradley will not be held responsible for\n");\r
- fprintf(fp, " * any damage done by the use of MZ80. It is purely \"as-is\".\n");\r
- fprintf(fp, " *\n");\r
- fprintf(fp, " * If you use MZ80 in a freeware application, credit in the following text:\n");\r
- fprintf(fp, " *\n");\r
- fprintf(fp, " * \"Multi-Z80 CPU emulator by Neil Bradley (neil@synthcom.com)\"\n");\r
- fprintf(fp, " *\n");\r
- fprintf(fp, " * must accompany the freeware application within the application itself or\n");\r
- fprintf(fp, " * in the documentation.\n");\r
- fprintf(fp, " *\n");\r
- fprintf(fp, " * Legal stuff aside:\n");\r
- fprintf(fp, " *\n");\r
- fprintf(fp, " * If you find problems with MZ80, please email the author so they can get\n");\r
- fprintf(fp, " * resolved. If you find a bug and fix it, please also email the author so\n");\r
- fprintf(fp, " * that those bug fixes can be propogated to the installed base of MZ80\n");\r
- fprintf(fp, " * users. If you find performance improvements or problems with MZ80, please\n");\r
- fprintf(fp, " * email the author with your changes/suggestions and they will be rolled in\n");\r
- fprintf(fp, " * with subsequent releases of MZ80.\n");\r
- fprintf(fp, " *\n");\r
- fprintf(fp, " * The whole idea of this emulator is to have the fastest available 32 bit\n");\r
- fprintf(fp, " * Multi-Z80 emulator for the PC, giving maximum performance. \n");\r
- fprintf(fp, " */\n\n");\r
- fprintf(fp, "#include <stdio.h>\n");\r
- fprintf(fp, "#include <stdlib.h>\n");\r
- fprintf(fp, "#include <string.h>\n");\r
- fprintf(fp, "#include \"mz80.h\"\n");\r
-\r
- // HACK HACK\r
-\r
- fprintf(fp, "UINT32 z80intAddr;\n");\r
- fprintf(fp, "UINT32 z80pc;\n");\r
- } \r
- else\r
- {\r
- // Whoops. Unknown emission type.\r
-\r
- assert(0);\r
- }\r
-\r
- fprintf(fp, "\n\n");\r
-}\r
-\r
-Alignment()\r
-{\r
- fprintf(fp, "\ntimes ($$-$) & 3 nop ; pad with NOPs to 4-byte boundary\n\n");\r
-}\r
-\r
-void ProcBegin(UINT32 dwOpcode)\r
-{\r
- Alignment();\r
- fprintf(fp, "%s:\n", procname);\r
-}\r
-\r
-void SetSubFlagsSZHVC(UINT8 *pszLeft, UINT8 *pszRight)\r
-{\r
- fprintf(fp, " cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | \n");\r
- fprintf(fp, " Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |\n");\r
- fprintf(fp, " pbSubSbcTable[((UINT32) %s << 8) | %s];\n", pszLeft, pszRight);\r
-}\r
-\r
-void SetSbcFlagsSZHVC(UINT8 *pszLeft, UINT8 *pszRight)\r
-{\r
- fprintf(fp, " cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | \n");\r
- fprintf(fp, " Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |\n");\r
- fprintf(fp, " pbSubSbcTable[((UINT32) %s << 8) | %s | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];\n", pszLeft, pszRight);\r
-}\r
-\r
-void SetAddFlagsSZHVC(UINT8 *pszLeft, UINT8 *pszRight)\r
-{\r
- fprintf(fp, " cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | \n");\r
- fprintf(fp, " Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |\n");\r
- fprintf(fp, " pbAddAdcTable[((UINT32) %s << 8) | %s];\n", pszLeft, pszRight);\r
-}\r
-\r
-void SetAdcFlagsSZHVC(UINT8 *pszLeft, UINT8 *pszRight)\r
-{\r
- fprintf(fp, " cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | \n");\r
- fprintf(fp, " Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN)) |\n");\r
- fprintf(fp, " pbAddAdcTable[((UINT32) %s << 8) | %s | (((UINT32) cpu.z80F & Z80_FLAG_CARRY) << 16)];\n", pszLeft, pszRight);\r
-}\r
-\r
-UINT32 dwOverflowCount = 0;\r
-\r
-SetOverflow()\r
-{\r
- fprintf(fp, " seto dl\n");\r
- fprintf(fp, " and ah, 0fbh ; Knock out parity/overflow\n");\r
- fprintf(fp, " shl dl, 2\n");\r
- fprintf(fp, " or ah, dl\n");\r
-}\r
- \r
-void FetchNextInstruction(UINT32 dwOpcode)\r
-{\r
- if (0xffffffff != dwOpcode)\r
- {\r
- fprintf(fp, " sub edi, byte %ld\n", Timing(bCurrentMode, dwOpcode));\r
- \r
- if (bCurrentMode == TIMING_REGULAR)\r
- fprintf(fp, " js near noMoreExec\n");\r
- else\r
- fprintf(fp, " js near noMoreExec\n");\r
- }\r
-\r
- fprintf(fp, " mov dl, byte [esi] ; Get our next instruction\n");\r
- fprintf(fp, " inc esi ; Increment PC\n");\r
- fprintf(fp, " jmp dword [z80regular+edx*4]\n\n");\r
-}\r
-\r
-void WriteValueToMemory(UINT8 *pszAddress, UINT8 *pszValue)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " mov [cyclesRemaining], edi\n");\r
- fprintf(fp, " mov [_z80af], ax ; Store AF\n");\r
-\r
- // First off, load our byte to write into al after we've saved AF\r
-\r
- if (strcmp(pszValue, "al") != 0)\r
- fprintf(fp, " mov al, %s ; And our data to write\n", pszValue);\r
- if (strcmp(pszValue, "[esi]") == 0) // Immediate value?\r
- fprintf(fp, " inc esi ; Increment our program counter\n");\r
-\r
- // Now get the address in DX - regardless of what it is\r
-\r
- if (strcmp(pszAddress, "[_z80de]") == 0 ||\r
- strcmp(pszAddress, "[_orgval]") == 0 ||\r
- strcmp(pszAddress, "[_z80ix]") == 0 ||\r
- strcmp(pszAddress, "[_z80iy]") == 0)\r
- fprintf(fp, " mov dx, %s\n", pszAddress);\r
-\r
- fprintf(fp, " mov edi, [_z80MemWrite] ; Point to the write array\n\n", cpubasename);\r
- fprintf(fp, "checkLoop%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " cmp [edi], word 0ffffh ; End of our list?\n");\r
- fprintf(fp, " je memoryWrite%ld ; Yes - go write it!\n", dwGlobalLabel);\r
-\r
- if (strcmp(pszAddress, "[_z80de]") == 0 ||\r
- strcmp(pszAddress, "[_orgval]") == 0 ||\r
- strcmp(pszAddress, "[_z80ix]") == 0 ||\r
- strcmp(pszAddress, "[_z80iy]") == 0)\r
- fprintf(fp, " cmp dx, [edi] ; Are we smaller?\n", pszAddress);\r
- else\r
- fprintf(fp, " cmp %s, [edi] ; Are we smaller?\n", pszAddress);\r
-\r
- fprintf(fp, " jb nextAddr%ld ; Yes... go to the next addr\n", dwGlobalLabel);\r
-\r
- if (strcmp(pszAddress, "[_z80de]") == 0 ||\r
- strcmp(pszAddress, "[_orgval]") == 0 ||\r
- strcmp(pszAddress, "[_z80ix]") == 0 ||\r
- strcmp(pszAddress, "[_z80iy]") == 0)\r
- fprintf(fp, " cmp dx, [edi+4] ; Are we smaller?\n", pszAddress);\r
- else\r
- fprintf(fp, " cmp %s, [edi+4] ; Are we smaller?\n", pszAddress);\r
- \r
- fprintf(fp, " jbe callRoutine%ld ; If not, go call it!\n\n", dwGlobalLabel);\r
- fprintf(fp, "nextAddr%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " add edi, 10h ; Next structure, please\n");\r
- fprintf(fp, " jmp short checkLoop%ld\n\n", dwGlobalLabel);\r
- fprintf(fp, "callRoutine%ld:\n", dwGlobalLabel);\r
- \r
- // Save off our registers!\r
- \r
- if ((strcmp(pszAddress, "dx") != 0) && (strcmp(pszAddress, "[_z80de]") != 0) &&\r
- (strcmp(pszAddress, "[_z80ix]") != 0) &&\r
- (strcmp(pszAddress, "[_orgval]") != 0) &&\r
- (strcmp(pszAddress, "[_z80iy]") != 0))\r
- fprintf(fp, " mov dx, %s ; Get our address to target\n", pszAddress);\r
- \r
- fprintf(fp, " call WriteMemoryByte ; Go write the data!\n");\r
- fprintf(fp, " jmp short WriteMacroExit%ld\n", dwGlobalLabel);\r
- \r
- fprintf(fp, "memoryWrite%ld:\n", dwGlobalLabel);\r
- \r
- if (strcmp(pszValue, "[esi]") == 0)\r
- fprintf(fp, " mov [ebp + e%s], al ; Store our direct value\n", pszAddress);\r
- else\r
- {\r
- if (pszValue[0] == 'b' && pszValue[1] == 'y' && pszValue[2] == 't')\r
- {\r
- fprintf(fp, " mov edi, edx\n");\r
- assert(strcmp(pszValue, "dl") != 0);\r
- \r
- fprintf(fp, " mov dl, %s\n", pszValue);\r
- \r
- if (strcmp(pszAddress, "dx") == 0)\r
- fprintf(fp, " mov [ebp + edi], dl\n");\r
- else\r
- fprintf(fp, " mov [ebp + e%s], dl\n", pszAddress);\r
- \r
- fprintf(fp, " mov edx, edi\n");\r
- }\r
- else\r
- {\r
- if (strcmp(pszAddress, "[_z80de]") != 0 &&\r
- strcmp(pszAddress, "[_orgval]") != 0 &&\r
- strcmp(pszAddress, "[_z80ix]") != 0 &&\r
- strcmp(pszAddress, "[_z80iy]") != 0)\r
- fprintf(fp, " mov [ebp + e%s], %s\n", pszAddress, pszValue);\r
- else\r
- fprintf(fp, " mov [ebp + edx], al\n");\r
- }\r
- }\r
-\r
- fprintf(fp, " mov ax, [_z80af] ; Get our accumulator and flags\n");\r
- \r
- fprintf(fp, "WriteMacroExit%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " mov edi, [cyclesRemaining]\n");\r
-\r
- ++dwGlobalLabel;\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */\n");\r
- fprintf(fp, " while (psMemWrite->lowAddr != 0xffffffff)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " if ((%s >= psMemWrite->lowAddr) && (%s <= psMemWrite->highAddr))\n", pszAddress, pszAddress);\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;\n");\r
- fprintf(fp, " if (psMemWrite->memoryCall)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " psMemWrite->memoryCall(%s, %s, psMemWrite);\n", pszAddress, pszValue);\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " else\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " *((UINT8 *) psMemWrite->pUserArea + (%s - psMemWrite->lowAddr)) = %s;\n", pszAddress, pszValue);\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " psMemWrite = NULL;\n");\r
- fprintf(fp, " break;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " ++psMemWrite;\n");\r
- fprintf(fp, " }\n\n");\r
- fprintf(fp, " if (psMemWrite)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80Base[%s] = (UINT8) %s;\n", pszAddress, pszValue);\r
- fprintf(fp, " }\n\n");\r
- }\r
-}\r
-\r
-void WriteWordToMemory(UINT8 *pszAddress, UINT8 *pszTarget)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " mov [cyclesRemaining], edi\n");\r
- fprintf(fp, " mov edi, [_z80MemWrite] ; Point to the write array\n\n", cpubasename);\r
- fprintf(fp, "checkLoop%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " cmp [edi], word 0ffffh ; End of the list?\n");\r
- fprintf(fp, " je memoryWrite%ld\n", dwGlobalLabel);\r
- fprintf(fp, " cmp %s, [edi] ; Are we smaller?\n", pszAddress);\r
- fprintf(fp, " jb nextAddr%ld ; Yes, go to the next address\n", dwGlobalLabel);\r
- fprintf(fp, " cmp %s, [edi+4] ; Are we bigger?\n", pszAddress);\r
- fprintf(fp, " jbe callRoutine%ld\n\n", dwGlobalLabel);\r
- fprintf(fp, "nextAddr%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " add edi, 10h ; Next structure!\n");\r
- fprintf(fp, " jmp short checkLoop%ld\n\n", dwGlobalLabel);\r
- fprintf(fp, "callRoutine%ld:\n", dwGlobalLabel);\r
-\r
- fprintf(fp, " push ax ; Save this for later\n");\r
-\r
- // Write the LSB\r
-\r
- fprintf(fp, " push dx\n");\r
-\r
- if (strcmp(pszTarget, "ax") != 0)\r
- {\r
- fprintf(fp, " mov ax, %s\n", pszTarget);\r
- }\r
- else\r
- {\r
- fprintf(fp, " xchg ah, al\n");\r
- }\r
-\r
- fprintf(fp, " call WriteMemoryByte\n");\r
- fprintf(fp, " pop dx\n");\r
- fprintf(fp, " pop ax\n");\r
- fprintf(fp, " inc dx\n\n");\r
-\r
- fprintf(fp, " push ax\n");\r
- fprintf(fp, " push dx\n");\r
-\r
- if (strcmp(pszTarget, "ax") != 0)\r
- {\r
- fprintf(fp, " mov ax, %s\n", pszTarget);\r
- fprintf(fp, " xchg ah, al\n");\r
- }\r
-\r
- fprintf(fp, " call WriteMemoryByte\n");\r
- fprintf(fp, " pop dx\n");\r
- fprintf(fp, " pop ax ; Restore us!\n");\r
-\r
- fprintf(fp, " jmp writeExit%ld\n\n", dwGlobalLabel);\r
-\r
- fprintf(fp, "memoryWrite%ld:\n", dwGlobalLabel);\r
-\r
- if (strlen(pszTarget) != 2)\r
- {\r
- fprintf(fp, " mov di, %s\n", pszTarget);\r
- fprintf(fp, " mov [ebp + e%s], di ; Store our word\n", pszAddress);\r
- }\r
- else\r
- {\r
- if (strcmp(pszTarget, "ax") != 0)\r
- {\r
- fprintf(fp, " mov [ebp + e%s], %s ; Store our word\n", pszAddress, pszTarget);\r
- }\r
- else\r
- {\r
- fprintf(fp, " xchg ah, al ; Swap for later\n");\r
- fprintf(fp, " mov [ebp + e%s], %s ; Store our word\n", pszAddress, pszTarget);\r
- fprintf(fp, " xchg ah, al ; Restore\n");\r
- }\r
- }\r
- \r
- fprintf(fp, "writeExit%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " mov edi, [cyclesRemaining]\n");\r
- \r
- dwGlobalLabel++;\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */\n");\r
- fprintf(fp, " while (psMemWrite->lowAddr != 0xffffffff)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " if ((%s >= psMemWrite->lowAddr) && (%s <= psMemWrite->highAddr))\n", pszAddress, pszAddress);\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;\n");\r
-\r
- fprintf(fp, " if (psMemWrite->memoryCall)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " psMemWrite->memoryCall(%s, (%s & 0xff), psMemWrite);\n", pszAddress, pszTarget);\r
- fprintf(fp, " psMemWrite->memoryCall(%s + 1, (%s >> 8), psMemWrite);\n", pszAddress, pszTarget);\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " else\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " *((UINT8 *) psMemWrite->pUserArea + (%s - psMemWrite->lowAddr)) = %s;\n", pszAddress, pszTarget);\r
- fprintf(fp, " *((UINT8 *) psMemWrite->pUserArea + (%s - psMemWrite->lowAddr) + 1) = %s >> 8;\n", pszAddress, pszTarget);\r
- fprintf(fp, " }\n");\r
-\r
- fprintf(fp, " psMemWrite = NULL;\n");\r
- fprintf(fp, " break;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " ++psMemWrite;\n");\r
- fprintf(fp, " }\n\n");\r
- fprintf(fp, " if (psMemWrite)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80Base[%s] = (UINT8) %s;\n", pszAddress, pszTarget);\r
- fprintf(fp, " cpu.z80Base[%s + 1] = (UINT8) ((UINT32) %s >> 8);\n", pszAddress, pszTarget);\r
- fprintf(fp, " }\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void WriteValueToIo(UINT8 *pszIoAddress, UINT8 *pszValue)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " mov [cyclesRemaining], edi\n");\r
- fprintf(fp, " mov [_z80af], ax ; Store AF\n");\r
-\r
- if (strcmp(pszValue, "al") != 0)\r
- fprintf(fp, " mov al, %s ; And our data to write\n", pszValue);\r
- if (strcmp(pszValue, "[esi]") == 0) // Immediate value?\r
- fprintf(fp, " inc esi ; Increment our program counter\n");\r
-\r
- fprintf(fp, " mov edi, [_z80IoWrite] ; Point to the I/O write array\n\n", cpubasename);\r
- fprintf(fp, "checkLoop%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " cmp [edi], word 0ffffh ; End of our list?\n");\r
- fprintf(fp, " je WriteMacroExit%ld ; Yes - ignore it!\n", dwGlobalLabel);\r
- fprintf(fp, " cmp %s, [edi] ; Are we smaller?\n", pszIoAddress);\r
- fprintf(fp, " jb nextAddr%ld ; Yes... go to the next addr\n", dwGlobalLabel);\r
- fprintf(fp, " cmp %s, [edi+2] ; Are we bigger?\n", pszIoAddress);\r
- fprintf(fp, " jbe callRoutine%ld ; If not, go call it!\n\n", dwGlobalLabel);\r
- fprintf(fp, "nextAddr%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " add edi, 0ch ; Next structure, please\n");\r
- fprintf(fp, " jmp short checkLoop%ld\n\n", dwGlobalLabel);\r
- fprintf(fp, "callRoutine%ld:\n", dwGlobalLabel);\r
-\r
- // Save off our registers!\r
-\r
- if (strcmp(pszIoAddress, "dx") != 0)\r
- fprintf(fp, " mov dx, %s ; Get our address to target\n", pszIoAddress);\r
-\r
- fprintf(fp, " call WriteIOByte ; Go write the data!\n");\r
- \r
- fprintf(fp, "WriteMacroExit%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " mov edi, [cyclesRemaining]\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " psIoWrite = cpu.z80IoWrite; /* Beginning of our handler */\n");\r
- fprintf(fp, " while (psIoWrite->lowIoAddr != 0xffff)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " if ((%s >= psIoWrite->lowIoAddr) && (%s <= psIoWrite->highIoAddr))\n", pszIoAddress, pszIoAddress);\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;\n");\r
- fprintf(fp, " psIoWrite->IOCall(%s, %s, psIoWrite);\n", pszIoAddress, pszValue);\r
- fprintf(fp, " psIoWrite = NULL;\n");\r
- fprintf(fp, " break;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " ++psIoWrite;\n");\r
- fprintf(fp, " }\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- } \r
- \r
- ++dwGlobalLabel;\r
-}\r
-\r
-void ReadValueFromMemory(UINT8 *pszAddress, UINT8 *pszTarget)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " mov [cyclesRemaining], edi\n");\r
- fprintf(fp, " mov edi, [_z80MemRead] ; Point to the read array\n\n", cpubasename);\r
- fprintf(fp, "checkLoop%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " cmp [edi], word 0ffffh ; End of the list?\n");\r
- fprintf(fp, " je memoryRead%ld\n", dwGlobalLabel);\r
- fprintf(fp, " cmp e%s, [edi] ; Are we smaller?\n", pszAddress);\r
- fprintf(fp, " jb nextAddr%ld ; Yes, go to the next address\n", dwGlobalLabel);\r
- fprintf(fp, " cmp e%s, [edi+4] ; Are we bigger?\n", pszAddress);\r
- fprintf(fp, " jbe callRoutine%ld\n\n", dwGlobalLabel);\r
- fprintf(fp, "nextAddr%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " add edi, 10h ; Next structure!\n");\r
- fprintf(fp, " jmp short checkLoop%ld\n\n", dwGlobalLabel);\r
- fprintf(fp, "callRoutine%ld:\n", dwGlobalLabel);\r
-\r
- if (strcmp(pszAddress, "dx") != 0)\r
- fprintf(fp, " mov dx, %s ; Get our address\n", pszAddress);\r
- \r
- fprintf(fp, " call ReadMemoryByte ; Standard read routine\n");\r
- \r
- // Yes, these are intentionally reversed!\r
- \r
- if (strcmp(pszTarget, "al") == 0)\r
- fprintf(fp, " mov [_z80af], al ; Save our new accumulator\n");\r
- else\r
- if (strcmp(pszTarget, "ah") == 0)\r
- fprintf(fp, " mov [_z80af + 1], al ; Save our new flags\n");\r
- else\r
- fprintf(fp, " mov %s, al ; Put our returned value here\n", pszTarget);\r
- \r
- // And are properly restored HERE:\r
- \r
- fprintf(fp, " mov ax, [_z80af] ; Get our AF back\n");\r
- \r
- // Restore registers here...\r
- \r
- fprintf(fp, " jmp short readExit%ld\n\n", dwGlobalLabel);\r
- fprintf(fp, "memoryRead%ld:\n", dwGlobalLabel);\r
- \r
- if (pszTarget[0] == 'b' && pszTarget[1] == 'y' && pszTarget[2] == 't')\r
- {\r
- fprintf(fp, " mov di, dx\n");\r
- fprintf(fp, " mov dl, [ebp + e%s]\n", pszAddress);\r
- fprintf(fp, " mov %s, dl\n", pszTarget);\r
- fprintf(fp, " mov dx, di\n");\r
- }\r
- else\r
- fprintf(fp, " mov %s, [ebp + e%s] ; Get our data\n\n", pszTarget, pszAddress);\r
- \r
- fprintf(fp, "readExit%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " mov edi, [cyclesRemaining]\n");\r
- \r
- dwGlobalLabel++;\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " psMemRead = cpu.z80MemRead; /* Beginning of our handler */\n");\r
- fprintf(fp, " while (psMemRead->lowAddr != 0xffffffff)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " if ((%s >= psMemRead->lowAddr) && (%s <= psMemRead->highAddr))\n", pszAddress, pszAddress);\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;\n");\r
- fprintf(fp, " if (psMemRead->memoryCall)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " %s = psMemRead->memoryCall(%s, psMemRead);\n", pszTarget, pszAddress);\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " else\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " %s = *((UINT8 *) psMemRead->pUserArea + (%s - psMemRead->lowAddr));\n", pszTarget, pszAddress);\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " psMemRead = NULL;\n");\r
- fprintf(fp, " break;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " ++psMemRead;\n");\r
- fprintf(fp, " }\n\n");\r
- fprintf(fp, " if (psMemRead)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " %s = cpu.z80Base[%s];\n", pszTarget, pszAddress);\r
- fprintf(fp, " }\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-\r
-void ReadWordFromMemory(UINT8 *pszAddress, UINT8 *pszTarget)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " mov [cyclesRemaining], edi\n");\r
- fprintf(fp, " mov edi, [_z80MemRead] ; Point to the read array\n\n", cpubasename);\r
- fprintf(fp, "checkLoop%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " cmp [edi], word 0ffffh ; End of the list?\n");\r
- fprintf(fp, " je memoryRead%ld\n", dwGlobalLabel);\r
- fprintf(fp, " cmp %s, [edi] ; Are we smaller?\n", pszAddress);\r
- fprintf(fp, " jb nextAddr%ld ; Yes, go to the next address\n", dwGlobalLabel);\r
- fprintf(fp, " cmp %s, [edi+4] ; Are we bigger?\n", pszAddress);\r
- fprintf(fp, " jbe callRoutine%ld\n\n", dwGlobalLabel);\r
- fprintf(fp, "nextAddr%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " add edi, 10h ; Next structure!\n");\r
- fprintf(fp, " jmp short checkLoop%ld\n\n", dwGlobalLabel);\r
- fprintf(fp, "callRoutine%ld:\n", dwGlobalLabel);\r
-\r
- if (strcmp(pszAddress, "dx") != 0)\r
- fprintf(fp, " mov dx, %s ; Get our address\n", pszAddress);\r
-\r
- if (strcmp(pszTarget, "ax") != 0)\r
- fprintf(fp, " push ax ; Save this for later\n");\r
-\r
- fprintf(fp, " push dx ; Save address\n");\r
- fprintf(fp, " call ReadMemoryByte ; Standard read routine\n");\r
- fprintf(fp, " pop dx ; Restore our address\n");\r
-\r
- fprintf(fp, " inc dx ; Next byte, please\n");\r
-\r
- fprintf(fp, " push ax ; Save returned byte\n");\r
- fprintf(fp, " call ReadMemoryByte ; Standard read routine\n");\r
- fprintf(fp, " xchg ah, al ; Swap for endian's sake\n");\r
- fprintf(fp, " pop dx ; Restore LSB\n");\r
-\r
- fprintf(fp, " mov dh, ah ; Our word is now in DX\n");\r
-\r
- // DX Now has our data and our address is toast\r
- \r
- if (strcmp(pszTarget, "ax") != 0)\r
- {\r
- fprintf(fp, " pop ax ; Restore this\n");\r
- \r
- if (strcmp(pszTarget, "dx") != 0)\r
- {\r
- fprintf(fp, " mov %s, dx ; Store our word\n", pszTarget);\r
- }\r
- }\r
- else\r
- fprintf(fp, " mov ax, dx\n");\r
-\r
- if (strcmp(pszTarget, "ax") == 0)\r
- {\r
- fprintf(fp, " xchg ah, al\n");\r
- }\r
- \r
- fprintf(fp, " jmp readExit%ld\n\n", dwGlobalLabel);\r
- \r
- fprintf(fp, "memoryRead%ld:\n", dwGlobalLabel);\r
- \r
- if (strlen(pszTarget) == 2)\r
- {\r
- fprintf(fp, " mov %s, [ebp + e%s]\n", pszTarget, pszAddress);\r
- if (strcmp(pszTarget, "ax") == 0)\r
- {\r
- fprintf(fp, " xchg ah, al\n");\r
- }\r
- }\r
- else\r
- {\r
- fprintf(fp, " mov dx, [ebp + e%s]\n", pszAddress);\r
- fprintf(fp, " mov %s, dx\n", pszTarget);\r
- }\r
- \r
- fprintf(fp, "readExit%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " mov edi, [cyclesRemaining]\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " psMemRead = cpu.z80MemRead; /* Beginning of our handler */\n");\r
- fprintf(fp, " while (psMemRead->lowAddr != 0xffffffff)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " if ((%s >= psMemRead->lowAddr) && (%s <= psMemRead->highAddr))\n", pszAddress, pszAddress);\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;\n");\r
- fprintf(fp, " if (psMemRead->memoryCall)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " %s = psMemRead->memoryCall(%s, psMemRead);\n", pszTarget, pszAddress);\r
- fprintf(fp, " %s |= (UINT32) ((UINT32) psMemRead->memoryCall(%s + 1, psMemRead) << 8);\n", pszTarget, pszAddress);\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " else\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " %s = *((UINT8 *) psMemRead->pUserArea + (%s - psMemRead->lowAddr));\n", pszTarget, pszAddress);\r
- fprintf(fp, " %s |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (%s - psMemRead->lowAddr + 1)) << 8);\n", pszTarget, pszAddress);\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " psMemRead = NULL;\n");\r
- fprintf(fp, " break;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " ++psMemRead;\n");\r
- fprintf(fp, " }\n\n");\r
- fprintf(fp, " if (psMemRead)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " %s = cpu.z80Base[%s];\n", pszTarget, pszAddress);\r
- fprintf(fp, " %s |= (UINT32) ((UINT32) cpu.z80Base[%s + 1] << 8);\n", pszTarget, pszAddress);\r
- fprintf(fp, " }\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-\r
- dwGlobalLabel++;\r
-}\r
-\r
-\r
-void ReadValueFromIo(UINT8 *pszIoAddress, UINT8 *pszTarget)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " mov [cyclesRemaining], edi\n");\r
- fprintf(fp, " mov edi, [_z80IoRead] ; Point to the read array\n\n", cpubasename);\r
- fprintf(fp, "checkLoop%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " cmp [edi], word 0ffffh ; End of the list?\n");\r
- fprintf(fp, " je ioRead%ld\n", dwGlobalLabel);\r
- fprintf(fp, " cmp %s, [edi] ; Are we smaller?\n", pszIoAddress);\r
- fprintf(fp, " jb nextAddr%ld ; Yes, go to the next address\n", dwGlobalLabel);\r
- fprintf(fp, " cmp %s, [edi+2] ; Are we bigger?\n", pszIoAddress);\r
- fprintf(fp, " jbe callRoutine%ld\n\n", dwGlobalLabel);\r
- fprintf(fp, "nextAddr%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " add edi, 0ch ; Next structure!\n");\r
- fprintf(fp, " jmp short checkLoop%ld\n\n", dwGlobalLabel);\r
- fprintf(fp, "callRoutine%ld:\n", dwGlobalLabel);\r
-\r
- if (strcmp(pszIoAddress, "dx") != 0)\r
- fprintf(fp, " mov dx, %s ; Get our address\n", pszIoAddress);\r
-\r
- fprintf(fp, " call ReadIOByte ; Standard read routine\n");\r
-\r
- // Yes, these are intentionally reversed!\r
- \r
- if (strcmp(pszTarget, "al") == 0)\r
- fprintf(fp, " mov [_z80af], al ; Save our new accumulator\n");\r
- else\r
- if (strcmp(pszTarget, "ah") == 0)\r
- fprintf(fp, " mov [_z80af + 1], ah ; Save our new flags\n");\r
- else\r
- if (strcmp(pszTarget, "dl") == 0)\r
- fprintf(fp, " mov [_z80de], al ; Put it in E\n");\r
- else\r
- if (strcmp(pszTarget, "dh") == 0)\r
- fprintf(fp, " mov [_z80de + 1], al ; Put it in D\n");\r
- else\r
- if (strcmp(pszTarget, "*dl") == 0)\r
- fprintf(fp, " mov dl, al ; Put it in DL for later consumption\n");\r
- else\r
- fprintf(fp, " mov %s, al ; Put our returned value here\n", pszTarget);\r
-\r
- // And are properly restored HERE:\r
-\r
- fprintf(fp, " mov ax, [_z80af] ; Get our AF back\n");\r
-\r
- // Restore registers here...\r
-\r
- fprintf(fp, " jmp short readExit%ld\n\n", dwGlobalLabel);\r
- fprintf(fp, "ioRead%ld:\n", dwGlobalLabel);\r
- \r
- if (strcmp(pszTarget, "*dl") == 0)\r
- fprintf(fp, " mov dl, 0ffh ; An unreferenced read\n");\r
- else\r
- fprintf(fp, " mov %s, 0ffh ; An unreferenced read\n", pszTarget);\r
- fprintf(fp, "readExit%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " mov edi, [cyclesRemaining]\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " psIoRead = cpu.z80IoRead; /* Beginning of our handler */\n");\r
- fprintf(fp, " while (psIoRead->lowIoAddr != 0xffff)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " if ((%s >= psIoRead->lowIoAddr) && (%s <= psIoRead->highIoAddr))\n", pszIoAddress, pszIoAddress);\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;\n");\r
- fprintf(fp, " %s = psIoRead->IOCall(%s, psIoRead);\n", pszTarget, pszIoAddress);\r
- fprintf(fp, " psIoRead = NULL;\n");\r
- fprintf(fp, " break;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " ++psIoRead;\n");\r
- fprintf(fp, " }\n\n");\r
- fprintf(fp, " if (psIoRead)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " %s = 0xff; /* Unclaimed I/O read */\n", pszTarget);\r
- fprintf(fp, " }\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-\r
- dwGlobalLabel++;\r
-}\r
-\r
-// Basic instruction set area\r
-\r
-void MiscHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (dwOpcode == 0xe3)\r
- {\r
- if (bThroughCallHandler)\r
- {\r
- fprintf(fp, " call PopWord\n");\r
- fprintf(fp, " xchg bx, [_wordval]\n");\r
- fprintf(fp, " call PushWord\n");\r
- }\r
- else\r
- {\r
- fprintf(fp, " mov dx, word [_z80sp]\n");\r
- fprintf(fp, " xchg bx, [ebp+edx]\n");\r
- fprintf(fp, " xor edx, edx\n");\r
- }\r
- }\r
-\r
- if (dwOpcode == 0x2a)\r
- {\r
- fprintf(fp, " mov dx, [esi] ; Get address to load\n");\r
- fprintf(fp, " add esi, 2 ; Skip over it so we don't execute it\n");\r
-\r
- ReadWordFromMemory("dx", "bx");\r
- fprintf(fp, " xor edx, edx\n");\r
- }\r
-\r
- if (dwOpcode == 0xfb)\r
- {\r
- fprintf(fp, " or dword [_z80iff], IFF1 ; Indicate interrupts are enabled now\n");\r
- fprintf(fp, " sub edi, 4 ; Takes 4 cycles!\n");\r
- fprintf(fp, " mov [dwEITiming], edi ; Snapshot our current timing\n");\r
- fprintf(fp, " mov [bEIExit], byte 1 ; Indicate we're exiting because of an EI\n");\r
- fprintf(fp, " xor edi, edi ; Force next instruction to exit\n");\r
- fprintf(fp, " mov dl, byte [esi] ; Get our next instruction\n");\r
- fprintf(fp, " inc esi ; Next PC\n");\r
- fprintf(fp, " jmp dword [z80regular+edx*4]\n\n");\r
- }\r
-\r
- if (dwOpcode == 0xf9)\r
- fprintf(fp, " mov word [_z80sp], bx\n");\r
-\r
- if (dwOpcode == 0xd9)\r
- {\r
- fprintf(fp, " mov [cyclesRemaining], edi\n");\r
- fprintf(fp, " mov di, [_z80de]\n");\r
- fprintf(fp, " xchg cx, [_z80bcprime]\n");\r
- fprintf(fp, " xchg di, [_z80deprime]\n");\r
- fprintf(fp, " xchg bx, [_z80hlprime]\n");\r
- fprintf(fp, " mov [_z80de], di\n");\r
- fprintf(fp, " mov edi, [cyclesRemaining]\n");\r
- }\r
-\r
- if (dwOpcode == 0x76)\r
- {\r
- fprintf(fp, " mov dword [_z80halted], 1 ; We've halted the chip!\n");\r
- \r
- if (FALSE == bNoTiming)\r
- {\r
- fprintf(fp, " xor edi, edi\n");\r
- fprintf(fp, " mov [cyclesRemaining], edi\n");\r
- }\r
- \r
- fprintf(fp, " jmp noMoreExec\n");\r
- return;\r
- }\r
- \r
- if (dwOpcode == 0x3f)\r
- {\r
- fprintf(fp, " mov dl, ah\n");\r
- fprintf(fp, " and dl, 01h\n");\r
- fprintf(fp, " shl dl, 4\n");\r
- fprintf(fp, " xor ah, 01h\n");\r
- fprintf(fp, " and ah, 0edh\n");\r
- fprintf(fp, " or ah, dl\n");\r
- }\r
- \r
- if (dwOpcode == 0x37)\r
- {\r
- fprintf(fp, " or ah, 1\n");\r
- fprintf(fp, " and ah,0edh\n");\r
- }\r
- \r
- if (dwOpcode == 0x27)\r
- {\r
- fprintf(fp, " mov dh, ah\n");\r
- fprintf(fp, " and dh, 02ah\n");\r
- fprintf(fp, " test ah, 02h ; Were we doing a subtraction?\n");\r
- fprintf(fp, " jnz handleNeg ; Nope!\n");\r
- fprintf(fp, " sahf\n");\r
- fprintf(fp, " daa\n");\r
- fprintf(fp, " lahf\n");\r
- fprintf(fp, " jmp short endDaa\n");\r
- fprintf(fp, "handleNeg:\n");\r
- fprintf(fp, " sahf\n");\r
- fprintf(fp, " das\n");\r
- fprintf(fp, " lahf\n");\r
- fprintf(fp, "endDaa:\n");\r
- fprintf(fp, " and ah, 0d5h\n");\r
- fprintf(fp, " or ah, dh\n");\r
- fprintf(fp, " xor edx, edx\n");\r
- }\r
- \r
- if (dwOpcode == 0x08)\r
- {\r
- fprintf(fp, " xchg ah, al\n");\r
- fprintf(fp, " xchg ax, [_z80afprime]\n");\r
- fprintf(fp, " xchg ah, al\n");\r
- }\r
- \r
- if (dwOpcode == 0x07)\r
- {\r
- fprintf(fp, " sahf\n");\r
- fprintf(fp, " rol al, 1\n");\r
- fprintf(fp, " lahf\n");\r
- fprintf(fp, " and ah, 0edh\n");\r
- }\r
- \r
- if (dwOpcode == 0x0f)\r
- {\r
- fprintf(fp, " sahf\n");\r
- fprintf(fp, " ror al, 1\n");\r
- fprintf(fp, " lahf\n");\r
- fprintf(fp, " and ah, 0edh\n");\r
- }\r
- \r
- if (dwOpcode == 0xe9)\r
- {\r
- fprintf(fp, " mov si, bx\n");\r
- fprintf(fp, " and esi, 0ffffh\n");\r
- fprintf(fp, " add esi, ebp\n");\r
- }\r
- \r
- if (dwOpcode == 0xeb)\r
- fprintf(fp, " xchg [_z80de], bx ; Exchange DE & HL\n");\r
- \r
- if (dwOpcode == 0x2f)\r
- {\r
- fprintf(fp, " not al\n");\r
- fprintf(fp, " or ah, 012h ; N And H are now on!\n");\r
- }\r
- \r
- if (dwOpcode == 0x10) // DJNZ\r
- {\r
- fprintf(fp, " mov dl, [esi] ; Get our relative offset\n");\r
- fprintf(fp, " inc esi ; Next instruction, please!\n");\r
- fprintf(fp, " dec ch ; Decrement B\n");\r
- fprintf(fp, " jz noJump ; Don't take the jump if it's done!\n");\r
- fprintf(fp, "; Otherwise, take the jump\n");\r
- \r
- fprintf(fp, " sub edi, 5\n");\r
- \r
- fprintf(fp, " xchg eax, edx\n");\r
- fprintf(fp, " cbw\n");\r
- fprintf(fp, " xchg eax, edx\n");\r
- fprintf(fp, " sub esi, ebp\n");\r
- fprintf(fp, " add si, dx\n");\r
- fprintf(fp, " add esi, ebp\n");\r
- fprintf(fp, "noJump:\n");\r
- fprintf(fp, " xor edx, edx\n");\r
- }\r
- \r
- if (dwOpcode == 0x3a) // LD A,(xxxx)\r
- {\r
- fprintf(fp, " mov dx, [esi] ; Get our address\n");\r
- fprintf(fp, " add esi, 2 ; Skip past the address\n");\r
- ReadValueFromMemory("dx", "al");\r
- fprintf(fp, " xor edx, edx ; Make sure we don't hose things\n");\r
- }\r
- \r
- if (dwOpcode == 0xf3) // DI\r
- {\r
- fprintf(fp, " and dword [_z80iff], (~IFF1) ; Not in an interrupt\n");\r
- }\r
- \r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (dwOpcode == 0x76) // HALT!\r
- {\r
- fprintf(fp, " cpu.z80halted = 1;\n");\r
- fprintf(fp, " dwElapsedTicks += sdwCyclesRemaining;\n");\r
-\r
- fprintf(fp, " sdwCyclesRemaining = 0;\n");\r
- }\r
- else\r
- if (dwOpcode == 0x2f) // CPL\r
- {\r
- fprintf(fp, " cpu.z80A ^= 0xff;\n");\r
- fprintf(fp, " cpu.z80F |= (Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);\n");\r
- }\r
- else\r
- if (dwOpcode == 0xd9) // EXX\r
- {\r
- fprintf(fp, " dwTemp = cpu.z80DE;\n");\r
- fprintf(fp, " cpu.z80DE = cpu.z80deprime;\n");\r
- fprintf(fp, " cpu.z80deprime = dwTemp;\n");\r
-\r
- fprintf(fp, " dwTemp = cpu.z80BC;\n");\r
- fprintf(fp, " cpu.z80BC = cpu.z80bcprime;\n");\r
- fprintf(fp, " cpu.z80bcprime = dwTemp;\n");\r
-\r
- fprintf(fp, " dwTemp = cpu.z80HL;\n");\r
- fprintf(fp, " cpu.z80HL = cpu.z80hlprime;\n");\r
- fprintf(fp, " cpu.z80hlprime = dwTemp;\n");\r
- }\r
- else\r
- if (dwOpcode == 0xf9) // LD SP, HL\r
- {\r
- fprintf(fp, " cpu.z80sp = cpu.z80HL;\n");\r
- }\r
- else\r
- if (dwOpcode == 0x27) // DAA\r
- {\r
- fprintf(fp, " dwAddr = (((cpu.z80F & Z80_FLAG_CARRY) | \n");\r
- fprintf(fp, " ((cpu.z80F & Z80_FLAG_HALF_CARRY) >> 3) | \n");\r
- fprintf(fp, " ((cpu.z80F & Z80_FLAG_NEGATIVE) << 1)) << 8) | cpu.z80A;\n");\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " cpu.z80F |= (wDAATable[dwAddr] >> 8);\n");\r
- fprintf(fp, " cpu.z80A = wDAATable[dwAddr] & 0xff;\n");\r
- }\r
- else\r
- if (dwOpcode == 0x2a)\r
- {\r
- fprintf(fp, " dwAddr = *pbPC++;\n");\r
- fprintf(fp, " dwAddr |= ((UINT32) *pbPC++ << 8);\n");\r
- ReadWordFromMemory("dwAddr", "cpu.z80HL");\r
- }\r
- else\r
- if (dwOpcode == 0xe3) // EX (SP), HL\r
- {\r
- ReadWordFromMemory("cpu.z80sp", "dwAddr");\r
- WriteWordToMemory("cpu.z80sp", "cpu.z80HL");\r
- fprintf(fp, " cpu.z80HL = dwAddr;\n");\r
- }\r
- else\r
- if (dwOpcode == 0xe9) // JP (HL)\r
- {\r
- fprintf(fp, " pbPC = cpu.z80Base + cpu.z80HL;\n");\r
- }\r
- else\r
- if (0x08 == dwOpcode) // EX AF, AF'\r
- {\r
- fprintf(fp, " dwAddr = (UINT32) cpu.z80AF;\n");\r
- fprintf(fp, " cpu.z80AF = cpu.z80afprime;\n");\r
- fprintf(fp, " cpu.z80afprime = dwAddr;\n");\r
- }\r
- else\r
- if (0xeb == dwOpcode) // EX DE, HL\r
- {\r
- fprintf(fp, " dwAddr = cpu.z80DE;\n");\r
- fprintf(fp, " cpu.z80DE = cpu.z80HL;\n");\r
- fprintf(fp, " cpu.z80HL = dwAddr;\n");\r
- }\r
- else\r
- if (0x10 == dwOpcode) // DJNZ\r
- {\r
- fprintf(fp, " sdwAddr = (INT8) *pbPC++; /* Get LSB first */\n");\r
- fprintf(fp, " if (--cpu.z80B)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " dwElapsedTicks += 5; /* 5 More for jump taken */\n");\r
- fprintf(fp, " cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;\n");\r
- fprintf(fp, " sdwAddr = (sdwAddr + (INT32) cpu.z80pc) & 0xffff;\n");\r
- fprintf(fp, " pbPC = cpu.z80Base + sdwAddr; /* Normalize the address */\n");\r
- fprintf(fp, " }\n");\r
- }\r
- else\r
- if (0x37 == dwOpcode) // SCF\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE);\n");\r
- fprintf(fp, " cpu.z80F |= Z80_FLAG_CARRY;\n");\r
- }\r
- else\r
- if (0x3f == dwOpcode) // CCF\r
- {\r
- fprintf(fp, " bTemp = (cpu.z80F & Z80_FLAG_CARRY) << 4;\n");\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE);\n");\r
- fprintf(fp, " cpu.z80F ^= Z80_FLAG_CARRY;\n");\r
- }\r
- else\r
- if (0x07 == dwOpcode) // RLCA\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);\n");\r
- fprintf(fp, " cpu.z80F |= (cpu.z80A >> 7);\n");\r
- fprintf(fp, " cpu.z80A = (cpu.z80A << 1) | (cpu.z80A >> 7);\n");\r
- }\r
- else\r
- if (0x0f == dwOpcode) // RRCA\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);\n");\r
- fprintf(fp, " cpu.z80F |= (cpu.z80A & Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80A = (cpu.z80A >> 1) | (cpu.z80A << 7);\n");\r
- }\r
- else\r
- if (0x3a == dwOpcode) // LD A, (xxxxh)\r
- {\r
- fprintf(fp, " dwTemp = *pbPC++;\n");\r
- fprintf(fp, " dwTemp |= (((UINT32) *pbPC++) << 8);\n");\r
- ReadValueFromMemory("dwTemp", "cpu.z80A");\r
- }\r
- else\r
- if (0xf3 == dwOpcode) // DI\r
- {\r
- fprintf(fp, " cpu.z80iff &= (~IFF1);\n");\r
- }\r
- else\r
- if (0xfb == dwOpcode) // EI\r
- {\r
- fprintf(fp, " cpu.z80iff |= IFF1;\n");\r
- }\r
- else\r
- if (0x00 == dwOpcode) // NOP\r
- {\r
- fprintf(fp, " /* Intentionally not doing anything - NOP! */\n");\r
- }\r
- else\r
- {\r
- InvalidInstructionC(1);\r
- }\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
- \r
-}\r
-\r
-void LdRegPairImmediate(UINT32 dwOpcode)\r
-{\r
- UINT8 bOp = 0;\r
-\r
- bOp = (dwOpcode >> 4) & 0x3;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (bOp == 0)\r
- fprintf(fp, " mov cx, [esi] ; Get our immediate value of BC\n");\r
- else\r
- if (bOp == 2)\r
- fprintf(fp, " mov bx, [esi] ; Get our immediate value of HL\n");\r
- else\r
- if (bOp == 1)\r
- {\r
- fprintf(fp, " mov dx, [esi] ; Get our immediate value of DE\n");\r
- fprintf(fp, " mov word [_z80de], dx ; Store DE\n");\r
- fprintf(fp, " xor edx, edx\n");\r
- }\r
- else\r
- if (bOp == 3)\r
- {\r
- fprintf(fp, " mov dx, [esi] ; Get our immediate value of SP\n");\r
- fprintf(fp, " mov word [_z80sp], dx ; Store it!\n");\r
- fprintf(fp, " xor edx, edx\n");\r
- }\r
- \r
- fprintf(fp, " add esi, 2\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " %s = *pbPC++; /* LSB First */\n", pbRegPairC[bOp]);\r
- fprintf(fp, " %s |= (((UINT32) *pbPC++ << 8)); /* Now the MSB */\n", pbRegPairC[bOp]);\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void LdRegpairPtrByte(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (dwOpcode == 0x36) // Immediate into (HL)\r
- WriteValueToMemory("bx", "[esi]");\r
-\r
- if (dwOpcode == 0x12)\r
- WriteValueToMemory("[_z80de]", "al"); // (DE), A\r
-\r
- if (dwOpcode == 0x2) // (BC), A\r
- WriteValueToMemory("cx", "al");\r
-\r
- if (dwOpcode >= 0x70 && dwOpcode < 0x78)\r
- WriteValueToMemory("bx", pbMathReg[dwOpcode & 0x07]);\r
-\r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (dwOpcode == 0x36)\r
- WriteValueToMemory("cpu.z80HL", "*pbPC++");\r
-\r
- if (dwOpcode == 0x12)\r
- WriteValueToMemory("cpu.z80DE", "cpu.z80A");\r
-\r
- if (dwOpcode == 0x02)\r
- WriteValueToMemory("cpu.z80BC", "cpu.z80A");\r
-\r
- if (dwOpcode >= 0x70 && dwOpcode < 0x78)\r
- WriteValueToMemory("cpu.z80HL", pbMathRegC[dwOpcode & 0x07]);\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void MathOperation(UINT32 dwOrgOpcode)\r
-{\r
- UINT8 bRegister;\r
- UINT32 dwOpcode;\r
- UINT8 tempstr[150];\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOrgOpcode);\r
-\r
- dwOpcode = dwOrgOpcode;\r
- bRegister = dwOpcode & 0x07;\r
- dwOpcode &= 0xf8;\r
-\r
- if (dwOpcode == 0x80)\r
- strcpy(tempstr, "add");\r
- if (dwOpcode == 0x88)\r
- strcpy(tempstr, "adc");\r
- if (dwOpcode == 0x90)\r
- strcpy(tempstr, "sub");\r
- if (dwOpcode == 0x98)\r
- strcpy(tempstr, "sbb");\r
- if (dwOpcode == 0xa0)\r
- strcpy(tempstr, "and");\r
- if (dwOpcode == 0xa8)\r
- strcpy(tempstr, "xor");\r
- if (dwOpcode == 0xb0)\r
- strcpy(tempstr, "or");\r
- if (dwOpcode == 0xb8)\r
- strcpy(tempstr, "cmp");\r
- \r
- // Let's see if we have to deal with (HL) or #xxh\r
- \r
- if (bRegister == 0x6)\r
- {\r
- // We have to deal with (HL)\r
- \r
- ReadValueFromMemory("bx", "dl");\r
- }\r
- \r
- if (bRegister != 0x06 && bRegister < 0xff)\r
- {\r
- fprintf(fp, " sahf\n");\r
- fprintf(fp, " %s al, %s\n", tempstr, pbMathReg[bRegister]);\r
- fprintf(fp, " lahf\n");\r
- }\r
- else // If it's (HL)....\r
- {\r
- fprintf(fp, " sahf\n");\r
- fprintf(fp, " %s al, dl\n", tempstr);\r
- fprintf(fp, " lahf\n");\r
- }\r
- \r
- if (dwOpcode != 0xa8 && dwOpcode != 0xa0 && dwOpcode != 0xb0)\r
- SetOverflow();\r
- \r
- if (dwOpcode == 0xa8)\r
- fprintf(fp, " and ah, 0ech ; Only these flags matter!\n");\r
- \r
- if (dwOpcode == 0xa0)\r
- {\r
- fprintf(fp, " and ah, 0ech ; Only these flags matter!\n");\r
- fprintf(fp, " or ah, 010h ; Half carry gets set\n");\r
- }\r
- \r
- if (dwOpcode == 0xb0)\r
- fprintf(fp, " and ah, 0ech ; No H, N, or C\n");\r
- \r
- if (dwOpcode == 0xb8)\r
- fprintf(fp, " or ah, 02h ; Set N for compare!\n");\r
- \r
- if (dwOpcode == 0x80 || dwOpcode == 0x88)\r
- fprintf(fp, " and ah, 0fdh ; No N!\n");\r
- \r
- if (dwOpcode == 0x90 || dwOpcode == 0x98)\r
- fprintf(fp, " or ah, 02h ; N Gets set!\n");\r
-\r
- if (bRegister == 0x6)\r
- fprintf(fp, " xor edx, edx ; Zero this...\n");\r
- \r
- FetchNextInstruction(dwOrgOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- dwOpcode = dwOrgOpcode;\r
- bRegister = dwOpcode & 0x07;\r
- dwOpcode &= 0xf8;\r
-\r
- if (6 == bRegister) // Deal with (HL)\r
- {\r
- ReadValueFromMemory("cpu.z80HL", "bTemp");\r
- }\r
-\r
- if (dwOpcode == 0xa0)\r
- {\r
- fprintf(fp, " cpu.z80A &= %s;\n", pbMathRegC[bRegister]);\r
- }\r
- else\r
- if (dwOpcode == 0xa8)\r
- {\r
- fprintf(fp, " cpu.z80A ^= %s;\n", pbMathRegC[bRegister]);\r
- }\r
- else\r
- if (dwOpcode == 0xb0)\r
- {\r
- fprintf(fp, " cpu.z80A |= %s;\n", pbMathRegC[bRegister]);\r
- }\r
- else\r
- if (dwOpcode == 0xb8)\r
- {\r
- // Don't do anything. We just do flags!\r
- }\r
- else\r
- if (dwOpcode == 0x88) // ADC\r
- {\r
- fprintf(fp, " bTemp2 = cpu.z80A + %s + (cpu.z80F & Z80_FLAG_CARRY);\n", pbMathRegC[bRegister]);\r
- }\r
- else\r
- if (dwOpcode == 0x90) // SUB\r
- {\r
- fprintf(fp, " bTemp2 = cpu.z80A - %s;\n", pbMathRegC[bRegister]);\r
- } \r
- else\r
- if (dwOpcode == 0x80) // ADD\r
- {\r
- fprintf(fp, " bTemp2 = cpu.z80A + %s;\n", pbMathRegC[bRegister]);\r
- }\r
- else\r
- if (dwOpcode == 0x98) // SBC\r
- {\r
- fprintf(fp, " bTemp2 = cpu.z80A - %s - (cpu.z80F & Z80_FLAG_CARRY);\n", pbMathRegC[bRegister]);\r
- }\r
- else\r
- {\r
- InvalidInstructionC(1);\r
- }\r
-\r
- // Now do flag fixup\r
-\r
- if (0xb0 == dwOpcode || 0xa8 == dwOpcode)\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[cpu.z80A];\n\n");\r
- }\r
-\r
- if (0xa0 == dwOpcode)\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " cpu.z80F |= bPostANDFlags[cpu.z80A];\n\n");\r
- }\r
-\r
- if (0xb8 == dwOpcode || 0x90 == dwOpcode)\r
- {\r
- SetSubFlagsSZHVC("cpu.z80A", pbMathRegC[bRegister]);\r
-\r
- if (0x90 == dwOpcode)\r
- {\r
- fprintf(fp, " cpu.z80A = bTemp2;\n");\r
- }\r
- }\r
-\r
- if (0x80 == dwOpcode) // Add fixup\r
- {\r
- SetAddFlagsSZHVC("cpu.z80A", pbMathRegC[bRegister]);\r
- fprintf(fp, " cpu.z80A = bTemp2;\n");\r
- }\r
-\r
- if (0x88 == dwOpcode) // Adc fixup\r
- {\r
- SetAdcFlagsSZHVC("cpu.z80A", pbMathRegC[bRegister]);\r
- fprintf(fp, " cpu.z80A = bTemp2;\n");\r
- }\r
-\r
- if (0x98 == dwOpcode) // Sbc fixup\r
- {\r
- SetSbcFlagsSZHVC("cpu.z80A", pbMathRegC[bRegister]);\r
- fprintf(fp, " cpu.z80A = bTemp2;\n");\r
- }\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void RegIntoMemory(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " mov dx, [esi] ; Get our address to write to\n");\r
- fprintf(fp, " add esi, 2 ; Next address, please...\n");\r
-\r
- if (0x32 == dwOpcode) // LD (xxxx), A\r
- WriteValueToMemory("dx", "al");\r
- if (0x22 == dwOpcode) // LD (xxxx), HL\r
- {\r
- WriteWordToMemory("dx", "bx");\r
- }\r
-\r
- fprintf(fp, " xor edx, edx ; Zero our upper byte\n");\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " dwTemp = *pbPC++;\n");\r
- fprintf(fp, " dwTemp |= ((UINT32) *pbPC++ << 8);\n");\r
-\r
- if (0x32 == dwOpcode)\r
- WriteValueToMemory("dwTemp", "cpu.z80A");\r
- if (0x22 == dwOpcode)\r
- WriteWordToMemory("dwTemp", "cpu.z80HL");\r
-\r
- return;\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void JpHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (0xc3 == dwOpcode) // If it's a straight jump...\r
- {\r
- fprintf(fp, " mov si, [esi] ; Get our new address\n");\r
- fprintf(fp, " and esi, 0ffffh ; Only the lower 16 bits\n");\r
- fprintf(fp, " add esi, ebp ; Our new address!\n");\r
- }\r
- else // It's a conditional handler...\r
- {\r
- fprintf(fp, " sahf ; Restore our flags\n");\r
- fprintf(fp, " j%s takeJump%ld ; We're going to take a jump\n", pbFlags[(dwOpcode >> 3) & 0x07], dwGlobalLabel);\r
- fprintf(fp, " add esi, 2 ; Skip past the address\n");\r
- fprintf(fp, " jmp short nextInst%ld ; Go execute the next instruction\n", dwGlobalLabel);\r
- fprintf(fp, "takeJump%ld:\n", dwGlobalLabel);\r
- \r
- fprintf(fp, " mov si, [esi] ; Get our new offset\n");\r
- fprintf(fp, " and esi, 0ffffh ; Only the lower WORD is valid\n");\r
- fprintf(fp, " add esi, ebp ; Our new address!\n");\r
- fprintf(fp, "nextInst%ld:\n", dwGlobalLabel);\r
- ++dwGlobalLabel;\r
- }\r
- \r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " dwAddr = *pbPC++; /* Get LSB first */\n");\r
- fprintf(fp, " dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */\n");\r
-\r
- if (0xc3 != dwOpcode)\r
- {\r
- fprintf(fp, " if %s\n", pbFlagsC[(dwOpcode >> 3) & 0x07]);\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " pbPC = cpu.z80Base + dwAddr; /* Normalize the address */\n");\r
- fprintf(fp, " }\n");\r
- }\r
- else // Regular jump here\r
- {\r
- fprintf(fp, " pbPC = cpu.z80Base + dwAddr; /* Normalize the address */\n");\r
- }\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void LdRegImmediate(UINT32 dwOpcode)\r
-{\r
- UINT8 bOp;\r
-\r
- bOp = (dwOpcode >> 3) & 0x7;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
-\r
- if (bOp != 2 && bOp != 3)\r
- fprintf(fp, " mov %s, [esi] ; Get our immediate value\n", pbMathReg[bOp]);\r
- else\r
- {\r
- fprintf(fp, " mov dl, [esi] ; Get our immediate value\n");\r
- fprintf(fp, " mov %s, dl ; Store our new value\n", pbMathReg[bOp]);\r
- }\r
- \r
- fprintf(fp, " inc esi\n");\r
- \r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " %s = *pbPC++; /* Get immediate byte into register */\n", pbMathRegC[bOp]);\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void IncRegister(UINT32 dwOpcode)\r
-{\r
- UINT32 dwOpcode1 = 0;\r
-\r
- dwOpcode1 = (dwOpcode >> 3) & 0x07;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " sahf\n");\r
- fprintf(fp, " inc %s\n", pbMathReg[dwOpcode1]);\r
- fprintf(fp, " lahf\n");\r
- SetOverflow();\r
- fprintf(fp, " and ah, 0fdh ; Knock out N!\n");\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);\n");\r
- fprintf(fp ," cpu.z80F |= bPostIncFlags[%s++];\n", pbMathRegC[dwOpcode1]);\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void DecRegister(UINT32 dwOpcode)\r
-{\r
- UINT32 dwOpcode1 = 0;\r
-\r
- dwOpcode1 = (dwOpcode >> 3) & 0x07;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " sahf\n");\r
- fprintf(fp, " dec %s\n", pbMathReg[dwOpcode1]);\r
- fprintf(fp, " lahf\n");\r
- SetOverflow();\r
- fprintf(fp, " or ah, 02h ; Set negative!\n");\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY);\n");\r
- fprintf(fp ," cpu.z80F |= bPostDecFlags[%s--];\n", pbMathRegC[dwOpcode1]);\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void IncDecRegpair(UINT32 dwOpcode)\r
-{\r
- UINT32 dwOpcode1 = 0;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if ((dwOpcode & 0x0f) == 3) // Increment?\r
- fprintf(fp, " inc %s\n", pbRegPairs[(dwOpcode >> 4) & 0x03]);\r
- else\r
- fprintf(fp, " dec %s\n", pbRegPairs[(dwOpcode >> 4) & 0x03]);\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if ((dwOpcode & 0x0f) == 3) // Increment\r
- fprintf(fp, " %s++;\n", pbRegPairC[(dwOpcode >> 4) & 0x03]);\r
- else\r
- fprintf(fp, " %s--;\n", pbRegPairC[(dwOpcode >> 4) & 0x03]);\r
- fprintf(fp, " %s &= 0xffff;\n", pbRegPairC[(dwOpcode >> 4) & 0x03]);\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void LdRegReg(UINT32 dwOpcode)\r
-{\r
- UINT8 bDestination;\r
- UINT8 bSource;\r
-\r
- bDestination = (dwOpcode >> 3) & 0x07;\r
- bSource = (dwOpcode) & 0x07;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
-\r
- ProcBegin(dwOpcode);\r
- \r
- if (bSource != bDestination)\r
- {\r
- if (bSource == 2 && bDestination == 3)\r
- {\r
- fprintf(fp, " mov dl, byte [_z80de + 1]\n");\r
- fprintf(fp, " mov [_z80de], dl\n");\r
- }\r
- else\r
- if (bSource == 3 && bDestination == 2)\r
- {\r
- fprintf(fp, " mov dl, byte [_z80de]\n");\r
- fprintf(fp, " mov [_z80de + 1], dl\n");\r
- }\r
- else\r
- fprintf(fp, " mov %s, %s\n", pbMathReg[bDestination], pbMathReg[bSource]);\r
- }\r
- \r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (bDestination != bSource)\r
- {\r
- fprintf(fp, " %s = %s;\n",\r
- pbMathRegC[bDestination],\r
- pbMathRegC[bSource]);\r
- }\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void MathOperationDirect(UINT32 dwOpcode)\r
-{\r
- UINT8 tempstr[4];\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- if (dwOpcode == 0xc6)\r
- strcpy(tempstr, "add");\r
- if (dwOpcode == 0xce)\r
- strcpy(tempstr, "adc");\r
- if (dwOpcode == 0xd6)\r
- strcpy(tempstr, "sub");\r
- if (dwOpcode == 0xde)\r
- strcpy(tempstr, "sbb");\r
- if (dwOpcode == 0xe6)\r
- strcpy(tempstr, "and");\r
- if (dwOpcode == 0xee)\r
- strcpy(tempstr, "xor");\r
- if (dwOpcode == 0xf6)\r
- strcpy(tempstr, "or");\r
- if (dwOpcode == 0xfe)\r
- strcpy(tempstr, "cmp");\r
- \r
- ProcBegin(dwOpcode);\r
- \r
- // Let's see if we have to deal with (HL) or #xxh\r
- \r
- fprintf(fp, " sahf\n");\r
- fprintf(fp, " %s al, [esi]\n", tempstr);\r
- fprintf(fp, " lahf\n");\r
- \r
- if (dwOpcode != 0xee && dwOpcode != 0xe6 && dwOpcode != 0xf6)\r
- {\r
- SetOverflow();\r
- }\r
- \r
- if (dwOpcode == 0xe6)\r
- {\r
- fprintf(fp, " and ah, 0ech ; Only parity, half carry, sign, zero\n");\r
- fprintf(fp, " or ah, 10h ; Half carry\n");\r
- }\r
- \r
- if (dwOpcode == 0xc6 || dwOpcode == 0xce)\r
- fprintf(fp, " and ah, 0fdh ; Knock out N!\n");\r
- \r
- if (dwOpcode == 0xd6 || dwOpcode == 0xde || dwOpcode == 0xfe)\r
- fprintf(fp, " or ah, 02h ; Set negative!\n");\r
-\r
- if (dwOpcode == 0xf6 || dwOpcode == 0xee)\r
- fprintf(fp, " and ah, 0ech ; No H, N, or C\n");\r
- \r
- fprintf(fp, " inc esi\n");\r
- \r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (0xfe == dwOpcode) // Cp\r
- {\r
- SetSubFlagsSZHVC("cpu.z80A", "*pbPC++");\r
- }\r
- else\r
- if (0xe6 == dwOpcode) // And\r
- {\r
- fprintf(fp, " cpu.z80A &= *pbPC++;\n");\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " cpu.z80F |= bPostANDFlags[cpu.z80A];\n\n");\r
- }\r
- else\r
- if (0xf6 == dwOpcode) // Or\r
- {\r
- fprintf(fp, " cpu.z80A |= *pbPC++;\n");\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[cpu.z80A];\n\n");\r
- }\r
- else\r
- if (0xc6 == dwOpcode) // Add\r
- {\r
- fprintf(fp, " bTemp = *pbPC++;\n");\r
- SetAddFlagsSZHVC("cpu.z80A", "bTemp");\r
- fprintf(fp, " cpu.z80A += bTemp;\n");\r
- }\r
- else\r
- if (0xce == dwOpcode) // Adc\r
- {\r
- fprintf(fp, " bTemp = *pbPC++ + (cpu.z80F & Z80_FLAG_CARRY);\n");\r
- SetAdcFlagsSZHVC("cpu.z80A", "bTemp");\r
- fprintf(fp, " cpu.z80A += bTemp;\n");\r
- }\r
- else\r
- if (0xd6 == dwOpcode) // Sub\r
- {\r
- fprintf(fp, " bTemp = *pbPC++;\n");\r
- SetSubFlagsSZHVC("cpu.z80A", "bTemp");\r
- fprintf(fp, " cpu.z80A -= bTemp;\n");\r
- }\r
- else\r
- if (0xde == dwOpcode) // Sbc\r
- {\r
- fprintf(fp, " bTemp = *pbPC++ + (cpu.z80F & Z80_FLAG_CARRY);\n");\r
- SetSbcFlagsSZHVC("cpu.z80A", "bTemp");\r
- fprintf(fp, " cpu.z80A = cpu.z80A - bTemp;\n");\r
- }\r
- else\r
- if (0xee == dwOpcode) // Xor\r
- {\r
- fprintf(fp, " cpu.z80A ^= *pbPC++;\n");\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[cpu.z80A];\n\n");\r
- }\r
- else\r
- InvalidInstructionC(1);\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-// JR cc, addr\r
-\r
-void JrHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
- \r
- fprintf(fp, " sub esi, ebp\n");\r
- fprintf(fp, " and esi, 0ffffh\n");\r
- fprintf(fp, " add esi, ebp\n");\r
-\r
- fprintf(fp, " mov dl, [esi] ; Get our relative offset\n");\r
- fprintf(fp, " inc esi ; Next instruction, please!\n");\r
-\r
- if (dwOpcode != 0x18)\r
- {\r
- fprintf(fp, " sahf\n");\r
- fprintf(fp, " j%s takeJump%ld\n", pbFlags[(dwOpcode >> 3) & 0x3], dwGlobalLabel);\r
- fprintf(fp, " jmp short noJumpMan%ld\n", dwGlobalLabel);\r
- fprintf(fp, "takeJump%ld:\n", dwGlobalLabel);\r
-\r
- if (FALSE == bNoTiming)\r
- {\r
- fprintf(fp, " sub edi, 5\n");\r
- }\r
- }\r
- else // It's a JR\r
- {\r
- fprintf(fp, " cmp dl, 0feh ; Jump to self?\n");\r
- fprintf(fp, " je yesJrMan ; Yup! Bail out!\n");\r
- }\r
- \r
- fprintf(fp, " xchg eax, edx\n");\r
- fprintf(fp, " cbw\n");\r
- fprintf(fp, " xchg eax, edx\n");\r
- fprintf(fp, " sub esi, ebp\n");\r
- fprintf(fp, " add si, dx\n");\r
- fprintf(fp, " and esi, 0ffffh ; Only the lower 16 bits\n");\r
- fprintf(fp, " add esi, ebp\n");\r
- fprintf(fp, " xor dh, dh\n");\r
- fprintf(fp, "noJumpMan%ld:\n", dwGlobalLabel++);\r
-\r
- FetchNextInstruction(dwOpcode);\r
- \r
- if (0x18 == dwOpcode)\r
- {\r
- fprintf(fp,"yesJrMan:\n");\r
-\r
- fprintf(fp, " xor edx, edx ; Zero me for later\n");\r
- fprintf(fp, " mov edi, edx\n");\r
- fprintf(fp, " mov [cyclesRemaining], edx\n");\r
- fprintf(fp, " sub esi, 2 ; Back to the instruction again\n");\r
- fprintf(fp, " jmp noMoreExec\n\n");\r
- }\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " sdwAddr = (INT8) *pbPC++; /* Get LSB first */\n");\r
- fprintf(fp, " cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;\n");\r
- fprintf(fp, " sdwAddr = (sdwAddr + (INT32) cpu.z80pc) & 0xffff;\n");\r
-\r
- if (0x18 != dwOpcode)\r
- {\r
- fprintf(fp, " if %s\n", pbFlagsC[(dwOpcode >> 3) & 0x03]);\r
- }\r
-\r
- fprintf(fp, " {\n");\r
-\r
- fprintf(fp, " sdwCyclesRemaining -= 5;\n");\r
-\r
- fprintf(fp, " pbPC = cpu.z80Base + sdwAddr; /* Normalize the address */\n");\r
- fprintf(fp, " }\n");\r
- \r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void CallHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (dwOpcode != 0xcd)\r
- {\r
- fprintf(fp, " sahf ; Restore our flags\n");\r
- fprintf(fp, " j%s takeJump%ld ; We're going call in this case\n", pbFlags[(dwOpcode >> 3) & 0x07], dwGlobalLabel);\r
- fprintf(fp, " add esi, 2 ; Skip past the address\n");\r
- fprintf(fp, " jmp short noCallTaken%ld ; Go execute the next instruction\n", dwGlobalLabel);\r
- fprintf(fp, "takeJump%ld:\n", dwGlobalLabel);\r
- \r
- fprintf(fp, " sub edi, 7\n");\r
- }\r
-\r
-\r
- if (bThroughCallHandler)\r
- {\r
- fprintf(fp, " mov dx, [esi] ; Get our call to address\n");\r
- fprintf(fp, " mov [_z80pc], dx ; Store our new program counter\n");\r
- fprintf(fp, " add esi, 2 ; Skip to our new address to be pushed\n");\r
- fprintf(fp, " sub esi, ebp ; Value to push onto the \"stack\"\n");\r
- fprintf(fp, " mov [_wordval], si ; Store our return address on the stack\n");\r
- fprintf(fp, " mov si, dx ; Our new address\n");\r
- fprintf(fp, " add esi, ebp ; And our base address\n");\r
- fprintf(fp, " call PushWord ; Go push our orgval to the stack\n");\r
- }\r
- else\r
- {\r
- fprintf(fp, " mov dx, [esi] ; Get our call to address\n");\r
- fprintf(fp, " mov [_z80pc], dx ; Store our new program counter\n");\r
- fprintf(fp, " add esi, 2 ; Skip to our new address to be pushed\n");\r
- fprintf(fp, " sub esi, ebp ; Value to push onto the \"stack\"\n");\r
- fprintf(fp, " mov dx, word [_z80sp] ; Get the current stack pointer\n");\r
- fprintf(fp, " sub dx, 2 ; Back up two bytes\n");\r
- fprintf(fp, " mov [ebp+edx], si ; PUSH It!\n");\r
- fprintf(fp, " mov word [_z80sp], dx ; Store our new stack pointer\n");\r
- fprintf(fp, " mov si, [_z80pc] ; Get our new program counter\n");\r
- fprintf(fp, " add esi, ebp ; Naturalize it!\n");\r
- }\r
-\r
- if (dwOpcode != 0xcd)\r
- fprintf(fp, "noCallTaken%ld:\n", dwGlobalLabel++);\r
-\r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " dwAddr = *pbPC++; /* Get LSB first */\n");\r
- fprintf(fp, " dwAddr |= ((UINT32) *pbPC++ << 8); /* Get MSB last */\n");\r
-\r
- if (0xcd != dwOpcode)\r
- {\r
- fprintf(fp, " if %s\n", pbFlagsC[(dwOpcode >> 3) & 0x07]);\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;\n");\r
- fprintf(fp, " pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */\n");\r
- fprintf(fp, " *pbSP-- = cpu.z80pc >> 8; /* MSB */\n");\r
- fprintf(fp, " *pbSP = (UINT8) cpu.z80pc; /* LSB */\n");\r
- fprintf(fp, " cpu.z80sp -= 2; /* Back our stack up */\n");\r
- fprintf(fp, " pbPC = cpu.z80Base + dwAddr; /* Normalize the address */\n");\r
- fprintf(fp, " }\n");\r
- }\r
- else // Just a regular call\r
- {\r
- fprintf(fp, " cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;\n");\r
- fprintf(fp, " pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */\n");\r
- fprintf(fp, " *pbSP-- = cpu.z80pc >> 8; /* LSB */\n");\r
- fprintf(fp, " *pbSP = (UINT8) cpu.z80pc; /* MSB */\n");\r
- fprintf(fp, " cpu.z80sp -= 2; /* Back our stack up */\n");\r
- fprintf(fp, " pbPC = cpu.z80Base + dwAddr; /* Normalize the address */\n");\r
- }\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void RetHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (dwOpcode != 0xc9)\r
- {\r
- fprintf(fp, " sahf\n");\r
- fprintf(fp, " j%s takeReturn%ld\n", pbFlags[(dwOpcode >> 3) & 0x07], dwGlobalLabel);\r
- fprintf(fp, " jmp short retNotTaken%ld\n", dwGlobalLabel);\r
- fprintf(fp, "takeReturn%ld:\n", dwGlobalLabel);\r
-\r
- if (FALSE == bNoTiming)\r
- {\r
- fprintf(fp, " sub edi, byte 6\n");\r
- }\r
- }\r
-\r
-\r
- if (bThroughCallHandler)\r
- {\r
- fprintf(fp, " call PopWord\n");\r
- fprintf(fp, " xor esi, esi\n");\r
- fprintf(fp, " mov si, dx\n");\r
- fprintf(fp, " add esi, ebp\n");\r
- fprintf(fp, " xor edx, edx\n");\r
- }\r
- else \r
- {\r
- fprintf(fp, " mov dx, word [_z80sp] ; Get our current stack pointer\n");\r
- fprintf(fp, " mov si, [edx+ebp] ; Get our return address\n");\r
- fprintf(fp, " and esi, 0ffffh ; Only within 64K!\n");\r
- fprintf(fp, " add esi, ebp ; Add in our base address\n");\r
- fprintf(fp, " add word [_z80sp], 02h ; Remove our two bytes from the stack\n");\r
- fprintf(fp, " xor edx, edx\n");\r
- }\r
-\r
- if (dwOpcode != 0xc9)\r
- fprintf(fp, "retNotTaken%ld:\n", dwGlobalLabel++);\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (dwOpcode != 0xc9)\r
- {\r
- fprintf(fp, " if %s\n", pbFlagsC[(dwOpcode >> 3) & 0x07]);\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " dwElapsedTicks += 6;\n");\r
- }\r
-\r
- fprintf(fp, " pbSP = cpu.z80Base + cpu.z80sp; /* Normalize our stack PTR */\n");\r
- fprintf(fp, " dwAddr = *pbSP++; /* Pop LSB */\n");\r
- fprintf(fp, " dwAddr |= ((UINT32) *pbSP << 8); /* Pop MSB */\n");\r
- fprintf(fp, " cpu.z80sp += 2; /* Pop the word off */\n");\r
- fprintf(fp, " pbPC = (cpu.z80Base + dwAddr); /* Point PC to our return address */\n");\r
-\r
- if (dwOpcode != 0xc9)\r
- {\r
- fprintf(fp, " }\n");\r
- }\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void RestartHandler(UINT32 dwOpcode)\r
-{\r
- UINT32 dwOpcode1 = 0;\r
-\r
- dwOpcode1 = dwOpcode & 0x38;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (bThroughCallHandler)\r
- {\r
- fprintf(fp, " sub esi, ebp\n");\r
- fprintf(fp, " mov [_wordval], si ; Store our return address\n");\r
- fprintf(fp, " call PushWord\n");\r
- fprintf(fp, " xor esi, esi\n");\r
- fprintf(fp, " mov si, %.4lxh\n", dwOpcode1);\r
- fprintf(fp, " add esi, ebp\n");\r
- }\r
- else \r
- {\r
- fprintf(fp, " mov dx, word [_z80sp] ; Get our stack pointer\n");\r
- fprintf(fp, " sub dx, 2 ; Make room for the new value!\n");\r
- fprintf(fp, " mov word [_z80sp], dx ; Store our new stack pointer\n");\r
- fprintf(fp, " sub esi, ebp ; Get our real PC\n");\r
- fprintf(fp, " mov [ebp+edx], si ; Our return address\n");\r
- fprintf(fp, " mov si, 0%.2xh ; Our new call address\n", dwOpcode1);\r
- fprintf(fp, " add esi, ebp ; Back to the base!\n");\r
- }\r
- \r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;\n");\r
- fprintf(fp, " pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */\n");\r
- fprintf(fp, " *pbSP-- = cpu.z80pc >> 8; /* LSB */\n");\r
- fprintf(fp, " *pbSP = (UINT8) cpu.z80pc; /* MSB */\n");\r
- fprintf(fp, " cpu.z80sp -= 2; /* Back our stack up */\n");\r
- fprintf(fp, " pbPC = cpu.z80Base + 0x%.2x; /* Normalize the address */\n", dwOpcode1);\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void ToRegFromHl(UINT32 dwOpcode)\r
-{\r
- UINT8 bReg;\r
-\r
- bReg = (dwOpcode >> 3) & 0x07;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (bReg != 2 && bReg != 3)\r
- ReadValueFromMemory("bx", pbMathReg[bReg]);\r
- else\r
- {\r
- ReadValueFromMemory("bx", pbLocalReg[bReg]);\r
- fprintf(fp, " mov %s, %s\n", pbMathReg[bReg], pbLocalReg[bReg]);\r
- }\r
-\r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- ReadValueFromMemory("cpu.z80HL", pbLocalRegC[bReg]);\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void AddRegpairOperations(UINT32 dwOpcode)\r
-{\r
- UINT8 bRegpair;\r
-\r
- bRegpair = (dwOpcode >> 4) & 0x3;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " mov dh, ah ; Get our flags\n");\r
- fprintf(fp, " and dh, 0ech ; Preserve the top three and bits 2 & 3\n");\r
- \r
- fprintf(fp, " mov [_orgval], bx ; Store our original value\n");\r
- fprintf(fp, " add bx, %s\n", pbRegPairs[bRegpair]);\r
- fprintf(fp, " lahf\n");\r
- \r
- fprintf(fp, " mov [cyclesRemaining], edi\n");\r
- fprintf(fp, " mov di, [_orgval] ; Get original\n");\r
- fprintf(fp, " xor di, bx ; XOR It with our computed value\n");\r
- fprintf(fp, " xor di, %s\n", pbRegPairs[bRegpair]);\r
- fprintf(fp, " and di, 1000h ; Just our half carry\n");\r
- fprintf(fp, " or dx, di ; Or in our flags\n");\r
- fprintf(fp, " and ah, 01h ; Just carry\n");\r
- fprintf(fp, " or ah, dh\n");\r
- fprintf(fp, " mov edi, [cyclesRemaining]\n"); \r
- fprintf(fp, " xor edx, edx\n"); \r
- \r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);\n");\r
- fprintf(fp, " dwTemp = cpu.z80HL + %s;\n", pbRegPairsC[bRegpair]);\r
- fprintf(fp, " cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY) | (((cpu.z80HL ^ dwTemp ^ %s) >> 8) & Z80_FLAG_HALF_CARRY);\n", pbRegPairsC[bRegpair]);\r
- fprintf(fp, " cpu.z80HL = dwTemp & 0xffff;\n");\r
-\r
- return;\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void PushPopOperations(UINT32 dwOpcode)\r
-{\r
- UINT8 bRegPair;\r
-\r
- bRegPair = ((dwOpcode >> 4) & 0x3) << 1;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if ((dwOpcode & 0xcf) == 0xc5) // Push\r
- {\r
- fprintf(fp, " sub word [_z80sp], 2\n");\r
- fprintf(fp, " mov dx, [_z80sp]\n");\r
- WriteWordToMemory("dx", pbPopRegPairs[bRegPair >> 1]);\r
- }\r
- else // Pop\r
- {\r
- fprintf(fp, " mov dx, [_z80sp]\n");\r
- ReadWordFromMemory("dx", pbPopRegPairs[bRegPair >> 1]);\r
- fprintf(fp, " add word [_z80sp], 2\n");\r
- } \r
-\r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if ((dwOpcode & 0xcf) == 0xc5) // Push?\r
- {\r
- fprintf(fp, " cpu.z80sp -= 2;\n");\r
- fprintf(fp, " pbSP = (cpu.z80Base + cpu.z80sp); /* Normalize the stack pointer */\n");\r
- \r
- WriteWordToMemory("cpu.z80sp", pbPopRegPairC[bRegPair >> 1]);\r
- return;\r
- }\r
- else\r
- {\r
- ReadWordFromMemory("cpu.z80sp", pbPopRegPairC[bRegPair >> 1]);\r
-\r
- fprintf(fp, " cpu.z80sp += 2;\n");\r
- fprintf(fp, " pbSP = (cpu.z80Base + cpu.z80sp); /* Normalize the stack pointer */\n");\r
- return;\r
- }\r
- \r
- InvalidInstructionC(1);\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void RraRlaHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " sahf\n");\r
- if (dwOpcode == 0x1f)\r
- fprintf(fp, " rcr al, 1\n");\r
- else\r
- fprintf(fp, " rcl al, 1\n");\r
- \r
- fprintf(fp, " lahf\n");\r
- fprintf(fp, " and ah, 0edh\n");\r
- \r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (0x1f == dwOpcode) // RRA\r
- {\r
- fprintf(fp, " bTemp = (cpu.z80F & Z80_FLAG_CARRY) << 7;\n");\r
- fprintf(fp, " cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY)) | (cpu.z80A & Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80A = ((cpu.z80A >> 1) | bTemp);\n");\r
- }\r
- else // RLA\r
- {\r
- fprintf(fp, " bTemp = cpu.z80A >> 7;\n");\r
- fprintf(fp, " cpu.z80A = (cpu.z80A << 1) | (cpu.z80F & Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80F = (cpu.z80F & ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY)) | bTemp;\n");\r
- }\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void LdByteRegpair(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (dwOpcode == 0x0a)\r
- ReadValueFromMemory("cx", "al");\r
- if (dwOpcode == 0x1a)\r
- {\r
- fprintf(fp, " mov dx, [_z80de]\n");\r
- ReadValueFromMemory("dx", "al");\r
- }\r
-\r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (dwOpcode == 0x0a)\r
- ReadValueFromMemory("cpu.z80BC", "cpu.z80A");\r
- if (dwOpcode == 0x1a)\r
- ReadValueFromMemory("cpu.z80DE", "cpu.z80A");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void IncDecHLPtr(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- ReadValueFromMemory("bx", "dl");\r
-\r
- fprintf(fp, " sahf\n");\r
-\r
- if (dwOpcode == 0x34)\r
- fprintf(fp, " inc dl\n");\r
- else\r
- fprintf(fp, " dec dl\n");\r
- fprintf(fp, " lahf\n");\r
-\r
- fprintf(fp, " o16 pushf\n");\r
- fprintf(fp, " shl edx, 16\n");\r
- fprintf(fp, " and ah, 0fbh ; Knock out parity/overflow\n");\r
- fprintf(fp, " pop dx\n");\r
- fprintf(fp, " and dh, 08h ; Just the overflow\n");\r
- fprintf(fp, " shr dh, 1 ; Shift it into position\n");\r
- fprintf(fp, " or ah, dh ; OR It in with the real flags\n");\r
- \r
- fprintf(fp, " shr edx, 16\n");\r
- \r
- if (dwOpcode == 0x34)\r
- fprintf(fp, " and ah, 0fdh ; Knock out N!\n");\r
- else\r
- fprintf(fp, " or ah, 02h ; Make it N!\n");\r
- \r
- WriteValueToMemory("bx", "dl");\r
- fprintf(fp, " xor edx, edx\n");\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- ReadValueFromMemory("cpu.z80HL", "bTemp");\r
-\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);\n");\r
-\r
- if (0x34 == dwOpcode)\r
- fprintf(fp ," cpu.z80F |= bPostIncFlags[bTemp];\n");\r
- else\r
- fprintf(fp ," cpu.z80F |= bPostDecFlags[bTemp];\n");\r
- \r
- if (0x34 == dwOpcode)\r
- fprintf(fp, " bTemp++;\n");\r
- else\r
- fprintf(fp, " bTemp--;\n");\r
- \r
- WriteValueToMemory("cpu.z80HL", "bTemp");\r
- return;\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void InOutHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " mov dl, [esi] ; Get our address to 'out' to\n");\r
- fprintf(fp, " inc esi ; Next address\n");\r
-\r
- if (b16BitIo)\r
- {\r
- fprintf(fp, " mov dh, al ; Upper 8 bits are the A register for 16 bit addressing\n");\r
- }\r
-\r
- if (0xd3 == dwOpcode)\r
- WriteValueToIo("dx", "al");\r
- else\r
- ReadValueFromIo("dx", "al");\r
-\r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp ," dwTemp = *pbPC++;\n");\r
-\r
- if (0xd3 == dwOpcode)\r
- WriteValueToIo("dwTemp", "cpu.z80A");\r
- else\r
- ReadValueFromIo("dwTemp", "cpu.z80A");\r
-\r
- // Not supposed to set flags for immediate instruction!\r
-\r
- return;\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-// CB Area\r
-\r
-void RESSETHandler(UINT32 dwOpcode)\r
-{\r
- UINT8 op = 0;\r
-\r
- op = dwOpcode & 0x07;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if ((2 == op) || (3 == op))\r
- fprintf(fp, " mov dx, [_z80de] ; Move DE into something half usable\n");\r
-\r
- if ((dwOpcode & 0x07) == 6) // (HL)?\r
- ReadValueFromMemory("bx", "dl");\r
-\r
- if ((dwOpcode & 0xc0) == 0x80)\r
- fprintf(fp, " and %s, 0%.2xh ; Reset a bit\n", \r
- pbLocalReg[op],\r
- 0xff - (1 << ((dwOpcode >> 3) & 0x7)));\r
-\r
- if ((dwOpcode & 0xc0) == 0xc0)\r
- fprintf(fp, " or %s, 0%.2xh ; Set a bit\n", \r
- pbLocalReg[op],\r
- (1 << ((dwOpcode >> 3) & 0x7)));\r
-\r
- if ((2 == op) || (3 == op))\r
- {\r
- fprintf(fp, " mov [_z80de], dx ; Once modified, put it back\n");\r
- fprintf(fp, " xor edx, edx\n");\r
- }\r
-\r
- if ((dwOpcode & 0x07) == 6) // (HL)?\r
- {\r
- WriteValueToMemory("bx", "dl");\r
- fprintf(fp, " xor edx, edx\n");\r
- }\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (6 == op) // (HL)?\r
- ReadValueFromMemory("cpu.z80HL", "bTemp");\r
-\r
- if ((dwOpcode & 0xc0) == 0x80) // RES\r
- fprintf(fp, " %s &= 0x%.2x;\n", pbMathRegC[op], (UINT8) ~((UINT8) 1 << ((dwOpcode >> 3) & 0x07)));\r
- else // SET\r
- fprintf(fp, " %s |= 0x%.2x;\n", pbMathRegC[op], 1 << ((dwOpcode >> 3) & 0x07));\r
-\r
- if (6 == op) // (HL)?\r
- WriteValueToMemory("cpu.z80HL", "bTemp");\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void BITHandler(UINT32 dwOpcode)\r
-{\r
- UINT8 op = 0;\r
- UINT8 bBitVal = 0;\r
-\r
- op = dwOpcode & 0x07;\r
- bBitVal = 1 << ((dwOpcode >> 3) & 0x07);\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if ((dwOpcode & 0x07) == 6) // (HL)?\r
- ReadValueFromMemory("bx", "dl");\r
-\r
- fprintf(fp, " mov byte [_z80af], ah ; Store F\n");\r
- fprintf(fp, " sahf\n");\r
-\r
- if ((dwOpcode & 0x07) == 6)\r
- fprintf(fp, " test dl, 0%.2xh ; Do a bitwise check\n", 1 << ((dwOpcode >> 3) & 0x7));\r
- else\r
- fprintf(fp, " test %s, 0%.2xh ; Do a bitwise check\n", pbMathReg[op], 1 << ((dwOpcode >> 3) & 0x7));\r
-\r
- fprintf(fp, " lahf\n");\r
- fprintf(fp, " and ah, 0c0h ; Only care about Z and S\n");\r
- fprintf(fp, " or ah, 10h ; Set half carry to 1\n");\r
-\r
- fprintf(fp, " and byte [_z80af], 029h ; Only zero/non-zero!\n");\r
- fprintf(fp, " or ah, byte [_z80af] ; Put it in with the real flags\n");\r
-\r
- if (6 == (dwOpcode & 0x07)) // (HL)?\r
- fprintf(fp, " xor edx, edx\n");\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (6 == op) // (HL)?\r
- ReadValueFromMemory("cpu.z80HL", "bTemp");\r
-\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO);\n");\r
- fprintf(fp, " cpu.z80F |= (Z80_FLAG_HALF_CARRY);\n");\r
- fprintf(fp, " if (!(%s & 0x%.2lx))\n", pbMathRegC[op], bBitVal);\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80F |= Z80_FLAG_ZERO;\n");\r
- fprintf(fp, " }\n");\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void RLCRRCRLRRSLASRASRLHandler(UINT32 dwOpcode)\r
-{\r
- UINT8 op = 0;\r
-\r
- op = dwOpcode & 0x07;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if ((2 == op) || (3 == op))\r
- fprintf(fp, " mov dx, [_z80de] ; Move DE into something half usable\n");\r
-\r
- if ((dwOpcode & 0x07) == 6) // (HL)?\r
- ReadValueFromMemory("bx", "dl");\r
-\r
- fprintf(fp, " sahf\n");\r
-\r
- if ((dwOpcode & 0xf8) == 0)\r
- fprintf(fp, " rol %s, 1\n", pbLocalReg[op]);\r
- else\r
- if ((dwOpcode & 0xf8) == 0x08)\r
- fprintf(fp, " ror %s, 1\n", pbLocalReg[op]);\r
- else\r
- if ((dwOpcode & 0xf8) == 0x10)\r
- fprintf(fp, " rcl %s, 1\n", pbLocalReg[op]);\r
- else\r
- if ((dwOpcode & 0xf8) == 0x18)\r
- fprintf(fp, " rcr %s, 1\n", pbLocalReg[op]);\r
- else\r
- if ((dwOpcode & 0xf8) == 0x20 || (dwOpcode & 0xf8) == 0x30)\r
- fprintf(fp, " shl %s, 1\n", pbLocalReg[op]);\r
- else\r
- if ((dwOpcode & 0xf8) == 0x28)\r
- fprintf(fp, " sar %s, 1\n", pbLocalReg[op]);\r
- else\r
- if ((dwOpcode & 0xf8) == 0x38)\r
- fprintf(fp, " shr %s, 1\n", pbLocalReg[op]);\r
- else\r
- assert(0);\r
- \r
- fprintf(fp, " lahf\n");\r
-\r
- if ((dwOpcode & 0xf8) >= 0x20)\r
- {\r
- if ((dwOpcode & 0xf8) == 0x30)\r
- fprintf(fp, " or %s, 1 ; Slide in a 1 bit (SLIA)\n", pbLocalReg[op]);\r
- fprintf(fp, " and ah, 0edh ; Clear H and N\n");\r
- }\r
- else\r
- {\r
- fprintf(fp, " and ah, 029h ; Clear H and N\n");\r
- fprintf(fp, " mov byte [_z80af], ah\n");\r
-\r
- fprintf(fp, " or %s, %s\n", pbLocalReg[op], pbLocalReg[op]);\r
- \r
- fprintf(fp, " lahf\n");\r
- fprintf(fp, " and ah, 0c4h ; Sign, zero, and parity\n");\r
- fprintf(fp, " or ah, byte [_z80af]\n");\r
- }\r
-\r
- if ((2 == op) || (3 == op))\r
- {\r
- fprintf(fp, " mov [_z80de], dx ; Once modified, put it back\n");\r
- fprintf(fp, " xor edx, edx\n");\r
- }\r
-\r
- if ((dwOpcode & 0x07) == 6) // (HL)?\r
- {\r
- WriteValueToMemory("bx", "dl");\r
- fprintf(fp, " xor edx, edx\n");\r
- }\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (6 == op) // (HL)?\r
- ReadValueFromMemory("cpu.z80HL", "bTemp");\r
-\r
- dwOpcode &= 0xf8; // Just the instruction\r
-\r
- if (0 == dwOpcode) // RLC\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " bTemp2 = (%s >> 7);\n", pbMathRegC[op]);\r
- fprintf(fp, " %s = (%s << 1) | bTemp2;\n", pbMathRegC[op], pbMathRegC[op]);\r
- fprintf(fp, " cpu.z80F |= bTemp2 | bPostORFlags[%s];\n", pbMathRegC[op]);\r
- }\r
- else\r
- if (0x08 == dwOpcode) // RRC\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80F |= (%s & Z80_FLAG_CARRY);\n", pbMathRegC[op]);\r
- fprintf(fp, " %s = (%s >> 1) | (%s << 7);\n", pbMathRegC[op], pbMathRegC[op], pbMathRegC[op]);\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[%s];\n", pbMathRegC[op]);\r
- }\r
- else\r
- if (0x10 == dwOpcode) // RL\r
- {\r
- fprintf(fp, " bTemp2 = cpu.z80F & Z80_FLAG_CARRY;\n");\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80F |= (%s >> 7);\n", pbMathRegC[op]);\r
- fprintf(fp, " %s = (%s << 1) | bTemp2;\n", pbMathRegC[op], pbMathRegC[op]);\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[%s];\n", pbMathRegC[op]);\r
- }\r
- else\r
- if (0x18 == dwOpcode) // RR\r
- {\r
- fprintf(fp, " bTemp2 = (cpu.z80F & Z80_FLAG_CARRY) << 7;\n");\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80F |= (%s & Z80_FLAG_CARRY);\n", pbMathRegC[op]);\r
- fprintf(fp, " %s = (%s >> 1) | bTemp2;\n", pbMathRegC[op], pbMathRegC[op]);\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[%s];\n", pbMathRegC[op]);\r
- }\r
- else\r
- if ((0x20 == dwOpcode) || (0x30 == dwOpcode)) // SLA/SRL\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80F |= (%s >> 7);\n", pbMathRegC[op]);\r
- fprintf(fp, " %s = (%s << 1);\n", pbMathRegC[op], pbMathRegC[op]);\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[%s];\n", pbMathRegC[op]);\r
- }\r
- else\r
- if (0x28 == dwOpcode) // SRA\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80F |= (%s & Z80_FLAG_CARRY);\n", pbMathRegC[op]);\r
- fprintf(fp, " %s = (%s >> 1) | (%s & 0x80);\n", pbMathRegC[op], pbMathRegC[op], pbMathRegC[op]);\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[%s];\n", pbMathRegC[op]);\r
- }\r
- else\r
- if (0x38 == dwOpcode) // SRL\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80F |= (%s & Z80_FLAG_CARRY);\n", pbMathRegC[op]);\r
- fprintf(fp, " %s = (%s >> 1);\n", pbMathRegC[op], pbMathRegC[op], pbMathRegC[op]);\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[%s];\n", pbMathRegC[op]);\r
- }\r
- else\r
- {\r
- InvalidInstructionC(2);\r
- }\r
-\r
- if (6 == op) // (HL)?\r
- WriteValueToMemory("cpu.z80HL", "bTemp");\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-// ED Area\r
-\r
-void RRDRLDHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- ReadValueFromMemory("bx", "dl"); // Get (HL)\r
- fprintf(fp, " mov dh, dl ; Put a copy in DH\n");\r
-\r
- if (0x6f == dwOpcode) // RLD\r
- {\r
- fprintf(fp, " shr dh, 4 ; Get our upper nibble in position\n");\r
- fprintf(fp, " shl dl, 4 ; Get our lower nibble into the higher position\n");\r
- fprintf(fp, " shl ecx, 16 ; Save this for later\n");\r
- fprintf(fp, " mov cl, al\n");\r
- fprintf(fp, " and cl, 0fh\n ; Only the lower nibble\n");\r
- fprintf(fp, " or dl, cl ; OR In A->(HL) transfer\n");\r
- fprintf(fp, " and al, 0f0h ; Only the upper 4 bits remain\n");\r
- fprintf(fp, " or al, dh ; OR It in to our accumulator\n");\r
- fprintf(fp, " shr ecx, 16 ; Restore this\n");\r
- }\r
- else // RRD\r
- if (0x67 == dwOpcode)\r
- {\r
- fprintf(fp, " shr dl, 4 ; Upper nibble to lower nibble\n");\r
- fprintf(fp, " shl ecx, 16 ; Save this\n");\r
- fprintf(fp, " mov cl, al\n");\r
- fprintf(fp, " shl cl, 4\n");\r
- fprintf(fp, " or dl, cl ; OR In what was in A\n");\r
- fprintf(fp, " and al, 0f0h ; Knock out lower part\n");\r
- fprintf(fp, " and dh, 0fh ; Only the lower nibble\n");\r
- fprintf(fp, " or al, dh ; OR In our nibble\n");\r
- fprintf(fp, " shr ecx, 16 ; Restore this\n");\r
- }\r
- else // Whoops!\r
- assert(0);\r
-\r
- // This routine assumes that the new value to be placed at (HL) is in DL\r
-\r
- fprintf(fp, " and ah, 29h ; Retain carry & two undefined bits\n");\r
- fprintf(fp, " mov dh, ah ; Store our flags away for later\n");\r
-\r
- fprintf(fp, " or al, al ; Get our flags\n");\r
- fprintf(fp, " lahf\n");\r
- fprintf(fp, " and ah,0c4h ; Only partiy, zero, and sign\n");\r
- fprintf(fp, " or ah, dh ; OR In our old flags\n");\r
-\r
- // Now go write the value back\r
-\r
- WriteValueToMemory("bx", "dl");\r
- fprintf(fp, " xor edx, edx ; Zero out this for later\n");\r
- \r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (0x67 == dwOpcode) // RRD\r
- {\r
- ReadValueFromMemory("cpu.z80HL", "bTemp");\r
- fprintf(fp, " bTemp2 = (cpu.z80A & 0x0f) << 4;\n");\r
- fprintf(fp, " cpu.z80A = (cpu.z80A & 0xf0) | (bTemp & 0x0f);\n");\r
- fprintf(fp, " bTemp = (bTemp >> 4) | bTemp2;\n");\r
-\r
- WriteValueToMemory("cpu.z80HL", "bTemp");\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[cpu.z80A];\n");\r
- }\r
- else\r
- if (0x6f == dwOpcode) // RLD\r
- {\r
- ReadValueFromMemory("cpu.z80HL", "bTemp");\r
-\r
- fprintf(fp, " bTemp2 = (cpu.z80A & 0x0f);\n");\r
- fprintf(fp, " cpu.z80A = (cpu.z80A & 0xf0) | (bTemp >> 4);\n");\r
- fprintf(fp, " bTemp = (bTemp << 4) | bTemp2;\n");\r
-\r
- WriteValueToMemory("cpu.z80HL", "bTemp");\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[cpu.z80A];\n");\r
- }\r
- else\r
- InvalidInstructionC(2);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void CPICPDCPIRCPDRHandler(UINT32 dwOpcode)\r
-{\r
- UINT32 dwRepeatOb = 0;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (dwOpcode == 0xb1 || dwOpcode == 0xb9)\r
- {\r
- fprintf(fp, "cpRepeat%ld:\n", dwGlobalLabel);\r
- dwRepeatOb = dwGlobalLabel;\r
- ++dwGlobalLabel;\r
- }\r
-\r
- // Now go get the data from the source\r
-\r
- ReadValueFromMemory("bx", "dl");\r
-\r
- // Target data is in DL\r
-\r
- fprintf(fp, " mov byte [_z80af], ah\n");\r
- fprintf(fp, " sahf\n");\r
- fprintf(fp, " cmp al, dl ; Do our comparison\n");\r
- fprintf(fp, " lahf\n");\r
- fprintf(fp, " and ah, 0fah ; No P/V or carry!\n");\r
- fprintf(fp, " dec cx ; Dec BC\n");\r
- fprintf(fp, " jz notBcZero%ld\n", dwGlobalLabel);\r
- fprintf(fp, " or ah, 04h ; P/V set when BC not zero\n");\r
- fprintf(fp, "notBcZero%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " or ah, 02h ; N Gets set when we do compares\n");\r
- fprintf(fp, " mov dl, byte [_z80af]\n");\r
- fprintf(fp, " and dl, 01h\n");\r
- fprintf(fp, " or ah, dl ; Preserve carry!\n");\r
- \r
- if (dwOpcode == 0xa1 || dwOpcode == 0xb1)\r
- fprintf(fp, " inc bx ; Increment!\n");\r
- if (dwOpcode == 0xa9 || dwOpcode == 0xb9)\r
- fprintf(fp, " dec bx ; Decrement!\n");\r
-\r
- // Let's see if we repeat...\r
- \r
- if (dwOpcode == 0xb1 || dwOpcode == 0xb9)\r
- {\r
- fprintf(fp, " sahf\n");\r
- fprintf(fp, " jz BCDone%ld\n", dwRepeatOb);\r
- fprintf(fp, " jnp BCDone%ld\n", dwRepeatOb);\r
-\r
- if (FALSE == bNoTiming)\r
- {\r
- fprintf(fp, " sub edi, dword 21\n");\r
- fprintf(fp, " js BCDoneExit%ld\n", dwRepeatOb);\r
- }\r
-\r
- fprintf(fp, " jmp cpRepeat%ld\n", dwRepeatOb);\r
-\r
- fprintf(fp, "BCDoneExit%ld:\n", dwRepeatOb);\r
- fprintf(fp, " sub esi, 2 ; Back up to the instruction again\n");\r
- fprintf(fp, " jmp noMoreExec\n\n");\r
- fprintf(fp, "BCDone%ld:\n", dwRepeatOb);\r
- }\r
- \r
- fprintf(fp, " xor edx, edx\n");\r
- \r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (0xb1 == dwOpcode || 0xb9 == dwOpcode) // Repeat instruction?\r
- {\r
- fprintf(fp, " while ((sdwCyclesRemaining >= 0) && (cpu.z80BC))\n");\r
- }\r
-\r
- fprintf(fp, " {\n"); \r
-\r
- ReadValueFromMemory("cpu.z80HL", "bTemp");\r
-\r
- if (0xb1 == dwOpcode || 0xa1 == dwOpcode)\r
- {\r
- fprintf(fp, " cpu.z80HL++;\n");\r
- fprintf(fp, " cpu.z80HL &= 0xffff;\n");\r
- }\r
- else\r
- {\r
- fprintf(fp, " cpu.z80HL--;\n");\r
- fprintf(fp, " cpu.z80HL &= 0xffff;\n");\r
- }\r
-\r
- fprintf(fp, " cpu.z80BC--;\n");\r
- fprintf(fp, " cpu.z80BC &= 0xffff;\n");\r
-\r
- if (0xb1 == dwOpcode || 0xb9 == dwOpcode) // Repeat?\r
- {\r
- fprintf(fp, " sdwCyclesRemaining -= 16;\n");\r
- fprintf(fp, " if (cpu.z80A == bTemp)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " break;\n");\r
- fprintf(fp, " }\n");\r
- }\r
-\r
- fprintf(fp, " }\n");\r
-\r
- // Now figure out what's going on\r
-\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);\n");\r
- fprintf(fp, " cpu.z80F |= (pbSubSbcTable[((UINT32) cpu.z80A << 8) | bTemp] & (Z80_FLAG_SIGN | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO));\n");\r
- fprintf(fp, " if (cpu.z80BC)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;\n");\r
-\r
- fprintf(fp, " }\n");\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void INIRINDRINIINDHandler(UINT32 dwOpcode)\r
-{\r
- UINT32 dwTempLabel = 0;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- dwTempLabel = dwGlobalLabel;\r
- dwGlobalLabel++;\r
-\r
- if (0xba == dwOpcode || 0xb2 == dwOpcode)\r
- fprintf(fp, "loopIt%ld:\n", dwTempLabel);\r
-\r
- // Fetch what's at (C) and put it in (HL)\r
-\r
- fprintf(fp, " push cx ; Save BC\n");\r
- \r
- if (b16BitIo == FALSE)\r
- fprintf(fp, " xor ch, ch ; We want 8 bit ports\n");\r
- \r
- ReadValueFromIo("cx", "*dl"); // Put our value in DL\r
- fprintf(fp, " pop cx ; Restore BC\n");\r
- \r
- WriteValueToMemory("bx", "dl");\r
- \r
- if (0xa2 == dwOpcode || 0xb2 == dwOpcode)\r
- fprintf(fp, " inc bx ; Increment HL\n");\r
- else\r
- if (0xaa == dwOpcode || 0xba == dwOpcode)\r
- fprintf(fp, " dec bx ; Decrement HL\n");\r
- \r
- // Now we decrement B\r
- \r
- fprintf(fp, " dec ch ; Decrement B (of C)\n");\r
- \r
- // Emit this instruction if we repeat\r
- \r
- if (0xba == dwOpcode || 0xb2 == dwOpcode)\r
- {\r
- fprintf(fp, " jz near finalExit%ld\n", dwTempLabel);\r
-\r
- // Otherwise, we need to loop again\r
-\r
- if (FALSE == bNoTiming)\r
- {\r
- fprintf(fp, " sub edi, dword 21\n");\r
- fprintf(fp, " js loopExit%ld\n", dwTempLabel);\r
- }\r
-\r
- fprintf(fp, " jmp loopIt%ld\n\n", dwTempLabel);\r
- fprintf(fp, "loopExit%ld:\n", dwTempLabel);\r
- fprintf(fp, " sub esi, 2\n");\r
- fprintf(fp, " jmp noMoreExec\n\n");\r
- }\r
- \r
- // Now let's fix up the flags\r
-\r
- fprintf(fp, "finalExit%ld:\n", dwTempLabel); \r
- fprintf(fp, " jnz clearFlag%ld\n", dwTempLabel);\r
- fprintf(fp, " or ah, 040h ; Set the Zero flag!\n");\r
- fprintf(fp, " jmp short continue%ld\n", dwTempLabel);\r
- fprintf(fp, "clearFlag%ld:\n", dwTempLabel);\r
- fprintf(fp, " and ah, 0bfh ; Clear the zero flag\n");\r
- fprintf(fp, "continue%ld:\n", dwTempLabel);\r
- fprintf(fp, " or ah, 02h ; Set negative!\n");\r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (0xb2 == dwOpcode || 0xba == dwOpcode) // Repeat instruction?\r
- {\r
- fprintf(fp, " while ((sdwCyclesRemaining > 0) && (cpu.z80B))\n");\r
- }\r
-\r
- fprintf(fp, " {\n"); \r
-\r
- ReadValueFromIo("cpu.z80B", "bTemp");\r
- WriteValueToMemory("cpu.z80HL", "bTemp");\r
-\r
- if (0xb2 == dwOpcode || 0xa2 == dwOpcode)\r
- {\r
- fprintf(fp, " cpu.z80HL++;\n");\r
- fprintf(fp, " cpu.z80HL &= 0xffff;\n");\r
- }\r
- else\r
- {\r
- fprintf(fp, " cpu.z80HL--;\n");\r
- fprintf(fp, " cpu.z80HL &= 0xffff;\n");\r
- }\r
-\r
- fprintf(fp, " sdwCyclesRemaining -= 16;\n");\r
- \r
- fprintf(fp, " cpu.z80B--;\n");\r
- fprintf(fp, " }\n");\r
-\r
- // Now figure out what's going on\r
-\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);\n");\r
- fprintf(fp, " cpu.z80F |= (bPostORFlags[bTemp] & (Z80_FLAG_SIGN | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY));\n");\r
- fprintf(fp, " if (cpu.z80B)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;\n");\r
-\r
- fprintf(fp, " pbPC -= 2;\n");\r
-\r
- fprintf(fp, " }\n");\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void OTIROTDROUTIOUTDHandler(UINT32 dwOpcode)\r
-{\r
- UINT32 dwTempLabel = 0;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- dwTempLabel = dwGlobalLabel;\r
- dwGlobalLabel++;\r
-\r
- if (0xbb == dwOpcode || 0xb3 == dwOpcode)\r
- fprintf(fp, "loopIt%ld:\n", dwTempLabel);\r
-\r
- // Fetch what's at (HL) and put it in DL\r
-\r
- ReadValueFromMemory("bx", "dl");\r
-\r
- fprintf(fp, " push cx ; Save BC\n");\r
- if (b16BitIo == FALSE)\r
- fprintf(fp, " xor ch, ch ; No 16 bit for this instruction!\n");\r
- WriteValueToIo("cx", "dl");\r
- fprintf(fp, " pop cx ; Restore BC now that it has been \"OUT\"ed\n");\r
- \r
- if (0xa3 == dwOpcode || 0xb3 == dwOpcode)\r
- fprintf(fp, " inc bx ; Increment HL\n");\r
- else\r
- if (0xab == dwOpcode || 0xbb == dwOpcode)\r
- fprintf(fp, " dec bx ; Decrement HL\n");\r
- \r
- // Now we decrement B\r
-\r
- fprintf(fp, " dec ch ; Decrement B (of C)\n");\r
- \r
- // Emit this instruction if we repeat\r
- \r
- if (0xbb == dwOpcode || 0xb3 == dwOpcode)\r
- {\r
- fprintf(fp, " jz near finalExit%ld\n", dwTempLabel);\r
-\r
- // Otherwise, we need to loop again\r
-\r
- if (FALSE == bNoTiming)\r
- {\r
- fprintf(fp, " sub edi, dword 21\n");\r
- fprintf(fp, " js loopExit%ld\n", dwTempLabel);\r
- }\r
-\r
- fprintf(fp, " jmp loopIt%ld\n\n", dwTempLabel);\r
- fprintf(fp, "loopExit%ld:\n", dwTempLabel);\r
- fprintf(fp, " sub esi, 2\n");\r
- fprintf(fp, " jmp noMoreExec\n\n");\r
- }\r
- \r
- // Now let's fix up the flags\r
-\r
- fprintf(fp, "finalExit%ld:\n", dwTempLabel); \r
- fprintf(fp, " jnz clearFlag%ld\n", dwTempLabel);\r
- fprintf(fp, " or ah, 040h ; Set the Zero flag!\n");\r
- fprintf(fp, " jmp short continue%ld\n", dwTempLabel);\r
- fprintf(fp, "clearFlag%ld:\n", dwTempLabel);\r
- fprintf(fp, " and ah, 0bfh ; Clear the zero flag\n");\r
- fprintf(fp, "continue%ld:\n", dwTempLabel);\r
- fprintf(fp, " or ah, 02h ; Set negative!\n");\r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (0xb3 == dwOpcode || 0xbb == dwOpcode) // Repeat instruction?\r
- {\r
- fprintf(fp, " while ((sdwCyclesRemaining > 0) && (cpu.z80B))\n");\r
- }\r
-\r
- fprintf(fp, " {\n");\r
- \r
- ReadValueFromMemory("cpu.z80HL", "bTemp");\r
- WriteValueToIo("cpu.z80BC", "bTemp");\r
-\r
- if (0xb3 == dwOpcode || 0xa3 == dwOpcode)\r
- {\r
- fprintf(fp, " cpu.z80HL++;\n");\r
- fprintf(fp, " cpu.z80HL &= 0xffff;\n");\r
- }\r
- else\r
- {\r
- fprintf(fp, " cpu.z80HL--;\n");\r
- fprintf(fp, " cpu.z80HL &= 0xffff;\n");\r
- }\r
-\r
- fprintf(fp, " sdwCyclesRemaining -= 16;\n");\r
- \r
- fprintf(fp, " cpu.z80B--;\n");\r
- fprintf(fp, " }\n");\r
-\r
- // Now figure out what's going on\r
-\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);\n");\r
- fprintf(fp, " cpu.z80F |= (bPostORFlags[bTemp] & (Z80_FLAG_SIGN | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY));\n");\r
- fprintf(fp, " if (cpu.z80B)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;\n");\r
-\r
- fprintf(fp, " }\n");\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void AdcSbcRegpair(UINT32 dwOpcode)\r
-{\r
- UINT8 bOp = 0;\r
-\r
- bOp = (dwOpcode >> 4) & 0x03;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " mov dx, %s ; Get our original register\n", pbRegPairs[bOp]);\r
- fprintf(fp, " mov [_orgval], dx ; Store this for later half carry computation\n");\r
- fprintf(fp, " mov [_orgval2], bx ; Store this, too\n");\r
- fprintf(fp, " sahf ; Restore our flags\n");\r
-\r
- if ((dwOpcode & 0xcf) == 0x4a)\r
- fprintf(fp, " adc bx, dx ; Do the operation!\n");\r
- else\r
- fprintf(fp, " sbb bx, dx ; Do the operation!\n");\r
-\r
- fprintf(fp, " lahf ; Get our new flags\n");\r
- \r
- if ((dwOpcode & 0xcf) != 0x4a)\r
- {\r
- SetOverflow();\r
- fprintf(fp, " and ah, 0edh ; Knock out negative & half carry flags\n");\r
- fprintf(fp, " or ah, 02h ; Negative!\n");\r
- fprintf(fp, " mov [_z80hl], bx\n");\r
- fprintf(fp, " xor bx, [_orgval]\n");\r
- fprintf(fp, " xor bx, [_orgval2]\n");\r
- fprintf(fp, " and bh, 10h ; Half carry?\n");\r
- fprintf(fp, " or ah, bh ; OR It in if so\n");\r
- fprintf(fp, " mov bx, [_z80hl]\n");\r
- }\r
- else\r
- {\r
- SetOverflow();\r
- fprintf(fp, " and ah, 0edh ; Knock out negative & half carry flags\n");\r
- fprintf(fp, " mov [_z80hl], bx\n");\r
- fprintf(fp, " xor bx, [_orgval]\n");\r
- fprintf(fp, " xor bx, [_orgval2]\n");\r
- fprintf(fp, " and bh, 10h ; Half carry?\n");\r
- fprintf(fp, " or ah, bh ; OR It in if so\n");\r
- fprintf(fp, " mov bx, [_z80hl]\n");\r
- }\r
-\r
- fprintf(fp, " xor edx, edx ; Make sure we don't hose things\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if ((dwOpcode & 0xcf) == 0x4a) // ADC\r
- {\r
- fprintf(fp, " dwTemp = cpu.z80HL + %s + (cpu.z80F & Z80_FLAG_CARRY);\n", pbRegPairsC[bOp]);\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " cpu.z80F |= ((dwTemp >> 8) & Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " if (0 == (dwTemp & 0xffff))\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80F |= Z80_FLAG_ZERO;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " cpu.z80F |= (((cpu.z80HL ^ dwTemp ^ %s) >> 8) & Z80_FLAG_HALF_CARRY);\n", pbRegPairsC[bOp]);\r
- fprintf(fp, " cpu.z80F |= ((((%s ^ cpu.z80HL ^ 0x8000) & (%s ^ dwTemp)) >> 13) & Z80_FLAG_OVERFLOW_PARITY);\n", pbRegPairsC[bOp], pbRegPairsC[bOp]);\r
- fprintf(fp, " cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80HL = dwTemp & 0xffff;\n");\r
- return;\r
- }\r
- else // SBC\r
- {\r
- fprintf(fp, " dwTemp = cpu.z80HL - %s - (cpu.z80F & Z80_FLAG_CARRY);\n", pbRegPairsC[bOp]);\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " cpu.z80F |= ((dwTemp >> 8) & Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " if (0 == (dwTemp & 0xffff))\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80F |= Z80_FLAG_ZERO;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " cpu.z80F |= (((cpu.z80HL ^ dwTemp ^ %s) >> 8) & Z80_FLAG_HALF_CARRY);\n", pbRegPairsC[bOp]);\r
- fprintf(fp, " cpu.z80F |= ((((%s ^ cpu.z80HL) & (%s ^ dwTemp)) >> 13) & Z80_FLAG_OVERFLOW_PARITY);\n", pbRegPairsC[bOp], pbRegPairsC[bOp]);\r
- fprintf(fp, " cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80HL = dwTemp & 0xffff;\n");\r
- return;\r
- }\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void RetIRetNHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (bThroughCallHandler)\r
- {\r
- fprintf(fp, " call PopWord\n");\r
- fprintf(fp, " xor esi, esi\n");\r
- fprintf(fp, " mov si, dx\n");\r
- fprintf(fp, " add esi, ebp\n");\r
- }\r
- else \r
- {\r
- fprintf(fp, " mov dx, word [_z80sp] ; Get our current stack pointer\n");\r
- fprintf(fp, " mov si, [edx+ebp] ; Get our return address\n");\r
- fprintf(fp, " and esi, 0ffffh ; Only within 64K!\n");\r
- fprintf(fp, " add esi, ebp ; Add in our base address\n");\r
- fprintf(fp, " add word [_z80sp], 02h ; Remove our two bytes from the stack\n");\r
- }\r
- \r
- if (dwOpcode == 0x45)\r
- {\r
- fprintf(fp, " xor edx, edx\n");\r
- fprintf(fp, " mov dl, [_z80iff] ; Get interrupt flags\n");\r
- fprintf(fp, " shr dl, 1 ; Move IFF2->IFF1\n");\r
- fprintf(fp, " and [_z80iff], dword (~IFF1) ; Get rid of IFF 1\n");\r
- fprintf(fp, " and dl, IFF1 ; Just want the IFF 1 value now\n");\r
- fprintf(fp, " or dword [_z80iff], edx\n");\r
- }\r
-\r
- fprintf(fp, " xor edx, edx ; Make sure we don't hose things\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (0x4d == dwOpcode) // RETI\r
- {\r
- fprintf(fp, " pbSP = cpu.z80Base + cpu.z80sp; /* Normalize our stack PTR */\n");\r
- fprintf(fp, " dwAddr = *pbSP++; /* Pop LSB */\n");\r
- fprintf(fp, " dwAddr |= ((UINT32) *pbSP << 8); /* Pop MSB */\n");\r
- fprintf(fp, " cpu.z80sp += 2; /* Pop the word off */\n");\r
- fprintf(fp, " pbPC = (cpu.z80Base + dwAddr); /* Point PC to our return address */\n");\r
- }\r
- else\r
- if (0x45 == dwOpcode) // RETN\r
- {\r
- fprintf(fp, " pbSP = cpu.z80Base + cpu.z80sp; /* Normalize our stack PTR */\n");\r
- fprintf(fp, " dwAddr = *pbSP++; /* Pop LSB */\n");\r
- fprintf(fp, " dwAddr |= ((UINT32) *pbSP << 8); /* Pop MSB */\n");\r
- fprintf(fp, " cpu.z80sp += 2; /* Pop the word off */\n");\r
- fprintf(fp, " pbPC = (cpu.z80Base + dwAddr); /* Point PC to our return address */\n");\r
- fprintf(fp, " cpu.z80iff &= ~(IFF1); /* Keep IFF2 around */\n");\r
- fprintf(fp, " cpu.z80iff |= ((cpu.z80iff >> 1) & IFF1); /* IFF2->IFF1 */\n");\r
- }\r
- else\r
- {\r
- InvalidInstructionC(2);\r
- }\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void ExtendedOutHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (b16BitIo == FALSE)\r
- fprintf(fp, " mov dl, cl ; Address in DX... (C)\n");\r
- else\r
- fprintf(fp, " mov dx, cx ; Address in DX... (BC)\n");\r
- \r
- WriteValueToIo("dx", pbMathReg[(dwOpcode >> 3) & 0x07]);\r
-\r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (b16BitIo == FALSE)\r
- fprintf(fp, " dwAddr = cpu.z80C;\n");\r
- else\r
- fprintf(fp, " dwAddr = cpu.z80BC;\n");\r
-\r
- WriteValueToIo("dwAddr", pbMathRegC[(dwOpcode >> 3) & 0x07]);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void ExtendedInHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (b16BitIo == FALSE)\r
- fprintf(fp, " mov dl, cl ; Address in DX... (C)\n");\r
- else\r
- fprintf(fp, " mov dx, cx ; Address in DX... (BC)\n");\r
- \r
- ReadValueFromIo("dx", pbMathReg[(dwOpcode >> 3) & 0x07]);\r
-\r
- fprintf(fp, ";\n; Remember, this variant of the IN instruction modifies the flags\n;\n\n");\r
- fprintf(fp, " sahf ; Restore our flags\n");\r
- fprintf(fp, " mov dh, ah ; Save flags for later\n");\r
- \r
- if (0x50 == dwOpcode || 0x58 == dwOpcode)\r
- {\r
- fprintf(fp, " mov dl, %s\n", pbMathReg[(dwOpcode >> 3) & 0x07]);\r
- fprintf(fp, " or dl, dl\n");\r
- }\r
- else\r
- fprintf(fp, " or %s, %s;\n", pbMathReg[(dwOpcode >> 3) & 0x07], pbMathReg[(dwOpcode >> 3) & 0x07]);\r
-\r
- fprintf(fp, " lahf\n");\r
- fprintf(fp, " and dh, 029h ; Only keep carry and two unused flags\n");\r
- fprintf(fp, " and ah, 0d4h\n");\r
- fprintf(fp, " or ah, dh\n");\r
-\r
- fprintf(fp, " xor edx, edx\n");\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (b16BitIo == FALSE)\r
- fprintf(fp, " dwAddr = cpu.z80C;\n");\r
- else\r
- fprintf(fp, " dwAddr = cpu.z80BC;\n");\r
-\r
- ReadValueFromIo("dwAddr", pbMathRegC[(dwOpcode >> 3) & 0x07]);\r
-\r
- // Set flags!\r
-\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[%s];\n", pbMathRegC[(dwOpcode >> 3) & 0x07]);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void NegHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " sahf\n");\r
- fprintf(fp, " sub dh, al\n");\r
- fprintf(fp, " lahf\n");\r
- fprintf(fp, " mov al, dh\n");\r
- \r
- SetOverflow();\r
- fprintf(fp, " or ah, 02h\n");\r
- fprintf(fp, " xor edx, edx\n");\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- SetSubFlagsSZHVC("0", "cpu.z80A");\r
- fprintf(fp, " cpu.z80A = 0 - cpu.z80A;\n");\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void ExtendedRegIntoMemory(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " mov dx, [esi] ; Get our address to write to\n");\r
- fprintf(fp, " add esi, 2 ; Next address, please...\n");\r
-\r
- if (dwOpcode == 0x43)\r
- WriteValueToMemory("dx", "cl");\r
- if (dwOpcode == 0x53)\r
- WriteValueToMemory("dx", "byte [_z80de]");\r
- if (dwOpcode == 0x63)\r
- WriteValueToMemory("dx", "bl");\r
- if (dwOpcode == 0x73)\r
- WriteValueToMemory("dx", "byte [_z80sp]");\r
-\r
- fprintf(fp, " inc dx\n");\r
-\r
- if (dwOpcode == 0x43)\r
- WriteValueToMemory("dx", "ch");\r
- if (dwOpcode == 0x53)\r
- WriteValueToMemory("dx", "byte [_z80de + 1]");\r
- if (dwOpcode == 0x63)\r
- WriteValueToMemory("dx", "bh");\r
- if (dwOpcode == 0x73)\r
- WriteValueToMemory("dx", "byte [_z80sp + 1]");\r
- \r
- fprintf(fp, " xor edx, edx ; Zero our upper word\n");\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " dwTemp = *pbPC++;\n");\r
- fprintf(fp, " dwTemp |= ((UINT32) *pbPC++ << 8);\n");\r
-\r
- if (0x43 == dwOpcode) // LD (xxxxh), BC\r
- WriteWordToMemory("dwTemp", "cpu.z80BC");\r
- if (0x53 == dwOpcode) // LD (xxxxh), DE\r
- WriteWordToMemory("dwTemp", "cpu.z80DE");\r
- if (0x63 == dwOpcode) // LD (xxxxh), HL\r
- WriteWordToMemory("dwTemp", "cpu.z80HL");\r
- if (0x73 == dwOpcode) // LD (xxxxh), SP\r
- WriteWordToMemory("dwTemp", "cpu.z80sp");\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void LdRegpair(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " mov dx, [esi] ; Get address to load\n");\r
- fprintf(fp, " add esi, 2 ; Skip over it so we don't execute it\n");\r
- \r
- if (dwOpcode == 0x4b)\r
- ReadValueFromMemory("dx", "cl");\r
- if (dwOpcode == 0x5b)\r
- ReadValueFromMemory("dx", "byte [_z80de]");\r
- if (dwOpcode == 0x7b)\r
- ReadValueFromMemory("dx", "byte [_z80sp]");\r
- \r
- fprintf(fp, " inc dx\n");\r
- \r
- if (dwOpcode == 0x4b)\r
- ReadValueFromMemory("dx", "ch");\r
- if (dwOpcode == 0x5b)\r
- ReadValueFromMemory("dx", "byte [_z80de + 1]");\r
- if (dwOpcode == 0x7b)\r
- ReadValueFromMemory("dx", "byte [_z80sp + 1]");\r
-\r
- fprintf(fp, " xor edx, edx\n");\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " dwTemp = *pbPC++;\n");\r
- fprintf(fp, " dwTemp |= ((UINT32) *pbPC++ << 8);\n");\r
-\r
- if (0x4b == dwOpcode)\r
- ReadWordFromMemory("dwTemp", "cpu.z80BC");\r
- if (0x5b == dwOpcode)\r
- ReadWordFromMemory("dwTemp", "cpu.z80DE");\r
- if (0x7b == dwOpcode)\r
- ReadWordFromMemory("dwTemp", "cpu.z80sp");\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void LDILDRLDIRLDDRHandler(UINT32 dwOpcode)\r
-{\r
- UINT32 dwOrgGlobal = 0;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (dwOpcode == 0xb0 || dwOpcode == 0xb8)\r
- {\r
- dwOrgGlobal = dwGlobalLabel;\r
- fprintf(fp, "ldRepeat%ld:\n", dwGlobalLabel);\r
- }\r
-\r
- ReadValueFromMemory("bx", "dl"); \r
-\r
- // Here we write the byte back to the target\r
- \r
- WriteValueToMemory("[_z80de]", "dl");\r
-\r
- // Now we decide what to do\r
- \r
- if ((dwOpcode & 0x0f) == 0)\r
- {\r
- fprintf(fp, " inc bx ; Increment HL\n");\r
- fprintf(fp, " inc word [_z80de] ; Increment DE\n");\r
- }\r
- else\r
- {\r
- fprintf(fp, " dec bx ; Decrement HL\n");\r
- fprintf(fp, " dec word [_z80de] ; Decrement DE\n");\r
- }\r
- \r
- fprintf(fp, " dec cx ; Decrement BC\n");\r
- \r
- if (dwOpcode == 0xb0 || dwOpcode == 0xb8)\r
- {\r
- if (FALSE == bNoTiming)\r
- {\r
- fprintf(fp, " jz noMore%ld\n", dwGlobalLabel);\r
- fprintf(fp, " sub edi, dword 16 ; 16 T-States per iteration\n");\r
- fprintf(fp, " js noMore%ld\n", dwGlobalLabel);\r
- }\r
- else\r
- {\r
- fprintf(fp, " jz noMore%ld\n", dwGlobalLabel);\r
- }\r
- \r
- fprintf(fp, " jmp ldRepeat%ld ; Loop until we're done!\n", dwOrgGlobal);\r
- fprintf(fp, "noMore%ld:\n", dwGlobalLabel);\r
- }\r
- \r
- fprintf(fp, " and ah, 0e9h ; Knock out H & N and P/V\n");\r
- fprintf(fp, " or cx, cx ; Flag BC\n");\r
- fprintf(fp, " jz atZero%ld ; We're done!\n", dwGlobalLabel);\r
- \r
- if (dwOpcode == 0xb0 || dwOpcode == 0xb8)\r
- {\r
- // It's a repeat, so let's readjust ESI, shall we?\r
- \r
- fprintf(fp, " or ah, 04h ; Non-zero - we're still going!\n");\r
- fprintf(fp, " sub esi, 2 ; Adjust back to the beginning of the instruction\n");\r
- fprintf(fp, " jmp noMoreExec\n\n");\r
- }\r
- else\r
- if (dwOpcode == 0xa0 || dwOpcode == 0xa8)\r
- {\r
- fprintf(fp, " or ah, 04h ; Non-zero - we're still going!\n");\r
- }\r
- \r
- fprintf(fp, "atZero%ld:\n", dwGlobalLabel);\r
- ++dwGlobalLabel;\r
- \r
- fprintf(fp, " xor edx, edx ; Make sure we don't hose things\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- // This is the actual move\r
-\r
- if (0xb0 == dwOpcode || 0xb8 == dwOpcode) // Repeat instruction?\r
- {\r
- fprintf(fp, " while ((sdwCyclesRemaining > 0) && (cpu.z80BC))\n");\r
-\r
- fprintf(fp, " {\n"); \r
- }\r
-\r
- ReadValueFromMemory("cpu.z80HL", "bTemp");\r
- WriteValueToMemory("cpu.z80DE", "bTemp");\r
-\r
- if ((dwOpcode & 0x0f) == 0)\r
- {\r
- fprintf(fp, " ++cpu.z80HL;\n");\r
- fprintf(fp, " ++cpu.z80DE;\n");\r
- }\r
- else \r
- {\r
- fprintf(fp, " --cpu.z80HL;\n");\r
- fprintf(fp, " --cpu.z80DE;\n");\r
- }\r
-\r
- fprintf(fp, " --cpu.z80BC;\n");\r
- fprintf(fp, " cpu.z80HL &= 0xffff;\n");\r
- fprintf(fp, " cpu.z80DE &= 0xffff;\n");\r
- fprintf(fp, " cpu.z80BC &= 0xffff;\n");\r
-\r
- if (0xb0 == dwOpcode || 0xb8 == dwOpcode) // Repeat instruction?\r
- {\r
- fprintf(fp, " sdwCyclesRemaining -= 21;\n");\r
-\r
- fprintf(fp, " }\n");\r
- }\r
-\r
- // Time for a flag fixup!\r
-\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY);\n");\r
- fprintf(fp, " if (cpu.z80BC)\n");\r
- fprintf(fp, " {\n");\r
-\r
- if (0xb0 == dwOpcode || 0xb8 == dwOpcode)\r
- {\r
- fprintf(fp, " pbPC -= 2; /* Back up so we hit this instruction again */\n");\r
- }\r
-\r
- fprintf(fp, " cpu.z80F |= Z80_FLAG_OVERFLOW_PARITY;\n");\r
- fprintf(fp, " }\n");\r
-\r
- if (0xb0 == dwOpcode || 0xb8 == dwOpcode) // Repeat instruction?\r
- {\r
- fprintf(fp, " sdwCyclesRemaining -= 16;\n");\r
- }\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void IMHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (dwOpcode == 0x46)\r
- fprintf(fp, " mov dword [_z80interruptMode], 0 ; IM 0\n");\r
-\r
- if (dwOpcode == 0x56)\r
- {\r
- fprintf(fp, " mov dword [_z80interruptMode], 1 ; Interrupt mode 1\n");\r
- fprintf(fp, " mov word [_z80intAddr], 038h ; Interrupt mode 1 cmd!\n");\r
- }\r
-\r
- if (dwOpcode == 0x5e)\r
- fprintf(fp, " mov dword [_z80interruptMode], 2 ; IM 2\n");\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (0x46 == dwOpcode) // IM 0\r
- fprintf(fp, " cpu.z80interruptMode = 0;\n");\r
-\r
- if (0x56 == dwOpcode) // IM 1\r
- {\r
- fprintf(fp, " cpu.z80interruptMode = 1;\n");\r
- fprintf(fp, " cpu.z80intAddr = 0x38;\n");\r
- }\r
-\r
- if (0x5e == dwOpcode) // IM 2\r
- fprintf(fp, " cpu.z80interruptMode = 2;\n");\r
- }\r
- else\r
- assert(0);\r
- \r
-}\r
-\r
-void IRHandler(UINT32 dwOpcode)\r
-{\r
- char *src, *dst;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- switch(dwOpcode) \r
- {\r
- case 0x57: \r
- dst = "al"; src="[_z80i]"; break;\r
- case 0x5F: \r
- dst = "al"; src="[_z80r]"; break;\r
- case 0x47: \r
- dst = "[_z80i]"; src="al"; break;\r
- case 0x4F: \r
- dst = "[_z80r]"; src="al"; break;\r
- }\r
-\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " mov %s, %s\n",dst,src);\r
- \r
- if (dwOpcode == 0x5f)\r
- {\r
- fprintf(fp, " and ah, 029h ; No N, H, Z, or S!\n");\r
- fprintf(fp, " or al,al ; Get appropriate flags\n");\r
- fprintf(fp, " o16 pushf\n");\r
- fprintf(fp, " pop dx\n");\r
- fprintf(fp, " and dl, 0c0h\n");\r
- fprintf(fp, " or ah, dl ; OR In our S & Z flags\n");\r
- \r
- fprintf(fp, " mov dl, [_z80iff]\n");\r
- fprintf(fp, " and dl, IFF2\n");\r
- fprintf(fp, " shl dl, 1\n");\r
- fprintf(fp, " or ah, dl\n");\r
-\r
- // Randomize R\r
-\r
- fprintf(fp, " mov edx, [dwLastRSample]\n");\r
- fprintf(fp, " sub edx, edi\n");\r
- fprintf(fp, " add edx, [_z80rCounter]\n");\r
- fprintf(fp, " shr edx, 2\n");\r
- fprintf(fp, " and edx, 07fh\n");\r
- fprintf(fp, " and byte [_z80r], 80h\n");\r
- fprintf(fp, " or byte [_z80r], dl\n");\r
-\r
- fprintf(fp, " xor edx, edx\n");\r
- fprintf(fp, " mov [dwLastRSample], edi\n");\r
- }\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (0x5f == dwOpcode) // LD A, R\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[cpu.z80r];\n");\r
- fprintf(fp, " cpu.z80F = (cpu.z80F & ~(Z80_FLAG_OVERFLOW_PARITY)) | ((cpu.z80iff & IFF2) << 1);\n");\r
- fprintf(fp, " cpu.z80A = cpu.z80r;\n");\r
-\r
- // Now randomize a little\r
-\r
- fprintf(fp, " bTemp = (cpu.z80r + (cpu.z80B + sdwCyclesRemaining + 1 + cpu.z80H)) ^ cpu.z80A;\n");\r
- fprintf(fp, " cpu.z80r = (cpu.z80r & 0x80) | (bTemp & 0x7f);\n");\r
- }\r
- else\r
- if (0x47 == dwOpcode) // LD I, A\r
- {\r
- fprintf(fp, " cpu.z80i = cpu.z80A;\n");\r
- }\r
- else\r
- if (0x57 == dwOpcode) // LD A, I\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_ZERO | Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " cpu.z80F |= ((cpu.z80iff & IFF2) << 1);\n");\r
- fprintf(fp, " cpu.z80A = cpu.z80i;\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[cpu.z80A];\n");\r
- }\r
- else\r
- if (0x4f == dwOpcode) // LD R, A\r
- {\r
- fprintf(fp, " cpu.z80r = cpu.z80A;\n");\r
- }\r
- else\r
- {\r
- InvalidInstructionC(2);\r
- }\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-// DD/FD Area\r
-\r
-void DDFDCBHandler(UINT32 dwOpcode)\r
-{\r
- UINT32 dwData = 0;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, "%sInst%.2x:\n", majorOp, dwOpcode);\r
- fprintf(fp, " mov dx, [esi] ; Get our instruction (and offset)\n");\r
- fprintf(fp, " add esi, 2 ; Increment our PC\n");\r
-\r
- fprintf(fp, " mov byte [_orgval], dl ; Store our value\n");\r
- fprintf(fp, " or dl, dl\n");\r
- fprintf(fp, " js notNeg%ld\n", dwGlobalLabel);\r
- fprintf(fp, " mov byte [_orgval + 1], 00h;\n");\r
-\r
- fprintf(fp, " jmp short jumpHandler%ld\n", dwGlobalLabel);\r
- fprintf(fp, "notNeg%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " mov byte [_orgval + 1], 0ffh; It's negative\n");\r
- fprintf(fp, "jumpHandler%ld:\n", dwGlobalLabel++);\r
- fprintf(fp, " shl ebx, 16 ; Save BX away\n");\r
- fprintf(fp, " mov bx, [_z80%s]\n", mz80Index);\r
- fprintf(fp, " add [_orgval], bx\n");\r
- fprintf(fp, " shr ebx, 16 ; Restore BX\n");\r
- fprintf(fp, " mov dl, dh ; Get our instruction\n");\r
- fprintf(fp, " xor dh, dh ; Zero this\n");\r
- fprintf(fp, " jmp dword [z80ddfdcbInstructions+edx*4]\n\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (strcmp("cpu.z80IX", mz80Index) == 0)\r
- dwData = 0;\r
- else\r
- dwData = 1;\r
-\r
- fprintf(fp, " DDFDCBHandler(%d);\n", dwData);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void LoadIndexReg(UINT32 dwOpcode)\r
-{\r
- UINT8 string[150];\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- sprintf(string, "[_z80%s]", mz80Index);\r
-\r
- fprintf(fp, " mov dx, [esi] ; Get our address to store\n");\r
- fprintf(fp, " add esi, 2\n");\r
-\r
- ReadWordFromMemory("dx", string);\r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " dwAddr = *pbPC++;\n");\r
- fprintf(fp, " dwAddr |= ((UINT32) *pbPC++ << 8);\n");\r
- ReadWordFromMemory("dwAddr", mz80Index);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void StoreIndexReg(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " mov dx, [esi] ; Get our address to store\n");\r
- fprintf(fp, " add esi, 2\n");\r
- fprintf(fp, " mov [_orgval], dx\n");\r
-\r
- fprintf(fp, " mov dl, [_z80%s]\n", mz80Index);\r
- WriteValueToMemory("[_orgval]", "dl");\r
-\r
- fprintf(fp, " inc word [_orgval]\n");\r
-\r
- fprintf(fp, " mov dl, [_z80%s + 1]\n", mz80Index);\r
- WriteValueToMemory("[_orgval]", "dl");\r
- fprintf(fp, " xor edx, edx\n");\r
- \r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " dwAddr = *pbPC++;\n");\r
- fprintf(fp, " dwAddr |= ((UINT32) *pbPC++ << 8);\n");\r
- WriteWordToMemory("dwAddr", mz80Index);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void LdIndexPtrReg(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- IndexedOffset(mz80Index);\r
-\r
- // DX Contains the address\r
-\r
- WriteValueToMemory("dx", pbMathReg[dwOpcode & 0x07]);\r
- fprintf(fp, " xor edx, edx\n");\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " sdwAddr = (INT8) *pbPC++; // Get the offset\n");\r
- fprintf(fp, " sdwAddr = ((INT32) %s + sdwAddr) & 0xffff;\n", mz80Index);\r
-\r
- WriteValueToMemory("sdwAddr", pbMathRegC[dwOpcode & 0x07]);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void UndocMathIndex(UINT32 dwOpcode)\r
-{\r
- UINT32 dwOpcode1 = 0;\r
- UINT8 *pbIndexReg = NULL;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (dwOpcode & 1)\r
- fprintf(fp, " mov dl, byte [_z80%s]\n", mz80Index);\r
- else\r
- fprintf(fp, " mov dl, byte [_z80%s + 1]\n", mz80Index);\r
-\r
- // Info is in DL - let's do the math operation\r
-\r
- fprintf(fp, " sahf ; Store our flags in x86 flag reg\n");\r
-\r
- dwOpcode1 = (dwOpcode & 0xf8); // Only the operation\r
-\r
- if (dwOpcode1 == 0x80)\r
- fprintf(fp, " add al, dl\n");\r
- else\r
- if (dwOpcode1 == 0x88)\r
- fprintf(fp, " adc al, dl\n");\r
- else\r
- if (dwOpcode1 == 0x90)\r
- fprintf(fp, " sub al, dl\n");\r
- else\r
- if (dwOpcode1 == 0x98)\r
- fprintf(fp, " sbb al, dl\n");\r
- else\r
- if (dwOpcode1 == 0xa0)\r
- fprintf(fp, " and al, dl\n");\r
- else\r
- if (dwOpcode1 == 0xa8)\r
- fprintf(fp, " xor al, dl\n");\r
- else\r
- if (dwOpcode1 == 0xb0)\r
- fprintf(fp, " or al, dl\n");\r
- else\r
- if (dwOpcode1 == 0xb8)\r
- fprintf(fp, " cmp al, dl\n");\r
- else\r
- assert(0);\r
-\r
- fprintf(fp, " lahf ; Get flags back into AH\n");\r
-\r
- if (dwOpcode1 != 0xa8 && dwOpcode1 != 0xa0 && dwOpcode1 != 0xb0)\r
- {\r
- SetOverflow();\r
- }\r
-\r
- if (dwOpcode1 == 0xa8)\r
- fprintf(fp, " and ah, 0ech ; Only these flags matter!\n");\r
-\r
- if (dwOpcode1 == 0xa0)\r
- {\r
- fprintf(fp, " and ah, 0ech ; Only these flags matter!\n");\r
- fprintf(fp, " or ah, 010h ; Half carry gets set\n");\r
- }\r
-\r
- if (dwOpcode1 == 0xb0)\r
- fprintf(fp, " and ah, 0ech ; No H, N, or C\n");\r
- \r
- if (dwOpcode1 == 0xb8)\r
- fprintf(fp, " or ah, 02h ; Negative gets set on a compare\n");\r
- \r
- if (dwOpcode1 == 0x80 || dwOpcode1 == 0x88)\r
- fprintf(fp, " and ah, 0fdh ; No N!\n");\r
- \r
- if (dwOpcode1 == 0x90 || dwOpcode1 == 0x98)\r
- fprintf(fp, " or ah, 02h ; N Gets set!\n");\r
- \r
- if (dwOpcode1 == 0xb0)\r
- fprintf(fp, " and ah, 0ech ; No H, N, or C\n");\r
- \r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (dwOpcode & 1)\r
- pbIndexReg = mz80IndexHalfLow;\r
- else\r
- pbIndexReg = mz80IndexHalfHigh;\r
-\r
- dwOpcode1 = (dwOpcode & 0xf8); // Only the operation\r
-\r
- if (0x80 == dwOpcode1) // ADD\r
- {\r
- fprintf(fp, " bTemp2 = cpu.z80A + %s;\n", pbIndexReg);\r
- SetAddFlagsSZHVC("cpu.z80A", pbIndexReg);\r
- }\r
- else\r
- if (0x88 == dwOpcode1) // ADC\r
- {\r
- fprintf(fp, " bTemp2 = cpu.z80A + %s + (cpu.z80F & Z80_FLAG_CARRY);\n", pbIndexReg);\r
- SetAdcFlagsSZHVC("cpu.z80A", pbIndexReg);\r
- }\r
- else\r
- if (0x90 == dwOpcode1) // SUB\r
- {\r
- fprintf(fp, " bTemp2 = cpu.z80A - %s;\n", pbIndexReg);\r
- SetSubFlagsSZHVC("cpu.z80A", pbIndexReg);\r
- }\r
- else \r
- if (0x98 == dwOpcode1) // SBC\r
- {\r
- fprintf(fp, " bTemp2 = cpu.z80A - %s - (cpu.z80F & Z80_FLAG_CARRY);\n", pbIndexReg);\r
- SetSbcFlagsSZHVC("cpu.z80A", pbIndexReg);\r
- }\r
- else\r
- if (0xa0 == dwOpcode1) // AND\r
- {\r
- fprintf(fp, " cpu.z80A &= %s;\n", pbIndexReg);\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " cpu.z80F |= bPostANDFlags[cpu.z80A];\n\n");\r
- }\r
- else\r
- if (0xa8 == dwOpcode1) // XOR\r
- {\r
- fprintf(fp, " cpu.z80A ^= %s;\n", pbIndexReg);\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[cpu.z80A];\n\n");\r
- }\r
- else\r
- if (0xb0 == dwOpcode1) // OR\r
- {\r
- fprintf(fp, " cpu.z80A |= %s;\n", pbIndexReg);\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[cpu.z80A];\n\n");\r
- }\r
- else\r
- if (0xb8 == dwOpcode1) // CP - Don't do anything! Just flags!\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[cpu.z80A];\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-\r
- InvalidInstructionC(2);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void UndocLoadHalfIndexReg(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " mov dl, [esi] ; Get immediate byte to load\n");\r
- fprintf(fp, " inc esi ; Next byte\n");\r
-\r
- if (dwOpcode == 0x26)\r
- fprintf(fp, " mov byte [_z80%s + 1], dl\n", mz80Index);\r
- if (dwOpcode == 0x2e)\r
- fprintf(fp, " mov byte [_z80%s], dl\n", mz80Index);\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (dwOpcode & 0x08)\r
- fprintf(fp, " %s = *pbPC++;\n", mz80IndexHalfLow);\r
- else\r
- fprintf(fp, " %s = *pbPC++;\n", mz80IndexHalfHigh);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void UndocIncDecIndexReg(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " sahf\n");\r
-\r
- if (dwOpcode == 0x24)\r
- fprintf(fp, " inc byte [_z80%s + 1]\n", mz80Index);\r
- if (dwOpcode == 0x25)\r
- fprintf(fp, " dec byte [_z80%s + 1]\n", mz80Index);\r
-\r
- if (dwOpcode == 0x2c)\r
- fprintf(fp, " inc byte [_z80%s]\n", mz80Index);\r
- if (dwOpcode == 0x2d)\r
- fprintf(fp, " dec byte [_z80%s]\n", mz80Index);\r
-\r
- fprintf(fp, " lahf\n");\r
- SetOverflow();\r
-\r
- if ((0x24 == dwOpcode) || (0x2c == dwOpcode))\r
- fprintf(fp, " and ah, 0fdh ; Knock out N!\n");\r
- else\r
- fprintf(fp, " or ah, 02h ; Set negative!\n");\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);\n");\r
-\r
- if (0x24 == dwOpcode || 0x2c == dwOpcode)\r
- {\r
- if (dwOpcode & 0x08)\r
- fprintf(fp, " cpu.z80F |= bPostIncFlags[%s++];\n", mz80IndexHalfLow);\r
- else \r
- fprintf(fp, " cpu.z80F |= bPostIncFlags[%s++];\n", mz80IndexHalfHigh);\r
- }\r
- else\r
- {\r
- if (dwOpcode & 0x08)\r
- fprintf(fp, " cpu.z80F |= bPostDecFlags[%s--];\n", mz80IndexHalfLow);\r
- else \r
- fprintf(fp, " cpu.z80F |= bPostDecFlags[%s--];\n", mz80IndexHalfHigh);\r
- }\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void ExIndexed(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if( bThroughCallHandler )\r
- {\r
- fprintf(fp, " mov dx, word [_z80%s]\n", mz80Index);\r
- fprintf(fp, " push dx\n");\r
- fprintf(fp, " call PopWord\n");\r
- fprintf(fp, " mov [_z80%s], dx\n", mz80Index);\r
- fprintf(fp, " pop dx\n");\r
- fprintf(fp, " mov [_wordval], dx\n" );\r
- fprintf(fp, " call PushWord\n" );\r
- } \r
- else \r
- {\r
- fprintf(fp, " mov [cyclesRemaining], edi\n");\r
- fprintf(fp, " mov dx, word [_z80sp]\n");\r
- fprintf(fp, " xor edi, edi\n");\r
- fprintf(fp, " mov di, [_z80%s]\n", mz80Index);\r
- fprintf(fp, " xchg di, [ebp+edx]\n");\r
- fprintf(fp, " mov [_z80%s], di\n", mz80Index);\r
- fprintf(fp, " xor edx, edx\n");\r
- fprintf(fp, " mov edi, [cyclesRemaining]\n");\r
- }\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- ReadWordFromMemory("cpu.z80sp", "dwAddr");\r
- WriteWordToMemory("cpu.z80sp", mz80Index);\r
- fprintf(fp, " %s = dwAddr;\n", mz80Index);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void IncDecIndexReg(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if (dwOpcode == 0x23)\r
- fprintf(fp, " inc word [_z80%s] ; Increment our mz80Index register\n", mz80Index);\r
- else\r
- fprintf(fp, " dec word [_z80%s] ; Increment our mz80Index register\n", mz80Index);\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (0x23 == dwOpcode)\r
- {\r
- fprintf(fp, " %s++;\n", mz80Index);\r
- }\r
- else\r
- {\r
- fprintf(fp, " %s--;\n", mz80Index);\r
- }\r
-\r
- fprintf(fp, " %s &= 0xffff;\n", mz80Index);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void LdRegIndexOffset(UINT32 dwOpcode)\r
-{\r
- UINT32 dwOpcode1 = 0;\r
-\r
- dwOpcode1 = (dwOpcode & 0x38) >> 3;\r
- \r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- IndexedOffset(mz80Index);\r
- \r
- ReadValueFromMemory("dx", pbMathReg[dwOpcode1]);\r
- \r
- fprintf(fp, " xor edx, edx ; Make sure we don't hose things\n");\r
- dwGlobalLabel++;\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " sdwAddr = (INT8) *pbPC++; // Get the offset\n");\r
- fprintf(fp, " sdwAddr = ((INT32) %s + sdwAddr) & 0xffff;\n", mz80Index);\r
-\r
- ReadValueFromMemory("sdwAddr", pbMathRegC[dwOpcode1]);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void LdByteToIndex(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " mov dx, [esi] ; Get our address\n");\r
- fprintf(fp, " add esi, 2 ; Skip over our storage bytes\n");\r
- fprintf(fp, " mov [cyclesRemaining], edi\n");\r
- fprintf(fp, " mov di, dx ; Store it here for later\n");\r
- fprintf(fp, " xor dh, dh\n");\r
- fprintf(fp, " or dl, dl\n");\r
- fprintf(fp, " jns noNegate%ld\n", dwGlobalLabel);\r
- fprintf(fp, " dec dh\n");\r
- fprintf(fp, "noNegate%ld:\n", dwGlobalLabel);\r
- fprintf(fp, " add dx, [_z80%s] ; Add in our index\n", mz80Index);\r
- fprintf(fp, " mov [_orgval], dx ; Store our address to write to\n");\r
- fprintf(fp, " mov dx, di\n");\r
- fprintf(fp, " xchg dh, dl\n");\r
- fprintf(fp, " mov edi, [cyclesRemaining]\n");\r
- \r
- WriteValueToMemory("[_orgval]", "dl");\r
- \r
- fprintf(fp, " xor edx, edx\n");\r
- ++dwGlobalLabel;\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " sdwAddr = (INT8) *pbPC++; // Get the offset\n");\r
- fprintf(fp, " sdwAddr = ((INT32) %s + sdwAddr) & 0xffff;\n", mz80Index);\r
-\r
- WriteValueToMemory("sdwAddr", "*pbPC++");\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-\r
-void SPToIndex(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " mov dx, [_z80%s] ; Get our source register\n", mz80Index);\r
- fprintf(fp, " mov word [_z80sp], dx ; Store our new SP\n");\r
- fprintf(fp, " xor edx, edx\n");\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " cpu.z80sp = %s;\n", mz80Index);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void AddIndexHandler(UINT32 dwOpcode)\r
-{\r
- UINT8 bRegPair;\r
-\r
- bRegPair = dwOpcode >> 4;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " mov dh, ah ; Get our flags\n");\r
- fprintf(fp, " and dh, 0ech ; Preserve the top three and bits 2 & 3\n");\r
-\r
- fprintf(fp, " mov [cyclesRemaining], edi\n");\r
- fprintf(fp, " mov di, [_z80%s] ; Get our value\n", mz80Index);\r
- fprintf(fp, " mov [_orgval], di ; Store our original value\n");\r
- fprintf(fp, " add di, %s\n", pbIndexedRegPairs[(dwOpcode & 0x30) >> 4]);\r
- fprintf(fp, " lahf\n");\r
- fprintf(fp, " mov [_z80%s], di ; Store our register back\n", mz80Index);\r
-\r
- fprintf(fp, " mov di, [_orgval] ; Get original\n");\r
- fprintf(fp, " xor di, word [_z80%s] ; XOR It with our computed value\n", mz80Index);\r
- fprintf(fp, " xor di, %s\n", pbIndexedRegPairs[(dwOpcode & 0x30) >> 4]);\r
- fprintf(fp, " and di, 1000h ; Just our half carry\n");\r
- fprintf(fp, " or dx, di ; Or in our flags\n");\r
- fprintf(fp, " and ah, 01h ; Just carry\n");\r
- fprintf(fp, " or ah, dh\n");\r
- fprintf(fp, " mov edi, [cyclesRemaining]\n");\r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (bRegPair != 2)\r
- { \r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);\n");\r
- fprintf(fp, " dwTemp = %s + %s;\n", mz80Index, pbRegPairsC[bRegPair]);\r
- fprintf(fp, " cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY) | (((%s ^ dwTemp ^ %s) >> 8) & Z80_FLAG_HALF_CARRY);\n", mz80Index, pbRegPairsC[bRegPair]);\r
- fprintf(fp, " %s = dwTemp & 0xffff;\n", mz80Index);\r
- }\r
- else\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_HALF_CARRY);\n");\r
- fprintf(fp, " dwTemp = %s + %s;\n", mz80Index, mz80Index);\r
- fprintf(fp, " cpu.z80F |= ((dwTemp >> 16) & Z80_FLAG_CARRY) | (((%s ^ dwTemp ^ %s) >> 8) & Z80_FLAG_HALF_CARRY);\n", mz80Index, pbRegPairsC[bRegPair]);\r
- fprintf(fp, " %s = dwTemp & 0xffff;\n", mz80Index);\r
- }\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void JPIXIYHandler(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " mov dx, [_z80%s] ; Get our value\n", mz80Index);\r
- fprintf(fp, " mov esi, edx ; New PC!\n");\r
- fprintf(fp, " add esi, ebp ; Add in our base\n");\r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " pbPC = cpu.z80Base + %s;\n", mz80Index);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void IncDecIndexed(UINT32 dwOpcode)\r
-{\r
- UINT8 szIndex[30];\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- IndexedOffset(mz80Index);\r
-\r
- fprintf(fp, " mov [_orgval], dx\n");\r
-\r
- ReadValueFromMemory("dx", "dl");\r
-\r
- fprintf(fp, " sahf\n");\r
-\r
- if (dwOpcode == 0x34)\r
- fprintf(fp, " inc dl\n");\r
- else\r
- fprintf(fp, " dec dl\n");\r
- fprintf(fp, " lahf\n");\r
-\r
- fprintf(fp, " o16 pushf\n");\r
- fprintf(fp, " shl edx, 16\n");\r
- fprintf(fp, " and ah, 0fbh ; Knock out parity/overflow\n");\r
- fprintf(fp, " pop dx\n");\r
- fprintf(fp, " and dh, 08h ; Just the overflow\n");\r
- fprintf(fp, " shr dh, 1 ; Shift it into position\n");\r
- fprintf(fp, " or ah, dh ; OR It in with the real flags\n");\r
-\r
- fprintf(fp, " shr edx, 16\n");\r
-\r
- if (dwOpcode == 0x34)\r
- fprintf(fp, " and ah, 0fdh ; Knock out N!\n");\r
- else\r
- fprintf(fp, " or ah, 02h ; Make it N!\n");\r
-\r
- WriteValueToMemory("[_orgval]", "dl");\r
-\r
- fprintf(fp, " xor edx, edx\n");\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " sdwAddr = (INT8) *pbPC++; /* Get LSB first */\n");\r
- fprintf(fp, " dwAddr = (sdwAddr + (INT32) %s) & 0xffff;\n", mz80Index);\r
-\r
- ReadValueFromMemory("dwAddr", "bTemp");\r
-\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_SIGN | Z80_FLAG_ZERO | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE);\n");\r
- \r
- if (0x34 == dwOpcode)\r
- {\r
- fprintf(fp ," cpu.z80F |= bPostIncFlags[bTemp++];\n");\r
- }\r
- else\r
- {\r
- fprintf(fp ," cpu.z80F |= bPostDecFlags[bTemp--];\n");\r
- }\r
- \r
- WriteValueToMemory("dwAddr", "bTemp");\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void MathOperationIndexed(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- IndexedOffset(mz80Index);\r
- ReadValueFromMemory("dx", "dl");\r
-\r
- fprintf(fp, " sahf\n");\r
-\r
- if (dwOpcode == 0x86) // Add\r
- fprintf(fp, " add al, dl\n");\r
- if (dwOpcode == 0x8e) // Adc\r
- fprintf(fp, " adc al, dl\n");\r
- if (dwOpcode == 0x96) // Sub\r
- fprintf(fp, " sub al, dl\n");\r
- if (dwOpcode == 0x9e) // Sbc\r
- fprintf(fp, " sbb al, dl\n");\r
- if (dwOpcode == 0xa6) // And\r
- fprintf(fp, " and al, dl\n");\r
- if (dwOpcode == 0xae) // Xor\r
- fprintf(fp, " xor al, dl\n");\r
- if (dwOpcode == 0xb6) // Or\r
- fprintf(fp, " or al, dl\n");\r
- if (dwOpcode == 0xbe) // Cp\r
- fprintf(fp, " cmp al, dl\n");\r
-\r
- fprintf(fp, " lahf\n");\r
-\r
- if (dwOpcode == 0x86 || dwOpcode == 0x8e)\r
- {\r
- SetOverflow();\r
- fprintf(fp, " and ah, 0fdh ; Knock out negative\n");\r
- }\r
-\r
- if (dwOpcode == 0x96 || dwOpcode == 0x9e || dwOpcode == 0xbe)\r
- {\r
- SetOverflow();\r
- fprintf(fp, " or ah, 02h ; Set negative\n");\r
- }\r
-\r
- if (dwOpcode == 0xae || dwOpcode == 0xb6)\r
- fprintf(fp, " and ah, 0ech ; Knock out H, N, and C\n");\r
-\r
- if (dwOpcode == 0xa6)\r
- {\r
- fprintf(fp, " and ah,0fch ; Knock out N & C\n");\r
- fprintf(fp, " or ah, 10h ; Set half carry\n");\r
- }\r
-\r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " sdwAddr = (INT8) *pbPC++; /* Get LSB first */\n");\r
- fprintf(fp, " dwAddr = (sdwAddr + (INT32) %s) & 0xffff;\n", mz80Index);\r
-\r
- ReadValueFromMemory("dwAddr", "bTemp");\r
-\r
- if (0x86 == dwOpcode) // ADD A, (IX/IY+nn)\r
- {\r
- SetAddFlagsSZHVC("cpu.z80A", "bTemp");\r
- fprintf(fp, " cpu.z80A += bTemp;\n");\r
- }\r
- else\r
- if (0x8e == dwOpcode) // ADC A, (IX/IY+nn)\r
- {\r
- fprintf(fp, " bTemp2 = (cpu.z80F & Z80_FLAG_CARRY);\n");\r
- SetAdcFlagsSZHVC("cpu.z80A", "bTemp");\r
- fprintf(fp, " cpu.z80A += bTemp + bTemp2;\n");\r
- }\r
- else\r
- if (0x96 == dwOpcode) // SUB A, (IX/IY+nn)\r
- {\r
- SetSubFlagsSZHVC("cpu.z80A", "bTemp");\r
- fprintf(fp, " cpu.z80A -= bTemp;\n");\r
- }\r
- else\r
- if (0x9e == dwOpcode) // SBC A, (IX/IY+nn)\r
- {\r
- fprintf(fp, " bTemp2 = cpu.z80A;\n");\r
- fprintf(fp, " cpu.z80A = cpu.z80A - bTemp - (cpu.z80F & Z80_FLAG_CARRY);\n");\r
- SetSbcFlagsSZHVC("bTemp2", "bTemp");\r
- }\r
- else\r
- if (0xa6 == dwOpcode) // AND A, (IX/IY+nn)\r
- {\r
- fprintf(fp, " cpu.z80A &= bTemp;\n");\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " cpu.z80F |= bPostANDFlags[cpu.z80A];\n\n");\r
- }\r
- else\r
- if (0xae == dwOpcode) // XOR A, (IX/IY+nn)\r
- {\r
- fprintf(fp, " cpu.z80A ^= bTemp;\n");\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[cpu.z80A];\n\n");\r
- }\r
- else\r
- if (0xb6 == dwOpcode) // OR A, (IX/IY+nn)\r
- {\r
- fprintf(fp, " cpu.z80A |= bTemp;\n");\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_CARRY | Z80_FLAG_NEGATIVE | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_HALF_CARRY | Z80_FLAG_ZERO | Z80_FLAG_SIGN);\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[cpu.z80A];\n\n");\r
- }\r
- else\r
- if (0xbe == dwOpcode) // CP A, (IX/IY+nn)\r
- {\r
- SetSubFlagsSZHVC("cpu.z80A", "bTemp");\r
- }\r
- else\r
- InvalidInstructionC(2);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void UndocIndexToReg(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if ((dwOpcode & 0x07) == 2 || (dwOpcode & 0x07) == 3)\r
- fprintf(fp, " mov dx, [_z80de] ; Get DE\n");\r
-\r
- if ((dwOpcode & 0x07) == 4)\r
- fprintf(fp, " mov dh, byte [_z80%s + 1]\n", mz80Index);\r
- if ((dwOpcode & 0x07) == 5)\r
- fprintf(fp, " mov dl, byte [_z80%s]\n", mz80Index);\r
-\r
- fprintf(fp, " mov byte [_z80%s + %ld], %s\n", mz80Index, 1 - ((dwOpcode & 0x08) >> 3), pbLocalReg[dwOpcode & 0x07]);\r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (dwOpcode != 0x64 && dwOpcode != 0x65 && dwOpcode != 0x6c && dwOpcode != 0x6d)\r
- {\r
- if (dwOpcode & 0x08)\r
- fprintf(fp, " %s = %s;\n", mz80IndexHalfLow, pbLocalRegC[dwOpcode & 0x07]);\r
- else\r
- fprintf(fp, " %s = %s;\n", mz80IndexHalfHigh, pbLocalRegC[dwOpcode & 0x07]);\r
- }\r
- else // IX/IY High/low weirdness afoot...\r
- {\r
- // We don't generate any code for ld indexH, indexH and ld indexL, indexL\r
-\r
- if (0x65 == dwOpcode) // LD indexH, indexL\r
- {\r
- fprintf(fp, " %s = %s;\n", mz80IndexHalfHigh, mz80IndexHalfLow);\r
- }\r
- else\r
- if (0x6c == dwOpcode) // LD indexH, indexL\r
- {\r
- fprintf(fp, " %s = %s;\n", mz80IndexHalfLow, mz80IndexHalfHigh);\r
- }\r
- }\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void UndocRegToIndex(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- if ((dwOpcode & 0x38) == 0x10 || (dwOpcode & 0x38) == 0x18)\r
- fprintf(fp, " mov dx, [_z80de] ; Get a usable copy of DE here\n");\r
-\r
- fprintf(fp, " mov %s, byte [_z80%s + %ld]\n", pbLocalReg[(dwOpcode >> 3) & 0x07], mz80Index, 1 - (dwOpcode & 1));\r
-\r
- if ((dwOpcode & 0x38) == 0x10 || (dwOpcode & 0x38) == 0x18)\r
- fprintf(fp, " mov [_z80de], dx ; Put it back!\n");\r
-\r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (dwOpcode & 1)\r
- fprintf(fp, " %s = %s;\n", pbLocalRegC[(dwOpcode >> 3) & 0x07], mz80IndexHalfLow);\r
- else\r
- fprintf(fp, " %s = %s;\n", pbLocalRegC[(dwOpcode >> 3) & 0x07], mz80IndexHalfHigh);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void LoadImmediate(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
-\r
- fprintf(fp, " mov dx, [esi] ; Get our word to load\n");\r
- fprintf(fp, " add esi, 2 ; Advance past the word\n");\r
- fprintf(fp, " mov [_z80%s], dx ; Store our new value\n", mz80Index);\r
- fprintf(fp, " xor edx, edx\n");\r
-\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, " %s = *pbPC++;\n", mz80Index);\r
- fprintf(fp, " %s |= ((UINT32) *pbPC++ << 8);\n", mz80Index);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-void PushPopOperationsIndexed(UINT32 dwOpcode)\r
-{\r
- UINT8 bRegPair;\r
- UINT8 bRegBaseLsb[25];\r
- UINT8 bRegBaseMsb[25];\r
- UINT8 string[150];\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- sprintf(bRegBaseLsb, "byte [_z80%s]", mz80Index);\r
- sprintf(bRegBaseMsb, "byte [_z80%s + 1]", mz80Index);\r
-\r
- sprintf(string, "[_z80%s]", mz80Index);\r
-\r
- ProcBegin(dwOpcode);\r
-\r
- if (dwOpcode == 0xe5) // Push IX/IY\r
- {\r
- fprintf(fp, " sub word [_z80sp], 2\n");\r
- fprintf(fp, " mov dx, [_z80sp]\n");\r
- \r
- WriteWordToMemory("dx", string); \r
- }\r
- else // Pop\r
- {\r
- fprintf(fp, " mov dx, [_z80sp]\n");\r
- ReadWordFromMemory("dx", string);\r
- fprintf(fp, " add word [_z80sp], 2\n");\r
- } \r
-\r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (0xe5 == dwOpcode) // Push IX/IY\r
- {\r
- fprintf(fp, " cpu.z80sp -= 2;\n");\r
- fprintf(fp, " pbSP = (cpu.z80Base + cpu.z80sp); /* Normalize the stack pointer */\n");\r
- \r
- WriteWordToMemory("cpu.z80sp", mz80Index);\r
- }\r
- else\r
- if (0xe1 == dwOpcode) // Pop IX/IY\r
- {\r
- ReadWordFromMemory("cpu.z80sp", mz80Index);\r
-\r
- fprintf(fp, " cpu.z80sp += 2;\n");\r
- fprintf(fp, " pbSP = (cpu.z80Base + cpu.z80sp); /* Normalize the stack pointer */\n");\r
- return;\r
- }\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-// DDFD XXCB Instructions\r
-\r
-void ddcbBitWise(UINT32 dwOpcode)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- ProcBegin(dwOpcode);\r
- \r
- // NOTE: _orgval contains the address to get from. It includes the offset\r
- // already computed plus the mz80Index register.\r
-\r
- // Read our byte\r
-\r
- fprintf(fp, " mov dx, [_orgval] ; Get our target address\n");\r
- ReadValueFromMemory("dx", "dl");\r
-\r
- // Do the operation\r
-\r
- if (dwOpcode != 0x06 && dwOpcode != 0x0e &&\r
- dwOpcode != 0x16 && dwOpcode != 0x1e &&\r
- dwOpcode != 0x26 && dwOpcode != 0x2e &&\r
- dwOpcode != 0x3e && (dwOpcode & 0xc7) != 0x86 &&\r
- (dwOpcode & 0xc7) != 0xc6)\r
- {\r
- fprintf(fp, " mov dh, ah ; Store our original flags\n");\r
- fprintf(fp, " and dh, 29h ; Keep our old flags\n");\r
- }\r
-\r
- if ((dwOpcode & 0xc7) != 0x86 && (dwOpcode & 0xc7) != 0xc6)\r
- fprintf(fp, " sahf ; Restore our flags\n");\r
-\r
- if (dwOpcode == 0x06)\r
- fprintf(fp, " rol dl, 1\n");\r
- if (dwOpcode == 0x0e)\r
- fprintf(fp, " ror dl, 1\n");\r
- if (dwOpcode == 0x16)\r
- fprintf(fp, " rcl dl, 1\n");\r
- if (dwOpcode == 0x1e)\r
- fprintf(fp, " rcr dl, 1\n");\r
- if (dwOpcode == 0x26)\r
- fprintf(fp, " shl dl, 1\n");\r
- if (dwOpcode == 0x2e)\r
- fprintf(fp, " sar dl, 1\n");\r
- if (dwOpcode == 0x3e)\r
- fprintf(fp, " shr dl, 1\n");\r
-\r
- // BIT, AND, and OR\r
-\r
- if ((dwOpcode & 0xc7) == 0x46)\r
- fprintf(fp, " test dl, 0%.2xh ; Is it set?\n", (1 << ((dwOpcode >> 3) & 0x07)));\r
- else\r
- if ((dwOpcode & 0xc7) == 0x86)\r
- fprintf(fp, " and dl, 0%.2xh ; Reset the bit\n", \r
- 0xff - (1 << ((dwOpcode >> 3) & 0x07)));\r
- else\r
- if ((dwOpcode & 0xc7) == 0xc6)\r
- fprintf(fp, " or dl, 0%.2xh ; Set the bit\n",\r
- (1 << ((dwOpcode >> 3) & 0x07)));\r
- \r
- if ((dwOpcode & 0xc7) != 0x86 && (dwOpcode & 0xc7) != 0xc6)\r
- fprintf(fp, " lahf ; Get our flags back\n"); \r
-\r
- // Do the flag fixup (if any)\r
-\r
- if (dwOpcode == 0x26 || dwOpcode == 0x2e || ((dwOpcode & 0xc7) == 0x46))\r
- fprintf(fp, " and ah, 0edh ; No Half carry or negative!\n");\r
- \r
- if (dwOpcode == 0x06 || dwOpcode == 0x0e ||\r
- dwOpcode == 0x16 || dwOpcode == 0x1e ||\r
- dwOpcode == 0x3e)\r
- fprintf(fp, " and ah, 0edh ; Knock out H & N\n");\r
-\r
- // BIT!\r
-\r
- if ((dwOpcode & 0xc7) == 0x46)\r
- {\r
- fprintf(fp, " or ah, 10h ; OR In our half carry\n");\r
- fprintf(fp, " and ah, 0d0h ; New flags\n");\r
- fprintf(fp, " or ah, dh ; OR In our old flags\n");\r
- }\r
-\r
- // Now write our data back if it's not a BIT instruction\r
-\r
- if ((dwOpcode & 0xc7) != 0x46) // If it's not a BIT, write it back\r
- WriteValueToMemory("[_orgval]", "dl");\r
- \r
- fprintf(fp, " xor edx, edx\n");\r
- FetchNextInstruction(dwOpcode);\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- if (0x06 == dwOpcode) // RLC\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " bTemp2 = (bTemp >> 7);\n");\r
- fprintf(fp, " bTemp = (bTemp << 1) | bTemp2;\n");\r
- fprintf(fp, " cpu.z80F |= bTemp2 | bPostORFlags[bTemp];\n");\r
- WriteValueToMemory("dwAddr", "bTemp");\r
- }\r
- else\r
- if (0x0e == dwOpcode) // RRC\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80F |= (bTemp & Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " bTemp = (bTemp >> 1) | (bTemp << 7);\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[bTemp];\n");\r
- WriteValueToMemory("dwAddr", "bTemp");\r
- }\r
- else\r
- if (0x16 == dwOpcode) // RL\r
- {\r
- fprintf(fp, " bTemp2 = cpu.z80F & Z80_FLAG_CARRY;\n");\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80F |= (bTemp >> 7);\n");\r
- fprintf(fp, " bTemp = (bTemp << 1) | bTemp2;\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[bTemp];\n");\r
- WriteValueToMemory("dwAddr", "bTemp");\r
- }\r
- else\r
- if (0x1e == dwOpcode) // RR\r
- {\r
- fprintf(fp, " bTemp2 = (cpu.z80F & Z80_FLAG_CARRY) << 7;\n");\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80F |= (bTemp & Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " bTemp = (bTemp >> 1) | bTemp2;\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[bTemp];\n");\r
- WriteValueToMemory("dwAddr", "bTemp");\r
- }\r
- else\r
- if (0x26 == dwOpcode) // SLA\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80F |= (bTemp >> 7);\n");\r
- fprintf(fp, " bTemp = (bTemp << 1);\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[bTemp];\n");\r
- WriteValueToMemory("dwAddr", "bTemp");\r
- }\r
- else\r
- if (0x2e == dwOpcode) // SRA\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80F |= (bTemp & Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " bTemp = (bTemp >> 1) | (bTemp & 0x80);\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[bTemp];\n");\r
- WriteValueToMemory("dwAddr", "bTemp");\r
- }\r
- else\r
- if (0x3e == dwOpcode) // SRL\r
- {\r
- fprintf(fp, " cpu.z80F &= ~(Z80_FLAG_ZERO | Z80_FLAG_SIGN | Z80_FLAG_HALF_CARRY | Z80_FLAG_OVERFLOW_PARITY | Z80_FLAG_NEGATIVE | Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " cpu.z80F |= (bTemp & Z80_FLAG_CARRY);\n");\r
- fprintf(fp, " bTemp = (bTemp >> 1);\n");\r
- fprintf(fp, " cpu.z80F |= bPostORFlags[bTemp];\n");\r
- WriteValueToMemory("dwAddr", "bTemp");\r
- }\r
- else\r
- if ((dwOpcode & 0xc0) == 0x40) // BIT\r
- {\r
- fprintf(fp, " cpu.z80F = (cpu.z80F & ~(Z80_FLAG_ZERO | Z80_FLAG_NEGATIVE)) | Z80_FLAG_HALF_CARRY;\n");\r
- fprintf(fp, " if (!(bTemp & 0x%.2x))\n", 1 << ((dwOpcode >> 3) & 0x07));\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80F |= Z80_FLAG_ZERO;\n");\r
- fprintf(fp, " }\n");\r
- }\r
- else\r
- if ((dwOpcode & 0xc0) == 0x80) // RES\r
- {\r
- fprintf(fp, " bTemp &= 0x%.2x;\n", ~(1 << ((dwOpcode >> 3) & 0x07)) & 0xff);\r
- WriteValueToMemory("dwAddr", "bTemp");\r
- }\r
- else\r
- if ((dwOpcode & 0xc0) == 0xC0) // SET\r
- {\r
- fprintf(fp, " bTemp |= 0x%.2x;\n", 1 << ((dwOpcode >> 3) & 0x07));\r
- WriteValueToMemory("dwAddr", "bTemp");\r
- }\r
- else\r
- InvalidInstructionC(4);\r
- }\r
- else\r
- assert(0);\r
-}\r
-\r
-GetTicksCode()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " global _%sGetElapsedTicks\n", cpubasename);\r
- fprintf(fp, " global %sGetElapsedTicks_\n", cpubasename);\r
- fprintf(fp, " global %sGetElapsedTicks\n", cpubasename);\r
- \r
- Alignment();\r
- sprintf(procname, "%sGetElapsedTicks_", cpubasename);\r
- ProcBegin(0xffffffff);\r
- fprintf(fp, "_%sGetElapsedTicks:\n", cpubasename);\r
- fprintf(fp, "%sGetElapsedTicks:\n", cpubasename);\r
- \r
- if (bUseStack)\r
- fprintf(fp, " mov eax, [esp+4] ; Get our context address\n");\r
- \r
- fprintf(fp, " or eax, eax ; Should we clear it?\n");\r
- fprintf(fp, " jz getTicks\n");\r
- fprintf(fp, " xor eax, eax\n");\r
- fprintf(fp, " xchg eax, [dwElapsedTicks]\n");\r
- fprintf(fp, " ret\n");\r
- fprintf(fp, "getTicks:\n");\r
- fprintf(fp, " mov eax, [dwElapsedTicks]\n");\r
- fprintf(fp, " ret\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "/* This will return the elapsed ticks */\n\n");\r
- fprintf(fp, "UINT32 %sGetElapsedTicks(UINT32 dwClear)\n", cpubasename);\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " UINT32 dwTemp = dwElapsedTicks;\n\n");\r
- fprintf(fp, " if (dwClear)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " dwElapsedTicks = 0;\n");\r
- fprintf(fp, " }\n\n");\r
- fprintf(fp, " return(dwTemp);\n");\r
- fprintf(fp, "}\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-ReleaseTimesliceCode()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " global _%sReleaseTimeslice\n", cpubasename);\r
- fprintf(fp, " global %sReleaseTimeslice_\n", cpubasename);\r
- fprintf(fp, " global %sReleaseTimeslice\n", cpubasename);\r
- \r
- Alignment();\r
- sprintf(procname, "%sReleaseTimeslice_", cpubasename);\r
- ProcBegin(0xffffffff);\r
- fprintf(fp, "_%sReleaseTimeslice:\n", cpubasename);\r
- fprintf(fp, "%sReleaseTimeslice:\n", cpubasename);\r
- \r
- fprintf(fp, " mov eax, [cyclesRemaining]\n");\r
- fprintf(fp, " sub [dwOriginalExec], eax\n");\r
- fprintf(fp, " mov [cyclesRemaining], dword 0\n");\r
- \r
- fprintf(fp, " ret\n\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "/* Releases mz80 from its current timeslice */\n\n");\r
- fprintf(fp, "void %sReleaseTimeslice(void)\n", cpubasename);\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " dwOriginalCycles -= sdwCyclesRemaining;\n");\r
- fprintf(fp, " sdwCyclesRemaining = 0;\n");\r
- fprintf(fp, "}\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-DataSegment()\r
-{\r
- UINT32 dwLoop = 0;\r
- UINT8 bUsed[256];\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- if (bOS2)\r
- fprintf(fp, " section .DATA32 use32 flat class=data\n");\r
- else\r
- fprintf(fp, " section .data use32 flat class=data\n");\r
- \r
- Alignment();\r
- fprintf(fp, " global _%scontextBegin\n", cpubasename);\r
- fprintf(fp, "_%scontextBegin:\n", cpubasename);\r
-\r
- fprintf(fp, " global _z80pc\n");\r
- fprintf(fp, " global z80pc_\n");\r
-\r
- if (bPlain)\r
- fprintf(fp, " global z80pc\n");\r
-\r
- fprintf(fp, " global _z80nmiAddr\n");\r
- fprintf(fp, " global _z80intAddr\n");\r
- fprintf(fp, " global z80intAddr\n");\r
-\r
- fprintf(fp, "\n");\r
- fprintf(fp, "; DO NOT CHANGE THE ORDER OF AF, BC, DE, HL and THE PRIME REGISTERS!\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, "_z80Base dd 0 ; Base address for Z80 stuff\n");\r
- fprintf(fp, "_z80MemRead dd 0 ; Offset of memory read structure array\n");\r
- fprintf(fp, "_z80MemWrite dd 0 ; Offset of memory write structure array\n");\r
- fprintf(fp, "_z80IoRead dd 0 ; Base address for I/O reads list\n");\r
- fprintf(fp, "_z80IoWrite dd 0 ; Base address for I/O write list\n");\r
- fprintf(fp, "_z80clockticks dd 0 ; # Of clock tips that have elapsed\n");\r
- fprintf(fp, "_z80iff dd 0 ; Non-zero if we're in an interrupt\n");\r
- fprintf(fp, "_z80interruptMode dd 0 ; Interrupt mode\n");\r
- fprintf(fp, "_z80halted dd 0 ; 0=Not halted, 1=Halted\n");\r
-#ifdef MZ80_TRAP\r
- fprintf(fp, "_z80trapList dd 0 ; pointer to trap list\n");\r
- fprintf(fp, "_z80trapAddr dw 0 ; PC where trap occurred\n");\r
-#endif\r
- fprintf(fp, "_z80af dd 0 ; A Flag & Flags\n");\r
- fprintf(fp, "_z80bc dd 0 ; BC\n");\r
- fprintf(fp, "_z80de dd 0 ; DE\n");\r
- fprintf(fp, "_z80hl dd 0 ; HL\n");\r
- fprintf(fp, "_z80afprime dd 0 ; A Flag & Flags prime\n");\r
- fprintf(fp, "_z80bcprime dd 0 ; BC prime\n");\r
- fprintf(fp, "_z80deprime dd 0 ; DE prime\n");\r
- fprintf(fp, "_z80hlprime dd 0 ; HL prime\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, "; The order of the following registers can be changed without adverse\n");\r
- fprintf(fp, "; effect. Keep the WORD and DWORDs on boundaries of two for faster access\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, "_z80ix dd 0 ; IX\n");\r
- fprintf(fp, "_z80iy dd 0 ; IY\n");\r
- fprintf(fp, "_z80sp dd 0 ; Stack pointer\n");\r
- \r
- if (bPlain)\r
- fprintf(fp,"z80pc:\n");\r
- \r
- fprintf(fp, "z80pc_:\n");\r
- fprintf(fp, "_z80pc dd 0 ; PC\n");\r
- fprintf(fp, "_z80nmiAddr dd 0 ; Address to jump to for NMI\n");\r
- fprintf(fp, "z80intAddr:\n");\r
- fprintf(fp, "_z80intAddr dd 0 ; Address to jump to for INT\n");\r
- fprintf(fp, "_z80rCounter dd 0 ; R Register counter\n");\r
- fprintf(fp, "_z80i db 0 ; I register\n");\r
- fprintf(fp, "_z80r db 0 ; R register\n");\r
- fprintf(fp, "_z80intPending db 0 ; Non-zero if an interrupt is pending\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, "_%scontextEnd:\n", cpubasename);\r
- Alignment();\r
- fprintf(fp, "dwElapsedTicks dd 0 ; # Of ticks elapsed\n");\r
- fprintf(fp, "cyclesRemaining dd 0 ; # Of cycles remaining\n");\r
- fprintf(fp, "dwOriginalExec dd 0 ; # Of cycles originally executing\n");\r
- fprintf(fp, "dwLastRSample dd 0 ; Last sample for R computation\n");\r
- fprintf(fp, "dwEITiming dd 0 ; Used when we cause an interrupt\n");\r
- fprintf(fp, "_orgval dw 0 ; Scratch area\n");\r
- fprintf(fp, "_orgval2 dw 0 ; Scratch area\n");\r
- fprintf(fp, "_wordval dw 0 ; Scratch area\n");\r
- fprintf(fp, "_intData db 0 ; Interrupt data when an interrupt is pending\n");\r
- fprintf(fp, "bEIExit db 0 ; Are we exiting because of an EI instruction?\n");\r
- fprintf(fp, "\n");\r
-\r
- // Debugger junk\r
-\r
- fprintf(fp, "RegTextPC db 'PC',0\n");\r
- fprintf(fp, "RegTextAF db 'AF',0\n");\r
- fprintf(fp, "RegTextBC db 'BC',0\n");\r
- fprintf(fp, "RegTextDE db 'DE',0\n");\r
- fprintf(fp, "RegTextHL db 'HL',0\n");\r
- fprintf(fp, "RegTextAFP db 'AF',27h,0\n");\r
- fprintf(fp, "RegTextBCP db 'BC',27h,0\n");\r
- fprintf(fp, "RegTextDEP db 'DE',27h,0\n");\r
- fprintf(fp, "RegTextHLP db 'HL',27h,0\n");\r
- fprintf(fp, "RegTextIX db 'IX',0\n");\r
- fprintf(fp, "RegTextIY db 'IY',0\n");\r
- fprintf(fp, "RegTextSP db 'SP',0\n");\r
- fprintf(fp, "RegTextI db 'I',0\n");\r
- fprintf(fp, "RegTextR db 'R',0\n");\r
-\r
- // 8 Byte textual info\r
-\r
- fprintf(fp, "RegTextA db 'A',0\n");\r
- fprintf(fp, "RegTextB db 'B',0\n");\r
- fprintf(fp, "RegTextC db 'C',0\n");\r
- fprintf(fp, "RegTextD db 'D',0\n");\r
- fprintf(fp, "RegTextE db 'E',0\n");\r
- fprintf(fp, "RegTextH db 'H',0\n");\r
- fprintf(fp, "RegTextL db 'L',0\n");\r
- fprintf(fp, "RegTextF db 'F',0\n");\r
-\r
- // Individual flags\r
-\r
- fprintf(fp, "RegTextCarry db 'Carry',0\n");\r
- fprintf(fp, "RegTextNegative db 'Negative',0\n");\r
- fprintf(fp, "RegTextParity db 'Parity',0\n");\r
- fprintf(fp, "RegTextOverflow db 'Overflow',0\n");\r
- fprintf(fp, "RegTextHalfCarry db 'HalfCarry',0\n");\r
- fprintf(fp, "RegTextZero db 'Zero',0\n");\r
- fprintf(fp, "RegTextSign db 'Sign',0\n");\r
- fprintf(fp, "RegTextIFF1 db 'IFF1',0\n");\r
- fprintf(fp, "RegTextIFF2 db 'IFF2',0\n\n");\r
-\r
- // Timing for interrupt modes\r
-\r
- fprintf(fp, "intModeTStates:\n");\r
- fprintf(fp, " db 13 ; IM 0 - 13 T-States\n");\r
- fprintf(fp, " db 11 ; IM 1 - 11 T-States\n");\r
- fprintf(fp, " db 11 ; IM 2 - 11 T-States\n\n");\r
-\r
- // Now the master reg/flag table\r
-\r
- fprintf(fp, "\n;\n");\r
- fprintf(fp, "; Info is in: pointer to text, address, shift value, mask value, size of data chunk\n");\r
- fprintf(fp, ";\n\n");\r
- fprintf(fp, "RegTable:\n");\r
-\r
- // Pointer to text, address, shift value, mask, size\r
-\r
- fprintf(fp, " dd RegTextPC, _z80pc - _%scontextBegin, 0, 0ffffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextSP, _z80sp - _%scontextBegin, 0, 0ffffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextAF, _z80af - _%scontextBegin, 0, 0ffffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextBC, _z80bc - _%scontextBegin, 0, 0ffffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextDE, _z80de - _%scontextBegin, 0, 0ffffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextHL, _z80hl - _%scontextBegin, 0, 0ffffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextAFP, _z80af - _%scontextBegin, 0, 0ffffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextBCP, _z80bc - _%scontextBegin, 0, 0ffffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextDEP, _z80de - _%scontextBegin, 0, 0ffffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextHLP, _z80hl - _%scontextBegin, 0, 0ffffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextIX, _z80ix - _%scontextBegin, 0, 0ffffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextIY, _z80iy - _%scontextBegin, 0, 0ffffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextI, _z80i - _%scontextBegin, 0, 0ffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextR, _z80r - _%scontextBegin, 0, 0ffh\n", cpubasename);\r
-\r
- // Individual regs\r
-\r
- fprintf(fp, " dd RegTextA, (_z80af + 1) - _%scontextBegin, 0, 0ffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextF, _z80af - _%scontextBegin, 0, 0ffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextB, (_z80bc + 1) - _%scontextBegin, 0, 0ffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextC, _z80bc - _%scontextBegin, 0, 0ffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextD, (_z80de + 1) - _%scontextBegin, 0, 0ffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextE, _z80de - _%scontextBegin, 0, 0ffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextH, (_z80hl + 1) - _%scontextBegin, 0, 0ffh\n", cpubasename);\r
- fprintf(fp, " dd RegTextL, _z80hl - _%scontextBegin, 0, 0ffh\n", cpubasename);\r
-\r
- // IFF register\r
-\r
- fprintf(fp, " dd RegTextIFF1, _z80iff - _%scontextBegin, 0, 01h\n", cpubasename);\r
- fprintf(fp, " dd RegTextIFF2, _z80iff - _%scontextBegin, 1, 01h\n", cpubasename);\r
-\r
- // Individual flags\r
-\r
- fprintf(fp, " dd RegTextCarry, _z80af - _%scontextBegin, 0, 01h\n", cpubasename);\r
- fprintf(fp, " dd RegTextNegative, _z80af - _%scontextBegin, 1, 01h\n", cpubasename);\r
- fprintf(fp, " dd RegTextParity, _z80af - _%scontextBegin, 2, 01h\n", cpubasename);\r
- fprintf(fp, " dd RegTextOverflow, _z80af - _%scontextBegin, 2, 01h\n", cpubasename);\r
- fprintf(fp, " dd RegTextHalfCarry, _z80af - _%scontextBegin, 4, 01h\n", cpubasename);\r
- fprintf(fp, " dd RegTextZero, _z80af - _%scontextBegin, 6, 01h\n", cpubasename);\r
- fprintf(fp, " dd RegTextSign, _z80af - _%scontextBegin, 7, 01h\n", cpubasename);\r
-\r
- // Now we write out our tables\r
- \r
- Alignment();\r
- \r
- for (dwLoop = 0; dwLoop < 256; dwLoop++)\r
- bUsed[dwLoop] = 0;\r
-\r
- // Now rip through and find out what is and isn't used\r
- \r
- dwLoop = 0;\r
- \r
- while (StandardOps[dwLoop].Emitter)\r
- {\r
- assert(StandardOps[dwLoop].bOpCode < 0x100);\r
- if (bUsed[StandardOps[dwLoop].bOpCode])\r
- {\r
- fprintf(stderr, "Oops! %.2x\n", dwLoop);\r
- fclose(fp);\r
- exit(1);\r
- }\r
- bUsed[StandardOps[dwLoop].bOpCode] = 1;\r
- dwLoop++;\r
- }\r
- \r
- // Now that that's taken care of, emit the table\r
- \r
- fprintf(fp, "z80regular:\n");\r
- \r
- dwLoop = 0;\r
- \r
- while (dwLoop < 0x100)\r
- {\r
- fprintf(fp, " dd ");\r
- if (bUsed[dwLoop])\r
- fprintf(fp, "RegInst%.2x", dwLoop);\r
- else\r
- fprintf(fp, "invalidInsByte");\r
- fprintf(fp, "\n");\r
- dwLoop++;\r
- }\r
- fprintf(fp, "\n");\r
- \r
- // Now rip through and find out what is and isn't used (CB Ops)\r
- \r
- for (dwLoop = 0; dwLoop < 0x100; dwLoop++)\r
- bUsed[dwLoop] = 0;\r
- \r
- dwLoop = 0;\r
- \r
- while (CBOps[dwLoop].Emitter)\r
- {\r
- assert(CBOps[dwLoop].bOpCode < 0x100);\r
- if (bUsed[CBOps[dwLoop].bOpCode])\r
- {\r
- fprintf(stderr, "Oops CB! %.2x\n", dwLoop);\r
- fclose(fp);\r
- exit(1);\r
- }\r
- bUsed[CBOps[dwLoop].bOpCode] = 1;\r
- dwLoop++;\r
- }\r
- \r
- dwLoop = 0;\r
- \r
- // Let's emit the CB prefixes\r
- \r
- fprintf(fp, "z80PrefixCB:\n");\r
- \r
- while (dwLoop < 0x100)\r
- {\r
- fprintf(fp, " dd ");\r
- if (bUsed[dwLoop])\r
- fprintf(fp, "CBInst%.2x", dwLoop);\r
- else\r
- fprintf(fp, "invalidInsWord");\r
- fprintf(fp, "\n");\r
- dwLoop++;\r
- }\r
- fprintf(fp, "\n");\r
- \r
- // Now rip through and find out what is and isn't used (ED Ops)\r
- \r
- for (dwLoop = 0; dwLoop < 0x100; dwLoop++)\r
- bUsed[dwLoop] = 0;\r
- \r
- dwLoop = 0;\r
- \r
- while (EDOps[dwLoop].Emitter)\r
- {\r
- assert(EDOps[dwLoop].bOpCode < 0x100);\r
- if (bUsed[EDOps[dwLoop].bOpCode])\r
- {\r
- fprintf(stderr, "Oops ED! %.2x\n", dwLoop);\r
- fclose(fp);\r
- exit(1);\r
- }\r
- bUsed[EDOps[dwLoop].bOpCode] = 1;\r
- dwLoop++;\r
- }\r
- \r
- dwLoop = 0;\r
- \r
- // Let's emit the ED prefixes\r
- \r
- fprintf(fp, "z80PrefixED:\n");\r
- \r
- while (dwLoop < 0x100)\r
- {\r
- fprintf(fp, " dd ");\r
- if (bUsed[dwLoop])\r
- fprintf(fp, "EDInst%.2x", dwLoop);\r
- else\r
- fprintf(fp, "invalidInsWord");\r
- fprintf(fp, "\n");\r
- dwLoop++;\r
- }\r
- fprintf(fp, "\n");\r
- \r
- // Now rip through and find out what is and isn't used (DD Ops)\r
- \r
- for (dwLoop = 0; dwLoop < 0x100; dwLoop++)\r
- bUsed[dwLoop] = 0;\r
- \r
- dwLoop = 0;\r
- \r
- while (DDFDOps[dwLoop].Emitter)\r
- {\r
- assert(DDFDOps[dwLoop].bOpCode < 0x100);\r
- if (bUsed[DDFDOps[dwLoop].bOpCode])\r
- {\r
- fprintf(stderr, "Oops DD! %.2x\n", bUsed[DDFDOps[dwLoop].bOpCode]);\r
- fclose(fp);\r
- exit(1);\r
- }\r
- bUsed[DDFDOps[dwLoop].bOpCode] = 1;\r
- dwLoop++;\r
- }\r
- \r
- dwLoop = 0;\r
- \r
- // Let's emit the DD prefixes\r
- \r
- fprintf(fp, "z80PrefixDD:\n");\r
- \r
- while (dwLoop < 0x100)\r
- {\r
- fprintf(fp, " dd ");\r
- if (bUsed[dwLoop])\r
- fprintf(fp, "DDInst%.2x", dwLoop);\r
- else\r
- fprintf(fp, "invalidInsWord");\r
- fprintf(fp, "\n");\r
- dwLoop++;\r
- }\r
- fprintf(fp, "\n");\r
- \r
- // Now rip through and find out what is and isn't used (FD Ops)\r
- \r
- for (dwLoop = 0; dwLoop < 0x100; dwLoop++)\r
- bUsed[dwLoop] = 0;\r
- \r
- dwLoop = 0;\r
- \r
- while (DDFDOps[dwLoop].Emitter)\r
- {\r
- assert(DDFDOps[dwLoop].bOpCode < 0x100);\r
- if (bUsed[DDFDOps[dwLoop].bOpCode])\r
- {\r
- fprintf(stderr, "Oops FD! %.2x\n", dwLoop);\r
- fclose(fp);\r
- exit(1);\r
- }\r
- bUsed[DDFDOps[dwLoop].bOpCode] = 1;\r
- dwLoop++;\r
- }\r
- \r
- for (dwLoop = 0; dwLoop < 0x100; dwLoop++)\r
- bUsed[dwLoop] = 0;\r
- \r
- // Let's emit the DDFD prefixes\r
- \r
- for (dwLoop = 0; dwLoop < 0x100; dwLoop++)\r
- bUsed[dwLoop] = 0;\r
- \r
- dwLoop = 0;\r
- \r
- while (DDFDOps[dwLoop].Emitter)\r
- {\r
- assert(DDFDOps[dwLoop].bOpCode < 0x100);\r
- if (bUsed[DDFDOps[dwLoop].bOpCode])\r
- {\r
- fprintf(stderr, "Oops FD! %.2x\n", dwLoop);\r
- exit(1);\r
- }\r
- bUsed[DDFDOps[dwLoop].bOpCode] = 1;\r
- dwLoop++;\r
- }\r
- \r
- dwLoop = 0;\r
- \r
- // Let's emit the DDFD prefixes\r
- \r
- fprintf(fp, "z80PrefixFD:\n");\r
- \r
- while (dwLoop < 0x100)\r
- {\r
- fprintf(fp, " dd ");\r
- if (bUsed[dwLoop])\r
- fprintf(fp, "FDInst%.2x", dwLoop);\r
- else\r
- fprintf(fp, "invalidInsWord");\r
- fprintf(fp, "\n");\r
- dwLoop++;\r
- }\r
- \r
- for (dwLoop = 0; dwLoop < 0x100; dwLoop++)\r
- bUsed[dwLoop] = 0;\r
- \r
- dwLoop = 0;\r
- \r
- while (DDFDCBOps[dwLoop].Emitter)\r
- {\r
- assert(DDFDCBOps[dwLoop].bOpCode < 0x100);\r
- if (bUsed[DDFDCBOps[dwLoop].bOpCode])\r
- {\r
- fprintf(stderr, "Oops CBFDDD! %.2x\n", bUsed[DDFDCBOps[dwLoop].bOpCode]);\r
- fclose(fp);\r
- exit(1);\r
- }\r
- bUsed[DDFDCBOps[dwLoop].bOpCode] = 1;\r
- dwLoop++;\r
- }\r
- \r
- // Let's emit the DDFD prefixes\r
- \r
- dwLoop = 0;\r
- \r
- fprintf(fp, "z80ddfdcbInstructions:\n");\r
- \r
- while (dwLoop < 0x100)\r
- {\r
- fprintf(fp, " dd ");\r
- if (bUsed[dwLoop])\r
- fprintf(fp, "DDFDCBInst%.2x", dwLoop);\r
- else\r
- fprintf(fp, "invalidInsWord");\r
- fprintf(fp, "\n");\r
- dwLoop++;\r
- }\r
- fprintf(fp, "\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "/* Modular global variables go here*/\n\n");\r
- fprintf(fp, "static CONTEXTMZ80 cpu; /* CPU Context */\n");\r
- fprintf(fp, "static UINT8 *pbPC; /* Program counter normalized */\n");\r
- fprintf(fp, "static UINT8 *pbSP; /* Stack pointer normalized */\n");\r
- fprintf(fp, "static struct MemoryReadByte *psMemRead; /* Read memory structure */\n");\r
- fprintf(fp, "static struct MemoryWriteByte *psMemWrite; /* Write memory structure */\n");\r
- fprintf(fp, "static struct z80PortRead *psIoRead; /* Read I/O structure */\n");\r
- fprintf(fp, "static struct z80PortWrite *psIoWrite; /* Write memory structure */\n");\r
- fprintf(fp, "static INT32 sdwCyclesRemaining; /* Used as a countdown */\n");\r
- fprintf(fp, "static UINT32 dwReturnCode; /* Return code from exec() */\n");\r
- fprintf(fp, "static UINT32 dwOriginalCycles; /* How many cycles did we start with? */\n");\r
- fprintf(fp, "static UINT32 dwElapsedTicks; /* How many ticks did we elapse? */\n");\r
- fprintf(fp, "static INT32 sdwAddr; /* Temporary address storage */\n");\r
- fprintf(fp, "static UINT32 dwAddr; /* Temporary stack address */\n");\r
- fprintf(fp, "static UINT8 *pbAddAdcTable; /* Pointer to add/adc flag table */\n");\r
- fprintf(fp, "static UINT8 *pbSubSbcTable; /* Pointer to sub/sbc flag table */\n");\r
- fprintf(fp, "static UINT32 dwTemp; /* Temporary value */\n\n");\r
- fprintf(fp, "static UINT8 bTemp; /* Temporary value */\n\n");\r
- fprintf(fp, "static UINT8 bTemp2; /* Temporary value */\n\n");\r
-\r
- fprintf(fp, "/* Precomputed flag tables */\n\n");\r
-\r
- fprintf(fp, "static UINT8 bPostIncFlags[0x100] = \n");\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,\n");\r
- fprintf(fp, " 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,\n");\r
- fprintf(fp, " 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,\n");\r
- fprintf(fp, " 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,\n");\r
- fprintf(fp, " 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,\n");\r
- fprintf(fp, " 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,\n");\r
- fprintf(fp, " 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,\n");\r
- fprintf(fp, " 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x94,\n");\r
- fprintf(fp, " 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,\n");\r
- fprintf(fp, " 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,\n");\r
- fprintf(fp, " 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,\n");\r
- fprintf(fp, " 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,\n");\r
- fprintf(fp, " 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,\n");\r
- fprintf(fp, " 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,\n");\r
- fprintf(fp, " 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,\n");\r
- fprintf(fp, " 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x50\n");\r
- fprintf(fp, "};\n\n");\r
-\r
- fprintf(fp, "static UINT8 bPostDecFlags[0x100] = \n");\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " 0x92,0x42,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,\n");\r
- fprintf(fp, " 0x12,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,\n");\r
- fprintf(fp, " 0x12,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,\n");\r
- fprintf(fp, " 0x12,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,\n");\r
- fprintf(fp, " 0x12,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,\n");\r
- fprintf(fp, " 0x12,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,\n");\r
- fprintf(fp, " 0x12,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,\n");\r
- fprintf(fp, " 0x12,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,\n");\r
- fprintf(fp, " 0x16,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,\n");\r
- fprintf(fp, " 0x92,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,\n");\r
- fprintf(fp, " 0x92,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,\n");\r
- fprintf(fp, " 0x92,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,\n");\r
- fprintf(fp, " 0x92,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,\n");\r
- fprintf(fp, " 0x92,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,\n");\r
- fprintf(fp, " 0x92,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,\n");\r
- fprintf(fp, " 0x92,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82\n");\r
- fprintf(fp, "};\n\n");\r
-\r
- fprintf(fp, "static UINT8 bPostORFlags[0x100] = \n");\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " 0x44,0x00,0x00,0x04,0x00,0x04,0x04,0x00,0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04,\n");\r
- fprintf(fp, " 0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04,0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00,\n");\r
- fprintf(fp, " 0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04,0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00,\n");\r
- fprintf(fp, " 0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00,0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04,\n");\r
- fprintf(fp, " 0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04,0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00,\n");\r
- fprintf(fp, " 0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00,0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04,\n");\r
- fprintf(fp, " 0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00,0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04,\n");\r
- fprintf(fp, " 0x00,0x04,0x04,0x00,0x04,0x00,0x00,0x04,0x04,0x00,0x00,0x04,0x00,0x04,0x04,0x00,\n");\r
- fprintf(fp, " 0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84,0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80,\n");\r
- fprintf(fp, " 0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80,0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84,\n");\r
- fprintf(fp, " 0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80,0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84,\n");\r
- fprintf(fp, " 0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84,0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80,\n");\r
- fprintf(fp, " 0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80,0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84,\n");\r
- fprintf(fp, " 0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84,0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80,\n");\r
- fprintf(fp, " 0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84,0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80,\n");\r
- fprintf(fp, " 0x84,0x80,0x80,0x84,0x80,0x84,0x84,0x80,0x80,0x84,0x84,0x80,0x84,0x80,0x80,0x84\n");\r
- fprintf(fp, "};\n\n");\r
-\r
- fprintf(fp, "static UINT8 bPostANDFlags[0x100] = \n");\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " 0x54,0x10,0x10,0x14,0x10,0x14,0x14,0x10,0x10,0x14,0x14,0x10,0x14,0x10,0x10,0x14,\n");\r
- fprintf(fp, " 0x10,0x14,0x14,0x10,0x14,0x10,0x10,0x14,0x14,0x10,0x10,0x14,0x10,0x14,0x14,0x10,\n");\r
- fprintf(fp, " 0x10,0x14,0x14,0x10,0x14,0x10,0x10,0x14,0x14,0x10,0x10,0x14,0x10,0x14,0x14,0x10,\n");\r
- fprintf(fp, " 0x14,0x10,0x10,0x14,0x10,0x14,0x14,0x10,0x10,0x14,0x14,0x10,0x14,0x10,0x10,0x14,\n");\r
- fprintf(fp, " 0x10,0x14,0x14,0x10,0x14,0x10,0x10,0x14,0x14,0x10,0x10,0x14,0x10,0x14,0x14,0x10,\n");\r
- fprintf(fp, " 0x14,0x10,0x10,0x14,0x10,0x14,0x14,0x10,0x10,0x14,0x14,0x10,0x14,0x10,0x10,0x14,\n");\r
- fprintf(fp, " 0x14,0x10,0x10,0x14,0x10,0x14,0x14,0x10,0x10,0x14,0x14,0x10,0x14,0x10,0x10,0x14,\n");\r
- fprintf(fp, " 0x10,0x14,0x14,0x10,0x14,0x10,0x10,0x14,0x14,0x10,0x10,0x14,0x10,0x14,0x14,0x10,\n");\r
- fprintf(fp, " 0x90,0x94,0x94,0x90,0x94,0x90,0x90,0x94,0x94,0x90,0x90,0x94,0x90,0x94,0x94,0x90,\n");\r
- fprintf(fp, " 0x94,0x90,0x90,0x94,0x90,0x94,0x94,0x90,0x90,0x94,0x94,0x90,0x94,0x90,0x90,0x94,\n");\r
- fprintf(fp, " 0x94,0x90,0x90,0x94,0x90,0x94,0x94,0x90,0x90,0x94,0x94,0x90,0x94,0x90,0x90,0x94,\n");\r
- fprintf(fp, " 0x90,0x94,0x94,0x90,0x94,0x90,0x90,0x94,0x94,0x90,0x90,0x94,0x90,0x94,0x94,0x90,\n");\r
- fprintf(fp, " 0x94,0x90,0x90,0x94,0x90,0x94,0x94,0x90,0x90,0x94,0x94,0x90,0x94,0x90,0x90,0x94,\n");\r
- fprintf(fp, " 0x90,0x94,0x94,0x90,0x94,0x90,0x90,0x94,0x94,0x90,0x90,0x94,0x90,0x94,0x94,0x90,\n");\r
- fprintf(fp, " 0x90,0x94,0x94,0x90,0x94,0x90,0x90,0x94,0x94,0x90,0x90,0x94,0x90,0x94,0x94,0x90,\n");\r
- fprintf(fp, " 0x94,0x90,0x90,0x94,0x90,0x94,0x94,0x90,0x90,0x94,0x94,0x90,0x94,0x90,0x90,0x94\n");\r
- fprintf(fp, "};\n\n");\r
-\r
- fprintf(fp, "static UINT16 wDAATable[0x800] = \n");\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " 0x5400,0x1001,0x1002,0x1403,0x1004,0x1405,0x1406,0x1007,\n");\r
- fprintf(fp, " 0x1008,0x1409,0x1010,0x1411,0x1412,0x1013,0x1414,0x1015,\n");\r
- fprintf(fp, " 0x1010,0x1411,0x1412,0x1013,0x1414,0x1015,0x1016,0x1417,\n");\r
- fprintf(fp, " 0x1418,0x1019,0x1020,0x1421,0x1422,0x1023,0x1424,0x1025,\n");\r
- fprintf(fp, " 0x1020,0x1421,0x1422,0x1023,0x1424,0x1025,0x1026,0x1427,\n");\r
- fprintf(fp, " 0x1428,0x1029,0x1430,0x1031,0x1032,0x1433,0x1034,0x1435,\n");\r
- fprintf(fp, " 0x1430,0x1031,0x1032,0x1433,0x1034,0x1435,0x1436,0x1037,\n");\r
- fprintf(fp, " 0x1038,0x1439,0x1040,0x1441,0x1442,0x1043,0x1444,0x1045,\n");\r
- fprintf(fp, " 0x1040,0x1441,0x1442,0x1043,0x1444,0x1045,0x1046,0x1447,\n");\r
- fprintf(fp, " 0x1448,0x1049,0x1450,0x1051,0x1052,0x1453,0x1054,0x1455,\n");\r
- fprintf(fp, " 0x1450,0x1051,0x1052,0x1453,0x1054,0x1455,0x1456,0x1057,\n");\r
- fprintf(fp, " 0x1058,0x1459,0x1460,0x1061,0x1062,0x1463,0x1064,0x1465,\n");\r
- fprintf(fp, " 0x1460,0x1061,0x1062,0x1463,0x1064,0x1465,0x1466,0x1067,\n");\r
- fprintf(fp, " 0x1068,0x1469,0x1070,0x1471,0x1472,0x1073,0x1474,0x1075,\n");\r
- fprintf(fp, " 0x1070,0x1471,0x1472,0x1073,0x1474,0x1075,0x1076,0x1477,\n");\r
- fprintf(fp, " 0x1478,0x1079,0x9080,0x9481,0x9482,0x9083,0x9484,0x9085,\n");\r
- fprintf(fp, " 0x9080,0x9481,0x9482,0x9083,0x9484,0x9085,0x9086,0x9487,\n");\r
- fprintf(fp, " 0x9488,0x9089,0x9490,0x9091,0x9092,0x9493,0x9094,0x9495,\n");\r
- fprintf(fp, " 0x9490,0x9091,0x9092,0x9493,0x9094,0x9495,0x9496,0x9097,\n");\r
- fprintf(fp, " 0x9098,0x9499,0x5500,0x1101,0x1102,0x1503,0x1104,0x1505,\n");\r
- fprintf(fp, " 0x5500,0x1101,0x1102,0x1503,0x1104,0x1505,0x1506,0x1107,\n");\r
- fprintf(fp, " 0x1108,0x1509,0x1110,0x1511,0x1512,0x1113,0x1514,0x1115,\n");\r
- fprintf(fp, " 0x1110,0x1511,0x1512,0x1113,0x1514,0x1115,0x1116,0x1517,\n");\r
- fprintf(fp, " 0x1518,0x1119,0x1120,0x1521,0x1522,0x1123,0x1524,0x1125,\n");\r
- fprintf(fp, " 0x1120,0x1521,0x1522,0x1123,0x1524,0x1125,0x1126,0x1527,\n");\r
- fprintf(fp, " 0x1528,0x1129,0x1530,0x1131,0x1132,0x1533,0x1134,0x1535,\n");\r
- fprintf(fp, " 0x1530,0x1131,0x1132,0x1533,0x1134,0x1535,0x1536,0x1137,\n");\r
- fprintf(fp, " 0x1138,0x1539,0x1140,0x1541,0x1542,0x1143,0x1544,0x1145,\n");\r
- fprintf(fp, " 0x1140,0x1541,0x1542,0x1143,0x1544,0x1145,0x1146,0x1547,\n");\r
- fprintf(fp, " 0x1548,0x1149,0x1550,0x1151,0x1152,0x1553,0x1154,0x1555,\n");\r
- fprintf(fp, " 0x1550,0x1151,0x1152,0x1553,0x1154,0x1555,0x1556,0x1157,\n");\r
- fprintf(fp, " 0x1158,0x1559,0x1560,0x1161,0x1162,0x1563,0x1164,0x1565,\n");\r
- fprintf(fp, " 0x1560,0x1161,0x1162,0x1563,0x1164,0x1565,0x1566,0x1167,\n");\r
- fprintf(fp, " 0x1168,0x1569,0x1170,0x1571,0x1572,0x1173,0x1574,0x1175,\n");\r
- fprintf(fp, " 0x1170,0x1571,0x1572,0x1173,0x1574,0x1175,0x1176,0x1577,\n");\r
- fprintf(fp, " 0x1578,0x1179,0x9180,0x9581,0x9582,0x9183,0x9584,0x9185,\n");\r
- fprintf(fp, " 0x9180,0x9581,0x9582,0x9183,0x9584,0x9185,0x9186,0x9587,\n");\r
- fprintf(fp, " 0x9588,0x9189,0x9590,0x9191,0x9192,0x9593,0x9194,0x9595,\n");\r
- fprintf(fp, " 0x9590,0x9191,0x9192,0x9593,0x9194,0x9595,0x9596,0x9197,\n");\r
- fprintf(fp, " 0x9198,0x9599,0x95a0,0x91a1,0x91a2,0x95a3,0x91a4,0x95a5,\n");\r
- fprintf(fp, " 0x95a0,0x91a1,0x91a2,0x95a3,0x91a4,0x95a5,0x95a6,0x91a7,\n");\r
- fprintf(fp, " 0x91a8,0x95a9,0x91b0,0x95b1,0x95b2,0x91b3,0x95b4,0x91b5,\n");\r
- fprintf(fp, " 0x91b0,0x95b1,0x95b2,0x91b3,0x95b4,0x91b5,0x91b6,0x95b7,\n");\r
- fprintf(fp, " 0x95b8,0x91b9,0x95c0,0x91c1,0x91c2,0x95c3,0x91c4,0x95c5,\n");\r
- fprintf(fp, " 0x95c0,0x91c1,0x91c2,0x95c3,0x91c4,0x95c5,0x95c6,0x91c7,\n");\r
- fprintf(fp, " 0x91c8,0x95c9,0x91d0,0x95d1,0x95d2,0x91d3,0x95d4,0x91d5,\n");\r
- fprintf(fp, " 0x91d0,0x95d1,0x95d2,0x91d3,0x95d4,0x91d5,0x91d6,0x95d7,\n");\r
- fprintf(fp, " 0x95d8,0x91d9,0x91e0,0x95e1,0x95e2,0x91e3,0x95e4,0x91e5,\n");\r
- fprintf(fp, " 0x91e0,0x95e1,0x95e2,0x91e3,0x95e4,0x91e5,0x91e6,0x95e7,\n");\r
- fprintf(fp, " 0x95e8,0x91e9,0x95f0,0x91f1,0x91f2,0x95f3,0x91f4,0x95f5,\n");\r
- fprintf(fp, " 0x95f0,0x91f1,0x91f2,0x95f3,0x91f4,0x95f5,0x95f6,0x91f7,\n");\r
- fprintf(fp, " 0x91f8,0x95f9,0x5500,0x1101,0x1102,0x1503,0x1104,0x1505,\n");\r
- fprintf(fp, " 0x5500,0x1101,0x1102,0x1503,0x1104,0x1505,0x1506,0x1107,\n");\r
- fprintf(fp, " 0x1108,0x1509,0x1110,0x1511,0x1512,0x1113,0x1514,0x1115,\n");\r
- fprintf(fp, " 0x1110,0x1511,0x1512,0x1113,0x1514,0x1115,0x1116,0x1517,\n");\r
- fprintf(fp, " 0x1518,0x1119,0x1120,0x1521,0x1522,0x1123,0x1524,0x1125,\n");\r
- fprintf(fp, " 0x1120,0x1521,0x1522,0x1123,0x1524,0x1125,0x1126,0x1527,\n");\r
- fprintf(fp, " 0x1528,0x1129,0x1530,0x1131,0x1132,0x1533,0x1134,0x1535,\n");\r
- fprintf(fp, " 0x1530,0x1131,0x1132,0x1533,0x1134,0x1535,0x1536,0x1137,\n");\r
- fprintf(fp, " 0x1138,0x1539,0x1140,0x1541,0x1542,0x1143,0x1544,0x1145,\n");\r
- fprintf(fp, " 0x1140,0x1541,0x1542,0x1143,0x1544,0x1145,0x1146,0x1547,\n");\r
- fprintf(fp, " 0x1548,0x1149,0x1550,0x1151,0x1152,0x1553,0x1154,0x1555,\n");\r
- fprintf(fp, " 0x1550,0x1151,0x1152,0x1553,0x1154,0x1555,0x1556,0x1157,\n");\r
- fprintf(fp, " 0x1158,0x1559,0x1560,0x1161,0x1162,0x1563,0x1164,0x1565,\n");\r
- fprintf(fp, " 0x1406,0x1007,0x1008,0x1409,0x140a,0x100b,0x140c,0x100d,\n");\r
- fprintf(fp, " 0x100e,0x140f,0x1010,0x1411,0x1412,0x1013,0x1414,0x1015,\n");\r
- fprintf(fp, " 0x1016,0x1417,0x1418,0x1019,0x101a,0x141b,0x101c,0x141d,\n");\r
- fprintf(fp, " 0x141e,0x101f,0x1020,0x1421,0x1422,0x1023,0x1424,0x1025,\n");\r
- fprintf(fp, " 0x1026,0x1427,0x1428,0x1029,0x102a,0x142b,0x102c,0x142d,\n");\r
- fprintf(fp, " 0x142e,0x102f,0x1430,0x1031,0x1032,0x1433,0x1034,0x1435,\n");\r
- fprintf(fp, " 0x1436,0x1037,0x1038,0x1439,0x143a,0x103b,0x143c,0x103d,\n");\r
- fprintf(fp, " 0x103e,0x143f,0x1040,0x1441,0x1442,0x1043,0x1444,0x1045,\n");\r
- fprintf(fp, " 0x1046,0x1447,0x1448,0x1049,0x104a,0x144b,0x104c,0x144d,\n");\r
- fprintf(fp, " 0x144e,0x104f,0x1450,0x1051,0x1052,0x1453,0x1054,0x1455,\n");\r
- fprintf(fp, " 0x1456,0x1057,0x1058,0x1459,0x145a,0x105b,0x145c,0x105d,\n");\r
- fprintf(fp, " 0x105e,0x145f,0x1460,0x1061,0x1062,0x1463,0x1064,0x1465,\n");\r
- fprintf(fp, " 0x1466,0x1067,0x1068,0x1469,0x146a,0x106b,0x146c,0x106d,\n");\r
- fprintf(fp, " 0x106e,0x146f,0x1070,0x1471,0x1472,0x1073,0x1474,0x1075,\n");\r
- fprintf(fp, " 0x1076,0x1477,0x1478,0x1079,0x107a,0x147b,0x107c,0x147d,\n");\r
- fprintf(fp, " 0x147e,0x107f,0x9080,0x9481,0x9482,0x9083,0x9484,0x9085,\n");\r
- fprintf(fp, " 0x9086,0x9487,0x9488,0x9089,0x908a,0x948b,0x908c,0x948d,\n");\r
- fprintf(fp, " 0x948e,0x908f,0x9490,0x9091,0x9092,0x9493,0x9094,0x9495,\n");\r
- fprintf(fp, " 0x9496,0x9097,0x9098,0x9499,0x949a,0x909b,0x949c,0x909d,\n");\r
- fprintf(fp, " 0x909e,0x949f,0x5500,0x1101,0x1102,0x1503,0x1104,0x1505,\n");\r
- fprintf(fp, " 0x1506,0x1107,0x1108,0x1509,0x150a,0x110b,0x150c,0x110d,\n");\r
- fprintf(fp, " 0x110e,0x150f,0x1110,0x1511,0x1512,0x1113,0x1514,0x1115,\n");\r
- fprintf(fp, " 0x1116,0x1517,0x1518,0x1119,0x111a,0x151b,0x111c,0x151d,\n");\r
- fprintf(fp, " 0x151e,0x111f,0x1120,0x1521,0x1522,0x1123,0x1524,0x1125,\n");\r
- fprintf(fp, " 0x1126,0x1527,0x1528,0x1129,0x112a,0x152b,0x112c,0x152d,\n");\r
- fprintf(fp, " 0x152e,0x112f,0x1530,0x1131,0x1132,0x1533,0x1134,0x1535,\n");\r
- fprintf(fp, " 0x1536,0x1137,0x1138,0x1539,0x153a,0x113b,0x153c,0x113d,\n");\r
- fprintf(fp, " 0x113e,0x153f,0x1140,0x1541,0x1542,0x1143,0x1544,0x1145,\n");\r
- fprintf(fp, " 0x1146,0x1547,0x1548,0x1149,0x114a,0x154b,0x114c,0x154d,\n");\r
- fprintf(fp, " 0x154e,0x114f,0x1550,0x1151,0x1152,0x1553,0x1154,0x1555,\n");\r
- fprintf(fp, " 0x1556,0x1157,0x1158,0x1559,0x155a,0x115b,0x155c,0x115d,\n");\r
- fprintf(fp, " 0x115e,0x155f,0x1560,0x1161,0x1162,0x1563,0x1164,0x1565,\n");\r
- fprintf(fp, " 0x1566,0x1167,0x1168,0x1569,0x156a,0x116b,0x156c,0x116d,\n");\r
- fprintf(fp, " 0x116e,0x156f,0x1170,0x1571,0x1572,0x1173,0x1574,0x1175,\n");\r
- fprintf(fp, " 0x1176,0x1577,0x1578,0x1179,0x117a,0x157b,0x117c,0x157d,\n");\r
- fprintf(fp, " 0x157e,0x117f,0x9180,0x9581,0x9582,0x9183,0x9584,0x9185,\n");\r
- fprintf(fp, " 0x9186,0x9587,0x9588,0x9189,0x918a,0x958b,0x918c,0x958d,\n");\r
- fprintf(fp, " 0x958e,0x918f,0x9590,0x9191,0x9192,0x9593,0x9194,0x9595,\n");\r
- fprintf(fp, " 0x9596,0x9197,0x9198,0x9599,0x959a,0x919b,0x959c,0x919d,\n");\r
- fprintf(fp, " 0x919e,0x959f,0x95a0,0x91a1,0x91a2,0x95a3,0x91a4,0x95a5,\n");\r
- fprintf(fp, " 0x95a6,0x91a7,0x91a8,0x95a9,0x95aa,0x91ab,0x95ac,0x91ad,\n");\r
- fprintf(fp, " 0x91ae,0x95af,0x91b0,0x95b1,0x95b2,0x91b3,0x95b4,0x91b5,\n");\r
- fprintf(fp, " 0x91b6,0x95b7,0x95b8,0x91b9,0x91ba,0x95bb,0x91bc,0x95bd,\n");\r
- fprintf(fp, " 0x95be,0x91bf,0x95c0,0x91c1,0x91c2,0x95c3,0x91c4,0x95c5,\n");\r
- fprintf(fp, " 0x95c6,0x91c7,0x91c8,0x95c9,0x95ca,0x91cb,0x95cc,0x91cd,\n");\r
- fprintf(fp, " 0x91ce,0x95cf,0x91d0,0x95d1,0x95d2,0x91d3,0x95d4,0x91d5,\n");\r
- fprintf(fp, " 0x91d6,0x95d7,0x95d8,0x91d9,0x91da,0x95db,0x91dc,0x95dd,\n");\r
- fprintf(fp, " 0x95de,0x91df,0x91e0,0x95e1,0x95e2,0x91e3,0x95e4,0x91e5,\n");\r
- fprintf(fp, " 0x91e6,0x95e7,0x95e8,0x91e9,0x91ea,0x95eb,0x91ec,0x95ed,\n");\r
- fprintf(fp, " 0x95ee,0x91ef,0x95f0,0x91f1,0x91f2,0x95f3,0x91f4,0x95f5,\n");\r
- fprintf(fp, " 0x95f6,0x91f7,0x91f8,0x95f9,0x95fa,0x91fb,0x95fc,0x91fd,\n");\r
- fprintf(fp, " 0x91fe,0x95ff,0x5500,0x1101,0x1102,0x1503,0x1104,0x1505,\n");\r
- fprintf(fp, " 0x1506,0x1107,0x1108,0x1509,0x150a,0x110b,0x150c,0x110d,\n");\r
- fprintf(fp, " 0x110e,0x150f,0x1110,0x1511,0x1512,0x1113,0x1514,0x1115,\n");\r
- fprintf(fp, " 0x1116,0x1517,0x1518,0x1119,0x111a,0x151b,0x111c,0x151d,\n");\r
- fprintf(fp, " 0x151e,0x111f,0x1120,0x1521,0x1522,0x1123,0x1524,0x1125,\n");\r
- fprintf(fp, " 0x1126,0x1527,0x1528,0x1129,0x112a,0x152b,0x112c,0x152d,\n");\r
- fprintf(fp, " 0x152e,0x112f,0x1530,0x1131,0x1132,0x1533,0x1134,0x1535,\n");\r
- fprintf(fp, " 0x1536,0x1137,0x1138,0x1539,0x153a,0x113b,0x153c,0x113d,\n");\r
- fprintf(fp, " 0x113e,0x153f,0x1140,0x1541,0x1542,0x1143,0x1544,0x1145,\n");\r
- fprintf(fp, " 0x1146,0x1547,0x1548,0x1149,0x114a,0x154b,0x114c,0x154d,\n");\r
- fprintf(fp, " 0x154e,0x114f,0x1550,0x1151,0x1152,0x1553,0x1154,0x1555,\n");\r
- fprintf(fp, " 0x1556,0x1157,0x1158,0x1559,0x155a,0x115b,0x155c,0x115d,\n");\r
- fprintf(fp, " 0x115e,0x155f,0x1560,0x1161,0x1162,0x1563,0x1164,0x1565,\n");\r
- fprintf(fp, " 0x5600,0x1201,0x1202,0x1603,0x1204,0x1605,0x1606,0x1207,\n");\r
- fprintf(fp, " 0x1208,0x1609,0x1204,0x1605,0x1606,0x1207,0x1208,0x1609,\n");\r
- fprintf(fp, " 0x1210,0x1611,0x1612,0x1213,0x1614,0x1215,0x1216,0x1617,\n");\r
- fprintf(fp, " 0x1618,0x1219,0x1614,0x1215,0x1216,0x1617,0x1618,0x1219,\n");\r
- fprintf(fp, " 0x1220,0x1621,0x1622,0x1223,0x1624,0x1225,0x1226,0x1627,\n");\r
- fprintf(fp, " 0x1628,0x1229,0x1624,0x1225,0x1226,0x1627,0x1628,0x1229,\n");\r
- fprintf(fp, " 0x1630,0x1231,0x1232,0x1633,0x1234,0x1635,0x1636,0x1237,\n");\r
- fprintf(fp, " 0x1238,0x1639,0x1234,0x1635,0x1636,0x1237,0x1238,0x1639,\n");\r
- fprintf(fp, " 0x1240,0x1641,0x1642,0x1243,0x1644,0x1245,0x1246,0x1647,\n");\r
- fprintf(fp, " 0x1648,0x1249,0x1644,0x1245,0x1246,0x1647,0x1648,0x1249,\n");\r
- fprintf(fp, " 0x1650,0x1251,0x1252,0x1653,0x1254,0x1655,0x1656,0x1257,\n");\r
- fprintf(fp, " 0x1258,0x1659,0x1254,0x1655,0x1656,0x1257,0x1258,0x1659,\n");\r
- fprintf(fp, " 0x1660,0x1261,0x1262,0x1663,0x1264,0x1665,0x1666,0x1267,\n");\r
- fprintf(fp, " 0x1268,0x1669,0x1264,0x1665,0x1666,0x1267,0x1268,0x1669,\n");\r
- fprintf(fp, " 0x1270,0x1671,0x1672,0x1273,0x1674,0x1275,0x1276,0x1677,\n");\r
- fprintf(fp, " 0x1678,0x1279,0x1674,0x1275,0x1276,0x1677,0x1678,0x1279,\n");\r
- fprintf(fp, " 0x9280,0x9681,0x9682,0x9283,0x9684,0x9285,0x9286,0x9687,\n");\r
- fprintf(fp, " 0x9688,0x9289,0x9684,0x9285,0x9286,0x9687,0x9688,0x9289,\n");\r
- fprintf(fp, " 0x9690,0x9291,0x9292,0x9693,0x9294,0x9695,0x9696,0x9297,\n");\r
- fprintf(fp, " 0x9298,0x9699,0x1334,0x1735,0x1736,0x1337,0x1338,0x1739,\n");\r
- fprintf(fp, " 0x1340,0x1741,0x1742,0x1343,0x1744,0x1345,0x1346,0x1747,\n");\r
- fprintf(fp, " 0x1748,0x1349,0x1744,0x1345,0x1346,0x1747,0x1748,0x1349,\n");\r
- fprintf(fp, " 0x1750,0x1351,0x1352,0x1753,0x1354,0x1755,0x1756,0x1357,\n");\r
- fprintf(fp, " 0x1358,0x1759,0x1354,0x1755,0x1756,0x1357,0x1358,0x1759,\n");\r
- fprintf(fp, " 0x1760,0x1361,0x1362,0x1763,0x1364,0x1765,0x1766,0x1367,\n");\r
- fprintf(fp, " 0x1368,0x1769,0x1364,0x1765,0x1766,0x1367,0x1368,0x1769,\n");\r
- fprintf(fp, " 0x1370,0x1771,0x1772,0x1373,0x1774,0x1375,0x1376,0x1777,\n");\r
- fprintf(fp, " 0x1778,0x1379,0x1774,0x1375,0x1376,0x1777,0x1778,0x1379,\n");\r
- fprintf(fp, " 0x9380,0x9781,0x9782,0x9383,0x9784,0x9385,0x9386,0x9787,\n");\r
- fprintf(fp, " 0x9788,0x9389,0x9784,0x9385,0x9386,0x9787,0x9788,0x9389,\n");\r
- fprintf(fp, " 0x9790,0x9391,0x9392,0x9793,0x9394,0x9795,0x9796,0x9397,\n");\r
- fprintf(fp, " 0x9398,0x9799,0x9394,0x9795,0x9796,0x9397,0x9398,0x9799,\n");\r
- fprintf(fp, " 0x97a0,0x93a1,0x93a2,0x97a3,0x93a4,0x97a5,0x97a6,0x93a7,\n");\r
- fprintf(fp, " 0x93a8,0x97a9,0x93a4,0x97a5,0x97a6,0x93a7,0x93a8,0x97a9,\n");\r
- fprintf(fp, " 0x93b0,0x97b1,0x97b2,0x93b3,0x97b4,0x93b5,0x93b6,0x97b7,\n");\r
- fprintf(fp, " 0x97b8,0x93b9,0x97b4,0x93b5,0x93b6,0x97b7,0x97b8,0x93b9,\n");\r
- fprintf(fp, " 0x97c0,0x93c1,0x93c2,0x97c3,0x93c4,0x97c5,0x97c6,0x93c7,\n");\r
- fprintf(fp, " 0x93c8,0x97c9,0x93c4,0x97c5,0x97c6,0x93c7,0x93c8,0x97c9,\n");\r
- fprintf(fp, " 0x93d0,0x97d1,0x97d2,0x93d3,0x97d4,0x93d5,0x93d6,0x97d7,\n");\r
- fprintf(fp, " 0x97d8,0x93d9,0x97d4,0x93d5,0x93d6,0x97d7,0x97d8,0x93d9,\n");\r
- fprintf(fp, " 0x93e0,0x97e1,0x97e2,0x93e3,0x97e4,0x93e5,0x93e6,0x97e7,\n");\r
- fprintf(fp, " 0x97e8,0x93e9,0x97e4,0x93e5,0x93e6,0x97e7,0x97e8,0x93e9,\n");\r
- fprintf(fp, " 0x97f0,0x93f1,0x93f2,0x97f3,0x93f4,0x97f5,0x97f6,0x93f7,\n");\r
- fprintf(fp, " 0x93f8,0x97f9,0x93f4,0x97f5,0x97f6,0x93f7,0x93f8,0x97f9,\n");\r
- fprintf(fp, " 0x5700,0x1301,0x1302,0x1703,0x1304,0x1705,0x1706,0x1307,\n");\r
- fprintf(fp, " 0x1308,0x1709,0x1304,0x1705,0x1706,0x1307,0x1308,0x1709,\n");\r
- fprintf(fp, " 0x1310,0x1711,0x1712,0x1313,0x1714,0x1315,0x1316,0x1717,\n");\r
- fprintf(fp, " 0x1718,0x1319,0x1714,0x1315,0x1316,0x1717,0x1718,0x1319,\n");\r
- fprintf(fp, " 0x1320,0x1721,0x1722,0x1323,0x1724,0x1325,0x1326,0x1727,\n");\r
- fprintf(fp, " 0x1728,0x1329,0x1724,0x1325,0x1326,0x1727,0x1728,0x1329,\n");\r
- fprintf(fp, " 0x1730,0x1331,0x1332,0x1733,0x1334,0x1735,0x1736,0x1337,\n");\r
- fprintf(fp, " 0x1338,0x1739,0x1334,0x1735,0x1736,0x1337,0x1338,0x1739,\n");\r
- fprintf(fp, " 0x1340,0x1741,0x1742,0x1343,0x1744,0x1345,0x1346,0x1747,\n");\r
- fprintf(fp, " 0x1748,0x1349,0x1744,0x1345,0x1346,0x1747,0x1748,0x1349,\n");\r
- fprintf(fp, " 0x1750,0x1351,0x1352,0x1753,0x1354,0x1755,0x1756,0x1357,\n");\r
- fprintf(fp, " 0x1358,0x1759,0x1354,0x1755,0x1756,0x1357,0x1358,0x1759,\n");\r
- fprintf(fp, " 0x1760,0x1361,0x1362,0x1763,0x1364,0x1765,0x1766,0x1367,\n");\r
- fprintf(fp, " 0x1368,0x1769,0x1364,0x1765,0x1766,0x1367,0x1368,0x1769,\n");\r
- fprintf(fp, " 0x1370,0x1771,0x1772,0x1373,0x1774,0x1375,0x1376,0x1777,\n");\r
- fprintf(fp, " 0x1778,0x1379,0x1774,0x1375,0x1376,0x1777,0x1778,0x1379,\n");\r
- fprintf(fp, " 0x9380,0x9781,0x9782,0x9383,0x9784,0x9385,0x9386,0x9787,\n");\r
- fprintf(fp, " 0x9788,0x9389,0x9784,0x9385,0x9386,0x9787,0x9788,0x9389,\n");\r
- fprintf(fp, " 0x9790,0x9391,0x9392,0x9793,0x9394,0x9795,0x9796,0x9397,\n");\r
- fprintf(fp, " 0x9398,0x9799,0x9394,0x9795,0x9796,0x9397,0x9398,0x9799,\n");\r
- fprintf(fp, " 0x97fa,0x93fb,0x97fc,0x93fd,0x93fe,0x97ff,0x5600,0x1201,\n");\r
- fprintf(fp, " 0x1202,0x1603,0x1204,0x1605,0x1606,0x1207,0x1208,0x1609,\n");\r
- fprintf(fp, " 0x160a,0x120b,0x160c,0x120d,0x120e,0x160f,0x1210,0x1611,\n");\r
- fprintf(fp, " 0x1612,0x1213,0x1614,0x1215,0x1216,0x1617,0x1618,0x1219,\n");\r
- fprintf(fp, " 0x121a,0x161b,0x121c,0x161d,0x161e,0x121f,0x1220,0x1621,\n");\r
- fprintf(fp, " 0x1622,0x1223,0x1624,0x1225,0x1226,0x1627,0x1628,0x1229,\n");\r
- fprintf(fp, " 0x122a,0x162b,0x122c,0x162d,0x162e,0x122f,0x1630,0x1231,\n");\r
- fprintf(fp, " 0x1232,0x1633,0x1234,0x1635,0x1636,0x1237,0x1238,0x1639,\n");\r
- fprintf(fp, " 0x163a,0x123b,0x163c,0x123d,0x123e,0x163f,0x1240,0x1641,\n");\r
- fprintf(fp, " 0x1642,0x1243,0x1644,0x1245,0x1246,0x1647,0x1648,0x1249,\n");\r
- fprintf(fp, " 0x124a,0x164b,0x124c,0x164d,0x164e,0x124f,0x1650,0x1251,\n");\r
- fprintf(fp, " 0x1252,0x1653,0x1254,0x1655,0x1656,0x1257,0x1258,0x1659,\n");\r
- fprintf(fp, " 0x165a,0x125b,0x165c,0x125d,0x125e,0x165f,0x1660,0x1261,\n");\r
- fprintf(fp, " 0x1262,0x1663,0x1264,0x1665,0x1666,0x1267,0x1268,0x1669,\n");\r
- fprintf(fp, " 0x166a,0x126b,0x166c,0x126d,0x126e,0x166f,0x1270,0x1671,\n");\r
- fprintf(fp, " 0x1672,0x1273,0x1674,0x1275,0x1276,0x1677,0x1678,0x1279,\n");\r
- fprintf(fp, " 0x127a,0x167b,0x127c,0x167d,0x167e,0x127f,0x9280,0x9681,\n");\r
- fprintf(fp, " 0x9682,0x9283,0x9684,0x9285,0x9286,0x9687,0x9688,0x9289,\n");\r
- fprintf(fp, " 0x928a,0x968b,0x928c,0x968d,0x968e,0x928f,0x9690,0x9291,\n");\r
- fprintf(fp, " 0x9292,0x9693,0x1334,0x1735,0x1736,0x1337,0x1338,0x1739,\n");\r
- fprintf(fp, " 0x173a,0x133b,0x173c,0x133d,0x133e,0x173f,0x1340,0x1741,\n");\r
- fprintf(fp, " 0x1742,0x1343,0x1744,0x1345,0x1346,0x1747,0x1748,0x1349,\n");\r
- fprintf(fp, " 0x134a,0x174b,0x134c,0x174d,0x174e,0x134f,0x1750,0x1351,\n");\r
- fprintf(fp, " 0x1352,0x1753,0x1354,0x1755,0x1756,0x1357,0x1358,0x1759,\n");\r
- fprintf(fp, " 0x175a,0x135b,0x175c,0x135d,0x135e,0x175f,0x1760,0x1361,\n");\r
- fprintf(fp, " 0x1362,0x1763,0x1364,0x1765,0x1766,0x1367,0x1368,0x1769,\n");\r
- fprintf(fp, " 0x176a,0x136b,0x176c,0x136d,0x136e,0x176f,0x1370,0x1771,\n");\r
- fprintf(fp, " 0x1772,0x1373,0x1774,0x1375,0x1376,0x1777,0x1778,0x1379,\n");\r
- fprintf(fp, " 0x137a,0x177b,0x137c,0x177d,0x177e,0x137f,0x9380,0x9781,\n");\r
- fprintf(fp, " 0x9782,0x9383,0x9784,0x9385,0x9386,0x9787,0x9788,0x9389,\n");\r
- fprintf(fp, " 0x938a,0x978b,0x938c,0x978d,0x978e,0x938f,0x9790,0x9391,\n");\r
- fprintf(fp, " 0x9392,0x9793,0x9394,0x9795,0x9796,0x9397,0x9398,0x9799,\n");\r
- fprintf(fp, " 0x979a,0x939b,0x979c,0x939d,0x939e,0x979f,0x97a0,0x93a1,\n");\r
- fprintf(fp, " 0x93a2,0x97a3,0x93a4,0x97a5,0x97a6,0x93a7,0x93a8,0x97a9,\n");\r
- fprintf(fp, " 0x97aa,0x93ab,0x97ac,0x93ad,0x93ae,0x97af,0x93b0,0x97b1,\n");\r
- fprintf(fp, " 0x97b2,0x93b3,0x97b4,0x93b5,0x93b6,0x97b7,0x97b8,0x93b9,\n");\r
- fprintf(fp, " 0x93ba,0x97bb,0x93bc,0x97bd,0x97be,0x93bf,0x97c0,0x93c1,\n");\r
- fprintf(fp, " 0x93c2,0x97c3,0x93c4,0x97c5,0x97c6,0x93c7,0x93c8,0x97c9,\n");\r
- fprintf(fp, " 0x97ca,0x93cb,0x97cc,0x93cd,0x93ce,0x97cf,0x93d0,0x97d1,\n");\r
- fprintf(fp, " 0x97d2,0x93d3,0x97d4,0x93d5,0x93d6,0x97d7,0x97d8,0x93d9,\n");\r
- fprintf(fp, " 0x93da,0x97db,0x93dc,0x97dd,0x97de,0x93df,0x93e0,0x97e1,\n");\r
- fprintf(fp, " 0x97e2,0x93e3,0x97e4,0x93e5,0x93e6,0x97e7,0x97e8,0x93e9,\n");\r
- fprintf(fp, " 0x93ea,0x97eb,0x93ec,0x97ed,0x97ee,0x93ef,0x97f0,0x93f1,\n");\r
- fprintf(fp, " 0x93f2,0x97f3,0x93f4,0x97f5,0x97f6,0x93f7,0x93f8,0x97f9,\n");\r
- fprintf(fp, " 0x97fa,0x93fb,0x97fc,0x93fd,0x93fe,0x97ff,0x5700,0x1301,\n");\r
- fprintf(fp, " 0x1302,0x1703,0x1304,0x1705,0x1706,0x1307,0x1308,0x1709,\n");\r
- fprintf(fp, " 0x170a,0x130b,0x170c,0x130d,0x130e,0x170f,0x1310,0x1711,\n");\r
- fprintf(fp, " 0x1712,0x1313,0x1714,0x1315,0x1316,0x1717,0x1718,0x1319,\n");\r
- fprintf(fp, " 0x131a,0x171b,0x131c,0x171d,0x171e,0x131f,0x1320,0x1721,\n");\r
- fprintf(fp, " 0x1722,0x1323,0x1724,0x1325,0x1326,0x1727,0x1728,0x1329,\n");\r
- fprintf(fp, " 0x132a,0x172b,0x132c,0x172d,0x172e,0x132f,0x1730,0x1331,\n");\r
- fprintf(fp, " 0x1332,0x1733,0x1334,0x1735,0x1736,0x1337,0x1338,0x1739,\n");\r
- fprintf(fp, " 0x173a,0x133b,0x173c,0x133d,0x133e,0x173f,0x1340,0x1741,\n");\r
- fprintf(fp, " 0x1742,0x1343,0x1744,0x1345,0x1346,0x1747,0x1748,0x1349,\n");\r
- fprintf(fp, " 0x134a,0x174b,0x134c,0x174d,0x174e,0x134f,0x1750,0x1351,\n");\r
- fprintf(fp, " 0x1352,0x1753,0x1354,0x1755,0x1756,0x1357,0x1358,0x1759,\n");\r
- fprintf(fp, " 0x175a,0x135b,0x175c,0x135d,0x135e,0x175f,0x1760,0x1361,\n");\r
- fprintf(fp, " 0x1362,0x1763,0x1364,0x1765,0x1766,0x1367,0x1368,0x1769,\n");\r
- fprintf(fp, " 0x176a,0x136b,0x176c,0x136d,0x136e,0x176f,0x1370,0x1771,\n");\r
- fprintf(fp, " 0x1772,0x1373,0x1774,0x1375,0x1376,0x1777,0x1778,0x1379,\n");\r
- fprintf(fp, " 0x137a,0x177b,0x137c,0x177d,0x177e,0x137f,0x9380,0x9781,\n");\r
- fprintf(fp, " 0x9782,0x9383,0x9784,0x9385,0x9386,0x9787,0x9788,0x9389,\n");\r
- fprintf(fp, " 0x938a,0x978b,0x938c,0x978d,0x978e,0x938f,0x9790,0x9391,\n");\r
- fprintf(fp, " 0x9392,0x9793,0x9394,0x9795,0x9796,0x9397,0x9398,0x9799 \n");\r
- fprintf(fp, "};\n\n");\r
-\r
- fprintf(fp, "void DDFDCBHandler(UINT32 dwWhich);\n\n");\r
-\r
- fprintf(fp, "\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
- \r
-CodeSegmentBegin()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " section .text use32 flat class=code\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "static void InvalidInstruction(UINT32 dwCount)\n");\r
- fprintf(fp, "{\n");\r
-\r
- fprintf(fp, " pbPC -= dwCount; /* Invalid instruction - back up */\n");\r
- fprintf(fp, " dwReturnCode = (UINT32) pbPC - (UINT32) cpu.z80Base;\n");\r
- fprintf(fp, " dwOriginalCycles -= sdwCyclesRemaining;\n");\r
- fprintf(fp, " sdwCyclesRemaining = 0;\n");\r
-\r
- fprintf(fp, "}\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-CodeSegmentEnd()\r
-{\r
-}\r
-\r
-ProgramEnd()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " end\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-EmitRegularInstructions()\r
-{\r
- UINT32 dwLoop = 0;\r
- UINT32 dwLoop2 = 0;\r
-\r
- bCurrentMode = TIMING_REGULAR;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- while (dwLoop < 0x100)\r
- {\r
- dwLoop2 = 0;\r
- sprintf(procname, "RegInst%.2x", dwLoop);\r
-\r
- while (StandardOps[dwLoop2].bOpCode != dwLoop && StandardOps[dwLoop2].bOpCode != 0xffffffff)\r
- dwLoop2++;\r
-\r
- assert(dwLoop2 < 0x100);\r
- if (StandardOps[dwLoop2].Emitter\r
- && StandardOps[dwLoop2].bOpCode != 0xffffffff)\r
- StandardOps[dwLoop2].Emitter((UINT32) dwLoop);\r
-\r
- dwLoop++;\r
- }\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "/* Main execution entry point */\n\n");\r
-\r
- fprintf(fp, "UINT32 %sexec(UINT32 dwCycles)\n", cpubasename);\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " UINT8 bOpcode;\n\n");\r
-\r
- fprintf(fp, " dwReturnCode = 0x80000000; /* Assume it'll work */\n");\r
-\r
- fprintf(fp, " sdwCyclesRemaining = dwCycles;\n");\r
- fprintf(fp, " dwOriginalCycles = dwCycles;\n");\r
-\r
- fprintf(fp, " if (cpu.z80halted)\n");\r
- fprintf(fp, " {\n");\r
-\r
- fprintf(fp, " dwElapsedTicks += dwCycles;\n");\r
- fprintf(fp, " return(0x80000000);\n");\r
-\r
- fprintf(fp, " }\n\n");\r
- \r
-\r
- fprintf(fp, " pbPC = cpu.z80Base + cpu.z80pc;\n\n");\r
-\r
- fprintf(fp, " while (sdwCyclesRemaining > 0)\n");\r
-\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " bOpcode = *pbPC++;\n");\r
- fprintf(fp, " switch (bOpcode)\n");\r
- fprintf(fp, " {\n");\r
-\r
- while (dwLoop < 0x100)\r
- {\r
- dwLoop2 = 0;\r
-\r
- fprintf(fp, " case 0x%.2x:\n", dwLoop);\r
- fprintf(fp, " {\n");\r
-\r
- while (StandardOps[dwLoop2].bOpCode != dwLoop && StandardOps[dwLoop2].bOpCode != 0xffffffff)\r
- dwLoop2++;\r
-\r
- if (bTimingRegular[dwLoop])\r
- {\r
- fprintf(fp, " sdwCyclesRemaining -= %ld;\n", bTimingRegular[dwLoop]);\r
- }\r
-\r
- if (StandardOps[dwLoop2].Emitter)\r
- {\r
- StandardOps[dwLoop2].Emitter(dwLoop);\r
- }\r
-\r
- fprintf(fp, " break;\n");\r
- fprintf(fp, " }\n");\r
- ++dwLoop;\r
- }\r
-\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " }\n\n");\r
-\r
- fprintf(fp, " dwElapsedTicks += (dwOriginalCycles - sdwCyclesRemaining);\n\n");\r
-\r
- fprintf(fp, " cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;\n");\r
-\r
- fprintf(fp, " return(dwReturnCode); /* Indicate success */\n");\r
- fprintf(fp, "}\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-EmitCBInstructions()\r
-{\r
- UINT32 dwLoop = 0;\r
- UINT32 dwLoop2 = 0;\r
-\r
- bCurrentMode = TIMING_CB;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- while (dwLoop < 0x100)\r
- {\r
- sprintf(procname, "CBInst%.2x", dwLoop);\r
- dwLoop2 = 0;\r
-\r
- while (CBOps[dwLoop2].bOpCode != dwLoop && CBOps[dwLoop2].bOpCode != 0xffffffff)\r
- dwLoop2++;\r
-\r
- assert(dwLoop2 < 0x100);\r
- if (CBOps[dwLoop2].Emitter && CBOps[dwLoop2].bOpCode != 0xffffffff)\r
- CBOps[dwLoop2].Emitter((UINT32) dwLoop);\r
-\r
- dwLoop++;\r
- }\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "void CBHandler(void)\n");\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " switch (*pbPC++)\n");\r
- fprintf(fp, " {\n");\r
-\r
- while (dwLoop < 0x100)\r
- {\r
- dwLoop2 = 0;\r
-\r
- fprintf(fp, " case 0x%.2x:\n", dwLoop);\r
- fprintf(fp, " {\n");\r
-\r
- while (CBOps[dwLoop2].bOpCode != dwLoop && CBOps[dwLoop2].bOpCode != 0xffffffff)\r
- dwLoop2++;\r
-\r
- if (bTimingCB[dwLoop])\r
- {\r
- fprintf(fp, " sdwCyclesRemaining -= %ld;\n", bTimingCB[dwLoop]);\r
- }\r
-\r
- if (CBOps[dwLoop2].Emitter)\r
- {\r
- CBOps[dwLoop2].Emitter(dwLoop);\r
- }\r
- else\r
- {\r
- InvalidInstructionC(2);\r
- }\r
-\r
- fprintf(fp, " break;\n");\r
- fprintf(fp, " }\n");\r
- ++dwLoop;\r
- }\r
-\r
- fprintf(fp, " }\n");\r
- fprintf(fp, "}\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-EmitEDInstructions()\r
-{\r
- UINT32 dwLoop = 0;\r
- UINT32 dwLoop2 = 0;\r
-\r
- bCurrentMode = TIMING_ED;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- while (dwLoop < 0x100)\r
- {\r
- sprintf(procname, "EDInst%.2x", dwLoop);\r
- dwLoop2 = 0;\r
-\r
- while (EDOps[dwLoop2].bOpCode != dwLoop && EDOps[dwLoop2].bOpCode != 0xffffffff)\r
- dwLoop2++;\r
-\r
- assert(dwLoop2 < 0x100);\r
- if (EDOps[dwLoop2].Emitter && EDOps[dwLoop2].bOpCode != 0xffffffff)\r
- EDOps[dwLoop2].Emitter((UINT32) dwLoop);\r
-\r
- dwLoop++;\r
- }\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "void EDHandler(void)\n");\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " switch (*pbPC++)\n");\r
- fprintf(fp, " {\n");\r
-\r
- while (dwLoop < 0x100)\r
- {\r
- dwLoop2 = 0;\r
-\r
- fprintf(fp, " case 0x%.2x:\n", dwLoop);\r
- fprintf(fp, " {\n");\r
-\r
- while (EDOps[dwLoop2].bOpCode != dwLoop && EDOps[dwLoop2].bOpCode != 0xffffffff)\r
- dwLoop2++;\r
-\r
- if (bTimingED[dwLoop])\r
- {\r
- fprintf(fp, " sdwCyclesRemaining -= %ld;\n", bTimingED[dwLoop]);\r
- }\r
-\r
- if (EDOps[dwLoop2].Emitter)\r
- {\r
- EDOps[dwLoop2].Emitter(dwLoop);\r
- }\r
- else\r
- {\r
- InvalidInstructionC(2);\r
- }\r
-\r
- fprintf(fp, " break;\n");\r
- fprintf(fp, " }\n");\r
- ++dwLoop;\r
- }\r
-\r
- fprintf(fp, " }\n");\r
- fprintf(fp, "}\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-\r
- fprintf(fp, "\n");\r
-}\r
-\r
-EmitDDInstructions()\r
-{\r
- UINT32 dwLoop = 0;\r
- UINT32 dwLoop2 = 0;\r
-\r
- bCurrentMode = TIMING_DDFD;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- while (dwLoop < 0x100)\r
- {\r
- sprintf(procname, "DDInst%.2x", dwLoop);\r
- dwLoop2 = 0;\r
- \r
- while (DDFDOps[dwLoop2].bOpCode != dwLoop && DDFDOps[dwLoop2].bOpCode != 0xffffffff)\r
- dwLoop2++;\r
- \r
- assert(dwLoop2 < 0x100);\r
- if (DDFDOps[dwLoop2].Emitter && DDFDOps[dwLoop2].bOpCode != 0xffffffff)\r
- DDFDOps[dwLoop2].Emitter((UINT32) dwLoop);\r
- \r
- dwLoop++;\r
- }\r
-\r
- bCurrentMode = TIMING_XXCB;\r
-\r
- dwLoop = 0;\r
-\r
- while (dwLoop < 0x100)\r
- {\r
- sprintf(procname, "DDFDCBInst%.2x", dwLoop);\r
- dwLoop2 = 0;\r
-\r
- while (DDFDCBOps[dwLoop2].bOpCode != dwLoop && DDFDCBOps[dwLoop2].bOpCode != 0xffffffff)\r
- dwLoop2++;\r
-\r
- assert(dwLoop2 < 0x100);\r
- if (DDFDCBOps[dwLoop2].Emitter && DDFDCBOps[dwLoop2].bOpCode != 0xffffffff)\r
- DDFDCBOps[dwLoop2].Emitter((UINT32) dwLoop);\r
-\r
- dwLoop++;\r
- }\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "void DDHandler(void)\n");\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " switch (*pbPC++)\n");\r
- fprintf(fp, " {\n");\r
-\r
- while (dwLoop < 0x100)\r
- {\r
- dwLoop2 = 0;\r
-\r
- fprintf(fp, " case 0x%.2x:\n", dwLoop);\r
- fprintf(fp, " {\n");\r
-\r
- while (DDFDOps[dwLoop2].bOpCode != dwLoop && DDFDOps[dwLoop2].bOpCode != 0xffffffff)\r
- dwLoop2++;\r
-\r
- if (bTimingDDFD[dwLoop])\r
- {\r
- fprintf(fp, " sdwCyclesRemaining -= %ld;\n", bTimingDDFD[dwLoop]);\r
- }\r
-\r
- if (DDFDOps[dwLoop2].Emitter)\r
- {\r
- DDFDOps[dwLoop2].Emitter(dwLoop);\r
- }\r
- else\r
- {\r
- InvalidInstructionC(2);\r
- }\r
-\r
- fprintf(fp, " break;\n");\r
- fprintf(fp, " }\n");\r
- ++dwLoop;\r
- }\r
-\r
- fprintf(fp, " }\n");\r
- fprintf(fp, "}\n");\r
-\r
- // DDFD Handler\r
-\r
- bCurrentMode = TIMING_XXCB;\r
-\r
- dwLoop = 0;\r
-\r
- fprintf(fp, "void DDFDCBHandler(UINT32 dwWhich)\n");\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " if (dwWhich)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " dwAddr = (UINT32) ((INT32) cpu.z80IY + ((INT32) *pbPC++)) & 0xffff;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " else\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " dwAddr = (UINT32) ((INT32) cpu.z80IX + ((INT32) *pbPC++)) & 0xffff;\n");\r
- fprintf(fp, " }\n\n");\r
-\r
- ReadValueFromMemory("dwAddr", "bTemp");\r
-\r
- fprintf(fp, " switch (*pbPC++)\n");\r
- fprintf(fp, " {\n");\r
-\r
- while (dwLoop < 0x100)\r
- {\r
- dwLoop2 = 0;\r
-\r
- fprintf(fp, " case 0x%.2x:\n", dwLoop);\r
- fprintf(fp, " {\n");\r
-\r
- while (DDFDCBOps[dwLoop2].bOpCode != dwLoop && DDFDCBOps[dwLoop2].bOpCode != 0xffffffff)\r
- dwLoop2++;\r
-\r
- if (bTimingXXCB[dwLoop])\r
- {\r
- fprintf(fp, " sdwCyclesRemaining -= %ld;\n", bTimingXXCB[dwLoop]);\r
- }\r
-\r
- if (DDFDCBOps[dwLoop2].Emitter)\r
- {\r
- DDFDCBOps[dwLoop2].Emitter(dwLoop);\r
- }\r
- else\r
- {\r
- InvalidInstructionC(4);\r
- }\r
-\r
- fprintf(fp, " break;\n");\r
- fprintf(fp, " }\n");\r
- ++dwLoop;\r
- }\r
-\r
- fprintf(fp, " }\n");\r
- fprintf(fp, "}\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-EmitFDInstructions()\r
-{\r
- UINT32 dwLoop = 0;\r
- UINT32 dwLoop2 = 0;\r
-\r
- bCurrentMode = TIMING_DDFD;\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- while (dwLoop < 0x100)\r
- {\r
- sprintf(procname, "FDInst%.2x", dwLoop);\r
- dwLoop2 = 0;\r
-\r
- while (DDFDOps[dwLoop2].bOpCode != dwLoop && DDFDOps[dwLoop2].bOpCode != 0xffffffff)\r
- dwLoop2++;\r
-\r
- assert(dwLoop2 < 0x100);\r
- if (DDFDOps[dwLoop2].Emitter && DDFDOps[dwLoop2].bOpCode != 0xffffffff)\r
- DDFDOps[dwLoop2].Emitter((UINT32) dwLoop);\r
-\r
- dwLoop++;\r
- }\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "void FDHandler(void)\n");\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " switch (*pbPC++)\n");\r
- fprintf(fp, " {\n");\r
-\r
- while (dwLoop < 0x100)\r
- {\r
- dwLoop2 = 0;\r
-\r
- fprintf(fp, " case 0x%.2x:\n", dwLoop);\r
- fprintf(fp, " {\n");\r
-\r
- while (DDFDOps[dwLoop2].bOpCode != dwLoop && DDFDOps[dwLoop2].bOpCode != 0xffffffff)\r
- dwLoop2++;\r
-\r
- if (bTimingDDFD[dwLoop])\r
- {\r
- fprintf(fp, " sdwCyclesRemaining -= %ld;\n", bTimingDDFD[dwLoop]);\r
- }\r
-\r
- if (DDFDOps[dwLoop2].Emitter)\r
- {\r
- DDFDOps[dwLoop2].Emitter(dwLoop);\r
- }\r
- else\r
- {\r
- InvalidInstructionC(2);\r
- }\r
-\r
- fprintf(fp, " break;\n");\r
- fprintf(fp, " }\n");\r
- ++dwLoop;\r
- }\r
-\r
- fprintf(fp, " }\n");\r
- fprintf(fp, "}\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-/* These are the meta routines */\r
-\r
-void ReadMemoryByteHandler()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- Alignment();\r
- fprintf(fp, "; This is a generic read memory byte handler when a foreign\n");\r
- fprintf(fp, "; handler is to be called\n\n");\r
- fprintf(fp, "; EDI=Handler address, EDX=Address\n");\r
- fprintf(fp, "; On return, EDX & EDI are undisturbed and AL=Byte read\n\n");\r
- fprintf(fp, "ReadMemoryByte:\n");\r
- \r
- fprintf(fp, " mov [_z80af], ax ; Save AF\n");\r
- fprintf(fp, " cmp [edi+8], dword 0 ; Null handler?\n");\r
- fprintf(fp, " je directReadHandler ; Yep! It's a direct read!\n\n");\r
-\r
- fprintf(fp, " mov [_z80hl], bx ; Save HL\n");\r
- fprintf(fp, " mov [_z80bc], cx ; Save BC\n");\r
-\r
- fprintf(fp, " sub esi, ebp ; Our program counter\n", cpubasename);\r
- fprintf(fp, " mov [_z80pc], si ; Save our program counter\n", cpubasename);\r
-\r
- // Now adjust the proper timing\r
-\r
- fprintf(fp, " mov esi, [dwOriginalExec] \n");\r
- fprintf(fp, " sub esi, [cyclesRemaining]\n");\r
- fprintf(fp, " add [dwElapsedTicks], esi\n");\r
- fprintf(fp, " add [_z80rCounter], esi\n");\r
- fprintf(fp, " sub [dwOriginalExec], esi\n");\r
- \r
- fprintf(fp, " push edi ; Save our structure address\n");\r
- fprintf(fp, " push edx ; And our desired address\n");\r
-\r
- if (FALSE == bUseStack)\r
- {\r
- fprintf(fp, " mov eax, edx ; Get our desired address reg\n");\r
- fprintf(fp, " mov edx, edi ; Pointer to the structure\n");\r
- }\r
- \r
- fprintf(fp, " call dword [edi + 8] ; Go call our handler\n");\r
- \r
- fprintf(fp, " pop edx ; Restore our address\n");\r
- fprintf(fp, " pop edi ; Restore our handler's address\n");\r
- \r
- fprintf(fp, " xor ebx, ebx ; Zero our future HL\n");\r
- fprintf(fp, " xor esi, esi ; Zero it!\n");\r
- fprintf(fp, " mov ebp, [_z80Base] ; Base pointer comes back\n", cpubasename);\r
- fprintf(fp, " mov si, [_z80pc] ; Get our program counter back\n", cpubasename);\r
- fprintf(fp, " xor ecx, ecx ; Zero our future BC\n");\r
- fprintf(fp, " add esi, ebp ; Rebase it properly\n");\r
- \r
- fprintf(fp, " mov bx, [_z80hl] ; Get HL back\n");\r
- fprintf(fp, " mov cx, [_z80bc] ; Get BC back\n");\r
- \r
- // Note: the callee must restore AF!\r
-\r
- fprintf(fp, " ret\n\n");\r
- fprintf(fp, "directReadHandler:\n");\r
- fprintf(fp, " mov eax, [edi+12] ; Get our base address\n");\r
- fprintf(fp, " sub edx, [edi] ; Subtract our base (low) address\n");\r
- fprintf(fp, " mov al, [edx+eax] ; Get our data byte\n");\r
- fprintf(fp, " and eax, 0ffh ; Only the lower byte matters!\n");\r
- fprintf(fp, " add edx, [edi] ; Add our base back\n");\r
- fprintf(fp, " ret ; Return to caller!\n\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void WriteMemoryByteHandler()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- Alignment();\r
- fprintf(fp, "; This is a generic read memory byte handler when a foreign\n");\r
- fprintf(fp, "; handler is to be called.\n");\r
- fprintf(fp, "; EDI=Handler address, AL=Byte to write, EDX=Address\n");\r
- fprintf(fp, "; EDI and EDX Are undisturbed on exit\n\n");\r
- fprintf(fp, "WriteMemoryByte:\n");\r
-\r
- fprintf(fp, " cmp [edi+8], dword 0 ; Null handler?\n");\r
- fprintf(fp, " je directWriteHandler\n\n");\r
- \r
- \r
- fprintf(fp, " mov [_z80hl], bx ; Save HL\n");\r
- fprintf(fp, " mov [_z80bc], cx ; Save BX\n");\r
- \r
- fprintf(fp, " sub esi, ebp ; Our program counter\n", cpubasename);\r
- fprintf(fp, " mov [_z80pc], si ; Save our program counter\n", cpubasename);\r
- \r
- // Now adjust the proper timing\r
- \r
- fprintf(fp, " mov esi, [dwOriginalExec] \n");\r
- fprintf(fp, " sub esi, [cyclesRemaining]\n");\r
- fprintf(fp, " add [dwElapsedTicks], esi\n");\r
- fprintf(fp, " add [_z80rCounter], esi\n");\r
- fprintf(fp, " sub [dwOriginalExec], esi\n");\r
- \r
- fprintf(fp, " push edi ; Save our structure address\n");\r
- \r
- if (bUseStack)\r
- fprintf(fp, " push eax ; Data to write\n");\r
- \r
- fprintf(fp, " push edx ; And our desired address\n");\r
- \r
- if (FALSE == bUseStack)\r
- {\r
- fprintf(fp, " xchg eax, edx ; Swap address/data around\n");\r
- fprintf(fp, " mov ebx, edi ; Our MemoryWriteByte structure address\n");\r
- }\r
- \r
- fprintf(fp, " call dword [edi + 8] ; Go call our handler\n");\r
- \r
- fprintf(fp, " pop edx ; Restore our address\n");\r
- \r
- if (bUseStack)\r
- fprintf(fp, " pop eax ; Restore our data written\n");\r
- \r
- fprintf(fp, " pop edi ; Save our structure address\n");\r
- \r
- fprintf(fp, " xor ebx, ebx ; Zero our future HL\n");\r
- fprintf(fp, " xor ecx, ecx ; Zero our future BC\n");\r
- fprintf(fp, " mov bx, [_z80hl] ; Get HL back\n");\r
- fprintf(fp, " mov cx, [_z80bc] ; Get BC back\n");\r
- fprintf(fp, " mov ax, [_z80af] ; Get AF back\n");\r
- fprintf(fp, " xor esi, esi ; Zero it!\n");\r
- fprintf(fp, " mov si, [_z80pc] ; Get our program counter back\n", cpubasename);\r
- fprintf(fp, " mov ebp, [_z80Base] ; Base pointer comes back\n", cpubasename);\r
- fprintf(fp, " add esi, ebp ; Rebase it properly\n");\r
-\r
- fprintf(fp, " ret\n\n");\r
-\r
- fprintf(fp, "directWriteHandler:\n");\r
- fprintf(fp, " sub edx, [edi] ; Subtract our offset\n");\r
- fprintf(fp, " add edx, [edi+12] ; Add in the base address\n");\r
- fprintf(fp, " mov [edx], al ; Store our byte\n");\r
- fprintf(fp, " sub edx, [edi+12] ; Restore our base address\n");\r
- fprintf(fp, " add edx, [edi] ; And put our offset back\n");\r
- fprintf(fp, " ret\n\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void PushWordHandler()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- Alignment();\r
- \r
- fprintf(fp, ";\n");\r
- fprintf(fp, "; DX=Top of SP, [_wordval]=word value to push\n");\r
- fprintf(fp, ";\n\n");\r
- fprintf(fp, "PushWord:\n");\r
- fprintf(fp, " mov dx, [_z80sp]\n");\r
- fprintf(fp, " dec dx\n");\r
- WriteValueToMemory("dx", "byte [_wordval+1]");\r
- fprintf(fp, " dec dx\n");\r
- WriteValueToMemory("dx", "byte [_wordval]");\r
- fprintf(fp, " sub [_z80sp], word 2\n");\r
- fprintf(fp, " xor edx, edx\n");\r
- fprintf(fp, " ret\n\n");\r
- }\r
-}\r
-\r
-void PopWordHandler()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- Alignment();\r
- \r
- fprintf(fp, ";\n");\r
- fprintf(fp, "; [_z80sp]=Top of SP, DX=Word value read\n");\r
- fprintf(fp, ";\n\n");\r
- fprintf(fp, "PopWord:\n");\r
- fprintf(fp, " mov dx, [_z80sp]\n");\r
- \r
- ReadWordFromMemory("dx", "dx");\r
- fprintf(fp, " ret\n\n");\r
- }\r
-}\r
-\r
-void ReadIoHandler()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- Alignment();\r
-\r
- fprintf(fp, "; This is a generic I/O read byte handler for when a foreign\n");\r
- fprintf(fp, "; handler is to be called\n");\r
-\r
- fprintf(fp, "; EDI=Handler address, EDX=I/O Address\n");\r
- fprintf(fp, "; On return, EDX & EDI are undisturbed and AL=Byte read\n\n");\r
- fprintf(fp, "ReadIOByte:\n");\r
- \r
- fprintf(fp, " mov [_z80af], ax ; Save AF\n");\r
- fprintf(fp, " mov [_z80hl], bx ; Save HL\n");\r
- fprintf(fp, " mov [_z80bc], cx ; Save BC\n");\r
-\r
- fprintf(fp, " sub esi, ebp ; Our program counter\n", cpubasename);\r
- fprintf(fp, " mov [_z80pc], si ; Save our program counter\n", cpubasename);\r
-\r
- // Now adjust the proper timing\r
-\r
- fprintf(fp, " mov esi, [dwOriginalExec] \n");\r
- fprintf(fp, " sub esi, [cyclesRemaining]\n");\r
- fprintf(fp, " add [dwElapsedTicks], esi\n");\r
- fprintf(fp, " add [_z80rCounter], esi\n");\r
- fprintf(fp, " sub [dwOriginalExec], esi\n");\r
-\r
- fprintf(fp, " push edi ; Save our structure address\n");\r
- fprintf(fp, " push edx ; And our desired I/O port\n");\r
-\r
- if (FALSE == bUseStack)\r
- {\r
- fprintf(fp, " mov eax, edx ; Get our desired address reg\n");\r
- fprintf(fp, " mov edx, edi ; Pointer to the structure\n");\r
- }\r
-\r
- fprintf(fp, " call dword [edi + 4] ; Go call our handler\n");\r
-\r
- fprintf(fp, " pop edx ; Restore our address\n");\r
- fprintf(fp, " pop edi ; Restore our handler's address\n");\r
-\r
- fprintf(fp, " xor ebx, ebx ; Zero our future HL\n");\r
- fprintf(fp, " xor ecx, ecx ; Zero our future BC\n");\r
- fprintf(fp, " xor esi, esi ; Zero it!\n");\r
- fprintf(fp, " mov si, [_z80pc] ; Get our program counter back\n", cpubasename);\r
- fprintf(fp, " mov ebp, [_z80Base] ; Base pointer comes back\n", cpubasename);\r
- fprintf(fp, " add esi, ebp ; Rebase it properly\n");\r
-\r
- fprintf(fp, " mov bx, [_z80hl] ; Get HL back\n");\r
- fprintf(fp, " mov cx, [_z80bc] ; Get BC back\n");\r
-\r
- // Note: the callee must restore AF!\r
-\r
- fprintf(fp, " ret\n\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void WriteIoHandler()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- Alignment();\r
-\r
- fprintf(fp, "; This is a generic write I/O byte handler when a foreign handler is to\n");\r
- fprintf(fp, "; be called\n");\r
- fprintf(fp, "; EDI=Handler address, AL=Byte to write, EDX=I/O Address\n");\r
- fprintf(fp, "; EDI and EDX Are undisturbed on exit\n\n");\r
- fprintf(fp, "WriteIOByte:\n");\r
- \r
- fprintf(fp, " mov [_z80hl], bx ; Save HL\n");\r
- fprintf(fp, " mov [_z80bc], cx ; Save BX\n");\r
-\r
- fprintf(fp, " sub esi, ebp ; Our program counter\n", cpubasename);\r
- fprintf(fp, " mov [_z80pc], si ; Save our program counter\n", cpubasename);\r
-\r
- // Now adjust the proper timing\r
-\r
- fprintf(fp, " mov esi, [dwOriginalExec] \n");\r
- fprintf(fp, " sub esi, [cyclesRemaining]\n");\r
- fprintf(fp, " add [dwElapsedTicks], esi\n");\r
- fprintf(fp, " add [_z80rCounter], esi\n");\r
- fprintf(fp, " sub [dwOriginalExec], esi\n");\r
-\r
- fprintf(fp, " push edi ; Save our structure address\n");\r
-\r
- if (bUseStack)\r
- fprintf(fp, " push eax ; Data to write\n");\r
-\r
- fprintf(fp, " push edx ; And our desired I/O address\n");\r
-\r
- if (FALSE == bUseStack)\r
- {\r
- fprintf(fp, " xchg eax, edx ; Swap address/data around\n");\r
- fprintf(fp, " mov ebx, edi ; Our z80IoWrite structure address\n");\r
- }\r
-\r
- fprintf(fp, " call dword [edi + 4] ; Go call our handler\n");\r
-\r
- fprintf(fp, " pop edx ; Restore our address\n");\r
- \r
- if (bUseStack)\r
- fprintf(fp, " pop eax ; Restore our data written\n");\r
- \r
- fprintf(fp, " pop edi ; Save our structure address\n");\r
-\r
- fprintf(fp, " xor ebx, ebx ; Zero our future HL\n");\r
- fprintf(fp, " xor ecx, ecx ; Zero our future BC\n");\r
- fprintf(fp, " mov bx, [_z80hl] ; Get HL back\n");\r
- fprintf(fp, " mov cx, [_z80bc] ; Get BC back\n");\r
- fprintf(fp, " mov ax, [_z80af] ; Get AF back\n");\r
- fprintf(fp, " xor esi, esi ; Zero it!\n");\r
- fprintf(fp, " mov si, [_z80pc] ; Get our program counter back\n", cpubasename);\r
- fprintf(fp, " mov ebp, [_z80Base] ; Base pointer comes back\n", cpubasename);\r
- fprintf(fp, " add esi, ebp ; Rebase it properly\n");\r
-\r
- fprintf(fp, " ret\n\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-ExecCode()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " global _%sexec\n", cpubasename);\r
- fprintf(fp, " global %sexec_\n", cpubasename);\r
- \r
- if (bPlain)\r
- fprintf(fp, " global %sexec\n", cpubasename);\r
- \r
- sprintf(procname, "%sexec_", cpubasename);\r
- ProcBegin(0xffffffff);\r
- \r
- fprintf(fp, "_%sexec:\n", cpubasename);\r
- \r
- if (bPlain)\r
- fprintf(fp, "%sexec:\n", cpubasename);\r
- \r
- if (bUseStack)\r
- fprintf(fp, " mov eax, [esp+4] ; Get our execution cycle count\n");\r
- \r
- fprintf(fp, " push ebx ; Save all registers we use\n");\r
- fprintf(fp, " push ecx\n");\r
- fprintf(fp, " push edx\n");\r
- fprintf(fp, " push ebp\n");\r
- fprintf(fp, " push esi\n");\r
- fprintf(fp, " push edi\n");\r
- fprintf(fp, "\n");\r
-\r
- fprintf(fp, " mov edi, eax\n"); \r
- fprintf(fp, " mov dword [cyclesRemaining], eax ; Store # of instructions to\n");\r
- fprintf(fp, " mov [dwLastRSample], eax\n");\r
- fprintf(fp, " mov [dwOriginalExec], eax ; Store this!\n");\r
-\r
- fprintf(fp, " cmp dword [_z80halted], 0\n");\r
- fprintf(fp, " je goCpu\n");\r
- fprintf(fp, " add [_z80rCounter], eax\n");\r
- \r
- if (FALSE == bNoTiming)\r
- {\r
- fprintf(fp, " add dword [dwElapsedTicks], eax\n");\r
- }\r
- \r
- fprintf(fp, " mov dword [cyclesRemaining], 0 ; Nothing left!\n");\r
- fprintf(fp, " mov eax, 80000000h ; Successful exection\n");\r
- fprintf(fp, " jmp popReg\n");\r
- fprintf(fp, "goCpu:\n");\r
- fprintf(fp, " cld ; Go forward!\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " xor eax, eax ; Zero EAX 'cause we use it!\n");\r
- fprintf(fp, " xor ebx, ebx ; Zero EBX, too\n");\r
- fprintf(fp, " xor ecx, ecx ; Zero ECX\n");\r
- fprintf(fp, " xor edx, edx ; And EDX\n");\r
- fprintf(fp, " xor esi, esi ; Zero our source address\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " mov ax, [_z80af] ; Accumulator & flags\n");\r
- fprintf(fp, " xchg ah, al ; Swap these for later\n");\r
- fprintf(fp, " mov bx, [_z80hl] ; Get our HL value\n");\r
- fprintf(fp, " mov cx, [_z80bc] ; And our BC value\n");\r
- fprintf(fp, " mov ebp, [_z80Base] ; Get the base address\n");\r
- fprintf(fp, " mov si, [_z80pc] ; Get our program counter\n");\r
- fprintf(fp, " add esi, ebp ; Add in our base address\n");\r
-\r
- fprintf(fp, " cmp [_z80intPending], byte 0 ; Interrupt pending?\n");\r
- fprintf(fp, " jz masterExecTarget\n\n");\r
- fprintf(fp, " call causeInternalInterrupt\n\n");\r
- fprintf(fp, "masterExecTarget:\n");\r
- fprintf(fp, " mov dl, [esi]\n");\r
- fprintf(fp, " inc esi\n");\r
- fprintf(fp, " jmp dword [z80regular+edx*4]\n\n");\r
- fprintf(fp, "; We get to invalidInsWord if it's a double byte invalid opcode\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, "invalidInsWord:\n");\r
- \r
- fprintf(fp, " dec esi\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, "; We get to invalidInsByte if it's a single byte invalid opcode\n");\r
- fprintf(fp, "\n");\r
- \r
- fprintf(fp, "invalidInsByte:\n");\r
- fprintf(fp, " xchg ah, al ; Swap them back so they look good\n");\r
- fprintf(fp, " mov [_z80af], ax ; Store A & flags\n");\r
- fprintf(fp, " dec esi ; Back up one instruction...\n");\r
- fprintf(fp, " mov edx, esi ; Get our address in EAX\n");\r
- fprintf(fp, " sub edx, ebp ; And subtract our base for\n");\r
- fprintf(fp, " ; an invalid instruction\n");\r
- fprintf(fp, " jmp short emulateEnd\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, "noMoreExec:\n");\r
- fprintf(fp, " cmp [bEIExit], byte 0 ; Are we exiting because of an EI?\n");\r
- fprintf(fp, " jne checkEI\n");\r
- fprintf(fp, "noMoreExecNoEI:\n");\r
- fprintf(fp, " xchg ah, al ; Swap these for later\n");\r
- fprintf(fp, " mov [_z80af], ax ; Store A & flags\n");\r
- \r
- fprintf(fp, " mov edx, [dwOriginalExec] ; Original exec time\n");\r
- fprintf(fp, " sub edx, edi ; Subtract # of cycles remaining\n");\r
- fprintf(fp, " add [_z80rCounter], edx\n");\r
- fprintf(fp, " add [dwElapsedTicks], edx ; Add our executed time\n");\r
- \r
- fprintf(fp, " mov edx, 80000000h ; Indicate successful exec\n");\r
- fprintf(fp, " jmp short emulateEnd ; All finished!\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, "; Now let's tuck away the virtual registers for next time\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, "storeFlags:\n");\r
- fprintf(fp, " xchg ah, al ; Swap these for later\n");\r
- fprintf(fp, " mov [_z80af], ax ; Store A & flags\n");\r
- fprintf(fp, "emulateEnd:\n");\r
- fprintf(fp, " mov [_z80hl], bx ; Store HL\n");\r
- fprintf(fp, " mov [_z80bc], cx ; Store BC\n");\r
- fprintf(fp, " sub esi, [_z80Base] ; Knock off physical address\n");\r
- fprintf(fp, " mov [_z80pc], si ; And store virtual address\n");\r
- fprintf(fp, " mov eax, edx ; Result code return\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, "popReg:\n");\r
- fprintf(fp, " pop edi ; Restore registers\n");\r
- fprintf(fp, " pop esi\n");\r
- fprintf(fp, " pop ebp\n");\r
- fprintf(fp, " pop edx\n");\r
- fprintf(fp, " pop ecx\n");\r
- fprintf(fp, " pop ebx\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " ret\n");\r
- fprintf(fp, "\n");\r
- Alignment();\r
- fprintf(fp, "checkEI:\n");\r
- fprintf(fp, " xor edx, edx\n");\r
- fprintf(fp, " mov [bEIExit], byte 0\n");\r
- fprintf(fp, " sub edx, edi ; Find out how much time has passed\n");\r
- fprintf(fp, " mov edi, [dwEITiming]\n");\r
- fprintf(fp, " sub edi, edx\n");\r
- fprintf(fp, " js noMoreExecNoEI\n");\r
- fprintf(fp, " xor edx, edx\n");\r
-\r
- fprintf(fp, " cmp [_z80intPending], byte 0\n");\r
- fprintf(fp, " je near masterExecTarget\n");\r
- fprintf(fp, " call causeInternalInterrupt\n");\r
- fprintf(fp, " jmp masterExecTarget\n\n");\r
-\r
- Alignment();\r
- fprintf(fp, "causeInternalInterrupt:\n");\r
- fprintf(fp, " mov dword [_z80halted], 0 ; We're not halted anymore!\n");\r
- fprintf(fp, " test [_z80iff], byte IFF1 ; Interrupt enabled yet?\n");\r
- fprintf(fp, " jz near internalInterruptsDisabled\n");\r
-\r
- fprintf(fp, "\n; Interrupts enabled. Clear IFF1 and IFF2\n\n");\r
-\r
- fprintf(fp, " mov [_z80intPending], byte 0\n");\r
-\r
- fprintf(fp, "\n; Save off our active register sets\n\n");\r
-\r
- fprintf(fp, " xchg ah, al ; Swap these for later\n");\r
- fprintf(fp, " mov [_z80af], ax ; Store A & flags\n");\r
- fprintf(fp, " mov [_z80hl], bx ; Store HL\n");\r
- fprintf(fp, " mov [_z80bc], cx ; Store BC\n");\r
- fprintf(fp, " sub esi, ebp ; Knock off physical address\n");\r
- fprintf(fp, " mov [_z80pc], si ; And store virtual address\n");\r
-\r
- fprintf(fp, " xor eax, eax\n");\r
- fprintf(fp, " mov al, [_intData]\n\n");\r
-\r
- fprintf(fp, "\n");\r
- fprintf(fp, " push edi\n");\r
- fprintf(fp, "\n");\r
- \r
- if (bThroughCallHandler)\r
- {\r
- fprintf(fp, " pushad\n" );\r
- fprintf(fp, " xor edx, edx\n" );\r
- fprintf(fp, " mov ax, [_z80pc]\n");\r
- fprintf(fp, " mov [_wordval], ax\n");\r
- fprintf(fp, " push ecx\n");\r
- fprintf(fp, " push ebx\n");\r
- fprintf(fp, " push esi\n");\r
- \r
- fprintf(fp, " mov ax, [_z80af]\n"); // Get AF\r
- fprintf(fp, " mov bx, [_z80hl]\n"); // Get HL\r
- fprintf(fp, " mov cx, [_z80bc]\n"); // Get BC\r
- fprintf(fp, " call PushWord\n");\r
- \r
- fprintf(fp, " pop esi\n");\r
- fprintf(fp, " pop ebx\n");\r
- fprintf(fp, " pop ecx\n");\r
- fprintf(fp, " popad\n" );\r
- }\r
- else\r
- {\r
- fprintf(fp, " mov dx, [_z80pc]\n");\r
- fprintf(fp, " xor edi, edi\n");\r
- fprintf(fp, " mov di, word [_z80sp]\n");\r
- fprintf(fp, " sub di, 2\n");\r
- fprintf(fp, " mov word [_z80sp], di\n");\r
- fprintf(fp, " mov [ebp+edi], dx\n");\r
- }\r
- \r
- fprintf(fp, " cmp dword [_z80interruptMode], 2 ; Are we lower than mode 2?\n");\r
- fprintf(fp, " jb internalJustModeTwo\n");\r
- fprintf(fp, " mov ah, [_z80i] ; Get our high address here\n");\r
- fprintf(fp, " and eax, 0ffffh ; Only the lower part\n");\r
- fprintf(fp, " mov ax, [eax+ebp] ; Get our vector\n");\r
- fprintf(fp, " jmp short internalSetNewVector ; Go set it!\n");\r
- fprintf(fp, "internalJustModeTwo:\n");\r
- fprintf(fp, " mov ax, word [_z80intAddr]\n");\r
- fprintf(fp, "internalSetNewVector:\n");\r
- fprintf(fp, " mov [_z80pc], ax\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " pop edi\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " xor eax, eax ; Zero this so we can use it as an index\n");\r
-\r
- fprintf(fp, " mov al, [_z80interruptMode]\n");\r
- fprintf(fp, " mov al, [intModeTStates+eax]\n");\r
- fprintf(fp, " sub edi, eax\n");\r
- fprintf(fp, " add [_z80rCounter], eax\n");\r
-\r
- fprintf(fp, "\n; Restore all the registers and whatnot\n\n");\r
-\r
- fprintf(fp, " mov ax, [_z80af] ; Accumulator & flags\n");\r
- fprintf(fp, " xchg ah, al ; Swap these for later\n");\r
- fprintf(fp, " mov bx, [_z80hl] ; Get our HL value\n");\r
- fprintf(fp, " mov cx, [_z80bc] ; And our BC value\n");\r
- fprintf(fp, " mov ebp, [_z80Base] ; Get the base address\n");\r
- fprintf(fp, " mov si, [_z80pc] ; Get our program counter\n");\r
- fprintf(fp, " add esi, ebp ; Add in our base address\n");\r
-\r
- fprintf(fp, "internalInterruptsDisabled:\n");\r
- fprintf(fp, " xor edx, edx\n");\r
- fprintf(fp, " ret\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-NmiCode()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " global _%snmi\n", cpubasename);\r
- fprintf(fp, " global %snmi_\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, " global %snmi\n", cpubasename);\r
- \r
- sprintf(procname, "%snmi_", cpubasename);\r
- ProcBegin(0xffffffff);\r
- fprintf(fp, "_%snmi:\n", cpubasename);\r
- \r
- if (bPlain)\r
- fprintf(fp, "%snmi:\n", cpubasename);\r
-\r
- fprintf(fp, " mov dword [_z80halted], 0 ; We're not halted anymore!\n");\r
- fprintf(fp, " mov al, [_z80iff] ; Get our IFF setting\n");\r
- fprintf(fp, " and al, IFF1 ; Just IFF 1\n");\r
- fprintf(fp, " shl al, 1 ; Makes IFF1->IFF2 and zeros IFF1\n");\r
- fprintf(fp, " mov [_z80iff], al ; Store it back to the interrupt state!\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " push ebp\n");\r
- fprintf(fp, " push edi\n");\r
- fprintf(fp, " mov ebp, [_z80Base]\n");\r
- fprintf(fp, "\n");\r
-\r
- fprintf(fp, " xor eax, eax\n");\r
- fprintf(fp, " mov ax, [_z80pc]\n");\r
-\r
- if (bThroughCallHandler)\r
- {\r
- fprintf(fp, " push esi\n");\r
- fprintf(fp, " push ebx\n");\r
- fprintf(fp, " push ecx\n");\r
-\r
- fprintf(fp, " mov [_wordval], ax\n");\r
- fprintf(fp, " mov esi, ebp\n");\r
- fprintf(fp, " add esi, eax\n");\r
- fprintf(fp, " mov ax, [_z80af]\n"); // Get AF\r
- fprintf(fp, " mov bx, [_z80hl]\n"); // Get HL\r
- fprintf(fp, " mov cx, [_z80bc]\n"); // Get BC\r
- fprintf(fp, " push ebx\n");\r
- fprintf(fp, " push ecx\n");\r
- fprintf(fp, " push edx\n");\r
- fprintf(fp, " push esi\n");\r
- fprintf(fp, " push eax\n");\r
- fprintf(fp, " call PushWord\n");\r
- fprintf(fp, " pop eax\n");\r
- fprintf(fp, " pop esi\n");\r
- fprintf(fp, " pop edx\n");\r
- fprintf(fp, " pop ecx\n");\r
- fprintf(fp, " pop ebx\n");\r
-\r
- fprintf(fp, " pop ecx\n");\r
- fprintf(fp, " pop ebx\n");\r
- fprintf(fp, " pop esi\n");\r
- } \r
- else \r
- { \r
- fprintf(fp, " xor edi, edi\n");\r
- fprintf(fp, " mov di, word [_z80sp]\n");\r
- fprintf(fp, " sub di, 2\n");\r
- fprintf(fp, " mov word [_z80sp], di\n");\r
- fprintf(fp, " mov [ebp+edi], ax\n");\r
- }\r
-\r
- fprintf(fp, " mov ax, [_z80nmiAddr]\n");\r
- fprintf(fp, " mov [_z80pc], ax\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " add [dwElapsedTicks], dword 11 ; 11 T-States for NMI\n");\r
- fprintf(fp, " add [_z80rCounter], dword 11\n");\r
- fprintf(fp, " pop edi\n");\r
- fprintf(fp, " pop ebp\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " xor eax, eax ; Indicate we took the interrupt\n");\r
- fprintf(fp, " ret\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "/* NMI Handler */\n\n");\r
- fprintf(fp, "UINT32 %snmi(void)\n", cpubasename);\r
- fprintf(fp, "{\n");\r
-\r
- fprintf(fp, " cpu.z80halted = 0;\n");\r
- fprintf(fp, " pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */\n");\r
- fprintf(fp, " *pbSP-- = cpu.z80pc >> 8; /* LSB */\n");\r
- fprintf(fp, " *pbSP = (UINT8) cpu.z80pc; /* MSB */\n");\r
- fprintf(fp, " cpu.z80sp -= 2; /* Back our stack up */\n");\r
- fprintf(fp, " cpu.z80pc = cpu.z80nmiAddr; /* Our NMI */\n");\r
-\r
- fprintf(fp, " return(0);\n");\r
- fprintf(fp, "}\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-IntCode()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " global _%sint\n", cpubasename);\r
- fprintf(fp, " global %sint_\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, " global %sint\n", cpubasename);\r
-\r
- sprintf(procname, "%sint_", cpubasename);\r
- ProcBegin(0xffffffff);\r
- fprintf(fp, "_%sint:\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, "%sint:\n", cpubasename);\r
-\r
- if (bUseStack)\r
- fprintf(fp, " mov eax, [esp+4] ; Get our (potential) lower interrupt address\n");\r
- \r
- fprintf(fp, " mov dword [_z80halted], 0 ; We're not halted anymore!\n");\r
-\r
- fprintf(fp, " mov ah, IFF1 ; Is IFF1 enabled?\n");\r
- fprintf(fp, " and ah, [_z80iff] ; Well, is it?\n");\r
- fprintf(fp, " jz near interruptsDisabled\n");\r
-\r
- fprintf(fp, "\n; Interrupts enabled. Clear IFF1 and IFF2\n\n");\r
-\r
- fprintf(fp, " and dword [_z80iff], ~(IFF1 | IFF2);\n\n");\r
- fprintf(fp, " mov [_z80intPending], byte 0\n");\r
-\r
- fprintf(fp, "\n");\r
- fprintf(fp, " push ebp\n");\r
- fprintf(fp, " push edi\n");\r
- fprintf(fp, " push edx\n");\r
- fprintf(fp, " mov ebp, [_z80Base]\n");\r
- fprintf(fp, "\n");\r
- \r
- \r
- if (bThroughCallHandler)\r
- {\r
- fprintf(fp, " pushad\n" );\r
- fprintf(fp, " xor edx, edx\n" );\r
- fprintf(fp, " mov ax, [_z80pc]\n");\r
- fprintf(fp, " mov [_wordval], ax\n");\r
- fprintf(fp, " push ecx\n");\r
- fprintf(fp, " push ebx\n");\r
- fprintf(fp, " push esi\n");\r
- \r
- fprintf(fp, " mov ax, [_z80af]\n"); // Get AF\r
- fprintf(fp, " mov bx, [_z80hl]\n"); // Get HL\r
- fprintf(fp, " mov cx, [_z80bc]\n"); // Get BC\r
- fprintf(fp, " call PushWord\n");\r
- \r
- fprintf(fp, " pop esi\n");\r
- fprintf(fp, " pop ebx\n");\r
- fprintf(fp, " pop ecx\n");\r
- fprintf(fp, " popad\n" );\r
- }\r
- else\r
- {\r
- fprintf(fp, " mov dx, [_z80pc]\n");\r
- fprintf(fp, " xor edi, edi\n");\r
- fprintf(fp, " mov di, word [_z80sp]\n");\r
- fprintf(fp, " sub di, 2\n");\r
- fprintf(fp, " mov word [_z80sp], di\n");\r
- fprintf(fp, " mov [ebp+edi], dx\n");\r
- }\r
- \r
- fprintf(fp, " cmp dword [_z80interruptMode], 2 ; Are we lower than mode 2?\n");\r
- fprintf(fp, " jb justModeTwo\n");\r
- fprintf(fp, " mov ah, [_z80i] ; Get our high address here\n");\r
- fprintf(fp, " and eax, 0ffffh ; Only the lower part\n");\r
- fprintf(fp, " mov ax, [eax+ebp] ; Get our vector\n");\r
- fprintf(fp, " jmp short setNewVector ; Go set it!\n");\r
- fprintf(fp, "justModeTwo:\n");\r
- fprintf(fp, " mov ax, word [_z80intAddr]\n");\r
- fprintf(fp, "setNewVector:\n");\r
- fprintf(fp, " mov [_z80pc], ax\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " pop edx\n");\r
- fprintf(fp, " pop edi\n");\r
- fprintf(fp, " pop ebp\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " xor eax, eax ; Zero this so we can use it as an index\n");\r
-\r
- fprintf(fp, " mov al, [_z80interruptMode]\n");\r
- fprintf(fp, " mov al, [intModeTStates+eax]\n");\r
- fprintf(fp, " add [dwElapsedTicks], eax\n");\r
- fprintf(fp, " add [_z80rCounter], eax\n");\r
- fprintf(fp, " xor eax, eax ; Indicate we took the interrupt\n");\r
-\r
- fprintf(fp, " jmp short z80intExit\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, "interruptsDisabled:\n");\r
- fprintf(fp, " mov [_z80intPending], byte 1\n");\r
- fprintf(fp, " mov [_intData], al ; Save this info for later\n");\r
- fprintf(fp, " mov eax, 0ffffffffh ; Indicate we didn't take it\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, "z80intExit:\n");\r
- fprintf(fp, " ret\n\n");\r
-\r
-\r
- fprintf(fp, " global _%sClearPendingInterrupt\n", cpubasename);\r
- fprintf(fp, " global %sClearPendingInterrupt_\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, " global %sClearPendingInterrupt\n", cpubasename);\r
-\r
- sprintf(procname, "%sClearPendingInterrupt_", cpubasename);\r
- ProcBegin(0xffffffff);\r
- fprintf(fp, "_%sClearPendingInterrupt:\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, "%sClearPendingInterrupt:\n", cpubasename);\r
-\r
- fprintf(fp, " mov [_z80intPending], byte 0\n");\r
- fprintf(fp, " ret\n\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "/* Interrupt handler */\n\n");\r
- fprintf(fp, "UINT32 %sint(UINT32 dwLowAddr)\n", cpubasename);\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " cpu.z80halted = 0;\n");\r
-\r
- fprintf(fp, " if (0 == (cpu.z80iff & IFF1))\n");\r
- fprintf(fp, " return(0xffffffff);\n");\r
-\r
- fprintf(fp, " cpu.z80iff &= ~(IFF1 | IFF2);\n");\r
- fprintf(fp, " pbSP = (cpu.z80Base + cpu.z80sp - 1); /* Normalize the stack pointer */\n");\r
- fprintf(fp, " *pbSP-- = cpu.z80pc >> 8; /* LSB */\n");\r
- fprintf(fp, " *pbSP = (UINT8) cpu.z80pc; /* MSB */\n");\r
- fprintf(fp, " cpu.z80sp -= 2; /* Back our stack up */\n");\r
-\r
- fprintf(fp, " if (2 == cpu.z80interruptMode)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80pc = ((UINT16) cpu.z80i << 8) | (dwLowAddr & 0xff);\n");\r
- fprintf(fp, " cpu.z80pc = ((UINT16) cpu.z80Base[cpu.z80pc + 1] << 8) | (cpu.z80Base[cpu.z80pc]);\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " else\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " cpu.z80pc = cpu.z80intAddr;\n");\r
- fprintf(fp, " }\n");\r
-\r
- fprintf(fp, " pbPC = cpu.z80Base + cpu.z80pc; /* Normalize the address */\n");\r
-\r
- fprintf(fp, " return(0);\n");\r
- fprintf(fp, "}\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-ResetCode()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " global _%sreset\n", cpubasename);\r
- fprintf(fp, " global %sreset_\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, " global %sreset\n", cpubasename);\r
- sprintf(procname, "%sreset_", cpubasename);\r
- ProcBegin(0xffffffff);\r
-\r
- fprintf(fp, "_%sreset:\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, "%sreset:\n", cpubasename);\r
-\r
- fprintf(fp, " xor eax, eax ; Zero AX\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " mov dword [_z80halted], eax ; We're not halted anymore!\n");\r
- fprintf(fp, " mov word [_z80af], 0040h ; Zero A & flags - zero flag set\n");\r
- fprintf(fp, " mov word [_z80bc], ax ; Zero BC\n");\r
- fprintf(fp, " mov word [_z80de], ax ; Zero DE\n");\r
- fprintf(fp, " mov word [_z80hl], ax ; Zero HL\n");\r
- fprintf(fp, " mov word [_z80afprime], ax ; Zero AF Prime\n");\r
- fprintf(fp, " mov word [_z80bcprime], ax ; Zero BC prime\n");\r
- fprintf(fp, " mov word [_z80deprime], ax ; Zero DE prime\n");\r
- fprintf(fp, " mov word [_z80hlprime], ax ; Zero HL prime\n");\r
- fprintf(fp, " mov byte [_z80i], al ; Zero Interrupt register\n");\r
- fprintf(fp, " mov byte [_z80r], al ; Zero refresh register\n");\r
- fprintf(fp, " mov word [_z80ix], 0ffffh ; Default mz80Index register\n");\r
- fprintf(fp, " mov word [_z80iy], 0ffffh ; Default mz80Index register\n");\r
- fprintf(fp, " mov word [_z80pc], ax ; Zero program counter\n");\r
- fprintf(fp, " mov word [_z80sp], ax ; And the stack pointer\n");\r
- fprintf(fp, " mov dword [_z80iff], eax ; IFF1/IFF2 disabled!\n");\r
- fprintf(fp, " mov dword [_z80interruptMode], eax ; Clear our interrupt mode (0)\n");\r
- fprintf(fp, " mov word [_z80intAddr], 38h ; Set default interrupt address\n");\r
- fprintf(fp, " mov word [_z80nmiAddr], 66h ; Set default nmi addr\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " ret\n");\r
- fprintf(fp, "\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "/* This routine is mz80's reset handler */\n\n");\r
- fprintf(fp, "void %sreset(void)\n", cpubasename);\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " cpu.z80halted = 0;\n");\r
- fprintf(fp, " cpu.z80AF = 0;\n");\r
- fprintf(fp, " cpu.z80F = Z80_FLAG_ZERO;\n");\r
- fprintf(fp, " cpu.z80BC = 0;\n");\r
- fprintf(fp, " cpu.z80DE = 0;\n");\r
- fprintf(fp, " cpu.z80HL = 0;\n");\r
- fprintf(fp, " cpu.z80afprime = 0;\n");\r
- fprintf(fp, " cpu.z80bcprime = 0;\n");\r
- fprintf(fp, " cpu.z80deprime = 0;\n");\r
- fprintf(fp, " cpu.z80hlprime = 0;\n");\r
- fprintf(fp, " cpu.z80i = 0;\n");\r
- fprintf(fp, " cpu.z80r = 0;\n");\r
- fprintf(fp, " cpu.z80IX = 0xffff; /* Yes, this is intentional */\n");\r
- fprintf(fp, " cpu.z80IY = 0xffff; /* Yes, this is intentional */\n");\r
- fprintf(fp, " cpu.z80pc = 0;\n");\r
- fprintf(fp, " cpu.z80sp = 0;\n");\r
- fprintf(fp, " cpu.z80interruptMode = 0;\n");\r
- fprintf(fp, " cpu.z80intAddr = 0x38;\n");\r
- fprintf(fp, " cpu.z80nmiAddr = 0x66;\n");\r
- fprintf(fp, "}\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-SetContextCode()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " global _%sSetContext\n", cpubasename);\r
- fprintf(fp, " global %sSetContext_\n", cpubasename);\r
- \r
- if (bPlain)\r
- fprintf(fp, " global %sSetContext\n", cpubasename);\r
- \r
- sprintf(procname, "%sSetContext_", cpubasename);\r
- ProcBegin(0xffffffff);\r
- fprintf(fp, "_%sSetContext:\n", cpubasename);\r
- \r
- if (bPlain)\r
- fprintf(fp, "%sSetContext:\n", cpubasename);\r
- \r
- if (bUseStack)\r
- fprintf(fp, " mov eax, [esp+4] ; Get our context address\n");\r
- \r
- fprintf(fp, " push esi ; Save registers we use\n");\r
- fprintf(fp, " push edi\n");\r
- fprintf(fp, " push ecx\n");\r
- fprintf(fp, " push es\n");\r
- fprintf(fp, " mov di, ds\n");\r
- fprintf(fp, " mov es, di\n");\r
- fprintf(fp, " mov edi, _%scontextBegin\n", cpubasename);\r
- fprintf(fp, " mov esi, eax ; Source address in ESI\n");\r
- fprintf(fp, " mov ecx, (_%scontextEnd - _%scontextBegin) >> 2\n", cpubasename, cpubasename);\r
- fprintf(fp, " rep movsd\n");\r
- fprintf(fp, " mov ecx, (_%scontextEnd - _%scontextBegin) & 0x03\n", cpubasename, cpubasename);\r
- fprintf(fp, " rep movsb\n");\r
- fprintf(fp, " pop es\n");\r
- fprintf(fp, " pop ecx\n");\r
- fprintf(fp, " pop edi\n");\r
- fprintf(fp, " pop esi\n");\r
- fprintf(fp, " ret ; No return code\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "/* Set mz80's context */\n\n");\r
- fprintf(fp, "void %sSetContext(void *pData)\n", cpubasename);\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " memcpy(&cpu, pData, sizeof(CONTEXTMZ80));\n");\r
- fprintf(fp, "}\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-GetContextCode()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " global _%sGetContext\n", cpubasename);\r
- fprintf(fp, " global %sGetContext_\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, " global %sGetContext\n", cpubasename);\r
- \r
- sprintf(procname, "%sGetContext_", cpubasename);\r
- ProcBegin(0xffffffff);\r
- fprintf(fp, "_%sGetContext:\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, "%sGetContext:\n", cpubasename);\r
-\r
- if (bUseStack)\r
- fprintf(fp, " mov eax, [esp+4] ; Get our context address\n");\r
-\r
- fprintf(fp, " push esi ; Save registers we use\n");\r
- fprintf(fp, " push edi\n");\r
- fprintf(fp, " push ecx\n");\r
- fprintf(fp, " push es\n");\r
- fprintf(fp, " mov di, ds\n");\r
- fprintf(fp, " mov es, di\n");\r
-\r
- fprintf(fp, " mov esi, _%scontextBegin\n", cpubasename);\r
- fprintf(fp, " mov edi, eax ; Source address in ESI\n");\r
-\r
- fprintf(fp, " mov ecx, (_%scontextEnd - _%scontextBegin) >> 2\n", cpubasename, cpubasename);\r
- fprintf(fp, " rep movsd\n");\r
- fprintf(fp, " mov ecx, (_%scontextEnd - _%scontextBegin) & 0x03\n", cpubasename, cpubasename);\r
- fprintf(fp, " rep movsb\n");\r
-\r
- fprintf(fp, " pop es\n");\r
- fprintf(fp, " pop ecx\n");\r
- fprintf(fp, " pop edi\n");\r
- fprintf(fp, " pop esi\n");\r
- fprintf(fp, " ret ; No return code\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "/* Get mz80's context */\n\n");\r
- fprintf(fp, "void %sGetContext(void *pData)\n", cpubasename);\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " memcpy(pData, &cpu, sizeof(CONTEXTMZ80));\n");\r
- fprintf(fp, "}\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-GetContextSizeCode()\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " global _%sGetContextSize\n", cpubasename);\r
- fprintf(fp, " global %sGetContextSize_\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, " global %sGetContextSize\n", cpubasename);\r
-\r
- sprintf(procname, "%sGetContextSize_", cpubasename);\r
- ProcBegin(0xffffffff);\r
-\r
- fprintf(fp, "_%sGetContextSize:\n", cpubasename);\r
- \r
- if (bPlain)\r
- fprintf(fp, "%sGetContextSize:\n", cpubasename);\r
-\r
- fprintf(fp, " mov eax, _%scontextEnd - _%scontextBegin\n", cpubasename, cpubasename);\r
- fprintf(fp, " ret\n\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "/* Get mz80's context size */\n\n");\r
- fprintf(fp, "UINT32 %sGetContextSize(void)\n", cpubasename);\r
- fprintf(fp, "{\n");\r
- fprintf(fp, " return(sizeof(CONTEXTMZ80));\n");\r
- fprintf(fp, "}\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void InitCode(void)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " global _%sinit\n", cpubasename);\r
- fprintf(fp, " global %sinit_\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, " global %sinit\n", cpubasename);\r
-\r
- sprintf(procname, "%sinit_", cpubasename);\r
- ProcBegin(0xffffffff);\r
-\r
- fprintf(fp, "_%sinit:\n", cpubasename);\r
- \r
- if (bPlain)\r
- fprintf(fp, "%sinit:\n", cpubasename);\r
-\r
- fprintf(fp, " ret\n\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "/* Initialize MZ80 for action */\n\n");\r
- fprintf(fp, "void %sinit(void)\n", cpubasename);\r
- fprintf(fp, "{\n");\r
-\r
- fprintf(fp, " UINT32 dwLoop;\n");\r
- fprintf(fp, " UINT8 *pbTempPtr;\n");\r
- fprintf(fp, " UINT8 *pbTempPtr2;\n");\r
- fprintf(fp, " UINT8 bNewAdd;\n");\r
- fprintf(fp, " UINT8 bNewSub;\n");\r
- fprintf(fp, " UINT8 bFlag;\n");\r
- fprintf(fp, " UINT8 bLow;\n");\r
- fprintf(fp, " UINT8 bHigh;\n");\r
- fprintf(fp, " UINT8 bCarry;\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " if (NULL == pbAddAdcTable)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " pbAddAdcTable = malloc(256*256*2);\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " if (NULL == pbAddAdcTable)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " return;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " pbTempPtr = pbAddAdcTable;\n\n");\r
- fprintf(fp, " pbSubSbcTable = malloc(256*256*2);\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " if (NULL == pbSubSbcTable)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " return;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " pbTempPtr2 = pbSubSbcTable;\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " for (dwLoop = 0; dwLoop < (256*256*2); dwLoop++)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " bLow = dwLoop & 0xff;\n");\r
- fprintf(fp, " bHigh = (dwLoop >> 8) & 0xff;\n");\r
- fprintf(fp, " bCarry = (dwLoop >> 16);\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " bFlag = 0;\n");\r
- fprintf(fp, " bNewAdd = bHigh + bLow + bCarry;\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " if (0 == bNewAdd)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " bFlag |= Z80_FLAG_ZERO;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " else\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " bFlag = bNewAdd & 0x80; /* Sign flag */\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " if (((UINT32) bLow + (UINT32) bHigh + (UINT32) bCarry) >= 0x100)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " bFlag |= Z80_FLAG_CARRY;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " if ( ((bLow ^ bHigh ^ 0x80) & (bLow ^ (bNewAdd & 0x80))) & 0x80)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " bFlag |= Z80_FLAG_OVERFLOW_PARITY;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " if (((bLow & 0x0f) + (bHigh & 0x0f) + bCarry) >= 0x10)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " bFlag |= Z80_FLAG_HALF_CARRY;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " *pbTempPtr++ = bFlag; /* Store our new flag */\n\n");\r
-\r
- fprintf(fp, " // Now do subtract - Zero\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " bFlag = Z80_FLAG_NEGATIVE;\n");\r
- fprintf(fp, " bNewSub = bHigh - bLow - bCarry;\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " if (0 == bNewSub)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " bFlag |= Z80_FLAG_ZERO;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " else\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " bFlag |= bNewSub & 0x80; /* Sign flag */\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " if ( ((INT32) bHigh - (INT32) bLow - (INT32) bCarry) < 0)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " bFlag |= Z80_FLAG_CARRY;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " if ( ((INT32) (bHigh & 0xf) - (INT32) (bLow & 0x0f) - (INT32) bCarry) < 0)\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " bFlag |= Z80_FLAG_HALF_CARRY;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " if ( ((bLow ^ bHigh) & (bHigh ^ bNewSub) & 0x80) )\n");\r
- fprintf(fp, " {\n");\r
- fprintf(fp, " bFlag |= Z80_FLAG_OVERFLOW_PARITY;\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " *pbTempPtr2++ = bFlag; /* Store our sub flag */\n");\r
- fprintf(fp, "\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, " }\n");\r
- fprintf(fp, "}\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void ShutdownCode(void)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- fprintf(fp, " global _%sshutdown\n", cpubasename);\r
- fprintf(fp, " global %sshutdown_\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, " global %sshutdown\n", cpubasename);\r
-\r
- sprintf(procname, "%sshutdown_", cpubasename);\r
- ProcBegin(0xffffffff);\r
-\r
- fprintf(fp, "_%sshutdown:\n", cpubasename);\r
- \r
- if (bPlain)\r
- fprintf(fp, "%sshutdown:\n", cpubasename);\r
-\r
- fprintf(fp, " ret\n\n");\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- fprintf(fp, "/* Shut down MZ80 */\n\n");\r
- fprintf(fp, "void %sshutdown(void)\n", cpubasename);\r
- fprintf(fp, "{\n");\r
-\r
- fprintf(fp, "}\n\n");\r
- }\r
- else\r
- {\r
- assert(0);\r
- }\r
-}\r
-\r
-void DebuggerCode(void)\r
-{\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- {\r
- Alignment();\r
-\r
- fprintf(fp, ";\n");\r
- fprintf(fp, "; In : EAX=Reg #, ESI=Context address\n");\r
- fprintf(fp, "; Out: EAX=Value of register\n");\r
- fprintf(fp, ";\n");\r
-\r
- fprintf(fp, "getRegValueInternal:\n");\r
-\r
- fprintf(fp, " push ecx\n");\r
- fprintf(fp, " push edx\n\n");\r
-\r
- fprintf(fp, " cmp eax, CPUREG_MAXINDEX\n");\r
- fprintf(fp, " jae badIndex2\n\n");\r
-\r
- fprintf(fp, " shl eax, 4 ; Times 16 for table entry size\n");\r
- fprintf(fp, " add eax, RegTable ; Now it's the memory location\n");\r
-\r
- fprintf(fp, " mov edx, [eax+4] ; Get the offset of the register\n");\r
- fprintf(fp, " mov edx, [edx + esi] ; Get our value\n");\r
-\r
- fprintf(fp, " mov ecx, [eax+8] ; Get our shift value\n");\r
- fprintf(fp, " shr edx, cl ; Shift it right by a value\n");\r
-\r
- fprintf(fp, " and edx, [eax+12] ; Mask off any unneeded bits\n");\r
- fprintf(fp, " mov eax, edx ; Put our value in EAX\n");\r
- fprintf(fp, " jmp short indexExit ; Index's exit!\n");\r
-\r
- fprintf(fp, "badIndex2:\n");\r
- fprintf(fp, " mov eax, 0ffffffffh\n\n");\r
- fprintf(fp, "indexExit:\n");\r
- fprintf(fp, " pop edx\n");\r
- fprintf(fp, " pop ecx\n");\r
- fprintf(fp, " ret\n\n");\r
-\r
- Alignment();\r
-\r
- fprintf(fp, ";\n");\r
- fprintf(fp, "; In : EAX=Value, EDX=Reg #, ESI=Context address\n");\r
- fprintf(fp, "; Out: EAX=Value of register\n");\r
- fprintf(fp, ";\n");\r
-\r
- fprintf(fp, "convertValueToText:\n");\r
-\r
- fprintf(fp, " push ecx\n");\r
- fprintf(fp, " push edx\n\n");\r
-\r
- fprintf(fp, " cmp edx, CPUREG_MAXINDEX\n");\r
- fprintf(fp, " jae badIndex3\n\n");\r
-\r
- fprintf(fp, " shl edx, 4 ; Times 16 for table entry size\n");\r
- fprintf(fp, " add edx, RegTable ; Now it's the memory location\n");\r
- fprintf(fp, " mov edx, [edx + 12] ; Shift mask\n");\r
- fprintf(fp, " xor ecx, ecx ; Zero our shift\n");\r
-\r
- fprintf(fp, "shiftLoop:\n");\r
- fprintf(fp, " test edx, 0f0000000h ; High nibble nonzero yet?\n");\r
- fprintf(fp, " jnz convertLoop ; Yup!\n");\r
- fprintf(fp, " shl edx, 4 ; Move over, bacon\n");\r
- fprintf(fp, " shl eax, 4 ; Move the value over, too\n");\r
- fprintf(fp, " jmp short shiftLoop ; Keep shiftin'\n\n");\r
-\r
- fprintf(fp, "convertLoop:\n");\r
- fprintf(fp, " mov ecx, eax ; Get our value\n");\r
- fprintf(fp, " shr ecx, 28 ; Only the top nibble\n");\r
- fprintf(fp, " add cl, '0' ; Convert to ASCII\n");\r
- fprintf(fp, " cmp cl, '9' ; Greater than 9?\n");\r
- fprintf(fp, " jbe noAdd ; Nope! Don't add it\n");\r
- fprintf(fp, " add cl, 32+7 ; Convert from lowercase a-f\n");\r
- fprintf(fp, "noAdd:\n");\r
- fprintf(fp, " mov [edi], cl ; New value storage\n");\r
- fprintf(fp, " inc edi ; Next byte, please\n");\r
- fprintf(fp, " shl eax, 4 ; Move the mask over\n");\r
- fprintf(fp, " shl edx, 4 ; Move the mask over\n");\r
- fprintf(fp, " jnz convertLoop ; Keep convertin'\n\n");\r
-\r
-\r
- fprintf(fp, "badIndex3:\n");\r
- fprintf(fp, " mov [edi], byte 0 ; Null terminate the sucker!\n");\r
- fprintf(fp, " pop edx\n");\r
- fprintf(fp, " pop ecx\n");\r
- fprintf(fp, " ret\n\n");\r
-\r
- fprintf(fp, " global _%sSetRegisterValue\n", cpubasename);\r
- fprintf(fp, " global %sSetRegisterValue_\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, " global %sSetRegisterValue\n", cpubasename);\r
-\r
- sprintf(procname, "%sSetRegisterValue_", cpubasename);\r
- ProcBegin(0xffffffff);\r
-\r
- fprintf(fp, "_%sSetRegisterValue:\n", cpubasename);\r
- if (bPlain)\r
- fprintf(fp, "%sSetRegisterValue:\n", cpubasename);\r
-\r
- fprintf(fp, " push esi\n");\r
- fprintf(fp, " push edi\n");\r
- fprintf(fp, " push edx\n");\r
- fprintf(fp, " push ecx\n");\r
-\r
- if (bUseStack)\r
- {\r
- fprintf(fp, " mov eax, [esp+20] ; Get our register #\n");\r
- fprintf(fp, " mov esi, [esp+24] ; Get our context address\n");\r
- fprintf(fp, " mov edi, [esp+28] ; Value to assign\n");\r
- }\r
- else\r
- {\r
- fprintf(fp, " mov esi, eax ; Get context\n");\r
- fprintf(fp, " mov eax, edx ; Get register # in EAX\n");\r
- fprintf(fp, " mov edi, ebx ; Get value to assign\n");\r
- }\r
-\r
- fprintf(fp, " or esi, esi ; Are we NULL?\n");\r
- fprintf(fp, " jnz userDefined\n");\r
-\r
- fprintf(fp, " mov esi, _%scontextBegin\n", cpubasename);\r
- fprintf(fp, "userDefined:\n\n");\r
- fprintf(fp, " shl eax, 4 ; Times 16 for reg entry size\n");\r
- fprintf(fp, " add eax, RegTable\n");\r
- fprintf(fp, " mov edx, [eax+12] ; Our mask\n");\r
- fprintf(fp, " not edx ; Invert EDX!\n");\r
- fprintf(fp, " test edi, edx ; Did we set any invalid bits?\n");\r
- fprintf(fp, " jnz rangeViolation\n\n");\r
-\r
- fprintf(fp, " not edx ; Toggle it back to normal\n");\r
- fprintf(fp, " mov ecx, [eax+8] ; Get our shift value\n");\r
- fprintf(fp, " shl edx, cl ; Shift our mask\n");\r
- fprintf(fp, " shl eax, cl ; And our value to OR in\n");\r
- \r
- fprintf(fp, " not edx ; Make it the inverse of what we want\n");\r
- fprintf(fp, " mov eax, [eax+4] ; Get our offset into the context\n");\r
- fprintf(fp, " and [esi+eax], edx ; Mask off the bits we're changin\n");\r
- fprintf(fp, " or [esi+eax], edi ; Or in our new value\n\n");\r
- fprintf(fp, " xor eax, eax\n");\r
- fprintf(fp, " jmp short setExit\n\n");\r
-\r
- fprintf(fp, "rangeViolation:\n");\r
- fprintf(fp, " mov eax, 0ffffffffh\n\n");\r
-\r
- fprintf(fp, "setExit:\n");\r
- fprintf(fp, " pop ecx\n");\r
- fprintf(fp, " pop edx\n");\r
- fprintf(fp, " pop edi\n");\r
- fprintf(fp, " pop esi\n\n");\r
-\r
- fprintf(fp, " ret\n\n");\r
-\r
- Alignment();\r
-\r
- fprintf(fp, " global _%sGetRegisterValue\n", cpubasename);\r
- fprintf(fp, " global %sGetRegisterValue_\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, " global %sGetRegisterValue\n", cpubasename);\r
-\r
- sprintf(procname, "%sGetRegisterValue_", cpubasename);\r
- ProcBegin(0xffffffff);\r
-\r
- fprintf(fp, "_%sGetRegisterValue:\n", cpubasename);\r
- if (bPlain)\r
- fprintf(fp, "%sGetRegisterValue:\n", cpubasename);\r
-\r
- fprintf(fp, " push esi\n");\r
-\r
- if (bUseStack)\r
- {\r
- fprintf(fp, " mov eax, [esp+8] ; Get our register #\n");\r
- fprintf(fp, " mov esi, [esp+12] ; Get our context address\n");\r
- }\r
- else\r
- {\r
- fprintf(fp, " mov esi, eax ; Get context\n");\r
- fprintf(fp, " mov eax, edx ; Get register # in EAX\n");\r
- }\r
-\r
- fprintf(fp, " or esi, esi ; Is context NULL?\n");\r
- fprintf(fp, " jnz getVal ; Nope - use it!\n");\r
- fprintf(fp, " mov esi, _%scontextBegin\n\n", cpubasename);\r
-\r
- fprintf(fp, "getVal:\n");\r
- fprintf(fp, " call getRegValueInternal\n\n");\r
-\r
- fprintf(fp, " pop esi\n");\r
-\r
- fprintf(fp, " ret\n\n");\r
-\r
- Alignment();\r
-\r
- fprintf(fp, " global _%sGetRegisterName\n", cpubasename);\r
- fprintf(fp, " global %sGetRegisterName_\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, " global %sGetRegisterName\n", cpubasename);\r
-\r
- sprintf(procname, "%sGetRegisterName_", cpubasename);\r
- ProcBegin(0xffffffff);\r
-\r
- fprintf(fp, "_%sGetRegisterName:\n", cpubasename);\r
- if (bPlain)\r
- fprintf(fp, "%sGetRegisterName:\n", cpubasename);\r
-\r
- if (bUseStack)\r
- {\r
- fprintf(fp, " mov eax, [esp+4] ; Get our register #\n");\r
- }\r
-\r
- fprintf(fp, " cmp eax, CPUREG_MAXINDEX\n");\r
- fprintf(fp, " jae badIndex\n");\r
-\r
- fprintf(fp, " shl eax, 4 ; Times 16 bytes for each entry\n");\r
- fprintf(fp, " mov eax, [eax+RegTable]\n");\r
- fprintf(fp, " jmp nameExit\n\n");\r
-\r
- fprintf(fp, "badIndex:\n");\r
- fprintf(fp, " xor eax, eax\n\n");\r
-\r
- fprintf(fp, "nameExit:\n");\r
- fprintf(fp, " ret\n\n");\r
-\r
- Alignment();\r
-\r
- fprintf(fp, " global _%sGetRegisterTextValue\n", cpubasename);\r
- fprintf(fp, " global %sGetRegisterTextValue_\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, " global %sGetRegisterTextValue\n", cpubasename);\r
-\r
- sprintf(procname, "%sGetRegisterTextValue_", cpubasename);\r
- ProcBegin(0xffffffff);\r
-\r
- fprintf(fp, "_%sGetRegisterTextValue:\n", cpubasename);\r
- if (bPlain)\r
- fprintf(fp, "%sGetRegisterTextValue:\n", cpubasename);\r
-\r
- fprintf(fp, " push esi\n");\r
- fprintf(fp, " push edi\n");\r
- fprintf(fp, " push edx\n");\r
-\r
- if (bUseStack)\r
- {\r
- fprintf(fp, " mov eax, [esp+16] ; Get our register #\n");\r
- fprintf(fp, " mov esi, [esp+20] ; Get our context address\n");\r
- fprintf(fp, " mov edi, [esp+24] ; Address to place text\n");\r
- }\r
- else\r
- {\r
- fprintf(fp, " mov esi, eax ; Get context\n");\r
- fprintf(fp, " mov eax, edx ; Get register # in EAX\n");\r
- fprintf(fp, " mov edi, ebx ; Address to place text\n");\r
- }\r
-\r
- fprintf(fp, " or esi, esi ; Is context NULL?\n");\r
- fprintf(fp, " jnz getVal2 ; Nope - use it!\n");\r
- fprintf(fp, " mov esi, _%scontextBegin\n\n", cpubasename);\r
-\r
- fprintf(fp, "getVal2:\n");\r
- fprintf(fp, " mov edx, eax ; Save off our index for later\n");\r
- fprintf(fp, " call getRegValueInternal\n\n");\r
-\r
- fprintf(fp, "; EAX Holds the value, EDX=Register #, and EDI=Destination!\n\n");\r
-\r
- fprintf(fp, " call convertValueToText\n\n");\r
-\r
- fprintf(fp, " pop edx\n");\r
- fprintf(fp, " pop esi\n");\r
- fprintf(fp, " pop edi\n");\r
-\r
- fprintf(fp, " ret\n\n");\r
-\r
- Alignment();\r
-\r
- fprintf(fp, " global _%sWriteValue\n", cpubasename);\r
- fprintf(fp, " global %sWriteValue_\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, " global %sWriteValue\n", cpubasename);\r
-\r
- sprintf(procname, "%sWriteValue_", cpubasename);\r
- ProcBegin(0xffffffff);\r
-\r
- fprintf(fp, "_%sWriteValue:\n", cpubasename);\r
- if (bPlain)\r
- fprintf(fp, "%sWriteValue:\n", cpubasename);\r
-\r
- fprintf(fp, " push esi\n");\r
- fprintf(fp, " push edi\n");\r
- fprintf(fp, " push edx\n");\r
- fprintf(fp, " push ebx\n");\r
- fprintf(fp, " push ecx\n");\r
- fprintf(fp, " push ebp\n");\r
-\r
- if (bUseStack)\r
- {\r
- fprintf(fp, " mov eax, [esp+28] ; What kind of write is this?\n");\r
- fprintf(fp, " mov ebx, [esp+32] ; Address\n");\r
- fprintf(fp, " mov edx, [esp+36] ; Value\n");\r
- }\r
- else\r
- {\r
- fprintf(fp, " xchg edx, ebx ; Addr=EBX, value=EDX\n");\r
- }\r
-\r
- fprintf(fp, " cmp eax, 1 ; Is it a word write?\n");\r
- fprintf(fp, " je near invalidWrite ; Yep - it's not valid\n");\r
- fprintf(fp, " cmp eax, 2 ; Is it a dword write?\n");\r
- fprintf(fp, " je near invalidWrite ; Yep - it's not valid\n\n");\r
- fprintf(fp, " or eax, eax ; Is it a byte write?\n");\r
- fprintf(fp, " jnz itsIoDummy ; Nope... it's an I/O write\n\n");\r
-\r
- // Here we do a write memory byte\r
-\r
- fprintf(fp, " mov ebp, [_z80Base] ; Base pointer comes back\n");\r
- fprintf(fp, " mov edi, [_z80MemWrite] ; Point to the write array\n");\r
-\r
- fprintf(fp, "checkLoop:\n");\r
- fprintf(fp, " cmp [edi], word 0ffffh ; End of our list?\n");\r
- fprintf(fp, " je memoryWrite ; Yes - go write it!\n");\r
- fprintf(fp, " cmp bx, [edi] ; Are we smaller?\n");\r
- fprintf(fp, " jb nextAddr ; Yes... go to the next addr\n");\r
- fprintf(fp, " cmp bx, [edi+4] ; Are we smaller?\n");\r
- fprintf(fp, " jbe callRoutine ; If not, go call it!\n");\r
-\r
- fprintf(fp, "nextAddr:\n");\r
- fprintf(fp, " add edi, 10h ; Next structure, please\n");\r
- fprintf(fp, " jmp short checkLoop\n");\r
-\r
- fprintf(fp, "callRoutine:\n");\r
-\r
- fprintf(fp, "\n;\n; EBX=Address to target, DL=Byte to write \n;\n\n");\r
-\r
- fprintf(fp, " cmp [edi+8], dword 0 ; Null handler?\n");\r
- fprintf(fp, " je directWriteHandler2\n\n");\r
- \r
- if (FALSE == bUseStack)\r
- {\r
- fprintf(fp, " mov eax, ebx ; Address\n");\r
- fprintf(fp, " mov ebx, edi ; Pointer to struct (EDX Already has the byte to write)\n");\r
- }\r
- else\r
- {\r
- fprintf(fp, " push edi ; Handler\n");\r
- fprintf(fp, " push edx ; Byte\n");\r
- fprintf(fp, " push ebx ; Address\n");\r
- }\r
- \r
- fprintf(fp, " call dword [edi + 8] ; Go call our handler\n");\r
-\r
- if (bUseStack)\r
- {\r
- fprintf(fp, " add esp, 12\n");\r
- }\r
-\r
- fprintf(fp, " jmp short itsGood\n");\r
-\r
- fprintf(fp, "directWriteHandler2:\n");\r
- fprintf(fp, " sub ebx, [edi] ; Subtract our offset\n");\r
- fprintf(fp, " add ebx, [edi+12] ; Add in the base address\n");\r
- fprintf(fp, " mov [ebx], dl ; Store our byte\n");\r
- fprintf(fp, " jmp short itsGood\n");\r
- fprintf(fp, "memoryWrite:\n");\r
- fprintf(fp, " mov [ebp + ebx], dl\n\n");\r
- fprintf(fp, " jmp short itsGood\n");\r
-\r
- // Here we do an "out"\r
-\r
- fprintf(fp, "itsIoDummy:\n");\r
-\r
- fprintf(fp, " mov edi, [_z80IoWrite] ; Point to the I/O write array\n");\r
-\r
- fprintf(fp, "IOCheck:\n");\r
- fprintf(fp, " cmp [edi], word 0ffffh ; End of our list?\n");\r
- fprintf(fp, " je itsGood ; Yes - ignore it!\n");\r
- fprintf(fp, " cmp bx, [edi] ; Are we smaller?\n");\r
- fprintf(fp, " jb nextIOAddr ; Yes... go to the next addr\n");\r
- fprintf(fp, " cmp bx, [edi+2] ; Are we bigger?\n");\r
- fprintf(fp, " jbe callIOHandler ; If not, go call it!\n");\r
-\r
- fprintf(fp, "nextIOAddr:\n");\r
- fprintf(fp, " add edi, 0ch ; Next structure, please\n");\r
- fprintf(fp, " jmp short IOCheck\n");\r
-\r
- fprintf(fp, "callIOHandler:\n");\r
-\r
- if (FALSE == bUseStack)\r
- {\r
- fprintf(fp, " mov eax, ebx ; Address\n");\r
- fprintf(fp, " mov ebx, edi ; Pointer to struct (EDX Already has the byte to write)\n");\r
- }\r
- else\r
- {\r
- fprintf(fp, " push edi ; Handler\n");\r
- fprintf(fp, " push edx ; Byte\n");\r
- fprintf(fp, " push ebx ; Address\n");\r
- }\r
-\r
- fprintf(fp, " call dword [edi+4] ; Call the handler!\n");\r
-\r
- if (bUseStack)\r
- fprintf(fp, " add esp, 12\n");\r
-\r
- fprintf(fp, " jmp short itsGood\n\n");\r
-\r
- // Errors and whatnot\r
-\r
- fprintf(fp, "invalidWrite:\n");\r
- fprintf(fp, " mov eax, 0ffffffffh\n");\r
- fprintf(fp, " jmp short writeValueExit\n\n");\r
-\r
- fprintf(fp, "itsGood:\n");\r
- fprintf(fp, " xor eax, eax\n\n");\r
-\r
- fprintf(fp, "writeValueExit:\n");\r
-\r
- fprintf(fp, " pop ebp\n");\r
- fprintf(fp, " pop ecx\n");\r
- fprintf(fp, " pop ebx\n");\r
- fprintf(fp, " pop edx\n");\r
- fprintf(fp, " pop esi\n");\r
- fprintf(fp, " pop edi\n");\r
-\r
- fprintf(fp, " ret\n\n");\r
-\r
- Alignment();\r
-\r
- fprintf(fp, " global _%sReadValue\n", cpubasename);\r
- fprintf(fp, " global %sReadValue_\n", cpubasename);\r
-\r
- if (bPlain)\r
- fprintf(fp, " global %sReadValue\n", cpubasename);\r
-\r
- sprintf(procname, "%sReadValue_", cpubasename);\r
- ProcBegin(0xffffffff);\r
-\r
- fprintf(fp, "_%sReadValue:\n", cpubasename);\r
- if (bPlain)\r
- fprintf(fp, "%sReadValue:\n", cpubasename);\r
-\r
- fprintf(fp, " push esi\n");\r
- fprintf(fp, " push edi\n");\r
- fprintf(fp, " push edx\n");\r
- fprintf(fp, " push ebx\n");\r
- fprintf(fp, " push ecx\n");\r
- fprintf(fp, " push ebp\n");\r
-\r
- if (bUseStack)\r
- {\r
- fprintf(fp, " mov eax, [esp+28] ; What kind of read is this?\n");\r
- fprintf(fp, " mov ebx, [esp+32] ; Address\n");\r
- }\r
- else\r
- {\r
- fprintf(fp, " xchg edx, ebx ; Addr=EBX\n");\r
- }\r
-\r
- fprintf(fp, " cmp eax, 1 ; Is it a word read?\n");\r
- fprintf(fp, " je near invalidRead ; Yep - it's not valid\n");\r
- fprintf(fp, " cmp eax, 2 ; Is it a dword read?\n");\r
- fprintf(fp, " je near invalidRead ; Yep - it's not valid\n\n");\r
- fprintf(fp, " or eax, eax ; Is it a byte read?\n");\r
- fprintf(fp, " jnz itsIoDummyRead ; Nope... it's an I/O read\n\n");\r
-\r
- // Here we do a read memory byte\r
-\r
- fprintf(fp, " mov ebp, [_z80Base] ; Base pointer comes back\n");\r
- fprintf(fp, " mov edi, [_z80MemRead] ; Point to the read array\n");\r
-\r
- fprintf(fp, "checkLoopRead:\n");\r
- fprintf(fp, " cmp [edi], word 0ffffh ; End of our list?\n");\r
- fprintf(fp, " je memoryRead ; Yes - go read it!\n");\r
- fprintf(fp, " cmp bx, [edi] ; Are we smaller?\n");\r
- fprintf(fp, " jb nextAddrRead ; Yes... go to the next addr\n");\r
- fprintf(fp, " cmp bx, [edi+4] ; Are we smaller?\n");\r
- fprintf(fp, " jbe callRoutineRead ; If not, go call it!\n");\r
-\r
- fprintf(fp, "nextAddrRead:\n");\r
- fprintf(fp, " add edi, 10h ; Next structure, please\n");\r
- fprintf(fp, " jmp short checkLoopRead\n");\r
-\r
- fprintf(fp, "callRoutineRead:\n");\r
-\r
- fprintf(fp, "\n;\n; EBX=Address to target\n;\n\n");\r
-\r
- fprintf(fp, " cmp [edi+8], dword 0 ; NULL HAndler?\n");\r
- fprintf(fp, " je handleSharedRead\n\n");\r
-\r
- if (FALSE == bUseStack)\r
- {\r
- fprintf(fp, " mov eax, ebx ; Address\n");\r
- fprintf(fp, " mov edx, edi ; Pointer to struct\n");\r
- }\r
- else\r
- {\r
- fprintf(fp, " push edi ; Handler\n");\r
- fprintf(fp, " push ebx ; Address\n");\r
- }\r
- \r
- fprintf(fp, " call dword [edi + 8] ; Go call our handler\n");\r
- fprintf(fp, " mov dl, al ; Get our byte read\n");\r
-\r
- if (bUseStack)\r
- {\r
- fprintf(fp, " add esp, 8\n");\r
- }\r
-\r
- fprintf(fp, " jmp short itsGoodRead\n\n");\r
-\r
- fprintf(fp, "memoryRead:\n");\r
- fprintf(fp, " mov dl, [ebp+ebx]\n\n");\r
- fprintf(fp, " jmp short itsGoodRead\n\n");\r
-\r
- fprintf(fp, "handleSharedRead:\n");\r
- fprintf(fp, " sub ebx, [edi]\n");\r
- fprintf(fp, " add ebx, [edi+12]\n");\r
- fprintf(fp, " mov dl, [ebx]\n");\r
- fprintf(fp, " jmp short itsGoodRead\n\n");\r
-\r
- // Here we do an "out"\r
-\r
- fprintf(fp, "itsIoDummyRead:\n");\r
-\r
- fprintf(fp, " mov edi, [_z80IoRead] ; Point to the I/O read array\n");\r
- fprintf(fp, " mov dl, 0ffh ; Assume no handler\n");\r
-\r
- fprintf(fp, "IOCheckRead:\n");\r
- fprintf(fp, " cmp [edi], word 0ffffh ; End of our list?\n");\r
- fprintf(fp, " je itsGoodRead ; Yes - ignore it!\n");\r
- fprintf(fp, " cmp bx, [edi] ; Are we smaller?\n");\r
- fprintf(fp, " jb nextIOAddrRead ; Yes... go to the next addr\n");\r
- fprintf(fp, " cmp bx, [edi+2] ; Are we bigger?\n");\r
- fprintf(fp, " jbe callIOHandlerRead ; If not, go call it!\n");\r
-\r
- fprintf(fp, "nextIOAddrRead:\n");\r
- fprintf(fp, " add edi, 0ch ; Next structure, please\n");\r
- fprintf(fp, " jmp short IOCheckRead\n");\r
-\r
- fprintf(fp, "callIOHandlerRead:\n");\r
-\r
- if (FALSE == bUseStack)\r
- {\r
- fprintf(fp, " mov eax, ebx ; Address\n");\r
- fprintf(fp, " mov edx, edi ; Pointer to struct (EDX Already has the byte to write)\n");\r
- }\r
- else\r
- {\r
- fprintf(fp, " push edi ; Handler\n");\r
- fprintf(fp, " push ebx ; Address\n");\r
- }\r
-\r
- fprintf(fp, " call dword [edi+4] ; Call the handler!\n");\r
- fprintf(fp, " mov dl, al ; Get our byte read\n");\r
-\r
- if (bUseStack)\r
- fprintf(fp, " add esp, 8\n");\r
-\r
- fprintf(fp, " jmp short itsGoodRead\n\n");\r
-\r
- // Errors and whatnot\r
-\r
- fprintf(fp, "invalidRead:\n");\r
- fprintf(fp, " mov eax, 0ffffffffh\n");\r
- fprintf(fp, " jmp short ReadValueExit\n\n");\r
-\r
- fprintf(fp, "itsGoodRead:\n");\r
- fprintf(fp, " xor eax, eax\n");\r
- fprintf(fp, " mov al, dl\n\n");\r
-\r
- fprintf(fp, "ReadValueExit:\n");\r
-\r
- fprintf(fp, " pop ebp\n");\r
- fprintf(fp, " pop ecx\n");\r
- fprintf(fp, " pop ebx\n");\r
- fprintf(fp, " pop edx\n");\r
- fprintf(fp, " pop esi\n");\r
- fprintf(fp, " pop edi\n");\r
-\r
- fprintf(fp, " ret\n\n");\r
-\r
-\r
-\r
- }\r
- else\r
- if (MZ80_C == bWhat)\r
- {\r
- }\r
-}\r
-\r
-\r
-EmitCode()\r
-{\r
- CodeSegmentBegin();\r
- EmitCBInstructions();\r
- EmitEDInstructions();\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- strcpy(mz80Index, "ix");\r
- \r
- else\r
- {\r
- strcpy(mz80Index, "cpu.z80IX");\r
- strcpy(mz80IndexHalfHigh, "cpu.z80XH");\r
- strcpy(mz80IndexHalfLow, "cpu.z80XL");\r
- }\r
-\r
- strcpy(majorOp, "DD");\r
- EmitDDInstructions();\r
-\r
- if (MZ80_ASSEMBLY_X86 == bWhat)\r
- strcpy(mz80Index, "iy");\r
- else\r
- {\r
- strcpy(mz80Index, "cpu.z80IY");\r
- strcpy(mz80IndexHalfHigh, "cpu.z80YH");\r
- strcpy(mz80IndexHalfLow, "cpu.z80YL");\r
- }\r
-\r
- strcpy(majorOp, "FD");\r
- EmitFDInstructions();\r
- majorOp[0] = '\0';\r
- EmitRegularInstructions();\r
- ReadMemoryByteHandler();\r
- WriteMemoryByteHandler();\r
-\r
- if (bThroughCallHandler)\r
- {\r
- PushWordHandler();\r
- PopWordHandler();\r
- }\r
-\r
- ReadIoHandler();\r
- WriteIoHandler();\r
- GetContextCode();\r
- SetContextCode();\r
- GetContextSizeCode();\r
- GetTicksCode();\r
- ReleaseTimesliceCode();\r
- ResetCode();\r
- IntCode();\r
- NmiCode();\r
- ExecCode();\r
- InitCode();\r
- ShutdownCode();\r
- DebuggerCode();\r
- CodeSegmentEnd();\r
-}\r
-\r
-main(int argc, char **argv)\r
-{\r
- UINT32 dwLoop = 0;\r
-\r
- printf("MakeZ80 - V%s - Copyright 1996-2000 Neil Bradley (neil@synthcom.com)\n", VERSION);\r
-\r
- if (argc < 2)\r
- {\r
- printf("Usage: %s outfile [option1] [option2] ....\n", argv[0]);\r
- printf("\n -s - Stack calling conventions (DJGPP, MSVC, Borland)\n");\r
- printf(" -x86 - Emit an assembly version of mz80\n");\r
- printf(" -c - Emit a C version of mz80\n");\r
- printf(" -cs - All stack operations go through handlers\n");\r
- printf(" -16 - Treat all I/O input and output as 16 bit (BC) instead of (C)\n");\r
- printf(" -l - Create 'plain' labels - ones without leading or trailing _'s\n");\r
- printf(" -nt - No timing additions occur\n");\r
- printf(" -os2 - Emit OS/2 compatible segmentation pragmas\n");\r
- exit(1);\r
- }\r
-\r
- dwLoop = 1;\r
-\r
- while (dwLoop < argc)\r
- {\r
- if (strcmp("-x86", argv[dwLoop]) == 0 || strcmp("-X86", argv[dwLoop]) == 0)\r
- bWhat = MZ80_ASSEMBLY_X86;\r
- if (strcmp("-c", argv[dwLoop]) == 0 || strcmp("-C", argv[dwLoop]) == 0)\r
- bWhat = MZ80_C;\r
- if (strcmp("-cs", argv[dwLoop]) == 0 || strcmp("-cs", argv[dwLoop]) == 0)\r
- bThroughCallHandler = TRUE;\r
- if (strcmp("-s", argv[dwLoop]) == 0 || strcmp("-S", argv[dwLoop]) == 0)\r
- bUseStack = 1;\r
- if (strcmp("-l", argv[dwLoop]) == 0 || strcmp("-L", argv[dwLoop]) == 0)\r
- bPlain = TRUE;\r
- if (strcmp("-16", argv[dwLoop]) == 0)\r
- b16BitIo = TRUE;\r
- if (strcmp("-os2", argv[dwLoop]) == 0 || strcmp("-OS2", argv[dwLoop]) == 0)\r
- bOS2 = TRUE;\r
- if (strcmp("-nt", argv[dwLoop]) == 0)\r
- {\r
- bNoTiming = TRUE;\r
- }\r
-\r
- dwLoop++;\r
- }\r
-\r
- if (bWhat == MZ80_UNKNOWN)\r
- {\r
- fprintf(stderr, "Need emitted type qualifier\n");\r
- exit(1);\r
- }\r
-\r
- for (dwLoop = 1; dwLoop < argc; dwLoop++)\r
- if (argv[dwLoop][0] != '-')\r
- {\r
- fp = fopen(argv[dwLoop], "w");\r
- break;\r
- }\r
-\r
- if (NULL == fp)\r
- {\r
- fprintf(stderr, "Can't open %s for writing\n", argv[1]);\r
- exit(1);\r
- }\r
-\r
- strcpy(cpubasename, "mz80");\r
-\r
- StandardHeader();\r
- DataSegment();\r
- EmitCode();\r
- ProgramEnd();\r
-\r
- fclose(fp);\r
-}\r