English Amiga Board


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

 
 
Thread Tools
Old 15 November 2016, 18:40   #21
arti
Registered User
 
Join Date: Jul 2008
Location: Poland
Posts: 662
I want use inflate from here https://raw.githubusercontent.com/ke...er/inflate.asm

Code:
long inflate(register z_streamp instream __asm("a5"), register int outdata __asm("a4"));
Can I use other types than long ?

Last edited by arti; 15 November 2016 at 18:55.
arti is offline  
Old 15 November 2016, 18:48   #22
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
The order is important. I ended up changing the macro syntax slightly to get the universal macros to work. I changed the example and there is now a test for GCC and vbcc which are now working for me. I updated my earlier post in this thread with an attachment to a new universal macro archive.

Quote:
Originally Posted by arti View Post
Can I use other types than long ?
Yes, but remember the 68k registers are 32 bits. Wider integer datatypes will not work and most datatypes can vary in size. The safest datatypes are probably int32_t, uint32_t, LONG, ULONG, APTR because they shouldn't vary in width. Narrower datatypes than 32 bit should be handled correctly but may be slower in some cases on the 68020+.

Last edited by matthey; 15 November 2016 at 19:03.
matthey is offline  
Old 15 November 2016, 23:53   #23
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Quote:
Originally Posted by arti View Post
I want use inflate from here https://raw.githubusercontent.com/ke...er/inflate.asm

Code:
long inflate(register z_streamp instream __asm("a5"), register int outdata __asm("a4"));
Can I use other types than long ?
Yes.

Something like
Code:
void inflate(register char *instream __asm("a5"), register char *outdata __asm("a4"));
would work.
alkis is offline  
Old 16 November 2016, 19:54   #24
arti
Registered User
 
Join Date: Jul 2008
Location: Poland
Posts: 662
That's how I have implemented it, posted here:
http://eab.abime.net/showpost.php?p=...9&postcount=55
arti is offline  
Old 17 November 2016, 00:34   #25
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Is it possible to have a small encoded and a decoded sample in order to play with it?
alkis is offline  
Old 17 November 2016, 12:57   #26
arti
Registered User
 
Join Date: Jul 2008
Location: Poland
Posts: 662
http://netsurf.baderman.net/inflate.zip
arti is offline  
Old 17 November 2016, 17:42   #27
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Can't really compile it. But...

You are doing
Code:
int inflate_asm(register z_streamp instream __asm("a5"), register int outdata __asm("a4"));

int __wrap_inflate2(z_streamp instream, int flush)
{
	int outdata;
	
    inflate_asm(instream, outdata);  

	//return inflate(instream, flush);
	
    return  outdata;
}
Your instream is a not a pointer to the encoded buffer.

z_streamp is (if you peek at zlib.h)

Code:
typedef struct z_stream_s {
    Bytef    *next_in;  /* next input byte */
    uInt     avail_in;  /* number of bytes available at next_in */
    uLong    total_in;  /* total nb of input bytes read so far */

    Bytef    *next_out; /* next output byte should be put there */
    uInt     avail_out; /* remaining free space at next_out */
    uLong    total_out; /* total nb of bytes output so far */

    char     *msg;      /* last error message, NULL if no error */
    struct internal_state FAR *state; /* not visible by applications */

    alloc_func zalloc;  /* used to allocate the internal state */
    free_func  zfree;   /* used to free the internal state */
    voidpf     opaque;  /* private data object passed to zalloc and zfree */

    int     data_type;  /* best guess about the data type: binary or text */
    uLong   adler;      /* adler32 value of the uncompressed data */
    uLong   reserved;   /* reserved for future use */
} z_stream;

typedef z_stream FAR *z_streamp;
As I understand the inflate.asm expects a pointer to (let's say) 200 bytes which are compressed and a large enough buffer (let's say 1000 bytes) to uncompress.

Your input pointer is not pointing to that. That's your problem, I think
alkis is offline  
Old 03 December 2016, 14:52   #28
arti
Registered User
 
Join Date: Jul 2008
Location: Poland
Posts: 662
That's how I corrected it :

Code:
#include "zlib.h"


int inflate_asm(register png_structrp png_ptr __asm("a5"), register int outdata __asm("a4"));

int /* PRIVATE */
png_zlib_inflate(png_structrp png_ptr, int flush)
{
   int outdata;
    
   if (png_ptr->zstream_start && png_ptr->zstream.avail_in > 0)
   {
      if ((*png_ptr->zstream.next_in >> 4) > 7)
      {
         png_ptr->zstream.msg = "invalid window size (libpng)";
         return Z_DATA_ERROR;
      }

      png_ptr->zstream_start = 0;
   }
   
    inflate_asm(&png_ptr->zstream, outdata);
   
   return  outdata;
}
but still doesn't work :/
arti is offline  
Old 03 December 2016, 19:27   #29
nogginthenog
Amigan
 
