Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some music and library support for playing it #55

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions compile.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

set name="jeznes"

set famitone_home=..\famitone5.0\
set nsf2data_home=%famitone_home%\nsf2data
set text2data_home=%famitone_home%\text2data
set CC65_HOME=..\cc65\bin\
set path=%path%;%CC65_HOME%
set path=%path%;%CC65_HOME%;%nsf2data_home%;%text2data_home%

nsf2data5.exe music/sfx.nsf -ca65
cp music/sfx.s src/music/sfx.s

text2vol5.exe music/music.txt -ca65
cp music/music.s src/music/music.s

cc65 -Oirs src/%name%.c -o build/%name%.s -g --add-source
ca65 src/crt0.s -o build/crt0.o -g
ca65 build/%name%.s -o build/%name%.o -g

ld65 -C nrom_32k_vert.cfg -o build/%name%.nes build/crt0.o build/%name%.o nes.lib -Ln build/%name%.labels.txt --dbgfile build/%name%.dbg
ld65 -C nrom_32k_vert.cfg -o build/%name%.nes build/crt0.o build/%name%.o nes.lib -Ln build/%name%.labels.txt --dbgfile build/%name%.dbg -v
Binary file added music/music.ftm
Binary file not shown.
87 changes: 33 additions & 54 deletions nrom_32k_vert.cfg
Original file line number Diff line number Diff line change
@@ -1,65 +1,44 @@
MEMORY {
#RAM Addresses:
# Zero page
ZP: start = $00, size = $100, type = rw, define = yes;
#note, the c compiler + neslib + famitone2 use about 60 zp addresses, I think

#note OAM: start = $0200, size = $0100, define = yes;
#note, sprites stored here in the RAM

RAM: start = $0300, size = $0400, define = yes;
#note VRAM_BUFFER: start = $700, size = 128, define = yes;

#INES Header:
HEADER: start = $0, size = $10, file = %O ,fill = yes;


#ROM Addresses:
PRG: start = $8000, size = $8000, file = %O ,fill = yes, define = yes;


#1 Bank of 8K CHR ROM
CHR: start = $0000, size = $2000, file = %O, fill = yes;
# Zero page
ZP: start = $0000, size = $0100, type = rw, define = yes;
# iNES Header
HEADER: start = $0000, size = $0010, file = %O, fill = yes;
# Program ROM
PRG: start = $8000, size = $7d00, file = %O, fill = yes, define = yes;
# Samples ROM
DMC: start = $fd00, size = $02fa, file = %O, fill = yes, define = yes;
# IRQ Vectors
VECTORS: start = $fffa, size = $0006, file = %O, fill = yes;
# 1 Bank of 8K CHR ROM
CHR: start = $0000, size = $2000, file = %O, fill = yes;

RAM: start = $0300, size = $0500, define = yes;
}




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;
CHARS: load = CHR, type = rw;
BSS: load = RAM, type = bss, define = yes;
HEAP: load = RAM, type = bss, optional = yes;
ZEROPAGE: load = ZP, type = zp;
ONCE: load = PRG, type = ro, define = yes, optional = yes;

SAMPLES: load = PRG, start = $f000, type = ro, optional = yes;
VECTORS: load = PRG, start = $fffa, type = ro;
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, type = rw, define = yes, run = RAM;
VECTORS: load = VECTORS, type = ro;
DMC: load = DMC, type = ro, optional = yes;
CHR: load = CHR, type = rw;
BSS: load = RAM, type = bss, define = yes;
HEAP: load = RAM, type = bss, optional = yes;
ZEROPAGE: load = ZP, type = zp;
}




#removed CONDES features




SYMBOLS {
__STACKSIZE__: type = weak, value = $0100; # 1 page stack
__STACK_START__: type = weak, value = $0700;

__STACKSIZE__: type = weak, value = $0100; # 1 page stack
__STACK_START__: type = weak, value = $0700;

NES_MAPPER: type = weak, value = 0; # mapper number, 0 = NROM
NES_PRG_BANKS: type = weak, value = 2; # number of 16K PRG banks, change to 2 for NROM256
NES_CHR_BANKS: type = weak, value = 1; # number of 8K CHR banks
NES_MIRRORING: type = weak, value = 1; # 0 horizontal, 1 vertical, 8 four screen

NES_MAPPER: type = weak, value = 0; # mapper number, 0 = NROM
NES_PRG_BANKS: type = weak, value = 2; # number of 16K PRG banks, change to 2 for NROM256
NES_CHR_BANKS: type = weak, value = 1; # number of 8K CHR banks
NES_MIRRORING: type = weak, value = 1; # 0 horizontal, 1 vertical, 8 four screen
}

