From 0641cbc58f607b57df2a8f70d368bb5bef4f31d4 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Tue, 19 May 2015 12:57:17 +0200 Subject: Clean up record dumper for version 2 to better match documentation --- src/export/split_version_2.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/export/split_version_2.c b/src/export/split_version_2.c index 324e61d..54e2313 100644 --- a/src/export/split_version_2.c +++ b/src/export/split_version_2.c @@ -98,16 +98,16 @@ static void finish_record( ) { g_state.outbuf[file][g_state.outfill[file]++] = '\n'; } -static uint16_t load_word( uint8_t *table_start, uint16_t base, int offset ) { +static uint16_t load_word( uint8_t *record, uint16_t base, int offset ) { int dword_offset = offset >> 1; /* If a word(subflag, t_off) would span over the end of a 0x4000 byte page, it is placed on the next page. All other words are shifted backwards, as well. */ if( base + 4 + 4 * dword_offset > 0x1ffc ) - table_start += 3 & ( 4 - ( base & 3 ) ); + record += 3 & ( 4 - ( base & 3 ) ); - return ((uint16_t*)table_start)[offset + 2]; + return ((uint16_t*)record)[offset + 2]; } static void dump_primary( uint8_t *end, uint32_t flags ) { @@ -158,27 +158,26 @@ static void dump_primary( uint8_t *end, uint32_t flags ) { dump_field( &end, 15 ); } -static void act_on_record( uint8_t * end, uint16_t base ) { - uint16_t *rec = (uint16_t*)end; - uint8_t *e = end; - uint16_t num_dwords = rec[0]; - uint16_t flagbytes = rec[1]; +static void act_on_record( uint8_t * rec, uint16_t base ) { + uint16_t entries = ((uint16_t*)rec)[0]; + uint16_t flagbytes = ((uint16_t*)rec)[1]; uint32_t flags = 0; + uint8_t *end = rec; int i; while(flagbytes--) flags = (flags<<8) | *--end; -// printf( "-------- %03d: %06X\n", num_dwords, flags ); - for (i = 0; i < num_dwords; i++ ) { - uint16_t subflag = load_word( e, base, 2*i ); - uint16_t t_off = load_word( e, base, 2*i+1 ); + //printf( "-------- %03d: %06X\n", entries, flags ); + for (i = 0; i < entries; i++ ) { + uint16_t subflag = load_word( rec, base, 2*i ); + uint16_t t_off = load_word( rec, base, 2*i+1 ); uint8_t *rec_start = end - t_off; if (i == 0) { - dump_string( num_dwords > 1 ? (uint8_t*)"01" : (uint8_t*)"00", 2, 0 ); + dump_string( entries > 1 ? (uint8_t*)"01" : (uint8_t*)"00", 2, 0 ); dump_primary( rec_start, flags ); } else { - uint8_t * rec_end = end - ( ( i+1 == num_dwords ) ? 0 : load_word( e, base, 2*i+3 ) ); + uint8_t * rec_end = end - ( ( i+1 == entries ) ? 0 : load_word( rec, base, 2*i+3 ) ); int file = g_outfilemap[g_cd][subflag&0x1F]; if( subflag == 0x4003 ) { finish_record(); -- cgit v1.2.3