Skip to content

Commit

Permalink
Initial commit ingame help
Browse files Browse the repository at this point in the history
  • Loading branch information
ifilot committed Jun 1, 2024
1 parent 79a5fbd commit 64f24ec
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ PYTHON=python3

make: OTHELLO.PRG

OTHELLO.PRG: *.c *.h *.s FONTMAP.DAT TILES.DAT OTHELLO.ZSM TILE.ZSM
OTHELLO.PRG: *.c *.h *.s FONTMAP.DAT TILES.DAT OTHELLO.ZSM TILE.ZSM HELP.DAT
$(CC) -O -o OTHELLO.PRG -t cx16 -C othello.cfg *.c *.s *.lib

HELP.DAT: help.hlp
$(PYTHON) help.py

TILES.DAT:
$(PYTHON) ../assets/scripts/convert_tilemap.py TILES.DAT

Expand Down
1 change: 1 addition & 0 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
#define GAME_RUN 0x01
#define GAME_MENU 0x02
#define GAME_SETTINGS 0x03
#define GAME_HELP 0x04

#define PLAYER_HUMAN 0x00
#define PLAYER_CPU 0x01
Expand Down
26 changes: 26 additions & 0 deletions src/help.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 _HELP_H
#define _HELP_H

void __fastcall__ load_help_assets();

#endif // _HELP_H
52 changes: 52 additions & 0 deletions src/help.hlp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# Generalized HELP file, any lines starting with "#" will be ignored
# in the parsing
#
# All pages are 320x240 pixels or 20 x 15 characters (16x16 font size)
# Writeable area is however 20x12 characters as first line and bottom two
# lines are already used.
#
|PAGE1|
____________________
Othello for the
Commander X16 is a
modern adaptation
of the classic
strategy board game,
tailored for the
retro charm of the
X16 platform.
|ENDPAGE|
|PAGE2|
____________________
Known for its simple
yet strategic
gameplay, Othello
challenges players
to outmaneuver their
opponent by flipping
discs (stones) on
the playing board.
|ENDPAGE|
|PAGE3|
____________________
The objective is to
have the majority
of stones in your
color when the
board is filled.
|ENDPAGE|
#|PAGE4|
#____________________
#____________________
#____________________
#____________________
#____________________
#____________________
#____________________
#____________________
#____________________
#____________________
#____________________
#____________________
#|ENDPAGE|
36 changes: 36 additions & 0 deletions src/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# parse .hlp file into binary file that can be parsed by the Othello game

def main():
pages = []
with open('help.hlp') as f:
lines = f.readlines()

for line in lines:
if line.startswith('#'):
continue

if line.startswith('|PAGE'):
parsing = True
curpage = bytearray()
continue

if line.startswith('|ENDPAGE|'):
parsing = False
curpage.extend([0x20] * (20 * 12 - len(curpage)))
pages.append(curpage)
continue

if parsing:
line = line.strip()
line = line.replace('_', ' ')
if len(line) > 20:
curpage += line[0:20].encode('ascii')
else:
curpage += line.encode('ascii') + bytearray([0x20] * (20 - len(line)))

with open('HELP.DAT', 'wb') as f:
for page in pages:
f.write(page)

if __name__ == '__main__':
main()
60 changes: 60 additions & 0 deletions src/help.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
;
;
; 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 _load_help_assets

.code
;
; Start the sound engine
;
.proc _load_help_assets: near

; set ram bank
lda #2 ; use bank 2, bank 1 is used for sound
sta $00 ; set ram bank 2

; assign file name
lda #$08 ; filename length
ldx #<filename ; low byte filename pointer
ldy #>filename ; high byte filename pointer
jsr X16::Kernal::SETNAM

; set file pointer
lda #2 ; file index
ldx #8 ; SD-card
ldy #2 ; headerless load
jsr X16::Kernal::SETLFS

; load file into memory
lda #0 ; load file into system memory
ldx #$00
ldy #$A0 ; banked memory
jsr X16::Kernal::LOAD

