/[projet1]/public/oric/games/Space 1999/Sources/trailer/tables.s
Defence Force logotype

Contents of /public/oric/games/Space 1999/Sources/trailer/tables.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 365 - (show annotations)
Mon Jul 19 10:58:27 2010 UTC (9 years, 3 months ago) by dbug
File size: 14016 byte(s)
Added the Space:1999 Trailer to the repository.

1 // ============================================================================
2 //
3 // Tables.s
4 //
5 // ============================================================================
6 //
7 // This file contains all the bss tables used through the demo.
8 //
9 // ============================================================================
10
11 .zero
12
13 ptr_dst
14 ptr_dst_low .dsb 1
15 ptr_dst_high .dsb 1
16
17 squared_value .dsb 2
18 nOddValue .dsb 1
19 yy .dsb 1
20
21 y .dsb 1
22 x .dsb 1
23 nSquareRoot .dsb 1
24
25 x0 .dsb 1
26 x1 .dsb 1
27 x2 .dsb 1
28 x3 .dsb 1
29
30 .text
31
32 _TablesInit
33 //jmp _TablesInit
34 .(
35 ;sei
36
37 //
38 // Clear the BSS section
39 //
40 .(
41 lda #0
42
43 ldx #<_BssStart_
44 stx ptr_dst_low
45 ldx #>_BssStart_
46 stx ptr_dst_high
47
48 ldx #((_BssEnd_-_BssStart_)+1)/256
49 loop_outer
50 tay
51 loop_inner
52 sta (ptr_dst),y
53 dey
54 bne loop_inner
55 inc ptr_dst_high
56 dex
57 bne loop_outer
58 .)
59
60
61 //
62 // Generate multiple of 6 data table
63 //
64 .(
65 lda #0
66 sta tmp0+0 // cur mul
67 sta tmp0+1 // cur div
68 sta tmp0+2 // cur mod
69
70 ldx #0
71 loop
72 lda tmp0+0
73 clc
74 sta _TableMul6,x
75 adc #6
76 sta tmp0+0
77
78 lda tmp0+1
79 sta _TableDiv6,x
80
81 lda tmp0+2
82 sta _TableMod6,x
83
84 ldy tmp0+2
85 iny
86 cpy #6
87 bne skip_mod
88 ldy #0
89 inc tmp0+1
90 skip_mod
91 sty tmp0+2
92
93 inx
94 bne loop
95 .)
96
97
98 .(
99 lda #0
100 sta tmp0
101
102 ldx #0
103 loop_div
104 ;
105 ; Store Div6
106 ;
107 lda _DIV6
108 ldy tmp0
109
110 ;
111 ; Store Mod6
112 ;
113 ldy _MOD6
114 lda _LeftPattern,y
115 ldy tmp0
116 ora #64
117 sta _Mod6Left,y
118
119 ldy _MOD6
120 lda _RightPattern,y
121 ldy tmp0
122 ora #64
123 sta _Mod6Right,y
124
125
126 ;
127 ; Update Div/Mod
128 ;
129 inc _MOD6
130 lda _MOD6
131 cmp #6
132 bne no_update
133 lda #0
134 sta _MOD6
135 inc _DIV6
136 no_update
137
138 ;
139 ; Inc Y
140 ;
141 inc tmp0
142 ldy tmp0
143 bne loop_div
144 .)
145
146 jsr _Tables_InitialiseScreenAddrTable
147 jsr _PrepareCosTable
148
149 rts
150 .)
151
152
153
154 //
155 // Generate screen pointer adresses
156 //
157 _Tables_InitialiseScreenAddrTable
158 .(
159 lda #<$a000
160 sta tmp0+0
161 lda #>$a000
162 sta tmp0+1
163
164 ldx #0
165 loop
166 lda tmp0+0
167 sta _HiresAddrLow,x
168 lda tmp0+1
169 sta _HiresAddrHigh,x
170
171 clc
172 lda tmp0+0
173 adc #40
174 sta tmp0+0
175 bcc skip
176 inc tmp0+1
177 skip
178
179 inx
180 cpx #200
181 bne loop
182 rts
183 .)
184
185
186 /*
187
188 Distance=SQR(DX^2 + DY^2)
189
190 90*90=
191
192 Let's say we have a 2x2 resolution, maximum values for a 240x200 screens become
193 120x100 from the center, which divided by two means a max squared distance of 60*60+50*50=3600+2500=6100 entries
194 SQR(6100)=78
195
196 http://en.wikipedia.org/wiki/Square_number
197 // The nth square number can be calculated from the previous two by adding the (n - 1)th square to itself,
198 // subtracting the (n - 2)th square number, and adding 2 (n2 = 2(n - 1)2 - (n - 2)2 + 2).
199 // For example, 2×52 - 42 + 2 = 2×25 - 16 + 2 = 50 - 16 + 2 = 36 = 62.
200
201 // So for example, 52 = 25 = 1 + 3 + 5 + 7 + 9.
202
203
204 If the explosion is in the top half of the screen, that's 40x89 bytes = 3560 bytes.
205 But considering we compute only one line on two, it's only 40x44 bytes= 1760 bytes
206 But considering we compute only one half on two, it's only 20x50 bytes= 1000 bytes
207
208 6100+1760=7860 bytes, which fits perfectly in the 8000 bytes depacking buffer :D
209
210 If for fast lookup we add the square table, we also have to store 60*2 additional values (to store from 0*0 to 60*60=3600)
211
212
213 void GenerateSquareTables()
214 {
215 unsigned char nOddValue=1;
216 unsigned char nTemp;
217 unsigned int squared_value=0;
218 unsigned char n=1;
219 unsigned char* ptr_root_table;
220
221 SquareRootTable[0]=0;
222
223 SquareTableLow[0] =0;
224 SquareTableHigh[0]=0;
225
226 ptr_root_table=SquareRootTable+1;
227
228 do
229 {
230 squared_value+=nOddValue;
231 nOddValue+=2;
232
233 if (n<60)
234 {
235 SquareTableLow[n] =squared_value&255;
236 SquareTableHigh[n]=(squared_value>>8);
237 }
238
239 nTemp=nOddValue;
240 while (nTemp)
241 {
242 *ptr_root_table++=n;
243 nTemp--;
244 }
245
246 n++;
247 }
248 while (n!=77); // 77*77
249 }
250
251 extern unsigned char SquareRootTable[6100];
252 extern unsigned int SquareTable[60];
253
254 _SquareRootTable = _BufferUnpack // 6100 bytes long
255 _SquareTable = _SquareRootTable+6100 // 60*2=120 bytes long
256 */
257
258
259 _GenerateSquareTables
260 ;jmp _GenerateSquareTables
261 .(
262 ; Initialise the first entries
263 lda #0
264 sta _SquareRootTable
265 sta _SquareTableLow
266 sta _SquareTableHigh
267 sta squared_value+0
268 sta squared_value+1
269
270 lda #<_SquareRootTable+1
271 sta __patch_root_table+1
272 lda #>_SquareRootTable+1
273 sta __patch_root_table+2
274
275 ldx #1 ; n=1
276 stx nOddValue
277
278 loop_start
279 ; squared_value+=nOddValue;
280 .(
281 clc
282 lda squared_value+0
283 adc nOddValue+0
284 sta squared_value+0
285 bcc skip
286 inc squared_value+1
287 skip
288 .)
289
290 ; if (n<60)
291 ; {
292 ; SquareTableLow[n] =squared_value&255;
293 ; SquareTableHigh[n]=(squared_value>>8);
294 ; }
295 .(
296 cpx #60
297 bcs skip
298
299 lda squared_value+0
300 sta _SquareTableLow,x
301
302 lda squared_value+1
303 sta _SquareTableHigh,x
304 skip
305 .)
306
307 ; nTemp=nOddValue;
308 ; while (nTemp)
309 ; {
310 ; *ptr_root_table++=n;
311 ; nTemp--;
312 ; }
313 ldy nOddValue
314 inner_loop
315 __patch_root_table
316 stx $1234
317 .(
318 inc __patch_root_table+1
319 bne skip
320 inc __patch_root_table+2
321 skip
322 .)
323 dey
324 bne inner_loop
325
326 ; nOddValue+=2;
327 inc nOddValue
328 inc nOddValue
329
330 inx ; n++;
331
332 loop_test
333 cpx #82 ; while (n!=77); // 77*77
334 bne loop_start
335
336 rts
337 .)
338
339
340 /*
341 void CreateHalfDisc()
342 {
343 unsigned char x,y;
344 unsigned char* ptr_part_buffer;
345 unsigned char* ptr_screen;
346 unsigned int nSquareDistance;
347 unsigned char nSquareRoot;
348 unsigned char xx,yy;
349
350 ptr_part_buffer=DiscPartTable;
351 yy=58;
352 for (y=0;y<60;y++)
353 {
354 xx=0;
355 for (x=0;x<20;x++)
356 {
357 nSquareDistance =((unsigned int)SquareTableHigh[xx]<<8)|SquareTableLow[xx];
358 nSquareDistance+=((unsigned int)SquareTableHigh[yy]<<8)|SquareTableLow[yy];
359 nSquareRoot=SquareRootTable[nSquareDistance];
360 ptr_part_buffer[x]=nSquareRoot;
361 xx+=3;
362 }
363 yy--;
364
365 ptr_part_buffer+=20;
366 }
367 }
368 */
369
370 // Part one, generate the right part
371 _CreateHalfDisc
372 .(
373 lda #<_DiscPartTable
374 sta tmp0+0
375
376 lda #>_DiscPartTable
377 sta tmp0+1
378
379 ldy #58
380 loop_y
381 sty yy
382
383 ; nSquareDistance+=((unsigned int)SquareTableHigh[yy]<<8)|SquareTableLow[yy];
384
385 clc
386 lda #<_SquareRootTable
387 adc _SquareTableLow,y
388 sta tmp1+0
389 lda #>_SquareRootTable
390 adc _SquareTableHigh,y
391 sta tmp1+1
392
393 ldy #0
394 ldx #0
395 loop_x
396 ; nSquareDistance+=((unsigned int)SquareTableHigh[xx]<<8)|SquareTableLow[xx];
397 ; ptr_part_buffer[x]=SquareRootTable[nSquareDistance];
398 clc
399 lda _SquareTableLow,x
400 adc tmp1+0
401 sta __patch+1
402 lda _SquareTableHigh,x
403 adc tmp1+1
404 sta __patch+2
405
406 __patch
407 lda $1234
408
409 sta (tmp0),y
410
411 inx
412 inx
413 ;inx // 3x inx gives a circle, 2x inx gives a flatish elipsoid
414
415 iny
416 cpy #20
417 bne loop_x
418
419 ; ptr_part_buffer+=20;
420 clc
421 lda tmp0+0
422 adc #20
423 sta tmp0+0
424 bcc skip
425 inc tmp0+1
426 skip
427
428 ldy yy
429 dey
430 bne loop_y
431
432 rts
433 .)
434
435
436
437 /*
438 void MirrorTheDisc()
439 {
440 unsigned char* ptr_part_buffer;
441 unsigned char* ptr_full_buffer;
442 unsigned char x,y;
443 unsigned char nSquareRoot;
444
445 ptr_part_buffer=DiscPartTable;
446 ptr_full_buffer=DiscFullTable;
447 for (y=0;y<60;y++)
448 {
449 for (x=0;x<20;x++)
450 {
451 nSquareRoot=*ptr_part_buffer++;
452 nSquareRoot>>=1;
453
454 ptr_full_buffer[20+x]=nSquareRoot;
455 ptr_full_buffer[20-x]=nSquareRoot;
456
457 ptr_full_buffer[20+x+40]=nSquareRoot+1;
458 ptr_full_buffer[20-x+40]=nSquareRoot+1;
459 }
460 ptr_full_buffer+=80;
461 }
462 }
463 */
464
465
466 // Part two, generate the complete palette
467 // This part erase the content of SquareTable and SquareRootTable
468 _MirrorTheDisc
469 .(
470 ; ptr_part_buffer=DiscPartTable;
471 ; ptr_full_buffer=DiscFullTable;
472 lda #<_DiscPartTable
473 sta tmp0+0
474 lda #>_DiscPartTable
475 sta tmp0+1
476
477 lda #<_DiscFullTable
478 sta tmp1+0
479 lda #>_DiscFullTable
480 sta tmp1+1
481
482 lda #60
483 sta y
484 loop_y
485
486 lda #20
487 sta x0
488 sta x1
489 lda #20+40
490 sta x2
491 sta x3
492
493 ldy #0
494 loop_x
495 ; nSquareRoot=*ptr_part_buffer++;
496 ; nSquareRoot>>=1;
497 sty x
498 lda (tmp0),y
499 lsr
500 sta nSquareRoot
501
502 ; ptr_full_buffer[20+x]=nSquareRoot;
503 ; ptr_full_buffer[20-x]=nSquareRoot;
504 ldy x0
505 dec x0
506 sta (tmp1),y
507 ldy x1
508 inc x1
509 sta (tmp1),y
510
511 inc nSquareRoot
512 lda nSquareRoot
513
514 ; ptr_full_buffer[20+x+40]=nSquareRoot+1;
515 ; ptr_full_buffer[20-x+40]=nSquareRoot+1;
516 ldy x2
517 dec x2
518 sta (tmp1),y
519 ldy x3
520 inc x3
521 sta (tmp1),y
522
523 ldy x
524 iny
525 cpy #20
526 bne loop_x
527
528 ; ptr_part_buffer+=40;
529 .(
530 clc
531 lda tmp0+0
532 adc #20
533 sta tmp0+0
534 bcc skip
535 inc tmp0+1
536 skip
537 .)
538
539 ; ptr_full_buffer+=80;
540 .(
541 clc
542 lda tmp1+0
543 adc #80
544 sta tmp1+0
545 bcc skip
546 inc tmp1+1
547 skip
548 .)
549
550 dec y
551 bne loop_y
552 rts
553 .)
554
555
556 /*
557 unsigned char x,y;
558 unsigned char* ptr_full_buffer;
559 unsigned char* ptr_screen;
560 unsigned char xx,yy;
561
562 // Pass 1, generate the green area
563 ptr_full_buffer=DiscFullTable+40;
564 ptr_screen=(unsigned char*)0xa000+40;
565 for (y=1;y<120;y++)
566 {
567 ptr_full_buffer[0]=0;
568 for (x=1;x<40;x++)
569 {
570 if (ptr_full_buffer[x-40]>=254)
571 {
572 // If some graphics detected higher in the column, force as graphics
573 ptr_full_buffer[x]=255;
574 }
575 else
576 {
577 if (ptr_screen[x]!=64)
578 {
579 // There is graphics here
580 ptr_full_buffer[x]=255;
581 }
582 else
583 if (ptr_screen[x+40]!=64)
584 {
585 // Graphics lower
586 ptr_full_buffer[x]=254;
587 }
588 }
589 }
590 ptr_full_buffer+=40;
591 ptr_screen+=40;
592 }
593 */
594
595 // Pass 1, generate the green area
596 _FilterTheDisc1
597 .(
598 ;ptr_screen=(unsigned char*)0xa000+40;
599 ;ptr_full_buffer=DiscFullTable+40;
600 lda #<$a000
601 sta tmp0+0
602 lda #>$a000
603 sta tmp0+1
604
605 lda #<_DiscFullTable
606 sta tmp1+0
607 lda #>_DiscFullTable
608 sta tmp1+1
609
610 lda #119
611 sta y
612 loop_y
613 ; ptr_full_buffer[0]=0;
614 ldy #0
615 sta (tmp1),y
616
617 lda #0+39
618 sta x0
619
620 lda #40+39
621 sta x1
622
623 lda #80+39
624 sta x2
625 loop_x
626
627 ldy x0
628 lda (tmp1),y
629
630 cmp #254
631 bcc test_for_graphics
632
633 ; if (ptr_full_buffer[x]>=254)
634 ; {
635 ; // If some graphics detected higher in the column, force as graphics
636 ; ptr_full_buffer[x+40]=255;
637 ; }
638 propagate_masking
639 lda #255
640 bne do_change
641
642 ; else
643 ; {
644 ; if (ptr_screen[x+40]!=64)
645 ; {
646 ; // There is graphics here
647 ; ptr_full_buffer[x+40]=255;
648 ; }
649 ; else
650 ; if (ptr_screen[x+80]!=64)
651 ; {
652 ; // Graphics lower
653 ; ptr_full_buffer[x+40]=254;
654 ; }
655 ; }
656 test_for_graphics
657 ldy x1
658 lda (tmp0),y
659 cmp #64
660 bne graphics_here
661
662 ldy x2
663 lda (tmp0),y
664 cmp #64
665 beq end_test
666
667 graphics_lower
668 lda #254
669 bne do_change
670
671 graphics_here
672 lda #255
673 bne do_change
674
675 do_change
676 ; ptr_full_buffer[x+40]=???;
677 ldy x1
678 sta (tmp1),y
679
680 end_test
681
682 dec x1
683 dec x2
684 dec x0
685 bne loop_x
686
687 ; ptr_screen+=40;
688 .(
689 clc
690 lda tmp0+0
691 adc #40
692 sta tmp0+0
693 bcc skip
694 inc tmp0+1
695 skip
696 .)
697
698 ; ptr_full_buffer+=40;
699 .(
700 clc
701 lda tmp1+0
702 adc #40
703 sta tmp1+0
704 bcc skip
705 inc tmp1+1
706 skip
707 .)
708
709 dec y
710 bne loop_y
711
712 rts
713 .)
714
715
716 /*
717 void PrepareCosTable()
718 {
719 unsigned int value;
720 unsigned char angle;
721
722 angle=0;
723 do
724 {
725 value=CosTable[angle];
726 value=(value*6)/256;
727 CosTable[angle]=(unsigned char)value;
728 angle++;
729 }
730 while (angle);
731 }
732 */
733
734 _PrepareCosTable
735 ;jmp _PrepareCosTable
736 .(
737 ldx #0
738 loop
739 clc
740 lda _CosTable,x
741 adc _CosTable,x
742 sta reg0+0 ; x2
743 lda #0
744 adc #0 ; Just to get the carry
745 sta reg0+1
746
747 clc
748 lda reg0+0
749 adc reg0+0
750 sta reg1+0 ; x4
751 lda reg0+1
752 adc reg0+1
753 sta reg1+1 ; x4
754
755 clc
756 lda reg0+0
757 adc reg1+0
758 sta reg1+0 ; x6
759 lda reg0+1
760 adc reg1+1
761 sta reg1+1 ; x6
762
763 lda reg1+1
764 sta _CosTable,x
765 inx
766 bne loop
767 rts
768 .)
769
770
771
772 /*
773 // pass two, other stuff
774 ptr_full_buffer=DiscFullTable+40;
775 for (y=1;y<120;y++)
776 {
777 for (x=1;x<39;x++)
778 {
779 if (ptr_full_buffer[x]<254)
780 {
781 // Empty area, we scan around
782 if (ptr_full_buffer[x-1]==255)
783 {
784 ptr_full_buffer[x]=254;
785 }
786 else
787 if (ptr_full_buffer[x+1]==255)
788 {
789 ptr_full_buffer[x]=254;
790 }
791 }
792 }
793 ptr_full_buffer+=40;
794 ptr_screen+=40;
795 }
796 */
797
798 _FilterTheDisc2
799 .(
800 ;ptr_full_buffer=DiscFullTable+40;
801 lda #<_DiscFullTable
802 sta tmp0+0
803 lda #>_DiscFullTable
804 sta tmp0+1
805
806 lda #120
807 sta y
808 loop_y
809 ; ptr_full_buffer[0]=0;
810 ldy #0
811 sta (tmp1),y
812
813 lda #37
814 sta x0
815
816 lda #38
817 sta x1
818
819 lda #39
820 sta x2
821
822 loop_x
823 ; if (ptr_full_buffer[x]<254)
824 ; {
825 ; }
826 ldy x1
827 lda (tmp0),y
828 cmp #254
829 bcs end_test
830
831 ; // Empty area, we scan around
832 ; if (ptr_full_buffer[x-1]==255)
833 ; {
834 ; ptr_full_buffer[x]=254;
835 ; }
836 ; else
837 ; if (ptr_full_buffer[x+1]==255)
838 ; {
839 ; ptr_full_buffer[x]=254;
840 ; }
841 ldy x0
842 lda (tmp0),y
843 cmp #255
844 beq fill
845
846 ldy x2
847 lda (tmp0),y
848 cmp #255
849 bne end_test
850
851 fill
852 lda #254
853 ldy x1
854 sta (tmp0),y
855
856 end_test
857
858 dec x1
859 dec x2
860 dec x0
861 bne loop_x
862
863 ; ptr_full_buffer+=40;
864 .(
865 clc
866 lda tmp0+0
867 adc #40
868 sta tmp0+0
869 bcc skip
870 inc tmp0+1
871 skip
872 .)
873
874 dec y
875 bne loop_y
876
877
878 rts
879 .)
880
881
882
883 .bss
884
885 *=$C000
886
887 // .dsb 256-(*&255)
888
889 _BssStart_
890
891 // Used by:
892 // - Polyfiller
893 // - Lines
894 // - Mandelbrot
895 _TableMul6 .dsb 256
896 _TableDiv6 .dsb 256
897 _TableMod6 .dsb 256
898
899 // Used by:
900 // - Polyfiller
901 _Mod6Left .dsb 256
902 _Mod6Right .dsb 256
903 _MinX .dsb 256
904 _MaxX .dsb 256
905
906 _BufferAddrLow
907 _HiresAddrLow .dsb 176
908 _TextAddrLow .dsb 80
909 _BufferAddrHigh
910 _HiresAddrHigh .dsb 176
911 _TextAddrHigh .dsb 80
912
913 _BufferUnpack .dsb 8000
914
915 _LabelPicture1 = _BufferUnpack+2010*1
916 _LabelPicture2 = _BufferUnpack+2010*2
917 _LabelPicture3 = _BufferUnpack+2010*3
918 _LabelPicture4 = _BufferUnpack+2010*4
919 _LabelPicture5 = _BufferUnpack+2010*5
920
921 _SquareRootTable = _BufferUnpack // 6680 bytes long
922 _SquareTableLow = _SquareRootTable+6680 // 60 bytes long
923 _SquareTableHigh = _SquareTableLow+60 // 60 bytes long
924 _DiscPartTable = _SquareTableHigh+60 // 20*60=1200 bytes long
925
926 _DiscFullTable = _BufferUnpack // 40*100=4000
927
928 _BssEnd_
929
930 .text
931
932
933

  ViewVC Help
Powered by ViewVC 1.1.26