Search
lxdream.org :: lxdream/src/sdram.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/sdram.c
changeset 1067:d3c00ffccfcd
prev991:60c7fab9c880
prev940:81e0d3051d5f
author nkeynes
date Sun Jul 05 13:54:48 2009 +1000 (12 years ago)
permissions -rw-r--r--
last change No-op merge lxdream-mem to tip to remove head (Long since merged in
actuality)
file annotate diff log raw
nkeynes@939
     1
/**
nkeynes@940
     2
 * $Id$
nkeynes@939
     3
 *
nkeynes@939
     4
 * Dreamcast main SDRAM - access methods and timing controls. This is fairly
nkeynes@939
     5
 * directly coupled to the SH4
nkeynes@939
     6
 *
nkeynes@939
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@939
     8
 *
nkeynes@939
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@939
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@939
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@939
    12
 * (at your option) any later version.
nkeynes@939
    13
 *
nkeynes@939
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@939
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@939
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@939
    17
 * GNU General Public License for more details.
nkeynes@939
    18
 */
nkeynes@939
    19
nkeynes@939
    20
#include "lxdream.h"
nkeynes@939
    21
#include "mem.h"
nkeynes@939
    22
#include "dreamcast.h"
nkeynes@991
    23
#include "xlat/xltcache.h"
nkeynes@939
    24
#include <string.h>
nkeynes@939
    25
nkeynes@939
    26
nkeynes@939
    27
static int32_t FASTCALL ext_sdram_read_long( sh4addr_t addr )
nkeynes@939
    28
{
nkeynes@939
    29
    return *((int32_t *)(dc_main_ram + (addr&0x00FFFFFF)));
nkeynes@939
    30
}
nkeynes@939
    31
static int32_t FASTCALL ext_sdram_read_word( sh4addr_t addr )
nkeynes@939
    32
{
nkeynes@939
    33
    return SIGNEXT16(*((int16_t *)(dc_main_ram + (addr&0x00FFFFFF))));
nkeynes@939
    34
}
nkeynes@939
    35
static int32_t FASTCALL ext_sdram_read_byte( sh4addr_t addr )
nkeynes@939
    36
{
nkeynes@939
    37
    return SIGNEXT8(*((int16_t *)(dc_main_ram + (addr&0x00FFFFFF))));
nkeynes@939
    38
}
nkeynes@939
    39
static void FASTCALL ext_sdram_write_long( sh4addr_t addr, uint32_t val )
nkeynes@939
    40
{
nkeynes@939
    41
    *(uint32_t *)(dc_main_ram + (addr&0x00FFFFFF)) = val;
nkeynes@939
    42
    xlat_invalidate_long(addr);
nkeynes@939
    43
}
nkeynes@939
    44
static void FASTCALL ext_sdram_write_word( sh4addr_t addr, uint32_t val )
nkeynes@939
    45
{
nkeynes@939
    46
    *(uint16_t *)(dc_main_ram + (addr&0x00FFFFFF)) = (uint16_t)val;
nkeynes@939
    47
    xlat_invalidate_word(addr);
nkeynes@939
    48
}
nkeynes@939
    49
static void FASTCALL ext_sdram_write_byte( sh4addr_t addr, uint32_t val )
nkeynes@939
    50
{
nkeynes@939
    51
    *(uint8_t *)(dc_main_ram + (addr&0x00FFFFFF)) = (uint8_t)val;
nkeynes@939
    52
    xlat_invalidate_word(addr);
nkeynes@939
    53
}
nkeynes@939
    54
static void FASTCALL ext_sdram_read_burst( unsigned char *dest, sh4addr_t addr )
nkeynes@939
    55
{
nkeynes@939
    56
    memcpy( dest, dc_main_ram+(addr&0x00FFFFFF), 32 );
nkeynes@939
    57
}
nkeynes@939
    58
static void FASTCALL ext_sdram_write_burst( sh4addr_t addr, unsigned char *src )
nkeynes@939
    59
{
nkeynes@939
    60
    memcpy( dc_main_ram+(addr&0x00FFFFFF), src, 32 );
nkeynes@939
    61
}
nkeynes@939
    62
nkeynes@939
    63
struct mem_region_fn mem_region_sdram = { ext_sdram_read_long, ext_sdram_write_long, 
nkeynes@939
    64
        ext_sdram_read_word, ext_sdram_write_word, 
nkeynes@939
    65
        ext_sdram_read_byte, ext_sdram_write_byte, 
nkeynes@939
    66
        ext_sdram_read_burst, ext_sdram_write_burst }; 
.