English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 11 December 2009, 00:24   #1
NovaCoder
Registered User
 
NovaCoder's Avatar
 
Join Date: Sep 2007
Location: Melbourne/Australia
Posts: 4,400
AGA C2P....help!

I'm currently trying to stick someone's assembler C2P routine into my C++ project, I think I've now got the bugger to link properly but it's not actually working yet.


As I'm crap at assembler can someone have a look at the attached routines and tell me (a) what I should be passing as arguments and (b) if any better routines exist.

http://home.iprimus.com.au/novacoder/c2p_030.h
http://home.iprimus.com.au/novacoder/c2p_030.s
http://home.iprimus.com.au/novacoder/c2p_030.o

The init method seems to work ok (as in it doesn't crash).

Code:
extern "C" void c2p1x1_cpu3blit1_queue_init (
                      UWORD chunkyx,  // width
                      UWORD chunkyy,  // height
                      UWORD scroffsy, // y offset
                      ULONG bplsize,  // modulo to next plane
                      ULONG signals1,
                      ULONG signals3,
                      struct Task *thistask,
                      struct Task *other
But this sucker just crashes my system though (causes a restart!).
Code:
extern "C" void c2p1x1_cpu3blit1_queue (
                      UBYTE *c2pscreen,
                      UBYTE *bitplanes);
This was borrowed from ADoom BTW.

Thanks

Last edited by NovaCoder; 11 December 2009 at 00:31.
NovaCoder is offline  
Old 11 December 2009, 00:38   #2
NovaCoder
Registered User
 
NovaCoder's Avatar
 
Join Date: Sep 2007
Location: Melbourne/Australia
Posts: 4,400
In particular I'm having trouble with the c2pscreen argument, not sure what that should be.
NovaCoder is offline  
Old 11 December 2009, 00:49   #3
korruptor
TDI
 
korruptor's Avatar
 
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
Pointer to the chunky buffer?
korruptor is offline  
Old 11 December 2009, 01:08   #4
NovaCoder
Registered User
 
NovaCoder's Avatar
 
Join Date: Sep 2007
Location: Melbourne/Australia
Posts: 4,400
Quote:
Originally Posted by korruptor View Post
Pointer to the chunky buffer?
Well that's what I assumed but it just hangs.

I'm doing this for a 320x200 bit bit chunky display:

Code:
 static byte *backBuffer;
 
 backBuffer=(byte*)malloc(64000);
The back buffer is then used by the following method:

Code:
void I_FinishUpdate ()
{
  int top, left, width, height;
  total_frames++;
 

    left = 0;
    top = 0;
    width = SCREENWIDTH;
    height = SCREENHEIGHT;

  if (video_is_native_mode) {
    if (video_is_using_blitter) {
      start_timer();
      Wait (1 << video_sigbit1); /* wait for prev c2p() to finish pass 3 */
      blit_time += end_timer();
      if (video_blit_is_in_progress) {
   start_timer();
   Wait (SIGBREAKF_CTRL_F); /* wait for prev ChangeScreenBuffer() safe */
   safe_time += end_timer();
   video_blit_is_in_progress = FALSE;
      }
      video_which = 1 - video_which;  /* render to the hidden bitmap */
      start_timer();
      c2p1x1_cpu3blit1_queue (backBuffer, video_raster[video_which]);
      c2p_time += end_timer();
      video_blit_is_in_progress = TRUE;
    }
  }
}
And it crashes on the call to 'c2p1x1_cpu3blit1_queue'.
NovaCoder is offline  
Old 11 December 2009, 13:09   #5
Kalms
Registered User
 
Join Date: Nov 2006
Location: Stockholm, Sweden
Posts: 237
The C code sends the arguments on the stack, but the assembly code expects them in registers.

Either

A) change the C function prototype to specify register locations for all arguments (exact syntax is compiler dependent)

or

B) change the assembly code to load register contents from the stack.
Kalms is offline  
Old 11 December 2009, 22:54   #6
NovaCoder
Registered User
 
NovaCoder's Avatar
 
Join Date: Sep 2007
Location: Melbourne/Australia
Posts: 4,400
Quote:
Originally Posted by Kalms View Post
The C code sends the arguments on the stack, but the assembly code expects them in registers.

Either

A) change the C function prototype to specify register locations for all arguments (exact syntax is compiler dependent)

or

B) change the assembly code to load register contents from the stack.
Yep that seems to be the problem, the code below *might* work for straight c but won't compile in c++

