main( void) { initEX16(); initLCD(); putsLCD( "Insert card...\n"); while ( !getCD()); Delayms( 100); if ( !mount()) putsLCD("Mount Failed"); else { clrLCD(); putsLCD("Playing..."); if ( !playWAV( "NELLY.WAV")) { clrLCD(); putsLCD("File not found"); } } while( 1) { } // main loop } //main
/* * UART sample. * * Some functions do not work with ICCAVR. */ int main(void) { int got; int userchoice; char *cp; u_long baud = 115200; #ifdef STDIO_FLOATING_POINT float dval = 0.0; #endif /* * Each device must be registered. We do this by referencing the * device structure of the driver. The advantage is, that only * those device drivers are included in our flash code, which we * really need. * * The uart0 device is the first one on the ATmega chip. So it * has no configurable base address or interrupt and we set both * parameters to zero. */ NutRegisterDevice(&DEV_UART, 0, 0); /* * Now, as the device is registered, we can open it. The fopen() * function returns a pointer to a FILE structure, which we use * for subsequent reading and writing. */ uart = fopen(DEV_UART_NAME, "r+"); freopen("uart0", "w", stdout); _ioctl(_fileno(stdout), UART_SETSPEED, &baud); /* * Before doing the first read or write, we set the baudrate. * This low level function doesn't know about FILE structures * and we use _fileno() to get the low level file descriptor * of the stream. * * The short sleep allows the UART to settle after the baudrate * change. */ _ioctl(_fileno(uart), UART_SETSPEED, &baud); /* Initialize the LCd */ NutRegisterDevice(&devLcd, 0, 0); /* Initialize UROM */ NutRegisterDevice(&devUrom, 0, 0); NutRegisterDevice(&devDebug0, 0, 0); /* * Stream devices can use low level read and write functions. * Writing program space data is supported too. */ _write(_fileno(uart), banner, strlen(banner)); { lcdPrint(banner); _write_P(_fileno(uart), presskey_P, sizeof(presskey_P)); } /* * Stream devices do buffered I/O. That means, nothing will be * passed to the hardware device until either the output buffer * is full or we do a flush. With stream I/O we typically use * fflush(), but low level writing a null pointer will also flush * the output buffer. */ _write(_fileno(uart), 0, 0); /* * The low level function read() will grab all available bytes * from the input buffer. If the buffer is empty, the call will * block until something is available for reading. */ got = _read(_fileno(uart), inbuf, sizeof(inbuf)); _write(_fileno(uart), inbuf, got); /* * Nut/OS never expects a thread to return. So we enter an * endless loop here. */ do { fflush(uart); lcdPrint("Main Menu"); userchoice = 0; /* * A bit more advanced input routine is able to read a string * up to and including the first newline character or until a * specified maximum number of characters, whichever comes first. */ puts("\n*************"); puts("\n* Main Menu *"); puts("\n*************\n"); puts("\n1. Generate speech\n"); puts("\n2. IRC\n"); puts("\n3. Settings\n"); puts("\n4. Help\n"); puts("\n5. Play wav\n"); puts("\nEnter your choice: "); readLine(inbuf, sizeof(inbuf)); /* * Streams support formatted output as well as printing strings * from program space. */ if (inbuf[0]) { puts("\n\n"); userchoice = atoi(inbuf); switch (userchoice) { case 1: speechSynthesize(uart); break; case 2: runIRC(uart); break; case 3: openSettings(uart); break; case 4: showHelp(uart); break; case 5: playWAV(uart); break; default: puts("Invalid option selected\n"); } } /* * Just to demonstrate formatted floating point output. * In order to use this, we need to link the application * with nutcrtf instead of nutcrt for pure integer. */ #ifdef STDIO_FLOATING_POINT dval += 1.0125; fprintf(uart, "FP %f\n", dval); #endif } while (1); }
void update_actors(unsigned long playerdat) { int i, j, player_x = player.x, player_y = player.y; buffer_clear(); // Handle player. if (playerdat & 0x01) player.y -= PLAYER_SPEED; if (playerdat & 0x02) player.y += PLAYER_SPEED; if (playerdat & 0x04) player.x -= PLAYER_SPEED; if (playerdat & 0x08) player.x += PLAYER_SPEED; if (player.x > 124) player.x = 124; if (player.x < 4) player.x = 4; if (player.y > 92) player.y = 92; if (player.y < 4) player.y = 4; if (player.health > 0) buffer_draw(player_x-4, player_y-4, player_ship); for (i = 0; i < MAX_BULLETS; i++) { // Handle bullets. short bullet_x, bullet_y, dir; bullet *curr = &bullets[i]; if (curr->info <= 0) continue; bullet_x = curr->x; bullet_y = curr->y; dir = curr->info & 0x0F; // Collision detection. if (curr->info & 0x10) { // Enemy bullet. if (abs(bullet_x - player.x) < 3 && abs(bullet_y - player.y) < 3) { player.health -= 1; curr->info = -1; playWAV((unsigned char *) &shoot[0], 4080, 0); continue; } } else { for (j = 0; j < MAX_ENEMIES; j++) {// Player bullet. short size; enemy_ref * curr_enemy = &enemies[j]; if (!curr_enemy->health) continue; size = curr_enemy->type->size; if (abs(bullet_x - curr_enemy->x) < size && abs(bullet_y - curr_enemy->y) < size) { curr_enemy->health -= 1; curr->info = -1; break; } } if (j < MAX_ENEMIES) continue; } if (bullet_x > 128 - BULLET_SPEED || bullet_x < BULLET_SPEED || bullet_y > 96 - BULLET_SPEED || bullet_y < BULLET_SPEED) { curr->info = -1; continue; } // If it survived all of that, update position and redraw. if (dir & 0x01) bullet_y -= BULLET_SPEED; if (dir & 0x02) bullet_y += BULLET_SPEED; if (dir & 0x04) bullet_x -= BULLET_SPEED; if (dir & 0x08) bullet_x += BULLET_SPEED; curr->x = bullet_x; curr->y = bullet_y; buffer_drawbullet(bullet_x, bullet_y, dir); } if (playerdat & 0x20) queue_bullet = 1; if(queue_bullet) { // Fix this queue_bullet = 0; fire_func(player.x, player.y, tick%4); } for (i = 0; i < MAX_ENEMIES; i++) { // Handle enemies. enemy *info; unsigned short movement, freq, size, weapon, px, py, counter; enemy_ref *curr = &enemies[i]; if (curr->health < 0) continue; if (curr->health == 0) { score += curr->type->score; curr->health = -1; playWAV((unsigned char *)&shoot[0], 4080, 0); if (curr->type == &enemy_list[6]) { SysTick_Init(0); buffer_draw(0, 40, (unsigned char *) &gamewin[0]); sprintf(&score_string[0], "%d", (score>>6)); RIT128x96x4_Buffer(); RIT128x96x4StringDraw(&score_string[0], 0, 0, 0x0F); while(1); } }