updated famitone2 library and added positional audio.

This commit is contained in:
Simon Ullrich Richter 2020-01-29 03:06:23 +01:00
parent 7c22316d3c
commit 5ce3a74bd5
5 changed files with 147 additions and 82 deletions

View File

@ -15,7 +15,7 @@ all: $(EXECUTABLE) ${CRT_OBJ}
crt0.o: *.s *.chr
%.s: %.c *.h levels/*.h
$(CC) -Oi $< --add-source
CC65_HOME=$(CC65_HOME) $(CC) -Oi $< --add-source
%.o: %.s
CC65_HOME=$(CC65_HOME) $(ASM) $<

View File

@ -1,4 +1,4 @@
;FamiTone2 v1.11
;FamiTone2 v1.12
@ -35,7 +35,7 @@ FT_TEMP_PTR = FT_TEMP ;word
FT_TEMP_PTR_L = FT_TEMP_PTR+0
FT_TEMP_PTR_H = FT_TEMP_PTR+1
FT_TEMP_VAR1 = FT_TEMP+2
FT_TEMP_SIZE = 3
;envelope structure offsets, 5 bytes per envelope, grouped by variable type
@ -148,6 +148,7 @@ FT_SFX_PTR_H = FT_SFX_BASE_ADR+2
FT_SFX_OFF = FT_SFX_BASE_ADR+3
FT_SFX_BUF = FT_SFX_BASE_ADR+4 ;11 bytes
FT_BASE_SIZE = FT_SFX_BUF+11-FT_BASE_ADR
;aliases for sound effect channels to use in user calls
@ -318,7 +319,7 @@ FamiToneMusicStop:
bne @set_envelopes
rts
jmp FamiToneSampleStop
;------------------------------------------------------------------------------
@ -409,7 +410,11 @@ FamiToneMusicPause:
tax ;set SZ flags for A
beq @unpause
@pause:
jsr FamiToneSampleStop
lda #0 ;mute sound
sta FT_CH1_VOLUME
sta FT_CH2_VOLUME
@ -926,8 +931,6 @@ _FT2ChannelUpdate:
rts
.if(FT_DPCM_ENABLE)
;------------------------------------------------------------------------------
; stop DPCM sample if it plays
@ -941,6 +944,9 @@ FamiToneSampleStop:
rts
.if(FT_DPCM_ENABLE)
;------------------------------------------------------------------------------
; play DPCM sample, used by music player, could be used externally
; in: A is number of a sample, 1..63
@ -1015,23 +1021,26 @@ _FT2SamplePlay:
FamiToneSfxInit:
stx <FT_TEMP_PTR_L
sty <FT_TEMP_PTR_H
ldy #0
.if(FT_PITCH_FIX)
lda FT_PAL_ADJUST ;add 2 to the sound list pointer for PAL
bne @ntsc
inx
bne @no_inc1
iny
@no_inc1:
inx
bne @ntsc
iny
@ntsc:
.endif
stx FT_SFX_ADR_L ;remember pointer to the data
sty FT_SFX_ADR_H
lda (FT_TEMP_PTR),y ;read and store pointer to the effects list
sta FT_SFX_ADR_L
iny
lda (FT_TEMP_PTR),y
sta FT_SFX_ADR_H
ldx #FT_SFX_CH0 ;init all the streams
@ -1068,14 +1077,13 @@ _FT2SfxClearChannel:
;------------------------------------------------------------------------------
; play sound effect
; in: A is a number of the sound effect
; in: A is a number of the sound effect 0..127
; X is offset of sound effect channel, should be FT_SFX_CH0..FT_SFX_CH3
;------------------------------------------------------------------------------
FamiToneSfxPlay:
asl a ;get offset in the effects list
asl a
tay
jsr _FT2SfxClearChannel ;stops the effect if it plays
@ -1089,7 +1097,7 @@ FamiToneSfxPlay:
sta FT_SFX_PTR_L,x ;store it
iny
lda (FT_TEMP_PTR),y
sta FT_SFX_PTR_H,x ;this enables the effect
sta FT_SFX_PTR_H,x ;this write enables the effect
rts

74
game.c
View File

@ -7,6 +7,12 @@
/* NESlib */
#include "neslib.h"
/* Low Level NES Api */
#define __NES__
//#include "nes.h"
#include <stdlib.h>
/* Name tables */
#include "levels/splat_title.h"
@ -80,8 +86,11 @@ extern const unsigned char music_music_data[];
/* Sound effects */
#define SFX_START 0
#define SFX_SPLAT 1
#define SFX_RESPAWN1 2
#define SFX_DEATH 3
#define SFX_SPLAT_VOL3 2
#define SFX_SPLAT_VOL2 3
#define SFX_SPLAT_VOL1 4
#define SFX_RESPAWN1 5
#define SFX_DEATH 6
/* Music */
#define MUSIC_LEVEL 0
@ -185,7 +194,7 @@ static unsigned char ptr,spr;
static unsigned char px,py;
static unsigned char wait;
static unsigned int i16;
static unsigned int sum,div;
static unsigned int sum,divvar;
static unsigned char nameRow[32];
@ -648,7 +657,7 @@ void show_credits() {
/* Write credits. */
i = 0;
j = 0;
div = 0;
divvar = 0;
/* Clear the scrolling nametables, A and C */
vram_adr(NAMETABLE_C);
@ -670,17 +679,17 @@ void show_credits() {
ppu_on_all();
do {
scroll(0,div);
scroll(0,divvar);
/* Judd as a sprite. */
if (i == 0 && div < 0x62) {
oam_meta_spr(0x70,0x48-div,0,(char*)i16);
if (i == 0 && divvar < 0x62) {
oam_meta_spr(0x70,0x48-divvar,0,(char*)i16);
}
div++;
divvar++;
WAIT_WITH_SKIP(1);
} while (div % 240);
if (div == 480) div = 0;
} while (divvar % 240);
if (divvar == 480) divvar = 0;
if (sum == NAMETABLE_A) sum = NAMETABLE_C;
else sum = NAMETABLE_A;
@ -695,10 +704,10 @@ void show_credits() {
vram_fill(0xa0,1024-64);
ppu_on_all();
while (div % 240 < 100) {
while (divvar % 240 < 100) {
WAIT_WITH_SKIP(1);
scroll(0,div);
div++;
scroll(0,divvar);
divvar++;
}
_skip_title:
@ -739,19 +748,19 @@ void show_endgame(void) {
sum = (player_score[0] + player_score[1]);
/* Calculate percentage for player 1 */
div = player_score[0] * 100;
div /= sum;
if (div == 100) div = 99;
if (div == 0) div = 1;
put_num(NAMETABLE_A+0x1EA,div,2);
divvar = player_score[0] * 100;
divvar /= sum;
if (divvar == 100) divvar = 99;
if (divvar == 0) divvar = 1;
put_num(NAMETABLE_A+0x1EA,divvar,2);
/* Player 2 must be 100% - (player 1) */
div = 100 - div;
put_num(NAMETABLE_A+0x1F4,div,2);
divvar = 100 - divvar;
put_num(NAMETABLE_A+0x1F4,divvar,2);
/* Convert Player 2's percentage to a gauge width */
div *= 9;
div /= 100;
divvar *= 9;
divvar /= 100;
/* Print the victory message. */
if (player_score[0] > player_score[1]) {
@ -780,11 +789,11 @@ void show_endgame(void) {
/* Set the gauge palettes. */
clear_update_list();
for (i = 4; i < 12 - div; ++i) {
for (i = 4; i < 12 - divvar; ++i) {
/* Player 1 on the left. */
set_tile_palette(i,8,1);
}
for (i = 12 - div; i <= 11; ++i) {
for (i = 12 - divvar; i <= 11; ++i) {
/* Player 2 on the right. */
set_tile_palette(i,8,2);
@ -857,6 +866,19 @@ void projectile_move(unsigned char id) {
}
/**
* Calculate player distance
*
* Uses Manhattan metric
*/
unsigned int player_dist(unsigned char id1, unsigned char id2){
int px2=player_x[id1]>>(TILE_SIZE_BIT+FP_BITS);
int py2=player_y[id1]>>(TILE_SIZE_BIT+FP_BITS);
int px=player_x[id2]>>(TILE_SIZE_BIT+FP_BITS);
int py=player_y[id2]>>(TILE_SIZE_BIT+FP_BITS);
return abs(px2-px)+abs(py2-py);
}
/**
* Player movement test.
*
@ -977,7 +999,9 @@ void player_move(unsigned char id,unsigned char dir_index) {
player_cnt[id]=TILE_SIZE<<FP_BITS;
player_diag_flip[id]=1;
sfx_play(SFX_SPLAT,0);
//APU.pulse[0].control=0x12;
sfx_play(SFX_SPLAT+((player_dist(0,1)>>2)%4),0); //positional audio
}
/**

Binary file not shown.

113
sounds.s
View File

@ -1,40 +1,73 @@
;this file for FamiTone2 libary generated by nsf2data tool
sounds:
.word @sfx_ntsc_0,@sfx_pal_0
.word @sfx_ntsc_1,@sfx_pal_1
.word @sfx_ntsc_2,@sfx_pal_2
.word @sfx_ntsc_3,@sfx_pal_3
@sfx_ntsc_0:
.byte $80,$7f,$81,$7e,$82,$00,$04,$81,$6a,$04,$81,$5e,$04,$81,$7e,$04
.byte $80,$74,$04,$81,$6a,$04,$81,$5e,$04,$81,$7e,$04,$80,$71,$04,$81
.byte $6a,$04,$81,$5e,$04,$81,$7e,$00
@sfx_ntsc_1:
.byte $89,$3f,$8a,$00,$01,$89,$3e,$8a,$0e,$01,$89,$3d,$8a,$0c,$01,$89
.byte $3c,$8a,$0a,$00
@sfx_ntsc_2:
.byte $80,$ff,$81,$ab,$82,$01,$01,$81,$3c,$01,$81,$9c,$82,$00,$01,$81
.byte $b5,$01,$81,$cb,$01,$80,$30,$00
@sfx_ntsc_3:
.byte $80,$3b,$81,$d5,$82,$00,$06,$80,$3f,$81,$cf,$01,$81,$c9,$01,$81
.byte $c3,$01,$81,$bd,$01,$81,$b7,$01,$81,$b1,$01,$80,$bf,$81,$ab,$01
.byte $81,$a5,$01,$81,$9f,$01,$81,$99,$01,$81,$96,$02,$81,$9a,$01,$81
.byte $9e,$01,$81,$a2,$01,$81,$a6,$01,$81,$aa,$01,$81,$ae,$01,$81,$b2
.byte $01,$81,$b6,$01,$81,$ba,$01,$81,$be,$01,$81,$c2,$01,$81,$c6,$00
@sfx_pal_0:
.byte $80,$7f,$81,$75,$82,$00,$04,$81,$62,$03,$81,$57,$03,$81,$75,$04
.byte $80,$74,$03,$81,$62,$03,$81,$57,$04,$81,$75,$03,$80,$71,$03,$81
.byte $62,$04,$81,$57,$03,$81,$75,$00
@sfx_pal_1:
.byte $89,$3f,$8a,$00,$01,$89,$3e,$8a,$0e,$01,$89,$3d,$8a,$0c,$01,$89
.byte $3c,$8a,$0a,$00
@sfx_pal_2:
.byte $80,$ff,$81,$8c,$82,$01,$01,$81,$26,$01,$81,$91,$82,$00,$01,$81
.byte $a8,$01,$81,$bc,$01,$80,$30,$00
@sfx_pal_3:
.byte $80,$3b,$81,$c6,$82,$00,$05,$80,$3f,$81,$c0,$01,$81,$ba,$01,$81
.byte $b4,$01,$81,$ae,$01,$81,$a8,$01,$80,$bf,$81,$a2,$01,$81,$9c,$01
.byte $81,$96,$01,$81,$90,$01,$81,$8b,$01,$81,$8f,$01,$81,$93,$01,$81
.byte $97,$01,$81,$9b,$01,$81,$9f,$01,$81,$a3,$01,$81,$a7,$01,$81,$ab
.byte $01,$81,$af,$01,$81,$b3,$00
;this file for FamiTone2 libary generated by nsf2data tool
sounds:
.word @ntsc
.word @pal
@ntsc:
.word @sfx_ntsc_0
.word @sfx_ntsc_1
.word @sfx_ntsc_2
.word @sfx_ntsc_3
.word @sfx_ntsc_4
.word @sfx_ntsc_5
.word @sfx_ntsc_6
@pal:
.word @sfx_pal_0
.word @sfx_pal_1
.word @sfx_pal_2
.word @sfx_pal_3
.word @sfx_pal_4
.word @sfx_pal_5
.word @sfx_pal_6
@sfx_ntsc_0:
.byte $80,$7f,$81,$7e,$82,$08,$04,$81,$6a,$04,$81,$5e,$04,$81,$7e,$04
.byte $80,$74,$04,$81,$6a,$04,$81,$5e,$04,$81,$7e,$04,$80,$71,$04,$81
.byte $6a,$04,$81,$5e,$04,$81,$7e,$06,$00
@sfx_pal_0:
.byte $80,$7f,$81,$75,$82,$08,$04,$81,$62,$03,$81,$57,$03,$81,$75,$04
.byte $80,$74,$03,$81,$62,$03,$81,$57,$04,$81,$75,$03,$80,$71,$03,$81
.byte $62,$04,$81,$57,$03,$81,$75,$05,$00
@sfx_ntsc_1:
.byte $89,$3f,$8a,$00,$01,$89,$3e,$8a,$0e,$01,$89,$3d,$8a,$0c,$01,$89
.byte $3c,$8a,$0a,$01,$00
@sfx_pal_1:
.byte $89,$3f,$8a,$00,$01,$89,$3e,$8a,$0e,$01,$89,$3d,$8a,$0c,$01,$89
.byte $3c,$8a,$0a,$01,$00
@sfx_ntsc_2:
.byte $89,$3a,$8a,$00,$01,$89,$39,$8a,$0e,$01,$89,$38,$8a,$0c,$01,$89
.byte $37,$8a,$0a,$01,$00
@sfx_pal_2:
.byte $89,$3a,$8a,$00,$01,$89,$39,$8a,$0e,$01,$89,$38,$8a,$0c,$01,$89
.byte $37,$8a,$0a,$01,$00
@sfx_ntsc_3:
.byte $89,$37,$8a,$00,$01,$89,$36,$8a,$0e,$01,$89,$35,$8a,$0c,$01,$89
.byte $34,$8a,$0a,$01,$00
@sfx_pal_3:
.byte $89,$37,$8a,$00,$01,$89,$36,$8a,$0e,$01,$89,$35,$8a,$0c,$01,$89
.byte $34,$8a,$0a,$01,$00
@sfx_ntsc_4:
.byte $89,$34,$8a,$00,$01,$89,$33,$8a,$0e,$01,$89,$32,$8a,$0c,$01,$89
.byte $31,$8a,$0a,$01,$00
@sfx_pal_4:
.byte $89,$34,$8a,$00,$01,$89,$33,$8a,$0e,$01,$89,$32,$8a,$0c,$01,$89
.byte $31,$8a,$0a,$01,$00
@sfx_ntsc_5:
.byte $80,$ff,$81,$ab,$82,$09,$01,$81,$3c,$01,$81,$9c,$82,$08,$01,$81
.byte $b5,$01,$81,$cb,$01,$00
@sfx_pal_5:
.byte $80,$ff,$81,$8c,$82,$09,$01,$81,$26,$01,$81,$91,$82,$08,$01,$81
.byte $a8,$01,$81,$bc,$01,$00
@sfx_ntsc_6:
.byte $80,$3b,$81,$d5,$82,$08,$06,$80,$3f,$81,$cf,$01,$81,$c9,$01,$81
.byte $c3,$01,$81,$bd,$01,$81,$b7,$01,$81,$b1,$01,$80,$bf,$81,$ab,$01
.byte $81,$a5,$01,$81,$9f,$01,$81,$99,$01,$81,$96,$02,$81,$9a,$01,$81
.byte $9e,$01,$81,$a2,$01,$81,$a6,$01,$81,$aa,$01,$81,$ae,$01,$81,$b2
.byte $01,$81,$b6,$01,$81,$ba,$01,$81,$be,$01,$81,$c2,$01,$81,$c6,$01
.byte $00
@sfx_pal_6:
.byte $80,$3b,$81,$c6,$82,$08,$05,$80,$3f,$81,$c0,$01,$81,$ba,$01,$81
.byte $b4,$01,$81,$ae,$01,$81,$a8,$01,$80,$bf,$81,$a2,$01,$81,$9c,$01
.byte $81,$96,$01,$81,$90,$01,$81,$8b,$01,$81,$8f,$01,$81,$93,$01,$81
.byte $97,$01,$81,$9b,$01,$81,$9f,$01,$81,$a3,$01,$81,$a7,$01,$81,$ab
.byte $01,$81,$af,$01,$81,$b3,$01,$00