mirror of
https://codeberg.org/hkzlab/TK2048.git
synced 2025-12-31 05:09:19 +11:00
Temporary drawing of the game board
This commit is contained in:
parent
8c48dfa6cd
commit
8fb45612a8
2 changed files with 26 additions and 11 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include "utility.h"
|
||||
#include "mem_map.h"
|
||||
#include "mem_registers.h"
|
||||
#include "line_data.h"
|
||||
|
|
@ -10,14 +11,14 @@
|
|||
#define SCREEN_WIDTH_B 40
|
||||
#define TILE_SIDE 35
|
||||
|
||||
#define TOP_OFFSET 11 // Top is offset by 11 lines
|
||||
#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;
|
||||
static uint8_t *back_buf = (uint8_t*)DISPLAY_PAGE_2;
|
||||
|
||||
// The grid is 5x5 squares,
|
||||
// It is offset on the left side by 7 pixels and on the top by 11
|
||||
// It is offset on the left side by 7 pixels and on the top by 14
|
||||
// Every square is 35x35 pixels
|
||||
|
||||
void swap_display_buffers(void);
|
||||
|
|
@ -28,12 +29,12 @@ void draw_game_background(void) {
|
|||
|
||||
// Horizontal borders
|
||||
for(uint8_t col = 0; col < GRID_SIDE * (TILE_SIDE/7); 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;
|
||||
buf[line_offset_map[TOP_OFFSET - 1] + col + LEFT_OFFSET_B] = 0x7F;
|
||||
buf[line_offset_map[TOP_OFFSET + (TILE_SIDE * GRID_SIDE) + 1] + col + LEFT_OFFSET_B] = 0x7F;
|
||||
}
|
||||
|
||||
// TODO vertical borders
|
||||
for(uint8_t row = 1; row < TILE_SIDE * GRID_SIDE; row++) { // Skipping one at the top
|
||||
// Vertical borders
|
||||
for(uint8_t row = 0; row < (TILE_SIDE * GRID_SIDE) + 1; row++) {
|
||||
buf[line_offset_map[row + TOP_OFFSET] + LEFT_OFFSET_B - 1] = 0x40;
|
||||
buf[line_offset_map[row + TOP_OFFSET] + LEFT_OFFSET_B + (GRID_SIDE * (TILE_SIDE/7))] = 0x01;
|
||||
}
|
||||
|
|
@ -44,17 +45,29 @@ void draw_game_background(void) {
|
|||
}
|
||||
|
||||
void draw_tiles(void) {
|
||||
uint8_t* grid = get_front_grid();
|
||||
|
||||
// Clear the grid so we'll be able to draw the boxes on
|
||||
clear_box(GRID_SIDE * (TILE_SIDE/7), GRID_SIDE * TILE_SIDE, LEFT_OFFSET_B, TOP_OFFSET + 1, back_buf);
|
||||
|
||||
|
||||
for (uint8_t tile = 0; tile < GRID_SIDE * GRID_SIDE; tile++) {
|
||||
if(grid[tile]) {
|
||||
uint8_t col = tile % GRID_SIDE;
|
||||
uint8_t row = tile / GRID_SIDE;
|
||||
|
||||
back_buf[line_offset_map[TOP_OFFSET + 15 + row * TILE_SIDE] + LEFT_OFFSET_B + 2 + (col * 5)] = grid[tile];
|
||||
}
|
||||
}
|
||||
|
||||
swap_display_buffers();
|
||||
}
|
||||
|
||||
void swap_display_buffers(void) {
|
||||
static uint8_t dp_counter = 0;
|
||||
|
||||
void swap_display_buffers(void) {
|
||||
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);
|
||||
PEEK(((uint16_t)front_buf == DISPLAY_PAGE_1) ? IO_DISPLAY_PAGE1 : IO_DISPLAY_PAGE2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,9 @@ __task int main(void) {
|
|||
|
||||
while(1){ // Outer loop
|
||||
reset_game();
|
||||
|
||||
draw_game_background();
|
||||
draw_tiles();
|
||||
|
||||
while(1) { // Game loop
|
||||
lfsr_update();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue