diff --git a/archive/main.c b/archive/main.c index 62bd6cf..ce54431 100644 --- a/archive/main.c +++ b/archive/main.c @@ -187,7 +187,7 @@ void main() { // Fill screen white for(j = 0; j < GB_BACKGROUND_COLUMNS * GB_BACKGROUND_ROWS; j++) filled[j] = SPRITE_TILESET_BLACK_LOW; - spriteBufferBackgroundLow(0x00, 0x00, GB_BACKGROUND_COLUMNS, GB_BACKGROUND_ROWS, filled); + spriteBufferBackground(0x00, 0x00, GB_BACKGROUND_COLUMNS, GB_BACKGROUND_ROWS, filled); SCX_REG = 0x00; SCY_REG = 0x00; diff --git a/src/conversation/questionbox.c b/src/conversation/questionbox.c index 67287a0..d0ebd38 100644 --- a/src/conversation/questionbox.c +++ b/src/conversation/questionbox.c @@ -44,7 +44,7 @@ void questionBoxSetOptions(char *title, char **options, uint8_t count) { // Repurpose old array and draw arrow spaces[0] = spriteFontTileFromChar(QUESTION_BOX_CURSOR); - spriteBufferBackgroundHigh(0x01, TEXTBOX_WIN_Y + 0x02, 1, 1, spaces); + spriteBufferWindow(0x01, TEXTBOX_Y + 0x02, 1, 1, spaces); } inline void questionBoxUpdate() { @@ -76,9 +76,9 @@ inline void questionBoxUpdate() { } else { tiles[0] = spriteFontTileFromChar(' '); } - spriteBufferBackgroundHigh( + spriteBufferWindow( 0x01 + ((i % 0x02) * QUESTION_BOX_QUESTION_SPACES), - TEXTBOX_WIN_Y + 0x02 + (i / 0x02), + TEXTBOX_Y + 0x02 + (i / 0x02), 1, 1, tiles ); diff --git a/src/conversation/textbox.c b/src/conversation/textbox.c index c623b19..dba80cc 100644 --- a/src/conversation/textbox.c +++ b/src/conversation/textbox.c @@ -77,6 +77,8 @@ void conversationTextboxSetText(char *text) { // Now we have organized the string nicely we can prep for rendering. Fill the // tiles with blank chars. textboxFillBlank(); + WY_REG = TEXTBOX_WINDOW_Y * TILE_HEIGHT; + SHOW_WIN; } inline void textboxFillBlank() { @@ -86,8 +88,8 @@ inline void textboxFillBlank() { tiles, TEXTBOX_WIDTH_IN_TILES, TEXTBOX_HEIGHT_IN_TILES, SPRITE_TILESET_WHITE_HIGH ); - spriteBufferBackgroundHigh( - 0x00, TEXTBOX_WIN_Y, + spriteBufferWindow( + 0x00, TEXTBOX_Y, TEXTBOX_WIDTH_IN_TILES, TEXTBOX_HEIGHT_IN_TILES, tiles ); @@ -108,6 +110,7 @@ inline void conversationTextboxUpdate() { if((TEXTBOX_ROW_COUNT - TEXTBOX_ROW_CURRENT) < TEXTBOX_TILES_ROWS) { TEXTBOX_STATE &= ~TEXTBOX_STATE_VISIBLE; HIDE_WIN; + LCDC_REG |= LCDCF_BG8000; conversationQueueNext(); return; } @@ -129,9 +132,9 @@ inline void conversationTextboxUpdate() { } else { tile = spriteFontTileFromChar(c); - spriteBufferBackgroundHigh( + spriteBufferWindow( 0x01 + (TEXTBOX_SCROLL % TEXTBOX_CHARS_PER_ROW), - TEXTBOX_WIN_Y + 0x01 + (TEXTBOX_SCROLL / TEXTBOX_CHARS_PER_ROW), + TEXTBOX_Y + 0x01 + (TEXTBOX_SCROLL / TEXTBOX_CHARS_PER_ROW), 1, 1, &tile ); diff --git a/src/conversation/textbox.h b/src/conversation/textbox.h index 25b19df..3862534 100644 --- a/src/conversation/textbox.h +++ b/src/conversation/textbox.h @@ -32,7 +32,9 @@ #define TEXTBOX_SCROLL_ROWS_MAX 14 -#define TEXTBOX_WIN_Y (18 - TEXTBOX_HEIGHT_IN_TILES) +#define TEXTBOX_Y 0x00 +#define TEXTBOX_WINDOW_Y (18 - TEXTBOX_HEIGHT_IN_TILES) +#define TEXTBOX_SCREEN_Y (TEXTBOX_WINDOW_Y + TEXTBOX_Y) extern char TEXTBOX_TEXTS[TEXTBOX_SCROLL_ROWS_MAX * TEXTBOX_CHARS_PER_ROW]; extern uint8_t TEXTBOX_ROW_COUNT; diff --git a/src/interrupts.h b/src/interrupts.h index 0c589f2..a804306 100644 --- a/src/interrupts.h +++ b/src/interrupts.h @@ -9,6 +9,6 @@ #include "libs.h" #include "conversation/textbox.h" -#define INTERRUPT_TEXTBOX_VRAM ((TEXTBOX_WIN_Y * TILE_HEIGHT) - 1) +#define INTERRUPT_TEXTBOX_VRAM ((TEXTBOX_SCREEN_Y * TILE_HEIGHT) - 1) void interruptOnScanline(); \ No newline at end of file diff --git a/src/libs.h b/src/libs.h index 9364fd8..90ef731 100644 --- a/src/libs.h +++ b/src/libs.h @@ -15,4 +15,4 @@ #include #define TILE_WIDTH 8 -#define TILE_HEIGHT 8 \ No newline at end of file +#define TILE_HEIGHT TILE_WIDTH \ No newline at end of file diff --git a/src/main.c b/src/main.c index 10943e1..9716cd7 100644 --- a/src/main.c +++ b/src/main.c @@ -18,11 +18,21 @@ void main() { // Create a critical section for some video stuff CRITICAL { DISPLAY_OFF; - LCDC_REG = LCDCF_OFF | LCDCF_BG8000 | LCDCF_BG9800 | LCDCF_BGON; + LCDC_REG = LCDCF_OFF | LCDCF_WIN9C00 | LCDCF_BG8000 | LCDCF_BG9800 | LCDCF_BGON; + /* + * LCD = Off + * WindowBank = 0x9C00 + * BG Chr = 0x8800 + * BG Bank = 0x9800 + * BG = On + */ + STAT_REG |= STATF_LYC; LYC_REG = 0x00; SCX_REG = 0x00; SCY_REG = 0x00; + WX_REG = TILE_WIDTH; + // WY_REG = 0x00; add_LCD(interruptOnScanline); } set_interrupts(VBL_IFLAG | LCD_IFLAG); @@ -47,12 +57,12 @@ void main() { for(j = 0; j < GB_BACKGROUND_COLUMNS * GB_BACKGROUND_ROWS; j++) { filled[j] = SPRITE_TILESET_WHITE_LOW; } - spriteBufferBackgroundLow(0x00, 0x00, GB_BACKGROUND_COLUMNS, GB_BACKGROUND_ROWS, filled); + spriteBufferBackground(0x00, 0x00, GB_BACKGROUND_COLUMNS, GB_BACKGROUND_ROWS, filled); // Card Test uint8_t cardTiles[SPRITE_CARD_TILE_COUNT]; spriteCardBufferTiles(cardTiles, CARD_SPADES_QUEEN); - spriteBufferBackgroundLow(0x00, 0x00, SPRITE_CARD_WIDTH, SPRITE_CARD_HEIGHT, cardTiles); + spriteBufferBackground(0x00, 0x00, SPRITE_CARD_WIDTH, SPRITE_CARD_HEIGHT, cardTiles); // Now turn the screen on DISPLAY_ON; diff --git a/src/sprites/sprites.c b/src/sprites/sprites.c index ecb7ce6..ef78e38 100644 --- a/src/sprites/sprites.c +++ b/src/sprites/sprites.c @@ -20,7 +20,7 @@ inline void spriteBufferHigh(uint8_t position, uint8_t length, uint8_t *tiles) { vmemcpy(vramPosition, tiles, SPRITE_VRAM_SIZE_PER_TILE * length); } -inline void spriteBufferBackgroundLow( +inline void spriteBufferBackground( uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t *tiles @@ -28,12 +28,11 @@ inline void spriteBufferBackgroundLow( set_tiles( x, y, height, width,// Bug? - SPRITE_VRAM_TILEMAP_LOW, + SPRITE_VRAM_TILEMAP_BACKGROUND_LOW, tiles ); } - -inline void spriteBufferBackgroundHigh( +inline void spriteBufferWindow( uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t *tiles @@ -41,7 +40,7 @@ inline void spriteBufferBackgroundHigh( set_tiles( x, y, height, width,// Bug? - SPRITE_VRAM_TILEMAP_LOW, + SPRITE_VRAM_TILEMAP_WINDOW_LOW, tiles ); } \ No newline at end of file diff --git a/src/sprites/sprites.h b/src/sprites/sprites.h index f6dc7c9..0067e47 100644 --- a/src/sprites/sprites.h +++ b/src/sprites/sprites.h @@ -12,7 +12,8 @@ #define SPRITE_VRAM_HIGH 0x8800 #define SPRITE_VRAM_DISTANCE_BETWEEN_LOW_AND_HIGH 0x0800 #define SPRITE_VRAM_SIZE_PER_TILE 0x10 -#define SPRITE_VRAM_TILEMAP_LOW 0x9800 +#define SPRITE_VRAM_TILEMAP_BACKGROUND_LOW 0x9800 +#define SPRITE_VRAM_TILEMAP_WINDOW_LOW 0x9C00 /** * Buffer tiles data into VRAM in the HIGH space (The upper bounds of VRAM) @@ -32,13 +33,13 @@ inline void spriteBufferHigh(uint8_t position, uint8_t length, uint8_t *tiles); */ inline void spriteBufferLow(uint8_t position, uint8_t length, uint8_t *tiles); -inline void spriteBufferBackgroundLow( +inline void spriteBufferBackground( uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t *tiles ); -inline void spriteBufferBackgroundHigh( +inline void spriteBufferWindow( uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t *tiles