]> 4ch.mooo.com Git - 16.git/blob - src/vrstest.c
wwwwwwwwwwwwwwwwwwwwwwwwwwww vrstest.c works wwwwww yakui-lover wwwww look! wwww
[16.git] / src / vrstest.c
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
3  *
4  * This file is part of Project 16.
5  *
6  * Project 16 is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Project 16 is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,
19  * Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22
23 #include <stdio.h>
24 #include <dos.h>
25 #include <string.h>
26 #include "src/lib/modex16.h"
27 #include "src/lib/16_sprite.h"
28 #include "src/lib/16_ca.h"
29 #include "src/lib/16_mm.h"
30
31 global_game_variables_t gvar;
32
33 void main() {
34         mminfo_t mm; mminfotype mmi;
35         __segment sega;
36         void __based(sega)* bigbuffer;
37         int i;
38         word start;
39         int plane;
40         float t1, t2;
41         boolean baka;
42         byte *pal;
43         int fd, size, size1;
44         struct sprite spri;
45         vrl1_vgax_offset_t * off, *off1;
46         struct vrs_container vrs;
47         vrl1_vgax_offset_t **vrl_line_offsets;
48         uint32_t huge *vrl_headers_offsets;
49         uint16_t huge *vrl_id_iter;
50         uint32_t vrl_size;
51         int num_of_vrl;
52         struct vrl1_vgax_header huge *curr_vrl;
53         struct vrl_container *vrl;
54         int success;
55
56
57
58         // DOSLIB: check our environment
59         probe_dos();
60
61         // DOSLIB: what CPU are we using?
62         // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.
63         //      So this code by itself shouldn't care too much what CPU it's running on. Except that other
64         //      parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for
65         //      the CPU to carry out tasks. --J.C.
66         cpu_probe();
67
68         // DOSLIB: check for VGA
69         if (!probe_vga()) {
70                 printf("VGA probe failed\n");
71                 return;
72         }
73         // hardware must be VGA or higher!
74         if (!(vga_state.vga_flags & VGA_IS_VGA)) {
75                 printf("This program requires VGA or higher graphics hardware\n");
76                 return;
77         }
78
79         //bmp = bitmapLoadPcx("data/chikyuu.pcx");
80         gvar.video.page[0]=modexDefaultPage(&gvar.video.page[0]);
81
82         mm.mmstarted=0;
83         MM_Startup(&mm, &mmi);
84         CA_Startup(&gvar);
85         if(CA_LoadFile("data/spri/chikyuu.vrs", &bigbuffer, &mm, &mmi)) baka=1; else baka=0;
86         fd = open("data/spri/chikyuu.vrs", O_RDONLY|O_BINARY);
87         size = lseek(fd, 0, SEEK_END);
88         lseek(fd, 0, SEEK_SET);
89         close(fd);
90         // Insert sanity cheks later
91         vrs.buffer = bigbuffer;
92         vrs.data_size = size - sizeof(struct vrl1_vgax_header);
93         num_of_vrl = 0;
94         vrl_id_iter = (uint16_t huge *)(vrs.buffer + vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST]);
95         while(vrl_id_iter[num_of_vrl]){
96                 num_of_vrl++;
97         }
98
99         // Allocate memory for vrl line offsets table
100         vrl_line_offsets = malloc(sizeof(vrl1_vgax_offset_t *)*num_of_vrl);
101
102         vrl_headers_offsets = (uint32_t huge *)(vrs.buffer + vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_VRS_LIST]);
103         // Calculate line offsets for each vrl
104         for(i = 0; i < num_of_vrl; i++){
105                 curr_vrl = (struct vrl1_vgax_header huge *)(vrs.buffer + vrl_headers_offsets[i]);
106
107                 // Calc. vrl size as (next_offset - curr_offset)
108                 if (i != num_of_vrl - 1){
109                         vrl_size = vrl_headers_offsets[i+1] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header);
110                 }
111                 // If it's the last vrl, size is (next_vrs_struct_offset - curr_offset)
112                 else{
113                         vrl_size = vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header);
114                 }
115                 vrl_line_offsets[i] = vrl1_vgax_genlineoffsets(curr_vrl, (byte *)curr_vrl + sizeof(struct vrl1_vgax_header), vrl_size);
116         }
117         vrs.vrl_line_offsets = vrl_line_offsets;
118
119         //read_vrs(&gvar, "data/spri/chikyuu.vrs", &vrs);
120         spri.spritesheet = &vrs;
121         spri.sprite_vrl_cont = malloc(sizeof(struct vrl_container));
122
123         vrl = malloc(sizeof(struct vrl_container));
124         i = get_vrl_by_id(&vrs, 10, vrl);
125         if(i == -2)
126         {
127                 puts("Die");
128                 return;
129         }
130         off = vrl1_vgax_genlineoffsets(curr_vrl/*vrl->buffer*/, vrl->buffer + sizeof(struct vrl1_vgax_header), vrl->data_size);
131         fd = open("data/spri/chikyuu.vrl", O_RDONLY|O_BINARY);
132         size = lseek(fd, 0, SEEK_END);
133         lseek(fd, 0, SEEK_SET);
134         close(fd);
135
136         if(CA_LoadFile("data/spri/chikyuu.vrl", &bigbuffer, &mm, &mmi)) baka=1; else baka=0;
137         off1 = vrl1_vgax_genlineoffsets(bigbuffer, (byte *)bigbuffer + sizeof(struct vrl1_vgax_header), size - sizeof(struct vrl1_vgax_header));
138
139
140         //read_vrs(&gvar, "data/spri/chikyuu.vrs", spri.spritesheet);
141         i = set_anim_by_id(&spri, 10);
142         if (i == -1)
143         {
144                 return;
145         }
146         spri.x = spri.y = 70;
147
148
149         /* fix up the palette and everything */
150         //modexPalUpdate1(bmp.palette);
151         //modexLoadPalFile("data/spri/chikyuu.pal", &pal);
152         //modexPalUpdate1(pal);
153
154         /* clear and draw one sprite and one bitmap */
155         VGAmodeX(1, 1, &gvar);
156         modexClearRegion(&gvar.video.page[0], 0, 0, gvar.video.page[0].sw, gvar.video.page[0].sh, 1);
157
158         /* non sprite comparison */
159         start = *clockw;
160         //for(i=0; i<100 ;i++) {
161         //      oldDrawBmp(VGA, 20, 20, &bmp, 0);
162         //}
163
164         start = *clockw;
165         //for(i=0; i<100 ;i++) {
166 //0000          modexDrawBmp(&gvar.video.page[0], 20, 20, &bmp);
167         //      modexDrawBmp(&gvar.video.page[0], 160, 120, &bmp);
168         //}
169         t1 = (*clockw-start) /18.2;
170
171         start = *clockw;
172         //for(i=0; i<100; i++) {
173 //0000          modexCopyPageRegion(&gvar.video.page[0], &gvar.video.page[0], 20, 20, 128, 20, 64, 64);
174                 modexCopyPageRegion(&gvar.video.page[0], &gvar.video.page[0], 0, 0, 0, 0, 320, 240);
175                 animate_spri(&spri);
176         draw_vrl1_vgax_modex(5,5,curr_vrl/*vrl->buffer*/,vrl->line_offsets,vrl->buffer + sizeof(struct vrl1_vgax_header),vrl->data_size);
177         draw_vrl1_vgax_modex(40,40,curr_vrl/*vrs.buffer*/ + vrl_headers_offsets[0],vrs.vrl_line_offsets[0],vrs.buffer + vrl_headers_offsets[0] + sizeof(struct vrl1_vgax_header),vrl_headers_offsets[1] - vrl_headers_offsets[0] - sizeof(struct vrl1_vgax_header));
178         draw_vrl1_vgax_modex(100, 5, bigbuffer, off1, (byte *)bigbuffer + sizeof(struct vrl1_vgax_header), size - sizeof(struct vrl1_vgax_header));
179
180         //}
181         t2 = (*clockw-start)/18.2;
182
183         //for (i = 0; i < 5; i++){
184         //animate_spri(&spri);
185
186         start = *clockw;
187         //for(i=0; i<100 ;i++) {
188         //      oldDrawBmp(VGA, 20, 20, &bmp, 1);
189         //}
190
191
192         start = *clockw;
193         //for(i=0; i<100 ;i++) {
194 //0000          modexDrawSprite(&gvar.video.page[0], 20, 20, &bmp);
195         //      modexDrawSprite(&gvar.video.page[0], 160, 120, &bmp);
196         //}
197         //_fmemset(MK_FP(0xA000, 0), (int)p->plane, gvar.video.page[0].sw*(gvar.video.page[0].sh*2));
198         //modexDrawBmp(&gvar.video.page[0], 0, 0, &bmp);
199         while(!kbhit())
200         {
201                 //DrawPBuf(&gvar.video.page[0], 0, 0, p, 0);
202         }
203         VGAmodeX(0, 1, &gvar);
204         free(spri.sprite_vrl_cont);
205         MM_FreePtr(&bigbuffer, &mm);
206         //MM_FreePtr(&((void __based(sega)*)spri.spritesheet->buffer), &mm);
207         MM_Shutdown(&mm);
208         CA_Shutdown(&gvar);
209         /*printf("\nmain=%Fp\n\n", &i);
210         printf("bmp.data=%Fp\n", bmp.data);
211         printf("*bmp.data=%Fp\n", *(bmp.data));
212         printf("&bmp.data=%Fp\n", &(bmp.data));
213
214         printf("\n%d\n", sizeof(p->plane));
215         printf("%d\n", sizeof(bmp));*/
216
217         /*for(i=0; i<(320*240); i++)
218         {
219                 fprintf(stdout, "%d", bmp.data[i]);
220                 if(i%bmp.width==0) fprintf(stdout, "\n");
221         }*/
222         printf("CPU to VGA: %f\n", t1);
223         printf("VGA to VGA: %f\n", t2);
224         printf("gvar.video.page[0].width: %u\n", gvar.video.page[0].width);
225         printf("gvar.video.page[0].height: %u\n", gvar.video.page[0].height);
226         printf("Num %d", num_of_vrl);
227         if(baka) printf("\nyay!\n");
228         else printf("\npoo!\n");
229 }