반정도 성공 했을까나요...
GyonG님 Ndslib 소스를 거의 95%이상은 Palib용으로 바꾼듯하네요.
문제는 GyonG님은 배경도 버퍼로 처리하셨던 터라 Tile이나 sprite로 깔아놓은 배경에서 픽셀 가져오는 방법/예외 처리하는데 문제가 좀 있는거같네요.
폰트의 배경중 투명하게 보이는 부분은 그냥 Data가 없을때 skip해 버린거라서 좀 막장코딩이네요.
결국 가져온 배경은 쓴거같지않은 색을 가져오고... 메모리 문제인가...
뭐 저녁에는 거의 될것도 같네요.
소스는 정리가 거의 안돼있어서... 올리긴하는데 저녁에 다시 수정하겠습니다.
void Graphics::drawString(int x, int y, const char *str)
{
int target_Screen;
// Palib
if(m_pimpl->activeLcd == Graphics::UPPER_LCD) target_Screen = 1;
else target_Screen = 0;
Font *pFont = m_pimpl->pFont;
int line_height = pFont->getHeight();
//int width = pFont->getWidth();
unsigned int color32 = (m_pimpl->color | (m_pimpl->color << 16)) & 0x3E07C1F;
// get color x, y
//nds_color top = PA_Get16bitPixel(target_Screen, x, y);
nds_color top;
int orig_x = x;
for (; *str; str++) {
unsigned short ch = (unsigned char)*str;
if (ch & 0x80) {
ch = (ch << 8) | (unsigned char)*++str;
}
int width, height;
unsigned int *pData = pFont->getData(ch, &width, &height);
if (!pData)
continue;
// next line
if (x + width >= SCREEN_WIDTH) {
x = orig_x;
y += line_height;
//top = PA_Get16bitPixel(target_Screen, x, y);
}
// nds_color *bottom = top + height * SCREEN_WIDTH;
unsigned int data = *pData;
int shift_count = 0;
nds_color tempTop[6];
// set...
for (int ix = 0; ix < width; ix++) {
//nds_color *curr = top;
for (int iy = 0; iy < height; iy++) {
top = 0;
// check bg color(ix, iy) - white-65535 / black-32768 / transparent - 0 / MAGENTA -- 64543
// check transparent color // only work if now prio 0 / under 1 sprite / 1,2 use bg
tempTop[3] = PA_EasyBgGetPixelCol(target_Screen, 2, x + ix, y + iy);
tempTop[2] = PA_EasyBgGetPixelCol(target_Screen, 1, x + ix, y + iy);
//tempTop[3] = PA_EasyBgGetPixelCol(target_Screen, 0, x + ix, y + iy);
// showing sprite
//tempTop[1] = PA_GetSpritePixel(target_Screen, 101, x + ix, y + iy);
tempTop[1] = PA_GetSpritePixel(target_Screen, 100, x + ix, y + iy);
// on 16bitbg
tempTop[0] = PA_Get16bitPixel(target_Screen, x + ix, y + iy);
for(s8 si=0;si<4;si++) {
if(!(tempTop[si]==0 || tempTop[si]==64543)) {
top=tempTop[si];
break;
}
else top = 0;
}
// load data color
if (++shift_count >= 8) {
shift_count = 0;
data = *(++pData);
} else {
data >>= 4;
}
if(data!=0 && top!=0 && top!=64543) {
int alpha = data & 0x0F;
u32 dst = top;
dst = (dst | (dst << 16)) & 0x3E07C1F;
u32 result = ((color32 - dst) * alpha / 8 + dst) & 0x3E07C1F;
// Put a pixel
// *curr = result | (result >> 16) | BIT(15);
PA_Put16bitPixel(target_Screen, x + ix, y + iy, result | (result >> 16) | BIT(15));
}
PA_Print(1, "%c4d: %d t: %d\n", data, top);
//Pause(1000);
}
if (shift_count > 0) {
shift_count = 0;
data = *(++pData);
}
}
x += width;
}
}