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