Code:
#ifndef __GNUC__
#define REG(reg,arg) register __##reg arg
#else
#define REG(reg,arg) arg __asm(#reg)
#endif
 
 
extern void c2p1x1_cpu3blit1_queue_init (
REG(d0, UWORD chunkyx), // width
REG(d1, UWORD chunkyy), // height
REG(d3, UWORD scroffsy), // y offset
REG(d5, ULONG bplsize), // modulo to next plane
REG(d6, ULONG signals1),
REG(d7, ULONG signals3),
REG(a2, struct Task *thistask),
REG(a3, struct Task *othertask),
REG(a4, UBYTE *chipbuff));
 
extern void c2p1x1_cpu3blit1_queue (
REG(a0, UBYTE *c2pscreen),
REG(a1, UBYTE *bitplanes));

Last edited by NovaCoder; 12 December 2009 at 00:18.
NovaCoder is offline  
Old 12 December 2009, 00:18   #7
NovaCoder
Registered User
 
NovaCoder's Avatar
 
Join Date: Sep 2007
Location: Melbourne/Australia
Posts: 4,400
Salass00 also come up with this idea:

If you can't use register arguments (IIRC C++ doesn't support this) then you can create small assembler stub functions that take arguments on the stack and put them in the correct registers like this:

Code:
XREF _c2p1x1_cpu3blit1_queue_init 
XREF _c2p1x1_cpu3blit1_queue 
XDEF _c2p1x1_cpu3blit1_queue_init_stub 
XDEF _c2p1x1_cpu3blit1_queue_stub 

_c2p1x1_cpu3blit1_queue_init_stub: 
movem.l 4(a7),d0-d1/d3/d5-d7/a2-a4 
jsr _c2p1x1_cpu3blit1_queue_init 
rts 

_c2p1x1_cpu3blit1_queue_stub 
movem.l 4(a7),a0-a1 
jsr _c2p1x1_cpu3blit1_queue 
rts


Then in your C++ code you use these two functions instead:

Code:
extern "C" void c2p1x1_cpu3blit1_queue_init_stub (UWORD chunkyx, UWORD chunkyy, UWORD scroffsy, ULONG bplsize, ULONG signals1, ULONG signals3, struct Task *thistask, struct Task *othertask, UBYTE *chipbuff);

extern "C" void c2p1x1_cpu3blit1_queue_stub (UBYTE *c2pscreen, UBYTE *bitplanes);
NovaCoder is offline  
Old 12 December 2009, 03:19   #8
Kalms
Registered User
 
Join Date: Nov 2006
Location: Stockholm, Sweden
Posts: 237
Quote:
Originally Posted by NovaCoder View Post
Code:
_c2p1x1_cpu3blit1_queue_init_stub: 
movem.l 4(a7),d0-d1/d3/d5-d7/a2-a4 
jsr _c2p1x1_cpu3blit1_queue_init 
rts
I presume the calling conventions of your C/C++ compiler is that d0-d1/a0-a1 are scratch, and others should be preserved by the called function. If so, the above stub will clobber some registers for you. This will cause mysterious crashes in optimized builds in the nearby region after the init call.

The stub below preserves registers properly:

Code:
_c2p1x1_cpu3blit1_queue_init_stub: 
movem.l d2-d7/a2-a6,-(sp)
movem.l 11*4+4(a7),d0-d1/d3/d5-d7/a2-a4 
jsr _c2p1x1_cpu3blit1_queue_init 
movem.l (sp)+,d2-d7/a2-a6
rts
Kalms is offline  
Old 17 December 2009, 00:15   #9
NovaCoder
Registered User
 
NovaCoder's Avatar
 
Join Date: Sep 2007
Location: Melbourne/Australia
Posts: 4,400
For other's reference, this got it working (thanx Salass00)

Code:
	XREF _c2p1x1_cpu3blit1_queue_init
	XREF _c2p1x1_cpu3blit1_queue
	XDEF _c2p1x1_cpu3blit1_queue_init_stub
	XDEF _c2p1x1_cpu3blit1_queue_stub

_c2p1x1_cpu3blit1_queue_init_stub:
	movem.l d3/d5-d7/a2-a4,-(a7)
	movem.l 32(a7),d0-d1/d3/d5-d7/a2-a4
	jsr _c2p1x1_cpu3blit1_queue_init
	movem.l (a7)+,d3/d5-d7/a2-a4
	rts

_c2p1x1_cpu3blit1_queue_stub:
	movem.l 4(a7),a0-a1
	jsr _c2p1x1_cpu3blit1_queue
	rts
NovaCoder 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
Any C2P experts here? oRBIT Coders. General 36 27 April 2010 07:26
HAM8 C2P Hacking NovaCoder Coders. General 2 25 March 2010 10:37
C2P Speed question Thorham Coders. General 5 20 January 2010 04:27
Gloom Akiko C2P? Whitesnake support.Games 5 23 April 2007 19:01
Game in c2p? oRBIT Amiga scene 11 01 February 2007 21:28

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 06:18.

Top

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