home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / AHDI / TTFHDX / DEFSCROL.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  9.8 KB  |  373 lines

  1. /*  DEFSCROL.C                            */
  2. /*    3/1/88        Derek Mui                */
  3. /*    3/2/88        Edited by ml. for use in factory HDX    */
  4.  
  5.  
  6. #include <obdefs.h>
  7. #include <osbind.h>
  8. #include <gemdefs.h>
  9. #include "fhdx.h"
  10. #include "define.h"
  11. #include "addr.h"
  12. #include "deflst.h"
  13. #include "scroll.h"
  14.  
  15. int    topptr;        /* top pointer    */
  16. int    totcnt;        /* total number of items */
  17. PADDR    *xampaddr;    /* defect list to be examined */
  18.  
  19. extern int xdesk, ydesk, wdesk, hdesk;    /* dimensions of desktop */
  20. extern int npndefs;
  21. extern PADDR *nppaddr;
  22.  
  23. /*
  24.  * Indices to entries in the window.
  25.  */
  26. int defent[] = {
  27.     ENTRY0, ENTRY1, ENTRY2, ENTRY3,
  28.     ENTRY4, ENTRY5, ENTRY6, ENTRY7
  29. };
  30.  
  31.  
  32. xamdeflst()
  33. {
  34.     long mul;
  35.     int     botptr, bret, value;
  36.     int  xoff, yoff, mx, my;
  37.     int  i, ret, cont;
  38.     int  np, xam;
  39.     int  k1, k2;
  40.  
  41.     /* Allocate memory to hold defects */
  42.     if ((xampaddr = mymalloc(npndefs*(sizeof(PADDR)))) <= 0) {
  43.         return err(nomemory);
  44.     }
  45.     
  46.     for (np = 0; np < npndefs; np++) {
  47.         xampaddr[np].exist = nppaddr[np].exist;
  48.         xampaddr[np].head = nppaddr[np].head;
  49.         xampaddr[np].cylndr = nppaddr[np].cylndr;
  50.         xampaddr[np].btoffst = nppaddr[np].btoffst;
  51.     }
  52.     
  53.     r_items();        /* read items */
  54.     
  55.     totcnt = npndefs;
  56.     if (npndefs > NM_ITEMS)        /* bigger than one window */
  57.     botptr = npndefs - NM_ITEMS;
  58.     else
  59.     botptr = 0;
  60.  
  61.     cont = TRUE;            /* control flag    */
  62.     while(cont) {
  63.     bret = form_do(xamform, -1);
  64.     graf_mkstate(&mx, &my, &k1, &k2);    /* graf mkstate    */
  65.     ret = bret & 0x7FFF;            /* mask off double click */
  66.     LWSET(OB_STATE(xamform, ret), 0);
  67.     value = 1;            /* scroll factor */
  68.  
  69.     switch (ret) {        /* Big Switch */
  70.         case FSVSLID:        
  71.         objc_offset(xamform, FSVELEV, &xoff, &yoff);
  72.         value = NM_ITEMS;        /* one full window size    */
  73.         if (my <= yoff)
  74.             goto up;        
  75.         goto down;
  76.  
  77.         case FSVELEV:
  78.         value = graf_slidebox(xamform, FSVSLID, FSVELEV, TRUE);
  79.         mul = (npndefs - NM_ITEMS) * value;
  80.         mul /= 1000;
  81.         value = (int)mul; 
  82.         value = (topptr - value);
  83.         if (value >= 0)
  84.             goto up;            /* go up */
  85.         else
  86.             value = -value;        /* go down */
  87.  
  88. down:        case FDNAROW:            /* scroll down */
  89.         if (topptr == botptr)
  90.             break;
  91.  
  92.         if ((topptr + value) <= botptr)
  93.             topptr += value;
  94.         else
  95.             topptr = botptr;
  96.  
  97.         goto sfiles;            
  98.  
  99. up:        case FUPAROW:            /* scroll up */
  100.         if (!topptr)
  101.             break;
  102.  
  103.         if ((topptr - value) >= 0)
  104.             topptr -= value;
  105.         else
  106.             topptr = 0;
  107.  
  108. sfiles:        r_show(topptr);        /* redisplay the file */
  109.         break;
  110.  
  111.         case FCLSBOX:
  112.           cont = FALSE;
  113.           break;
  114.  
  115.         default:
  116.           if (ret >= ENTRY0 && ret <= ENTRY7) {
  117.                 erasemsg();        /* erase EXAMINING box */
  118.                 want2edt(ret);    /* let user edit entry */
  119.                 dsplymsg(xamform);    /* redraw EXAMINING box */
  120.           }
  121.           break;  
  122.     }                /* end of switch */
  123.     }                    /* while */
  124.     erasemsg();
  125.     
  126.     /* New inputted list = Examined list */
  127.     for (xam = 0, np = 0; xam < npndefs; xam++) {
  128.         if (xampaddr[xam].exist) {
  129.             nppaddr[np].head = xampaddr[xam].head;
  130.             nppaddr[np].cylndr = xampaddr[xam].cylndr;
  131.             nppaddr[np].btoffst = xampaddr[xam].btoffst;
  132.             np++;
  133.         }
  134.     }
  135.     npndefs = np;    /* current number of input entries */
  136.     free(xampaddr);
  137.     return (TRUE);
  138. }
  139.  
  140.  
  141.  
  142. /*---------------*/
  143. /* read in items */
  144. /*---------------*/
  145.  
  146. int    
  147. r_items()
  148. {
  149.     int  h, status;
  150.     int  full, i;
  151.     char temp[10];
  152.  
  153.     topptr = 0;            /* reset top pointer    */
  154.  
  155.     /* Feed the window with inputted entries */
  156.     if (npndefs < NM_ITEMS)
  157.         full = npndefs;
  158.     else
  159.         full = NM_ITEMS;
  160.         
  161.     for (i = 0; i < full; i++) {
  162.         /* Head number */
  163.         itoa(xampaddr[i].head, (xamform[defent[i]].ob_spec)->te_ptext);
  164.         
  165.         /* Cylinder number */
  166.         itoa(xampaddr[i].cylndr, temp);
  167.         strcat((xamform[defent[i]].ob_spec)->te_ptext, temp);
  168.         if (xampaddr[i].cylndr < 10)
  169.        strcat((xamform[defent[i]].ob_spec)->te_ptext, "   ");
  170.     else if (xampaddr[i].cylndr < 100)
  171.        strcat((xamform[defent[i]].ob_spec)->te_ptext, "  ");
  172.     else if (xampaddr[i].cylndr < 1000)
  173.        strcat((xamform[defent[i]].ob_spec)->te_ptext, " ");
  174.        
  175.     /* Byte offset */
  176.         itoa(xampaddr[i].btoffst, temp);
  177.         strcat((xamform[defent[i]].ob_spec)->te_ptext, temp);
  178.  
  179.     xamform[defent[i]].ob_flags |= (SELECTABLE | TOUCHEXIT);
  180.         LWSET(OB_STATE(xamform, defent[i]), NORMAL);
  181.     }
  182.     
  183.     for (; i < NM_ITEMS; i++) {
  184.     strcpy((xamform[defent[i]].ob_spec)->te_ptext, "@");
  185.     xamform[defent[i]].ob_flags &= ~(SELECTABLE | TOUCHEXIT);
  186.         LWSET(OB_STATE(xamform, defent[i]), DISABLED);
  187.     }
  188.     
  189.     h = LWGET(OB_HEIGHT(xamform, FSVSLID));
  190.  
  191.     if (npndefs > NM_ITEMS)
  192.     h = (h * NM_ITEMS) / npndefs;
  193.  
  194.     LWSET(OB_Y(xamform, FSVELEV), 0);      /* move it to the top */
  195.     LWSET(OB_HEIGHT(xamform, FSVELEV), h);  /* height of the elevator */
  196.     dsplymsg(xamform);
  197. }
  198.     
  199.  
  200.  
  201. /*----------------------------------------------*/
  202. /*    show items and update the scroll bar    */
  203. /*----------------------------------------------*/
  204.  
  205. r_show(index)
  206. int index;        /* where to start */
  207. {    
  208.     int  i, ndx, full, x, y;
  209.     long h;
  210.     char temp[10];
  211.     PADDR *curpaddr;
  212.     int  curent;
  213.     
  214.  
  215.     if ((full = index + NM_ITEMS) > npndefs)
  216.         full = npndefs;
  217.         
  218.     /* Feed the window with inputted entries */
  219.     for (i = index, ndx = 0; i < full; i++,ndx++) {
  220.         curpaddr = xampaddr + i;
  221.         curent = defent[ndx];
  222.         
  223.         /* Head number */
  224.         itoa(curpaddr->head, (xamform[curent].ob_spec)->te_ptext);
  225.         
  226.         /* Cylinder number */
  227.         itoa(curpaddr->cylndr, temp);
  228.         strcat((xamform[curent].ob_spec)->te_ptext, temp);
  229.         if (curpaddr->cylndr < 10)
  230.        strcat((xamform[curent].ob_spec)->te_ptext, "   ");
  231.     else if (curpaddr->cylndr < 100)
  232.        strcat((xamform[curent].ob_spec)->te_ptext, "  ");
  233.     else if (curpaddr->cylndr < 1000)
  234.        strcat((xamform[curent].ob_spec)->te_ptext, " ");
  235.        
  236.     /* Byte offset */
  237.         itoa(curpaddr->btoffst, temp);
  238.         strcat((xamform[curent].ob_spec)->te_ptext, temp);
  239.         
  240.         if (!curpaddr->exist) {
  241.             xamform[curent].ob_state = DISABLED;
  242.             xamform[curent].ob_flags &= ~(SELECTABLE | TOUCHEXIT);
  243.     } else {
  244.         xamform[curent].ob_state = NORMAL;
  245.             xamform[curent].ob_flags |= (SELECTABLE | TOUCHEXIT);
  246.     }
  247.         
  248.     objc_draw(xamform, curent, 1, 0, 0, wdesk, hdesk);
  249.     }
  250.     
  251.     for (; ndx < NM_ITEMS; ndx++) {
  252.         curent = defent[ndx];
  253.     xamform[curent].ob_state = DISABLED;
  254.         xamform[curent].ob_flags &= ~(SELECTABLE | TOUCHEXIT);
  255.         strcpy((xamform[curent].ob_spec)->te_ptext, "@");
  256.     objc_draw(xamform, curent, 1, 0, 0, wdesk, hdesk);
  257.     }
  258.         
  259.  
  260.     h = LWGET(OB_HEIGHT(xamform, FSVSLID));
  261.     h = topptr * h;
  262.     
  263.     if (totcnt)
  264.     h = h / totcnt;
  265.  
  266.     LWSET(OB_Y(xamform, FSVELEV), h);
  267.     /* draw the new one */
  268.     objc_draw(xamform, FSVSLID, MAX_DEPTH, 0, 0, wdesk, hdesk);
  269. }
  270.  
  271.  
  272. /*
  273.  *  An entry is selected while examining to be edited.
  274.  */
  275. want2edt(ent)
  276. int ent;
  277. {
  278.     int i, stat, stent;
  279.     PADDR *curpaddr;
  280.     char temp[10];
  281.     
  282.     for (i = 0; i < NM_ITEMS; i++) {
  283.         if (ent == defent[i]) {
  284.             curpaddr = xampaddr + topptr + i;
  285.             itoa(curpaddr->head, edtform[EDHDNUM].ob_spec->te_ptext);
  286.             itoa(curpaddr->cylndr, edtform[EDCYLNUM].ob_spec->te_ptext);
  287.             itoa(curpaddr->btoffst, edtform[EDBYTOFF].ob_spec->te_ptext);
  288.             edtform[EDTCN].ob_state = NORMAL;
  289.             edtform[EDTDEL].ob_state = NORMAL;
  290.             edtform[EDTOK].ob_state = NORMAL;
  291.             graf_mouse(ARROW, 0L);
  292.             dsplymsg(edtform);
  293.             stent = EDHDNUM;
  294.             
  295. redoent:    edtform[EDTOK].ob_state = NORMAL;
  296.             objc_draw(edtform, EDTOK, 1, 0, 0, wdesk, hdesk);
  297.         stat = form_do(edtform, stent);
  298.  
  299.             switch (stat) {
  300.                 case EDTDEL:
  301.                     curpaddr->exist = FALSE;
  302.                     xamform[ent].ob_state = DISABLED;
  303.                     xamform[ent].ob_flags &= ~(SELECTABLE | TOUCHEXIT);
  304.                     break;
  305.                     
  306.                 case EDTOK:
  307.             /* Check validity of input and perform appropiate action */
  308.             switch (chknput(edtform, EDHDNUM, EDCYLNUM, EDBYTOFF)) {
  309.             
  310.             case OK:
  311.                 /* Update entry */
  312.                 gpaddr(curpaddr, edtform, EDHDNUM, EDCYLNUM,
  313.                         EDBYTOFF);
  314.                         
  315.                 /* Update head number on screen */
  316.                 itoa(curpaddr->head,
  317.                         xamform[ent].ob_spec->te_ptext);
  318.                         
  319.                 /* Update cylinder number on screen */
  320.                 itoa(curpaddr->cylndr, temp);
  321.                 strcat(xamform[ent].ob_spec->te_ptext, temp);
  322.                 if (curpaddr->cylndr < 10)
  323.                     strcat(xamform[ent].ob_spec->te_ptext, "   ");
  324.                 else if (curpaddr->cylndr < 100)
  325.                     strcat(xamform[ent].ob_spec->te_ptext, "  ");
  326.                 else if (curpaddr->cylndr < 1000)
  327.                     strcat(xamform[ent].ob_spec->te_ptext, " ");
  328.                 
  329.                 /* Update byte offset on screen */
  330.                 itoa(curpaddr->btoffst, temp);
  331.                 strcat(xamform[ent].ob_spec->te_ptext, temp);
  332.                 break;
  333.                 
  334.             case INCMPL:
  335.             case EMPTY:
  336.                 form_alert(1, npcmpent);
  337.                 stent = EDHDNUM;
  338.                 goto redoent;
  339.                 
  340.             case HD2BIG:
  341.                 form_alert(1, bghdnum);
  342.                 clrnput(edtform, EDHDNUM, -1, -1, EDTBOX);
  343.                 stent = EDHDNUM;
  344.                 goto redoent;
  345.  
  346.             case CYL2BIG:
  347.                 form_alert(1, bgcylnum);
  348.                 clrnput(edtform, -1, EDCYLNUM, -1, EDTBOX);
  349.                 stent = EDCYLNUM;
  350.                 goto redoent;
  351.  
  352.             case BYT2BIG:
  353.                 form_alert(1, bgbytnum);
  354.                 clrnput(edtform, -1, -1, EDBYTOFF, EDTBOX);
  355.                 stent = EDBYTOFF;
  356.                 goto redoent;
  357.                 
  358.             default:
  359.                 break;
  360.             }
  361.                     
  362.                 case EDTCN:
  363.                     break;
  364.  
  365.         default:
  366.             break;                    
  367.         }
  368.         erasemsg();
  369.         break;
  370.         }
  371.     }
  372. }
  373.