home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / programm / GNU_C++ / LIB / CFLIB-11.LZH / src / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-09  |  3.2 KB  |  175 lines

  1. #include <ctype.h>
  2.  
  3. #include "intern.h"
  4.  
  5. long ts2ol(short i1, short i2)
  6. {
  7.     short va[2];
  8.          
  9.     va[0] = i1;
  10.     va[1] = i2;
  11.     return *(long *)(va);
  12. }
  13.  
  14. void ol2ts(long l, short *i1, short *i2)
  15. {
  16.     short    *va;
  17.     
  18.     va = (short *)&l;
  19.     *i1 = va[0];
  20.     *i2 = va[1];
  21. }
  22.  
  23.  
  24. static void cf_background(GRECT *box, MFDB *buffer, int get)
  25. {
  26.     MFDB    screen;
  27.     int    xy [8];
  28.     GRECT    r;
  29.     
  30.     r = *box;
  31.     if (rc_intersect(&gl_desk, &r))                        /* nur sichtbaren Bereich */
  32.     {
  33.         screen.fd_addr = NULL;                                /* Bildschirm */
  34.         buffer->fd_w = r.g_w;
  35.         buffer->fd_h = r.g_h;
  36.         buffer->fd_wdwidth = (r.g_w + 15) >> 4;     /* Anzahl in intS */
  37.         buffer->fd_stand     = FALSE;
  38.         buffer->fd_nplanes = gl_planes;
  39.         if (get)
  40.             buffer->fd_addr     = cf_malloc((long)buffer->fd_wdwidth * 2L * r.g_h * gl_planes, "cf_background", FALSE);
  41.             
  42.         if (buffer->fd_addr != NULL)
  43.         {
  44.             hide_mouse();
  45.             if (get)
  46.             {
  47.                 xy[0] = r.g_x;
  48.                 xy[1] = r.g_y;
  49.                 xy[2] = r.g_x + r.g_w - 1;
  50.                 xy[3] = r.g_y + r.g_h - 1;
  51.                 xy[4] = 0;
  52.                 xy[5] = 0;
  53.                 xy[6] = r.g_w-1;
  54.                 xy[7] = r.g_h-1;
  55.                 vro_cpyfm(cf_vdi_handle, S_ONLY, xy, &screen, buffer);
  56.             }
  57.             else
  58.             {
  59.                 xy[0] = 0;
  60.                 xy[1] = 0;
  61.                 xy[2] = r.g_w - 1;
  62.                 xy[3] = r.g_h - 1;
  63.                 xy[4] = r.g_x;
  64.                 xy[5] = r.g_y;
  65.                 xy[6] = r.g_x + r.g_w - 1;
  66.                 xy[7] = r.g_y + r.g_h - 1;
  67.                 vro_cpyfm(cf_vdi_handle, S_ONLY, xy, buffer, &screen);
  68.                 Mfree(buffer->fd_addr);
  69.             }
  70.             show_mouse();
  71.         }
  72.         else
  73. #ifdef __MTAES__
  74.             form_dial(FMD_FINISH, &r, &r);
  75. #else
  76.             form_dial(FMD_FINISH, r.g_x, r.g_y, r.g_w, r.g_h, r.g_x, r.g_y, r.g_w, r.g_h);
  77. #endif
  78.     }
  79. }
  80.  
  81. void save_background(GRECT *box, MFDB *buffer)
  82. {
  83.     cf_background(box, buffer, TRUE);
  84. }
  85.  
  86. void restore_background(GRECT *box, MFDB *buffer)
  87. {
  88.     cf_background(box, buffer, FALSE);
  89. }
  90.  
  91. int get_patchlev(char *id_str, char *pl)
  92. {
  93.     char    *p;
  94.     int    len;
  95.     int    ret = FALSE;
  96.         
  97.     len = (int)strlen(id_str);
  98.     if (id_str[0] == '$' && id_str[len-1] == '$')
  99.     {
  100.         p = id_str;
  101.         while (!isdigit(*p))
  102.             p++;
  103.         while (*p != '$' && !isspace(*p))
  104.             *pl++ = *p++;
  105.         *pl = EOS;
  106.         ret = TRUE;
  107.     }
  108.     return ret;
  109. }
  110.  
  111. #ifndef _GEMLIB_H_
  112. /*
  113.  * Kennt die Pure/GEM-Lib nicht.
  114. */
  115. int rc_intersect(GRECT *r1, GRECT *r2)
  116. {
  117.     int    tx, ty, tw, th, ret;
  118.         
  119.     tx = max(r2->g_x, r1->g_x);
  120.     tw = min(r2->g_x + r2->g_w, r1->g_x + r1->g_w) - tx;
  121.     ret = (0 < tw);
  122.     if (ret) 
  123.     {
  124.         ty = max (r2->g_y, r1->g_y);
  125.         th = min (r2->g_y + r2->g_h, r1->g_y + r1->g_h) - ty;
  126.         ret = (0 < th);
  127.         if (ret) 
  128.         {
  129.             r2->g_x = tx;
  130.             r2->g_y = ty;
  131.             r2->g_w = tw;
  132.             r2->g_h = th;
  133.         }
  134.     }
  135.     return (ret);
  136. }
  137. #endif
  138.  
  139. void *cf_malloc(long size, char *who, int global)
  140. {
  141.     void    *r = NULL;
  142.  
  143.     if (global && getcookie("MiNT", NULL))
  144. /*        r = (void *)Mxalloc(size, 43);*/
  145.         r = (void *)Mxalloc(size, 0x23);
  146.     else
  147.         r = (void *)Malloc(size);
  148.  
  149.     if (r == NULL)
  150.     {
  151.         char    msg[80];
  152.  
  153.         if (gl_gem > 0)
  154.         {
  155.             sprintf(msg, "[3][CF-Lib (%s)|Can't allocate RAM!][Ignore|Exit]", who);
  156.             if (form_alert(2, msg) == 2)
  157.             {
  158.                 appl_exit();
  159.                 exit(-39);
  160.             }
  161.         }
  162.         else
  163.         {
  164.             fprintf(stderr, "CF-Lib (%s)\nCan't allocate RAM!\n", who);
  165.             exit(-39);
  166.         }
  167.     }
  168.     return r;
  169. }
  170.  
  171. void *malloc_global(long size)
  172. {
  173.     return cf_malloc(size, "malloc_global", TRUE);
  174. }
  175.