www.pudn.com > sn068s.zip > CPUMEM.NI


%ifndef SNEeSe_CPUmem_i 
%define SNEeSe_CPUmem_i 
 
%ifndef SNEeSe_memmap_asm 
 
extern _memmap_text_start,_memmap_data_start,_memmap_bss_start 
extern _Read_Bank8Mapping,_Write_Bank8Mapping 
extern _Read_Bank8Offset,_Write_Bank8Offset 
extern _Dummy 
extern _SNES_GET_WORD 
extern UNSUPPORTED_READ,_UNSUPPORTED_READ 
extern UNSUPPORTED_WRITE,_UNSUPPORTED_WRITE 
extern IGNORE_WRITE,_IGNORE_WRITE 
extern _PPU_READ,_PPU_WRITE 
extern _SRAM_READ,_SRAM_WRITE 
extern _SRAM_WRITE_2k,_SRAM_WRITE_4k 
%endif 
 
%if 0 
 
Macro's included in this ASM header 
 
All macros assume ebx contains 24-bit address, al or ax (depending on size) 
the location to return data (for read) or accept data (for write) at. 
edi is always corrupted. 
 
GET_BYTE    Get byte from any bank 
GET_WORD    Get word from any bank 
SET_BYTE    Set byte in any bank 
SET_WORD    Set word in any bank 
 
GET_WORD may be passed an optional 'Reverse' parameter to skip the last 
xchg. If this is done, the low byte will be returned in ah, high byte 
in al. 
 
SET_WORD may be passed an optional 'NoSave' parameter to prevent the 
push/pop used to preserve the data word. 
 
SET_WORD may be passed an optional 'Double' parameter to force it to 
use al for both high and low bytes of write data. eax is not modified. 
 
SET_WORD_HL is an alternate macros for when the address being passed in 
is of the high byte, and the high byte will be written first. This 
alternate macro does not support NoSave or Double. 
%endif 
 
%macro GET_BYTE 0 
 mov edi,ebx 
 shr edi,13 
 mov edi,[_Read_Bank8Offset+edi*4] 
 test edi,edi 
 jnz %%read_direct 
 mov edi,ebx 
 shr edi,13 
 call [_Read_Bank8Mapping+edi*4] 
 jmp short %%read_done 
%%read_direct: 
 mov al,[edi+ebx] 
%%read_done: 
%endmacro 
 
;%1 = Reverse 
%macro GET_WORD 0-1 0 
%ifidni %1,Reverse 
 GET_BYTE 
 mov ah,al 
 inc ebx 
 and ebx,0x00FFFFFF 
 GET_BYTE 
%else 
 inc ebx 
 test ebx,0x1FFF 
 jnz %%single_block 
 dec ebx 
 call _SNES_GET_WORD 
 jmp short %%read_done 
%%single_block: 
 mov edi,ebx 
 shr edi,13 
 mov edi,[_Read_Bank8Offset+edi*4] 
 test edi,edi 
 jnz %%read_direct 
 mov edi,ebx 
 shr edi,13 
 push edi 
 dec ebx 
 call [_Read_Bank8Mapping+edi*4] 
 mov ah,al 
 inc ebx 
 pop edi 
 call [_Read_Bank8Mapping+edi*4] 
 ror ax,8 
 jmp short %%read_done 
%%read_direct: 
 mov ax,[edi+ebx-1] 
%%read_done: 
%endif 
%endmacro 
 
%macro SET_BYTE 0 
 mov edi,ebx 
 shr edi,13 
 mov edi,[_Write_Bank8Offset+edi*4] 
 test edi,edi 
 jnz %%write_direct 
 mov edi,ebx 
 shr edi,13 
 call [_Write_Bank8Mapping+edi*4] 
 jmp short %%write_done 
%%write_direct: 
 mov [edi+ebx],al 
%%write_done: 
%endmacro 
 
;%1 = NoSave/Double 
%macro SET_WORD 0-1 0 
 SET_BYTE 
%ifnidni %1,Double 
%ifnidni %1,NoSave 
 push eax 
%endif 
 mov al,ah 
%endif 
 inc ebx 
 and ebx,0x00FFFFFF 
 SET_BYTE 
%ifnidni %1,Double 
%ifnidni %1,NoSave 
 pop eax 
%endif 
%endif 
%endmacro 
 
%macro SET_WORD_HL 0 
 push eax 
 mov al,ah 
 SET_BYTE 
 pop eax 
 dec ebx 
 and ebx,0x00FFFFFF 
 SET_BYTE 
%endmacro 
 
%endif ; !SNEeSe_CPUmem_i