-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chapter 31.a
161 lines (141 loc) · 4.29 KB
/
Chapter 31.a
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
;-------------------------------------------------------------
; Chapter 31 - Drawing Lines - Online
;-------------------------------------------------------------
processor 6502
include "vcs.h"
include "macro.h"
include "xmacro.h" ; timer macros
;-----------------------------------------------------------------
; Variables SEGment
;-----------------------------------------------------------------
seg.u Variables ; set Variables SEGment (uninitialized)
org $80 ; start Variables at $80
;-----------------------------------------------------------------
; Declare variables
;-----------------------------------------------------------------
Temp .byte
X1 .byte ; start X coordinate of line
Y1 .byte ; start Y coordinate of line
Y2 .byte ; end Y coordinate of line
Slope .word ; 16-bit slope
XFrac .byte ; X fractional
;-----------------------------------------------------------------
; Code SEGment
;-----------------------------------------------------------------
seg Code ; set Code SEGment
org $f000 ; start Code at $f000
;-----------------------------------------------------------------
; Initialize and set initial offsets of objects.
;-----------------------------------------------------------------
Start
CLEAN_START ; macro to safely clear memroy and TIA
;-----------------------------------------------------------------
; Set initial values to calculate line
lda #80
sta X1
lda #80
sta Y1
lda #120
sta Y2
lda #0
sta Slope
lda #0
sta Slope+1
NextFrame
VERTICAL_SYNC
TIMER_SETUP 37
;-----------------------------------------------------------------
; Set missile 0 X start position
lda X1 ; starting X
ldx #2 ; missile 0
jsr SetHorizPos
sta WSYNC
sta HMOVE
TIMER_WAIT
TIMER_SETUP 192
lda #$54
sta COLUP0
ldy #0
sty XFrac
ScanLoop
cpy Y1
bcc NoLine ; out of bounds (< Y1)?
cpy Y2
bcs NoLine ; out of bounds (> Y2)?
;-----------------------------------------------------------------
; Add slope to X fractional error
lda XFrac
clc
adc Slope ; this sets carry flag
sta XFrac
lda Slope+1
adc #7 ; 7 + carry flag
tax ; -> X
lda DotWidths,x ; lookup register for missile width
sta Temp ; -> Temp
lda HMoveTable,x ; lookup HMOVE register for X offset
sta WSYNC
sta HMOVE ; apply moves on previous scanline
ldx #2
stx ENAM0 ; enable missile
ldx Temp
stx NUSIZ0 ; set missile width
sta HMM0 ; set HMM0 for next scanline
NextScan
iny
cpy #192
bcc ScanLoop ; any more scanlines?
beq DoneLine ; branch always taken
NoLine
sta WSYNC
lda #0
sta ENAM0 ; hide missile
jmp NextScan
DoneLine
TIMER_SETUP 30
;-----------------------------------------------------------------
; Change slope of line
lda Slope
clc
adc #3 ; speed of line sweeping r to l
sta Slope
lda Slope+1
adc #0
cmp #2
bmi NoLineReset
lda #$fe
NoLineReset
sta Slope+1
TIMER_WAIT
jmp NextFrame
SetHorizPos subroutine
sta WSYNC ; start a new line
bit 0 ; waste 3 cycles
sec ; set carry flag
DivideLoop
sbc #15 ; subtract 15
bcs DivideLoop ; branch until negative
eor #7 ; calculate fine offset
asl
asl
asl
asl
sta RESP0,x ; fix coarse position
sta HMP0,x ; set fine offset
rts ; return to caller
;-----------------------------------------------------------------
; HMOVE table from -7 to +8
;-----------------------------------------------------------------
HMoveTable
hex 7060504030201000f0e0d0c0b0a09080
;-----------------------------------------------------------------
; Table for NUSIZ registers
;-----------------------------------------------------------------
DotWidths
hex 40403030201000000010203030404040
;-----------------------------------------------------------------
; Epilogue
;-----------------------------------------------------------------
org $fffc ; start at $fffc
.word Start ; reset vector at $fffc
.word Start ; interrupt vector at $fffe (unused in VCS)