]> 4ch.mooo.com Git - 16.git/blob - src/vrstest.c
16_pm worked on~
[16.git] / src / vrstest.c
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
3  *\r
4  * This file is part of Project 16.\r
5  *\r
6  * Project 16 is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Project 16 is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
19  * Fifth Floor, Boston, MA 02110-1301 USA.\r
20  *\r
21  */\r
22 \r
23 #include "src/lib/modex16.h"\r
24 #include "src/lib/16_sprit.h"\r
25 #include "src/lib/16_ca.h"\r
26 #include "src/lib/16_mm.h"\r
27 \r
28 void main() {\r
29         global_game_variables_t gvar;\r
30         __segment sega;\r
31         memptr bigbuffer;\r
32         int i;\r
33         word start;\r
34         int plane;\r
35         float t1, t2;\r
36         boolean baka;\r
37         byte *pal;\r
38         int size, size1;\r
39         struct sprite spri;\r
40         vrl1_vgax_offset_t * off, *off1;\r
41         struct vrs_container vrs;\r
42         vrl1_vgax_offset_t **vrl_line_offsets;\r
43         uint32_t huge *vrl_headers_offsets;\r
44         uint16_t huge *vrl_id_iter;\r
45         uint32_t vrl_size;\r
46         int num_of_vrl;\r
47         struct vrl1_vgax_header huge *curr_vrl;\r
48         struct vrl_container *vrl;\r
49         word w=0;\r
50 \r
51         // DOSLIB: check our environment\r
52         probe_dos();\r
53 \r
54         // DOSLIB: what CPU are we using?\r
55         // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.\r
56         //      So this code by itself shouldn't care too much what CPU it's running on. Except that other\r
57         //      parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for\r
58         //      the CPU to carry out tasks. --J.C.\r
59         cpu_probe();\r
60 \r
61         // DOSLIB: check for VGA\r
62         if (!probe_vga()) {\r
63                 printf("VGA probe failed\n");\r
64                 return;\r
65         }\r
66         // hardware must be VGA or higher!\r
67         if (!(vga_state.vga_flags & VGA_IS_VGA)) {\r
68                 printf("This program requires VGA or higher graphics hardware\n");\r
69                 return;\r
70         }\r
71 \r
72         //gvar.video.page[0]=modexDefaultPage(&gvar.video.page[0]);\r
73 \r
74         gvar.mm.mmstarted=0;\r
75         MM_Startup(&gvar);\r
76         CA_Startup(&gvar);\r
77         // What should be done by read_vrs:\r
78         //sega = (mm.bufferseg);\r
79         if(CA_LoadFile("data/spri/chikyuu.vrs", &bigbuffer, &gvar)) baka=1; else baka=0;\r
80 \r
81         // Insert sanity cheks later\r
82         vrs.buffer = bigbuffer;\r
83         vrs.data_size = size - sizeof(struct vrl1_vgax_header);\r
84         num_of_vrl = 0;\r
85         vrl_id_iter = (uint16_t huge *)(vrs.buffer + vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST]);\r
86         while(vrl_id_iter[num_of_vrl]){\r
87                 num_of_vrl++;\r
88         }\r
89 \r
90         // Allocate memory for vrl line offsets table\r
91         vrl_line_offsets = malloc(sizeof(vrl1_vgax_offset_t *)*num_of_vrl);\r
92 \r
93         vrl_headers_offsets = (uint32_t huge *)(vrs.buffer + vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_VRS_LIST]);\r
94         // Calculate line offsets for each vrl\r
95         for(i = 0; i < num_of_vrl; i++){\r
96                 curr_vrl = (struct vrl1_vgax_header huge *)(vrs.buffer + vrl_headers_offsets[i]);\r
97 \r
98                 // Calc. vrl size as (next_offset - curr_offset)\r
99                 if (i != num_of_vrl - 1){\r
100                         vrl_size = vrl_headers_offsets[i+1] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header);\r
101                 }\r
102                 // If it's the last vrl, size is (next_vrs_struct_offset - curr_offset)\r
103                 else{\r
104                         vrl_size = vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header);\r
105                 }\r
106                 vrl_line_offsets[i] = vrl1_vgax_genlineoffsets(curr_vrl, (byte *)curr_vrl + sizeof(struct vrl1_vgax_header), vrl_size);\r
107         }\r
108         vrs.vrl_line_offsets = vrl_line_offsets;\r
109 \r
110 \r
111         //read_vrs(&gvar, "data/spri/chikyuu.vrs", &vrs);\r
112         spri.spritesheet = &vrs;\r
113         spri.sprite_vrl_cont = malloc(sizeof(struct vrl_container));\r
114         i = set_anim_by_id(&spri, 11);\r
115         if (i == -1)\r
116         {\r
117                 return;\r
118         }\r
119         spri.x = 5;\r
120         spri.y = 100;\r
121 \r
122 //      Uncomment to see broken sprites\r
123 /*      sega = mm.bufferseg;\r
124         if(CA_LoadFile("data/spri/CHUBACW1.vrl", &bigbuffer, &mm, &mmi)) baka=1; else baka=0;*/\r
125 \r
126         /* clear and draw one sprite and one bitmap */\r
127         VGAmodeX(1, 1, &gvar);\r
128         modexHiganbanaPageSetup(&gvar.video);\r
129 \r
130         /* non sprite comparison */\r
131         start = *clockw;\r
132         modexCopyPageRegion(&gvar.video.page[0], &gvar.video.page[0], 0, 0, 0, 0, 320, 240);\r
133         t1 = (*clockw-start) /18.2;\r
134 \r
135         start = *clockw;\r
136 \r
137         t2 = (*clockw-start)/18.2;\r
138 \r
139         for (i = 0; i < 5; i++){\r
140         spri.delay = 1; animate_spri(&spri); spri.x += 20; sleep(1); }\r
141 \r
142         while(!kbhit())\r
143         {\r
144                 switch(w)\r
145                 {\r
146                         case 1024:\r
147                                 modexPalUpdate0(pal);\r
148                                 w=0;\r
149                         default:\r
150                                 w++;\r
151                         break;\r
152                 }\r
153         }\r
154         VGAmodeX(0, 1, &gvar);\r
155         MM_ShowMemory(&gvar);\r
156         MM_DumpData(&gvar);\r
157         free(spri.sprite_vrl_cont);\r
158         MM_FreePtr(&bigbuffer, &gvar);\r
159         //MM_FreePtr(&((void __based(sega)*)spri.spritesheet->buffer), &mm);\r
160         CA_Shutdown(&gvar);\r
161         MM_Shutdown(&gvar);\r
162         //printf("CPU to VGA: %f\n", t1);\r
163         //printf("VGA to VGA: %f\n", t2);\r
164         heapdump(&gvar);\r
165         printf("Project 16 vrstest.exe. This is just a test file!\n");\r
166         printf("version %s\n", VERSION);\r
167         printf("t1: %f\n", t1);\r
168         printf("t2: %f\n", t2);\r
169         printf("gvar.video.page[0].width: %u\n", gvar.video.page[0].width);\r
170         printf("gvar.video.page[0].height: %u\n", gvar.video.page[0].height);\r
171         printf("Num %d", num_of_vrl);\r
172         if(baka) printf("\nyay!\n");\r
173         else printf("\npoo!\n");\r
174 }\r