source: thomson/tools/decb.cpp@ 5095d40

main
Last change on this file since 5095d40 was 5095d40, checked in by Adrien Destugues <pulkomandy@…>, 9 years ago

Binxploder: split out decb handling.

  • It will soon be used in other tools.

git-svn-id: svn://localhost/thomson@58 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

  • Property mode set to 100644
File size: 762 bytes
Line 
1/* DECB - parse DECB file format.
2 * Copyright 2013-2015, Adrien Destugues <pulkomandy@pulkomandy.tk>
3 * This file is distributed under the terms of the MIT Licence.
4 */
5
6#include <vector>
7
8#include <arpa/inet.h>
9
10struct __attribute__((packed)) DECB_Chunk {
11 uint8_t type;
12 uint16_t length;
13 uint16_t addr;
14 std::vector<uint8_t> data;
15};
16
17
18bool DECB_ReadChunk(FILE* in, DECB_Chunk& out) {
19 // Read the chunk header
20 int value = fread(&out, 5, 1, in);
21 if (value == 0)
22 return false;
23
24 // 6809 is little endian, take that into account...
25 out.length = ntohs(out.length);
26 out.addr = ntohs(out.addr);
27
28 // Resize the data member to the proper size and read the data to it.
29 out.data.reserve(out.length);
30 fread(&out.data[0], out.length, 1, in);
31
32 return true;
33};
Note: See TracBrowser for help on using the repository browser.