int main(void) { _delay_ms(100); LCD_Initalize(); LCD_WriteText("Anal Intruder 1"); LCD_GoTo(0, 1); LCD_WriteText("8=======D (.)(.)"); pad_init(); motor_init(); brzeczyk_init(); sensors_init(); sei(); play(power, 11); while(1) { while(!pad_get_state()) // sprawdzenie po³¹czenia z padem { m1_stop(); m2_stop(); LCD_Clear(); LCD_WriteText("Pad conn error!"); LCD_GoTo(0, 1); LCD_WriteText("Reconnecting..."); _delay_ms(500); pad_init(); tryb = 0; lcd_old = -1; motor_lcd = false; } lcd_tryb(); switch(tryb) { case 0: if(!(tab[4] & (1 << 4))) // jeœli wciœniêty trojkat tryb = 1; else if(!(tab[4] & (1 << 5))) // jeœli wciœniête jest kolko tryb = 2; break; case 1: pad_loop(); break; case 2: sensors_loop(); break; } if(!(tab[3] & (1 << 3))) { // jeœli wciœniêty start tryb = 0; m1_stop(); m2_stop(); srednia = 0; } } }
/* Begin MD5 HMAC functions */ static void hmac_md5_init(hmac_md5_ctx *ctx, const char *key, const int key_len) { unsigned char final_key[MAX_DIGEST_BLOCK_LEN] = {0}; unsigned char init_key[MAX_DIGEST_BLOCK_LEN] = {0}; int final_len = key_len; if(key_len > MAX_DIGEST_BLOCK_LEN) final_len = MAX_DIGEST_BLOCK_LEN; memcpy(init_key, key, final_len); if(MD5_BLOCK_LEN < key_len) { /* Calculate the digest of the key */ md5(final_key, init_key, final_len); } else { memcpy(final_key, init_key, key_len); } pad_init(ctx->block_inner_pad, ctx->block_outer_pad, final_key, final_len); MD5Init(&ctx->ctx_inside); MD5Update(&ctx->ctx_inside, ctx->block_inner_pad, MD5_BLOCK_LEN); MD5Init(&ctx->ctx_outside); MD5Update(&ctx->ctx_outside, ctx->block_outer_pad, MD5_BLOCK_LEN); return; }
int main(int argc, char **argv) { char *hide = "\x1b[2J\x1b[H\x1b[?25l"; char *show = "\x1b[?25h"; char **args = argv + 1; if (fb_init(FBDEV)) { fprintf(stderr, "fbpad: failed to initialize the framebuffer\n"); return 1; } if (sizeof(fbval_t) != FBM_BPP(fb_mode())) { fprintf(stderr, "fbpad: fbval_t does not match framebuffer depth\n"); return 1; } if (pad_init()) { fprintf(stderr, "fbpad: cannot find fonts\n"); return 1; } write(1, hide, strlen(hide)); signalsetup(); fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK); while (args[0] && args[0][0] == '-') args++; mainloop(args[0] ? args : NULL); write(1, show, strlen(show)); pad_free(); scr_done(); fb_free(); return 0; }
void pad_autoread() { print(PSTR("pad autoread\n\r")); pad_init(); uint8_t ld =0; while(!uart_read_ready()) { uint8_t d = pad_read(); if (ld!=d) { print_hb(0,d); ld=d; } } }
void MyPS2Application::Init() { // Initialise control pad 0 if(!pad_init(PAD_0, PAD_INIT_LOCK | PAD_INIT_ANALOGUE | PAD_INIT_PRESSURE)) { printf("Failed to initialise control pad\n"); pad_cleanup(PAD_0); exit(0); } // Allocate memory for the graphics data SPS2Manager.Initialise(1024); // 1024 * 4K Pages = 4MB Total VIFStaticDMA.Initialise(512); // 512 * 4K Pages = 2MB Static DMA VIFDynamicDMA.Initialise(256); // 256 * 4K Pages * 2 Buffers = // 2MB Dynamic DMA // Register our signal function for every possible signal (e.g. ctrl + c) for(int sig=0; sig<128; sig++) signal(sig, sig_handle); // Define the clear screen colour. We want to clear to blueish. SPS2Manager.InitScreenClear(0, 0x05, 0x30); // Register our signal function for every possible signal (i.e. ctrl + c) for(int sig=0; sig<128; sig++) signal(sig, sig_handle); // Set up the DMA packet to clear the screen. We want to clear to blue. SPS2Manager.InitScreenClear(0, 0x25, 0x10); // Set up the background sprite's size. InitializeBackgroundSprite(); // Set game state. game_state = INTRO; // Initialize the game state booleans. intro_loaded = false; menu_loaded = false; game_loaded = false; game_over_loaded = false; ball_launched = false; game_music = false; // Set up the number of rows and columns of blocks to be made. num_block_row = 5; num_block_column = 8; }
int main(void) { setSysTick(); config_PWM(); gpio_init_motor(); pen_up(); pad_init(); draw(); /* Create a task to button check. */ //xTaskCreate(H1,(signed portCHAR *) "AutoWrite", 512, NULL, tskIDLE_PRIORITY + 4, NULL ); /* Start running the tasks. */ //vTaskStartScheduler(); while(1); }
/* Begin SHA512 HMAC functions */ static void hmac_sha512_init(hmac_sha512_ctx *ctx, const char *key, const int key_len) { unsigned char final_key[MAX_DIGEST_BLOCK_LEN] = {0}; int final_len = key_len; if(key_len > MAX_DIGEST_BLOCK_LEN) final_len = MAX_DIGEST_BLOCK_LEN; /* When we eventually support arbitrary key sizes, take the digest * of the key with: sha512(final_key, init_key, final_len); */ memcpy(final_key, key, final_len); pad_init(ctx->block_inner_pad, ctx->block_outer_pad, final_key, final_len); SHA512_Init(&ctx->ctx_inside); SHA512_Update(&ctx->ctx_inside, ctx->block_inner_pad, SHA512_BLOCK_LEN); SHA512_Init(&ctx->ctx_outside); SHA512_Update(&ctx->ctx_outside, ctx->block_outer_pad, SHA512_BLOCK_LEN); return; }
uint8_t pad_do_prompt() { char cmd[17]; scan_key(cmd,17); if (strcmp(cmd,"init")==0) { pad_init(); return 1; } if ((strcmp(cmd,"test")==0) || (strcmp(cmd,"ping")==0)) { if (pad_ping()) { print_ok_nl(); } else { print_err_nl(); } return 1; } if (strcmp(cmd,"state")==0) { uint8_t d = pad_state(); if (d == PAD_REMOTE_ERROR) { print_err_nl(); } else { print_hb(0,d); print_nl(); } return 1; } if (strcmp(cmd,"led")==0) { pad_led(); return 1; } if (strcmp(cmd,"rled")==0) { pad_remote_led(); return 1; } if (strcmp(cmd,"read")==0) { uint8_t d = pad_read(); print_hb(0,d); print_nl(); return 1; } if (strcmp(cmd,"write")==0) { uint8_t v0 = scan_uint8(); if (pad_write(v0)) { print_ok_nl(); } else { print_err_nl(); } return 1; } if (strcmp(cmd,"autoread")==0) { pad_autoread(); return 1; } return 1; }
int fst_cipher_init (FSTCipher *cipher, unsigned int seed, unsigned int enc_type) { int i,j; unsigned int temp; unsigned int sortpos; unsigned char c; cipher->enc_type = enc_type; cipher->wrapcount = 0; cipher->add_to_lookup = 0; cipher->seed = seed; FST_HEAVY_DBG_2 ("init_cipher: seed = 0x%08x, enc_type = 0x%02x", seed, enc_type); if (!pad_init (&seed, enc_type, cipher->pad, sizeof (cipher->pad))) return FALSE; /* adjust pad */ c = 0; for (i = 0; i < sizeof (cipher->pad); i++) c = c | cipher->pad[i]; if (!(c & 1)) cipher->pad[0] = cipher->pad[0] | 0x71; /* init cipher->pos */ temp = seed_step (seed); temp = temp >> 16; cipher->pos = ( (temp << 6) - temp) >> 16; /* init cipher->lookup */ for(i = 0; i <sizeof (cipher->lookup); i++) cipher->lookup[i] = (unsigned char)i; if (enc_type & 0x08) { MD5Context ctx; unsigned char md5[MD5_HASH_LEN]; FST_HEAVY_DBG ("init_cipher: enc_type & 0x08"); MD5Init (&ctx); MD5Update (&ctx, cipher->pad, sizeof(cipher->pad)); MD5Final (md5, &ctx); /* correct md5 byte order on big-endian since it's converted to (unsigned int*) below */ reverse_bytes ( (unsigned int*)&md5, 4); /* modify cipher->lookup */ for (i = 0; i < sizeof (cipher->lookup); i++) { if ( (j = calculate_num( (unsigned int*) &md5, 0x100 - i) + i) != i) { unsigned char a = cipher->lookup[j]; unsigned char b = cipher->lookup[i]; cipher->lookup[i] = a; cipher->lookup[j] = b; } } } if(enc_type & 0x10) { FST_HEAVY_DBG ("init_cipher: enc_type & 0x10"); for (seed = cipher->pos, i=0; i < 20; i++) { seed = seed_step (seed); cipher->pad16[i] = seed; } seed = seed_step (seed); /* CHECKME: endianess? */ EncryptionType2::enc_type_2(cipher->pad16, seed); } /* sort cipher->pad */ sortpos = ( (cipher->pos * cipher->pos) + 2) % (sizeof(cipher->pad)-4); qsort (cipher->pad + sortpos, 5, 1, qsort_cmp_func); /* modify every third byte of cipher->pad */ for (i = 5; i < sizeof (cipher->pad); i += 3) { c = cipher->pad[i]; c = ~c + i; cipher->pad[i] = c | 1; } // print_bin_data(cipher->pad, sizeof(cipher->pad)); // print_bin_data(cipher->lookup, sizeof(cipher->lookup)); return TRUE; }
int main(void) { // Make sure these four lines are put first since some of the // other classes need the managers to be initialised so they // can pick up the correct data. SPS2Manager.Initialise(4096); // 4096 * 4K Pages = 16MB Total VIFStaticDMA.Initialise(3072); // 1536 * 4K Pages = 6MB Static DMA VIFDynamicDMA.Initialise(256); // 256 * 4K Pages * 2 Buffers = // 2MB Dynamic DMA Pipeline.Initialise(); // Initialise graphics pipline class // Initialise Lighting // Three lights and Ambient light // Direction vector Colour Pipeline.SetLight1(Vector4( 0.0f, 0.5f, -1.0f, 0.0f), Vector4( 0.0f, 0.0f, 128.0f, 0.0f)); Pipeline.SetLight2(Vector4( 1.0f, -0.5f, -1.0f, 0.0f), Vector4( 0.0f, 128.0f, 0.0f, 0.0f)); Pipeline.SetLight3(Vector4( -1.0f, -0.5f, -1.0f, 0.0f), Vector4( 128.0f, 0.0f, 0.0f, 0.0f)); // Colour Pipeline.SetAmbient(Vector4(50.0f,50.0f,50.0f,50.0f)); // Terrain to render CTerrain Terrain; // Performance timer - call after SPS2Manager.Initialise() CTimer Timer; // Set up audio devices AudioDevice DSP0(0); // Set up music in sound buffer 0 SoundSample music("go_cart", &DSP0); // Play the music! music.Play(); // Initialise control pad 0 if(!pad_init(PAD_0, PAD_INIT_LOCK | PAD_INIT_ANALOGUE | PAD_INIT_PRESSURE)) { printf("Failed to initialise control pad\n"); pad_cleanup(PAD_0); exit(0); } enable_actuator(0, 1, 1); // Initialise the VU1 manager class CVU1MicroProgram VU1MicroCode(&VU_vu1code_start, &VU_vu1code_end); // Upload the microcode VU1MicroCode.Upload(); // Register our signal function for every possible signal (i.e. ctrl + c) for(int sig=0; sig<128; sig++) signal(sig, sig_handle); // Set up the DMA packet to clear the screen. We want to clear to blue. SPS2Manager.InitScreenClear(0, 0x25, 0x50); // Set Up Camera -------------------------------------------------------------- Pipeline.PositionCamera(Vector4(0.0f, 55.0f, 80.0f, 1.0f), Vector4(0.0f, 40.0f, 0.0f, 1.0f)); // Load in texture and models ---------------------------------------------- // Set up asset loader AssetManager assetManager; assetManager.Initialize(); // Terrain texture CTexture* terrainTexture = assetManager.GetTexture("terrain"); // Set up game manager GameManager* gameManager = new GameManager; gameManager->Initialize(); // The main Render loop ------------------------------------------------------- while(g_bLoop) { // Process Audio DSP0.HandleAudio(); VIFDynamicDMA.Fire(); // Update Control Pad pad_update(PAD_0); Pipeline.Update(0, 0, 0, 0, 0); // Logic g_bLoop = gameManager->Logic(); // Render SPS2Manager.BeginScene(); // Render terrain AssetManager::GetSingleton().LoadTexture(terrainTexture); Matrix4x4 matWorld, matTrans, matScale; matTrans.Translation(0.0f, -30.0f, 0.0f); matScale.Scaling(20.0f); matWorld = matScale * matTrans; Terrain.SetWorldMatrix(matWorld); Terrain.Render(); // Render scene gameManager->Render(); SPS2Manager.EndScene(); // Dump screenshot if requested if(pad[0].pressed & PAD_R2)SPS2Manager.ScreenShot(); } // Shutdown Audio DSP0.Close(); // Shutdown control pad set_actuator(0, 0, 0); pad_cleanup(PAD_0); // Shutdown game manager gameManager->Shutdown(); // Shutdown asset manager assetManager.Shutdown(); return 0; }