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