8
8
#include "../runtime.h"
9
9
#include "../wasm.h"
10
10
#include "../window.h"
11
+ #include "main.h"
11
12
12
13
#if defined(_WIN32 )
13
14
#include <windows.h>
14
15
#endif
15
16
16
17
#define DISK_FILE_EXT ".disk"
17
18
19
+ static uint8_t * memory ;
20
+ static w4_Disk disk = {0 };
21
+ static uint8_t * wasmData ;
22
+ static size_t wasmLength ;
23
+
18
24
typedef struct {
19
25
// Should be the 4 byte ASCII string "CART" (1414676803)
20
26
uint32_t magic ;
@@ -23,7 +29,7 @@ typedef struct {
23
29
char title [128 ];
24
30
25
31
// Length of the cart.wasm bytes used to offset backwards from the footer
26
- uint32_t cartLength ;
32
+ uint32_t wasmLength ;
27
33
} FileFooter ;
28
34
29
35
static long audioDataCallback (cubeb_stream * stream , void * userData ,
@@ -117,10 +123,12 @@ static void trimFileExtension (char *path) {
117
123
}
118
124
}
119
125
126
+ void resetCart () {
127
+ w4_runtimeInit (memory , & disk );
128
+ w4_wasmLoadModule (wasmData , wasmLength );
129
+ }
130
+
120
131
int main (int argc , const char * argv []) {
121
- uint8_t * cartBytes ;
122
- size_t cartLength ;
123
- w4_Disk disk = {0 };
124
132
const char * title = "WASM-4" ;
125
133
char * diskPath = NULL ;
126
134
@@ -139,9 +147,9 @@ int main (int argc, const char* argv[]) {
139
147
footer .title [sizeof (footer .title )- 1 ] = '\0' ;
140
148
title = footer .title ;
141
149
142
- cartBytes = malloc (footer .cartLength );
143
- fseek (file , - sizeof (FileFooter ) - footer .cartLength , SEEK_END );
144
- cartLength = fread (cartBytes , 1 , footer .cartLength , file );
150
+ wasmData = malloc (footer .wasmLength );
151
+ fseek (file , - sizeof (FileFooter ) - footer .wasmLength , SEEK_END );
152
+ wasmLength = fread (wasmData , 1 , footer .wasmLength , file );
145
153
fclose (file );
146
154
147
155
// Look for disk file
@@ -161,11 +169,11 @@ int main (int argc, const char* argv[]) {
161
169
}
162
170
163
171
fseek (file , 0 , SEEK_END );
164
- cartLength = ftell (file );
172
+ wasmLength = ftell (file );
165
173
fseek (file , 0 , SEEK_SET );
166
174
167
- cartBytes = malloc (cartLength );
168
- cartLength = fread (cartBytes , 1 , cartLength , file );
175
+ wasmData = malloc (wasmLength );
176
+ wasmLength = fread (wasmData , 1 , wasmLength , file );
169
177
fclose (file );
170
178
171
179
// Look for disk file
@@ -178,10 +186,10 @@ int main (int argc, const char* argv[]) {
178
186
179
187
audioInit ();
180
188
181
- uint8_t * memory = w4_wasmInit ();
189
+ memory = w4_wasmInit ();
182
190
w4_runtimeInit (memory , & disk );
183
191
184
- w4_wasmLoadModule (cartBytes , cartLength );
192
+ w4_wasmLoadModule (wasmData , wasmLength );
185
193
186
194
w4_windowBoot (title );
187
195
0 commit comments