SDL xbios target using gcc

C and PASCAL (or any other high-level languages) in here please

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

MegatronUK
Atarian
Atarian
Posts: 6
Joined: Fri Jan 04, 2019 11:11 am

SDL xbios target using gcc

Postby MegatronUK » Fri Jan 04, 2019 11:29 am

Hi everyone,

I'm playing around with Vincent Rivière's m68k set of GCC tools, including the port of SDL. I know, I know, it's very limited in xbios mode on an ST (16 colour greyscale according to the docs) and slow, but I'm just wanting to try a few things.

However, I'm not having any luck at all getting anything displayed.

I'm using Hatari, configured as a vanilla ST, and no matter what I do, whether it's trying to display a bitmap, or render a simple flat rectangle it doesn't work. The behaviour I see is SDL initialises the screen (320x200x8), it goes black, then whatever I try to blit to the screen gets at most, shown as a 1 pixel line at the top of the screen - even if all I'm doing is filling the entire screen with white as follows:

Code: Select all

#include <stdio.h>
#include <unistd.h>
#include <SDL/SDL.h>

SDL_version compiled;
SDL_version linked;
int main(int argc, char* argv[]){
   
   SDL_Surface *bg;
   SDL_Surface *image;
   SDL_Surface *bmp;
   SDL_Surface *display;
   SDL_Rect src, dest;
   char vdriver[32];
   FILE *log;   
   
   SDL_VERSION(&compiled);
   
   log = fopen("MENU.LOG","w");

   fprintf(log, "Menu tool running\n");
   fprintf(log, "-----------------\n");
   fprintf(log, "\n");
   fprintf(log, "libSDL: Initialising...\n");
   fflush(log);
   
   if (SDL_Init(SDL_INIT_VIDEO) != 0){
      // Error occurred loading SDL
      fprintf(log, "SDL_Init Error: %s\n", SDL_GetError());
      fflush(log);
      fclose(log);
      sleep(2);
      exit(-1);
   } else {
      
      fprintf(log, "libSDL: Initialised v%d.%d.%d ok!\n", compiled.major, compiled.minor, compiled.patch);
      fflush(log);
      
      // Set display mode for the SDL screen
      fprintf(log, "Display: Driver loading...\n");
      fflush(log);
      display = SDL_SetVideoMode(320, 200, 0, SDL_SWSURFACE);
      if(display == NULL){
         fprintf(log, "SDL_SetVideoMode Error: %s\n", SDL_GetError());
         fflush(log);
         SDL_Quit();
         fclose(log);
         sleep(2);
         exit(-1);
      } else {
         fprintf(log, "Display: Driver %s ok!\n", SDL_VideoDriverName(vdriver, 32));
         fprintf(log, "Display: Driver mode %dx%dx%dbpp ok!\n", display->w, display->h, display->format->BitsPerPixel);
         fflush(log);
      }
      
      // Load splash bitmap
      fprintf(log, "Bitmap: Loading...\n");
      fflush(log);
      bmp = SDL_LoadBMP("C:\\COMPILER\\MENU\\LOGO.BMP");
      if (bmp == NULL){
         fprintf(log, "SDL_LoadBMP Error: %s\n", SDL_GetError());
         fflush(log);
         SDL_Quit();
         fclose(log);
         sleep(2);
         exit(-1);
      } else {
         fprintf(log, "Bitmap: Loaded %dx%dx%dbpp ok!\n", bmp->w, bmp->h, bmp->format->BitsPerPixel);
         fflush(log);
         bg = SDL_DisplayFormat(bmp);
         SDL_FreeSurface(bmp);
      }
      
      // Fill screen white
      fprintf(log, "Box: Drawing...\n");
      SDL_FillRect(display, NULL, 0xFFFFFF);
      SDL_Flip(display);
      fprintf(log, "Box: Drawn\n");
      fflush(log);
      
      // Display bitmap on screen
      image = SDL_DisplayFormat(bg);
      SDL_FreeSurface(bg);
      fprintf(log, "Display: Blitting...\n");
      fflush(log);
      
      //Construct the source rectangle for our blit
        src.x = 0;
        src.y = 0;
        src.w = image->w;    //Use image->w to display the entire width of the image
        src.h = image->h;    //Use image->h to display the entire height of the image

        //Construct the destination rectangle for our blit
        dest.x = 140;       
        dest.y = 0;
        dest.w = image->w;    //Ensure the destination is large enough for the image's entire width/height
        dest.h = image->h;
      
      SDL_BlitSurface(image, NULL, display, &dest);
      SDL_Flip(display);
      fprintf(log, "Display: Blitted ok!\n");
      fflush(log);
      SDL_Delay(3000);
      SDL_FreeSurface(image);
      fprintf(log, "Bitmap: Freed\n");
      fflush(log);
   }
   fprintf(log, "libSDL: Unloading...\n");
   fflush(log);
   SDL_Quit();
   fprintf(log, "libSDL: ok\n");
   fflush(log);
   fclose(log);
   sleep(2);
   return 0;
}


My log file indicates everything proceeds okay, but the white box renders as a single pixel white line at the top of the screen, as does the bitmap image:

sdl.jpg


The output I'm writing to the log shows no errors:

Code: Select all

Menu tool running
-----------------

libSDL: Initialising...
libSDL: Initialised v1.2.15 ok!
Display: Driver loading...
Display: Driver xbios ok!
Display: Driver mode 320x200x8bpp ok!
Bitmap: Loading...
Bitmap: Loaded 180x135x8bpp ok!
Box: Drawing...
Box: Drawn
Display: Blitting...
Display: Blitted ok!
Bitmap: Freed
libSDL: Unloading...
libSDL: ok


I suppose most people (if any) have used SDL in GEM, but did anyone come across this behaviour?
You do not have the required permissions to view the files attached to this post.

MegatronUK
Atarian
Atarian
Posts: 6
Joined: Fri Jan 04, 2019 11:11 am

Re: SDL xbios target using gcc

Postby MegatronUK » Thu Jan 10, 2019 9:31 pm

I can replicate the error with a basic SDL_Fillrect() command:

Code: Select all

SDL_Init(SDL_INIT_VIDEO);
display = SDL_SetVideoMode(320, 200, 0, SDL_SWSURFACE|SDL_FULLSCREEN);
for(i=0;i<256;i++){
      colors[i].r=i;
      colors[i].g=i;
      colors[i].b=i;
   }
SDL_SetColors(display, colors, 0, 256);
box.x = 100;
box.y = 100;
box.w = 90;
box.h = 90;
SDL_FillRect(display, &box, SDL_MapRGB(display->format, 0xFF, 0xFF, 0xFF));
SDL_Flip(display);
SDL_Delay(5000);


The above extract should draw a white box of 90x90 pixels at 100,100 - it instead does this:

grab0022.png


Changing the x coordinates to 0 does this:

grab0053.png


It appears that x coordinates are being honoured, but the base value for y coordinates is off the top of the display, hence everything I draw I only ever see the last line of pixels; so my bitmap is probably being correctly displayed in glorious greyscale, but I just cannot see it :D

I've passed the info on to Patrice to see if he has any ideas. I've also updated to Hatari 2.1.0 to see if it was something to do with video support that perhaps was fixed between the version I was using on Ubuntu 16.04 LTS (Hatari 1.8.0) and the current release, sadly it seems not.

John
You do not have the required permissions to view the files attached to this post.

jury
Captain Atari
Captain Atari
Posts: 310
Joined: Tue Sep 21, 2004 11:11 am
Location: Poland

Re: SDL xbios target using gcc

Postby jury » Fri Jan 11, 2019 4:57 am

MegatronUK wrote:I'm using Hatari, configured as a vanilla ST, and no matter what I do, whether it's trying to display a bitmap, or render a simple flat rectangle it doesn't work. The behaviour I see is SDL initialises the screen (320x200x8)

The output I'm writing to the log shows no errors:

Code: Select all

...
Display: Driver mode 320x200x8bpp ok!



Are you sure you have configured Hatari correctly? ST surely do not have ( unfortunately :) ) 8 bpp modes. It shoud show 4bpp.
So maybe its a problem with wrong configuration.

MegatronUK wrote:

Code: Select all

   
      // Display bitmap on screen
      image = SDL_DisplayFormat(bg);



This is definitely redundant, especially that you try to run it on ST, which has quite limited power for SDL stuff. You can blit to display directly from bg structure, or load ( and do sdl_displayformat ) directly to image structure.

jury
Captain Atari
Captain Atari
Posts: 310
Joined: Tue Sep 21, 2004 11:11 am
Location: Poland

Re: SDL xbios target using gcc

Postby jury » Fri Jan 11, 2019 6:45 am

OK, done some quick test on Falcon and it seems all is fine as seen on the attached screen.
So its either Hatari related ( like wrong configuration ) or implementation of SDL for ST is rather not proper, especially, that SDLs target is definitely not ST.
You do not have the required permissions to view the files attached to this post.

MegatronUK
Atarian
Atarian
Posts: 6
Joined: Fri Jan 04, 2019 11:11 am

Re: SDL xbios target using gcc

Postby MegatronUK » Fri Jan 11, 2019 8:25 am

Hi, unfortunately SDL won't initialise with an SDL screen set to 4bit:

Code: Select all

display = SDL_SetVideoMode(320, 200, 4, SDL_SWSURFACE|SDL_FULLSCREEN);


This raises an SDL_Error message of:

Code: Select all

Invalid bits per pixel (range is {8...32})


I definitely have Hatari configured to 16 colour mode. Basic ST emulation mode, no blitter, 8MHz, 16 color, local filesystem mapped to a GEMDOS drive. Other than that, it hasn't had any further tweaking. I've tried different TOS versions (and EmuTOS) to see if it makes a difference and nothing.

The display depth doesn't appear to have any impact - I can draw a box and fill it with any colour and it gets converted down to a relevant greyscale mode (although I of course only ever see the bottom row of pixels). For example, I can see differences between doing a SDL_Fillrect(,, 0xFF, 0x00, 0x00) or SDL_Fillrect(,, 0x00, 0xFF, 0x00) or SDL_Fillrect(,, 0x00, 0x00, 0xFF).

Of course, this could simply be a Hatari emulation issue, but I don't have a real ST to test with at the moment.

jury
Captain Atari
Captain Atari
Posts: 310
Joined: Tue Sep 21, 2004 11:11 am
Location: Poland

Re: SDL xbios target using gcc

Postby jury » Sat Jan 12, 2019 2:52 pm

MegatronUK wrote:Hi, unfortunately SDL won't initialise with an SDL screen set to 4bit:

Code: Select all

display = SDL_SetVideoMode(320, 200, 4, SDL_SWSURFACE|SDL_FULLSCREEN);


This raises an SDL_Error message of:

Code: Select all

Invalid bits per pixel (range is {8...32})



Have you tried to set SDL_VIDEODRIVER to xbios? If not, do so and then run the code. From what I understand, GEM video driver ( and I guess thats the one you are using ) works only for 8bpp or higher and with xbios one 4bpp can be set.

MegatronUK
Atarian
Atarian
Posts: 6
Joined: Fri Jan 04, 2019 11:11 am

Re: SDL xbios target using gcc

Postby MegatronUK » Sat Jan 12, 2019 3:48 pm

With no SDL_VIDEODRIVER environment variable set it defaults to xbios - the code...

Code: Select all

fprintf(log, "Display: Driver %s ok!\n", SDL_VideoDriverName(vdriver, 32));

...correctly prints that xbios mode is in use.

I reported my findings to Patrice and he's been looking at it as well - he thinks that there may be some regressions with the back end Atari-specific chunky to planar video routines in libSDL; as the same "everything draws on line 0" display issues occur for him as well when he tried one of the example SDL routines.

I have my fingers crossed that he can solve it!

I've also just bought myself a 520 STE so that in the future I can check on real hardware. For now I'm continuing to develop on Linux+X11 and Cygwin so I can still progress things... I'm aiming to have a game browser/launcher tool like iGame for WHDLoad games on the Amiga.

MegatronUK
Atarian
Atarian
Posts: 6
Joined: Fri Jan 04, 2019 11:11 am

Re: SDL xbios target using gcc

Postby MegatronUK » Sun Jan 13, 2019 11:58 pm

Patrice has released a new version of libSDL 1.2.15 to resolve the regression in the c2p routine, as well as a few other enhancements. You can find it on his webpage.

It has certainly fixed my display problems:

grab0003.png


I am rather happy :D

Yes, it's certainly not fast, but it works.

Now I need to put some effort into speeding this thing up... scanning an emulated ST hard drive shows that this thing won't be practical in real use... scan and save to CSV is probably the way to go, then reload the CSV the next time around.

I'm also not using SDL_ttf for text output - because it results in an absolutely massive binary (pulls in libpng, bz2, libz and more), so have put together a lightweight bitmap to font routine instead (still working the kinks out!) that has no other dependencies than libSDL itself.
You do not have the required permissions to view the files attached to this post.

MegatronUK
Atarian
Atarian
Posts: 6
Joined: Fri Jan 04, 2019 11:11 am

Re: SDL xbios target using gcc

Postby MegatronUK » Mon Jan 14, 2019 12:16 am

And with text now showing...

grab0004.png


List of scanned games shown in browser window, game thumbnails or folder bitmaps shown on the right and detected .TOS/.PRG files for that game, plus any README files in that games folder (ultimately will be able to view the text file before launching the game - by one of the detected binaries).

I'm writing it to work best with collections of HD-compatible games, like the ones ppera has done (it's so nice having all the .TOS and .TXT files named consistently, though I scan for any that match those extensions).

Lots of optimization now to do! As scrolling between games causes a delay of about 2-3 seconds now! :coffe:
You do not have the required permissions to view the files attached to this post.

User avatar
Eero Tamminen
Atari God
Atari God
Posts: 1830
Joined: Sun Jul 31, 2011 1:11 pm

Re: SDL xbios target using gcc

Postby Eero Tamminen » Thu Jan 17, 2019 11:42 pm

Remember that Hatari debugger includes a profiler:
https://hg.tuxfamily.org/mercurialroot/ ... #Profiling

It can provide for example timing annotated disassembly, and call, instruction & cycle count callgraphs. For 68000 emulation, the information is cycle-accurate.


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 3 guests