#include #include #include #include #include #include #include void sendcmd(int fd, char *cmd) { write(fd, cmd, strlen(cmd)); } struct character { int dx, dy; int mx, my; int vx, vy; int image; } ch[16]; int image_init(int fd) { char cmd[128]; sprintf(cmd, "$id0000ffffffffffffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id0001ffffff7777ffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id0002ffff77777777ffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id0003ffff77777777ffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id0004ffffff7777ffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id0005fffffff77ffff77f+"); sendcmd(fd, cmd); sprintf(cmd, "$id0006fffffff77ffff77f+"); sendcmd(fd, cmd); sprintf(cmd, "$id0007f77777777777777f+"); sendcmd(fd, cmd); sprintf(cmd, "$id0008f77777777777777f+"); sendcmd(fd, cmd); sprintf(cmd, "$id0009f77fff1111ffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id000af77fff1111ffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id000bffffff2222ffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id000cfffff222222fffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id000dffff222ff222ffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id000efff222ffff222fff+"); sendcmd(fd, cmd); sprintf(cmd, "$id000f222222ffff222222+"); sendcmd(fd, cmd); sprintf(cmd, "$id0100ffffffffffffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id0101ffffff2222ffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id0102ffff22222222ffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id0103ffff22222222ffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id0104ffffff2222ffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id0105fffffff22ffff77f+"); sendcmd(fd, cmd); sprintf(cmd, "$id0106fffffff22ffff77f+"); sendcmd(fd, cmd); sprintf(cmd, "$id0107f77777777777777f+"); sendcmd(fd, cmd); sprintf(cmd, "$id0108f77777777777777f+"); sendcmd(fd, cmd); sprintf(cmd, "$id0109f77fff3333ffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id010af77fff3333ffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id010bffffff1111ffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id010cfffff111111fffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id010dffff111ff111ffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id010efff111ffff111fff+"); sendcmd(fd, cmd); sprintf(cmd, "$id010f111111ffff111111+"); sendcmd(fd, cmd); sprintf(cmd, "$id0200ffffffffffffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id0201ffffff4444ffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id0202ff444444444444ff+"); sendcmd(fd, cmd); sprintf(cmd, "$id0203f4442442442444ff+"); sendcmd(fd, cmd); sprintf(cmd, "$id0204f44442424242244f+"); sendcmd(fd, cmd); sprintf(cmd, "$id0205f44224242424444f+"); sendcmd(fd, cmd); sprintf(cmd, "$id0206f44442222222444f+"); sendcmd(fd, cmd); sprintf(cmd, "$id0207ff444422222444ff+"); sendcmd(fd, cmd); sprintf(cmd, "$id0208ffff44222244ffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id0209ffffff2222ffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id020affffff2222ffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id020bffffff2222ffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id020cfffff22222ffffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id020dffff22222222ffff+"); sendcmd(fd, cmd); sprintf(cmd, "$id020eff222fff2222222f+"); sendcmd(fd, cmd); sprintf(cmd, "$id020ff22fff22ff2f2fff+"); sendcmd(fd, cmd); sprintf(cmd, "$id03000055555555555000+"); sendcmd(fd, cmd); sprintf(cmd, "$id03015550005555555555+"); sendcmd(fd, cmd); sprintf(cmd, "$id03025555555550005555+"); sendcmd(fd, cmd); sprintf(cmd, "$id03035555000055555555+"); sendcmd(fd, cmd); sprintf(cmd, "$id03045555555555555555+"); sendcmd(fd, cmd); sprintf(cmd, "$id03055000555555000005+"); sendcmd(fd, cmd); sprintf(cmd, "$id03065555500055555555+"); sendcmd(fd, cmd); sprintf(cmd, "$id03070005555550005500+"); sendcmd(fd, cmd); sprintf(cmd, "$id03085555555555555555+"); sendcmd(fd, cmd); sprintf(cmd, "$id03095555550000055555+"); sendcmd(fd, cmd); sprintf(cmd, "$id030a5000555555550005+"); sendcmd(fd, cmd); sprintf(cmd, "$id030b5555500055555555+"); sendcmd(fd, cmd); sprintf(cmd, "$id030c5555555555000005+"); sendcmd(fd, cmd); sprintf(cmd, "$id030d5555000005555555+"); sendcmd(fd, cmd); sprintf(cmd, "$id030e0055555555555000+"); sendcmd(fd, cmd); sprintf(cmd, "$id030f5555555000555555+"); sendcmd(fd, cmd); return 0; } void send_chd(int fd, int i) { char cmd[128]; sprintf(cmd, "$dx%02x%04x+", i, ch[i].dx); sendcmd(fd, cmd); sprintf(cmd, "$dy%02x%04x+", i, ch[i].dy); sendcmd(fd, cmd); } void send_chm(int fd, int i) { char cmd[128]; sprintf(cmd, "$mx%02x%02x+", i, ch[i].mx); sendcmd(fd, cmd); sprintf(cmd, "$my%02x%02x+", i, ch[i].my); sendcmd(fd, cmd); } int sprite_init(int fd) { char cmd[128]; int i, im; srand(time(NULL)); for (i = 0; i < 16; i++) { ch[i].dx = (rand() % 200) + 200; ch[i].dy = (rand() % 200) + 200; ch[i].vx = (rand() % 2) * 2 - 1; ch[i].vy = (rand() % 2) * 2 - 1; ch[i].mx = (rand() % 4); ch[i].my = (rand() % 4); send_chd(fd, i); send_chm(fd, i); if (i < 4) im = 0; else if (i < 8) im = 1; else if (i < 15) im = 2; else im = 3; sprintf(cmd, "$im%02x%02x+", i, im); sendcmd(fd, cmd); sprintf(cmd, "$en%02x%02x+", i, 1); sendcmd(fd, cmd); sprintf(cmd, "$rx%02x%02x+", i, 0); sendcmd(fd, cmd); sprintf(cmd, "$ry%02x%02x+", i, 0); sendcmd(fd, cmd); if (i == 15) { sprintf(cmd, "$tx%02x%02x+", i, 1); sendcmd(fd, cmd); sprintf(cmd, "$ty%02x%02x+", i, 1); sendcmd(fd, cmd); } else { sprintf(cmd, "$tx%02x%02x+", i, 0); sendcmd(fd, cmd); sprintf(cmd, "$ty%02x%02x+", i, 0); sendcmd(fd, cmd); } } return 0; } int main(int argc, char *argv[]) { int fd; int i; char cmd[128]; fd = open("/dev/cuad0", O_RDWR); if (fd < 0) { fprintf(stderr, "cannot open device.\n"); exit (-1); } image_init(fd); sprite_init(fd); while (1) { for (i = 0; i < 16; i++) { ch[i].dx += ch[i].vx; ch[i].dy += ch[i].vy; if (ch[i].dx < 0) ch[i].vx = 3 + (rand() % 5); if (ch[i].dx> 639) ch[i].vx = -3 - (rand() % 5); if (ch[i].dy < 0) ch[i].vy = 3 + (rand() % 5); if (ch[i].dy> 479) ch[i].vy = -3 - (rand() % 5); if ((rand() % 100) == 0) { ch[i].mx = (rand() % 4); ch[i].my = (rand() % 4); send_chm(fd, i); sprintf(cmd, "$rx%02x%02x+", i, rand() % 2); sendcmd(fd, cmd); sprintf(cmd, "$ry%02x%02x+", i, rand() % 2); sendcmd(fd, cmd); } send_chd(fd, i); fprintf(stdout, "%d, dx = %d, dy = %d, vx = %d, vy = %d, mx = %d, my = %d\n", i, ch[i].dx, ch[i].dy, ch[i].vx, ch[i].vy, ch[i].mx, ch[i].my); } usleep(100000); } return 0; }

AltStyle によって変換されたページ (->オリジナル) /