filename | src/pvr2/rendsave.c |
changeset | 295:6637664291a8 |
next | 429:e581b90c3fb3 |
author | nkeynes |
date | Thu Jan 25 10:16:32 2007 +0000 (17 years ago) |
permissions | -rw-r--r-- |
last change | Move PVR2 dma handling (0x10000000-0x13FFFFFF) into pvr2mem.c, minor register cleanups in asic.c |
file | annotate | diff | log | raw |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00001.2 +++ b/src/pvr2/rendsave.c Thu Jan 25 10:16:32 2007 +00001.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 modify1.12 + * it under the terms of the GNU General Public License as published by1.13 + * the Free Software Foundation; either version 2 of the License, or1.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 of1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1.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 the1.30 + * actual page size, of course.1.31 + */1.32 +#define SAVE_PAGE_SIZE 10241.33 +#define SAVE_PAGE_COUNT 81921.34 +1.35 +extern char *video_base;1.36 +1.37 +/* Determine pages of memory to save. Start walking from the render tilemap1.38 + * data and build up a page list1.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't1.77 + * really use a lot of space. Loader is assumed to know which1.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 +}
.