char MOD_IO2::ReadMultipleIadr(unsigned char R_ADDR, char * buffer, unsigned char NumOfBytes) { unsigned char aflag; if(NumOfBytes==1) { buffer[0] = ReadSingleIadr(R_ADDR, aflag); return (!aflag); } else { Start(); aflag = WriteSingle(SL_WRITE); aflag|= WriteSingle(R_ADDR); Stop(); Start(); aflag|= WriteSingle(SL_READ); for(int i=0; i<NumOfBytes-1; i++) buffer[i] = ReadSingle(ACK); buffer[NumOfBytes-1] = ReadSingle(NACK); Stop(); return (!aflag); } }
Vector2 PacketReader::ReadVector2() { return Vector2( ReadSingle(), ReadSingle() ); }
Vector3 PacketReader::ReadVector3() { return Vector3( ReadSingle(), ReadSingle(), ReadSingle() ); }
Quaternion PacketReader::ReadQuaternion() { return Quaternion( ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle() ); }
Vector4 PacketReader::ReadVector4() { return Vector4( ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle() ); }
/* * Loader for AAA files */ int LoadAAA(string filename, KeyframeAnimation& anim) { ifstream file(filename.c_str(), ios::in | ios::binary); if(!file) return 1; unsigned char anim_name_len = ReadByte(file); string anim_name = ""; for(unsigned int i = 0; i < anim_name_len; ++i) anim_name += ReadByte(file); unsigned int frame_count = ReadUInt32(file); vector<Keyframe> frames = vector<Keyframe>(); for(unsigned int i = 0; i < frame_count; ++i) { Keyframe frame = Keyframe(); frame.next = ReadInt32(file); frame.duration = ReadSingle(file); unsigned int bone_count = ReadUInt32(file); for(unsigned int j = 0; j < bone_count; ++j) { string bone_name = ""; unsigned char bone_name_len = ReadByte(file); for(unsigned int k = 0; k < bone_name_len; ++k) bone_name += ReadByte(file); Vec3 ori; ori.x = ReadSingle(file); ori.y = ReadSingle(file); ori.z = ReadSingle(file); Vec3 pos; pos.x = ReadSingle(file); pos.y = ReadSingle(file); pos.z = ReadSingle(file); frame.values[Bone::string_table[bone_name]] = BoneInfluence(ori, pos, 1.0f); } frames.push_back(frame); } anim.name = anim_name; anim.frames = frames; return 0; }
char MOD_IO2::ReadSingleIadr(unsigned char R_ADDR, unsigned char &aPtr) { unsigned char aflag; char data; Start(); aflag = WriteSingle(SL_WRITE); aflag|= WriteSingle(R_ADDR); Stop(); Start(); aflag|= WriteSingle(SL_READ); data = ReadSingle(NACK); Stop(); aPtr = aflag; return data; }
void CSvnProp::Read(const char* data, const char* dataEnd) { //Read 'copy from' data //Rev std::string value; for(;data != dataEnd && !IsEnd(*data); ++data) value += *data; m_copyFromRev = atoi(value.c_str()); //Path Skip(&data, dataEnd); value.clear(); for(;data != dataEnd && !IsEnd(*data); ++data) value += *data; m_copyFromPath = value; //Props Skip(&data, dataEnd); while(data != dataEnd) data = ReadSingle(data, dataEnd); }
/* ======================================================================================================================= ======================================================================================================================= */ void InterruptHandlerReader(unsigned char *Register) { /*~~~~~~~~~~~~~~~~*/ /* * char phello[20]; * //for testing */ unsigned char len; /*~~~~~~~~~~~~~~~~*/ /* * Register = Register & 0xF7; * //set the parity flag to 0 ; * parity is not used in 15693 and Tag-It */ #if DBG Put_byte(*Register); #endif if(*Register == 0xA0) { /* TX active and only 3 bytes left in FIFO */ i_reg = 0x00; #if DBG kputchar('.'); /* FIFO filling is done in the transmit function */ #endif } else if(*Register == BIT7) { /* TX complete */ i_reg = 0x00; *Register = Reset; /* reset the FIFO after TX */ DirectCommand(Register); #if DBG kputchar('T'); #endif } else if((*Register & BIT1) == BIT1) { /* collision error */ i_reg = 0x02; /* RX complete */ // *Register = StopDecoders; /* reset the FIFO after TX */ // DirectCommand(Register); CollPoss = CollisionPosition; ReadSingle(&CollPoss, 1); // *Register = 0x0c; // ReadSingle(Register, 1); /* * CollPoss &= 0xF7; */ len = CollPoss - 0x20; /* number of valid bytes if FIFO */ if(!POLLING) { kputchar('{'); Put_byte(CollPoss); kputchar('}'); } if((len & 0x0f) != 0x00) len = len + 0x10; /* add 1 byte if broken byte recieved */ len = len >> 4; if(len != 0x00) { buf[RXTXstate] = FIFO; /* write the recieved bytes to the correct place of the * buffer; * */ ReadCont(&buf[RXTXstate], len); RXTXstate = RXTXstate + len; } /* if */ *Register = StopDecoders; /* reset the FIFO after TX */ DirectCommand(Register); *Register = Reset; DirectCommand(Register); *Register = IRQStatus; /* IRQ status register address */ *(Register + 1) = IRQMask; //ReadSingle(Register, 2); /* function call for single address read */ // ReadCont(Register, 2); if (SPIMODE) ReadCont(Register, 2); else ReadSingle(Register, 1); TRF_IRQ_CLEAR(); }
Matrix PacketReader::ReadMatrix() { Matrix matrix; matrix.M11 = ReadSingle(); matrix.M12 = ReadSingle(); matrix.M13 = ReadSingle(); matrix.M14 = ReadSingle(); matrix.M21 = ReadSingle(); matrix.M22 = ReadSingle(); matrix.M23 = ReadSingle(); matrix.M24 = ReadSingle(); matrix.M31 = ReadSingle(); matrix.M32 = ReadSingle(); matrix.M33 = ReadSingle(); matrix.M34 = ReadSingle(); matrix.M41 = ReadSingle(); matrix.M42 = ReadSingle(); matrix.M43 = ReadSingle(); matrix.M44 = ReadSingle(); return matrix; }
/* * Loader for AAK files */ int LoadAAK(string filename, vector<MaterialModelPair>& material_model_pairs, vector<string>& material_names, Skeleton*& skeleton) { ifstream file(filename.c_str(), ios::in | ios::binary); if(!file) return 1; unsigned int materials_count = ReadUInt32(file); for(unsigned int i = 0; i < materials_count; ++i) { unsigned int mat_name_len = ReadByte(file); string mat_name = ""; for(unsigned int j = 0; j < mat_name_len; ++j) mat_name += ReadByte(file); material_names.push_back(mat_name); VertexBuffer* vbo = new VertexBuffer(Triangles); MaterialModelPair mmp = MaterialModelPair(); mmp.material_index = i; mmp.vbo = vbo; unsigned int vinfo_count = ReadUInt32(file); int target = 0; SkinVInfo tri[3]; vbo->SetAllocatedSize(vinfo_count); for(unsigned int j = 0; j < vinfo_count; ++j) { float x = ReadSingle(file); float y = ReadSingle(file); float z = ReadSingle(file); float u = ReadSingle(file); float v = ReadSingle(file); float nx = ReadSingle(file); float ny = ReadSingle(file); float nz = ReadSingle(file); unsigned char indices[4]; unsigned char weights[4]; for(int k = 0; k < 4; ++k) { indices[k] = ReadByte(file); weights[k] = ReadByte(file); } tri[target++] = SkinVInfo(Vec3(x, y, z), Vec3(u, v, 0.0f), Vec3(nx, ny, nz), indices, weights); if(target == 3) { AddTriangleVertexInfo(vbo, tri[0], tri[1], tri[2]); target = 0; } } material_model_pairs.push_back(mmp); } Skeleton* temp_skel; Skeleton::ReadSkeleton(file, &temp_skel); skeleton = temp_skel; return 0; }
/* * Loader for AAM models */ int LoadAAM(string filename, VertexBuffer* vbo) { ifstream file(filename.c_str(), ios::in | ios::binary); if(!file) return 1; // loading the compressed form of the data vector<Vec3> vertices = vector<Vec3>(); vector<Vec3> texcoords = vector<Vec3>(); vector<Vec3> normals = vector<Vec3>(); unsigned int vertex_count = ReadUInt32(file); for(unsigned int i = 0; i < vertex_count; ++i) { float x = ReadSingle(file); float y = ReadSingle(file); float z = ReadSingle(file); vertices.push_back(Vec3(x, y, z)); } unsigned int texcoord_count = ReadUInt32(file); for(unsigned int i = 0; i < texcoord_count; ++i) { float u = ReadSingle(file); float v = ReadSingle(file); texcoords.push_back(Vec3(u, v, 0)); // third texcoord always 0 } unsigned int normal_count = ReadUInt32(file); for(unsigned int i = 0; i < normal_count; ++i) { float x = ReadSingle(file); float y = ReadSingle(file); float z = ReadSingle(file); normals.push_back(Vec3(x, y, z)); } // load and apply the decompression indices unsigned int vinfo_count = ReadUInt32(file); VTNTT verts[3]; int target_vert = 0; vbo->SetAllocatedSize(vinfo_count); for(unsigned int i = 0; i < vinfo_count; ++i) { unsigned int x_index = ReadUInt32(file); unsigned int uv_index = ReadUInt32(file); unsigned int n_index = ReadUInt32(file); verts[target_vert++] = VTNTT(vertices[x_index], texcoords[uv_index], normals[n_index]); if(target_vert == 3) { AddTriangleVertexInfo(vbo, verts[0], verts[1], verts[2]); target_vert = 0; } } file.close(); // success! return 0; }