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.
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"
31 global_game_variables_t gvar;
34 mminfo_t mm; mminfotype mmi;
36 void __based(sega)* bigbuffer;
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;
52 struct vrl1_vgax_header huge *curr_vrl;
53 struct vrl_container *vrl;
59 // DOSLIB: check our environment
62 // DOSLIB: what CPU are we using?
63 // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.
64 // So this code by itself shouldn't care too much what CPU it's running on. Except that other
65 // parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for
66 // the CPU to carry out tasks. --J.C.
69 // DOSLIB: check for VGA
71 printf("VGA probe failed\n");
74 // hardware must be VGA or higher!
75 if (!(vga_state.vga_flags & VGA_IS_VGA)) {
76 printf("This program requires VGA or higher graphics hardware\n");
80 //bmp = bitmapLoadPcx("data/chikyuu.pcx");
81 gvar.video.page[0]=modexDefaultPage(&gvar.video.page[0]);
84 MM_Startup(&mm, &mmi);
86 if(CA_LoadFile("data/spri/chikyuu.vrs", &bigbuffer, &mm, &mmi)) baka=1; else baka=0;
87 fd = open("data/spri/chikyuu.vrs", O_RDONLY|O_BINARY);
88 size = lseek(fd, 0, SEEK_END);
89 lseek(fd, 0, SEEK_SET);
91 // Insert sanity cheks later
92 vrs.buffer = bigbuffer;
93 vrs.data_size = size - sizeof(struct vrl1_vgax_header);
95 vrl_id_iter = (uint16_t huge *)(vrs.buffer + vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST]);
96 while(vrl_id_iter[num_of_vrl]){
100 // Allocate memory for vrl line offsets table
101 vrl_line_offsets = malloc(sizeof(vrl1_vgax_offset_t *)*num_of_vrl);
103 vrl_headers_offsets = (uint32_t huge *)(vrs.buffer + vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_VRS_LIST]);
104 // Calculate line offsets for each vrl
105 for(i = 0; i < num_of_vrl; i++){
106 curr_vrl = (struct vrl1_vgax_header huge *)(vrs.buffer + vrl_headers_offsets[i]);
108 // Calc. vrl size as (next_offset - curr_offset)
109 if (i != num_of_vrl - 1){
110 vrl_size = vrl_headers_offsets[i+1] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header);
112 // If it's the last vrl, size is (next_vrs_struct_offset - curr_offset)
114 vrl_size = vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header);
116 vrl_line_offsets[i] = vrl1_vgax_genlineoffsets(curr_vrl, (byte *)curr_vrl + sizeof(struct vrl1_vgax_header), vrl_size);
118 vrs.vrl_line_offsets = vrl_line_offsets;
120 //read_vrs(&gvar, "data/spri/chikyuu.vrs", &vrs);
121 spri.spritesheet = &vrs;
122 spri.sprite_vrl_cont = malloc(sizeof(struct vrl_container));
124 vrl = malloc(sizeof(struct vrl_container));
125 i = get_vrl_by_id(&vrs, 10, vrl);
131 off = vrl1_vgax_genlineoffsets(curr_vrl/*vrl->buffer*/, vrl->buffer + sizeof(struct vrl1_vgax_header), vrl->data_size);
132 fd = open("data/spri/chikyuu.vrl", O_RDONLY|O_BINARY);
133 size = lseek(fd, 0, SEEK_END);
134 lseek(fd, 0, SEEK_SET);
137 if(CA_LoadFile("data/spri/chikyuu.vrl", &bigbuffer, &mm, &mmi)) baka=1; else baka=0;
138 off1 = vrl1_vgax_genlineoffsets(bigbuffer, (byte *)bigbuffer + sizeof(struct vrl1_vgax_header), size - sizeof(struct vrl1_vgax_header));
141 //read_vrs(&gvar, "data/spri/chikyuu.vrs", spri.spritesheet);
142 i = set_anim_by_id(&spri, 10);
147 spri.x = spri.y = 70;
150 /* fix up the palette and everything */
151 //modexPalUpdate1(bmp.palette);
152 //modexLoadPalFile("data/spri/chikyuu.pal", &pal);
153 //modexPalUpdate1(pal);
155 /* clear and draw one sprite and one bitmap */
156 VGAmodeX(1, 1, &gvar);
157 modexClearRegion(&gvar.video.page[0], 0, 0, gvar.video.page[0].sw, gvar.video.page[0].sh, 1);
159 /* non sprite comparison */
161 modexCopyPageRegion(&gvar.video.page[0], &gvar.video.page[0], 0, 0, 0, 0, 320, 240);
163 t1 = (*clockw-start) /18.2;
167 draw_vrl1_vgax_modex(5,5,curr_vrl/*vrl->buffer*/,vrl->line_offsets,vrl->buffer + sizeof(struct vrl1_vgax_header),vrl->data_size);
168 draw_vrl1_vgax_modex(40,40,curr_vrl/*vrs.buffer*/ + vrl_headers_offsets[0],vrs.vrl_line_offsets[0],vrs.buffer + vrl_headers_offsets[0] + sizeof(struct vrl1_vgax_header),vrl_headers_offsets[1] - vrl_headers_offsets[0] - sizeof(struct vrl1_vgax_header));
169 draw_vrl1_vgax_modex(100, 5, bigbuffer, off1, (byte *)bigbuffer + sizeof(struct vrl1_vgax_header), size - sizeof(struct vrl1_vgax_header));
171 t2 = (*clockw-start)/18.2;
173 //for (i = 0; i < 5; i++){
174 //animate_spri(&spri);
181 modexPalUpdate0(pal);
188 VGAmodeX(0, 1, &gvar);
189 free(spri.sprite_vrl_cont);
190 MM_FreePtr(&bigbuffer, &mm);
191 //MM_FreePtr(&((void __based(sega)*)spri.spritesheet->buffer), &mm);
194 //printf("CPU to VGA: %f\n", t1);
195 //printf("VGA to VGA: %f\n", t2);
196 printf("t1: %f\n", t1);
197 printf("t2: %f\n", t2);
198 printf("gvar.video.page[0].width: %u\n", gvar.video.page[0].width);
199 printf("gvar.video.page[0].height: %u\n", gvar.video.page[0].height);
200 printf("Num %d", num_of_vrl);
201 if(baka) printf("\nyay!\n");
202 else printf("\npoo!\n");