Search
lxdream.org :: lxdream/src/pvr2/pvr2.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/pvr2.c
changeset 94:8d80d9c7cc7d
prev85:71e239d20c5d
next98:7b59bca968e9
author nkeynes
date Sun Feb 05 04:05:27 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Video code reshuffle to start getting real video happening.
Implement colourspace conversions
Various tweaks
file annotate diff log raw
1.1 --- a/src/pvr2/pvr2.c Sun Jan 22 22:38:51 2006 +0000
1.2 +++ b/src/pvr2/pvr2.c Sun Feb 05 04:05:27 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: pvr2.c,v 1.13 2006-01-22 22:38:51 nkeynes Exp $
1.6 + * $Id: pvr2.c,v 1.14 2006-02-05 04:05:27 nkeynes Exp $
1.7 *
1.8 * PVR2 (Video) MMIO and supporting functions.
1.9 *
1.10 @@ -30,7 +30,11 @@
1.11
1.12 void pvr2_init( void );
1.13 uint32_t pvr2_run_slice( uint32_t );
1.14 -void pvr2_next_frame( void );
1.15 +void pvr2_display_frame( void );
1.16 +
1.17 +video_driver_t video_driver = NULL;
1.18 +struct video_buffer video_buffer[2];
1.19 +int video_buffer_idx = 0;
1.20
1.21 struct dreamcast_module pvr2_module = { "PVR2", pvr2_init, NULL, NULL,
1.22 pvr2_run_slice, NULL,
1.23 @@ -42,16 +46,18 @@
1.24 register_io_region( &mmio_region_PVR2PAL );
1.25 register_io_region( &mmio_region_PVR2TA );
1.26 video_base = mem_get_region_by_name( MEM_REGION_VIDEO );
1.27 + video_driver = &video_gtk_driver;
1.28 }
1.29
1.30 uint32_t pvr2_time_counter = 0;
1.31 +uint32_t pvr2_frame_counter = 0;
1.32 uint32_t pvr2_time_per_frame = 20000000;
1.33
1.34 uint32_t pvr2_run_slice( uint32_t nanosecs )
1.35 {
1.36 pvr2_time_counter += nanosecs;
1.37 while( pvr2_time_counter >= pvr2_time_per_frame ) {
1.38 - pvr2_next_frame();
1.39 + pvr2_display_frame();
1.40 pvr2_time_counter -= pvr2_time_per_frame;
1.41 }
1.42 return nanosecs;
1.43 @@ -66,46 +72,51 @@
1.44 * the window. If the video configuration has changed, first recompute the
1.45 * new frame size/depth.
1.46 */
1.47 -void pvr2_next_frame( void )
1.48 +void pvr2_display_frame( void )
1.49 {
1.50 - if( bChanged ) {
1.51 - int dispsize = MMIO_READ( PVR2, DISPSIZE );
1.52 - int dispmode = MMIO_READ( PVR2, DISPMODE );
1.53 - int vidcfg = MMIO_READ( PVR2, VIDCFG );
1.54 - vid_stride = ((dispsize & DISPSIZE_MODULO) >> 20) - 1;
1.55 - vid_lpf = ((dispsize & DISPSIZE_LPF) >> 10) + 1;
1.56 - vid_ppl = ((dispsize & DISPSIZE_PPL)) + 1;
1.57 - vid_col = (dispmode & DISPMODE_COL);
1.58 - frame_start = video_base + MMIO_READ( PVR2, DISPADDR1 );
1.59 - interlaced = (vidcfg & VIDCFG_I ? 1 : 0);
1.60 - bEnabled = (dispmode & DISPMODE_DE) && (vidcfg & VIDCFG_VO ) ? 1 : 0;
1.61 - vid_size = (vid_ppl * vid_lpf) << (interlaced ? 3 : 2);
1.62 - vid_hres = vid_ppl;
1.63 - vid_vres = vid_lpf;
1.64 - if( interlaced ) vid_vres <<= 1;
1.65 - switch( vid_col ) {
1.66 - case MODE_RGB15:
1.67 - case MODE_RGB16: vid_hres <<= 1; break;
1.68 - case MODE_RGB24: vid_hres *= 3; break;
1.69 - case MODE_RGB32: vid_hres <<= 2; break;
1.70 - }
1.71 - vid_hres >>= 2;
1.72 - video_update_size( vid_hres, vid_vres, vid_col );
1.73 - bChanged = 0;
1.74 - }
1.75 + int dispsize = MMIO_READ( PVR2, DISPSIZE );
1.76 + int dispmode = MMIO_READ( PVR2, DISPMODE );
1.77 + int vidcfg = MMIO_READ( PVR2, VIDCFG );
1.78 + int vid_stride = ((dispsize & DISPSIZE_MODULO) >> 20) - 1;
1.79 + int vid_lpf = ((dispsize & DISPSIZE_LPF) >> 10) + 1;
1.80 + int vid_ppl = ((dispsize & DISPSIZE_PPL)) + 1;
1.81 + gboolean bEnabled = (dispmode & DISPMODE_DE) && (vidcfg & VIDCFG_VO ) ? TRUE : FALSE;
1.82 + gboolean interlaced = (vidcfg & VIDCFG_I ? TRUE : FALSE);
1.83 if( bEnabled ) {
1.84 - if( MMIO_READ( PVR2, VIDCFG2 ) & 0x08 ) {
1.85 - /* Blanked */
1.86 - uint32_t colour = MMIO_READ( PVR2, BORDERCOL );
1.87 - video_fill( colour );
1.88 - } else {
1.89 - /* Assume bit depths match for now... */
1.90 - memcpy( video_data, frame_start, vid_size );
1.91 + video_buffer_t buffer = &video_buffer[video_buffer_idx];
1.92 + video_buffer_idx = !video_buffer_idx;
1.93 + video_buffer_t last = &video_buffer[video_buffer_idx];
1.94 + buffer->colour_format = (dispmode & DISPMODE_COL);
1.95 + buffer->rowstride = (vid_ppl + vid_stride) << 2;
1.96 + buffer->data = frame_start = video_base + MMIO_READ( PVR2, DISPADDR1 );
1.97 + buffer->vres = vid_lpf;
1.98 + if( interlaced ) buffer->vres <<= 1;
1.99 + switch( buffer->colour_format ) {
1.100 + case COLFMT_RGB15:
1.101 + case COLFMT_RGB16: buffer->hres = vid_ppl << 1; break;
1.102 + case COLFMT_RGB24: buffer->hres = (vid_ppl << 2) / 3; break;
1.103 + case COLFMT_RGB32: buffer->hres = vid_ppl; break;
1.104 + }
1.105 +
1.106 + if( video_driver != NULL ) {
1.107 + if( buffer->hres != last->hres ||
1.108 + buffer->vres != last->vres ||
1.109 + buffer->colour_format != last->colour_format) {
1.110 + video_driver->set_output_format( buffer->hres, buffer->vres,
1.111 + buffer->colour_format );
1.112 + }
1.113 + if( MMIO_READ( PVR2, VIDCFG2 ) & 0x08 ) { /* Blanked */
1.114 + uint32_t colour = MMIO_READ( PVR2, BORDERCOL );
1.115 + video_driver->display_blank_frame( colour );
1.116 + } else {
1.117 + video_driver->display_frame( buffer );
1.118 + }
1.119 }
1.120 } else {
1.121 - memset( video_data, 0, vid_size );
1.122 + video_buffer_idx = 0;
1.123 + video_buffer[0].hres = video_buffer[0].vres = 0;
1.124 }
1.125 - video_update_frame();
1.126 + pvr2_frame_counter++;
1.127 asic_event( EVENT_SCANLINE1 );
1.128 asic_event( EVENT_SCANLINE2 );
1.129 asic_event( EVENT_RETRACE );
1.130 @@ -123,12 +134,6 @@
1.131 MMIO_REGID(PVR2,reg), MMIO_REGDESC(PVR2,reg) );
1.132
1.133 switch(reg) {
1.134 - case DISPSIZE: bChanged = 1;
1.135 - case DISPMODE: bChanged = 1;
1.136 - case DISPADDR1: bChanged = 1;
1.137 - case DISPADDR2: bChanged = 1;
1.138 - case VIDCFG: bChanged = 1;
1.139 - break;
1.140 case RENDSTART:
1.141 if( val == 0xFFFFFFFF )
1.142 pvr2_render_scene();
1.143 @@ -159,7 +164,7 @@
1.144 {
1.145 /* Actual rendering goes here :) */
1.146 asic_event( EVENT_PVR_RENDER_DONE );
1.147 - DEBUG( "Rendered frame %d", video_frame_count );
1.148 + DEBUG( "Rendered frame %d", pvr2_frame_counter );
1.149 }
1.150
1.151 /** Tile Accelerator */
1.152 @@ -196,7 +201,7 @@
1.153 int count = length >> 5;
1.154 for( i=0; i<count; i++ ){
1.155 unsigned int type = (cmd_list[i].command >> 24) & 0xFF;
1.156 - DEBUG( "PVR2 cmd: %08X %08X %08X", cmd_list[i].command, cmd_list[i].param1, cmd_list[i].param2 );
1.157 + DEBUG( "PVR2 cmd: %08X %08X %08X %08X %08X %08X %08X %08X", cmd_list[i].command, cmd_list[i].param1, cmd_list[i].param2, cmd_list[i].texture, cmd_list[i].alpha, cmd_list[i].red, cmd_list[i].green, cmd_list[i].blue );
1.158 if( type == 0 ) {
1.159 /* End of list */
1.160 switch( pvr2_last_poly_type ) {
.