Skip to content

Commit 919a9c1

Browse files
committed
add rotation
1 parent 9b1b340 commit 919a9c1

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

intro/starf.s

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
;
77
; starfield
88

9-
nb_stars equ 220
9+
;nb_stars equ 220
10+
nb_stars equ 160
1011
raster_dbg equ 0
12+
enable_rotate equ 1
1113

1214
; MACRO(S) DEFINITION(S)
1315
macro supexec ; 1 argument : subroutine address
@@ -98,6 +100,14 @@ raster_dbg equ 0
98100
;subi.w #512,d0
99101
move.w d0,(a1)+ ; X
100102
move.w d1,(a1)+ ; Y
103+
muls.w d0,d0
104+
muls.w d1,d1
105+
add.l d1,d0 ; X^2+Y^2
106+
cmp.l #$40000000,d0
107+
blt.s .ok
108+
subq #4,a1
109+
bra.s .loopr
110+
.ok
101111
bsr rand
102112
andi.w #1023,d0
103113
add.w #1,d0
@@ -150,14 +160,40 @@ mainloop:
150160
endif
151161
move.w #nb_stars-1,d7
152162
.starloop
153-
move.w (a1)+,d0 ; X
154-
move.w (a1)+,d1 ; Y
163+
if enable_rotate
164+
; rotation : (x+iy)(cost+isint) = xcost-ysint + i(ycost+xsint)
165+
; cost = 32751 / 32768 (15bits)
166+
; sint = 1055 / 32768 (15bits)
167+
move.w (a1),d0
168+
move.w d0,d2
169+
move.w 2(a1),d1
170+
move.w d1,d3
171+
muls.w #32751,d0 ; xcost
172+
muls.w #1055,d3 ; ysint
173+
muls.w #1055,d2 ; xsint
174+
muls.w #32751,d1 ; ycost
175+
;sub.l d3,d0 ; xcost-ysint
176+
add.l d3,d0 ; xcost+ysint (-t as angle)
177+
add.l d0,d0
178+
swap d0
179+
move.w d0,(a1)+
180+
;add.l d2,d1 ; ycost+xsint
181+
sub.l d2,d1 ; ycost-xsint (-t as angle)
182+
add.l d1,d1
183+
swap d1
184+
move.w d1,(a1)+
185+
else ; enable_rotate
186+
;move.w (a1)+,d0 ; X
187+
;move.w (a1)+,d1 ; Y
188+
movem.w (a1)+,d0-d1 ; X-Y
189+
endif
190+
155191
move.w (a1),d3 ; Z
156192
ext.l d0
157193
ext.l d1
158194

159-
divs.w d3,d0
160-
divs.w d3,d1
195+
divs.w d3,d0 ; Xproj = X/Z
196+
divs.w d3,d1 ; Yproj = Y/Z
161197

162198
; decrement Z
163199
subq.w #7,d3

0 commit comments

Comments
 (0)