2 * $Id: rendload.c,v 1.1 2007-01-16 11:09:39 nkeynes Exp $
4 * Scene-save loader support. This is the other side of rendsave.c
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.
25 char *scene_magic = "%!-lxDream!Scene";
27 #define PVR2_BASE 0xA05F8000
29 #define COPYREG(x) long_write( (PVR2_BASE+x), scene_header.pvr2_regs[(x>>2)] )
31 int pvr2_render_load_scene( FILE *f )
38 uint32_t pvr2_regs[0x400];
39 uint32_t palette[0x400];
41 uint32_t start = 0xFFFFFFFF, length;
43 if( fread( &scene_header, sizeof(scene_header), 1, f ) != 1 ) {
44 fprintf( stderr, "Failed to read scene header (%s)\n", strerror(errno) );
47 if( memcmp( scene_magic, scene_header.magic, 16 ) != 0 ) {
48 fprintf( stderr, "Failed to load scene data: Header not found\n" );
53 fprintf( stdout, "Loaded header\n" );
54 /* Load the VRAM sections */
56 fread( &start, sizeof(uint32_t), 1, f );
57 if( start == 0xFFFFFFFF ) { /* EOF */
60 fread( &length, sizeof(uint32_t), 1, f );
61 int read = fread( (char *)(0xA5000000 + start), 1, length, f );
62 if( read != length ) {
63 fprintf( stderr, "Failed to load %d bytes at %08X (Got %d - %s)\n",
64 length, start, read, strerror(errno) );
68 fprintf( stdout, "Loaded %d bytes at %08X\n", length, start );
72 /* Copy the fog table */
73 memcpy( (char *)0xA05F8200, ((char *)scene_header.pvr2_regs) + 0x200, 0x200 );
74 /* Copy the palette data */
75 memcpy( (char *)0xA05F9000, scene_header.palette, 4096 );
76 /* And now the other registers */
108 fprintf( stdout, "Load complete\n" );
113 void pvr2_render_loaded_scene()
116 long_write( (PVR2_BASE+0x14), 0xFFFFFFFF );
117 asic_wait( EVENT_PVR_RENDER_DONE );
119 asic_wait( EVENT_RETRACE );
120 uint32_t addr = long_read( (PVR2_BASE+0x060) );
121 uint32_t mod = long_read( (PVR2_BASE+0x04C) );
122 long_write( (PVR2_BASE+0x050), addr);
123 long_write( (PVR2_BASE+0x054), addr + (mod<<3) );
130 pvr2_render_load_scene(stdin);
131 pvr2_render_loaded_scene();
133 asic_wait(EVENT_RETRACE);
135 asic_wait(EVENT_RETRACE);
137 asic_wait(EVENT_RETRACE);
.