llvm-mos-sdk
nes-mmc1
mapper.h
Go to the documentation of this file.
1
// Copyright 2022 LLVM-MOS Project
2
// Licensed under the Apache License, Version 2.0 with LLVM Exceptions.
3
// See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
4
// information.
5
//
6
// Copyright 2019 Doug Fraker
7
// Copyright 2018 Christopher Parker
8
//
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
15
//
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
18
//
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
// SOFTWARE.
26
27
#ifndef _MAPPER_H_
28
#define _MAPPER_H_
29
30
#include <
ines.h
>
31
32
#ifdef __cplusplus
33
extern
"C"
{
34
#endif
35
36
// Contains functions to help with working with multiple PRG/CHR banks
37
38
// Access the current settings of MMC1 registers.
39
extern
volatile
const
char
CHR_BANK0_CUR
;
40
extern
volatile
const
char
CHR_BANK1_CUR
;
41
extern
volatile
const
char
MMC1_CTRL_CUR
;
42
43
// Maximum level of recursion to allow with banked_call and similar functions.
44
#define MAX_BANK_DEPTH 10
45
46
// Switch to another bank and call this function.
47
// Note: Using banked_call to call a second function from within
48
// another banked_call is safe.
49
__attribute__((leaf, callback(2))) void banked_call(
char
bank_id
,
50
void
(*
method
)(
void
));
51
52
// Switch to the given bank (to $8000-bfff). Your prior bank is not saved.
53
// Can be used for reading data with a function in the fixed bank.
54
// bank_id: The bank to switch to.
55
__attribute__((leaf))
void
set_prg_bank(
char
bank_id
);
56
57
// Get the current PRG bank at $8000-bfff.
58
// returns: The current bank.
59
__attribute__((leaf))
char
get_prg_bank(
void
);
60
61
// Set the current 1st 4k chr bank to the bank with this id.
62
// this will take effect at the next frame
63
// and automatically rewrite at the top of every frame
64
__attribute__((leaf))
void
set_chr_bank_0(
char
bank_id
);
65
66
// Set the current 2nd 4k chr bank to the bank with this id.
67
// this will take effect at the next frame
68
// and automatically rewrite at the top of every frame
69
__attribute__((leaf))
void
set_chr_bank_1(
char
bank_id
);
70
71
// Set the current 1st 4k chr bank to the bank with this id.
72
// this will take effect immediately, such as for mid screen changes
73
// but then will be overwritten by the set_chr_bank_0() value
74
// in the next frame.
75
void
split_chr_bank_0
(
char
bank_id
);
76
77
// Set the current 2nd 4k chr bank to the bank with this id.
78
// this will take effect immediately, such as for mid screen changes
79
// but then will be overwritten by the set_chr_bank_1() value
80
// in the next frame.
81
void
split_chr_bank_1
(
char
bank_id
);
82
83
// Sets the CHR bank 0 register to the given value and retries if interrupted.
84
// Persists across NMIs.
85
void
set_chr_bank_0_retry
(
char
bank_id
);
86
87
// Reliably sets the CHR bank 0 register to the given value and retries if
88
// interrupted. Persists across NMIs.
89
void
set_chr_bank_1_retry
(
char
bank_id
);
90
91
// if you need to swap CHR banks mid screen, perhaps you need more
92
// than 256 unique tiles, first write (one time only) the CHR bank
93
// for the top of the screen with set_chr_bank_0().
94
// Then, every frame, time a mid screen split (probably with
95
// a sprite zero hit) and then change the CHR bank with
96
// split_chr_bank_0().
97
//
98
// example ---- in game loop
99
// split(0); ---- wait for sprite zero hit, set X scroll to 0
100
// split_chr_bank_0(6) ---- change CHR bank to #6
101
102
#define MIRROR_LOWER_BANK 0
103
#define MIRROR_UPPER_BANK 1
104
#define MIRROR_VERTICAL 2
105
#define MIRROR_HORIZONTAL 3
106
107
// Set the current mirroring mode. Your options are MIRROR_LOWER_BANK,
108
// MIRROR_UPPER_BANK, MIRROR_HORIZONTAL, and MIRROR_VERTICAL.
109
// LOWER and UPPER are single screen modes.
110
__attribute__((leaf))
void
set_mirroring(
char
mirroring);
111
112
// Set all 5 bits of the $8000 MMC1 Control register. Overwrites mirroring
113
// setting.
114
void
set_mmc1_ctrl
(
char
value);
115
116
// some things deleted
117
118
#ifdef __cplusplus
119
}
120
#endif
121
122
#endif // _MAPPER_H_
set_mmc1_ctrl
void set_mmc1_ctrl(char value)
split_chr_bank_0
void split_chr_bank_0(char bank_id)
ines.h
CHR_BANK1_CUR
const volatile char CHR_BANK1_CUR
set_chr_bank_0_retry
void set_chr_bank_0_retry(char bank_id)
split_chr_bank_1
void split_chr_bank_1(char bank_id)
CHR_BANK0_CUR
const volatile char CHR_BANK0_CUR
method
void(* method)(void))
Definition:
mapper.h:41
set_chr_bank_1_retry
void set_chr_bank_1_retry(char bank_id)
bank_id
char bank_id
Definition:
mapper.h:97
MMC1_CTRL_CUR
const volatile char MMC1_CTRL_CUR
Generated by
1.8.17