filename | src/pvr2/rendsave.c |
changeset | 669:ab344e42bca9 |
prev | 561:533f6b478071 |
next | 677:3ee62740ff8f |
author | nkeynes |
date | Mon May 12 10:00:13 2008 +0000 (15 years ago) |
permissions | -rw-r--r-- |
last change | Cleanup most of the -Wall warnings (getting a bit sloppy...) Convert FP code to use fixed banks rather than indirect pointer (3-4% faster this way now) |
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 "dreamcast.h"
26 /**
27 * Size of pages for the purposes of saving - this has nothing to do with the
28 * actual page size, of course.
29 */
30 #define SAVE_PAGE_SIZE 1024
31 #define SAVE_PAGE_COUNT 8192
33 extern char *video_base;
35 /* Determine pages of memory to save. Start walking from the render tilemap
36 * data and build up a page list
37 */
38 static void pvr2_find_referenced_pages( char *pages )
39 {
40 /* Dummy implementation - save everything */
41 memset( pages, 1, SAVE_PAGE_COUNT );
42 }
44 /**
45 * Save the current rendering data to a file for later analysis.
46 * @return 0 on success, non-zero on failure.
47 */
48 int pvr2_render_save_scene( const gchar *filename )
49 {
50 struct header {
51 char magic[16];
52 uint32_t version;
53 uint32_t timestamp;
54 uint32_t frame_count;
55 } scene_header;
57 char page_map[SAVE_PAGE_COUNT];
58 int i,j;
59 pvr2_find_referenced_pages(page_map);
61 FILE *f = fopen( filename, "wo" );
62 if( f == NULL ) {
63 ERROR( "Unable to open file '%s' to write scene data: %s", filename, strerror(errno) );
64 return -1;
65 }
67 /* Header */
68 memcpy( scene_header.magic, SCENE_SAVE_MAGIC, 16 );
69 scene_header.version = SCENE_SAVE_VERSION;
70 scene_header.timestamp = time(NULL);
71 scene_header.frame_count = pvr2_get_frame_count();
72 fwrite( &scene_header, sizeof(scene_header), 1, f );
74 /* PVR2 registers - could probably be more specific, but doesn't
75 * really use a lot of space. Loader is assumed to know which
76 * registers actually need to be set.
77 */
78 fwrite( mmio_region_PVR2.mem, 0x1000, 1, f );
79 fwrite( mmio_region_PVR2PAL.mem, 0x1000, 1, f );
81 /* Write out the VRAM pages we care about */
82 for( i=0; i<SAVE_PAGE_COUNT; i++ ) {
83 if( page_map[i] != 0 ) {
84 for( j=i+1; j<SAVE_PAGE_COUNT && page_map[j] != 0; j++ );
85 /* Write region from i..j-1 */
86 uint32_t start = i * SAVE_PAGE_SIZE;
87 uint32_t length = (j-i) * SAVE_PAGE_SIZE;
88 fwrite( &start, sizeof(uint32_t), 1, f );
89 fwrite( &length, sizeof(uint32_t), 1, f );
90 fwrite( video_base + start, 1, length, f );
91 i = j-1;
92 }
93 }
94 /* Write out the EOF marker */
95 uint32_t eof = 0xFFFFFFFF;
96 fwrite( &eof, sizeof(uint32_t), 1, f );
97 fclose( f );
98 return 0;
99 }
.