Search
lxdream.org :: lxdream/src/sh4/sh4mmio.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4mmio.c
changeset 561:533f6b478071
prev550:a27e31340147
next736:a02d1475ccfd
author nkeynes
date Tue Jan 01 05:08:38 2008 +0000 (12 years ago)
branchlxdream-mmu
permissions -rw-r--r--
last change Enable Id keyword on all source files
file annotate diff log raw
nkeynes@30
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@30
     3
 * 
nkeynes@30
     4
 * Miscellaneous and not-really-implemented SH4 peripheral modules. Also
nkeynes@30
     5
 * responsible for including the IMPL side of the SH4 MMIO pages.
nkeynes@30
     6
 * Most of these will eventually be split off into their own files.
nkeynes@30
     7
 *
nkeynes@30
     8
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@30
     9
 *
nkeynes@30
    10
 * This program is free software; you can redistribute it and/or modify
nkeynes@30
    11
 * it under the terms of the GNU General Public License as published by
nkeynes@30
    12
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@30
    13
 * (at your option) any later version.
nkeynes@30
    14
 *
nkeynes@30
    15
 * This program is distributed in the hope that it will be useful,
nkeynes@30
    16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@30
    17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@30
    18
 * GNU General Public License for more details.
nkeynes@30
    19
 */
nkeynes@35
    20
#define MODULE sh4_module
nkeynes@30
    21
nkeynes@1
    22
#include "dream.h"
nkeynes@428
    23
#include "dreamcast.h"
nkeynes@1
    24
#include "mem.h"
nkeynes@19
    25
#include "clock.h"
nkeynes@428
    26
#include "sh4/sh4core.h"
nkeynes@428
    27
#include "sh4/sh4mmio.h"
nkeynes@1
    28
#define MMIO_IMPL
nkeynes@428
    29
#include "sh4/sh4mmio.h"
nkeynes@1
    30
nkeynes@1
    31
/********************************* BSC *************************************/
nkeynes@1
    32
nkeynes@323
    33
uint32_t bsc_input = 0x0300;
nkeynes@1
    34
nkeynes@323
    35
uint16_t bsc_read_pdtra()
nkeynes@1
    36
{
nkeynes@323
    37
    int i;
nkeynes@323
    38
    uint32_t pctra = MMIO_READ( BSC, PCTRA );
nkeynes@323
    39
    uint16_t output = MMIO_READ( BSC, PDTRA );
nkeynes@323
    40
    uint16_t input_mask = 0, output_mask = 0;
nkeynes@323
    41
    for( i=0; i<16; i++ ) {
nkeynes@323
    42
	int bits = (pctra >> (i<<1)) & 0x03;
nkeynes@323
    43
	if( bits == 2 ) input_mask |= (1<<i);
nkeynes@323
    44
	else if( bits != 0 ) output_mask |= (1<<i);
nkeynes@323
    45
    }
nkeynes@323
    46
nkeynes@323
    47
    /* ??? */
nkeynes@323
    48
    if( ((output | (~output_mask)) & 0x03) == 3 ) {
nkeynes@323
    49
        output |= 0x03;
nkeynes@1
    50
    } else {
nkeynes@323
    51
        output &= ~0x03;
nkeynes@1
    52
    }
nkeynes@323
    53
nkeynes@323
    54
    return (bsc_input & input_mask) | output;
nkeynes@1
    55
}
nkeynes@1
    56
nkeynes@323
    57
uint32_t bsc_read_pdtrb()
nkeynes@1
    58
{
nkeynes@1
    59
    int i;
nkeynes@323
    60
    uint32_t pctrb = MMIO_READ( BSC, PCTRB );
nkeynes@323
    61
    uint16_t output = MMIO_READ( BSC, PDTRB );
nkeynes@323
    62
    uint16_t input_mask = 0, output_mask = 0;
nkeynes@323
    63
    for( i=0; i<4; i++ ) {
nkeynes@323
    64
	int bits = (pctrb >> (i<<1)) & 0x03;
nkeynes@323
    65
	if( bits == 2 ) input_mask |= (1<<i);
nkeynes@323
    66
	else if( bits != 0 ) output_mask |= (1<<i);
nkeynes@1
    67
    }
nkeynes@323
    68
nkeynes@323
    69
    return ((bsc_input>>16) & input_mask) | output;
nkeynes@323
    70
nkeynes@1
    71
}
nkeynes@1
    72
nkeynes@336
    73
MMIO_REGION_WRITE_DEFFN(BSC)
nkeynes@323
    74
nkeynes@1
    75
int32_t mmio_region_BSC_read( uint32_t reg )
nkeynes@1
    76
{
nkeynes@1
    77
    int32_t val;
nkeynes@1
    78
    switch( reg ) {
nkeynes@1
    79
        case PDTRA:
nkeynes@323
    80
	    val = bsc_read_pdtra();
nkeynes@323
    81
	    break;
nkeynes@1
    82
        case PDTRB:
nkeynes@323
    83
	    val = bsc_read_pdtrb();
nkeynes@323
    84
	    break;
nkeynes@1
    85
        default:
nkeynes@1
    86
            val = MMIO_READ( BSC, reg );
nkeynes@1
    87
    }
nkeynes@1
    88
    return val;
nkeynes@1
    89
}
nkeynes@1
    90
nkeynes@1
    91
/********************************* UBC *************************************/
nkeynes@1
    92
nkeynes@1
    93
MMIO_REGION_STUBFNS( UBC )
nkeynes@1
    94
nkeynes@1
    95
nkeynes@1
    96
/********************************** SCI *************************************/
nkeynes@1
    97
nkeynes@1
    98
MMIO_REGION_STUBFNS( SCI )
nkeynes@1
    99
.