uint8_t for chars, lexfilename needs work
[henge/webcc.git] / src / apc / ir.c
index 421f6e5..4e23d16 100755 (executable)
@@ -6,12 +6,14 @@
   ----------------------------------------------------------------------------*/\r
 #include <errno.h>\r
 #include <stdio.h>\r
+#include <unitypes.h> //uint8_t as a char\r
+#include <unistr.h> //u32_cpy\r
 #include <stdint.h> //uint64_t\r
-#include <string.h> //memmove\r
 #include <stdlib.h> //malloc\r
 #include <apc/ir.h>\r
 \r
-\r
+//extern\r
+//scanner_scanpixels(int*, int);\r
 \r
 /* functions needed from irmem.c */\r
 extern\r
@@ -27,9 +29,13 @@ struct odat*
 alloc_odat(void);\r
 \r
 extern\r
-void\r
+struct vdat*\r
 alloc_vdat(void);\r
 \r
+extern\r
+void\r
+alloc_mdat(void);\r
+\r
 extern\r
 struct link*\r
 alloc_link(void);\r
@@ -46,6 +52,14 @@ extern
 struct odat*\r
 curr_odat(void);\r
 \r
+extern\r
+struct variant*\r
+curr_variant(void);\r
+\r
+extern\r
+struct variant*\r
+alloc_variant(void);\r
+\r
 extern\r
 struct vdat*\r
 curr_vdat(void);\r
@@ -66,11 +80,15 @@ extern
 struct model*\r
 curr_model(void);\r
 \r
+extern\r
+struct quad*\r
+curr_quad(void);\r
+\r
 /* struct definitions needed from irmem.c */\r
 extern int num_cdats;\r
 extern struct cdat** cdat_stackp;\r
 extern struct odat* curr_set_odatp;\r
-extern uint64_t ss_ref_id;\r
+extern int ss_ref_id;\r
 \r
 extern int num_vdats;\r
 /* Dynamically allocate memory for a class data structure,\r
@@ -83,14 +101,14 @@ extern int num_vdats;
    which is a list of all allocated cdats*/\r
 void\r
 push_cdat\r
