aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2016-05-26 11:08:05 +0100
committerIan C <ianc@noddybox.co.uk>2016-05-26 11:08:05 +0100
commit6ae9e74d5b9e8cc69c33b7f707399b69632026d9 (patch)
tree4b9c2e0e393edd1e19fefa84c11c5a319de28d3a
parent663c4fc9de4d8167cb02e9fdd5e87547437399f6 (diff)
Added extra NES ROM options.
-rw-r--r--doc/casm.html16
-rw-r--r--src/example/nes.asm20
-rw-r--r--src/nesout.c45
3 files changed, 68 insertions, 13 deletions
diff --git a/doc/casm.html b/doc/casm.html
index 5581eba..014262e 100644
--- a/doc/casm.html
+++ b/doc/casm.html
@@ -1403,6 +1403,22 @@ option nes-tv-format, pal|ntsc
Defines the TV format stored in the ROM header, defaulting to <b>pal</b>.
</td></tr>
+<tr><td class="cmd">
+option nes-mirror, horizontal|vertical|vram
+</td>
+<td class="def">
+Defines whether nametables are mirrored horizontally, vertically or not at
+all respectively. Defaults to <b>horizontal</b>.
+</td></tr>
+
+<tr><td class="cmd">
+option nes-battery-ram, on|off
+</td>
+<td class="def">
+Defines whether there is battery backed RAM in the cartridge. Defaults to
+<b>off</b>.
+</td></tr>
+
</table>
diff --git a/src/example/nes.asm b/src/example/nes.asm
index 8228914..4598a41 100644
--- a/src/example/nes.asm
+++ b/src/example/nes.asm
@@ -6,6 +6,7 @@
option nes-vector,reset,start
option nes-vector,nmi,nmi
option nes-vector,brk,nmi
+ option nes-mirror,horizontal
vsync: macro
.wait
@@ -15,18 +16,27 @@ vsync: macro
start: org $c000
- sei
+ ; Clear decimal and setup stack
+ ;
cld
ldx #$ff
txs
- ; this sets up the PPU. Apparently.
+ ; Wait for the PPU. Recommended practice is clear the flag, and
+ ; wait for 2 VBL signals
+ ;
+ bit $2002
+ vsync
+ vsync
+
+ ; Setup PPU
+ ;
lda #%00001000
sta $2000
lda #%00011110
sta $2001
- ; Set PPU to palette
+ ; Setup the palette
;
loadpalette:
lda #$3f
@@ -34,8 +44,6 @@ loadpalette:
lda #$00
sta $2006
- ; Load the palette
- ;
ldx #0
.loop lda palette,x
sta $2007
@@ -52,7 +60,7 @@ loadpalette:
load_namemap:
lda #$20
sta $2006
- lda #$20
+ lda #$40
sta $2006
ldx #0
diff --git a/src/nesout.c b/src/nesout.c
index 44ab1af..8152239 100644
--- a/src/nesout.c
+++ b/src/nesout.c
@@ -45,7 +45,9 @@ enum option_t
{
OPT_VECTOR,
OPT_TV_FORMAT,
- OPT_MAPPER
+ OPT_MAPPER,
+ OPT_MIRROR,
+ OPT_BATTERY_RAM
};
static const ValueTable option_set[] =
@@ -53,6 +55,8 @@ static const ValueTable option_set[] =
{"nes-vector", OPT_VECTOR},
{"nes-tv-format", OPT_TV_FORMAT},
{"nes-mapper", OPT_MAPPER},
+ {"nes-mirror", OPT_MIRROR},
+ {"nes-battery-ram", OPT_BATTERY_RAM},
{NULL}
};
@@ -63,6 +67,19 @@ typedef enum
VECTOR_BRK
} VectorType;
+typedef enum
+{
+ MIRROR_HORIZONTAL = 0x00,
+ MIRROR_VERTICAL = 0x01,
+ MIRROR_VRAM = 0x08,
+} MirrorType;
+
+typedef enum
+{
+ PAL = 1,
+ NTSC = 0
+} TVFormat;
+
static ValueTable vector_table[] =
{
{"reset", VECTOR_RESET},
@@ -71,11 +88,13 @@ static ValueTable vector_table[] =
{NULL}
};
-typedef enum
+static ValueTable mirror_table[] =
{
- PAL = 1,
- NTSC = 0
-} TVFormat;
+ {"horizontal", MIRROR_HORIZONTAL},
+ {"vertical", MIRROR_VERTICAL},
+ {"vram", MIRROR_VRAM},
+ {NULL}
+};
static ValueTable format_table[] =
{
@@ -90,9 +109,11 @@ static struct
int vector[3];
TVFormat tv_format;
int mapper;
+ MirrorType mirror;
+ int battery_ram;
} option =
{
- {-1, -1, -1}, PAL, 0
+ {-1, -1, -1}, PAL, 0, MIRROR_HORIZONTAL, FALSE
};
@@ -173,6 +194,15 @@ CommandStatus NESOutputSetOption(int opt, int argc, char *argv[],
option.mapper = f;
break;
+ case OPT_MIRROR:
+ CMD_TABLE(argv[0], mirror_table, val);
+ option.mirror = val->value;
+ break;
+
+ case OPT_BATTERY_RAM:
+ option.battery_ram = ParseTrueFalse(argv[0], FALSE);
+ break;
+
default:
break;
}
@@ -302,7 +332,8 @@ int NESOutput(const char *filename, const char *filename_bank,
fputc(num_vrom, fp);
- fputc((option.mapper & 0x0f) << 4, fp);
+ fputc(((option.mapper & 0x0f) << 4) | option.mirror |
+ (option.battery_ram ? 0x02 : 0x00), fp);
fputc(option.mapper & 0xf0, fp);
fputc(0, fp);