Skip to content

Instantly share code, notes, and snippets.

@marethyu
Last active August 5, 2021 04:21
Show Gist options
  • Select an option

  • Save marethyu/0233f2e469a00a75333a609fe4d3718b to your computer and use it in GitHub Desktop.

Select an option

Save marethyu/0233f2e469a00a75333a609fe4d3718b to your computer and use it in GitHub Desktop.
C++ program to display Nintendo logo
#include <iostream>
#define GET_BIT(n, p) ((n & (1 << (p))) != 0)
#define SET_BIT(n, p) do { n |= (1 << (p)); } while (0)
const uint8_t data[48] = {
0xCE, 0xED, 0x66, 0x66, 0xCC, 0x0D, 0x00, 0x0B, 0x03, 0x73, 0x00, 0x83,
0x00, 0x0C, 0x00, 0x0D, 0x00, 0x08, 0x11, 0x1F, 0x88, 0x89, 0x00, 0x0E,
0xDC, 0xCC, 0x6E, 0xE6, 0xDD, 0xDD, 0xD9, 0x99, 0xBB, 0xBB, 0x67, 0x63,
0x6E, 0x0E, 0xEC, 0xCC, 0xDD, 0xDC, 0x99, 0x9F, 0xBB, 0xB9, 0x33, 0x3E
};
const int ROWS = 16;
const int COLS = 96;
uint8_t mem[384];
char display[ROWS][COLS];
int idx;
uint8_t dup_bits(uint8_t n)
{
uint8_t res = 0;
for (int p = 3; p >= 0; --p)
{
if (GET_BIT(n, p))
{
SET_BIT(res, p * 2 + 1);
SET_BIT(res, p * 2);
}
}
return res;
}
char color(int i)
{
switch (i)
{
case 0: return '0';
case 1: return '1';
case 2: return '2';
case 3: return '3';
}
return '*';
}
int main()
{
idx = 0;
for (int i = 0; i < 48; ++i)
{
uint8_t row1 = dup_bits(data[i] >> 4);
uint8_t row2 = dup_bits(data[i] & 0xF);
mem[idx++] = row1;
mem[idx++] = 0x00;
mem[idx++] = row1;
mem[idx++] = 0x00;
mem[idx++] = row2;
mem[idx++] = 0x00;
mem[idx++] = row2;
mem[idx++] = 0x00;
}
int z = 0;
for (int y = 0; y < 2; ++y)
{
for (int x = 0; x < 12; ++x)
{
int row = y * 8;
for (int i = z; i < z + 16; i += 2, ++row)
{
int col = x * 8;
for (int p = 7; p >= 0; --p, ++col)
{
display[row][col] = color((GET_BIT(mem[i + 1], p) << 1) | GET_BIT(mem[i], p));
}
}
z += 16;
}
}
for (int i = 0; i < ROWS; ++i)
{
for (int j = 0; j < COLS; ++j)
{
std::cout << (display[i][j] != '1' ? ' ' : '1');
}
std::cout << std::endl;
}
return 0;
}
1111 1111 1111 1111
1111 1111 1111 1111
111111 1111 1111 1111 1111
111111 1111 1111 1111 1111
111111 1111 11111111 1111
111111 1111 11111111 1111
1111 11 1111 1111 1111 1111 1111 11111111 1111 1111 1111111111 11111111
1111 11 1111 1111 1111 1111 1111 11111111 1111 1111 1111111111 11111111
1111 11 1111 1111 111111 1111 1111 1111 1111 111111 1111 1111 1111 1111 1111
1111 11 1111 1111 111111 1111 1111 1111 1111 111111 1111 1111 1111 1111 1111
1111 111111 1111 1111 1111 1111 111111111111 1111 1111 1111 1111 1111 1111
1111 111111 1111 1111 1111 1111 111111111111 1111 1111 1111 1111 1111 1111
1111 111111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111
1111 111111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111
1111 1111 1111 1111 1111 1111 1111111111 1111 1111 1111111111 11111111
1111 1111 1111 1111 1111 1111 1111111111 1111 1111 1111111111 11111111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment