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 / BSLSCROL.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  7.7 KB  |  303 lines

  1. /*  BSLSCROL.C
  2. /*    3/1/88        Derek Mui                */
  3. /*    4/29/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 "bsl.h"
  13. #include "scroll.h"
  14.  
  15. int    topptr;        /* top pointer    */
  16. int    totcnt;        /* total number of items */
  17. int    nent;        /* number of entries in BSL */
  18. long    nspc;        /* number of sectors per cylinder */
  19. BSLINFO    *bslinfo;    /* BSL info to be displayed */
  20.  
  21. extern int xdesk, ydesk, wdesk, hdesk;    /* dimensions of desktop */
  22. extern char *bsl;
  23. extern long bslsiz;
  24. extern long gbslsiz();
  25. extern long nument();
  26. extern long get3bytes();
  27.  
  28. /*
  29.  * Indices to entries in the window.
  30.  */
  31. int bslent[] = {
  32.     BENTRY0, BENTRY1, BENTRY2, BENTRY3,
  33.     BENTRY4, BENTRY5, BENTRY6, BENTRY7
  34. };
  35.  
  36.  
  37. dsplybsl(dev, nheads, nspt)
  38. int dev;        /* physical device number (0 -> 7) */
  39. UWORD nheads;        /* number of heads */
  40. UWORD nspt;        /* number of sectors per track */
  41. {
  42.     int  i;    /* number of bsl entries to be displayed */
  43.     long mul;
  44.     int     botptr, bret, value;
  45.     int  xoff, yoff, mx, my;
  46.     int  ret, cont;
  47.     int  k1, k2;
  48.  
  49.     /* Find size of BSL */
  50.     /*
  51.     bslsiz = gbslsiz(dev);
  52.     /**/
  53.     /* Allocate memory for BSL */
  54.     /*
  55.     
  56.     bsl = 0L;
  57.     if ((bsl = (BYTE *)mymalloc((int)bslsiz << 9)) <= 0) {
  58.     return err(nomemory);
  59.     }
  60.     
  61.     if ((ret = rdbsl(dev)) != OK) {
  62.     if (ret == INVALID)
  63.         err(cruptbsl);
  64.     ret = ERROR;
  65.     goto leavewin;
  66.     }
  67.     /**/
  68.     
  69.     nent = (int)nument(VENDOR);        /* find if there is any entry */
  70.     nspc = (long)nheads * (long)nspt;
  71.     
  72.     /* Allocate memory to hold defects */
  73.     bslinfo = 0L;
  74.     if ((bslinfo = (BSLINFO *)mymalloc(nent*(sizeof(BSLINFO)))) <= 0) {
  75.         ret = err(nomemory);
  76.         goto leavewin;
  77.     }
  78.     
  79.     for (i = 0; i < nent; i++) {
  80.         bslinfo[i].num = i+1;
  81.         bslinfo[i].sectnum = get3bytes(bsl + ((RENT + i) * BPE));
  82.         bslinfo[i].cylndr = (unsigned int)(bslinfo[i].sectnum / nspc);
  83.         bslinfo[i].head
  84.             = (UWORD)((bslinfo[i].sectnum - bslinfo[i].cylndr * nspc) / nspt);
  85.     }
  86.  
  87.     br_items();        /* read items */
  88.     
  89.     totcnt = nent;
  90.     if (nent > NM_ITEMS)        /* bigger than one window */
  91.     botptr = nent - NM_ITEMS;
  92.     else
  93.     botptr = 0;
  94.  
  95.     cont = TRUE;            /* control flag    */
  96.     while(cont) {
  97.     bret = form_do(bslform, -1);
  98.     graf_mkstate(&mx, &my, &k1, &k2);    /* graf mkstate    */
  99.     ret = bret & 0x7FFF;            /* mask off double click */
  100.     LWSET(OB_STATE(bslform, ret), 0);
  101.     value = 1;            /* scroll factor */
  102.  
  103.     switch (ret) {        /* Big Switch */
  104.         case BVSLID:        
  105.         objc_offset(bslform, BVELEV, &xoff, &yoff);
  106.         value = NM_ITEMS;        /* one full window size    */
  107.         if (my <= yoff)
  108.             goto bup;        
  109.         goto bdown;
  110.  
  111.         case BVELEV:
  112.         value = graf_slidebox(bslform, BVSLID, BVELEV, TRUE);
  113.         mul = (nent - NM_ITEMS) * value;
  114.         mul /= 1000;
  115.         value = (int)mul; 
  116.         value = (topptr - value);
  117.         if (value >= 0)
  118.             goto bup;            /* go up */
  119.         else
  120.             value = -value;        /* go down */
  121.  
  122. bdown:        case BDNAROW:            /* scroll down */
  123.         if (topptr == botptr)
  124.             break;
  125.  
  126.         if ((topptr + value) <= botptr)
  127.             topptr += value;
  128.         else
  129.             topptr = botptr;
  130.  
  131.         goto sbsl;            
  132.  
  133. bup:        case BUPAROW:            /* scroll up */
  134.         if (!topptr)
  135.             break;
  136.  
  137.         if ((topptr - value) >= 0)
  138.             topptr -= value;
  139.         else
  140.             topptr = 0;
  141.  
  142. sbsl:        br_show(topptr);        /* redisplay the file */
  143.         break;
  144.  
  145.         case BCLSBOX:
  146.           cont = FALSE;
  147.           break;
  148.  
  149.         default:
  150.           break;  
  151.     }                /* end of switch */
  152.     }                    /* while */
  153.     ret = TRUE;
  154. leavewin:
  155.     erasemsg();
  156.     if (bsl > 0L) free(bsl);    
  157.     if (bslinfo > 0L) free(bslinfo);
  158.     return (ret);
  159. }
  160.  
  161.  
  162.  
  163. /*---------------*/
  164. /* read in items */
  165. /*---------------*/
  166.  
  167. int    
  168. br_items()
  169. {
  170.     int  h, status;
  171.     int  full, i;
  172.     char temp[10];
  173.  
  174.     topptr = 0;            /* reset top pointer    */
  175.  
  176.     /* Feed the window with inputted entries */
  177.     if (nent < NM_ITEMS)
  178.         full = nent;
  179.     else
  180.         full = NM_ITEMS;
  181.         
  182.     for (i = 0; i < full; i++) {
  183.         /* count */
  184.         itoa(bslinfo[i].num, temp);
  185.         strcpy((bslform[bslent[i]].ob_spec)->te_ptext, temp);
  186.         if (bslinfo[i].num < 10)
  187.        strcat((bslform[bslent[i]].ob_spec)->te_ptext, "  ");
  188.     else if (bslinfo[i].num < 100)
  189.        strcat((bslform[bslent[i]].ob_spec)->te_ptext, " ");
  190.        
  191.         /* Head number */
  192.         itoa(bslinfo[i].head, temp);
  193.         strcat((bslform[bslent[i]].ob_spec)->te_ptext, temp);
  194.         if (bslinfo[i].num < 10)
  195.        strcat((bslform[bslent[i]].ob_spec)->te_ptext, " ");
  196.         
  197.         /* Cylinder number */
  198.         itoa(bslinfo[i].cylndr, temp);
  199.         strcat((bslform[bslent[i]].ob_spec)->te_ptext, temp);
  200.         if (bslinfo[i].cylndr < 10)
  201.        strcat((bslform[bslent[i]].ob_spec)->te_ptext, "   ");
  202.     else if (bslinfo[i].cylndr < 100)
  203.        strcat((bslform[bslent[i]].ob_spec)->te_ptext, "  ");
  204.     else if (bslinfo[i].cylndr < 1000)
  205.        strcat((bslform[bslent[i]].ob_spec)->te_ptext, " ");
  206.        
  207.     /* Sector Number */
  208.         ltoa(bslinfo[i].sectnum, temp);
  209.         strcat((bslform[bslent[i]].ob_spec)->te_ptext, temp);
  210.         
  211.     LWSET(OB_STATE(bslform, bslent[i]), NORMAL);
  212.     }
  213.     
  214.     for (; i < NM_ITEMS; i++) {
  215.         strcpy((bslform[bslent[i]].ob_spec)->te_ptext, "@");
  216.     LWSET(OB_STATE(bslform, bslent[i]), DISABLED);
  217.     }
  218.     
  219.     h = LWGET(OB_HEIGHT(bslform, BVSLID));
  220.  
  221.     if (nent > NM_ITEMS)
  222.     h = (h * NM_ITEMS) / nent;
  223.  
  224.     LWSET(OB_Y(bslform, BVELEV), 0);        /* move it to the top */
  225.     LWSET(OB_HEIGHT(bslform, BVELEV), h);    /* height of the elevator */
  226.     graf_mouse(ARROW, 0L);
  227.     dsplymsg(bslform);
  228. }
  229.     
  230.  
  231.  
  232. /*----------------------------------------------*/
  233. /*    show items and update the scroll bar    */
  234. /*----------------------------------------------*/
  235.  
  236. br_show(index)
  237. int index;        /* where to start */
  238. {    
  239.     int  i, ndx, full, x, y;
  240.     long h;
  241.     char temp[10];
  242.     BSLINFO *curbslinfo;
  243.     int  curent;
  244.  
  245.     if ((full = index + NM_ITEMS) > nent)
  246.         full = nent;
  247.         
  248.     /* Feed the window with inputted entries */
  249.     for (i = index, ndx = 0; i < full; i++,ndx++) {
  250.         curbslinfo = bslinfo + i;
  251.         curent = bslent[ndx];
  252.         
  253.         /* count */
  254.         itoa(curbslinfo->num, temp);
  255.         strcpy((bslform[curent].ob_spec)->te_ptext, temp);
  256.         if (curbslinfo->num < 10)
  257.        strcat((bslform[curent].ob_spec)->te_ptext, "  ");
  258.     else if (curbslinfo->num < 100)
  259.        strcat((bslform[curent].ob_spec)->te_ptext, " ");
  260.        
  261.         /* Head number */
  262.         itoa(curbslinfo->head, temp);
  263.         strcat((bslform[curent].ob_spec)->te_ptext, temp);
  264.         if (curbslinfo->head < 10)
  265.        strcat((bslform[curent].ob_spec)->te_ptext, " ");
  266.         
  267.         /* Cylinder number */
  268.         itoa(curbslinfo->cylndr, temp);
  269.         strcat((bslform[curent].ob_spec)->te_ptext, temp);
  270.         if (curbslinfo->cylndr < 10)
  271.        strcat((bslform[curent].ob_spec)->te_ptext, "   ");
  272.     else if (curbslinfo->cylndr < 100)
  273.        strcat((bslform[curent].ob_spec)->te_ptext, "  ");
  274.     else if (curbslinfo->cylndr < 1000)
  275.        strcat((bslform[curent].ob_spec)->te_ptext, " ");
  276.        
  277.     /* Sector number */
  278.         ltoa(curbslinfo->sectnum, temp);
  279.         strcat((bslform[curent].ob_spec)->te_ptext, temp);
  280.         
  281.         LWSET(OB_STATE(bslform, curent), NORMAL);
  282.     objc_draw(bslform, curent, 1, 0, 0, wdesk, hdesk);
  283.     }
  284.     
  285.     for (; ndx < NM_ITEMS; ndx++) {
  286.         curent = bslent[ndx];
  287.         strcpy((bslform[curent].ob_spec)->te_ptext, "@");
  288.         LWSET(OB_STATE(bslform, curent), DISABLED);
  289.     objc_draw(bslform, curent, 1, 0, 0, wdesk, hdesk);
  290.     }
  291.         
  292.     h = LWGET(OB_HEIGHT(bslform, BVSLID));
  293.     h = topptr * h;
  294.     
  295.     if (totcnt)
  296.     h = h / totcnt;
  297.  
  298.     LWSET(OB_Y(bslform, BVELEV), h);
  299.     /* draw the new one */
  300.     objc_draw(bslform, BVSLID, MAX_DEPTH, 0, 0, wdesk, hdesk);
  301. }
  302.  
  303.