Search
lxdream.org :: lxdream/src/sh4/sh4mem.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4mem.c
changeset 418:b9b14afa0959
prev406:9289b62f8f33
next419:09f85e586ff2
author nkeynes
date Thu Oct 04 08:47:52 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Add explicit branch cases for main ram - yes it's faster...
file annotate diff log raw
nkeynes@10
     1
/**
nkeynes@418
     2
 * $Id: sh4mem.c,v 1.25 2007-10-04 08:47:52 nkeynes Exp $
nkeynes@10
     3
 * sh4mem.c is responsible for the SH4's access to memory (including memory
nkeynes@10
     4
 * mapped I/O), using the page maps created in mem.c
nkeynes@10
     5
 *
nkeynes@10
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@10
     7
 *
nkeynes@10
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@10
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@10
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@10
    11
 * (at your option) any later version.
nkeynes@10
    12
 *
nkeynes@10
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@10
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@10
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@10
    16
 * GNU General Public License for more details.
nkeynes@10
    17
 */
nkeynes@10
    18
nkeynes@35
    19
#define MODULE sh4_module
nkeynes@35
    20
nkeynes@10
    21
#include <string.h>
nkeynes@10
    22
#include <zlib.h>
nkeynes@10
    23
#include "dream.h"
nkeynes@10
    24
#include "mem.h"
nkeynes@10
    25
#include "mmio.h"
nkeynes@70
    26
#include "sh4core.h"
nkeynes@10
    27
#include "sh4mmio.h"
nkeynes@10
    28
#include "dreamcast.h"
nkeynes@100
    29
#include "pvr2/pvr2.h"
nkeynes@10
    30
nkeynes@10
    31
#define OC_BASE 0x1C000000
nkeynes@10
    32
#define OC_TOP  0x20000000
nkeynes@10
    33
nkeynes@90
    34
#define TRANSLATE_VIDEO_64BIT_ADDRESS(a)  ( (((a)&0x00FFFFF8)>>1)|(((a)&0x00000004)<<20)|((a)&0x03)|0x05000000 )
nkeynes@10
    35
nkeynes@10
    36
#ifdef ENABLE_WATCH
nkeynes@10
    37
#define CHECK_READ_WATCH( addr, size ) \
nkeynes@10
    38
    if( mem_is_watched(addr,size,WATCH_READ) != NULL ) { \
nkeynes@10
    39
        WARN( "Watch triggered at %08X by %d byte read", addr, size ); \
nkeynes@10
    40
        dreamcast_stop(); \
nkeynes@10
    41
    }
nkeynes@10
    42
#define CHECK_WRITE_WATCH( addr, size, val )                  \
nkeynes@10
    43
    if( mem_is_watched(addr,size,WATCH_WRITE) != NULL ) { \
nkeynes@10
    44
        WARN( "Watch triggered at %08X by %d byte write <= %0*X", addr, size, size*2, val ); \
nkeynes@10
    45
        dreamcast_stop(); \
nkeynes@10
    46
    }
nkeynes@10
    47
#else
nkeynes@10
    48
#define CHECK_READ_WATCH( addr, size )
nkeynes@234
    49
#define CHECK_WRITE_WATCH( addr, size, val )
nkeynes@10
    50
#endif
nkeynes@10
    51
nkeynes@406
    52
#ifdef ENABLE_TRACE_IO
nkeynes@172
    53
#define TRACE_IO( str, p, r, ... ) if(io_rgn[(uint32_t)p]->trace_flag && !MMIO_NOTRACE_BYNUM((uint32_t)p,r)) \
nkeynes@172
    54
    TRACE( str " [%s.%s: %s]", __VA_ARGS__,			       \
nkeynes@10
    55
    MMIO_NAME_BYNUM((uint32_t)p), MMIO_REGID_BYNUM((uint32_t)p, r), \
nkeynes@10
    56
    MMIO_REGDESC_BYNUM((uint32_t)p, r) )
nkeynes@172
    57
