⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpu.asm

📁 nes游戏模拟器
💻 ASM
📖 第 1 页 / 共 4 页
字号:
	CPU_INX
	jmp _??
	
;********************************** INY ***************************************
; Increment the value in the Y register by one.
_C8::
	CPU_INY
	jmp _??

;********************************** JMP ***************************************
; Get the value to set the PC to and store that value in the PC register.

_4C::
	GET_ADDR_ABSOLUTE
	CPU_JMP bx
	jmp _??
	
_6C::
	GET_ADDR_INDIRECT
	CPU_JMP bx
	jmp _??

;********************************** JSR ***************************************
; Get the value to set the PC to and store that value in the PC register.
; Save the return address on the stack.
_20::
	GET_ADDR_ABSOLUTE
	CPU_JSR bx
	jmp _??

;********************************** LDA ***************************************
; For all the addressing modes except for immediate, get the address 
; to read memory from, then read memory and load it into the A register.
; For the immediate mode just load the byte into the A register.

_A9::
	GET_ADDR_IMMEDIATE
	CPU_LD? CPU.A, al
	jmp _??

_A5::
	GET_ADDR_ZEROPAGE
	READ_MEMORY ax
    CPU_LD? CPU.A, al
	jmp _??

_B5::
	GET_ADDR_ZEROPAGE_X
	READ_MEMORY ax
    CPU_LD? CPU.A, al
	jmp _??

_AD::
	GET_ADDR_ABSOLUTE
	READ_MEMORY bx
    CPU_LD? CPU.A, al
    jmp _??

_B9::
	GET_ADDR_ABSOLUTE_Y
	READ_MEMORY bx
    CPU_LD? CPU.A, al
    jmp _??

_BD::
	GET_ADDR_ABSOLUTE_X
	READ_MEMORY bx
    CPU_LD? CPU.A, al
    jmp _??

_A1::
	GET_ADDR_PREINDEXED
	READ_MEMORY bx
    CPU_LD? CPU.A, al
    jmp _??

_B1::
	GET_ADDR_POSTINDEXED
	READ_MEMORY bx
    CPU_LD? CPU.A, al
    jmp _??


;********************************** LDX ***************************************
; For all the addressing modes except for immediate, get the address 
; to read memory from, then read memory and load it into the X register.
; For the immediate mode just load the byte into the X register.

_A2::
	GET_ADDR_IMMEDIATE
	CPU_LD? CPU.X, al
	jmp _??

_A6:: 
	GET_ADDR_ZEROPAGE
	READ_MEMORY ax
    CPU_LD? CPU.X, al
	jmp _??

_B6::
	GET_ADDR_ZEROPAGE_Y
	READ_MEMORY ax
    CPU_LD? CPU.X, al
	jmp _??

_AE::
	GET_ADDR_ABSOLUTE
	READ_MEMORY bx
    CPU_LD? CPU.X, al
    jmp _??

_BE::
	GET_ADDR_ABSOLUTE_Y
	READ_MEMORY bx
    CPU_LD? CPU.X, al
    jmp _??

;********************************** LDY ***************************************
; For all the addressing modes except for immediate, get the address 
; to read memory from, then read memory and load it into the Y register.
; For the immediate mode just load the byte into the Y register.

_A0::
	GET_ADDR_IMMEDIATE
	CPU_LD? CPU.Y, al
	jmp _??

_A4:: 
	GET_ADDR_ZEROPAGE
	READ_MEMORY ax
    CPU_LD? CPU.Y, al
	jmp _??

_B4::
	GET_ADDR_ZEROPAGE_X
	READ_MEMORY ax
    CPU_LD? CPU.Y, al
	jmp _??

_AC::
	GET_ADDR_ABSOLUTE
	READ_MEMORY bx
    CPU_LD? CPU.Y, al
    jmp _??

_BC::
	GET_ADDR_ABSOLUTE_X
	READ_MEMORY bx
    CPU_LD? CPU.Y, al
    jmp _??

;********************************** LSR ***************************************
; Perform a logical shift right with most significant bit being filled
; with a zero and the least significant bit going into the carry.
_4A::
	mov ebx, OFFSET (CPU.A)
	CPU_LSR ebx
	jmp _??
	
_46::
	GET_ADDR_ZEROPAGE
	GET_MEMORY_POINTER ax
	mov ebx, eax
	CPU_LSR ebx
	jmp _??
	
_56::
	GET_ADDR_ZEROPAGE_X
	GET_MEMORY_POINTER ax
	mov ebx, eax
	CPU_LSR ebx
	jmp _??

