TK2048/src/dlog_main.c
2025-10-07 12:52:38 +02:00

74 lines
1.9 KiB
C

#include <stubs.h>
#include <string.h>
#include <calypsi/intrinsics6502.h>
#include "game_hgr_graphics.h"
#include "monitor_subroutines.h"
#include "utility.h"
#include "mem_map.h"
#include "shared_page.h"
#include "state_page.h"
#include "dlog_data.h"
#include "game_data.h"
#include "input.h"
#include "sound.h"
#include "module_list.h"
// External initialization requirements
#pragma require __preserve_zp
#pragma require __data_initialization_needed
static state_page_data* state_page = (state_page_data*)STATE_PAGE;
static shared_page_data *shared_page = (shared_page_data*)SHARED_PAGE;
#define WAIT_COUNTER_END 0xFFFF
void main(void) {
uint16_t wait_counter = 0;
dlog_data *dld = (dlog_data *)(shared_page->module_data);
game_data *gad = (game_data *)(shared_page->module_data);
// Make sure the buffers are pointing to the correct memory
initialize_display_buffers();
switch(dld->mode) {
case DLOG_MODE_WIN:
snd_festive();
ddraw_endgame_box(1, dld->score, state_page->hi_score);
break;
case DLOG_MODE_LOSE:
snd_sad_scale();
ddraw_endgame_box(-1, dld->score, state_page->hi_score);
break;
default:
case DLOG_MODE_START:
ddraw_endgame_box(0, dld->score, state_page->hi_score);
snd_start();
break;
};
if(dld->score > state_page->hi_score) { // New high-score. We need to save it.
state_page->hi_score = dld->score;
shared_page->master_command = MASTER_COMMAND_SAVE;
} else {
shared_page->master_command = MASTER_COMMAND_NONE;
}
shared_page->next_module_idx = MODULE_GAME; // Go to the GAME module
gad->mode = GAME_MODE_NORMAL; // Set the proper start mode for the game
while(!read_any_key() && (wait_counter != WAIT_COUNTER_END)) {
wait_counter++;
lfsr_update();
}
if (wait_counter == WAIT_COUNTER_END) {
shared_page->next_module_idx = MODULE_DEMO; // Actually go to the DEMO module
return;
}
snd_mod_button();
return;
}