]> 4ch.mooo.com Git - 16.git/blob - src/vrstest.c
wwww merged
[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         // What should be done by read_vrs:
87         sega = (mm.bufferseg);
88         if(CA_LoadFile("data/spri/chikyuu.vrs", &bigbuffer, &mm, &mmi)) baka=1; else baka=0;
89         fd = open("data/spri/chikyuu.vrs", O_RDONLY|O_BINARY);
90         size = lseek(fd, 0, SEEK_END);
91         lseek(fd, 0, SEEK_SET);
92         close(fd);
93         // Insert sanity cheks later
94         vrs.buffer = bigbuffer;
95         vrs.data_size = size - sizeof(struct vrl1_vgax_header);
96         num_of_vrl = 0;
97         vrl_id_iter = (uint16_t huge *)(vrs.buffer + vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST]);
98         while(vrl_id_iter[num_of_vrl]){
99                 num_of_vrl++;
100         }
101
102         // Allocate memory for vrl line offsets table
103         vrl_line_offsets = malloc(sizeof(vrl1_vgax_offset_t *)*num_of_vrl);
104
105         vrl_headers_offsets = (uint32_t huge *)(vrs.buffer + vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_VRS_LIST]);
106         // Calculate line offsets for each vrl
107         for(i = 0; i < num_of_vrl; i++){
108                 curr_vrl = (struct vrl1_vgax_header huge *)(vrs.buffer + vrl_headers_offsets[i]);
109
110                 // Calc. vrl size as (next_offset - curr_offset)
111                 if (i != num_of_vrl - 1){
112                         vrl_size = vrl_headers_offsets[i+1] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header);
113                 }
114                 // If it's the last vrl, size is (next_vrs_struct_offset - curr_offset)
115                 else{
116                         vrl_size = vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header);
117                 }
118                 vrl_line_offsets[i] = vrl1_vgax_genlineoffsets(curr_vrl, (byte *)curr_vrl + sizeof(struct vrl1_vgax_header), vrl_size);
119         }
120         vrs.vrl_line_offsets = vrl_line_offsets;
121
122
123         //read_vrs(&gvar, "data/spri/chikyuu.vrs", &vrs);
124         spri.spritesheet = &vrs;
125         spri.sprite_vrl_cont = malloc(sizeof(struct vrl_container));
126         i = set_anim_by_id(&spri, 11);
127         if (i == -1)
128         {
129                 return;
130         }
131         spri.x = 5;
132         spri.y = 100;
133
134 //      Uncomment to see broken sprites
135 /*      sega = mm.bufferseg;
136         if(CA_LoadFile("data/spri/CHUBACW1.vrl", &bigbuffer, &mm, &mmi)) baka=1; else baka=0;*/
137
138         /* clear and draw one sprite and one bitmap */
139         VGAmodeX(1, 1, &gvar);
140         modexClearRegion(&gvar.video.page[0], 0, 0, gvar.video.page[0].sw, gvar.video.page[0].sh, 1);
141
142         /* non sprite comparison */
143         start = *clockw;
144         modexCopyPageRegion(&gvar.video.page[0], &gvar.video.page[0], 0, 0, 0, 0, 320, 240);
145         t1 = (*clockw-start) /18.2;
146
147         start = *clockw;
148
149         t2 = (*clockw-start)/18.2;
150
151         for (i = 0; i < 5; i++){
152         spri.delay = 1; animate_spri(&spri); spri.x += 20; sleep(2); }
153
154         while(!kbhit())
155         {
156                 switch(w)
157                 {
158                         case 1024:
159                                 modexPalUpdate0(pal);
160                                 w=0;
161                         default:
162                                 w++;
163                         break;
164                 }
165         }
166         VGAmodeX(0, 1, &gvar);
167         free(spri.sprite_vrl_cont);
168         MM_FreePtr(&bigbuffer, &mm);
169         //MM_FreePtr(&((void __based(sega)*)spri.spritesheet->buffer), &mm);
170         MM_Shutdown(&mm);
171         CA_Shutdown(&gvar);
172         //printf("CPU to VGA: %f\n", t1);
173         //printf("VGA to VGA: %f\n", t2);
174         printf("t1: %f\n", t1);
175         printf("t2: %f\n", t2);
176         printf("gvar.video.page[0].width: %u\n", gvar.video.page[0].width);
177         printf("gvar.video.page[0].height: %u\n", gvar.video.page[0].height);
178         printf("Num %d", num_of_vrl);
179         if(baka) printf("\nyay!\n");
180         else printf("\npoo!\n");
181 }