#define TRACE_P4IO( str, io, r, ... ) if(io->trace_flag && !MMIO_NOTRACE_IOBYNUM(io,r)) \
nkeynes@156
    58
TRACE( str " [%s.%s: %s]", __VA_ARGS__, \
nkeynes@156
    59
    io->id, MMIO_REGID_IOBYNUM(io, r), \
nkeynes@156
    60
    MMIO_REGDESC_IOBYNUM(io, r) )
nkeynes@406
    61
#else
nkeynes@406
    62
#define TRACE_IO( str, p, r, ... )
nkeynes@406
    63
#define TRACE_P4IO( str, io, r, ... )
nkeynes@406
    64
#endif
nkeynes@10
    65
nkeynes@10
    66
extern struct mem_region mem_rgn[];
nkeynes@10
    67
extern struct mmio_region *P4_io[];
nkeynes@418
    68
char *sh4_main_ram;
nkeynes@10
    69
nkeynes@10
    70
int32_t sh4_read_p4( uint32_t addr )
nkeynes@10
    71
{
nkeynes@10
    72
    struct mmio_region *io = P4_io[(addr&0x1FFFFFFF)>>19];
nkeynes@10
    73
    if( !io ) {
nkeynes@282
    74
        if( (addr & 0xFF000000) != 0xF4000000 ) {
nkeynes@282
    75
	    /* OC address cache isn't implemented, but don't complain about it.
nkeynes@282
    76
	     * Complain about anything else though */
nkeynes@282
    77
            ERROR( "Attempted read from unknown P4 region: %08X", addr );
nkeynes@282
    78
        }
nkeynes@10
    79
        return 0;
nkeynes@10
    80
    } else {
nkeynes@156
    81
	int32_t val = io->io_read( addr&0xFFF );
nkeynes@156
    82
	TRACE_P4IO( "Long read %08X <= %08X", io, (addr&0xFFF), val, addr );
nkeynes@156
    83
        return val;
nkeynes@10
    84
    }    
nkeynes@10
    85
}
nkeynes@10
    86
nkeynes@10
    87
void sh4_write_p4( uint32_t addr, int32_t val )
nkeynes@10
    88
{
nkeynes@10
    89
    struct mmio_region *io = P4_io[(addr&0x1FFFFFFF)>>19];
nkeynes@10
    90
    if( !io ) {
nkeynes@10
    91
        if( (addr & 0xFC000000) == 0xE0000000 ) {
nkeynes@10
    92
            /* Store queue */
nkeynes@10
    93
            SH4_WRITE_STORE_QUEUE( addr, val );
nkeynes@38
    94
        } else if( (addr & 0xFF000000) != 0xF4000000 ) {
nkeynes@38
    95
	    /* OC address cache isn't implemented, but don't complain about it.
nkeynes@38
    96
	     * Complain about anything else though */
nkeynes@10
    97
            ERROR( "Attempted write to unknown P4 region: %08X", addr );
nkeynes@10
    98
        }
nkeynes@10
    99
    } else {
nkeynes@156
   100
	TRACE_P4IO( "Long write %08X => %08X", io, (addr&0xFFF), val, addr );
nkeynes@10
   101
        io->io_write( addr&0xFFF, val );
nkeynes@10
   102
    }
nkeynes@10
   103
}
nkeynes@10
   104
nkeynes@10
   105
int32_t sh4_read_phys_word( uint32_t addr )
nkeynes@10
   106
{
nkeynes@10
   107
    char *page;
nkeynes@83
   108
    if( addr >= 0xE0000000 ) /* P4 Area, handled specially */
nkeynes@10
   109
        return SIGNEXT16(sh4_read_p4( addr ));
nkeynes@10
   110
    
nkeynes@10
   111
    if( (addr&0x1F800000) == 0x04000000 ) {
nkeynes@10
   112
        addr = TRANSLATE_VIDEO_64BIT_ADDRESS(addr);
nkeynes@10
   113
    }
nkeynes@10
   114
nkeynes@10
   115
    page = page_map[ (addr & 0x1FFFFFFF) >> 12 ];
nkeynes@10
   116
    if( ((uint32_t)page) < MAX_IO_REGIONS ) { /* IO Region */
nkeynes@10
   117
        if( page == NULL ) {
nkeynes@10
   118
            ERROR( "Attempted word read to missing page: %08X",
nkeynes@10
   119
                   addr );
nkeynes@10
   120
            return 0;
nkeynes@10
   121
        }
nkeynes@10
   122
        return SIGNEXT16(io_rgn[(uint32_t)page]->io_read(addr&0xFFF));
nkeynes@10
   123
    } else {
nkeynes@10
   124
        return SIGNEXT16(*(int16_t *)(page+(addr&0xFFF)));
nkeynes@10
   125
    }
nkeynes@10
   126
}
nkeynes@10
   127