_4E::
	GET_ADDR_ABSOLUTE
	GET_MEMORY_POINTER bx
	mov ebx, eax
	CPU_LSR ebx
	jmp _??

_5E::
	GET_ADDR_ABSOLUTE_X
	GET_MEMORY_POINTER bx
	mov ebx, eax
	CPU_LSR ebx
	jmp _??

;********************************** ORA ***************************************
; Perform a logical or operation on the memory and the A register
; storing the result in the A register.
_09::
	GET_ADDR_IMMEDIATE
	CPU_ORA al
	jmp _??

_05::
	GET_ADDR_ZEROPAGE
	GET_MEMORY_BYTE ax
	CPU_ORA al
	jmp _??

_15::
	GET_ADDR_ZEROPAGE_X
	GET_MEMORY_BYTE ax
	CPU_ORA al
	jmp _??

_0D::
	GET_ADDR_ABSOLUTE
	GET_MEMORY_BYTE bx
	CPU_ORA al
    jmp _??

_19::
	GET_ADDR_ABSOLUTE_Y
	GET_MEMORY_BYTE bx
	CPU_ORA al
    jmp _??

_1D::
	GET_ADDR_ABSOLUTE_X
	GET_MEMORY_BYTE bx
	CPU_ORA al
    jmp _??

_01::
	GET_ADDR_PREINDEXED
	GET_MEMORY_BYTE bx
	CPU_ORA al
    jmp _??

_11::
	GET_ADDR_POSTINDEXED
	GET_MEMORY_BYTE bx
	CPU_ORA al
    jmp _??

;********************************** PHA ***************************************
; Pushes the A register onto the stack.
_48::
	CPU_PHA
	jmp _??
	
;********************************** PHP ***************************************
; Pushes the flags register onto the stack.
_08::
	CPU_PHP
	jmp _??

;********************************** PLA ***************************************
; Pops the A register from the stack.
_68::
	CPU_PLA
	jmp _??

;********************************** PLP ***************************************
; Pops the flags register from the stack.
_28::
	CPU_PLP
	jmp _??

;********************************** ROL ***************************************
; Perform a rotate left with most significant bit going into the carry flag
; and the least significant bit coming from the carry flag.
_2A::
	mov ebx, OFFSET (CPU.A)
	CPU_ROL ebx
	jmp _??
	
_26::
	GET_ADDR_ZEROPAGE
	GET_MEMORY_POINTER ax
	mov ebx, eax
	CPU_ROL ebx
	jmp _??
	
_36::
	GET_ADDR_ZEROPAGE_X
	GET_MEMORY_POINTER ax
	mov ebx, eax
	CPU_ROL ebx
	jmp _??

_2E::
	GET_ADDR_ABSOLUTE
	GET_MEMORY_POINTER bx
	mov ebx, eax
	CPU_ROL ebx
	jmp _??

_3E::
	GET_ADDR_ABSOLUTE_X
	GET_MEMORY_POINTER bx
	mov ebx, eax
	CPU_ROL ebx
	jmp _??

;********************************** ROR ***************************************
; Perform a rotate right with least significant bit going into the carry flag
; and the most significant bit coming from the carry flag.
_6A::
	mov ebx, OFFSET (CPU.A)
	CPU_ROR ebx
	jmp _??
	
_66::
	GET_ADDR_ZEROPAGE
	GET_MEMORY_POINTER ax
	mov ebx, eax
	CPU_ROR ebx
	jmp _??
	
_76::
	GET_ADDR_ZEROPAGE_X
	GET_MEMORY_POINTER ax
	mov ebx, eax
	CPU_ROR ebx
	jmp _??

_6E::
	GET_ADDR_ABSOLUTE
	GET_MEMORY_POINTER bx
	mov ebx, eax
	CPU_ROR ebx
	jmp _??

_7E::
	GET_ADDR_ABSOLUTE_X
	GET_MEMORY_POINTER bx
	mov ebx, eax
	CPU_ROR ebx
	jmp _??

;********************************** RTI ***************************************
; Return from an interrupt.
_40::
	CPU_RTI
	jmp _??
	
;********************************** RTS ***************************************
; Return from an subroutine.
_60::
	CPU_RTS
	jmp _??

;********************************** SBC ***************************************
; Subtract memory from the accumulator and with the carry bit as well.

_E9::
	GET_ADDR_IMMEDIATE
	CPU_SBC al
	jmp _??

_E5::
	GET_ADDR_ZEROPAGE
	GET_MEMORY_BYTE ax
	CPU_SBC al
	jmp _??

_F5::
	GET_ADDR_ZEROPAGE_X
	GET_MEMORY_BYTE ax
	CPU_SBC al
	jmp _??

