*DISPLAY vs *MDISPLAY

Discussions related to graphics (2D and 3D), animation and games programming
RichardRussell

*DISPLAY vs *MDISPLAY

Post by RichardRussell »

In both BBC BASIC for Windows and BBC BASIC for SDL 2.0 *DISPLAY (OSCLI "DISPLAY...") displays a BMP image stored in a file whereas *MDISPLAY (OSCLI "MDISPLAY...") displays a BMP image stored in memory. If you are only displaying the image once then you might as well use *DISPLAY, but if you are displaying it multiple times, and speed is important, it is better to load it into memory just once then display it using *MDISPLAY.

Typically you would load the image file into memory using *LOAD (OSCLI "LOAD...") but alternatively, and perhaps more straightforwardly, you could load it into a string. Here's an example using one of the images from the supplied dibley.bbc program:

Code: Select all

      REM Load the image into a string (do this just once):
      bmpfile$ = @lib$ + "..\examples\games\.Graphics\1.BMP"
      F% = OPENIN(bmpfile$)
      bmp1$ = GET$#F% BY EXT#F%
      CLOSE #F%

      REM Display the image (typically multiple times):
      *HEX 64
      REPEAT
        x% = RND(1200) : y% = RND(1000)
        OSCLI "MDISPLAY " + STR$~PTR(bmp1$) + " " + STR$(x%) + "," + STR$(y%)
        WAIT 10
      UNTIL FALSE
Both *DISPLAY and *MDISPLAY allow you to scale the image and/or to specify a 'transparent' colour, but those features are not demonstrated here. In BBC BASIC for SDL 2.0 (only) the image may be in .PNG, .GIF or .JPG format, as well as .BMP.
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

Re: *DISPLAY vs *MDISPLAY

Post by KenDown »

This looks a very useful routine and I've just incorporated it into my Display program where, in one particular bit, speed is indeed of the essence. The trouble was that when I tried to move on to the next picture my program crashed with the message "Number too big" and the offending line was one in the jpg routine from the HELP

iid%!8 =&AA00BB8B

I found that it worked just fine if I restored
*HEX 32

Is that because my computer is only 32 bit? Is there something else I've overlooked?

Thanks.
RichardRussell

Re: *DISPLAY vs *MDISPLAY

Post by RichardRussell »

KenDown wrote: Wed 28 Oct 2020, 14:30I found that it worked just fine if I restored *HEX 32
*HEX 64 is required on a 64-bit system. This forum is supposed to cater for all the supported platforms (Windows, MacOS, Linux, Raspbian, Android, iOS, in-browser) so any code I publish here ought to be fully compatible, unless stated otherwise (or it's obvious that it can't be).