Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2016-05-02 04:02:17

bbsfoo
Member
Registered: 2016-02-08
Posts: 16

Is there something wrong with my code?

#define FONT_COUNT 1024
const unsigned char font[FONT_COUNT] =
{
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    // Char 000 (.)
    0x7E, 0x81, 0xA5, 0x81, 0xBD, 0x99, 0x81, 0x7E,    // Char 001 (.)
    0x7E, 0xFF, 0xDB, 0xFF, 0xC3, 0xE7, 0xFF, 0x7E,    // Char 002 (.)
    0x6C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38, 0x10, 0x00,    // Char 003 (.)
    0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x10, 0x00,    // Char 004 (.)
    0x38, 0x7C, 0x38, 0xFE, 0xFE, 0x7C, 0x38, 0x7C,    // Char 005 (.)
    0x10, 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x7C,    // Char 006 (.)
    0x00, 0x00, 0x18, 0x3C, 0x3C, 0x18, 0x00, 0x00,    // Char 007 (.)
    0xFF, 0xFF, 0xE7, 0xC3, 0xC3, 0xE7, 0xFF, 0xFF,    // Char 008 (.)
    0x00, 0x3C, 0x66, 0x42, 0x42, 0x66, 0x3C, 0x00,    // Char 009 (.)
    0xFF, 0xC3, 0x99, 0xBD, 0xBD, 0x99, 0xC3, 0xFF,    // Char 010 (.)
    0x0F, 0x07, 0x0F, 0x7D, 0xCC, 0xCC, 0xCC, 0x78,    // Char 011 (.)
    0x3C, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x18,    // Char 012 (.)
    0x3F, 0x33, 0x3F, 0x30, 0x30, 0x70, 0xF0, 0xE0,    // Char 013 (.)
    0x7F, 0x63, 0x7F, 0x63, 0x63, 0x67, 0xE6, 0xC0,    // Char 014 (.)
    0x99, 0x5A, 0x3C, 0xE7, 0xE7, 0x3C, 0x5A, 0x99,    // Char 015 (.)
    0x80, 0xE0, 0xF8, 0xFE, 0xF8, 0xE0, 0x80, 0x00,    // Char 016 (.)
    0x02, 0x0E, 0x3E, 0xFE, 0x3E, 0x0E, 0x02, 0x00,    // Char 017 (.)
    0x18, 0x3C, 0x7E, 0x18, 0x18, 0x7E, 0x3C, 0x18,    // Char 018 (.)
    0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00,    // Char 019 (.)
    0x7F, 0xDB, 0xDB, 0x7B, 0x1B, 0x1B, 0x1B, 0x00,    // Char 020 (.)
    0x3E, 0x63, 0x38, 0x6C, 0x6C, 0x38, 0xCC, 0x78,    // Char 021 (.)
    0x00, 0x00, 0x00, 0x00, 0x7E, 0x7E, 0x7E, 0x00,    // Char 022 (.)
    0x18, 0x3C, 0x7E, 0x18, 0x7E, 0x3C, 0x18, 0xFF,    // Char 023 (.)
    0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x00,    // Char 024 (.)
    0x18, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x00,    // Char 025 (.)
    0x00, 0x18, 0x0C, 0xFE, 0x0C, 0x18, 0x00, 0x00,    // Char 026 (.)
    0x00, 0x30, 0x60, 0xFE, 0x60, 0x30, 0x00, 0x00,    // Char 027 (.)
    0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xFE, 0x00, 0x00,    // Char 028 (.)
    0x00, 0x24, 0x66, 0xFF, 0x66, 0x24, 0x00, 0x00,    // Char 029 (.)
    0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x00, 0x00,    // Char 030 (.)
    0x00, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, 0x00, 0x00,    // Char 031 (.)
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    // Char 032 ( )
    0x30, 0x78, 0x78, 0x30, 0x30, 0x00, 0x30, 0x00,    // Char 033 (!)
    0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00,    // Char 034 (")
    0x6C, 0x6C, 0xFE, 0x6C, 0xFE, 0x6C, 0x6C, 0x00,    // Char 035 (#)
    0x30, 0x7C, 0xC0, 0x78, 0x0C, 0xF8, 0x30, 0x00,    // Char 036 ($)
    0x00, 0xC6, 0xCC, 0x18, 0x30, 0x66, 0xC6, 0x00,    // Char 037 (%)
    0x38, 0x6C, 0x38, 0x76, 0xDC, 0xCC, 0x76, 0x00,    // Char 038 (&)
    0x60, 0x60, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,    // Char 039 (')
    0x18, 0x30, 0x60, 0x60, 0x60, 0x30, 0x18, 0x00,    // Char 040 (()
    0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00,    // Char 041 ())
    0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00,    // Char 042 (*)
    0x00, 0x30, 0x30, 0xFC, 0x30, 0x30, 0x00, 0x00,    // Char 043 (+)
    0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x60,    // Char 044 (,)
    0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00,    // Char 045 (-)
    0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00,    // Char 046 (.)
    0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0x80, 0x00,    // Char 047 (/)
    0x7C, 0xC6, 0xCE, 0xDE, 0xF6, 0xE6, 0x7C, 0x00,    // Char 048 (0)
    0x30, 0x70, 0x30, 0x30, 0x30, 0x30, 0xFC, 0x00,    // Char 049 (1)
    0x78, 0xCC, 0x0C, 0x38, 0x60, 0xCC, 0xFC, 0x00,    // Char 050 (2)
    0x78, 0xCC, 0x0C, 0x38, 0x0C, 0xCC, 0x78, 0x00,    // Char 051 (3)
    0x1C, 0x3C, 0x6C, 0xCC, 0xFE, 0x0C, 0x1E, 0x00,    // Char 052 (4)
    0xFC, 0xC0, 0xF8, 0x0C, 0x0C, 0xCC, 0x78, 0x00,    // Char 053 (5)
    0x38, 0x60, 0xC0, 0xF8, 0xCC, 0xCC, 0x78, 0x00,    // Char 054 (6)
    0xFC, 0xCC, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x00,    // Char 055 (7)
    0x78, 0xCC, 0xCC, 0x78, 0xCC, 0xCC, 0x78, 0x00,    // Char 056 (8)
    0x78, 0xCC, 0xCC, 0x7C, 0x0C, 0x18, 0x70, 0x00,    // Char 057 (9)
    0x00, 0x30, 0x30, 0x00, 0x00, 0x30, 0x30, 0x00,    // Char 058 (smile
    0x00, 0x30, 0x30, 0x00, 0x00, 0x30, 0x30, 0x60,    // Char 059 (wink
    0x18, 0x30, 0x60, 0xC0, 0x60, 0x30, 0x18, 0x00,    // Char 060 (<)
    0x00, 0x00, 0xFC, 0x00, 0x00, 0xFC, 0x00, 0x00,    // Char 061 (smile
    0x60, 0x30, 0x18, 0x0C, 0x18, 0x30, 0x60, 0x00,    // Char 062 (>)
    0x78, 0xCC, 0x0C, 0x18, 0x30, 0x00, 0x30, 0x00,    // Char 063 (?)
    0x7C, 0xC6, 0xDE, 0xDE, 0xDE, 0xC0, 0x78, 0x00,    // Char 064 (@)
    0x30, 0x78, 0xCC, 0xCC, 0xFC, 0xCC, 0xCC, 0x00,    // Char 065 (A)
    0xFC, 0x66, 0x66, 0x7C, 0x66, 0x66, 0xFC, 0x00,    // Char 066 (B)
    0x3C, 0x66, 0xC0, 0xC0, 0xC0, 0x66, 0x3C, 0x00,    // Char 067 (C)
    0xF8, 0x6C, 0x66, 0x66, 0x66, 0x6C, 0xF8, 0x00,    // Char 068 (D)
    0xFE, 0x62, 0x68, 0x78, 0x68, 0x62, 0xFE, 0x00,    // Char 069 (E)
    0xFE, 0x62, 0x68, 0x78, 0x68, 0x60, 0xF0, 0x00,    // Char 070 (F)
    0x3C, 0x66, 0xC0, 0xC0, 0xCE, 0x66, 0x3E, 0x00,    // Char 071 (G)
    0xCC, 0xCC, 0xCC, 0xFC, 0xCC, 0xCC, 0xCC, 0x00,    // Char 072 (H)
    0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00,    // Char 073 (I)
    0x1E, 0x0C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78, 0x00,    // Char 074 (J)
    0xE6, 0x66, 0x6C, 0x78, 0x6C, 0x66, 0xE6, 0x00,    // Char 075 (K)
    0xF0, 0x60, 0x60, 0x60, 0x62, 0x66, 0xFE, 0x00,    // Char 076 (L)
    0xC6, 0xEE, 0xFE, 0xFE, 0xD6, 0xC6, 0xC6, 0x00,    // Char 077 (M)
    0xC6, 0xE6, 0xF6, 0xDE, 0xCE, 0xC6, 0xC6, 0x00,    // Char 078 (N)
    0x38, 0x6C, 0xC6, 0xC6, 0xC6, 0x6C, 0x38, 0x00,    // Char 079 (O)
    0xFC, 0x66, 0x66, 0x7C, 0x60, 0x60, 0xF0, 0x00,    // Char 080 (P)
    0x78, 0xCC, 0xCC, 0xCC, 0xDC, 0x78, 0x1C, 0x00,    // Char 081 (Q)
    0xFC, 0x66, 0x66, 0x7C, 0x6C, 0x66, 0xE6, 0x00,    // Char 082 (R)
    0x78, 0xCC, 0xE0, 0x70, 0x1C, 0xCC, 0x78, 0x00,    // Char 083 (S)
    0xFC, 0xB4, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00,    // Char 084 (T)
    0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xFC, 0x00,    // Char 085 (U)
    0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x00,    // Char 086 (V)
    0xC6, 0xC6, 0xC6, 0xD6, 0xFE, 0xEE, 0xC6, 0x00,    // Char 087 (W)
    0xC6, 0xC6, 0x6C, 0x38, 0x38, 0x6C, 0xC6, 0x00,    // Char 088 (X)
    0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x30, 0x78, 0x00,    // Char 089 (Y)
    0xFE, 0xC6, 0x8C, 0x18, 0x32, 0x66, 0xFE, 0x00,    // Char 090 (Z)
    0x78, 0x60, 0x60, 0x60, 0x60, 0x60, 0x78, 0x00,    // Char 091 ([)
    0xC0, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x02, 0x00,    // Char 092 (\)
    0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x00,    // Char 093 (])
    0x10, 0x38, 0x6C, 0xC6, 0x00, 0x00, 0x00, 0x00,    // Char 094 (^)
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,    // Char 095 (_)
    0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,    // Char 096 (`)
    0x00, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00,    // Char 097 (a)
    0xE0, 0x60, 0x60, 0x7C, 0x66, 0x66, 0xDC, 0x00,    // Char 098 (b)
    0x00, 0x00, 0x78, 0xCC, 0xC0, 0xCC, 0x78, 0x00,    // Char 099 (c)
    0x1C, 0x0C, 0x0C, 0x7C, 0xCC, 0xCC, 0x76, 0x00,    // Char 100 (d)
    0x00, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00,    // Char 101 (e)
    0x38, 0x6C, 0x60, 0xF0, 0x60, 0x60, 0xF0, 0x00,    // Char 102 (f)
    0x00, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8,    // Char 103 (g)
    0xE0, 0x60, 0x6C, 0x76, 0x66, 0x66, 0xE6, 0x00,    // Char 104 (h)
    0x30, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00,    // Char 105 (i)
    0x0C, 0x00, 0x0C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78,    // Char 106 (j)
    0xE0, 0x60, 0x66, 0x6C, 0x78, 0x6C, 0xE6, 0x00,    // Char 107 (k)
    0x70, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00,    // Char 108 (l)
    0x00, 0x00, 0xCC, 0xFE, 0xFE, 0xD6, 0xC6, 0x00,    // Char 109 (m)
    0x00, 0x00, 0xF8, 0xCC, 0xCC, 0xCC, 0xCC, 0x00,    // Char 110 (n)
    0x00, 0x00, 0x78, 0xCC, 0xCC, 0xCC, 0x78, 0x00,    // Char 111 (o)
    0x00, 0x00, 0xDC, 0x66, 0x66, 0x7C, 0x60, 0xF0,    // Char 112 (p)
    0x00, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0x1E,    // Char 113 (q)
    0x00, 0x00, 0xDC, 0x76, 0x66, 0x60, 0xF0, 0x00,    // Char 114 (r)
    0x00, 0x00, 0x7C, 0xC0, 0x78, 0x0C, 0xF8, 0x00,    // Char 115 (s)
    0x10, 0x30, 0x7C, 0x30, 0x30, 0x34, 0x18, 0x00,    // Char 116 (t)
    0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00,    // Char 117 (u)
    0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x00,    // Char 118 (v)
    0x00, 0x00, 0xC6, 0xD6, 0xFE, 0xFE, 0x6C, 0x00,    // Char 119 (w)
    0x00, 0x00, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0x00,    // Char 120 (x)
    0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8,    // Char 121 (y)
    0x00, 0x00, 0xFC, 0x98, 0x30, 0x64, 0xFC, 0x00,    // Char 122 (z)
    0x1C, 0x30, 0x30, 0xE0, 0x30, 0x30, 0x1C, 0x00,    // Char 123 ({)
    0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00,    // Char 124 (|)
    0xE0, 0x30, 0x30, 0x1C, 0x30, 0x30, 0xE0, 0x00,    // Char 125 (})
    0x76, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    // Char 126 (~)
    0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0x00,    // Char 127 (.)
};


