home *** CD-ROM | disk | FTP | other *** search
Text File | 1985-01-28 | 6.1 KB | 99 lines | [TEXT/MACA] |
- { These procedures and functions are declared "in-line" -- the Pascal compiler is told what instructions
- to emit instead of what routine to call. These procedures take up a little more room (up to eight words
- more) than ordinary procedure calls or traps to Toolbox or OS routines. But they're very fast and some do
- things which you can't do in Pascal.
- Among the Toolbox utility routines which are exactly replaced: bitSet, bitClr, bitTst, bitAnd, bitOr,
- bitNot, bitXor, loWord and hiWord. In addition, some extensions are given: word-size operations,
- arithmetic shifts, and so on. Also, routines like "callProc" and "abort" provide functionality not found
- in Pascal or ROM routines.
- To use this as a unit, move the source to a Lisa, compile it in Pascal, and name it in the "uses"
- section of your program. Or you can just include the declarations you need in your program; be careful
- to type the hex codes correctly.
-
- Comments? Suggestions? Bugs? Fan mail?
- Mike Morton, 6 Blackwood St. #102, Boston, MA 02115
- Version 1 -- 30 January 1985. }
- unit inlines;
- interface
-
- type INLByte = -128..127; { NOTE: You may want to change bitSet, etc. to a more common pointer type. }
- INLPtr = ^INLByte; { I've declared these two types just to avoid depending on any other units. }
-
- procedure abort; INLINE $4AFC; { ILLEGAL -- die badly on finding an inconsistency }
- procedure abortArg (aboType: integer); INLINE $4AFC; { ILLEGAL -- stack a code first for debugging }
- procedure rangeChk (bound, n: integer); { make sure N is in 0..bound inclusive; die if not }
- INLINE $301F,$419F; { MOVE.W (A7)+,D0; CHK (A7)+,D0 }
- procedure callProc (address: longint); { call a procedure at any address }
- INLINE $205F,$4E90; { MOVE.L (A7)+,A0; JSR (A0) }
-
- { Bit routines take a pointer and bit offset. Bits are numbered left-to-right, like the Toolbox does. }
- procedure bChange (p: INLPtr; offset: integer); { flip specified bit }
- INLINE $301F,$205F,$3200,$E640,$4601,$0370,$0000;
- { MOVE.W (A7)+,D0; MOVE.L (A7)+,A0; MOVE.W D0,D1; ASR.W #3,D0; NOT.B D1; BCHG D1,0(A0,D0) }
-
- procedure bSet (p: INLPtr; offset: integer); { set specified bit }
- INLINE $301F,$205F,$3200,$E640,$4601,$03F0,$0000;
- { same as for bChange ; BSET D1,0(A0,D0) }
-
- procedure bClear (p: INLPtr; offset: integer); { clear specified bit }
- INLINE $301F,$205F,$3200,$E640,$4601,$03B0,$0000;
- { same as for bChange ; BCLR D1,0(A0,D0) }
-
- function bTest (p: INLPtr; offset: integer): boolean; { test bit; TRUE return means bit = 1 }
- INLINE $301F,$205F,$3200,$E640,$4601,$0330,$0000,$56D7,$4417;
- { same as for bChange ; BTST D1,0(A0,D0); SNE (A7); NEG.B (A7) }
-
- function lslWord (a, shift: integer): integer; { logical/arithmetic shift word "a" left by "shift" }
- INLINE $4C9F,$0003,$E161,$3E81; { MOVEM.W (A7)+,D0/D1; ASL.W D0,D1; MOVE.W D1,(A7) }
-
- function lsrWord (a, shift: integer): integer; { logical shift word "a" right by "shift" }
- INLINE $4C9F,$0003,$E069,$3E81; { MOVEM.W (A7)+,D0/D1; LSR.W D0,D1; MOVE.W D1,(A7) }
-
- function asrWord (a, shift: integer): integer; { arithmetic shift word "a" right by "shift" }
- INLINE $4C9F,$0003,$E061,$3E81; { MOVEM.W (A7)+,D0/D1; ASR.W D0,D1; MOVE.W D1,(A7) }
-
- function lslLong (a: longint; shift: integer): longint; { logical/arithmetic shift long "a" left by "shift" }
- INLINE $321F,$201F,$E3A0,$2E80; { MOVE.W (A7)+,D1; MOVE.L (A7)+,D0; ASL.L D1,D0; MOVE.L D0,(A7) }
-
- function lsrLong (a: longint; shift: integer): longint; { logical shift long "a" right by "shift" }
- INLINE $321F,$201F,$E2A8,$2E80; { same as for lslLong, but LSR instead of ASL }
-
- function asrLong (a: longint; shift: integer): longint; { arithmetic shift long "a" right by "shift" }
- INLINE $321F,$201F,$E2A0,$2E80; { same as for lslLong, but ASR instead of ASL }
-
- function lowWord (a: longint): integer; { extract the low 16 bits of the long argument }
- INLINE $201F,$3E80; { MOVE.L (A7)+,D0; MOVE.W D0,(A7) }
-
- function highWord (a: longint): integer; { extract the high 16 bits of the argument }
- INLINE $3E9F,$3E9F; { MOVE.W (A7)+,(A7); MOVE.W (A7)+,(A7) }
-
- function notWord (a: integer): integer; { logical NOT a word }
- INLINE $301F,$4640,$3E80; { MOVE.W (A7)+,D0; NOT.W D0; MOVE.W D0,(A7) }
-
- function andWord (a, b: integer): integer; { AND two words }
- INLINE $301F,$C05F,$3E80; { MOVE.W (A7)+,D0; AND.W (A7)+,D0; MOVE.W D0,(A7) }
-
- function orWord (a, b: integer): integer; { OR two words }
- INLINE $301F,$805F,$3E80; { MOVE.W (A7)+,D0; OR.W (A7)+,D0; MOVE.W D0,(A7) }
-
- function eorWord (a, b: integer): integer; { EOR two words }
- INLINE $301F,$B157,$3E9F; { MOVE.W (A7)+,D0; EOR.W D0,(A7); MOVE.W (A7)+,(A7) }
-
- function notLong (a: longint): longint; { logical NOT a long }
- INLINE $201F,$4680,$2E80; { MOVE.L (A7)+,D0; NOT.L D0; MOVE.L D0,(A7) }
-
- function andLong (a, b: longint): longint; { AND two longs }
- INLINE $201F,$C09F,$2E80; { MOVE.L (A7)+,D0; AND.L (A7)+,D0; MOVE.L D0,(A7) }
-
- function orLong (a, b: longint): longint; { OR two longs }
- INLINE $201F,$809F,$2E80; { MOVE.L (A7)+,D0; OR.L (A7)+,D0; MOVE.L D0,(A7) }
-
- function eorLong (a, b: longint): longint; { EOR two longs }
- INLINE $201F,$B197,$2E9F; { MOVE.L (A7)+,D0; EOR.L D0,(A7); MOVE.L (A7)+,(A7) }
-
- implementation
-
- { "This section intentionally left blank." }
-
- end. { of unit "inlines" }
-