home *** CD-ROM | disk | FTP | other *** search
- /* > $.CLIB.C.ramtrans
- *
- * HASWIN Graphics Library
- * =========================
- *
- * Copyright (C) H.A.Shaw 1990.
- * Howard A. Shaw.
- * The Unit for Space Sciences,
- * Room 165,
- * Physics Building,
- * University of Kent at Canterbury.
- * Canterbury.
- * Kent. CT2 7NJ
- * You may use and distribute this code freely, however please leave
- * it alone. If you find bugs (and there will be many) please contact
- * me and the master source can be modified. If you keep me informed
- * of who you give copies of this to then I can get release upgrades
- * to them.
- *
- * Routines to control RAM transfers and stack RAM transfer transmit
- * and receive routines.
- */
- #include "includes.h"
-
- typedef struct ramstore {
- int (*code)(void *, int, int, buffer *);
- int length, bytes;
- void *buff;
- } ramstore;
-
- #define HASWIN_MAXFILES 8
- static ramstore haswin_ramrxstack[HASWIN_MAXFILES];
- static int haswin_ramrxstackptr = 0;
- static ramstore haswin_ramtxstack[HASWIN_MAXFILES];
- static int haswin_ramtxstackptr = 0;
-
- void haswin_setramrxroutine(int (*user)(void *, int, int, buffer *), int len) {
-
- if (user) {
- haswin_ramrxbuffer = haswin_realloc(haswin_ramrxbuffer, len, "haswin_setramrxroutine", "main transfer buffer");
- haswin_ramrxlength = len;
- haswin_ramrxroutine = user;
- } else {
- if (haswin_ramrxbuffer)
- if (!haswin_free(haswin_ramrxbuffer))
- haswin_errorbox("haswin_setramrxroutine: failed to free ram receive buffer memory");
- haswin_ramrxbuffer = 0;
- haswin_ramrxlength = 0;
- haswin_ramrxroutine = 0;
- }
- haswin_ramrxbytes = 0;
- }
-
- void haswin_setramtxroutine(int (*user)(void *, int, int, buffer *), int len) {
-
- if (user) {
- haswin_ramtxbuffer = haswin_realloc(haswin_ramtxbuffer, len, "haswin_setramtxroutine", "main transfer buffer");
- haswin_ramtxlength = len;
- haswin_ramtxroutine = user;
- } else {
- if (haswin_ramtxbuffer)
- if (!haswin_free(haswin_ramtxbuffer))
- haswin_errorbox("haswin_setramtxroutine: failed to free ram transmit buffer memory");
- haswin_ramtxbuffer = 0;
- haswin_ramtxlength = 0;
- haswin_ramtxroutine = 0;
- }
- haswin_ramtxbytes = 0;
- }
- /*
- * push the current ramtxroutine onto the ramtxroutine stack and
- * set a new one if we can.
- */
- int haswin_pushramtxroutine(int (*user)(void *, int, int, buffer *), int length) {
-
- if (haswin_ramtxstackptr == HASWIN_MAXFILES)
- return(HASWIN_FALSE);
- haswin_ramtxstack[haswin_ramtxstackptr].code = haswin_ramtxroutine;
- haswin_ramtxstack[haswin_ramtxstackptr].buff = haswin_ramtxbuffer;
- haswin_ramtxstack[haswin_ramtxstackptr].length = haswin_ramtxlength;
- haswin_ramtxstack[haswin_ramtxstackptr].bytes = haswin_ramtxbytes;
- haswin_ramtxstackptr++;
- haswin_setramtxroutine(user, length);
- return(HASWIN_TRUE);
- }
-
- /*
- * push the current ramrxroutine onto the ramrxroutine stack and
- * set a new one if we can.
- */
- int haswin_pushramrxroutine(int (*user)(void *, int, int, buffer *), int length) {
-
- if (haswin_ramrxstackptr == HASWIN_MAXFILES)
- return(HASWIN_FALSE);
- haswin_ramrxstack[haswin_ramrxstackptr].code = haswin_ramrxroutine;
- haswin_ramrxstack[haswin_ramrxstackptr].buff = haswin_ramrxbuffer;
- haswin_ramrxstack[haswin_ramrxstackptr].length = haswin_ramrxlength;
- haswin_ramrxstack[haswin_ramrxstackptr].bytes = haswin_ramrxbytes;
- haswin_ramrxstackptr++;
- haswin_setramrxroutine(user, length);
- return(HASWIN_TRUE);
- }
-
- /*
- * pull a ramtxroutine from the ramtx stack if we can
- */
- int haswin_popramtxroutine(void) {
-
- if (haswin_ramtxstackptr <= 0) {
- haswin_setramtxroutine(0, 0);
- return(HASWIN_FALSE);
- }
- haswin_ramtxstackptr--;
- haswin_ramtxroutine = haswin_ramtxstack[haswin_ramtxstackptr].code;
- haswin_ramtxbuffer = haswin_ramtxstack[haswin_ramtxstackptr].buff;
- haswin_ramtxlength = haswin_ramtxstack[haswin_ramtxstackptr].length;
- haswin_ramtxbytes = haswin_ramtxstack[haswin_ramtxstackptr].bytes;
- return(HASWIN_TRUE);
- }
-
- /*
- * pull a ramrxroutine from the ramrx stack if we can
- */
- int haswin_popramrxroutine(void) {
-
- if (haswin_ramrxstackptr <= 0) {
- haswin_setramrxroutine(0, 0);
- return(HASWIN_FALSE);
- }
- haswin_ramrxstackptr--;
- haswin_ramrxroutine = haswin_ramrxstack[haswin_ramrxstackptr].code;
- haswin_ramrxbuffer = haswin_ramrxstack[haswin_ramrxstackptr].buff;
- haswin_ramrxlength = haswin_ramrxstack[haswin_ramrxstackptr].length;
- haswin_ramrxbytes = haswin_ramrxstack[haswin_ramrxstackptr].bytes;
- return(HASWIN_TRUE);
- }
-
-