Join Date: Feb 2012
Location: London
Posts: 1,311
> register int outdata

Try using 'unsigned char *' instead of int. In C int is a signed type which may cause problems (use unsigned int at least).

For example:
Code:
int inflate_asm(register png_structrp png_ptr __asm("a5"), register unsigned char *outdata __asm("a4"));
unsigned char *png_zlib_inflate(png_structrp png_ptr, int flush)
inflate_asm(&png_ptr->zstream, outdata);
After this line add this and see what it outputs:
printf("%lx\n", outdata);
nogginthenog is offline  
Old 15 December 2019, 18:33   #30
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,196
Been trying to compile ptplayer.h (Frank protracker replayer) file to gcc.

with Bebbo gcc compiler (based on GCC 6) this doesn't work:

Code:
  void  mt_install_cia(register void *custom __asm("a6"),
			  register void *VectorBase __asm("a0"), register UBYTE PALflag, asm("d0"));
Original stuff used ASM and REG directives. It didn't work either (even if this includes #include <SDI_compiler.h> which is supposed to define proper ASM/REG directives)

Code:
   void ASM mt_install_cia(REG(a6, void *custom),
			  REG(a0, void *VectorBase), REG(d0, UBYTE PALflag));
last time I mixed asm & gcc together I read params from the stack from asm side. But that sucked, specially here with a third party library.
jotd is offline  
Old 15 December 2019, 18:59   #31
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
Quote:
Originally Posted by jotd View Post
Been trying to compile ptplayer.h (Frank protracker replayer) file to gcc.

with Bebbo gcc compiler (based on GCC 6) this doesn't work:

Code:
  void  mt_install_cia(register void *custom __asm("a6"),
			  register void *VectorBase __asm("a0"), register UBYTE PALflag, asm("d0"));
Original stuff used ASM and REG directives. It didn't work either (even if this includes #include <SDI_compiler.h> which is supposed to define proper ASM/REG directives)

Code:
   void ASM mt_install_cia(REG(a6, void *custom),
			  REG(a0, void *VectorBase), REG(d0, UBYTE PALflag));
last time I mixed asm & gcc together I read params from the stack from asm side. But that sucked, specially here with a third party library.
EDIT: Just reread your question, my answer may not be what you need, but...

I do it with inline assembly. You get to specify how a bunch of local variables are mapped to registers, then you can write a tiny bit of inline asm that is basically just a jsr. It's not as easy as the other way, but once you've done one it's not so bad.

I don't know if it's more efficient, but you get to specify which registers get clobbered rather than saving them yourself, if you want, which may help, amongst other things.

There's an example in the code attached to this post http://eab.abime.net/showpost.php?p=1361520&postcount=6 which may or may not be 100% correct, I can't check until I'm at a PC tomorrow.

Last edited by deimos; 15 December 2019 at 19:18.
deimos is offline  
Old 15 December 2019, 20:48   #32
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,196
that's how gcc defines OS calls. With this macro technique.

Code:
#define Supervisor(___userFunction) \
      LP1A5FP(0x1e, ULONG, Supervisor , __fpt, ___userFunction, d7,\
      , EXEC_BASE_NAME, ULONG (*__fpt)())

with macro defined as:

