filename | src/pvr2/rendsave.c |
changeset | 934:3acd3b3ee6d1 |
prev | 736:a02d1475ccfd |
author | nkeynes |
date | Mon Jan 26 07:26:24 2009 +0000 (15 years ago) |
permissions | -rw-r--r-- |
last change | Add read_byte_for_write mem function for correct implementation of AND.B and friends with TLB enabled. Add read_byte and read_long MMIO stubs to do correct sign extension of IO reads |
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 "pvr2/pvr2mmio.h"
25 #include "dreamcast.h"
27 /**
28 * Size of pages for the purposes of saving - this has nothing to do with the
29 * actual page size, of course.
30 */
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
36 */
37 static void pvr2_find_referenced_pages( char *pages )
38 {
39 /* Dummy implementation - save everything */
40 memset( pages, 1, SAVE_PAGE_COUNT );
41 }
43 /**
44 * Save the current rendering data to a file for later analysis.
45 * @return 0 on success, non-zero on failure.
46 */
47 int pvr2_render_save_scene( const gchar *filename )
48 {
49 struct header {
50 char magic[16];
51 uint32_t version;
52 uint32_t timestamp;
53 uint32_t frame_count;
54 } scene_header;
56 char page_map[SAVE_PAGE_COUNT];
57 int i,j;
58 pvr2_find_referenced_pages(page_map);
60 FILE *f = fopen( filename, "wo" );
61 if( f == NULL ) {
62 ERROR( "Unable to open file '%s' to write scene data: %s", filename, strerror(errno) );
63 return -1;
64 }
66 /* Header */
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.
76 */
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 );
90 i = j-1;
91 }
92 }
93 /* Write out the EOF marker */
94 uint32_t eof = 0xFFFFFFFF;
95 fwrite( &eof, sizeof(uint32_t), 1, f );
96 fclose( f );
97 return 0;
98 }
.