From dd0e5ce53de3222fb20206ecc913ce830ec6bf9c Mon Sep 17 00:00:00 2001 From: hkz Date: Sun, 12 Oct 2025 21:12:24 +0200 Subject: [PATCH] Integrate the new dialog module for the VDP --- Makefile | 4 +-- src/utility.c | 14 ++++++++++ src/utility.h | 69 ++++++++++++++++++++++++------------------------ src/vddlg_main.c | 28 +++++++++++++++----- 4 files changed, 73 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index 1f6ad02..30d14d4 100644 --- a/Makefile +++ b/Makefile @@ -36,8 +36,8 @@ DEMO_C_SRCS = demo_main.c input.c utility.c game_hgr_graphics_demo.c hgr_line_da VDPIN_ASM_SRCS = tk2k_startup_module.s preserve_zero_pages.s vdp.s vdp_utils.s vdp_init.s VDPIN_C_SRCS = vdpin_main.c utility.c -VDDLG_ASM_SRCS = tk2k_startup_module.s preserve_zero_pages.s sound.s -VDDLG_C_SRCS = vddlg_main.c input.c utility.c game_hgr_graphics.c hgr_line_data.c +VDDLG_ASM_SRCS = tk2k_startup_module.s preserve_zero_pages.s sound.s vdp.s vdp_utils.s game_vdp_graphics.s +VDDLG_C_SRCS = vddlg_main.c input.c utility.c # Object files MASTER_OBJS = $(MASTER_ASM_SRCS:%.s=%.o) $(MASTER_C_SRCS:%.c=%.o) diff --git a/src/utility.c b/src/utility.c index 7c84154..fb29948 100644 --- a/src/utility.c +++ b/src/utility.c @@ -3,6 +3,20 @@ #include "mem_registers.h" #include "monitor_subroutines.h" +void decbuf_to_ascii(uint8_t len, uint8_t *buf) { + for(uint8_t idx = 0; idx < len; idx++) { + buf[idx] += 0x30; + } + + // Swap the order in the array + uint8_t tmp; + for(uint8_t idx = 0; idx < len/2; idx++) { + tmp = buf[idx]; + buf[idx] = buf[(len - 1) - idx]; + buf[(len - 1) - idx] = tmp; + } +} + void num_to_decbuf(uint16_t n, uint8_t len, uint8_t *buf) { for(uint8_t idx = 0; idx < len; idx++) { buf[idx] = n % 10; diff --git a/src/utility.h b/src/utility.h index d30bb0a..2195052 100644 --- a/src/utility.h +++ b/src/utility.h @@ -1,34 +1,35 @@ -#ifndef _UTILITY_HEADER_ -#define _UTILITY_HEADER_ - -#include - -#define SCREEN_HEIGHT 192 -#define SCREEN_WIDTH_BYTES 128 -#define BYTES_PER_LINE 40 - -#define PEEKZ(a) (*(volatile uint8_t* __attribute__((zpage)))(a)) -#define POKEZ(a, b) ((*(volatile uint8_t* __attribute__((zpage)))(a)) = b) - -#define PEEK(a) (*(volatile uint8_t*)(a)) -#define POKE(a, b) ((*(volatile uint8_t*)(a)) = b) - -#define PEEKW(a) (*(volatile uint16_t*)(a)) -#define POKEW(a, b) ((*(volatile uint16_t*)(a)) = b) - -#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) - -// 0x356 - 0x357 actually fall inside the -// decoding table for DISK II sector reading, -// but they're unused bytes! So we can use them -// to store the lfsr_update -#define LFSR_REGISTER_ADDRESS 0x0356 - -void num_to_decbuf(uint16_t n, uint8_t len, uint8_t *buf); -uint8_t bit_reverse(uint8_t b); -uint8_t bit_count(uint8_t b); -void lfsr_init(uint16_t reg); -uint16_t lfsr_update(void); -uint8_t calculate_crc8(uint8_t* data, uint8_t len); - -#endif /* _UTILITY_HEADER_ */ +#ifndef _UTILITY_HEADER_ +#define _UTILITY_HEADER_ + +#include + +#define SCREEN_HEIGHT 192 +#define SCREEN_WIDTH_BYTES 128 +#define BYTES_PER_LINE 40 + +#define PEEKZ(a) (*(volatile uint8_t* __attribute__((zpage)))(a)) +#define POKEZ(a, b) ((*(volatile uint8_t* __attribute__((zpage)))(a)) = b) + +#define PEEK(a) (*(volatile uint8_t*)(a)) +#define POKE(a, b) ((*(volatile uint8_t*)(a)) = b) + +#define PEEKW(a) (*(volatile uint16_t*)(a)) +#define POKEW(a, b) ((*(volatile uint16_t*)(a)) = b) + +#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) + +// 0x356 - 0x357 actually fall inside the +// decoding table for DISK II sector reading, +// but they're unused bytes! So we can use them +// to store the lfsr_update +#define LFSR_REGISTER_ADDRESS 0x0356 + +void decbuf_to_ascii(uint8_t len, uint8_t *buf); +void num_to_decbuf(uint16_t n, uint8_t len, uint8_t *buf); +uint8_t bit_reverse(uint8_t b); +uint8_t bit_count(uint8_t b); +void lfsr_init(uint16_t reg); +uint16_t lfsr_update(void); +uint8_t calculate_crc8(uint8_t* data, uint8_t len); + +#endif /* _UTILITY_HEADER_ */ diff --git a/src/vddlg_main.c b/src/vddlg_main.c index 5c32d8f..319f829 100644 --- a/src/vddlg_main.c +++ b/src/vddlg_main.c @@ -3,7 +3,8 @@ #include -#include "game_hgr_graphics.h" +#include "vdp_utils.h" +#include "game_vdp_graphics.h" #include "monitor_subroutines.h" #include "utility.h" #include "mem_map.h" @@ -21,6 +22,7 @@ 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 score_buf[7] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; #define WAIT_COUNTER_END 0xFFFF @@ -29,21 +31,35 @@ void main(void) { 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(); + __disable_interrupts(); // Make sure the interrupts are disabled + + num_to_decbuf(state_page->hi_score, 6, score_buf); + decbuf_to_ascii(6, score_buf); + + vdp_clear_dialog(); + vdp_switch_nt(1); // Make sure VDP shows the correct dialog nametable + + vdp_print_string(1, 6, 10, "Current High-Score :"); + vdp_print_string(1, 13, 12, (char*)score_buf); + vdp_print_string(1, 5, 15, "Press any key to START"); + vdp_print_string(1, 1, 23, "hkz@social.chinwag.org"); + vdp_print_string(1, 27, 23, "2025"); switch(dld->mode) { case DLOG_MODE_WIN: snd_festive(); - ddraw_endgame_box(1, dld->score, state_page->hi_score); + //ddraw_endgame_box(1, dld->score, state_page->hi_score); + vdp_print_string(1, 11, 8, "YOU WIN!!!"); break; case DLOG_MODE_LOSE: snd_sad_scale(); - ddraw_endgame_box(-1, dld->score, state_page->hi_score); + //ddraw_endgame_box(-1, dld->score, state_page->hi_score); + vdp_print_string(1, 11, 8, "GAME OVER!"); break; default: case DLOG_MODE_START: - ddraw_endgame_box(0, dld->score, state_page->hi_score); + //ddraw_endgame_box(0, dld->score, state_page->hi_score); + vdp_print_string(1, 7, 8, "WELCOME TO TK2048!"); snd_start(); break; };