Search
lxdream.org :: lxdream/src/sdram.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/sdram.c
changeset 953:f4a156508ad1
next962:54a657069b81
author nkeynes
date Tue Jan 13 11:56:28 2009 +0000 (13 years ago)
permissions -rw-r--r--
last change Merge lxdream-mem branch back to trunk
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@953
    23
#include <string.h>
nkeynes@953
    24
nkeynes@953
    25
nkeynes@953
    26
static int32_t FASTCALL ext_sdram_read_long( sh4addr_t addr )
nkeynes@953
    27
{
nkeynes@953
    28
    return *((int32_t *)(dc_main_ram + (addr&0x00FFFFFF)));
nkeynes@953
    29
}
nkeynes@953
    30
static int32_t FASTCALL ext_sdram_read_word( sh4addr_t addr )
nkeynes@953
    31
{
nkeynes@953
    32
    return SIGNEXT16(*((int16_t *)(dc_main_ram + (addr&0x00FFFFFF))));
nkeynes@953
    33
}
nkeynes@953
    34
static int32_t FASTCALL ext_sdram_read_byte( sh4addr_t addr )
nkeynes@953
    35
{
nkeynes@953
    36
    return SIGNEXT8(*((int16_t *)(dc_main_ram + (addr&0x00FFFFFF))));
nkeynes@953
    37
}
nkeynes@953
    38
static void FASTCALL ext_sdram_write_long( sh4addr_t addr, uint32_t val )
nkeynes@953
    39
{
nkeynes@953
    40
    *(uint32_t *)(dc_main_ram + (addr&0x00FFFFFF)) = val;
nkeynes@953
    41
    xlat_invalidate_long(addr);
nkeynes@953
    42
}
nkeynes@953
    43
static void FASTCALL ext_sdram_write_word( sh4addr_t addr, uint32_t val )
nkeynes@953
    44
{
nkeynes@953
    45
    *(uint16_t *)(dc_main_ram + (addr&0x00FFFFFF)) = (uint16_t)val;
nkeynes@953
    46
    xlat_invalidate_word(addr);
nkeynes@953
    47
}
nkeynes@953
    48
static void FASTCALL ext_sdram_write_byte( sh4addr_t addr, uint32_t val )
nkeynes@953
    49
{
nkeynes@953
    50
    *(uint8_t *)(dc_main_ram + (addr&0x00FFFFFF)) = (uint8_t)val;
nkeynes@953
    51
    xlat_invalidate_word(addr);
nkeynes@953
    52
}
nkeynes@953
    53
static void FASTCALL ext_sdram_read_burst( unsigned char *dest, sh4addr_t addr )
nkeynes@953
    54
{
nkeynes@953
    55
    memcpy( dest, dc_main_ram+(addr&0x00FFFFFF), 32 );
nkeynes@953
    56
}
nkeynes@953
    57
static void FASTCALL ext_sdram_write_burst( sh4addr_t addr, unsigned char *src )
nkeynes@953
    58
{
nkeynes@953
    59
    memcpy( dc_main_ram+(addr&0x00FFFFFF), src, 32 );
nkeynes@953
    60
}
nkeynes@953
    61
nkeynes@953
    62
struct mem_region_fn mem_region_sdram = { ext_sdram_read_long, ext_sdram_write_long, 
nkeynes@953
    63
        ext_sdram_read_word, ext_sdram_write_word, 
nkeynes@953
    64
        ext_sdram_read_byte, ext_sdram_write_byte, 
nkeynes@953
    65
        ext_sdram_read_burst, ext_sdram_write_burst }; 
.