Search
lxdream.org :: lxdream/src/pvr2/rendsave.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/rendsave.c
changeset 736:a02d1475ccfd
prev677:3ee62740ff8f
next934:3acd3b3ee6d1
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
nkeynes@295
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@295
     3
 *
nkeynes@295
     4
 * Scene-save support. This is mainly for test/debug purposes.
nkeynes@295
     5
 *
nkeynes@295
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@295
     7
 *
nkeynes@295
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@295
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@295
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@295
    11
 * (at your option) any later version.
nkeynes@295
    12
 *
nkeynes@295
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@295
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@295
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@295
    16
 * GNU General Public License for more details.
nkeynes@295
    17
 */
nkeynes@295
    18
nkeynes@295
    19
#include <stdio.h>
nkeynes@295
    20
#include <errno.h>
nkeynes@295
    21
#include <time.h>
nkeynes@669
    22
#include <string.h>
nkeynes@295
    23
#include "pvr2/pvr2.h"
nkeynes@677
    24
#include "pvr2/pvr2mmio.h"
nkeynes@295
    25
#include "dreamcast.h"
nkeynes@295
    26
nkeynes@295
    27
/**
nkeynes@295
    28
 * Size of pages for the purposes of saving - this has nothing to do with the 
nkeynes@295
    29
 * actual page size, of course.
nkeynes@295
    30
 */
nkeynes@295
    31
#define SAVE_PAGE_SIZE 1024
nkeynes@295
    32
#define SAVE_PAGE_COUNT 8192
nkeynes@295
    33
nkeynes@295
    34
extern char *video_base;
nkeynes@295
    35
nkeynes@295
    36
/* Determine pages of memory to save. Start walking from the render tilemap
nkeynes@295
    37
 * data and build up a page list
nkeynes@295
    38
 */
nkeynes@295
    39
static void pvr2_find_referenced_pages( char *pages )
nkeynes@295
    40
{
nkeynes@295
    41
    /* Dummy implementation - save everything */
nkeynes@295
    42
    memset( pages, 1, SAVE_PAGE_COUNT );
nkeynes@295
    43
}
nkeynes@295
    44
nkeynes@295
    45
/**
nkeynes@295
    46
 * Save the current rendering data to a file for later analysis.
nkeynes@295
    47
 * @return 0 on success, non-zero on failure.
nkeynes@295
    48
 */
nkeynes@295
    49
int pvr2_render_save_scene( const gchar *filename )
nkeynes@295
    50
{
nkeynes@295
    51
    struct header {
nkeynes@736
    52
        char magic[16];
nkeynes@736
    53
        uint32_t version;
nkeynes@736
    54
        uint32_t timestamp;
nkeynes@736
    55
        uint32_t frame_count;
nkeynes@295
    56
    } scene_header;
nkeynes@295
    57
nkeynes@295
    58
    char page_map[SAVE_PAGE_COUNT];
nkeynes@295
    59
    int i,j;
nkeynes@295
    60
    pvr2_find_referenced_pages(page_map);
nkeynes@736
    61
nkeynes@295
    62
    FILE *f = fopen( filename, "wo" ); 
nkeynes@295
    63
    if( f == NULL ) {
nkeynes@736
    64
        ERROR( "Unable to open file '%s' to write scene data: %s", filename, strerror(errno) );
nkeynes@736
    65
        return -1;
nkeynes@295
    66
    }
nkeynes@295
    67
nkeynes@295
    68
    /* Header */
nkeynes@295
    69
    memcpy( scene_header.magic, SCENE_SAVE_MAGIC, 16 );
nkeynes@295
    70
    scene_header.version = SCENE_SAVE_VERSION;
nkeynes@295
    71
    scene_header.timestamp = time(NULL);
nkeynes@295
    72
    scene_header.frame_count = pvr2_get_frame_count();
nkeynes@295
    73
    fwrite( &scene_header, sizeof(scene_header), 1, f );
nkeynes@295
    74
nkeynes@295
    75
    /* PVR2 registers - could probably be more specific, but doesn't 
nkeynes@295
    76
     * really use a lot of space. Loader is assumed to know which
nkeynes@295
    77
     * registers actually need to be set.
nkeynes@295
    78
     */
nkeynes@295
    79
    fwrite( mmio_region_PVR2.mem, 0x1000, 1, f );
nkeynes@295
    80
    fwrite( mmio_region_PVR2PAL.mem, 0x1000, 1, f );
nkeynes@295
    81
nkeynes@295
    82
    /* Write out the VRAM pages we care about */
nkeynes@295
    83
    for( i=0; i<SAVE_PAGE_COUNT; i++ ) {
nkeynes@736
    84
        if( page_map[i] != 0 ) {
nkeynes@736
    85
            for( j=i+1; j<SAVE_PAGE_COUNT && page_map[j] != 0; j++ );
nkeynes@736
    86
            /* Write region from i..j-1 */
nkeynes@736
    87
            uint32_t start = i * SAVE_PAGE_SIZE;
nkeynes@736
    88
            uint32_t length = (j-i) * SAVE_PAGE_SIZE;
nkeynes@736
    89
            fwrite( &start, sizeof(uint32_t), 1, f );
nkeynes@736
    90
            fwrite( &length, sizeof(uint32_t), 1, f );
nkeynes@736
    91
            fwrite( video_base + start, 1, length, f );
nkeynes@736
    92
            i = j-1;
nkeynes@736
    93
        }
nkeynes@295
    94
    }
nkeynes@295
    95
    /* Write out the EOF marker */
nkeynes@295
    96
    uint32_t eof = 0xFFFFFFFF;
nkeynes@295
    97
    fwrite( &eof, sizeof(uint32_t), 1, f );
nkeynes@295
    98
    fclose( f );
nkeynes@429
    99
    return 0;
nkeynes@295
   100
}
.