void key_choice() { if(key_check(0)==0) //检测PB16按键按下 { // orgVal[2]++; // RPMIN_tmp_SPI0++; // FLOAT_Singal_SPI_Write(LDC1000_CMD_PWRCONFIG,0x00,SPI1); // FLOAT_Singal_SPI_Write(LDC1000_CMD_RPMAX,orgVal[2],SPI1); // FLOAT_Singal_SPI_Write(LDC1000_CMD_PWRCONFIG,0x01,SPI1); // systick_delay_ms(50); // FLOAT_Singal_SPI_Write(LDC1000_CMD_PWRCONFIG,0x00,SPI0); // FLOAT_Singal_SPI_Write(LDC1000_CMD_RPMAX,RPMIN_tmp_SPI0,SPI0); // FLOAT_Singal_SPI_Write(LDC1000_CMD_PWRCONFIG,0x01,SPI0); kd_Steering+=0.05; } if(key_check(1)==0) //检测PB17按键按下 { kd_Steering-=0.05; // orgVal[2]--; // RPMIN_tmp_SPI0--; // FLOAT_Singal_SPI_Write(LDC1000_CMD_PWRCONFIG,0x00,SPI1); // FLOAT_Singal_SPI_Write(LDC1000_CMD_RPMAX,orgVal[2],SPI1); // FLOAT_Singal_SPI_Write(LDC1000_CMD_PWRCONFIG,0x01,SPI1); // systick_delay_ms(50); // FLOAT_Singal_SPI_Write(LDC1000_CMD_PWRCONFIG,0x00,SPI0); // FLOAT_Singal_SPI_Write(LDC1000_CMD_RPMAX,RPMIN_tmp_SPI0,SPI0); // FLOAT_Singal_SPI_Write(LDC1000_CMD_PWRCONFIG,0x01,SPI0); } }
/*! * @brief 启动前进行检测(检测按键是否按下,按下则进入死循环,防止进入 main 函数,松开按键后再按下则进行解锁) * @since v5.0 * @note 此函数可避免 下载口在 main 前 复用了导致无法下载等问题 */ void start_check() { #if 0 uint8 flag = 0; key_init(KEY_A); if(key_check(KEY_A) == KEY_DOWN ) { //按键按下 led_init(LED0); while(1) { if(key_check(KEY_A) == KEY_UP) { flag = 1; } led_turn(LED0); printf("\n进入死循环等待!"); DELAY_MS(500); //此处的延时,可起到 按键 消抖的功能 //如果 送开按键后,再按下 按键,则 进行解锁 操作 if((flag == 1) && (key_check(KEY_A) == KEY_DOWN )) { while(key_check(KEY_A) == KEY_DOWN) //等待按键 弹起 { led_turn(LED0); DELAY_MS(100); //此处的延时,可起到 按键 消抖的功能 } while(key_check(KEY_A) == KEY_UP) //等待按键 弹起后 再 进行解锁 { led_turn(LED0); DELAY_MS(50); //此处的延时,可起到 按键 消抖的功能 } printf("\n进行解锁操作,请重新刷入固件"); //解锁单片机 flash_init(); DELAY_MS(100); flash_erase_sector(0); //擦除扇区 0 (解锁) NVIC_SystemReset(); //复位单片机 } } } #endif }
/* * copy the keys for fork */ int copy_keys(unsigned long clone_flags, struct task_struct *tsk) { key_check(tsk->thread_keyring); key_check(tsk->request_key_auth); /* no thread keyring yet */ tsk->thread_keyring = NULL; /* copy the request_key() authorisation for this thread */ key_get(tsk->request_key_auth); return 0; } /* end copy_keys() */
/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //----------时间量处理------------ &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/ void time_dis(mico_i2c_device_t * slave_device) { if(wifi_display==1) { wifi_display_timer++; if(wifi_display_timer==500) { wifi_display=0; wifi_display_timer=0; } } if(wifi_display==0) { time_shan_dis();//闪烁树立 gjys_1f_dis(slave_device);//关机1分钟延时处理 key_check(slave_device); baoc_dis(slave_device); out_dis(slave_device); fan_time_dis(slave_device); Heart_time_dis(slave_device); proces_out_dis(slave_device); } }
static noinline void key_gc_unused_key(struct key *key) { key_check(key); security_key_free(key); if (test_bit(KEY_FLAG_IN_QUOTA, &key->flags)) { spin_lock(&key->user->lock); key->user->qnkeys--; key->user->qnbytes -= key->quotalen; spin_unlock(&key->user->lock); } atomic_dec(&key->user->nkeys); if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags)) atomic_dec(&key->user->nikeys); key_user_put(key->user); if (key->type->destroy) key->type->destroy(key); kfree(key->description); #ifdef KEY_DEBUGGING key->magic = KEY_DEBUG_MAGIC_X; #endif kmem_cache_free(key_jar, key); }
/* * Garbage collect an unreferenced, detached key */ static noinline void key_gc_unused_key(struct key *key) { key_check(key); /* Throw away the key data if the key is instantiated */ if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags) && !test_bit(KEY_FLAG_NEGATIVE, &key->flags) && key->type->destroy) key->type->destroy(key); security_key_free(key); /* deal with the user's key tracking and quota */ if (test_bit(KEY_FLAG_IN_QUOTA, &key->flags)) { spin_lock(&key->user->lock); key->user->qnkeys--; key->user->qnbytes -= key->quotalen; spin_unlock(&key->user->lock); } atomic_dec(&key->user->nkeys); if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags)) atomic_dec(&key->user->nikeys); key_user_put(key->user); kfree(key->description); #ifdef KEY_DEBUGGING key->magic = KEY_DEBUG_MAGIC_X; #endif kmem_cache_free(key_jar, key); }
/* * copy the keys in a thread group for fork without CLONE_THREAD */ int copy_thread_group_keys(struct task_struct *tsk) { key_check(current->thread_group->session_keyring); key_check(current->thread_group->process_keyring); /* no process keyring yet */ tsk->signal->process_keyring = NULL; /* same session keyring */ rcu_read_lock(); tsk->signal->session_keyring = key_get(rcu_dereference(current->signal->session_keyring)); rcu_read_unlock(); return 0; } /* end copy_thread_group_keys() */
/* * copy the keys for fork */ int copy_keys(unsigned long clone_flags, struct task_struct *tsk) { key_check(tsk->thread_keyring); /* no thread keyring yet */ tsk->thread_keyring = NULL; return 0; } /* end copy_keys() */
/* * copy the keys in a thread group for fork without CLONE_THREAD */ int copy_thread_group_keys(struct task_struct *tsk) { unsigned long flags; key_check(current->thread_group->session_keyring); key_check(current->thread_group->process_keyring); /* no process keyring yet */ tsk->signal->process_keyring = NULL; /* same session keyring */ spin_lock_irqsave(¤t->sighand->siglock, flags); tsk->signal->session_keyring = key_get(current->signal->session_keyring); spin_unlock_irqrestore(¤t->sighand->siglock, flags); return 0; } /* end copy_thread_group_keys() */
static int multi_key_detection(void) { int current_status = 0; int index = 0; int count = long_press_time / ( KEY_SAMPLE_PERIOD + 40 ); //ADC delay count = count / 2; // make it 3 times faster !!! DAP int m_key = 0; int cur_key = 0; int adc_data[4] = {0, 0, 0, 0}; int adc_raw; int channel = MULTIKEY_ADC_CHANNEL; IMM_GetOneChannelValue(channel, adc_data, &adc_raw); m_key = cur_key = key_check(adc_data[0], adc_data[1]); while(index++ < count) { /* Check if the current state has been changed */ current_status = INREG32(ACCDET_MEMORIZED_IN) & 0x3; if(current_status != 0) { return (m_key | SHORT_PRESS); } /* Check if the voltage has been changed (press one key and another) */ IMM_GetOneChannelValue(channel, adc_data, &adc_raw); cur_key = key_check(adc_data[0], adc_data[1]); if(m_key != cur_key) return (m_key | SHORT_PRESS); else m_key = cur_key; msleep(KEY_SAMPLE_PERIOD); } return (m_key | LONG_PRESS); }
int main(void) { int i; char choice; char quit; main_init(); quit = FALSE; do { choice = title_page(); switch (choice) { case (0) : case (1) : gPlayers = choice + 1; break; case (2) : continue; default : quit = TRUE; }; if (!quit) { game_reset(); // main game loop do { key_check(); for (i = 0; i != gPlayers; ++i) { player_key_check(i); player_stack_linecheck(i); player_update(i); } screen_draw(); blit(gBuff, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); } while (gWinner == 0); record_scores(); table_display(); } } while (!quit); table_display(); main_exit(); return 0; }
/* * Garbage collect a list of unreferenced, detached keys */ static noinline void key_gc_unused_keys(struct list_head *keys) { while (!list_empty(keys)) { struct key *key = list_entry(keys->next, struct key, graveyard_link); list_del(&key->graveyard_link); kdebug("- %u", key->serial); key_check(key); security_key_free(key); /* deal with the user's key tracking and quota */ if (test_bit(KEY_FLAG_IN_QUOTA, &key->flags)) { spin_lock(&key->user->lock); key->user->qnkeys--; key->user->qnbytes -= key->quotalen; spin_unlock(&key->user->lock); } atomic_dec(&key->user->nkeys); if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags)) atomic_dec(&key->user->nikeys); /* now throw away the key memory */ if (key->type->destroy) key->type->destroy(key); key_user_put(key->user); kfree(key->description); #ifdef KEY_DEBUGGING key->magic = KEY_DEBUG_MAGIC_X; #endif kmem_cache_free(key_jar, key); } }
/* * Garbage collect a list of unreferenced, detached keys */ static noinline void key_gc_unused_keys(struct list_head *keys) { while (!list_empty(keys)) { struct key *key = list_entry(keys->next, struct key, graveyard_link); short state = key->state; list_del(&key->graveyard_link); kdebug("- %u", key->serial); key_check(key); /* Throw away the key data if the key is instantiated */ if (state == KEY_IS_POSITIVE && key->type->destroy) key->type->destroy(key); security_key_free(key); /* deal with the user's key tracking and quota */ if (test_bit(KEY_FLAG_IN_QUOTA, &key->flags)) { spin_lock(&key->user->lock); key->user->qnkeys--; key->user->qnbytes -= key->quotalen; spin_unlock(&key->user->lock); } atomic_dec(&key->user->nkeys); if (state != KEY_IS_UNINSTANTIATED) atomic_dec(&key->user->nikeys); key_user_put(key->user); kfree(key->description); memzero_explicit(key, sizeof(*key)); kmem_cache_free(key_jar, key); } }
static void timer_callback(void *parameter) { int i; key_t key; rt_ubase_t level; struct dev_key *dev_key = (struct dev_key *)parameter; RT_ASSERT(dev_key != RT_NULL); for (i = 0; i < KEY_NUM; i++) { key = key_check(i); if (KEY_VALUE(key) != KEY_NONE) { dev_key->key_buffer[dev_key->save_index] = key; level = rt_hw_interrupt_disable(); dev_key->save_index++; if (dev_key->save_index >= KEY_QUEUE_LEN) dev_key->save_index = 0; rt_hw_interrupt_enable(level); /* invoke callback */ if(dev_key->parent.rx_indicate != RT_NULL) { rt_size_t length; if (dev_key->read_index > dev_key->save_index) length = KEY_QUEUE_LEN - dev_key->read_index + dev_key->save_index; else length = dev_key->save_index - dev_key->read_index; dev_key->parent.rx_indicate(&dev_key->parent, length); } } } }
void main(void) { int i1=0; int count10S = 0; Device_init(); disable_irq(PIT0_IRQn); systick_delay_ms(50); FLOAT_LDC_init(SPI1); systick_delay_ms(50); FLOAT_LDC_init(SPI0); systick_delay_ms(1000); uart_init(UART3,115200); key_init(0); key_init(1); key_init(2); //LDC_EVM_TEST(); //Speed_Ctl_Init(short point_value, double dKpp, double dKii, double dKdd); while(1) { //value_collect(); LCD_P6x8Str(0,2,"Rmax Lmin"); printf("Rmax Rmin\r\n"); systick_delay_ms(1500); i1=50; while(i1--) { adjustment[2]=(float)filter(SPI1)/10;//右max LCD_BL(55,2,(uint16)adjustment[2]); printf("%d\r\n",adjustment[2]); } i1=50; while(i1--) { adjustment[1]=(float)filter(SPI0)/10;//左min LCD_BL(90,2,(uint16)adjustment[1]); printf("%d\r\n",adjustment[1]); } LCD_BL(55,2,(uint16)adjustment[1]); LCD_BL(90,2,(uint16)adjustment[2]); LCD_P6x8Str(0,4,"Lmax Rmin"); printf("Lmax Rmin\r\n"); systick_delay_ms(1500); i1=50; while(i1--) { adjustment[3]=(float)filter(SPI1)/10;//右min LCD_BL(55,4,(uint16)adjustment[3]); printf("%d\r\n",adjustment[3]); } i1=50; while(i1--) { adjustment[4]=(float)filter(SPI0)/10;//左max LCD_BL(90,4,(uint16)adjustment[4]); printf("%d\r\n",adjustment[4]); } LCD_BL(55,4,(uint16)adjustment[4]); LCD_BL(90,4,(uint16)adjustment[3]); if(adjustment[1]<=adjustment[3]) adjustment[5]=adjustment[1];//次小值 else adjustment[5]=adjustment[3];//次小值 if(adjustment[2]>=adjustment[4]) adjustment[6]=adjustment[2];//次大值 else adjustment[6]=adjustment[4];//次大值 divisor = (adjustment[2] - adjustment[3])/60; //48 //50 divisor2 = (adjustment[4] - adjustment[1])/59; //48 //45 zengfuzhi = (adjustment[2] - adjustment[3])/(adjustment[4] - adjustment[1]); // for(int i=0;i<10;i++) // { // printf("%d\r\n",adjustment[i]); // } // systick_delay_ms(1000); LCD_P6x8Str(0,6,"Mid value"); i1 = 50; systick_delay_ms(1500); while(i1--) { adjustment[7]=(float)filter(SPI0)/10;//左 adjustment[8]=(float)filter(SPI1)/10;//右 LCD_BL(55,6,(uint16)adjustment[7]); LCD_BL(90,6,(uint16)adjustment[8]); } if(adjustment[7]>=adjustment[8]) { flag=1; adjustment[0]=adjustment[7]-adjustment[8]; } else { flag=0; adjustment[0]=adjustment[8]-adjustment[7]; } LCD_Fill(0x00); Out_side_collect(); LCD_Fill(0x00); adjustment_change(); enable_irq(PIT0_IRQn); while(1) { if(PIT_1sFlag == 1) { gpio_turn(PTD4); PIT_1sFlag = 0; count10S ++; } if(key_check(2) == 0) { LCD_Fill(0x00); Motor_stop(); break; } else { if(PIT_5msFlag == 1) { LDC_get(); PIT_5msFlag = 0; Steering_Change(); } if(count10S > 10) { if(gpio_get(PTC4) == 0) { while(1) { Motor_stop(); Steering_Change(); } } } if(PIT_10msFlag == 1) { Quad_count(); now = (float)guad_val; Motor_PID(now); PIT_10msFlag = 0; } if(PIT_20msFlag == 1) { PIT_20msFlag = 0; } if(PIT_50msFlag == 1) { //Result_collect(); PIT_50msFlag = 0; } //printf("guad_val:%d \r\n",(guad_val)); //TEST_display(); speed_control(); //key_choice(); uint16 i23 = gpio_get(PTC4); //LCD_BL(50,2,(uint16)(i23)); } } } }
/*! * @brief OLED显示 * @since v1.0 * @note 没啥 * Sample usage: oled_display(); */ void oled_display() { //第一行显示拨码开关状态 OLED_P6x8Str(0, 0, "12345678"); OLED_P6x8Str(50, 0, "speed:"); Display_number(86, 0, vPID.Setpoint); OLED_P6x8Str(50, 1, "Error:"); Display_number(86, 1, Error); OLED_P6x8Str(0, 2, "slope:"); DisplayFloat(36, 2, slope.slope); OLED_P6x8Str(80, 2, "P:"); DisplayFloatpid(92, 2, actuator_P); OLED_P6x8Str(0, 3, "Distance:"); Display_number(54, 3, distance); OLED_P6x8Str(86, 3, "D:"); DisplayFloatpid(98, 3, actuator_D); OLED_P6x8Str(0, 4, "Bluetooth:"); if(bluetooth == 1) OLED_P6x8Str(60, 4, "connected "); else if(bluetooth == 0) OLED_P6x8Str(60, 4, "disconnect"); else OLED_P6x8Str(60, 4, "off "); OLED_P6x8Str(0, 5, "stop?"); if(stop_done) OLED_P6x8Str(36, 5, "yes"); else OLED_P6x8Str(36, 5, "no"); #if ( CAR_NUMBER == 1 ) OLED_P6x8Str(0, 7, "Interesting"); OLED_P6x8Str(91, 7, "Car:1A"); #endif #if ( CAR_NUMBER == 2 ) OLED_P6x8Str(0, 7, "Interesting"); OLED_P6x8Str(91, 7, "Car:2B"); #endif if(!gpio_get (PTE1)) OLED_P6x8Str(0, 1, "^"); else OLED_P6x8Str(0, 1, " "); if(!gpio_get (PTE2)) OLED_P6x8Str(6, 1, "^"); else OLED_P6x8Str(6, 1, " "); if(!gpio_get (PTE3)) OLED_P6x8Str(12, 1, "^"); else OLED_P6x8Str(12, 1, " "); if(!gpio_get (PTE4)) OLED_P6x8Str(18, 1, "^"); else OLED_P6x8Str(18, 1, " "); if(!gpio_get (PTE5)) OLED_P6x8Str(24, 1, "^"); else OLED_P6x8Str(24, 1, " "); if(!gpio_get (PTE6)) OLED_P6x8Str(30, 1, "^"); else OLED_P6x8Str(30, 1, " "); if(!gpio_get (PTE7)) OLED_P6x8Str(36, 1, "^"); else OLED_P6x8Str(36, 1, " "); if(!gpio_get (PTE8)) OLED_P6x8Str(42, 1, "^"); else OLED_P6x8Str(42, 1, " "); if(key_check(KEY_A) == KEY_DOWN) { OLED_Init(); //OLED初始化 防花屏 } if(key_check(KEY_U) == KEY_DOWN) //按K2重新获取两边线数组,串口接收 { get_initial_value(img, &slope); printf("const int left_initial[110] ={"); for(i = 0; i < 110; i++) { printf("%d, ", slope.left_initial_value[i]); //printf("[%d]=%d\n", i, slope.right_initial_value[i]); } printf("};\nconst int right_initial[110] ={"); for(i = 0; i < 110; i++) { printf("%d, ", slope.right_initial_value[i]); //printf("[%d]=%d\n", i, slope.right_initial_value[i]); } printf("};//Pay attention to delete the last \",\"\n"); //initial_value_get=1; } }
/***********************************主函数**************************************/ void main(void) { for(i = 0; i < 110; i++) //装载摄像头边线初值 { slope.left_initial_value[i] = left_initial[i]; slope.right_initial_value[i] = right_initial[i]; } camera_init(imgbuff); //初始化摄像头 //配置中断服务函数 set_vector_handler(PORTA_VECTORn , PORTA_IRQHandler); //设置LPTMR的中断服务函数为 PORTA_IRQHandler set_vector_handler(DMA0_VECTORn , DMA0_IRQHandler); //设置LPTMR的中断服务函数为 PORTA_IRQHandler set_vector_handler(PORTE_VECTORn ,PORTE_IRQHandler); //设置PORTE的中断服务函数为 PORTE_IRQHandler enable_irq (PORTE_IRQn); //使能PORTE中断 port_init(PTE2, ALT1 | PULLUP ); //5 蓝牙同时发车 if(!gpio_get (PTE2)) //蓝牙通讯同时发车 { key_init(KEY_A); OLED_Init(); while(1) { #if ( CAR_NUMBER == 2 ) OLED_P6x8Str(0, 6, "Press K6 to start!"); if(key_check(KEY_A) == KEY_DOWN) //按K3发车 { uart_putchar(VCAN_PORT, ch); OLED_P6x8Str(0, 6, " "); bluetooth = 1; break; } #endif #if ( CAR_NUMBER == 1 ) OLED_P6x8Str(0, 6, "Start 2B to start!"); while(uart_query (VCAN_PORT) == 0); OLED_P6x8Str(0, 6, " "); bluetooth = 1; break; #endif } } else { bluetooth = 2; } mk60int(); init_PID(); while(1) { oled_display(); camera_get_img(); //摄像头获取图像 img_extract(img, imgbuff, CAMERA_SIZE); //解压图像 get_slope(img, &slope); //获取斜率 boundary_detection();//扫描图像获取边界 picture_analysis();//获取中线 //SetMotorVoltage(0.2,0.2); if(!gpio_get (PTE1)) { vcan_sendimg(imgbuff,CAMERA_SIZE);//摄像头看图像 } if(!gpio_get (PTE2)) //蓝牙同时发车 { #if ( CAR_NUMBER == 1 ) if(uart_querychar (VCAN_PORT, &ch) != 0) { if(ch == 's') { stop_done = 1; } } #endif #if ( CAR_NUMBER == 2 ) if(stop_done) { lptmr_delay_ms(500); //延时确保后车过线 while(1) { uart_putchar(VCAN_PORT, ch_stop); } } #endif } if(!gpio_get (PTE3)) //速度40 { vPID.Setpoint = 40; } if(!gpio_get (PTE4)) //速度45 { vPID.Setpoint = 45; } if(!gpio_get (PTE5)) //速度50 { vPID.Setpoint = 50; } if(!gpio_get (PTE6)) //速度47 { vPID.Setpoint = 46; } if(!gpio_get (PTE7)) //速度48 { vPID.Setpoint = 47; } if(!gpio_get (PTE8)) //速度49 { vPID.Setpoint = 48; } //ware1[0]=xielv; //vcan_sendware(ware1, sizeof(xielv)); /* Display_number(36, 6, ttt); Display_number(0, 6, sss); printf("%d,", left_diuxian1); printf("%d\n",tt-t); */ //printf("%d\n",speed1); //printf("%d,",left_diuxian1); //printf("%d\n",slope3); //printf("%d,",left_chazi); //printf("%d\n",right_chazi); //printf("%d,",m); //printf("%d\n",a); // if(!gpio_get (PTE8)) // { // for(l=0;l<120;l++) // { // printf("%d,",left_bianjie[l]); // } // printf("\n"); // } } }
int game_start(void) { int target, score, gameover, hit, i, j; int prev_key10, prev_key11, key10, key11; unsigned int ds; char t, nc; char disp[MAXINVNUM+1]; /* [0: 1234567890n] のような画面イメージ */ /* 照準,区切り,インベーダとUFO */ target = 0; t = '0'; score = 0; /* 照準とスコアの初期化 */ speed_count = 0; speed = INITSPEED; /* プレイ速度の初期化 */ shift_flag = FALSE; /* 敵の前進フラグの初期化 */ disp[0] = '0'; disp[1] = ':'; /* 表示フィールドの初期化 */ for (i = 2; i < MAXINVNUM; i++) disp[i] = ' '; disp[MAXINVNUM] = '\0'; gameover = FALSE; /* ゲーム終了フラグの初期化 */ key10 = key_check(10); /* キーバッファ(照準キー)の初期化 */ prev_key10 = KEYOFF; key11 = key_check(11); /* キーバッファ(発射キー)の初期化 */ prev_key11 = KEYOFF; lcd_cursor(0,1); /* 初期画面の表示 */ lcd_printstr(disp); while (gameover == FALSE){ /* ゲームオーバでなければループ */ /* キーの立上りを検出するための前回チェック時のキー状態を記憶 */ /* キーバッファ(照準キー)処理 */ if (key10 != KEYTRANS) prev_key10 = key10; /* 遷移中は前々回の値そのまま */ key10 = key_check(10); /* キーバッファ(発射キー)処理 */ if (key11 != KEYTRANS) prev_key11 = key11; /* 遷移中は前々回の値そのまま */ key11 = key_check(11); if ((prev_key10 == KEYOFF) && (key10 == KEYON)){ /* 照準キーが押されたときの処理 */ /* 照準は 0->1->...->8->9->n->0->... と順に変化する */ target++; /* 照準 +1 */ if (target > 10) target = 0; /* UFOの次は0 */ if (target < 10) t = '0' + target; /* 照準がUFOでないときのキャラ */ else t = 'n'; /* 照準がUFOのときのキャラ */ disp[0] = t; /* 照準値を表示にセット */ effect('t'); /* 効果音を鳴らす */ /* フィールドの表示 */ lcd_cursor(0,1); lcd_printstr(disp); } if ((prev_key11 == KEYOFF) && (key11 == KEYON)){ /* 発射キーが押されたときの処理 */ hit = FALSE; /* ヒット判定フラグの初期化 */ i = 2; /* 最も左の敵表示位置 */ while ((i < MAXINVNUM) && (hit != TRUE)){ /* 列の左から命中を探す */ if (disp[i] == t){ /* 照準と一致するキャラか? */ hit = TRUE; /* ヒット判定 */ ds = MAXINVNUM - i; /* 基本得点の計算(砲台に近い程大) */ score = score + ds; /* 得点追加 */ if (target > 9) score = score + ds * 2; /* UFOなら3倍の得点 */ for (j = i; j > 2; j--) disp[j] = disp[j-1]; /* 命中左側を右寄せ */ disp[2] = ' '; /* 最も左は常に空白を詰める */ /* フィールドの表示 */ lcd_cursor(0,1); lcd_printstr(disp); } i++; /* 探索位置を +1 */ } /* ヒット判定があるか右端まで調べたら, 探索終了 */ if (hit == TRUE) effect('s'); /* 命中時の効果音 */ else { /* Add 3-1 */ zanki--; /* get damage */ effect('m'); /* 失敗時の効果音 */ } } /* 敵が前進するタイミングのときの処理 */ if (shift_flag == TRUE){ /* 前進フラグが立っているなら */ if (disp[2] != ' ') disp[1] = disp[2]; /* 侵略時のみ区切りに侵入 */ for (i = 2; i < MAXINVNUM; i++) /* 敵全体を左に1つシフト */ disp[i] = disp[i + 1]; if (score % 10 == 1) nc = 'n'; /* スコアの最下位が1ならUFO出現 */ else nc = (random() % 10) + '0'; /* それ以外はランダムな数字 */ disp[MAXINVNUM - 1] = nc; /* 右端に新キャラを入れる */ shift_flag = FALSE; /* 前進フラグの消去 */ lcd_cursor(0,1); /* フィールドの表示 */ lcd_printstr(disp); } /* Modify 3-1 */ if (disp[1] != ':') { zanki--; score += game_start(); } if(zanki==0) { gameover = TRUE; } } return score; /* 得点を返す */ }
int main(void) { unsigned int score, high_score; char score_s[MAXDIGITNUM+1]; ROMEMU(); USE_UI(); timer_pri_set(0,1); random_init(); lcd_init(); key_init(); timer_init(); sound_init(); timer_set(1,100); timer_start(1); ENINT(); lcd_cursor(0,0); lcd_printstr(" 0:Game Start "); lcd_cursor(0,1); lcd_printstr(" *:High Score "); high_score = 0; lcd_cursor(0,0); while(1) { if (key_check(10) == KEYON){ /* *キー:ハイスコア表示 */ lcd_cursor(0,0); /* LCD にハイスコア表示 */ lcd_printstr(" High Score is "); lcd_cursor(0,1); lcd_printstr(" "); lcd_cursor(0,1); lcd_printstr(ntos(high_score,score_s)); } if (key_check(10) == KEYOFF){ lcd_cursor(0,0); lcd_printstr(" 0:Game Start "); lcd_cursor(0,1); lcd_printstr(" *:High Score "); } if (key_check(11) == KEYON){ /* 0キー:ゲームスタート */ zanki = 5; lcd_cursor(0,0); /* LCD に操作方法表示 */ lcd_printstr("*:Sight 0:Trig."); score = game_start(); /* ゲームスタート */ lcd_cursor(0,1); /* 得点表示欄のクリア */ lcd_printstr(" "); if (score > high_score){ /* ハイスコアのとき */ high_score = score; /* ハイスコア登録 */ lcd_cursor(0,0); /* ハイスコア表示 */ lcd_printstr(" High Score !!! "); lcd_cursor(0,1); lcd_printstr(ntos(high_score,score_s)); } else { /* ハイスコアでないとき*/ lcd_cursor(0,0); /* スコアを表示 */ lcd_printstr(" Your Score ... "); lcd_cursor(0,1); lcd_printstr(ntos(score,score_s)); } n_time = 0; while (n_time < WAITFEWSEC); /* 得点表示後にちょっと待つ */ lcd_cursor(0,0); /* LCD にメッセージ表示 */ lcd_printstr(" 0:Game Start "); lcd_cursor(0,1); lcd_printstr(" *:High Score "); } } }
void main_run() { int c, d; if (key[KEY_PGUP]) { bemfreerun = 1; old_key_pgup = 1; } else if (old_key_pgup) { old_key_pgup = 0; if (!key[KEY_LSHIFT] && !key[KEY_RSHIFT]) bemfreerun = 0; } if (bemfreerun == 2) { // A key was pressed while freerunning; disable freerun temporarily // until no key is pressed any more. if (!key_any_down()) bemfreerun = 1; } if ((fcount > 0 || (bemfreerun == 1) || (motor && fasttape))) { if (autoboot) autoboot--; fcount--; framesrun++; if (bemfreerun || (motor && fasttape)) fcount=0; if (x65c02) m65c02_exec(); else m6502_exec(); ddnoiseframes++; if (ddnoiseframes >= 5) { ddnoiseframes = 0; ddnoise_mix(); } key_check(); poll_joystick(); for (c = 0; c < 2; c++) { joybutton[c] = 0; for (d = 0; d < joy[c].num_buttons; d++) { if (joy[c].button[d].b) joybutton[c] = 1; } } if (savestate_wantload) savestate_doload(); if (savestate_wantsave) savestate_dosave(); if (key[KEY_F10] && (debug_core || debug_tube)) debug_step = 1; if (key[KEY_F12] && !resetting) { m6502_reset(); video_reset(); i8271_reset(); wd1770_reset(); sid_reset(); music5000_reset(); if (curtube != -1) tubes[curtube].reset(); tube_reset(); } resetting = key[KEY_F12]; } else { framesrun = 0; rest(1); } if (key[KEY_PGDN] && !old_key_pgdn) bempause ^= 1; old_key_pgdn = key[KEY_PGDN]; if (key[KEY_RIGHT] && !old_key_right && bempause) bemstep = 1; old_key_right = key[KEY_RIGHT]; if (framesrun > 10) fcount = 0; }