diff --git a/src/constants.h b/src/constants.h index c5a9716..85bffe1 100644 --- a/src/constants.h +++ b/src/constants.h @@ -95,6 +95,7 @@ #define GAME_STOP 0x00 #define GAME_RUN 0x01 #define GAME_MENU 0x02 +#define GAME_SETTINGS 0x03 #define PLAYER_HUMAN 0x00 #define PLAYER_CPU 0x01 diff --git a/src/game.c b/src/game.c index 8317e85..d5913ea 100644 --- a/src/game.c +++ b/src/game.c @@ -37,6 +37,7 @@ uint8_t board_offset_x = 6; uint8_t board_offset_y = 4; uint8_t no_move_counter = 0; uint16_t cpu_waittime = 200; +uint8_t background_scroll = YES; /** * @brief Initialize the game scene diff --git a/src/game.h b/src/game.h index 56f3b6f..5f9e1d2 100644 --- a/src/game.h +++ b/src/game.h @@ -31,6 +31,7 @@ #include "constants.h" #include "video.h" #include "sound.h" +#include "sound_low.h" #include "mouse.h" extern uint8_t *board; // store board configuration @@ -50,6 +51,7 @@ extern uint8_t board_offset_x; // board x-offset with respect to screen extern uint8_t board_offset_y; // board y-offset with respect to screen extern uint8_t no_move_counter; // how many turns in a row no move can be made extern uint16_t cpu_waittime; // time to wait until the computer makes a move +extern uint8_t background_scroll; // whether or not to perform background scrolling /** * @brief Initialize the game scene diff --git a/src/main.c b/src/main.c index 8eef179..d4c6b85 100644 --- a/src/main.c +++ b/src/main.c @@ -46,7 +46,12 @@ void main() { while(1) { while(gamestate == GAME_MENU) { clear_screen(); - game_menu(); + game_title(); + } + + while(gamestate == GAME_SETTINGS) { + clear_screen(); + game_settings(); } while(gamestate == GAME_RUN) { diff --git a/src/menu.c b/src/menu.c index f63fcc7..48eabc8 100644 --- a/src/menu.c +++ b/src/menu.c @@ -20,29 +20,81 @@ #include "menu.h" +/** + * @brief Show game title screen + * + */ +void game_title() { + static unsigned char keycode; + static const uint8_t offsetx = 8; + + write_string("CX16-OTHELLO", 0, 0); + write_string("music by Crisps", 1, 5); + write_string("1.2.0", 0, 15); + + // build sample board + build_board(6, 4, offsetx); + + // set sprites + assign_sprite(1, stone_color1); + assign_sprite(2, stone_color2); + assign_sprite(3, stone_color1); + assign_sprite(4, stone_color2); + + // print stone colors + set_sprite(1, 6, offsetx+2); + set_sprite(2, 6, offsetx+3); + set_sprite(3, 7, offsetx+3); + set_sprite(4, 7, offsetx+2); + + write_string("(S) SETTINGS", 11, 0); + write_string("(H) HELP", 12, 0); + write_string("(ENTER) START", 14, 0); + + while(1) { + asm("jsr $FFE4"); + asm("sta %v", keycode); + + switch(keycode) { + case 83: + gamestate = GAME_SETTINGS; + return; + case KEYCODE_RETURN: + gamestate = GAME_RUN; + init_game(); + return; + } + + // update sound buffer + sound_fill_buffers(); + update_background_diagonal(); + } +} + /** * @brief Show game menu * */ -void game_menu() { +void game_settings() { static unsigned char keycode; unsigned short *mouse_x = (unsigned short *)0x2; unsigned short *mouse_y = (unsigned short *)0x4; - write_string("CX16-OTHELLO", 0, 1); - write_string("music by Crisps", 1, 5); - write_string("1.1.0", 0, 15); + write_string("SETTINGS", 0, 0); + + write_string("(1) Player 1:", 1, 0); + write_string("(2) Player 2:", 2, 0); + write_string("(B) Board:", 4, 0); - write_string("(1) PLAYER 1:", 3, 1); - write_string("(2) PLAYER 2:", 4, 1); - write_string("(B) BOARD:", 6, 1); + write_string("(S) Size:", 6, 0); - write_string("(S) SIZE:", 8, 1); + write_string("(C) Disc player 1:", 9, 0); + write_string("(V) Disc player 2:", 10, 0); - write_string("(C) TILE COLOR 1:", 11, 1); - write_string("(V) TILE COLOR 2:", 12, 1); + write_string("(G) BG scroll:", 12, 0); + write_string("(M) Music:", 13, 0); - write_string("Hit ENTER to start", 14, 1); + write_string("(ESCAPE) BACK", 14, 0); print_choice(); @@ -63,6 +115,19 @@ void game_menu() { board_type = (board_type == BOARD_STONE ? BOARD_WOOD : BOARD_STONE); print_choice(); break; + case 71: + background_scroll = (background_scroll == YES ? NO : YES); + print_choice(); + break; + case 77: + music = (music == YES ? NO : YES); + if(music == YES) { + start_bgmusic(); + } else { + stop_bgmusic(); + } + print_choice(); + break; case 67: stone_color1++; @@ -108,9 +173,8 @@ void game_menu() { print_choice(); break; - case KEYCODE_RETURN: - gamestate = GAME_RUN; - init_game(); + case KEYCODE_ESCAPE: + gamestate = GAME_MENU; return; } @@ -129,13 +193,19 @@ void print_choice() { static const uint8_t offsetx = 12; // print whether player 1 is a human or a cpu - write_string(player1_type == PLAYER_HUMAN ? "HUMAN" : "CPU ", 3, 14); + write_string(player1_type == PLAYER_HUMAN ? "HUMAN" : "CPU ", 1, 14); // print whether player 2 is a human or a cpu - write_string(player2_type == PLAYER_HUMAN ? "HUMAN" : "CPU ", 4, 14); + write_string(player2_type == PLAYER_HUMAN ? "HUMAN" : "CPU ", 2, 14); // print board style - write_string(board_type == BOARD_STONE ? "STONE" : "WOOD ", 7, 1); + write_string(board_type == BOARD_STONE ? "STONE" : "WOOD ", 5, 1); + + // background scrolling + write_string(background_scroll == YES ? "YES" : "NO ", 12, 15); + + // music + write_string(music == YES ? "ON " : "OFF ", 13, 11); // print board size switch(boardsize) { @@ -149,10 +219,10 @@ void print_choice() { memcpy(buf, "10 x 10", 8); break; } - write_string(buf, 9, 1); + write_string(buf, 7, 1); // build sample board - build_board(4, 6, offsetx); + build_board(4, 4, offsetx); // set sprites assign_sprite(1, stone_color1); @@ -161,11 +231,11 @@ void print_choice() { assign_sprite(4, stone_color2); // print stone colors - set_sprite(1, 7, offsetx+1); - set_sprite(2, 7, offsetx+2); - set_sprite(3, 8, offsetx+2); - set_sprite(4, 8, offsetx+1); + set_sprite(1, 5, offsetx+1); + set_sprite(2, 5, offsetx+2); + set_sprite(3, 6, offsetx+2); + set_sprite(4, 6, offsetx+1); - set_tile(11, 18, stone_color1, 0x00); - set_tile(12, 18, stone_color2, 0x00); + set_tile(9, 18, stone_color1, 0x00); + set_tile(10, 18, stone_color2, 0x00); } \ No newline at end of file diff --git a/src/menu.h b/src/menu.h index 221d45b..6581d5d 100644 --- a/src/menu.h +++ b/src/menu.h @@ -30,10 +30,16 @@ #include "sound.h" /** - * @brief Show game menu + * @brief Show game settings menu * */ -void game_menu(); +void game_settings(); + +/** + * @brief Show game title screen + * + */ +void game_title(); /** * @brief Print current game configuration to the screen diff --git a/src/sound.c b/src/sound.c new file mode 100644 index 0000000..667fb87 --- /dev/null +++ b/src/sound.c @@ -0,0 +1,33 @@ +/************************************************************************** + * * + * Author: Ivo Filot * + * * + * CX16-OTHELLO is free software: * + * you can redistribute it and/or modify it under the terms of the * + * GNU General Public License as published by the Free Software * + * Foundation, either version 3 of the License, or (at your option) * + * any later version. * + * * + * CX16-OTHELLO is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty * + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see http://www.gnu.org/licenses/. * + * * + **************************************************************************/ + +#include "sound.h" + +uint8_t music = YES; + +/** + * @brief Fill sound buffer + * + */ +void sound_fill_buffers() { + if(music) { + sound_fill_buffers_asm(); + } +} \ No newline at end of file diff --git a/src/sound.h b/src/sound.h index 978ef1f..3bf52c1 100644 --- a/src/sound.h +++ b/src/sound.h @@ -21,40 +21,17 @@ #ifndef _SOUND_H #define _SOUND_H -/** - * @brief Initialize sound engine - * - */ -void __fastcall__ init_sound(); +#include -/** - * @brief Start background music - * - */ -void __fastcall__ start_bgmusic(); +#include "constants.h" +#include "sound_low.h" -/** - * @brief Stop background music - * - */ -void __fastcall__ stop_bgmusic(); - -/** - * @brief Rewind background music - * - */ -void __fastcall__ rewind_bgmusic(); - -/** - * @brief Fill sound buffers - * - */ -void __fastcall__ sound_fill_buffers(); +extern uint8_t music; // whether to play music /** - * @brief Play short sound when placing down a stone + * @brief Fill sound buffer * */ -void __fastcall__ play_thumb(); +void sound_fill_buffers(); #endif // _SOUND_H \ No newline at end of file diff --git a/src/sound_low.h b/src/sound_low.h new file mode 100644 index 0000000..33620fa --- /dev/null +++ b/src/sound_low.h @@ -0,0 +1,60 @@ +/************************************************************************** + * * + * Author: Ivo Filot * + * * + * CX16-OTHELLO is free software: * + * you can redistribute it and/or modify it under the terms of the * + * GNU General Public License as published by the Free Software * + * Foundation, either version 3 of the License, or (at your option) * + * any later version. * + * * + * CX16-OTHELLO is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty * + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see http://www.gnu.org/licenses/. * + * * + **************************************************************************/ + +#ifndef _SOUND_LOW_H +#define _SOUND_LOW_H + +/** + * @brief Initialize sound engine + * + */ +void __fastcall__ init_sound(); + +/** + * @brief Start background music + * + */ +void __fastcall__ start_bgmusic(); + +/** + * @brief Stop background music + * + */ +void __fastcall__ stop_bgmusic(); + +/** + * @brief Rewind background music + * + */ +void __fastcall__ rewind_bgmusic(); + +/** + * @brief Fill sound buffers + * + */ +void __fastcall__ sound_fill_buffers_asm(); + +/** + * @brief Play short sound when placing down a stone + * + */ +void __fastcall__ play_thumb(); + +#endif // _SOUND_LOW_H \ No newline at end of file diff --git a/src/sound.s b/src/sound_low.s similarity index 97% rename from src/sound.s rename to src/sound_low.s index 3f7c1f6..1ef55da 100644 --- a/src/sound.s +++ b/src/sound_low.s @@ -28,7 +28,7 @@ .export _start_bgmusic .export _stop_bgmusic .export _rewind_bgmusic -.export _sound_fill_buffers +.export _sound_fill_buffers_asm .export _play_thumb TONE1 = 1189 @@ -55,11 +55,6 @@ CHANNEL = 0 ldy #>filename2 ; high byte jsr zsmkit::zsm_setfile - ; set attenuation for background music - ldx #0 ; priority - lda #$20 ; attenuation value - jsr zsmkit::zsm_setatten - rts .endproc @@ -69,6 +64,12 @@ CHANNEL = 0 .proc _start_bgmusic: near ldx #0 jsr zsmkit::zsm_play + + ; set attenuation for background music + ldx #0 ; priority + lda #$20 ; attenuation value + jsr zsmkit::zsm_setatten + rts .endproc @@ -93,8 +94,9 @@ CHANNEL = 0 ; ; Fill sound buffers ; -.proc _sound_fill_buffers: near - jmp zsmkit::zsm_fill_buffers +.proc _sound_fill_buffers_asm: near + jsr zsmkit::zsm_fill_buffers + rts .endproc ; diff --git a/src/video.c b/src/video.c index f52f3b1..33016da 100644 --- a/src/video.c +++ b/src/video.c @@ -313,15 +313,15 @@ void clear_foreground() { * */ void update_background_diagonal() { - #if SCROLL_BACKGROUND == 1 - clock_t curtick = clock(); + if(background_scroll == YES) { + clock_t curtick = clock(); - if(((curtick - prevtick) * 1000 / CLOCKS_PER_SEC) > SCROLLSPEED) { - prevtick = curtick; - VERA.layer0.hscroll = (VERA.layer0.hscroll - 1) % 16; - VERA.layer0.vscroll = (VERA.layer0.vscroll - 1) % 16; + if(((curtick - prevtick) * 1000 / CLOCKS_PER_SEC) > SCROLLSPEED) { + prevtick = curtick; + VERA.layer0.hscroll = (VERA.layer0.hscroll - 1) % 16; + VERA.layer0.vscroll = (VERA.layer0.vscroll - 1) % 16; + } } - #endif } /**