BITBLT example for 256 colors

GFA BASIC-related articles in here please

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

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2312
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

BITBLT example for 256 colors

Postby lp » Mon Feb 03, 2014 8:48 pm

Here's the example I wrote rather quickly for calimero. Instead of loading an image (sprite) from disk, it creates one on the screen then blits it to a buffer. Then it blits the sprite from the buffer to the mouse position. This way it is really two examples in one. :wink:

I didn't test it in TC, but I think it should work as it inquires all the screen information from the AES and VDI.

Code: Select all

REM #lib new lib
CLIP OFF
' init some variables
bp_&=WORD{LONG{GB+4}+20} !bit planes (via aes global array)
sw_&=WORK_OUT(0)+1 !screen size (via vdi)
sh_&=WORK_OUT(1)+1
DIM s_%(8),d_%(8),p_%(8) !bitblt parameters
s_%(4)=0     !these don't change
s_%(5)=bp_&  !bit planes
d_%(4)=0     !device specific format
d_%(5)=bp_&
p_%(8)=3     !replace mode
' define sprite size 32x32
x&=20
y&=20
w&=32
h&=32
' draw a colorful sprite
c&=0
FOR i&=y& TO y&+h&-1
  FOR j&=x& TO x&+w&-1
    COLOR BYTE(c&)
    PLOT i&,j&
    INC c&
  NEXT j&
NEXT i&
COLOR 1
BOX x&,y&,x&+w&-1,y&+h&-1
' calc buffer size for sprite data in bytes
bs_%=((w&*bp_&)\8)*h&
DIM sprite_|(bs_%) !create buffer
ba_%=V:sprite_|(0) !buffer address
' blit sprite from screen to buffer
s_%(0)=0       !0 forces the vdi to assume the screen
s_%(1)=sw_&    !screen width
s_%(2)=sh_&    !screen height
s_%(3)=sw_&\16 !width in words
d_%(0)=ba_%
d_%(1)=w&
d_%(2)=h&
d_%(3)=w&\16
p_%(0)=x&
p_%(1)=y&
p_%(2)=x&+w&-1
p_%(3)=y&+h&-1
p_%(4)=0
p_%(5)=0
p_%(6)=w&-1
p_%(7)=h&-1
BITBLT s_%(),d_%(),p_%()            !vdi blit
~FORM_DIAL(3,0,0,0,0,0,0,sw_&,sh_&) !force redraw the desktop
CLIP 0,0,sw_&,sh_&                  !set clipping to full screen
CLS
PRINT "Press right mouse button to exit..."
DO
  MOUSE mx&,my&,mk&
  ' blit sprite from buffer to screen (at mouse position)
  s_%(0)=ba_%
  s_%(1)=w&
  s_%(2)=h&
  s_%(3)=w&\16
  d_%(0)=0
  d_%(1)=sw_&
  d_%(2)=sh_&
  d_%(3)=sw_&\16
  p_%(0)=0
  p_%(1)=0
  p_%(2)=w&-1
  p_%(3)=h&-1
  p_%(4)=mx&      !adjust destination to mouse location
  p_%(5)=my&
  p_%(6)=mx&+w&-1
  p_%(7)=my&+h&-1
  ~GRAF_MOUSE(256,0) !hidem
  BITBLT s_%(),d_%(),p_%()
  ~GRAF_MOUSE(257,0) !showm
LOOP UNTIL mk&=2
~FORM_DIAL(3,0,0,0,0,0,0,sw_&,sh_&) !force redraw the desktop
EDIT

User avatar
calimero
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2123
Joined: Thu Sep 15, 2005 10:01 am
Location: STara Pazova, Serbia
Contact:

Re: BITBLT example for 256 colors

Postby calimero » Mon Feb 03, 2014 9:50 pm

It works in falcon true color (16bit) mode.

Thanx a million!

Btw is there any Falcon game writen in GFA basic in 256 or TC mode?

I think that Capy / YesCREW is writen in GFA basic but it use 16 color in 640x480 resolution...
using Atari since 1986.http://wet.atari.orghttp://milan.kovac.cc/atari/software/ ・ Atari Falcon030/CT63/SV ・ Atari STe ・ Atari Mega4/MegaFile30/SM124 ・ Amiga 1200/PPC ・ Amiga 500 ・ C64 ・ ZX Spectrum ・ RPi ・ MagiC! ・ MiNT 1.18 ・ OS X

User avatar
simonsunnyboy
Moderator
Moderator
Posts: 5001
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: BITBLT example for 256 colors

