Search
lxdream.org :: lxdream/src/asic.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/asic.c
changeset 15:5194dd0fdb60
prev2:42349f6ea216
next20:3ffb66aa25c7
author nkeynes
date Mon Dec 12 13:11:11 2005 +0000 (14 years ago)
permissions -rw-r--r--
last change Add dreamcast_module module structure
file annotate diff log raw
nkeynes@1
     1
#include <assert.h>
nkeynes@1
     2
#include "dream.h"
nkeynes@1
     3
#include "mem.h"
nkeynes@1
     4
#include "sh4/intc.h"
nkeynes@2
     5
#include "dreamcast.h"
nkeynes@15
     6
#include "modules.h"
nkeynes@1
     7
#include "maple.h"
nkeynes@2
     8
#include "ide.h"
nkeynes@15
     9
#include "asic.h"
nkeynes@1
    10
#define MMIO_IMPL
nkeynes@1
    11
#include "asic.h"
nkeynes@1
    12
/*
nkeynes@1
    13
 * Open questions:
nkeynes@1
    14
 *   1) Does changing the mask after event occurance result in the
nkeynes@1
    15
 *      interrupt being delivered immediately?
nkeynes@1
    16
 *   2) If the pending register is not cleared after an interrupt, does
nkeynes@1
    17
 *      the interrupt line remain high? (ie does the IRQ reoccur?)
nkeynes@1
    18
 * TODO: Logic diagram of ASIC event/interrupt logic.
nkeynes@1
    19
 *
nkeynes@1
    20
 * ... don't even get me started on the "EXTDMA" page, about which, apparently,
nkeynes@1
    21
 * practically nothing is publicly known...
nkeynes@1
    22
 */
nkeynes@1
    23
nkeynes@15
    24
struct dreamcast_module asic_module = { "ASIC", asic_init, NULL, NULL, NULL,
nkeynes@15
    25
					NULL, NULL };
nkeynes@15
    26
nkeynes@1
    27
void asic_init( void )
nkeynes@1
    28
{
nkeynes@1
    29
    register_io_region( &mmio_region_ASIC );
nkeynes@1
    30
    register_io_region( &mmio_region_EXTDMA );
nkeynes@1
    31
    mmio_region_ASIC.trace_flag = 0; /* Because this is called so often */
nkeynes@1
    32
    asic_event( EVENT_GDROM_CMD );
nkeynes@1
    33
}
nkeynes@1
    34
nkeynes@1
    35
void mmio_region_ASIC_write( uint32_t reg, uint32_t val )
nkeynes@1
    36
{
nkeynes@1
    37
    switch( reg ) {
nkeynes@1
    38
        case PIRQ0:
nkeynes@1
    39
        case PIRQ1:
nkeynes@1
    40
        case PIRQ2:
nkeynes@1
    41
            /* Clear any interrupts */
nkeynes@1
    42
            MMIO_WRITE( ASIC, reg, MMIO_READ(ASIC, reg)&~val );
nkeynes@1
    43
            break;
nkeynes@1
    44
        case MAPLE_STATE:
nkeynes@1
    45
            MMIO_WRITE( ASIC, reg, val );
nkeynes@1
    46
            if( val & 1 ) {
nkeynes@1
    47
                uint32_t maple_addr = MMIO_READ( ASIC, MAPLE_DMA) &0x1FFFFFE0;
nkeynes@2
    48
		WARN( "Maple request initiated at %08X, halting", maple_addr );
nkeynes@2
    49
                maple_handle_buffer( maple_addr );
nkeynes@1
    50
                MMIO_WRITE( ASIC, reg, 0 );
nkeynes@2
    51
//                dreamcast_stop();
nkeynes@1
    52
            }
nkeynes@1
    53
            break;
nkeynes@1
    54
        default:
nkeynes@1
    55
            MMIO_WRITE( ASIC, reg, val );
nkeynes@1
    56
            WARN( "Write to ASIC (%03X <= %08X) [%s: %s]",
nkeynes@1
    57
                  reg, val, MMIO_REGID(ASIC,reg), MMIO_REGDESC(ASIC,reg) );
nkeynes@1
    58
    }
nkeynes@1
    59
}
nkeynes@1
    60
nkeynes@1
    61
int32_t mmio_region_ASIC_read( uint32_t reg )
nkeynes@1
    62
{
nkeynes@1
    63
    int32_t val;
nkeynes@1
    64
    switch( reg ) {
nkeynes@2
    65
        /*
nkeynes@2
    66
        case 0x89C:
nkeynes@2
    67
            sh4_stop();
nkeynes@2
    68
            return 0x000000B;
nkeynes@2
    69
        */     
nkeynes@1
    70
        case PIRQ0:
nkeynes@1
    71
        case PIRQ1:
nkeynes@1
    72
        case PIRQ2:
nkeynes@1
    73
            val = MMIO_READ(ASIC, reg);
nkeynes@1
    74
//            WARN( "Read from ASIC (%03X => %08X) [%s: %s]",
nkeynes@1
    75
//                  reg, val, MMIO_REGID(ASIC,reg), MMIO_REGDESC(ASIC,reg) );
nkeynes@1
    76
            return val;            
nkeynes@1
    77
        case G2STATUS:
nkeynes@1
    78
            return 0; /* find out later if there's any cases we actually need to care about */
nkeynes@1
    79
        default:
nkeynes@1
    80
            val = MMIO_READ(ASIC, reg);
nkeynes@1
    81
            WARN( "Read from ASIC (%03X => %08X) [%s: %s]",
nkeynes@1
    82
                  reg, val, MMIO_REGID(ASIC,reg), MMIO_REGDESC(ASIC,reg) );
nkeynes@1
    83
            return val;
nkeynes@1
    84
    }
nkeynes@1
    85
           
nkeynes@1
    86
}
nkeynes@1
    87
