]> 4ch.mooo.com Git - plz.git/blob - _plzpart/copper.c
836fa7e5885a7d35efa455d7d3ca08c184fbb71e
[plz.git] / _plzpart / copper.c
1 /*
2  * Written by Nick Kovac with minor changes by Claudio Matsuoka
3  */
4
5 #include "common.h"
6
7 int frame_count = 0;
8 int cop_drop = 0;
9 uint8_t *cop_pal;
10 int do_pal = 0;
11 int cop_start = 0;
12 int cop_scrl = 0;
13 int cop_plz = 1;
14
15 static int dtau[65];
16
17 uint8_t fadepal[768 * 2];
18 uint8_t *cop_fadepal;
19
20 extern int l1, l2, l3, l4;
21 extern int k1, k2, k3, k4;
22 extern int il1, il2, il3, il4;
23 extern int ik1, ik2, ik3, ik4;
24 extern int ttptr;
25
26
27 void pompota(void);
28 void moveplz(void);
29 void do_drop(void);
30 void initpparas(void);
31
32
33 int init_copper()
34 {
35         int ccc;
36
37         for (ccc = 0; ccc < 65; ccc++) {
38                 dtau[ccc] = ccc * ccc / 4 * 43 / 128 + 60;
39         }
40
41         return 0;
42 }
43
44 int close_copper()
45 {
46         return 0;
47 }
48
49 // [nk] just before retrace
50 void copper1()
51 {
52         // There is also assembly code to set the first pixel of
53         // display memory here, but it may not be necessary.
54
55         vga_set_hscroll_offset(cop_scrl);
56 }
57
58 // [nk] in retrace
59 void copper2()
60 {
61         // [nk] Don't think this is used.
62         frame_count++;
63
64         if (do_pal != 0) {
65                 do_pal = 0;
66                 vga_upload_palette(cop_pal);
67         }
68
69         pompota();
70         moveplz();
71
72         if (cop_drop != 0)
73         {
74                 do_drop();
75         }
76 }
77
78 void pompota()
79 {
80
81         // [NK 18/1/2014] Disable this for now, as it looks a bit jittery.
82         return;
83
84 #if 0
85         // [NK] This function toggles the horizontal split point every frame 
86         // [NK] between line 60 and 61, and toggles the horizontal offset between 0 and 4.
87         // [NK] I think the original intention of this code was to give more variation
88         // [NK] cheaply, almost like a cheap alpha blend between two plasmas, but
89         // [NK] it seems to cause a lot of flicker in the port. Perhaps more precise timing is
90         // [NK] required to give the original effect? In any case I disabled this code
91         // [NK] temporarily.
92
93         vga_set_line_compare(60);
94         cop_scrl = 4;
95
96         pompi++;
97
98         if ((pompi & 1) != 0)
99         {
100                 // [NK 12/1/2014] Moving the starting line up and down each alternate frame
101                 // [NK 12/1/2014] doesn't look good in windowed mode.
102                 // [NK 13/1/2014] Seems to work okay in fullscreen mode though.
103                 vga_set_line_compare(61);
104                 cop_scrl = 0;
105         }
106 #endif
107 }
108
109 void moveplz()
110 {
111         k1 += -3;
112         k1 &= 4095;
113         k2 += -2;
114         k2 &= 4095;
115         k3 += 1;
116         k3 &= 4095;
117         k4 += 2;
118         k4 &= 4095;
119
120         l1 += -1;
121         l1 &= 4095;
122         l2 += -2;
123         l2 &= 4095;
124         l3 += 2;
125         l3 &= 4095;
126         l4 += 3;
127         l4 &= 4095;
128 }
129
130 void do_drop()
131 {
132         cop_drop++;
133
134         if (cop_drop <= 64) {
135                 vga_set_line_compare(dtau[cop_drop]);
136         } else {
137                 //@@over
138
139                 int bShouldFade = 0;
140
141                 if (cop_drop >= 256) {
142                 } else if (cop_drop >= 128) {
143                         bShouldFade = 1;
144                 } else if (cop_drop > 96) {
145                 } else /*if (cop_drop > 64) */{
146                         bShouldFade = 1;
147                 }
148
149                 if (bShouldFade) {
150                         cop_pal = fadepal;
151                         do_pal = 1;
152
153                         if (cop_drop == 65) {
154                                 vga_set_line_compare(400);
155                                 initpparas();
156                         } else {
157                                 int i, ccc;
158
159                                 vga_set_line_compare(60);
160
161                                 // [NK 9/1/2014] Fade the palette using 8.8 fixed point numbers. 
162
163                                 uint8_t* pcop_fadepal = cop_fadepal;
164                                 uint8_t* pfadepal = fadepal;
165
166                                 for (i = 0; i < (768 / 16); i++) {
167                                         for (ccc = 0; ccc < 16; ccc++) {
168                                                 uint8_t al = pcop_fadepal[ccc*2];
169                                                 uint8_t ah = pcop_fadepal[(ccc*2) + 1];
170
171                                                 uint8_t oldval = pfadepal[ccc + 768];
172                                                 pfadepal[ccc + 768] += al;
173                                                 uint8_t newval = pfadepal[ccc + 768];
174                                                 uint8_t carry = 0;
175                                                 if (newval < oldval) {
176                                                         carry = 1;
177                                                 }
178
179                                                 pfadepal[ccc] += ah + carry;
180                                         }
181
182                                         pcop_fadepal += 32;
183                                         pfadepal += 16;
184                                 }
185                         }
186                 } else {
187                         cop_drop = 0;
188                 }
189         }
190 }
191
192 void initpparas()
193 {
194         l1 = il1;
195         l2 = il2;
196         l3 = il3;
197         l4 = il4;
198
199         k1 = ik1;
200         k2 = ik2;
201         k3 = ik3;
202         k4 = ik4;
203 }
204