llvm-mos-sdk
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 
43 #define MAPPER_USE_MIRRORED_NAMETABLE \
44  asm(".global __four_screen\n __four_screen = 0\n")
45 
52 #define MAPPER_USE_4_SCREEN_NAMETABLE \
53  asm(".global __four_screen\n __four_screen = 1\n")
54 
55 // Contains functions to help with working with multiple PRG/CHR banks
56 // For MMC3 code.
57 
58 // Switch to another bank and call this function. Note: Using banked_call to
59 // call a second function from within another banked_call is safe. This function
60 // works no matter which switchable bank the function is in.
61 __attribute__((leaf, callback(2))) void banked_call(char bankId,
62  void (*method)(void));
63 
64 // Same as banked_call, but assumes the bank is 8000/c000.
65 __attribute__((leaf, callback(2))) void banked_call_8000(char bankId,
66  void (*method)(void));
67 
68 // Same as banked_call, but assumes the bank is a000.
69 __attribute__((leaf, callback(2))) void banked_call_a000(char bankId,
70  void (*method)(void));
71 
72 // Sets the bank at the address with the given high byte.
73 __attribute__((leaf)) void set_prg_bank(char bank_id, char addr_hi);
74 
75 // Gets the bank at the address with the given high byte.
76 __attribute__((leaf)) char get_prg_bank(char addr_hi);
77 
78 // Switch to the given bank (at $8000-9fff or $c000-dfff). Your prior bank is
79 // not saved.
80 // bank_id: The bank to switch to.
81 __attribute__((leaf)) void set_prg_8000(char bank_id);
82 
83 // Get the current PRG bank at $8000-9fff (or $c000-dfff).
84 // returns: The current bank.
85 char get_prg_8000(void);
86 
87 // Switch to the given bank (at $a000-bfff). Your prior bank is not saved.
88 // bank_id: The bank to switch to.
89 __attribute__((leaf)) void set_prg_a000(char bank_id);
90 
91 // Get the current PRG bank at $a000-bfff.
92 // returns: The current bank.
93 char get_prg_a000(void);
94 
95 // Changes a portion of the tilesets. If interrupted, these may have no effect.
96 // All but the low three bits of reg must be zero.
97 __attribute__((leaf)) void set_chr_bank(char reg, char bank_id);
98 
99 // Same as set_chr_bank, but retries if interrupted.
100 __attribute__((leaf)) void set_chr_bank_retry(char bank, char bank_id);
101 
102 // Same as the above, but hard-code the bank.
103 void set_chr_mode_0(char chr_id);
104 void set_chr_mode_1(char chr_id);
105 void set_chr_mode_2(char chr_id);
106 void set_chr_mode_3(char chr_id);
107 void set_chr_mode_4(char chr_id);
108 void set_chr_mode_5(char chr_id);
109 
110 #define MIRROR_VERTICAL 0
111 #define MIRROR_HORIZONTAL 1
112 
113 // Set the current mirroring mode. Your options are
114 // MIRROR_HORIZONTAL, and MIRROR_VERTICAL.
115 __attribute__((leaf)) void set_mirroring(char mirroring);
116 
117 #define PRG_MODE_0 0
118 #define PRG_MODE_1 0x40
119 // Set the PRG ROM bank mode. Takes effect after the next PRG or CHR bank
120 // switch.
121 void set_prg_mode(char mode);
122 
123 #define CHR_A12_STRAIGHT 0
124 #define CHR_A12_INVERT 0x80
125 // Set whether CHR A12 is inverted. Takes effect after the next PRG or CHR bank
126 // switch.
127 void set_chr_a12_inversion(char mode);
128 
129 #define WRAM_OFF 0x40
130 #define WRAM_ON 0x80
131 #define WRAM_READ_ONLY 0xC0
132 
133 // Set the WRAM mode. Your options are
134 // WRAM_OFF, WRAM_ON, and WRAM_READ_ONLY.
135 // May not work in some emulators.
136 __attribute__((leaf)) void set_wram_mode(char mode);
137 
138 // Turns off MMC3 irqs, and changes the array pointer
139 // to point to a default 0xff
140 __attribute__((leaf)) void disable_irq(void);
141 
142 // This points an array to the IRQ system
143 // Also turns ON the system
144 __attribute__((leaf)) void set_irq_ptr(const void *address);
145 
146 // Check if it's safe to write to the irq array
147 // returns 0xff if done, zero if not done
148 // if the irq pointer is pointing to 0xff it is
149 // safe to edit.
150 __attribute__((leaf)) char is_irq_done(void);
151 
152 #ifdef __cplusplus
153 }
154 #endif
155 
156 #endif // _MAPPER_H_
ines.h
get_prg_8000
char get_prg_8000(void)
set_chr_mode_4
void set_chr_mode_4(char chr_id)
get_prg_a000
char get_prg_a000(void)
set_chr_mode_1
void set_chr_mode_1(char chr_id)
method
void(* method)(void))
Definition: mapper.h:41
bank_id
char bank_id
Definition: mapper.h:97
set_chr_a12_inversion
void set_chr_a12_inversion(char mode)
address
uint8_t uint16_t address
Definition: bios.h:180
set_prg_mode
void set_prg_mode(char mode)
set_chr_mode_2
void set_chr_mode_2(char chr_id)
mode
const void uint16_t uint8_t mode
Definition: memory.h:58
set_chr_mode_3
void set_chr_mode_3(char chr_id)
set_chr_mode_5
void set_chr_mode_5(char chr_id)
set_chr_mode_0
void set_chr_mode_0(char chr_id)
addr_hi
char addr_hi
Definition: mapper.h:73