filename | test/rendload.c |
changeset | 297:26fc4446ac09 |
next | 561:533f6b478071 |
author | nkeynes |
date | Fri Sep 28 07:25:22 2007 +0000 (16 years ago) |
permissions | -rw-r--r-- |
last change | Remove MMU check (probably shouldn't be here anyway), and disable TRACE_IO checks by default |
file | annotate | diff | log | raw |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00001.2 +++ b/test/rendload.c Fri Sep 28 07:25:22 2007 +00001.3 @@ -0,0 +1,138 @@1.4 +/**1.5 + * $Id: rendload.c,v 1.1 2007-01-16 11:09:39 nkeynes Exp $1.6 + *1.7 + * Scene-save loader support. This is the other side of rendsave.c1.8 + *1.9 + * Copyright (c) 2005 Nathan Keynes.1.10 + *1.11 + * This program is free software; you can redistribute it and/or modify1.12 + * it under the terms of the GNU General Public License as published by1.13 + * the Free Software Foundation; either version 2 of the License, or1.14 + * (at your option) any later version.1.15 + *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 of1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1.19 + * GNU General Public License for more details.1.20 + */1.21 +1.22 +#include <stdio.h>1.23 +#include <errno.h>1.24 +#include "lib.h"1.25 +#include "asic.h"1.26 +#include "pvr.h"1.27 +1.28 +char *scene_magic = "%!-lxDream!Scene";1.29 +1.30 +#define PVR2_BASE 0xA05F80001.31 +1.32 +#define COPYREG(x) long_write( (PVR2_BASE+x), scene_header.pvr2_regs[(x>>2)] )1.33 +1.34 +int pvr2_render_load_scene( FILE *f )1.35 +{1.36 + struct {1.37 + char magic[16];1.38 + uint32_t version;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.43 + } scene_header;1.44 + uint32_t start = 0xFFFFFFFF, length;1.45 +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.48 + return -1;1.49 + }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.52 + fclose(f);1.53 + return -1;1.54 + }1.55 +1.56 + fprintf( stdout, "Loaded header\n" );1.57 + /* Load the VRAM sections */1.58 + while(1) {1.59 + fread( &start, sizeof(uint32_t), 1, f );1.60 + if( start == 0xFFFFFFFF ) { /* EOF */1.61 + break;1.62 + }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.68 + fclose(f);1.69 + return -2;1.70 + } else {1.71 + fprintf( stdout, "Loaded %d bytes at %08X\n", length, start );1.72 + }1.73 + }1.74 +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.80 + COPYREG(0x018);1.81 + COPYREG(0x020);1.82 + COPYREG(0x02C);1.83 + COPYREG(0x030);1.84 + COPYREG(0x044);1.85 + COPYREG(0x048);1.86 + COPYREG(0x04C);1.87 + COPYREG(0x05C);1.88 + COPYREG(0x060);1.89 + COPYREG(0x064);1.90 + COPYREG(0x068);1.91 + COPYREG(0x06C);1.92 + COPYREG(0x074);1.93 + COPYREG(0x078);1.94 + COPYREG(0x07C);1.95 + COPYREG(0x080);1.96 + COPYREG(0x084);1.97 + COPYREG(0x088);1.98 + COPYREG(0x08C);1.99 + COPYREG(0x098);1.100 + COPYREG(0x0B0);1.101 + COPYREG(0x0B4);1.102 + COPYREG(0x0B8);1.103 + COPYREG(0x0BC);1.104 + COPYREG(0x0C0);1.105 + COPYREG(0x0E4);1.106 + COPYREG(0x0F4);1.107 + COPYREG(0x108);1.108 + COPYREG(0x110);1.109 + COPYREG(0x114);1.110 + COPYREG(0x118);1.111 + fprintf( stdout, "Load complete\n" );1.112 + fclose(f);1.113 +}1.114 +1.115 +1.116 +void pvr2_render_loaded_scene()1.117 +{1.118 + asic_clear();1.119 + long_write( (PVR2_BASE+0x14), 0xFFFFFFFF );1.120 + asic_wait( EVENT_PVR_RENDER_DONE );1.121 + asic_clear();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.127 +}1.128 +1.129 +1.130 +int main()1.131 +{1.132 + pvr_init();1.133 + pvr2_render_load_scene(stdin);1.134 + pvr2_render_loaded_scene();1.135 + asic_clear();1.136 + asic_wait(EVENT_RETRACE);1.137 + asic_clear();1.138 + asic_wait(EVENT_RETRACE);1.139 + asic_clear();1.140 + asic_wait(EVENT_RETRACE);1.141 +}
.