-
Notifications
You must be signed in to change notification settings - Fork 1
/
bresenham.i
123 lines (111 loc) · 1.81 KB
/
bresenham.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
.macro BresenhamPlotSpan
; filled vectors - just get span info here
; update pixel spans for filling in edge tiles
txa
cmp SpansStart,y
bcs :+
sta SpansStart,y
cmp SpansWindowStart,y
bcs :+
sta SpansWindowStart,y
:
cmp SpansEnd,y
bcc :+
sta SpansEnd,y
cmp SpansWindowEnd,y
bcc :+
sta SpansWindowEnd,y
:
.endmac
.macro BresenhamPlotPixel
; wireframe vectors - draw single point
; bmi @nextline
lda AddrMSBForY,y
sta DrawPtr+1
lda AddrLSBForY,y
; bmi @nextline
clc
adc AddrLSBForX,x
sta DrawPtr
lda [DrawPtr]
ora AddrBitForX,x
sta [DrawPtr]
.endmac
; -------------------------------------------------------------------
.macro BresenhamPlot steep, dir_y
; set up error accumulation
.if steep
lda z:Line2DX
sec
sbc z:LineDY
sta z:LineError
sec
sbc z:LineDY
sta z:LineAddError
.else
lda z:Line2DY
sec
sbc z:LineDX
sta z:LineError
sec
sbc z:LineDX
sta z:LineAddError
.endif
ldx z:LineX1
ldy z:LineY1
; loop - plot single pixels (or fill edge tiles) along the line
@plotpixels:
.if ::FILL_VECTORS <> 1
BresenhamPlotPixel
.endif
; update delta
lda z:LineError
bmi @no_overflow
; error overflow
clc
adc z:LineAddError
sta z:LineError
; update secondary axis
.if steep
inx
.else
.if ::FILL_VECTORS = 1
BresenhamPlotSpan
.endif
dir_y
.endif
bra @nextpixel
; no error overflow
@no_overflow:
clc
; update error based on secondary axis
.if steep
adc z:Line2DX
.else
adc z:Line2DY
.endif
sta z:LineError
; update primary axis
@nextpixel:
.if steep
; steep lines update spans when Y changes
.if ::FILL_VECTORS = 1
BresenhamPlotSpan
.endif
dir_y
dec z:LineDY
.else
inx
dec z:LineDX
.endif
; move to next point
bpl @plotpixels
; at the end, roll non-steep lines back one and update once more
.if ::FILL_VECTORS = 1
.if .not steep
dex
BresenhamPlotSpan
.endif
.endif
jmp drawline
.endmac