From 3e62f030ed63ac684a853f59acd6b984a81a8779 Mon Sep 17 00:00:00 2001 From: ketmar Date: Thu, 22 Mar 2012 00:55:41 +0200 Subject: [PATCH] sound system seems to work ok --- asm/defs/rst.awa | 4 ++-- asm/game.awa | 13 +++++++++++++ asm/game/dodie.awa | 2 ++ src/awish.c | 2 +- src/resfile.c | 13 +++++++++++-- src/video.c | 22 +++++++++++++++++++--- 6 files changed, 48 insertions(+), 8 deletions(-) diff --git a/asm/defs/rst.awa b/asm/defs/rst.awa index 7c2e69d..670c030 100644 --- a/asm/defs/rst.awa +++ b/asm/defs/rst.awa @@ -34,8 +34,8 @@ econst: FRST_SET_ITEM_NAME = 19 ; arg1: pos(<0: in level data; pos=(-pos) //econst: FRST_NEW_LEVEL_FILE = 30 ; arg1: pos(<0: in level data; pos=(-pos)-1); arg2 (if present) name length, else asiiz econst: FRST_PLAY_SOUND = 50 ; arg1: sound index; arg2 (if present) channel; rst_result: -1 or channel -econst: FRST_STOP_CHANNEL = 51 ; arg1: channel -econst: FRST_IS_CHANNEL_PLAYING = 52 ; arg1: channel; rst_result: bool +econst: FRST_STOP_CHANNEL = 51 ; arg1: channel (-1: all) +econst: FRST_IS_CHANNEL_PLAYING = 52 ; arg1: channel; rst_result: bool (-1: how many channels are playing) econst: FRST_LOAD_SOUND = 53 ; arg1: sound index; rst_result: bool econst: FRST_UNLOAD_SOUND = 54 ; arg1: sound index; rst_result: bool econst: FRST_IS_SOUND_LOADED = 55 ; arg1: sound index; rst_result: bool diff --git a/asm/game.awa b/asm/game.awa index 4eba1b0..5e8f4f6 100644 --- a/asm/game.awa +++ b/asm/game.awa @@ -87,11 +87,24 @@ entry_game_initialize: set [cur_level], 13 set [cur_level], 12 */ + rst FRST_STOP_CHANNEL, -1 + ; load sounds + psh 0 +@@: + dup + rst FRST_LOAD_SOUND + add 1 + dup + jlt @@b, 23 + drp entry_game_restart_level: rst FRST_ML_GAME bsr clear_stack bsr kill_all_threads + ; stop all sound + rst FRST_STOP_CHANNEL, -1 + rst FRST_PLAY_SOUND, SND_HARRY_EATS_APPLE ; set [game_state], GAME_STATE_STARTED brk diff --git a/asm/game/dodie.awa b/asm/game/dodie.awa index 4346764..b337ff4 100644 --- a/asm/game/dodie.awa +++ b/asm/game/dodie.awa @@ -103,6 +103,7 @@ locals: .f, .c jle .animloop, [spr_num], PSPR_LYING_DEAD ; set spr_num, PSPR_LYING_DEAD, 0 + rst FRST_PLAY_SOUND, SND_PROF_FALLS_DEAD end endp: entry_die_fall @@ -123,6 +124,7 @@ proc: entry_die_monster sus [monster_tid] ; set [spr_num], PSPR_HARRY_EATS_PROF_START + rst FRST_PLAY_SOUND, SND_HARRY_EATS_PROF .animloop: brk brk diff --git a/src/awish.c b/src/awish.c index 5119536..bd7dd6d 100644 --- a/src/awish.c +++ b/src/awish.c @@ -374,7 +374,7 @@ int main (int argc, char *argv[]) { } // initResFile(&resfile, "RESOURCE.DAT"); - initResFile(&sndfile, "RESOURCE.DAT"); + initResFile(&sndfile, "RESOURCE.SND"); atexit(quitCleanupRes); // if (loadFont() != 0) { diff --git a/src/resfile.c b/src/resfile.c index d3ac5f9..6c0cb12 100644 --- a/src/resfile.c +++ b/src/resfile.c @@ -108,14 +108,15 @@ static int tryInitResFile (ResFile *resfile, const char *fname) { FILE *fl = fopen(fname, "rb"); int rr = -1, sz; // + //fprintf(stderr, "RES: [%s]\n", fname); if (!fl) return -1; if (!resfile) goto quit; memset(resfile, 0, sizeof(resfile)); // if (fread(sign, 3, 1, fl) != 1) goto quit; - if (memcmp(sign, "RES", 3) != 0) goto quit; + if (memcmp(sign, "RES", 3) != 0 && memcmp(sign, "SND", 3) != 0 && memcmp(sign, "MUS", 3) != 0) goto quit; if (fread(&fcnt, 1, 1, fl) != 1) goto quit; - if (fcnt < 93) goto quit; + if (fcnt < 1/*93*/) goto quit; // resfile->fl = fl; resfile->count = fcnt; @@ -134,12 +135,14 @@ static int tryInitResFile (ResFile *resfile, const char *fname) { // fl = NULL; rr = 0; + //fprintf(stderr, "RES: [%s]: OK\n", fname); quit: if (fl != NULL) { fclose(fl); if (resfile->sizes) free(resfile->sizes); if (resfile->offsets) free(resfile->offsets); memset(resfile, 0, sizeof(resfile)); + //fprintf(stderr, "RES: [%s]: FAIL\n", fname); } return rr; } @@ -708,9 +711,11 @@ Mix_Chunk *loadDiskSoundFile (const char *fname) { if (data != NULL) { Mix_Chunk *res = loadADS(data, rsz); // + //if (goobers) fprintf(stderr, "sound [%s]: %s\n", fname, res!=NULL?"OK":"BAD"); free(data); return res; } + //if (goobers) fprintf(stderr, "sound [%s]: MISSING\n", fname); return NULL; } @@ -747,6 +752,7 @@ static Mix_Chunk *tryDiskSoundFile (int idx) { Mix_Chunk *loadSoundFile (ResFile *resfile, int idx) { Mix_Chunk *res = NULL; // + //fprintf(stderr, ":::%p:%d:%d\n", resfile, idx, resfile->count); if (!datfirst) res = tryDiskSoundFile(idx); if (res == NULL && resfile != NULL && idx >= 0 && idx < resfile->count) { uint8_t *data; @@ -755,7 +761,10 @@ Mix_Chunk *loadSoundFile (ResFile *resfile, int idx) { data = tryResFile(resfile, idx, &rsz, NULL, -1); if (data != NULL) { res = loadADS(data, rsz); + //if (goobers) fprintf(stderr, "sound [%d]: %s\n", idx, res!=NULL?"OK":"BAD"); free(data); + } else { + //if (goobers) fprintf(stderr, "sound [%d]: MISSING\n", idx); } } if (res == NULL && datfirst) res = tryDiskSoundFile(idx); diff --git a/src/video.c b/src/video.c index 8d43267..2976ddd 100644 --- a/src/video.c +++ b/src/video.c @@ -18,6 +18,10 @@ #include "video.h" +#ifndef AWISH_NO_SOUND +# include "SDL_mixer.h" +#endif + //////////////////////////////////////////////////////////////////////////////// SDL_Surface *screen = NULL; @@ -29,22 +33,34 @@ Uint8 font[256][8]; //////////////////////////////////////////////////////////////////////////////// static void quitCleanupCB (void) { //if (TTF_WasInit()) TTF_Quit(); + Mix_CloseAudio(); SDL_Quit(); } //////////////////////////////////////////////////////////////////////////////// void sdlInit (void) { - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) { + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER +#ifndef AWISH_NO_SOUND + | SDL_INIT_AUDIO +#endif + ) < 0) { fprintf(stderr, "FATAL: can't set videomode!\n"); exit(1); } - atexit(quitCleanupCB); - // SDL_WM_SetCaption("Awish", "Awish"); SDL_EnableKeyRepeat(200, 25); //SDL_EnableUNICODE(1); // just4fun SDL_EnableUNICODE(0); // just4fun +#ifndef AWISH_NO_SOUND + Mix_Init(0); + if (Mix_OpenAudio(22050, AUDIO_U8, 0, 8192)) { + SDL_Quit(); + fprintf(stderr, "FATAL: unable to open audio!\n"); + exit(1); + } +#endif + atexit(quitCleanupCB); } -- 2.11.4.GIT