nkeynes@295: /** nkeynes@295: * $Id: rendsave.c,v 1.1 2007-01-16 10:34:46 nkeynes Exp $ nkeynes@295: * nkeynes@295: * Scene-save support. This is mainly for test/debug purposes. nkeynes@295: * nkeynes@295: * Copyright (c) 2005 Nathan Keynes. nkeynes@295: * nkeynes@295: * This program is free software; you can redistribute it and/or modify nkeynes@295: * it under the terms of the GNU General Public License as published by nkeynes@295: * the Free Software Foundation; either version 2 of the License, or nkeynes@295: * (at your option) any later version. nkeynes@295: * nkeynes@295: * This program is distributed in the hope that it will be useful, nkeynes@295: * but WITHOUT ANY WARRANTY; without even the implied warranty of nkeynes@295: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nkeynes@295: * GNU General Public License for more details. nkeynes@295: */ nkeynes@295: nkeynes@295: #include nkeynes@295: #include nkeynes@295: #include nkeynes@295: #include "pvr2/pvr2.h" nkeynes@295: #include "dreamcast.h" nkeynes@295: nkeynes@295: /** nkeynes@295: * Size of pages for the purposes of saving - this has nothing to do with the nkeynes@295: * actual page size, of course. nkeynes@295: */ nkeynes@295: #define SAVE_PAGE_SIZE 1024 nkeynes@295: #define SAVE_PAGE_COUNT 8192 nkeynes@295: nkeynes@295: extern char *video_base; nkeynes@295: nkeynes@295: /* Determine pages of memory to save. Start walking from the render tilemap nkeynes@295: * data and build up a page list nkeynes@295: */ nkeynes@295: static void pvr2_find_referenced_pages( char *pages ) nkeynes@295: { nkeynes@295: /* Dummy implementation - save everything */ nkeynes@295: memset( pages, 1, SAVE_PAGE_COUNT ); nkeynes@295: } nkeynes@295: nkeynes@295: /** nkeynes@295: * Save the current rendering data to a file for later analysis. nkeynes@295: * @return 0 on success, non-zero on failure. nkeynes@295: */ nkeynes@295: int pvr2_render_save_scene( const gchar *filename ) nkeynes@295: { nkeynes@295: struct header { nkeynes@295: char magic[16]; nkeynes@295: uint32_t version; nkeynes@295: uint32_t timestamp; nkeynes@295: uint32_t frame_count; nkeynes@295: } scene_header; nkeynes@295: nkeynes@295: char page_map[SAVE_PAGE_COUNT]; nkeynes@295: int i,j; nkeynes@295: pvr2_find_referenced_pages(page_map); nkeynes@295: nkeynes@295: FILE *f = fopen( filename, "wo" ); nkeynes@295: if( f == NULL ) { nkeynes@295: ERROR( "Unable to open file '%s' to write scene data: %s", filename, strerror(errno) ); nkeynes@295: return -1; nkeynes@295: } nkeynes@295: nkeynes@295: /* Header */ nkeynes@295: memcpy( scene_header.magic, SCENE_SAVE_MAGIC, 16 ); nkeynes@295: scene_header.version = SCENE_SAVE_VERSION; nkeynes@295: scene_header.timestamp = time(NULL); nkeynes@295: scene_header.frame_count = pvr2_get_frame_count(); nkeynes@295: fwrite( &scene_header, sizeof(scene_header), 1, f ); nkeynes@295: nkeynes@295: /* PVR2 registers - could probably be more specific, but doesn't nkeynes@295: * really use a lot of space. Loader is assumed to know which nkeynes@295: * registers actually need to be set. nkeynes@295: */ nkeynes@295: fwrite( mmio_region_PVR2.mem, 0x1000, 1, f ); nkeynes@295: fwrite( mmio_region_PVR2PAL.mem, 0x1000, 1, f ); nkeynes@295: nkeynes@295: /* Write out the VRAM pages we care about */ nkeynes@295: for( i=0; i