English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 05 April 2020, 13:51   #1
olleharstedt
Registered User

 
Join Date: Mar 2020
Location: Hamburg
Posts: 20
Hacking the SDL API

OK, so hear me out... All SDL implementations on Amiga seem to be done to be able to port games TO Amiga, from another platform. What about making an SDL implementation for porting FROM Amiga? This way, the SDL API could be hacked to really take advantage of the Amiga hardware, like sprites and playfields. The point of doing this would be to make a new Amiga game compile on other platforms, like Linux and PC, and could increase the business incentive. Thoughts?
olleharstedt is offline  
Old 05 April 2020, 13:56   #2
olleharstedt
Registered User

 
Join Date: Mar 2020
Location: Hamburg
Posts: 20
Wrong subforum. Can mods move it to general coding, please?
olleharstedt is offline  
Old 05 April 2020, 18:10   #3
jotd
This cat is no more
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 48
Posts: 4,236
check my bagman remake: https://github.com/jotd666/bagman. It is C++ but SDL level is C.

For graphics, it respects SDL interface 99% of the time but bitmaps are loaded using a native planar format, and SDL blit function uses the blitter. No c2p shit and all. This allows the game to run 50 fps on a 68060 and 25fps on 68030/68020.

The trick is to pre-process images (png) using python to create a custom RAW format with bitplanes (and header to provide dimensions, etc...). Now SDL implementation is able to load this format and create the bitplanes internally in memory in SDL _Image structure.

I'm in the process of supporting sprites too (not only BOBs) but I lost interest in the way. I'll probably start again, though.

But it started from a Windows/Linux SDL compliant project. Now 95% of the code is the same. Only on amiga, the pseudo-implementation of SDL is embedded, and images & sounds asset files are different (raw vs png/wav in real SDL)

Last edited by jotd; 05 April 2020 at 18:16.
jotd is offline  
Old 05 April 2020, 18:58   #4
Samurai_Crow
Total Chaos forever!

Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Ft. Collins, CO USA
Age: 45
Posts: 1,488
Send a message via Yahoo to Samurai_Crow
With regards to porting from Amiga, I think a little thicker emulation layer than SDL would be preferable. For example, the copper horizontal sprite muxing would be accomplished using a textured quad with texture wrapping would accomplish the same thing on a conventional graphics core.

The point I'm making is that Amiga does things differently to accomplish the graphical effects than what a PC style graphics core does. We need a higher level wrapper for the Amiga effects to accomplish what you are suggesting.
Samurai_Crow is offline  
Old 05 April 2020, 19:51   #5
DamienD
disengaged
DamienD's Avatar
 
Join Date: Aug 2005
Location: London / Sydney
Age: 43
Posts: 17,711
Quote:
Originally Posted by olleharstedt View Post
Wrong subforum. Can mods move it to general coding, please?
Done
DamienD is offline  
Old 05 April 2020, 20:10   #6
jotd
This cat is no more
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 48
Posts: 4,236
one thing is sure: I'll design my new SDL based game with Amiga in mind.
jotd is offline  
Old 05 April 2020, 21:23   #7
olleharstedt
Registered User

 
Join Date: Mar 2020
Location: Hamburg
Posts: 20
Quote:
Originally Posted by jotd View Post
check my bagman remake: https://github.com/jotd666/bagman. It is C++ but SDL level is C.

I'm in the process of supporting sprites too (not only BOBs) but I lost interest in the way. I'll probably start again, though.

Nice, I will!


Sprites I'm a big believer in. What do you think about wrapping e.g. SDL_BlitSurface around a C macro and add an extra argument for sprite channel? Then if __AMIGA__ is def, the sprite channel will be used, and if not, that argument will be ignored.