nkeynes@10
   128
int32_t sh4_read_long( uint32_t addr )
nkeynes@10
   129
{
nkeynes@10
   130
    char *page;
nkeynes@10
   131
    
nkeynes@10
   132
    CHECK_READ_WATCH(addr,4);
nkeynes@10
   133
nkeynes@418
   134
    if( addr >= 0xE0000000 ) { /* P4 Area, handled specially */
nkeynes@10
   135
        return sh4_read_p4( addr );
nkeynes@418
   136
    } else if( (addr&0x1C000000) == 0x0C000000 ) {
nkeynes@418
   137
	return *(int32_t *)(sh4_main_ram + (addr&0x00FFFFFF));
nkeynes@418
   138
    } else if( (addr&0x1F800000) == 0x04000000 ) {
nkeynes@10
   139
        addr = TRANSLATE_VIDEO_64BIT_ADDRESS(addr);
nkeynes@355
   140
	pvr2_render_buffer_invalidate(addr, FALSE);
nkeynes@217
   141
    } else if( (addr&0x1F800000) == 0x05000000 ) {
nkeynes@355
   142
	pvr2_render_buffer_invalidate(addr, FALSE);
nkeynes@10
   143
    }
nkeynes@10
   144
nkeynes@10
   145
    page = page_map[ (addr & 0x1FFFFFFF) >> 12 ];
nkeynes@10
   146
    if( ((uint32_t)page) < MAX_IO_REGIONS ) { /* IO Region */
nkeynes@10
   147
        int32_t val;
nkeynes@10
   148
        if( page == NULL ) {
nkeynes@10
   149
            ERROR( "Attempted long read to missing page: %08X", addr );
nkeynes@10
   150
            return 0;
nkeynes@10
   151
        }
nkeynes@10
   152
        val = io_rgn[(uint32_t)page]->io_read(addr&0xFFF);
nkeynes@10
   153
        TRACE_IO( "Long read %08X <= %08X", page, (addr&0xFFF), val, addr );
nkeynes@10
   154
        return val;
nkeynes@10
   155
    } else {
nkeynes@10
   156
        return *(int32_t *)(page+(addr&0xFFF));
nkeynes@10
   157
    }
nkeynes@10
   158
}
nkeynes@10
   159
nkeynes@10
   160
