home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
64'er
/
64ER_CD.iso
/
s85xx
/
s8504b.d64
/
facet.src
< prev
next >
Wrap
Text File
|
1995-03-30
|
8KB
|
468 lines
; FACET - DRAW SHADED TRIANGULAR FACETS
; AND STRAIGHT LINES.
;
; RICHARD L. RYLANDER 11/4/84
;
; LOAD "ARITH.HEX" AND "GRAPH.HEX"
; BEFORE USING
;
ORIGIN = $C26F
RAM = $034A
;
XPLT = $033F
YPLT = $0341
NORM = $C224
NOSCAL = $0347
PLOT = $C143
UNPLOT = $C146
;
MLPCND = $AC
MLPLER = $AD
PROD = $AE
MULT = $C011
;
DVDND = $FD
DVSOR = $FB
QUOT = $FD
DIVIDE = $C025
;
*=RAM
;
XMIN *=*+2
YMIN *=*+1
XMID *=*+2
YMID *=*+1
XMAX *=*+2
YMAX *=*+1
YTOP *=*+1
YBOT *=*+1
YBASE *=*+1
DLTAX1 *=*+2
DLTAX2 *=*+1
DLTAX3 *=*+1
DELTAX *=*+1
DLTAY1 *=*+1
DLTAY2 *=*+1
DLTAY3 *=*+1
DELTAY *=*+1
XDIFF *=*+1
FLAG1 *=*+1
FLAG2 *=*+1
FLAG3 *=*+1
FLAG *=*+1
EDGES *=*+1
ERROR *=*+2
MODE *=*+1
COUNT *=*+2
;
;
*=ORIGIN
;
;*****************************************
;
; SCALE ALL Y COORDINATES FROM 0..239
; PSUEDO-COORDINATE RANGE TO 0..199
; TRUE SCREEN COORDINATE RANGE
;
SCALE LDY #6
LDA #$D5
STA MLPCND
SCLP LDA YMIN,Y
STA MLPLER
JSR MULT
STA YMIN,Y
DEY
DEY
DEY
BPL SCLP
RTS
;
;
;*****************************************
;
; EXCHANGE 'MIN' AND 'MID' COORDINATES
;
SWAP12 LDY #2
LOOP1 LDA XMIN,Y
PHA
LDA XMID,Y
STA XMIN,Y
PLA
STA XMID,Y
DEY
BPL LOOP1
RTS
;
;*****************************************
;
; EXCHANGE 'MID' AND 'MAX' COORDINATES
;
SWAP23 LDY #2
LOOP2 LDA XMID,Y
PHA
LDA XMAX,Y
STA XMID,Y
PLA
STA XMAX,Y
DEY
BPL LOOP2
RTS
;
;*****************************************
;
; SORT COORDINATES ACCORDING TO X COMPONENTS
;
SORTX LDX #2
SORTLP SEC
LDA XMID
SBC XMIN
LDA XMID+1
SBC XMIN+1
BCS NOSWP1
JSR SWAP12
NOSWP1 DEX
BEQ SORTED
SEC
LDA XMAX
SBC XMID
LDA XMAX+1
SBC XMID+1
BCS SORTLP
JSR SWAP23
JMP SORTLP
SORTED RTS
;
;*****************************************
;
; DRAW A LINE BETWEEN XMIN,YMIN AND XMID,YMID
; USING FAST DDA (DIGITAL DIFFERENTIAL ANALYZER)
; TECHNIQUE
;
LINE LDA #2 ; ENSURE XMAX IS
STA XMAX+1 ; LARGEST BEFORE
JSR SORTX ; ORDERING 'MIN' AND 'MID'
LDA NOSCAL
BEQ OUTLN
JSR SCALE
OUTLN JSR FINDXY ; ENTRY POINT TO
LDA XMIN ; OUTLINE FACETS
STA XPLT
LDA XMIN+1
STA XPLT+1
LDA YMIN
STA YPLT
LDA DLTAX1+1 ; CHECK FOR DX>DY
BNE STEPX
SEC
LDA DLTAX1
SBC DLTAY1
BCS STEPX
STEPY LDA DLTAY1
STA ERROR
STA COUNT
LSR ERROR
SEC
LDA DLTAX1
SBC ERROR
STA ERROR
LDA DLTAX1+1
SBC #0
STA ERROR+1
INC COUNT
LNLP1 LDA MODE ; 0 = DRAW, 1 = ERASE
BNE ERASE1
JSR PLOT
JMP SK1
ERASE1 JSR UNPLOT
SK1 LDA FLAG1 ; 0 = POSITIVE SLOPE
BNE NSLOPE
INC YPLT
BNE SK2 ; ALWAYS BRANCH
NSLOPE DEC YPLT
SK2 BIT ERROR+1
BMI SK3
INC XPLT
BNE NOINC1
INC XPLT+1
NOINC1 SEC
LDA ERROR
SBC DLTAY1
STA ERROR
LDA ERROR+1
SBC #0
STA ERROR+1
SK3 CLC
LDA ERROR
ADC DLTAX1
STA ERROR
LDA ERROR+1
ADC DLTAX1+1
STA ERROR+1
DEC COUNT
BNE LNLP1
RTS
;
STEPX LDA DLTAX1
STA ERROR
STA COUNT
LDA DLTAX1+1
STA ERROR+1
STA COUNT+1
LSR ERROR+1
ROR ERROR
SEC
LDA DLTAY1
SBC ERROR
STA ERROR
LDA #0
SBC ERROR+1
STA ERROR+1
LNLP2 LDA MODE
BNE ERASE2
JSR PLOT
JMP SKP1
ERASE2 JSR UNPLOT
SKP1 INC XPLT
BNE NOINC2
INC XPLT+1
NOINC2 BIT ERROR+1
BMI SKP3
LDA FLAG1
BNE NGSLP
INC YPLT
BNE SKP2 ; ALWAYS BRANCH
NGSLP DEC YPLT
SKP2 SEC
LDA ERROR
SBC DLTAX1
STA ERROR
LDA ERROR+1
SBC DLTAX1+1
STA ERROR+1
SKP3 CLC
LDA ERROR
ADC DLTAY1
STA ERROR
LDA ERROR+1
ADC #0
STA ERROR+1
SEC
LDA COUNT
SBC #1
STA COUNT
BCS TEST
DEC COUNT+1
TEST BIT COUNT+1
BPL LNLP2
RTS
;
;*****************************************
; DRAW A SHADED VERTICAL LINE AT
; XPLT FROM YTOP TO YBOT
;
VLINE SEC ; MAKE SURE YTOP>YBOT
LDA YTOP
SBC YBOT
BCS DRAW
LDA YTOP
PHA
LDA YBOT
STA YTOP
PLA
STA YBOT
DRAW LDA YTOP
STA YPLT
JSR NORM ; PLOT A SHADE-WEIGHTED
LDA YTOP ; PIXEL CHECKING ONLY
CMP YBOT ; FOR SHADE STYLE
BEQ DONE
DEC YTOP
JMP DRAW
DONE RTS
;
;*****************************************
;
; FIND ENDPOINTS FOR VERTICAL LINES
; BETWEEN FACET EDGES
;
ENDPTS LDA XDIFF
STA MLPCND
LDA DELTAY
STA MLPLER
JSR MULT
STA DVDND+1
LDA PROD
STA DVDND
LDA #0
STA DVSOR+1
LDA DELTAX
STA DVSOR
JSR DIVIDE
LDA FLAG
BNE NEGSLP
CLC
LDA YBASE
ADC QUOT
BCC SKIP2
NEGSLP SEC
LDA YBASE
SBC QUOT
SKIP2 RTS
;
;*****************************************
;
; FIND COORDINATE DIFFERENCES
;
; ALL "DELTA X" VALUES POSITIVE,
; SINGLE PRECISION (JUST LOWER BYTE)
;
FINDXY SEC
LDA XMID
SBC XMIN
STA DLTAX1
LDA XMID+1
SBC XMIN+1
STA DLTAX1+1
SEC
LDA XMAX
SBC XMID
STA DLTAX2
SEC
LDA XMAX
SBC XMIN
STA DLTAX3
;
; USE ABS(DELTA Y) VALUES,
; FLAGS INDICATE SLOPE OF LIMIT LINES
;
LDA #$00
STA FLAG1
STA FLAG2
STA FLAG3
SEC
LDA YMID
SBC YMIN
BCS STORE1
INC FLAG1
LDA YMIN
SBC YMID
STORE1 STA DLTAY1
SEC
LDA YMAX
SBC YMID
BCS STORE2
INC FLAG2
LDA YMID
SBC YMAX
STORE2 STA DLTAY2
SEC
LDA YMAX
SBC YMIN
BCS STORE3
INC FLAG3
LDA YMIN
SBC YMAX
STORE3 STA DLTAY3
RTS
;
;*****************************************
;
; DRAW A SHADED TRIANGULAR FACET
;
FACET JSR SORTX
LDA NOSCAL
BEQ YSOK
JSR SCALE
YSOK JSR FINDXY
LDA XMIN
STA XPLT
LDA XMIN+1
STA XPLT+1
FCETLP SEC
LDA XPLT
SBC XMIN
STA XDIFF
LDA DLTAX1
BEQ CONT
STA DELTAX
LDA DLTAY1
STA DELTAY
LDA FLAG1
STA FLAG
LDA YMIN
STA YBASE
JSR ENDPTS
STA YTOP
LDA DLTAX3
BEQ CONT
STA DELTAX
LDA DLTAY3
STA DELTAY
LDA FLAG3
STA FLAG
JSR ENDPTS
STA YBOT
JSR VLINE
LDA XPLT+1
CMP XMID+1
BNE NEXTX1
LDA XPLT
CMP XMID
BEQ CONT
NEXTX1 INC XPLT
BNE SKIP3
INC XPLT+1
SKIP3 JMP FCETLP
CONT SEC
LDA XPLT
SBC XMIN
STA XDIFF
LDA DLTAX3
BEQ FINI
STA DELTAX
LDA DLTAY3
STA DELTAY
LDA FLAG3
STA FLAG
LDA YMIN
STA YBASE
JSR ENDPTS
STA YBOT
SEC
LDA XPLT
SBC XMID
STA XDIFF
LDA DLTAX2
BEQ FINI
STA DELTAX
LDA DLTAY2
STA DELTAY
LDA FLAG2
STA FLAG
LDA YMID
STA YBASE
JSR ENDPTS
STA YTOP
JSR VLINE
LDA XPLT+1
CMP XMAX+1
BNE NEXTX2
LDA XPLT
CMP XMAX
BEQ FINI
NEXTX2 INC XPLT
BNE SKIP4
INC XPLT+1
SKIP4 JMP CONT
FINI LDA EDGES
BEQ FINISH
JSR OUTLN
JSR SWAP23
JSR OUTLN
JSR SWAP12
JSR SWAP23
JSR SWAP12
JSR OUTLN
FINISH RTS
.END