Postby simonsunnyboy » Tue Feb 04, 2014 5:24 pm

Thanks for this interesting example. I actually never have seen a working example of the BITBLT command sofar.
I'll have to try this out.
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2312
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: BITBLT example for 256 colors

Postby lp » Sat Feb 15, 2014 4:23 pm

Here's a revised version with replacements for GFA's built-in GET and PUT. The built in commands were great back in the day when there was only 3 video modes. They fail horribly on anything over 16 colors or if the block produces a string over 32kb in size. Internally GFA uses Line-A, hence the problems in modes over 16 colors.

Here's a solution that should work in any video mode regardless of block size. Instead of strings, they use memory blocks so the only limit is free ram. I decided to use the same internal layout that GFA used on the strings, so the buffer must be 6 bytes longer than what the bitmap requires. This also allows the use of GETSIZE() to compute the ram requirements which adds the required 6 bytes for us. :wink:

The six byte header is the <width&><height&><planes&> of the block.
@get will abort the blit if any part of the block falls outside the screen limits.
@put will abort the blit if the planes in the header do not match the current screen planes.

I'm not sure if this will work with old libraries as GETSIZE() internally fetches the current screen planes from the Line-A table.

Code: Select all

' get/put v1.00
REM #lib new lib
REM #sym !debug use only
$M65536  !limit app to 64k of ram when compiled
'
x&=20 !sprite dimensions
y&=20
w&=32
h&=32
ba_%=MALLOC(GETSIZE(x&,y&,x&+w&-1,y&+h&-1)) !ask gfa the size and make a buffer
IF ba_%<=0 !valid adr?
  PRINT "Error at malloc() failed!"
  EDIT
ENDIF
@draw_sprite
@get(x&,y&,w&,h&,ba_%) !copy sprite from screen to buffer
CLIP 0,0 TO WORK_OUT(0),WORK_OUT(1)  !set clipping to full screen
PRINT "Press right mouse button to exit..."
DO
  MOUSE mx&,my&,mk&
  ~GRAF_MOUSE(256,0)   !hidem
  @put(mx&,my&,3,ba_%) !copy sprite from buffer to screen
  ~GRAF_MOUSE(257,0)   !showm
LOOP UNTIL mk&=2
~FORM_DIAL(3,0,0,0,0,0,0,sw_&,sh_&) !force redraw the desktop
~MFREE(ba_%)
EDIT
'
> PROCEDURE draw_sprite
  LOCAL c&,i&,j&
  c&=0
  FOR i&=y& TO y&+h&-1
    FOR j&=x& TO x&+w&-1
      COLOR BYTE(c&)
      PLOT i&,j&
      INC c&
    NEXT j&
  NEXT i&
  COLOR 1
  BOX x&,y&,x&+w&-1,y&+h&-1
RETURN
' ----
> PROCEDURE get(x&,y&,w&,h&,a%)
  $X get
  LOCAL s.mfdb%,d.mfdb%
  IF x&=>0 AND x&+w&-1<=WORK_OUT(0)
    IF y&=>0 AND y&+h&-1<=WORK_OUT(1)
      INLINE s.mfdb%,20
      INLINE d.mfdb%,20
      WORD{a%+0}=w&
      WORD{a%+2}=h&
      WORD{a%+4}=WORD{LONG{GB+4}+20}
      LONG{s.mfdb%+0}=0
      WORD{s.mfdb%+4}=WORK_OUT(0)+1
      WORD{s.mfdb%+6}=WORK_OUT(1)+1
      WORD{s.mfdb%+8}=SHR&(WORK_OUT(0)+1,4) !\16
      WORD{s.mfdb%+10}=0
      WORD{s.mfdb%+12}=WORD{a%+4}
      LONG{d.mfdb%+0}=a%+6
      WORD{d.mfdb%+4}=w&
      WORD{d.mfdb%+6}=h&
      WORD{d.mfdb%+8}=SHR(w&,4) !\16
      WORD{d.mfdb%+10}=0
      WORD{d.mfdb%+12}=WORD{a%+4}
      CONTRL(0)=109
      CONTRL(1)=4
      CONTRL(3)=1
      CONTRL(6)=V~H
      LONG{CONTRL+14}=s.mfdb%
      LONG{CONTRL+18}=d.mfdb%
      INTIN(0)=3
      PTSIN(0)=x&
      PTSIN(1)=y&
      PTSIN(2)=x&+w&-1
      PTSIN(3)=y&+h&-1
      PTSIN(4)=0
      PTSIN(5)=0
      PTSIN(6)=w&-1
      PTSIN(7)=h&-1
      VDISYS
    ENDIF
  ENDIF
RETURN
> PROCEDURE put(x&,y&,m&,a%)
  $X put
  LOCAL w&,h&,s.mfdb%,d.mfdb%
  IF WORD{a%+4}=WORD{LONG{GB+4}+20} !blk planes matches scrn planes?
    INLINE s.mfdb%,20
    INLINE d.mfdb%,20
    w&=WORD{a%+0}
    h&=WORD{a%+2}
    LONG{s.mfdb%+0}=a%+6
    WORD{s.mfdb%+4}=w&
    WORD{s.mfdb%+6}=h&
    WORD{s.mfdb%+8}=SHR&(w&,4) !\16
    WORD{s.mfdb%+10}=0
    WORD{s.mfdb%+12}=WORD{a%+4}
    LONG{d.mfdb%+0}=0
    WORD{d.mfdb%+4}=WORK_OUT(0)+1
    WORD{d.mfdb%+6}=WORK_OUT(1)+1
    WORD{d.mfdb%+8}=SHR&(WORK_OUT(0)+1,4) !\16
    WORD{d.mfdb%+10}=0
    WORD{d.mfdb%+12}=WORD{a%+4}
    CONTRL(0)=109
    CONTRL(1)=4
    CONTRL(3)=1
    CONTRL(6)=V~H
    LONG{CONTRL+14}=s.mfdb%
    LONG{CONTRL+18}=d.mfdb%
    INTIN(0)=m&
    PTSIN(0)=0
    PTSIN(1)=0
    PTSIN(2)=w&-1
    PTSIN(3)=h&-1
    PTSIN(4)=x&
    PTSIN(5)=y&
    PTSIN(6)=x&+w&-1
    PTSIN(7)=y&+h&-1
    VDISYS
  ENDIF
RETURN
' eof

m0n0
Captain Atari
Captain Atari
Posts: 419
Joined: Mon Oct 05, 2009 3:13 am

Re: BITBLT example for 256 colors

Postby m0n0 » Sat Feb 15, 2014 10:49 pm

Does it also works fine for fVDI? I believe it's not possible under fVDI to blit 256 color graphics when running in TC mode.

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2312
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: BITBLT example for 256 colors

Postby lp » Sat Feb 15, 2014 10:58 pm

m0n0 wrote:Does it also works fine for fVDI? I believe it's not possible under fVDI to blit 256 color graphics when running in TC mode.


No clue. I promptly deleted fVDI and only run NVDI with aranym since day one. Anyway if you read the code above carefully, source and destination must have the exact same bit plane level. If you run this example in TC it blits TC to TC.

User avatar
BoNuS
Atari Super Hero
Atari Super Hero
Posts: 731
Joined: Mon Jan 19, 2009 12:45 pm
Location: The Netherlands
Contact:

Re: BITBLT example for 256 colors

Postby BoNuS » Sun Feb 16, 2014 11:31 am

Well Men at War is made in 256 colors in GFA basic :)
But it uses 2 x 16 Color palets, 4 bitplanes for the first 16 colors, the other 4 bitplanes
for the other colors.

This to uses more colors but also to maintain speed...
http://bonus.home.xs4all.nl/
2 x Falcon 030 - a mint Atari TT - Mega STE - 2x STE - 1x Mega 2 - 2x STFM - 1 x STF - 3x SC1224 - 2x SM124 - 1x SM125 2x Portofolio+interface
- 3x 1435 monitor - 1 x Ult.Ripper cardridge - Mega 1,2,and 4 ( just to much Atari stuff)

User avatar
hylst
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 133
Joined: Wed Apr 27, 2011 6:22 pm
Location: France : Strasbourg
Contact:

Re: BITBLT example for 256 colors

Postby hylst » Tue Apr 08, 2014 12:23 pm

You rocks Lonny ;o)
Clean code as usual :)

I'll give it a try in TC too.
Require a large block to be interessant (speed) compared to chained bmove or generated card or long, as they are lot of initialisations to do.
But your code is flexible.
Falcon CT60 +CENTRAM14 - 520 STE 4M - 1040 STf
Let's visit my Personal website http://hylst.t15.org !
The new website of my productions (French for the moment)


Social Media

     

Return to “GFA BASIC”

Who is online

Users browsing this forum: No registered users and 4 guests