Search
lxdream.org :: lxdream/src/pvr2/rendsave.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/rendsave.c
changeset 295:6637664291a8
next429:e581b90c3fb3
author nkeynes
date Tue Jan 16 10:34:46 2007 +0000 (15 years ago)
permissions -rw-r--r--
last change Bug 24: Initial implementation of "save scene" function
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/pvr2/rendsave.c Tue Jan 16 10:34:46 2007 +0000
1.3 @@ -0,0 +1,97 @@
1.4 +/**
1.5 + * $Id: rendsave.c,v 1.1 2007-01-16 10:34:46 nkeynes Exp $
1.6 + *
1.7 + * Scene-save support. This is mainly for test/debug purposes.
1.8 + *
1.9 + * Copyright (c) 2005 Nathan Keynes.
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.20 + */
1.21 +
1.22 +#include <stdio.h>
1.23 +#include <errno.h>
1.24 +#include <time.h>
1.25 +#include "pvr2/pvr2.h"
1.26 +#include "dreamcast.h"
1.27 +
1.28 +/**
1.29 + * Size of pages for the purposes of saving - this has nothing to do with the
1.30 + * actual page size, of course.
1.31 + */
1.32 +#define SAVE_PAGE_SIZE 1024
1.33 +#define SAVE_PAGE_COUNT 8192
1.34 +
1.35 +extern char *video_base;
1.36 +
1.37 +/* Determine pages of memory to save. Start walking from the render tilemap
1.38 + * data and build up a page list
1.39 + */
1.40 +static void pvr2_find_referenced_pages( char *pages )
1.41 +{
1.42 + /* Dummy implementation - save everything */
1.43 + memset( pages, 1, SAVE_PAGE_COUNT );
1.44 +}
1.45 +
1.46 +/**
1.47 + * Save the current rendering data to a file for later analysis.
1.48 + * @return 0 on success, non-zero on failure.
1.49 + */
1.50 +int pvr2_render_save_scene( const gchar *filename )
1.51 +{
1.52 + struct header {
1.53 + char magic[16];
1.54 + uint32_t version;
1.55 + uint32_t timestamp;
1.56 + uint32_t frame_count;
1.57 + } scene_header;
1.58 +
1.59 + char page_map[SAVE_PAGE_COUNT];
1.60 + int i,j;
1.61 + pvr2_find_referenced_pages(page_map);
1.62 +
1.63 + FILE *f = fopen( filename, "wo" );
1.64 + if( f == NULL ) {
1.65 + ERROR( "Unable to open file '%s' to write scene data: %s", filename, strerror(errno) );
1.66 + return -1;
1.67 + }
1.68 +
1.69 + /* Header */
1.70 + memcpy( scene_header.magic, SCENE_SAVE_MAGIC, 16 );
1.71 + scene_header.version = SCENE_SAVE_VERSION;
1.72 + scene_header.timestamp = time(NULL);
1.73 + scene_header.frame_count = pvr2_get_frame_count();
1.74 + fwrite( &scene_header, sizeof(scene_header), 1, f );
1.75 +
1.76 + /* PVR2 registers - could probably be more specific, but doesn't
1.77 + * really use a lot of space. Loader is assumed to know which
1.78 + * registers actually need to be set.
1.79 + */
1.80 + fwrite( mmio_region_PVR2.mem, 0x1000, 1, f );
1.81 + fwrite( mmio_region_PVR2PAL.mem, 0x1000, 1, f );
1.82 +
1.83 + /* Write out the VRAM pages we care about */
1.84 + for( i=0; i<SAVE_PAGE_COUNT; i++ ) {
1.85 + if( page_map[i] != 0 ) {
1.86 + for( j=i+1; j<SAVE_PAGE_COUNT && page_map[j] != 0; j++ );
1.87 + /* Write region from i..j-1 */
1.88 + uint32_t start = i * SAVE_PAGE_SIZE;
1.89 + uint32_t length = (j-i) * SAVE_PAGE_SIZE;
1.90 + fwrite( &start, sizeof(uint32_t), 1, f );
1.91 + fwrite( &length, sizeof(uint32_t), 1, f );
1.92 + fwrite( video_base + start, 1, length, f );
1.93 + i = j-1;
1.94 + }
1.95 + }
1.96 + /* Write out the EOF marker */
1.97 + uint32_t eof = 0xFFFFFFFF;
1.98 + fwrite( &eof, sizeof(uint32_t), 1, f );
1.99 + fclose( f );
1.100 +}
.