mirror of
https://codeberg.org/hkzlab/TK2048.git
synced 2026-01-05 07:29:20 +11:00
Begin wiring in the VDP code in the game module
This commit is contained in:
parent
28a1fbfc18
commit
26e94d2957
5 changed files with 142 additions and 89 deletions
114
src/vdgam_main.c
114
src/vdgam_main.c
|
|
@ -3,16 +3,19 @@
|
|||
|
||||
#include <calypsi/intrinsics6502.h>
|
||||
|
||||
#include "vdp_utils.h"
|
||||
#include "game_vdp_graphics.h"
|
||||
|
||||
#include "monitor_subroutines.h"
|
||||
#include "utility.h"
|
||||
#include "mem_map.h"
|
||||
#include "mem_registers.h"
|
||||
#include "shared_page.h"
|
||||
#include "state_page.h"
|
||||
#include "dlog_data.h"
|
||||
#include "game_data.h"
|
||||
#include "input.h"
|
||||
#include "game_logic.h"
|
||||
#include "game_hgr_graphics.h"
|
||||
#include "monitor_subroutines.h"
|
||||
#include "sound.h"
|
||||
#include "module_list.h"
|
||||
|
|
@ -21,36 +24,41 @@
|
|||
#pragma require __preserve_zp
|
||||
#pragma require __data_initialization_needed
|
||||
|
||||
#define MOVES_TEXT_X 32
|
||||
#define MOVES_TEXT_Y 61
|
||||
#define MOVES_TEXT_WIDTH 5
|
||||
#define HSCORE_TEXT_X 27
|
||||
#define HSCORE_TEXT_Y 13
|
||||
|
||||
#define SCORE_TEXT_X 32
|
||||
#define SCORE_TEXT_Y 29
|
||||
#define SCORE_TEXT_WIDTH 5
|
||||
#define SCORE_TEXT_X 27
|
||||
#define SCORE_TEXT_Y 8
|
||||
|
||||
#define HIGH_TEXT_X 32
|
||||
#define HIGH_TEXT_Y 107
|
||||
#define MOVES_TEXT_X 27
|
||||
#define MOVES_TEXT_Y 4
|
||||
|
||||
#define WIN_SCORE_BONUS 10000
|
||||
|
||||
static state_page_data* state_page = (state_page_data*)STATE_PAGE;
|
||||
static shared_page_data *shared_page = (shared_page_data*)SHARED_PAGE;
|
||||
static uint8_t text_buf[7] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
void main(void) {
|
||||
uint16_t moves_count = 0;
|
||||
uint16_t score = 0;
|
||||
int8_t done = 0;
|
||||
|
||||
__disable_interrupts(); // Make sure the interrupts are disabled
|
||||
|
||||
// By default, once we return from this, return to the DLOG module and give the master no command to execute
|
||||
shared_page->master_command = MASTER_COMMAND_NONE;
|
||||
shared_page->next_module_idx = MODULE_DLOG; // Go to the DLOG module
|
||||
shared_page->next_module_idx = MODULE_DLOG_VDP; // Go to the dialog module
|
||||
|
||||
dlog_data *dld = (dlog_data *)(shared_page->module_data);
|
||||
dlog_data *gad = (dlog_data *)(shared_page->module_data);
|
||||
|
||||
// Make sure the buffers are pointing to the correct memory and are clear
|
||||
clear_display_buffers();
|
||||
vdp_clear_gamegrid();
|
||||
vdp_switch_nt(0); // Make sure VDP shows the gamegrid
|
||||
|
||||
// Setup the IRQ handler
|
||||
POKEW(IRQ_HANDLER_ADDRESS, (uint16_t)vdp_irq_handler);
|
||||
|
||||
// Reset the game, calculate the initial score depending on which tiles we randomly get
|
||||
score = reset_game();
|
||||
|
|
@ -68,37 +76,59 @@ void main(void) {
|
|||
}
|
||||
|
||||
// Draw the initial state of the game
|
||||
draw_game_background(state_page->hi_score);
|
||||
draw_number(moves_count, MOVES_TEXT_WIDTH, MOVES_TEXT_X, MOVES_TEXT_Y);
|
||||
draw_number(score, SCORE_TEXT_WIDTH, SCORE_TEXT_X, SCORE_TEXT_Y);
|
||||
draw_tiles();
|
||||
num_to_decbuf(state_page->hi_score, 6, text_buf); // High score
|
||||
decbuf_to_ascii(6, text_buf);
|
||||
vdp_print_string(0, HSCORE_TEXT_X, HSCORE_TEXT_Y, (char*)text_buf);
|
||||
|
||||
num_to_decbuf(moves_count, 6, text_buf); // Moves count
|
||||
decbuf_to_ascii(6, text_buf);
|
||||
vdp_print_string(0, MOVES_TEXT_X, MOVES_TEXT_Y, (char*)text_buf);
|
||||
|
||||
num_to_decbuf(score, 6, text_buf); // Score
|
||||
decbuf_to_ascii(6, text_buf);
|
||||
vdp_print_string(0, SCORE_TEXT_X, SCORE_TEXT_Y, (char*)text_buf);
|
||||
|
||||
vdp_draw_joystick(JS_POS_CENTER); // Center the joystick
|
||||
|
||||
vdp_redraw_tiles();
|
||||
|
||||
// Swap graphical buffers
|
||||
swap_display_buffers();
|
||||
__enable_interrupts();
|
||||
|
||||
while(1) { // Game loop
|
||||
lfsr_update();
|
||||
|
||||
__disable_interrupts();
|
||||
vdp_draw_joystick(JS_POS_CENTER);
|
||||
__enable_interrupts();
|
||||
|
||||
switch(read_kb()) {
|
||||
case K_UP:
|
||||
SND_TAP();
|
||||
done = step_game(GAME_STEP_UP);
|
||||
ddraw_direction_arrows(GRAPH_ARROW_UP);
|
||||
__disable_interrupts();
|
||||
vdp_draw_joystick(JS_POS_UP);
|
||||
__enable_interrupts();
|
||||
break;
|
||||
case K_DOWN:
|
||||
SND_TAP();
|
||||
done = step_game(GAME_STEP_DOWN);
|
||||
ddraw_direction_arrows(GRAPH_ARROW_DOWN);
|
||||
__disable_interrupts();
|
||||
vdp_draw_joystick(JS_POS_DOWN);
|
||||
__enable_interrupts();
|
||||
break;
|
||||
case K_LEFT:
|
||||
SND_TAP();
|
||||
done = step_game(GAME_STEP_LEFT);
|
||||
ddraw_direction_arrows(GRAPH_ARROW_LEFT);
|
||||
__disable_interrupts();
|
||||
vdp_draw_joystick(JS_POS_LEFT);
|
||||
__enable_interrupts();
|
||||
break;
|
||||
case K_RIGHT:
|
||||
SND_TAP();
|
||||
done = step_game(GAME_STEP_RIGHT);
|
||||
ddraw_direction_arrows(GRAPH_ARROW_RIGHT);
|
||||
__disable_interrupts();
|
||||
vdp_draw_joystick(JS_POS_RIGHT);
|
||||
__enable_interrupts();
|
||||
break;
|
||||
case K_CTRL_R:
|
||||
snd_mod_button();
|
||||
|
|
@ -112,9 +142,9 @@ void main(void) {
|
|||
shared_page->master_command = MASTER_COMMAND_SAVE;
|
||||
case K_CTRL_L:
|
||||
snd_mod_button();
|
||||
sync_display1_buffer();
|
||||
shared_page->next_module_idx = MODULE_GAME;
|
||||
gad->mode = GAME_MODE_LOAD;
|
||||
__disable_interrupts();
|
||||
return;
|
||||
default:
|
||||
continue; // Do nothing, loop again
|
||||
|
|
@ -123,17 +153,22 @@ void main(void) {
|
|||
// Increase the count of moves we made (unless we lost or reset the game)
|
||||
if(done >= 0) moves_count++;
|
||||
|
||||
// Draw the number of moves
|
||||
draw_number(moves_count, MOVES_TEXT_WIDTH, MOVES_TEXT_X, MOVES_TEXT_Y);
|
||||
|
||||
// Draw the moved tiles
|
||||
draw_tiles();
|
||||
num_to_decbuf(moves_count, 6, text_buf); // Moves count
|
||||
decbuf_to_ascii(6, text_buf);
|
||||
__disable_interrupts();
|
||||
vdp_print_string(0, MOVES_TEXT_X, MOVES_TEXT_Y, (char*)text_buf);
|
||||
__enable_interrupts();
|
||||
|
||||
// If we have won, or we got a reset request, break out of this loop
|
||||
if(done) {
|
||||
score += (done > 0) ? WIN_SCORE_BONUS : 0;
|
||||
draw_number(score, SCORE_TEXT_WIDTH, SCORE_TEXT_X, SCORE_TEXT_Y);
|
||||
swap_display_buffers(); // Make sure we show the latest changes
|
||||
|
||||
num_to_decbuf(score, 6, text_buf); // Score
|
||||
decbuf_to_ascii(6, text_buf);
|
||||
__disable_interrupts();
|
||||
vdp_print_string(0, SCORE_TEXT_X, SCORE_TEXT_Y, (char*)text_buf);
|
||||
__enable_interrupts();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -147,20 +182,21 @@ void main(void) {
|
|||
score = calculate_score();
|
||||
|
||||
// Draw the score
|
||||
draw_number(score, SCORE_TEXT_WIDTH, SCORE_TEXT_X, SCORE_TEXT_Y);
|
||||
|
||||
swap_display_buffers();
|
||||
|
||||
// Draw the new tile directly on the front buffer, this way we make it appear with an "animation"
|
||||
ddraw_single_tile(random_tile_off - 1);
|
||||
num_to_decbuf(score, 6, text_buf); // Score
|
||||
decbuf_to_ascii(6, text_buf);
|
||||
__disable_interrupts();
|
||||
vdp_print_string(0, SCORE_TEXT_X, SCORE_TEXT_Y, (char*)text_buf);
|
||||
vdp_redraw_tiles();
|
||||
__enable_interrupts();
|
||||
}
|
||||
|
||||
// Sync the display buffers
|
||||
sync_display1_buffer();
|
||||
|
||||
|
||||
dld->mode = (done > 0) ? DLOG_MODE_WIN : DLOG_MODE_LOSE;
|
||||
dld->score = score;
|
||||
|
||||
__disable_interrupts();
|
||||
|
||||
// One last update to the tiles
|
||||
vdp_redraw_tiles();
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue