Fix endian swaps, so makeobj works on big-endian machines. Fix simgraph16.cc for big-endian platforms. The code assumed that tile_dirty had little-endian byte order. The assignment to const *sp was a compiler error. Index: descriptor/writer/image_writer.cc --- descriptor/writer/image_writer.cc.orig +++ descriptor/writer/image_writer.cc @@ -81,7 +81,7 @@ static uint16 pixrgb_to_pixval(uint32 rgb) // else store color as 3 red, 4, green, 3 red pix = ((rgb >> 14) & 0x0380) | ((rgb >> 9) & 0x0078) | ((rgb >> 5) & 0x07); pix = 0x8020 + 31*31 + pix*31 + alpha; - return endian(pix); + return pix; } @@ -89,7 +89,7 @@ static uint16 pixrgb_to_pixval(uint32 rgb) for (int i = 0; i < SPECIAL; i++) { if (image_t::rgbtab[i] == (uint32)rgb) { pix = 0x8000 + i; - return endian(pix); + return pix; } } @@ -99,7 +99,7 @@ static uint16 pixrgb_to_pixval(uint32 rgb) // RGB 555 pix = ((r & 0xF8) << 7) | ((g & 0xF8) << 2) | ((b & 0xF8) >> 3); - return endian(pix); + return pix; } @@ -192,8 +192,8 @@ uint16 *image_writer_t::encode_image(int x, int y, dim PIXVAL pixval = pixrgb_to_pixval(pix); if( pixval >= 0x8020 && !has_transparent ) { if( count ) { - *colored_run_counter = endian(count); - *dest++ = endian(0x8000); + *colored_run_counter = endian(uint16(count)); + *dest++ = endian(uint16(0x8000)); colored_run_counter = dest++; count = 0; } @@ -201,14 +201,14 @@ uint16 *image_writer_t::encode_image(int x, int y, dim } else if( pixval < 0x8020 && has_transparent ) { if( count ) { - *colored_run_counter = endian(count+has_transparent); - *dest++ = endian(0x8000); + *colored_run_counter = endian(uint16(count+has_transparent)); + *dest++ = endian(uint16(0x8000)); colored_run_counter = dest++; count = 0; } has_transparent = 0; } - *dest++ = pixval; + *dest++ = endian(uint16(pixval)); count++; if (row_px_count >= img_width) { // end of line ? break; @@ -226,7 +226,7 @@ uint16 *image_writer_t::encode_image(int x, int y, dim // this only happens at the end of a line, so no need to increment clear_colored_run_pair_count } else { - *colored_run_counter = endian(count + has_transparent); + *colored_run_counter = endian(uint16(count + has_transparent)); clear_colored_run_pair_count++; } } while( row_px_count < img_width ); Index: descriptor/writer/obj_node.cc --- descriptor/writer/obj_node.cc.orig +++ descriptor/writer/obj_node.cc @@ -50,7 +50,7 @@ void obj_node_t::write(FILE* fp) fseek(fp, write_offset - OBJ_NODE_INFO_SIZE, SEEK_SET); uint32 type = endian(desc.type); uint16 children = endian(desc.children); - uint16 size16 = endian(desc.size); + uint16 size16 = endian(uint16(desc.size)); fwrite(&type, 4, 1, fp); fwrite(&children, 2, 1, fp); fwrite(&size16, 2, 1, fp); @@ -60,7 +60,7 @@ void obj_node_t::write(FILE* fp) fseek(fp, write_offset - EXT_OBJ_NODE_INFO_SIZE, SEEK_SET); uint32 type = endian(desc.type); uint16 children = endian(desc.children); - uint16 size16 = endian(LARGE_RECORD_SIZE); + uint16 size16 = endian(uint16(LARGE_RECORD_SIZE)); uint32 size = endian(desc.size); fwrite(&type, 4, 1, fp); fwrite(&children, 2, 1, fp); Index: display/simgraph16.cc --- display/simgraph16.cc.orig +++ display/simgraph16.cc @@ -981,7 +981,7 @@ static inline void mark_tile_dirty(const int x, const #if 0 assert(bit / 8 < tile_buffer_length); #endif - ((uint8*)tile_dirty)[bit >> 3] |= 1 << (bit & 7); + tile_dirty[bit >> 5] |= 1 << (bit & 31); } @@ -1012,7 +1012,7 @@ static void mark_rect_dirty_nc(KOORD_VAL x1, KOORD_VAL int bit = y1 * tile_buffer_per_line + x1; const int end = bit + x2 - x1; do { - ((uint8*)tile_dirty)[bit >> 3] |= 1 << (bit & 7); + tile_dirty[bit >> 5] |= 1 << (bit & 31); } while( ++bit <= end ); } } @@ -2485,7 +2485,7 @@ static void display_img_nc(KOORD_VAL h, const KOORD_VA #ifdef SIM_BIG_ENDIAN // low level c++ without any unrolling while( runlen-- ) { - *sp++ = *p++; + *p++ = *sp++; } #else // trying to merge reads and writes