home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / haswinlib / c / ramtrans < prev    next >
Encoding:
Text File  |  1991-02-04  |  5.1 KB  |  138 lines

  1. /* > $.CLIB.C.ramtrans
  2.  *
  3.  *      HASWIN Graphics Library
  4.  *     =========================
  5.  *
  6.  *      Copyright (C) H.A.Shaw 1990.
  7.  *              Howard A. Shaw.
  8.  *              The Unit for Space Sciences,
  9.  *              Room 165,
  10.  *              Physics Building,
  11.  *              University of Kent at Canterbury.
  12.  *              Canterbury.
  13.  *              Kent.  CT2 7NJ
  14.  *      You may use and distribute this code freely, however please leave
  15.  *      it alone.  If you find bugs (and there will be many) please contact
  16.  *      me and the master source can be modified.  If you keep me informed
  17.  *      of who you give copies of this to then I can get release upgrades
  18.  *      to them.
  19.  *
  20.  *      Routines to control RAM transfers and stack RAM transfer transmit
  21.  *      and receive routines.
  22.  */
  23. #include "includes.h"
  24.  
  25. typedef struct ramstore {
  26.         int      (*code)(void *, int, int, buffer *);
  27.         int      length, bytes;
  28.         void     *buff;
  29. } ramstore;
  30.  
  31. #define HASWIN_MAXFILES         8
  32. static ramstore  haswin_ramrxstack[HASWIN_MAXFILES];
  33. static int       haswin_ramrxstackptr = 0;
  34. static ramstore  haswin_ramtxstack[HASWIN_MAXFILES];
  35. static int       haswin_ramtxstackptr = 0;
  36.  
  37. void haswin_setramrxroutine(int (*user)(void *, int, int, buffer *), int len) {
  38.  
  39.         if (user) {
  40.                 haswin_ramrxbuffer = haswin_realloc(haswin_ramrxbuffer, len, "haswin_setramrxroutine", "main transfer buffer");
  41.                 haswin_ramrxlength = len;
  42.                 haswin_ramrxroutine = user;
  43.         } else {
  44.                 if (haswin_ramrxbuffer)
  45.                         if (!haswin_free(haswin_ramrxbuffer))
  46.                                 haswin_errorbox("haswin_setramrxroutine: failed to free ram receive buffer memory");
  47.                 haswin_ramrxbuffer = 0;
  48.                 haswin_ramrxlength = 0;
  49.                 haswin_ramrxroutine = 0;
  50.         }
  51.         haswin_ramrxbytes = 0;
  52. }
  53.  
  54. void haswin_setramtxroutine(int (*user)(void *, int, int, buffer *), int len) {
  55.  
  56.         if (user) {
  57.                 haswin_ramtxbuffer = haswin_realloc(haswin_ramtxbuffer, len, "haswin_setramtxroutine", "main transfer buffer");
  58.                 haswin_ramtxlength = len;
  59.                 haswin_ramtxroutine = user;
  60.         } else {
  61.                 if (haswin_ramtxbuffer)
  62.                         if (!haswin_free(haswin_ramtxbuffer))
  63.                                 haswin_errorbox("haswin_setramtxroutine: failed to free ram transmit buffer memory");
  64.                 haswin_ramtxbuffer = 0;
  65.                 haswin_ramtxlength = 0;
  66.                 haswin_ramtxroutine = 0;
  67.         }
  68.         haswin_ramtxbytes = 0;
  69. }
  70. /*
  71.  *      push the current ramtxroutine onto the ramtxroutine stack and
  72.  *      set a new one if we can.
  73.  */
  74. int haswin_pushramtxroutine(int (*user)(void *, int, int, buffer *), int length) {
  75.  
  76.         if (haswin_ramtxstackptr == HASWIN_MAXFILES)
  77.                 return(HASWIN_FALSE);
  78.         haswin_ramtxstack[haswin_ramtxstackptr].code   = haswin_ramtxroutine;
  79.         haswin_ramtxstack[haswin_ramtxstackptr].buff   = haswin_ramtxbuffer;
  80.         haswin_ramtxstack[haswin_ramtxstackptr].length = haswin_ramtxlength;
  81.         haswin_ramtxstack[haswin_ramtxstackptr].bytes  = haswin_ramtxbytes;
  82.         haswin_ramtxstackptr++;
  83.         haswin_setramtxroutine(user, length);
  84.         return(HASWIN_TRUE);
  85. }
  86.  
  87. /*
  88.  *      push the current ramrxroutine onto the ramrxroutine stack and
  89.  *      set a new one if we can.
  90.  */
  91. int haswin_pushramrxroutine(int (*user)(void *, int, int, buffer *), int length) {
  92.  
  93.         if (haswin_ramrxstackptr == HASWIN_MAXFILES)
  94.                 return(HASWIN_FALSE);
  95.         haswin_ramrxstack[haswin_ramrxstackptr].code   = haswin_ramrxroutine;
  96.         haswin_ramrxstack[haswin_ramrxstackptr].buff   = haswin_ramrxbuffer;
  97.         haswin_ramrxstack[haswin_ramrxstackptr].length = haswin_ramrxlength;
  98.         haswin_ramrxstack[haswin_ramrxstackptr].bytes  = haswin_ramrxbytes;
  99.         haswin_ramrxstackptr++;
  100.         haswin_setramrxroutine(user, length);
  101.         return(HASWIN_TRUE);
  102. }
  103.  
  104. /*
  105.  *      pull a ramtxroutine from the ramtx stack if we can
  106.  */
  107. int haswin_popramtxroutine(void) {
  108.  
  109.         if (haswin_ramtxstackptr <= 0) {
  110.                 haswin_setramtxroutine(0, 0);
  111.                 return(HASWIN_FALSE);
  112.         }
  113.         haswin_ramtxstackptr--;
  114.         haswin_ramtxroutine = haswin_ramtxstack[haswin_ramtxstackptr].code;
  115.         haswin_ramtxbuffer  = haswin_ramtxstack[haswin_ramtxstackptr].buff;
  116.         haswin_ramtxlength  = haswin_ramtxstack[haswin_ramtxstackptr].length;
  117.         haswin_ramtxbytes   = haswin_ramtxstack[haswin_ramtxstackptr].bytes;
  118.         return(HASWIN_TRUE);
  119. }
  120.  
  121. /*
  122.  *      pull a ramrxroutine from the ramrx stack if we can
  123.  */
  124. int haswin_popramrxroutine(void) {
  125.  
  126.         if (haswin_ramrxstackptr <= 0) {
  127.                 haswin_setramrxroutine(0, 0);
  128.                 return(HASWIN_FALSE);
  129.         }
  130.         haswin_ramrxstackptr--;
  131.         haswin_ramrxroutine = haswin_ramrxstack[haswin_ramrxstackptr].code;
  132.         haswin_ramrxbuffer  = haswin_ramrxstack[haswin_ramrxstackptr].buff;
  133.         haswin_ramrxlength  = haswin_ramrxstack[haswin_ramrxstackptr].length;
  134.         haswin_ramrxbytes   = haswin_ramrxstack[haswin_ramrxstackptr].bytes;
  135.         return(HASWIN_TRUE);
  136. }
  137.  
  138.