Large fonts on the BrainPad (G30)

I did a small trick I learned from John where I simply draw each pixel 4 times and the font is suddenly larger. However this was extremely slow, maybe 5 characters per second. This was the bottleneck!


        private static void Draw8LargePixelsSlow(int x, int y, byte c, BrainPad.Color.Palette color)
        {
            for (int i = 0; i < 8; i++)
            {
                if (((c >> i) & 1) > 0)
                {
                    SetPixel(x, y + i * 2, color);
                    SetPixel(x + 1, y + i * 2, color);
                    SetPixel(x, y + i * 2 + 1, color);
                    SetPixel(x + 1, y + i * 2 + 1, color);

                }
                else
                {
                    SetPixel(x, y + i * 2, 0);
                    SetPixel(x + 1, y + i * 2, 0);
                    SetPixel(x, y + i * 2 + 1, 0);
                    SetPixel(x + 1, y + i * 2 + 1, 0);
                }
            }

        }

I then changed this to draw the pixels to a temp array that I sent all together. It is like 100 times faster now!! I knew it wild going to be faster but the difference was a lot more than I had expected.


       private static byte[] largechartemp = new byte[8 * 2*2];
        private static void Draw8LargePixels(int x, int y, byte c, ushort color)
        {
            Array.Clear(largechartemp, 0, largechartemp.Length);

            for (int i = 0; i < 8; i++)
            {
                if (((c >> i) & 1) > 0)
                {
                    largechartemp[i * 4 + 0] = (byte)(color >> 8);
                    largechartemp[i * 4 + 1] = (byte)(color >> 0);
                    largechartemp[i * 4 + 2] = (byte)(color >> 8);
                    largechartemp[i * 4 + 3] = (byte)(color >> 0);
                }
            }
            SetClip(x, y, 1, 16);
            WriteCommand(0x2C);
            WriteData(largechartemp);
            
            SetClip(x+1, y, 1, 16);
            WriteCommand(0x2C);
            WriteData(largechartemp);
        }

Remember that the Brain Pad is based on the G30 so any code you see just drops in your next G30 project.

3 Likes