From 78943068787ee6d63e1045df9d286d98b5a2912c Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Mon, 15 Feb 1999 23:26:16 +0100 Subject: [PATCH] rnd-19990215-2 --- src/buttons.c | 938 -------------------------------------------------- src/buttons.h | 19 - src/events.c | 6 - src/files.c | 37 +- src/misc.c | 40 +++ src/misc.h | 39 ++- src/screens.c | 433 ----------------------- src/sound.c | 190 +++------- src/sound.h | 13 +- src/tools.c | 78 ----- 10 files changed, 114 insertions(+), 1679 deletions(-) diff --git a/src/buttons.c b/src/buttons.c index 7c1e9c9a..1e0ff787 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -669,944 +669,6 @@ void DrawCompleteVideoDisplay() VX,VY, VXSIZE,VYSIZE, DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY2); } -void DrawSoundDisplay(unsigned long state) -{ - int pos, cx = DOOR_GFX_PAGEX4, cy = 0; - - pos = (state & BUTTON_SOUND_MUSIC ? SOUND_BUTTON_MUSIC_XPOS : - state & BUTTON_SOUND_LOOPS ? SOUND_BUTTON_LOOPS_XPOS : - SOUND_BUTTON_SIMPLE_XPOS); - - if (state & BUTTON_ON) - cy -= SOUND_BUTTON_YSIZE; - - if (state & BUTTON_PRESSED) - cx = DOOR_GFX_PAGEX3; - - XCopyArea(display,pix[PIX_DOOR],drawto,gc, - cx + pos,cy + SOUND_BUTTON_ANY_YPOS, - SOUND_BUTTON_XSIZE,SOUND_BUTTON_YSIZE, - DX + pos,DY + SOUND_BUTTON_ANY_YPOS); - - redraw_mask |= REDRAW_DOOR_1; -} - -void DrawGameButton(unsigned long state) -{ - int pos, cx = DOOR_GFX_PAGEX4, cy = -GAME_BUTTON_YSIZE; - - pos = (state & BUTTON_GAME_STOP ? GAME_BUTTON_STOP_XPOS : - state & BUTTON_GAME_PAUSE ? GAME_BUTTON_PAUSE_XPOS : - GAME_BUTTON_PLAY_XPOS); - - if (state & BUTTON_PRESSED) - cx = DOOR_GFX_PAGEX3; - - XCopyArea(display,pix[PIX_DOOR],drawto,gc, - cx + pos,cy + GAME_BUTTON_ANY_YPOS, - GAME_BUTTON_XSIZE,GAME_BUTTON_YSIZE, - DX + pos,DY + GAME_BUTTON_ANY_YPOS); - - redraw_mask |= REDRAW_DOOR_1; -} - -void DrawYesNoButton(unsigned long state, int mode) -{ - Drawable dest_drawto; - int dest_xoffset, dest_yoffset; - int xpos, cx = DOOR_GFX_PAGEX4; - - if (mode == DB_INIT) - { - dest_drawto = pix[PIX_DB_DOOR]; - dest_xoffset = DOOR_GFX_PAGEX1; - dest_yoffset = 0; - } - else - { - dest_drawto = drawto; - dest_xoffset = DX; - dest_yoffset = DY; - } - - xpos = (state & BUTTON_OK ? OK_BUTTON_XPOS : NO_BUTTON_XPOS); - - if (state & BUTTON_PRESSED) - cx = DOOR_GFX_PAGEX3; - - XCopyArea(display, pix[PIX_DOOR], dest_drawto, gc, - cx + xpos, OK_BUTTON_GFX_YPOS, - OK_BUTTON_XSIZE, OK_BUTTON_YSIZE, - dest_xoffset + xpos, dest_yoffset + OK_BUTTON_YPOS); - - redraw_mask |= REDRAW_DOOR_1; -} - -void DrawConfirmButton(unsigned long state, int mode) -{ - Drawable dest_drawto; - int dest_xoffset, dest_yoffset; - int cx = DOOR_GFX_PAGEX4; - - if (mode == DB_INIT) - { - dest_drawto = pix[PIX_DB_DOOR]; - dest_xoffset = DOOR_GFX_PAGEX1; - dest_yoffset = 0; - } - else - { - dest_drawto = drawto; - dest_xoffset = DX; - dest_yoffset = DY; - } - - if (state & BUTTON_PRESSED) - cx = DOOR_GFX_PAGEX3; - - XCopyArea(display, pix[PIX_DOOR], dest_drawto, gc, - cx + CONFIRM_BUTTON_XPOS, CONFIRM_BUTTON_GFX_YPOS, - CONFIRM_BUTTON_XSIZE, CONFIRM_BUTTON_YSIZE, - dest_xoffset + CONFIRM_BUTTON_XPOS, - dest_yoffset + CONFIRM_BUTTON_YPOS); - - redraw_mask |= REDRAW_DOOR_1; -} - -void DrawPlayerButton(unsigned long state, int mode) -{ - Drawable dest_drawto; - int dest_xoffset, dest_yoffset; - int graphic = GFX_SPIELER1; /* default */ - int graphic_offset = (PLAYER_BUTTON_XSIZE - TILEX/2)/2; - int xpos, ypos; - int cx = DOOR_GFX_PAGEX4, cy = 0; - - if (mode == DB_INIT) - { - dest_drawto = pix[PIX_DB_DOOR]; - dest_xoffset = DOOR_GFX_PAGEX1; - dest_yoffset = 0; - } - else - { - dest_drawto = drawto; - dest_xoffset = DX; - dest_yoffset = DY; - } - - if (state & BUTTON_PLAYER_1) - graphic = GFX_SPIELER1; - else if (state & BUTTON_PLAYER_2) - graphic = GFX_SPIELER2; - else if (state & BUTTON_PLAYER_3) - graphic = GFX_SPIELER3; - else if (state & BUTTON_PLAYER_4) - graphic = GFX_SPIELER4; - - xpos = (state & BUTTON_PLAYER_1 || state & BUTTON_PLAYER_3 ? - PLAYER_BUTTON_1_XPOS : PLAYER_BUTTON_2_XPOS); - ypos = (state & BUTTON_PLAYER_1 || state & BUTTON_PLAYER_2 ? - PLAYER_BUTTON_1_YPOS : PLAYER_BUTTON_3_YPOS); - - if (state & BUTTON_PRESSED) - { - cx = DOOR_GFX_PAGEX3; - graphic_offset += 1; - } - - XCopyArea(display, pix[PIX_DOOR], dest_drawto, gc, - cx + PLAYER_BUTTON_GFX_XPOS, cy + PLAYER_BUTTON_GFX_YPOS, - PLAYER_BUTTON_XSIZE, PLAYER_BUTTON_YSIZE, - dest_xoffset + xpos, dest_yoffset + ypos); - DrawMiniGraphicExt(dest_drawto,gc, - dest_xoffset + xpos + graphic_offset, - dest_yoffset + ypos + graphic_offset, - graphic); - - redraw_mask |= REDRAW_DOOR_1; -} - -/* several buttons in the level editor */ - -void DrawEditButton(unsigned long state) -{ - int i; - int xpos = 0, ypos = 1, xsize = 2, ysize = 3; - int cx = DOOR_GFX_PAGEX6, cy = DOOR_GFX_PAGEY2; - static int edit_pos[6][4] = - { - {ED_BUTTON_CTRL_XPOS,ED_BUTTON_CTRL_YPOS, - ED_BUTTON_CTRL_XSIZE,ED_BUTTON_CTRL_YSIZE}, - - {ED_BUTTON_FILL_XPOS,ED_BUTTON_FILL_YPOS, - ED_BUTTON_FILL_XSIZE,ED_BUTTON_FILL_YSIZE}, - - {ED_BUTTON_LEFT_XPOS,ED_BUTTON_LEFT_YPOS, - ED_BUTTON_LEFT_XSIZE,ED_BUTTON_LEFT_YSIZE}, - - {ED_BUTTON_UP_XPOS,ED_BUTTON_UP_YPOS, - ED_BUTTON_UP_XSIZE,ED_BUTTON_UP_YSIZE}, - - {ED_BUTTON_DOWN_XPOS,ED_BUTTON_DOWN_YPOS, - ED_BUTTON_DOWN_XSIZE,ED_BUTTON_DOWN_YSIZE}, - - {ED_BUTTON_RIGHT_XPOS,ED_BUTTON_RIGHT_YPOS, - ED_BUTTON_RIGHT_XSIZE,ED_BUTTON_RIGHT_YSIZE} - }; - - if (state & ED_BUTTON_PRESSED) - cx = DOOR_GFX_PAGEX5; - - for(i=0;i<6;i++) - { - if (state & (1<=0 && pressed) - { - pressed = FALSE; - DrawVideoDisplay(video_button[choice]<<1,0); - } - else if (ON_VIDEO_BUTTON(mx,my) && VIDEO_BUTTON(mx)==choice && !pressed) - { - pressed = TRUE; - DrawVideoDisplay(video_button[choice],0); - } - } - } - else /* Maustaste wieder losgelassen */ - { - if (ON_VIDEO_BUTTON(mx,my) && VIDEO_BUTTON(mx)==choice && pressed) - { - DrawVideoDisplay(video_button[choice]<<1,0); - return_code = choice+1; - choice = -1; - pressed = FALSE; - } - else - { - choice = -1; - pressed = FALSE; - } - } - - BackToFront(); - return(return_code); -} - -int CheckSoundButtons(int mx, int my, int button) -{ - int return_code = 0; - static int choice = -1; - static boolean pressed = FALSE; - int sound_state[3]; - - sound_state[0] = BUTTON_SOUND_MUSIC | (BUTTON_ON * setup.sound_music); - sound_state[1] = BUTTON_SOUND_LOOPS | (BUTTON_ON * setup.sound_loops); - sound_state[2] = BUTTON_SOUND_SIMPLE | (BUTTON_ON * setup.sound_simple); - - if (button) - { - if (!motion_status) /* Maustaste neu gedrückt */ - { - if (ON_SOUND_BUTTON(mx,my)) - { - choice = SOUND_BUTTON(mx); - pressed = TRUE; - DrawSoundDisplay(sound_state[choice] | BUTTON_PRESSED); - } - } - else /* Mausbewegung bei gedrückter Maustaste */ - { - if ((!ON_SOUND_BUTTON(mx,my) || SOUND_BUTTON(mx)!=choice) && - choice>=0 && pressed) - { - pressed = FALSE; - DrawSoundDisplay(sound_state[choice] | BUTTON_RELEASED); - } - else if (ON_SOUND_BUTTON(mx,my) && SOUND_BUTTON(mx)==choice && !pressed) - { - pressed = TRUE; - DrawSoundDisplay(sound_state[choice] | BUTTON_PRESSED); - } - } - } - else /* Maustaste wieder losgelassen */ - { - if (ON_SOUND_BUTTON(mx,my) && SOUND_BUTTON(mx)==choice && pressed) - { - DrawSoundDisplay(sound_state[choice] | BUTTON_RELEASED); - return_code = 1<=0 && pressed) - { - pressed = FALSE; - DrawGameButton(game_state[choice] | BUTTON_RELEASED); - } - else if (ON_GAME_BUTTON(mx,my) && GAME_BUTTON(mx)==choice && !pressed) - { - pressed = TRUE; - DrawGameButton(game_state[choice] | BUTTON_PRESSED); - } - } - } - else /* Maustaste wieder losgelassen */ - { - if (ON_GAME_BUTTON(mx,my) && GAME_BUTTON(mx)==choice && pressed) - { - DrawGameButton(game_state[choice] | BUTTON_RELEASED); - return_code = 1<=0 && pressed) - { - pressed = FALSE; - DrawYesNoButton(yesno_button[choice] | BUTTON_RELEASED, DB_NORMAL); - } - else if (ON_YESNO_BUTTON(mx,my) && YESNO_BUTTON(mx)==choice && !pressed) - { - pressed = TRUE; - DrawYesNoButton(yesno_button[choice] | BUTTON_PRESSED, DB_NORMAL); - } - } - } - else /* Maustaste wieder losgelassen */ - { - if (ON_YESNO_BUTTON(mx,my) && YESNO_BUTTON(mx)==choice && pressed) - { - DrawYesNoButton(yesno_button[choice] | BUTTON_RELEASED, DB_NORMAL); - return_code = choice+1; - choice = -1; - pressed = FALSE; - } - else - { - choice = -1; - pressed = FALSE; - } - } - - BackToFront(); - return(return_code); -} - -int CheckConfirmButton(int mx, int my, int button) -{ - int return_code = 0; - static int choice = -1; - static boolean pressed = FALSE; - - if (button) - { - if (!motion_status) /* Maustaste neu gedrückt */ - { - if (ON_CONFIRM_BUTTON(mx,my)) - { - choice = 0; - pressed = TRUE; - DrawConfirmButton(BUTTON_PRESSED, DB_NORMAL); - } - } - else /* Mausbewegung bei gedrückter Maustaste */ - { - if (!ON_CONFIRM_BUTTON(mx,my) && choice>=0 && pressed) - { - pressed = FALSE; - DrawConfirmButton(BUTTON_RELEASED, DB_NORMAL); - } - else if (ON_CONFIRM_BUTTON(mx,my) && !pressed) - { - pressed = TRUE; - DrawConfirmButton(BUTTON_PRESSED, DB_NORMAL); - } - } - } - else /* Maustaste wieder losgelassen */ - { - if (ON_CONFIRM_BUTTON(mx,my) && pressed) - { - DrawConfirmButton(BUTTON_RELEASED, DB_NORMAL); - return_code = BUTTON_CONFIRM; - choice = -1; - pressed = FALSE; - } - else - { - choice = -1; - pressed = FALSE; - } - } - - BackToFront(); - return(return_code); -} - -int CheckPlayerButtons(int mx, int my, int button) -{ - int return_code = 0; - static int choice = -1; - static boolean pressed = FALSE; - int player_state[4] = - { - BUTTON_PLAYER_1, - BUTTON_PLAYER_2, - BUTTON_PLAYER_3, - BUTTON_PLAYER_4 - }; - - if (button) - { - if (!motion_status) /* Maustaste neu gedrückt */ - { - if (ON_PLAYER_BUTTON(mx,my)) - { - choice = PLAYER_BUTTON(mx,my); - pressed = TRUE; - DrawPlayerButton(player_state[choice] | BUTTON_PRESSED, DB_NORMAL); - } - } - else /* Mausbewegung bei gedrückter Maustaste */ - { - if ((!ON_PLAYER_BUTTON(mx,my) || PLAYER_BUTTON(mx,my)!=choice) && - choice>=0 && pressed) - { - pressed = FALSE; - DrawPlayerButton(player_state[choice] | BUTTON_RELEASED, DB_NORMAL); - } - else if (ON_PLAYER_BUTTON(mx,my) && PLAYER_BUTTON(mx,my)==choice && !pressed) - { - pressed = TRUE; - DrawPlayerButton(player_state[choice] | BUTTON_PRESSED, DB_NORMAL); - } - } - } - else /* Maustaste wieder losgelassen */ - { - if (ON_PLAYER_BUTTON(mx,my) && PLAYER_BUTTON(mx,my)==choice && pressed) - { - DrawPlayerButton(player_state[choice] | BUTTON_RELEASED, DB_NORMAL); - return_code = player_state[choice]; - choice = -1; - pressed = FALSE; - } - else - { - choice = -1; - pressed = FALSE; - } - } - - BackToFront(); - return(return_code); -} - -/* several buttons in the level editor */ - -int CheckEditButtons(int mx, int my, int button) -{ - int return_code = 0; - static int choice = -1; - static boolean pressed = FALSE; - static int edit_button[6] = - { - ED_BUTTON_CTRL, - ED_BUTTON_FILL, - ED_BUTTON_LEFT, - ED_BUTTON_UP, - ED_BUTTON_DOWN, - ED_BUTTON_RIGHT - }; - - if (button) - { - if (!motion_status) /* Maustaste neu gedrückt */ - { - if (ON_EDIT_BUTTON(mx,my)) - { - choice = EDIT_BUTTON(mx,my); - pressed = TRUE; - DrawEditButton(edit_button[choice] | ED_BUTTON_PRESSED); - if (edit_button[choice]!=ED_BUTTON_CTRL && - edit_button[choice]!=ED_BUTTON_FILL) - return_code = 1<=0 && pressed) - { - pressed = FALSE; - DrawEditButton(edit_button[choice] | ED_BUTTON_RELEASED); - } - else if (ON_EDIT_BUTTON(mx,my) && EDIT_BUTTON(mx,my)==choice) - { - if (!pressed) - DrawEditButton(edit_button[choice] | ED_BUTTON_PRESSED); - pressed = TRUE; - if (edit_button[choice]!=ED_BUTTON_CTRL && - edit_button[choice]!=ED_BUTTON_FILL) - return_code = 1<=0 && pressed) - { - pressed = FALSE; - DrawCtrlButton(ctrl_button[choice] | ED_BUTTON_RELEASED); - } - else if (ON_CTRL_BUTTON(mx,my) && CTRL_BUTTON(mx,my)==choice && !pressed) - { - pressed = TRUE; - DrawCtrlButton(ctrl_button[choice] | ED_BUTTON_PRESSED); - } - } - } - else /* Maustaste wieder losgelassen */ - { - if (ON_CTRL_BUTTON(mx,my) && CTRL_BUTTON(mx,my)==choice && pressed) - { - DrawCtrlButton(ctrl_button[choice] | ED_BUTTON_RELEASED); - return_code = 1<<(choice+6); - choice = -1; - pressed = FALSE; - } - else - { - choice = -1; - pressed = FALSE; - } - } - - BackToFront(); - return(return_code); -} - -int CheckElemButtons(int mx, int my, int button) -{ - int return_code = -1; - static int choice = -1; - static boolean pressed = FALSE; - - if (button) - { - if (!motion_status) /* Maustaste neu gedrückt */ - { - if (ON_ELEM_BUTTON(mx,my)) - { - choice = ELEM_BUTTON(mx,my); - pressed = TRUE; - DrawElemButton(choice,ED_BUTTON_PRESSED); - if (choice==ED_BUTTON_EUP || - choice==ED_BUTTON_EDOWN) - return_code = choice; - } - } - else /* Mausbewegung bei gedrückter Maustaste */ - { - if ((!ON_ELEM_BUTTON(mx,my) || ELEM_BUTTON(mx,my)!=choice) && - choice>=0 && pressed) - { - pressed = FALSE; - DrawElemButton(choice,ED_BUTTON_RELEASED); - } - else if (ON_ELEM_BUTTON(mx,my) && ELEM_BUTTON(mx,my)==choice) - { - if (!pressed) - DrawElemButton(choice,ED_BUTTON_PRESSED); - pressed = TRUE; - if (choice==ED_BUTTON_EUP || - choice==ED_BUTTON_EDOWN) - return_code = choice; - } - } - } - else /* Maustaste wieder losgelassen */ - { - if (ON_ELEM_BUTTON(mx,my) && ELEM_BUTTON(mx,my)==choice && pressed) - { - DrawElemButton(choice,ED_BUTTON_RELEASED); - if (choice!=ED_BUTTON_EUP && - choice!=ED_BUTTON_EDOWN) - return_code = choice; - choice = -1; - pressed = FALSE; - } - else - { - choice = -1; - pressed = FALSE; - } - } - - BackToFront(); - return(return_code); -} - -int CheckCountButtons(int mx, int my, int button) -{ - int return_code = -1; - static int choice = -1; - static boolean pressed = FALSE; - - if (button) - { - if (!motion_status) /* Maustaste neu gedrückt */ - { - if (ON_COUNT_BUTTON(mx,my)) - { - choice = COUNT_BUTTON(mx,my); - pressed = TRUE; - DrawCountButton(choice,ED_BUTTON_PRESSED); - return_code = choice; - } - } - else /* Mausbewegung bei gedrückter Maustaste */ - { - if ((!ON_COUNT_BUTTON(mx,my) || COUNT_BUTTON(mx,my)!=choice) && - choice>=0 && pressed) - { - pressed = FALSE; - DrawCountButton(choice,ED_BUTTON_RELEASED); - } - else if (ON_COUNT_BUTTON(mx,my) && COUNT_BUTTON(mx,my)==choice) - { - if (!pressed) - DrawCountButton(choice,ED_BUTTON_PRESSED); - pressed = TRUE; - return_code = choice; - } - } - } - else /* Maustaste wieder losgelassen */ - { - if (ON_COUNT_BUTTON(mx,my) && COUNT_BUTTON(mx,my)==choice && pressed) - { - DrawCountButton(choice,ED_BUTTON_RELEASED); - choice = -1; - pressed = FALSE; - } - else - { - choice = -1; - pressed = FALSE; - } - } - - BackToFront(); - return(return_code); -} - /* NEW GADGET STUFF -------------------------------------------------------- */ diff --git a/src/buttons.h b/src/buttons.h index fcd23247..b5bb5ec3 100644 --- a/src/buttons.h +++ b/src/buttons.h @@ -250,25 +250,6 @@ void DrawVideoDisplay(unsigned long, unsigned long); void DrawCompleteVideoDisplay(void); -void DrawSoundDisplay(unsigned long); -void DrawGameButton(unsigned long); -void DrawYesNoButton(unsigned long, int); -void DrawConfirmButton(unsigned long, int); -void DrawPlayerButton(unsigned long, int); -void DrawEditButton(unsigned long state); -void DrawCtrlButton(unsigned long state); -void DrawElemButton(int, int); -void DrawCountButton(int, int); -int CheckVideoButtons(int, int, int); -int CheckSoundButtons(int, int, int); -int CheckGameButtons(int, int, int); -int CheckYesNoButtons(int, int, int); -int CheckConfirmButton(int, int, int); -int CheckPlayerButtons(int, int, int); -int CheckEditButtons(int, int, int); -int CheckCtrlButtons(int, int, int); -int CheckElemButtons(int, int, int); -int CheckCountButtons(int, int, int); /* NEW GADGET STUFF -------------------------------------------------------- */ diff --git a/src/events.c b/src/events.c index 61d1fc8d..8a03effd 100644 --- a/src/events.c +++ b/src/events.c @@ -334,12 +334,6 @@ void HandleButton(int mx, int my, int button) { old_mx = mx; old_my = my; - - /* - HandleVideoButtons(mx,my, button); - HandleSoundButtons(mx,my, button); - HandleGameButtons(mx,my, button); - */ } HandleGadgets(mx, my, button); diff --git a/src/files.c b/src/files.c index 2ef526dd..e48a0991 100644 --- a/src/files.c +++ b/src/files.c @@ -275,27 +275,6 @@ static void InitUserLevelDirectory(char *level_subdir) } } -static void getFileChunk(FILE *file, char *chunk_buffer, int *chunk_length) -{ - fgets(chunk_buffer, CHUNK_ID_LEN + 1, file); - - *chunk_length = - (fgetc(file) << 24) | - (fgetc(file) << 16) | - (fgetc(file) << 8) | - (fgetc(file) << 0); -} - -static void putFileChunk(FILE *file, char *chunk_name, int chunk_length) -{ - fputs(chunk_name, file); - - fputc((chunk_length >> 24) & 0xff, file); - fputc((chunk_length >> 16) & 0xff, file); - fputc((chunk_length >> 8) & 0xff, file); - fputc((chunk_length >> 0) & 0xff, file); -} - static void setLevelInfoToDefaults() { int i, x, y; @@ -406,7 +385,7 @@ void LoadLevel(int level_nr) /* read chunk "HEAD" */ if (file_version >= FILE_VERSION_1_2) { - getFileChunk(file, chunk, &chunk_length); + getFileChunk(file, chunk, &chunk_length, BYTE_ORDER_BIG_ENDIAN); if (strcmp(chunk, "HEAD") || chunk_length != LEVEL_HEADER_SIZE) { Error(ERR_WARN, "wrong 'HEAD' chunk of level file '%s'", filename); @@ -456,7 +435,7 @@ void LoadLevel(int level_nr) /* read chunk "BODY" */ if (file_version >= FILE_VERSION_1_2) { - getFileChunk(file, chunk, &chunk_length); + getFileChunk(file, chunk, &chunk_length, BYTE_ORDER_BIG_ENDIAN); /* look for optional author chunk */ if (strcmp(chunk, "AUTH") == 0 && chunk_length == MAX_LEVEL_AUTHOR_LEN) @@ -465,7 +444,7 @@ void LoadLevel(int level_nr) level.author[i] = fgetc(file); level.author[MAX_LEVEL_NAME_LEN] = 0; - getFileChunk(file, chunk, &chunk_length); + getFileChunk(file, chunk, &chunk_length, BYTE_ORDER_BIG_ENDIAN); } /* look for optional content chunk */ @@ -481,7 +460,7 @@ void LoadLevel(int level_nr) for(x=0; x<3; x++) level.mampfer_inhalt[i][x][y] = fgetc(file); - getFileChunk(file, chunk, &chunk_length); + getFileChunk(file, chunk, &chunk_length, BYTE_ORDER_BIG_ENDIAN); } /* next check body chunk identifier and chunk length */ @@ -530,7 +509,7 @@ void SaveLevel(int level_nr) fputs(LEVEL_COOKIE, file); /* file identifier */ fputc('\n', file); - putFileChunk(file, "HEAD", LEVEL_HEADER_SIZE); + putFileChunk(file, "HEAD", LEVEL_HEADER_SIZE, BYTE_ORDER_BIG_ENDIAN); fputc(level.fieldx, file); fputc(level.fieldy, file); @@ -557,12 +536,12 @@ void SaveLevel(int level_nr) for(i=0; i> 24) & 0xff, file); + fputc((chunk_length >> 16) & 0xff, file); + fputc((chunk_length >> 8) & 0xff, file); + fputc((chunk_length >> 0) & 0xff, file); + } + else /* BYTE_ORDER_LITTLE_ENDIAN */ + { + fputc((chunk_length >> 0) & 0xff, file); + fputc((chunk_length >> 8) & 0xff, file); + fputc((chunk_length >> 16) & 0xff, file); + fputc((chunk_length >> 24) & 0xff, file); + } +} + #define TRANSLATE_KEYSYM_TO_KEYNAME 0 #define TRANSLATE_KEYSYM_TO_X11KEYNAME 1 #define TRANSLATE_X11KEYNAME_TO_KEYSYM 2 diff --git a/src/misc.h b/src/misc.h index 9793cb73..004b7e43 100644 --- a/src/misc.h +++ b/src/misc.h @@ -16,23 +16,30 @@ #include "main.h" -#define INIT_COUNTER 0 -#define READ_COUNTER 1 +/* values for InitCounter() and Counter() */ +#define INIT_COUNTER 0 +#define READ_COUNTER 1 -#define NEW_RANDOMIZE -1 +/* values for InitRND() */ +#define NEW_RANDOMIZE -1 -#define ERR_RETURN 0 -#define ERR_WARN (1 << 0) -#define ERR_EXIT (1 << 1) -#define ERR_HELP (1 << 2) -#define ERR_SOUND_SERVER (1 << 3) -#define ERR_NETWORK_SERVER (1 << 4) -#define ERR_NETWORK_CLIENT (1 << 5) -#define ERR_FROM_SERVER (ERR_SOUND_SERVER | ERR_NETWORK_SERVER) -#define ERR_EXIT_HELP (ERR_EXIT | ERR_HELP) -#define ERR_EXIT_SOUND_SERVER (ERR_EXIT | ERR_SOUND_SERVER) -#define ERR_EXIT_NETWORK_SERVER (ERR_EXIT | ERR_NETWORK_SERVER) -#define ERR_EXIT_NETWORK_CLIENT (ERR_EXIT | ERR_NETWORK_CLIENT) +/* values for Error() */ +#define ERR_RETURN 0 +#define ERR_WARN (1 << 0) +#define ERR_EXIT (1 << 1) +#define ERR_HELP (1 << 2) +#define ERR_SOUND_SERVER (1 << 3) +#define ERR_NETWORK_SERVER (1 << 4) +#define ERR_NETWORK_CLIENT (1 << 5) +#define ERR_FROM_SERVER (ERR_SOUND_SERVER | ERR_NETWORK_SERVER) +#define ERR_EXIT_HELP (ERR_EXIT | ERR_HELP) +#define ERR_EXIT_SOUND_SERVER (ERR_EXIT | ERR_SOUND_SERVER) +#define ERR_EXIT_NETWORK_SERVER (ERR_EXIT | ERR_NETWORK_SERVER) +#define ERR_EXIT_NETWORK_CLIENT (ERR_EXIT | ERR_NETWORK_CLIENT) + +/* values for getFileChunk() and putFileChunk() */ +#define BYTE_ORDER_BIG_ENDIAN 0 +#define BYTE_ORDER_LITTLE_ENDIAN 1 void InitCounter(void); unsigned long Counter(void); @@ -57,6 +64,8 @@ void GetOptions(char **); void Error(int, char *, ...); void *checked_malloc(unsigned long); void *checked_calloc(unsigned long); +void getFileChunk(FILE *, char *, int *, int); +void putFileChunk(FILE *, char *, int, int); char *getKeyNameFromKeySym(KeySym); char *getX11KeyNameFromKeySym(KeySym); KeySym getKeySymFromX11KeyName(char *); diff --git a/src/screens.c b/src/screens.c index a27dcba8..3bf0c300 100644 --- a/src/screens.c +++ b/src/screens.c @@ -1928,186 +1928,6 @@ void CalibrateJoystick(int player_nr) DrawSetupInputScreen(); } - - -#if 0 - -void CalibrateJoystick_OLD() -{ -#ifdef __FreeBSD__ - struct joystick joy_ctrl; -#else - struct joystick_control - { - int buttons; - int x; - int y; - } joy_ctrl; -#endif - -#ifdef MSDOS - char joy_nr[4]; -#endif - - int joystick_nr = setup.input[0].joystick_nr; - int new_joystick_xleft, new_joystick_xright, new_joystick_xmiddle; - int new_joystick_yupper, new_joystick_ylower, new_joystick_ymiddle; - - if (joystick_status == JOYSTICK_OFF) - goto error_out; - -#ifndef MSDOS - ClearWindow(); - DrawText(SX+16, SY+7*32, "MOVE JOYSTICK TO",FS_BIG,FC_YELLOW); - DrawText(SX+16, SY+8*32, " THE UPPER LEFT ",FS_BIG,FC_YELLOW); - DrawText(SX+16, SY+9*32, "AND PRESS BUTTON",FS_BIG,FC_YELLOW); - BackToFront(); - -#ifdef __FreeBSD__ - joy_ctrl.b1 = joy_ctrl.b2 = 0; -#else - joy_ctrl.buttons = 0; -#endif - while(Joystick() & JOY_BUTTON); -#ifdef __FreeBSD__ - while(!(joy_ctrl.b1 || joy_ctrl.b2)) -#else - while(!joy_ctrl.buttons) -#endif - { - if (read(joystick_device, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl)) - { - joystick_status=JOYSTICK_OFF; - goto error_out; - } - Delay(10); - } - - new_joystick_xleft = joy_ctrl.x; - new_joystick_yupper = joy_ctrl.y; - - ClearWindow(); - DrawText(SX+16, SY+7*32, "MOVE JOYSTICK TO",FS_BIG,FC_YELLOW); - DrawText(SX+32, SY+8*32, "THE LOWER RIGHT",FS_BIG,FC_YELLOW); - DrawText(SX+16, SY+9*32, "AND PRESS BUTTON",FS_BIG,FC_YELLOW); - BackToFront(); - -#ifdef __FreeBSD__ - joy_ctrl.b1 = joy_ctrl.b2 = 0; -#else - joy_ctrl.buttons = 0; -#endif - while(Joystick() & JOY_BUTTON); -#ifdef __FreeBSD__ - while(!(joy_ctrl.b1 || joy_ctrl.b2)) -#else - while(!joy_ctrl.buttons) -#endif - { - if (read(joystick_device, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl)) - { - joystick_status=JOYSTICK_OFF; - goto error_out; - } - Delay(10); - } - - new_joystick_xright = joy_ctrl.x; - new_joystick_ylower = joy_ctrl.y; - - ClearWindow(); - DrawText(SX+32, SY+16+7*32, "CENTER JOYSTICK",FS_BIG,FC_YELLOW); - DrawText(SX+16, SY+16+8*32, "AND PRESS BUTTON",FS_BIG,FC_YELLOW); - BackToFront(); - -#ifdef __FreeBSD__ - joy_ctrl.b1 = joy_ctrl.b2 = 0; -#else - joy_ctrl.buttons = 0; -#endif - while(Joystick() & JOY_BUTTON); -#ifdef __FreeBSD__ - while(!(joy_ctrl.b1 || joy_ctrl.b2)) -#else - while(!joy_ctrl.buttons) -#endif - { - if (read(joystick_device, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl)) - { - joystick_status=JOYSTICK_OFF; - goto error_out; - } - Delay(10); - } - - new_joystick_xmiddle = joy_ctrl.x; - new_joystick_ymiddle = joy_ctrl.y; - - setup.input[player_nr].joy.xleft = new_joystick_xleft; - setup.input[player_nr].joy.yupper = new_joystick_yupper; - setup.input[player_nr].joy.xright = new_joystick_xright; - setup.input[player_nr].joy.ylower = new_joystick_ylower; - setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle; - setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle; - - CheckJoystickData(); - - DrawSetupScreen(); - while(Joystick() & JOY_BUTTON); - return; - -#endif - error_out: - -#ifdef MSDOS - joy_nr[0] = '#'; - joy_nr[1] = SETUP_2ND_JOYSTICK_ON(local_player->setup)+49; - joy_nr[2] = '\0'; - - remove_joystick(); - ClearWindow(); - DrawText(SX+32, SY+7*32, "CENTER JOYSTICK",FS_BIG,FC_YELLOW); - DrawText(SX+16+7*32, SY+8*32, joy_nr, FS_BIG,FC_YELLOW); - DrawText(SX+32, SY+9*32, "AND PRESS A KEY",FS_BIG,FC_YELLOW); - BackToFront(); - - for(clear_keybuf();!keypressed();); - install_joystick(JOY_TYPE_2PADS); - - ClearWindow(); - DrawText(SX+16, SY+7*32, "MOVE JOYSTICK TO",FS_BIG,FC_YELLOW); - DrawText(SX+16, SY+8*32, " THE UPPER LEFT ",FS_BIG,FC_YELLOW); - DrawText(SX+32, SY+9*32, "AND PRESS A KEY",FS_BIG,FC_YELLOW); - BackToFront(); - - for(clear_keybuf();!keypressed();); - calibrate_joystick(SETUP_2ND_JOYSTICK_ON(local_player->setup)); - - ClearWindow(); - DrawText(SX+16, SY+7*32, "MOVE JOYSTICK TO",FS_BIG,FC_YELLOW); - DrawText(SX+32, SY+8*32, "THE LOWER RIGHT",FS_BIG,FC_YELLOW); - DrawText(SX+32, SY+9*32, "AND PRESS A KEY",FS_BIG,FC_YELLOW); - BackToFront(); - - for(clear_keybuf();!keypressed();); - calibrate_joystick(SETUP_2ND_JOYSTICK_ON(local_player->setup)); - - DrawSetupScreen(); - return; -#endif - - ClearWindow(); - DrawText(SX+16, SY+16, "NO JOYSTICK",FS_BIG,FC_YELLOW); - DrawText(SX+16, SY+48, " AVAILABLE ",FS_BIG,FC_YELLOW); - BackToFront(); - Delay(3000); - DrawSetupScreen(); -} - -#endif - - - void HandleGameActions() { if (game_status != PLAYING) @@ -2123,256 +1943,3 @@ void HandleGameActions() BackToFront(); } - -void HandleVideoButtons(int mx, int my, int button) -{ - return; - - - - - if (game_status != MAINMENU && game_status != PLAYING) - return; - - switch(CheckVideoButtons(mx,my,button)) - { - case BUTTON_VIDEO_EJECT: - TapeStop(); - if (TAPE_IS_EMPTY(tape)) - { - LoadTape(level_nr); - if (TAPE_IS_EMPTY(tape)) - Request("No tape for this level !",REQ_CONFIRM); - } - else - { - if (tape.changed) - SaveTape(tape.level_nr); - TapeErase(); - } - DrawCompleteVideoDisplay(); - break; - - case BUTTON_VIDEO_STOP: - TapeStop(); - break; - - case BUTTON_VIDEO_PAUSE: - TapeTogglePause(); - break; - - case BUTTON_VIDEO_REC: - if (TAPE_IS_STOPPED(tape)) - { - TapeStartRecording(); - -#ifndef MSDOS - if (options.network) - SendToServer_StartPlaying(); - else -#endif - { - game_status = PLAYING; - InitGame(); - } - } - else if (tape.pausing) - { - if (tape.playing) /* PLAYING -> PAUSING -> RECORDING */ - { - tape.pos[tape.counter].delay = tape.delay_played; - tape.playing = FALSE; - tape.recording = TRUE; - tape.changed = TRUE; - - DrawVideoDisplay(VIDEO_STATE_PLAY_OFF | VIDEO_STATE_REC_ON,0); - } - else - TapeTogglePause(); - } - break; - - case BUTTON_VIDEO_PLAY: - if (TAPE_IS_EMPTY(tape)) - break; - - if (TAPE_IS_STOPPED(tape)) - { - TapeStartPlaying(); - - game_status = PLAYING; - InitGame(); - } - else if (tape.playing) - { - if (tape.pausing) /* PAUSE -> PLAY */ - TapeTogglePause(); - else if (!tape.fast_forward) /* PLAY -> FAST FORWARD PLAY */ - { - tape.fast_forward = TRUE; - DrawVideoDisplay(VIDEO_STATE_FFWD_ON, 0); - } - else if (!tape.pause_before_death) /* FFWD PLAY -> + AUTO PAUSE */ - { - tape.pause_before_death = TRUE; - DrawVideoDisplay(VIDEO_STATE_PBEND_ON, VIDEO_DISPLAY_LABEL_ONLY); - } - else /* -> NORMAL PLAY */ - { - tape.fast_forward = FALSE; - tape.pause_before_death = FALSE; - DrawVideoDisplay(VIDEO_STATE_FFWD_OFF | VIDEO_STATE_PBEND_OFF, 0); - } - } - break; - - default: - break; - } - - BackToFront(); -} - -void HandleSoundButtons(int mx, int my, int button) -{ - - - - return; - - - - if (game_status != PLAYING) - return; - - switch(CheckSoundButtons(mx,my,button)) - { - case BUTTON_SOUND_MUSIC: - if (setup.sound_music) - { - setup.sound_music = FALSE; - FadeSound(background_loop[level_nr % num_bg_loops]); - DrawSoundDisplay(BUTTON_SOUND_MUSIC_OFF); - } - else if (sound_loops_allowed) - { - setup.sound = setup.sound_music = TRUE; - PlaySoundLoop(background_loop[level_nr % num_bg_loops]); - DrawSoundDisplay(BUTTON_SOUND_MUSIC_ON); - } - else - DrawSoundDisplay(BUTTON_SOUND_MUSIC_OFF); - break; - - case BUTTON_SOUND_LOOPS: - if (setup.sound_loops) - { - setup.sound_loops = FALSE; - DrawSoundDisplay(BUTTON_SOUND_LOOPS_OFF); - } - else if (sound_loops_allowed) - { - setup.sound = setup.sound_loops = TRUE; - DrawSoundDisplay(BUTTON_SOUND_LOOPS_ON); - } - else - DrawSoundDisplay(BUTTON_SOUND_LOOPS_OFF); - break; - - case BUTTON_SOUND_SIMPLE: - if (setup.sound_simple) - { - setup.sound_simple = FALSE; - DrawSoundDisplay(BUTTON_SOUND_SIMPLE_OFF); - } - else if (sound_status==SOUND_AVAILABLE) - { - setup.sound = setup.sound_simple = TRUE; - DrawSoundDisplay(BUTTON_SOUND_SIMPLE_ON); - } - else - DrawSoundDisplay(BUTTON_SOUND_SIMPLE_OFF); - break; - - default: - break; - } - - BackToFront(); -} - -void HandleGameButtons(int mx, int my, int button) -{ - - - - return; - - - - if (game_status != PLAYING) - return; - - switch(CheckGameButtons(mx,my,button)) - { - case BUTTON_GAME_STOP: - if (AllPlayersGone) - { - CloseDoor(DOOR_CLOSE_1); - game_status = MAINMENU; - DrawMainMenu(); - break; - } - - if (Request("Do you really want to quit the game ?", - REQ_ASK | REQ_STAY_CLOSED)) - { -#ifndef MSDOS - if (options.network) - SendToServer_StopPlaying(); - else -#endif - { - game_status = MAINMENU; - DrawMainMenu(); - } - } - else - OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK); - break; - - case BUTTON_GAME_PAUSE: - if (options.network) - { -#ifndef MSDOS - if (tape.pausing) - SendToServer_ContinuePlaying(); - else - SendToServer_PausePlaying(); -#endif - } - else - TapeTogglePause(); - break; - - case BUTTON_GAME_PLAY: - if (tape.pausing) - { -#ifndef MSDOS - if (options.network) - SendToServer_ContinuePlaying(); - else -#endif - { - tape.pausing = FALSE; - DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0); - } - } - break; - - default: - break; - } - - BackToFront(); -} diff --git a/src/sound.c b/src/sound.c index 51a75c88..928a955c 100644 --- a/src/sound.c +++ b/src/sound.c @@ -708,28 +708,17 @@ static int ulaw_to_linear(unsigned char ulawbyte) /*** THE STUFF BELOW IS ONLY USED BY THE MAIN PROCESS ***/ -#ifndef MSDOS -static unsigned long be2long(unsigned long *be) /* big-endian -> longword */ -{ - unsigned char *ptr = (unsigned char *)be; - - return(ptr[0]<<24 | ptr[1]<<16 | ptr[2]<<8 | ptr[3]); -} - -static unsigned long le2long(unsigned long *be) /* little-endian -> longword */ -{ - unsigned char *ptr = (unsigned char *)be; - - return(ptr[3]<<24 | ptr[2]<<16 | ptr[1]<<8 | ptr[0]); -} -#endif /* !MSDOS */ +#define CHUNK_ID_LEN 4 /* IFF style chunk id length */ +#define WAV_HEADER_SIZE 20 /* size of WAV file header */ boolean LoadSound(struct SoundInfo *snd_info) { char filename[256]; char *sound_ext = "wav"; #ifndef MSDOS - struct SoundHeader_WAV *sound_header; + byte sound_header_buffer[WAV_HEADER_SIZE]; + char chunk[CHUNK_ID_LEN + 1]; + int chunk_length, dummy; FILE *file; int i; #endif @@ -742,166 +731,69 @@ boolean LoadSound(struct SoundInfo *snd_info) if ((file = fopen(filename, "r")) == NULL) { Error(ERR_WARN, "cannot open sound file '%s' - no sounds", filename); - return(FALSE); + return FALSE; } - if (fseek(file, 0, SEEK_END) < 0) + /* read chunk "RIFF" */ + getFileChunk(file, chunk, &chunk_length, BYTE_ORDER_LITTLE_ENDIAN); + if (strcmp(chunk, "RIFF") != 0) { - Error(ERR_WARN, "cannot read sound file '%s' - no sounds", filename); + Error(ERR_WARN, "missing 'RIFF' chunk of sound file '%s'", filename); fclose(file); - return(FALSE); + return FALSE; } - snd_info->file_len = ftell(file); - rewind(file); - - snd_info->file_ptr = checked_malloc(snd_info->file_len); - - if (fread(snd_info->file_ptr, 1, snd_info->file_len, file) != - snd_info->file_len) + /* read chunk "WAVE" */ + getFileChunk(file, chunk, &dummy, BYTE_ORDER_LITTLE_ENDIAN); + if (strcmp(chunk, "WAVE") != 0) { - Error(ERR_WARN, "cannot read sound file '%s' - no sounds", filename); + Error(ERR_WARN, "missing 'WAVE' chunk of sound file '%s'", filename); fclose(file); - return(FALSE); - } - - fclose(file); - - sound_header = (struct SoundHeader_WAV *)snd_info->file_ptr; - - if (strncmp(sound_header->magic_RIFF, "RIFF", 4) || - snd_info->file_len != le2long(&sound_header->header_size) + 8 || - strncmp(sound_header->magic_WAVE, "WAVE", 4) || - strncmp(sound_header->magic_DATA, "data", 4) || - snd_info->file_len != le2long(&sound_header->data_size) + 44) - { - Error(ERR_WARN, "'%s' is not a RIFF/WAVE file or broken - no sounds", - filename); - return(FALSE); + return FALSE; } - snd_info->data_ptr = snd_info->file_ptr + 44; - snd_info->data_len = le2long(&sound_header->data_size); - - for (i=0; idata_len; i++) - snd_info->data_ptr[i] = snd_info->data_ptr[i]^0x80; - -#else /* MSDOS */ - - snd_info->sample_ptr = load_sample(filename); - if (!snd_info->sample_ptr) - { - Error(ERR_WARN, "cannot read sound file '%s' - no sounds", filename); - return(FALSE); - } - -#endif /* MSDOS */ - - return(TRUE); -} - -boolean LoadSound_8SVX(struct SoundInfo *snd_info) -{ - char filename[256]; -#ifndef MSDOS - struct SoundHeader_8SVX *sound_header; - FILE *file; - char *ptr; - char *sound_ext = "8svx"; -#else - char *sound_ext = "wav"; -#endif - - sprintf(filename, "%s/%s/%s.%s", - options.base_directory, SOUNDS_DIRECTORY, snd_info->name, sound_ext); - -#ifndef MSDOS - if (!(file=fopen(filename,"r"))) - { - Error(ERR_WARN, "cannot open sound file '%s' - no sounds", filename); - return(FALSE); - } + /* read header information */ + for (i=0; ifile_len = ftell(file); - rewind(file); - - if (!(snd_info->file_ptr=malloc(snd_info->file_len))) - { - Error(ERR_WARN, "out of memory (this shouldn't happen :) - no sounds"); - fclose(file); - return(FALSE); - } + snd_info->data_len = chunk_length; + snd_info->data_ptr = checked_malloc(snd_info->data_len); - if (fread(snd_info->file_ptr,1,snd_info->file_len,file)!=snd_info->file_len) + /* read sound data */ + if (fread(snd_info->data_ptr, 1, snd_info->data_len, file) != + snd_info->data_len) { Error(ERR_WARN, "cannot read sound file '%s' - no sounds", filename); fclose(file); - return(FALSE); + return FALSE; } fclose(file); - sound_header = (struct SoundHeader_8SVX *)snd_info->file_ptr; - - if (strncmp(sound_header->magic_FORM,"FORM",4) || - snd_info->file_len != be2long(&sound_header->chunk_size)+8 || - strncmp(sound_header->magic_8SVX,"8SVX",4)) - { - Error(ERR_WARN, "'%s' is not an IFF/8SVX file or broken - no sounds", - filename); - return(FALSE); - } - - ptr = (char *)snd_info->file_ptr + 12; - - while(ptr < (char *)(snd_info->file_ptr + snd_info->file_len)) - { - if (!strncmp(ptr,"VHDR",4)) - { - ptr += be2long((unsigned long *)(ptr + 4)) + 8; - continue; - } - else if (!strncmp(ptr,"ANNO",4)) - { - ptr += be2long((unsigned long *)(ptr + 4)) + 8; - continue; - } - else if (!strncmp(ptr,"CHAN",4)) - { - ptr += be2long((unsigned long *)(ptr + 4)) + 8; - continue; - } - else if (!strncmp(ptr,"BODY",4)) - { - snd_info->data_ptr = (byte *)ptr + 8; - snd_info->data_len = be2long((unsigned long *)(ptr + 4)); - return(TRUE); - } - else - { - /* other chunk not recognized here */ - ptr += be2long((unsigned long *)(ptr + 4)) + 8; - continue; - } - } + for (i=0; idata_len; i++) + snd_info->data_ptr[i] = snd_info->data_ptr[i] ^ 0x80; - return(FALSE); #else /* MSDOS */ + snd_info->sample_ptr = load_sample(filename); - if(!snd_info->sample_ptr) + if (!snd_info->sample_ptr) { Error(ERR_WARN, "cannot read sound file '%s' - no sounds", filename); return(FALSE); } - return(TRUE); + #endif /* MSDOS */ + + return(TRUE); } void PlaySound(int nr) @@ -1006,16 +898,16 @@ void StopSoundExt(int nr, int method) #endif } -void FreeSounds(int max) +void FreeSounds(int num_sounds) { int i; - if (sound_status==SOUND_OFF) + if (sound_status == SOUND_OFF) return; - for(i=0;i