📄 makez80.c
字号:
fprintf(fp, "callRoutine%ld:\n", dwGlobalLabel); fprintf(fp, " push ax ; Save this for later\n"); // Write the LSB fprintf(fp, " push dx\n"); if (strcmp(pszTarget, "ax") != 0) { fprintf(fp, " mov ax, %s\n", pszTarget); } else { fprintf(fp, " xchg ah, al\n"); } fprintf(fp, " call WriteMemoryByte\n"); fprintf(fp, " pop dx\n"); fprintf(fp, " pop ax\n"); fprintf(fp, " inc dx\n\n"); fprintf(fp, " push ax\n"); fprintf(fp, " push dx\n"); if (strcmp(pszTarget, "ax") != 0) { fprintf(fp, " mov ax, %s\n", pszTarget); fprintf(fp, " xchg ah, al\n"); } fprintf(fp, " call WriteMemoryByte\n"); fprintf(fp, " pop dx\n"); fprintf(fp, " pop ax ; Restore us!\n"); fprintf(fp, " jmp writeExit%ld\n\n", dwGlobalLabel); fprintf(fp, "memoryWrite%ld:\n", dwGlobalLabel); if (strlen(pszTarget) != 2) { fprintf(fp, " mov di, %s\n", pszTarget); fprintf(fp, " mov [ebp + e%s], di ; Store our word\n", pszAddress); } else { if (strcmp(pszTarget, "ax") != 0) { fprintf(fp, " mov [ebp + e%s], %s ; Store our word\n", pszAddress, pszTarget); } else { fprintf(fp, " xchg ah, al ; Swap for later\n"); fprintf(fp, " mov [ebp + e%s], %s ; Store our word\n", pszAddress, pszTarget); fprintf(fp, " xchg ah, al ; Restore\n"); } } fprintf(fp, "writeExit%ld:\n", dwGlobalLabel); fprintf(fp, " mov edi, [cyclesRemaining]\n"); dwGlobalLabel++; } else if (MZ80_C == bWhat) { fprintf(fp, " psMemWrite = cpu.z80MemWrite; /* Beginning of our handler */\n"); fprintf(fp, " while (psMemWrite->lowAddr != 0xffffffff)\n"); fprintf(fp, " {\n"); fprintf(fp, " if ((%s >= psMemWrite->lowAddr) && (%s <= psMemWrite->highAddr))\n", pszAddress, pszAddress); fprintf(fp, " {\n"); fprintf(fp, " cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;\n"); fprintf(fp, " if (psMemWrite->memoryCall)\n"); fprintf(fp, " {\n"); fprintf(fp, " psMemWrite->memoryCall(%s, (%s & 0xff), psMemWrite);\n", pszAddress, pszTarget); fprintf(fp, " psMemWrite->memoryCall(%s + 1, (%s >> 8), psMemWrite);\n", pszAddress, pszTarget); fprintf(fp, " }\n"); fprintf(fp, " else\n"); fprintf(fp, " {\n"); fprintf(fp, " *((UINT8 *) psMemWrite->pUserArea + (%s - psMemWrite->lowAddr)) = %s;\n", pszAddress, pszTarget); fprintf(fp, " *((UINT8 *) psMemWrite->pUserArea + (%s - psMemWrite->lowAddr) + 1) = %s >> 8;\n", pszAddress, pszTarget); fprintf(fp, " }\n"); fprintf(fp, " psMemWrite = NULL;\n"); fprintf(fp, " break;\n"); fprintf(fp, " }\n"); fprintf(fp, " ++psMemWrite;\n"); fprintf(fp, " }\n\n"); fprintf(fp, " if (psMemWrite)\n"); fprintf(fp, " {\n"); fprintf(fp, " cpu.z80Base[%s] = (UINT8) %s;\n", pszAddress, pszTarget); fprintf(fp, " cpu.z80Base[%s + 1] = (UINT8) ((UINT32) %s >> 8);\n", pszAddress, pszTarget); fprintf(fp, " }\n\n"); } else { assert(0); }}void WriteValueToIo(UINT8 *pszIoAddress, UINT8 *pszValue){ if (MZ80_ASSEMBLY_X86 == bWhat) { fprintf(fp, " mov [cyclesRemaining], edi\n"); fprintf(fp, " mov [_z80af], ax ; Store AF\n"); if (strcmp(pszValue, "al") != 0) fprintf(fp, " mov al, %s ; And our data to write\n", pszValue); if (strcmp(pszValue, "[esi]") == 0) // Immediate value? fprintf(fp, " inc esi ; Increment our program counter\n"); fprintf(fp, " mov edi, [_z80IoWrite] ; Point to the I/O write array\n\n", cpubasename); fprintf(fp, "checkLoop%ld:\n", dwGlobalLabel); fprintf(fp, " cmp [edi], word 0ffffh ; End of our list?\n"); fprintf(fp, " je WriteMacroExit%ld ; Yes - ignore it!\n", dwGlobalLabel); fprintf(fp, " cmp %s, [edi] ; Are we smaller?\n", pszIoAddress); fprintf(fp, " jb nextAddr%ld ; Yes... go to the next addr\n", dwGlobalLabel); fprintf(fp, " cmp %s, [edi+2] ; Are we bigger?\n", pszIoAddress); fprintf(fp, " jbe callRoutine%ld ; If not, go call it!\n\n", dwGlobalLabel); fprintf(fp, "nextAddr%ld:\n", dwGlobalLabel); fprintf(fp, " add edi, 0ch ; Next structure, please\n"); fprintf(fp, " jmp short checkLoop%ld\n\n", dwGlobalLabel); fprintf(fp, "callRoutine%ld:\n", dwGlobalLabel); // Save off our registers! if (strcmp(pszIoAddress, "dx") != 0) fprintf(fp, " mov dx, %s ; Get our address to target\n", pszIoAddress); fprintf(fp, " call WriteIOByte ; Go write the data!\n"); fprintf(fp, "WriteMacroExit%ld:\n", dwGlobalLabel); fprintf(fp, " mov edi, [cyclesRemaining]\n"); } else if (MZ80_C == bWhat) { fprintf(fp, " psIoWrite = cpu.z80IoWrite; /* Beginning of our handler */\n"); fprintf(fp, " while (psIoWrite->lowIoAddr != 0xffff)\n"); fprintf(fp, " {\n"); fprintf(fp, " if ((%s >= psIoWrite->lowIoAddr) && (%s <= psIoWrite->highIoAddr))\n", pszIoAddress, pszIoAddress); fprintf(fp, " {\n"); fprintf(fp, " cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;\n"); fprintf(fp, " psIoWrite->IOCall(%s, %s, psIoWrite);\n", pszIoAddress, pszValue); fprintf(fp, " psIoWrite = NULL;\n"); fprintf(fp, " break;\n"); fprintf(fp, " }\n"); fprintf(fp, " ++psIoWrite;\n"); fprintf(fp, " }\n\n"); } else { assert(0); } ++dwGlobalLabel;}void ReadValueFromMemory(UINT8 *pszAddress, UINT8 *pszTarget){ if (MZ80_ASSEMBLY_X86 == bWhat) { fprintf(fp, " mov [cyclesRemaining], edi\n"); fprintf(fp, " mov edi, [_z80MemRead] ; Point to the read array\n\n", cpubasename); fprintf(fp, "checkLoop%ld:\n", dwGlobalLabel); fprintf(fp, " cmp [edi], word 0ffffh ; End of the list?\n"); fprintf(fp, " je memoryRead%ld\n", dwGlobalLabel); fprintf(fp, " cmp e%s, [edi] ; Are we smaller?\n", pszAddress); fprintf(fp, " jb nextAddr%ld ; Yes, go to the next address\n", dwGlobalLabel); fprintf(fp, " cmp e%s, [edi+4] ; Are we bigger?\n", pszAddress); fprintf(fp, " jbe callRoutine%ld\n\n", dwGlobalLabel); fprintf(fp, "nextAddr%ld:\n", dwGlobalLabel); fprintf(fp, " add edi, 10h ; Next structure!\n"); fprintf(fp, " jmp short checkLoop%ld\n\n", dwGlobalLabel); fprintf(fp, "callRoutine%ld:\n", dwGlobalLabel); if (strcmp(pszAddress, "dx") != 0) fprintf(fp, " mov dx, %s ; Get our address\n", pszAddress); fprintf(fp, " call ReadMemoryByte ; Standard read routine\n"); // Yes, these are intentionally reversed! if (strcmp(pszTarget, "al") == 0) fprintf(fp, " mov [_z80af], al ; Save our new accumulator\n"); else if (strcmp(pszTarget, "ah") == 0) fprintf(fp, " mov [_z80af + 1], al ; Save our new flags\n"); else fprintf(fp, " mov %s, al ; Put our returned value here\n", pszTarget); // And are properly restored HERE: fprintf(fp, " mov ax, [_z80af] ; Get our AF back\n"); // Restore registers here... fprintf(fp, " jmp short readExit%ld\n\n", dwGlobalLabel); fprintf(fp, "memoryRead%ld:\n", dwGlobalLabel); if (pszTarget[0] == 'b' && pszTarget[1] == 'y' && pszTarget[2] == 't') { fprintf(fp, " mov di, dx\n"); fprintf(fp, " mov dl, [ebp + e%s]\n", pszAddress); fprintf(fp, " mov %s, dl\n", pszTarget); fprintf(fp, " mov dx, di\n"); } else fprintf(fp, " mov %s, [ebp + e%s] ; Get our data\n\n", pszTarget, pszAddress); fprintf(fp, "readExit%ld:\n", dwGlobalLabel); fprintf(fp, " mov edi, [cyclesRemaining]\n"); dwGlobalLabel++; } else if (MZ80_C == bWhat) { fprintf(fp, " psMemRead = cpu.z80MemRead; /* Beginning of our handler */\n"); fprintf(fp, " while (psMemRead->lowAddr != 0xffffffff)\n"); fprintf(fp, " {\n"); fprintf(fp, " if ((%s >= psMemRead->lowAddr) && (%s <= psMemRead->highAddr))\n", pszAddress, pszAddress); fprintf(fp, " {\n"); fprintf(fp, " cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;\n"); fprintf(fp, " if (psMemRead->memoryCall)\n"); fprintf(fp, " {\n"); fprintf(fp, " %s = psMemRead->memoryCall(%s, psMemRead);\n", pszTarget, pszAddress); fprintf(fp, " }\n"); fprintf(fp, " else\n"); fprintf(fp, " {\n"); fprintf(fp, " %s = *((UINT8 *) psMemRead->pUserArea + (%s - psMemRead->lowAddr));\n", pszTarget, pszAddress); fprintf(fp, " }\n"); fprintf(fp, " psMemRead = NULL;\n"); fprintf(fp, " break;\n"); fprintf(fp, " }\n"); fprintf(fp, " ++psMemRead;\n"); fprintf(fp, " }\n\n"); fprintf(fp, " if (psMemRead)\n"); fprintf(fp, " {\n"); fprintf(fp, " %s = cpu.z80Base[%s];\n", pszTarget, pszAddress); fprintf(fp, " }\n\n"); } else { assert(0); }}void ReadWordFromMemory(UINT8 *pszAddress, UINT8 *pszTarget){ if (MZ80_ASSEMBLY_X86 == bWhat) { fprintf(fp, " mov [cyclesRemaining], edi\n"); fprintf(fp, " mov edi, [_z80MemRead] ; Point to the read array\n\n", cpubasename); fprintf(fp, "checkLoop%ld:\n", dwGlobalLabel); fprintf(fp, " cmp [edi], word 0ffffh ; End of the list?\n"); fprintf(fp, " je memoryRead%ld\n", dwGlobalLabel); fprintf(fp, " cmp %s, [edi] ; Are we smaller?\n", pszAddress); fprintf(fp, " jb nextAddr%ld ; Yes, go to the next address\n", dwGlobalLabel); fprintf(fp, " cmp %s, [edi+4] ; Are we bigger?\n", pszAddress); fprintf(fp, " jbe callRoutine%ld\n\n", dwGlobalLabel); fprintf(fp, "nextAddr%ld:\n", dwGlobalLabel); fprintf(fp, " add edi, 10h ; Next structure!\n"); fprintf(fp, " jmp short checkLoop%ld\n\n", dwGlobalLabel); fprintf(fp, "callRoutine%ld:\n", dwGlobalLabel); if (strcmp(pszAddress, "dx") != 0) fprintf(fp, " mov dx, %s ; Get our address\n", pszAddress); if (strcmp(pszTarget, "ax") != 0) fprintf(fp, " push ax ; Save this for later\n"); fprintf(fp, " push dx ; Save address\n"); fprintf(fp, " call ReadMemoryByte ; Standard read routine\n"); fprintf(fp, " pop dx ; Restore our address\n"); fprintf(fp, " inc dx ; Next byte, please\n"); fprintf(fp, " push ax ; Save returned byte\n"); fprintf(fp, " call ReadMemoryByte ; Standard read routine\n"); fprintf(fp, " xchg ah, al ; Swap for endian's sake\n"); fprintf(fp, " pop dx ; Restore LSB\n"); fprintf(fp, " mov dh, ah ; Our word is now in DX\n"); // DX Now has our data and our address is toast if (strcmp(pszTarget, "ax") != 0) { fprintf(fp, " pop ax ; Restore this\n"); if (strcmp(pszTarget, "dx") != 0) { fprintf(fp, " mov %s, dx ; Store our word\n", pszTarget); } } else fprintf(fp, " mov ax, dx\n"); if (strcmp(pszTarget, "ax") == 0) { fprintf(fp, " xchg ah, al\n"); } fprintf(fp, " jmp readExit%ld\n\n", dwGlobalLabel); fprintf(fp, "memoryRead%ld:\n", dwGlobalLabel); if (strlen(pszTarget) == 2) { fprintf(fp, " mov %s, [ebp + e%s]\n", pszTarget, pszAddress); if (strcmp(pszTarget, "ax") == 0) { fprintf(fp, " xchg ah, al\n"); } } else { fprintf(fp, " mov dx, [ebp + e%s]\n", pszAddress); fprintf(fp, " mov %s, dx\n", pszTarget); } fprintf(fp, "readExit%ld:\n", dwGlobalLabel); fprintf(fp, " mov edi, [cyclesRemaining]\n"); } else if (MZ80_C == bWhat) { fprintf(fp, " psMemRead = cpu.z80MemRead; /* Beginning of our handler */\n"); fprintf(fp, " while (psMemRead->lowAddr != 0xffffffff)\n"); fprintf(fp, " {\n"); fprintf(fp, " if ((%s >= psMemRead->lowAddr) && (%s <= psMemRead->highAddr))\n", pszAddress, pszAddress); fprintf(fp, " {\n"); fprintf(fp, " cpu.z80pc = (UINT32) pbPC - (UINT32) cpu.z80Base;\n"); fprintf(fp, " if (psMemRead->memoryCall)\n"); fprintf(fp, " {\n"); fprintf(fp, " %s = psMemRead->memoryCall(%s, psMemRead);\n", pszTarget, pszAddress); fprintf(fp, " %s |= (UINT32) ((UINT32) psMemRead->memoryCall(%s + 1, psMemRead) << 8);\n", pszTarget, pszAddress); fprintf(fp, " }\n"); fprintf(fp, " else\n"); fprintf(fp, " {\n"); fprintf(fp, " %s = *((UINT8 *) psMemRead->pUserArea + (%s - psMemRead->lowAddr));\n", pszTarget, pszAddress); fprintf(fp, " %s |= (UINT32) ((UINT32) *((UINT8 *) psMemRead->pUserArea + (%s - psMemRead->lowAddr + 1)) << 8);\n", pszTarget, pszAddress); fprintf(fp, " }\n"); fprintf(fp, " psMemRead = NULL;\n"); fprintf(fp, " break;\n"); fprintf(fp, " }\n"); fprintf(fp, " ++psMemRead;\n"); fprintf(fp, " }\n\n"); fprintf(fp, " if (psMemRead)\n"); fprintf(fp, " {\n"); fprintf(fp, " %s = cpu.z80Base[%s];\n", pszTarget, pszAddress); fprintf(fp, " %s |= (UINT32) ((UINT32) cpu.z80Base[%s + 1] << 8);\n", pszTarget, pszAddress); fprintf(fp, " }\n\n"); } else { assert(0); } dwGlobalLabel++;}void ReadValueFromIo(UINT8 *pszIoAddress, UINT8 *pszTarget){ if (MZ80_ASSEMBLY_X86 == bWhat) { fprintf(fp, " mov [cyclesRemaining], edi\n"); fprintf(fp, " mov edi, [_z80IoRead] ; Point to the read array\n\n", cpubasename); fprintf(fp, "checkLoop%ld:\n", dwGlobalLabel); fprintf(fp, " cmp [edi], word 0ffffh ; End of the list?\n"); fprintf(fp, " je ioRead%ld\n", dwGlobalLabel); fprintf(fp, " cmp %s, [edi] ; Are we smaller?\n", pszIoAddress); fprintf(fp, " jb nextAddr%ld ; Yes, go to the next address\n", dwGlobalLabel); fprintf(fp, " cmp %s, [edi+2] ; Are we bigger?\n", pszIoAddress); fprintf(fp, " jbe callRoutine%ld\n\n", dwGlobalLabel); fprintf(fp, "nextAddr%ld:\n", dwGlobalLabel); fprintf(fp, " add edi, 0ch ; Next structure!\n"); fprintf(fp, " jmp short checkLoop%ld\n\n", dwGlobalLabel); fprintf(fp, "callRoutine%ld:\n", dwGlobalLabel); if (strcmp(pszIoAddress, "dx") != 0) fprintf(fp, " mov dx, %s ; Get our address\n", pszIoAddress); fprintf(fp, " call ReadIOByte ; Standard read routine\n"); // Yes, these are intentionally reversed! if (strcmp(pszTarget, "al") == 0) fprintf(fp, " mov [_z80af], al ; Save our new accumulator\n"); else if (strcmp(pszTarget, "ah") == 0) fprintf(fp, " mov [_z80af + 1], ah ; Save our new flags\n"); else if (strcmp(pszTarget, "dl") == 0) fprintf(fp, " mov [_z80de], al ; Put it in E\n"); else if (strcmp(pszTarget, "dh") == 0) fprintf(fp, " mov [_z80de + 1], al ; Put it in D\n"); else if (strcmp(pszTarget, "*dl") == 0) fprintf(fp, " mov dl, al ; Put it in DL for later consumption\n"); else fprintf(fp, " mov %s, al ; Put our returned value here\n", pszTarget); // And are properly restored HERE: fprintf(fp, " mov ax, [_z80af] ; Get our AF back\n"); // Restore registers here... fprintf(fp, " jmp short readExit%ld\n\n", dwGlobalLabel); fprintf(fp, "ioRead%ld:\n", dwGlobalLabel); if (strcmp(pszTarget, "*dl") == 0) fprintf(fp, " mov dl, 0ffh ; An unreferenced read\n"); else fprintf(fp,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -