]> 4ch.mooo.com Git - 16.git/blob - src/vrstest.c
Merge remote-tracking branch 'upstream/master'
[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 void main() {
32         global_game_variables_t gvar;
33         __segment sega;
34         memptr bigbuffer;
35         int i;
36         word start;
37         int plane;
38         float t1, t2;
39         boolean baka;
40         byte *pal;
41         int size, size1;
42         struct sprite spri;
43         vrl1_vgax_offset_t * off, *off1;
44         struct vrs_container vrs;
45         vrl1_vgax_offset_t **vrl_line_offsets;
46         uint32_t huge *vrl_headers_offsets;
47         uint16_t huge *vrl_id_iter;
48         uint32_t vrl_size;
49         int num_of_vrl;
50         struct vrl1_vgax_header huge *curr_vrl;
51         struct vrl_container *vrl;
52         word w=0;
53
54         // DOSLIB: check our environment
55         probe_dos();
56
57         // DOSLIB: what CPU are we using?
58         // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.
59         //      So this code by itself shouldn't care too much what CPU it's running on. Except that other
60         //      parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for
61         //      the CPU to carry out tasks. --J.C.
62         cpu_probe();
63
64         // DOSLIB: check for VGA
65         if (!probe_vga()) {
66                 printf("VGA probe failed\n");
67                 return;
68         }
69         // hardware must be VGA or higher!
70         if (!(vga_state.vga_flags & VGA_IS_VGA)) {
71                 printf("This program requires VGA or higher graphics hardware\n");
72                 return;
73         }
74
75         //gvar.video.page[0]=modexDefaultPage(&gvar.video.page[0]);
76
77         gvar.mm.mmstarted=0;
78         MM_Startup(&gvar.mm, &gvar.mmi);
79         CA_Startup(&gvar);
80         // What should be done by read_vrs:
81         //sega = (mm.bufferseg);
82         if(CA_LoadFile("data/spri/chikyuu.vrs", &bigbuffer, &gvar)) baka=1; else baka=0;
83
84         // Insert sanity cheks later
85         vrs.buffer = bigbuffer;
86         vrs.data_size = size - sizeof(struct vrl1_vgax_header);
87         num_of_vrl = 0;
88         vrl_id_iter = (uint16_t huge *)(vrs.buffer + vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST]);
89         while(vrl_id_iter[num_of_vrl]){
90                 num_of_vrl++;
91         }
92
93         // Allocate memory for vrl line offsets table
94         vrl_line_offsets = malloc(sizeof(vrl1_vgax_offset_t *)*num_of_vrl);
95
96         vrl_headers_offsets = (uint32_t huge *)(vrs.buffer + vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_VRS_LIST]);
97         // Calculate line offsets for each vrl
98         for(i = 0; i < num_of_vrl; i++){
99                 curr_vrl = (struct vrl1_vgax_header huge *)(vrs.buffer + vrl_headers_offsets[i]);
100
101                 // Calc. vrl size as (next_offset - curr_offset)
102                 if (i != num_of_vrl - 1){
103                         vrl_size = vrl_headers_offsets[i+1] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header);
104                 }
105                 // If it's the last vrl, size is (next_vrs_struct_offset - curr_offset)
106                 else{
107                         vrl_size = vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header);
108                 }
109                 vrl_line_offsets[i] = vrl1_vgax_genlineoffsets(curr_vrl, (byte *)curr_vrl + sizeof(struct vrl1_vgax_header), vrl_size);
110         }
111         vrs.vrl_line_offsets = vrl_line_offsets;
112
113
114         //read_vrs(&gvar, "data/spri/chikyuu.vrs", &vrs);
115         spri.spritesheet = &vrs;
116         spri.sprite_vrl_cont = malloc(sizeof(struct vrl_container));
117         i = set_anim_by_id(&spri, 11);
118         if (i == -1)
119         {
120                 return;
121         }
122         spri.x = 5;
123         spri.y = 100;
124
125 //      Uncomment to see broken sprites
126 /*      sega = mm.bufferseg;
127         if(CA_LoadFile("data/spri/CHUBACW1.vrl", &bigbuffer, &mm, &mmi)) baka=1; else baka=0;*/
128
129         /* clear and draw one sprite and one bitmap */
130         VGAmodeX(1, 1, &gvar);
131         modexHiganbanaPageSetup(&gvar.video);
132
133         /* non sprite comparison */
134         start = *clockw;
135         modexCopyPageRegion(&gvar.video.page[0], &gvar.video.page[0], 0, 0, 0, 0, 320, 240);
136         t1 = (*clockw-start) /18.2;
137
138         start = *clockw;
139
140         t2 = (*clockw-start)/18.2;
141
142         for (i = 0; i < 5; i++){
143         spri.delay = 1; animate_spri(&spri); spri.x += 20; sleep(1); }
144
145         while(!kbhit())
146         {
147                 switch(w)
148                 {
149                         case 1024:
150                                 modexPalUpdate0(pal);
151                                 w=0;
152                         default:
153                                 w++;
154                         break;
155                 }
156         }
157         VGAmodeX(0, 1, &gvar);
158         MM_ShowMemory(&gvar, &gvar.mm);
159         MM_DumpData(&gvar.mm);
160         free(spri.sprite_vrl_cont);
161         MM_FreePtr(&bigbuffer, &gvar.mm);
162         //MM_FreePtr(&((void __based(sega)*)spri.spritesheet->buffer), &mm);
163         CA_Shutdown(&gvar);
164         MM_Shutdown(&gvar.mm);
165         //printf("CPU to VGA: %f\n", t1);
166         //printf("VGA to VGA: %f\n", t2);
167         heapdump(&gvar);
168         printf("Project 16 vrstest.exe. This is just a test file!\n");
169         printf("version %s\n", VERSION);
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 }