]> 4ch.mooo.com Git - 16.git/blob - src/vrstest.c
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_sprit.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         word w=0;
56
57
58
59         // DOSLIB: check our environment
60         probe_dos();
61
62         // DOSLIB: what CPU are we using?
63         // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.
64         //      So this code by itself shouldn't care too much what CPU it's running on. Except that other
65         //      parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for
66         //      the CPU to carry out tasks. --J.C.
67         cpu_probe();
68
69         // DOSLIB: check for VGA
70         if (!probe_vga()) {
71                 printf("VGA probe failed\n");
72                 return;
73         }
74         // hardware must be VGA or higher!
75         if (!(vga_state.vga_flags & VGA_IS_VGA)) {
76                 printf("This program requires VGA or higher graphics hardware\n");
77                 return;
78         }
79
80         //bmp = bitmapLoadPcx("data/chikyuu.pcx");
81         gvar.video.page[0]=modexDefaultPage(&gvar.video.page[0]);
82
83         mm.mmstarted=0;
84         MM_Startup(&mm, &mmi);
85         CA_Startup(&gvar);
86         if(CA_LoadFile("data/spri/chikyuu.vrs", &bigbuffer, &mm, &mmi)) baka=1; else baka=0;
87         fd = open("data/spri/chikyuu.vrs", O_RDONLY|O_BINARY);
88         size = lseek(fd, 0, SEEK_END);
89         lseek(fd, 0, SEEK_SET);
90         close(fd);
91         // Insert sanity cheks later
92         vrs.buffer = bigbuffer;
93         vrs.data_size = size - sizeof(struct vrl1_vgax_header);
94         num_of_vrl = 0;
95         vrl_id_iter = (uint16_t huge *)(vrs.buffer + vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST]);
96         while(vrl_id_iter[num_of_vrl]){
97                 num_of_vrl++;
98         }
99
100         // Allocate memory for vrl line offsets table
101         vrl_line_offsets = malloc(sizeof(vrl1_vgax_offset_t *)*num_of_vrl);
102
103         vrl_headers_offsets = (uint32_t huge *)(vrs.buffer + vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_VRS_LIST]);
104         // Calculate line offsets for each vrl
105         for(i = 0; i < num_of_vrl; i++){
106                 curr_vrl = (struct vrl1_vgax_header huge *)(vrs.buffer + vrl_headers_offsets[i]);
107
108                 // Calc. vrl size as (next_offset - curr_offset)
109                 if (i != num_of_vrl - 1){
110                         vrl_size = vrl_headers_offsets[i+1] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header);
111                 }
112                 // If it's the last vrl, size is (next_vrs_struct_offset - curr_offset)
113                 else{
114                         vrl_size = vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header);
115                 }
116                 vrl_line_offsets[i] = vrl1_vgax_genlineoffsets(curr_vrl, (byte *)curr_vrl + sizeof(struct vrl1_vgax_header), vrl_size);
117         }
118         vrs.vrl_line_offsets = vrl_line_offsets;
119
120         //read_vrs(&gvar, "data/spri/chikyuu.vrs", &vrs);
121         spri.spritesheet = &vrs;
122         spri.sprite_vrl_cont = malloc(sizeof(struct vrl_container));
123
124         vrl = malloc(sizeof(struct vrl_container));
125         i = get_vrl_by_id(&vrs, 10, vrl);
126         if(i == -2)
127         {
128                 puts("Die");
129                 return;
130         }
131         off = vrl1_vgax_genlineoffsets(curr_vrl/*vrl->buffer*/, vrl->buffer + sizeof(struct vrl1_vgax_header), vrl->data_size);
132         fd = open("data/spri/chikyuu.vrl", O_RDONLY|O_BINARY);
133         size = lseek(fd, 0, SEEK_END);
134         lseek(fd, 0, SEEK_SET);
135         close(fd);
136
137         if(CA_LoadFile("data/spri/chikyuu.vrl", &bigbuffer, &mm, &mmi)) baka=1; else baka=0;
138         off1 = vrl1_vgax_genlineoffsets(bigbuffer, (byte *)bigbuffer + sizeof(struct vrl1_vgax_header), size - sizeof(struct vrl1_vgax_header));
139
140
141         //read_vrs(&gvar, "data/spri/chikyuu.vrs", spri.spritesheet);
142         i = set_anim_by_id(&spri, 10);
143         if (i == -1)
144         {
145                 return;
146         }
147         spri.x = spri.y = 70;
148
149
150         /* fix up the palette and everything */
151         //modexPalUpdate1(bmp.palette);
152         //modexLoadPalFile("data/spri/chikyuu.pal", &pal);
153         //modexPalUpdate1(pal);
154
155         /* clear and draw one sprite and one bitmap */
156         VGAmodeX(1, 1, &gvar);
157         modexClearRegion(&gvar.video.page[0], 0, 0, gvar.video.page[0].sw, gvar.video.page[0].sh, 1);
158
159         /* non sprite comparison */
160         start = *clockw;
161         modexCopyPageRegion(&gvar.video.page[0], &gvar.video.page[0], 0, 0, 0, 0, 320, 240);
162         animate_spri(&spri);
163         t1 = (*clockw-start) /18.2;
164
165         start = *clockw;
166
167         draw_vrl1_vgax_modex(5,5,curr_vrl/*vrl->buffer*/,vrl->line_offsets,vrl->buffer + sizeof(struct vrl1_vgax_header),vrl->data_size);
168         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));
169         draw_vrl1_vgax_modex(100, 5, bigbuffer, off1, (byte *)bigbuffer + sizeof(struct vrl1_vgax_header), size - sizeof(struct vrl1_vgax_header));
170
171         t2 = (*clockw-start)/18.2;
172
173         //for (i = 0; i < 5; i++){
174         //animate_spri(&spri);
175
176         while(!kbhit())
177         {
178                 switch(w)
179                 {
180                         case 1024:
181                                 modexPalUpdate0(pal);
182                                 w=0;
183                         default:
184                                 w++;
185                         break;
186                 }
187         }
188         VGAmodeX(0, 1, &gvar);
189         free(spri.sprite_vrl_cont);
190         MM_FreePtr(&bigbuffer, &mm);
191         //MM_FreePtr(&((void __based(sega)*)spri.spritesheet->buffer), &mm);
192         MM_Shutdown(&mm);
193         CA_Shutdown(&gvar);
194         //printf("CPU to VGA: %f\n", t1);
195         //printf("VGA to VGA: %f\n", t2);
196         printf("t1: %f\n", t1);
197         printf("t2: %f\n", t2);
198         printf("gvar.video.page[0].width: %u\n", gvar.video.page[0].width);
199         printf("gvar.video.page[0].height: %u\n", gvar.video.page[0].height);
200         printf("Num %d", num_of_vrl);
201         if(baka) printf("\nyay!\n");
202         else printf("\npoo!\n");
203 }