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


;%define TRAP_BAD_READS 
;%define TRAP_BAD_WRITES 
;%define TRAP_IGNORED_WRITES 
; 
; 
; SNEeSe SNES memory mapper v2.0 - NASM rewrite 
; 
; There are two native pointer tables in this code, and two call tables. 
;  Each table has 2k entries (1 per 8k - 8 per bank). 
;  Native pointer table is consulted first, if nonzero, pointer is added 
;   to SNES address, result being native address for read/write. 
;  If native pointer is zero, call table is used to process read. 
; 
;  Files are split up as follows: 
; 
;    memmap.asm   Memory map handlers and table declarations. 
;    memmap.ni    Memory mapping macros. 
;    PPU.asm      Hardware port (21xx/40xx/42xx/43xx) handlers. 
;    DMA.asm      DMA emulation code. 
; 
; 
 
%define SNEeSe_memmap_asm 
 
%include "misc.ni" 
%include "memmap.ni" 
%include "cpumem.ni" 
%include "PPU.ni" 
 
section .text 
EXPORT_C memmap_text_start 
section .data 
EXPORT_C memmap_data_start 
section .bss 
EXPORT_C memmap_bss_start 
 
extern _SRAM_Mask 
extern _Map_Address 
extern _Map_Byte 
 
section .bss 
ALIGNB 
EXPORT_C Read_Bank8Mapping  ,skipl 256*8 
EXPORT_C Write_Bank8Mapping ,skipl 256*8 
EXPORT_C Read_Bank8Offset   ,skipl 256*8 
EXPORT_C Write_Bank8Offset  ,skipl 256*8 
EXPORT_C Dummy              ,skipk 64 
 
section .text 
ALIGNC 
EXPORT_C SNES_GET_WORD 
 GET_BYTE 
 mov ah,al 
 inc ebx 
 and ebx,0x00FFFFFF 
 GET_BYTE 
 ror ax,8 
 ret 
 
ALIGNC 
EXPORT UNSUPPORTED_READ 
EXPORT_C UNSUPPORTED_READ 
    mov al,0 
%ifdef DEBUG 
%ifdef TRAP_BAD_READS 
extern _InvalidHWRead 
    mov [_Map_Address],ebx  ; Set up Map Address so message works! 
    mov [_Map_Byte],al      ; Set up Map Byte so message works 
    pusha 
    call _InvalidHWRead     ; Unmapped hardware address! 
    popa 
%endif 
%endif 
    ret 
 
ALIGNC 
EXPORT UNSUPPORTED_WRITE 
EXPORT_C UNSUPPORTED_WRITE 
%ifdef DEBUG 
%ifdef TRAP_BAD_WRITES 
extern _InvalidHWWrite 
    mov [_Map_Address],ebx  ; Set up Map Address so message works! 
    mov [_Map_Byte],al      ; Set up Map Byte so message works 
    pusha 
    call _InvalidHWWrite    ; Unmapped hardware address! 
    popa 
%endif 
%endif 
    ret 
 
ALIGNC 
EXPORT IGNORE_WRITE 
EXPORT_C IGNORE_WRITE 
%ifdef DEBUG 
%ifdef TRAP_IGNORED_WRITES 
extern _InvalidHWWrite 
    mov [_Map_Address],ebx  ; Set up Map Address so message works! 
    mov [_Map_Byte],al      ; Set up Map Byte so message works 
    pusha 
    call _InvalidHWWrite    ; Unmapped hardware address! 
    popa 
%endif 
%endif 
    ret 
 
ALIGNC 
EXPORT_C PPU_READ 
    PPU_READ 
 
ALIGNC 
EXPORT_C PPU_WRITE 
    PPU_WRITE 
 
ALIGNC 
EXPORT_C SRAM_READ 
    mov edi,[_SRAM_Mask] 
    and edi,ebx 
    mov al,[_SRAM+edi] 
    ret 
 
ALIGNC 
EXPORT_C SRAM_WRITE 
    mov edi,[_SRAM_Mask] 
    and edi,ebx 
    mov [_SRAM+edi],al 
    ret 
 
ALIGNC 
EXPORT_C SRAM_WRITE_2k 
    mov edi,2048 - 1 
    and edi,ebx 
    mov [_SRAM+edi],al 
    mov [_SRAM+edi+2048],al 
    mov [_SRAM+edi+4096],al 
    mov [_SRAM+edi+6144],al 
    ret 
 
ALIGNC 
EXPORT_C SRAM_WRITE_4k 
    mov edi,4096 - 1 
    and edi,ebx 
    mov [_SRAM+edi],al 
    mov [_SRAM+edi+4096],al 
    ret 
 
section .text 
ALIGNC 
section .data 
ALIGND 
section .bss 
ALIGNB