📄 asmz80.asm
字号:
.486p
model flat
_DATA segment dword public use32 'DATA'
_regAF dw 0
_regBC dw 0
_regDE dw 0
_regHL dw 0
_regSP dw 0
_regPC dw 0
memVal dw 0
_nFlag db 0
_imeFlag db 0
clkLeft dw 0
divClk dw 0
timerClk dw 0
_lcdClk dw 0
_lcdUpdateCount dw 0
_oldPC dw 0
_halted db 0
_minTime dw 0
_intReq2 dw 0
_intReq3 dw 0
_DATA ends
_TEXT segment dword public use32 'CODE'
extern _getmemfunc
extern _putmemfunc
extern @RenderLine
extern @RedrawLCD
extern @DebugChecks
extern _mem
extern _oam
extern _hiRam
extern _dmaClk
extern _timerClkCount
extern _intReq
extern _lcdMode
extern _lcdY
extern _lcdUpdateFreq
extern _clkMult
extern _debugCheckEnable
extern _run
extern _endStepOver
extern _ignoreStack
extern _gdmaClk
extern _displayEnabled
get_opbyte:
; cmp [_regPC],0fe00h
; jae gob_noDirectRead
; cmp byte ptr [_lcdMode],3
; jz gob_callmem
; cmp byte ptr [_dmaClk],0
; jne gob_callmem
movzx esi,[_regPC]
mov ebp,esi
shr esi,12
and ebp,0fffh
mov esi,[esi*4+offset _mem]
or esi,esi
jz gob_callmem
push ax
mov ah,[esi+ebp]
mov byte ptr [memVal],ah
pop ax
gob_end:
inc [_regPC]
ret
gob_noDirectRead:
cmp [_regPC],0fea0h
jb gob_oam
cmp [_regPC],0ff80h
jae gob_hi
gob_callmem:
pusha
mov ax,[_regPC]
mov esi,[_getmemfunc]
db 0ffh,0d6h ;call esi
mov byte ptr [memVal],al
popa
inc [_regPC]
ret
gob_oam:
mov si,[_regPC]
and esi,0ffh
push ax
mov ah,[esi+offset _oam]
mov byte ptr [memVal],ah
pop ax
inc [_regPC]
ret
gob_hi:
mov si,[_regPC]
and esi,0ffh
push ax
mov ah,[esi+offset _hiRam]
mov byte ptr [memVal],ah
pop ax
inc [_regPC]
ret
get_opword:
inc [_regPC]
call get_opbyte
shl [memVal],8
sub [_regPC],2
call get_opbyte
inc [_regPC]
ret
get_bc:
; cmp bx,0fe00h
; jae gbc_noDirectRead
; cmp byte ptr [_lcdMode],3
; jz gbc_callmem
; cmp byte ptr [_dmaClk],0
; jne gbc_callmem
movzx esi,bx
mov ebp,esi
shr esi,12
and ebp,0fffh
mov esi,[esi*4+offset _mem]
or esi,esi
jz gbc_callmem
push ax
mov ah,[esi+ebp]
mov byte ptr [memVal],ah
pop ax
gbc_end:
ret
gbc_noDirectRead:
cmp bx,0fea0h
jb gbc_oam
cmp bx,0ff80h
jae gbc_hi
gbc_callmem:
pusha
mov ax,bx
mov esi,[_getmemfunc]
db 0ffh,0d6h ;call esi
mov byte ptr [memVal],al
popa
ret
gbc_oam:
mov si,bx
and esi,0ffh
push ax
mov ah,[esi+offset _oam]
mov byte ptr [memVal],ah
pop ax
ret
gbc_hi:
mov si,bx
and esi,0ffh
push ax
mov ah,[esi+offset _hiRam]
mov byte ptr [memVal],ah
pop ax
ret
get_de:
; cmp cx,0fe00h
; jae gde_noDirectRead
; cmp byte ptr [_lcdMode],3
; jz gde_callmem
; cmp byte ptr [_dmaClk],0
; jne gde_callmem
movzx esi,cx
mov ebp,esi
shr esi,12
and ebp,0fffh
mov esi,[esi*4+offset _mem]
or esi,esi
jz gde_callmem
push ax
mov ah,[esi+ebp]
mov byte ptr [memVal],ah
pop ax
gde_end:
ret
gde_noDirectRead:
cmp cx,0fea0h
jb gde_oam
cmp cx,0ff80h
jae gde_hi
gde_callmem:
pusha
mov ax,cx
mov esi,[_getmemfunc]
db 0ffh,0d6h ;call esi
mov byte ptr [memVal],al
popa
ret
gde_oam:
mov si,cx
and esi,0ffh
push ax
mov ah,[esi+offset _oam]
mov byte ptr [memVal],ah
pop ax
ret
gde_hi:
mov si,cx
and esi,0ffh
push ax
mov ah,[esi+offset _hiRam]
mov byte ptr [memVal],ah
pop ax
ret
get_hl:
; cmp dx,0fe00h
; jae ghl_noDirectRead
; cmp byte ptr [_lcdMode],3
; jz ghl_callmem
; cmp byte ptr [_dmaClk],0
; jne ghl_callmem
movzx esi,dx
mov ebp,esi
shr esi,12
and ebp,0fffh
mov esi,[esi*4+offset _mem]
or esi,esi
jz ghl_callmem
push ax
mov ah,[esi+ebp]
mov byte ptr [memVal],ah
pop ax
ghl_end:
ret
ghl_noDirectRead:
cmp dx,0fea0h
jb ghl_oam
cmp dx,0ff80h
jae ghl_hi
ghl_callmem:
pusha
mov ax,dx
mov esi,[_getmemfunc]
db 0ffh,0d6h ;call esi
mov byte ptr [memVal],al
popa
ret
ghl_oam:
mov si,dx
and esi,0ffh
push ax
mov ah,[esi+offset _oam]
mov byte ptr [memVal],ah
pop ax
ret
ghl_hi:
mov si,dx
and esi,0ffh
push ax
mov ah,[esi+offset _hiRam]
mov byte ptr [memVal],ah
pop ax
ret
get_si:
; cmp si,0fe00h
; jae gsi_noDirectRead
; cmp byte ptr [_lcdMode],3
; jz gsi_callmem
; cmp byte ptr [_dmaClk],0
; jne gsi_callmem
push esi
movzx esi,si
mov ebp,esi
shr esi,12
and ebp,0fffh
mov esi,[esi*4+offset _mem]
or esi,esi
jz gsi_end
push ax
mov ah,[esi+ebp]
mov byte ptr [memVal],ah
pop ax
pop esi
ret
gsi_end:
pop esi
jmp gsi_callmem
gsi_noDirectRead:
cmp si,0fea0h
jb gsi_oam
cmp si,0ff80h
jae gsi_hi
gsi_callmem:
pusha
mov ax,si
mov esi,[_getmemfunc]
db 0ffh,0d6h ;call esi
mov byte ptr [memVal],al
popa
ret
gsi_oam:
and esi,0ffh
push ax
mov ah,[esi+offset _oam]
mov byte ptr [memVal],ah
pop ax
ret
gsi_hi:
and esi,0ffh
push ax
mov ah,[esi+offset _hiRam]
mov byte ptr [memVal],ah
pop ax
ret
get_spword:
lea esi,[edi+1]
call get_si
shl [memVal],8
mov esi,edi
call get_si
ret
put_bc:
cmp bx,8000h
jb pbc_noDirectWrite
cmp bx,0fe00h
jae pbc_noDirectWrite
cmp byte ptr [_lcdMode],3
jz pbc_noDirectWrite
cmp byte ptr [_dmaClk],0
jne pbc_noDirectWrite
movzx esi,bx
mov ebp,esi
shr esi,12
and ebp,0fffh
mov esi,[esi*4+offset _mem]
or esi,esi
jz pbc_end
push ax
mov ah,byte ptr [memVal]
mov [esi+ebp],ah
pop ax
pbc_end:
ret
pbc_noDirectWrite:
pusha
mov ax,bx
mov dl,byte ptr [memVal]
mov esi,[_putmemfunc]
db 0ffh,0d6h ;call esi
popa
ret
put_de:
cmp cx,8000h
jb pde_noDirectWrite
cmp cx,0fe00h
jae pde_noDirectWrite
cmp byte ptr [_lcdMode],3
jz pde_noDirectWrite
cmp byte ptr [_dmaClk],0
jne pde_noDirectWrite
movzx esi,cx
mov ebp,esi
shr esi,12
and ebp,0fffh
mov esi,[esi*4+offset _mem]
or esi,esi
jz pde_end
push ax
mov ah,byte ptr [memVal]
mov [esi+ebp],ah
pop ax
pde_end:
ret
pde_noDirectWrite:
pusha
mov ax,cx
mov dl,byte ptr [memVal]
mov esi,[_putmemfunc]
db 0ffh,0d6h ;call esi
popa
ret
put_hl:
cmp dx,8000h
jb phl_noDirectWrite
cmp dx,0fe00h
jae phl_noDirectWrite
cmp byte ptr [_lcdMode],3
jz phl_noDirectWrite
cmp byte ptr [_dmaClk],0
jne phl_noDirectWrite
movzx esi,dx
mov ebp,esi
shr esi,12
and ebp,0fffh
mov esi,[esi*4+offset _mem]
or esi,esi
jz phl_end
push ax
mov ah,byte ptr [memVal]
mov [esi+ebp],ah
pop ax
phl_end:
ret
phl_noDirectWrite:
pusha
mov ax,dx
mov dl,byte ptr [memVal]
mov esi,[_putmemfunc]
db 0ffh,0d6h ;call esi
popa
ret
put_si:
cmp si,8000h
jb psi_noDirectWrite
cmp si,0fe00h
jae psi_noDirectWrite
cmp byte ptr [_lcdMode],3
jz psi_noDirectWrite
cmp byte ptr [_dmaClk],0
jne psi_noDirectWrite
movzx esi,si
mov ebp,esi
shr esi,12
and ebp,0fffh
mov esi,[esi*4+offset _mem]
or esi,esi
jz psi_end
push ax
mov ah,byte ptr [memVal]
mov [esi+ebp],ah
pop ax
psi_end:
ret
psi_noDirectWrite:
pusha
mov ax,si
mov dl,byte ptr [memVal]
mov esi,[_putmemfunc]
db 0ffh,0d6h ;call esi
popa
ret
put_spword:
mov si,di
call put_si
lea esi,[edi+1]
shr [memVal],8
call put_si
ret
nop:
jmp next
adc_a_b:
sahf
adc al,bh
lahf
mov byte ptr [_nFlag],0
jmp next
adc_a_c:
sahf
adc al,bl
lahf
mov byte ptr [_nFlag],0
jmp next
adc_a_d:
sahf
adc al,ch
lahf
mov byte ptr [_nFlag],0
jmp next
adc_a_e:
sahf
adc al,cl
lahf
mov byte ptr [_nFlag],0
jmp next
adc_a_h:
sahf
adc al,dh
lahf
mov byte ptr [_nFlag],0
jmp next
adc_a_l:
sahf
adc al,dl
lahf
mov byte ptr [_nFlag],0
jmp next
adc_a_xhl:
call get_hl
sahf
adc al,byte ptr [memVal]
lahf
mov byte ptr [_nFlag],0
jmp next
adc_a_a:
sahf
adc al,al
lahf
mov byte ptr [_nFlag],0
jmp next
adc_a_byte:
call get_opbyte
sahf
adc al,byte ptr [memVal]
lahf
mov byte ptr [_nFlag],0
jmp next
add_hl_bc:
add dx,bx
push bx
mov bl,ah
lahf
and bl,40h
and ah,0bfh
or ah,bl
pop bx
mov byte ptr [_nFlag],0
jmp next
add_hl_de:
add dx,cx
push bx
mov bl,ah
lahf
and bl,40h
and ah,0bfh
or ah,bl
pop bx
mov byte ptr [_nFlag],0
jmp next
add_hl_hl:
add dx,dx
push bx
mov bl,ah
lahf
and bl,40h
and ah,0bfh
or ah,bl
pop bx
mov byte ptr [_nFlag],0
jmp next
add_hl_sp:
add dx,di
push bx
mov bl,ah
lahf
and bl,40h
and ah,0bfh
or ah,bl
pop bx
mov byte ptr [_nFlag],0
jmp next
add_a_b:
add al,bh
lahf
mov byte ptr [_nFlag],0
jmp next
add_a_c:
add al,bl
lahf
mov byte ptr [_nFlag],0
jmp next
add_a_d:
add al,ch
lahf
mov byte ptr [_nFlag],0
jmp next
add_a_e:
add al,cl
lahf
mov byte ptr [_nFlag],0
jmp next
add_a_h:
add al,dh
lahf
mov byte ptr [_nFlag],0
jmp next
add_a_l:
add al,dl
lahf
mov byte ptr [_nFlag],0
jmp next
add_a_xhl:
call get_hl
add al,byte ptr [memVal]
lahf
mov byte ptr [_nFlag],0
jmp next
add_a_a:
add al,al
lahf
mov byte ptr [_nFlag],0
jmp next
add_a_byte:
call get_opbyte
add al,byte ptr [memVal]
lahf
mov byte ptr [_nFlag],0
jmp next
add_sp_disp:
call get_opbyte
movsx si,byte ptr [memVal]
add di,si
lahf
and ah,0bfh
mov byte ptr [_nFlag],0
jmp next
and_a_b:
and al,bh
lahf
and ah,40h
or ah,10h
mov byte ptr [_nFlag],0
jmp next
and_a_c:
and al,bl
lahf
and ah,40h
or ah,10h
mov byte ptr [_nFlag],0
jmp next
and_a_d:
and al,ch
lahf
and ah,40h
or ah,10h
mov byte ptr [_nFlag],0
jmp next
and_a_e:
and al,cl
lahf
and ah,40h
or ah,10h
mov byte ptr [_nFlag],0
jmp next
and_a_h:
and al,dh
lahf
and ah,40h
or ah,10h
mov byte ptr [_nFlag],0
jmp next
and_a_l:
and al,dl
lahf
and ah,40h
or ah,10h
mov byte ptr [_nFlag],0
jmp next
and_a_xhl:
call get_hl
and al,byte ptr [memVal]
lahf
and ah,40h
or ah,10h
mov byte ptr [_nFlag],0
jmp next
and_a_a:
and al,al
lahf
and ah,40h
or ah,10h
mov byte ptr [_nFlag],0
jmp next
and_byte:
call get_opbyte
and al,byte ptr [memVal]
lahf
and ah,40h
or ah,10h
mov byte ptr [_nFlag],0
jmp next
bit_0_b:
test bh,1
push bx
mov bl,ah
lahf
and bl,1
and ah,040h
or ah,bl
or ah,10h
pop bx
mov byte ptr [_nFlag],0
jmp next
bit_0_c:
test bl,1
push bx
mov bl,ah
lahf
and bl,1
and ah,040h
or ah,bl
or ah,10h
pop bx
mov byte ptr [_nFlag],0
jmp next
bit_0_d:
test ch,1
push bx
mov bl,ah
lahf
and bl,1
and ah,040h
or ah,bl
or ah,10h
pop bx
mov byte ptr [_nFlag],0
jmp next
bit_0_e:
test cl,1
push bx
mov bl,ah
lahf
and bl,1
and ah,040h
or ah,bl
or ah,10h
pop bx
mov byte ptr [_nFlag],0
jmp next
bit_0_h:
test dh,1
push bx
mov bl,ah
lahf
and bl,1
and ah,040h
or ah,bl
or ah,10h
pop bx
mov byte ptr [_nFlag],0
jmp next
bit_0_l:
test dl,1
push bx
mov bl,ah
lahf
and bl,1
and ah,040h
or ah,bl
or ah,10h
pop bx
mov byte ptr [_nFlag],0
jmp next
bit_0_xhl:
call get_hl
test byte ptr [memVal],1
push bx
mov bl,ah
lahf
and bl,1
and ah,040h
or ah,bl
or ah,10h
pop bx
mov byte ptr [_nFlag],0
call put_hl
jmp next
bit_0_a:
test al,1
push bx
mov bl,ah
lahf
and bl,1
and ah,040h
or ah,bl
or ah,10h
pop bx
mov byte ptr [_nFlag],0
jmp next
bit_1_b:
test bh,2
push bx
mov bl,ah
lahf
and bl,1
and ah,040h
or ah,bl
or ah,10h
pop bx
mov byte ptr [_nFlag],0
jmp next
bit_1_c:
test bl,2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -