1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
* Mupen64plus - flashram.c *
3
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
4
* Copyright (C) 2002 Hacktarux *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License as published by *
8
* the Free Software Foundation; either version 2 of the License, or *
9
* (at your option) any later version. *
11
* This program is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU General Public License for more details. *
16
* You should have received a copy of the GNU General Public License *
17
* along with this program; if not, write to the *
18
* Free Software Foundation, Inc., *
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
27
#include "../r4300/r4300.h"
29
#include "../main/main.h"
33
typedef enum flashram_mode
43
static unsigned long long status;
44
static unsigned char flashram[0x20000];
45
static unsigned int erase_offset, write_pointer;
47
void save_flashram_infos(char *buf)
49
memcpy(buf+0 , &use_flashram , 4);
50
memcpy(buf+4 , &mode , 4);
51
memcpy(buf+8 , &status , 8);
52
memcpy(buf+16, &erase_offset , 4);
53
memcpy(buf+20, &write_pointer, 4);
56
void load_flashram_infos(char *buf)
58
memcpy(&use_flashram , buf+0 , 4);
59
memcpy(&mode , buf+4 , 4);
60
memcpy(&status , buf+8 , 8);
61
memcpy(&erase_offset , buf+16, 4);
62
memcpy(&write_pointer, buf+20, 4);
71
unsigned int flashram_status()
73
return (status >> 32);
76
void flashram_command(unsigned int command)
78
switch(command & 0xff000000)
81
erase_offset = (command & 0xffff) * 128;
85
status = 0x1111800800c20000LL;
88
erase_offset = (command & 0xffff) * 128;
89
status = 0x1111800400c20000LL;
94
case 0xd2000000: // execute
104
filename = malloc(strlen(get_savespath())+
105
strlen(ROM_SETTINGS.goodname)+4+1);
106
strcpy(filename, get_savespath());
107
strcat(filename, ROM_SETTINGS.goodname);
108
strcat(filename, ".fla");
109
f = fopen(filename, "rb");
112
fread(flashram, 1, 0x20000, f);
117
for (i=0; i<0x20000; i++)
122
for (i=erase_offset; i<(erase_offset+128); i++)
124
flashram[i^S8] = 0xff;
126
f = fopen(filename, "wb");
129
printf("Warning: couldn't open flashram file '%s' for erasing.\n", filename);
133
fwrite(flashram, 1, 0x20000, f);
144
filename = malloc(strlen(get_savespath())+
145
strlen(ROM_SETTINGS.goodname)+4+1);
146
strcpy(filename, get_savespath());
147
strcat(filename, ROM_SETTINGS.goodname);
148
strcat(filename, ".fla");
149
f = fopen(filename, "rb");
152
fread(flashram, 1, 0x20000, f);
157
for (i=0; i<0x20000; i++)
162
for (i=0; i<128; i++)
164
flashram[(erase_offset+i)^S8]=
165
((unsigned char*)rdram)[(write_pointer+i)^S8];
167
f = fopen(filename, "wb");
170
printf("Warning: couldn't open flashram file '%s' for writing.\n", filename);
174
fwrite(flashram, 1, 0x20000, f);
183
printf("unknown flashram command with mode:%x\n", (int)mode);
191
status = 0x1111800100c20000LL;
195
status = 0x11118004f0000000LL;
198
printf("unknown flashram command:%x\n", (int)command);
204
void dma_read_flashram()
213
rdram[pi_register.pi_dram_addr_reg/4] = (unsigned int)(status >> 32);
214
rdram[pi_register.pi_dram_addr_reg/4+1] = (unsigned int)(status);
217
filename = malloc(strlen(get_savespath())+
218
strlen(ROM_SETTINGS.goodname)+4+1);
219
strcpy(filename, get_savespath());
220
strcat(filename, ROM_SETTINGS.goodname);
221
strcat(filename, ".fla");
222
f = fopen(filename, "rb");
225
fread(flashram, 1, 0x20000, f);
230
for (i=0; i<0x20000; i++)
236
for (i=0; i<(pi_register.pi_wr_len_reg & 0x0FFFFFF)+1; i++)
238
((unsigned char*)rdram)[(pi_register.pi_dram_addr_reg+i)^S8]=
239
flashram[(((pi_register.pi_cart_addr_reg-0x08000000)&0xFFFF)*2+i)^S8];
243
printf("unknown dma_read_flashram:%x\n", mode);
249
void dma_write_flashram()
254
write_pointer = pi_register.pi_dram_addr_reg;
257
printf("unknown dma_read_flashram:%x\n", mode);