static u16 amic1608_adc_readdate(void) { int i; u16 data = 0; /* * 启动转换 * 使用模拟SPI控制AMiC-1608AI-5ID时,必须先把CLK置低,再把CS置低启动采样,否则将不能正确读取采样值 */ clk_low(); //loop_ten(1); ship_select(); /* * 先发出6个CLK出去,在这段时间内数据无效,所以不用读取数据 */ for(i = 0; i < 6; i++) { clk_high(); loop_ten(1); clk_low(); loop_ten(1); } for (i = 0; i< 16; i++) { clk_low(); data <<= 1; loop_ten(1); clk_high(); loop_ten(1); data |= readbit(); } ship_release(); return data; }
void startup_menu(void) { reset_menu_palette(); menu_select = 0; key_wait = 30; // int counter; menu_counter = 0; counter2 = 0; arena.difficulty = 0; int y1 = 170; int y2 = 190 + menu_select * 30; int y3 = 218 + menu_select * 30; int y4 = 218 + menu_select * 30; int anykey = 0; int i; //#define TEST_MUSIC #ifdef TEST_MUSIC arena.level = 3; init_beat_new_level(); #endif init_menu_circles(); while (TRUE) { #ifdef TEST_MUSIC run_beat(); #endif clear_to_color(display, COL_BACK1); run_menu_background(); menu_counter += 4; if (menu_counter >= 40) menu_counter = 0; counter2 ++; if (counter2 >= 256) counter2 = 0; // textprintf_centre_ex(display, font, 300, 190, -1, -1, "W H I T E B U T T E R F L Y"); draw_rle_sprite(display, white_RLE, 150, 150); int my = 300; y1 = my - 23; y2 = my - 10 + menu_select * 30; y3 = my + 19 + menu_select * 30; y4 = my + 150; // rectfill(display, 370, y1, 600, y2, COL_COL1); TRANS_MODE rectfill(display, 370, y2 + 9, 640, y3 - 2, TRANS_BLUE3); rect(display, 368, y2 + 7, 641, y3 - 0, TRANS_BLUE3); END_TRANS // rectfill(display, 370, y3, 600, y4, TRANS_DGREEN); textprintf_ex(display, font, 400, my, -1, -1, "START GAME"); switch(arena.difficulty) { case 0: textprintf_ex(display, font, 400, my + 30, -1, -1, "DIFFICULTY - NORMAL"); break; case 1: textprintf_ex(display, font, 400, my + 30, -1, -1, "DIFFICULTY - HARD"); break; case 2: textprintf_ex(display, font, 400, my + 30, -1, -1, "DIFFICULTY - PUNISHMENT"); break; } // textprintf_ex(display [2], font, 400, 260, -1, -1, "STAGE - %i", arena.starting_level); textprintf_ex(display, font, 400, my + 90, -1, -1, "SET KEYS"); textprintf_ex(display, font, 400, my + 120, -1, -1, "OPTIONS"); textprintf_ex(display, font, 400, my + 150, -1, -1, "EXIT"); // textprintf_ex(display, font, 40, 10, -1, -1, "%i", joy[0].stick[options.joy_stick].axis[0].pos); // textprintf_ex(display, font, 40, 30, -1, -1, "%i", joy[0].stick[options.joy_stick].axis[1].pos); /* if (options.joystick) textprintf_ex(display, font, 400, my + 120, -1, -1, "CALIBRATE JOYSTICK"); else { textprintf_ex(display, font, 400, my + 120, -1, -1, "NO JOYSTICK"); drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); rectfill(display, 399, my + 110, 530, my + 135, CONVERT_WHITE_TO_GREY); drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); } */ if (options.joystick) { if (options.key_or_joy == 1) textprintf_ex(display, font, 400, my + 60, -1, -1, "CONTROLS - JOYSTICK"); else textprintf_ex(display, font, 400, my + 60, -1, -1, "CONTROLS - KEYBOARD"); } else { textprintf_ex(display, font, 400, my + 60, -1, -1, "NO JOYSTICK"); drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); rectfill(display, 399, my + 50, 530, my + 75, CONVERT_WHITE_TO_GREY); drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); } // textprintf_ex(display, font, 5, 5, -1, -1, "%i", any_joystick_input()); my = 330; y2 = my + 7 + arena.just_got_highscore * 30; y3 = my + 29 + arena.just_got_highscore * 30; if (arena.just_got_highscore > 0) { rectfill(display, 0, y2 - 5, 250, y3, COL_COL3); rect(display, -1, y2 - 5 - 2, 250 + 2, y3 + 2, COL_COL4); } // textprintf_right_ex(display, font, 137, my, -1, -1, "HIGH"); // textprintf_ex(display, font, 157, my, -1, -1, "SCORES"); textprintf_centre_ex(display, font, 147, my, -1, -1, "HIGHSCORES"); textprintf_right_ex(display, font, 137, my + 40, -1, -1, "NORMAL"); textprintf_ex(display, font, 157, my + 40, -1, -1, "%i", options.highscore [0]); textprintf_right_ex(display, font, 137, my + 70, -1, -1, "HARD"); textprintf_ex(display, font, 157, my + 70, -1, -1, "%i", options.highscore [1]); textprintf_right_ex(display, font, 137, my + 100, -1, -1, "PUNISHMENT"); textprintf_ex(display, font, 157, my + 100, -1, -1, "%i", options.highscore [2]); textprintf_right_ex(display, font, 600, 570, -1, -1, "COPYRIGHT 2009 LINLEY HENZELL"); // should print last score here... anykey = 0; for (i = KEY_A; i < KEY_CAPSLOCK + 1; i ++) { if (key [i]) { anykey = 1; } } if (anykey == 0 && (options.joystick == 0 || any_joystick_input() == 0)) key_wait = 0; if (key_wait == 0) { if (menu_command(MC_UP)) { menu_select --; if (menu_select < 0) menu_select = MENU_EXIT; if (menu_select == MENU_JOY_OR_KEYS && options.joystick == 0) menu_select = MENU_JOY_OR_KEYS - 1; key_wait = 7; } if (menu_command(MC_DOWN)) { menu_select ++; if (menu_select > MENU_EXIT) menu_select = 0; if (menu_select == MENU_JOY_OR_KEYS && options.joystick == 0) menu_select = MENU_KEYS; key_wait = 7; } if (menu_command(MC_LEFT)) { // if (menu_select == 2) // arena.starting_level = 1; if (menu_select == MENU_JOY_OR_KEYS) { if (options.key_or_joy == 0) options.key_or_joy = 1; else options.key_or_joy = 0; } if (menu_select == MENU_DIFFICULTY) { arena.difficulty --; if (arena.difficulty < 0) arena.difficulty = 0; } key_wait = 7; } if (menu_command(MC_RIGHT)) { // if (menu_select == 2) // arena.starting_level = 2; if (menu_select == MENU_JOY_OR_KEYS) { if (options.key_or_joy == 0) options.key_or_joy = 1; else options.key_or_joy = 0; } if (menu_select == MENU_DIFFICULTY) { arena.difficulty ++; if (arena.difficulty > 2) arena.difficulty = 2; } key_wait = 7; } // if (key [KEY_ESC]) // exit(0); if (menu_command(MC_SELECT)) { if (menu_select == MENU_EXIT) { goodbye_menu_circles(); return; } if (menu_select == MENU_KEYS) { key_wait = 10; define_keys(); key_wait = 10; } if (menu_select == MENU_OPTIONS) { key_wait = 10; set_options(); key_wait = 10; } /* if (menu_select == MENU_CALIBRATE) { jstick_calibrate(); key_wait = 20; ticked = 0; }*/ if (menu_select == MENU_START) { arena.level = 1;//arena.starting_level; ticked = 0; key_wait = 30; if (ship_select() == 1) { vsync(); // clear_bitmap(screen); // clear_bitmap(display); player.type = PTYPE_BASIC; // player.type = PTYPE_BOMBER; // player.type = PTYPE_ANENOME; // player.type = PTYPE_HAND; player.weapon_level = 0; int ship_select = select_a_ship(); if (ship_select != -1) { switch(ship_select) { default: case 0: player.type = PTYPE_BASIC; break; case 1: player.type = PTYPE_ANENOME; break; case 2: player.type = PTYPE_BOMBER; break; case 3: player.type = PTYPE_HAND; break; case 4: player.type = PTYPE_SQUID; break; } if (arena.level == 1) arena.from_start = 1; else arena.from_start = 0; arena.cleared = 0; arena.unlocked = 0; menu_counter = 0; goodbye_menu_circles(); new_game(); game_loop(); if (arena.level == 4) congratulations(); arena.target_palette = PAL_MENU; arena.shift_palette = 2; init_menu_circles(); // reset_menu_palette(); key_wait = 10; // was 1 // flower_dir *= -1; ticked = 0; } } else key_wait = 20; } else key_wait = 20; } } else key_wait --; do { thing ++; } while (ticked == 0); ticked = 0; if (arena.shift_palette > 0 && menu_counter % 12 == 0) { run_palette_shift(); build_new_palette(0, 0, 0, 0); set_palette(palet); if (arena.shift_palette == 1) arena.shift_palette = 0; } vsync(); blit(display, screen, 0, 0, 100, 0, 600, 600); }; }