#define LP1A5FP(offs, rt, name, t1, v1, r1, bt, bn, fpt)	\
({								\
   typedef fpt;							\
   t1 _##name##_v1 = (v1);					\
   rt _##name##_re2 =						\
   ({								\
      register int _d1 __asm("d1");				\
      register int _a0 __asm("a0");				\
      register int _a1 __asm("a1");				\
      register rt _##name##_re __asm("d0");			\
      register void *const _##name##_bn __asm("a6") = (bn);	\
      register t1 _n1 __asm(#r1) = _##name##_v1;		\
      __asm volatile ("exg d7,a5\n\tjsr a6@(-"#offs":W)\n\texg d7,a5" \
      : "=r" (_##name##_re), "=r" (_d1), "=r" (_a0), "=r" (_a1)	\
      : "r" (_##name##_bn), "rf"(_n1)				\
      : "fp0", "fp1", "cc", "memory");				\
      _##name##_re;						\
   });								\
   _##name##_re2;						\
})
Seems that the "old" syntax doesn't work anymore (I just copied ptreplay.h from modsurfer and it doesn't work too). I'm going to create a redirection with inline asm to be able to call the real routines.

Last edited by jotd; 15 December 2019 at 21:06.
jotd is offline  
Old 15 December 2019, 21:11   #33
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
gcc used to support __asm(), which SDI_compiler.h defines as REG() macro.
All real Amiga gcc-ports worked with it. Seems your port is broken.

Last edited by phx; 15 December 2019 at 21:13. Reason: Confused __reg with __asm.
phx is offline  
Old 15 December 2019, 21:42   #34
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,196
yeah probably. I'm using an old distro of Bebbo gcc 6 (6.4). Debugger also doesn't work.

But latest amiga gcc version crashes randomly at startup with my code (on fopen, on printf, other...), and I seriously believe that the latest version is buggy, not my code (which has been ported on Windows & NDS without issues). With this version there are no random crashes at last (yes, I have increased stack to a big value)
jotd is offline  
Old 15 December 2019, 21:44   #35
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
Quote:
Originally Posted by phx View Post
gcc used to support __asm(), which SDI_compiler.h defines as REG() macro.
All real Amiga gcc-ports worked with it. Seems your port is broken.
I don't think gcc supports parameters as registers anymore, at least that's how I read the documentation, https://gcc.gnu.org/onlinedocs/gcc-6...ter-Variables:

Quote:
...the following uses are explicitly not supported. If they appear to work, it is only happenstance, and may stop working as intended due to (seemingly) unrelated changes in surrounding code...
  • Passing parameters to or from routines written in assembler (or other languages)...
I don't know if that's really the same thing as what we're talking about here, but there seems to be no other mention of parameter passing through registers anywhere in the gcc documentation.

Last edited by deimos; 17 December 2019 at 13:54.
deimos is offline  
Old 15 December 2019, 23:06   #36
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,196
Well, good news, I upgraded, and it compiled okay with the new build.

(m68k-amigaos-gcc (GCC) 6.5.0b 191023121710)

https://franke.ms/download/setup-amiga-gcc.exe

Well, it still crashes, but when I add -noixemul it works So now I have the debugger and all! I didn't think I would solve several problems because of this. Thanks anyone.
jotd is offline  
Old 25 December 2019, 11:34   #37
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,196
Now I'd like to return something as a register. I suppose that:

Code:
  ULONG ASM read_joystick(REG(d0, ULONG number));
isn't going to work. What's the syntax?
jotd is offline  
Old 25 December 2019, 12:38   #38
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
Quote:
Originally Posted by jotd View Post
Now I'd like to return something as a register. I suppose that:

Code:
  ULONG ASM read_joystick(REG(d0, ULONG number));
isn't going to work.
No. That would expect a function argument in d0, not the return value.

Quote:
What's the syntax?
C functions always return their result in a register. For 8/16/32-bit integer and pointers you can always expect d0. For 64-bit it might be d0/d1, when the compiler supports 64 bit, but be prepared for surpises (like the placement of the high-word in d0 or d1). For floating point it depends on the ABI. The V.4-ABI (Unix) always returns 64-bit double precision in d0/d1 (float in d0), no matter if you compiled for FPU or not. The common Amiga ABI (used by all Amiga compilers) returns in fp0, when generating FPU code, and in d0/d1 for soft-float. For returning structures it becomes more complicated. Usually small structures are returned in multiple registers, like d0,d1,a0,a1. But I would try to avoid that.

Last edited by phx; 25 December 2019 at 12:47. Reason: Don't forget pointers.
phx is offline  
Old 25 December 2019, 17:08   #39
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,196
indeed all I wanted was to return status in D0: working, thanks
jotd is offline  
Old 11 March 2020, 18:42   #40
sparhawk
Registered User
 
sparhawk's Avatar
 
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
I know that D0/D1 and A0/A1 are scratch registers and don't need to be saved. What I'm unsure about is, what's the case if I specify another register as param like in the below example:
Code:
uint32_t foo(void *param1 __asm("d0"), void *param2 __asm("d1"), void *param3 __asm("d2"));
In this case d2 is an input parameter. Is it still needed to be preserved? I would assume yes, but it would be nice to get it confirmed.
sparhawk 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
Replacing OS4 functions for OS3.x arti Coders. C/C++ 25 17 December 2018 16:03
functions benchmark wawa Coders. System 2 15 April 2013 18:55
How do the non-i/o functions work? mikro project.WHDLoad 3 03 November 2011 14:33
Lost F key Functions on WINuae startup breadbaker support.WinUAE 8 06 December 2005 20:09
CD32 blue button functions differently oldpx support.WinUAE 6 09 August 2004 13:43

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 21:01.

Top

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