// main framework loop - collects mouse clicks and if it hit a button calls the relevant handler with the relevant arg void run_events_loop(TreeNode* screen){ buttons = malloc(sizeof(Button*) * 100); // max num of buttons per panel get_screen_buttons(screen); realloc(buttons, sizeof(Button*) * buttons_count); SDL_Event e; int stop = 0; while (!stop){ while (SDL_PollEvent(&e) != 0) { if (e.type == SDL_QUIT) { quit_all(0); stop = 1; glob_quit = 1; game_on = 0; } else if (e.type == SDL_MOUSEBUTTONUP){ int x, y; SDL_GetMouseState(&x, &y); for (int i = 0; i < buttons_count; i++) if (is_click_on_button(x, y, buttons[i])){ if (buttons[i]->handler) buttons[i]->handler(buttons[i]->args); stop = 1; break; } } } SDL_Delay(1); } free(buttons); buttons = NULL; buttons_count = 0; }
static ssize_t print_sample(const struct iio_channel *chn, void *buf, size_t len, void *d) { fwrite(buf, 1, len, stdout); if (num_samples != 0) { num_samples--; if (num_samples == 0) { quit_all(EXIT_SUCCESS); return -1; } } return len; }
BOOL WINAPI sig_handler_fn(DWORD dwCtrlType) { /* Runs in its own thread */ switch (dwCtrlType) { case CTRL_C_EVENT: case CTRL_CLOSE_EVENT: quit_all(SIGTERM); return TRUE; default: return FALSE; } }
static void * sig_handler_thd(void *data) { sigset_t *mask = data; int ret, sig; /* Blocks until one of the termination signals is received */ do { ret = sigwait(mask, &sig); } while (ret == EINTR); quit_all(ret); return NULL; }
/* undo berechnet nebenbei aus den HW-Registern alle Parameter */ void undo(int how) { int u1u2; ww=800;hh=524;x_off=80;y_off=32; xres=640; yres=480;clock=1;interlace=0;tc=0;vsync=2; interlace=(ccreg1[1]&2)>>1; if (interlace<0) interlace=0; if (interlace>0) interlace=1; if ((monitor_type==2)&&(ccreg1[1]&4)) tc=1; else tc=0; if (ccreg1[0]&4) clock=0; else clock=1; if ((mcreg1[0]&0x100)&&(clock==1)) #if DEMO_VERSION||(VERSION==0) { long adr; adr=(char*)get_tabele(); if ((adr!=0)&&(sledgehammer!=-1)) *(int*)(adr+pl_idx*256+0x40)=sledgehammer; alert(ERROR18);quit_all(); } #else clock=2; #endif if (monitor_type==2) { hh=(vcreg1[0])/2; y_off=(vcreg1[3])/2; yres=(vcreg1[4]-vcreg1[3])/2; vsync=(vcreg1[0]-vcreg1[5]+interlace)/2; if (pl_idx!=1) { /* mono,16,256,TC */ /* xres=xcreg1[0]*4-152;*/ xres=mcreg1[3]*coltable[pl_idx]; ww=xcreg1[0]*4+8; hsync=xcreg1[5]; u1u2=4*xcreg1[0]-xres*(tc+1)+8; u1=42+2*xcreg1[3]-2*((u1u2-160)/4+x88[pl_idx]+((xres*(1+tc)-640)>>2)); u2=u1u2-u1; if (!(ccreg1[0]&0x100)) { u1=u1+64;u2=u2-64; } }
/*---------------------------------------------------*/ void init() { int n,xs,ys; int bootdev; long old_stack; ap_id=appl_init(); if (!_app) (void)menu_register(ap_id," BlowUP030"); if (ap_id==-1) { puts("ERROR: ap_id=-1 !"); exit(1); } for (n=0;n<rs_numobs;n++) /*rsrc_obfix(rs_object,n);*/ { rs_object[n].ob_x=(rs_object[n].ob_x&255)*8+ (rs_object[n].ob_x>>8); rs_object[n].ob_y=(rs_object[n].ob_y&255)*16+ (rs_object[n].ob_y>>8); rs_object[n].ob_width=(rs_object[n].ob_width&255)*8+ (rs_object[n].ob_width>>8); rs_object[n].ob_height=(rs_object[n].ob_height&255)*16+ (rs_object[n].ob_height>>8); } wind_calc(WC_BORDER,NAME|MOVER|CLOSER,0,0,rs_object[TREE1].ob_width,rs_object[TREE1].ob_height, &xs,&ys,&cw,&ch); open_f=0; if (_app) { open_w(); if (!open_f) quit_all(); } get_conf(); if (mon_type()==0) rs_object[SAVER].ob_state|=DISABLED; (void)graf_mouse(ARROW,0); old_stack=Super(0L); bootdev=*(int*)(0x446); boot_prg_name[0]=(char)(bootdev+65); (void)Super((void*)old_stack); }
int main(int argc, char **argv) { unsigned int i, nb_channels; unsigned int buffer_size = SAMPLES_PER_READ; int c, option_index = 0, arg_index = 0, ip_index = 0; struct iio_device *dev; size_t sample_size; while ((c = getopt_long(argc, argv, "+hn:t:b:s:", options, &option_index)) != -1) { switch (c) { case 'h': usage(); return EXIT_SUCCESS; case 'n': arg_index += 2; ip_index = arg_index; break; case 't': arg_index += 2; trigger_name = argv[arg_index]; break; case 'b': arg_index += 2; buffer_size = atoi(argv[arg_index]); break; case 's': arg_index += 2; num_samples = atoi(argv[arg_index]); break; case '?': return EXIT_FAILURE; } } if (arg_index + 1 >= argc) { fprintf(stderr, "Incorrect number of arguments.\n\n"); usage(); return EXIT_FAILURE; } if (ip_index) ctx = iio_create_network_context(argv[ip_index]); else ctx = iio_create_default_context(); if (!ctx) { fprintf(stderr, "Unable to create IIO context\n"); return EXIT_FAILURE; } #ifndef _WIN32 set_handler(SIGHUP, &quit_all); #endif set_handler(SIGINT, &quit_all); set_handler(SIGSEGV, &quit_all); set_handler(SIGTERM, &quit_all); dev = get_device(ctx, argv[arg_index + 1]); if (!dev) { iio_context_destroy(ctx); return EXIT_FAILURE; } if (trigger_name) { struct iio_device *trigger = get_device(ctx, trigger_name); if (!trigger) { iio_context_destroy(ctx); return EXIT_FAILURE; } if (!iio_device_is_trigger(trigger)) { fprintf(stderr, "Specified device is not a trigger\n"); iio_context_destroy(ctx); return EXIT_FAILURE; } /* Fixed rate for now */ iio_device_attr_write_longlong(trigger, "frequency", 100); iio_device_set_trigger(dev, trigger); } nb_channels = iio_device_get_channels_count(dev); if (argc == arg_index + 2) { /* Enable all channels */ for (i = 0; i < nb_channels; i++) iio_channel_enable(iio_device_get_channel(dev, i)); } else { for (i = 0; i < nb_channels; i++) { unsigned int j; struct iio_channel *ch = iio_device_get_channel(dev, i); for (j = arg_index + 2; j < argc; j++) { const char *n = iio_channel_get_name(ch); if (!strcmp(argv[j], iio_channel_get_id(ch)) || (n && !strcmp(n, argv[j]))) iio_channel_enable(ch); } } } sample_size = iio_device_get_sample_size(dev); buffer = iio_device_create_buffer(dev, buffer_size, false); if (!buffer) { fprintf(stderr, "Unable to allocate buffer\n"); iio_context_destroy(ctx); return EXIT_FAILURE; } while (app_running) { int ret = iio_buffer_refill(buffer); if (ret < 0) { fprintf(stderr, "Unable to refill buffer: %s\n", strerror(-ret)); break; } /* If there are only the samples we requested, we don't need to * demux */ if (iio_buffer_step(buffer) == sample_size) { void *start = iio_buffer_start(buffer); ptrdiff_t len = (intptr_t) iio_buffer_end(buffer) - (intptr_t) start; size_t read_len; if (num_samples && len > num_samples * sample_size) len = num_samples * sample_size; for (read_len = len; len; ) { ssize_t nb = fwrite(start, 1, len, stdout); if (nb < 0) { fprintf(stderr, "Unable to write data!\n"); goto err_destroy_buffer; } len -= nb; start = (void *)((intptr_t) start + nb); } if (num_samples) { num_samples -= read_len / sample_size; if (!num_samples) quit_all(EXIT_SUCCESS); } } else { iio_buffer_foreach_sample(buffer, print_sample, NULL); } } err_destroy_buffer: iio_buffer_destroy(buffer); iio_context_destroy(ctx); return exit_code; }
int main(void) { set_handler(SIGINT, &quit_all); set_handler(SIGSEGV, &quit_all); set_handler(SIGTERM, &quit_all); int fd = open("/dev/fb0", O_RDONLY); if (fd < 0) { fprintf(stderr, "Unable to open framebuffer\n"); return EXIT_FAILURE; } struct fb_fix_screeninfo fbinfo; struct fb_var_screeninfo varinfo; if (ioctl(fd, FBIOGET_FSCREENINFO, &fbinfo) < 0) { fprintf(stderr, "get fixed screen info failed\n"); close(fd); return EXIT_FAILURE; } if (ioctl(fd, FBIOGET_VSCREENINFO, &varinfo) < 0) { fprintf(stderr, "get var screen info failed\n"); close(fd); return EXIT_FAILURE; } close(fd); fd = open("/dev/mem", O_RDWR); if (fd < 0) { fprintf(stderr, "Unable to open /dev/mem\n"); return EXIT_FAILURE; } ipu = malloc(sizeof(*ipu)); if (!ipu) { fprintf(stderr, "Unable to allocate memory\n"); close(fd); return EXIT_FAILURE; } void *addr = mmap(NULL, 0x64, PROT_READ | PROT_WRITE, MAP_SHARED, fd, JZ4770_IPU_BASE_ADDR); if (!addr) { fprintf(stderr, "Unable to mmap /dev/mem\n"); free(ipu); close(fd); return EXIT_FAILURE; } ipu->base = addr; ipu->fb = fbinfo.smem_start; ipu->src_stride = ipu->dst_stride = fbinfo.line_length; ipu->dev_mem_fd = fd; printf("Framebuffer physical address: 0x%lx\n", fbinfo.smem_start); ipu_run_test(ipu, !varinfo.yoffset); quit_all(EXIT_SUCCESS); return 0; }
/*---------------------------------------------------*/ void event_handler() { int dummy,ev_bkstate,ev_bkreturn,ev_bbutton,ev_breturn,ev_bmx,ev_bmy; int mbuff[8]/*,xs[4]*/; int mwhich,obn; int col,ba; while(1) { mwhich=evnt_multi(MU_KEYBD|MU_BUTTON|MU_MESAG,1,1, 1,0,0, 0,0,0, 0,0,0,0, 0,mbuff,0, 0,&ev_bmx,&ev_bmy, &ev_bbutton,&ev_bkstate, &ev_bkreturn,&ev_breturn); if (mwhich&MU_KEYBD); if (mwhich&MU_BUTTON) { obn=objc_find(rs_object,0,10,ev_bmx,ev_bmy); if ((obn==SAVE)&!(rs_object[SAVE].ob_state&DISABLED)) { rs_object[SAVE].ob_state=SELECTED; redraw(SAVE); save(); rs_object[SAVE].ob_state=0; redraw(SAVE); } else if ((obn==SAVER)&!(rs_object[SAVER].ob_state&DISABLED)) { saver_flag=!saver_flag; rs_object[SAVER].ob_state=SELECTED*saver_flag; redraw(SAVER); get_modes(saver_flag,-3); /* Saver setzten */ } else { col=(obn-COL2R1)/5; ba=obn-5*col-COL2R1; if ((col>=0)&&(col<5)&&(ba>=0)&&(ba<=2)&& !(rs_object[COL2R1+5*col+ba].ob_state&DISABLED)) { radio(COL2R1+5*col+ba,COL2R1+5*col,COL2R1+5*col+2); if (ba==2) { get_modes(col,0); } else { get_modes(col,1+ba); } redraw(COL2BOX+5*col); } } (void)evnt_button(1,1,0,&dummy,&dummy,&dummy,&dummy); } if (mwhich&MU_MESAG) { if (mbuff[0]==WM_REDRAW) { get_conf(); redraw(TREE1); } if (mbuff[0]==WM_MOVED) { wind_set(wid,WF_CURRXYWH, mbuff[4],mbuff[5],mbuff[6],mbuff[7]); (void)wind_get(wid,WF_WORKXYWH, &rs_object[TREE1].ob_x,&rs_object[TREE1].ob_y, &dummy,&dummy); } if ((mbuff[0]==WM_TOPPED)||(mbuff[0]==WM_NEWTOP)) wind_set(wid,WF_TOP); if (mbuff[0]==WM_CLOSED) quit_all(); if ((mbuff[0]==AC_OPEN)&&(!open_f)) { open_w(); } if ((mbuff[0]==AC_CLOSE)&(open_f)) { open_f=0; } if ((mbuff[0]==WM_ICONIFY)||(mbuff[0]==WM_ALLICONIFY)) { wind_set(wid,WF_ICONIFY,mbuff[4],mbuff[5],82,32+24); } if ((mbuff[0]==WM_UNICONIFY)) { wind_set(wid,WF_UNICONIFY,mbuff[4],mbuff[5],mbuff[6],mbuff[7]); } } } }
int main(int argc, char **argv) { unsigned int i, nb_channels; unsigned int buffer_size = SAMPLES_PER_READ; const char *arg_uri = NULL; const char *arg_ip = NULL; int c, option_index = 0; struct iio_device *dev; size_t sample_size; int timeout = -1; bool scan_for_context = false; while ((c = getopt_long(argc, argv, "+hn:u:t:b:s:T:a", options, &option_index)) != -1) { switch (c) { case 'h': usage(); return EXIT_SUCCESS; case 'n': arg_ip = optarg; break; case 'u': arg_uri = optarg; break; case 'a': scan_for_context = true; break; case 't': trigger_name = optarg; break; case 'b': buffer_size = atoi(optarg); break; case 's': num_samples = atoi(optarg); break; case 'T': timeout = atoi(optarg); break; case '?': return EXIT_FAILURE; } } if (argc == optind) { fprintf(stderr, "Incorrect number of arguments.\n\n"); usage(); return EXIT_FAILURE; } setup_sig_handler(); if (scan_for_context) ctx = scan(); else if (arg_uri) ctx = iio_create_context_from_uri(arg_uri); else if (arg_ip) ctx = iio_create_network_context(arg_ip); else ctx = iio_create_default_context(); if (!ctx) { fprintf(stderr, "Unable to create IIO context\n"); return EXIT_FAILURE; } if (timeout >= 0) iio_context_set_timeout(ctx, timeout); dev = iio_context_find_device(ctx, argv[optind]); if (!dev) { fprintf(stderr, "Device %s not found\n", argv[optind]); iio_context_destroy(ctx); return EXIT_FAILURE; } if (trigger_name) { struct iio_device *trigger = iio_context_find_device( ctx, trigger_name); if (!trigger) { fprintf(stderr, "Trigger %s not found\n", trigger_name); iio_context_destroy(ctx); return EXIT_FAILURE; } if (!iio_device_is_trigger(trigger)) { fprintf(stderr, "Specified device is not a trigger\n"); iio_context_destroy(ctx); return EXIT_FAILURE; } /* * Fixed rate for now. Try new ABI first, * fail gracefully to remain compatible. */ if (iio_device_attr_write_longlong(trigger, "sampling_frequency", DEFAULT_FREQ_HZ) < 0) iio_device_attr_write_longlong(trigger, "frequency", DEFAULT_FREQ_HZ); iio_device_set_trigger(dev, trigger); } nb_channels = iio_device_get_channels_count(dev); if (argc == optind + 1) { /* Enable all channels */ for (i = 0; i < nb_channels; i++) iio_channel_enable(iio_device_get_channel(dev, i)); } else { for (i = 0; i < nb_channels; i++) { unsigned int j; struct iio_channel *ch = iio_device_get_channel(dev, i); for (j = optind + 1; j < (unsigned int) argc; j++) { const char *n = iio_channel_get_name(ch); if (!strcmp(argv[j], iio_channel_get_id(ch)) || (n && !strcmp(n, argv[j]))) iio_channel_enable(ch); } } } sample_size = iio_device_get_sample_size(dev); buffer = iio_device_create_buffer(dev, buffer_size, false); if (!buffer) { char buf[256]; iio_strerror(errno, buf, sizeof(buf)); fprintf(stderr, "Unable to allocate buffer: %s\n", buf); iio_context_destroy(ctx); return EXIT_FAILURE; } while (app_running) { int ret = iio_buffer_refill(buffer); if (ret < 0) { if (app_running) { char buf[256]; iio_strerror(-ret, buf, sizeof(buf)); fprintf(stderr, "Unable to refill buffer: %s\n", buf); } break; } /* If there are only the samples we requested, we don't need to * demux */ if (iio_buffer_step(buffer) == sample_size) { void *start = iio_buffer_start(buffer); size_t read_len, len = (intptr_t) iio_buffer_end(buffer) - (intptr_t) start; if (num_samples && len > num_samples * sample_size) len = num_samples * sample_size; for (read_len = len; len; ) { size_t nb = fwrite(start, 1, len, stdout); if (!nb) goto err_destroy_buffer; len -= nb; start = (void *)((intptr_t) start + nb); } if (num_samples) { num_samples -= read_len / sample_size; if (!num_samples) quit_all(EXIT_SUCCESS); } } else { iio_buffer_foreach_sample(buffer, print_sample, NULL); } } err_destroy_buffer: iio_buffer_destroy(buffer); iio_context_destroy(ctx); return exit_code; }
/*---------------------------------------------------*/ void init() { int work_in[11]; int work_out[58]; int dummy,bootdev; long ldummy; long old_stack; char ausnahme[30]="A:\\AUTO\\CAUTO.PRG"; ap_id=appl_init(); if (ap_id==-1) {puts("ERROR: ap_id=-1 !");exit(1);} if (rsrc_load("BLOWCONF.RSC")==0) { #if !FRANCAISE (void)form_alert(1,"[3][ No Resource |BLOWCONF.RSC missing][ OK ]"); #else (void)form_alert(1,"[3][ BLOWCONF.RSC | introuvable !][ OK ]"); #endif quit_all(); } #if DEMO_VERSION alert(ERROR8); form_alert(0,"[1][BlowUP030 for the ATARI-Falcon| (c) by| Georg Acher| &|\ Michael Eberl][ OK ]"); #endif handle=graf_handle(&dummy,&dummy,&dummy,&dummy); for (dummy=0;dummy<=9;dummy++) work_in[dummy]=1; work_in[10]=2; v_opnvwk(work_in, &handle, work_out ); vdi_x=work_out[0];vdi_y=work_out[1]; v_clsvwk(handle); handle=graf_handle(&dummy,&dummy,&dummy,&dummy); for(dummy=0;(dummy<5)&&(_GemParBlk.global[10]!=planetab[dummy]);dummy++); #if DEMO_VERSION if (dummy!=2) {alert(ERROR4);exit(0);} #endif pl_idx=dummy; wind_update(BEG_UPDATE); wind_update(BEG_MCTRL); (void)graf_mouse(ARROW,0); old_stack=Super(0L); bootdev=*((int*)0x446); /* Bootdevice */ boot_prg_name[0]=(char)(bootdev+65); ausnahme[0]=(char)(bootdev+65); Super((void *) old_stack); if (bootdev==0) /* Wenn von A: gebootet ... */ { ldummy=Fopen( ausnahme, FO_READ ); /* Existiert ein CAUTO-Programm? */ if (ldummy>=0) /* Ja? Dann ist das Bootlaufwerk nicht das Bootlaufwerk */ { bootdev=2; /* Laufwerk C ist richtig! */ boot_prg_name[0]=(char)(bootdev+65); /* Name korrigieren */ (void)Fclose( (int)ldummy ); } } #if DEMO_VERSION if (pl_idx!=2) {alert(ERROR4);exit(0);} #endif }