1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/rendload.c Tue Sep 11 01:05:05 2007 +0000
1.5 + * $Id: rendload.c,v 1.1 2007-01-16 11:09:39 nkeynes Exp $
1.7 + * Scene-save loader support. This is the other side of rendsave.c
1.9 + * Copyright (c) 2005 Nathan Keynes.
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.28 +char *scene_magic = "%!-lxDream!Scene";
1.30 +#define PVR2_BASE 0xA05F8000
1.32 +#define COPYREG(x) long_write( (PVR2_BASE+x), scene_header.pvr2_regs[(x>>2)] )
1.34 +int pvr2_render_load_scene( FILE *f )
1.39 + uint32_t timestamp;
1.40 + uint32_t frame_count;
1.41 + uint32_t pvr2_regs[0x400];
1.42 + uint32_t palette[0x400];
1.44 + uint32_t start = 0xFFFFFFFF, length;
1.46 + if( fread( &scene_header, sizeof(scene_header), 1, f ) != 1 ) {
1.47 + fprintf( stderr, "Failed to read scene header (%s)\n", strerror(errno) );
1.50 + if( memcmp( scene_magic, scene_header.magic, 16 ) != 0 ) {
1.51 + fprintf( stderr, "Failed to load scene data: Header not found\n" );
1.56 + fprintf( stdout, "Loaded header\n" );
1.57 + /* Load the VRAM sections */
1.59 + fread( &start, sizeof(uint32_t), 1, f );
1.60 + if( start == 0xFFFFFFFF ) { /* EOF */
1.63 + fread( &length, sizeof(uint32_t), 1, f );
1.64 + int read = fread( (char *)(0xA5000000 + start), 1, length, f );
1.65 + if( read != length ) {
1.66 + fprintf( stderr, "Failed to load %d bytes at %08X (Got %d - %s)\n",
1.67 + length, start, read, strerror(errno) );
1.71 + fprintf( stdout, "Loaded %d bytes at %08X\n", length, start );
1.75 + /* Copy the fog table */
1.76 + memcpy( (char *)0xA05F8200, ((char *)scene_header.pvr2_regs) + 0x200, 0x200 );
1.77 + /* Copy the palette data */
1.78 + memcpy( (char *)0xA05F9000, scene_header.palette, 4096 );
1.79 + /* And now the other registers */
1.111 + fprintf( stdout, "Load complete\n" );
1.116 +void pvr2_render_loaded_scene()
1.119 + long_write( (PVR2_BASE+0x14), 0xFFFFFFFF );
1.120 + asic_wait( EVENT_PVR_RENDER_DONE );
1.122 + asic_wait( EVENT_RETRACE );
1.123 + uint32_t addr = long_read( (PVR2_BASE+0x060) );
1.124 + uint32_t mod = long_read( (PVR2_BASE+0x04C) );
1.125 + long_write( (PVR2_BASE+0x050), addr);
1.126 + long_write( (PVR2_BASE+0x054), addr + (mod<<3) );
1.133 + pvr2_render_load_scene(stdin);
1.134 + pvr2_render_loaded_scene();
1.136 + asic_wait(EVENT_RETRACE);
1.138 + asic_wait(EVENT_RETRACE);
1.140 + asic_wait(EVENT_RETRACE);