annotate src/xsf/vio2sf.c @ 3052:95b34f46a231

Comment out MPEG2/MPEG4 determination using the variable id. It is not used anywhere. Code analysis run, unique ID 6nYoHM.
author Tony Vroon <chainsaw@gentoo.org>
date Sat, 18 Apr 2009 19:06:20 +0100
parents 6013ab159139
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2961
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1 #include <stdio.h>
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2 #include <stdlib.h>
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
3 #include <string.h>
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
4
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
5 #include "desmume/MMU.h"
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
6 #include "desmume/armcpu.h"
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
7 #include "desmume/NDSSystem.h"
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
8 #include "desmume/SPU.h"
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
9 #include "desmume/cp15.h"
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
10
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
11 #include <zlib.h>
2965
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2961
diff changeset
12 #include <glib.h>
2961
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
13 #include "tagget.h"
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
14 #include "vio2sf.h"
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
15
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
16 volatile BOOL execute = FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
17
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
18 static struct
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
19 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
20 unsigned char *rom;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
21 unsigned char *state;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
22 unsigned romsize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
23 unsigned statesize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
24 unsigned stateptr;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
25 } loaderwork = {0, 0, 0, 0, 0};
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
26
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
27 static void load_term(void)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
28 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
29 if (loaderwork.rom)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
30 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
31 free(loaderwork.rom);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
32 loaderwork.rom = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
33 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
34 loaderwork.romsize = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
35 if (loaderwork.state)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
36 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
37 free(loaderwork.state);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
38 loaderwork.state = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
39 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
40 loaderwork.statesize = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
41 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
42
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
43 static int load_map(int issave, unsigned char *udata, unsigned usize)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
44 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
45 unsigned char *iptr;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
46 unsigned isize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
47 unsigned char *xptr;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
48 unsigned xsize = getdwordle(udata + 4);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
49 unsigned xofs = getdwordle(udata + 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
50 if (issave)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
51 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
52 iptr = loaderwork.state;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
53 isize = loaderwork.statesize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
54 loaderwork.state = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
55 loaderwork.statesize = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
56 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
57 else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
58 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
59 iptr = loaderwork.rom;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
60 isize = loaderwork.romsize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
61 loaderwork.rom = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
62 loaderwork.romsize = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
63 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
64 if (!iptr)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
65 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
66 iptr = malloc(xofs + xsize + 10);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
67 if (!iptr)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
68 return XSF_FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
69 memset(iptr, 0, xofs + xsize + 10);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
70 isize = xofs + xsize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
71 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
72 else if (isize < xofs + xsize)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
73 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
74 unsigned rsize = xofs + xsize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
75 if (!issave)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
76 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
77 rsize -= 1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
78 rsize |= rsize >> 1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
79 rsize |= rsize >> 2;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
80 rsize |= rsize >> 4;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
81 rsize |= rsize >> 8;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
82 rsize |= rsize >> 16;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
83 rsize += 1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
84 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
85 xptr = realloc(iptr, xofs + rsize + 10);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
86 if (!xptr)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
87 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
88 free(iptr);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
89 return XSF_FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
90 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
91 iptr = xptr;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
92 isize = rsize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
93 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
94 memcpy(iptr + xofs, udata + 8, xsize);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
95 if (issave)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
96 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
97 loaderwork.state = iptr;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
98 loaderwork.statesize = isize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
99 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
100 else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
101 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
102 loaderwork.rom = iptr;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
103 loaderwork.romsize = isize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
104 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
105 return XSF_TRUE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
106 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
107
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
108 static int load_mapz(int issave, unsigned char *zdata, unsigned zsize, unsigned zcrc)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
109 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
110 int ret;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
111 int zerr;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
112 uLongf usize = 8;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
113 uLongf rsize = usize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
114 unsigned char *udata;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
115 unsigned char *rdata;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
116
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
117 udata = malloc(usize);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
118 if (!udata)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
119 return XSF_FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
120
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
121 while (Z_OK != (zerr = uncompress(udata, &usize, zdata, zsize)))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
122 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
123 if (Z_MEM_ERROR != zerr && Z_BUF_ERROR != zerr)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
124 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
125 free(udata);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
126 return XSF_FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
127 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
128 if (usize >= 8)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
129 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
130 usize = getdwordle(udata + 4) + 8;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
131 if (usize < rsize)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
132 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
133 rsize += rsize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
134 usize = rsize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
135 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
136 else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
137 rsize = usize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
138 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
139 else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
140 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
141 rsize += rsize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
142 usize = rsize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
143 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
144 free(udata);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
145 udata = malloc(usize);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
146 if (!udata)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
147 return XSF_FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
148 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
149
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
150 rdata = realloc(udata, usize);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
151 if (!rdata)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
152 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
153 free(udata);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
154 return XSF_FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
155 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
156
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
157 if (0)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
158 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
159 unsigned ccrc = crc32(crc32(0L, Z_NULL, 0), rdata, usize);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
160 if (ccrc != zcrc)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
161 return XSF_FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
162 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
163
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
164 ret = load_map(issave, rdata, usize);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
165 free(rdata);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
166 return ret;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
167 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
168
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
169 static int load_psf_one(unsigned char *pfile, unsigned bytes)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
170 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
171 unsigned char *ptr = pfile;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
172 unsigned code_size;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
173 unsigned resv_size;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
174 unsigned code_crc;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
175 if (bytes < 16 || getdwordle(ptr) != 0x24465350)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
176 return XSF_FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
177
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
178 resv_size = getdwordle(ptr + 4);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
179 code_size = getdwordle(ptr + 8);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
180 code_crc = getdwordle(ptr + 12);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
181
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
182 if (resv_size)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
183 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
184 unsigned resv_pos = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
185 ptr = pfile + 16;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
186 if (16+ resv_size > bytes)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
187 return XSF_FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
188 while (resv_pos + 12 < resv_size)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
189 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
190 unsigned save_size = getdwordle(ptr + resv_pos + 4);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
191 unsigned save_crc = getdwordle(ptr + resv_pos + 8);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
192 if (getdwordle(ptr + resv_pos + 0) == 0x45564153)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
193 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
194 if (resv_pos + 12 + save_size > resv_size)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
195 return XSF_FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
196 if (!load_mapz(1, ptr + resv_pos + 12, save_size, save_crc))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
197 return XSF_FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
198 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
199 resv_pos += 12 + save_size;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
200 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
201 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
202
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
203 if (code_size)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
204 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
205 ptr = pfile + 16 + resv_size;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
206 if (16 + resv_size + code_size > bytes)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
207 return XSF_FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
208 if (!load_mapz(0, ptr, code_size, code_crc))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
209 return XSF_FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
210 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
211
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
212 return XSF_TRUE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
213 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
214
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
215 typedef struct
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
216 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
217 const char *tag;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
218 int taglen;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
219 int level;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
220 int found;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
221 } loadlibwork_t;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
222
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
223 static int load_libs(int level, void *pfile, unsigned bytes);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
224
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
225 static int load_psfcb(void *pWork, const char *pNameTop, const char *pNameEnd, const char *pValueTop, const char *pValueEnd)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
226 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
227 loadlibwork_t *pwork = (loadlibwork_t *)pWork;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
228 int ret = xsf_tagenum_callback_returnvaluecontinue;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
229 if (pNameEnd - pNameTop == pwork->taglen && !strncasecmp(pNameTop, pwork->tag , pwork->taglen))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
230 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
231 unsigned l = pValueEnd - pValueTop;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
232 char *lib = malloc(l + 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
233 if (!lib)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
234 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
235 ret = xsf_tagenum_callback_returnvaluebreak;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
236 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
237 else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
238 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
239 void *libbuf;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
240 unsigned libsize;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
241 memcpy(lib, pValueTop, l);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
242 lib[l] = '\0';
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
243 if (!xsf_get_lib(lib, &libbuf, &libsize))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
244 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
245 ret = xsf_tagenum_callback_returnvaluebreak;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
246 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
247 else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
248 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
249 if (!load_libs(pwork->level + 1, libbuf, libsize) || !load_psf_one(libbuf, libsize))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
250 ret = xsf_tagenum_callback_returnvaluebreak;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
251 else
2965
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2961
diff changeset
252 {
2961
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
253 pwork->found++;
2965
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2961
diff changeset
254 free(libbuf);
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2961
diff changeset
255 }
2961
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
256 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
257 free(lib);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
258 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
259 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
260 return ret;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
261 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
262
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
263 static int load_libs(int level, void *pfile, unsigned bytes)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
264 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
265 char tbuf[16];
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
266 loadlibwork_t work;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
267 int n = 1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
268
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
269 if (level > 10)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
270 return XSF_TRUE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
271
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
272 work.level = level;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
273 work.tag = "_lib";
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
274
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
275 do
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
276 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
277 work.taglen = strlen(work.tag);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
278 work.found = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
279
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
280 if (xsf_tagenum(load_psfcb, &work, pfile, bytes) < 0)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
281 return XSF_FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
282
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
283 #ifdef HAVE_SPRINTF_S
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
284 sprintf_s(tbuf, sizeof(tbuf), "_lib%10d", ++n);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
285 #else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
286 sprintf(tbuf, "_lib%10d", ++n);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
287 #endif
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
288 work.tag = tbuf;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
289 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
290 while (work.found);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
291
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
292 return XSF_TRUE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
293 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
294
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
295 static int load_psf(void *pfile, unsigned bytes)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
296 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
297 load_term();
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
298
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
299 if (!load_libs(1, pfile, bytes) || !load_psf_one(pfile, bytes))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
300 return XSF_FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
301
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
302 return XSF_TRUE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
303 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
304
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
305 static void load_getstateinit(unsigned ptr)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
306 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
307 loaderwork.stateptr = ptr;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
308 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
309
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
310 static u16 getwordle(const unsigned char *pData)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
311 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
312 return pData[0] | (((u16)pData[1]) << 8);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
313 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
314
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
315 static void load_getsta(Status_Reg *ptr, unsigned l)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
316 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
317 unsigned s = l << 2;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
318 unsigned i;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
319 if ((loaderwork.stateptr > loaderwork.statesize) || ((loaderwork.stateptr + s) > loaderwork.statesize))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
320 return;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
321 for (i = 0; i < l; i++)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
322 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
323 u32 st = getdwordle(loaderwork.state + loaderwork.stateptr + (i << 2));
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
324 ptr[i].bits.N = (st >> 31) & 1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
325 ptr[i].bits.Z = (st >> 30) & 1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
326 ptr[i].bits.C = (st >> 29) & 1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
327 ptr[i].bits.V = (st >> 28) & 1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
328 ptr[i].bits.Q = (st >> 27) & 1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
329 ptr[i].bits.RAZ = (st >> 8) & ((1 << 19) - 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
330 ptr[i].bits.I = (st >> 7) & 1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
331 ptr[i].bits.F = (st >> 6) & 1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
332 ptr[i].bits.T = (st >> 5) & 1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
333 ptr[i].bits.mode = (st >> 0) & 0x1f;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
334 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
335 loaderwork.stateptr += s;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
336 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
337
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
338 static void load_getbool(BOOL *ptr, unsigned l)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
339 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
340 unsigned s = l << 2;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
341 unsigned i;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
342 if ((loaderwork.stateptr > loaderwork.statesize) || ((loaderwork.stateptr + s) > loaderwork.statesize))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
343 return;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
344 for (i = 0; i < l; i++)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
345 ptr[i] = (BOOL)getdwordle(loaderwork.state + loaderwork.stateptr + (i << 2));
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
346 loaderwork.stateptr += s;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
347 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
348
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
349 #if defined(SIGNED_IS_NOT_2S_COMPLEMENT)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
350 /* 2's complement */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
351 #define u32tos32(v) ((s32)((((s64)(v)) ^ 0x8000) - 0x8000))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
352 #else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
353 /* 2's complement */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
354 #define u32tos32(v) ((s32)v)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
355 #endif
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
356
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
357 static void load_gets32(s32 *ptr, unsigned l)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
358 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
359 unsigned s = l << 2;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
360 unsigned i;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
361 if ((loaderwork.stateptr > loaderwork.statesize) || ((loaderwork.stateptr + s) > loaderwork.statesize))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
362 return;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
363 for (i = 0; i < l; i++)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
364 ptr[i] = u32tos32(getdwordle(loaderwork.state + loaderwork.stateptr + (i << 2)));
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
365 loaderwork.stateptr += s;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
366 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
367
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
368 static void load_getu32(u32 *ptr, unsigned l)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
369 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
370 unsigned s = l << 2;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
371 unsigned i;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
372 if ((loaderwork.stateptr > loaderwork.statesize) || ((loaderwork.stateptr + s) > loaderwork.statesize))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
373 return;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
374 for (i = 0; i < l; i++)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
375 ptr[i] = getdwordle(loaderwork.state + loaderwork.stateptr + (i << 2));
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
376 loaderwork.stateptr += s;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
377 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
378
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
379 static void load_getu16(u16 *ptr, unsigned l)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
380 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
381 unsigned s = l << 1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
382 unsigned i;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
383 if ((loaderwork.stateptr > loaderwork.statesize) || ((loaderwork.stateptr + s) > loaderwork.statesize))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
384 return;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
385 for (i = 0; i < l; i++)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
386 ptr[i] = getwordle(loaderwork.state + loaderwork.stateptr + (i << 1));
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
387 loaderwork.stateptr += s;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
388 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
389
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
390 static void load_getu8(u8 *ptr, unsigned l)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
391 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
392 unsigned s = l;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
393 unsigned i;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
394 if ((loaderwork.stateptr > loaderwork.statesize) || ((loaderwork.stateptr + s) > loaderwork.statesize))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
395 return;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
396 for (i = 0; i < l; i++)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
397 ptr[i] = loaderwork.state[loaderwork.stateptr + i];
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
398 loaderwork.stateptr += s;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
399 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
400
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
401 void gdb_stub_fix(armcpu_t *armcpu)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
402 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
403 /* armcpu->R[15] = armcpu->instruct_adr; */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
404 armcpu->next_instruction = armcpu->instruct_adr;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
405 if(armcpu->CPSR.bits.T == 0)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
406 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
407 armcpu->instruction = MMU_read32_acl(armcpu->proc_ID, armcpu->next_instruction,CP15_ACCESS_EXECUTE);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
408 armcpu->instruct_adr = armcpu->next_instruction;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
409 armcpu->next_instruction += 4;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
410 armcpu->R[15] = armcpu->next_instruction + 4;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
411 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
412 else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
413 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
414 armcpu->instruction = MMU_read16_acl(armcpu->proc_ID, armcpu->next_instruction,CP15_ACCESS_EXECUTE);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
415 armcpu->instruct_adr = armcpu->next_instruction;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
416 armcpu->next_instruction += 2;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
417 armcpu->R[15] = armcpu->next_instruction + 2;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
418 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
419 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
420
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
421 static void load_setstate(void)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
422 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
423 if (!loaderwork.statesize)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
424 return;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
425
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
426 /* Skip over "Desmume Save File" crap */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
427 load_getstateinit(0x17);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
428
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
429 /* Read ARM7 cpu registers */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
430 load_getu32(&NDS_ARM7.proc_ID, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
431 load_getu32(&NDS_ARM7.instruction, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
432 load_getu32(&NDS_ARM7.instruct_adr, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
433 load_getu32(&NDS_ARM7.next_instruction, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
434 load_getu32(NDS_ARM7.R, 16);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
435 load_getsta(&NDS_ARM7.CPSR, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
436 load_getsta(&NDS_ARM7.SPSR, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
437 load_getu32(&NDS_ARM7.R13_usr, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
438 load_getu32(&NDS_ARM7.R14_usr, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
439 load_getu32(&NDS_ARM7.R13_svc, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
440 load_getu32(&NDS_ARM7.R14_svc, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
441 load_getu32(&NDS_ARM7.R13_abt, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
442 load_getu32(&NDS_ARM7.R14_abt, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
443 load_getu32(&NDS_ARM7.R13_und, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
444 load_getu32(&NDS_ARM7.R14_und, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
445 load_getu32(&NDS_ARM7.R13_irq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
446 load_getu32(&NDS_ARM7.R14_irq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
447 load_getu32(&NDS_ARM7.R8_fiq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
448 load_getu32(&NDS_ARM7.R9_fiq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
449 load_getu32(&NDS_ARM7.R10_fiq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
450 load_getu32(&NDS_ARM7.R11_fiq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
451 load_getu32(&NDS_ARM7.R12_fiq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
452 load_getu32(&NDS_ARM7.R13_fiq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
453 load_getu32(&NDS_ARM7.R14_fiq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
454 load_getsta(&NDS_ARM7.SPSR_svc, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
455 load_getsta(&NDS_ARM7.SPSR_abt, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
456 load_getsta(&NDS_ARM7.SPSR_und, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
457 load_getsta(&NDS_ARM7.SPSR_irq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
458 load_getsta(&NDS_ARM7.SPSR_fiq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
459 load_getu32(&NDS_ARM7.intVector, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
460 load_getu8(&NDS_ARM7.LDTBit, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
461 load_getbool(&NDS_ARM7.waitIRQ, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
462 load_getbool(&NDS_ARM7.wIRQ, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
463 load_getbool(&NDS_ARM7.wirq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
464
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
465 /* Read ARM9 cpu registers */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
466 load_getu32(&NDS_ARM9.proc_ID, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
467 load_getu32(&NDS_ARM9.instruction, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
468 load_getu32(&NDS_ARM9.instruct_adr, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
469 load_getu32(&NDS_ARM9.next_instruction, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
470 load_getu32(NDS_ARM9.R, 16);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
471 load_getsta(&NDS_ARM9.CPSR, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
472 load_getsta(&NDS_ARM9.SPSR, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
473 load_getu32(&NDS_ARM9.R13_usr, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
474 load_getu32(&NDS_ARM9.R14_usr, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
475 load_getu32(&NDS_ARM9.R13_svc, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
476 load_getu32(&NDS_ARM9.R14_svc, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
477 load_getu32(&NDS_ARM9.R13_abt, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
478 load_getu32(&NDS_ARM9.R14_abt, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
479 load_getu32(&NDS_ARM9.R13_und, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
480 load_getu32(&NDS_ARM9.R14_und, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
481 load_getu32(&NDS_ARM9.R13_irq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
482 load_getu32(&NDS_ARM9.R14_irq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
483 load_getu32(&NDS_ARM9.R8_fiq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
484 load_getu32(&NDS_ARM9.R9_fiq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
485 load_getu32(&NDS_ARM9.R10_fiq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
486 load_getu32(&NDS_ARM9.R11_fiq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
487 load_getu32(&NDS_ARM9.R12_fiq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
488 load_getu32(&NDS_ARM9.R13_fiq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
489 load_getu32(&NDS_ARM9.R14_fiq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
490 load_getsta(&NDS_ARM9.SPSR_svc, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
491 load_getsta(&NDS_ARM9.SPSR_abt, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
492 load_getsta(&NDS_ARM9.SPSR_und, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
493 load_getsta(&NDS_ARM9.SPSR_irq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
494 load_getsta(&NDS_ARM9.SPSR_fiq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
495 load_getu32(&NDS_ARM9.intVector, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
496 load_getu8(&NDS_ARM9.LDTBit, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
497 load_getbool(&NDS_ARM9.waitIRQ, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
498 load_getbool(&NDS_ARM9.wIRQ, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
499 load_getbool(&NDS_ARM9.wirq, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
500
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
501 /* Read in other internal variables that are important */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
502 load_gets32(&nds.ARM9Cycle, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
503 load_gets32(&nds.ARM7Cycle, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
504 load_gets32(&nds.cycles, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
505 load_gets32(nds.timerCycle[0], 4);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
506 load_gets32(nds.timerCycle[1], 4);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
507 load_getbool(nds.timerOver[0], 4);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
508 load_getbool(nds.timerOver[1], 4);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
509 load_gets32(&nds.nextHBlank, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
510 load_getu32(&nds.VCount, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
511 load_getu32(&nds.old, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
512 load_gets32(&nds.diff, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
513 load_getbool(&nds.lignerendu, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
514 load_getu16(&nds.touchX, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
515 load_getu16(&nds.touchY, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
516
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
517 /* Read in memory/registers specific to the ARM9 */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
518 load_getu8 (ARM9Mem.ARM9_ITCM, 0x8000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
519 load_getu8 (ARM9Mem.ARM9_DTCM, 0x4000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
520 load_getu8 (ARM9Mem.ARM9_WRAM, 0x1000000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
521 load_getu8 (ARM9Mem.MAIN_MEM, 0x400000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
522 load_getu8 (ARM9Mem.ARM9_REG, 0x10000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
523 load_getu8 (ARM9Mem.ARM9_VMEM, 0x800);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
524 load_getu8 (ARM9Mem.ARM9_OAM, 0x800);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
525 load_getu8 (ARM9Mem.ARM9_ABG, 0x80000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
526 load_getu8 (ARM9Mem.ARM9_BBG, 0x20000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
527 load_getu8 (ARM9Mem.ARM9_AOBJ, 0x40000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
528 load_getu8 (ARM9Mem.ARM9_BOBJ, 0x20000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
529 load_getu8 (ARM9Mem.ARM9_LCD, 0xA4000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
530
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
531 /* Read in memory/registers specific to the ARM7 */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
532 load_getu8 (MMU.ARM7_ERAM, 0x10000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
533 load_getu8 (MMU.ARM7_REG, 0x10000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
534 load_getu8 (MMU.ARM7_WIRAM, 0x10000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
535
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
536 /* Read in shared memory */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
537 load_getu8 (MMU.SWIRAM, 0x8000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
538
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
539 #ifdef GDB_STUB
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
540 #else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
541 gdb_stub_fix(&NDS_ARM9);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
542 gdb_stub_fix(&NDS_ARM7);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
543 #endif
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
544 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
545
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
546 static struct
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
547 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
548 unsigned char *pcmbufalloc;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
549 unsigned char *pcmbuftop;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
550 unsigned filled;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
551 unsigned used;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
552 u32 bufferbytes;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
553 u32 cycles;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
554 int xfs_load;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
555 int sync_type;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
556 int arm7_clockdown_level;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
557 int arm9_clockdown_level;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
558 } sndifwork = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
559
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
560 static void SNDIFDeInit(void)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
561 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
562 if (sndifwork.pcmbufalloc)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
563 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
564 free(sndifwork.pcmbufalloc);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
565 sndifwork.pcmbufalloc = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
566 sndifwork.pcmbuftop = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
567 sndifwork.bufferbytes = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
568 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
569 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
570 static int SNDIFInit(int buffersize)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
571 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
572 u32 bufferbytes = buffersize * sizeof(s16);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
573 SNDIFDeInit();
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
574 sndifwork.pcmbufalloc = malloc(bufferbytes + 3);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
575 if (!sndifwork.pcmbufalloc)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
576 return -1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
577 sndifwork.pcmbuftop = sndifwork.pcmbufalloc + ((4 - (((int)sndifwork.pcmbufalloc) & 3)) & 3);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
578 sndifwork.bufferbytes = bufferbytes;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
579 sndifwork.filled = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
580 sndifwork.used = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
581 sndifwork.cycles = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
582 return 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
583 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
584 static void SNDIFMuteAudio(void)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
585 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
586 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
587 static void SNDIFUnMuteAudio(void)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
588 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
589 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
590 static void SNDIFSetVolume(int volume)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
591 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
592 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
593 static int SNDIFGetAudioSpace(void)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
594 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
595 return sndifwork.bufferbytes >> 2; // bytes to samples
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
596 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
597 static void SNDIFUpdateAudio(s16 * buffer, u32 num_samples)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
598 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
599 u32 num_bytes = num_samples << 2;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
600 if (num_bytes > sndifwork.bufferbytes) num_bytes = sndifwork.bufferbytes;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
601 memcpy(sndifwork.pcmbuftop, buffer, num_bytes);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
602 sndifwork.filled = num_bytes;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
603 sndifwork.used = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
604 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
605 #define VIO2SFSNDIFID 2
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
606 static SoundInterface_struct VIO2SFSNDIF =
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
607 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
608 VIO2SFSNDIFID,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
609 "vio2sf Sound Interface",
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
610 SNDIFInit,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
611 SNDIFDeInit,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
612 SNDIFUpdateAudio,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
613 SNDIFGetAudioSpace,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
614 SNDIFMuteAudio,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
615 SNDIFUnMuteAudio,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
616 SNDIFSetVolume
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
617 };
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
618
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
619 SoundInterface_struct *SNDCoreList[] = {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
620 &VIO2SFSNDIF,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
621 &SNDDummy,
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
622 NULL
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
623 };
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
624
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
625 static struct armcpu_ctrl_iface *arm9_ctrl_iface = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
626 static struct armcpu_ctrl_iface *arm7_ctrl_iface = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
627
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
628 int xsf_start(void *pfile, unsigned bytes)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
629 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
630 int frames = xsf_tagget_int("_frames", pfile, bytes, -1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
631 int clockdown = xsf_tagget_int("_clockdown", pfile, bytes, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
632 sndifwork.sync_type = xsf_tagget_int("_vio2sf_sync_type", pfile, bytes, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
633 sndifwork.arm9_clockdown_level = xsf_tagget_int("_vio2sf_arm9_clockdown_level", pfile, bytes, clockdown);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
634 sndifwork.arm7_clockdown_level = xsf_tagget_int("_vio2sf_arm7_clockdown_level", pfile, bytes, clockdown);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
635
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
636 sndifwork.xfs_load = 0;
2965
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2961
diff changeset
637 printf("load_psf... ");
2961
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
638 if (!load_psf(pfile, bytes))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
639 return XSF_FALSE;
2965
6013ab159139 Make forward seeking work. Backwards seeking is still not working.
William Pitcock <nenolod@atheme.org>
parents: 2961
diff changeset
640 printf("ok!\n");
2961
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
641
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
642 #ifdef GDB_STUB
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
643 if (NDS_Init(&arm9_base_memory_iface, &arm9_ctrl_iface, &arm7_base_memory_iface, &arm7_ctrl_iface))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
644 #else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
645 if (NDS_Init())
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
646 #endif
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
647 return XSF_FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
648
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
649 SPU_ChangeSoundCore(VIO2SFSNDIFID, 737);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
650
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
651 execute = FALSE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
652
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
653 MMU_unsetRom();
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
654 if (loaderwork.rom)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
655 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
656 NDS_SetROM(loaderwork.rom, loaderwork.romsize - 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
657 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
658
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
659 NDS_Reset();
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
660
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
661 execute = TRUE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
662
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
663 if (loaderwork.state)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
664 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
665 armcp15_t *c9 = (armcp15_t *)NDS_ARM9.coproc[15];
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
666 int proc;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
667 if (frames == -1)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
668 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
669
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
670 /* set initial ARM9 coprocessor state */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
671
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
672 armcp15_moveARM2CP(c9, 0x00000000, 0x01, 0x00, 0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
673 armcp15_moveARM2CP(c9, 0x00000000, 0x07, 0x05, 0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
674 armcp15_moveARM2CP(c9, 0x00000000, 0x07, 0x06, 0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
675 armcp15_moveARM2CP(c9, 0x00000000, 0x07, 0x0a, 0, 4);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
676 armcp15_moveARM2CP(c9, 0x04000033, 0x06, 0x00, 0, 4);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
677 armcp15_moveARM2CP(c9, 0x0200002d, 0x06, 0x01, 0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
678 armcp15_moveARM2CP(c9, 0x027e0021, 0x06, 0x02, 0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
679 armcp15_moveARM2CP(c9, 0x08000035, 0x06, 0x03, 0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
680 armcp15_moveARM2CP(c9, 0x027e001b, 0x06, 0x04, 0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
681 armcp15_moveARM2CP(c9, 0x0100002f, 0x06, 0x05, 0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
682 armcp15_moveARM2CP(c9, 0xffff001d, 0x06, 0x06, 0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
683 armcp15_moveARM2CP(c9, 0x027ff017, 0x06, 0x07, 0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
684 armcp15_moveARM2CP(c9, 0x00000020, 0x09, 0x01, 0, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
685
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
686 armcp15_moveARM2CP(c9, 0x027e000a, 0x09, 0x01, 0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
687
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
688 armcp15_moveARM2CP(c9, 0x00000042, 0x02, 0x00, 0, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
689 armcp15_moveARM2CP(c9, 0x00000042, 0x02, 0x00, 0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
690 armcp15_moveARM2CP(c9, 0x00000002, 0x03, 0x00, 0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
691 armcp15_moveARM2CP(c9, 0x05100011, 0x05, 0x00, 0, 3);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
692 armcp15_moveARM2CP(c9, 0x15111011, 0x05, 0x00, 0, 2);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
693 armcp15_moveARM2CP(c9, 0x07dd1e10, 0x01, 0x00, 0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
694 armcp15_moveARM2CP(c9, 0x0005707d, 0x01, 0x00, 0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
695
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
696 armcp15_moveARM2CP(c9, 0x00000000, 0x07, 0x0a, 0, 4);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
697 armcp15_moveARM2CP(c9, 0x02004000, 0x07, 0x05, 0, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
698 armcp15_moveARM2CP(c9, 0x02004000, 0x07, 0x0e, 0, 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
699
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
700 /* set initial timer state */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
701
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
702 MMU_write16(0, REG_TM0CNTL, 0x0000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
703 MMU_write16(0, REG_TM0CNTH, 0x00C1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
704 MMU_write16(1, REG_TM0CNTL, 0x0000);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
705 MMU_write16(1, REG_TM0CNTH, 0x00C1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
706 MMU_write16(1, REG_TM1CNTL, 0xf7e7);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
707 MMU_write16(1, REG_TM1CNTH, 0x00C1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
708
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
709 /* set initial interrupt state */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
710
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
711 MMU.reg_IME[0] = 0x00000001;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
712 MMU.reg_IE[0] = 0x00042001;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
713 MMU.reg_IME[1] = 0x00000001;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
714 MMU.reg_IE[1] = 0x0104009d;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
715 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
716 else if (frames > 0)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
717 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
718 /* execute boot code */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
719 int i;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
720 for (i=0; i<frames; i++)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
721 NDS_exec_frame(0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
722 i = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
723 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
724
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
725 /* load state */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
726
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
727 load_setstate();
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
728 free(loaderwork.state);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
729 loaderwork.state = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
730
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
731 if (frames == -1)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
732 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
733 armcp15_moveARM2CP(c9, (NDS_ARM9.R13_irq & 0x0fff0000) | 0x0a, 0x09, 0x01, 0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
734 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
735
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
736 /* restore timer state */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
737
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
738 for (proc = 0; proc < 2; proc++)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
739 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
740 MMU_write16(proc, REG_TM0CNTH, T1ReadWord(MMU.MMU_MEM[proc][0x40], REG_TM0CNTH & 0xFFF));
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
741 MMU_write16(proc, REG_TM1CNTH, T1ReadWord(MMU.MMU_MEM[proc][0x40], REG_TM1CNTH & 0xFFF));
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
742 MMU_write16(proc, REG_TM2CNTH, T1ReadWord(MMU.MMU_MEM[proc][0x40], REG_TM2CNTH & 0xFFF));
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
743 MMU_write16(proc, REG_TM3CNTH, T1ReadWord(MMU.MMU_MEM[proc][0x40], REG_TM3CNTH & 0xFFF));
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
744 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
745 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
746 else if (frames > 0)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
747 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
748 /* skip 1 sec */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
749 int i;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
750 for (i=0; i<frames; i++)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
751 NDS_exec_frame(0, 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
752 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
753 execute = TRUE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
754 sndifwork.xfs_load = 1;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
755 return XSF_TRUE;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
756 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
757
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
758 int xsf_gen(void *pbuffer, unsigned samples)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
759 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
760 unsigned char *ptr = pbuffer;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
761 unsigned bytes = samples <<= 2;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
762 if (!sndifwork.xfs_load) return 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
763 while (bytes)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
764 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
765 unsigned remainbytes = sndifwork.filled - sndifwork.used;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
766 if (remainbytes > 0)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
767 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
768 if (remainbytes > bytes)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
769 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
770 memcpy(ptr, sndifwork.pcmbuftop + sndifwork.used, bytes);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
771 sndifwork.used += bytes;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
772 ptr += bytes;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
773 remainbytes -= bytes; /**/
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
774 bytes = 0; /**/
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
775 break;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
776 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
777 else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
778 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
779 memcpy(ptr, sndifwork.pcmbuftop + sndifwork.used, remainbytes);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
780 sndifwork.used += remainbytes;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
781 ptr += remainbytes;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
782 bytes -= remainbytes;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
783 remainbytes = 0;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
784 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
785 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
786 if (remainbytes == 0)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
787 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
788
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
789 #define HBASE_CYCLES 33509300.322234
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
790 #define VBASE_CYCLES (((double)HBASE_CYCLES) / 100)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
791 #define HSAMPLES ((u32)((44100.0 * 6 * (99 + 256)) / HBASE_CYCLES))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
792 #define VSAMPLES ((u32)((44100.0 * 6 * (99 + 256) * 263) / HBASE_CYCLES))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
793
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
794 int numsamples;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
795 if (sndifwork.sync_type == 1)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
796 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
797 /* vsync */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
798 sndifwork.cycles += (441 * 6 * (99 + 256) * 263);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
799 if (sndifwork.cycles >= (u32)(VBASE_CYCLES * (VSAMPLES + 1)))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
800 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
801 numsamples = (VSAMPLES + 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
802 sndifwork.cycles -= (u32)(VBASE_CYCLES * (VSAMPLES + 1));
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
803 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
804 else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
805 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
806 numsamples = (VSAMPLES + 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
807 sndifwork.cycles -= (u32)(VBASE_CYCLES * (VSAMPLES + 0));
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
808 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
809 NDS_exec_frame(sndifwork.arm9_clockdown_level, sndifwork.arm7_clockdown_level);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
810 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
811 else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
812 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
813 /* hsync */
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
814 sndifwork.cycles += (44100 * 6 * (99 + 256));
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
815 if (sndifwork.cycles >= (u32)(HBASE_CYCLES * (HSAMPLES + 1)))
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
816 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
817 numsamples = (HSAMPLES + 1);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
818 sndifwork.cycles -= (u32)(HBASE_CYCLES * (HSAMPLES + 1));
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
819 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
820 else
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
821 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
822 numsamples = (HSAMPLES + 0);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
823 sndifwork.cycles -= (u32)(HBASE_CYCLES * (HSAMPLES + 0));
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
824 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
825 NDS_exec_hframe(sndifwork.arm9_clockdown_level, sndifwork.arm7_clockdown_level);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
826 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
827 SPU_EmulateSamples(numsamples);
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
828 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
829 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
830 return ptr - (unsigned char *)pbuffer;
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
831 }
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
832
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
833 void xsf_term(void)
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
834 {
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
835 MMU_unsetRom();
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
836 NDS_DeInit();
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
837 load_term();
70b0973e7b70 Merge xsf plugin.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
838 }