int32_t sh4_read_word( uint32_t addr )
nkeynes@10
   161
{
nkeynes@10
   162
    char *page;
nkeynes@10
   163
nkeynes@10
   164
    CHECK_READ_WATCH(addr,2);
nkeynes@10
   165
nkeynes@418
   166
    if( addr >= 0xE0000000 ) { /* P4 Area, handled specially */
nkeynes@10
   167
        return SIGNEXT16(sh4_read_p4( addr ));
nkeynes@418
   168
    } else if( (addr&0x1C000000) == 0x0C000000 ) {
nkeynes@418
   169
	return SIGNEXT16(*(int16_t *)(sh4_main_ram + (addr&0x00FFFFFF)));
nkeynes@418
   170
    } else if( (addr&0x1F800000) == 0x04000000 ) {
nkeynes@10
   171
        addr = TRANSLATE_VIDEO_64BIT_ADDRESS(addr);
nkeynes@355
   172
	pvr2_render_buffer_invalidate(addr, FALSE);
nkeynes@217
   173
    } else if( (addr&0x1F800000) == 0x05000000 ) {
nkeynes@355
   174
	pvr2_render_buffer_invalidate(addr, FALSE);
nkeynes@10
   175
    }
nkeynes@217
   176
    
nkeynes@10
   177
    page = page_map[ (addr & 0x1FFFFFFF) >> 12 ];
nkeynes@10
   178
    if( ((uint32_t)page) < MAX_IO_REGIONS ) { /* IO Region */
nkeynes@10
   179
        int32_t val;
nkeynes@10
   180
        if( page == NULL ) {
nkeynes@10
   181
            ERROR( "Attempted word read to missing page: %08X", addr );
nkeynes@10
   182
            return 0;
nkeynes@10
   183
        }
nkeynes@10
   184
        val = SIGNEXT16(io_rgn[(uint32_t)page]->io_read(addr&0xFFF));
nkeynes@10
   185
        TRACE_IO( "Word read %04X <= %08X", page, (addr&0xFFF), val&0xFFFF, addr );
nkeynes@10
   186
        return val;
nkeynes@10
   187
    } else {
nkeynes@10
   188
        return SIGNEXT16(*(int16_t *)(page+(addr&0xFFF)));
nkeynes@10
   189
    }
nkeynes@10
   190
}
nkeynes@10
   191
nkeynes@10
   192
int32_t sh4_read_byte( uint32_t addr )
nkeynes@10
   193
{
nkeynes@10
   194
    char *page;
nkeynes@10
   195
nkeynes@10
   196
    CHECK_READ_WATCH(addr,1);
nkeynes@10
   197
nkeynes@418
   198
    if( addr >= 0xE0000000 ) { /* P4 Area, handled specially */
nkeynes@10
   199
        return SIGNEXT8(sh4_read_p4( addr ));
nkeynes@418
   200
    } else if( (addr&0x1C000000) == 0x0C000000 ) {
nkeynes@418
   201
	return SIGNEXT8(*(int8_t *)(sh4_main_ram + (addr&0x00FFFFFF)));
nkeynes@418
   202
    } else if( (addr&0x1F800000) == 0x04000000 ) {
nkeynes@10
   203
        addr = TRANSLATE_VIDEO_64BIT_ADDRESS(addr);
nkeynes@355
   204
    	pvr2_render_buffer_invalidate(addr, FALSE);
nkeynes@217
   205
    } else if( (addr&0x1F800000) == 0x05000000 ) {
nkeynes@355
   206
	pvr2_render_buffer_invalidate(addr, FALSE);
nkeynes@10
   207
    }
nkeynes@217
   208
nkeynes@10
   209
    
nkeynes@10
   210
    page = page_map[ (addr & 0x1FFFFFFF) >> 12 ];
nkeynes@10
   211
    if( ((uint32_t)page) < MAX_IO_REGIONS ) { /* IO Region */
nkeynes@10
   212
        int32_t val;
nkeynes@10
   213
        if( page == NULL ) {
nkeynes@10
   214
            ERROR( "Attempted byte read to missing page: %08X", addr );
nkeynes@10
   215
            return 0;
nkeynes@10
   216
        }
nkeynes@10
   217
        val = SIGNEXT8(io_rgn[(uint32_t)page]->io_read(addr&0xFFF));
nkeynes@10
   218
        TRACE_IO( "Byte read %02X <= %08X", page, (addr&0xFFF), val&0xFF, addr );
nkeynes@10
   219
        return val;
nkeynes@10
   220
    } else {
nkeynes@10
   221
        return SIGNEXT8(*(int8_t *)(page+(addr&0xFFF)));
nkeynes@10
   222
    }
nkeynes@10
   223
}
nkeynes@10
   224
nkeynes@10
   225
