parent
ce51f737b5
commit
0965f80e99
@ -0,0 +1,61 @@
|
||||
//
|
||||
// Created by Wouter Groeneveld on 28/07/18.
|
||||
//
|
||||
|
||||
#ifndef GBA_BITMAP_ENGINE_TEXT_STREAM_H
|
||||
#define GBA_BITMAP_ENGINE_TEXT_STREAM_H
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#define TEXT_WIDTH 8
|
||||
|
||||
// tonc_text.h assemly ref
|
||||
extern const u32 toncfontTiles[192];
|
||||
#define toncfontTilesLen 768
|
||||
extern u16 *vid_page;
|
||||
|
||||
typedef struct tagTXT_BASE
|
||||
{
|
||||
u16 *dst0; //!< writing buffer starting point
|
||||
u32 *font; // pointer to font used
|
||||
u8 *chars; // character map (chars as in letters, not tiles)
|
||||
u8 *cws; // char widths (for VWF)
|
||||
u8 dx,dy; // letter distances
|
||||
u16 flags; // for later
|
||||
u8 extra[12]; // ditto
|
||||
} ALIGN4 TXT_BASE;
|
||||
|
||||
|
||||
class TextStream {
|
||||
private:
|
||||
int currRow, currCol;
|
||||
short currColorIndex;
|
||||
|
||||
u8 txt_lut[256];
|
||||
|
||||
TXT_BASE __txt_base;
|
||||
TXT_BASE *gptxt;
|
||||
|
||||
static TextStream* inst;
|
||||
TextStream();
|
||||
TextStream(TextStream& other) = delete;
|
||||
TextStream(TextStream&& other) = delete;
|
||||
|
||||
public:
|
||||
void clear();
|
||||
void setText(std::string text, int row, int col);
|
||||
void setText(const char* text, int row, int col);
|
||||
|
||||
inline void setFontColorIndex(short index) { currColorIndex = index; }
|
||||
|
||||
static TextStream& instance();
|
||||
|
||||
TextStream& operator << (const char* s);
|
||||
TextStream& operator << (const int s);
|
||||
TextStream& operator << (const u32 s);
|
||||
TextStream& operator << (const bool s);
|
||||
};
|
||||
|
||||
|
||||
#endif //GBA_SPRITE_ENGINE_TEXT_STREAM_H
|
@ -0,0 +1,106 @@
|
||||
//
|
||||
// Created by Wouter Groeneveld on 28/07/18.
|
||||
//
|
||||
|
||||
#include <libgba-sprite-engine/gba/tonc_memmap.h>
|
||||
#include <libgba-sprite-engine/palette/palette_manager.h>
|
||||
#include <libgba-sprite-engine/background/text_stream.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
TextStream* TextStream::inst;
|
||||
|
||||
void TextStream::clear() {
|
||||
currRow = 0;
|
||||
currCol = 0;
|
||||
currColorIndex = 1;
|
||||
// can't actually 'clear' stuff in bitmap-mode, unless we fuck up everything else!
|
||||
|
||||
gptxt->dx= gptxt->dy= 8;
|
||||
|
||||
gptxt->dst0= vid_mem;
|
||||
gptxt->font= (u32*)toncfontTiles;
|
||||
gptxt->chars= txt_lut;
|
||||
gptxt->cws= NULL;
|
||||
|
||||
int ii;
|
||||
for(ii=0; ii<96; ii++)
|
||||
gptxt->chars[ii+32]= ii;
|
||||
}
|
||||
|
||||
TextStream::TextStream() {
|
||||
gptxt = &__txt_base;
|
||||
clear();
|
||||
}
|
||||
|
||||
TextStream& TextStream::instance() {
|
||||
if(!inst) {
|
||||
inst = new TextStream();
|
||||
}
|
||||
return *inst;
|
||||
}
|
||||
|
||||
void TextStream::setText(std::string text, int row, int col) {
|
||||
setText(text.c_str(), row, col);
|
||||
}
|
||||
|
||||
// thank you cern/tonclib
|
||||
void TextStream::setText(const char* text, int yPos, int xPos) {
|
||||
/*
|
||||
INLINE void m4_puts(int x, int y, const char *str, u8 clrid)
|
||||
{ bm8_puts(&vid_page[(y*240+x)>>1], str, clrid); }
|
||||
*/
|
||||
|
||||
u16 *dst = &vid_page[(yPos*240*TEXT_WIDTH+xPos)>>1];
|
||||
int c, x=0, dx= gptxt->dx>>1;
|
||||
|
||||
while((c=*text++) != 0)
|
||||
{
|
||||
if(c == '\n') // line break
|
||||
{
|
||||
dst += 120*gptxt->dy;
|
||||
x=0;
|
||||
}
|
||||
else // normal character
|
||||
{
|
||||
int ix, iy;
|
||||
u32 row, pxs;
|
||||
|
||||
// point to glyph; each line is one byte
|
||||
u8 *pch= (u8*)&gptxt->font[2*gptxt->chars[c]];
|
||||
for(iy=0; iy<8; iy++)
|
||||
{
|
||||
row= pch[iy];
|
||||
for(ix=x; row>0; row >>= 2, ix++)
|
||||
{
|
||||
pxs= dst[iy*120+ix];
|
||||
if(row&1)
|
||||
pxs= (pxs&0xFF00) | currColorIndex;
|
||||
if(row&2)
|
||||
pxs= (pxs&0x00FF) | (currColorIndex<<8);
|
||||
|
||||
dst[iy*120+ix]= pxs;
|
||||
}
|
||||
}
|
||||
x += dx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TextStream& TextStream::operator<<(const int s) {
|
||||
return *this << std::to_string(s).c_str();
|
||||
}
|
||||
|
||||
TextStream& TextStream::operator<<(const u32 s) {
|
||||
return *this << std::to_string(s).c_str();
|
||||
}
|
||||
|
||||
TextStream& TextStream::operator<<(const bool s) {
|
||||
return *this << (s ? "TRUE" : "FALSE");
|
||||
}
|
||||
|
||||
TextStream& TextStream::operator<<(const char * s) {
|
||||
setText(s, currRow, currCol);
|
||||
currRow++;
|
||||
return *this;
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
@=======================================================================
|
||||
@
|
||||
@ toncfont, 128x48@1,
|
||||
@ + 96 tiles not compressed
|
||||
@ Total size: 768 = 768
|
||||
@
|
||||
@ Time-stamp: 2006-05-09, 00:37:31
|
||||
@ Exported by Cearn's Usenti v1.7.4
|
||||
@ (comments, kudos, flames to "daytshen@hotmail.com")
|
||||
@
|
||||
@=======================================================================
|
||||
|
||||
.section .rodata
|
||||
.align 2
|
||||
.global toncfontTiles @ 768 bytes
|
||||
toncfontTiles:
|
||||
.word 0x00000000,0x00000000,0x18181818,0x00180018,0x00003636,0x00000000,0x367F3636,0x0036367F
|
||||
.word 0x3C067C18,0x00183E60,0x1B356600,0x0033566C,0x6E16361C,0x00DE733B,0x000C1818,0x00000000
|
||||
.word 0x0C0C1830,0x0030180C,0x3030180C,0x000C1830,0xFF3C6600,0x0000663C,0x7E181800,0x00001818
|
||||
.word 0x00000000,0x0C181800,0x7E000000,0x00000000,0x00000000,0x00181800,0x183060C0,0x0003060C
|
||||
.word 0x7E76663C,0x003C666E,0x181E1C18,0x00181818,0x3060663C,0x007E0C18,0x3860663C,0x003C6660
|
||||
.word 0x33363C38,0x0030307F,0x603E067E,0x003C6660,0x3E060C38,0x003C6666,0x3060607E,0x00181818
|
||||
.word 0x3C66663C,0x003C6666,0x7C66663C,0x001C3060,0x00181800,0x00181800,0x00181800,0x0C181800
|
||||
.word 0x06186000,0x00006018,0x007E0000,0x0000007E,0x60180600,0x00000618,0x3060663C,0x00180018
|
||||
|
||||
.word 0x5A5A663C,0x003C067A,0x7E66663C,0x00666666,0x3E66663E,0x003E6666,0x06060C78,0x00780C06
|
||||
.word 0x6666361E,0x001E3666,0x1E06067E,0x007E0606,0x1E06067E,0x00060606,0x7606663C,0x007C6666
|
||||
.word 0x7E666666,0x00666666,0x1818183C,0x003C1818,0x60606060,0x003C6660,0x0F1B3363,0x0063331B
|
||||
.word 0x06060606,0x007E0606,0x6B7F7763,0x00636363,0x7B6F6763,0x00636373,0x6666663C,0x003C6666
|
||||
.word 0x3E66663E,0x00060606,0x3333331E,0x007E3B33,0x3E66663E,0x00666636,0x3C0E663C,0x003C6670
|
||||
.word 0x1818187E,0x00181818,0x66666666,0x003C6666,0x66666666,0x00183C3C,0x6B636363,0x0063777F
|
||||
.word 0x183C66C3,0x00C3663C,0x183C66C3,0x00181818,0x0C18307F,0x007F0306,0x0C0C0C3C,0x003C0C0C
|
||||
.word 0x180C0603,0x00C06030,0x3030303C,0x003C3030,0x00663C18,0x00000000,0x00000000,0x003F0000
|
||||
|
||||
.word 0x00301818,0x00000000,0x603C0000,0x007C667C,0x663E0606,0x003E6666,0x063C0000,0x003C0606
|
||||
.word 0x667C6060,0x007C6666,0x663C0000,0x003C067E,0x0C3E0C38,0x000C0C0C,0x667C0000,0x3C607C66
|
||||
.word 0x663E0606,0x00666666,0x18180018,0x00301818,0x30300030,0x1E303030,0x36660606,0x0066361E
|
||||
.word 0x18181818,0x00301818,0x7F370000,0x0063636B,0x663E0000,0x00666666,0x663C0000,0x003C6666
|
||||
.word 0x663E0000,0x06063E66,0x667C0000,0x60607C66,0x663E0000,0x00060606,0x063C0000,0x003E603C
|
||||
.word 0x0C3E0C0C,0x00380C0C,0x66660000,0x007C6666,0x66660000,0x00183C66,0x63630000,0x00367F6B
|
||||
.word 0x36630000,0x0063361C,0x66660000,0x0C183C66,0x307E0000,0x007E0C18,0x0C181830,0x00301818
|
||||
.word 0x18181818,0x00181818,0x3018180C,0x000C1818,0x003B6E00,0x00000000,0x00000000,0x00000000
|
||||
|
Loading…
Reference in new issue