-
Notifications
You must be signed in to change notification settings - Fork 0
/
nesdefs.dasm
156 lines (128 loc) · 4.09 KB
/
nesdefs.dasm
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
processor 6502
;;;;; CONSTANTS
PPU_CTRL = $2000
PPU_MASK = $2001
PPU_STATUS = $2002
OAM_ADDR = $2003
OAM_DATA = $2004
PPU_SCROLL = $2005
PPU_ADDR = $2006
PPU_DATA = $2007
PPU_OAM_DMA = $4014
JOYPAD1 = $4016
JOYPAD2 = $4017
BUTTON_A = 1 << 7
BUTTON_B = 1 << 6
BUTTON_SELECT = 1 << 5
BUTTON_START = 1 << 4
BUTTON_UP = 1 << 3
BUTTON_DOWN = 1 << 2
BUTTON_LEFT = 1 << 1
BUTTON_RIGHT = 1 << 0
; NOTE: I've put this outside of the PPU & APU, because it is a feature
; of the APU that is primarily of use to the PPU.
OAM_DMA = $4014
; OAM local RAM copy goes from $0200-$02FF:
OAM_RAM = $0200
; PPU_CTRL flags
CTRL_NMI EQM %10000000 ; Execute Non-Maskable Interrupt on VBlank
CTRL_8x8 EQM %00000000 ; Use 8x8 Sprites
CTRL_8x16 EQM %00100000 ; Use 8x16 Sprites
CTRL_BG_0000 EQM %00000000 ; Background Pattern Table at $0000 in VRAM
CTRL_BG_1000 EQM %00010000 ; Background Pattern Table at $1000 in VRAM
CTRL_SPR_0000 EQM %00000000 ; Sprite Pattern Table at $0000 in VRAM
CTRL_SPR_1000 EQM %00001000 ; Sprite Pattern Table at $1000 in VRAM
CTRL_INC_1 EQM %00000000 ; Increment PPU Address by 1 (Horizontal rendering)
CTRL_INC_32 EQM %00000100 ; Increment PPU Address by 32 (Vertical rendering)
CTRL_NT_2000 EQM %00000000 ; Name Table Address at $2000
CTRL_NT_2400 EQM %00000001 ; Name Table Address at $2400
CTRL_NT_2800 EQM %00000010 ; Name Table Address at $2800
CTRL_NT_2C00 EQM %00000011 ; Name Table Address at $2C00
; PPU_MASK flags
MASK_TINT_RED EQM %00100000 ; Red Background
MASK_TINT_BLUE EQM %01000000 ; Blue Background
MASK_TINT_GREEN EQM %10000000 ; Green Background
MASK_SPR EQM %00010000 ; Sprites Visible
MASK_BG EQM %00001000 ; Backgrounds Visible
MASK_SPR_CLIP EQM %00000100 ; Sprites clipped on left column
MASK_BG_CLIP EQM %00000010 ; Background clipped on left column
MASK_COLOR EQM %00000000 ; Display in Color
MASK_MONO EQM %00000001 ; Display in Monochrome
; read flags
F_BLANK EQM %10000000 ; VBlank Active
F_SPRITE0 EQM %01000000 ; VBlank hit Sprite 0
F_SCAN8 EQM %00100000 ; More than 8 sprites on current scanline
F_WIGNORE EQM %00010000 ; VRAM Writes currently ignored.
;;;;; CARTRIDGE FILE HEADER
NES_MIRR_HORIZ EQM 0
NES_MIRR_VERT EQM 1
NES_MIRR_QUAD EQM 8
MAC NES_HEADER
seg Header
org $Bff0
.NES_MAPPER SET {1} ;mapper number
.NES_PRG_BANKS SET {2} ;number of 16K PRG banks, change to 2 for NROM256
.NES_CHR_BANKS SET {3} ;number of 8K CHR banks (0 = RAM)
.NES_MIRRORING SET {4} ;0 horizontal, 1 vertical, 8 four screen
byte $4e,$45,$53,$1a ; header
byte .NES_PRG_BANKS
byte .NES_CHR_BANKS
byte .NES_MIRRORING|(.NES_MAPPER<<4)
byte .NES_MAPPER&$f0
byte 0,0,0,0,0,0,0,0 ; reserved, set to zero
seg Code
org $C000
ENDM
;;;;; NES_INIT SETUP MACRO (place at start)
MAC NES_INIT
sei ;disable IRQs
cld ;decimal mode not supported
ldx #$ff
txs ;set up stack pointer
inx ;increment X to 0
stx PPU_MASK ;disable rendering
stx DMC_FREQ ;disable DMC interrupts
stx PPU_CTRL ;disable NMI interrupts
bit PPU_STATUS ;clear VBL flag
bit APU_CHAN_CTRL ;ack DMC IRQ bit 7
lda #$40
sta APU_FRAME ;disable APU Frame IRQ
lda #$0F
sta APU_CHAN_CTRL ;disable DMC, enable/init other channels.
ENDM
;;;;; NES_VECTORS - CPU vectors at end of address space
MAC NES_VECTORS
seg Vectors ; segment "Vectors"
org $fffa ; start at address $fffa
.word NMIHandler ; $fffa vblank nmi
.word Start ; $fffc reset
.word NMIHandler ; $fffe irq / brk
ENDM
;;;;; PPU_SETADDR <address> - set 16-bit PPU address
MAC PPU_SETADDR
lda #>{1} ; upper byte
sta PPU_ADDR
lda #<{1} ; lower byte
sta PPU_ADDR
ENDM
;;;;; PPU_SETVALUE <value> - feed 8-bit value to PPU
MAC PPU_SETVALUE
lda #{1}
sta PPU_DATA
ENDM
;;;;; SAVE_REGS - save A/X/Y registers
MAC SAVE_REGS
pha
txa
pha
tya
pha
ENDM
;;;;; RESTORE_REGS - restore Y/X/A registers
MAC RESTORE_REGS
pla
tay
pla
tax
pla
ENDM