-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathgraphic9.src
214 lines (184 loc) · 4.22 KB
/
graphic9.src
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
.page
.subttl 'graphics9'
;***************************************************************
;
; dotwo - add two 2-byte values if carry clear
; subtract two 2-byte values if carry set
;
;***************************************************************
dotwo2
bcc addtw2 ;go do addition
bcs subtw2 ;go do subtraction
dotwo
bcs subtwo ;go do subtraction
;***************************************************************
;
; addtwo - add vwork+y and vwork+x - result in y/a
;
;***************************************************************
addtwo
jsr settwo ;put vwrok+y into y/a
addtw2 ;enter here to add y/a to vwork+x
clc
adc vwork,x
pha
tya
adc vwork+1,x
tay
pla
rts
;****************************************************************
;
; subtwo - subtract vwork+y - vwork+x - result in y/a
;
;****************************************************************
subtwo
jsr settwo ;move vwork+y into y/a
subtw2 ;enter here with 1st value in y/a
sec
sbc vwork,x
sta temp
tya
sbc vwork+1,x
tay
php
lda temp
plp
rts
;************************************************************
;
; settwo - move value in vwork+y into y/a
;
;************************************************************
settwo
lda vwork,y
pha
lda vwork+1,y
tay
pla
rts
;******************************************************************
;
; abstwo - get absolute value of vwork+y - vwork+x
; result in y/a - carry === vwork+y >= vwork+x
;
;******************************************************************
abstwo
jsr subtwo ;subtract vwork+y - vwork+x
abstw2 ;entrance with vwork+y in y/a
bpl absrts ;done if result is positive
invert php
clc
eor #$ff ;invert low byte result and add 1
adc #1
pha
tya
eor #$ff ;invert high byte result
adc #0 ;add back any carry
tay
pla
plp
absrts rts
;****************************************************************
;
; twobyt - multiply 2 byte fraction in y/a times 2 bytes
; integer found in vwork+x-reg. result = y/a
;
;****************************************************************
twobyt
sty vtemp1 ;save fraction
sta vtemp2
lda vwork,x
ldy vwork+1,x
php ;save sign of integer
jsr abstw2 ;absolute value
sta vwork,x
tya
sta vwork+1,x
lda #0
sta vtemp3 ;initialize result to zero
ldy #16 ;initialize count
twoby1
lsr vtemp1
ror vtemp2
bcc twoby2 ;skip if no bit set
clc
adc vwork,x ;add integer low byte
pha
lda vtemp3
adc vwork+1,x ;add integer high byte to total
sta vtemp3
pla
twoby2
lsr vtemp3 ;divide by 2
ror a
dey
bne twoby1 ;loop 16 times - test all bits in 2 bytes
adc #0 ;add back round factor
ldy vtemp3
bcc tworts
iny
tworts plp ;pop sign
jmp abstw2 ;return with signed product in y/a
;******************************************************************
; dstpos - move xdest/ydest to xpos/ypos
;
;******************************************************************
dstpos
ldy #0
jsr dstmov
ldy #2
dstmov
lda xdest,y
sta xpos,y
lda xdest+1,y
sta xpos+1,y
rts
;*****************************************************************
;
; optwrd - get an optional 2 byte value in y,a.
; case 1 : pointer at end of line:
; return a=y=0, clear c to flag 'default'
; case 2 : pointer is at comma, next non-blank is also a comma:
; return a=y=0, clear c to flag 'default'
; case 3 : pointer is at comma, next non-blank is not a comma:
; get word in y,a, set c to flag 'non-default'
;
;*****************************************************************
optwrd
jsr chrgot
beq optw90
jsr chkcom
cmp #','
beq optw90
jsr getwrd
sec
rts
optw90
lda #0
tay
clc
optw99
rts
;*****************************************************************
;
; optbyt - get an optional 1 byte value in x.
; enter with default value in x.
; case 1 : pointer at end of line:
; return default x.
; case 2 : pointer is at comma, next non-blank is also a comma:
; return default x.
; case 3 : pointer is at comma, next non-blank is not a comma:
; get byte in x.
;
;*****************************************************************
optzer ;optional byte, with default=0
ldx #0
optbyt
jsr chrgot
beq optw99
jsr chkcom
cmp #','
beq optw99
jmp getbyt
;.end