📄 emu65816.asm
字号:
shortcall macro lowbyte, highbyte ; Add 1 less than normal to PC before using macro
pushbyte dh
pushbyte dl
mov dl, lowbyte
mov dh, highbyte
endm vectorcall
longcall_ebx macro ; Add 1 less to PC before using macro
mov ebp, ebx
mov ebx, edx
and ebp, 00FFFFFFh
shr ebx, 8
pushbyte bh
pushbyte bl
pushbyte dl
mov edx, ebp
endm vectorcall
; EBX: Pointer to data of 65816 operand
; EDX: PC ESI: cycles left CL: Flags
; EAX: Temporary, not used by trapandread
nzflag_xfer macro
setz ch
sets ah
shl ch, 1
shl ah, 7
or cl, ch
or cl, ah
endm
nzcflag_xfer_sub macro ; complements carry first
; set complement of carry (cmp and sub differ on x86 machines)
setnc al
setz ch
sets ah
shl ch, 1
shl ah, 7
or cl, ch
or cl, al
or cl, ah
endm
adc8 macro imm
local dobcd, notoverflow, notoverflowbcd, alldone
ifb <imm>
trapandread8 ebx
endif
mov ch, cl ; ch==cl==P
movzx eax, byte [_reg.A]
and cl, 0FFh-FOVERFLOW-FZERO-FCARRY-FNEGATIVE ; clear affected flags
test cl, FDECIMAL
jnz dobcd
shr ch, 1 ; get 65816 carry flag
adc al, bl ; add and save accumulator
mov byte [_reg.A], al
setc ch ; get carry flag state 1=carry.
; would use adc cl,0 but that changes the overflow flag
jno notoverflow
or cl, FOVERFLOW
notoverflow:
or cl, ch ; save carry flag state
or cl, [nz_8bit + eax] ; get zero/negative flags
jmp alldone
dobcd:
shr ch,1 ; Move 6502 Carry to 80x86's
adc al, bl
daa ; change al according to BCD adjust rules
mov byte [_reg.A], al
setc ch ; get carry flag state 1=carry.
; would use adc cl,0 but that changes the overflow flag
jno notoverflow
or cl, FOVERFLOW
notoverflowbcd:
or cl, ch ; save carry flag state
or cl, [nz_8bit + eax] ; get zero/negative flags
alldone:
endm adc8
adc16 macro imm
local dobcd, notoverflow, notoverflowbcd, alldone
ifb <imm>
trapandread16 ebx
endif
mov ch, cl ; ch==cl==P
mov eax, dword [_reg.A]
and cl, 0FFh-FOVERFLOW-FZERO-FCARRY-FNEGATIVE ; clear affected flags
test cl, FDECIMAL
jnz dobcd
shr ch, 1 ; get 65816 carry flag
adc ax, bx ; add and save accumulator
mov dword [_reg.A], eax
setz al
setc ch ; get carry flag state 1=carry.
; would use adc cl,0 but that changes the overflow flag
sets ah
jno notoverflow
or cl, FOVERFLOW
notoverflow:
shl ah, 7
or cl, ch ; save carry flag state
shl al, 1
or cl, ah
or cl, al
jmp alldone
dobcd:
shr ch, 1 ; get 65816 carry flag
adc al, bl ; eax=65816 A; Do one byte at a time with BCD
daa ; adjust for BCD
mov byte [_reg.A], al
adc ah, bh
mov al, ah
daa
mov byte [_reg.A + 1], al
setc ch ; get carry flag state 1=carry.
setz al
sets ah
jno notoverflow
or cl, FOVERFLOW
notoverflowbcd:
or dword [_reg.A], 0 ; set nz flags
or cl, ch ; save carry flag state
shl ah, 7
shl al, 1
or cl, ah
or cl, al
alldone:
endm adc16
and8 macro imm ; and memory with A
ifb <imm>
trapandread8 ebx
endif
movzx eax, byte [_reg.A]
and cl, 0FFh-FZERO-FNEGATIVE ; clear affected flags
and al, bl
mov byte [_reg.A], al
or cl, [nz_8bit + eax]
endm and8
and16 macro imm
ifb <imm>
trapandread16 ebx
endif
mov eax, dword [_reg.A]
and cl, 0FFh-FZERO-FNEGATIVE ; clear affected flags
and ax, bx
mov dword [_reg.A], eax
nzflag_xfer
endm and16
shl8 macro
mov edi, ebx ; save pointer to data
trapandread8 ebx
and cl, 0FFh-FZERO-FNEGATIVE-FCARRY; clear affected flags
test bl, 80h
setnz ch
movzx ebx, bl
or cl, ch ; left bit into carry
shl bl, 1
or cl, [nz_8bit + ebx]
trapandwrite8 edi, bl
endm shl8
shl16 macro
mov edi, ebx ; save pointer to data
trapandread16 ebx
and ebx, 0000FFFFh
and cl, 0FFh-FZERO-FNEGATIVE-FCARRY; clear affected flags
test bh, 80h
setnz ch
or cl, ch ; left bit into carry
shl bx, 1
nzflag_xfer
trapandwrite16 edi, bl, bh
endm shl16
shl8_a macro
movzx ebx, byte [_reg.A]
and cl, 0FFh-FZERO-FNEGATIVE-FCARRY; clear affected flags
shl bl, 1
jnc @F
or cl, FCARRY ; left bit into carry
@@: mov byte [_reg.A], bl
or cl, [nz_8bit + ebx]
endm shl8
shl16_a macro
mov ebx, dword [_reg.A]
and cl, 0FFh-FZERO-FNEGATIVE-FCARRY; clear affected flags
shl bx, 1
setz al
sets ch
jnc @F
or cl, FCARRY ; left bit into carry
@@: shl ch, 7
shl al, 1
or cl, ch
mov dword [_reg.A], ebx
or cl, al
endm shl16
bit8 macro imm
local notzero
ifb <imm>
trapandread8 ebx ; read memory at [ebx] into ebx
endif
mov eax, ebx ; save memory
ifb <imm>
and cl, 0FFh-FZERO-FNEGATIVE-FOVERFLOW ; clear affected flags
else
and cl, 0FFh-FZERO ; clear affected flags
endif
and bl, byte [_reg.A]
jnz notzero
or cl, FZERO ; zero flag
notzero:
ifb <imm>
and al, 80h+40h ; get flags
or cl, al ; transfer
endif
endm bit8
bit16 macro imm
local notzero
ifb <imm>
trapandread16 ebx ; read memory at [ebx] into ebx
endif
mov eax, ebx ; save memory
ifb <imm>
and cl, 0FFh-FZERO-FNEGATIVE-FOVERFLOW ; clear affected flags
else
and cl, 0FFh-FZERO ; clear affected flags
endif
and bx, word [_reg.A]
jnz notzero
or cl, FZERO ; zero flag
notzero:
ifb <imm>
and ah, 80h+40h ; get flags
or cl, ah ; transfer
endif
endm bit16
cmp8 macro imm
ifb <imm>
trapandread8 ebx ; read memory byte
endif
and cl, 0FFh-FNEGATIVE-FZERO-FCARRY ; clear flags affected
cmp byte [_reg.A], bl ; compare operand with A
nzcflag_xfer_sub
endm cmp8
cmp16 macro imm
ifb <imm>
trapandread16 ebx ; read memory word
endif
and cl, 0FFh-FNEGATIVE-FZERO-FCARRY ; clear flags affected
cmp word [_reg.A], bx ; compare operand with A
nzcflag_xfer_sub
endm cmp16
cpx8 macro imm
ifb <imm>
trapandread8 ebx ; read memory byte
endif
and cl, 0FFh-FNEGATIVE-FZERO-FCARRY ; clear flags affected
cmp byte [_reg.X], bl ; compare operand with A
nzcflag_xfer_sub
endm cpx8
cpx16 macro imm
ifb <imm>
trapandread16 ebx ; read memory word
endif
and cl, 0FFh-FNEGATIVE-FZERO-FCARRY ; clear flags affected
cmp word [_reg.X], bx ; compare operand with A
nzcflag_xfer_sub
endm cpx16
cpy8 macro imm
ifb <imm>
trapandread8 ebx ; read memory byte
endif
and cl, 0FFh-FNEGATIVE-FZERO-FCARRY ; clear flags affected
cmp byte [_reg.Y], bl ; compare operand with A
; set complement of carry (cmp uses a sub, which differs on x86 machines)
nzcflag_xfer_sub
endm cpy8
cpy16 macro imm
ifb <imm>
trapandread16 ebx ; read memory word
endif
and cl, 0FFh-FNEGATIVE-FZERO-FCARRY ; clear flags affected
cmp word [_reg.Y], bx ; compare operand with A
nzcflag_xfer_sub
endm cpy16
dec8 macro
mov edi, ebx ; remember address
trapandread8 ebx ; read memory byte
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
movzx ebx, bl
dec bl
or cl, [nz_8bit + ebx]
trapandwrite8 edi, bl
endm dec8
dec16 macro
mov edi, ebx ; remember address
trapandread16 ebx ; read memory byte
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
dec bx
nzflag_xfer
trapandwrite16 edi, bl, bh
endm dec16
dex8 macro
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
dec byte [_reg.X]
nzflag_xfer
endm dex8
dex16 macro
mov ebx, dword [_reg.X]
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
;dec word [_reg.X]
dec bx
mov byte [_reg.X], bl
mov byte [_reg.X+1], bh
nzflag_xfer
endm dex16
dey8 macro
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
dec byte [_reg.Y]
nzflag_xfer
endm dey8
dey16 macro
mov ebx, dword [_reg.Y]
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
;dec word [_reg.Y]
dec bx
mov byte [_reg.Y], bl
mov byte [_reg.Y+1], bh
nzflag_xfer
endm dey16
deca8 macro
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
dec byte [_reg.A]
nzflag_xfer
endm dex8
deca16 macro
mov ebx, dword [_reg.A]
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
;dec word [_reg.A]
dec bx
mov byte [_reg.A], bl
mov byte [_reg.A+1], bh
nzflag_xfer
endm deca16
xor8 macro imm ; XOR with A
ifb <imm>
trapandread8 ebx
endif
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
xor byte [_reg.A], bl
nzflag_xfer
endm xor8
xor16 macro imm ; XOR with A
ifb <imm>
trapandread16 ebx
endif
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
xor word [_reg.A], bx
nzflag_xfer
endm xor16
inc8 macro
mov edi, ebx ; remember address
trapandread8 ebx ; read memory byte
movzx ebx, bl
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
inc bl
or cl, [nz_8bit + ebx]
trapandwrite8 edi, bl
endm inc8
inc16 macro
mov edi, ebx ; remember address
trapandread16 ebx ; read memory byte
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
inc bx
nzflag_xfer
trapandwrite16 edi, bl, bh
endm inc16
inx8 macro
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
inc byte [_reg.X]
nzflag_xfer
endm inx8
inx16 macro
mov ebx, dword [_reg.X]
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
;inc word [_reg.X]
inc bx
mov byte [_reg.X], bl
nzflag_xfer
mov byte [_reg.X+1], bh
endm inx16
iny8 macro
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
inc byte [_reg.Y]
nzflag_xfer
endm iny8
iny16 macro
mov ebx, dword [_reg.Y]
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
;inc word [_reg.Y]
inc bx
mov byte [_reg.Y], bl
nzflag_xfer
mov byte [_reg.Y+1], bh
endm iny16
inca8 macro
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
inc byte [_reg.A]
nzflag_xfer
endm inca8
inca16 macro
mov ebx, dword [_reg.A]
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
;inc word [_reg.A]
inc bx
mov byte [_reg.A], bl
nzflag_xfer
mov byte [_reg.A+1], bh
endm inca16
lda8 macro imm
ifb <imm>
trapandread8 ebx ; read memory byte
endif
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
movzx ebx, bl
mov byte [_reg.A], bl
or cl, [nz_8bit + ebx]
endm lda8
lda16 macro imm
local notnegative, notzero
ifb <imm>
trapandread16 ebx ; read memory byte
endif
mov byte [_reg.A], bl
and ebx, 0000FFFFh
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
mov byte [_reg.A + 1], bh
test bh, 80h
jz notnegative
or cl, FNEGATIVE
notnegative:
test ebx, ebx
jnz notzero
or cl, FZERO
notzero:
endm lda16
ldx8 macro imm
ifb <imm>
trapandread8 ebx
endif
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
movzx ebx, bl
mov byte [_reg.X], bl
or cl, [nz_8bit + ebx]
endm ldx8
ldx16 macro imm
local notnegative, notzero
ifb <imm>
trapandread16 ebx
endif
mov byte [_reg.X], bl
and ebx, 0000FFFFh
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
mov byte [_reg.X + 1], bh
test bh, 80h
jz notnegative
or cl, FNEGATIVE
notnegative:
test ebx, ebx
jnz notzero
or cl, FZERO
notzero:
endm ldx16
ldy8 macro imm
ifb <imm>
trapandread8 ebx
endif
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
movzx ebx, bl
mov byte [_reg.Y], bl
or cl, [nz_8bit + ebx]
endm ldy8
ldy16 macro imm
local notnegative, notzero
ifb <imm>
trapandread16 ebx
endif
mov byte [_reg.Y], bl
and ebx, 0000FFFFh
and cl, 0FFh-FNEGATIVE-FZERO ; clear flags affected
mov byte [_reg.Y + 1], bh
test bh, 80h
jz notnegative
or cl, FNEGATIVE
notnegative:
test ebx, ebx
jnz notzero
or cl, FZERO
notzero:
endm ldy16
shr8 macro
mov edi, ebx ; save pointer to data
trapandread8 ebx
and cl, 0FFh-FZERO-FNEGATIVE-FCARRY; clear affected flags
shr bl, 1
setz al
setc ch
shl al, 1 ; get zero flag
or cl, ch ; right bit into carry
or cl, al
trapandwrite8 edi, bl
endm shr8
shr16 macro
mov edi, ebx ; save pointer to data
trapandread16 ebx
and ebx, 0000FFFFh
and cl, 0FFh-FZERO-FNEGATIVE-FCARRY; clear affected flags
shr bx, 1
setc ch
test ebx, ebx
setz al
or cl, ch ; right bit into carry
shl al, 1 ; get zero flag
or cl, al
; negative flag always cleared
trapandwrite16 edi, bl, bh
endm shr16
shr8_a macro
mov bl, byte [_reg.A]
and cl, 0FFh-FZERO-FNEGATIVE-FCARRY; clear affected flags, N always = 0
shr bl, 1
setc ch
jnz @F
or cl, FZERO
@@: mov byte [_reg.A], bl
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -