English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 09 August 2010, 15:49   #21
korruptor
TDI
 
korruptor's Avatar
 
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
I didn't want to spoil your Project thread, but I just wanted to say this is a cracking idea and, since it's SDL, I couldn't resist seeing how it ran on the Mac (in the absence of spoUP's )



I've not looked into the colour issue, but that'll be trivial.

All I've done is setup an Xcode project with the SDL frameworks, removed the MessageBox and windows.h references and hardcoded a location to load a module from. It worked fine

Please keep up with this! When I get more time I'll happily do what I can to see the Mac version stays in sync, as well.

I'd *love* to have this fully working so I could make some 8bit tunes natively on my laptop!

Last edited by korruptor; 09 August 2010 at 16:01.
korruptor is offline  
Old 09 August 2010, 16:20   #22
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,719
Hmm... Seems the RGB is swapped to BGR on your port...
All you need is to swap the RGB positions in the palette table (ProTracker_SDL.c). E.g. 0x0000FF -> 0xFF0000
I made a smart palette system, makes everything easier when it comes to color changing

EDIT: Hmm no, it seems to be something else. Let me try something.
EDIT2: Aha! It was the alpa channel missing.

Code:
/* our main palette */
unsigned int palette[48] = 
{
	0x00BBBBBB, /* 0 - tracker bg */
	0x00888888, /* 1 - tracker bg */
	0x00555555, /* 2 - tracker bg */

	0x00000000, /* 3 - general text */
	0x00009955, /* 4 - pattern text */

	0x00444444, /* 5 - cursor */
	0x00777777, /* 6 - cursor */
	0x00AAAAAA, /* 7 - cursor */

	0x0000FF00, /* 8 - colorkey/transparency */

	0x00BB00FF  /* 9 - quadrascope */
};
Overwrite this with the table in ProTracker_SDL.c

I'll convert the vumeter pixels too now, hold on.

EDIT3:
This is the new vumeter_bitmap.h:
http://pastebin.com/j2kNzS1h

Done! Thanks for finding that error, I'll update the sources.

Last edited by 8bitbubsy; 09 August 2010 at 16:36.
8bitbubsy is offline  
Old 09 August 2010, 16:24   #23
korruptor
TDI
 
korruptor's Avatar
 
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
Yup, found and fixed that after I posted.

Sounds great, I'm really impressed
korruptor is offline  
Old 09 August 2010, 16:44   #24
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,719
Quote:
Originally Posted by korruptor View Post
Yup, found and fixed that after I posted.
Remember that the vumeter doesn't use the palette, so you need to change *all* the pixels in the bitmap. I did that for you, check my post earlier (where I linked to pastebin.com)


Quote:
Originally Posted by korruptor View Post
Sounds great, I'm really impressed
Thanks!

4mat
I spoke to him and showed him this project, he loved it

Last edited by 8bitbubsy; 09 August 2010 at 16:50.
8bitbubsy is offline  
Old 09 August 2010, 16:45   #25
korruptor
TDI
 
korruptor's Avatar
 
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
I just stuck this in, but obviously the VUs were wrong

Edit: yeah, just seen your post! Two ticks, lemme drop that in.

Code:
unsigned int palette[48] = 
{
  // Blue, Green, Red, Alpha
  (0xBB << 24) | (0xBB << 16) | (0xBB << 8) | (0x00 << 0),
  (0x88 << 24) | (0x88 << 16) | (0x88 << 8) | (0x00 << 0),
  (0x55 << 24) | (0x55 << 16) | (0x55 << 8) | (0x00 << 0),
  (0x00 << 24) | (0x00 << 16) | (0x00 << 8) | (0x00 << 0),
  (0x55 << 24) | (0x99 << 16) | (0x00 << 8) | (0x00 << 0),
  (0x44 << 24) | (0x44 << 16) | (0x44 << 8) | (0x00 << 0),
  (0x77 << 24) | (0x77 << 16) | (0x77 << 8) | (0x00 << 0),
  (0xaa << 24) | (0xaa << 16) | (0xaa << 8) | (0x00 << 0),
  (0x00 << 24) | (0xff << 16) | (0x00 << 8) | (0x00 << 0),
  (0xff << 24) | (0x00 << 16) | (0xbb << 8) | (0x00 << 0)
};
korruptor is offline  
Old 09 August 2010, 16:48   #26
korruptor
TDI
 
korruptor's Avatar
 
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
Pixel format is BRGA on mine, which is daft as I'm on Intel. Two ticks...

I've not used SDL in about 8 years, as you can tell
korruptor is offline  
Old 09 August 2010, 16:55   #27
korruptor
TDI
 
korruptor's Avatar
 
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
It's cos the pixel masks aren't set:

Try these:

Code:
SDL_Surface *dst = SDL_CreateRGBSurface(screen->flags, src_width, src_height, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
korruptor is offline  
Old 09 August 2010, 16:57   #28
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,719
The pixel format is ARGB here, Windows 7 + SDL 1.2.
EDIT: Nice, I'll do that.

Ok:
pixbuf = SDL_CreateRGBSurface(screen->flags, 320, 255, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);

In ProTracker_SDL.c...
If you've ever wondered why I do 320x255 and not 320x256, then I can tell you it's because ProTracker doesn't actually plot on the last scanline.

If you see any other errors, feel free to comment! I love to learn from my (many) mistakes. Btw, do you hang around on IRC or MSN? It's easier to talk and share code there.

Last edited by 8bitbubsy; 09 August 2010 at 17:05.
8bitbubsy is offline  
Old 09 August 2010, 17:09   #29
korruptor
TDI
 
korruptor's Avatar
 
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
Oh, hang on, that's still the wrong order on mine. There's something else. Lemme have a poke about.

Which IRC channel are you on?
korruptor is offline  
Old 09 August 2010, 17:13   #30
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,719
Quote:
Originally Posted by korruptor View Post
Oh, hang on, that's still the wrong order on mine. There's something else. Lemme have a poke about.

Which IRC channel are you on?
Join #ProTracker on either FreeNode, EFNet, EsperNet, Abime or IRCNet. I'm on that channel on all those networks
8bitbubsy is offline  
Old 09 August 2010, 17:31   #31
korruptor
TDI
 
korruptor's Avatar
 
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
Cool, I'll pop in when I get time to look at this. I've got as far as checking the screen and surface pixel formats, which match. Endians look ok, so I'm wondering if there's actually an endian difference when it's getting to the graphic card.

I need to dig about but I'm at work, so it's a bit tricky
korruptor is offline  
Old 09 August 2010, 21:17   #32
SyX
Registered User
 
Join Date: Sep 2004
Location: Brasil
Age: 50
Posts: 181
Only want to add that commenting the MessageBoxs, the programs goes perfectly in my Debian 64

Click image for larger version

Name:	protracker_sdl.png
Views:	207
Size:	23.3 KB
ID:	26141

Great Job!!!
SyX is offline  
Old 09 August 2010, 21:25   #33
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,719
8bitbubsy is offline  
Old 09 August 2010, 21:44   #34
korruptor
TDI
 
korruptor's Avatar
 
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
Okie doke, I was being a pleb earlier.

All your draw code assumes the screen's pixel format matches your palette, which isn't always the case. What I normally do is keep the colour components split until the last minute, and then shift and pack them together depending. So RGBA in my iPhone stuff ends up being:

Code:
U32 colour = (alpha << 24) | (blue << 16) | (green << 8) | red;
SDL gives you the amounts to shift by, which is handy. I just changed your drawPaletteBitmap function to this:

Code:
void drawPaletteBitmap(char *src, SDL_Surface * screen, SDL_Surface *dst, int putx, int puty, int src_width, int src_height)
{
  unsigned int *dst_p = (unsigned int *)dst->pixels;
  int x, y;
  unsigned int tmpC = 0;
  
  for (y = 0; y < src_height; y++)
  {
    int _y = (puty + y) * dst->w;
    int srcY = y * src_width;

    for (x = 0; x < src_width; x++)
    {
      int paletteIndex = src[srcY + x];
      if (paletteIndex != 8)
      {
        // get the ARGB colour value
        tmpC = palette[paletteIndex];
        
        // Convert each component into the screen format
        unsigned int pixel = (((tmpC & 0xFF000000) >> 24) << screen->format->Ashift ) | 
                                    (((tmpC & 0x00FF0000) >> 16) << screen->format->Rshift ) | 
                                    (((tmpC & 0x0000FF00) >> 8)  << screen->format->Gshift ) | 
                                    ((tmpC & 0x000000FF) << screen->format->Bshift );
        
      int _x = putx + x;
      if (((puty + y) < dst->h) && (_x < dst->w))
        dst_p[_y + _x] = pixel;
      }
    }
  }
  return;
}
That works fine with no data changes on my machine. For the VUs, I'd do all that shifting and repacking in loadBitmap call, before you actually get going. In fact, that'd probably sort all of it out so you could do straight pixel copying in the main loop...

I don't think speed's much of an issue for this stuff though
korruptor is offline  
Old 09 August 2010, 21:48   #35
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,719
Quote:
Originally Posted by korruptor View Post
I don't think speed's much of an issue for this stuff though
Actually, it is... I spent a long time optimizing, and it went down from 5% CPU load to 0-1% on my Intel Core2 Quad 2.4GHz... 20% CPU load on my other DELL 2.8GHz
I'll try the code now and check the CPU load again.

EDIT: Around 1% more CPU load with your code.... I'm sceptic.
Meh you're right, portability is important! I'll keep your code, thanks
So I guess you're joining the project, or? No need to often commit anything to the source, but just if you feel like adding/changing/optimizing something, then feel free

Last edited by 8bitbubsy; 09 August 2010 at 22:00.
8bitbubsy is offline  
Old 09 August 2010, 22:00   #36
korruptor
TDI
 
korruptor's Avatar
 
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
Well, you can side step all that by building your palette to match the screen format. You have the base colours, so do all that shifting into a new palette structure on entry and go back to straight pixel copying in the main loop.
korruptor is offline  
Old 09 August 2010, 22:02   #37
korruptor
TDI
 
korruptor's Avatar
 
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
Quote:
Originally Posted by 8bitbubsy View Post
So I guess you're joining the project, or? No need to often commit anything to the source, but just if you feel like adding/changing/optimizing something, then feel free
Haha, I was just being curious, honest! I've not used SDL in anger in years

I'm happy to keep a mac version together for you, if that helps?
korruptor is offline  
Old 09 August 2010, 22:07   #38
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,719
Hmm, what about
pixbuf = SDL_CreateRGBSurface(screen->flags, 320, 255, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
?

Should I change the last four parameters to something in the screen struct?


Mmm! Back to 0-1% CPU load.

Code:
/* our main palette */
unsigned int palette[48] = 
{
	0x00BBBBBB, /* 0 - tracker bg */
	0x00888888, /* 1 - tracker bg */
	0x00555555, /* 2 - tracker bg */

	0x00000000, /* 3 - general text */
	0x00009955, /* 4 - pattern text */

	0x00444444, /* 5 - cursor */
	0x00777777, /* 6 - cursor */
	0x00AAAAAA, /* 7 - cursor */

	0x0000FF00, /* 8 - colorkey/transparency */

	0x00BB00FF  /* 9 - quadrascope */
};

void convertPaletteToScreenFmt(unsigned int *palette, SDL_Surface *screen);


[...]
convertPaletteToScreenFmt(palette, screen);
[...]

void convertPaletteToScreenFmt(unsigned int *palette, SDL_Surface *screen)
{
	if ((screen != NULL) && (palette != NULL))
	{
		int i;
		for (i = 0; i < 48; i++)
		{
			if (palette == NULL)
				return;

			{
				unsigned int pix = *palette;
				*palette++ = (((pix & 0xFF000000) >> 24) << screen->format->Ashift ) | 
							(((pix & 0x00FF0000) >> 16) << screen->format->Rshift ) | 
							(((pix & 0x0000FF00) >> 8)  << screen->format->Gshift ) | 
							((pix & 0x000000FF) << screen->format->Bshift );
			}
		}
	}
	return;
}

Last edited by 8bitbubsy; 09 August 2010 at 22:13.
8bitbubsy is offline  
Old 09 August 2010, 22:12   #39
korruptor
TDI
 
korruptor's Avatar
 
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
korruptor is offline  
Old 09 August 2010, 22:16   #40
TCD
HOL/FTP busy bee
 
TCD's Avatar
 
Join Date: Sep 2006
Location: Germany
Age: 46
Posts: 32,022
Code:
if ((screen != NULL) && (palette != NULL))
	{
                ...
		{
			if (palette == NULL)
				return;
Hmm
TCD 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
My old source code gemanix Coders. General 36 09 July 2017 13:33
Source code for game in C? Leandro Jardim Coders. General 2 17 February 2013 00:27
Protracker all Versions incl. Source sun68 support.Apps 16 01 April 2012 00:59
Source Code camelord support.Games 2 06 August 2010 17:45
Source Code Thalion project.WinUAE - Kaillera 3 28 April 2006 09:55

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 00:13.

Top

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