📄 cpu.asm
字号:
; * STY. Opcodes 84, 94, 8C *
; ********************************************************************
CPU_ST? MACRO wAddress:REQ, byData:REQ
WRITE_MEMORY wAddress, byData
ENDM
; ********************************************************************
; * TAX. Opcode AA *
; ********************************************************************
CPU_TAX MACRO
; Transfer the A register to the X register.
mov al, CPU.A
mov CPU.X, al
test al, al
; Set/clear the sign and zero flags.
MODIFYFLAGS S, , Z,
ENDM
; ********************************************************************
; * TAY. Opcode A8 *
; ********************************************************************
CPU_TAY MACRO
; Transfer the A register to the Y register.
mov al, CPU.A
mov CPU.Y, al
test al, al
; Set/clear the sign and zero flags.
MODIFYFLAGS S, , Z,
ENDM
; ********************************************************************
; * TSX. Opcode BA *
; ********************************************************************
CPU_TSX MACRO
; Transfer the SP register to the X register.
mov al, CPU.S
mov CPU.X, al
test al, al
; Set/clear the sign and zero flags.
MODIFYFLAGS S, , Z,
ENDM
; ********************************************************************
; * TXA. Opcode 8A *
; ********************************************************************
CPU_TXA MACRO
; Transfer the X register to the A register.
mov al, CPU.X
mov CPU.A, al
test al, al
; Set/clear the sign and zero flags.
MODIFYFLAGS S, , Z,
ENDM
; ********************************************************************
; * TXS. Opcode 9A *
; ********************************************************************
CPU_TXS MACRO
; Transfer the X register to the SP register.
mov al, CPU.X
mov CPU.S, al
ENDM
; ********************************************************************
; * TYA. Opcode 98 *
; ********************************************************************
CPU_TYA MACRO
; Transfer the Y register to the A register.
mov al, CPU.Y
mov CPU.A, al
test al, al
; Set/clear the sign and zero flags.
MODIFYFLAGS S, , Z,
ENDM
;******************************************************************************
;* Name: _RunCPU
;* Desc: TBA
;******************************************************************************
RunCPU PROC C dwFlags : DWORD
LOCAL dwOpcode : DWORD ; Temporary storage for our opcode.
; Save all the registers before entering.
pushad
RunCPU_RunAgain:
; Get the opcode byte.
GET_MEMORY_BYTE CPU.P
; Save the opcode for later use and then jump to the
; correct opcode using the jump table defined above.
and eax, 000000FFh
mov dwOpcode, eax
jmp [adwOpcodeJumpTable+eax*4]
;********************************** ADC ***************************************
; Add memory to the accumulator with the carry bit as well.
_69::
GET_ADDR_IMMEDIATE
CPU_ADC al
jmp _??
_65::
GET_ADDR_ZEROPAGE
GET_MEMORY_BYTE ax
CPU_ADC al
jmp _??
_75::
GET_ADDR_ZEROPAGE_X
GET_MEMORY_BYTE ax
CPU_ADC al
jmp _??
_6D::
GET_ADDR_ABSOLUTE
GET_MEMORY_BYTE bx
CPU_ADC al
jmp _??
_79::
GET_ADDR_ABSOLUTE_Y
GET_MEMORY_BYTE bx
CPU_ADC al
jmp _??
_7D::
GET_ADDR_ABSOLUTE_X
GET_MEMORY_BYTE bx
CPU_ADC al
jmp _??
_61::
GET_ADDR_PREINDEXED
GET_MEMORY_BYTE bx
CPU_ADC al
jmp _??
_71::
GET_ADDR_POSTINDEXED
GET_MEMORY_BYTE bx
CPU_ADC al
jmp _??
;********************************** AND ***************************************
; For all the addressing modes except for immediate, get the address
; of the byte to AND A with, then use that address to get the byte
; and perform the AND operation with it. For the immediate mode,
; just AND the byte with the A register.
_29::
GET_ADDR_IMMEDIATE
CPU_AND al
jmp _??
_25::
GET_ADDR_ZEROPAGE
GET_MEMORY_BYTE ax
CPU_AND al
jmp _??
_35::
GET_ADDR_ZEROPAGE_X
GET_MEMORY_BYTE ax
CPU_AND al
jmp _??
_2D::
GET_ADDR_ABSOLUTE
GET_MEMORY_BYTE bx
CPU_AND al
jmp _??
_39::
GET_ADDR_ABSOLUTE_Y
GET_MEMORY_BYTE bx
CPU_AND al
jmp _??
_3D::
GET_ADDR_ABSOLUTE_X
GET_MEMORY_BYTE bx
CPU_AND al
jmp _??
_21::
GET_ADDR_PREINDEXED
GET_MEMORY_BYTE bx
CPU_AND al
jmp _??
_31::
GET_ADDR_POSTINDEXED
GET_MEMORY_BYTE bx
CPU_AND al
jmp _??
;********************************** ASL ***************************************
; Perform a logical shift left with least significant bit being filled
; with a zero and the most significant bit going into the carry.
_0A::
mov ebx, OFFSET (CPU.A)
CPU_ASL ebx
jmp _??
_06::
GET_ADDR_ZEROPAGE
GET_MEMORY_POINTER ax
mov ebx, eax
CPU_ASL ebx
jmp _??
_16::
GET_ADDR_ZEROPAGE_X
GET_MEMORY_POINTER ax
mov ebx, eax
CPU_ASL ebx
jmp _??
_0E::
GET_ADDR_ABSOLUTE
GET_MEMORY_POINTER bx
mov ebx, eax
CPU_ASL ebx
jmp _??
_1E::
GET_ADDR_ABSOLUTE_X
GET_MEMORY_POINTER bx
mov ebx, eax
CPU_ASL ebx
jmp _??
;********************************** BCC ***************************************
; Branches to a memory location if the carry flag is clear.
_90::
GET_ADDR_RELATIVE
CPU_BCC ax
jmp _??
;********************************** BCS ***************************************
; Branches to a memory location if the carry flag is set.
_B0::
GET_ADDR_RELATIVE
CPU_BCS ax
jmp _??
;********************************** BEQ ***************************************
; Branches to a memory location if the zero flag is set.
_F0::
GET_ADDR_RELATIVE
CPU_BEQ ax
jmp _??
;********************************** BIT ***************************************
; Ands the operand with the A register and transfers bit 7 and 6 to
; the flags register.
_24::
GET_ADDR_ZEROPAGE
GET_MEMORY_BYTE ax
CPU_BIT al
jmp _??
_2C::
GET_ADDR_ABSOLUTE
GET_MEMORY_BYTE bx
CPU_BIT al
jmp _??
;********************************** BMI ***************************************
; Branches to a memory location if the sign flag is set.
_30::
GET_ADDR_RELATIVE
CPU_BMI ax
jmp _??
;********************************** BNE ***************************************
; Branches to a memory location if the zero flag is clear.
_D0::
GET_ADDR_RELATIVE
CPU_BNE ax
jmp _??
;********************************** BPL ***************************************
; Branches to a memory location if the sign flag is clear.
_10::
GET_ADDR_RELATIVE
CPU_BPL ax
jmp _??
;********************************** BRK ***************************************
; Push the PC and flags onto the stack and then jump to the word
; address specified in the PRG-ROM at $FFFE
_00::
CPU_BRK
jmp _??
;********************************** BVC ***************************************
; Branches to a memory location if the overflow flag is clear.
_50::
GET_ADDR_RELATIVE
CPU_BVC ax
jmp _??
;********************************** BVS ***************************************
; Branches to a memory location if the overflow flag is set.
_70::
GET_ADDR_RELATIVE
CPU_BVS ax
jmp _??
;********************************** CLC ***************************************
; Clears the carry flag.
_18::
CPU_CLC
jmp _??
;********************************** CLD ***************************************
; Clears the decimal flag.
_D8::
CPU_CLD
jmp _??
;********************************** CLI ***************************************
; Clears the interrupt flag.
_58::
CPU_CLI
jmp _??
;********************************** CLV ***************************************
; Clears the overflow flag.
_B8::
CPU_CLV
jmp _??
;********************************** CMP ***************************************
; Compares memory with the A register by using subtraction.
_C9::
GET_ADDR_IMMEDIATE
CPU_CP? CPU.A, al
jmp _??
_C5::
GET_ADDR_ZEROPAGE
GET_MEMORY_BYTE ax
CPU_CP? CPU.A, al
jmp _??
_D5::
GET_ADDR_ZEROPAGE_X
GET_MEMORY_BYTE ax
CPU_CP? CPU.A, al
jmp _??
_CD::
GET_ADDR_ABSOLUTE
GET_MEMORY_BYTE bx
CPU_CP? CPU.A, al
jmp _??
_D9::
GET_ADDR_ABSOLUTE_Y
GET_MEMORY_BYTE bx
CPU_CP? CPU.A, al
jmp _??
_DD::
GET_ADDR_ABSOLUTE_X
GET_MEMORY_BYTE bx
CPU_CP? CPU.A, al
jmp _??
_C1::
GET_ADDR_PREINDEXED
GET_MEMORY_BYTE bx
CPU_CP? CPU.A, al
jmp _??
_D1::
GET_ADDR_POSTINDEXED
GET_MEMORY_BYTE bx
CPU_CP? CPU.A, al
jmp _??
;********************************** CPX ***************************************
; Compares memory with the X register by using subtraction.
_E0::
GET_ADDR_IMMEDIATE
CPU_CP? CPU.X, al
jmp _??
_E4::
GET_ADDR_ZEROPAGE
GET_MEMORY_BYTE ax
CPU_CP? CPU.X, al
jmp _??
_EC::
GET_ADDR_ABSOLUTE
GET_MEMORY_BYTE bx
CPU_CP? CPU.X, al
jmp _??
;********************************** CPY ***************************************
; Compares memory with the Y register by using subtraction.
_C0::
GET_ADDR_IMMEDIATE
CPU_CP? CPU.Y, al
jmp _??
_C4::
GET_ADDR_ZEROPAGE
GET_MEMORY_BYTE ax
CPU_CP? CPU.Y, al
jmp _??
_CC::
GET_ADDR_ABSOLUTE
GET_MEMORY_BYTE bx
CPU_CP? CPU.Y, al
jmp _??
;********************************** DEC ***************************************
; Decrement the value in memory by 1.
_C6::
GET_ADDR_ZEROPAGE
GET_MEMORY_POINTER ax
mov ebx, eax
CPU_DEC ebx
jmp _??
_D6::
GET_ADDR_ZEROPAGE_X
GET_MEMORY_POINTER ax
mov ebx, eax
CPU_DEC ebx
jmp _??
_CE::
GET_ADDR_ABSOLUTE
GET_MEMORY_POINTER bx
mov ebx, eax
CPU_DEC ebx
jmp _??
_DE::
GET_ADDR_ABSOLUTE_X
GET_MEMORY_POINTER bx
mov ebx, eax
CPU_DEC ebx
jmp _??
;********************************** DEX ***************************************
; Decrement the value in the X register by one.
_CA::
CPU_DEX
jmp _??
;********************************** DEY ***************************************
; Decrement the value in the Y register by one.
_88::
CPU_DEY
jmp _??
;********************************** EOR ***************************************
; Perform a logical exclusive or operation on the memory and the A register
; storing the result in the A register.
_49::
GET_ADDR_IMMEDIATE
CPU_EOR al
jmp _??
_45::
GET_ADDR_ZEROPAGE
GET_MEMORY_BYTE ax
CPU_EOR al
jmp _??
_55::
GET_ADDR_ZEROPAGE_X
GET_MEMORY_BYTE ax
CPU_EOR al
jmp _??
_4D::
GET_ADDR_ABSOLUTE
GET_MEMORY_BYTE bx
CPU_EOR al
jmp _??
_59::
GET_ADDR_ABSOLUTE_Y
GET_MEMORY_BYTE bx
CPU_EOR al
jmp _??
_5D::
GET_ADDR_ABSOLUTE_X
GET_MEMORY_BYTE bx
CPU_EOR al
jmp _??
_41::
GET_ADDR_PREINDEXED
GET_MEMORY_BYTE bx
CPU_EOR al
jmp _??
_51::
GET_ADDR_POSTINDEXED
GET_MEMORY_BYTE bx
CPU_EOR al
jmp _??
;********************************** INC ***************************************
; Increment the value in memory by 1.
_E6::
GET_ADDR_ZEROPAGE
GET_MEMORY_POINTER ax
mov ebx, eax
CPU_INC ebx
jmp _??
_F6::
GET_ADDR_ZEROPAGE_X
GET_MEMORY_POINTER ax
mov ebx, eax
CPU_INC ebx
jmp _??
_EE::
GET_ADDR_ABSOLUTE
GET_MEMORY_POINTER bx
mov ebx, eax
CPU_INC ebx
jmp _??
_FE::
GET_ADDR_ABSOLUTE_X
GET_MEMORY_POINTER bx
mov ebx, eax
CPU_INC ebx
jmp _??
;********************************** INX ***************************************
; Increment the value in the X register by one.
_E8::
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -