Search
lxdream.org :: lxdream/src/pvr2/pvr2.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/pvr2.c
changeset 1:eea311cfd33e
next2:42349f6ea216
author nkeynes
date Sat Mar 13 00:03:32 2004 +0000 (16 years ago)
permissions -rw-r--r--
last change This commit was generated by cvs2svn to compensate for changes in r2,
which included commits to RCS files with non-trunk default branches.
file annotate diff log raw
nkeynes@1
     1
#include "dream.h"
nkeynes@1
     2
#include "video.h"
nkeynes@1
     3
#include "mem.h"
nkeynes@1
     4
#include "asic.h"
nkeynes@1
     5
#include "pvr2.h"
nkeynes@1
     6
#define MMIO_IMPL
nkeynes@1
     7
#include "pvr2.h"
nkeynes@1
     8
nkeynes@1
     9
char *video_base;
nkeynes@1
    10
nkeynes@1
    11
void pvr2_init( void )
nkeynes@1
    12
{
nkeynes@1
    13
    register_io_region( &mmio_region_PVR2 );
nkeynes@1
    14
    video_base = mem_get_region_by_name( MEM_REGION_VIDEO );
nkeynes@1
    15
}
nkeynes@1
    16
nkeynes@1
    17
uint32_t vid_stride, vid_lpf, vid_ppl, vid_hres, vid_vres, vid_col;
nkeynes@1
    18
int interlaced, bChanged = 1, bEnabled = 0, vid_size = 0;
nkeynes@1
    19
char *frame_start; /* current video start address (in real memory) */
nkeynes@1
    20
nkeynes@1
    21
/*
nkeynes@1
    22
 * Display the next frame, copying the current contents of video ram to
nkeynes@1
    23
 * the window. If the video configuration has changed, first recompute the
nkeynes@1
    24
 * new frame size/depth.
nkeynes@1
    25
 */
nkeynes@1
    26
void pvr2_next_frame( void )
nkeynes@1
    27
{
nkeynes@1
    28
    if( bChanged ) {
nkeynes@1
    29
        int dispsize = MMIO_READ( PVR2, DISPSIZE );
nkeynes@1
    30
        int dispmode = MMIO_READ( PVR2, DISPMODE );
nkeynes@1
    31
        int vidcfg = MMIO_READ( PVR2, VIDCFG );
nkeynes@1
    32
        vid_stride = ((dispsize & DISPSIZE_MODULO) >> 20) - 1;
nkeynes@1
    33
        vid_lpf = ((dispsize & DISPSIZE_LPF) >> 10) + 1;
nkeynes@1
    34
        vid_ppl = ((dispsize & DISPSIZE_PPL)) + 1;
nkeynes@1
    35
        vid_col = (dispmode & DISPMODE_COL);
nkeynes@1
    36
        frame_start = video_base + MMIO_READ( PVR2, DISPADDR1 );
nkeynes@1
    37
        interlaced = (vidcfg & VIDCFG_I ? 1 : 0);
nkeynes@1
    38
        bEnabled = (dispmode & DISPMODE_DE) && (vidcfg & VIDCFG_VO ) ? 1 : 0;
nkeynes@1
    39
        vid_size = (vid_ppl * vid_lpf) << (interlaced ? 3 : 2);
nkeynes@1
    40
        vid_hres = vid_ppl;
nkeynes@1
    41
        vid_vres = vid_lpf;
nkeynes@1
    42
        if( interlaced ) vid_vres <<= 1;
nkeynes@1
    43
        switch( vid_col ) {
nkeynes@1
    44
            case MODE_RGB15:
nkeynes@1
    45
            case MODE_RGB16: vid_hres <<= 1; break;
nkeynes@1
    46
            case MODE_RGB24: vid_hres *= 3; break;
nkeynes@1
    47
            case MODE_RGB32: vid_hres <<= 2; break;
nkeynes@1
    48
        }
nkeynes@1
    49
        vid_hres >>= 2;
nkeynes@1
    50
        video_update_size( vid_hres, vid_vres, vid_col );
nkeynes@1
    51
        bChanged = 0;
nkeynes@1
    52
    }
nkeynes@1
    53
    if( bEnabled ) {
nkeynes@1
    54
        /* Assume bit depths match for now... */
nkeynes@1
    55
        memcpy( video_data, frame_start, vid_size );
nkeynes@1
    56
    } else {
nkeynes@1
    57
        memset( video_data, 0, vid_size );
nkeynes@1
    58
    }
nkeynes@1
    59
    video_update_frame();
nkeynes@1
    60
    asic_event( EVENT_SCANLINE1 );
nkeynes@1
    61
    asic_event( EVENT_SCANLINE2 );
nkeynes@1
    62
    asic_event( EVENT_RETRACE );
nkeynes@1
    63
}
nkeynes@1
    64
nkeynes@1
    65
void mmio_region_PVR2_write( uint32_t reg, uint32_t val )
nkeynes@1
    66
{
nkeynes@1
    67
    if( reg >= 0x200 && reg < 0x600 ) { /* Fog table */
nkeynes@1
    68
        MMIO_WRITE( PVR2, reg, val );
nkeynes@1
    69
        /* I don't want to hear about these */
nkeynes@1
    70
        return;
nkeynes@1
    71
    }
nkeynes@1
    72
    
nkeynes@1
    73
    INFO( "PVR2 write to %08X <= %08X [%s: %s]", reg, val, 
nkeynes@1
    74
          MMIO_REGID(PVR2,reg), MMIO_REGDESC(PVR2,reg) );
nkeynes@1
    75
   
nkeynes@1
    76
    switch(reg) {
nkeynes@1
    77
        case DISPSIZE: bChanged = 1;
nkeynes@1
    78
        case DISPMODE: bChanged = 1;
nkeynes@1
    79
        case DISPADDR1: bChanged = 1;
nkeynes@1
    80
        case DISPADDR2: bChanged = 1;
nkeynes@1
    81
        case VIDCFG: bChanged = 1;
nkeynes@1
    82
            break;
nkeynes@1
    83
            
nkeynes@1
    84
    }
nkeynes@1
    85
    MMIO_WRITE( PVR2, reg, val );
nkeynes@1
    86
}
nkeynes@1
    87
nkeynes@1
    88
MMIO_REGION_READ_FN( PVR2, reg )
nkeynes@1
    89
{
nkeynes@1
    90
    switch( reg ) {
nkeynes@1
    91
        case BEAMPOS:
nkeynes@1
    92
            return sh4r.icount&0x20 ? 0x2000 : 0;
nkeynes@1
    93
        default:
nkeynes@1
    94
            return MMIO_READ( PVR2, reg );
nkeynes@1
    95
    }
nkeynes@1
    96
}
.