Next level after that: Sprite reuse.
olleharstedt is offline  
Old 05 April 2020, 21:25   #8
olleharstedt
Registered User

 
Join Date: Mar 2020
Location: Hamburg
Posts: 20
Quote:
Originally Posted by Samurai_Crow View Post
With regards to porting from Amiga, I think a little thicker emulation layer than SDL would be preferable. For example, the copper horizontal sprite muxing would be accomplished using a textured quad with texture wrapping would accomplish the same thing on a conventional graphics core.

The point I'm making is that Amiga does things differently to accomplish the graphical effects than what a PC style graphics core does. We need a higher level wrapper for the Amiga effects to accomplish what you are suggesting.

Not sure I agree. Most clever things you do on Amiga can be done with brute-force on literary all other platforms, so mostly you'd have to do a #ifdef __AMIGA__ to setup a copper list etc and just ignore it otherwise (that is, just fallback to standard SDL).
olleharstedt is offline  
Old 05 April 2020, 21:28   #9
jotd
This cat is no more
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 48
Posts: 4,236
the way SDL handles sound play with mixers and all is completely incompatible with Amiga hardware too. In that case, a higher level API is okay (anyway, unless you're doing very elaborate sfx system, you can use phx ptreplay to play modules & sound effects)
jotd is offline  
Old 05 April 2020, 23:06   #10
olleharstedt
Registered User

 
Join Date: Mar 2020
Location: Hamburg
Posts: 20
What about this?


#ifdef __AMIGA__
#define SPRITE SimpleSprite
#else
#define SPRITE SDL_Surface
#endif

/** Similar logic with rcSprite */

#ifdef __AMIGA__
/** MoveSprite can be the standard AmigaOS function, or a custom ASM routine */
#define MOVE_SPRITE(sprite, rcSprite) MoveSprite(NULL, sprite, rcSprite.x, rcSprite.y)
#else
/** Assumes screen is defined */
#define MOVE_SPRITE(sprite, rcSprite) SDL_BlitSurface(sprite, NULL, screen, rcSprite)
#endif
olleharstedt is offline  
Old 05 April 2020, 23:08   #11
Samurai_Crow
Total Chaos forever!

Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Ft. Collins, CO USA
Age: 45
Posts: 1,488
Send a message via Yahoo to Samurai_Crow
Or just put the SDL version in a separate library or link lib would work better.
Samurai_Crow is offline  
Old 05 April 2020, 23:09   #12
jotd
This cat is no more
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 48
Posts: 4,236
with sprites, it's even trickier, specially if you reuse the same sprite image over and over.

while you can blit a pattern any number of times, moving a sprite means changing the control word at the start of SPRDAT. So if you want to display the same sprite more than once (example: enemies) you have to duplicate the sprite.

It would work with main character for instance, when there's only 1 instance of the sprite. If you want to do multiplexing or such, you can't have a unified interface.

For BOBs it works well. I kept SDL_BlitSurface and derived the SDL_Surface structure as "SDL_Amiga_Surface".

There I could add number of planes, cookie cut or not, etc... One could add bitmap type (sprite, bitmap), with still this non-reuse constraint I talked about at the beginning of my post.
jotd is offline  
Old 05 April 2020, 23:33   #13
olleharstedt
Registered User

 
Join Date: Mar 2020
Location: Hamburg
Posts: 20
One "solution" could be to make macros with variadic arguments, and then simply drop the extra arguments (used for clever sprite reuse etc) ifndef __AMIGA__. Still, might end up pretty crazy code-base.
olleharstedt is offline  
Old 06 April 2020, 00:10   #14
olleharstedt
Registered User

 
Join Date: Mar 2020
Location: Hamburg
Posts: 20
Quote:
Originally Posted by jotd View Post
For BOBs it works well. I kept SDL_BlitSurface and derived the SDL_Surface structure as "SDL_Amiga_Surface".

This is in the code-base you linked?
olleharstedt is offline  
Old 06 April 2020, 00:51   #15
Samurai_Crow
Total Chaos forever!

Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Ft. Collins, CO USA
Age: 45
Posts: 1,488
Send a message via Yahoo to Samurai_Crow
@olleharstedt

I found a download link to WarpSDL (not TurboSDL after all) on the Aminet: http://aminet.net/package/util/libs/WarpSDL_0_4usr

It's incomplete and doesn't come with usable headers to use the library. It's binary only.
Samurai_Crow is offline  
Old 06 April 2020, 08:52   #16
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 47
Posts: 3,878
Quote:
Originally Posted by Samurai_Crow View Post
With regards to porting from Amiga, I think a little thicker emulation layer than SDL would be preferable. For example, the copper horizontal sprite muxing would be accomplished using a textured quad with texture wrapping would accomplish the same thing on a conventional graphics core.

The point I'm making is that Amiga does things differently to accomplish the graphical effects than what a PC style graphics core does. We need a higher level wrapper for the Amiga effects to accomplish what you are suggesting.
I kinda agree with that (if i understood it correctly).
We need some kind of hardware abstraction layer for the Amiga, that makes as little assumptions about the underlying hardware as possible, but still uses the machine at its best.
And i seriously doubt SDL is the right base for this, it's too much PC oriented.
meynaf is offline  
Old 06 April 2020, 09:10   #17
Steril707
Tigerskunk!

Steril707's Avatar
 
Join Date: Sep 2016
Location: Amiga Island
Posts: 1,552
Interesting idea, anyway..
Steril707 is offline  
Old 06 April 2020, 19:30   #18
olleharstedt
Registered User

 
Join Date: Mar 2020
Location: Hamburg
Posts: 20
Quote:
Originally Posted by meynaf View Post
I kinda agree with that (if i understood it correctly).
We need some kind of hardware abstraction layer for the Amiga, that makes as little assumptions about the underlying hardware as possible, but still uses the machine at its best.
And i seriously doubt SDL is the right base for this, it's too much PC oriented.

SDL can never be this since it doesn't distinguish between sprites and bobs; it assumes no hardware support for sprites (and other things). But yeah, as I argue you can make an Amiga SDL which fallbacks to bobs for everything (SDL_BlitSurface).
olleharstedt is offline  
Old 06 April 2020, 19:50   #19
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 47
Posts: 3,878
Quote:
Originally Posted by olleharstedt View Post
SDL can never be this since it doesn't distinguish between sprites and bobs; it assumes no hardware support for sprites (and other things). But yeah, as I argue you can make an Amiga SDL which fallbacks to bobs for everything (SDL_BlitSurface).
Sprites and bobs are your smallest problem actually. SDL has no knowledge about planar formats, chip mem, cia timers, etc.
Therefore the idea is to design something more or less from scratch, with same goal as SDL - but made for Amiga hardware rather than PC.
I have something like that for my programs actually - but i just can't port it to PC.
meynaf is offline  
Old 06 April 2020, 21:33   #20
olleharstedt
Registered User

 
Join Date: Mar 2020
Location: Hamburg
Posts: 20
Quote:
Originally Posted by meynaf View Post
Sprites and bobs are your smallest problem actually. SDL has no knowledge about planar formats, chip mem, cia timers, etc.
Therefore the idea is to design something more or less from scratch, with same goal as SDL - but made for Amiga hardware rather than PC.
I have something like that for my programs actually - but i just can't port it to PC.

Depends on how much hardware you want to bang, no? What about doing something system friendly?
olleharstedt 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
OpenRetro Games Database API DanielAllsopp support.FS-UAE 4 17 May 2019 14:39
Do we have a 3D API? TEG Coders. General 5 21 January 2019 09:48
Best Anti-virus (with API) tygre support.Apps 11 05 November 2018 10:09
Programmer API for WinUAE AmireX support.WinUAE 6 12 October 2005 17:36
Windows API for Amiga OS? Pyromania Amiga scene 3 11 April 2002 13:02

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 08:29.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.09205 seconds with 12 queries