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));
123 i = set_anim_by_id(&spri, 11);
131 // Uncomment to see broken sprites
132 //if(CA_ReadFile("data/spri/CHUBACW1.vrl", &bigbuffer, &mm)) baka=1; else baka=0;
133 //if(CA_LoadFile("data/spri/CHUBACW1.vrl", &bbuffer, &mm, &mmi)) baka=1; else baka=0;
135 /* clear and draw one sprite and one bitmap */
136 VGAmodeX(1, 1, &gvar);
137 modexClearRegion(&gvar.video.page[0], 0, 0, gvar.video.page[0].sw, gvar.video.page[0].sh, 1);
139 /* non sprite comparison */
141 modexCopyPageRegion(&gvar.video.page[0], &gvar.video.page[0], 0, 0, 0, 0, 320, 240);
142 t1 = (*clockw-start) /18.2;
146 t2 = (*clockw-start)/18.2;
148 for (i = 0; i < 5; i++){
149 spri.delay = 1; animate_spri(&spri); spri.x += 20; sleep(2); }
156 modexPalUpdate0(pal);
163 VGAmodeX(0, 1, &gvar);
164 free(spri.sprite_vrl_cont);
165 MM_FreePtr(&bigbuffer, &mm);
166 //MM_FreePtr(&((void __based(sega)*)spri.spritesheet->buffer), &mm);
169 //printf("CPU to VGA: %f\n", t1);
170 //printf("VGA to VGA: %f\n", t2);
171 printf("t1: %f\n", t1);
172 printf("t2: %f\n", t2);
173 printf("gvar.video.page[0].width: %u\n", gvar.video.page[0].width);
174 printf("gvar.video.page[0].height: %u\n", gvar.video.page[0].height);
175 printf("Num %d", num_of_vrl);
176 if(baka) printf("\nyay!\n");
177 else printf("\npoo!\n");