revision 297:26fc4446ac09
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 297:26fc4446ac09 |
parent | 296:1aa1c5ba59fd |
child | 298:44d94dd0e8aa |
author | nkeynes |
date | Tue Jan 16 11:09:39 2007 +0000 (17 years ago) |
Bug 24: Initial implementation of scene save loader
test/Makefile | view | annotate | diff | log | ||
test/rendload.c | view | annotate | diff | log |
1.1 --- a/test/Makefile Tue Jan 16 10:36:19 2007 +00001.2 +++ b/test/Makefile Tue Jan 16 11:09:39 2007 +00001.3 @@ -112,6 +112,10 @@1.4 readdata: crt0.so readdata.so1.5 $(SH4CC) $(SH4LDFLAGS) $^ -o $@ $(SH4LIBS)1.7 +rend: crt0.so rendload.so asic.so lib.so timer.so pvr.so1.8 + $(SH4CC) $(SH4LDFLAGS) $^ -o $@ $(SH4LIBS)1.9 + $(SH4OBJCOPY) rend rend.bin1.10 +1.11 .PHONY : clean1.12 clean:1.13 rm -f *.o *.so *.ao *.ac *.bin mapleid ide readmem dumpasic
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00002.2 +++ b/test/rendload.c Tue Jan 16 11:09:39 2007 +00002.3 @@ -0,0 +1,138 @@2.4 +/**2.5 + * $Id: rendload.c,v 1.1 2007-01-16 11:09:39 nkeynes Exp $2.6 + *2.7 + * Scene-save loader support. This is the other side of rendsave.c2.8 + *2.9 + * Copyright (c) 2005 Nathan Keynes.2.10 + *2.11 + * This program is free software; you can redistribute it and/or modify2.12 + * it under the terms of the GNU General Public License as published by2.13 + * the Free Software Foundation; either version 2 of the License, or2.14 + * (at your option) any later version.2.15 + *2.16 + * This program is distributed in the hope that it will be useful,2.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of2.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the2.19 + * GNU General Public License for more details.2.20 + */2.21 +2.22 +#include <stdio.h>2.23 +#include <errno.h>2.24 +#include "lib.h"2.25 +#include "asic.h"2.26 +#include "pvr.h"2.27 +2.28 +char *scene_magic = "%!-lxDream!Scene";2.29 +2.30 +#define PVR2_BASE 0xA05F80002.31 +2.32 +#define COPYREG(x) long_write( (PVR2_BASE+x), scene_header.pvr2_regs[(x>>2)] )2.33 +2.34 +int pvr2_render_load_scene( FILE *f )2.35 +{2.36 + struct {2.37 + char magic[16];2.38 + uint32_t version;2.39 + uint32_t timestamp;2.40 + uint32_t frame_count;2.41 + uint32_t pvr2_regs[0x400];2.42 + uint32_t palette[0x400];2.43 + } scene_header;2.44 + uint32_t start = 0xFFFFFFFF, length;2.45 +2.46 + if( fread( &scene_header, sizeof(scene_header), 1, f ) != 1 ) {2.47 + fprintf( stderr, "Failed to read scene header (%s)\n", strerror(errno) );2.48 + return -1;2.49 + }2.50 + if( memcmp( scene_magic, scene_header.magic, 16 ) != 0 ) {2.51 + fprintf( stderr, "Failed to load scene data: Header not found\n" );2.52 + fclose(f);2.53 + return -1;2.54 + }2.55 +2.56 + fprintf( stdout, "Loaded header\n" );2.57 + /* Load the VRAM sections */2.58 + while(1) {2.59 + fread( &start, sizeof(uint32_t), 1, f );2.60 + if( start == 0xFFFFFFFF ) { /* EOF */2.61 + break;2.62 + }2.63 + fread( &length, sizeof(uint32_t), 1, f );2.64 + int read = fread( (char *)(0xA5000000 + start), 1, length, f );2.65 + if( read != length ) {2.66 + fprintf( stderr, "Failed to load %d bytes at %08X (Got %d - %s)\n",2.67 + length, start, read, strerror(errno) );2.68 + fclose(f);2.69 + return -2;2.70 + } else {2.71 + fprintf( stdout, "Loaded %d bytes at %08X\n", length, start );2.72 + }2.73 + }2.74 +2.75 + /* Copy the fog table */2.76 + memcpy( (char *)0xA05F8200, ((char *)scene_header.pvr2_regs) + 0x200, 0x200 );2.77 + /* Copy the palette data */2.78 + memcpy( (char *)0xA05F9000, scene_header.palette, 4096 );2.79 + /* And now the other registers */2.80 + COPYREG(0x018);2.81 + COPYREG(0x020);2.82 + COPYREG(0x02C);2.83 + COPYREG(0x030);2.84 + COPYREG(0x044);2.85 + COPYREG(0x048);2.86 + COPYREG(0x04C);2.87 + COPYREG(0x05C);2.88 + COPYREG(0x060);2.89 + COPYREG(0x064);2.90 + COPYREG(0x068);2.91 + COPYREG(0x06C);2.92 + COPYREG(0x074);2.93 + COPYREG(0x078);2.94 + COPYREG(0x07C);2.95 + COPYREG(0x080);2.96 + COPYREG(0x084);2.97 + COPYREG(0x088);2.98 + COPYREG(0x08C);2.99 + COPYREG(0x098);2.100 + COPYREG(0x0B0);2.101 + COPYREG(0x0B4);2.102 + COPYREG(0x0B8);2.103 + COPYREG(0x0BC);2.104 + COPYREG(0x0C0);2.105 + COPYREG(0x0E4);2.106 + COPYREG(0x0F4);2.107 + COPYREG(0x108);2.108 + COPYREG(0x110);2.109 + COPYREG(0x114);2.110 + COPYREG(0x118);2.111 + fprintf( stdout, "Load complete\n" );2.112 + fclose(f);2.113 +}2.114 +2.115 +2.116 +void pvr2_render_loaded_scene()2.117 +{2.118 + asic_clear();2.119 + long_write( (PVR2_BASE+0x14), 0xFFFFFFFF );2.120 + asic_wait( EVENT_PVR_RENDER_DONE );2.121 + asic_clear();2.122 + asic_wait( EVENT_RETRACE );2.123 + uint32_t addr = long_read( (PVR2_BASE+0x060) );2.124 + uint32_t mod = long_read( (PVR2_BASE+0x04C) );2.125 + long_write( (PVR2_BASE+0x050), addr);2.126 + long_write( (PVR2_BASE+0x054), addr + (mod<<3) );2.127 +}2.128 +2.129 +2.130 +int main()2.131 +{2.132 + pvr_init();2.133 + pvr2_render_load_scene(stdin);2.134 + pvr2_render_loaded_scene();2.135 + asic_clear();2.136 + asic_wait(EVENT_RETRACE);2.137 + asic_clear();2.138 + asic_wait(EVENT_RETRACE);2.139 + asic_clear();2.140 + asic_wait(EVENT_RETRACE);2.141 +}
.