-
Notifications
You must be signed in to change notification settings - Fork 100
/
sfc_mapper_002_uxrom.c
57 lines (50 loc) · 1.69 KB
/
sfc_mapper_002_uxrom.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "sfc_cpu.h"
#include "sfc_famicom.h"
#include "sfc_mapper_helper.h"
#include <assert.h>
#include <string.h>
#ifndef NDEBUG
#include <stdio.h>
#endif
// ------------------------------- MAPPER 002 - UxROM
/// <summary>
/// StepFC: MAPPER 002 - UxROM 重置
/// </summary>
/// <param name="famicom">The famicom.</param>
/// <returns></returns>
static sfc_ecode sfc_mapper_02_reset(sfc_famicom_t* famicom) {
// 你用UxROM居然没有32KB PRG-ROM?
assert(famicom->rom_info.count_prgrom16kb > 2 && "bad count");
// PRG-ROM
sfc_load_prgrom_8k(famicom, 0, 0);
sfc_load_prgrom_8k(famicom, 1, 1);
const int last = famicom->rom_info.count_prgrom16kb * 2;
sfc_load_prgrom_8k(famicom, 2, last-2);
sfc_load_prgrom_8k(famicom, 3, last-1);
// CHR-ROM 没有 是RAM
for (int i = 0; i != 8; ++i)
sfc_load_chrrom_1k(famicom, i, i);
return SFC_ERROR_OK;
}
/// <summary>
/// SFCs the mapper 02 write high.
/// </summary>
/// <param name="famicom">The famicom.</param>
/// <param name="address">The address.</param>
/// <param name="value">The value.</param>
static void sfc_mapper_02_write_high(sfc_famicom_t* famicom, uint16_t address, uint8_t value) {
const int bank = (value % famicom->rom_info.count_prgrom16kb) * 2;
sfc_load_prgrom_8k(famicom, 0, bank + 0);
sfc_load_prgrom_8k(famicom, 1, bank + 1);
}
/// <summary>
/// SFCs the load mapper 01.
/// </summary>
/// <param name="famicom">The famicom.</param>
/// <returns></returns>
extern inline sfc_ecode sfc_load_mapper_02(sfc_famicom_t* famicom) {
// 初始化回调接口
famicom->mapper.reset = sfc_mapper_02_reset;
famicom->mapper.write_high = sfc_mapper_02_write_high;
return SFC_ERROR_OK;
}