Made frame its own code.
This commit is contained in:
40
src/conversation/frame.c
Normal file
40
src/conversation/frame.c
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
28
src/conversation/frame.h
Normal file
28
src/conversation/frame.h
Normal file
@@ -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
|
||||
);
|
@@ -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
|
||||
);
|
||||
|
@@ -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;
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user