From b627eaca5195a42362783f8a969930b702c26f0b Mon Sep 17 00:00:00 2001 From: ifilot Date: Sat, 25 May 2024 22:22:04 +0200 Subject: [PATCH] Initial commit mouse --- src/main.c | 4 ++++ src/menu.c | 33 ++++++++++++++++++++------------- src/menu.h | 1 + src/mouse.h | 26 ++++++++++++++++++++++++++ src/mouse.s | 31 +++++++++++++++++++++++++++++++ src/sound.s | 4 ++-- 6 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 src/mouse.h create mode 100644 src/mouse.s diff --git a/src/main.c b/src/main.c index 298444a..3419218 100644 --- a/src/main.c +++ b/src/main.c @@ -25,6 +25,7 @@ #include "constants.h" #include "game.h" #include "menu.h" +#include "mouse.h" unsigned char keycode; @@ -33,6 +34,9 @@ void main() { init_screen(); load_tiles(); + // // enable mouse + init_mouse(); + // load sound engine init_sound(); start_bgmusic(); diff --git a/src/menu.c b/src/menu.c index 0b33fd3..f4692f9 100644 --- a/src/menu.c +++ b/src/menu.c @@ -26,18 +26,22 @@ */ void game_menu() { static unsigned char keycode; + unsigned short *mouse_x = (unsigned short *)0x2; + unsigned short *mouse_y = (unsigned short *)0x4; + static unsigned char mouse_buttons; write_string("CX16-OTHELLO", 0, 1); + write_string("music by Crisps", 1, 5); write_string("1.1.0", 0, 15); - write_string("(1) PLAYER 1:", 2, 1); - write_string("(2) PLAYER 2:", 3, 1); - write_string("(B) BOARD:", 4, 1); + write_string("(1) PLAYER 1:", 3, 1); + write_string("(2) PLAYER 2:", 4, 1); + write_string("(B) BOARD:", 6, 1); + + write_string("(S) SIZE:", 8, 1); write_string("(C) TILE COLOR 1:", 11, 1); write_string("(V) TILE COLOR 2:", 12, 1); - write_string("(S) BOARD", 6, 1); - write_string(" SIZE:", 7, 1); write_string("Hit ENTER to start", 14, 1); @@ -112,6 +116,9 @@ void game_menu() { return; } + asm("jsr $FF6B"); + asm("sta %v", mouse_buttons); + // update sound buffer sound_fill_buffers(); update_background_diagonal(); @@ -123,31 +130,31 @@ void game_menu() { * */ void print_choice() { - char buf[20]; + char buf[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; static const uint8_t offsetx = 12; // print whether player 1 is a human or a cpu - write_string(player1_type == PLAYER_HUMAN ? "HUMAN" : "CPU ", 2, 14); + write_string(player1_type == PLAYER_HUMAN ? "HUMAN" : "CPU ", 3, 14); // print whether player 2 is a human or a cpu - write_string(player2_type == PLAYER_HUMAN ? "HUMAN" : "CPU ", 3, 14); + write_string(player2_type == PLAYER_HUMAN ? "HUMAN" : "CPU ", 4, 14); // print board style - write_string(board_type == BOARD_STONE ? "STONE" : "WOOD ", 4, 12); + write_string(board_type == BOARD_STONE ? "STONE" : "WOOD ", 7, 1); // print board size switch(boardsize) { case 6: - memcpy(buf, " 6 x 6 ", 8); + memcpy(buf, "6 x 6 ", 7); break; case 8: - memcpy(buf, " 8 x 8 ", 8); + memcpy(buf, "8 x 8 ", 7); break; case 10: - memcpy(buf, "10 x 10", 8); + memcpy(buf, "10 x 10", 7); break; } - write_string(buf, 8, 1); + write_string(buf, 9, 1); // build sample board build_board(4, 6, offsetx); diff --git a/src/menu.h b/src/menu.h index 7c34891..5862dd2 100644 --- a/src/menu.h +++ b/src/menu.h @@ -26,6 +26,7 @@ #include "video.h" #include "game.h" +#include "mouse.h" /** * @brief Show game menu diff --git a/src/mouse.h b/src/mouse.h new file mode 100644 index 0000000..33fc544 --- /dev/null +++ b/src/mouse.h @@ -0,0 +1,26 @@ +/************************************************************************** + * * + * 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 _MOUSE_H +#define _MOUSE_H + +void init_mouse(); + +#endif // _MOUSE_H \ No newline at end of file diff --git a/src/mouse.s b/src/mouse.s new file mode 100644 index 0000000..e0f7ac1 --- /dev/null +++ b/src/mouse.s @@ -0,0 +1,31 @@ +; +; +; 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 "x16.inc" + +.export _init_mouse + +.proc _init_mouse: near + sec + jsr X16::Kernal::SCREEN_MODE + lda #1 + jsr X16::Kernal::MOUSE_CONFIG + rts +.endproc \ No newline at end of file diff --git a/src/sound.s b/src/sound.s index 3bd6f12..3f7c1f6 100644 --- a/src/sound.s +++ b/src/sound.s @@ -40,8 +40,8 @@ CHANNEL = 0 ; Start the sound engine ; .proc _init_sound: near - jsr zsmkit::zsm_init_engine ; initialize engine - jsr zsmkit::zsmkit_setisr + jsr zsmkit::zsm_init_engine ; initialize engine + jsr zsmkit::zsmkit_setisr ; load background music ldx #0 ; priority