📄 make6502.c
字号:
if (0x0d == dwOpcode) Absolute(); else if (0x05 == dwOpcode) ZeroPage(); else if (0x09 == dwOpcode) Immediate("dl"); else if (0x1d == dwOpcode) AbsoluteX(); else if (0x19 == dwOpcode) AbsoluteY(); else if (0x01 == dwOpcode) IndirectX(); else if (0x11 == dwOpcode) IndirectY(); else if (0x15 == dwOpcode) ZeroPageX(); else assert(0); // Address is now in DX to read if (0x09 != dwOpcode) { if ((0x05 == dwOpcode || 0x15 == dwOpcode) && (bZeroDirect)) fprintf(fp, " mov dl, [ebp+edx] ; Get our zero page data\n"); else ReadMemoryByte("dl", "dx"); } // Let's do the OR with A, shall we? fprintf(fp, " mov dh, ah ; Get the flags\n"); fprintf(fp, " or al, dl ; OR In our value\n"); fprintf(fp, " lahf ; Get the flag settings\n"); fprintf(fp, " and ah, 0c0h ; Only sign and zero flag\n"); fprintf(fp, " and dh, 03fh ; Clear sign & zero flags\n"); fprintf(fp, " or ah, dh ; Merge the affected flags together\n"); FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// EOR Handlervoid EorHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; Eor\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); if (0x4d == dwOpcode) Absolute(); else if (0x45 == dwOpcode) ZeroPage(); else if (0x49 == dwOpcode) Immediate("dl"); else if (0x5d == dwOpcode) AbsoluteX(); else if (0x59 == dwOpcode) AbsoluteY(); else if (0x41 == dwOpcode) IndirectX(); else if (0x51 == dwOpcode) IndirectY(); else if (0x55 == dwOpcode) ZeroPageX(); else assert(0); // Address is now in DX to read if (0x49 != dwOpcode) { if ((0x45 == dwOpcode || 0x55 == dwOpcode) && (bZeroDirect)) fprintf(fp, " mov dl, [ebp+edx] ; Get our zero page data\n"); else ReadMemoryByte("dl", "dx"); } // Let's do the XOR with A, shall we? fprintf(fp, " mov dh, ah ; Get the flags\n"); fprintf(fp, " xor al, dl ; XOR In our value\n"); fprintf(fp, " lahf ; Get the flag settings\n"); fprintf(fp, " and ah, 0c0h ; Only sign and zero flag\n"); fprintf(fp, " and dh, 03fh ; Clear sign & zero flags\n"); fprintf(fp, " or ah, dh ; Merge the affected flags together\n"); FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// STA Handlervoid StaHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; STA\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); if (0x9d == dwOpcode) AbsoluteX(); else if (0x99 == dwOpcode) AbsoluteY(); else if (0x8d == dwOpcode) Absolute(); else if (0x85 == dwOpcode) ZeroPage(); else if (0x81 == dwOpcode) IndirectX(); else if (0x91 == dwOpcode) IndirectY(); else if (0x95 == dwOpcode) ZeroPageX(); else assert(0); if ((0x85 == dwOpcode || 0x95 == dwOpcode) && bZeroDirect) fprintf(fp, " mov [ebp+edx], al ; Store A\n"); else WriteMemoryByte("al", "dx"); FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// STX Handlervoid StxHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; STX\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); if (0x8e == dwOpcode) Absolute(); else if (0x86 == dwOpcode) ZeroPage(); else if (0x96 == dwOpcode) ZeroPageY(); else assert(0); if ((0x86 == dwOpcode || 0x96 == dwOpcode) && bZeroDirect) fprintf(fp, " mov [ebp+edx], bl ; Store X\n"); else WriteMemoryByte("bl", "dx"); FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// STY Handlervoid StyHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; STY\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); if (0x8c == dwOpcode) Absolute(); else if (0x84 == dwOpcode) ZeroPage(); else if (0x94 == dwOpcode) ZeroPageX(); else assert(0); if ((0x86 == dwOpcode || 0x96 == dwOpcode) && bZeroDirect) fprintf(fp, " mov [ebp+edx], cl ; Store Y\n"); else WriteMemoryByte("cl", "dx"); FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// LDA Handlervoid LdaHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; LDA\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); if (0xa9 == dwOpcode) Immediate("al"); else if (0xad == dwOpcode) Absolute(); else if (0xa5 == dwOpcode) ZeroPage(); else if (0xbd == dwOpcode) AbsoluteX(); else if (0xb9 == dwOpcode) AbsoluteY(); else if (0xa1 == dwOpcode) IndirectX(); else if (0xb1 == dwOpcode) IndirectY(); else if (0xb5 == dwOpcode) ZeroPageX(); else assert(0); if (0xa9 != dwOpcode) { if (bZeroDirect && (0xb5 == dwOpcode || 0xa5 == dwOpcode)) fprintf(fp, " mov al, [ebp+edx] ; Get our zero page byte\n"); else ReadMemoryByte("al", "dx"); } SetZeroSign("al"); // Set flags according to A FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// TXSvoid TxsHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; TXS\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); fprintf(fp, " mov [_%ss], bl ; X -> S\n", cpubasename); FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// TSXvoid TsxHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; TSX\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); fprintf(fp, " mov bl, [_%ss] ; S -> X\n", cpubasename); SetZeroSign("bl"); // Set flags according to X FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// TAXvoid TaxHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; TAX\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); fprintf(fp, " mov bl, al ; X = A\n"); SetZeroSign("bl"); // Set flags according to X FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// TXAvoid TxaHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; TXA\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); fprintf(fp, " mov al, bl ; A = X\n"); SetZeroSign("al"); // Set flags according to A FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// TAYvoid TayHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; TAY\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); fprintf(fp, " mov cl, al ; Y = A\n"); SetZeroSign("cl"); // Set flags according to Y FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// TYAvoid TyaHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; TYA\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); fprintf(fp, " mov al, cl ; A = Y\n"); SetZeroSign("al"); // Set flags according to A FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// Branch handlervoid BranchHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; Branch\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); // Put test case here if (0xd0 == dwOpcode) // BNE { fprintf(fp, " test ah, 40h ; Are we non-zero?\n"); fprintf(fp, " jz short takeJump%.2x ; Do it!\n", dwOpcode); } else if (0x30 == dwOpcode) // BMI { fprintf(fp, " test ah, 80h ; Are we minus?\n"); fprintf(fp, " jnz short takeJump%.2x ; Do it!\n", dwOpcode); } else if (0xb0 == dwOpcode) // BCS { fprintf(fp, " test ah, 1h ; Is carry set?\n"); fprintf(fp, " jnz short takeJump%.2x ; Do it!\n", dwOpcode); } else if (0x10 == dwOpcode) // BPL { fprintf(fp, " test ah, 80h ; Are we plus?\n"); fprintf(fp, " jz short takeJump%.2x ; Do it!\n", dwOpcode); } else if (0x70 == dwOpcode) // BVS { fprintf(fp, " test ah, 10h ; Overflow set?\n"); fprintf(fp, " jnz short takeJump%.2x ; Do it!\n", dwOpcode); } else if (0x50 == dwOpcode) // BVC { fprintf(fp, " test ah, 10h ; Overflow not set?\n"); fprintf(fp, " jz short takeJump%.2x ; Do it!\n", dwOpcode); } else if (0xf0 == dwOpcode) // BEQ { fprintf(fp, " test ah, 40h ; Non-zero set?\n"); fprintf(fp, " jnz short takeJump%.2x ; Do it!\n", dwOpcode); } else if (0x90 == dwOpcode) // BCC { fprintf(fp, " test ah, 1h ; Carry not set?\n"); fprintf(fp, " jz short takeJump%.2x ; Do it!\n", dwOpcode); } else assert(0); fprintf(fp, " inc esi ; Skip past the offset\n"); FetchAndExec(bTimingTable[dwOpcode] - 1); fprintf(fp, "takeJump%.2x:\n", dwOpcode); FetchInstructionByte(); // Go get our offset just in case fprintf(fp, " movsx dx, dl\n"); if (bBankswitch) { PageToPC(); fprintf(fp, " add si, dx\n"); fprintf(fp, " mov [_%spc], si\n", cpubasename); PCToPage(); } else { fprintf(fp, " sub esi, ebp\n"); fprintf(fp, " add si, dx\n"); fprintf(fp, " add esi, ebp\n"); } ++dwGlobalLabel; FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// JMPvoid JmpHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; JMP\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); FetchInstructionWord(); if (0x6c == dwOpcode) ReadMemoryWord(); if (bBankswitch) { fprintf(fp, " xor esi, esi\n"); fprintf(fp, " mov si, dx\n"); fprintf(fp, " mov [_%spc], si\n", cpubasename); PCToPage(); } else { fprintf(fp, " add edx, ebp ; Add in our base\n"); fprintf(fp, " mov esi, edx ; Put it here for execution\n"); } ++dwGlobalLabel; FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// Brkvoid BrkHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; BRK\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); if (bBankswitch) PageToPC(); else fprintf(fp, " sub esi, ebp ; Get our real program counter\n"); fprintf(fp, " inc si ; Move to the next position\n"); fprintf(fp, " or [_altFlags], byte 14h ; Indicate a break happened\n"); FlagsX86to6502(); fprintf(fp, " mov dl, [_%ss] ; Get our stack pointer\n", cpubasename); fprintf(fp, " add dx, 0ffh ; Stack area is 100-1ffh\n"); fprintf(fp, " mov [edx+ebp], si ; Store our PC\n"); fprintf(fp, " dec dx ; Back up for flag storage\n"); fprintf(fp, " mov [edx+ebp], ah ; Store our flags\n"); fprintf(fp, " dec dx ; Back up for flag storage\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -