filename | test/rendload.c |
changeset | 561:533f6b478071 |
prev | 297:26fc4446ac09 |
author | nkeynes |
date | Tue Feb 07 11:59:07 2012 +1000 (12 years ago) |
permissions | -rw-r--r-- |
last change | Add enable/disable vertex attribute calls when making a shader active Add vec3 uniform setter |
view | annotate | diff | log | raw |
1 /**
2 * $Id$
3 *
4 * Scene-save loader support. This is the other side of rendsave.c
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 "lib.h"
22 #include "asic.h"
23 #include "pvr.h"
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 )
32 {
33 struct {
34 char magic[16];
35 uint32_t version;
36 uint32_t timestamp;
37 uint32_t frame_count;
38 uint32_t pvr2_regs[0x400];
39 uint32_t palette[0x400];
40 } scene_header;
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) );
45 return -1;
46 }
47 if( memcmp( scene_magic, scene_header.magic, 16 ) != 0 ) {
48 fprintf( stderr, "Failed to load scene data: Header not found\n" );
49 fclose(f);
50 return -1;
51 }
53 fprintf( stdout, "Loaded header\n" );
54 /* Load the VRAM sections */
55 while(1) {
56 fread( &start, sizeof(uint32_t), 1, f );
57 if( start == 0xFFFFFFFF ) { /* EOF */
58 break;
59 }
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) );
65 fclose(f);
66 return -2;
67 } else {
68 fprintf( stdout, "Loaded %d bytes at %08X\n", length, start );
69 }
70 }
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 */
77 COPYREG(0x018);
78 COPYREG(0x020);
79 COPYREG(0x02C);
80 COPYREG(0x030);
81 COPYREG(0x044);
82 COPYREG(0x048);
83 COPYREG(0x04C);
84 COPYREG(0x05C);
85 COPYREG(0x060);
86 COPYREG(0x064);
87 COPYREG(0x068);
88 COPYREG(0x06C);
89 COPYREG(0x074);
90 COPYREG(0x078);
91 COPYREG(0x07C);
92 COPYREG(0x080);
93 COPYREG(0x084);
94 COPYREG(0x088);
95 COPYREG(0x08C);
96 COPYREG(0x098);
97 COPYREG(0x0B0);
98 COPYREG(0x0B4);
99 COPYREG(0x0B8);
100 COPYREG(0x0BC);
101 COPYREG(0x0C0);
102 COPYREG(0x0E4);
103 COPYREG(0x0F4);
104 COPYREG(0x108);
105 COPYREG(0x110);
106 COPYREG(0x114);
107 COPYREG(0x118);
108 fprintf( stdout, "Load complete\n" );
109 fclose(f);
110 }
113 void pvr2_render_loaded_scene()
114 {
115 asic_clear();
116 long_write( (PVR2_BASE+0x14), 0xFFFFFFFF );
117 asic_wait( EVENT_PVR_RENDER_DONE );
118 asic_clear();
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) );
124 }
127 int main()
128 {
129 pvr_init();
130 pvr2_render_load_scene(stdin);
131 pvr2_render_loaded_scene();
132 asic_clear();
133 asic_wait(EVENT_RETRACE);
134 asic_clear();
135 asic_wait(EVENT_RETRACE);
136 asic_clear();
137 asic_wait(EVENT_RETRACE);
138 }
.