Search
lxdream.org :: lxdream/src/pvr2/pvr2.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/pvr2.c
changeset 56:3224dceaf2a3
prev35:21a4be098304
next65:9f124c245fc6
author nkeynes
date Sun Jan 01 08:09:42 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Implement PVR DMA channel
view annotate diff log raw
     1 /**
     2  * $Id: pvr2.c,v 1.11 2006-01-01 08:09:42 nkeynes Exp $
     3  *
     4  * PVR2 (Video) MMIO and supporting functions.
     5  *
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    18 #define MODULE pvr2_module
    20 #include "dream.h"
    21 #include "video.h"
    22 #include "mem.h"
    23 #include "asic.h"
    24 #include "pvr2.h"
    25 #include "sh4/sh4core.h"
    26 #define MMIO_IMPL
    27 #include "pvr2.h"
    29 char *video_base;
    31 void pvr2_init( void );
    32 uint32_t pvr2_run_slice( uint32_t );
    33 void pvr2_next_frame( void );
    35 struct dreamcast_module pvr2_module = { "PVR2", pvr2_init, NULL, NULL, 
    36 					pvr2_run_slice, NULL,
    37 					NULL, NULL };
    39 void pvr2_init( void )
    40 {
    41     register_io_region( &mmio_region_PVR2 );
    42     register_io_region( &mmio_region_PVR2TA );
    43     video_base = mem_get_region_by_name( MEM_REGION_VIDEO );
    44 }
    46 uint32_t pvr2_time_counter = 0;
    47 uint32_t pvr2_time_per_frame = 20000000;
    49 uint32_t pvr2_run_slice( uint32_t nanosecs ) 
    50 {
    51     pvr2_time_counter += nanosecs;
    52     while( pvr2_time_counter >= pvr2_time_per_frame ) {
    53 	pvr2_next_frame();
    54 	pvr2_time_counter -= pvr2_time_per_frame;
    55     }
    56     return nanosecs;
    57 }
    59 uint32_t vid_stride, vid_lpf, vid_ppl, vid_hres, vid_vres, vid_col;
    60 int interlaced, bChanged = 1, bEnabled = 0, vid_size = 0;
    61 char *frame_start; /* current video start address (in real memory) */
    63 /*
    64  * Display the next frame, copying the current contents of video ram to
    65  * the window. If the video configuration has changed, first recompute the
    66  * new frame size/depth.
    67  */
    68 void pvr2_next_frame( void )
    69 {
    70     if( bChanged ) {
    71         int dispsize = MMIO_READ( PVR2, DISPSIZE );
    72         int dispmode = MMIO_READ( PVR2, DISPMODE );
    73         int vidcfg = MMIO_READ( PVR2, VIDCFG );
    74         vid_stride = ((dispsize & DISPSIZE_MODULO) >> 20) - 1;
    75         vid_lpf = ((dispsize & DISPSIZE_LPF) >> 10) + 1;
    76         vid_ppl = ((dispsize & DISPSIZE_PPL)) + 1;
    77         vid_col = (dispmode & DISPMODE_COL);
    78         frame_start = video_base + MMIO_READ( PVR2, DISPADDR1 );
    79         interlaced = (vidcfg & VIDCFG_I ? 1 : 0);
    80         bEnabled = (dispmode & DISPMODE_DE) && (vidcfg & VIDCFG_VO ) ? 1 : 0;
    81         vid_size = (vid_ppl * vid_lpf) << (interlaced ? 3 : 2);
    82         vid_hres = vid_ppl;
    83         vid_vres = vid_lpf;
    84         if( interlaced ) vid_vres <<= 1;
    85         switch( vid_col ) {
    86             case MODE_RGB15:
    87             case MODE_RGB16: vid_hres <<= 1; break;
    88             case MODE_RGB24: vid_hres *= 3; break;
    89             case MODE_RGB32: vid_hres <<= 2; break;
    90         }
    91         vid_hres >>= 2;
    92         video_update_size( vid_hres, vid_vres, vid_col );
    93         bChanged = 0;
    94     }
    95     if( bEnabled ) {
    96         /* Assume bit depths match for now... */
    97         memcpy( video_data, frame_start, vid_size );
    98     } else {
    99         memset( video_data, 0, vid_size );
   100     }
   101     video_update_frame();
   102     asic_event( EVENT_SCANLINE1 );
   103     asic_event( EVENT_SCANLINE2 );
   104     asic_event( EVENT_RETRACE );
   105 }
   107 void mmio_region_PVR2_write( uint32_t reg, uint32_t val )
   108 {
   109     if( reg >= 0x200 && reg < 0x600 ) { /* Fog table */
   110         MMIO_WRITE( PVR2, reg, val );
   111         /* I don't want to hear about these */
   112         return;
   113     }
   115     INFO( "PVR2 write to %08X <= %08X [%s: %s]", reg, val, 
   116           MMIO_REGID(PVR2,reg), MMIO_REGDESC(PVR2,reg) );
   118     switch(reg) {
   119         case DISPSIZE: bChanged = 1;
   120         case DISPMODE: bChanged = 1;
   121         case DISPADDR1: bChanged = 1;
   122         case DISPADDR2: bChanged = 1;
   123         case VIDCFG: bChanged = 1;
   124             break;
   126     }
   127     MMIO_WRITE( PVR2, reg, val );
   128 }
   130 MMIO_REGION_READ_FN( PVR2, reg )
   131 {
   132     switch( reg ) {
   133         case BEAMPOS:
   134             return sh4r.icount&0x20 ? 0x2000 : 1;
   135         default:
   136             return MMIO_READ( PVR2, reg );
   137     }
   138 }
   140 void pvr2_set_base_address( uint32_t base ) 
   141 {
   142     mmio_region_PVR2_write( DISPADDR1, base );
   143 }
   146 int32_t mmio_region_PVR2TA_read( uint32_t reg )
   147 {
   148     return 0xFFFFFFFF;
   149 }
   151 char pvr2ta_remainder[8];
   153 void mmio_region_PVR2TA_write( uint32_t reg, uint32_t val )
   154 {
   156 }
   158 void pvr2ta_write( char *buf, uint32_t length )
   159 {
   161 }
.