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 (11 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
view annotate diff log raw
     1 /**
     2  * $Id$
     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 <string.h>
    23 #include "pvr2/pvr2.h"
    24 #include "pvr2/pvr2mmio.h"
    25 #include "dreamcast.h"
    27 /**
    28  * Size of pages for the purposes of saving - this has nothing to do with the 
    29  * actual page size, of course.
    30  */
    31 #define SAVE_PAGE_SIZE 1024
    32 #define SAVE_PAGE_COUNT 8192
    34 extern char *video_base;
    36 /* Determine pages of memory to save. Start walking from the render tilemap
    37  * data and build up a page list
    38  */
    39 static void pvr2_find_referenced_pages( char *pages )
    40 {
    41     /* Dummy implementation - save everything */
    42     memset( pages, 1, SAVE_PAGE_COUNT );
    43 }
    45 /**
    46  * Save the current rendering data to a file for later analysis.
    47  * @return 0 on success, non-zero on failure.
    48  */
    49 int pvr2_render_save_scene( const gchar *filename )
    50 {
    51     struct header {
    52         char magic[16];
    53         uint32_t version;
    54         uint32_t timestamp;
    55         uint32_t frame_count;
    56     } scene_header;
    58     char page_map[SAVE_PAGE_COUNT];
    59     int i,j;
    60     pvr2_find_referenced_pages(page_map);
    62     FILE *f = fopen( filename, "wo" ); 
    63     if( f == NULL ) {
    64         ERROR( "Unable to open file '%s' to write scene data: %s", filename, strerror(errno) );
    65         return -1;
    66     }
    68     /* Header */
    69     memcpy( scene_header.magic, SCENE_SAVE_MAGIC, 16 );
    70     scene_header.version = SCENE_SAVE_VERSION;
    71     scene_header.timestamp = time(NULL);
    72     scene_header.frame_count = pvr2_get_frame_count();
    73     fwrite( &scene_header, sizeof(scene_header), 1, f );
    75     /* PVR2 registers - could probably be more specific, but doesn't 
    76      * really use a lot of space. Loader is assumed to know which
    77      * registers actually need to be set.
    78      */
    79     fwrite( mmio_region_PVR2.mem, 0x1000, 1, f );
    80     fwrite( mmio_region_PVR2PAL.mem, 0x1000, 1, f );
    82     /* Write out the VRAM pages we care about */
    83     for( i=0; i<SAVE_PAGE_COUNT; i++ ) {
    84         if( page_map[i] != 0 ) {
    85             for( j=i+1; j<SAVE_PAGE_COUNT && page_map[j] != 0; j++ );
    86             /* Write region from i..j-1 */
    87             uint32_t start = i * SAVE_PAGE_SIZE;
    88             uint32_t length = (j-i) * SAVE_PAGE_SIZE;
    89             fwrite( &start, sizeof(uint32_t), 1, f );
    90             fwrite( &length, sizeof(uint32_t), 1, f );
    91             fwrite( video_base + start, 1, length, f );
    92             i = j-1;
    93         }
    94     }
    95     /* Write out the EOF marker */
    96     uint32_t eof = 0xFFFFFFFF;
    97     fwrite( &eof, sizeof(uint32_t), 1, f );
    98     fclose( f );
    99     return 0;
   100 }
.