English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 11 June 2017, 01:05   #1
Hedeon
Semi-Retired
 
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,994
Issue with C and Warp3D

Hi all,

I'm trying to do more in C and less in assembly. I'm also trying to learn Warp3D on the classic amiga.

There are not a lot of examples about, but I got some from http://os4coding.net/forum/warp3d-how-get-started

The sources are from Kas1e. I adapted them to WarpOS.

Now I hit the following issue (and I've bothered phx enough with my stuff so I now bother all of you :-) ):

Inside the simple_texture.c source there is the line:

bm = screen->rastport.bitmap

The program fails with an INVALIDBITMAP error from Warp3D.

Tracing the program during wosdb (thanks phx!) it is shown that the bitmap pointer is actually loaded with a 0x0.

Looking closer it looks like that bm is actually loaded with screen->rastport.bitmap+4. The correct bitmap is loaded if I do a screen->rastport.layer.

Is it my includes or what am I missing here?
Hedeon is offline  
Old 11 June 2017, 11:15   #2
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
I also replied to you by email, but now I guess your only problem might be alignment. Unlike the OS headers of AmigaOS4 and MorphOS, which have proper alignment directives included, you have to make sure yourself that the AmigaOS/68k NDK3.x headers are correctly aligned, when compiling for WarpOS or PowerUp.

With vbcc you have two options:
1. -amiga-align on the command line, makes sure all structures are aligned according to the AmigaOS 68k ABI. Which means fields with size of 16 bits or greater are aligned to 16 bits.
2. Use #pragma amiga-align before including OS headers in your source and #pragma default-align to return to natural PPC alignment. This is the better solution for program performance.

I already sent you this example source, which works fine:
Code:
#pragma amiga-align
#include <intuition/intuitionbase.h>
#include <proto/exec.h>
#include <proto/dos.h>
#pragma default-align

struct IntuitionBase *IntuitionBase;

void printbmptr(struct Screen *scr)
{
  struct BitMap *bm = scr->RastPort.BitMap;

  Printf("Bitmap is %08lx\n",(ULONG)bm);
}

int main(void)
{
  if (IntuitionBase = (struct IntuitionBase *)
                      OpenLibrary("intuition.library",0)) {
    printbmptr(IntuitionBase->ActiveScreen);
    CloseLibrary((struct Library *)IntuitionBase);
  }
  return 0;
}
In the assembler output you see that, thanks to #pragma amiga-align, the offset to the bitmap pointer is correct (0x54+4 = 88):
Code:
_printbmptr:
        mflr    r11
        stwu    r1,-32(r1)
        stw     r11,40(r1)
        mr      r9,r3
        lwz     r10,88(r9)
        stw     r10,28(r1)
        lwz     r3,@_l2(r2)
        bl      _Printf
        lwz     r11,40(r1)
        addi    r1,r1,32
        mtlr    r11
        blr

Last edited by phx; 11 June 2017 at 11:18. Reason: to -> two ;)
phx is offline  
Old 11 June 2017, 12:49   #3
Hedeon
Semi-Retired
 
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,994
Thanks phx, that did the trick. Bitmap is loaded correctly now!

Do the standard includes like stdio.h also need this?
Hedeon is offline  
Old 11 June 2017, 21:35   #4
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
No. Compilers headers know their architecture, of course!
phx is offline  
Old 11 June 2017, 22:50   #5
Hedeon
Semi-Retired
 
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,994
Does it do harm to put ALL includes between those two pragmas? Or does that give me a whole lot of other problems?
Hedeon is offline  
Old 12 June 2017, 09:30   #6
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Only the OS-headers, which are used by the 68k ROM code must be 16-bit aligned. The rest is PPC-native and must not be 16-bit aligned, otherwise functions in the C-library (vclib) may crash.

You may get away with it, though, as there are not many structures in the standard headers (so a global -amiga-align switch usually works). But I wouldn't do that.

For your own local headers it doesn't matter, as you are recompiling everything using them. You would only degrade performance by bad alignment.
phx is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
PowerUp and Warp3d Zilog request.Other 5 13 August 2014 18:02
warp3d patch? roy bates request.Other 8 02 January 2012 13:35
Warp3d woes Wasagi support.Hardware 13 02 December 2010 19:55
Warp3D in WinUAE !!! RetroMan Amiga scene 17 21 July 2003 21:18
Warp3D and Amithlon Ivan Castle New to Emulation or Amiga scene 2 29 December 2002 18:12

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 19:17.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.11575 seconds with 13 queries