-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrain.asm
More file actions
207 lines (156 loc) · 3.79 KB
/
Copy pathrain.asm
File metadata and controls
207 lines (156 loc) · 3.79 KB
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
processor 6502
include "vcs.h"
include "macro.h"
p_len = #10
PF_H = #192
PF_min = #8
seg.u vars ; segmento non inizializzato
org $80 ; origine all'inizio della ram
p_y ds 1 ; 1 byte - player 0 y pos
r_seed ds 1 ; random seed
snd_on ds 1 ; il suono è acceso ?
SEG main
ORG $F000
Reset:
ldx #0
lda #0
Clear CLEAN_START ;macro
;sta 0,x
;inx
;bne Clear
lda INTIM ; seed
cmp #227 ; Horizontal length
bcc SeedOk
lsr
SeedOk
sta r_seed
lda #PF_H
sta p_y
;lda #0
lda #$8C
sta COLUBK
lda #$86
sta COLUP0
sta COLUPF
lda #%00000000
sta GRP0
lda #$4
sta AUDC0
sta AUDF0
StartFrame
lda #%11111111
sta PF0
sta PF1
sta PF2
lda snd_on
beq YesSound
dec snd_on
bne YesSound
lda #0
sta AUDV0
YesSound:
ldx r_seed ; (3)
jsr pos_x ; (6) set the initial course position of the player 0 graphic
lda #%00000000
sta GRP0
pos_y_management
dec p_y ; velocità verticale: 2px/frame
dec p_y
lda p_y
cmp #PF_min
bcs PosYinRange
lda #192
sta p_y
jsr galois_lfsr_random ; chiamata più volte per maggiore entropia
jsr galois_lfsr_random
jsr galois_lfsr_random ; alla fine il risultato è in r_seed
lda #$4 ; Riproduci suono alzando il volume
sta AUDV0
lda #$1
sta snd_on
PosYinRange ; si potrebbe fare il branch direttamente a vsync
Vsync
lda #0
sta VBLANK
lda #2
sta VSYNC
sta WSYNC
sta WSYNC
sta WSYNC
lda #0
sta VSYNC
ldx #37
Vbl
sta WSYNC
dex
bne Vbl
lda #%00000000 ; Togli il playfield prima di iniziare a disegnare
sta PF0
sta PF1
sta PF2
ldx #192
Draw
txa ; trasferiamo la x nell'accumulatore perchè dopo effettuiamo adc
cmp p_y
bcs NoDroplet
clc ; per effettuare addizione senza carry (può essere impostato come on randomicamente)
adc #p_len
cmp p_y
bcc NoDroplet
Droplet
lda #%00001000
sta GRP0
jmp DrawLoop
NoDroplet
lda #%00000000
sta GRP0
; non necessario jmp a DrawLoop
DrawLoop
sta WSYNC
dex
bne Draw
; reset della grafica del player e del pf prima dell'inizio del frame
lda #%00000000
sta GRP0
lda #%11111111
sta PF0
sta PF1
sta PF2
ldx #28 ; Uso qualche linea di overscan in meno perchè a volte le istruzioni ci mettono più di una scanline per completarsi (?)
Overscan
sta WSYNC
dex
bne Overscan
lda #%01000010
sta VBLANK
jmp StartFrame
Divide15 ; il 6502 non può dividere per 15
.POS SET 0
REPEAT 160
.byte (.POS / 15) + 1
.POS SET .POS + 1
REPEND
pos_x ; subroutine per posizionare uno sprite, divide il numero che si trova nel registro x, il risultato viene salvato nel registro x
lda Divide15,x
tax
sta WSYNC
; ---- loop semplice che impiega 5 cicli ( 15 color clocks )
SimpleLoop: dex ; (2)
bne SimpleLoop ; (2/3)
sta RESP0 ; (3)
rts ; (6) return to caller
; Galois 8-bit Linear Feedback Shift Registers
; https://samiam.org/blog/20130617.html
galois_lfsr_random
lda r_seed ; keep calling funtion to for better entropy
lsr ; shift right
bcc noeor0 ; if carry 1, then exclusive OR the bits
eor #$D4 ; d4 tap (11010100)
noeor0: sta r_seed
rts
org $fffa ; set origin to last 6 bytes of 4k rom
InterruptVectors
.word Reset ; NMI
.word Reset ; RESET
.word Reset ; IRQ
END