Skip to content

Commit

Permalink
Initial commit mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
ifilot committed May 25, 2024
1 parent b3a152c commit b627eac
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "constants.h"
#include "game.h"
#include "menu.h"
#include "mouse.h"

unsigned char keycode;

Expand All @@ -33,6 +34,9 @@ void main() {
init_screen();
load_tiles();

// // enable mouse
init_mouse();

// load sound engine
init_sound();
start_bgmusic();
Expand Down
33 changes: 20 additions & 13 deletions src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "video.h"
#include "game.h"
#include "mouse.h"

/**
* @brief Show game menu
Expand Down
26 changes: 26 additions & 0 deletions src/mouse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**************************************************************************
* *
* Author: Ivo Filot <ivo@ivofilot.nl> *
* *
* 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
31 changes: 31 additions & 0 deletions src/mouse.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
;
;
; Author: Ivo Filot <ivo@ivofilot.nl>
;
; 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
4 changes: 2 additions & 2 deletions src/sound.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b627eac

Please sign in to comment.