home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / utility / disk / ttool2 / ttool2.c < prev   
C/C++ Source or Header  |  1989-09-21  |  21KB  |  940 lines

  1. /************************************
  2.  *                                  *
  3.  *          TINYTOOL V2.1           *
  4.  *       Disk & Memory Zapper       *
  5.  *                                  *
  6.  * Original by Alain Birtz, 16/2/86 *
  7.  * Modified for alignment by        *
  8.  *        Kendall Whitesell, 1/6/86 *
  9.  *                                  *
  10.  * Major revisions & support for    *
  11.  * hard drives by David Jones,      *
  12.  *                         18/12/88 *
  13.  *                                  *
  14.  ************************************/
  15.  
  16. #include "gemdefs.h"
  17. #include "osbind.h"
  18.  
  19. /************************************************************************/
  20.  
  21. #define NO_WINDOW    (-1)
  22. #define WI_KIND        (MOVER|CLOSER|NAME)    /* can be moved, closed    */
  23.                         /* and title exist    */
  24.  
  25. #define digitoi(n)    ( n - ((n<'A') ? '0' : ((n<'a') ? 55 : 87)) )
  26.  
  27. /************************************************************************/
  28.  
  29. extern int    gl_apid;
  30.  
  31. int    menu_id ;                    /* our menu id            */
  32. int handle;                        /* virtual workstation        */
  33. int phys_handle;                /* physical workstation        */
  34. int    wi_handle;                    /* window handle        */
  35. int    top_window;                    /* handle of topped        */
  36. int    xdesk,ydesk,hdesk,wdesk;
  37. int    xwork,ywork,hwork,wwork;    /* desktop , work areas        */
  38. int    msgbuff[8];                    /* event message buffer        */
  39. int    mx,my;                        /* mouse x and y position    */
  40. int    butdown;                    /* button state            */
  41. int    d;                            /* dummy variable        */
  42.  
  43. int    contrl[12];                    /* AES, VDI variable        */
  44. int    intin[128];
  45. int    ptsin[128];
  46. int    intout[128];
  47. int    ptsout[128];
  48. int    work_in[11];                /* Input GSX parameter        */
  49. int    work_out[57];                /* Output GSX parameter        */
  50.  
  51. int mode;                        /* read=0, write=1        */
  52. int drv,side,sec,trk,buf512[256];    /* used in sector editor    */
  53. int open_flag;                    /* set to 1 if file is open    */
  54. int exitflg;                    /* exit flag            */
  55. int clear_flag;                    /* if 1, erase last message    */
  56. int ed_choice;                    /* user choice editor        */
  57. int h_chr;                        /* character height        */
  58. int dev=2;                        /* device: screen=2, printer=0    */
  59. int intro_lvl;                    /* flag in draw(),clicked()    */
  60. int wd[4],ed_scr[4],mess[4];    /* rectangular area        */
  61. int ch[3][4],box[5][4];            /* clickable button        */
  62. char line_str[49];                /* dilplaying line        */
  63. char buf64[64];                    /* current byte displaying    */
  64. char *main_ptr,*temp_ptr;        /* work pointer            */
  65. long counter;                    /* first value displaying    */
  66. long file_handle;                /* allocated file number    */
  67.  
  68.  
  69. /************************************************************************/
  70.  
  71. ltohxs(lg,s,len)                /* convert in hexadecimal the value of     */
  72. char s[];                        /* lg to a char string s of length    */
  73. long lg;                        /* 'len' with leading zero        */
  74. int len;
  75. {
  76. int i, n;
  77. long t_lg;
  78.  
  79.     s[len]='\0';
  80.     i=len-1;
  81.  
  82.     {
  83.     while (i>-1)
  84.         {
  85.         t_lg=lg;
  86.         n=(int) (t_lg & 0xFL);
  87.         s[i--]=n+48+(n>9)*7;
  88.         lg >>= 4;
  89.         }
  90.     }
  91. }
  92.  
  93. /************************************************************************/
  94.  
  95. long stol(s,b)            /* s is a (string) number in base b    */
  96. char *s;                /* return this number (long integer)    */
  97. int b;
  98. {
  99. long lg;
  100. char cc;
  101.  
  102.     lg=0L;
  103.     while((cc = *s++))
  104.         lg=lg*b+digitoi(cc);
  105.     return(lg);
  106. }
  107.  
  108. /************************************************************************/
  109.  
  110. long l_param(x,drventry)    /* return a long parameter given    */
  111. int x,drventry;                        /* by the user, echo at x char from    */
  112. {                            /* start of message screen        */
  113. int base;
  114. char s[11], *t;
  115.  
  116.     graf_mouse(256,0);        /* hide mouse            */
  117.     readline(s,10,mess[0]+12+x*8,mess[1]+h_chr);
  118.     graf_mouse(257,0);        /* show mouse            */
  119.  
  120.     if (drventry && s[0]>='A' && s[0]<='P')
  121.         return(s[0]-'A');
  122.     if (drventry && s[0]>='a' && s[0]<='p')
  123.         return(s[0]-'a');
  124.     if (s[0]=='$')
  125.         {
  126.         base=16;
  127.         t=s+1;
  128.         }
  129.     else
  130.         {
  131.         base=10;
  132.         t=s;
  133.         }
  134.  
  135.     return(stol(t,base));
  136. }
  137.  
  138. /************************************************************************/
  139.  
  140. i_param(x,drventry)        /* return a integer parameter given    */
  141. int x,drventry;            /* by the user, echo at x char from    */
  142. {                        /* start of message screen        */
  143. int n;
  144.  
  145.     n=(int) l_param(x,drventry);
  146.     return(n);
  147. }
  148.  
  149. /************************************************************************/
  150.  
  151. file_sel()            /* set file_handle > -1 if succesfully    */
  152. {                /* openned, -1 if an error occur    */
  153. static char oldpath[128];
  154. char pathname[128],filename[13],*ptr1,*ptr2;
  155. int but_exit;
  156.  
  157.     if (!(*oldpath)) {
  158.         strcpy(oldpath,"A:\\*.*");
  159.         *oldpath += Dgetdrv();
  160.     }
  161.  
  162.     *filename = '\0';
  163.     fsel_input(oldpath,filename,&but_exit);/* file selector    */
  164.  
  165.     strcpy(pathname,oldpath);
  166.     ptr1=pathname;
  167.     while(*ptr1++)                /* find end of string    */
  168.         ;
  169.     while(*ptr1!='\\')            /* find last \ and    */
  170.         *ptr1--;            /* replace the         */
  171.     ptr2=filename;                /* remainder by the    */
  172.     while(*++ptr1 = *ptr2++)        /* filename to complete    */
  173.         ;                /* the pathname        */
  174.  
  175.     if (but_exit)
  176.         {
  177.         if ((file_handle=Fopen(pathname,2))<0L)
  178.             form_alert(2,"[3][Cannot open this file][Cancel]");
  179.         }    
  180.     else
  181.         file_handle = -1L;
  182. }
  183.  
  184. /************************************************************************/
  185.  
  186. time_out()
  187. {
  188.     evnt_timer(200,0);
  189. }
  190.  
  191. /************************************************************************/
  192.  
  193.  
  194. rd_wr()                    /* read: mode 0, write: mode 1    */
  195. {
  196.     register char *ptr64;
  197.     register int i;
  198.  
  199.     if (temp_ptr==buf64)
  200.         return;
  201.  
  202.     ptr64=buf64;
  203.  
  204.     if (mode) {
  205.         for (i=0;i<64;i++)    /* copy 64 bytes in memory    */
  206.             if ((long)temp_ptr>=8 && (long)temp_ptr<=0x3fffff || (long)temp_ptr>=0xfc0000 && (long)temp_ptr<=0xfeffff)
  207.                 *temp_ptr++ = *ptr64++;
  208.     }
  209.     else {
  210.         for (i=0;i<64;i++)    /* copy 64 bytes to work buffer    */
  211.             if ((long)temp_ptr>=0 && (long)temp_ptr<=0x3fffff || (long)temp_ptr>=0xfc0000 && (long)temp_ptr<=0xfeffff)
  212.                 *ptr64++ = *temp_ptr++;
  213.             else
  214.                 *ptr64++ = 0;
  215.     }
  216. }
  217.  
  218. /************************************************************************/
  219.  
  220. c_peek(mem_ptr)                /* read protected memory    */
  221. char *mem_ptr;
  222. {
  223.     temp_ptr=mem_ptr;
  224.     mode=0;
  225.     Supexec(rd_wr);
  226. }
  227.  
  228. /************************************************************************/
  229.  
  230. c_poke(mem_ptr)                /* write protected memory    */
  231. char *mem_ptr;
  232. {
  233.     temp_ptr=mem_ptr;
  234.     mode=1;
  235.     Supexec(rd_wr);
  236. }
  237.  
  238. /************************************************************************/
  239.  
  240. exit()
  241. {
  242.     gemdos(0);
  243. }
  244.  
  245. main()
  246. {
  247.     appl_init();
  248.     phys_handle=graf_handle(&d,&d,&d,&d);
  249.     menu_id=menu_register(gl_apid,"  Tiny tool");
  250.     graf_mouse(0,0);        /* arrow form            */
  251.     wi_handle=NO_WINDOW;
  252.     butdown=1;
  253.  
  254.     multi();
  255. }
  256.  
  257. /************************************************************************/
  258.  
  259. open_vwork()                    /* open workstation    */
  260. {
  261. int i, rez;
  262.  
  263.     for(i=0;i<10;work_in[i++]=1);      
  264.         work_in[10]=2;
  265.     handle=phys_handle;
  266.     v_opnvwk(work_in,&handle,work_out);
  267.  
  268.     rez=Getrez();
  269.     if (!rez)
  270.         {
  271.         form_alert(2,"[3][ |HIGH or MEDIUM resolution only][Cancel]");
  272.         appl_exit();
  273.         exitflg=1;
  274.         }
  275.  
  276.     h_chr= (rez==2) ? 10:8;        /* high:medium resolution    */
  277.     vst_height(handle,6,&d,&d,&d,&d);
  278. }
  279.  
  280. /************************************************************************/
  281.  
  282. open_window()                    /* open window        */
  283. {
  284.     wind_get(0,WF_WORKXYWH,&xdesk,&ydesk,&wdesk,&hdesk);
  285.     wi_handle=wind_create(WI_KIND,xdesk+19,ydesk+30,404,19*h_chr);
  286.     wind_get(wi_handle,WF_WORKXYWH,&xwork,&ywork,&wwork,&hwork);
  287.     wind_set(wi_handle,WF_NAME," TINY TOOL EDITOR V2.1 ",0,0);
  288.     wind_open(wi_handle,xdesk+19,ydesk+30,404,19*h_chr);
  289. }
  290.  
  291. /************************************************************************/
  292.  
  293. multi()
  294. {
  295. int event, k;
  296.  
  297.     while (1)
  298.         {
  299.         event = evnt_multi(MU_MESAG | MU_BUTTON,
  300.                 1,1,butdown,0,0,0,0,0,0,0,0,0,0,
  301.                 msgbuff,0,0,&mx,&my,&d,&d,&d,&d);
  302.  
  303.         wind_update(1);
  304.  
  305.         wind_get(wi_handle,WF_TOP,&top_window,&d,&d,&d);
  306.  
  307.         if (event & MU_MESAG)
  308.  
  309. /*..................................................begin switch........*/
  310. switch (msgbuff[0])
  311. {
  312.     case WM_REDRAW:
  313.     if (msgbuff[3] == wi_handle)
  314.         {
  315.         draw();
  316.         }
  317.     break;
  318.  
  319.     case WM_TOPPED:
  320.     if (msgbuff[3] == wi_handle)
  321.         {
  322.         wind_set(wi_handle,WF_TOP,0,0,0,0);
  323.         }
  324.     break;
  325.  
  326.     case AC_CLOSE:
  327.     if ((msgbuff[3] == menu_id)&&(wi_handle != NO_WINDOW))
  328.         {
  329.         v_clsvwk(handle);
  330.         wi_handle = NO_WINDOW;
  331.         }
  332.     break;
  333.  
  334.     case WM_CLOSED:
  335.     if (msgbuff[3] == wi_handle)
  336.         {
  337.         if (open_flag==1)    /* close openned file        */
  338.             Fclose((int) file_handle);
  339.         wind_close(wi_handle);
  340.         wind_delete(wi_handle);
  341.         v_clsvwk(handle);
  342.         wi_handle = NO_WINDOW;
  343.         }
  344.     break;
  345.  
  346.     case WM_MOVED:
  347.     if (msgbuff[3] == wi_handle)
  348.         {
  349.         wind_set(wi_handle,WF_CURRXYWH,((msgbuff[4] & 0xfff8)+3)
  350.             ,msgbuff[5],msgbuff[6],msgbuff[7]);
  351.         wind_get(wi_handle,WF_WORKXYWH,&xwork,&ywork,&wwork,&hwork);
  352.         move_wrk();
  353.         }
  354.     break;
  355.  
  356.     case AC_OPEN:
  357.     if (msgbuff[4] == menu_id && wi_handle == NO_WINDOW)
  358.         {
  359.         open_vwork();
  360.         if (!exitflg)
  361.             {
  362.                 intro_lvl=0;
  363.                 open_window();
  364.             }
  365.         }
  366.     break;
  367.  
  368. }
  369. /*....................................................end switch........*/
  370.  
  371.         if ((event & MU_BUTTON)&&(wi_handle == top_window))
  372.             if (butdown)
  373.                 wait(clicked());
  374.             else
  375.                 butdown=1;
  376.  
  377.         wind_update(0);
  378.     }                    /* end of while (1)    */
  379.  
  380. }
  381.  
  382. /************************************************************************/
  383.  
  384. move_wrk()
  385. {
  386.     register int i;
  387.  
  388.     wd[0]=xwork;            /* work area            */
  389.     wd[1]=ywork;
  390.     wd[2]=xwork+wwork;
  391.     wd[3]=ywork+hwork;
  392.  
  393.     ed_scr[0]=xwork+10;        /* editor area            */
  394.     ed_scr[1]=ywork+h_chr;
  395.     ed_scr[2]=xwork+wwork-10;
  396.     ed_scr[3]=ywork+11*h_chr;
  397.  
  398.     mess[0]=ed_scr[0];        /* message area            */
  399.     mess[1]=ywork+hwork-5*h_chr;
  400.     mess[2]=ed_scr[2];
  401.     mess[3]=mess[1]+(3*h_chr)/2;
  402.  
  403.     for (i=0;i<5;i++) {
  404.         box[i][0]=ed_scr[0]+83*i;
  405.         box[i][1]=ywork+hwork-(5*h_chr)/2;
  406.         box[i][2]=box[i][0]+50;
  407.         box[i][3]=box[i][1]+(3*h_chr)/2;
  408.     }
  409.  
  410.     for (i=0;i<3;i++)
  411.     {                    /* choice button */
  412.         ch[i][0]=xwork+(3*i+1)*wwork/10;
  413.         ch[i][1]=ywork+3*hwork/4;
  414.         ch[i][2]=ch[i][0]+2*wwork/10;
  415.         ch[i][3]=ch[i][1]+3*h_chr/2;
  416.     }
  417. }
  418.  
  419. draw()
  420. {
  421.     register int i;
  422.     static char box_name[5][6]={"  \001","  \002","RESET","WRITE","PRINT"};
  423.     static char ch_name[3][7]={"MEMORY","SECTOR"," FILE"};
  424.     static char *intr[8] = {"Parameters in decimal or hexa. (32 or $20)",
  425.             "Drive : 0-15 or A-P   Side : 0 or 1",
  426.             "To modify a byte, click on its hexa",
  427.             "representation and click WRITE",
  428.             "RESET to renew, PRINT dump to printer",
  429.             "\001 and \002 to see above and below",
  430.             "------------------------------- by A.Birtz",
  431.             "Click on the Editor of your choice"};
  432.  
  433.     int pxyarray[4];
  434.  
  435.     wind_get(wi_handle,WF_WORKXYWH,&xwork,&ywork,&wwork,&hwork);
  436.     graf_mouse(256,0);        /* hide mouse            */
  437.  
  438.     pxyarray[0] = xdesk;
  439.     pxyarray[1] = ydesk;
  440.     pxyarray[2] = xdesk+wdesk;
  441.     pxyarray[3] = ydesk+hdesk;
  442.     vs_clip(handle,1,pxyarray);
  443.  
  444.     move_wrk();
  445.  
  446.     fill(wd,2,4);            /*  Grey texture    */
  447.  
  448.     if(intro_lvl)            /* work screen            */
  449.  
  450.     {
  451.     for(i=0;i<5;i++)        /* work button            */
  452.         {
  453.         fill(box[i],0,0);    /* white space            */
  454.         v_gtext(handle,box[i][0]+6,box[i][1]+h_chr,box_name[i]);
  455.         }
  456.     }
  457.  
  458.     else                /* introduction screen        */
  459.  
  460.     {
  461.     fill(ed_scr,0,0);        /*  white space            */
  462.     for(i=0;i<8;i++)
  463.         v_gtext(handle,ed_scr[0]+16,ed_scr[1]+h_chr*(i+2),intr[i]);
  464.  
  465.     for (i=0;i<3;i++)
  466.         {            /* choice button        */
  467.         fill(ch[i],0,0);    /* white space            */
  468.         v_gtext(handle,ch[i][0]+16,ch[i][1]+h_chr,ch_name[i]);
  469.         }
  470.     }
  471.     
  472.     graf_mouse(257,0);        /* show mouse            */
  473.  
  474. }
  475.  
  476. /************************************************************************/
  477.  
  478. fill(rect,style,index)
  479. int rect[], style, index;
  480. {
  481.     graf_mouse(256,0);        /* hide mouse            */
  482.     vsf_interior(handle,style);    /* fill inside the rect.    */
  483.     vsf_style(handle,index);    /* with index and style param.    */
  484.     vsf_color(handle,1);
  485.     vswr_mode(handle,0);
  486.     v_bar(handle,rect);
  487.     graf_mouse(257,0);        /* show mouse            */
  488. }
  489.  
  490. /************************************************************************/
  491.  
  492. line(mem_adr,no)
  493. char *mem_adr;
  494. long no;
  495. {
  496. int i, j, n, h_nib, l_nib;
  497. char cc,s[9];
  498.  
  499.     ltohxs(no,s,8);            /* convert no to hexa. string    */
  500.     i=0;
  501.     while(i<2)            /* 2 header space        */
  502.         line_str[i++]=' ';
  503.     while(i<10) {    /* no in hexadecimal        */
  504.         line_str[i]=s[i-2];
  505.         i++;
  506.     }
  507.     while(i<12)            /* 2 more space            */
  508.         line_str[i++]=' ';
  509.     for (j=0;j<8;j++)        /* 8 byte in hexa and 8 chr    */
  510.         {
  511.         cc = *mem_adr++;    /* pick the chr in memory    */
  512.         n = cc & 0xff;        /* low byte            */
  513.         h_nib=n>>4;        /* first hexa digit of byte    */
  514.         line_str[i++]=h_nib+((h_nib>9) ? 55:48);
  515.         l_nib = n & 0xF;    /* last hexa digit of byte    */
  516.         line_str[i++]=l_nib+((l_nib>9) ? 55:48);
  517.         line_str[i++]=' ';    /* space between 2 byte        */
  518.                     /* displaying character        */
  519.         if(n && (dev || (n>31 && n<128)))
  520.             line_str[j+37]=cc;
  521.         else            /* if not printable: dot    */
  522.             line_str[j+37]='.';
  523.         }
  524.     line_str[i++]=' ';        /* one more space before 8 chr    */
  525.     for (j=46;j<48;j++)        /* last 2 space            */
  526.         line_str[j]=' ';
  527.     line_str[j]='\0';
  528. }
  529.  
  530. /************************************************************************/
  531.  
  532. readline(s,max_len,xpos,ypos)
  533. char *s;
  534. int max_len,xpos,ypos;
  535. {
  536.     int i,xy_loc[2];
  537.     char cc;
  538.  
  539.     vsin_mode(handle,4,1);
  540.     xy_loc[0]=xpos;
  541.     xy_loc[1]=ypos;
  542.     i=0;
  543.     do {
  544.     vrq_string(handle,1,1,xy_loc,s+i);    /* read char.        */
  545.     cc = *(s+i);
  546.  
  547.     if (cc>='0' && cc<='9' || cc>='A' && cc<='P' || cc>='a' && cc<='p' || cc=='$') 
  548.                         /* deci. or hexa. numb.    or drive letter */
  549.         {
  550.         v_gtext(handle,xpos,ypos,s);
  551.         i++;
  552.         }
  553.  
  554.     if (i && (cc==8 || cc==127))        /* backspace or delete    */
  555.         {
  556.         *(s+i)='\0';
  557.         i--;
  558.         *(s+i)=' ';
  559.         v_gtext(handle,xpos,ypos,s);    /* erase...        */
  560.         *(s+i)='\0';
  561.         }
  562.     } while (cc && i<max_len);
  563. }
  564.  
  565. /************************************************************************/
  566.  
  567. clicked()
  568. {
  569. int i,r3;
  570.  
  571.     if (intro_lvl)
  572.         {
  573.         for(i=0;i<5;i++)    /* if  a clickable box        */
  574.             if (inside(box[i]))
  575.                 return(1000+i);
  576.  
  577.  
  578.         if (my>ed_scr[1]+h_chr && my<ed_scr[3]-h_chr
  579.             && mx>ed_scr[0]+98 && mx<ed_scr[0]+282)
  580.             {        /* if byte in the editor screen    */
  581.             r3=(mx-ed_scr[0]-98)/8;
  582.             if (r3%3==2)
  583.                 return(-1);
  584.             return(8*((my-ed_scr[1])/h_chr-1) + r3/3);
  585.             }
  586.         }
  587.     else
  588.         for(i=0;i<3;i++)    /* if choice editor button    */
  589.             if (inside(ch[i]))
  590.                 return(2000+i);
  591.  
  592.     return(-1);            /* bad click            */
  593. }
  594.  
  595. /************************************************************************/
  596.  
  597. inside(rect)                /* return 1 if the mouse is    */
  598. int rect[];                /* inside rect, 0 otherwise    */
  599. {
  600.     if (mx>rect[0] && mx<rect[2] && my>rect[1] && my<rect[3])
  601.         return(1);
  602.     else
  603.         return(0);
  604. }
  605.  
  606. /************************************************************************/
  607.  
  608. change(byte_no)
  609. int byte_no;
  610. {
  611. char s[3];
  612.  
  613.     message("Actual value:",0,1);
  614.     ltohxs((long) (buf64[byte_no] & 0xFF),s,2);
  615.     message(s,14,0);
  616.     message("New value:",19,0);
  617.     buf64[byte_no]=i_param(30,0);
  618.     display(buf64,counter);
  619.     clear_flag=1;
  620. }
  621.  
  622. /************************************************************************/
  623.  
  624. print()
  625. {
  626. char *s, *ptr64;
  627. int i;
  628. long lg;
  629.  
  630.     if (!Cprnos())            /* check printer status        */
  631.         {
  632.         message("Printer not ready, check and retry",0,1);
  633.         return;
  634.         }
  635.  
  636.     ptr64=buf64;
  637.     lg=counter;
  638.     dev=0;
  639.  
  640.     Cprnout('\n');            /* blank line            */
  641.     Cprnout('\r');
  642.  
  643.     for(i=0;i<8;i++)        /* print no, bytes and char    */
  644.         {
  645.         Cprnout('\n');        /* next line            */
  646.         Cprnout('\r');
  647.         line(ptr64,lg);
  648.         s=line_str;
  649.         while (*s)
  650.             Cprnout(*s++);    /* the line...            */
  651.         ptr64 += 8L;
  652.         lg += 8L;
  653.         }
  654.  
  655.     clear_flag=1;
  656.     dev=2;
  657. }
  658.  
  659. /************************************************************************/
  660.  
  661. wait(clk)
  662. int clk;
  663. {
  664.     if (clk<0)
  665.         return;
  666.  
  667.     if (intro_lvl)            /* work screen            */
  668.         {
  669.         if (clear_flag)
  670.                 {
  671.                 fill(mess,0,0);
  672.                 clear_flag=0;
  673.                 }
  674.  
  675.         switch(clk) {
  676.         case 1000:up();break;        /* up arrow button    */
  677.         case 1001:down();break;        /* down arrow button    */
  678.         case 1002:reset();break;    /* RESET button        */
  679.         case 1003:write();break;    /* WRITE button        */
  680.         case 1004:print();break;    /* PRINT button        */
  681.         default:break; }
  682.  
  683.         if (clk<1000)
  684.             change(clk);
  685.         }
  686.     else
  687.         {
  688.  
  689.         ed_choice=clk-2000;        /* choice screen    */
  690.         intro_lvl=1;
  691.         draw();
  692.  
  693.         switch(ed_choice) {
  694.         case 0:memory();break;        /* MEMORY button    */
  695.         case 1:sector();break;        /* SECTOR button    */
  696.         case 2:file();break;        /* FILE button        */
  697.         default:break; }
  698.  
  699.         }
  700. }
  701.  
  702. /************************************************************************/
  703.  
  704. write()
  705. {
  706. long status;
  707.  
  708.     if (ed_choice==0)        /* write byte in memory        */
  709.         {
  710.         c_poke(main_ptr);
  711.         status=0L;
  712.         }
  713.  
  714.     if (ed_choice==1)        /* write current sector        */
  715.         {
  716.         c_poke(main_ptr);
  717.         if (drv<2)
  718.             status=Flopwr(buf512,0L,drv,sec,trk,side,1);
  719.         else
  720.             status=Rwabs(1,buf512,1,sec,drv);
  721.         }
  722.  
  723.     if (ed_choice==2)        /* write 64 bytes on file    */
  724.         {
  725.         Fseek(main_ptr,(int) file_handle,0);
  726.         status=Fwrite((int) file_handle,64L,buf64);
  727.         }
  728.  
  729.     if (status<0L)
  730.         message("Write error!",0,1);
  731.     else
  732.         message("Done...",0,1);
  733.  
  734.     clear_flag=1;
  735. }
  736.     
  737. /************************************************************************/
  738.  
  739. down()
  740. {
  741.     main_ptr += 64;
  742.     counter += 64L;
  743.     n_up_down();
  744. }
  745.  
  746. /************************************************************************/
  747.  
  748. up()
  749. {
  750.     main_ptr -= 64;
  751.     counter -= 64L;
  752.     n_up_down();
  753. }
  754.  
  755. /************************************************************************/
  756.  
  757. n_up_down()
  758. {
  759.     if (ed_choice==0)        /* memory editor        */
  760.         display(main_ptr,counter);
  761.  
  762.     if (ed_choice==1)        /* sector editor        */
  763.         if (counter<0L || counter>512L)
  764.             {
  765.             message("Out of sector",0,1);
  766.             clear_flag=1;
  767.             }
  768.         else
  769.             display(main_ptr,counter);
  770.  
  771.     if (ed_choice==2)        /* file editor            */
  772.         {
  773.         Fseek(main_ptr,(int) file_handle,0);
  774.         file_read();
  775.         display(buf64,counter);
  776.         }
  777. }
  778.  
  779. /************************************************************************/
  780. reset()
  781. {
  782.     intro_lvl=0;
  783.     draw();
  784. }
  785.  
  786. /************************************************************************/
  787.  
  788. memory()
  789. {
  790.     time_out();
  791.     message("Start address:",0,1);
  792.                     /* keep starting address    */
  793.     main_ptr=(char *)l_param(16,0);
  794.     counter=(long)main_ptr;
  795.     display(main_ptr,counter);
  796. }
  797.  
  798. /************************************************************************/
  799.  
  800. sector()
  801. {
  802.     message("Drive:",0,1);
  803.     drv=i_param(7,1);
  804.     if (drv>1) {
  805.         message("Sector:",11,0);
  806.         sec=i_param(19,0);
  807.     }
  808.     else {
  809.         message("Side:",11,0);
  810.         side=i_param(17,0);
  811.         message("Sector:",21,0);
  812.         sec=i_param(29,0);
  813.         message("Track:",33,0);
  814.         trk=i_param(40,0);
  815.     }
  816.  
  817.     if (sec_read()<0L)
  818.         return;            /* error            */
  819.     main_ptr=(char *)buf512;
  820.     counter=0L;
  821.     display(main_ptr,counter);
  822. }
  823.  
  824. /************************************************************************/
  825.  
  826. sec_read()
  827. {
  828. long status;
  829.  
  830.     if (drv<2)
  831.         status=Floprd(buf512,0L,drv,sec,trk,side,1);
  832.     else
  833.         status=Rwabs(0,buf512,1,sec,drv);
  834.  
  835.     if (status)
  836.         {
  837.         message("Read error!",0,1);
  838.         clear_flag=1;
  839.         return((int) status);
  840.         }
  841. }
  842.  
  843. /************************************************************************/
  844.  
  845. file()
  846. {
  847.     long status;
  848.  
  849.     if (open_flag==1)
  850.         {            /* close openned file        */
  851.         Fclose((int) file_handle);
  852.         open_flag=0;
  853.         }
  854.  
  855.     file_sel();            /* choose a file    */
  856.  
  857.     if (file_handle<0L) {
  858.         intro_lvl = 0;
  859.         return;            /* error            */
  860.     }
  861.  
  862.     /* Wait for inevitable WM_REDRAW message to be received */
  863.     evnt_mesag(msgbuff);
  864.  
  865.     draw();
  866.  
  867.     message("File offset (beginning=0)",0,1);
  868.                     /* keep file offset        */
  869.     main_ptr=(char *)l_param(30,0);
  870.  
  871.     open_flag=1;
  872.     counter=(long)main_ptr;
  873.     Fseek(counter,(int) file_handle,0);
  874.     file_read();
  875.     display(buf64,counter);
  876.  
  877. }
  878.  
  879. /************************************************************************/
  880.  
  881. file_read()
  882. {
  883. int i;
  884. long status;
  885.  
  886.     status=Fread((int) file_handle,64L,buf64);
  887.     if (status<0L)            /* status < 0L mean error    */
  888.         {
  889.         message("Read error!",0,1);
  890.         clear_flag=1;
  891.         return;
  892.         }
  893.     if (status<64L)            /* status > -1L mean # of read    */
  894.         for (i=(int) status;i<64;i++)
  895.             buf64[i]='\0';    /* fill tail with zero        */
  896. }
  897.  
  898. /************************************************************************/
  899.  
  900. display(ptr_mem,lg)
  901. long lg;
  902. char *ptr_mem;
  903. {
  904. char *ptr64;
  905. int i;
  906.  
  907.     c_peek(ptr_mem);        /* read in supervisor mode    */
  908.  
  909.     ptr64=buf64;
  910.  
  911.     graf_mouse(256,0);        /* hide mouse            */
  912.     fill(ed_scr,0,0);        /* blank space            */
  913.  
  914.     for(i=2;i<10;i++)        /* print no, bytes and char    */
  915.         {
  916.         line(ptr64,lg);
  917.         v_gtext(handle,ed_scr[0]+2,ed_scr[1]+h_chr*i,line_str);
  918.         ptr64 += 8L;
  919.         lg += 8L;
  920.         }
  921.  
  922.     graf_mouse(257,0);        /* show mouse            */
  923. }
  924.  
  925. /************************************************************************/
  926.  
  927. message(text,chr_1_pos,clear)
  928. char *text;
  929. int chr_1_pos, clear;
  930. {
  931.     if (clear)
  932.         fill(mess,0,0);        /* white space            */
  933.     graf_mouse(256,0);        /* hide mouse            */
  934.     v_gtext(handle,mess[0]+12+8*chr_1_pos,mess[1]+h_chr,text);
  935.                     /* print message        */
  936.     graf_mouse(257,0);        /* show mouse            */
  937. }
  938.  
  939. /************************************************************************/
  940.