From 45228018f29e5d720f910bec3001e1c66db34d3c Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Wed, 20 Apr 2022 23:38:14 -0700 Subject: [PATCH] Finished textbox, learned that windows aren't transparent --- assets/images/font.png | Bin 737 -> 725 bytes src/conversation/textbox.c | 26 +++++++++++++++----------- src/conversation/textbox.h | 2 +- src/main.c | 19 +++++++++---------- src/main.h | 2 ++ 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/assets/images/font.png b/assets/images/font.png index 1758e2f0ca78db03e9f7c7165be98c7439cb9358..1e47c1e5459a644e8f2cb2d60fa84bd25b930bac 100644 GIT binary patch delta 713 zcmV;)0yh2O1=R(R7=Hu<0001A>uK8n0004VQb$4nuFf3k00004XF*Lt006O%3;baP z00006P)t-so4gMXI1khAOj`f|010qNS#tmY4#EHc4#EKyC`y0;00LM^L_t(Y$E8*a zwuK-FgdGg~-|Q0x6us5$o@b{l9fz-^h$vJbGM?hSKWy~=$$y6hKy8eU+u?q3&KIcp z8yPTw4wf7vOVASFEWXOn00rhG$gT}gtr#Gf0KowY`RZ2Sg5suy^|+oHdNna0Y(r9c zEEui;s!L1K?Xow(2M`571L!8fqlCj*3#?aSubYc;WZoVV%|6E5R7G7zJVN^z8OQ|~ zj!6KiHGw53E`O&tQd4ZqsRiC5Cq|Ems4Ry0k-z{@NNHUfOIpB8d*_Ecl%|rKF};Bs z;Q%l)86S*bBKN{t778YK%$Ji&Ztug(NS79@GmwK3giPA?#9KdT(%SUm^lX@!I}z=! z^u#wnV;~)YhV|{Dj@6C9($&V7TOCMySmD-9E55pc-hb-!q^`^=zh-s(P`UxQPcuI* z0G8U1Bv4I2iO|l#_o-6@bRBd7rVo;GvqE0Axs$Ad1avd?_;>=y35aJ8)?pD?8YCPO z&e{OJtH|INr0Wp>6==HJ+-o{T?4sV}1E?g+k5o;oWJy4OH v@&A@}`9aqF&)rhYU;n*~?*xxJJT{R(FGVU~edUO700000NkvXXu0mjfvyC|w delta 725 zcmV;`0xJF01>psd7=H)@0001*8-&^b0004VQb$4nuFf3k0000CP)t-so4gN;tPe0^ zFb_Bn_)CX_0007mNkl7%;fOdJrR@mWJ;$ec%K>%W(GLd4+S@Z~~tS1%HG=D!#K$qDNsR%ML1}4q` zxzgO5N z(!P7o6fi&&!jb{82q-c<&VhFC0|KLpT7gZaW>}a$yqEH z7`$>4i!(`|=76bgPhk*u$-!NbURqK2nAJ{;H0Z4WYJVM600~d;_%i^|)wnod=p_U~ zRtCJ@@o{{>?qm}sbJmXxKvTtZ^E&_~Wfa1(U*q+W?F+q_| z#Hs~&{~mZ4HGBmaNWV~JfIWB!yO16!hD=0uhh3hk+L#jCy2JAt0j}Brtm_|c-}2c> zQS6x<0e^TIT?epJh#mh3Sbq`SmJYUf-{~I%WNq`Fm;O|kYt8lTMIlY(T{TDZJ~~4= z0y6aW^idWnRefTng_2UU3&BHuUg$Wko5Tn{(2_SccBd3o3GwxDJg zMv&lb^+I^*qI@7|`2RriC_nwtqilY91KqTL&i~*2@bBacp*aql5oc&B00000NkvXX Hu0mjfP7_N; diff --git a/src/conversation/textbox.c b/src/conversation/textbox.c index ef20cfd..82449f5 100644 --- a/src/conversation/textbox.c +++ b/src/conversation/textbox.c @@ -21,7 +21,7 @@ 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); @@ -41,9 +41,8 @@ inline void conversationTextboxInit() { TEXTBOX_TILES[TEXTBOX_WIDTH_IN_TILES * (i+1) - 1] = BORDER_TILE_CENTER_RIGHT; } - // Setup tiles. set_win_tiles( - 0, 0, + 0x00, 0x00, TEXTBOX_WIDTH_IN_TILES, TEXTBOX_HEIGHT_IN_TILES, TEXTBOX_TILES ); @@ -53,7 +52,10 @@ void conversationTextboxSetText(char *text) { uint8_t i, j, k, rowStart, stateFlags; char c, c2; + // Begin by filling the textbox text chars with whitespace to begin. + // TODO: I'm pretty sure I can move this lower and optimize. for(i = 0; i < TEXTBOX_SCROLL_ROWS_MAX * TEXTBOX_CHARS_PER_ROW; i++) { + break; TEXTBOX_TEXTS[i] = ' '; } @@ -66,9 +68,9 @@ void conversationTextboxSetText(char *text) { // Copy source text to buffer, also determine wordwrapping here. i = 0, j = 0, rowStart = 0, stateFlags = 0; - while((c = text[i]) != '\0') { + while((c = text[i]) != '\0') {// "For each char in string" if(c == ' ') { - // Scan ahead and look at how many chars remain to the next space + // Scan ahead and look at how many chars remain to the next space. k = i + 1; while( (c2 = text[k]) != '\0' && @@ -86,16 +88,18 @@ void conversationTextboxSetText(char *text) { stateFlags |= 1 << 0; } - // Do we need to newline? + // Do we need to insert newline where we are currently? if((stateFlags & (1 << 0)) != 0) { - stateFlags &= ~(1 << 0); - rowStart = i; - j = ((j / TEXTBOX_CHARS_PER_ROW) + 1) * TEXTBOX_CHARS_PER_ROW; + stateFlags &= ~(1 << 0);// Remove newline flag i++; + rowStart = i;// Update the row start (Should this be i+1?) + //TODO: can I optimize the next line by using rowStart somehow? + j = ((j / TEXTBOX_CHARS_PER_ROW) + 1) * TEXTBOX_CHARS_PER_ROW;// Update destination character position. TEXTBOX_ROW_COUNT++; continue; } + // Insert the character TEXTBOX_TEXTS[j] = c; i++; j++; @@ -162,8 +166,8 @@ inline void conversationTextboxUpdate() { } else { tiles[0] = c - 33 + FONT_DATA_POSITION; set_win_tiles( - 1 + (TEXTBOX_SCROLL % TEXTBOX_CHARS_PER_ROW), - 1 + (TEXTBOX_SCROLL / TEXTBOX_CHARS_PER_ROW), + 0x01 + (TEXTBOX_SCROLL % TEXTBOX_CHARS_PER_ROW), + 0x01 + (TEXTBOX_SCROLL / TEXTBOX_CHARS_PER_ROW), 1, 1, tiles ); diff --git a/src/conversation/textbox.h b/src/conversation/textbox.h index d584af6..0ab6c54 100644 --- a/src/conversation/textbox.h +++ b/src/conversation/textbox.h @@ -41,7 +41,7 @@ #define TEXTBOX_TILES_ROWS 3 #define TEXTBOX_TILE_BLANK COMMON_TILE_3 -#define TEXTBOX_SCROLL_ROWS_MAX 9 +#define TEXTBOX_SCROLL_ROWS_MAX 14 // STR_ ## name ## _DATA, STR_ ## name ## _LENGTH #define conversationTextboxString(name) conversationTextboxSetText(\ diff --git a/src/main.c b/src/main.c index 80bf412..0ca1272 100644 --- a/src/main.c +++ b/src/main.c @@ -137,8 +137,9 @@ void main() { // Set up the GAMEBOY's registers. disable_interrupts(); DISPLAY_OFF; - LCDC_REG = LCDCF_OFF | LCDCF_WIN9C00 | LCDCF_BG8800 | LCDCF_BG9800 | LCDCF_BGON; - BGP_REG = 0xE4U; + LCDC_REG = LCDCF_OFF | LCDCF_WIN9C00 | LCDCF_WINON | LCDCF_BG8800 | LCDCF_BG9800 | LCDCF_BGON; + // Set the background color palette register + BGP_REG = OBP0_REG = OBP1_REG = 0xE4U; // Init the random seed initarand(DIV_REG); @@ -154,23 +155,21 @@ void main() { // pokerInit(); // Fill screen white - for(j = 0; j < 0x20*0x20; j++) filled[j] = COMMON_TILE_3; + for(j = 0; j < GB_BACKGROUND_COLUMNS * GB_BACKGROUND_ROWS; j++) filled[j] = COMMON_TILE_3; set_bkg_tiles(0x00, 0x00, GB_BACKGROUND_COLUMNS, GB_BACKGROUND_ROWS, filled); SCX_REG = 0x00; SCY_REG = 0x00; + // Alright begin the game logic here. + // conversationQueueNext(); + char DEBUG_TEXT[] = "Hello World\nThe quick brown fox jumps over the lazy dog. How now brown cow? The fitness gram pacer test"; + conversationTextboxSetText(DEBUG_TEXT); + // Now turn the screen on DISPLAY_ON; enable_interrupts(); wait_vbl_done(); - // Alright begin the game logic here. - // conversationQueueNext(); - char DEBUG_TEXT[] = "Hello World\nThe quick brown fox jumps over the lazy dog. How now brown cow? The fitness gram pacer test is a"; - // uint8_t DEBUG_TEXT_LENGTH = strlen(DEBUG_TEXT); - // for(j = 0; j < DEBUG_TEXT_LENGTH; j++) DEBUG_TEXT[j] = DEBUG_TEXT[j] - 33 + 4; - conversationTextboxSetText(DEBUG_TEXT); - // Begin the loop while(1) { // Wait for VSYNC diff --git a/src/main.h b/src/main.h index 0a0e6b8..669fe5d 100644 --- a/src/main.h +++ b/src/main.h @@ -10,6 +10,8 @@ #include "libs.h" #include "time.h" +#include "SM.h" + #include "display/common.h" #include "display/tilemap.h" #include "poker/poker.h"