-( char* name\r
+( uint8_t* name\r
 )\r
 {\r
   struct cdat* curr_cdatp;\r
 \r
   curr_cdatp = alloc_cdat();\r
 \r
-  memmove(curr_cdatp->name, name, 32);\r
+  u8_cpy(curr_cdatp->name, name, 32);\r
   curr_cdatp->idx = num_cdats;\r
 \r
   /* Set the cdat as a subclass of the previous cdat */\r
@@ -120,8 +138,8 @@ pop_cdat
 \r
 void\r
 insert_set_label\r
-( char* name,\r
-  uint64_t ref_id\r
+( uint8_t* name,\r
+  int ref_id\r
 )\r
 {\r
 \r
@@ -130,8 +148,9 @@ insert_set_label
   curr_setp = curr_set();\r
   curr_set_odatp = alloc_odat();\r
 \r
-  memmove(curr_set_odatp->name, name, 32);\r
-  memmove(curr_setp->name, name, 32);\r
+  u8_cpy(curr_set_odatp->name, name, 32);\r
+  u8_cpy(curr_setp->name, name, 32);\r
+  curr_set_odatp->parent_odatp = NULL;\r
 \r
   if(ref_id != -1)\r
     { curr_set_odatp->ref_id = ref_id;\r
@@ -148,7 +167,7 @@ insert_set_label
    for another set. Allocate the memory for the set so taht it can be populated*/\r
 void\r
 insert_set_olink\r
-( uint64_t ref_id\r
+( int ref_id\r
 )\r
 {\r
   struct set* curr_setp;\r
@@ -161,8 +180,8 @@ insert_set_olink
 \r
 void\r
 insert_set_vlink\r
-( uint64_t ref_id,\r
-  char* anim_name\r
+( int ref_id,\r
+  uint8_t* anim_name\r
 )\r
 {\r
   struct cdat* curr_cdatp;\r
@@ -179,7 +198,7 @@ insert_set_vlink
   curr_linkp->type = 2;\r
   /* Store the target odat information*/\r
   curr_linkp->link_t.vlink.ref_id = ref_id;\r
-  memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
+  u8_cpy(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
   /* Store the linking odat/cdat information */\r
   curr_linkp->classp = curr_cdatp;\r
   curr_linkp->odatp = curr_odatp;\r
@@ -191,7 +210,7 @@ insert_set_vlink
 /* Svlinks dont have animation names */\r
 void\r
 insert_set_svlink\r
-( uint64_t ref_id \r
+( int ref_id \r
 )\r
 {\r
   struct cdat* curr_cdatp;\r
@@ -217,7 +236,7 @@ insert_set_svlink
 void\r
 insert_set\r
 ()\r
-{ uint64_t ref_id;\r
+{ int ref_id;\r
   struct odat* curr_odatp;\r
   struct cdat* curr_cdatp;\r
   struct set* curr_setp;\r
@@ -235,7 +254,7 @@ insert_set
   curr_vdatp->creator = curr_set_odatp;\r
 \r
   curr_setp->cdat_idx = curr_cdatp->idx; //does a set need its class idx?\r
-  memmove(curr_setp->name, curr_odatp->name, 32);\r
+  u8_cpy(curr_setp->name, curr_odatp->name, 32);\r
   curr_cdatp->num_sets++;\r
 \r
   curr_odatp->cdat_idx = curr_cdatp->idx;\r
@@ -271,15 +290,15 @@ insert_set_vdatid
  the functions to use via curr_odat(). */\r
 void\r
 insert_ele_label\r
-( char* name,\r
-  uint64_t ref_id\r
+( uint8_t* name,\r
+  int ref_id\r
 )\r
 {\r
   struct odat* curr_odatp;\r
 \r
   curr_odatp = alloc_odat();\r
 \r
-  memmove(curr_odatp->name, name, 32);\r
+  u8_cpy(curr_odatp->name, name, 32);\r
 \r
   if(ref_id != -1)\r
     curr_odatp->ref_id = ref_id;\r
@@ -292,7 +311,7 @@ insert_ele_label
    the ref_id to the corresponding odat. */\r
 void\r
 insert_ele_olink\r
-( uint64_t ref_id\r
+( int ref_id\r
 )\r
 {\r
   /* Do nothing because we already know the ref_id that\r
@@ -301,8 +320,8 @@ insert_ele_olink
 \r
 void\r
 insert_ele_vlink\r
-( uint64_t ref_id,\r
-  char* anim_name\r
+( int ref_id,\r
+  uint8_t* anim_name\r
 )\r
 {\r
   struct cdat* curr_cdatp;\r
@@ -320,13 +339,13 @@ insert_ele_vlink
   curr_linkp->set_idx = curr_cdatp->num_sets;\r
   //curr_linkp->ele_idx = curr_setp->num_ele;\r
   curr_linkp->link_t.vlink.ref_id = ref_id;\r
-  memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
+  u8_cpy(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
 \r
 }\r
 \r
 void\r
 insert_ele_svlink\r
-( uint64_t ref_id\r
+( int ref_id\r
 )\r
 {\r
   struct cdat* curr_cdatp;\r
@@ -350,7 +369,7 @@ insert_ele_svlink
 void\r
 insert_ele()\r
 {\r
-  uint64_t ref_id;\r
+  int ref_id;\r
   struct cdat* curr_cdatp;\r
   struct odat* curr_odatp;\r
   struct vdat* curr_vdatp;\r
@@ -371,6 +390,7 @@ insert_ele()
   /* Populate odat for ele */\r
   curr_odatp->cdat_idx = curr_cdatp->idx;\r
   curr_odatp->refp = curr_refp;\r
+  curr_odatp->parent_odatp = curr_set_odatp;\r
 \r
   ref_id = curr_odatp->ref_id;\r
 \r
@@ -390,76 +410,125 @@ insert_ele_vdatid
 }\r
 \r
 void\r
-insert_quad\r
-( void* quad_filep\r
-)\r
+insert_vdat\r
+(uint8_t* filename, int height, int width, uint8_t* filepath)\r
 {\r
-  struct odat* curr_odatp;\r
-\r
-  curr_odatp->quad_filep = quad_filep;\r
-}\r
-\r
-/* Inserting the hitbox into the set\r
-   odat. Elements that don't have\r
-   a hitbox will use the sets root. */\r
-void\r
-insert_hitbox\r
-( int hitbox\r
-)\r
-{ struct odat* curr_odatp;\r
-\r
-  curr_odatp = curr_odat();\r
-  curr_odatp->hitbox = hitbox;\r
-}\r
+  struct vdat* curr_vdatp;\r
+  int filename_len, filepath_len;\r
 \r
-/* Inserting the root into the set\r
-   odat. Elements that don't have\r
-   a root will use the sets root. */\r
-void\r
-insert_root\r
-( int x,\r
-  int y,\r
-  int z\r
-)\r
-{ struct odat* curr_odatp;\r
+  curr_vdatp = alloc_vdat();\r
 \r
-  curr_odatp = curr_odat();\r
-  curr_odatp->root.x = x;\r
-  curr_odatp->root.y = y;\r
-  curr_odatp->root.z = z;\r
+  u8_strcpy(curr_vdatp->filename, filename);\r
+  u8_strcpy(curr_vdatp->filepath, filepath);\r
+  curr_vdatp->height = height;\r
+  curr_vdatp->width = width;\r
+  curr_vdatp->creator = curr_odat();\r
+  \r
 }\r
 \r
 \r
 void\r
-insert_framesheet\r
-( char direction,\r
-  char* name,\r
-  uint64_t ref_id,\r
-  int height ,\r
-  int width,\r
-  int num_frames\r
-)\r
-{ struct vdat* curr_vdatp;\r
-  struct model* curr_modelp;\r
+insert_variant\r
+(uint8_t* filename, int height, int width, uint8_t* filepath)\r
+{ struct variant* curr_variantp;\r
+  int x, y, pixel, num_frames, n;\r
+  int* pixel_buf;\r
+  \r
+  /* Allocate the mdat */\r
+  curr_variantp = alloc_variant();\r
 \r
-  curr_vdatp = curr_vdat();\r
-  curr_modelp = curr_model();\r
+  u8_strcpy(curr_variantp->filename, filename);\r
+  u8_strcpy(curr_variantp->filepath, filepath);\r
+  curr_variantp->height = height;\r
+  curr_variantp->width = width;\r
 \r
-  curr_modelp->spritesheet[(int)direction].height = height;\r
-  curr_modelp->spritesheet[(int)direction].width = width;\r
-  curr_modelp->spritesheet[(int)direction].num_frames = num_frames;\r
-  curr_vdatp->num_models++;\r
-}\r
-\r
-void\r
-insert_frame_pointer\r
-( char direction,\r
-  void* frame\r
-)\r
-{ struct model* curr_modelp;\r
+  //curr_mdatp->quad_list[num_quads].x/.y/.z/ref_id */\r
 \r
-  curr_modelp = curr_model();\r
 \r
-  curr_modelp->spritesheet[(int)direction].frames[curr_modelp->spritesheet[(int)direction].num_frames++] = frame;\r
+  curr_set_odatp->variant_list[curr_set_odatp->vli++] = curr_variantp;\r
 }\r
+  \r
+\r
+/* void */\r
+/* insert_quad */\r
+/* ( int x, int y, int z, int ref_id */\r
+/* ) */\r
+/* { */\r
+/*   struct quad* curr_quadp; */\r
+\r
+/*   curr_quadp = curr_quad(); */\r
+\r
+/*   curr_quadp->x = x; */\r
+/*   curr_quadp->y = y; */\r
+/*   curr_quadp->z = z; */\r
+/*   curr_quadp->ref_id = ref_id; */\r
+  \r
+\r
+\r
+/* } */\r
+\r
+/* /\* serting the hitbox into the set */\r
+/*    odat. Elements that don't have */\r
+/*    a hitbox will use the sets root. *\/ */\r
+/* void */\r
+/* insert_hitbox */\r
+/* ( int hitbox */\r
+/* ) */\r
+/* { struct odat* curr_odatp; */\r
+\r
+/*   curr_odatp = curr_odat(); */\r
+/*   curr_odatp->hitbox = hitbox; */\r
+/* } */\r
+\r
+/* /\* Inserting the root into the set */\r
+/*    odat. Elements that don't have */\r
+/*    a root will use the sets root. *\/ */\r
+/* void */\r
+/* insert_root */\r
+/* ( int x, */\r
+/*   int y, */\r
+/*   int z */\r
+/* ) */\r
+/* { struct odat* curr_odatp; */\r
+\r
+/*   curr_odatp = curr_odat(); */\r
+/*   curr_odatp->root.x = x; */\r
+/*   curr_odatp->root.y = y; */\r
+/*   curr_odatp->root.z = z; */\r
+/* } */\r
+\r
+\r
+\r
+/* void */\r
+/* insert_framesheet */\r
+/* ( uint8_t direction, */\r
+/*   uint8_t* name, */\r
+/*   int ref_id, */\r
+/*   int height , */\r
+/*   int width, */\r
+/*   int num_frames */\r
+/* ) */\r
+/* { struct vdat* curr_vdatp; */\r
+/*   struct model* curr_modelp; */\r
+\r
+/*   curr_vdatp = curr_vdat(); */\r
+/*   curr_modelp = curr_model(); */\r
+\r
+/*   curr_modelp->spritesheet[(int)direction].height = height; */\r
+/*   curr_modelp->spritesheet[(int)direction].width = width; */\r
+/*   curr_modelp->spritesheet[(int)direction].num_frames = num_frames; */\r
+/*   curr_vdatp->num_models++; */\r
+/* } */\r
+\r
+/* void */\r
+/* insert_frame_pointer */\r
+/* ( uint8_t direction, */\r
+/*   void* frame */\r
+/* ) */\r
+/* { struct model* curr_modelp; */\r
+\r
+/*   curr_modelp = curr_model(); */\r
+\r
+/*   curr_modelp->spritesheet[(int)direction].frames[curr_modelp->spritesheet[(int)direction].num_frames++] = frame; */\r
+/* } */\r
 \r