From 1da7b6a8b48af23ef1ee57a96bfa798acc804b26 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Tue, 26 Apr 2022 22:59:20 -0700 Subject: [PATCH] Made frame its own code. --- src/conversation/frame.c | 40 +++++++++++++++++++++++++++++++ src/conversation/frame.h | 28 ++++++++++++++++++++++ src/conversation/textbox.c | 48 +++++++------------------------------- src/conversation/textbox.h | 15 +++--------- src/main.c | 4 ++-- 5 files changed, 82 insertions(+), 53 deletions(-) create mode 100644 src/conversation/frame.c create mode 100644 src/conversation/frame.h diff --git a/src/conversation/frame.c b/src/conversation/frame.c new file mode 100644 index 0000000..479dae6 --- /dev/null +++ b/src/conversation/frame.c @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2022 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "frame.h" + +inline void frameBuffer( + uint8_t buffer[], + uint8_t bufferWidth, uint8_t bufferHeight, + uint8_t fill +) { + uint8_t i, j, max; + max = bufferWidth * bufferHeight; + + // Corners + buffer[0] = BORDER_TILE_TOP_LEFT; + buffer[bufferWidth-1] = BORDER_TILE_TOP_RIGHT; + buffer[max-1] = BORDER_TILE_BOTTOM_RIGHT; + buffer[max-bufferWidth] = BORDER_TILE_BOTTOM_LEFT; + + // Edges + for(i = 1; i < bufferWidth-1; i++) { + buffer[i] = BORDER_TILE_TOP_CENTER; + buffer[max - 1 - i] = BORDER_TILE_BOTTOM_CENTER; + } + for(i = 1; i < bufferHeight - 1; i++) { + buffer[bufferWidth * i] = BORDER_TILE_CENTER_LEFT; + buffer[bufferWidth * (i+1) - 1] = BORDER_TILE_CENTER_RIGHT; + } + + // Inner + for(j = 1; j < bufferHeight-1; j++) { + for(i = 1; i < bufferWidth-1; i++) { + buffer[i + (j * bufferWidth)] = fill; + } + } +} \ No newline at end of file diff --git a/src/conversation/frame.h b/src/conversation/frame.h new file mode 100644 index 0000000..d1cf955 --- /dev/null +++ b/src/conversation/frame.h @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2022 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "../libs.h" +#include "../util.h" +#include "../display/common.h" +#include "../display/tilemap.h" + +#define BORDER_TILE_TOP_LEFT BORDER_DATA_POSITION +#define BORDER_TILE_TOP_CENTER BORDER_TILE_TOP_LEFT + 1 +#define BORDER_TILE_TOP_RIGHT BORDER_TILE_TOP_CENTER + 1 +#define BORDER_TILE_CENTER_LEFT BORDER_TILE_TOP_RIGHT + 1 +#define BORDER_TILE_CENTER BORDER_TILE_CENTER_LEFT + 1 +#define BORDER_TILE_CENTER_RIGHT BORDER_TILE_CENTER + 1 +#define BORDER_TILE_BOTTOM_LEFT BORDER_TILE_CENTER_RIGHT + 1 +#define BORDER_TILE_BOTTOM_CENTER BORDER_TILE_BOTTOM_LEFT + 1 +#define BORDER_TILE_BOTTOM_RIGHT BORDER_TILE_BOTTOM_CENTER + 1 + +inline void frameBuffer( + uint8_t buffer[], + uint8_t bufferWidth, uint8_t bufferHeight, + uint8_t fill +); \ No newline at end of file diff --git a/src/conversation/textbox.c b/src/conversation/textbox.c index b164d77..07c95a0 100644 --- a/src/conversation/textbox.c +++ b/src/conversation/textbox.c @@ -22,31 +22,9 @@ inline void conversationTextboxInit() { TEXTBOX_STATE = 0; // Setup window data - move_win(7, SCREENHEIGHT - (TEXTBOX_HEIGHT_IN_TILES * 8)); + // move_win(7, SCREENHEIGHT - (TEXTBOX_HEIGHT_IN_TILES * 8)); set_win_data(FONT_DATA_POSITION, FONT_IMAGE_TILES, FONT_IMAGE); set_win_data(BORDER_DATA_POSITION, BORDER_IMAGE_TILES, BORDER_IMAGE); - - // Corners - TEXTBOX_TILES[0] = BORDER_TILE_TOP_LEFT; - TEXTBOX_TILES[TEXTBOX_WIDTH_IN_TILES-1] = BORDER_TILE_TOP_RIGHT; - TEXTBOX_TILES[TEXTBOX_TILES_MAX-1] = BORDER_TILE_BOTTOM_RIGHT; - TEXTBOX_TILES[TEXTBOX_TILES_MAX-TEXTBOX_WIDTH_IN_TILES] = BORDER_TILE_BOTTOM_LEFT; - - // Edges - for(i = 1; i < TEXTBOX_WIDTH_IN_TILES - 1; i++) { - TEXTBOX_TILES[i] = BORDER_TILE_TOP_CENTER; - TEXTBOX_TILES[TEXTBOX_TILES_MAX - 1 - i] = BORDER_TILE_BOTTOM_CENTER; - } - for(i = 1; i < TEXTBOX_HEIGHT_IN_TILES - 1; i++) { - TEXTBOX_TILES[TEXTBOX_WIDTH_IN_TILES * i] = BORDER_TILE_CENTER_LEFT; - TEXTBOX_TILES[TEXTBOX_WIDTH_IN_TILES * (i+1) - 1] = BORDER_TILE_CENTER_RIGHT; - } - - set_win_tiles( - 0x00, 0x00, - TEXTBOX_WIDTH_IN_TILES, TEXTBOX_HEIGHT_IN_TILES, - TEXTBOX_TILES - ); } void conversationTextboxSetText(char *text) { @@ -107,24 +85,16 @@ void conversationTextboxSetText(char *text) { // Now we have organized the string nicely we can prep for rendering. Fill the // tiles with blank chars. textboxFillBlank(); - - // Show the window layer. - SHOW_WIN; } inline void textboxFillBlank() { - uint8_t i, j; - uint8_t TEXTBOX_TILES[TEXTBOX_CHAR_ROWS * TEXTBOX_CHARS_PER_ROW]; - - for(j = 0; j < TEXTBOX_CHAR_ROWS; j++) { - for(i = 0; i < TEXTBOX_CHARS_PER_ROW ; i++) { - TEXTBOX_TILES[i + (j * TEXTBOX_CHARS_PER_ROW)] = TEXTBOX_TILE_BLANK; - } - } + uint8_t TEXTBOX_TILES[TEXTBOX_WIDTH_IN_TILES * TEXTBOX_HEIGHT_IN_TILES]; - set_win_tiles( - 0x01, 0x01, - TEXTBOX_WIDTH_IN_TILES - 0x02, TEXTBOX_HEIGHT_IN_TILES - 0x02, + frameBuffer(TEXTBOX_TILES, TEXTBOX_WIDTH_IN_TILES, TEXTBOX_HEIGHT_IN_TILES, TEXTBOX_TILE_BLANK); + + set_bkg_tiles( + 0x00, TEXTBOX_WIN_Y, + TEXTBOX_WIDTH_IN_TILES, TEXTBOX_HEIGHT_IN_TILES, TEXTBOX_TILES ); } @@ -166,9 +136,9 @@ inline void conversationTextboxUpdate() { } else { tiles[0] = c - TEXTBOX_FONT_START + FONT_DATA_POSITION; - set_win_tiles( + set_bkg_tiles( 0x01 + (TEXTBOX_SCROLL % TEXTBOX_CHARS_PER_ROW), - 0x01 + (TEXTBOX_SCROLL / TEXTBOX_CHARS_PER_ROW), + TEXTBOX_WIN_Y + 0x01 + (TEXTBOX_SCROLL / TEXTBOX_CHARS_PER_ROW), 1, 1, tiles ); diff --git a/src/conversation/textbox.h b/src/conversation/textbox.h index 0fab516..d5cd949 100644 --- a/src/conversation/textbox.h +++ b/src/conversation/textbox.h @@ -12,18 +12,7 @@ #include "../display/common.h" #include "../display/tilemap.h" #include "queue.h" - -#define BORDER_TILE_TOP_LEFT BORDER_DATA_POSITION -#define BORDER_TILE_TOP_CENTER BORDER_TILE_TOP_LEFT + 1 -#define BORDER_TILE_TOP_RIGHT BORDER_TILE_TOP_CENTER + 1 -#define BORDER_TILE_CENTER_LEFT BORDER_TILE_TOP_RIGHT + 1 -#define BORDER_TILE_CENTER BORDER_TILE_CENTER_LEFT + 1 -#define BORDER_TILE_CENTER_RIGHT BORDER_TILE_CENTER + 1 -#define BORDER_TILE_BOTTOM_LEFT BORDER_TILE_CENTER_RIGHT + 1 -#define BORDER_TILE_BOTTOM_CENTER BORDER_TILE_BOTTOM_LEFT + 1 -#define BORDER_TILE_BOTTOM_RIGHT BORDER_TILE_BOTTOM_CENTER + 1 - -#define TEXTBOX_WIN_Y 0 +#include "frame.h" #define TEXTBOX_STATE_VISIBLE (1 << 0) #define TEXTBOX_STATE_SCROLLED (1 << 1) @@ -45,6 +34,8 @@ #define TEXTBOX_FONT_START 33 +#define TEXTBOX_WIN_Y (18 - TEXTBOX_HEIGHT_IN_TILES) + extern char TEXTBOX_TEXTS[TEXTBOX_SCROLL_ROWS_MAX * TEXTBOX_CHARS_PER_ROW]; extern uint8_t TEXTBOX_ROW_COUNT; extern uint8_t TEXTBOX_ROW_CURRENT; diff --git a/src/main.c b/src/main.c index ab7d3e8..ab01751 100644 --- a/src/main.c +++ b/src/main.c @@ -137,7 +137,7 @@ void main() { // Set up the GAMEBOY's registers. disable_interrupts(); DISPLAY_OFF; - LCDC_REG = LCDCF_OFF | LCDCF_WIN9C00 | LCDCF_WINON | LCDCF_BG8800 | LCDCF_BG9800 | LCDCF_BGON; + LCDC_REG = LCDCF_OFF | LCDCF_WIN9C00 | LCDCF_BG8800 | LCDCF_BG9800 | LCDCF_BGON; // Set the background color palette register BGP_REG = OBP0_REG = OBP1_REG = 0xE4U; @@ -188,6 +188,6 @@ void main() { // Update conversation fade effect conversationFadeUpdate(); - mainDebugDraw(); + // mainDebugDraw(); } } \ No newline at end of file