27 changes: 27 additions & 0 deletions src/bss.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,33 @@
#include "screens/title.h"
#include "sprites.h"

// Current level when the game is in playing state.
unsigned char current_level;

// Count of balls displayed on the playfield section of whichever screen is
// loaded.
unsigned char current_ball_count;

// Which playfield pattern is currently being displayed.
unsigned char current_playfield_pattern;

// Number of players currently playing.
unsigned char player_count;

// Count of lives remaining.
unsigned char lives_count;

// Percentage of the playfield which has been cleared.
// Note: This is calculated in update_hud() only because it's expensive.
unsigned char cleared_tile_percentage;

// How many playfield tiles have been cleared. This is used to compute the
// percentage |cleared_tile_percentage|.
unsigned int cleared_tile_count;

// Current score counter.
unsigned int score;

unsigned char playfield[PLAYFIELD_WIDTH * PLAYFIELD_HEIGHT];

#if ENABLE_CHEATS
Expand Down
3 changes: 1 addition & 2 deletions src/constants/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#define PLAYER_SPEED 0x2

#define MAX_BALLS 20
#define BALL_SPEED_POSITIVE 1
#define BALL_SPEED_NEGATIVE (-1)
#define BALL_SPEED 1
#define BALL_WIDTH 8
#define BALL_HEIGHT 8

Expand Down
101 changes: 67 additions & 34 deletions src/crt0.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@



FT_BASE_ADR = $0100 ;page in RAM, should be $xx00
FT_BASE_ADR = $0600 ;page in RAM, should be $xx00
FT_DPCM_OFF = $f000 ;$c000..$ffc0, 64-byte steps
FT_SFX_STREAMS = 2 ;number of sound effects played at once, 1..4

FT_THREAD = 1 ;undefine if you call sound effects in the same thread as sound update
FT_PAL_SUPPORT = 1 ;undefine to exclude PAL support
FT_NTSC_SUPPORT = 1 ;undefine to exclude NTSC support
Expand All @@ -16,7 +15,6 @@ FT_SFX_ENABLE = 1 ;undefine to exclude all sound effects code




;REMOVED initlib
;this called the CONDES function

Expand Down Expand Up @@ -70,10 +68,10 @@ NAME_UPD_ENABLE: .res 1
PAL_UPDATE: .res 1
PAL_BG_PTR: .res 2
PAL_SPR_PTR: .res 2
SCROLL_X: .res 1
SCROLL_Y: .res 1
SCROLL_X1: .res 1
SCROLL_Y1: .res 1
;SCROLL_X: .res 1
;SCROLL_Y: .res 1
;SCROLL_X1: .res 1
;SCROLL_Y1: .res 1
PAD_STATE: .res 2 ;one byte per controller
PAD_STATEP: .res 2
PAD_STATET: .res 2
Expand All @@ -83,18 +81,41 @@ PPU_MASK_VAR: .res 1
RAND_SEED: .res 2
FT_TEMP: .res 3

TEMP: .res 11
MUSIC_PLAY: .res 1
ft_music_addr: .res 2

BUF_4000: .res 1
BUF_4001: .res 1
BUF_4002: .res 1
BUF_4003: .res 1
BUF_4004: .res 1
BUF_4005: .res 1
BUF_4006: .res 1
BUF_4007: .res 1
BUF_4008: .res 1
BUF_4009: .res 1
BUF_400A: .res 1
BUF_400B: .res 1
BUF_400C: .res 1
BUF_400D: .res 1
BUF_400E: .res 1
BUF_400F: .res 1

PREV_4003: .res 1
PREV_4007: .res 1

TEMP: .res 10
SPRID: .res 1

PAD_BUF =TEMP+1

PTR =TEMP ;word
LEN =TEMP+2 ;word
NEXTSPR =TEMP+4
SCRX =TEMP+5
SCRY =TEMP+6
SRC =TEMP+7 ;word
DST =TEMP+9 ;word
;NEXTSPR =TEMP+4 ; NEXTSPR removed
SCRX =TEMP+4
SCRY =TEMP+5
SRC =TEMP+6 ;word
DST =TEMP+8 ;word

RLE_LOW =TEMP
RLE_HIGH =TEMP+1
Expand All @@ -103,8 +124,8 @@ RLE_BYTE =TEMP+3

;nesdoug code requires
VRAM_INDEX: .res 1
META_PTR: .res 2
DATA_PTR: .res 2
;META_PTR: .res 2 ; META_PTR removed
;DATA_PTR: .res 2 ; DATA_PTR removed



Expand Down Expand Up @@ -231,10 +252,16 @@ detectNTSC:
ldx #0
jsr _set_vram_update

ldx #<music_data
ldy #>music_data
lda <NTSC_MODE
jsr FamiToneInit
lda #$ff ;previous pulse period MSB, to not write it when not changed
sta PREV_4003
sta PREV_4007

jsr _music_stop

; ldx #<music_data
; ldy #>music_data
; lda <NTSC_MODE
; jsr FamiToneInit

.if(FT_SFX_ENABLE)
ldx #<sounds_data
Expand All @@ -254,27 +281,33 @@ detectNTSC:

.include "lib/neslib.s"
.include "lib/nesdoug.s"
.include "music/famitone2.s"



.include "music/famitone5.s"
.include "lib/ft_drv/driver.s"

.segment "RODATA"

music_data:
.include "music/TestMusic3.s"
.include "music/music.s"

.if(FT_SFX_ENABLE)
music_dummy_data:
.byte $0D,$00,$0D,$00,$0D,$00,$0D,$00,$00,$10,$0E,$B8,$0B,$0F,$00,$16
.byte $00,$01,$40,$06,$96,$00,$18,$00,$22,$00,$22,$00,$22,$00,$22,$00
.byte $22,$00,$00,$3F

.if(FT_SFX_ENABLE)
sounds_data:
.include "music/sfx.s"
.endif
.include "music/sfx.s"
.endif

.segment "SAMPLES"
; .incbin "music_dpcm.bin"
.segment "DMC"
.if(FT_DPCM_ENABLE)
.incbin "../music/samples.bin"
.endif

.segment "VECTORS"
.word nmi ;$fffa vblank nmi
.word start ;$fffc reset
.word irq ;$fffe irq / brk
.word nmi ;$fffa vblank nmi
.word start ;$fffc reset
.word irq ;$fffe irq / brk

.segment "CHARS"
.incbin "../graphics/graphics.chr"
.segment "CHR"
.incbin "../graphics/graphics.chr"
21 changes: 17 additions & 4 deletions src/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,30 @@
#define get_positive_line_segment_origin() (temp_int_2)
#define set_positive_line_segment_origin(a) (temp_int_2 = (a))

#define get_x_velocity() (temp_signed_byte_1)
#define set_x_velocity(a) (temp_signed_byte_1 = (a))
#define get_y_velocity() (temp_signed_byte_2)
#define set_y_velocity(a) (temp_signed_byte_2 = (a))
#define get_flags_byte() (temp_byte_6)
#define set_flags_byte(a) (temp_byte_6 = (a))

#define get_x_direction() (temp_byte_7)
#define set_x_direction(a) (temp_byte_7 = (a))
#define get_y_direction() (temp_byte_7)
#define set_y_direction(a) (temp_byte_7 = (a))

#define get_x_candidate_pixel_coord() (temp_byte_2)
#define set_x_candidate_pixel_coord(a) (temp_byte_2 = (a))
#define inc_x_candidate_pixel_coord() (++temp_byte_2)
#define dec_x_candidate_pixel_coord() (--temp_byte_2)

#define get_y_candidate_pixel_coord() (temp_byte_3)
#define set_y_candidate_pixel_coord(a) (temp_byte_3 = (a))
#define inc_y_candidate_pixel_coord() (++temp_byte_3)
#define dec_y_candidate_pixel_coord() (--temp_byte_3)

#define get_x_compare_pixel_coord() (temp_byte_4)
#define set_x_compare_pixel_coord(a) (temp_byte_4 = (a))
#define get_y_compare_pixel_coord() (temp_byte_4)
#define set_y_compare_pixel_coord(a) (temp_byte_4 = (a))

#define get_playfield_tile_value() (temp_byte_4)
#define set_playfield_tile_value(a) (temp_byte_4 = (a))

#endif // __JEZNES_DATA_H__
Loading