; reset ram bank
lda #0 ; reset ram bank
sta $00

rts
.endproc

filename: .asciiz "help.dat"
9 changes: 9 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "menu.h"
#include "mouse.h"
#include "sound.h"
#include "help.h"

unsigned char keycode;

Expand All @@ -39,6 +40,9 @@ void main() {
init_sound();
start_bgmusic();

// load help assets
load_help_assets();

// enable mouse
init_mouse();
set_mouse_pointer(TILE_MOUSE_CURSOR);
Expand All @@ -54,6 +58,11 @@ void main() {
game_settings();
}

while(gamestate == GAME_HELP) {
clear_screen();
game_help();
}

while(gamestate == GAME_RUN) {
switch(current_player) {
case PLAYER_ONE:
Expand Down
78 changes: 78 additions & 0 deletions src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "menu.h"

uint8_t helppage = 0;

/**
* @brief Show game title screen
*
Expand Down Expand Up @@ -59,6 +61,9 @@ void game_title() {
case 83:
gamestate = GAME_SETTINGS;
return;
case 72:
gamestate = GAME_HELP;
return;
case KEYCODE_RETURN:
gamestate = GAME_RUN;
init_game();
Expand All @@ -71,6 +76,79 @@ void game_title() {
}
}

/**
* @brief Show help screen
*
*/
void game_help() {
static unsigned char keycode;
uint8_t *ptr = (uint8_t*)(0xA000 + 240 * helppage);
uint8_t x,y;
uint32_t map_base_addr;
char buf[4] = {0x00, 0x00, 0x00, 0x00};

// set sprites
assign_sprite(1, TILE_NONE);
assign_sprite(2, TILE_NONE);
assign_sprite(3, TILE_NONE);
assign_sprite(4, TILE_NONE);

write_string("HELP", 0, 0);
write_string("(N) NEXT (P) PREV", 13, 0);
write_string("(ESC) BACK PAGE:", 14, 0);

// print the page
asm("lda #2");
asm("sta $00");
for(y=1; y<12; y++) {
map_base_addr = MAPBASE1 + (y * MAPWIDTH) * 2;
VERA.address = map_base_addr;
VERA.address_hi = map_base_addr >> 16;
VERA.address_hi |= 0b10000;

for(x=0; x<20; x++) {
if(*ptr >= ' ' && *ptr <= '~') {
VERA.data0 = (*ptr) - 0x20 + 0x40;
} else {
VERA.data0 = 0x40;
}
VERA.data0 = 0x00;
ptr++;
}
}
asm("lda #0");
asm("sta $00");

// print page number
itoa(helppage+1, buf, 10);
write_string(buf, 14, 17);

while(1) {
asm("jsr $FFE4");
asm("sta %v", keycode);

switch(keycode) {
case KEYCODE_ESCAPE:
gamestate = GAME_MENU;
return;
case 78:
if(helppage < 3) {
helppage++;
}
return;
case 80:
if(helppage > 0) {
helppage--;
}
return;
}

// update sound buffer
sound_fill_buffers();
update_background_diagonal();
}
}

/**
* @brief Show game menu
*
Expand Down
8 changes: 8 additions & 0 deletions src/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "mouse.h"
#include "sound.h"

extern uint8_t helppage;

/**
* @brief Show game settings menu
*
Expand All @@ -41,6 +43,12 @@ void game_settings();
*/
void game_title();

/**
* @brief Show help screen
*
*/
void game_help();

/**
* @brief Print current game configuration to the screen
*
Expand Down
1 change: 1 addition & 0 deletions src/sound_low.s
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ CHANNEL = 0
; Start the sound engine
;
.proc _init_sound: near
lda #1 ; assign rambank 0
jsr zsmkit::zsm_init_engine ; initialize engine
jsr zsmkit::zsmkit_setisr

Expand Down

0 comments on commit 64f24ec

Please sign in to comment.