Compare commits

..

No commits in common. "ae0f787453bf99653f8000a7a5d4f9a7aad49d3e" and "1f52d53afb881e578a09c139cfa7fc3bfd143cfb" have entirely different histories.

21 changed files with 10 additions and 1800 deletions

View File

@ -1,25 +0,0 @@
MEMORY {
ZP: start = $0000, size = $0100, type = rw, define = yes;
OAM: start = $0200, size = $0100, type = rw, define = yes;
RAM: start = $0300, size = $0500, type = rw, define = yes;
HEADER: start = $0000, size = $0010, type = ro, file = %O, fill = yes, fillval = $00;
PRG: start = $8000, size = $8000, type = ro, file = %O, fill = yes, fillval = $00, define = yes;
CHR: start = $0000, size = $2000, type = ro, file = %O, fill = yes, fillval = $00;
}
SEGMENTS {
HEADER: load = HEADER, type = ro;
STARTUP: load = PRG, type = ro, define = yes;
LOWCODE: load = PRG, type = ro, optional = yes;
INIT: load = PRG, type = ro, define = yes, optional = yes;
CODE: load = PRG, type = ro, define = yes;
RODATA: load = PRG, type = ro, define = yes;
DATA: load = PRG, run = RAM, type = rw, define = yes;
ONCE: load = PRG, type = ro, define = yes, optional = yes;
VECTORS: load = PRG, type = ro, start = $FFFA;
OAM: load = OAM, type = rw;
BSS: load = RAM, type = bss, define = yes;
HEAP: load = RAM, type = bss, optional = yes;
ZEROPAGE: load = ZP, type = zp;
CHARS: load = CHR, type = ro;
}

Binary file not shown.

View File

@ -1,32 +0,0 @@
MEMORY {
ZP: start = $0000, size = $0100, type = rw, define = yes;
OAM: start = $0200, size = $0100, type = rw, define = yes;
RAM: start = $0300, size = $0500, type = rw, define = yes;
HEADER: start = $0000, size = $0010, type = ro, file = %O, fill = yes, fillval = $00;
BNK0: start = $8000, size = $2000, type = ro, file = %O, fill = yes, fillval = $00, define = yes;
BNK1: start = $A000, size = $2000, type = ro, file = %O, fill = yes, fillval = $00, define = yes;
BNK2: start = $C000, size = $2000, type = ro, file = %O, fill = yes, fillval = $00, define = yes;
BNK3: start = $E000, size = $2000, type = ro, file = %O, fill = yes, fillval = $00, define = yes;
CHR: start = $0000, size = $2000, type = ro, file = %O, fill = yes, fillval = $00;
}
SEGMENTS {
HEADER: load = HEADER, type = ro;
STARTUP: load = BNK0, type = ro, define = yes;
LOWCODE: load = BNK0, type = ro, optional = yes;
INIT: load = BNK0, type = ro, define = yes, optional = yes;
CODE: load = BNK0, type = ro, define = yes;
RODATA: load = BNK0, type = ro, define = yes;
DATA: load = BNK0, run = RAM, type = rw, define = yes;
BNK0: load = BNK0, type = ro, start = $8000, optional = yes;
BNK1: load = BNK1, type = ro, start = $A000, optional = yes;
BNK2: load = BNK2, type = ro, start = $C000, optional = yes;
BNK3: load = BNK3, type = ro, start = $E000, optional = yes;
LAST_BNK: load = BNK3, type = ro, start = $E000;
VECTORS: load = BNK3, type = ro, start = $FFFA;
OAM: load = OAM, type = rw;
BSS: load = RAM, type = bss, define = yes;
HEAP: load = RAM, type = bss, optional = yes;
ZEROPAGE: load = ZP, type = zp;
CHARS: load = CHR, type = ro;
}

146
Makefile
View File

@ -1,146 +0,0 @@
# - - - - - - - - - - - - - #
# Variables to change #
# - - - - - - - - - - - - - #
# CC65 executable locations
CC65 = ../../cc65/bin/cc65.exe
# CA65 executable locations
CA65 = ../../cc65/bin/ca65.exe
# LD65 executable locations
LD65 = ../../cc65/bin/ld65.exe
# NES lib locations
NESLIB = ../../cc65/lib/nes.lib
# asminc folder locations
ASMINC = ../../cc65/asminc
# Emulator executable location
EMULATOR = ../../Mesen/Mesen.exe
# Hexdump executable location
HEXDUMP = ..\..\hexdump.exe
# Game name
GAME_NAME = Boilerplate
# Folder with h files to include
INC = include
# Folder with c sources files
SRC = src
# Bin folder for binary output
BIN = bin
# Folder with assembler sources files
ASM = asm
# Change this to 0 if you don't want FamiStudio
FAMISTUDIO = 1
# Change this to 1 if you want the MMC5 mapper
MMC5 = 0
# ! - - - - - - - - - - - - - - - - ! #
# DO NOT CHANGE ANYTHING AFTER THIS #
# ! - - - - - - - - - - - - - - - - ! #
# get all c files
SRCFILE = $(call rwildcard,$(SRC),*.c)
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
# make the nes game from assembler files and from c files
all:
make asm
make c
# make the nes game from c files
c: $(GAME_NAME)_c.nes
make clean
# make the nes game from assembler files
asm: $(GAME_NAME)_a.nes
make clean
# create the nes file from assembler sources
$(GAME_NAME)_a.nes:
# create folder if it does not exist
@-if not exist "$(BIN)" ( mkdir "$(BIN)" )
# assemble main file
.\$(CA65) asm/crt0.asm -o $(BIN)/$(GAME_NAME).o --debug-info -DFAMISTUDIO=$(FAMISTUDIO) -DMMC5=$(MMC5)
# link files
ifeq ($(MMC5),1)
.\$(LD65) $(BIN)/$(GAME_NAME).o -C $(GAME_NAME)_mmc5.cfg -o $(GAME_NAME)_a.nes --dbgfile $(GAME_NAME)_a.DBG
else
.\$(LD65) $(BIN)/$(GAME_NAME).o -C $(GAME_NAME).cfg -o $(GAME_NAME)_a.nes --dbgfile $(GAME_NAME)_a.DBG
endif
# create the nes file from c sources
$(GAME_NAME)_c.nes: $(addprefix $(BIN)/,$(SRCFILE:.c=.o))
# assemble main file
$(CA65) $(ASM)/crt0.asm -g -o $(BIN)/$(GAME_NAME).o -I$(ASMINC) -DC_CODE -DFAMISTUDIO=$(FAMISTUDIO) -DMMC5=$(MMC5)
# link files
ifeq ($(MMC5),1)
$(LD65) $(BIN)/$(GAME_NAME).o $^ -C $(GAME_NAME)_mmc5.cfg -o $@ $(NESLIB) --dbgfile $(GAME_NAME)_c.DBG
else
$(LD65) $(BIN)/$(GAME_NAME).o $^ -C $(GAME_NAME).cfg -o $@ $(NESLIB) --dbgfile $(GAME_NAME)_c.DBG
endif
# assemble object files
$(BIN)/%.o: $(BIN)/%.asm
# create folder if it does not exist
@-if not exist "$(@D)" ( mkdir "$(@D)" )
# assemble a file
$(CA65) -g -I$(INC) -I$(ASMINC) -o $@ $^ -DC_CODE -DFAMISTUDIO=$(FAMISTUDIO) -DMMC5=$(MMC5)
# compile c files
$(BIN)/%.asm: %.c
# create folder if it does not exist
@-if not exist "$(@D)" ( mkdir "$(@D)" )
# compile a file
$(CC65) -O -g -I$(INC) -I$(ASM) -o $@ $^ $(NESLIB) --add-source -DFAMISTUDIO=$(FAMISTUDIO) -DMMC5=$(MMC5)
# clean object files
clean:
@-if exist "$(BIN)" ( rmdir /Q /S "$(BIN)" )
# clean all generated files
clean_all:
make clean
del $(GAME_NAME)_a.nes
del $(GAME_NAME)_a.DBG
del $(GAME_NAME)_c.nes
del $(GAME_NAME)_c.DBG
del dump_$(GAME_NAME)_a.txt
del dump_$(GAME_NAME)_c.txt
# run the nes game generated with c sources
run_c:
$(EMULATOR) $(GAME_NAME)_c.nes
# run the nes game generated with assembler sources
run_a:
$(EMULATOR) $(GAME_NAME)_a.nes
# dump the nes files binary into hexa text
hex:
$(HEXDUMP) $(GAME_NAME)_a.nes > dump_$(GAME_NAME)_a.txt
$(HEXDUMP) $(GAME_NAME)_c.nes > dump_$(GAME_NAME)_c.txt

