void backup_flash() { int ret; volatile u16 *read_addr=(volatile u16 *)0x22000000; volatile u16 *write_addr=(volatile u16 *)0x20200000; u32 i; flash_info_struct flash_info; vdp_start_draw_list(); vdp_end_draw_list(); if ((ret = ar_init_flash_io(&flash_info)) != IAPETUS_ERR_OK) { if (!ar_handle_detect_error(ret)) return; } for (i = 0; i < 0x40000; i++) write_addr[i] = read_addr[i]; vdp_printf(&main_font, 8, 3 * 8, 0xF, "Firmware ready to download. Set your"); vdp_printf(&main_font, 8, 4 * 8, 0xF, "Commlink utility to download data from"); vdp_printf(&main_font, 8, 5 * 8, 0xF, "LWRAM(0x00200000 to 0x00240000)"); vdp_printf(&main_font, 8, 6 * 8, 0xF, "Press any button to exit."); commlink_start_service(); wait_for_press(-1); commlink_stop_service(); }
BOOL ar_handle_detect_error(int err) { char text[128]; u16 press; u16 vendor_id, device_id; if (err == IAPETUS_ERR_HWNOTFOUND) sprintf(text, "HW not found."); else if(err == IAPETUS_ERR_UNSUPPORTED) sprintf(text, "HW not supported."); else sprintf(text, "Unknown error."); vdp_printf(&main_font, 8, 8, 0xF, "Error detecting cart. %s", text); ar_get_product_id(&vendor_id, &device_id); vdp_printf(&main_font, 8, 16, 0xF, "HW ID: %04X %04X", vendor_id, device_id); press=wait_for_press(-1); if (err != IAPETUS_ERR_UNSUPPORTED) return FALSE; if (press & PAD_A && press & PAD_B && press & PAD_C) { vdp_vsync(); vdp_clear_screen(&main_font); return TRUE; } return FALSE; }
int main(void) { union uKeyRoster scan; init(); while (1) { wait_for_press(); // Result is stored in prev_keys & keys and hopefully keys2 SET_LED_1(); scan = pack_array( keys ); build_key_list ( keys ); if (isConfigured(MODE_SEND_ROSTER)==0) { can_prep_button_roster_msg( &msg1, scan ); can_send_msg_no_wait( CAN_TRANSMIT_CHANNEL1, &msg1 ); } if (isConfigured(MODE_SEND_PRESSED)==0) { can_prep_button_pressed_msg( &msg2 ); can_send_msg_no_wait( CAN_TRANSMIT_CHANNEL2, &msg2 ); } RESET_LED_1(); } return(0); }
void credits() { vdp_printf(&main_font, 8, 8, 0xF, "Copyright 2014 Pseudo Saturn Team"); vdp_printf(&main_font, 8, 2 * 8, 15, "http://github.com/cyberwarriorx/pseudosaturn"); vdp_printf(&main_font, 8, 10 * 8, 15, "Press any button to go back"); wait_for_press(-1); vdp_clear_screen(&main_font); }
//***** main ***************************************************** int main(void) { union uKeyRoster scan; chip_init(); // Chip initialization can_init(); /* Enables Mob0 for Reception! */ can_init_test_msg(); byte result = CANSTMOB; send_test_msgs(); /* TEST A) Initial Board Alive test, call this below. Watch LEDs go. led_test_pattern(); */ /* B) Enable Receive Interrupts and call Show_byte() in the ISR. ALL CODE IS IN ISR() */ while (1) {}; while (1) { wait_for_press(); // Result is stored in prev_keys & keys and hopefully keys2 scan = pack_array( keys ); can_prep_button_roster_msg( &msg1, scan ); can_send_msg( 0, &msg1 ); show_byte( scan.array[0], 1 ); // result = CANEN2; // shows MOb n in use mob1 is staying "in use" after 1 can_tx() // result = CANSTMOB; // shows TXOK or ERRs BERR staying on instead of TXOK // result = CANGSTA; // shows TXOK or ERRs TXBSY blinking (retires?) // result = 0x83; // result = scan.array[0]; // show_byte( a, 1 ); // [0] upper nibble is front row // [0] lower is top row // [1] upper nibble is 2nd row // [1] lower is 3rd row // [2] upper nibble is 4th row /* for (int j=0; j<4; j++) { show_result_toggle(result); delay (one_second/2); } */ } return(0); }
int start_game(snake psnake,food Tfood) { move_snake(psnake); draw_snake(psnake); //检测按键:当按键为Q/q时,返回-1 if(wait_for_press(psnake)==-1){ print_infowin("Quit Game!"); gameover(gamewin, "Quit Game!"); return -1; } //检测贪吃蛇状态:1.是否吃到食物;2.是否触碰自己或者边界. if(check_snake(psnake,Tfood)<0){ gameover(gamewin,"GAME OVER!!!"); print_infowin("QUIT GMAE!"); return -1; } else return 1; }
int main(void) { ONPIN(DDRB, IR_LED); ONPIN(DDRB, ST_LED); ONPIN(PORTB, ST_SW); ONMASK(PORTD, MASK(SW1) | MASK(SW2) | MASK(SW3) | MASK(SW4) | MASK(SW5)); OFFMASK(DDRD, MASK(SW1) | MASK(SW2) | MASK(SW3) | MASK(SW4) | MASK(SW5)); _delay_ms(800); // Pick a frequency char hf = 0; hf = GETPIN(PINB, ST_SW) == 0; OFFPIN(PORTB, ST_SW); ONPIN(PORTB, ST_LED); _delay_ms(200); OFFPIN(PORTB, ST_LED); _delay_ms(200); if (hf) { ONPIN(PORTB, ST_LED); _delay_ms(200); OFFPIN(PORTB, ST_LED); _delay_ms(200); set_frequency_56(); // 56 khz } else { set_frequency_38(); //set the transmit frequency to 38KHz } while(1) { wait_for_press(); ONPIN(PORTB, ST_LED); send_start_bit(); unsigned char code = read_press(); code += IR_CODE_BASE; send_command(181); OFFPIN(PORTB, ST_LED); } }
int reflash_ar(font_struct *font, u8 *rom_addr, int ask_upload) { int ret; volatile u16 *write_addr=(volatile u16 *)0x22000000; u16 *read_addr=(u16 *)((u32)rom_addr | 0x20000000); flash_info_struct flash_info; int i; vdp_start_draw_list(); vdp_end_draw_list(); for (;;) { start: if ((ret = ar_init_flash_io(&flash_info)) != IAPETUS_ERR_OK) { if (!ar_handle_detect_error(ret)) return 1; } vdp_printf(font, 8, 8, 0xF, "Detected cart succesfully"); if (ask_upload) { vdp_printf(font, 8, 3 * 8, 0xF, "Please upload flash to 0x00200000 and"); vdp_printf(font, 8, 4 * 8, 0xF, "then press 'A' to continue. "); vdp_printf(font, 8, 5 * 8, 0xF, "Press 'X' to exit."); commlink_start_service(); if (wait_for_press(PAD_A | PAD_X) & PAD_X) return 1; commlink_stop_service(); if (strncmp((char *)read_addr, "SEGA SEGASATURN ", 16) != 0) { vdp_printf(font, 8, 7 * 8, 0xF, "Invalid or no ROM uploaded. "); vdp_printf(font, 8, 8 * 8, 0xF, "Press 'A' to try again."); wait_for_press(PAD_A); vdp_clear_screen(font); goto start; } } vdp_printf(font, 8, 7 * 8, 0xF, "WARNING: Rewriting the flash may damage"); vdp_printf(font, 8, 8 * 8, 0xF, "your AR. Press A+B+C to continue."); vdp_printf(font, 8, 9 * 8, 0xF, "Press 'X' to exit."); for (;;) { vdp_vsync(); if (per[0].but_push & PAD_A && per[0].but_push & PAD_B && per[0].but_push & PAD_C) break; else if (per[0].but_push_once & PAD_X) return 1; } vdp_printf(font, 8, 11 * 8, 0xF, "DO NOT TURN OFF YOUR SYSTEM"); vdp_printf(font, 8, 12 * 8, 0xF, "Erasing flash..."); ar_erase_flash_all(&flash_info); vdp_printf(font, 17 * 8, 12 * 8, 0xF, "OK"); vdp_printf(font, 8, 13 * 8, 0xF, "Writing flash..."); font->transparent = FALSE; for (i = 0; i < flash_info.num_pages; i++) { vdp_printf(font, 17 * 8, 13 * 8, 0xF, "%d%% ", (i+1) * 100 / flash_info.num_pages); ar_write_flash(&flash_info, write_addr+(i*flash_info.page_size), read_addr+(i*flash_info.page_size), 1); } vdp_printf(font, 17 * 8, 13 * 8, 0xF, "OK "); font->transparent = TRUE; vdp_printf(font, 8, 14 * 8, 0xF, "Verifying flash..."); ret = ar_verify_write_flash(&flash_info, write_addr, read_addr, flash_info.num_pages); vdp_printf(font, 19 * 8, 14 * 8, 0xF, ret ? "OK" : "FAILED"); if (ret) { vdp_printf(font, 8, 15 * 8, 0xF, "SUCCESS! Press reset to finish."); goto done; } vdp_printf(font, 8, 15 * 8, 0xF, "Failed flashing AR. Press a 'A' to"); vdp_printf(font, 8, 16 * 8, 0xF, "retry or 'X' to exit"); if (wait_for_press(PAD_A | PAD_X) & PAD_X) return 0; vdp_clear_screen(font); } done: wait_for_press(PAD_A); return 1; }