home *** CD-ROM | disk | FTP | other *** search
- /******************************************
- * TSMALLOC.C *
- * Copyright TimeSlice, Inc. 1985, 86, 87. *
- ******************************************/
-
-
- #include <ts.h>
-
- #if defined(TURBOC) && ( defined(MS) || defined(MP) )
- short ts_brklev , _tstc_sp ;
- #define swap(a,b) ((int)a^=(int)b,(int)b^=(int)a,(int)a^=(int)b)
- #endif
-
-
- /***
- * _TS_FREE( PTR )
- * Frees allocated ptr (in near segment for Microsoft large).
- ***/
- void _ts_free( off, seg )
- unsigned off, seg ;
- {
- int free() ;
-
- critstart(DOS_CRCLASS);/*become critical */
- #if ( defined(ML) || defined(MD) ) && defined(MICROSOFT)
- _nfree( off ) ;
- #else
- #if defined(TURBOC) && ( defined(MS) || defined(MP) )
- ssleep() ; /*put slicer to sleep */
- asm mov cx, off /*get the pointer value */
- asm pushf /* save current flags */
- asm cli ; /* disable interrupts */
- asm push __brklvl ; /* Save current stack overflow/near heap base marker */
- asm mov ax, sp ; /* Get current value of stack pointer */
- asm mov bx, ts_brklev
- asm mov __brklvl,bx /*let the break level become what it used to be */
- asm mov sp, _tstc_sp /* point to the original stack */
- asm push ax /* save real sp */
- asm push bp /*..and real bp */
- asm mov bp, sp /*make new bp */
- asm push cx /*push offset */
- #if defined(MS)
- asm call free /*call free */
- #else
- asm call far ptr free /*call free */
- #endif
- asm pop cx /*remove param */
- asm pop bp /*get real bp back */
- asm pop cx /*get the real sp back */
- asm mov sp, cx /*point to real stack */
- asm pop cx /*get real __brklvl back */
- asm mov bx, __brklvl /*get newly updated heap marker */
- asm mov ts_brklev,bx /*save it for the next time */
- asm mov __brklvl, cx /*restore the current heap marker */
- asm popf /* restore cpuflags register */
- swake() ;
- #else
- free( off, seg );
- #endif
- #endif
- critend(DOS_CRCLASS) ;
-
- }
-
-
- /***
- * _TS_MALLOC( NBYTES )
- * Allocate nbytes (in near segment for Microsoft large).
- ***/
- char *_ts_malloc( nbytes ) {
-
- #if ( defined(ML) || defined(MD)) && defined(MICROSOFT)
- char near *_nmalloc();
- union {
- char *ptr;
- struct {
- int off, seg;
- }i;
- } genptr;
-
- genptr.i.seg = ( genptr.i.off = (unsigned short)cpcrit( DOS_CRCLASS,_nmalloc , nbytes ) ) ? _datseg : 0 ;
- if (genptr.ptr) memset(genptr.ptr, 0, nbytes);
- return genptr.ptr;
- #else
- char *malloc();
- char *cp ;
- #if defined(TURBOC) && ( defined(MS) || defined(MP) )
- critstart(DOS_CRCLASS);/*become critical */
- ssleep() ; /*put slicer to sleep */
- asm mov cx, nbytes /*get the number of bytes to allocate */
- asm pushf /* save current flags */
- asm cli ; /* disable interrupts */
- asm push __brklvl ; /* Save current stack overflow/near heap base marker */
- asm mov ax, sp ; /* Get current value of stack pointer */
- asm mov bx, ts_brklev
- asm mov __brklvl,bx /*let the break level become what it used to be */
- asm mov sp, _tstc_sp /* point to the original stack */
- asm push ax /* save real sp */
- asm push bp /*..and real bp */
- asm mov bp, sp /*make new bp */
- asm push cx /*push nbytes */
- #if defined(MS)
- asm call malloc/*call malloc */
- #else
- asm call far ptr malloc/*call malloc */
- #endif
- asm pop cx /*remove param */
- asm pop bp /*get real bp back */
- asm pop cx /*get the real sp back */
- asm mov sp, cx /*point to real stack */
- asm pop cx /*get real __brklvl back */
- asm mov bx, __brklvl /*get newly updated heap marker */
- asm mov ts_brklev,bx /*save it for the next time */
- asm mov __brklvl, cx /*restore the current heap marker */
- asm mov cp , ax
- asm popf /* restore cpuflags register */
- swake() ;
- critend(DOS_CRCLASS) ;
- return cp ;
- #else
- return cpcrit( DOS_CRCLASS , malloc , nbytes );
- #endif
- #endif
- }
-
-