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