nkeynes@1
    88
void asic_event( int event )
nkeynes@1
    89
{
nkeynes@1
    90
    int offset = ((event&0x60)>>3);
nkeynes@1
    91
    int result = (MMIO_READ(ASIC, PIRQ0 + offset))  |=  (1<<(event&0x1F));
nkeynes@1
    92
nkeynes@1
    93
    if( result & MMIO_READ(ASIC, IRQA0 + offset) )
nkeynes@1
    94
        intc_raise_interrupt( INT_IRQ13 );
nkeynes@1
    95
    if( result & MMIO_READ(ASIC, IRQB0 + offset) )
nkeynes@1
    96
        intc_raise_interrupt( INT_IRQ11 );
nkeynes@1
    97
    if( result & MMIO_READ(ASIC, IRQC0 + offset) )
nkeynes@1
    98
        intc_raise_interrupt( INT_IRQ9 );
nkeynes@1
    99
}
nkeynes@1
   100
nkeynes@1
   101
nkeynes@1
   102
nkeynes@1
   103
MMIO_REGION_WRITE_FN( EXTDMA, reg, val )
nkeynes@1
   104
{
nkeynes@2
   105
    switch( reg ) {
nkeynes@2
   106
        case IDEALTSTATUS: /* Device control */
nkeynes@2
   107
            ide_write_control( val );
nkeynes@2
   108
            break;
nkeynes@2
   109
        case IDEDATA:
nkeynes@2
   110
            ide_write_data_pio( val );
nkeynes@2
   111
            break;
nkeynes@2
   112
        case IDEFEAT:
nkeynes@2
   113
            if( ide_can_write_regs() )
nkeynes@2
   114
                idereg.feature = (uint8_t)val;
nkeynes@2
   115
            break;
nkeynes@2
   116
        case IDECOUNT:
nkeynes@2
   117
            if( ide_can_write_regs() )
nkeynes@2
   118
                idereg.count = (uint8_t)val;
nkeynes@2
   119
            break;
nkeynes@2
   120
        case IDELBA0:
nkeynes@2
   121
            if( ide_can_write_regs() )
nkeynes@2
   122
                idereg.lba0 = (uint8_t)val;
nkeynes@2
   123
            break;
nkeynes@2
   124
        case IDELBA1:
nkeynes@2
   125
            if( ide_can_write_regs() )
nkeynes@2
   126
                idereg.lba1 = (uint8_t)val;
nkeynes@2
   127
            break;
nkeynes@2
   128
        case IDELBA2:
nkeynes@2
   129
            if( ide_can_write_regs() )
nkeynes@2
   130
                idereg.lba2 = (uint8_t)val;
nkeynes@2
   131
            break;
nkeynes@2
   132
        case IDEDEV:
nkeynes@2
   133
            if( ide_can_write_regs() )
nkeynes@2
   134
                idereg.device = (uint8_t)val;
nkeynes@2
   135
            break;
nkeynes@2
   136
        case IDECMD:
nkeynes@2
   137
            if( ide_can_write_regs() ) {
nkeynes@2
   138
                ide_clear_interrupt();
nkeynes@2
   139
                ide_write_command( (uint8_t)val );
nkeynes@2
   140
            }
nkeynes@2
   141
            break;
nkeynes@2
   142
            
nkeynes@2
   143
        default:
nkeynes@2
   144
            MMIO_WRITE( EXTDMA, reg, val );
nkeynes@2
   145
    }
nkeynes@1
   146
}
nkeynes@1
   147
nkeynes@1
   148
MMIO_REGION_READ_FN( EXTDMA, reg )
nkeynes@1
   149
{
nkeynes@1
   150
    switch( reg ) {
nkeynes@2
   151
        case IDEALTSTATUS: return idereg.status;
nkeynes@2
   152
        case IDEDATA: return ide_read_data_pio( );
nkeynes@2
   153
        case IDEFEAT: return idereg.error;
nkeynes@2
   154
        case IDECOUNT:return idereg.count;
nkeynes@2
   155
        case IDELBA0: return idereg.disc;
nkeynes@2
   156
        case IDELBA1: return idereg.lba1;
nkeynes@2
   157
        case IDELBA2: return idereg.lba2;
nkeynes@2
   158
        case IDEDEV: return idereg.device;
nkeynes@2
   159
        case IDECMD:
nkeynes@2
   160
            ide_clear_interrupt();
nkeynes@2
   161
            return idereg.status;
nkeynes@1
   162
        default:
nkeynes@1
   163
            return MMIO_READ( EXTDMA, reg );
nkeynes@1
   164
    }
nkeynes@1
   165
}
nkeynes@1
   166
.