From ccf46b9afbd2167a074ed43e5fe2a094c34f80b4 Mon Sep 17 00:00:00 2001 From: hkz Date: Thu, 17 Jul 2025 14:38:12 +0200 Subject: [PATCH] Add code to show partial background --- Makefile | 3 ++- src/game_graphics.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 83198cd..3e767ed 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,8 @@ LIBS=clib-6502.a # Common source files ASM_SRCS = tk2k_startup.s C_SRCS = main.c monitor_subroutines.c utility.c \ - game_graphics.c game_logic.c input.c + game_graphics.c game_logic.c input.c \ + line_data.c # Object files OBJS = $(ASM_SRCS:%.s=%.o) $(C_SRCS:%.c=%.o) diff --git a/src/game_graphics.c b/src/game_graphics.c index a8690ba..fb7e17b 100644 --- a/src/game_graphics.c +++ b/src/game_graphics.c @@ -1,18 +1,60 @@ #include "game_graphics.h" +#include + #include "mem_map.h" +#include "mem_registers.h" +#include "line_data.h" +#include "game_logic.h" + +#define SCREEN_WIDTH_B 40 +#define TILE_SIDE 28 #define TOP_OFFSET 14 // Top is offset by 14 lines #define LEFT_OFFSET_B 1 // Left is offset by 1 bytes (7 pixels) +static uint8_t *front_buf = (uint8_t*)DISPLAY_PAGE_1; +static uint8_t *back_buf = (uint8_t*)DISPLAY_PAGE_1; + // The grid is 5x5 squares, // It is offset on the left side by 7 pixels and on the top by 14 // Every square is 28x28 pixels -void draw_game_background(void) { +void swap_display_buffers(void); +void draw_game_background(void) { + // Draw the background on display page 1 + uint8_t* buf = (uint8_t*)DISPLAY_PAGE_1; + + // Horizontal borders + for(uint8_t col = 0; col < GRID_SIDE * 4; col++) { + buf[line_offset_map[TOP_OFFSET] + col + LEFT_OFFSET_B] = 0x7F; + buf[line_offset_map[TOP_OFFSET + (TILE_SIDE * GRID_SIDE)] + col + LEFT_OFFSET_B] = 0x7F; + } + + // vertical borders + for(uint8_t col = 0; col < GRID_SIDE * 4; col++) { + buf[line_offset_map[TOP_OFFSET] + col + LEFT_OFFSET_B] = 0x7F; + buf[line_offset_map[TOP_OFFSET + (TILE_SIDE * GRID_SIDE)] + col + LEFT_OFFSET_B] = 0x7F; + } + + // Copy the data from display page 1 to 2 + memcpy((void*)DISPLAY_PAGE_1, (void*)DISPLAY_PAGE_2, DISPLAY_PAGE_SIZE); + } void draw_tiles(void) { + swap_display_buffers(); +} + +void swap_display_buffers(void) { + static uint8_t dp_counter = 0; + + uint8_t *temp = front_buf; + front_buf = back_buf; + back_buf = temp; + + // Show the current buffer + PEEK((dp_counter++ & 0x01) ? IO_DISPLAY_PAGE1 : IO_DISPLAY_PAGE2); }