Changeset 5095d40 in thomson


Ignore:
Timestamp:
Mar 13, 2015, 10:12:59 PM (9 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
b3195d1
Parents:
2ee52fb
Message:

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

Location:
tools
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • tools/binxploder.cpp

    r2ee52fb r5095d40  
    33 * This file is distributed under the terms of the MIT Licence.
    44 */
    5 
    6 #include <arpa/inet.h>
    75
    86#include <stdint.h>
     
    119#include <string.h>
    1210
    13 struct __attribute__((packed)) Header {
    14         uint8_t type;
    15         uint16_t length;
    16         uint16_t addr;
    17 };
     11#include "decb.cpp"
    1812
    1913int main(int argc, char* argv[])
    2014{
    21         FILE* f1, * f2;
    22         Header h;
    23 
    2415        if (argc < 2)
    2516        {
     
    2819        }
    2920
     21        FILE* f1, * f2;
     22        uint8_t i = 0;
     23        DECB_Chunk h;
     24
    3025        f1 = fopen(argv[1], "rb");
     26        char* buf = (char*)malloc(strlen(argv[1] + 3));
    3127
    32         char* buf = (char*)malloc(strlen(argv[1] + 3));
    33         uint8_t i;
    34 
    35         while(fread(&h, sizeof(h), 1, f1))
     28        while(DECB_ReadChunk(f1, h))
    3629        {
    37                 // 6809 is little endian, take that into account...
    38                 h.length = ntohs(h.length);
    39                 h.addr = ntohs(h.addr);
    40 
    4130                printf("Type: %02x - Size: %04x - Load: %04x\n", h.type, h.length, h.addr);
    4231
     
    4433                f2 = fopen(buf, "wb");
    4534
    46                 char* b2 = (char*)malloc(h.length);
    47                 fread(b2, h.length, 1, f1);
    48                 fwrite(b2, h.length, 1, f2);
     35                fwrite(&h.data[0], h.length, 1, f2);
    4936
    50                 free(b2);
    5137                fclose(f2);
    5238        }
Note: See TracChangeset for help on using the changeset viewer.