home *** CD-ROM | disk | FTP | other *** search
- \ GRAPHICS.SEQ A graphics package by Davies, Smith, and Smiley.
-
- comment:
- Here are some graphics primitives, from the following package.
- +--------------------------------------------------------------+
- | FLOATING-POINT TURTLE GRAPHICS |
- | Behold ! On the following screens will be revealed the |
- | wonders of Lines and Turtle Graphics. Let the lights dim |
- | and Wagner's "Ride of the Valkyries" play softly in the |
- | background. Prepare, for you are about to perceive |
- | |
- | T H E M A G I C O F F O R T H ! |
- | |
- | |
- | R. L. Davies |
- | E. Tim Smith |
- | (or the other way around) |
- | and Mark Smiley |
- | |
- +--------------------------------------------------------------+
- comment;
-
- POSTFIX \ We will use the post version of the assembler here.
-
- \ XINTCALL and INTCALL by E.T. Smith
-
- CODE <XINTCALL> DX POP CX POP BX POP AX POP BP PUSH SI PUSH
- 0 INT SI POP BP POP PUSHF 1PUSH END-CODE
-
- : XINTCALL [ ' <XINTCALL> 7 + ( 7 + for direct code )
- ( 9 + for indirect code ) ] LITERAL C!
- [ ' <XINTCALL> ] LITERAL EXECUTE ;
-
- : INTCALL XINTCALL NIP ;
-
- : FINTCALL XINTCALL DROP ;
-
- \ Line Drawing --------------- by Tim Smith --------------------
- \ Graphics Comments --------- by R. L. Davies ---------------
-
- : MODE ( n -- ) 0 0 0 16 INTCALL DROP ;
-
- VARIABLE COLOR 1 COLOR !
- VARIABLE ASPECT 10 ASPECT !
- VARIABLE OLDX
- VARIABLE OLDY
- VARIABLE NEWX
- VARIABLE NEWY
-
- VARIABLE XSCALE
- 100 CONSTANT YSCALE
-
-
- comment:
-
- MODE is used to set the screen mode. 2 is Text, 4 is Medium
- Graphics, and 6 is High Graphics.
- COLOR holds the present pencolor.
- ASPECT holds the screen aspect factor for scrunch.
- OLDX holds the old X position (as though you couldn't guess).
- OLDY holds the old Y position.
- NEWX holds the new X position.
- NEWY holds the new Y position.
-
- XSCALE holds the screen resolution X-scale, depending on mode.
- YSCALE is the constant for screen resolution for the Y-axis.
- comment;
-
- VOCABULARY GRAPH GRAPH ALSO DEFINITIONS
-
- VARIABLE X1
- VARIABLE X2
- VARIABLE Y1
- VARIABLE Y2
-
- CREATE LTBL 8 ALLOT
-
- LABEL (PIXEL)
- 3328 # AX MOV 16 INT 127 # AX AND AX AX OR
- AX NOT RET END-CODE
-
-
- comment:
-
- GRAPH is a vocabulary that will hold most of the words which,
- though useful in other words, are actually trivial.
- X1 holds the old X coordinate for the Assembly procedures.
- X2 holds the new X coordinate.
- Y1 holds the old Y coordinate.
- Y2 holds the new Y coordinate.
-
- LTBL holds a series of values used in the line procedure.
-
- (PIXEL) is a procedure which finds the color at a position
- and returns FALSE if background and TRUE if a color
- (1, 2, or 3).
- comment;
-
- LABEL (PSET)
- BX PUSH CX PUSH DX PUSH AX PUSH SI PUSH DI PUSH BP PUSH
- COLOR #) AX MOV 12 # AH MOV 16 INT
- BP POP DI POP SI POP AX POP DX POP CX POP BX POP
- RET END-CODE
-
- LABEL STEEP
- LTBL 2 + #) AX MOV AX SHR AX LTBL 4 + #) MOV
- X1 #) CX MOV Y1 #) DX MOV 0 # BX MOV
- LTBL 2 + #) AX MOV AX LTBL 6 + #) MOV HERE
- (PSET) #) CALL SI DX ADD LTBL #) BX ADD
- LTBL 4 + #) BX CMP HERE 8 + JLE LTBL 2 + #) BX SUB
- DI CX ADD LTBL 6 + #) DEC JGE RET END-CODE
-
- comment:
- (PSET) is the procedure that actually plots a point in the
- present COLOR.
-
- STEEP is the procedure that draws lines with slopes greater
- than one.
- comment;
-
-
- LABEL EASY
- LTBL #) AX MOV AX SHR AX LTBL 4 + #) MOV
- X1 #) CX MOV Y1 #) DX MOV 0 # BX MOV
- LTBL #) AX MOV AX LTBL 6 + #) MOV HERE
- (PSET) #) CALL DI CX ADD LTBL 2 + #) BX ADD
- LTBL 4 + #) BX CMP HERE 8 + JLE LTBL #) BX SUB
- SI DX ADD LTBL 6 + #) DEC JGE RET END-CODE
-
- LABEL CSTEEP STEEP #) CALL RET END-CODE
-
- LABEL STORE-X
- AX LTBL #) MOV LTBL #) AX MOV LTBL 2 + #) AX CMP
- CSTEEP JL EASY #) CALL RET END-CODE
-
-
-
- comment:
-
- EASY is the procedure that draws lines with slopes less than
- or equal to zero.
-
- CSTEEP is a short procedure that calls the STEEP procedure.
-
- STORE-X -- Guess.
-
- comment;
-
-
- LABEL STORE-Y
- AX LTBL 2 + #) MOV X2 #) AX MOV X1 #) AX SUB
- 1 # DI MOV STORE-X JGE -1 # DI MOV
- AX NEG STORE-X #) JMP END-CODE
-
- LABEL (LINE)
- OLDX #) AX MOV XSCALE #) AX ADD AX X1 #) MOV
- NEWX #) AX MOV XSCALE #) AX ADD AX X2 #) MOV
- OLDY #) AX MOV AX NEG 100 # AX ADD AX Y1 #) MOV
- NEWY #) AX MOV AX NEG 100 # AX ADD AX Y2 #) MOV
- Y2 #) AX MOV Y1 #) AX SUB 1 # SI MOV STORE-Y JGE
- -1 # SI MOV AX NEG STORE-Y #) JMP END-CODE
-
-
-
- comment:
-
- STORE-Y -- Guess again.
-
- (LINE) is the procedure that, first, modifys the coordinates
- so that they are plotted with (0,0) at the center of the
- screen. Second, delta-Y is calculated and the
- Y-increment is set.
-
-
- comment;
-
-
- FORTH DEFINITIONS
-
- CODE LINE ( -- )
- SI PUSH BP PUSH (LINE) #) CALL BP POP SI POP
- NEXT END-CODE
-
- CODE PIXEL ( x y -- f )
- (PIXEL) #) CALL 1PUSH END-CODE
-
- : SEGMENT ( x y nx ny -- )
- NEWY ! NEWX ! OLDY ! OLDX ! LINE ;
-
-
- comment:
-
- The following definitions are linked to the Forth Vocabulary.
-
- LINE is the Forth link to the line-drawing procedures.
-
- \ LINE is a slow line routine that takes scrunch into
- account. Define LINE above as ((LINE)) to use.
-
- PIXEL takes in a position and returns TRUE if the dot is
- on or FALSE if the dot is off.
-
- SEGMENT takes an old position and a new position and draws
- a line in the current COLOR. Any old positions are
- changed to the position given as the old position.
- comment;
-
- \ (CLS) Clear a graphics screen, by Mark Smiley
-
- forth assembler also GRAPH also definitions
-
- HEX
-
- LABEL (CLSG)
- CX PUSH AX PUSH
- 2000 # CX MOV
- 0 # AX MOV
- AX DI MOV
- CLD
- REP STOSW
- AX POP CX POP
- RET END-CODE
-
- DECIMAL
-
-
- comment:
-
- Clears the screen without re-setting the system into graphics
- mode (via MODE). So it doesn't put the cursor back into the
- upper left-hand corner.
- save registers
-
- set flag so REP decrements CX (until CX=0)
- AX STOS is the same as STOSW in ordinary assembler (AX sets
- STOS to work on "words" [cells] rather than on bytes).
- restore registers
-
- comment;
-
-
- \ CLSG clears high or med res. graphics screen
-
- FORTH DEFINITIONS
- HEX
-
- CODE CLSG
- AX PUSH
- B800 # AX MOV
- AX ES MOV \ B800 ES MOV won't work
- (CLSG) #) CALL
- AX POP
- NEXT END-CODE
-
- DECIMAL
-
- only forth also definitions
-