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