AROS World Exec

Development => Development (General) => Topic started by: aGGreSSor on November 05, 2020, 02:56:33 PM

Title: Strange behavior DrawImage() in AROS (SOLVED)
Post by: aGGreSSor on November 05, 2020, 02:56:33 PM
I have compiled two versions of the classic example  on using the function ImageDraw() in Intuition: old from AmigaOS 3 and new for AmigaOS 4.

simpleimage.c work in AmigaOS 3:
(https://i.postimg.cc/L5mj7ZTZ/simpleimage-os3.png)

but simpleimage.c don't work in AROS (AROS One and IcarOS)
(https://i.postimg.cc/gkSBVYzK/simpleimage-i386-aros.png)

simpleimage_os4.c work in AmigaOS 4:
(https://i.postimg.cc/vBZQNYnZ/simpleimage-os4.png)

I think I've already met this error 20 years ago, but then it was on a real amiga and it was about placing the image in the chip memory.
I went through all the memory type from exec/memory.h and didn't achieve the result..

Unfortunately, this prevents compilation of old good Workbench applications.
I would like to understand why this is happening. Source and executable files included.
Title: Re: Strange behavior DrawImage() in AROS
Post by: deadwood on November 05, 2020, 03:19:07 PM
My first bet would be that it is endianess related. The image is collection of WORDs. Try flipping the bytes in each element of the array.
Title: Re: Strange behavior DrawImage() in AROS
Post by: aGGreSSor on November 05, 2020, 04:21:21 PM
My first bet would be that it is endianess related. The image is collection of WORDs. Try flipping the bytes in each element of the array.
Oh, you are absolutely right!

I flipped the bytes:
Code: [Select]
#ifdef __AROS__       // little-endian (i386, x86_64)
WORD myImageData[] =
    {
    0xFFFF, 0x00FF,
    0x00C0, 0x0003,
    0x00C0, 0x0003,
    0x00C0, 0x0003,
    0x00C0, 0x0003,
    0x00C0, 0x0003,
    0x00C0, 0x0003,
    0x00C0, 0x0003,
    0x00C0, 0x0003,
    0xFFFF, 0x00FF,
    };
#else                  // Big-endian (m68, ppc)
WORD myImageData[] =
    {
    0xFFFF, 0xFF00,
    0xC000, 0x0300,
    0xC000, 0x0300,
    0xC000, 0x0300,
    0xC000, 0x0300,
    0xC000, 0x0300,
    0xC000, 0x0300,
    0xC000, 0x0300,
    0xC000, 0x0300,
    0xFFFF, 0xFF00,
    };
#endif

and got what I wanted:
(https://i.postimg.cc/J0Y4Qh5j/simpleimage-new.png)

Thank you!
Title: Re: Strange behavior DrawImage() in AROS (SOLVED)
Post by: Mazze on December 25, 2020, 02:41:23 PM
I recommend
#if AROS_BIG_ENDIAN (#if, not #ifdef ! )
https://aros.sourceforge.io/documentation/developers/app-dev/portable.php#endianness

If you check for only for __AROS__ you'll get wrong endianess on 68k.
Title: Re: Strange behavior DrawImage() in AROS (SOLVED)
Post by: aGGreSSor on December 26, 2020, 01:23:13 AM
I recommend
#if AROS_BIG_ENDIAN (#if, not #ifdef ! )
https://aros.sourceforge.io/documentation/developers/app-dev/portable.php#endianness

If you check for only for __AROS__ you'll get wrong endianess on 68k.
Thank you! I didn't know that, I will take note.