/************************************ * * * TINYTOOL V2.1 * * Disk & Memory Zapper * * * * Original by Alain Birtz, 16/2/86 * * Modified for alignment by * * Kendall Whitesell, 1/6/86 * * * * Major revisions & support for * * hard drives by David Jones, * * 18/12/88 * * * ************************************/ #include "gemdefs.h" #include "osbind.h" /************************************************************************/ #define NO_WINDOW (-1) #define WI_KIND (MOVER|CLOSER|NAME) /* can be moved, closed */ /* and title exist */ #define digitoi(n) ( n - ((n<'A') ? '0' : ((n<'a') ? 55 : 87)) ) /************************************************************************/ extern int gl_apid; int menu_id ; /* our menu id */ int handle; /* virtual workstation */ int phys_handle; /* physical workstation */ int wi_handle; /* window handle */ int top_window; /* handle of topped */ int xdesk,ydesk,hdesk,wdesk; int xwork,ywork,hwork,wwork; /* desktop , work areas */ int msgbuff[8]; /* event message buffer */ int mx,my; /* mouse x and y position */ int butdown; /* button state */ int d; /* dummy variable */ int contrl[12]; /* AES, VDI variable */ int intin[128]; int ptsin[128]; int intout[128]; int ptsout[128]; int work_in[11]; /* Input GSX parameter */ int work_out[57]; /* Output GSX parameter */ int mode; /* read=0, write=1 */ int drv,side,sec,trk,buf512[256]; /* used in sector editor */ int open_flag; /* set to 1 if file is open */ int exitflg; /* exit flag */ int clear_flag; /* if 1, erase last message */ int ed_choice; /* user choice editor */ int h_chr; /* character height */ int dev=2; /* device: screen=2, printer=0 */ int intro_lvl; /* flag in draw(),clicked() */ int wd[4],ed_scr[4],mess[4]; /* rectangular area */ int ch[3][4],box[5][4]; /* clickable button */ char line_str[49]; /* dilplaying line */ char buf64[64]; /* current byte displaying */ char *main_ptr,*temp_ptr; /* work pointer */ long counter; /* first value displaying */ long file_handle; /* allocated file number */ /************************************************************************/ ltohxs(lg,s,len) /* convert in hexadecimal the value of */ char s[]; /* lg to a char string s of length */ long lg; /* 'len' with leading zero */ int len; { int i, n; long t_lg; s[len]='\0'; i=len-1; { while (i>-1) { t_lg=lg; n=(int) (t_lg & 0xFL); s[i--]=n+48+(n>9)*7; lg >>= 4; } } } /************************************************************************/ long stol(s,b) /* s is a (string) number in base b */ char *s; /* return this number (long integer) */ int b; { long lg; char cc; lg=0L; while((cc = *s++)) lg=lg*b+digitoi(cc); return(lg); } /************************************************************************/ long l_param(x,drventry) /* return a long parameter given */ int x,drventry; /* by the user, echo at x char from */ { /* start of message screen */ int base; char s[11], *t; graf_mouse(256,0); /* hide mouse */ readline(s,10,mess[0]+12+x*8,mess[1]+h_chr); graf_mouse(257,0); /* show mouse */ if (drventry && s[0]>='A' && s[0]<='P') return(s[0]-'A'); if (drventry && s[0]>='a' && s[0]<='p') return(s[0]-'a'); if (s[0]=='$') { base=16; t=s+1; } else { base=10; t=s; } return(stol(t,base)); } /************************************************************************/ i_param(x,drventry) /* return a integer parameter given */ int x,drventry; /* by the user, echo at x char from */ { /* start of message screen */ int n; n=(int) l_param(x,drventry); return(n); } /************************************************************************/ file_sel() /* set file_handle > -1 if succesfully */ { /* openned, -1 if an error occur */ static char oldpath[128]; char pathname[128],filename[13],*ptr1,*ptr2; int but_exit; if (!(*oldpath)) { strcpy(oldpath,"A:\\*.*"); *oldpath += Dgetdrv(); } *filename = '\0'; fsel_input(oldpath,filename,&but_exit);/* file selector */ strcpy(pathname,oldpath); ptr1=pathname; while(*ptr1++) /* find end of string */ ; while(*ptr1!='\\') /* find last \ and */ *ptr1--; /* replace the */ ptr2=filename; /* remainder by the */ while(*++ptr1 = *ptr2++) /* filename to complete */ ; /* the pathname */ if (but_exit) { if ((file_handle=Fopen(pathname,2))<0L) form_alert(2,"[3][Cannot open this file][Cancel]"); } else file_handle = -1L; } /************************************************************************/ time_out() { evnt_timer(200,0); } /************************************************************************/ rd_wr() /* read: mode 0, write: mode 1 */ { register char *ptr64; register int i; if (temp_ptr==buf64) return; ptr64=buf64; if (mode) { for (i=0;i<64;i++) /* copy 64 bytes in memory */ if ((long)temp_ptr>=8 && (long)temp_ptr<=0x3fffff || (long)temp_ptr>=0xfc0000 && (long)temp_ptr<=0xfeffff) *temp_ptr++ = *ptr64++; } else { for (i=0;i<64;i++) /* copy 64 bytes to work buffer */ if ((long)temp_ptr>=0 && (long)temp_ptr<=0x3fffff || (long)temp_ptr>=0xfc0000 && (long)temp_ptr<=0xfeffff) *ptr64++ = *temp_ptr++; else *ptr64++ = 0; } } /************************************************************************/ c_peek(mem_ptr) /* read protected memory */ char *mem_ptr; { temp_ptr=mem_ptr; mode=0; Supexec(rd_wr); } /************************************************************************/ c_poke(mem_ptr) /* write protected memory */ char *mem_ptr; { temp_ptr=mem_ptr; mode=1; Supexec(rd_wr); } /************************************************************************/ exit() { gemdos(0); } main() { appl_init(); phys_handle=graf_handle(&d,&d,&d,&d); menu_id=menu_register(gl_apid," Tiny tool"); graf_mouse(0,0); /* arrow form */ wi_handle=NO_WINDOW; butdown=1; multi(); } /************************************************************************/ open_vwork() /* open workstation */ { int i, rez; for(i=0;i<10;work_in[i++]=1); work_in[10]=2; handle=phys_handle; v_opnvwk(work_in,&handle,work_out); rez=Getrez(); if (!rez) { form_alert(2,"[3][ |HIGH or MEDIUM resolution only][Cancel]"); appl_exit(); exitflg=1; } h_chr= (rez==2) ? 10:8; /* high:medium resolution */ vst_height(handle,6,&d,&d,&d,&d); } /************************************************************************/ open_window() /* open window */ { wind_get(0,WF_WORKXYWH,&xdesk,&ydesk,&wdesk,&hdesk); wi_handle=wind_create(WI_KIND,xdesk+19,ydesk+30,404,19*h_chr); wind_get(wi_handle,WF_WORKXYWH,&xwork,&ywork,&wwork,&hwork); wind_set(wi_handle,WF_NAME," TINY TOOL EDITOR V2.1 ",0,0); wind_open(wi_handle,xdesk+19,ydesk+30,404,19*h_chr); } /************************************************************************/ multi() { int event, k; while (1) { event = evnt_multi(MU_MESAG | MU_BUTTON, 1,1,butdown,0,0,0,0,0,0,0,0,0,0, msgbuff,0,0,&mx,&my,&d,&d,&d,&d); wind_update(1); wind_get(wi_handle,WF_TOP,&top_window,&d,&d,&d); if (event & MU_MESAG) /*..................................................begin switch........*/ switch (msgbuff[0]) { case WM_REDRAW: if (msgbuff[3] == wi_handle) { draw(); } break; case WM_TOPPED: if (msgbuff[3] == wi_handle) { wind_set(wi_handle,WF_TOP,0,0,0,0); } break; case AC_CLOSE: if ((msgbuff[3] == menu_id)&&(wi_handle != NO_WINDOW)) { v_clsvwk(handle); wi_handle = NO_WINDOW; } break; case WM_CLOSED: if (msgbuff[3] == wi_handle) { if (open_flag==1) /* close openned file */ Fclose((int) file_handle); wind_close(wi_handle); wind_delete(wi_handle); v_clsvwk(handle); wi_handle = NO_WINDOW; } break; case WM_MOVED: if (msgbuff[3] == wi_handle) { wind_set(wi_handle,WF_CURRXYWH,((msgbuff[4] & 0xfff8)+3) ,msgbuff[5],msgbuff[6],msgbuff[7]); wind_get(wi_handle,WF_WORKXYWH,&xwork,&ywork,&wwork,&hwork); move_wrk(); } break; case AC_OPEN: if (msgbuff[4] == menu_id && wi_handle == NO_WINDOW) { open_vwork(); if (!exitflg) { intro_lvl=0; open_window(); } } break; } /*....................................................end switch........*/ if ((event & MU_BUTTON)&&(wi_handle == top_window)) if (butdown) wait(clicked()); else butdown=1; wind_update(0); } /* end of while (1) */ } /************************************************************************/ move_wrk() { register int i; wd[0]=xwork; /* work area */ wd[1]=ywork; wd[2]=xwork+wwork; wd[3]=ywork+hwork; ed_scr[0]=xwork+10; /* editor area */ ed_scr[1]=ywork+h_chr; ed_scr[2]=xwork+wwork-10; ed_scr[3]=ywork+11*h_chr; mess[0]=ed_scr[0]; /* message area */ mess[1]=ywork+hwork-5*h_chr; mess[2]=ed_scr[2]; mess[3]=mess[1]+(3*h_chr)/2; for (i=0;i<5;i++) { box[i][0]=ed_scr[0]+83*i; box[i][1]=ywork+hwork-(5*h_chr)/2; box[i][2]=box[i][0]+50; box[i][3]=box[i][1]+(3*h_chr)/2; } for (i=0;i<3;i++) { /* choice button */ ch[i][0]=xwork+(3*i+1)*wwork/10; ch[i][1]=ywork+3*hwork/4; ch[i][2]=ch[i][0]+2*wwork/10; ch[i][3]=ch[i][1]+3*h_chr/2; } } draw() { register int i; static char box_name[5][6]={" \001"," \002","RESET","WRITE","PRINT"}; static char ch_name[3][7]={"MEMORY","SECTOR"," FILE"}; static char *intr[8] = {"Parameters in decimal or hexa. (32 or $20)", "Drive : 0-15 or A-P Side : 0 or 1", "To modify a byte, click on its hexa", "representation and click WRITE", "RESET to renew, PRINT dump to printer", "\001 and \002 to see above and below", "------------------------------- by A.Birtz", "Click on the Editor of your choice"}; int pxyarray[4]; wind_get(wi_handle,WF_WORKXYWH,&xwork,&ywork,&wwork,&hwork); graf_mouse(256,0); /* hide mouse */ pxyarray[0] = xdesk; pxyarray[1] = ydesk; pxyarray[2] = xdesk+wdesk; pxyarray[3] = ydesk+hdesk; vs_clip(handle,1,pxyarray); move_wrk(); fill(wd,2,4); /* Grey texture */ if(intro_lvl) /* work screen */ { for(i=0;i<5;i++) /* work button */ { fill(box[i],0,0); /* white space */ v_gtext(handle,box[i][0]+6,box[i][1]+h_chr,box_name[i]); } } else /* introduction screen */ { fill(ed_scr,0,0); /* white space */ for(i=0;i<8;i++) v_gtext(handle,ed_scr[0]+16,ed_scr[1]+h_chr*(i+2),intr[i]); for (i=0;i<3;i++) { /* choice button */ fill(ch[i],0,0); /* white space */ v_gtext(handle,ch[i][0]+16,ch[i][1]+h_chr,ch_name[i]); } } graf_mouse(257,0); /* show mouse */ } /************************************************************************/ fill(rect,style,index) int rect[], style, index; { graf_mouse(256,0); /* hide mouse */ vsf_interior(handle,style); /* fill inside the rect. */ vsf_style(handle,index); /* with index and style param. */ vsf_color(handle,1); vswr_mode(handle,0); v_bar(handle,rect); graf_mouse(257,0); /* show mouse */ } /************************************************************************/ line(mem_adr,no) char *mem_adr; long no; { int i, j, n, h_nib, l_nib; char cc,s[9]; ltohxs(no,s,8); /* convert no to hexa. string */ i=0; while(i<2) /* 2 header space */ line_str[i++]=' '; while(i<10) { /* no in hexadecimal */ line_str[i]=s[i-2]; i++; } while(i<12) /* 2 more space */ line_str[i++]=' '; for (j=0;j<8;j++) /* 8 byte in hexa and 8 chr */ { cc = *mem_adr++; /* pick the chr in memory */ n = cc & 0xff; /* low byte */ h_nib=n>>4; /* first hexa digit of byte */ line_str[i++]=h_nib+((h_nib>9) ? 55:48); l_nib = n & 0xF; /* last hexa digit of byte */ line_str[i++]=l_nib+((l_nib>9) ? 55:48); line_str[i++]=' '; /* space between 2 byte */ /* displaying character */ if(n && (dev || (n>31 && n<128))) line_str[j+37]=cc; else /* if not printable: dot */ line_str[j+37]='.'; } line_str[i++]=' '; /* one more space before 8 chr */ for (j=46;j<48;j++) /* last 2 space */ line_str[j]=' '; line_str[j]='\0'; } /************************************************************************/ readline(s,max_len,xpos,ypos) char *s; int max_len,xpos,ypos; { int i,xy_loc[2]; char cc; vsin_mode(handle,4,1); xy_loc[0]=xpos; xy_loc[1]=ypos; i=0; do { vrq_string(handle,1,1,xy_loc,s+i); /* read char. */ cc = *(s+i); if (cc>='0' && cc<='9' || cc>='A' && cc<='P' || cc>='a' && cc<='p' || cc=='$') /* deci. or hexa. numb. or drive letter */ { v_gtext(handle,xpos,ypos,s); i++; } if (i && (cc==8 || cc==127)) /* backspace or delete */ { *(s+i)='\0'; i--; *(s+i)=' '; v_gtext(handle,xpos,ypos,s); /* erase... */ *(s+i)='\0'; } } while (cc && ied_scr[1]+h_chr && myed_scr[0]+98 && mxrect[0] && mxrect[1] && my512L) { message("Out of sector",0,1); clear_flag=1; } else display(main_ptr,counter); if (ed_choice==2) /* file editor */ { Fseek(main_ptr,(int) file_handle,0); file_read(); display(buf64,counter); } } /************************************************************************/ reset() { intro_lvl=0; draw(); } /************************************************************************/ memory() { time_out(); message("Start address:",0,1); /* keep starting address */ main_ptr=(char *)l_param(16,0); counter=(long)main_ptr; display(main_ptr,counter); } /************************************************************************/ sector() { message("Drive:",0,1); drv=i_param(7,1); if (drv>1) { message("Sector:",11,0); sec=i_param(19,0); } else { message("Side:",11,0); side=i_param(17,0); message("Sector:",21,0); sec=i_param(29,0); message("Track:",33,0); trk=i_param(40,0); } if (sec_read()<0L) return; /* error */ main_ptr=(char *)buf512; counter=0L; display(main_ptr,counter); } /************************************************************************/ sec_read() { long status; if (drv<2) status=Floprd(buf512,0L,drv,sec,trk,side,1); else status=Rwabs(0,buf512,1,sec,drv); if (status) { message("Read error!",0,1); clear_flag=1; return((int) status); } } /************************************************************************/ file() { long status; if (open_flag==1) { /* close openned file */ Fclose((int) file_handle); open_flag=0; } file_sel(); /* choose a file */ if (file_handle<0L) { intro_lvl = 0; return; /* error */ } /* Wait for inevitable WM_REDRAW message to be received */ evnt_mesag(msgbuff); draw(); message("File offset (beginning=0)",0,1); /* keep file offset */ main_ptr=(char *)l_param(30,0); open_flag=1; counter=(long)main_ptr; Fseek(counter,(int) file_handle,0); file_read(); display(buf64,counter); } /************************************************************************/ file_read() { int i; long status; status=Fread((int) file_handle,64L,buf64); if (status<0L) /* status < 0L mean error */ { message("Read error!",0,1); clear_flag=1; return; } if (status<64L) /* status > -1L mean # of read */ for (i=(int) status;i<64;i++) buf64[i]='\0'; /* fill tail with zero */ } /************************************************************************/ display(ptr_mem,lg) long lg; char *ptr_mem; { char *ptr64; int i; c_peek(ptr_mem); /* read in supervisor mode */ ptr64=buf64; graf_mouse(256,0); /* hide mouse */ fill(ed_scr,0,0); /* blank space */ for(i=2;i<10;i++) /* print no, bytes and char */ { line(ptr64,lg); v_gtext(handle,ed_scr[0]+2,ed_scr[1]+h_chr*i,line_str); ptr64 += 8L; lg += 8L; } graf_mouse(257,0); /* show mouse */ } /************************************************************************/ message(text,chr_1_pos,clear) char *text; int chr_1_pos, clear; { if (clear) fill(mess,0,0); /* white space */ graf_mouse(256,0); /* hide mouse */ v_gtext(handle,mess[0]+12+8*chr_1_pos,mess[1]+h_chr,text); /* print message */ graf_mouse(257,0); /* show mouse */ } /************************************************************************/