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