int main(int argc, char *argv[]) { /* int inet_pton(int af, const char *src, void *dst); */ struct in_addr tmp; char buf[sizeof(struct in_addr)] = {0}; char ip[INET_ADDRSTRLEN] = {0}; int i; __be32 ipbe32; printf("sizeof(struct in_addr):%ld\n", sizeof(struct in_addr)); inet_pton(AF_INET, "127.127.1.1", buf); inet_ntop(AF_INET, buf, ip, INET_ADDRSTRLEN); printf("ip:%s\n", ip); inet_pton(AF_INET, "127.0.0.1", &tmp.s_addr); bit_check(&tmp.s_addr, sizeof(tmp.s_addr)); inet_pton(AF_INET, "127.0.0.1", &ipbe32); bit_check(&ipbe32, sizeof(ipbe32)); return 0; }
int main(int argc, char *argv[]) { int i = 0x01020304; int tmp_i; short j = 0x0102; short tmp_j; bit_check(&i, sizeof(i)); tmp_i = htonl(i); bit_check(&tmp_i, sizeof(tmp_i)); bit_check(&j, sizeof(j)); tmp_j = htons(j); bit_check(&tmp_j, sizeof(tmp_j)); return 0; }
void select_read(void){ int button_data = return_button(); bool select = bit_check(button_data, 4); if(select != select_prev && select == 1){ if (speed_set_data.enable == 1){ speed_set_data.enable = 0; } else{ speed_set_data.enable = 1; } } select_prev = select; }
int read_button_screen(int screen_old, bool fix){ int screen = screen_old; /*BUTTON_DATA * 0 bit | DOWN * 1 bit | UP * 2 bit | LEFT * 3 bit | RIGHT * 4 bit | SELECT */ int button_data = return_button(); bool down = bit_check(button_data, 0); bool up = bit_check(button_data, 1); bool left = bit_check(button_data, 2); //bool right = bit_check(button_data, 3); bool select = bit_check(button_data, 4); if (fix == 0){ screen = 4;//no fix screen } else{ if (select == 1 || (fix == 1 && screen == 4)){// back function screen = 0; } else if (screen == 0 && left == 1){ screen = 2; } else if ((up || down) == 1 && screen == 0){ // set speed screen = 1; } } if (screen_old != screen){ clearDisplay(); } return screen; }
// include components (set bit in >glyphs) of currently loaded compound glyph (with >curgid) // returns additional space requirements (when bits below >donegid are touched) static int otf_subset_glyf(OTF_FILE *otf,int curgid,int donegid,BITSET glyphs) // {{{ { int ret=0; if (get_SHORT(otf->gly)>=0) { // not composite return ret; // done } char *cur=otf->gly+10; unsigned short flags; do { flags=get_USHORT(cur); const unsigned short sub_gid=get_USHORT(cur+2); assert(sub_gid<otf->numGlyphs); if (!bit_check(glyphs,sub_gid)) { // bad: temporarily load sub glyph const int len=otf_get_glyph(otf,sub_gid); assert(len>0); bit_set(glyphs,sub_gid); if (sub_gid<donegid) { ret+=len; ret+=otf_subset_glyf(otf,sub_gid,donegid,glyphs); // composite of composites?, e.g. in DejaVu } const int res=otf_get_glyph(otf,curgid); // reload current glyph assert(res); } // skip parameters cur+=6; if (flags&0x01) { cur+=2; } if (flags&0x08) { cur+=2; } else if (flags&0x40) { cur+=4; } else if (flags&0x80) { cur+=8; } } while (flags&0x20); // more components return ret; }
int main(void) { pid_t pid, ppid; int ret; int status; int *p = NULL; pid = vfork(); int i = 0; if (pid == 0) { //fprintf(stdout, "child process ret address:%p\n", &ret); //ret = 0x01010101; //fprintf(stdout, "child process ret address:%p\n", &ret); fprintf(stdout, "I am pid(getpid returned):%d\n", getpid()); sleep(100); if (i == 0) { // exit(0xf7); return 0xf7; } else { return 0; } } else if (pid > 0) { //fprintf(stdout, "prent process ret address:%p\n", &ret); fprintf(stdout, "my child pid(fork returned):%d\n",pid); //ret = wait(&status); //ret = waitpid(-1, NULL, 0); //ret = waitpid(-1, &status, 0); ret = waitpid(pid, &status, 0); //siginfo_t infop; //ret = waitid(P_PID, pid, &infop, WNOHANG); bit_check(&status, sizeof(status)); fprintf(stdout, "my child pid(wait returned):%d, status:%#x\n", ret, status); ret = WIFSIGNALED(status); if (ret) { fprintf(stdout, "terminated by a signal"); ret = WTERMSIG(status); fprintf(stdout, "number:%d\n", ret); } ret = WIFEXITED(status); fprintf(stdout, "child return value:%d\n", ret); #if 0 /* If WIFSIGNALED(STATUS), the terminating signal. */ #define __WTERMSIG(status) ((status) & 0x7f) /* Nonzero if STATUS indicates normal termination. */ #define __WIFEXITED(status) (__WTERMSIG(status) == 0) # define WIFEXITED(status) __WIFEXITED (__WAIT_INT (status)) #endif ret = WEXITSTATUS(status); fprintf(stdout, "child return status value:%#x\n", ret); #if 0 #define __WEXITSTATUS(status) (((status) & 0xff00) >> 8) # define WEXITSTATUS(status) __WEXITSTATUS (__WAIT_INT (status)) #endif } else { fprintf(stdout ,"create child error:%s\n", strerror(errno)); } return 0; }
int main(void) { uint8_t pad_up, pad_down, pad_left, pad_right, pad_y, pad_b, pad_x, pad_a, pad_black, pad_white, pad_start, pad_select, pad_l3, pad_r3, pad_l, pad_r, pad_left_analog_x, pad_left_analog_y, pad_right_analog_x, pad_right_analog_y; // Set clock @ 16Mhz CPU_PRESCALE(0); // Disable JTAG bit_set(MCUCR, 1 << JTD); bit_set(MCUCR, 1 << JTD); // Setup pins setup_pins(); // Init XBOX pad emulation xbox_init(true); // Pins polling and gamepad status updates for (;;) { xbox_reset_watchdog(); pad_up = !bit_check(PINC, 7); pad_down = !bit_check(PINB, 2); pad_left = !bit_check(PINB, 0); pad_right = !bit_check(PIND, 3); pad_y = !bit_check(PIND, 2); pad_b = !bit_check(PIND, 1); pad_x = !bit_check(PIND, 0); pad_a = !bit_check(PIND, 4); pad_black = !bit_check(PINC, 6); pad_white = !bit_check(PIND, 7); pad_start = !bit_check(PINE, 6); pad_select = !bit_check(PINB, 4); pad_l3 = !bit_check(PINB, 5); pad_r3 = !bit_check(PINB, 6); pad_l = !bit_check(PINB, 7); pad_r = !bit_check(PIND, 6); pad_left_analog_x = pad_left_analog_y = pad_right_analog_x = pad_right_analog_y = 0x7F; if(!bit_check(PINB, 1)) { pad_left_analog_x = 0x00; } else if(!bit_check(PINB, 3)) { pad_left_analog_x = 0xFF; } if(!bit_check(PINF, 0)) { pad_left_analog_y = 0x00; } else if(!bit_check(PINF, 1)) { pad_left_analog_y = 0xFF; } if(!bit_check(PINF, 4)) { pad_right_analog_x = 0x00; } else if(!bit_check(PINF, 5)) { pad_right_analog_x = 0xFF; } if(!bit_check(PINF, 6)) { pad_right_analog_y = 0x00; } else if(!bit_check(PINF, 7)) { pad_right_analog_y = 0xFF; } pad_up ? bit_set(gamepad_state.digital_buttons_1, XBOX_DPAD_UP) : bit_clear(gamepad_state.digital_buttons_1, XBOX_DPAD_UP); pad_down ? bit_set(gamepad_state.digital_buttons_1, XBOX_DPAD_DOWN) : bit_clear(gamepad_state.digital_buttons_1, XBOX_DPAD_DOWN); pad_left ? bit_set(gamepad_state.digital_buttons_1, XBOX_DPAD_LEFT) : bit_clear(gamepad_state.digital_buttons_1, XBOX_DPAD_LEFT); pad_right ? bit_set(gamepad_state.digital_buttons_1, XBOX_DPAD_RIGHT) : bit_clear(gamepad_state.digital_buttons_1, XBOX_DPAD_RIGHT); pad_start ? bit_set(gamepad_state.digital_buttons_1, XBOX_START) : bit_clear(gamepad_state.digital_buttons_1, XBOX_START); pad_select ? bit_set(gamepad_state.digital_buttons_1, XBOX_BACK) : bit_clear(gamepad_state.digital_buttons_1, XBOX_BACK); pad_l3 ? bit_set(gamepad_state.digital_buttons_1, XBOX_LEFT_STICK) : bit_clear(gamepad_state.digital_buttons_1, XBOX_LEFT_STICK); pad_r3 ? bit_set(gamepad_state.digital_buttons_1, XBOX_RIGHT_STICK) : bit_clear(gamepad_state.digital_buttons_1, XBOX_RIGHT_STICK); pad_a ? bit_set(gamepad_state.digital_buttons_2, XBOX_A) : bit_clear(gamepad_state.digital_buttons_2, XBOX_A); pad_b ? bit_set(gamepad_state.digital_buttons_2, XBOX_B) : bit_clear(gamepad_state.digital_buttons_2, XBOX_B); pad_x ? bit_set(gamepad_state.digital_buttons_2, XBOX_X) : bit_clear(gamepad_state.digital_buttons_2, XBOX_X); pad_y ? bit_set(gamepad_state.digital_buttons_2, XBOX_Y) : bit_clear(gamepad_state.digital_buttons_2, XBOX_Y); pad_black ? bit_set(gamepad_state.digital_buttons_2, XBOX_LB) : bit_clear(gamepad_state.digital_buttons_2, XBOX_LB); pad_white ? bit_set(gamepad_state.digital_buttons_2, XBOX_RB) : bit_clear(gamepad_state.digital_buttons_2, XBOX_RB); if(pad_start && pad_select) { bit_set(gamepad_state.digital_buttons_2, XBOX_HOME); } else { bit_clear(gamepad_state.digital_buttons_2, XBOX_HOME); } gamepad_state.l_x = pad_left_analog_x * 257 + -32768; gamepad_state.l_y = pad_left_analog_y * -257 + 32767; gamepad_state.r_x = pad_right_analog_x * 257 + -32768; gamepad_state.r_y = pad_right_analog_y * -257 + 32767; gamepad_state.lt = pad_l * 0xFF; gamepad_state.rt = pad_r * 0xFF; xbox_send_pad_state(); } }