www.pudn.com > sn068s.zip > APUSKIP.ASM


; 
; 
; APUskip.asm - Contains APU skipper 
; 
; 
 
%include "misc.ni" 
%include "PPU.ni" 
 
extern _cpu_65c816_A,_cpu_65c816_X,_cpu_65c816_Y 
 
section .text 
EXPORT_C APUskip_text_start 
section .data 
EXPORT_C APUskip_data_start 
section .bss 
EXPORT_C APUskip_bss_start 
 
section .bss 
ALIGNB 
EXPORT_C APUI00a,skipb  ; This is the APU value when _APUI00b=0 
EXPORT_C APUI00b,skipb  ; This is a count type of variable for flipping _APUI00a 
EXPORT_C APUI00c,skipb  ; Binary counter used in conjuction with _APUI01c 
_APUI01a:   skipb   ; This is the APU value when _APUI01b=0 
_APUI01b:   skipb   ; This is a count type of variable for flipping _APUI01a 
_APUI01c:   skipb   ; Binary counter upper byte of _APUI00c 
_APUI02a:   skipb   ; This is the APU value when _APUI02b=0 
_APUI02b:   skipb   ; This is a count type of variable for flipping _APUI02a 
_APUI02c:   skipb   ; Binary counter used in conjuction with _APUI03c 
_APUI03a:   skipb   ; This is the APU value when _APUI03b=0 
_APUI03b:   skipb   ; This is a count type of variable for flipping _APUI03a 
_APUI03c:   skipb   ; Binary counter upper byte of _APUI02c 
 
section .text 
ALIGNC 
EXPORT_C Reset_APU_Skipper 
 pusha 
 ; Set eax to 0, as we're setting most everything to 0... 
 xor eax,eax 
 
 mov [_APUI00a],al 
 mov [_APUI00b],al 
 mov [_APUI00c],al 
 mov [_APUI01a],al 
 mov [_APUI01b],al 
 mov [_APUI01c],al 
 mov [_APUI02a],al 
 mov [_APUI02b],al 
 mov [_APUI02c],al 
 mov [_APUI03a],al 
 mov [_APUI03b],al 
 mov [_APUI03c],al 
 popa 
 
 ret 
 
ALIGNC 
SNES_R2140_SKIP:    ; APUI00 
 cmp byte [_APUI00b],0 
 jne short .return_xl 
 
 mov al,[_cpu_65c816_A] 
 inc byte [_APUI00b] 
 mov byte [_APUI01b],0 
 ret 
 
.return_xl: 
 cmp byte [_APUI00b],1 
 jne short .return_yl 
 
 mov al,[_cpu_65c816_X] 
 inc byte [_APUI00b] 
 mov byte [_APUI01b],1 
 ret 
 
.return_yl: 
 cmp byte [_APUI00b],2 
 jne short .return_zero 
 
 mov al,[_cpu_65c816_Y] 
 inc byte [_APUI00b] 
 mov byte [_APUI01b],2 
 ret 
 
.return_zero: 
 cmp byte [_APUI00b],3 
 jne short .return_FF 
 
 mov al,0 
 inc byte [_APUI00b] 
 ret 
 
.return_FF: 
 cmp byte [_APUI00b],4 
 jne short .return_55 
 
 mov al,0xff 
 inc byte [_APUI00b] 
 ret 
 
.return_55: 
 cmp byte [_APUI00b],5 
 jne short .return_1 
 
 mov al,0x55 
 inc byte [_APUI00b] 
 ret 
 
.return_1: 
 cmp byte [_APUI00b],6 
 jne short .return_AA 
 
 mov al,1 
 inc byte [_APUI00b] 
 ret 
 
.return_AA: 
 cmp byte [_APUI00b],7 
 jne short .return_written 
 
 mov al,0xAA 
 mov byte [_APUI01b],6 
 inc byte [_APUI00b] 
 ret 
 
.return_written: 
 cmp byte [_APUI00b],8 
 jne short .return_all 
 
 mov al,[_APUI00a] 
 inc byte [_APUI00b] 
 ret 
 
