/[projet1]/users/chema/TINE/stars.s
Defence Force logotype

Contents of /users/chema/TINE/stars.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 354 - (show annotations)
Sun Jun 27 19:32:47 2010 UTC (9 years, 9 months ago) by Chema
File size: 12510 byte(s)
First tweaks after the BETA1 version

Changed the way rear view is patched, so no it is in obj3d.s before calling GLOBROT. Is much more efficient.

Also corrected an error with this, as only Z component was inverted, and not also X component. This also meant changes into stars.s which also had some errors in rear view...

Tweaked the rotation of the initial screen ships, and added the hermit as type of ship (but not yet created in universe.s)
1
2 #include "oobj3d\params.h"
3 #include "tine.h"
4
5
6
7 ;THETSTEP .byt 2
8
9 #define TEMP3 tmp3
10 #define TEMP1 tmp1
11 #define TEMP2 tmp2
12
13
14
15 ;
16 ; INITSTAR -- Initialize starfield, etc.
17 ;
18 ; Stars have locations x=-160..160 and y=-100..100
19 ;
20 INITSTAR
21 .(
22 ldy #NSTARS
23 LOOP
24 jsr NEWSTAR
25 dey
26 bpl LOOP
27
28 lda invert
29 sta move_stars+1
30 beq normal
31 ldx #<STARSUBZ
32 ldy #>STARSUBZ
33 jmp patch
34 normal
35 ldx #<STARADDZ
36 ldy #>STARADDZ
37 patch
38 stx patch_staraddz+1
39 sty patch_staraddz+2
40 rts
41 .)
42
43 NEWSTAR
44 .(
45 ;.Y contains index into star table
46 #ifdef REALRANDOM
47 jsr randgen
48 #else
49 jsr _gen_rnd_number
50 #endif
51 loop1
52 cmp #(CLIP_BOTTOM-CENTER_Y) ;100
53 bcc SETY
54 cmp #(256-(CENTER_Y-CLIP_TOP)) ;156 ;-100
55 bcs SETY
56 ;and #%10111111 ;-65..63
57 cmp #$80
58 ror
59 jmp loop1
60 SETY STA STARY,Y
61
62 #ifdef REALRANDOM
63 lda randseed
64 #else
65 lda _rnd_seed
66 #endif
67 loop2
68 cmp #(CLIP_RIGHT-CENTER_X) ;120
69 bcc SETX
70 cmp #(256-(CENTER_X-CLIP_LEFT)) ;136
71 bcs SETX
72 ;and #%10111111 ;-65..63
73 cmp #$80
74 ror
75 jmp loop2
76 SETX sta STARX,Y
77 rts
78 .)
79
80 /*
81 tabnrs1 .byt (CLIP_BOTTOM-CENTER_Y)-1, (256-(CENTER_Y-CLIP_TOP-1))
82 tabnrs2 .byt (CLIP_RIGHT-CENTER_X)-1, (256-(CENTER_X-CLIP_LEFT)-1)
83
84 NEWREARSTAR
85 .(
86 ;.Y contains index into star table
87 jsr _gen_rnd_number
88 cmp #(CLIP_BOTTOM-CENTER_Y) ;100
89 bcc SETY
90 cmp #(256-(CENTER_Y-CLIP_TOP)) ;156 ;-100
91 bcs SETY
92 ;and #%10111111 ;-65..63
93 and #1
94 tax
95 lda tabnrs1,x
96 SETY STA STARY,Y
97
98 lda _rnd_seed
99 cmp #(CLIP_RIGHT-CENTER_X) ;120
100 bcc SETX
101 cmp #(256-(CENTER_X-CLIP_LEFT)) ;136
102 bcs SETX
103 ;and #%10111111 ;-65..63
104 and #1
105 tax
106 lda tabnrs2,x
107 SETX sta STARX,Y
108 rts
109 .)
110
111 */
112
113 ;
114 ; PLOTSTAR -- Plot stars into bitmap!
115 ;
116 PlotStars
117 .(
118 ldy #NSTARS
119 LOOP sty TEMP
120 lda STARX,y
121 clc
122 adc #CENTER_X
123 tax
124 lda STARY,y
125 clc
126 adc #CENTER_Y
127 tay
128 PLOT
129 ; Now plot the star!
130
131 ; Inline this?
132 #ifdef 0
133 jsr pixel_address
134 #else
135 lda _HiresAddrLow,y ; 4
136 sta tmp0+0 ; 3
137 lda _HiresAddrHigh,y ; 4
138 sta tmp0+1 ; 3 => Total 14 cycles
139 ldy _TableDiv6,x
140 lda _TableBit6Reverse,x ; 4
141 #endif
142 ora (tmp0),y ; 5
143 sta (tmp0),y
144
145 bypass
146 ldy TEMP
147 dey
148 bpl LOOP
149 rts
150 .)
151
152
153
154 ;; Routine to move stars depending on
155 ;; global:
156 ;; g_alpha Total rotation in X (Pitch)
157 ;; g_beta Total rotation in Y (Yaw)
158 ;; g_delta Total rotation in Z (Roll)
159 ;; g_theta Total speed?
160
161 move_stars
162 .(
163 lda #$00 ; SMC invert
164 beq normal1
165 lda g_alpha
166 eor #$80
167 sta g_alpha
168 ;lda g_beta
169 ;eor #$80
170 ;sta g_beta
171 lda g_delta
172 eor #$80
173 sta g_delta
174 normal1
175
176 lda g_alpha
177 beq nowbeta
178 bmi negmove1
179 jsr STARADDY
180 jmp nowbeta
181 negmove1
182 jsr STARSUBY
183
184 nowbeta
185 lda g_beta
186 beq nowdelta
187 bmi negmove2
188 jsr STARSUBX
189 jmp nowdelta
190 negmove2
191 jsr STARADDX
192
193 nowdelta
194 lda g_delta
195 beq nowtheta
196 bmi negmove3
197 ;and #$7f
198 sta tmp
199 loop1
200 jsr STARROTP
201 dec tmp
202 bne loop1
203
204 jmp nowtheta
205 negmove3
206 and #$7f
207 beq nowtheta
208 sta tmp
209 loop2
210 jsr STARROTM
211 dec tmp
212 bne loop2
213
214 nowtheta
215 /*
216 lda invert
217 beq normal
218 jsr STARSUBZ
219 jmp more
220 normal
221 jsr STARADDZ ; This can't be negative...
222 */
223
224 +patch_staraddz
225 jsr STARADDZ
226
227 more
228 lda #0
229 sta g_alpha
230 sta g_beta
231 sta g_delta
232 sta g_theta
233
234 rts
235 .)
236
237
238 ;
239 ; STARROTP -- Rotate stars about z-axis, positive.
240 ;
241 STARROTP
242 .(
243 LDY #NSTARS
244 LOOP LDA STARX,Y
245 BMI NEGX
246 POSX TAX
247 LDA STARYREM,Y ;y*cos(delta)
248 SEC
249 SBC tab_sindeltarem2,X ;-x*sin(delta)
250 STA STARYREM,Y
251 LDA STARY,Y
252 SBC tab_sindelta2,X
253 LDX STARY,Y
254 STA STARY,Y ;y=-x*sd + y*cd
255 BMI NEGY ;LDX sets flag
256
257 POSY LDA STARXREM,Y
258 CLC
259 ADC tab_sindeltarem2,X ;x*cos(theta) + y*sin(theta)
260 STA STARXREM,Y
261 LDA STARX,Y
262 ADC tab_sindelta2,X
263 STA STARX,Y
264 BMI NEGCHK
265
266 POSCHK
267 cmp #(CLIP_RIGHT-CENTER_X)
268 BCS NEW
269 YCHK LDA STARY,Y
270 BMI NEGYCHK
271 CMP #64
272 BCS NEW
273 DEY
274 BPL LOOP
275 RTS
276
277 NEGYCHK CMP #(256-(CENTER_Y-CLIP_TOP))
278 BCS NOTNEW
279 NEW JSR NEWSTAR
280 NOTNEW DEY
281 BPL LOOP
282 RTS
283
284 NEGCHK cmp #(256-(CENTER_X-CLIP_LEFT))
285 BCS YCHK
286 BCC NEW
287
288 NEGX EOR #$FF
289 TAX
290 INX
291 LDA STARYREM,Y ;y*cos(delta)
292 CLC
293 ADC tab_sindeltarem2,X ;-x*sin(delta)
294 STA STARYREM,Y
295 LDA STARY,Y
296 ADC tab_sindelta2,X
297 LDX STARY,Y
298 STA STARY,Y ;y=-x*sd + y*cd
299 BPL POSY ;LDX sets flag
300
301 NEGY TXA
302 EOR #$FF
303 TAX
304 INX
305 LDA STARXREM,Y
306 SEC
307 SBC tab_sindeltarem2,X ;x*cos(theta) + y*sin(theta)
308 STA STARXREM,Y
309 LDA STARX,Y
310 SBC tab_sindelta2,X
311 STA STARX,Y
312 BPL POSCHK
313 BMI NEGCHK
314 .)
315
316 ;
317 ; STARROTM -- Rotate stars, negative.
318 ; (sin -> -sin)
319 ;
320 STARROTM
321 .(
322
323 LDY #NSTARS
324 LOOP LDA STARX,Y
325 BMI NEGX
326 POSX TAX
327 LDA STARYREM,Y ;y*cos(delta)
328 CLC
329 ADC tab_sindeltarem2,X ;+x*sin(delta)
330 STA STARYREM,Y
331 LDA STARY,Y
332 ADC tab_sindelta2,X
333 LDX STARY,Y
334 STA STARY,Y ;y=x*sd + y*cd
335 BMI NEGY ;LDX sets flag
336
337 POSY LDA STARXREM,Y
338 SEC
339 SBC tab_sindeltarem2,X ;x*cos(theta) - y*sin(theta)
340 STA STARXREM,Y
341 LDA STARX,Y
342 SBC tab_sindelta2,X
343 STA STARX,Y
344 BMI NEGCHK
345 POSCHK
346
347 cmp #(256-(CENTER_X-CLIP_LEFT))
348 BCS NEW
349 YCHK LDA STARY,Y
350 BMI NEGYCHK
351 CMP #(CLIP_BOTTOM-CENTER_Y)
352 BCS NEW
353 DEY
354 BPL LOOP
355 RTS
356
357 NEGYCHK CMP #(256-(CENTER_Y-CLIP_TOP))
358 BCS NOTNEW
359 NEW JSR NEWSTAR
360 NOTNEW DEY
361 BPL LOOP
362 RTS
363
364 NEGCHK cmp #(256-(CENTER_X-CLIP_LEFT))
365 BCS YCHK
366 BCC NEW
367
368 NEGX EOR #$FF
369 TAX
370 INX
371 LDA STARYREM,Y ;y*cos(delta)
372 SEC
373 SBC tab_sindeltarem2,X ;+x*sin(delta)
374 STA STARYREM,Y
375 LDA STARY,Y
376 SBC tab_sindelta2,X
377 LDX STARY,Y
378 STA STARY,Y ;y=x*sd + y*cd
379 BPL POSY ;LDX sets flag
380
381 NEGY TXA
382 EOR #$FF
383 TAX
384 INX
385 LDA STARXREM,Y
386 CLC
387 ADC tab_sindeltarem2,X ;x*cos(theta) - y*sin(theta)
388 STA STARXREM,Y
389 LDA STARX,Y
390 ADC tab_sindelta2,X
391 STA STARX,Y
392 BPL POSCHK
393 BMI NEGCHK
394 .)
395
396 ;
397 ; STARADDZ -- Move stars, forwards or backwards. Idea
398 ; is that stars move radially outward from the center
399 ; of the screen, with velocity dependent on the distance
400 ; from the center of the screen.
401 ;
402 STARADDZ
403 .(
404 lda g_theta
405 beq ELRTS
406 lsr
407 lsr
408 lsr
409 tax
410 inx
411 stx tmp
412
413 LDY #NSTARS
414 LOOP
415 ;LDA g_theta; LDX THETSTEP
416 ;BEQ ELRTS
417
418 LDX #0 ; sign
419 LDA STARX,Y
420 bpl C2
421 dex
422 C2
423 STX TEMP2
424 ldx tmp
425 L1
426 ASL
427 ROL TEMP2
428 DEX
429 BNE L1 ;Divide by 128/64/32/16
430 CLC
431 ADC STARXREM,Y
432 STA STARXREM,Y
433 LDA TEMP2
434 ADC STARX,Y ;x = x + 1/16 x
435 STA STARX,Y
436 BMI NEGCHK
437 ;BNE NEW ;valid high = either 00 or $FF
438
439 POSCHK cmp #(CLIP_RIGHT-CENTER_X) ;if x>=max_x then need a new star
440 BCC ADDY
441 NEW JSR NEWSTAR
442 JMP NEXT
443 NEGCHK
444 cmp #(256-(CENTER_X-CLIP_LEFT)) ;and if x<=min_x
445 BCC NEW
446
447 ADDY LDX #00 ;Sign
448 LDA STARY,Y
449 BPL C1
450 DEX
451 C1 STX TEMP1
452 LDX tmp; g_theta
453 L2 ASL
454 ROL TEMP1
455 DEX
456 BNE L2
457 CLC
458 ADC STARYREM,Y
459 STA STARYREM,Y
460 LDA TEMP1
461 ADC STARY,Y
462 BVS NEW
463 STA STARY,Y
464 BMI NEGY
465
466 POSY CMP #(CLIP_BOTTOM-CENTER_Y) ;if abs(y)>max_y then new
467 BCS NEW
468 NEXT DEY
469 BPL LOOP
470 ELRTS RTS
471 NEGY CMP #(256-(CENTER_Y-CLIP_TOP))
472 BCC NEW
473 DEY
474 BPL LOOP
475 RTS
476 .)
477
478
479
480 STARSUBZ
481 .(
482
483 lda g_theta
484 beq OTRORTS
485 lsr
486 lsr
487 lsr
488 tax
489 inx
490 stx tmp
491
492 LDY #NSTARS
493
494 ;Same thing but subtract
495 LDY #NSTARS
496 LOOP
497 LDX #0 ; sign
498 LDA STARX,Y
499 bpl C1
500 dex
501 C1
502 STX TEMP2
503 ldx tmp
504
505 L1
506
507 ASL
508 ROL TEMP2
509 DEX
510 BNE L1
511 STA TEMP
512 LDA STARXREM,Y
513 SEC
514 SBC TEMP
515 STA STARXREM,Y
516 LDA STARX,Y ;x = x - 1/16 x
517 SBC TEMP2
518 STA STARX,Y
519 BMI NEGCHK
520
521 POSCHK cmp #16 ;if abs(x)<16 then need a new star
522 BCS ADDY
523 NEW JSR NEWSTAR
524 JMP NEXT
525 NEGCHK cmp #(256-16)
526 BCS NEW
527
528 ADDY LDX #00 ;Sign
529 LDA STARY,Y
530 BPL C2
531 DEX
532 C2 STX TEMP1
533 LDX tmp ;THETSTEP
534 L2 ASL
535 ROL TEMP1
536 DEX
537 BNE L2
538 STA TEMP
539 LDA STARYREM,Y
540 SEC
541 SBC TEMP
542 STA STARYREM,Y
543 LDA STARY,Y
544 SBC TEMP1
545 BVS NEW
546 STA STARY,Y
547 BMI NEGY
548
549 POSY CMP #16 ;if abs(y)<16 then new
550 BCC NEW
551 NEXT DEY
552 BPL LOOP
553 OTRORTS RTS
554 NEGY CMP #(256-16)
555 BCS NEW
556 DEY
557 BPL LOOP
558 RTS
559 .)
560
561
562
563 ;
564 ; STARADDX, STARSUBX, STARADDY, STARSUBY
565 ; Routines to move stars right/left/up/down to simulate
566 ; rotations around x and y axis.
567 ;
568 ;ADDTAB .byt 0,12,24,36,48,60,72
569 ADDTAB .byt 0,4,8,12,16,20,24,28,32,36,40,44,52,60
570 STARADDX
571 .(
572 lda g_beta
573 ldy #NSTARS
574 and #$7f ; Get absolute value
575 tax
576 LDA ADDTAB,X
577
578 STA _smc_add+1
579 LOOP LDA STARX,Y
580 CLC
581 _smc_add
582 ADC #$00 ; SMC
583 STA STARX,Y
584 BMI NEXT
585
586 POSCHK cmp #(CLIP_RIGHT-CENTER_X) ;if x>=max_x then need a new star
587 BCC NEXT
588 NEW JSR NEWSTAR
589 NEXT DEY
590 BPL LOOP
591 ELRTS RTS
592 .)
593
594 STARSUBX
595 .(
596 lda g_beta
597 ldy #NSTARS
598 and #$7f ; Get absolute value
599 tax
600 LDA ADDTAB,X
601
602 STA _smc_sub+1
603 LOOP LDA STARX,Y
604 SEC
605 _smc_sub
606 SBC #$00 ; SMC
607 STA STARX,Y
608 BPL NEXT
609
610
611 POSCHK cmp #(256-(CENTER_X-CLIP_LEFT+1)) ;if x<min_x then need a new star
612 BCS NEXT
613 NEW JSR NEWSTAR
614 NEXT DEY
615 BPL LOOP
616 ELRTS RTS
617 .)
618
619
620 STARADDY
621 .(
622 lda g_alpha
623 ldy #NSTARS
624 and #$7f ; Get absolute value
625 tax
626 LDA ADDTAB,X
627
628 STA _smc_add+1
629 LOOP LDA STARY,Y
630 CLC
631 _smc_add
632 ADC #$00 ;SMC
633 BVS NEW ;might happen for large temp
634 STA STARY,Y
635 BMI NEXT
636 CMP #(CLIP_BOTTOM-CENTER_Y)
637 BCC NEXT
638 NEW JSR NEWSTAR
639 NEXT DEY
640 BPL LOOP
641 ELRTS RTS
642 .)
643
644 STARSUBY
645 .(
646 lda g_alpha
647 ldy #NSTARS
648 and #$7f ; Get absolute value
649 tax
650 LDA ADDTAB,X
651
652 STA _smc_sub+1
653 LOOP LDA STARY,Y
654 SEC
655 _smc_sub
656 SBC #$00 ; SMC
657 BVS NEW
658 STA STARY,Y
659 BPL NEXT
660 CMP #(256-(CENTER_Y-CLIP_TOP))
661 BCS NEXT
662 NEW JSR NEWSTAR
663 NEXT DEY
664 BPL LOOP
665 ELRTS RTS
666 .)
667
668

  ViewVC Help
Powered by ViewVC 1.1.26