void ctt_send (Domain_t *dp, Participant_t *pp, Endpoint_t *sep, Endpoint_t *dep, DDS_ParticipantVolatileSecureMessage *msg) { Writer_t *wp; DDS_Time_t time; DDS_InstanceHandleSeq handles; DDS_InstanceHandle_t h; int error; CTT_ASSERT (dp); memcpy (msg->message_identity.source_guid, dp->participant.p_guid_prefix.prefix, 12); msg->message_identity.sequence_number = psmp_seqnr++; if (pp) memcpy (msg->destination_participant_key, pp->p_guid_prefix.prefix, 12); if (dep) { memcpy (msg->destination_endpoint_key, pp->p_guid_prefix.prefix, 12); memcpy (msg->destination_endpoint_key + 12, dep->entity_id.id, 4); memcpy (msg->source_endpoint_key, dp->participant.p_guid_prefix.prefix, 12); memcpy (msg->source_endpoint_key + 12, sep->entity_id.id, 4); } CTT_TRACE ('T', msg); wp = (Writer_t *) dp->participant.p_builtin_ep [EPB_PARTICIPANT_VOL_SEC_W]; /* Send participant data. */ if (pp) { DDS_SEQ_INIT (handles); h = pp->p_builtin_ep [EPB_PARTICIPANT_VOL_SEC_R]->entity.handle; DDS_SEQ_LENGTH (handles) = DDS_SEQ_MAXIMUM (handles) = 1; DDS_SEQ_DATA (handles) = &h; sys_gettime ((Time_t *) &time); error = DDS_DataWriter_write_w_timestamp_directed (wp, msg, 0, &time, &handles); if (error) fatal_printf ("ctt_send: error sending crypto tokens message!"); } else { sys_gettime ((Time_t *) &time); error = DDS_DataWriter_write_w_timestamp (wp, msg, 0, &time); if (error) fatal_printf ("ctt_send: error sending crypto tokens message!"); } CTT_ASSERT (dp); }
/* * Main loop */ void game_run(void) { U32 tm, tmx; loaddata(); /* load cached data */ game_period = sysarg_args_period ? sysarg_args_period : GAME_PERIOD; tm = sys_gettime(); game_state = XRICK; /* main loop */ while (game_state != EXIT) { /* timer */ tmx = tm; tm = sys_gettime(); tmx = tm - tmx; if (tmx < game_period) sys_sleep(game_period - tmx); /* video */ /*DEBUG*//*game_rects=&draw_SCREENRECT;*//*DEBUG*/ sysvid_update(game_rects); draw_STATUSRECT.next = NULL; /* FIXME freerects should handle this */ /* sound */ /*snd_mix();*/ /* events */ if (game_waitevt) sysevt_wait(); /* wait for an event */ else sysevt_poll(); /* process events (non-blocking) */ /* frame */ frame(); } freedata(); /* free cached data */ }
int main(int argc, char **argv) { int pid; argv[argc] = 0; uint64_t before = sys_gettime(); if (argc > 1) { pid = fork(); if (pid < 0) { printf("Error: cannot fork process.\n"); } else if (pid == 0) { __exec(NULL, argv + 1, NULL); } waitpid(pid, NULL); } uint64_t after = sys_gettime(); printf("\n ===== Summary ===== \n"); printf("real %ld ticks.\n", after - before); printf("\n"); return 0; }
DDS_ReturnCode_t DDS_DomainParticipant_get_current_time (DDS_DomainParticipant dp, DDS_Time_t *current_time) { DDS_ReturnCode_t ret; ctrc_begind (DCPS_ID, DCPS_DP_G_TIME, &dp, sizeof (dp)); ctrc_contd (current_time, sizeof (*current_time)); ctrc_endd (); if (!current_time) return (DDS_RETCODE_BAD_PARAMETER); if (!domain_ptr (dp, 1, &ret)) return (ret); sys_gettime ((Time_t *) current_time); lock_release (dp->lock); return (DDS_RETCODE_OK); }
int msg_send_liveliness (Domain_t *dp, unsigned kind) { ParticipantMessageData msgd; Writer_t *wp; DDS_Time_t time; int error; if (!domain_ptr (dp, 1, (DDS_ReturnCode_t *) &error)) return (error); msgd.participantGuidPrefix = dp->participant.p_guid_prefix; wp = (Writer_t *) dp->participant.p_builtin_ep [EPB_PARTICIPANT_MSG_W]; lock_release (dp->lock); msgd.kind [0] = msgd.kind [1] = msgd.kind [2] = 0; if (kind == 0) /* Automatic mode. */ msgd.kind [3] = 1; else if (kind == 1) /* Manual mode. */ msgd.kind [3] = 2; else msgd.kind [3] = 0; msgd.data._length = msgd.data._maximum = 0; msgd.data._esize = 1; msgd.data._own = 1; msgd.data._buffer = NULL; sys_gettime ((Time_t *) &time); error = DDS_DataWriter_write_w_timestamp (wp, &msgd, 0, &time); #ifdef DISC_MSG_DUMP /* Message to remote participant. */ if (spdp_log) msg_data_info (&dp->participant, &msgd, 'T', 0); #endif return (error); }
/* * Main loop */ void game_run(void) { U32 tm; #if 0 U32 tmx; #endif loaddata(); /* load cached data */ game_period = sysarg_args_period ? sysarg_args_period : GAME_PERIOD; tm = sys_gettime(); game_state = XRICK; /* main loop */ while (game_state != EXIT) { #if 0 /* This code doesn't make any sense to me at all. It waits until the desired amount of time has passed and then takes the time at which it started waiting (which is not synchronous with anything) as the reference point for the next frame. This sort of works if your system takes very little time to compute the frame, but fails horribly otherwise, e.g. if you use blocking I/O (sound, vblank). */ tmx = tm; tm = sys_gettime(); tmx = tm - tmx; if (tmx < game_period) sys_sleep(game_period - tmx); #endif /* video */ /*DEBUG*//*game_rects=&draw_SCREENRECT;*//*DEBUG*/ sysvid_update(game_rects); draw_STATUSRECT.next = NULL; /* FIXME freerects should handle this */ /* timer */ /* Reset the timing if it's way out of line, such as when the game thread has been paused. */ if (sys_gettime() - tm > game_period * 10) tm = sys_gettime() - game_period / 2; /* Update sound while waiting. */ do { syssnd_callback(); } while (sys_gettime() - tm < game_period / 2); /* Use the time at which the frame should have been complete as reference for the next frame. This makes it possible to "catch up" if a frame has taken longer for some reason. */ tm = tm + game_period / 2; /* sound */ /*snd_mix();*/ /* events */ if (game_waitevt) sysevt_wait(); /* wait for an event */ else sysevt_poll(); /* process events (non-blocking) */ /* frame */ frame(); } freedata(); /* free cached data */ }
unsigned int gettime_msec(void) { return (unsigned int) sys_gettime(); }
time_t gettime_msec(void) { return (time_t)sys_gettime(); }
/* * Main introduction * * return: SCREEN_RUNNING, SCREEN_DONE, SCREEN_EXIT */ U8 screen_introMain(void) { static U8 seq = 0; static U8 seen = 0; static U8 first = TRUE; static U8 period = 0; static U32 tm = 0; U8 i, s[32]; //char tutu[50]; //sprintf(tutu,"seen %d ctrl=%d seq=%d, %d %d ",seen,control_status,seq, 0 , SCREEN_TIMEOUT); //slPrint(tutu,slLocate(2,14)); //slPrintHex(control_status,slLocate(1,2)); if (seq == 0) { draw_tilesBank = 0; if (first == TRUE) seq = 1; else seq = 4; period = game_period; game_period = 50; game_rects = &draw_SCREENRECT; #ifdef ENABLE_SOUND game_setmusic("sounds/tune5.wav", -1); #endif } syssnd_play(music_snd, 1); //sprintf(tutu,"seen %d ctrl=%d seq=%d, %d %d ",seen,control_status,seq, 0 , SCREEN_TIMEOUT); //slPrint(tutu,slLocate(2,15)); switch (seq) { case 1: /* dispay hall of fame */ sysvid_clear(); tm = sys_gettime(); #ifdef GFXPC /* Rick Dangerous title */ draw_tllst = (U8 *)screen_imainrdt; draw_setfb(32, 16); draw_filter = 0xaaaa; draw_tilesList(); /* Core Design copyright + press space to start */ draw_tllst = (U8 *)screen_imaincdc; draw_setfb(64, 80); draw_filter = 0x5555; draw_tilesList(); #endif #ifdef GFXST draw_pic(0, 0, 0x140, 0xc8, pic_splash); #endif seq = 2; break; case 2: /* wait for key pressed or timeout */ if (control_status & CONTROL_FIRE) { //slPrint("2 key pressed",slLocate(3,3)); seq = 3; } else if (sys_gettime() - tm > SCREEN_TIMEOUT) { seen++; //while(1); seq = 4; //control_status =0; } //char fff2[50]; //sprintf ( fff2,"2 not press %d %d", control_status, CONTROL_FIRE); //slPrint(fff2,slLocate(3,3)); break; case 3: /* wait for key released */ if (!(control_status & CONTROL_FIRE)) { if (seen++ == 0) seq = 4; else seq = 7; //while(1); } //control_status =0; break; case 4: /* display Rick Dangerous title and Core Design copyright */ //slPrint("case 3 ",slLocate(3,3)); sysvid_clear(); tm = sys_gettime(); /* hall of fame title */ #ifdef GFXPC draw_tllst = (U8 *)screen_imainhoft; draw_setfb(32, 0); draw_filter = 0xaaaa; draw_tilesList(); #endif #ifdef GFXST draw_pic(0, 0, 0x140, 0x20, pic_haf); #endif /* hall of fame content */ draw_setfb(56, 40); #ifdef GFXPC draw_filter = 0x5555; #endif for (i = 0; i < 8; i++) { sprintf((char *)s, "%06d@@@....@@@%s", game_hscores[i].score, game_hscores[i].name); s[26] = '\377'; s[27] = '\377'; s[28] = '\376'; draw_tllst = s; draw_tilesList(); } seq = 5; break; case 5: /* wait for key pressed or timeout */ if (control_status & CONTROL_FIRE) { //slPrint("5 key pressed",slLocate(3,3)); // if (!(control_status & CONTROL_FIRE)) seq = 6; } else if (sys_gettime() - tm > SCREEN_TIMEOUT) { seen++; seq = 1; } break; case 6: /* wait for key released */ if (!(control_status & CONTROL_FIRE)) { if (seen++ == 0) seq = 1; else seq = 7; //while(1); } //else //control_status =0; break; } if (control_status & CONTROL_EXIT) /* check for exit request */ return SCREEN_EXIT; if (seq == 7) { /* we're done */ sysvid_clear(); seq = 0; seen = 0; first = FALSE; game_period = period; return SCREEN_DONE; } else return SCREEN_RUNNING; }