.return_all: 
 mov al,[_APUI00c]      ; New extra skipper, if all else fails this should work for 2140! 
 inc byte [_APUI00c] 
 mov byte [_APUI01b],0xb    ; This keeps high word at 0 during cycle (for now at least) 
 cmp byte [_APUI00c],0 
 je  short .reset_skipper 
 ret 
 
.reset_skipper: 
 mov byte [_APUI00b],0  ; Ensures the skipper switches off 
 inc byte [_APUI01c] 
 mov byte [_APUI01b],0 
 ret 
 
ALIGNC 
SNES_R2141_SKIP:    ; APUI01 
 cmp byte [_APUI01b],0 
 jne short .return_xh 
 
 mov al,[_cpu_65c816_A+1] 
 inc byte [_APUI01b] 
 ret 
 
.return_xh: 
 cmp byte [_APUI01b],1 
 jne short .return_yh 
 
 mov al,[_cpu_65c816_X+1] 
 inc byte [_APUI01b] 
 ret 
 
.return_yh: 
 cmp byte [_APUI01b],2 
 jne short .return_al 
 
 mov al,[_cpu_65c816_Y+1] 
 inc byte [_APUI01b] 
 ret 
 
.return_al: 
 cmp byte [_APUI01b],3 
 jne short .return_xl 
 
 mov al,[_cpu_65c816_A] 
 inc byte [_APUI01b] 
 ret 
 
.return_xl: 
 cmp byte [_APUI01b],4 
 jne short .return_yl 
 
 mov al,[_cpu_65c816_X] 
 inc byte [_APUI01b] 
 ret 
 
.return_yl: 
 cmp byte [_APUI01b],5 
 jne short .return_BB 
 
 mov al,[_cpu_65c816_Y] 
 inc byte [_APUI01b] 
 ret 
 
.return_BB: 
 cmp byte [_APUI01b],6 
 jne short .return_zero 
 
 mov al,0xBB 
 inc byte [_APUI01b] 
 ret 
 
.return_zero: 
 cmp byte [_APUI01b],7 
 jne short .return_FF 
 
 mov al,0 
 inc byte [_APUI01b] 
 ret 
 
.return_FF: 
 cmp byte [_APUI01b],8 
 jne short .return_55 
 
 mov al,0xff 
 inc byte [_APUI01b] 
 ret 
 
.return_55: 
 cmp byte [_APUI01b],9 
 jne short .return_written 
 
 mov al,0x55 
 inc byte [_APUI01b] 
 ret 
 
.return_written: 
 cmp byte [_APUI01b],10 
 jne short .return_special 
 
 mov al,[_APUI01a] 
 mov byte [_APUI01b],0 
 ret 
 
.return_special: 
 mov al,[_APUI01c]  ; This can only be reached in special cases 
 ret 
 
ALIGNC 
SNES_R2142_SKIP:    ; APUI02 
 cmp byte [_APUI02b],0 
 jne short .return_xl 
 
 mov al,[_cpu_65c816_A] 
 inc byte [_APUI02b] 
 mov byte [_APUI03b],0 
 ret 
 
.return_xl: 
 cmp byte [_APUI02b],1 
 jne short .return_yl 
 
 mov al,[_cpu_65c816_X] 
 inc byte [_APUI02b] 
 mov byte [_APUI03b],1 
 ret 
 
.return_yl: 
 cmp byte [_APUI02b],2 
 jne short .return_zero 
 
 mov al,[_cpu_65c816_Y] 
 inc byte [_APUI02b] 
 mov byte [_APUI03b],2 
 ret 
 
.return_zero: 
 cmp byte [_APUI02b],3 
 jne short .return_FF 
 
 mov al,0 
 inc byte [_APUI02b] 
 ret 
 
.return_FF: 
 cmp byte [_APUI02b],4 
 jne short .return_55 
 
 mov al,0xff 
 inc byte [_APUI02b] 
 ret 
 
.return_55: 
 cmp byte [_APUI02b],5 
 jne short .return_AA 
 
 mov al,0x55 
 inc byte [_APUI02b] 
 ret 
 
.return_AA: 
 cmp byte [_APUI02b],6 
 jne short .return_written 
 
 mov al,0xAA 
 mov byte [_APUI03b],6 
 inc byte [_APUI02b] 
 ret 
 
.return_written: 
 mov al,[_APUI02a] 
 mov byte [_APUI02b],0 
 ret 
 