void sh4_write_long( uint32_t addr, uint32_t val )
nkeynes@10
   226
{
nkeynes@10
   227
    char *page;
nkeynes@400
   228
nkeynes@400
   229
    // fprintf( stderr, "MOV.L %08X => %08X\n", val, addr );
nkeynes@10
   230
    CHECK_WRITE_WATCH(addr,4,val);
nkeynes@10
   231
nkeynes@83
   232
    if( addr >= 0xE0000000 ) {
nkeynes@10
   233
        sh4_write_p4( addr, val );
nkeynes@10
   234
        return;
nkeynes@418
   235
    } else if( (addr&0x1C000000) == 0x0C000000 ) {
nkeynes@418
   236
	*(uint32_t *)(sh4_main_ram + (addr&0x00FFFFFF)) = val;
nkeynes@418
   237
	return;
nkeynes@418
   238
    } else if( (addr&0x1F800000) == 0x04000000 || 
nkeynes@418
   239
	       (addr&0x1F800000) == 0x11000000 ) {
nkeynes@150
   240
	texcache_invalidate_page(addr& 0x7FFFFF);
nkeynes@10
   241
        addr = TRANSLATE_VIDEO_64BIT_ADDRESS(addr);
nkeynes@355
   242
	pvr2_render_buffer_invalidate(addr, TRUE);
nkeynes@165
   243
    } else if( (addr&0x1F800000) == 0x05000000 ) {
nkeynes@355
   244
	pvr2_render_buffer_invalidate(addr, TRUE);
nkeynes@10
   245
    }
nkeynes@10
   246
nkeynes@10
   247
    if( (addr&0x1FFFFFFF) < 0x200000 ) {
nkeynes@10
   248
        ERROR( "Attempted write to read-only memory: %08X => %08X", val, addr);
nkeynes@10
   249
        sh4_stop();
nkeynes@10
   250
        return;
nkeynes@10
   251
    }
nkeynes@137
   252
    if( (addr&0x1F800000) == 0x00800000 )
nkeynes@137
   253
	asic_g2_write_word();
nkeynes@137
   254
nkeynes@10
   255
    page = page_map[ (addr & 0x1FFFFFFF) >> 12 ];
nkeynes@10
   256
    if( ((uint32_t)page) < MAX_IO_REGIONS ) { /* IO Region */
nkeynes@10
   257
        if( page == NULL ) {
nkeynes@137
   258
	    if( (addr & 0x1F000000) >= 0x04000000 &&
nkeynes@137
   259
		(addr & 0x1F000000) < 0x07000000 )
nkeynes@137
   260
		return;
nkeynes@10
   261
            ERROR( "Long write to missing page: %08X => %08X", val, addr );
nkeynes@10
   262
            return;
nkeynes@10
   263
        }
nkeynes@10
   264
        TRACE_IO( "Long write %08X => %08X", page, (addr&0xFFF), val, addr );
nkeynes@10
   265
        io_rgn[(uint32_t)page]->io_write(addr&0xFFF, val);
nkeynes@10
   266
    } else {
nkeynes@400
   267
	xlat_invalidate_long(addr);
nkeynes@10
   268
        *(uint32_t *)(page+(addr&0xFFF)) = val;
nkeynes@10
   269
    }
nkeynes@10
   270
}
nkeynes@10
   271
nkeynes@10
   272
void sh4_write_word( uint32_t addr, uint32_t val )
nkeynes@10
   273
{
nkeynes@10
   274
    char *page;
nkeynes@10
   275
nkeynes@400
   276
    //    fprintf( stderr, "MOV.W %04X => %08X\n", val, addr );
nkeynes@10
   277
    CHECK_WRITE_WATCH(addr,2,val);
nkeynes@10
   278
nkeynes@83
   279
    if( addr >= 0xE0000000 ) {
nkeynes@10
   280
        sh4_write_p4( addr, (int16_t)val );
nkeynes@10
   281
        return;
nkeynes@418
   282
    } else if( (addr&0x1C000000) == 0x0C000000 ) {
nkeynes@418
   283
	*(uint16_t *)(sh4_main_ram + (addr&0x00FFFFFF)) = val;
nkeynes@418
   284
	return;
nkeynes@418
   285
    } else if( (addr&0x1F800000) == 0x04000000 ||
nkeynes@130
   286
	(addr&0x1F800000) == 0x11000000 ) {
nkeynes@150
   287
	texcache_invalidate_page(addr& 0x7FFFFF);
nkeynes@10
   288
        addr = TRANSLATE_VIDEO_64BIT_ADDRESS(addr);
nkeynes@355
   289
	pvr2_render_buffer_invalidate(addr, TRUE);
nkeynes@165
   290
    } else if( (addr&0x1F800000) == 0x05000000 ) {
nkeynes@355
   291
	pvr2_render_buffer_invalidate(addr, TRUE);
nkeynes@10
   292
    }
nkeynes@406
   293
nkeynes@400
   294
    if( (addr&0x1FFFFFFF) < 0x200000 ) {
nkeynes@400
   295
        ERROR( "Attempted write to read-only memory: %08X => %08X", val, addr);
nkeynes@400
   296
        sh4_stop();
nkeynes@400
   297
        return;
nkeynes@400
   298
    }
nkeynes@10
   299
    page = page_map[ (addr & 0x1FFFFFFF) >> 12 ];
nkeynes@10
   300
    if( ((uint32_t)page) < MAX_IO_REGIONS ) { /* IO Region */
nkeynes@10
   301
        if( page == NULL ) {
nkeynes@10
   302
            ERROR( "Attempted word write to missing page: %08X", addr );
nkeynes@10
   303
            return;
nkeynes@10
   304
        }
nkeynes@10
   305
        TRACE_IO( "Word write %04X => %08X", page, (addr&0xFFF), val&0xFFFF, addr );
nkeynes@10
   306
        io_rgn[(uint32_t)page]->io_write(addr&0xFFF, val);
nkeynes@10
   307
    } else {
nkeynes@400
   308
	xlat_invalidate_word(addr);
nkeynes@10
   309
        *(uint16_t *)(page+(addr&0xFFF)) = val;
nkeynes@10
   310
    }
nkeynes@10
   311
}
nkeynes@10
   312
nkeynes@10
   313
void sh4_write_byte( uint32_t addr, uint32_t val )
nkeynes@10
   314
{
nkeynes@10
   315
    char *page;
nkeynes@10
   316
    
nkeynes@400
   317
    //    fprintf( stderr, "MOV.B %02X => %08X\n", val, addr );
nkeynes@10
   318
    CHECK_WRITE_WATCH(addr,1,val);
nkeynes@10
   319
nkeynes@83
   320
    if( addr >= 0xE0000000 ) {
nkeynes@10
   321
        sh4_write_p4( addr, (int8_t)val );
nkeynes@10
   322
        return;
nkeynes@418
   323
    } else if( (addr&0x1C000000) == 0x0C000000 ) {
nkeynes@418
   324
	*(uint8_t *)(sh4_main_ram + (addr&0x00FFFFFF)) = val;
nkeynes@418
   325
	return;
nkeynes@418
   326
    } else if( (addr&0x1F800000) == 0x04000000 ||
nkeynes@418
   327
	       (addr&0x1F800000) == 0x11000000 ) {
nkeynes@150
   328
	texcache_invalidate_page(addr& 0x7FFFFF);
nkeynes@10
   329
        addr = TRANSLATE_VIDEO_64BIT_ADDRESS(addr);
nkeynes@355
   330
	pvr2_render_buffer_invalidate(addr, TRUE);
nkeynes@165
   331
    } else if( (addr&0x1F800000) == 0x05000000 ) {
nkeynes@355
   332
	pvr2_render_buffer_invalidate(addr, TRUE);
nkeynes@10
   333
    }
nkeynes@10
   334
    
nkeynes@400
   335
    if( (addr&0x1FFFFFFF) < 0x200000 ) {
nkeynes@400
   336
        ERROR( "Attempted write to read-only memory: %08X => %08X", val, addr);
nkeynes@400
   337
        sh4_stop();
nkeynes@400
   338
        return;
nkeynes@400
   339
    }
nkeynes@10
   340
    page = page_map[ (addr & 0x1FFFFFFF) >> 12 ];
nkeynes@10
   341
    if( ((uint32_t)page) < MAX_IO_REGIONS ) { /* IO Region */
nkeynes@10
   342
        if( page == NULL ) {
nkeynes@10
   343
            ERROR( "Attempted byte write to missing page: %08X", addr );
nkeynes@10
   344
            return;
nkeynes@10
   345
        }
nkeynes@10
   346
        TRACE_IO( "Byte write %02X => %08X", page, (addr&0xFFF), val&0xFF, addr );
nkeynes@10
   347
        io_rgn[(uint32_t)page]->io_write( (addr&0xFFF), val);
nkeynes@10
   348
    } else {
nkeynes@400
   349
	xlat_invalidate_word(addr);
nkeynes@10
   350
        *(uint8_t *)(page+(addr&0xFFF)) = val;
nkeynes@10
   351
    }
nkeynes@10
   352
}
nkeynes@10
   353
nkeynes@10
   354
nkeynes@10
   355
nkeynes@10
   356
/* FIXME: Handle all the many special cases when the range doesn't fall cleanly
nkeynes@400
   357
 * into the same memory block
nkeynes@10
   358
 */
nkeynes@10
   359
void mem_copy_from_sh4( char *dest, uint32_t srcaddr, size_t count ) {
nkeynes@103
   360
    if( srcaddr >= 0x04000000 && srcaddr < 0x05000000 ) {
nkeynes@103
   361
	pvr2_vram64_read( dest, srcaddr, count );
nkeynes@103
   362
    } else {
nkeynes@103
   363
	char *src = mem_get_region(srcaddr);
nkeynes@103
   364
	if( src == NULL ) {
nkeynes@103
   365
	    ERROR( "Attempted block read from unknown address %08X", srcaddr );
nkeynes@103
   366
	} else {
nkeynes@103
   367
	    memcpy( dest, src, count );
nkeynes@103
   368
	}
nkeynes@103
   369
    }
nkeynes@10
   370
}
nkeynes@10
   371
nkeynes@10
   372
void mem_copy_to_sh4( uint32_t destaddr, char *src, size_t count ) {
nkeynes@325
   373
    int region;
nkeynes@325
   374
nkeynes@325
   375
    if( destaddr >= 0x10000000 && destaddr < 0x14000000 ) {
nkeynes@325
   376
	pvr2_dma_write( destaddr, src, count );
nkeynes@325
   377
	return;
nkeynes@325
   378
    } else if( (destaddr & 0x1F800000) == 0x05000000 ) {
nkeynes@355
   379
	pvr2_render_buffer_invalidate( destaddr, TRUE );
nkeynes@325
   380
    } else if( (destaddr & 0x1F800000) == 0x04000000 ) {
nkeynes@103
   381
	pvr2_vram64_write( destaddr, src, count );
nkeynes@325
   382
	return;
nkeynes@325
   383
    }
nkeynes@325
   384
    char *dest = mem_get_region(destaddr);
nkeynes@325
   385
    if( dest == NULL )
nkeynes@325
   386
	ERROR( "Attempted block write to unknown address %08X", destaddr );
nkeynes@325
   387
    else {
nkeynes@400
   388
	xlat_invalidate_block( destaddr, count );
nkeynes@325
   389
	memcpy( dest, src, count );
nkeynes@90
   390
    }
nkeynes@10
   391
}
nkeynes@369
   392
nkeynes@369
   393
void sh4_flush_store_queue( uint32_t addr )
nkeynes@369
   394
{
nkeynes@369
   395
    /* Store queue operation */
nkeynes@369
   396
    int queue = (addr&0x20)>>2;
nkeynes@371
   397
    char *src = (char *)&sh4r.store_queue[queue];
nkeynes@369
   398
    uint32_t hi = (MMIO_READ( MMU, (queue == 0 ? QACR0 : QACR1) ) & 0x1C) << 24;
nkeynes@369
   399
    uint32_t target = addr&0x03FFFFE0 | hi;
nkeynes@369
   400
    mem_copy_to_sh4( target, src, 32 );
nkeynes@369
   401
}
.