📄 make6502.c
字号:
void Immediate(UINT8 *pszRegister){ fprintf(fp, " mov %s, [esi] ; Get our next byte\n", pszRegister); fprintf(fp, " inc esi ; Increment to our next byte\n");}// LDX Handlervoid LdxHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; LDX\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); if (0xa2 == dwOpcode) Immediate("bl"); else if (0xae == dwOpcode) Absolute(); else if (0xa6 == dwOpcode) ZeroPage(); else if (0xbe == dwOpcode) AbsoluteY(); else if (0xb6 == dwOpcode) ZeroPageY(); else assert(0); if (0xa2 != dwOpcode) { if ((0xa6 != dwOpcode && 0xb6 != dwOpcode) || (FALSE == bZeroDirect)) ReadMemoryByte("bl", "dx"); else fprintf(fp, " mov bl, [ebp + edx] ; Zero page!\n"); } SetZeroSign("bl"); FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// LDY Handlervoid LdyHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; LDY\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); if (0xa0 == dwOpcode) Immediate("cl"); else if (0xac == dwOpcode) Absolute(); else if (0xa4 == dwOpcode) ZeroPage(); else if (0xbc == dwOpcode) AbsoluteX(); else if (0xb4 == dwOpcode) ZeroPageX(); else assert(0); if (0xa0 != dwOpcode) { if ((0xa4 != dwOpcode && 0xb4 != dwOpcode) || (FALSE == bZeroDirect)) ReadMemoryByte("cl", "dx"); else fprintf(fp, " mov cl, [ebp + edx] ; Zero page!\n"); } SetZeroSign("cl"); FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// DEC Handlervoid DecxyHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); if (0x88 == dwOpcode) fprintf(fp, "; DEY\n"); else fprintf(fp, "; DEX\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); if (0x88 == dwOpcode) DecSetZeroSign("cl"); // Decrement & do Y else if (0xca == dwOpcode) DecSetZeroSign("bl"); // Decrement & do X else assert(0); FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// DeaIna Handlervoid DeaInaHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); if (0x3a == dwOpcode) fprintf(fp, "; DEA\n"); else fprintf(fp, "; INA\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); if (0x3a == dwOpcode) DecSetZeroSign("al"); // Decrement else if (0x1a == dwOpcode) DecSetZeroSign("al"); // Decrement else assert(0); FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// INC Handlervoid IncxyHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); if (0xc8 == dwOpcode) fprintf(fp, "; INY\n"); else fprintf(fp, "; INX\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); if (0xc8 == dwOpcode) IncSetZeroSign("cl"); // Increment & do Y else if (0xe8 == dwOpcode) IncSetZeroSign("bl"); // Increment & do X else assert(0); FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// INC Handlervoid IncHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; INC\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); if (0xee == dwOpcode || 0xfe == dwOpcode) { if (0xee == dwOpcode) Absolute(); else AbsoluteX(); fprintf(fp, " push edx ; Save this for later\n"); ReadMemoryByte("dl", "dx"); fprintf(fp, " mov bh, dl ; Save the data we just got\n"); } else if (0xe6 == dwOpcode || 0xf6 == dwOpcode) { if (0xe6 == dwOpcode) ZeroPage(); else ZeroPageX(); if (FALSE == bZeroDirect) { fprintf(fp, " push edx ; Save this for later\n"); ReadMemoryByte("dl", "dx"); fprintf(fp, " mov bh, dl ; Save the data we just got\n"); } } else assert(0); // Handle the increment fprintf(fp, " mov ch, ah ; Save flags\n"); fprintf(fp, " and ch, 03fh ; No sign or zero flags\n"); if (((0xe6 == dwOpcode) || (0xf6 == dwOpcode)) && (bZeroDirect)) fprintf(fp, " inc byte [edx+ebp] ; Increment our zero page stuff\n"); else fprintf(fp, " inc bh ; Increment!\n"); fprintf(fp, " lahf\n"); fprintf(fp, " and ah, 0c0h ; Only sign & zero flags\n"); fprintf(fp, " or ah, ch ; Merge the two flags together\n"); if ( (0xee == dwOpcode || 0xfe == dwOpcode) || (((0xe6 == dwOpcode) || (0xf6 == dwOpcode)) && (FALSE == bZeroDirect)) ) { fprintf(fp, " pop edx ; Restore our address\n"); WriteMemoryByte("bh", "dx"); } fprintf(fp, " xor bh, bh ; Zero this so we don't totally screw things up\n"); fprintf(fp, " xor ch, ch ; Zero this as well\n"); FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// DEC Handlervoid DecHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; DEC\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); if (0xce == dwOpcode || 0xde == dwOpcode) { if (0xce == dwOpcode) Absolute(); else AbsoluteX(); fprintf(fp, " push edx ; Save this for later\n"); ReadMemoryByte("dl", "dx"); fprintf(fp, " mov bh, dl ; Save the data we just got\n"); } else if (0xc6 == dwOpcode || 0xd6 == dwOpcode) { if (0xc6 == dwOpcode) ZeroPage(); else ZeroPageX(); if (FALSE == bZeroDirect) { fprintf(fp, " push edx ; Save this for later\n"); ReadMemoryByte("dl", "dx"); fprintf(fp, " mov bh, dl ; Save the data we just got\n"); } } else assert(0); // Handle the increment fprintf(fp, " mov ch, ah ; Save flags\n"); fprintf(fp, " and ch, 03fh ; No sign or zero flags\n"); if (((0xc6 == dwOpcode) || (0xd6 == dwOpcode)) && (bZeroDirect)) fprintf(fp, " dec byte [edx+ebp] ; Increment our zero page stuff\n"); else fprintf(fp, " dec bh ; Decrement!\n"); fprintf(fp, " lahf\n"); fprintf(fp, " and ah, 0c0h ; Only sign & zero flags\n"); fprintf(fp, " or ah, ch ; Merge the two flags together\n"); if ( (0xce == dwOpcode || 0xde == dwOpcode) || (((0xc6 == dwOpcode) || (0xd6 == dwOpcode)) && (FALSE == bZeroDirect)) ) { fprintf(fp, " pop edx ; Restore our address\n"); WriteMemoryByte("bh", "dx"); } fprintf(fp, " xor bh, bh ; Zero this so we don't totally screw things up\n"); fprintf(fp, " xor ch, ch ; Zero this as well\n"); FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// AND Handlervoid AndHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; AND\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); if (0x2d == dwOpcode) Absolute(); else if (0x25 == dwOpcode) ZeroPage(); else if (0x29 == dwOpcode) Immediate("dl"); else if (0x3d == dwOpcode) AbsoluteX(); else if (0x39 == dwOpcode) AbsoluteY(); else if (0x21 == dwOpcode) IndirectX(); else if (0x31 == dwOpcode) IndirectY(); else if (0x35 == dwOpcode) ZeroPageX(); else assert(0); if ((bZeroDirect) && ((0x25 == dwOpcode) || (0x35 == dwOpcode))) fprintf(fp, " and al, [ebp+edx] ; And it!\n"); else { if (0x29 != dwOpcode) ReadMemoryByte("dl", "dx"); fprintf(fp, " and al, dl ; And it\n"); } fprintf(fp, " mov bh, ah ; Save flags for later\n"); fprintf(fp, " lahf ; Get the flags\n"); fprintf(fp, " and ah, 0c0h ; Only sign and zero flag\n"); fprintf(fp, " and bh, 03fh ; Kill sign and zero flag\n"); fprintf(fp, " or ah, bh ; Get our original (other) flags back\n"); fprintf(fp, " xor bh, bh ; Kill it so we don't screw X up for later\n"); FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// ASL Handlervoid AslHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; Asl\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); if (0x0a == dwOpcode) { fprintf(fp, " sahf ; Restore flags\n"); fprintf(fp, " mov dl, ah ; Store our original flags\n"); fprintf(fp, " shl al, 1 ; Shift left by 1\n"); fprintf(fp, " lahf ; Load the flags back in\n"); fprintf(fp, " and dl, 03eh ; No carry, zero, or sign\n"); fprintf(fp, " and ah, 0c1h ; Only carry, zero and sign\n"); fprintf(fp, " or ah, dl ; Or it into our flags\n"); } else if (0x0e == dwOpcode) // Absolute Absolute(); else if (0x06 == dwOpcode) // Zero page ZeroPage(); else if (0x1e == dwOpcode) // Absolute X AbsoluteX(); else if (0x16 == dwOpcode) // Zero page X ZeroPageX(); else assert(0); // We have the address. Now fetch the info! if (0x0a != dwOpcode) { // Read the data if (((0x16 == dwOpcode) || (0x06 == dwOpcode)) && bZeroDirect) fprintf(fp, " mov bh, [ebp+edx] ; Get our zero page stuff\n"); else { fprintf(fp, " push edx ; Save our address\n"); ReadMemoryByte("bh", "dx"); fprintf(fp, " pop edx ; Restore our address\n"); } // Process the data fprintf(fp, " sahf ; Restore flags\n"); fprintf(fp, " mov ch, ah ; Store our original flags\n"); fprintf(fp, " shl bh, 1 ; Shift left by 1\n"); fprintf(fp, " lahf ; Load the flags back in\n"); fprintf(fp, " and ch, 03eh ; No carry, zero, or sign\n"); fprintf(fp, " and ah, 0c1h ; Only carry, zero and sign\n"); fprintf(fp, " or ah, ch ; Or it into our flags\n"); fprintf(fp, " xor ch, ch ; Clear it!\n"); // Write the data back if (((0x16 == dwOpcode) || (0x06 == dwOpcode)) && bZeroDirect) fprintf(fp, " mov [ebp+edx], bh ; Set our zero page byte\n"); else WriteMemoryByte("bh", "dx"); fprintf(fp, " xor bh, bh ; Prevent us from being hosed later\n"); } FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// LSR Handlervoid LsrHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; Lsr\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode); if (0x4a == dwOpcode) { fprintf(fp, " sahf ; Restore flags\n"); fprintf(fp, " mov dl, ah ; Store our original flags\n"); fprintf(fp, " shr al, 1 ; Shift right by 1\n"); fprintf(fp, " lahf ; Load the flags back in\n"); fprintf(fp, " and dl, 03eh ; No carry, zero, or sign\n"); fprintf(fp, " and ah, 0c1h ; Only carry, zero and sign\n"); fprintf(fp, " or ah, dl ; Or it into our flags\n"); } else if (0x4e == dwOpcode) // Absolute Absolute(); else if (0x46 == dwOpcode) // Zero page ZeroPage(); else if (0x5e == dwOpcode) // Absolute X AbsoluteX(); else if (0x56 == dwOpcode) // Zero page X ZeroPageX(); else assert(0); // We have the address. Now fetch the info! if (0x4a != dwOpcode) { // Read the data fprintf(fp, " push edx ; Save our address away\n"); if (((0x56 == dwOpcode) || (0x46 == dwOpcode)) && bZeroDirect) fprintf(fp, " mov bh, [ebp+edx] ; Get our zero page stuff\n"); else ReadMemoryByte("bh", "dx"); // Process the data fprintf(fp, " sahf ; Restore flags\n"); fprintf(fp, " mov ch, ah ; Store our original flags\n"); fprintf(fp, " shr bh, 1 ; Shift right by 1\n"); fprintf(fp, " lahf ; Load the flags back in\n"); fprintf(fp, " and ch, 03eh ; No carry, zero, or sign\n"); fprintf(fp, " and ah, 0c1h ; Only carry, zero and sign\n"); fprintf(fp, " or ah, ch ; Or it into our flags\n"); fprintf(fp, " xor ch, ch ; Clear it!\n"); // Write the data back fprintf(fp, " pop edx ; Restore our address\n"); if (((0x56 == dwOpcode) || (0x46 == dwOpcode)) && bZeroDirect) fprintf(fp, " mov [ebp+edx], bh ; Set our zero page byte\n"); else WriteMemoryByte("bh", "dx"); fprintf(fp, " xor bh, bh ; Zero the upper part so we don't host X!\n"); } FetchAndExec(bTimingTable[dwOpcode]); ProcEnd(string);}// ORA Handlervoid OraHandler(UINT16 dwOpcode){ fprintf(fp, ";\n"); fprintf(fp, "; Ora\n"); fprintf(fp, ";\n"); sprintf(string, "RegInst%.2x", dwOpcode); ProcBegin(string, dwOpcode);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -