mac-rom/QuickDraw/Classic/Lines.m.a
Elliot Nunn 0ba83392d4 Bring in CubeE sources
Resource forks are included only for .rsrc files. These are DeRezzed into their data fork. 'ckid' resources, from the Projector VCS, are not included.

The Tools directory, containing mostly junk, is also excluded.
2017-09-20 18:04:16 +08:00

413 lines
11 KiB
Plaintext

;
; File: Lines.m.a
;
; Contains: xxx put contents here (or delete the whole line) xxx
;
; Written by: xxx put name of writer here (or delete the whole line) xxx
;
; Copyright: © 1988-1990 by Apple Computer, Inc., all rights reserved.
;
; Change History (most recent first):
;
; <2> 5/30/90 JT Adding to BBS for the first time. Line, LineTo, Move, and MoveTo
; now reset the horizontal pen fraction.
; <1.1> 11/11/88 CCH Fixed Header.
; <1.0> 11/9/88 CCH Adding to EASE.
; <1.2> 10/12/88 CCH Changed Òm.GrafType.aÓ to ÒGrafType.m.aÓ.
; <1.1> 5/18/88 MSH Changed inclides to use m.GRAPHTYPES to work under EASE.
; <1.0> 2/11/88 BBM Adding file for the first time into EASEÉ
;
; To Do:
;
;EASE$$$ READ ONLY COPY of file ÒLINES.m.aÓ
; 1.1 CCH 11/11/1988 Fixed Header.
; 1.0 CCH 11/ 9/1988 Adding to EASE.
; OLD REVISIONS BELOW
; 1.2 CCH 10/12/1988 Changed Òm.GrafType.aÓ to ÒGrafType.m.aÓ.
; 1.1 MSH 5/18/88 Changed inclides to use m.GRAPHTYPES to work under EASE.
; 1.0 BBM 2/11/88 Adding file for the first time into EASEÉ
; END EASE MODIFICATION HISTORY
BLANKS ON
STRING ASIS
INCLUDE 'GRAFTYPES.m.a'
IF (&TYPE('hasPenFraction') = 'UNDEFINED') THEN
IF forROM THEN
hasPenFraction EQU 0
ELSEIF (sysVers >= $700) THEN
hasPenFraction EQU 1
ELSE
hasPenFraction EQU 0
ENDIF
ENDIF
;-----------------------------------------------------------------
;
;
; * *** * * ***** ***
; * * * * * * *
; * * ** * * *
; * * * * * *** ***
; * * * ** * *
; * * * * * * *
; ***** *** * * ***** ***
;
;
;
; Line Drawing Rountines
;
StdLine PROC EXPORT
IMPORT CheckPic,PutPicVerb,PutPicByte,PutPicLong,DoLine
;---------------------------------------------------------------
;
; PROCEDURE StdLine(newPt: Point);
;
PARAMSIZE EQU 4
NEWPT EQU PARAMSIZE+8-4
LINK A6,#0 ;NO LOCAL VARS
MOVEM.L D5-D7/A3-A4,-(SP) ;SAVE REGS
JSR CHECKPIC ;SET UP A4,A3 AND CHECK PICSAVE
BLE.S NOTPIC ;BRANCH IF NOT PICSAVE
MOVE.B #FRAME,-(SP) ;PUSH VERB
JSR PutPicVerb ;CHECK pnSize, pnMode, pnPat
;--------------------------------------------------------
;
; PUT ONE OF FOUR LINE OPCODES BASED ON NEWPT AND DH,DV.
;
; line 20, pnLoc(pt), newPt(pt)
; line from 21, newPt(pt)
; short line 22, pnLoc(pt), dh,dv(-128..127)
; short line from 23, dh,dv(-128..127)
;
MOVEQ #$20,D7 ;INIT OPCODE TO $20
MOVE.L PICSAVE(A3),A4 ;GET PICSAVE HANDLE
MOVE.L (A4),A4 ;DE-REFERENCE PICSAVE
MOVE.L PNLOC(A3),D0 ;GET CURRENT PNLOC
CMP.L PICPNLOC(A4),D0 ;IS LINE FROM LAST ENDPOINT ?
BNE.S NOTFROM ;NO, CONTINUE
ADDQ #1,D7 ;YES, SET BIT ZERO
NOTFROM MOVE NEWPT+H(A6),D6 ;GET NEWPT.H
SUB D0,D6 ;CALC DH = NEWPT.H - PNLOC.H
MOVE D6,D0 ;COPY DH
EXT.W D0
CMP.W D6,D0 ;IS DH -128..127 ?
BNE.S PUTOP ;NO, CONTINUE
MOVE NEWPT+V(A6),D5 ;GET NEWPT.V
SUB PNLOC+V(A3),D5 ;CALC DV = NEWPT.V - PNLOC.V
MOVE D5,D0 ;COPY DV
EXT.W D0
CMP.W D5,D0 ;IS DV -128..127 ?
BNE.S PUTOP ;NO, CONTINUE
ADDQ #2,D7 ;YES, SET BIT ONE IN OPCODE
PUTOP MOVE.B D7,-(SP)
JSR PutPicByte ;PUT ONE OF 4 LINE OPCODES
ROR #1,D7 ;DO WE NEED STARTPT ? (BIT 0)
BCS.S STARTOK ;NO, CONTINUE
MOVE.L PNLOC(A3),-(SP)
JSR PutPicLong ;YES, PUT STARTPT = PNLOC
STARTOK ROR #1,D7 ;IS LINE SHORT ? (BIT 1)
BCS.S DHDV ;YES, PUT DH,DV
MOVE.L NEWPT(A6),-(SP) ;NO, PUT LONG NEWPT
JSR PutPicLong ;PUT NEWPT TO THEPIC
BRA.S UPDATE
DHDV MOVE.B D6,-(SP) ;PUSH DH (-128..127)
JSR PutPicByte ;PUT TO THEPIC
MOVE.B D5,-(SP) ;PUSH DV (-128..127)
JSR PutPicByte ;PUT TO THEPIC
UPDATE MOVE.L PICSAVE(A3),A4 ;GET PICSAVE HANDLE
MOVE.L (A4),A4 ;DE-REFERENCE PICSAVE
MOVE.L NEWPT(A6),PICPNLOC(A4) ;UPDATE PICTURE SAVING STATE
NOTPIC MOVE.L NEWPT(A6),-(SP) ;PUSH NEWPT
JSR DoLine ;DoLine(newPt);
MOVEM.L (SP)+,D5-D7/A3-A4 ;RESTORE REGS
UNLINK PARAMSIZE,'STDLINE '
LineTo PROC EXPORT
;----------------------------------------------------------
;
; PROCEDURE LineTo(h,v: INTEGER);
;
MOVE.L GRAFGLOBALS(A5),A0 ;POINT TO QUICKDRAW GLOBALS
IF hasPenFraction THEN
move.w #$8000,pnLocFixed(a0) ; reset pen fraction.
ENDIF
MOVE.L THEPORT(A0),A0 ;GET CURRENT GRAFPORT
MOVE.L GRAFPROCS(A0),D0 ;IS GRAFPROCS NIL ?
MOVE.L JStdLine,A0 ;get piece of trap table
BEQ.S USESTD ;YES, USE STD PROC
MOVE.L D0,A0
MOVE.L LINEPROC(A0),A0 ;NO, GET PROC PTR
USESTD JMP (A0) ;GO TO IT
Line PROC EXPORT
IMPORT LineTo
;----------------------------------------------------------
;
; PROCEDURE Line(dh,dv: INTEGER);
;
MOVE.L GRAFGLOBALS(A5),A0 ;POINT TO QUICKDRAW GLOBALS
IF hasPenFraction THEN
move.w #$8000,pnLocFixed(a0) ; reset pen fraction.
ENDIF
MOVE.L THEPORT(A0),A0 ;GET CURRENT GRAFPORT
MOVE PNLOC+H(A0),D0 ;GET CURRENT PENLOC.H
ADD D0,6(SP) ;ADD TO DH
MOVE PNLOC+V(A0),D0 ;GET CURRENT PENLOC.V
ADD D0,4(SP) ;ADD TO DV
JMP LineTo ;LineTo(pnLoc.h+dh,pnLoc.v+dv);
MoveTo PROC EXPORT
;----------------------------------------------------------
;
; PROCEDURE MoveTo(h,v: INTEGER);
;
MOVE.L (SP)+,A0 ;POP RETURN ADDR
MOVE.L GRAFGLOBALS(A5),A1 ;POINT TO QUICKDRAW GLOBALS
IF hasPenFraction THEN
move.w #$8000,pnLocFixed(a1) ; reset pen fraction.
ENDIF
MOVE.L THEPORT(A1),A1 ;POINT TO CURRENT GRAFPORT
MOVE.L (SP)+,PNLOC(A1) ;COPY POINT INTO PNLOC
JMP (A0) ;RETURN
MOVE PROC EXPORT
EXPORT Moov
;----------------------------------------------------------
;
; PROCEDURE Move(dh,dv: INTEGER);
;
MOOV MOVE.L (SP)+,A0 ;POP RETURN ADDR
MOVE (SP)+,D0 ;POP DV
MOVE (SP)+,D1 ;POP DH
MOVE.L GRAFGLOBALS(A5),A1 ;POINT TO QUICKDRAW GLOBALS
IF hasPenFraction THEN
move.w #$8000,pnLocFixed(a1) ; reset pen fraction.
ENDIF
MOVE.L THEPORT(A1),A1 ;GET CURRENT GRAFPORT
ADD D0,PNLOC+V(A1) ;ADD DV TO PNLOC.V
ADD D1,PNLOC+H(A1) ;ADD DH TO PNLOC.H
JMP (A0) ;RETURN
DoLine PROC EXPORT
IMPORT DrawLine,PutLine,SetHSize
;----------------------------------------------------------
;
; PROCEDURE DoLine(newPt: Point);
;
; { called by StdLine and StdPoly frame }
;
MOVEM.L D6-D7/A3-A4,-(SP) ;SAVE REGS
MOVE.L GRAFGLOBALS(A5),A4 ;POINT TO QUICKDRAW GLOBALS
MOVE.L THEPORT(A4),A3 ;POINT TO CURRENT GRAFPORT
MOVE.L 20(SP),D7 ;GET NEWPT
MOVE.L PNLOC(A3),D6 ;OLDPT := THEPORT^.PNLOC
;
; CHECK IF WE ARE SAVING FOR A POLYGON
;
TST.L POLYSAVE(A3) ;ARE WE SAVING FOR A POLYGON ?
BEQ.S NOTPOLY ;NO, CONTINUE
MOVE.L THEPOLY(A4),A1 ;YES, GET POLYHANDLE
MOVE.L (A1),A0 ;DE-REFERENCE IT
MOVE (A0),D0 ;GET CURRENT POLYSIZE
CMP #10,D0 ;IS THIS THE FIRST POINT ?
BNE.S FIRSTOK ;NO, CONTINUE
MOVE.L D6,0(A0,D0) ;YES, INSTALL FIRST := OLDPT
ADD #4,D0 ;BUMP INDEX
FIRSTOK MOVE.L D7,0(A0,D0) ;INSTALL NEWPT AT END
ADD #4,D0 ;BUMP INDEX
MOVE D0,(A0) ;UPDATE INDEX
CMP POLYMAX(A4),D0 ;TIME TO MAKE BIGGER ?
BLT.S SIZEOK ;NO, CONTINUE
ADD #256,POLYMAX(A4) ;YES, GROW IN CHUNKS
MOVE.L A1,-(SP) ;PUSH POLYHANDLE
MOVE POLYMAX(A4),-(SP) ;PUSH NEW SIZE
JSR SETHSIZE ;MAKE THEPOLY BIGGER
SIZEOK BRA.S NOTRGN ;DONT SAVE FOR RGN TOO
;
; IF NOT POLY, THEN CHECK FOR RGNSAVE.
; IF RGNSAVE THEN PutLine(oldPt,newPt,rgnBuf,rgnIndex,rgnMax);
;
NOTPOLY TST.L RGNSAVE(A3) ;ARE WE SAVING FOR A REGION ?
BEQ.S NOTRGN
MOVE.L D6,-(SP) ;PUSH OLDPT
MOVE.L D7,-(SP) ;PUSH NEWPT
MOVE.L RGNBUF(A4),-(SP) ;PUSH RGNBUF
PEA RGNINDEX(A4) ;PUSH VAR RGNINDEX
PEA RGNMAX(A4) ;PUSH VAR RGNMAX
JSR PUTLINE ;ADD INVERSION PTS TO RGNBUF
NOTRGN MOVE.L D6,-(SP) ;PUSH OLDPT
MOVE.L D7,-(SP) ;PUSH NEWPT
JSR DRAWLINE ;DRAW THE LINE
MOVE.L D7,PNLOC(A3) ;UPDATE THEPORT^.PNLOC
MOVEM.L (SP)+,D6-D7/A3-A4 ;RESTORE REGS
MOVE.L (SP)+,(SP) ;STRIP PARAM
RTS ;AND RETURN
HidePen PROC EXPORT
EXPORT ShowPen
;----------------------------------------------------------
;
; PROCEDURE HidePen;
;
MOVEQ #-1,D0
BRA.S SHARE
;----------------------------------------------------------
;
; PROCEDURE ShowPen;
;
ShowPen MOVEQ #1,D0
SHARE MOVE.L GRAFGLOBALS(A5),A0 ;POINT TO QUICKDRAW GLOBALS
MOVE.L THEPORT(A0),A0 ;GET CURRENT PORT
ADD D0,PNVIS(A0) ;INCREMENT/DECREMENT PNVIS
RTS ;AND RETURN
GetPenState PROC EXPORT
EXPORT SetPenState
;----------------------------------------------------------
;
; PROCEDURE GetPenState(VAR pnState: PenState);
; PROCEDURE SetPenState(pnState: PenState);
;
MOVEQ #1,D0 ;SET A FLAG
BRA.S SHARE ;AND SHARE CODE
SetPenState
CLR D0 ;CLEAR FLAG AND SHARE
SHARE MOVE.L GRAFGLOBALS(A5),A0 ;POINT TO QUICKDRAW GLOBALS
MOVE.L THEPORT(A0),A0 ;GET CURRENT GRAFPORT
LEA PNLOC(A0),A0 ;POINT TO PNLOC
MOVE.L 4(SP),A1 ;POINT TO VAR PNSTATE
TST D0 ;is this SET penstate ?
BNE.S NOTSET ;NO, CONTINUE
EXG A0,A1 ;YES, SWAP SRC AND DST
NOTSET MOVE.L (A0)+,(A1)+ ;COPY PNLOC FROM THEPORT
MOVE.L (A0)+,(A1)+ ;COPY PNSIZE FROM THEPORT
MOVE.W (A0)+,(A1)+ ;COPY PNMODE FROM THEPORT
MOVE.L (A0)+,(A1)+ ;COPY PNPAT FROM THEPORT
MOVE.L (A0)+,(A1)+ ;ALL 8 BYTES
MOVE.L (SP)+,(SP) ;STRIP 4 BYTES
RTS ;AND RETURN
GetPen PROC EXPORT
;----------------------------------------------------------
;
; PROCEDURE GetPen(VAR pt: Point);
; { inquire the current pen location }
;
MOVE.L GRAFGLOBALS(A5),A0 ;POINT TO QUICKDRAW GLOBALS
MOVE.L THEPORT(A0),A0 ;GET CURRENT GRAFPORT
MOVE.L 4(SP),A1 ;POINT TO VAR PT
MOVE.L PNLOC(A0),(A1) ;GET PNLOC FROM THEPORT
MOVE.L (SP)+,(SP) ;STRIP 4 BYTES
RTS ;AND RETURN
PenSize PROC EXPORT
;----------------------------------------------------------
;
; PROCEDURE PenSize(width,height: INTEGER);
; { set the pen width and height }
;
MOVE.L GRAFGLOBALS(A5),A0 ;POINT TO QUICKDRAW GLOBALS
MOVE.L THEPORT(A0),A0 ;GET CURRENT GRAFPORT
MOVE.L 4(SP),PNSIZE(A0) ;SET PEN WIDTH AND HEIGHT
MOVE.L (SP)+,(SP) ;STRIP 4 BYTES
RTS ;AND RETURN
PenMode PROC EXPORT
IMPORT PortWord
;----------------------------------------------------------
;
; PROCEDURE PenMode(mode: INTEGER);
; { set the transfer mode for line drawing }
;
MOVEQ #PNMODE,D0 ;PUT PORT OFFSET IN D0
JMP PORTWORD ;INSTALL PARAM INTO THEPORT
PenPat PROC EXPORT
;----------------------------------------------------------
;
; PROCEDURE PenPat(pat: Pattern);
; { set the pattern for line drawing }
;
MOVE.L GRAFGLOBALS(A5),A0 ;POINT TO QUICKDRAW GLOBALS
MOVE.L THEPORT(A0),A0 ;GET CURRENT GRAFPORT
LEA PNPAT(A0),A0 ;POINT TO PNPAT
MOVE.L 4(SP),A1 ;POINT TO INPUT PATTERN
MOVE.L (A1)+,(A0)+ ;COPY PATTERN INTO THEPORT
MOVE.L (A1)+,(A0)+ ;ALL 8 BYTES
MOVE.L (SP)+,(SP) ;STRIP 4 BYTES
RTS ;AND RETURN
PenNormal PROC EXPORT
;----------------------------------------------------------
;
; PROCEDURE PenNormal;
; { restore all line drawing parameters to normal }
;
MOVE.L GRAFGLOBALS(A5),A0 ;POINT TO QUICKDRAW GLOBALS
MOVE.L THEPORT(A0),A0 ;GET CURRENT GRAFPORT
MOVE.L #$00010001,PNSIZE(A0) ;PEN SIZE:=1,1
MOVE #8,PNMODE(A0) ;PENMODE:=PATTERN COPY
MOVEQ #-1,D0
MOVE.L D0,PNPAT(A0) ;PNPAT:=BLACK
MOVE.L D0,PNPAT+4(A0)
RTS
END