1 /* Project 16 Source Code~
2 * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
4 * This file is part of Project 16.
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.
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.
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.
23 #include "src/lib/modex16.h"
24 #include "src/lib/16_sprit.h"
25 #include "src/lib/16_ca.h"
26 #include "src/lib/16_mm.h"
29 global_game_variables_t gvar;
40 vrl1_vgax_offset_t * off, *off1;
41 struct vrs_container vrs;
42 vrl1_vgax_offset_t **vrl_line_offsets;
43 uint32_t huge *vrl_headers_offsets;
44 uint16_t huge *vrl_id_iter;
47 struct vrl1_vgax_header huge *curr_vrl;
48 struct vrl_container *vrl;
51 // DOSLIB: check our environment
54 // DOSLIB: what CPU are we using?
55 // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.
56 // So this code by itself shouldn't care too much what CPU it's running on. Except that other
57 // parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for
58 // the CPU to carry out tasks. --J.C.
61 // DOSLIB: check for VGA
63 printf("VGA probe failed\n");
66 // hardware must be VGA or higher!
67 if (!(vga_state.vga_flags & VGA_IS_VGA)) {
68 printf("This program requires VGA or higher graphics hardware\n");
72 //gvar.video.page[0]=modexDefaultPage(&gvar.video.page[0]);
75 MM_Startup(&gvar.mm, &gvar.mmi);
77 // What should be done by read_vrs:
78 //sega = (mm.bufferseg);
79 if(CA_LoadFile("data/spri/chikyuu.vrs", &bigbuffer, &gvar)) baka=1; else baka=0;
81 // Insert sanity cheks later
82 vrs.buffer = bigbuffer;
83 vrs.data_size = size - sizeof(struct vrl1_vgax_header);
85 vrl_id_iter = (uint16_t huge *)(vrs.buffer + vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST]);
86 while(vrl_id_iter[num_of_vrl]){
90 // Allocate memory for vrl line offsets table
91 vrl_line_offsets = malloc(sizeof(vrl1_vgax_offset_t *)*num_of_vrl);
93 vrl_headers_offsets = (uint32_t huge *)(vrs.buffer + vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_VRS_LIST]);
94 // Calculate line offsets for each vrl
95 for(i = 0; i < num_of_vrl; i++){
96 curr_vrl = (struct vrl1_vgax_header huge *)(vrs.buffer + vrl_headers_offsets[i]);
98 // Calc. vrl size as (next_offset - curr_offset)
99 if (i != num_of_vrl - 1){
100 vrl_size = vrl_headers_offsets[i+1] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header);
102 // If it's the last vrl, size is (next_vrs_struct_offset - curr_offset)
104 vrl_size = vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header);
106 vrl_line_offsets[i] = vrl1_vgax_genlineoffsets(curr_vrl, (byte *)curr_vrl + sizeof(struct vrl1_vgax_header), vrl_size);
108 vrs.vrl_line_offsets = vrl_line_offsets;
111 //read_vrs(&gvar, "data/spri/chikyuu.vrs", &vrs);
112 spri.spritesheet = &vrs;
113 spri.sprite_vrl_cont = malloc(sizeof(struct vrl_container));
114 i = set_anim_by_id(&spri, 11);
122 // Uncomment to see broken sprites
123 /* sega = mm.bufferseg;
124 if(CA_LoadFile("data/spri/CHUBACW1.vrl", &bigbuffer, &mm, &mmi)) baka=1; else baka=0;*/
126 /* clear and draw one sprite and one bitmap */
127 VGAmodeX(1, 1, &gvar);
128 modexHiganbanaPageSetup(&gvar.video);
130 /* non sprite comparison */
132 modexCopyPageRegion(&gvar.video.page[0], &gvar.video.page[0], 0, 0, 0, 0, 320, 240);
133 t1 = (*clockw-start) /18.2;
137 t2 = (*clockw-start)/18.2;
139 for (i = 0; i < 5; i++){
140 spri.delay = 1; animate_spri(&spri); spri.x += 20; sleep(1); }
147 modexPalUpdate0(pal);
154 VGAmodeX(0, 1, &gvar);
155 MM_ShowMemory(&gvar, &gvar.mm);
156 MM_DumpData(&gvar.mm);
157 free(spri.sprite_vrl_cont);
158 MM_FreePtr(&bigbuffer, &gvar.mm);
159 //MM_FreePtr(&((void __based(sega)*)spri.spritesheet->buffer), &mm);
161 MM_Shutdown(&gvar.mm);
162 //printf("CPU to VGA: %f\n", t1);
163 //printf("VGA to VGA: %f\n", t2);
165 printf("Project 16 vrstest.exe. This is just a test file!\n");
166 printf("version %s\n", VERSION);
167 printf("t1: %f\n", t1);
168 printf("t2: %f\n", t2);
169 printf("gvar.video.page[0].width: %u\n", gvar.video.page[0].width);
170 printf("gvar.video.page[0].height: %u\n", gvar.video.page[0].height);
171 printf("Num %d", num_of_vrl);
172 if(baka) printf("\nyay!\n");
173 else printf("\npoo!\n");