int  x;
int  y;

#define REGISTER(address)    (*(volatile unsigned char *)address)

#define JOYPAD        REGISTER(0xff00)
#define SCX            REGISTER(0xff43)
#define SCY            REGISTER(0xff42)

#define LCDC        REGISTER(0xff40)
#define LCDSTAT        REGISTER(0xff41)
#define JOYPAD        REGISTER(0xff00)
#define LY            REGISTER(0xff44)

#define    VRAM_START_ADDRESS    0x8000
#define GB_MAP_ADDRESS        0x9800


#define COL_MAX                20
#define ROW_MAX                18

typedef unsigned char uint8;

void wait_for_vblank()
{

    while (LY != 144);

}


void turn_off_lcd()
{
    wait_for_vblank();
    LCDC = LCDC & 0x7f;

}

void turn_on_lcd()
{

    LCDC = LCDC | 0x80;
}

void initialize_text_mode()
{
    int i;
    unsigned char *dest;
   
    turn_off_lcd();
   
    LCDC = LCDC | (1<<0);
    LCDC = LCDC | (1<<4);
    LCDC = LCDC & (~(1<<3));

    i = 0;
    dest = (unsigned char *)VRAM_START_ADDRESS;
    while (i < FONT_COUNT)
    {
        *dest++ = ~font[i];
        *dest++ = ~font[i];
        i++;
    }


    for (i=0; i<32*32; i++)
    {
        *((unsigned char *)GB_MAP_ADDRESS + i) = 0;
    }


    x = 0;
    y = 0;
   
    turn_on_lcd();
}


