Search
lxdream.org :: lxdream/src/pvr2/pvr2.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/pvr2.c
changeset 193:31151fcc3cb7
prev191:df4441cf3128
next197:f65ff8c8320d
author nkeynes
date Fri Aug 04 01:38:30 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Add more tile list limit tests
Implement tile list limits in the ta core.
Rename TA_TILEEND to TA_LISTEND
file annotate diff log raw
nkeynes@31
     1
/**
nkeynes@193
     2
 * $Id: pvr2.c,v 1.30 2006-08-04 01:38:27 nkeynes Exp $
nkeynes@31
     3
 *
nkeynes@133
     4
 * PVR2 (Video) Core module implementation and MMIO registers.
nkeynes@31
     5
 *
nkeynes@31
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@31
     7
 *
nkeynes@31
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@31
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@31
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@31
    11
 * (at your option) any later version.
nkeynes@31
    12
 *
nkeynes@31
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@31
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@31
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@31
    16
 * GNU General Public License for more details.
nkeynes@31
    17
 */
nkeynes@35
    18
#define MODULE pvr2_module
nkeynes@31
    19
nkeynes@1
    20
#include "dream.h"
nkeynes@144
    21
#include "display.h"
nkeynes@1
    22
#include "mem.h"
nkeynes@1
    23
#include "asic.h"
nkeynes@103
    24
#include "pvr2/pvr2.h"
nkeynes@56
    25
#include "sh4/sh4core.h"
nkeynes@1
    26
#define MMIO_IMPL
nkeynes@103
    27
#include "pvr2/pvr2mmio.h"
nkeynes@1
    28
nkeynes@1
    29
char *video_base;
nkeynes@1
    30
nkeynes@133
    31
static void pvr2_init( void );
nkeynes@133
    32
static void pvr2_reset( void );
nkeynes@133
    33
static uint32_t pvr2_run_slice( uint32_t );
nkeynes@133
    34
static void pvr2_save_state( FILE *f );
nkeynes@133
    35
static int pvr2_load_state( FILE *f );
nkeynes@133
    36
nkeynes@94
    37
void pvr2_display_frame( void );
nkeynes@94
    38
nkeynes@161
    39
int colour_format_bytes[] = { 2, 2, 2, 1, 3, 4, 1, 1 };
nkeynes@161
    40
nkeynes@133
    41
struct dreamcast_module pvr2_module = { "PVR2", pvr2_init, pvr2_reset, NULL, 
nkeynes@133
    42
					pvr2_run_slice, NULL,
nkeynes@133
    43
					pvr2_save_state, pvr2_load_state };
nkeynes@133
    44
nkeynes@103
    45
nkeynes@144
    46
display_driver_t display_driver = NULL;
nkeynes@15
    47
nkeynes@103
    48
struct video_timing {
nkeynes@103
    49
    int fields_per_second;
nkeynes@103
    50
    int total_lines;
nkeynes@108
    51
    int retrace_lines;
nkeynes@103
    52
    int line_time_ns;
nkeynes@103
    53
};
nkeynes@103
    54
nkeynes@133
    55
struct video_timing pal_timing = { 50, 625, 65, 32000 };
nkeynes@108
    56
struct video_timing ntsc_timing= { 60, 525, 65, 31746 };
nkeynes@103
    57
nkeynes@133
    58
struct pvr2_state {
nkeynes@133
    59
    uint32_t frame_count;
nkeynes@133
    60
    uint32_t line_count;
nkeynes@133
    61
    uint32_t line_remainder;
nkeynes@133
    62
    uint32_t irq_vpos1;
nkeynes@133
    63
    uint32_t irq_vpos2;
nkeynes@133
    64
    gboolean retrace;
nkeynes@133
    65
    struct video_timing timing;
nkeynes@133
    66
} pvr2_state;
nkeynes@15
    67
nkeynes@133
    68
struct video_buffer video_buffer[2];
nkeynes@133
    69
int video_buffer_idx = 0;
nkeynes@133
    70
nkeynes@133
    71
static void pvr2_init( void )
nkeynes@1
    72
{
nkeynes@1
    73
    register_io_region( &mmio_region_PVR2 );
nkeynes@85
    74
    register_io_region( &mmio_region_PVR2PAL );
nkeynes@56
    75
    register_io_region( &mmio_region_PVR2TA );
nkeynes@1
    76
    video_base = mem_get_region_by_name( MEM_REGION_VIDEO );
nkeynes@133
    77
    texcache_init();
nkeynes@133
    78
    pvr2_reset();
nkeynes@133
    79
}
nkeynes@133
    80
nkeynes@133
    81
static void pvr2_reset( void )
nkeynes@133
    82
{
nkeynes@133
    83
    pvr2_state.line_count = 0;
nkeynes@133
    84
    pvr2_state.line_remainder = 0;
nkeynes@133
    85
    pvr2_state.irq_vpos1 = 0;
nkeynes@133
    86
    pvr2_state.irq_vpos2 = 0;
nkeynes@133
    87
    pvr2_state.retrace = FALSE;
nkeynes@133
    88
    pvr2_state.timing = ntsc_timing;
nkeynes@133
    89
    video_buffer_idx = 0;
nkeynes@133
    90
    
nkeynes@133
    91
    pvr2_ta_init();
nkeynes@107
    92
    pvr2_render_init();
nkeynes@133
    93
    texcache_flush();
nkeynes@133
    94
}
nkeynes@133
    95
nkeynes@133
    96
static void pvr2_save_state( FILE *f )
nkeynes@133
    97
{
nkeynes@133
    98
    fwrite( &pvr2_state, sizeof(pvr2_state), 1, f );
nkeynes@193
    99
    pvr2_ta_save_state( f );
nkeynes@133
   100
}
nkeynes@133
   101
nkeynes@133
   102
static int pvr2_load_state( FILE *f )
nkeynes@133
   103
{
nkeynes@153
   104
    if( fread( &pvr2_state, sizeof(pvr2_state), 1, f ) != 1 )
nkeynes@153
   105
	return 1;
nkeynes@193
   106
    return pvr2_ta_load_state(f);
nkeynes@133
   107
}
nkeynes@133
   108
nkeynes@133
   109
static uint32_t pvr2_run_slice( uint32_t nanosecs ) 
nkeynes@133
   110
{
nkeynes@133
   111
    pvr2_state.line_remainder += nanosecs;
nkeynes@133
   112
    while( pvr2_state.line_remainder >= pvr2_state.timing.line_time_ns ) {
nkeynes@133
   113
	pvr2_state.line_remainder -= pvr2_state.timing.line_time_ns;
nkeynes@133
   114
nkeynes@133
   115
	pvr2_state.line_count++;
nkeynes@133
   116
	if( pvr2_state.line_count == pvr2_state.timing.total_lines ) {
nkeynes@133
   117
	    asic_event( EVENT_RETRACE );
nkeynes@133
   118
	    pvr2_state.line_count = 0;
nkeynes@133
   119
	    pvr2_state.retrace = TRUE;
nkeynes@133
   120
	}
nkeynes@133
   121
nkeynes@133
   122
	if( pvr2_state.line_count == pvr2_state.irq_vpos1 ) {
nkeynes@133
   123
	    asic_event( EVENT_SCANLINE1 );
nkeynes@133
   124
	} 
nkeynes@133
   125
	if( pvr2_state.line_count == pvr2_state.irq_vpos2 ) {
nkeynes@133
   126
	    asic_event( EVENT_SCANLINE2 );
nkeynes@133
   127
	}
nkeynes@133
   128
nkeynes@133
   129
	if( pvr2_state.line_count == pvr2_state.timing.retrace_lines ) {
nkeynes@133
   130
	    if( pvr2_state.retrace ) {
nkeynes@133
   131
		pvr2_display_frame();
nkeynes@133
   132
		pvr2_state.retrace = FALSE;
nkeynes@133
   133
	    }
nkeynes@133
   134
	}
nkeynes@133
   135
    }
nkeynes@133
   136
    return nanosecs;
nkeynes@133
   137
}
nkeynes@133
   138
nkeynes@133
   139
int pvr2_get_frame_count() 
nkeynes@133
   140
{
nkeynes@133
   141
    return pvr2_state.frame_count;
nkeynes@106
   142
}
nkeynes@106
   143
nkeynes@103
   144
/**
nkeynes@1
   145
 * Display the next frame, copying the current contents of video ram to
nkeynes@1
   146
 * the window. If the video configuration has changed, first recompute the
nkeynes@1
   147
 * new frame size/depth.
nkeynes@1
   148
 */
nkeynes@94
   149
void pvr2_display_frame( void )
nkeynes@1
   150
{
nkeynes@103
   151
    uint32_t display_addr = MMIO_READ( PVR2, DISPADDR1 );
nkeynes@103
   152
    
nkeynes@94
   153
    int dispsize = MMIO_READ( PVR2, DISPSIZE );
nkeynes@94
   154
    int dispmode = MMIO_READ( PVR2, DISPMODE );
nkeynes@103
   155
    int vidcfg = MMIO_READ( PVR2, DISPCFG );
nkeynes@94
   156
    int vid_stride = ((dispsize & DISPSIZE_MODULO) >> 20) - 1;
nkeynes@94
   157
    int vid_lpf = ((dispsize & DISPSIZE_LPF) >> 10) + 1;
nkeynes@94
   158
    int vid_ppl = ((dispsize & DISPSIZE_PPL)) + 1;
nkeynes@103
   159
    gboolean bEnabled = (dispmode & DISPMODE_DE) && (vidcfg & DISPCFG_VO ) ? TRUE : FALSE;
nkeynes@103
   160
    gboolean interlaced = (vidcfg & DISPCFG_I ? TRUE : FALSE);
nkeynes@161
   161
    video_buffer_t buffer = &video_buffer[video_buffer_idx];
nkeynes@161
   162
    video_buffer_idx = !video_buffer_idx;
nkeynes@161
   163
    video_buffer_t last = &video_buffer[video_buffer_idx];
nkeynes@161
   164
    buffer->rowstride = (vid_ppl + vid_stride) << 2;
nkeynes@161
   165
    buffer->data = video_base + MMIO_READ( PVR2, DISPADDR1 );
nkeynes@161
   166
    buffer->vres = vid_lpf;
nkeynes@161
   167
    if( interlaced ) buffer->vres <<= 1;
nkeynes@161
   168
    switch( (dispmode & DISPMODE_COL) >> 2 ) {
nkeynes@161
   169
    case 0: 
nkeynes@161
   170
	buffer->colour_format = COLFMT_ARGB1555;
nkeynes@161
   171
	buffer->hres = vid_ppl << 1; 
nkeynes@161
   172
	break;
nkeynes@161
   173
    case 1: 
nkeynes@161
   174
	buffer->colour_format = COLFMT_RGB565;
nkeynes@161
   175
	buffer->hres = vid_ppl << 1; 
nkeynes@161
   176
	break;
nkeynes@161
   177
    case 2:
nkeynes@161
   178
	buffer->colour_format = COLFMT_RGB888;
nkeynes@161
   179
	buffer->hres = (vid_ppl << 2) / 3; 
nkeynes@161
   180
	break;
nkeynes@161
   181
    case 3: 
nkeynes@161
   182
	buffer->colour_format = COLFMT_ARGB8888;
nkeynes@161
   183
	buffer->hres = vid_ppl; 
nkeynes@161
   184
	break;
nkeynes@161
   185
    }
nkeynes@161
   186
	
nkeynes@161
   187
    if( buffer->hres <=8 )
nkeynes@161
   188
	buffer->hres = 640;
nkeynes@161
   189
    if( buffer->vres <=8 )
nkeynes@161
   190
	buffer->vres = 480;
nkeynes@161
   191
    if( display_driver != NULL ) {
nkeynes@161
   192
	if( buffer->hres != last->hres ||
nkeynes@161
   193
	    buffer->vres != last->vres ||
nkeynes@161
   194
	    buffer->colour_format != last->colour_format) {
nkeynes@161
   195
	    display_driver->set_display_format( buffer->hres, buffer->vres,
nkeynes@161
   196
						buffer->colour_format );
nkeynes@94
   197
	}
nkeynes@161
   198
	if( !bEnabled ) {
nkeynes@161
   199
	    display_driver->display_blank_frame( 0 );
nkeynes@161
   200
	} else if( MMIO_READ( PVR2, DISPCFG2 ) & 0x08 ) { /* Blanked */
nkeynes@161
   201
	    uint32_t colour = MMIO_READ( PVR2, DISPBORDER );
nkeynes@161
   202
	    display_driver->display_blank_frame( colour );
nkeynes@161
   203
	} else if( !pvr2_render_display_frame( PVR2_RAM_BASE + display_addr ) ) {
nkeynes@161
   204
	    display_driver->display_frame( buffer );
nkeynes@65
   205
	}
nkeynes@1
   206
    }
nkeynes@133
   207
    pvr2_state.frame_count++;
nkeynes@1
   208
}
nkeynes@1
   209
nkeynes@1
   210
void mmio_region_PVR2_write( uint32_t reg, uint32_t val )
nkeynes@1
   211
{
nkeynes@1
   212
    if( reg >= 0x200 && reg < 0x600 ) { /* Fog table */
nkeynes@1
   213
        MMIO_WRITE( PVR2, reg, val );
nkeynes@1
   214
        /* I don't want to hear about these */
nkeynes@1
   215
        return;
nkeynes@1
   216
    }
nkeynes@1
   217
    
nkeynes@1
   218
    switch(reg) {
nkeynes@189
   219
    case PVRID:
nkeynes@189
   220
    case PVRVER:
nkeynes@189
   221
    case GUNPOS:
nkeynes@189
   222
    case TA_POLYPOS:
nkeynes@189
   223
    case TA_LISTPOS:
nkeynes@189
   224
	/* Readonly registers */
nkeynes@189
   225
	break;
nkeynes@191
   226
    case RENDER_START:
nkeynes@189
   227
	if( val == 0xFFFFFFFF )
nkeynes@189
   228
	    pvr2_render_scene();
nkeynes@189
   229
	break;
nkeynes@191
   230
    case PVRUNK1:
nkeynes@191
   231
    	MMIO_WRITE( PVR2, reg, val&0x000007FF );
nkeynes@191
   232
    	break;
nkeynes@191
   233
    case RENDER_POLYBASE:
nkeynes@191
   234
    	MMIO_WRITE( PVR2, reg, val&0x00F00000 );
nkeynes@191
   235
    	break;
nkeynes@191
   236
    case RENDER_TSPCFG:
nkeynes@191
   237
    	MMIO_WRITE( PVR2, reg, val&0x00010101 );
nkeynes@191
   238
    	break;
nkeynes@191
   239
    case DISPBORDER:
nkeynes@191
   240
    	MMIO_WRITE( PVR2, reg, val&0x01FFFFFF );
nkeynes@191
   241
    	break;
nkeynes@191
   242
    case DISPMODE:
nkeynes@191
   243
    	MMIO_WRITE( PVR2, reg, val&0x00FFFF7F );
nkeynes@191
   244
    	break;
nkeynes@191
   245
    case RENDER_MODE:
nkeynes@191
   246
    	MMIO_WRITE( PVR2, reg, val&0x00FFFF0F );
nkeynes@191
   247
    	break;
nkeynes@191
   248
    case RENDER_SIZE:
nkeynes@191
   249
    	MMIO_WRITE( PVR2, reg, val&0x000001FF );
nkeynes@191
   250
    	break;
nkeynes@108
   251
    case DISPADDR1:
nkeynes@189
   252
	val &= 0x00FFFFFC;
nkeynes@189
   253
	MMIO_WRITE( PVR2, reg, val );
nkeynes@133
   254
	if( pvr2_state.retrace ) {
nkeynes@108
   255
	    pvr2_display_frame();
nkeynes@133
   256
	    pvr2_state.retrace = FALSE;
nkeynes@108
   257
	}
nkeynes@108
   258
	break;
nkeynes@191
   259
    case DISPADDR2:
nkeynes@191
   260
    	MMIO_WRITE( PVR2, reg, val&0x00FFFFFC );
nkeynes@191
   261
    	break;
nkeynes@191
   262
    case DISPSIZE:
nkeynes@191
   263
    	MMIO_WRITE( PVR2, reg, val&0x3FFFFFFF );
nkeynes@191
   264
    	break;
nkeynes@191
   265
    case RENDER_ADDR1:
nkeynes@191
   266
    case RENDER_ADDR2:
nkeynes@191
   267
    	MMIO_WRITE( PVR2, reg, val&0x01FFFFFC );
nkeynes@191
   268
    	break;
nkeynes@191
   269
    case RENDER_HCLIP:
nkeynes@191
   270
	MMIO_WRITE( PVR2, reg, val&0x07FF07FF );
nkeynes@189
   271
	break;
nkeynes@191
   272
    case RENDER_VCLIP:
nkeynes@191
   273
	MMIO_WRITE( PVR2, reg, val&0x03FF03FF );
nkeynes@189
   274
	break;
nkeynes@189
   275
    case HPOS_IRQ:
nkeynes@191
   276
	MMIO_WRITE( PVR2, reg, val&0x03FF33FF );
nkeynes@189
   277
	break;
nkeynes@103
   278
    case VPOS_IRQ:
nkeynes@189
   279
	val = val & 0x03FF03FF;
nkeynes@189
   280
	pvr2_state.irq_vpos1 = (val >> 16);
nkeynes@133
   281
	pvr2_state.irq_vpos2 = val & 0x03FF;
nkeynes@189
   282
	MMIO_WRITE( PVR2, reg, val );
nkeynes@103
   283
	break;
nkeynes@191
   284
    case RENDER_SHADOW:
nkeynes@191
   285
	MMIO_WRITE( PVR2, reg, val&0x000001FF );
nkeynes@191
   286
	break;
nkeynes@191
   287
    case RENDER_OBJCFG:
nkeynes@191
   288
    	MMIO_WRITE( PVR2, reg, val&0x003FFFFF );
nkeynes@191
   289
    	break;
nkeynes@191
   290
    case RENDER_TSPCLIP:
nkeynes@191
   291
    	MMIO_WRITE( PVR2, reg, val&0x7FFFFFFF );
nkeynes@191
   292
    	break;
nkeynes@191
   293
    case RENDER_BGPLANE:
nkeynes@191
   294
    	MMIO_WRITE( PVR2, reg, val&0x1FFFFFFF );
nkeynes@191
   295
    	break;
nkeynes@191
   296
    case RENDER_ISPCFG:
nkeynes@191
   297
    	MMIO_WRITE( PVR2, reg, val&0x00FFFFF9 );
nkeynes@191
   298
    	break;
nkeynes@189
   299
    case TA_TILEBASE:
nkeynes@193
   300
    case TA_LISTEND:
nkeynes@189
   301
    case TA_LISTBASE:
nkeynes@191
   302
	MMIO_WRITE( PVR2, reg, val&0x00FFFFE0 );
nkeynes@189
   303
	break;
nkeynes@191
   304
    case RENDER_TILEBASE:
nkeynes@189
   305
    case TA_POLYBASE:
nkeynes@189
   306
    case TA_POLYEND:
nkeynes@191
   307
	MMIO_WRITE( PVR2, reg, val&0x00FFFFFC );
nkeynes@189
   308
	break;
nkeynes@189
   309
    case TA_TILESIZE:
nkeynes@191
   310
	MMIO_WRITE( PVR2, reg, val&0x000F003F );
nkeynes@189
   311
	break;
nkeynes@189
   312
    case TA_TILECFG:
nkeynes@191
   313
	MMIO_WRITE( PVR2, reg, val&0x00133333 );
nkeynes@189
   314
	break;
nkeynes@189
   315
    case TA_INIT:
nkeynes@100
   316
	if( val & 0x80000000 )
nkeynes@100
   317
	    pvr2_ta_init();
nkeynes@100
   318
	break;
nkeynes@189
   319
	
nkeynes@191
   320
    /* Nonexistent registers (as far as we know, anyway) */
nkeynes@191
   321
    case 0x01C:
nkeynes@191
   322
    case 0x024:
nkeynes@191
   323
    case 0x028:
nkeynes@191
   324
    case 0x058:
nkeynes@191
   325
    	break;
nkeynes@189
   326
    default:
nkeynes@189
   327
	MMIO_WRITE( PVR2, reg, val );
nkeynes@1
   328
    }
nkeynes@1
   329
}
nkeynes@1
   330
nkeynes@1
   331
MMIO_REGION_READ_FN( PVR2, reg )
nkeynes@1
   332
{
nkeynes@1
   333
    switch( reg ) {
nkeynes@1
   334
        case BEAMPOS:
nkeynes@2
   335
            return sh4r.icount&0x20 ? 0x2000 : 1;
nkeynes@1
   336
        default:
nkeynes@1
   337
            return MMIO_READ( PVR2, reg );
nkeynes@1
   338
    }
nkeynes@1
   339
}
nkeynes@19
   340
nkeynes@85
   341
MMIO_REGION_DEFFNS( PVR2PAL )
nkeynes@85
   342
nkeynes@19
   343
void pvr2_set_base_address( uint32_t base ) 
nkeynes@19
   344
{
nkeynes@19
   345
    mmio_region_PVR2_write( DISPADDR1, base );
nkeynes@19
   346
}
nkeynes@56
   347
nkeynes@56
   348
nkeynes@65
   349
nkeynes@98
   350
nkeynes@56
   351
int32_t mmio_region_PVR2TA_read( uint32_t reg )
nkeynes@56
   352
{
nkeynes@56
   353
    return 0xFFFFFFFF;
nkeynes@56
   354
}
nkeynes@56
   355
nkeynes@56
   356
void mmio_region_PVR2TA_write( uint32_t reg, uint32_t val )
nkeynes@56
   357
{
nkeynes@189
   358
    pvr2_ta_write( (char *)&val, sizeof(uint32_t) );
nkeynes@56
   359
}
nkeynes@56
   360
nkeynes@85
   361
nkeynes@103
   362
void pvr2_vram64_write( sh4addr_t destaddr, char *src, uint32_t length )
nkeynes@103
   363
{
nkeynes@103
   364
    int bank_flag = (destaddr & 0x04) >> 2;
nkeynes@103
   365
    uint32_t *banks[2];
nkeynes@103
   366
    uint32_t *dwsrc;
nkeynes@103
   367
    int i;
nkeynes@65
   368
nkeynes@103
   369
    destaddr = destaddr & 0x7FFFFF;
nkeynes@103
   370
    if( destaddr + length > 0x800000 ) {
nkeynes@103
   371
	length = 0x800000 - destaddr;
nkeynes@103
   372
    }
nkeynes@103
   373
nkeynes@103
   374
    for( i=destaddr & 0xFFFFF000; i < destaddr + length; i+= PAGE_SIZE ) {
nkeynes@103
   375
	texcache_invalidate_page( i );
nkeynes@103
   376
    }
nkeynes@103
   377
nkeynes@108
   378
    banks[0] = ((uint32_t *)(video_base + ((destaddr & 0x007FFFF8) >>1)));
nkeynes@103
   379
    banks[1] = banks[0] + 0x100000;
nkeynes@108
   380
    if( bank_flag ) 
nkeynes@108
   381
	banks[0]++;
nkeynes@103
   382
    
nkeynes@103
   383
    /* Handle non-aligned start of source */
nkeynes@103
   384
    if( destaddr & 0x03 ) {
nkeynes@103
   385
	char *dest = ((char *)banks[bank_flag]) + (destaddr & 0x03);
nkeynes@103
   386
	for( i= destaddr & 0x03; i < 4 && length > 0; i++, length-- ) {
nkeynes@103
   387
	    *dest++ = *src++;
nkeynes@103
   388
	}
nkeynes@103
   389
	bank_flag = !bank_flag;
nkeynes@103
   390
    }
nkeynes@103
   391
nkeynes@103
   392
    dwsrc = (uint32_t *)src;
nkeynes@103
   393
    while( length >= 4 ) {
nkeynes@103
   394
	*banks[bank_flag]++ = *dwsrc++;
nkeynes@103
   395
	bank_flag = !bank_flag;
nkeynes@103
   396
	length -= 4;
nkeynes@103
   397
    }
nkeynes@103
   398
    
nkeynes@103
   399
    /* Handle non-aligned end of source */
nkeynes@103
   400
    if( length ) {
nkeynes@103
   401
	src = (char *)dwsrc;
nkeynes@103
   402
	char *dest = (char *)banks[bank_flag];
nkeynes@103
   403
	while( length-- > 0 ) {
nkeynes@103
   404
	    *dest++ = *src++;
nkeynes@103
   405
	}
nkeynes@103
   406
    }  
nkeynes@103
   407
nkeynes@103
   408
}
nkeynes@103
   409
nkeynes@103
   410
void pvr2_vram64_read( char *dest, sh4addr_t srcaddr, uint32_t length )
nkeynes@103
   411
{
nkeynes@103
   412
    int bank_flag = (srcaddr & 0x04) >> 2;
nkeynes@103
   413
    uint32_t *banks[2];
nkeynes@103
   414
    uint32_t *dwdest;
nkeynes@103
   415
    int i;
nkeynes@103
   416
nkeynes@103
   417
    srcaddr = srcaddr & 0x7FFFFF;
nkeynes@103
   418
    if( srcaddr + length > 0x800000 )
nkeynes@103
   419
	length = 0x800000 - srcaddr;
nkeynes@103
   420
nkeynes@108
   421
    banks[0] = ((uint32_t *)(video_base + ((srcaddr&0x007FFFF8)>>1)));
nkeynes@103
   422
    banks[1] = banks[0] + 0x100000;
nkeynes@108
   423
    if( bank_flag )
nkeynes@108
   424
	banks[0]++;
nkeynes@103
   425
    
nkeynes@103
   426
    /* Handle non-aligned start of source */
nkeynes@103
   427
    if( srcaddr & 0x03 ) {
nkeynes@103
   428
	char *src = ((char *)banks[bank_flag]) + (srcaddr & 0x03);
nkeynes@103
   429
	for( i= srcaddr & 0x03; i < 4 && length > 0; i++, length-- ) {
nkeynes@103
   430
	    *dest++ = *src++;
nkeynes@103
   431
	}
nkeynes@103
   432
	bank_flag = !bank_flag;
nkeynes@103
   433
    }
nkeynes@103
   434
nkeynes@103
   435
    dwdest = (uint32_t *)dest;
nkeynes@103
   436
    while( length >= 4 ) {
nkeynes@103
   437
	*dwdest++ = *banks[bank_flag]++;
nkeynes@103
   438
	bank_flag = !bank_flag;
nkeynes@103
   439
	length -= 4;
nkeynes@103
   440
    }
nkeynes@103
   441
    
nkeynes@103
   442
    /* Handle non-aligned end of source */
nkeynes@103
   443
    if( length ) {
nkeynes@103
   444
	dest = (char *)dwdest;
nkeynes@103
   445
	char *src = (char *)banks[bank_flag];
nkeynes@103
   446
	while( length-- > 0 ) {
nkeynes@103
   447
	    *dest++ = *src++;
nkeynes@103
   448
	}
nkeynes@103
   449
    }
nkeynes@103
   450
}
nkeynes@127
   451
nkeynes@127
   452
void pvr2_vram64_dump( sh4addr_t addr, uint32_t length, FILE *f ) 
nkeynes@127
   453
{
nkeynes@127
   454
    char tmp[length];
nkeynes@127
   455
    pvr2_vram64_read( tmp, addr, length );
nkeynes@127
   456
    fwrite_dump( tmp, length, f );
nkeynes@127
   457
}
.