]> 4ch.mooo.com Git - 16.git/blobdiff - src/vrstest.c
wwww polished vrstest.c
[16.git] / src / vrstest.c
index d27889d91a9d30081a14b2e65b0763ba21387b65..f971d44254e2d620108e0e6cf9d655115d98a41d 100755 (executable)
-/* Project 16 Source Code~\r
- * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
- *\r
- * This file is part of Project 16.\r
- *\r
- * Project 16 is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 3 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Project 16 is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
- * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
- * Fifth Floor, Boston, MA 02110-1301 USA.\r
- *\r
- */\r
-\r
-#include <stdio.h>\r
-#include <dos.h>\r
-#include <string.h>\r
-#include "src/lib/modex16.h"\r
-#include "src/lib/16_sprite.h"\r
-#include "src/lib/16_ca.h"\r
-#include "src/lib/16_mm.h"\r
-\r
-\r
-global_game_variables_t gvar;\r
-\r
-void main() {\r
-       int i;\r
-       word start;\r
-       int plane;\r
-       float t1, t2;\r
-\r
-       // DOSLIB: check our environment\r
-       probe_dos();\r
-\r
-       // DOSLIB: what CPU are we using?\r
-       // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.\r
-       //      So this code by itself shouldn't care too much what CPU it's running on. Except that other\r
-       //      parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for\r
-       //      the CPU to carry out tasks. --J.C.\r
-       cpu_probe();\r
-\r
-       // DOSLIB: check for VGA\r
-       if (!probe_vga()) {\r
-               printf("VGA probe failed\n");\r
-               return;\r
-       }\r
-       // hardware must be VGA or higher!\r
-       if (!(vga_state.vga_flags & VGA_IS_VGA)) {\r
-               printf("This program requires VGA or higher graphics hardware\n");\r
-               return;\r
-       }\r
-\r
-       //bmp = bitmapLoadPcx("data/chikyuu.pcx");\r
-\r
-       VGAmodeX(1, 1, &gvar);\r
-       gvar.video.page[0]=modexDefaultPage(&gvar.video.page[0]);\r
-\r
-       /* fix up the palette and everything */\r
-       //modexPalUpdate1(bmp.palette);\r
-\r
-       /* clear and draw one sprite and one bitmap */\r
-       modexClearRegion(&gvar.video.page[0], 0, 0, gvar.video.page[0].sw, gvar.video.page[0].sh, 1);\r
-\r
-       /* non sprite comparison */\r
-       start = *clockw;\r
-       //for(i=0; i<100 ;i++) {\r
-       //      oldDrawBmp(VGA, 20, 20, &bmp, 0);\r
-       //}\r
-\r
-       start = *clockw;\r
-       //for(i=0; i<100 ;i++) {\r
-//0000         modexDrawBmp(&gvar.video.page[0], 20, 20, &bmp);\r
-       //      modexDrawBmp(&gvar.video.page[0], 160, 120, &bmp);\r
-       //}\r
-       t1 = (*clockw-start) /18.2;\r
-\r
-       start = *clockw;\r
-       //for(i=0; i<100; i++) {\r
-//0000         modexCopyPageRegion(&gvar.video.page[0], &gvar.video.page[0], 20, 20, 128, 20, 64, 64);\r
-               modexCopyPageRegion(&gvar.video.page[0], &gvar.video.page[0], 0, 0, 0, 0, 320, 240);\r
-       //}\r
-       t2 = (*clockw-start)/18.2;\r
-\r
-\r
-       start = *clockw;\r
-       //for(i=0; i<100 ;i++) {\r
-       //      oldDrawBmp(VGA, 20, 20, &bmp, 1);\r
-       //}\r
-\r
-\r
-       start = *clockw;\r
-       //for(i=0; i<100 ;i++) {\r
-//0000         modexDrawSprite(&gvar.video.page[0], 20, 20, &bmp);\r
-       //      modexDrawSprite(&gvar.video.page[0], 160, 120, &bmp);\r
-       //}\r
-       //_fmemset(MK_FP(0xA000, 0), (int)p->plane, gvar.video.page[0].sw*(gvar.video.page[0].sh*2));\r
-       //modexDrawBmp(&gvar.video.page[0], 0, 0, &bmp);\r
-       while(!kbhit())\r
-       {\r
-               //DrawPBuf(&gvar.video.page[0], 0, 0, p, 0);\r
-       }\r
-       VGAmodeX(0, 1, &gvar);\r
-       /*printf("\nmain=%Fp\n\n", &i);\r
-       printf("bmp.data=%Fp\n", bmp.data);\r
-       printf("*bmp.data=%Fp\n", *(bmp.data));\r
-       printf("&bmp.data=%Fp\n", &(bmp.data));\r
-\r
-       printf("\n%d\n", sizeof(p->plane));\r
-       printf("%d\n", sizeof(bmp));*/\r
-\r
-       /*for(i=0; i<(320*240); i++)\r
-       {\r
-               fprintf(stdout, "%d", bmp.data[i]);\r
-               if(i%bmp.width==0) fprintf(stdout, "\n");\r
-       }*/\r
-       printf("CPU to VGA: %f\n", t1);\r
-       printf("VGA to VGA: %f\n", t2);\r
-       printf("gvar.video.page[0].width: %u\n", gvar.video.page[0].width);\r
-       printf("gvar.video.page[0].height: %u\n", gvar.video.page[0].height);\r
-       return;\r
-}\r
+/* Project 16 Source Code~
+ * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
+ *
+ * This file is part of Project 16.
+ *
+ * Project 16 is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Project 16 is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>, or
+ * write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <stdio.h>
+#include <dos.h>
+#include <string.h>
+#include "src/lib/modex16.h"
+#include "src/lib/16_sprite.h"
+#include "src/lib/16_ca.h"
+#include "src/lib/16_mm.h"
+
+global_game_variables_t gvar;
+
+void main() {
+       mminfo_t mm; mminfotype mmi;
+       __segment sega;
+       void __based(sega)* bigbuffer;
+       int i;
+       word start;
+       int plane;
+       float t1, t2;
+       boolean baka;
+       byte *pal;
+       int fd, size, size1;
+       struct sprite spri;
+       vrl1_vgax_offset_t * off, *off1;
+       struct vrs_container vrs;
+       vrl1_vgax_offset_t **vrl_line_offsets;
+       uint32_t huge *vrl_headers_offsets;
+       uint16_t huge *vrl_id_iter;
+       uint32_t vrl_size;
+       int num_of_vrl;
+       struct vrl1_vgax_header huge *curr_vrl;
+       struct vrl_container *vrl;
+       int success;
+       byte w=1;
+
+
+
+       // DOSLIB: check our environment
+       probe_dos();
+
+       // DOSLIB: what CPU are we using?
+       // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.
+       //      So this code by itself shouldn't care too much what CPU it's running on. Except that other
+       //      parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for
+       //      the CPU to carry out tasks. --J.C.
+       cpu_probe();
+
+       // DOSLIB: check for VGA
+       if (!probe_vga()) {
+               printf("VGA probe failed\n");
+               return;
+       }
+       // hardware must be VGA or higher!
+       if (!(vga_state.vga_flags & VGA_IS_VGA)) {
+               printf("This program requires VGA or higher graphics hardware\n");
+               return;
+       }
+
+       //bmp = bitmapLoadPcx("data/chikyuu.pcx");
+       gvar.video.page[0]=modexDefaultPage(&gvar.video.page[0]);
+
+       mm.mmstarted=0;
+       MM_Startup(&mm, &mmi);
+       CA_Startup(&gvar);
+       if(CA_LoadFile("data/spri/chikyuu.vrs", &bigbuffer, &mm, &mmi)) baka=1; else baka=0;
+       fd = open("data/spri/chikyuu.vrs", O_RDONLY|O_BINARY);
+       size = lseek(fd, 0, SEEK_END);
+       lseek(fd, 0, SEEK_SET);
+       close(fd);
+       // Insert sanity cheks later
+       vrs.buffer = bigbuffer;
+       vrs.data_size = size - sizeof(struct vrl1_vgax_header);
+       num_of_vrl = 0;
+       vrl_id_iter = (uint16_t huge *)(vrs.buffer + vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST]);
+       while(vrl_id_iter[num_of_vrl]){
+               num_of_vrl++;
+       }
+
+       // Allocate memory for vrl line offsets table
+       vrl_line_offsets = malloc(sizeof(vrl1_vgax_offset_t *)*num_of_vrl);
+
+       vrl_headers_offsets = (uint32_t huge *)(vrs.buffer + vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_VRS_LIST]);
+       // Calculate line offsets for each vrl
+       for(i = 0; i < num_of_vrl; i++){
+               curr_vrl = (struct vrl1_vgax_header huge *)(vrs.buffer + vrl_headers_offsets[i]);
+
+               // Calc. vrl size as (next_offset - curr_offset)
+               if (i != num_of_vrl - 1){
+                       vrl_size = vrl_headers_offsets[i+1] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header);
+               }
+               // If it's the last vrl, size is (next_vrs_struct_offset - curr_offset)
+               else{
+                       vrl_size = vrs.vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header);
+               }
+               vrl_line_offsets[i] = vrl1_vgax_genlineoffsets(curr_vrl, (byte *)curr_vrl + sizeof(struct vrl1_vgax_header), vrl_size);
+       }
+       vrs.vrl_line_offsets = vrl_line_offsets;
+
+       //read_vrs(&gvar, "data/spri/chikyuu.vrs", &vrs);
+       spri.spritesheet = &vrs;
+       spri.sprite_vrl_cont = malloc(sizeof(struct vrl_container));
+
+       vrl = malloc(sizeof(struct vrl_container));
+       i = get_vrl_by_id(&vrs, 10, vrl);
+       if(i == -2)
+       {
+               puts("Die");
+               return;
+       }
+       off = vrl1_vgax_genlineoffsets(curr_vrl/*vrl->buffer*/, vrl->buffer + sizeof(struct vrl1_vgax_header), vrl->data_size);
+       fd = open("data/spri/chikyuu.vrl", O_RDONLY|O_BINARY);
+       size = lseek(fd, 0, SEEK_END);
+       lseek(fd, 0, SEEK_SET);
+       close(fd);
+
+       if(CA_LoadFile("data/spri/chikyuu.vrl", &bigbuffer, &mm, &mmi)) baka=1; else baka=0;
+       off1 = vrl1_vgax_genlineoffsets(bigbuffer, (byte *)bigbuffer + sizeof(struct vrl1_vgax_header), size - sizeof(struct vrl1_vgax_header));
+
+
+       //read_vrs(&gvar, "data/spri/chikyuu.vrs", spri.spritesheet);
+       i = set_anim_by_id(&spri, 10);
+       if (i == -1)
+       {
+               return;
+       }
+       spri.x = spri.y = 70;
+
+
+       /* fix up the palette and everything */
+       //modexPalUpdate1(bmp.palette);
+       //modexLoadPalFile("data/spri/chikyuu.pal", &pal);
+       //modexPalUpdate1(pal);
+
+       /* clear and draw one sprite and one bitmap */
+       VGAmodeX(1, 1, &gvar);
+       modexClearRegion(&gvar.video.page[0], 0, 0, gvar.video.page[0].sw, gvar.video.page[0].sh, 1);
+
+       /* non sprite comparison */
+       start = *clockw;
+       modexCopyPageRegion(&gvar.video.page[0], &gvar.video.page[0], 0, 0, 0, 0, 320, 240);
+       animate_spri(&spri);
+       t1 = (*clockw-start) /18.2;
+
+       start = *clockw;
+
+       draw_vrl1_vgax_modex(5,5,curr_vrl/*vrl->buffer*/,vrl->line_offsets,vrl->buffer + sizeof(struct vrl1_vgax_header),vrl->data_size);
+       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));
+       draw_vrl1_vgax_modex(100, 5, bigbuffer, off1, (byte *)bigbuffer + sizeof(struct vrl1_vgax_header), size - sizeof(struct vrl1_vgax_header));
+
+       t2 = (*clockw-start)/18.2;
+
+       //for (i = 0; i < 5; i++){
+       //animate_spri(&spri);
+
+       while(!kbhit())
+       {
+               switch(w)
+               {
+                       case 252:
+                               modexPalUpdate0(pal);
+                               w=1;
+                       default:
+                               w++;
+                       break;
+               }
+       }
+       VGAmodeX(0, 1, &gvar);
+       free(spri.sprite_vrl_cont);
+       MM_FreePtr(&bigbuffer, &mm);
+       //MM_FreePtr(&((void __based(sega)*)spri.spritesheet->buffer), &mm);
+       MM_Shutdown(&mm);
+       CA_Shutdown(&gvar);
+       //printf("CPU to VGA: %f\n", t1);
+       //printf("VGA to VGA: %f\n", t2);
+       printf("t1: %f\n", t1);
+       printf("t2: %f\n", t2);
+       printf("gvar.video.page[0].width: %u\n", gvar.video.page[0].width);
+       printf("gvar.video.page[0].height: %u\n", gvar.video.page[0].height);
+       printf("Num %d", num_of_vrl);
+       if(baka) printf("\nyay!\n");
+       else printf("\npoo!\n");
+}