void putc2(char c)
{
    unsigned char *p;

    p = (unsigned char *)GB_MAP_ADDRESS + (y<<5) + x;
   
    while (LCDSTAT & 0x02);
   

    *p = c;
    x++;
    if (x == COL_MAX)
    {
        y++;
        x=0;
    }

}

void puts2(char *s)
{
    while(*s != 0)
        putc2(*s++);

}

void main()
{
    initialize_text_mode();

    puts2("ABC");


}


look this

        *dest++ = ~font[i];
        *dest++ = ~font[i];
or this
        *dest++ = font[i];
        *dest++ = font[i];
above is ok,
but
        *dest++ = ~font[i];
        *dest++ = font[i];
or this
        *dest++ = font[i];
        *dest++ = ~font[i];
nothing display
why????

Offline

 

#2 2016-05-02 14:27:52

Tauwasser
Member
Registered: 2010-10-23
Posts: 160

Re: Is there something wrong with my code?

Your routine does a 1bpp to 2bpp conversion.

Code:

        *dest++ = ~font[i];
        *dest++ = ~font[i];

All font '1' bits become a '0' bit in dest. All '0' bits become a '1' bit in dest. Therefore, 1bpp color 0 maps to 2bpp color 3, 1bpp color 1 maps to 2bpp color 0.

Code:

        *dest++ = font[i];
        *dest++ = font[i];

Bits stay the same, therefore, 1bpp color 0 maps to 2bpp color 0, 1bpp color 1 maps to 2bpp color 3.

Code:

        *dest++ = ~font[i];
        *dest++ = font[i];

Mixed bits. 1bpp color 0 maps to 2bpp color 1, 1bpp color 1 maps to 2bpp color 2.

Code:

        *dest++ = font[i];
        *dest++ = ~font[i];

Mixed bits. 1bpp color 0 maps to 2bpp color 1, 1bpp color 2 maps to 2bpp color 1.

So I suggest, if regular display (0 -> 0, 1 -> 3) and inverted display (0 -> 3, 1 -> 0) work, then you probably have the same two shades in palette entries 1 and 2 and therefore don't see dot data.
You can confirm this if you use BGB and view the VRAM data without palettes (uncheck the box) or alternatively check the palette entries.

cYa,

Tauwasser

Offline

 

#3 2016-05-03 05:00:38

bbsfoo
Member
Registered: 2016-02-08
Posts: 16

Re: Is there something wrong with my code?

Tauwasser wrote:

Your routine does a 1bpp to 2bpp conversion.

Code:

        *dest++ = ~font[i];
        *dest++ = ~font[i];

All font '1' bits become a '0' bit in dest. All '0' bits become a '1' bit in dest. Therefore, 1bpp color 0 maps to 2bpp color 3, 1bpp color 1 maps to 2bpp color 0.

Code:

        *dest++ = font[i];
        *dest++ = font[i];

Bits stay the same, therefore, 1bpp color 0 maps to 2bpp color 0, 1bpp color 1 maps to 2bpp color 3.

Code:

        *dest++ = ~font[i];
        *dest++ = font[i];

Mixed bits. 1bpp color 0 maps to 2bpp color 1, 1bpp color 1 maps to 2bpp color 2.

Code:

        *dest++ = font[i];
        *dest++ = ~font[i];

Mixed bits. 1bpp color 0 maps to 2bpp color 1, 1bpp color 2 maps to 2bpp color 1.

So I suggest, if regular display (0 -> 0, 1 -> 3) and inverted display (0 -> 3, 1 -> 0) work, then you probably have the same two shades in palette entries 1 and 2 and therefore don't see dot data.
You can confirm this if you use BGB and view the VRAM data without palettes (uncheck the box) or alternatively check the palette entries.

cYa,

Tauwasser

thank you very much.
when i set the BGP register, everythink is ok!!

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson