Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#include "nyan.h"
#define WIDTH 240
#define HEIGHT 320
#define CWIDTH 8
#define CHEIGHT 15
struct frame_descriptor {
void* FDADR;
void* FSADR;
uint32_t FIDR;
uint32_t LCDCMD;
};
void draw_char(uint16_t *fb, char c, int x0, int y0)
{
char *font = (void*)0x80008f50;
char *glyph = font + (c*15);
for (int dy=0; dy<CHEIGHT; dy++) {
for (int dx=0; dx<CWIDTH; dx++) {
if ((glyph[dy] >> (7-dx)) & 1) {
fb[(y0+dy)*WIDTH+(x0+dx)] = 0xffff;
}
}
}
}
void draw_str(uint16_t *fb, char *str, int x0, int y0)
{
while (*str) {
draw_char(fb, *str++, x0, y0);
x0 += CWIDTH;
}
}
static int lut[] = {0, 1608, 3215, 4821, 6423, 8022, 9616, 11204, 12785, 14359, 15923, 17479, 19024, 20557, 22078, 23586, 25079, 26557, 28020, 29465, 30893, 32302, 33692, 35061, 36409, 37736, 39039, 40319, 41575, 42806, 44011, 45189, 46340, 47464, 48558, 49624, 50660, 51665, 52639, 53581, 54491, 55368, 56212, 57022, 57797, 58538, 59243, 59913, 60547, 61144, 61705, 62228, 62714, 63162, 63571, 63943, 64276, 64571, 64826, 65043, 65220, 65358, 65457, 65516, 65536, 65516, 65457, 65358, 65220, 65043, 64826, 64571, 64276, 63943, 63571, 63162, 62714, 62228, 61705, 61144, 60547, 59913, 59243, 58538, 57797, 57022, 56212, 55368, 54491, 53581, 52639, 51665, 50660, 49624, 48558, 47464, 46340, 45189, 44011, 42806, 41575, 40319, 39039, 37736, 36409, 35061, 33692, 32302, 30893, 29465, 28020, 26557, 25079, 23586, 22078, 20557, 19024, 17479, 15923, 14359, 12785, 11204, 9616, 8022, 6423, 4821, 3215, 1608, 0, -1609, -3216, -4822, -6424, -8023, -9617, -11205, -12786, -14360, -15924, -17480, -19025, -20558, -22079, -23587, -25080, -26558, -28021, -29466, -30894, -32303, -33693, -35062, -36410, -37737, -39040, -40320, -41576, -42807, -44012, -45190, -46341, -47465, -48559, -49625, -50661, -51666, -52640, -53582, -54492, -55369, -56213, -57023, -57798, -58539, -59244, -59914, -60548, -61145, -61706, -62229, -62715, -63163, -63572, -63944, -64277, -64572, -64827, -65044, -65221, -65359, -65458, -65517, -65536, -65517, -65458, -65359, -65221, -65044, -64827, -64572, -64277, -63944, -63572, -63163, -62715, -62229, -61706, -61145, -60548, -59914, -59244, -58539, -57798, -57023, -56213, -55369, -54492, -53582, -52640, -51666, -50661, -49625, -48559, -47465, -46341, -45190, -44012, -42807, -41576, -40320, -39040, -37737, -36410, -35062, -33693, -32303, -30894, -29466, -28021, -26558, -25080, -23587, -22079, -20558, -19025, -17480, -15924, -14360, -12786, -11205, -9617, -8023, -6424, -4822, -3216, -1609};
int main(void)
{
void (*sleep)(int duration) = (void(*)(int))0x8000ece8;
struct frame_descriptor *fd = (void*)0xa400a000;
uint16_t *fb = (void*)0xa400a280;
//volatile void **FDADR0 = (void*)0x9e200200;
//volatile uint32_t *CCCR = (volatile uint32_t*)0xad300000;
//*CCCR = 0b0101100101;
// Enter Frequency Change Sequence
//__asm__ __volatile__ ("MCR p14, 0, %0, c6, c0, 0" ::"r"(0b10));
*(uint32_t*)&fb ^= 0x40000;
int ni=0;
for (int i=0;; i=((i+2)&0xff)) {
for (int y=0; y<HEIGHT; y++) {
for (int x=0; x<WIDTH; x++) {
fb[y*WIDTH+x] = ((x+i)^(y+i))/4;
}
}
char msg[] = "Hello baremetal armv5te world!";
/*draw_str(fb, msg, 0, 0);
for (int y=0; y<16; y++) {
for (int x=0; x<16; x++) {
draw_char(fb, y*16+x, x*CWIDTH, (y+2)*CHEIGHT);
}
}*/
for (int x=0; x<30; x++) {
draw_char(fb, msg[x], x*CWIDTH, 80 + lut[(i*4+(x*8))&0xff]/0x1000);
}
for (int y=0; y<NYAN_HEIGHT*4; y++) {
for (int x=0; x<NYAN_WIDTH*4; x++) {
if (nyana[ni][y/4][x/4]) {
fb[(180+y)*WIDTH+x+52] = nyan[ni][y/4][x/4];
}
}
}
if (i&2) {
ni++;
if (ni>=NYAN_FRAMES) ni = 0;
}
*(uint32_t*)&fd->FSADR ^= 0x40000;
*(uint32_t*)&fb ^= 0x40000;
sleep(20);
}
}