• R/O
  • HTTP
  • SSH
  • HTTPS

提交

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

wwww


Commit MetaInfo

修訂848c772e64209441c696de3d8101f7b3b81f1354 (tree)
時間2016-07-22 04:01:14
作者yakui-lover <yakui-lover@yand...>
Commiteryakui-lover

Log Message

Documented 16_vrs files
Also, wrapped header file in #ifdef
and added a check for invalid vrl id get_vrl_by_id

Change Summary

差異

--- a/src/lib/16_vrs.c
+++ b/src/lib/16_vrs.c
@@ -1,20 +1,21 @@
11 #include <stdio.h>
22 #include <fcntl.h>
33 #include <ctype.h>
4-#include <errno.h>
5-#include <assert.h>
64 #include <stdint.h>
75 #include <stdlib.h>
8-#include <string.h>
96 #include <unistd.h>
107
11-#include "stdlib.h"
128 #include "16_vrs.h"
139
10+// Read .vrs file into memory
1411 int read_vrs(char *filename, struct vrs_container *vrs_cont){
12+ // Initialise a local copy of becessary variables
13+ // so vrs_cont won't be dirty on error
1514 int fd;
1615 unsigned long size;
1716 unsigned char *buffer;
17+ // Open filename, get size of file,
18+ // populate the vrs_container if all tests pass
1819 fd = open(filename, O_RDONLY|O_BINARY);
1920 // Insert sanity cheks later
2021 size = lseek(fd, 0, SEEK_END);
@@ -23,25 +24,45 @@ int read_vrs(char *filename, struct vrs_container *vrs_cont){
2324 read(fd, buffer, size);
2425 vrs_cont->size = size;
2526 vrs_cont->buffer = buffer;
26-
27+ // 0 is an invalid value for ids under vrs specifications,
28+ // so it is safe to flush ids to this value
29+ vrs_cont->anchor_sprite_id = 0;
30+ vrs_cont->current_sprite_id = 0;
2731 return 0;
2832 }
2933
34+// Seek and return a specified .vrl blob from .vrs blob in memory
3035 struct vrl_container* get_vrl_by_id(struct vrs_container *vrs_cont, uint16_t id){
3136 uint16_t *ids;
3237 uint32_t *vrl_list;
33- int counter = 0;
3438 struct vrl_container *vrl_cont;
39+ int counter = 0;
40+ // If id is invalid, return null
3541 if(id == 0){
42+ // Probably add an error message?
3643 return 0;
3744 }
45+ // Get id list from .vrs blob (base + offset)
3846 ids = (uint16_t*)vrs_cont->buffer + (unsigned long)vrs_cont->vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST];
47+ // Loop through the id list until we found the right one or hit the end of the list
48+ // Counter is keeping track of the offset(in ids/vrl blobs)
3949 while(ids[counter] != id && ids[counter]){
4050 counter++;
4151 }
52+ // Return null if we couldn't find the requested id
53+ if(!ids[counter]){
54+ // Error message?
55+ return 0;
56+ }
57+ // Get vrl list from .vrs blob (base + offset)
4258 vrl_list = (uint32_t *)(vrs_cont->buffer + vrs_cont->vrs_hdr->offset_table[VRS_HEADER_OFFSET_VRS_LIST]);
59+ // Allocate memory for vrl_cont
4360 vrl_cont = (struct vrl_container*)malloc(sizeof(struct vrl_container));
61+ // Get vrl_header from .vrs (base + offset from vrl_list)
62+ // Counter is number of vrls to skip (ids and vrls are aligned according to the .vrs specification)
4463 vrl_cont->vrl_header = (struct vrl1_vgax_header*)(vrs_cont->buffer + vrl_list[counter]);
64+ // Get .vrl size by integer arithmetics (next vrl - current vrl)
65+ // Untested. May be an incorrect way to do so
4566 vrl_cont->size = vrl_list[counter+1] - vrl_list[counter];
4667 return vrl_cont;
4768 }
--- a/src/lib/16_vrs.h
+++ b/src/lib/16_vrs.h
@@ -1,14 +1,32 @@
1+#ifndef __16_VRS__
2+#define __16_VRS__
3+
4+#include <stdint.h>
15 #include "hw/vga/vrl.h"
26 #include "hw/vga/vrs.h"
37
8+// Container for .vrs files loaded in memory with useful info
9+// Includes:
10+// + size of the .vrs blob in memory
11+// + pointer to the blob/vrs header
12+// + id of the curent (shown) animation
13+// + id of the first sprite of the curret animation (supplementary)
14+// + id of the current (shown) sprite
15+
416 struct vrs_container{
517 unsigned long size;
618 union{
719 unsigned char *buffer;
820 struct vrs_header *vrs_hdr;
921 };
22+ uint16_t anchor_sprite_id;
23+ uint16_t current_sprite_id;
1024 };
1125
26+// Container for .vrl files loaded in memory with useful info
27+// Includes:
28+// + size of the .vrl blob in memory
29+// + pointer to the blob/vrl header
1230 struct vrl_container{
1331 unsigned long size;
1432 union{
@@ -17,5 +35,23 @@ struct vrl_container{
1735 };
1836 };
1937
38+// Read .vrs file into memory
39+// In:
40+// + char *filename - name of the file to load
41+// + struct vrs_container *vrs_cont - pointer to the vrs_container
42+// to load the file into
43+// Out:
44+// + int - 0 on succes, 1 on failure
2045 int read_vrs(char *filename, struct vrs_container *vrs_cont);
46+
47+// Seek and return a specified .vrl blob from .vrs blob in memory
48+// In:
49+// + struct vrs_container *vrs_cont - pointer to the vrs_container
50+// with a loaded .vrs file
51+// + uint16_t id - id of the vrl to retrive
52+// Out:
53+// struct vrl_container* - a pointer to a vrl_container with a pointer
54+// to the requested .vrl blob
2155 struct vrl_container* get_vrl_by_id(struct vrs_container *vrs_cont, uint16_t id);
56+
57+#endif