ALIGNC 
SNES_R2143_SKIP:    ; APUI03 
 cmp byte [_APUI03b],0 
 jne short .return_xh 
 
 mov al,[_cpu_65c816_A+1] 
 inc byte [_APUI03b] 
 ret 
 
.return_xh: 
 cmp byte [_APUI03b],1 
 jne short .return_yh 
 
 mov al,[_cpu_65c816_X+1] 
 inc byte [_APUI03b] 
 ret 
 
.return_yh: 
 cmp byte [_APUI03b],2 
 jne short .return_al 
 
 mov al,[_cpu_65c816_Y+1] 
 inc byte [_APUI03b] 
 ret 
 
.return_al: 
 cmp byte [_APUI03b],3 
 jne short .return_xl 
 
 mov al,[_cpu_65c816_A] 
 inc byte [_APUI03b] 
 ret 
 
.return_xl: 
 cmp byte [_APUI03b],4 
 jne short .return_yl 
 
 mov al,[_cpu_65c816_X] 
 inc byte [_APUI03b] 
 ret 
 
.return_yl: 
 cmp byte [_APUI03b],5 
 jne short .return_BB 
 
 mov al,[_cpu_65c816_Y] 
 inc byte [_APUI03b] 
 ret 
 
.return_BB: 
 cmp byte [_APUI03b],6 
 jne short .return_zero 
 
 mov al,0xBB 
 inc byte [_APUI03b] 
 ret 
 
.return_zero: 
 cmp byte [_APUI03b],7 
 jne short .return_FF 
 
 mov al,0 
 inc byte [_APUI03b] 
 ret 
 
.return_FF: 
 cmp byte [_APUI03b],8 
 jne short .return_55 
 
 mov al,0xFF 
 inc byte [_APUI03b] 
 ret 
 
.return_55: 
 cmp byte [_APUI03b],9 
 jne short .return_written 
 
 mov al,0x55 
 inc byte [_APUI03b] 
 ret 
 
.return_written: 
 mov al,[_APUI03a] 
 mov byte [_APUI03b],0 
 ret 
 
ALIGNC 
SNES_W2140_SKIP:    ; APUI00 
 mov [_APUI00a],al 
;cmp al,0xff 
;je short .alt 
;mov byte [_APUI00b],0 
 ret 
;.alt: 
; mov byte [_APUI00b],7 
; ret 
 
ALIGNC 
SNES_W2141_SKIP:    ; APUI01 
 mov [_APUI01a],al 
 mov byte [_APUI01b],0 
 ret 
 
ALIGNC 
SNES_W2142_SKIP:    ; APUI02 
 mov [_APUI02a],al 
 mov byte [_APUI02b],0 
 ret 
 
ALIGNC 
SNES_W2143_SKIP:    ; APUI03 
 mov [_APUI03a],al 
 mov byte [_APUI03b],0 
 ret 
 
ALIGNC 
EXPORT_C Make_APU_Skipper 
 pusha 
 mov eax,SNES_R2140_SKIP 
 mov edx,SNES_R2141_SKIP 
 mov esi,SNES_R2142_SKIP 
 mov edi,SNES_R2143_SKIP 
 
 mov ebx,Read_21_Address(0x40) 
 mov cl,0x40 / 4 
 
.set_read_loop: 
 mov [ebx],eax 
 mov [ebx+1*4],edx 
 mov [ebx+2*4],esi 
 mov [ebx+3*4],edi 
 add ebx,4*4 
 dec cl 
 jnz .set_read_loop 
 
 mov eax,SNES_W2140_SKIP 
 mov edx,SNES_W2141_SKIP 
 mov esi,SNES_W2142_SKIP 
 mov edi,SNES_W2143_SKIP 
 
 mov ebx,Write_21_Address(0x40) 
 mov cl,0x40 / 4 
 
.set_write_loop: 
 mov [ebx],eax 
 mov [ebx+1*4],edx 
 mov [ebx+2*4],esi 
 mov [ebx+3*4],edi 
 add ebx,4*4 
 dec cl 
 jnz .set_write_loop 
 
 popa 
 ret 
 
section .text 
ALIGNC 
section .data 
ALIGND 
section .bss 
ALIGNB