View File

@ -4,14 +4,14 @@ A NES game that serves as a base for starting a new NES project.
----------------- -----------------
- [**Features**](#features) - [**Features**](##-**Features**)
- [**Prerequisite**](#prerequisite) - [**Prerequisite**](##-**Prerequisite**)
- [**Project configuration**](#project-configuration) - [**Project configuration**](##-**Project-configuration**)
- [**Source configuration**](#source-configuration) - [**Source configuration**](###-**Source-configuration**)
- [**Makefile configuration**](#makefile-configuration) - [**Makefile configuration**](###-**Makefile-configuration**)
- [**FamiStudio configuration**](#famistudio-configuration) - [**FamiStudio configuration**](###-**FamiStudio-configuration**)
- [**Building the game**](#building-the-game) - [**Building the game**](##--**Building-the-game**)
- [**Running the game**](#running-the-game) - [**Running the game**](##--**Running-the-game**)
----------------- -----------------
@ -26,9 +26,8 @@ This project has/can:
- An IRQ handler (that does nothing, but we need one). - An IRQ handler (that does nothing, but we need one).
- Support for the FamiStudio Sound Engine (<https://famistudio.org>) - Support for the FamiStudio Sound Engine (<https://famistudio.org>)
- Some defined constant (PPU, APU, etc.). - Some defined constant (PPU, APU, etc.).
- Compile the game with the MMC5 mapper. (<https://www.nesdev.org/wiki/MMC5>)
Note: *This project has by default 32K of PRG and 8K of CHR.* Note: *This project has no mapper. i.e. it is a NROM game with 32K of PRG and 8K of CHR by default.*
----------------- -----------------
@ -87,8 +86,7 @@ To configure the sources files, you must:
``` ```
3. Rename the .cfg file to `your_game_name.cfg`. 3. Rename the .cfg file to `your_game_name.cfg`.
4. *(Optional)* If you want to use the MMC5 mapper, rename the mmc5 .cfg file to `your_game_name_mmc5.cfg`. It must end with `_mmc5.cfg`. 4. *(Optional)* get the FamiStudio Sound Engine
5. *(Optional)* get the FamiStudio Sound Engine
1. Place the `famistudio_ca65.s` file in `asm/audio/` 1. Place the `famistudio_ca65.s` file in `asm/audio/`
*Note: if you are coding in C, you should include `famistudio_cc65.h` somewhere in your include folder* *Note: if you are coding in C, you should include `famistudio_cc65.h` somewhere in your include folder*
2. in the `crt0.asm` in the FamiStudio section, include your music files. Example: 2. in the `crt0.asm` in the FamiStudio section, include your music files. Example:
@ -200,20 +198,11 @@ You will need to indicate to the Makefile where cc65 and other software programs
FAMISTUDIO = 1 FAMISTUDIO = 1
``` ```
- **MMC5**: *(Required)*
If you want to use the MMC5 mapper for your game, set this to 1, otherwise set it to 0. Example:
```make
MMC5 = 0
```
### **FamiStudio configuration** ### **FamiStudio configuration**
You can configure the engine by editing `asm/audio/famistudio_config.asm`. You can configure the engine by editing `asm/audio/famistudio_config.asm`.
If you need help, you can check the FamiStudio documentation: <https://famistudio.org/doc/soundengine> If you need help, you can check the FamiStudio documentation: <https://famistudio.org/doc/soundengine>
Note: *The 'FAMISTUDIO_EXP_MMC5' option is configured correctly by default. You do not need to change it*
## **Building the game** ## **Building the game**
Note: make sure that you have correctly set up the Makefile and source files. Note: make sure that you have correctly set up the Makefile and source files.

View File

@ -1,109 +0,0 @@
;----------------------------------------
; FamiStudio Sound Engine configuration
;----------------------------------------
;----------------------------------------
; You don't need to edit this
;----------------------------------------
FAMISTUDIO_CFG_EXTERNAL=1
.ifdef C_CODE
FAMISTUDIO_CFG_C_BINDINGS = 1
.endif
;----------------------------------------
; Segments Configuration (You don't need to edit this too)
;----------------------------------------
.define FAMISTUDIO_CA65_ZP_SEGMENT ZEROPAGE
.define FAMISTUDIO_CA65_RAM_SEGMENT BSS
.define FAMISTUDIO_CA65_CODE_SEGMENT CODE
;----------------------------------------
; Audio Expansions (ONLY 0 OR 1 MUST BE ENABLE)
;----------------------------------------
; Konami VRC6 (2 extra square + saw)
FAMISTUDIO_EXP_VRC6 = 0
; Konami VRC7 (6 FM channels)
FAMISTUDIO_EXP_VRC7 = 0
; Nintendo MMC5 (2 extra squares, extra DPCM not supported)
FAMISTUDIO_EXP_MMC5 = MMC5
; Sunsoft S5B (2 extra squares, advanced features not supported.)
FAMISTUDIO_EXP_S5B = 0
; Famicom Disk System (extra wavetable channel)
FAMISTUDIO_EXP_FDS = 0
; Namco 163 (between 1 and 8 extra wavetable channels) + number of channels.
FAMISTUDIO_EXP_N163 = 0
FAMISTUDIO_EXP_N163_CHN_CNT = 4
;----------------------------------------
; Global Engine Configuration
;----------------------------------------
; One of these MUST be defined (PAL or NTSC playback).
; Note that only NTSC support is supported when using any of the audio expansions.
FAMISTUDIO_CFG_PAL_SUPPORT = 0
FAMISTUDIO_CFG_NTSC_SUPPORT = 1
; Support for sound effects playback + number of SFX that can play at once.
FAMISTUDIO_CFG_SFX_SUPPORT = 1
FAMISTUDIO_CFG_SFX_STREAMS = 2
; Blaarg's smooth vibrato technique. Eliminates phase resets ("pops") on
; square channels.
FAMISTUDIO_CFG_SMOOTH_VIBRATO = 0
; Enables DPCM playback support.
FAMISTUDIO_CFG_DPCM_SUPPORT = 1
; Must be enabled if you are calling sound effects from a different
; thread than the sound engine update.
FAMISTUDIO_CFG_THREAD = 1
;----------------------------------------
; Supported Features Configuration
;----------------------------------------
; Must be enabled if the songs you will be importing have been created using FamiTracker tempo mode.
; If you are using FamiStudio tempo mode, this must be undefined. You cannot mix and match tempo modes,
; the engine can only run in one mode or the other.
; More information at: https://famistudio.org/doc/song/#tempo-modes
; FAMISTUDIO_USE_FAMITRACKER_TEMPO = 1
; Must be enabled if the songs uses delayed notes or delayed cuts. This is obviously only available when using
; FamiTracker tempo mode as FamiStudio tempo mode does not need this.
; FAMISTUDIO_USE_FAMITRACKER_DELAYED_NOTES_OR_CUTS = 1
; Must be enabled if any song uses the volume track. The volume track allows manipulating the volume at the track
; level independently from instruments.
; More information at: https://famistudio.org/doc/pianoroll/#editing-volume-tracks-effects
FAMISTUDIO_USE_VOLUME_TRACK = 0
; Must be enabled if any song uses slides on the volume track. Volume track must be enabled too.
; More information at: https://famistudio.org/doc/pianoroll/#editing-volume-tracks-effects
FAMISTUDIO_USE_VOLUME_SLIDES = 0
; Must be enabled if any song uses the pitch track. The pitch track allows manipulating the pitch at the track
; level independently from instruments.
; More information at: https://famistudio.org/doc/pianoroll/#pitch
FAMISTUDIO_USE_PITCH_TRACK = 0
; Must be enabled if any song uses slide notes. Slide notes allows portamento and slide effects.
; More information at: https://famistudio.org/doc/pianoroll/#slide-notes
FAMISTUDIO_USE_SLIDE_NOTES = 0
; Must be enabled if any song uses slide notes on the noise channel too.
; More information at: https://famistudio.org/doc/pianoroll/#slide-notes
FAMISTUDIO_USE_NOISE_SLIDE_NOTES = 0
; Must be enabled if any song uses the vibrato speed/depth effect track.
; More information at: https://famistudio.org/doc/pianoroll/#vibrato-depth-speed
FAMISTUDIO_USE_VIBRATO = 0
; Must be enabled if any song uses arpeggios (not to be confused with instrument arpeggio envelopes, those
; are always supported).
; More information at: (TODO)
FAMISTUDIO_USE_ARPEGGIO = 0
; Must be enabled if any song uses the "Duty Cycle" effect (equivalent of FamiTracker Vxx, also called "Timbre").
FAMISTUDIO_USE_DUTYCYCLE_EFFECT = 0
;----------------------------------------

View File

@ -1,173 +0,0 @@
; This file for the FamiStudio Sound Engine and was generated by FamiStudio
.if FAMISTUDIO_CFG_C_BINDINGS
.export _music_data_arpeggio=music_data_arpeggio
.endif
music_data_arpeggio:
.byte 1
.word @instruments
.word @samples-4
.word @song0ch0,@song0ch1,@song0ch2,@song0ch3,@song0ch4
.byte .lobyte(@tempo_env_7_mid), .hibyte(@tempo_env_7_mid), 0, 0
.export music_data_arpeggio
.global FAMISTUDIO_DPCM_PTR
@instruments:
.word @env1,@env0,@env3,@env2
.word @env5,@env0,@env4,@env2
@samples:
@env0:
.byte $c0,$7f,$00,$00
@env1:
.byte $00,$cc,$c7,$c4,$c2,$c1,$c0,$00,$06
@env2:
.byte $00,$c0,$7f,$00,$01
@env3:
.byte $7f,$00,$00
@env4:
.byte $c2,$7f,$00,$00
@env5:
.byte $07,$c7,$c6,$c6,$c5,$00,$04,$c3,$c2,$c1,$c1,$00,$0a
@tempo_env_7_mid:
.byte $03,$05,$05,$06,$03,$06,$05,$05,$80
@song0ch0:
.byte $f7, $e7, $6b, $f7, $e7, $6b, $f7, $e7, $6b, $f7, $e7
@song0ch0loop:
.byte $6a, .lobyte(@tempo_env_7_mid), .hibyte(@tempo_env_7_mid), $f7, $e7, $6b, $f7, $e7, $6b, $f7, $e7, $6b, $f7, $e7, $6b
.byte $f7, $e7, $6b, $f7, $e7, $6b, $82
@song0ref35:
.byte $3d, $83, $00, $85, $41, $83, $00, $85, $42, $83, $00, $85, $44, $83, $00, $85, $3d, $83, $00, $85, $41, $83, $00, $85
.byte $42, $83, $00, $85, $44, $83, $00, $85
.byte $ff, $20
.word @song0ref35
@song0ref70:
.byte $6b
@song0ref71:
.byte $3a, $83, $00, $85, $3e, $83, $00, $85, $3f, $83, $00, $85, $41, $83, $00, $85, $3a, $83, $00, $85, $3e, $83, $00, $85
.byte $3f, $83, $00, $85, $41, $83, $00, $85
.byte $ff, $20
.word @song0ref71
.byte $6b
.byte $ff, $20
.word @song0ref35
.byte $ff, $20
.word @song0ref35
.byte $ff, $20
.word @song0ref70
.byte $ff, $20
.word @song0ref71
.byte $fd
.word @song0ch0loop
@song0ch1:
@song0ref122:
.byte $82
@song0ref123:
.byte $31, $83, $00, $85, $35, $83, $00, $85, $36, $83, $00, $85, $38, $83, $00, $85, $31, $83, $00, $85, $35, $83, $00, $85
.byte $36, $83, $00, $85, $38, $83, $00, $85
.byte $ff, $20
.word @song0ref123
@song0ref158:
.byte $2e, $83, $00, $85, $32, $83, $00, $85, $33, $83, $00, $85, $35, $83, $00, $85, $2e, $83, $00, $85, $32, $83, $00, $85
.byte $33, $83, $00, $85, $35, $83, $00, $85
.byte $ff, $20
.word @song0ref158
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref158
.byte $ff, $20
.word @song0ref158
@song0ch1loop:
.byte $ff, $20
.word @song0ref122
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref158
.byte $ff, $20
.word @song0ref158
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref158
.byte $ff, $20
.word @song0ref158
.byte $f7, $e7, $f7, $e7
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref158
.byte $ff, $20
.word @song0ref158
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref123
.byte $ff, $20
.word @song0ref158
.byte $ff, $20
.word @song0ref158
.byte $fd
.word @song0ch1loop
@song0ch2:
.byte $f7, $e7, $f7, $e7
@song0ref265:
.byte $80
@song0ref266:
.byte $25, $8b, $29, $8b, $2a, $8b, $2c, $8b, $25, $8b, $29, $8b, $2a, $8b, $2c, $8b, $25, $8b, $29, $8b, $2a, $8b, $2c, $8b
.byte $25, $8b, $29, $8b, $2a, $8b, $2c, $8b, $22, $8b, $26, $8b, $27, $8b, $29, $8b, $22, $8b, $26, $8b, $27, $8b, $29, $8b
.byte $22, $8b, $26, $8b, $27, $8b, $29, $8b, $22, $8b, $26, $8b, $27, $8b, $29, $8b
@song0ch2loop:
.byte $ff, $40
.word @song0ref265
.byte $ff, $40
.word @song0ref266
.byte $ff, $40
.word @song0ref266
.byte $ff, $40
.word @song0ref266
.byte $ff, $40
.word @song0ref266
.byte $fd
.word @song0ch2loop
@song0ch3:
.byte $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7
@song0ch3loop:
.byte $80
@song0ref359:
.byte $1e, $8b, $00, $8b, $1e, $8b, $00, $8b, $1e, $8b, $1e, $8b, $1e, $8b, $00, $8b, $1e, $8b, $00, $8b, $1e, $8b, $00, $8b
.byte $1e, $8b, $00, $a7
.byte $ff, $1c
.word @song0ref359
.byte $ff, $1c
.word @song0ref359
.byte $ff, $1c
.word @song0ref359
.byte $ff, $1c
.word @song0ref359
.byte $ff, $1c
.word @song0ref359
.byte $ff, $1c
.word @song0ref359
.byte $ff, $1c
.word @song0ref359
.byte $ff, $1c
.word @song0ref359
.byte $ff, $1c
.word @song0ref359
.byte $fd
.word @song0ch3loop
@song0ch4:
.byte $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7
@song0ch4loop:
.byte $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $fd
.word @song0ch4loop

View File

@ -1,291 +0,0 @@
; This file for the FamiStudio Sound Engine and was generated by FamiStudio
.if FAMISTUDIO_CFG_C_BINDINGS
.export _music_data_arpeggio_mmc5=music_data_arpeggio_mmc5
.endif
music_data_arpeggio_mmc5:
.byte 1
.word @instruments
.word @samples-4
.word @song0ch0,@song0ch1,@song0ch2,@song0ch3,@song0ch4,@song0ch5,@song0ch6
.byte .lobyte(@tempo_env_7_mid), .hibyte(@tempo_env_7_mid), 0, 0
.export music_data_arpeggio_mmc5
.global FAMISTUDIO_DPCM_PTR
@instruments:
.word @env1,@env0,@env3,@env2
.word @env5,@env0,@env4,@env2
@samples:
@env0:
.byte $c0,$7f,$00,$00
@env1:
.byte $00,$cc,$c7,$c4,$c2,$c1,$c0,$00,$06
@env2:
.byte $00,$c0,$7f,$00,$01
@env3:
.byte $7f,$00,$00
@env4:
.byte $c2,$7f,$00,$00
@env5:
.byte $07,$c7,$c6,$c6,$c5,$00,$04,$c3,$c2,$c1,$c1,$00,$0a
@tempo_env_7_mid:
.byte $03,$05,$05,$06,$03,$06,$05,$05,$80
@song0ch0:
.byte $f7, $e7, $6b, $f7, $e7, $6b, $f7, $e7, $6b, $f7, $e7
@song0ch0loop:
.byte $6a, .lobyte(@tempo_env_7_mid), .hibyte(@tempo_env_7_mid), $f7, $e7, $6b, $f7, $e7, $6b, $f7, $e7, $6b, $f7, $e7, $6b
.byte $f7, $e7, $6b, $f7, $e7, $6b, $f7, $e7, $6b, $f7, $e7
@song0ref39:
.byte $6b
@song0ref40:
.byte $82
@song0ref41:
.byte $3d, $83, $00, $85, $41, $83, $00, $85, $42, $83, $00, $85, $44, $83, $00, $85, $3d, $83, $00, $85, $41, $83, $00, $85
.byte $42, $83, $00, $85, $44, $83, $00, $85
.byte $ff, $20
.word @song0ref41
@song0ref76:
.byte $6b
@song0ref77:
.byte $3a, $83, $00, $85, $3e, $83, $00, $85, $3f, $83, $00, $85, $41, $83, $00, $85, $3a, $83, $00, $85, $3e, $83, $00, $85
.byte $3f, $83, $00, $85, $41, $83, $00, $85
.byte $ff, $20
.word @song0ref77
.byte $6b, $80
.byte $ff, $20
.word @song0ref41
.byte $ff, $20
.word @song0ref41
.byte $ff, $20
.word @song0ref76
.byte $ff, $20
.word @song0ref77
.byte $ff, $20
.word @song0ref39
.byte $ff, $20
.word @song0ref41
.byte $ff, $20
.word @song0ref76
.byte $ff, $20
.word @song0ref77
.byte $6b, $80, $44, $8b, $00, $a7, $44, $8b, $00, $a7, $44, $8b, $00, $a7, $44, $8b, $00, $8b, $44, $8b, $00, $8b, $6b, $41
.byte $8b, $00, $a7, $41, $8b, $00, $a7, $41, $8b, $00, $a7, $41, $8b, $00, $8b, $41, $8b, $00, $8b, $6b, $42, $8b, $00, $a7
.byte $42, $8b, $00, $a7, $42, $8b, $00, $a7, $42, $8b, $00, $8b, $42, $8b, $00, $8b, $6b, $3f, $8b, $00, $a7, $3f, $8b, $00
.byte $a7, $3f, $8b, $00, $a7, $3f, $8b, $00, $8b, $3f, $8b, $00, $8b, $fd
.word @song0ch0loop
@song0ch1:
@song0ref226:
.byte $82
@song0ref227:
.byte $31, $83, $00, $85, $35, $83, $00, $85, $36, $83, $00, $85, $38, $83, $00, $85, $31, $83, $00, $85, $35, $83, $00, $85
.byte $36, $83, $00, $85, $38, $83, $00, $85
.byte $ff, $20
.word @song0ref227
@song0ref262:
.byte $2e, $83, $00, $85, $32, $83, $00, $85, $33, $83, $00, $85, $35, $83, $00, $85, $2e, $83, $00, $85, $32, $83, $00, $85
.byte $33, $83, $00, $85, $35, $83, $00, $85
.byte $ff, $20
.word @song0ref262
.byte $ff, $20
.word @song0ref227
.byte $ff, $20
.word @song0ref227
.byte $ff, $20
.word @song0ref262
.byte $ff, $20
.word @song0ref262
@song0ch1loop:
.byte $ff, $20
.word @song0ref226
.byte $ff, $20
.word @song0ref227
.byte $ff, $20
.word @song0ref262
.byte $ff, $20
.word @song0ref262
.byte $ff, $20
.word @song0ref227
.byte $ff, $20
.word @song0ref227
.byte $ff, $20
.word @song0ref262
.byte $ff, $20
.word @song0ref262
.byte $80, $38, $8b, $00, $a7, $38, $8b, $00, $a7, $38, $8b, $00, $a7, $38, $8b, $00, $8b, $38, $8b, $00, $8b, $35, $8b, $00
.byte $a7, $35, $8b, $00, $a7, $35, $8b, $00, $a7, $35, $8b, $00, $8b, $35, $8b, $00, $8b, $36, $8b, $00, $a7, $36, $8b, $00
.byte $a7, $36, $8b, $00, $a7, $36, $8b, $00, $8b, $36, $8b, $00, $8b, $33, $8b, $00, $a7, $33, $8b, $00, $a7, $33, $8b, $00
.byte $a7, $33, $8b, $00, $8b, $33, $8b, $00, $8b
.byte $ff, $20
.word @song0ref226
.byte $ff, $20
.word @song0ref227
.byte $ff, $20
.word @song0ref262
.byte $ff, $20
.word @song0ref262
.byte $ff, $20
.word @song0ref227
.byte $ff, $20
.word @song0ref227
.byte $ff, $20
.word @song0ref262
.byte $ff, $20
.word @song0ref262
.byte $80
.byte $ff, $20
.word @song0ref227
.byte $ff, $20
.word @song0ref227
.byte $ff, $20
.word @song0ref262
.byte $ff, $20
.word @song0ref262
.byte $ff, $20
.word @song0ref226
.byte $ff, $20
.word @song0ref227
.byte $ff, $20
.word @song0ref262
.byte $ff, $20
.word @song0ref262
.byte $ff, $20
.word @song0ref227
.byte $ff, $20
.word @song0ref227
.byte $ff, $20
.word @song0ref262
.byte $ff, $20
.word @song0ref262
.byte $fd
.word @song0ch1loop
@song0ch2:
.byte $f7, $e7, $f7, $e7
@song0ref483:
.byte $80
@song0ref484:
.byte $25, $8b, $29, $8b, $2a, $8b, $2c, $8b, $25, $8b, $29, $8b, $2a, $8b, $2c, $8b, $25, $8b, $29, $8b, $2a, $8b, $2c, $8b
.byte $25, $8b, $29, $8b, $2a, $8b, $2c, $8b, $22, $8b, $26, $8b, $27, $8b, $29, $8b, $22, $8b, $26, $8b, $27, $8b, $29, $8b
.byte $22, $8b, $26, $8b, $27, $8b, $29, $8b, $22, $8b, $26, $8b, $27, $8b, $29, $8b
@song0ch2loop:
.byte $ff, $40
.word @song0ref483
.byte $ff, $40
.word @song0ref484
.byte $ff, $40
.word @song0ref484
.byte $ff, $40
.word @song0ref484
.byte $ff, $40
.word @song0ref484
.byte $ff, $40
.word @song0ref484
.byte $ff, $40
.word @song0ref484
.byte $ff, $40
.word @song0ref484
.byte $ff, $40
.word @song0ref484
.byte $fd
.word @song0ch2loop
@song0ch3:
.byte $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7
@song0ch3loop:
.byte $80
@song0ref589:
.byte $1e, $8b, $00, $8b, $1e, $8b, $00, $8b, $1e, $8b, $00, $8b, $1e, $8b, $00, $8b, $1e, $8b, $1e, $8b, $1e, $8b, $00, $8b
.byte $1e, $8b, $00, $a7
.byte $ff, $1c
.word @song0ref589
.byte $ff, $1c
.word @song0ref589
.byte $ff, $1c
.word @song0ref589
.byte $ff, $1c
.word @song0ref589
.byte $ff, $1c
.word @song0ref589
.byte $ff, $1c
.word @song0ref589
.byte $ff, $1c
.word @song0ref589
.byte $ff, $1c
.word @song0ref589
.byte $ff, $1c
.word @song0ref589
.byte $ff, $1c
.word @song0ref589
.byte $ff, $1c
.word @song0ref589
.byte $ff, $1c
.word @song0ref589
.byte $ff, $1c
.word @song0ref589
.byte $ff, $1c
.word @song0ref589
.byte $ff, $1c
.word @song0ref589
.byte $ff, $1c
.word @song0ref589
.byte $ff, $1c
.word @song0ref589
.byte $fd
.word @song0ch3loop
@song0ch4:
.byte $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7
@song0ch4loop:
@song0ref680:
.byte $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7
.byte $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7, $fd
.word @song0ch4loop
@song0ch5:
.byte $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7
@song0ch5loop:
.byte $ff, $1c
.word @song0ref680
.byte $85, $82
@song0ref733:
.byte $25, $83, $00, $85, $29, $83, $00, $85, $2a, $83, $00, $85, $2c, $83, $00, $85, $25, $83, $00, $85, $29, $83, $00, $85
.byte $2a, $83, $00, $85, $2c, $83, $00, $85
.byte $ff, $20
.word @song0ref733
@song0ref768:
.byte $22, $83, $00, $85, $26, $83, $00, $85, $27, $83, $00, $85, $29, $83, $00, $85, $22, $83, $00, $85, $26, $83, $00, $85
.byte $27, $83, $00, $85, $29, $83, $00, $85
.byte $ff, $20
.word @song0ref768
.byte $ff, $20
.word @song0ref733
.byte $ff, $20
.word @song0ref733
.byte $ff, $20
.word @song0ref768
.byte $ff, $1f
.word @song0ref768
.byte $fd
.word @song0ch5loop
@song0ch6:
.byte $f7, $e7, $f7, $e7, $f7, $e7, $f7, $e7
@song0ch6loop:
.byte $ff, $1c
.word @song0ref680
.byte $ff, $20
.word @song0ref40
.byte $ff, $20
.word @song0ref41
.byte $ff, $20
.word @song0ref77
.byte $ff, $20
.word @song0ref77
.byte $ff, $20
.word @song0ref41
.byte $ff, $20
.word @song0ref41
.byte $ff, $20
.word @song0ref77
.byte $ff, $20
.word @song0ref77
.byte $fd
.word @song0ch6loop

View File

@ -1,113 +0,0 @@
;**********
; Constants
;**********
; Replace the value with the name of your CHR file
.define GAME_CHR "Boilerplate.chr"
;----------
; PPU
;----------
PPU_CTRL := $2000
PPU_MASK := $2001
PPU_STATUS := $2002
PPU_SCROLL := $2005
PPU_ADDR := $2006
PPU_DATA := $2007
; PPU MASK
PPU_MASK_GREY = %00000001
PPU_MASK_BKG8 = %00000010
PPU_MASK_SPR8 = %00000100
PPU_MASK_BKG = %00001000
PPU_MASK_SPR = %00010000
PPU_MASK_R = %00100000
PPU_MASK_G = %01000000
PPU_MASK_B = %10000000
; PPU CTRL
PPU_CTRL_NM_1 = %00000001
PPU_CTRL_NM_2 = %00000010
PPU_CTRL_INC = %00000100
PPU_CTRL_SPR = %00001000
PPU_CTRL_BKG = %00010000
PPU_CTRL_SPR_SIZE = %00100000
PPU_CTRL_SEL = %01000000
PPU_CTRL_NMI = %10000000
;----------
; APU
;----------
APU := $4000
APU_SQ1_VOL := $4000
APU_SQ1_SWEEP := $4001
APU_SQ1_LO := $4002
APU_SQ1_HI := $4003
APU_SQ2_VOL := $4004
APU_SQ2_SWEEP := $4005
APU_SQ2_LO := $4006
APU_SQ2_HI := $4007
APU_TRI_LINEAR := $4008
APU_TRI_LO := $400A
APU_TRI_HI := $400B
APU_NOISE_VOL := $400C
APU_NOISE_LO := $400E
APU_NOISE_HI := $400F
APU_DMC_FREQ := $4010
APU_DMC_RAW := $4011
APU_DMC_START := $4012
APU_DMC_LEN := $4013
APU_SND_CHN := $4015
APU_CTRL := $4015
APU_STATUS := $4015
APU_FRAME := $4017
;----------
; OAM
;----------
OAMDMA := $4014
;----------
; IO
;----------
IO_JOY1 := $4016
IO_JOY2 := $4017
;----------
; NMI
;----------
NMI_DONE = %10000000
NMI_SCRL = %00010000
NMI_PLT = %00001000
NMI_ATR = %00000100
NMI_SPR = %00000010
NMI_BKG = %00000001
;----------
; MMC5
;----------
.ifdef MMC5
MMC5_PRG_MODE := $5100
MMC5_CHR_MODE := $5101
MMC5_RAM_BNK := $5113
MMC5_PRG_BNK0 := $5114
MMC5_PRG_BNK1 := $5115
MMC5_PRG_BNK2 := $5116
MMC5_PRG_BNK3 := $5117
.endif

View File

@ -1,102 +0,0 @@
;****************
; Author: Safyrus
;****************
.ifdef C_CODE
.export _exit,__STARTUP__:absolute=1
.import _main
.endif
; Header of the file (not part of the cartridge, used by the emulator)
.segment "HEADER"
.byte "NES", $1A; 0-3: Header
.byte $02 ; 4: PRG ROM
.byte $01 ; 5: CHR ROM
.if MMC5=1
.byte $51 ; 6: Flags 6
.else
.byte $01 ; 6: Flags 6
.endif
.byte $00 ; 7: Flags 7
.byte $00 ; 8: Flags 8
.byte $00 ; 9: Flags 9
.byte $00 ; 10: Flags 10
.byte $00,$00,$00,$00,$00 ; Padding
.include "constant.asm"
.include "macro.asm"
.include "memory.asm"
; This is the code to use when using the MMC5 mapper
.if MMC5=1
.segment "LAST_BNK"
; 6502 vectors subrountines
.include "vector/rst.asm"
.include "vector/nmi.asm"
.include "vector/irq.asm"
.if FAMISTUDIO=1
; FamiStudio Sound Engine
.include "audio/famistudio_config.asm"
.include "audio/famistudio_ca65.s"
.endif
.segment "STARTUP"
.ifdef C_CODE
_exit:
.endif
.ifndef C_CODE
; main file
.include "main.asm"
.endif
.segment "BNK1"
.if FAMISTUDIO=1
; Musics
.include "audio/music/arpeggio_mmc5.s"
.endif
; This is the code to use when not using any mapper
.else
.segment "STARTUP"
.ifdef C_CODE
_exit:
.endif
; 6502 vectors subrountines
.include "vector/rst.asm"
.include "vector/nmi.asm"
.include "vector/irq.asm"
.ifndef C_CODE
; main file
.include "main.asm"
.endif
.if FAMISTUDIO=1
; FamiStudio Sound Engine
.include "audio/famistudio_config.asm"
.include "audio/famistudio_ca65.s"
; Musics
.include "audio/music/arpeggio.s"
.endif
.endif
; 6502 vectors
.segment "VECTORS"
; 6502 vectors
.word NMI ; fffa nmi/vblank
.word RST ; fffc reset
.word IRQ ; fffe irq/brk
; CHR ROM data
.segment "CHARS"
.incbin GAME_CHR

View File

@ -1,20 +0,0 @@
;**********
; Macros
;**********
.macro pushreg
PHA
TXA
PHA
TYA
PHA
.endmacro
.macro pullreg
PLA
TAY
PLA
TAX
PLA
.endmacro

View File

@ -1,88 +0,0 @@
;**********
; Main
;**********
MAIN:
.if FAMISTUDIO=1
.if MMC5=1
LDX #<music_data_arpeggio_mmc5 ; music data (lo)
LDY #>music_data_arpeggio_mmc5 ; music data (hi)
.else
LDX #<music_data_arpeggio ; music data (lo)
LDY #>music_data_arpeggio ; music data (hi)
.endif
LDA #$01 ; NTSC
JSR famistudio_init
LDA #$00 ; Song 0
JSR famistudio_music_play
.endif
@wait_vblank:
LDA nmi_flags
AND #NMI_DONE
BEQ @wait_vblank
.if FAMISTUDIO=1
; update sound engine
JSR famistudio_update
.endif
LDA #(PPU_MASK_BKG8+PPU_MASK_BKG+PPU_MASK_SPR8+PPU_MASK_SPR)
STA PPU_MASK
LDA #(NMI_ATR+NMI_PLT+NMI_SCRL+NMI_BKG+NMI_SPR)
STA nmi_flags
LDA #$23
STA atr_nametable
LDX #$00
LDA #$00
@loop_atr:
STA attributes, X
INX
CPX #$40
BNE @loop_atr
LDX #$00
@loop_plt:
TXA
STA palettes, X
INX
CPX #25
BNE @loop_plt
LDA #$40
STA OAM+0
LDA #$01
STA OAM+1
LDA #$00
STA OAM+2
LDA game_state
STA OAM+3
LDA #($05 + %00000000)
STA background+0
LDA #$20
STA background+1
LDA game_state
STA background+2
LDA #$04
STA background+3
LDA #$00
STA background+4
LDA #$01
STA background+5
LDA #$02
STA background+6
LDA #$03
STA background+7
LDA #$00
STA background+8
LDX game_state
INX
STX game_state
JMP @wait_vblank

View File

@ -1,91 +0,0 @@
;**********
; Memory
;**********
.segment "ZEROPAGE"
; NMI Flags to activate graphical update
; Note: You cannot activate all updates.
; You need to have a execution time
; < ~2273 cycles (2000 to be sure)
; 7 bit 0
; ---- ----
; E..R PASB
; | | ||||
; | | |||+- Background tiles update
; | | ||| Execution time depend on data
; | | ||| (cycles ~= 16 + 38*p + for i:p do (14*p[i].n))
; | | ||| (p=packet number, p[i].n = packet data size)
; | | ||+-- Sprites update (513+ cycles)
; | | |+--- Nametables attributes update (821 cycles)
; | | +---- Palettes update (356 cycles)
; | +------ Scroll update (31 cycles)
; +--------- 1 when NMI has ended, should be set to 0 after reading.
; If let to 1, it means the NMI is disable
nmi_flags: .res 1
.export _nmi_flags=nmi_flags
; Scroll X position
scroll_x: .res 1
.export _scroll_x=scroll_x
; Scroll Y position
scroll_y: .res 1
.export _scroll_y=scroll_y
; Nametable high adress to update attributes for
; $23 = Nametable 1
; $27 = Nametable 2
; $2B = Nametable 3
; $2F = Nametable 4
atr_nametable: .res 1
.export _atr_nametable=atr_nametable
; value of the PPU_MASK (need to be refresh manually)
ppu_ctrl_val: .res 1
.export _ppu_ctrl_val=ppu_ctrl_val
; Attributes data to send to PPU during VBLANK
attributes: .res 64
.export _attributes=attributes
; Palettes data to send to PPU during VBLANK
; byte 0 = transparente color
; byte 1-3 = background palette 1
; byte 4-6 = background palette 2
; ...
; byte 13-16 = sprite palette 1
; ...
palettes: .res 25
.export _palettes=palettes
; Index for the background data
background_index: .res 1
.export _background_index=background_index
; Background data to send to PPU during VBLANK
; Packet structure:
; byte 0 = v.ssssss (v= vertical draw, s= size)
; byte 1-2 = ppu adress
; byte 3-s = tile data
; packet of size 0 means there is no more data to draw
background: .res 127
.export _background=background
;****************
; OAM SEGMENT
;****************
.segment "OAM"
OAM:
.export _OAM=OAM
;****************
; BSS SEGMENT
;****************
.segment "BSS"
game_state: .res 1
.export _game_state=game_state

View File

@ -1,16 +0,0 @@
;***********
; IRQ vector
;***********
IRQ:
; save register
PHA
; clear APU interrupt
LDA APU_STATUS
; restore register
PLA
; return
RTI

View File

@ -1,217 +0,0 @@
;***********
; NMI vector
;***********
;--------------------
; Cycles notes
;--------------------
; 2273 cycles per VBLANK
; base (before @done) = 13+3+2+3+(2+3)*5
; @sprite = 513+ cycles
; @scroll = 31 cycles
; @attribute = 821 cycles
; @palette = 356 cycless
; @background ~= 16+(38*p+14*p[i].n)
;--------------------
NMI:
; save registers
pushreg
; do we need to do stuff ? (E flag)
BIT nmi_flags
BPL @start
JMP @end
@start:
; load NMI flags
LDA nmi_flags
; is the background flag on ? (B flag)
LSR
BCC @background_end
@background:
; save flags
PHA
LDX #$00
@background_loop:
; read size
LDA background, X
; if size = 0 then end
BEQ @background_loop_end
; save size to Y
AND #$3F
TAY
; is vertical flag off ?
LDA background, X
ASL
BCC @background_loop_hor
; tell the ppu to inc by 32
@background_loop_ver:
LDA ppu_ctrl_val
ORA #(PPU_CTRL_INC)
STA PPU_CTRL
JMP @background_loop_start
; tell the ppu to inc by 1
@background_loop_hor:
LDA ppu_ctrl_val
AND #($FF-PPU_CTRL_INC)
STA PPU_CTRL
@background_loop_start:
; reset latch
BIT PPU_STATUS
; set PPU adr
INX
LDA background, X
STA PPU_ADDR
INX
LDA background, X
STA PPU_ADDR
; send data
@background_loop_data:
; send 1 tile
INX
LDA background, X
STA PPU_DATA
; loop
DEY
BNE @background_loop_data
INX
JMP @background_loop
@background_loop_end:
; restore PPU_CTRL
LDA ppu_ctrl_val
STA PPU_CTRL
; restore flags
PLA
@background_end:
; is the sprite flag on ? (S flag)
LSR
BCC @sprite_end
@sprite:
; Update sprites
LDX #>OAM
STX OAMDMA
@sprite_end:
; is the attribute flag on ? (A flag)
LSR
BCC @attribute_end
@attribute:
; save flags
PHA
; reset latch
BIT PPU_STATUS
; set PPU address
LDA atr_nametable
STA PPU_ADDR
LDA #$C0
STA PPU_ADDR
; send data to PPU
LDX #$00
@attribute_loop:
; send 1 byte
LDA attributes, X
STA PPU_DATA
INX
; send another byte
LDA attributes, X
STA PPU_DATA
INX
; loop
CPX #$40
BNE @attribute_loop
; restore flags
PLA
@attribute_end:
; is the palette flag on ? (P flag)
LSR
BCC @palette_end
@palette:
; save flags
PHA
; reset latch
BIT PPU_STATUS
; set PPU address
LDA #$3F
STA PPU_ADDR
LDA #$00
STA PPU_ADDR
; send data to PPU
LDX #$00
; send transparent color
LDA palettes, X
TAY
INX
@palette_loop:
; send background
TYA
STA PPU_DATA
; send 3 colors
LDA palettes, X
STA PPU_DATA
INX
LDA palettes, X
STA PPU_DATA
INX
LDA palettes, X
STA PPU_DATA
INX
; loop
CPX #25
BNE @palette_loop
; restore flags
PLA
@palette_end:
; is the scroll flag on ? (R flag)
LSR
BCC @scroll_end
@scroll:
; reset latch
BIT PPU_STATUS
; set scrolling position to scroll_x, scroll_y
LDX scroll_x
STX PPU_SCROLL
LDX scroll_y
STX PPU_SCROLL
; set high order bit of X and Y
LDA ppu_ctrl_val
STA PPU_CTRL
@scroll_end:
@done:
; tell that we are done
LDA #NMI_DONE
ORA nmi_flags
STA nmi_flags
@end:
; restore registers
pullreg
; return
RTI

View File

@ -1,70 +0,0 @@
;***********
; RST vector
;***********
.ifdef C_CODE
.import _main
.endif
RST:
SEI ; Disable interrupt
CLD ; Clear/disable decimal
LDX #$FF ; Initialized stack
TXS
INX ; X=0
STX PPU_CTRL ; Disable NMI
STX PPU_MASK ; Disable Rendering
STX APU_DMC_FREQ ; Disable DMC IRQ
; Wait for the PPU to initialized
BIT PPU_STATUS ; Clear the VBL flag if it was set at reset time
@vwait1:
BIT PPU_STATUS
BPL @vwait1 ; At this point, about 27384 cycles have passed
@clrmem:
LDA #$00
STA $0000, x
STA $0100, x
STA $0200, x
STA $0300, x
STA $0400, x
STA $0500, x
STA $0600, x
STA $0700, x
INX
BNE @clrmem
@vwait2:
BIT PPU_STATUS
BPL @vwait2 ; At this point, about 57165 cycles have passed
LDA #%10010000 ; Enable NMI + set background table to $1000
STA PPU_CTRL
STA ppu_ctrl_val
.if MMC5=1
; - - - - - - -
; setup MMC5
; - - - - - - -
; set $8000-9FFF to BNK 0
LDA #$80
STA MMC5_PRG_BNK0
; set $A000-BFFF to BNK 1
LDA #$81
STA MMC5_PRG_BNK1
; set $C000-DFFF to BNK 2
LDA #$82
STA MMC5_PRG_BNK2
.endif
CLI
.ifdef C_CODE
JMP _main
.else
JMP MAIN
.endif

View File

@ -1,90 +0,0 @@
#ifndef _CONSTANT_H_
#define _CONSTANT_H_
#include "type.h"
// ----------
// PPU
// ----------
#define PPU_CTRL 0x2000
#define PPU_MASK 0x2001
#define PPU_STATUS 0x2002
#define PPU_SCROLL 0x2005
#define PPU_ADDR 0x2006
#define PPU_DATA 0x2007
// PPU MASK
#define PPU_MASK_GREY 0b00000001
#define PPU_MASK_BKG8 0b00000010
#define PPU_MASK_SPR8 0b00000100
#define PPU_MASK_BKG 0b00001000
#define PPU_MASK_SPR 0b00010000
#define PPU_MASK_R 0b00100000
#define PPU_MASK_G 0b01000000
#define PPU_MASK_B 0b10000000
// PPU CTRL
#define PPU_CTRL_NM_1 0b00000001
#define PPU_CTRL_NM_2 0b00000010
#define PPU_CTRL_INC 0b00000100
#define PPU_CTRL_SPR 0b00001000
#define PPU_CTRL_BKG 0b00010000
#define PPU_CTRL_SPR_SIZE 0b00100000
#define PPU_CTRL_SEL 0b01000000
#define PPU_CTRL_NMI 0b10000000
// ----------
// APU
// ----------
#define APU 0x4000
#define APU_SQ1_VOL 0x4000
#define APU_SQ1_SWEEP 0x4001
#define APU_SQ1_LO 0x4002
#define APU_SQ1_HI 0x4003
#define APU_SQ2_VOL 0x4004
#define APU_SQ2_SWEEP 0x4005
#define APU_SQ2_LO 0x4006
#define APU_SQ2_HI 0x4007
#define APU_TRI_LINEAR 0x4008
#define APU_TRI_LO 0x400A
#define APU_TRI_HI 0x400B
#define APU_NOISE_VOL 0x400C
#define APU_NOISE_LO 0x400E
#define APU_NOISE_HI 0x400F
#define APU_DMC_FREQ 0x4010
#define APU_DMC_RAW 0x4011
#define APU_DMC_START 0x4012
#define APU_DMC_LEN 0x4013
#define APU_SND_CHN 0x4015
#define APU_CTRL 0x4015
#define APU_STATUS 0x4015
#define APU_FRAME 0x4017
// ----------
// OAM
// ----------
#define OAMDMA 0x4014
// ----------
// IO
// ----------
#define IO_JOY1 0x4016
#define IO_JOY2 0x4017
// ----------
// NMI
// ----------
#define NMI_DONE 0b10000000
#define NMI_SCRL 0b00010000
#define NMI_PLT 0b00001000
#define NMI_ATR 0b00000100
#define NMI_SPR 0b00000010
#define NMI_BKG 0b00000001
#endif // _CONSTANT_H_

View File

@ -1,11 +0,0 @@
#ifndef _RAM_VARIABLES_
#define _RAM_VARIABLES_
#include "type.h"
extern uint8_t game_state;
#define OAM_SIZE 256
extern uint8_t OAM[OAM_SIZE];
#endif // _RAM_VARIABLES_

View File

@ -1,7 +0,0 @@
#ifndef _TYPE_H_
#define _TYPE_H_
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
#endif // _TYPE_H_

View File

@ -1,86 +0,0 @@
#ifndef _ZP_VARIABLES_
#define _ZP_VARIABLES_
#include "type.h"
// NMI Flags to activate graphical update
// Note: You cannot activate all updates.
// You need to have a execution time
// < ~2273 cycles (2000 to be sure)
// 7 bit 0
// ---- ----
// E..R PASB
// | | ||||
// | | |||+- Background tiles update
// | | ||| Execution time depend on data
// | | ||| (cycles ~= 16 + 38*p + for i:p do (14*p[i].n))
// | | ||| (p=packet number, p[i].n = packet data size)
// | | ||+-- Sprites update (513+ cycles)
// | | |+--- Nametables attributes update (821 cycles)
// | | +---- Palettes update (356 cycles)
// | +------ Scroll update (31 cycles)
// +--------- 1 when NMI has ended, should be set to 0 after reading.
// If let to 1, it means the NMI is disable
extern uint8_t nmi_flags;
#pragma zpsym ("nmi_flags")
// Scroll X position
extern uint8_t scroll_x;
#pragma zpsym ("scroll_x")
// Scroll Y position
extern uint8_t scroll_y;
#pragma zpsym ("scroll_y")
// Nametable high adress to update attributes for
// $23 = Nametable 1
// $27 = Nametable 2
// $2B = Nametable 3
// $2F = Nametable 4
extern uint8_t atr_nametable;
#pragma zpsym ("atr_nametable")
// value of the PPU_MASK (need to be refresh manually)
extern uint8_t ppu_ctrl_val;
#pragma zpsym ("ppu_ctrl_val")
// Attributes data to send to PPU during VBLANK
#define ATTRIBUTES_SIZE 64
extern uint8_t attributes[ATTRIBUTES_SIZE];
#pragma zpsym ("attributes")
// Palettes data to send to PPU during VBLANK
// byte 0 = transparente color
// byte 1-3 = background palette 1
// byte 4-6 = background palette 2
// ...
// byte 13-16 = sprite palette 1
// ...
#define PALETTES_SIZE 25
extern uint8_t palettes[PALETTES_SIZE];
#pragma zpsym ("palettes")
// Index for the background data
extern uint8_t background_index;
#pragma zpsym ("background_index")
// Background data to send to PPU during VBLANK
// Packet structure:
// byte 0 = v.ssssss (v= vertical draw, s= size)
// byte 1-2 = ppu adress
// byte 3-s = tile data
// packet of size 0 means there is no more data to draw
#define BACKGROUND_SIZE 128
extern uint8_t background[BACKGROUND_SIZE];
#pragma zpsym ("background")
#endif // _ZP_VARIABLES_

View File

@ -1,92 +0,0 @@
#include "constant.h"
#include "zp_variables.h"
#include "ram_variables.h"
#if FAMISTUDIO 1
#include "famistudio_cc65.h"
#if MMC5 1
extern uint8_t music_data_arpeggio_mmc5[];
#else
extern uint8_t music_data_arpeggio[];
#endif
#endif
void init()
{
#if FAMISTUDIO 1
#if MMC5 1
famistudio_init(1, music_data_arpeggio_mmc5);
#else
famistudio_init(1, music_data_arpeggio);
#endif
famistudio_music_play(0);
#endif
}
void loop()
{
static uint8_t i = 0;
// set PPU_MASK to draw background and sprites
*(uint8_t *)PPU_MASK = PPU_MASK_BKG + PPU_MASK_BKG8 + PPU_MASK_SPR + PPU_MASK_SPR8;
// tell to the nmi what we want to do for the next frame
nmi_flags = NMI_SCRL + NMI_PLT + NMI_BKG + NMI_ATR + NMI_SPR;
// tall the nmi we want to change the attruvtes of the first nametable
atr_nametable = 0x23;
// reset attributes
do
{
attributes[i] = 0;
++i;
} while (i < ATTRIBUTES_SIZE);
// reset paletttes
i = 0;
do
{
palettes[i] = i;
++i;
} while (i < PALETTES_SIZE);
// update sprite
OAM[0] = 0x40;
OAM[1] = 0x01;
OAM[2] = 0x00;
OAM[3] = game_state;
// update background
background[0] = 0x05;
background[1] = 0x20;
background[2] = game_state;
background[3] = 0x04;
background[4] = 0x00;
background[5] = 0x01;
background[6] = 0x02;
background[7] = 0x03;
background[8] = 0x00;
// inc variable
++game_state;
}
void main()
{
init();
while (1)
{
// wait for the next frame
while ((nmi_flags & 0x80) == 0)
{
}
#if FAMISTUDIO 1
famistudio_update();
#endif
loop();
}
}