From 781dba2e4095d0e72af3f0c38d2de7bafc21c57d Mon Sep 17 00:00:00 2001 From: yakui-lover Date: Tue, 19 Jul 2016 20:20:36 +0100 Subject: [PATCH] Added a bit of .vrs handling functions (untested) --- src/lib/16_vrs.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/lib/16_vrs.h | 21 +++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/lib/16_vrs.c create mode 100644 src/lib/16_vrs.h diff --git a/src/lib/16_vrs.c b/src/lib/16_vrs.c new file mode 100644 index 00000000..d5457ae5 --- /dev/null +++ b/src/lib/16_vrs.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 index 00000000..38b8132d --- /dev/null +++ b/src/lib/16_vrs.h @@ -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); -- 2.39.2