4 * Scene-save support. This is mainly for test/debug purposes.
6 * Copyright (c) 2005 Nathan Keynes.
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.
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.
23 #include "pvr2/pvr2.h"
24 #include "pvr2/pvr2mmio.h"
25 #include "dreamcast.h"
28 * Size of pages for the purposes of saving - this has nothing to do with the
29 * actual page size, of course.
31 #define SAVE_PAGE_SIZE 1024
32 #define SAVE_PAGE_COUNT 8192
34 /* Determine pages of memory to save. Start walking from the render tilemap
35 * data and build up a page list
37 static void pvr2_find_referenced_pages( char *pages )
39 /* Dummy implementation - save everything */
40 memset( pages, 1, SAVE_PAGE_COUNT );
44 * Save the current rendering data to a file for later analysis.
45 * @return 0 on success, non-zero on failure.
47 int pvr2_render_save_scene( const gchar *filename )
56 char page_map[SAVE_PAGE_COUNT];
58 pvr2_find_referenced_pages(page_map);
60 FILE *f = fopen( filename, "wo" );
62 ERROR( "Unable to open file '%s' to write scene data: %s", filename, strerror(errno) );
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.
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( pvr2_main_ram + start, 1, length, f );
93 /* Write out the EOF marker */
94 uint32_t eof = 0xFFFFFFFF;
95 fwrite( &eof, sizeof(uint32_t), 1, f );
.