home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / code / p_dissbi.sit / DissBits / inlines < prev    next >
Encoding:
Text File  |  1985-01-28  |  6.1 KB  |  99 lines  |  [TEXT/MACA]

  1. {      These procedures and functions are declared "in-line" -- the Pascal compiler is told what instructions
  2.   to emit instead of what routine to call.  These procedures take up a little more room (up to eight words
  3.   more) than ordinary procedure calls or traps to Toolbox or OS routines.  But they're very fast and some do
  4.   things which you can't do in Pascal.
  5.        Among the Toolbox utility routines which are exactly replaced: bitSet, bitClr, bitTst, bitAnd, bitOr,
  6.   bitNot, bitXor, loWord and hiWord.  In addition, some extensions are given: word-size operations,
  7.   arithmetic shifts, and so on.     Also, routines like "callProc" and "abort" provide functionality not found
  8.   in Pascal or ROM routines.
  9.        To use this as a unit, move the source to a Lisa, compile it in Pascal, and name it in the "uses"
  10.   section of your program.  Or you can just include the declarations you need in your program; be careful
  11.   to type the hex codes correctly.
  12.  
  13.                 Comments?  Suggestions?     Bugs?  Fan mail?
  14.                 Mike Morton, 6 Blackwood St. #102, Boston, MA  02115
  15.                 Version 1 -- 30 January 1985.                                    }
  16. unit inlines;
  17. interface
  18.  
  19.    type INLByte      =  -128..127; { NOTE: You may want to change bitSet, etc. to a more common pointer type.  }
  20.         INLPtr      =  ^INLByte;  { I've declared these two types just to avoid depending on any other units. }
  21.  
  22.    procedure abort;              INLINE $4AFC; { ILLEGAL -- die badly on finding an inconsistency  }
  23.    procedure abortArg (aboType: integer); INLINE $4AFC; { ILLEGAL -- stack a code first for debugging        }
  24.    procedure rangeChk (bound, n: integer);            { make sure N is in 0..bound inclusive; die if not  }
  25.            INLINE $301F,$419F;                    { MOVE.W (A7)+,D0; CHK (A7)+,D0                }
  26.    procedure callProc (address: longint);            { call a procedure at any address            }
  27.            INLINE $205F,$4E90;                    { MOVE.L (A7)+,A0; JSR (A0)                }
  28.  
  29.    { Bit routines take a pointer and bit offset.  Bits are numbered left-to-right, like the Toolbox does.   }
  30.    procedure bChange (p: INLPtr; offset: integer);      { flip specified bit                    }
  31.            INLINE $301F,$205F,$3200,$E640,$4601,$0370,$0000;
  32.            { MOVE.W (A7)+,D0; MOVE.L (A7)+,A0; MOVE.W D0,D1; ASR.W #3,D0; NOT.B D1; BCHG D1,0(A0,D0)        }
  33.  
  34.    procedure bSet (p: INLPtr; offset: integer);            { set specified bit                    }
  35.            INLINE $301F,$205F,$3200,$E640,$4601,$03F0,$0000;
  36.            {                same as for bChange                  ; BSET D1,0(A0,D0)        }
  37.  
  38.    procedure bClear (p: INLPtr; offset: integer);       { clear specified bit                    }
  39.            INLINE $301F,$205F,$3200,$E640,$4601,$03B0,$0000;
  40.            {                same as for bChange                  ; BCLR D1,0(A0,D0)        }
  41.  
  42.    function bTest (p: INLPtr; offset: integer): boolean; { test bit; TRUE return means bit = 1            }
  43.            INLINE $301F,$205F,$3200,$E640,$4601,$0330,$0000,$56D7,$4417;
  44.            {                same as for bChange        ; BTST D1,0(A0,D0); SNE (A7); NEG.B (A7)        }
  45.  
  46.    function lslWord (a, shift: integer): integer;       { logical/arithmetic shift word "a" left by "shift" }
  47.            INLINE $4C9F,$0003,$E161,$3E81;            { MOVEM.W (A7)+,D0/D1; ASL.W D0,D1; MOVE.W D1,(A7)  }
  48.  
  49.    function lsrWord (a, shift: integer): integer;       { logical shift word "a" right by "shift"        }
  50.            INLINE $4C9F,$0003,$E069,$3E81;            { MOVEM.W (A7)+,D0/D1; LSR.W D0,D1; MOVE.W D1,(A7)  }
  51.  
  52.    function asrWord (a, shift: integer): integer;       { arithmetic shift word "a" right by "shift"        }
  53.            INLINE $4C9F,$0003,$E061,$3E81;            { MOVEM.W (A7)+,D0/D1; ASR.W D0,D1; MOVE.W D1,(A7)  }
  54.  
  55.    function lslLong (a: longint; shift: integer): longint; { logical/arithmetic shift long "a" left by "shift" }
  56.            INLINE $321F,$201F,$E3A0,$2E80;     { MOVE.W (A7)+,D1; MOVE.L (A7)+,D0; ASL.L D1,D0; MOVE.L D0,(A7) }
  57.  
  58.    function lsrLong (a: longint; shift: integer): longint; { logical shift long "a" right by "shift"        }
  59.            INLINE $321F,$201F,$E2A8,$2E80;           { same as for lslLong, but LSR instead of ASL    }
  60.  
  61.    function asrLong (a: longint; shift: integer): longint; { arithmetic shift long "a" right by "shift"        }
  62.            INLINE $321F,$201F,$E2A0,$2E80;           { same as for lslLong, but ASR instead of ASL    }
  63.  
  64.    function lowWord (a: longint): integer;            { extract the low 16 bits of the long argument        }
  65.            INLINE $201F,$3E80;                    { MOVE.L (A7)+,D0; MOVE.W D0,(A7)            }
  66.  
  67.    function highWord (a: longint): integer;            { extract the high 16 bits of the argument        }
  68.            INLINE $3E9F,$3E9F;                    { MOVE.W (A7)+,(A7); MOVE.W (A7)+,(A7)            }
  69.  
  70.    function notWord (a: integer): integer;            { logical NOT a word                    }
  71.            INLINE $301F,$4640,$3E80;                { MOVE.W (A7)+,D0; NOT.W D0; MOVE.W D0,(A7)        }
  72.  
  73.    function andWord (a, b: integer): integer;            { AND two words                        }
  74.            INLINE $301F,$C05F,$3E80;                { MOVE.W (A7)+,D0; AND.W (A7)+,D0; MOVE.W D0,(A7)   }
  75.  
  76.    function orWord (a, b: integer): integer;            { OR two words                        }
  77.            INLINE $301F,$805F,$3E80;                { MOVE.W (A7)+,D0; OR.W (A7)+,D0; MOVE.W D0,(A7)    }
  78.  
  79.    function eorWord (a, b: integer): integer;            { EOR two words                        }
  80.            INLINE $301F,$B157,$3E9F;                { MOVE.W (A7)+,D0; EOR.W D0,(A7); MOVE.W (A7)+,(A7) }
  81.  
  82.    function notLong (a: longint): longint;            { logical NOT a long                    }
  83.            INLINE $201F,$4680,$2E80;                { MOVE.L (A7)+,D0; NOT.L D0; MOVE.L D0,(A7)        }
  84.  
  85.    function andLong (a, b: longint): longint;            { AND two longs                        }
  86.            INLINE $201F,$C09F,$2E80;                { MOVE.L (A7)+,D0; AND.L (A7)+,D0; MOVE.L D0,(A7)   }
  87.  
  88.    function orLong (a, b: longint): longint;            { OR two longs                        }
  89.            INLINE $201F,$809F,$2E80;                { MOVE.L (A7)+,D0; OR.L (A7)+,D0; MOVE.L D0,(A7)    }
  90.  
  91.    function eorLong (a, b: longint): longint;            { EOR two longs                        }
  92.            INLINE $201F,$B197,$2E9F;                { MOVE.L (A7)+,D0; EOR.L D0,(A7); MOVE.L (A7)+,(A7) }
  93.  
  94. implementation
  95.  
  96.    { "This section intentionally left blank." }
  97.  
  98. end.                                { of unit "inlines"                    }
  99.