1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Mupen64plus - cart_rom.c *
3 * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
4 * Copyright (C) 2014 Bobby Smiles *
5 * *
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. *
10 * *
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. *
15 * *
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 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
21
22 #include "cart_rom.h"
23 #include "pi_controller.h"
24
init_cart_rom(struct cart_rom * cart_rom,uint8_t * rom,size_t rom_size)25 void init_cart_rom(struct cart_rom* cart_rom,
26 uint8_t* rom, size_t rom_size)
27 {
28 cart_rom->rom = rom;
29 cart_rom->rom_size = rom_size;
30 }
31
poweron_cart_rom(struct cart_rom * cart_rom)32 void poweron_cart_rom(struct cart_rom* cart_rom)
33 {
34 cart_rom->last_write = 0;
35 cart_rom->rom_written = 0;
36 }
37
38
read_cart_rom(void * opaque,uint32_t address,uint32_t * value)39 int read_cart_rom(void* opaque, uint32_t address, uint32_t* value)
40 {
41 struct pi_controller* pi = (struct pi_controller*)opaque;
42 uint32_t addr = ROM_ADDR(address);
43
44 if (pi->cart_rom.rom_written)
45 {
46 *value = pi->cart_rom.last_write;
47 pi->cart_rom.rom_written = 0;
48 }
49 else
50 {
51 *value = *(uint32_t*)(pi->cart_rom.rom + addr);
52 }
53
54 return 0;
55 }
56
write_cart_rom(void * opaque,uint32_t address,uint32_t value,uint32_t mask)57 int write_cart_rom(void* opaque, uint32_t address, uint32_t value, uint32_t mask)
58 {
59 struct pi_controller* pi = (struct pi_controller*)opaque;
60 pi->cart_rom.last_write = value & mask;
61 pi->cart_rom.rom_written = 1;
62
63 return 0;
64 }
65