]> 4ch.mooo.com Git - 16.git/commitdiff
Added a bit of .vrs handling functions (untested)
authoryakui-lover <yakui-lover@yandex.ru>
Tue, 19 Jul 2016 19:20:36 +0000 (20:20 +0100)
committeryakui-lover <yakui-lover@yandex.ru>
Tue, 19 Jul 2016 19:20:36 +0000 (20:20 +0100)
src/lib/16_vrs.c [new file with mode: 0644]
src/lib/16_vrs.h [new file with mode: 0644]

diff --git a/src/lib/16_vrs.c b/src/lib/16_vrs.c
new file mode 100644 (file)
index 0000000..d5457ae
--- /dev/null
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <errno.h>
+#include <assert.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "stdlib.h"
+#include "16_vrs.h"
+
+int read_vrs(char *filename, struct vrs_container *vrs_cont){
+       int fd;
+       unsigned long size;
+       unsigned char *buffer;
+       fd = open(filename, O_RDONLY|O_BINARY);
+       // Insert sanity cheks later
+       size = lseek(fd, 0, SEEK_END);
+       buffer = malloc(size);
+       lseek(fd, 0, SEEK_SET);
+       read(fd, buffer, size);
+       vrs_cont->size = size;
+       vrs_cont->buffer = buffer;
+
+       return 0;
+}
+
+struct vrl_container* get_vrl_by_id(struct vrs_container *vrs_cont, uint16_t id){
+       uint16_t *ids; 
+       uint32_t *vrl_list;
+       int counter = 0;
+       struct vrl_container *vrl_cont;
+       if(id == 0){
+               return 0;
+       }
+       ids = (uint16_t*)vrs_cont->buffer + (unsigned long)vrs_cont->vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST];
+       while(ids[counter] != id && ids[counter]){
+               counter++;
+       }
+       vrl_list = (uint32_t *)(vrs_cont->buffer + vrs_cont->vrs_hdr->offset_table[VRS_HEADER_OFFSET_VRS_LIST]);
+       vrl_cont = (struct vrl_container*)malloc(sizeof(struct vrl_container));
+       vrl_cont->vrl_header = (struct vrl1_vgax_header*)(vrs_cont->buffer + vrl_list[counter]);
+       vrl_cont->size = vrl_list[counter+1] - vrl_list[counter];
+       return vrl_cont;
+}
diff --git a/src/lib/16_vrs.h b/src/lib/16_vrs.h
new file mode 100644 (file)
index 0000000..38b8132
--- /dev/null
@@ -0,0 +1,21 @@
+#include "hw/vga/vrl.h"
+#include "hw/vga/vrs.h"
+
+struct vrs_container{
+       unsigned long size;
+       union{
+               unsigned char *buffer;
+               struct vrs_header *vrs_hdr;
+       };
+};
+
+struct vrl_container{
+       unsigned long size;
+       union{
+               unsigned char *buffer;
+               struct vrl1_vgax_header *vrl_header;
+       };
+};
+
+int read_vrs(char *filename, struct vrs_container *vrs_cont);
+struct vrl_container* get_vrl_by_id(struct vrs_container *vrs_cont, uint16_t id);