_ED::
	GET_ADDR_ABSOLUTE
	GET_MEMORY_BYTE bx
	CPU_SBC al
    jmp _??

_F9::
	GET_ADDR_ABSOLUTE_Y
	GET_MEMORY_BYTE bx
	CPU_SBC al
    jmp _??

_FD::
	GET_ADDR_ABSOLUTE_X
	GET_MEMORY_BYTE bx
	CPU_SBC al
    jmp _??

_E1::
	GET_ADDR_PREINDEXED
	GET_MEMORY_BYTE bx
	CPU_SBC al
    jmp _??

_F1::
	GET_ADDR_POSTINDEXED
	GET_MEMORY_BYTE bx
	CPU_SBC al
    jmp _??
    
;********************************** SEC ***************************************
; Set the carry flag.
_38::
	CPU_SEC
	jmp _??

;********************************** SED ***************************************
; Set the decimal flag.
_F8::
	CPU_SED
	jmp _??

;********************************** SEI ***************************************
; Set the interrupt flag.
_78::
	CPU_SEI
	jmp _??

;********************************** STA ***************************************
; For all the addressing modes, get the address to write the A register
; to, then store the A register into that memory address.

_85::
	GET_ADDR_ZEROPAGE
    CPU_ST? ax, CPU.A
	jmp _??

_95::
	GET_ADDR_ZEROPAGE_X
    CPU_ST? ax, CPU.A
	jmp _??

_8D::
	GET_ADDR_ABSOLUTE
    CPU_ST? bx, CPU.A
    jmp _??

_99::
	GET_ADDR_ABSOLUTE_Y
    CPU_ST? bx, CPU.A
    jmp _??

_9D::
	GET_ADDR_ABSOLUTE_X
    CPU_ST? bx, CPU.A
    jmp _??

_81::
	GET_ADDR_PREINDEXED
    CPU_ST? bx, CPU.A
    jmp _??

_91::
	GET_ADDR_POSTINDEXED
    CPU_ST? bx, CPU.A
    jmp _??


;********************************** STX ***************************************

; For all the addressing modes, get the address to write the X register
; to, then store the X register into that memory address.

_86::
	GET_ADDR_ZEROPAGE
    CPU_ST? ax, CPU.X
	jmp _??

_96::
	GET_ADDR_ZEROPAGE_Y
    CPU_ST? ax, CPU.X
	jmp _??

_8E::
	GET_ADDR_ABSOLUTE
    CPU_ST? bx, CPU.X
    jmp _??


;********************************** STY ***************************************

; For all the addressing modes, get the address to write the Y register
; to, then store the Y register into that memory address.

_84::
	GET_ADDR_ZEROPAGE
    CPU_ST? ax, CPU.Y
	jmp _??

_94::
	GET_ADDR_ZEROPAGE_X
    CPU_ST? ax, CPU.Y
	jmp _??

_8C::
	GET_ADDR_ABSOLUTE
    CPU_ST? bx, CPU.Y
    jmp _??

;********************************** TAX ***************************************
; Transfers the A register to the X register.
_AA::
	CPU_TAX
	jmp _??

;********************************** TAY ***************************************
; Transfers the A register to the YX register.
_A8::
	CPU_TAY
	jmp _??

;********************************** TSX ***************************************
; Transfers the S register to the X register.
_BA::
	CPU_TSX
	jmp _??

;********************************** TXA ***************************************
; Transfers the X register to the A register.
_8A::
	CPU_TXA
	jmp _??

;********************************** TXS ***************************************
; Transfers the X register to the S register.
_9A::
	CPU_TXS
	jmp _??

;********************************** TYA ***************************************
; Transfers the Y register to the A register.
_98::
	CPU_TYA
	jmp _??

_??::
    
	; When the instruction is finished me must subtract the
	; number of cycles the instruction takes and add the
	; number of bytes for the instruction to the PC.
	xor ax, ax
	mov ebx, dwOpcode
    mov al, [abyOpcodeCycles+ebx]
    sub CPU.byCycles, al
    mov al, [abyOpcodeBytes+ebx]
    add CPU.P, ax

	; In step mode, we execute one instruction and then exit
	; the function to let an external module control what
	; happens next. In run mode, we run until the cpu cycles
	; are less that zero and then let an external module 
	; control what happens next.
	.IF dwFlags == RUNCPU_STEP
		jmp RunCPU_End
	.ELSEIF dwFlags == RUNCPU_RUN
		cmp CPU.byCycles, 0
		jg RunCPU_RunAgain
	.ENDIF
	
    ; We're done now so pop all the flags and return.
RunCPU_End:
	popad
    ret

RunCPU ENDP

END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -