Search
lxdream.org :: lxdream/src/pvr2/rendsave.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/rendsave.c
changeset 561:533f6b478071
prev429:e581b90c3fb3
next669:ab344e42bca9
author nkeynes
date Tue Jan 01 05:08:38 2008 +0000 (12 years ago)
branchlxdream-mmu
permissions -rw-r--r--
last change Enable Id keyword on all source files
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@295
    22
#include "pvr2/pvr2.h"
nkeynes@295
    23
#include "dreamcast.h"
nkeynes@295
    24
nkeynes@295
    25
/**
nkeynes@295
    26
 * Size of pages for the purposes of saving - this has nothing to do with the 
nkeynes@295
    27
 * actual page size, of course.
nkeynes@295
    28
 */
nkeynes@295
    29
#define SAVE_PAGE_SIZE 1024
nkeynes@295
    30
#define SAVE_PAGE_COUNT 8192
nkeynes@295
    31
nkeynes@295
    32
extern char *video_base;
nkeynes@295
    33
nkeynes@295
    34
/* Determine pages of memory to save. Start walking from the render tilemap
nkeynes@295
    35
 * data and build up a page list
nkeynes@295
    36
 */
nkeynes@295
    37
static void pvr2_find_referenced_pages( char *pages )
nkeynes@295
    38
{
nkeynes@295
    39
    /* Dummy implementation - save everything */
nkeynes@295
    40
    memset( pages, 1, SAVE_PAGE_COUNT );
nkeynes@295
    41
}
nkeynes@295
    42
nkeynes@295
    43
/**
nkeynes@295
    44
 * Save the current rendering data to a file for later analysis.
nkeynes@295
    45
 * @return 0 on success, non-zero on failure.
nkeynes@295
    46
 */
nkeynes@295
    47
int pvr2_render_save_scene( const gchar *filename )
nkeynes@295
    48
{
nkeynes@295
    49
    struct header {
nkeynes@295
    50
	char magic[16];
nkeynes@295
    51
	uint32_t version;
nkeynes@295
    52
	uint32_t timestamp;
nkeynes@295
    53
	uint32_t frame_count;
nkeynes@295
    54
    } scene_header;
nkeynes@295
    55
nkeynes@295
    56
    char page_map[SAVE_PAGE_COUNT];
nkeynes@295
    57
    int i,j;
nkeynes@295
    58
    pvr2_find_referenced_pages(page_map);
nkeynes@295
    59
    
nkeynes@295
    60
    FILE *f = fopen( filename, "wo" ); 
nkeynes@295
    61
    if( f == NULL ) {
nkeynes@295
    62
	ERROR( "Unable to open file '%s' to write scene data: %s", filename, strerror(errno) );
nkeynes@295
    63
	return -1;
nkeynes@295
    64
    }
nkeynes@295
    65
nkeynes@295
    66
    /* Header */
nkeynes@295
    67
    memcpy( scene_header.magic, SCENE_SAVE_MAGIC, 16 );
nkeynes@295
    68
    scene_header.version = SCENE_SAVE_VERSION;
nkeynes@295
    69
    scene_header.timestamp = time(NULL);
nkeynes@295
    70
    scene_header.frame_count = pvr2_get_frame_count();
nkeynes@295
    71
    fwrite( &scene_header, sizeof(scene_header), 1, f );
nkeynes@295
    72
nkeynes@295
    73
    /* PVR2 registers - could probably be more specific, but doesn't 
nkeynes@295
    74
     * really use a lot of space. Loader is assumed to know which
nkeynes@295
    75
     * registers actually need to be set.
nkeynes@295
    76
     */
nkeynes@295
    77
    fwrite( mmio_region_PVR2.mem, 0x1000, 1, f );
nkeynes@295
    78
    fwrite( mmio_region_PVR2PAL.mem, 0x1000, 1, f );
nkeynes@295
    79
nkeynes@295
    80
    /* Write out the VRAM pages we care about */
nkeynes@295
    81
    for( i=0; i<SAVE_PAGE_COUNT; i++ ) {
nkeynes@295
    82
	if( page_map[i] != 0 ) {
nkeynes@295
    83
	    for( j=i+1; j<SAVE_PAGE_COUNT && page_map[j] != 0; j++ );
nkeynes@295
    84
	    /* Write region from i..j-1 */
nkeynes@295
    85
	    uint32_t start = i * SAVE_PAGE_SIZE;
nkeynes@295
    86
	    uint32_t length = (j-i) * SAVE_PAGE_SIZE;
nkeynes@295
    87
	    fwrite( &start, sizeof(uint32_t), 1, f );
nkeynes@295
    88
	    fwrite( &length, sizeof(uint32_t), 1, f );
nkeynes@295
    89
	    fwrite( video_base + start, 1, length, f );
nkeynes@295
    90
	    i = j-1;
nkeynes@295
    91
	}
nkeynes@295
    92
    }
nkeynes@295
    93
    /* Write out the EOF marker */
nkeynes@295
    94
    uint32_t eof = 0xFFFFFFFF;
nkeynes@295
    95
    fwrite( &eof, sizeof(uint32_t), 1, f );
nkeynes@295
    96
    fclose( f );
nkeynes@429
    97
    return 0;
nkeynes@295
    98
}
.