$include (..\lib\compStch.ext) /* *============================================================================ * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE * * Permission to use for any purpose, modify, copy, and make enhancements * and derivative works of the software is granted if attribution is given to * R.M. Gillmore, dba the ACME Software Deli, as the author * * While the ACME Software Deli does not work for money, there is nonetheless * a significant amount of work involved. The ACME Software Deli maintains the * rights to all code written, though it may be used and distributed as long as * the following conditions are maintained. * * 1. The copyright statement at the top of each code block is maintained in * your distribution. * 2. You do not identify yourself as the ACME Software Deli * 3. Any changes made to the software are sent to the ACME Software Deli *============================================================================ */ ptrMathModule: do; $if not noID declare IDString (*) byte data ( '@(#)ptrMath.p86 $Author: rmgillmore $ $Date:: 2025-05-04 19:35:39#$:', 0 ); $endif $set (PTRMATH_IMPLEMENTATION) $include (..\lib\ptrMath.ext) normalizePtr: procedure ( pointerIn ) pointer reentrant public; declare pointerIn pointer, pointerOut pointer, forDwordMath dword, ( lowerWord, upperWord ) word; forDwordMath = double( word( selector$of( pointerIn ) ) ); forDwordMath = shl( forDwordMath, 4 ); forDwordMath = forDwordMath + double( offset$of( pointerIn ) ); upperWord = shr( forDwordMath, 4 ); lowerWord = forDwordMath and 0000$000fh; pointerOut = build$ptr( selector( upperWord ), lowerWord ); return ( pointerOut ); end normalizePtr; ptdw: procedure ( pointerIn ) dword reentrant public; declare pointerIn pointer, dwordOut dword at ( @pointerIn ); return ( dwordOut ); end ptdw; dwtp: procedure ( dwordIn ) pointer reentrant public; declare dwordIn dword, pointerOut pointer at ( @dwordIn ); return ( pointerOut ); end dwtp; /* * functions for pointer arithmetic */ incPtr: procedure ( pointerIn, dataElementSize, numberElements ) pointer reentrant public; declare pointerIn pointer, dataElementSize word, numberElements word, pointerOut pointer; pointerOut = pointerIn; if ( size( pointerOut ) = size( numberElements ) ) then do; /* * the short pointer case */ declare wordVar word at ( @pointerOut ); wordVar = wordVar + ( dataElementSize * numberElements ); end; else do; /* * the long pointer case */ declare selectorOut selector, offsetOut word; selectorOut = selector$of( pointerOut ); offsetOut = offset$of( pointerOut ); offsetOut = offsetOut + ( dataElementSize * numberElements ); if ( offsetOut < offset$of( pointerIn ) ) then do; selectorOut = selector( word( selectorOut ) + 1000h ); end; pointerOut = build$ptr( selectorOut, offsetOut ); end; return ( pointerOut ); end incPtr; decPtr: procedure ( pointerIn, dataElementSize, numberElements ) pointer reentrant public; declare pointerIn pointer, dataElementSize word, numberElements word, pointerOut pointer; pointerOut = pointerIn; if ( size( pointerOut ) = size( numberElements ) ) then do; /* * the short pointer case */ declare wordVar word at ( @pointerOut ); wordVar = wordVar - ( dataElementSize * numberElements ); end; else do; /* * the long pointer case */ declare selectorOut selector, offsetOut word; selectorOut = selector$of( pointerOut ); offsetOut = offset$of( pointerOut ); offsetOut = offsetOut - ( dataElementSize * numberElements ); if ( offsetOut > offset$of( pointerIn ) ) then do; selectorOut = selector( word( selectorOut ) - 1000h ); end; pointerOut = build$ptr( selectorOut, offsetOut ); end; return ( pointerOut ); end decPtr; end ptrMathModule;