Followers

Tuesday, May 7, 2019

Amiga Blitz

Display Library & AGA

introduction

The display library is an important addition to Blitzbasic2. Developed as a replacement for slices, it offers
Not only game programmers have access to the AGA chipset and a modular approach to controlling the
Amiga graphics hardware.

The display of the Amiga is controlled by the coprocessor Copper, which performs one in each frame
List of instructions. So 50 times a second on PAL Amigas. The cathode ray of the line for
Line goes across the screen and every single pixel is drawn through a series of hardware
Controlled registers. The copper here has the task to keep everything in sync.
A copperlist includes information about the colors, bitplanes, sprites, the current resolution and
much more. This information requires the cathode ray (video beam) to render the display.
initialization

Unlike slices, which are displayed as soon as they are initialized, the display
Library so-called copper lists for initialization. These copper lists are created with InitCopList.
The CreateDisplay function also creates a Copperlist. An important difference to slices is
that they allocate memory each time a display change is required while the
Display Library can initialize multiple copper lists before the display is generated.
There are two forms of InitCopList. The short version only requires the Copperlist number and
the corresponding flags. The height of the display is then preset to 256 pixels. The width of the
Displays can be 320, 640 or 1280, depending on which resolution and color depth you use with the flags
has defined.

The longer version of InitCopList has the following format:
InitCopList CopList #, ypos, height, type, sprites, colors, customs
The parameter ypos is usually set to 44, which corresponds to the top of a PAL screen.
If the Copperlist is used below another Copperlist, ypos must be 2 rows lower
lie as the last line of the previous Copper List.
The parameter sprite should always be set to 8, even if this amount is not required. The
Parameter colors is set to the desired number. When more than 32 colors are used
should always the flag #agacolors be set!
The customs parameter provides room for extended copper lists assigned to each display
can. The use of custom will be discussed later in this chapter.

flags

InitCopList uses 32 for OCS/ECS so use that on the InitCopList instead of 44




The parameter Flags is calculated by adding the individual values. Note: if the parameter
If a variable is to be assigned to flags in which the flags have previously been stored, then this variable must be used
Long type (.l = 32Bit)!
#onebitplane $ 01
#twobitplanes $ 02
#threebitplanes $ 03
#fourbitplanes $ 04
#fivebitplanes $ 05
#sixbitplanes $ 06
#sevenbitplanes $ 07 only for AGA
#eightbitplanes $ 08 only for AGA
#smoothscrolling $ 10 Set if you want to scroll bitmaps.
#dualplayfields $ 20 Enables dual playfield mode
#extrahalfbright $ 40 Forces EHB mode with 6 bitplanes
#ham $ 80 HAM mode
#lores $ 000
#hires $ 100
#superhires $ 200
#loressprites $ 400
#hiressprites $ 800 only for AGA
#superhiressprites $ c00 only for AGA
# fetchmode0 $ 0000
# fetchmode1 $ 1000 only for AGA
# fetchmode2 $ 2000 only for AGA
# fetchmode3 $ 3000 only for AGA
#agacolors $ 10000 only for AGA

The #agacolors flag must always be set if there are more than 32 colors or 24-bit color definitions
should be used.
SAMPLE InitCopList 0,34,256,$10000|$01|$10|$400,8,1,-4



Extended copper control
The extended version of InitCopList allows you to assign custom Copper commands.
There are some functions in the display library that require this parameter.
There are two types of Copper commands. The first one allows the Copper every single line of the display
while the second allows the Copper to work on a particular line.
The following functions require a negative offset, this shows the number of instructions to the
must be assigned to each line.

DisplayDblScan CopList #, Mode [, copoffset]; (size = -2)
DisplayRainbow CopList #, register, palette [, copoffset]; (ecs = -1 aga = -4)
DisplayRGB CopList #, register, line, r, g, b [, copoffset]; (ecs = -1 aga = -4)
DisplayUser CopList #, Line, String [, CopOffset]; (size = -len / 4)
DisplayScroll CopList #, & xpos.q (n), & xpos.q (n) [, CopOffset]; (size = -3)
The following functions expect the offset to be a positive value which expresses that many
Instructions are assigned for each instance of this command. Note that the above functions are not
may be mixed with the following:
CustomColors CopList #, CCOffset, YPos, Palette, startcol, numcols
CustomString CopList #, CCOffset, YPos, Copper $
In the directory "Blitz Examples" there are examples that use these functions.

InitCopList CopList#, ypos, height, type, sprites, colors, customs

The #agacolors flag must always be set if there are more than 32 colors or 24-bit color definitions
should be used.
Smoothscrolling - soft scrolling
If the #smoothscrolling flag has been set, the extended form of the function must be used
DisplayBitmap so that the bitmap can be displayed at any position,
this allows the programmer to scroll the bitmap being displayed.
Note:
• Always use the enhanced version of DisplayBitmap with #smoothscrolling set
Flag, even if the bitmap is displayed at coordinate 0, 0.
• DisplayBitmap accepts X-coordinate values ​​of type Quick (.q) and positions them
Bitmap on AGA machines in pixel groups.
• The width of the display decreases compared to the default values ​​320, 640, 1280 when
#smoothscrolling is enabled.

Dual Play Fields
If the #dualplayfields flag is set, two bitmaps will be superimposed on the same display
displayed. A combination of the flags #dualplayfields and #smoothscrolling allows parallax
Effects. This effect occurs when both bitplanes are scrolled at different speeds. Note that
it is possible to use two 16-color bitmaps on AGA machines when #dualplayfields is enabled
is and the number of bitplanes is set to 8.
Sprites
The number of available sprites depends on the type of display and the fetchmode settings. The
Most AGA modes require the display to be downsized to represent 8 sprites at a time
to be able to. Currently, this can only be achieved by using the DisplayAdjust function.
Examples can be found on the "Blitz Examples" diskette.
The AGA hardware allows the programmer to use LowRes, HighRes and SuperHighRes
Sprites. The higher resolutions allow a graphics dithering (the targeted use of pixel
Noise to avoid hard color transitions). This is especially necessary if
Three colored sprites should be used. Big dithered HighRes sprites can often look better
as 16 colored LowRes sprites.
Note that it is unrealistic to use 4 bitplanes and more than 3 sprites. The result of
Adjustment that would be necessary for this would be a really narrow display.
FetchMode
AGA hardware allows the DMA bitplane to manage data in 16, 32 or 64 pixel groups. ever
The larger the groups, the more bandwidth the processor has. This is particularly noticeable
AGA Amigas without Fastram.
The bitmaps used must always be a multiple of the fetching mode used. The attempt
Using higher fetching modes than 3 (64 pixels) will end up in considerable difficulty
DisplayAdjust still a useful display hinzubekommen. A display with Fetchmode 3 and more
as a sprite should shrink to a width of 256 pixels.
Several displays
If more than one Copper List is to be used, it is important to ensure that between the individual
Copperlisten must have a gap of at least 3 lines. This means that the Y position is the lower one
Copperlist must be the amount of the previous, plus the y-position of the previous, plus 3.
nextCopListY = lastCopListY + lastCopListHeight + 3

Extended copper control
The extended version of InitCopList allows you to assign custom Copper commands.
There are some functions in the display library that require this parameter.
There are two types of Copper commands. The first one allows the Copper every single line of the display
while the second allows the Copper to work on a particular line.
The following functions require a negative offset, this shows the number of instructions to the
must be assigned to each line.

DisplayDblScan CopList #, Mode [, copoffset]; (size = -2)
DisplayRainbow CopList #, register, palette [, copoffset]; (ecs = -1 aga = -4)
DisplayRGB CopList #, register, line, r, g, b [, copoffset]; (ecs = -1 aga = -4)
DisplayUser CopList #, Line, String [, CopOffset]; (size = -len / 4)
DisplayScroll CopList #, & xpos.q (n), & xpos.q (n) [, CopOffset]; (size = -3)
The following functions expect the offset to be a positive value which expresses that many
Instructions are assigned for each instance of this command. Note that the above functions are not
may be mixed with the following:
CustomColors CopList #, CCOffset, YPos, Palette, startcol, numcols
CustomString CopList #, CCOffset, YPos, Copper $
In the directory "Blitz Examples" there are examples that use these functions.


example 1

The first example creates two large bitmaps, drawing in one line and in the other rectangles
become. From the generated 32 color palette, the first bitmap uses the first 16 and the second bitmap
the remaining 16 colors.

The flags for InitCopList are listed below:

#eightbitplanes = $08
#smoothscrolling = $10
#dualplayfields = $20
#lores = $000
#fetchmode3 = $3000
#agacolors = $10000
Note that InitCopList can be executed before switching to FlashMode. All display
Functions are independent of the active mode, except CreateDisplay which is in the
Flash mode must be performed.
Also interesting is the use of the advanced form of DisplayBitmap. She allows it
Assign coordinates for both bitmaps with a single command.
; two 16 color playfields in Dualplayfield mode
BitMap 0,640,512,4
BitMap 1,640,512,4
75
For i=0 To 100
Use BitMap 0:Box Rnd(640),Rnd(512),Rnd(640),Rnd(512),Rnd(16)
Use BitMap 1:Line Rnd(640),Rnd(512),Rnd(640),Rnd(512),Rnd(1)
Next
InitPalette 0,32
For i=1 To 31:AGAPalRGB 0,1,Rnd(256),Rnd(256),Rnd(256):Next
InitCopList 0,$13038
BLITZ
CreateDisplay 0
DisplayPalette 0,0
While Joyb(0)=0
VWait
x=160+Sin(r)*160:y=128+Cos(r)*128
DisplayBitMap 0,0,x,y,1,320-x,256-y
r+.05
Wend
End

Example 2

The second example demonstrates the use of sprites. The DisplayAdjust function is required
so we get access to all 8 sprite channels. Unfortunately it is difficult to get a higher fetchmode
use without having to access a very narrow display.
SpriteMode2 tells Blitz that we want to create 64-pixel sprites for all sprite channels. Without
SpriteMode would otherwise charge each sprite 4 channels. One of the improved features of AGA.
Note that DisplaySprite also allows partial-pixel positions as X-parameters and then tries
to display the sprite at this position.
; gently scrolling 16 color screen with 8x64 sized sprites.

SpriteMode 2
InitShape 0,64,64,2:ShapesBitMap 0,0
Circlef 32,32,32,1:Circlef 16,8,6,2:Circlef 48,8,6,3:Circlef 32,32,8,0
GetaSprite 0,0
BitMap 0,640,512,4
For i=0 To 100
    Use BitMap 0:Box Rnd(640),Rnd(512),Rnd(640),Rnd(512),Rnd(16)
Next
InitPalette 0,48
For i=1 To 31:AGAPalRGB 0,i,Rnd(256),Rnd(256),Rnd(256):Next
InitCopList 0,$10014
DisplayAdjust 0,-2,8,0,16,0 ; underscan!
BLITZ

CreateDisplay 0
DisplayPalette 0,0
For i=0 To 7
DisplaySprite 0,0,20+i*30,(20+i*50)&127,i
Next
While Joyb(0)=0
VWait
x=160+Sin(r)*160:y=128+Cos(r)*128
DisplayBitMap 0,0,x,y
r+.05
Wend
End


example 1

The first example creates two large bitmaps, drawing in one line and in the other rectangles
become. From the generated 32 color palette, the first bitmap uses the first 16 and the second bitmap
the remaining 16 colors.
The flags for InitCopList are listed below:
#eightbitplanes = $ 08
#smoothscrolling = $ 10
#dualplayfields = $ 20
#lores = $ 000
# fetchmode3 = $ 3000
#agacolors = $ 10000

Note that InitCopList can be executed before switching to FlashMode. All display
Functions are independent of the active mode, except CreateDisplay which is in the
Flash mode must be performed.
Also interesting is the use of the advanced form of DisplayBitmap. She allows it
Assign coordinates for both bitmaps with a single command.
; two 16 color playfields in Dualplayfield mode

BitMap 0.640,512.4
Bitmap 1,640,512.4
75
For i = 0 to 100
Use BitMap 0: Box Rnd (640), Rnd (512), Rnd (640), Rnd (512), Rnd (16)
Use BitMap 1: Line Rnd (640), Rnd (512), Rnd (640), Rnd (512), Rnd (1)
Next
InitPalette 0.32
For i = 1 To 31: AGAPalRGB 0,1, Rnd (256), Rnd (256), Rnd (256): Next
InitCopList 0, $ 13038
LIGHTNING
CreateDisplay 0
DisplayPalette 0.0
While Joyb (0) = 0
Vwait
x = 160 + Sin (R) * 160: y = 128 + Cos (R) * 128
DisplayBitMap 0,0, x, y, 1,320-x, 256-y
r + .05
Wend
End

Example 2

The second example demonstrates the use of sprites. The DisplayAdjust function is required
so we get access to all 8 sprite channels. Unfortunately it is difficult to get a higher fetchmode
use without having to access a very narrow display.
SpriteMode2 tells Blitz that we want to create 64-pixel sprites for all sprite channels. Without
SpriteMode would otherwise charge each sprite 4 channels. One of the improved features of AGA.
Note that DisplaySprite also allows partial-pixel positions as X-parameters and then tries
to display the sprite at this position.
; gently scrolling 16 color screen with 8x64 sized sprites.

SpriteMode 2
InitShape 0,64,64,2: ShapesBitMap 0,0
Circlef 32,32,32,1: Circlef 16,8,6,2: Circlef 48,8,6,3: Circlef 32,32,8,0
GetaSprite 0,0
BitMap 0.640,512.4
For i = 0 to 100
Use BitMap 0: Box Rnd (640), Rnd (512), Rnd (640), Rnd (512), Rnd (16)
Next
InitPalette 0.48
For i = 1 To 31: AGAPalRGB 0, i, Rnd (256), Rnd (256), Rnd (256): Next
InitCopList 0, $ 10014
DisplayAdjust 0, -2,8,0,16,0; underscan!
LIGHTNING
76
CreateDisplay 0
DisplayPalette 0.0
For i = 0 to 7
DisplaySprite 0,0,20 + i * 30, (20 + i * 50) & 127, i
Next
While Joyb (0) = 0
Vwait
x = 160 + Sin (R) * 160: y = 128 + Cos (R) * 128
DisplayBitMap 0,0, x, y
r + .05
Wend
End




Originally Posted by bippym  View Post
I've not read the tutorial but if the only thing stopping this working is the shapes then dont give up.

Learn a little about shapes.... all you need to do is grab these properly and it should work..
Agree 100%. I never got along with the shape grabber personally although Ive not tried the version Bippy mentioned. If you focus on getting the shapes file to save properly then your program can go ahead. I would also wonder whether or not anybody has written a tutorial for cutting the shapes.
You can code it yourself. All you need to do is load the .iff containing your shapes in the same way as above. Cut the shapes using

Code:
getashape n,x,y,w,h
where n is shape number, x and y are top left coordinates and w and h are width and height of the desired shape in pixels.
Do this for all shapes and then save the shapes file with
Code:
saveshapes n,n, "shapesfilename"
where n and n specify the range of the shapes you cut previously.

If you want to include the shape cutting as part of your main code you could do it all before you begin the main code and drop the "saveshapes" command as you will be cutting all your shapes "on the fly" at the start of your program. Then you could add the code
Code:
free bitmap n
to release the .iff memory for the rest of your program whilst retaining your newly cut shapes.

Whatever way you go good luck. Apologies for the lack of proper punctuation in this post, Im using a mates wierd norwegian mac


-------------------------------------------

Blitz 2 web site link

http://www.david-mcminn.co.uk/blitz-2000/archives/bb2/


-------------------------------------------------

InitCopList Examples

WBStartup

LoadShape 50,"Background/level1"
LoadPalette 0,"Graphics/palette.pal"

BLITZ

;set up bitmap...
;
BitMap 0,320+16,200,4
BitMap 1,320+16,200,4

InitCopList 0,44,200,$14,8,32,0
DisplayPalette 0,0
CreateDisplay 0

DisplayBitMap 0,0

db=0

Use BitMap 0: Blit 50,0,0
Use BitMap 1: Blit 50,0,0

;while mouse button not hit

While RawStatus(69)=0

VWait
Displaybitmap 0, db

db=1-db

Wend




-----------------------------------------------------------

Adding only 4 bytes to your src makes a big speedup:

Code:
 For a=0 To 31
      AGAPalRGB 0,32+a+bary(0),bar(a),0,0
  ;Next
  ;For a=0 To 31
      AGAPalRGB 0,32+a+bary(1),0,bar(a),0
  ;Next
  ;For a=0 To 31
      AGAPalRGB 0,32+a+bary(2),0,0,bar(a)
  Next
also,

Code:
DisplayBitMap 0,0
Repeat
  ;DisplayBitMap 0,0
  DisplayRainbow 0,0,0

  ;For a=0 To 255
  ;  AGAPalRGB 0,a,0,0,0 ; blank the palette
  ;Next
  InitPalette 0,256   ;< this is an ASM routine inside the blitzlib! trust me: it is faster!

  For a=0 To 2
    bary(a)=bary(a)+baryt(a)
    baryt(a)=baryt(a)+barydir(a)
    If Abs(baryt(a))=13 Then barydir(a)=0-barydir(a)
  Next
And, while setting up the bars:
this
Code:
For a=1 To 16
  bar(a-1)=(a*16)-1
Next
For a=16 To 1 Step -1
  bar(15+(17-a))=(a*16)-1
Next
becomes
Code:
;we try to create bars of 32pixl height:
;the saturation value should spread from 0to255 (AGA),
;the bar appears to be 3d-like.

For a=0 To 15
  bar(a)   = (a*16)       ;we donot reach 255 here...
  bar(a+15)= ((16-a)*16)
Next

---------------------------------------------------------------------------------------------------------------------


; AGA copperbars by Coagulus (EAB)
; modified by Cylon (EAB)

DEFTYPE.w

InitPalette 0,256

BitMap 0,320,256,1  ;just 1 bplane needed! saves chipmem!

Dim bar(32)    ;saturation value (0-255) of bar y line
Dim bary(3)    ; 1-red 2-green 3-blue
Dim baryt(3)
Dim barydir(3)

;we create bars of 32pixl height:
For a=0 To 15
  bar(a)   = (a*16)
  bar(a+15)= ((16-a)*16)
Next

baryt(0)=-3
baryt(2)=3
barydir(0)=1
barydir(1)=1
barydir(2)=1

VWait 100    ;two seconds is enough before takin' the machine over

BLITZ

;SpriteMode 2 ;not needed.

;1bitplane 24bit(256,256,256) aga coplist
;again: we use the copper only, so 1 bplane is enough.
InitCopList 0,34,256,$10000|$01|$10|$400,8,1,-4
CreateDisplay 0

DisplayPalette 0,0
DisplayBitMap 0,0

Repeat
  VWait
  DisplayRainbow 0,0,0

  InitPalette0,256

  For a=0 To 2
    bary(a) +baryt(a)
    baryt(a)+barydir(a)
    If Abs(baryt(a)) = 13 Then barydir(a)=0-barydir(a)
  Next

  For a=0 To 31
      AGAPalRGB 0,32+a+bary(0),bar(a),0,0
      AGAPalRGB 0,32+a+bary(1),0,bar(a),0
      AGAPalRGB 0,32+a+bary(2),0,0,bar(a)
  Next

Until Joyb(0) OR Joyb(1)

End

----------------------------------------------------------------------------------------------------

NEWTYPE .bullets
x.q
y.q
dx.q
dy.q
speed.q
alive.b
End NEWTYPE

db.b

LoadShape 0,"bullet.bsh"
LoadPalette 0,"bullet.iff" ;<--- 256 color iff


Dim sinus(360)
For i=0 To 360
    sinus(i)=Sin(i*Pi/180)
Next

Dim cosinus(360)
For i=0 To 360
    cosinus(i)=Cos(i*Pi/180)
Next

Dim List bullet.bullets(200)


For i=0 To 45
  If AddItem(bullet())
    bullet()\x=160+10*cosinus(8*i)
    bullet()\y=128+10*sinus(8*i)
    bullet()\alive=1
    bullet()\speed=1
    bullet()\dx=bullet()\speed*cosinus(8*i)
    bullet()\dy=bullet()\speed*sinus(8*i)
  EndIf
Next




BLITZ

BitMap 0,320+64,256+64,3;<--- for doublebuffer ??first?? playfield 8 color
BitMap 1,320+64,256+64,3;<--- for doublebuffer ??first??playfield 8 color
BitMap 2,320+64,256+64,5;<--- ??second?? playfield 32 color

Buffer 0,2*16384:Buffer 1,2*16384; allows us to store moving objects on each bitmap

InitCopList 0,44,256,$10038,8,256,0; <---- AGA+SMOOTH SCROOLING+ 2 PLAYFIELD + 256 color

DisplayPalette 0,0
CreateDisplay 0

Repeat                       ;

 VWait

 DisplayBitMap 0,db,16,16,2,0,0



 db=1-db                      ; alternates between bitmaps 1 and 0...
 UnBuffer db                  ; erase previous gfx stored in buffer ready to update positions
 Use BitMap db

 Gosub update_bullets
 Gosub draw_bullets



                     ;
 ;Poke.w $dff180,$fff   ;


 Until Joyb(0)=1         ;


End


.update_bullets
ResetList bullet()
While NextItem(bullet())
  If bullet()\x < 6 Then bullet()\alive=0
  If bullet()\x >320+16 Then bullet()\alive=0
  If bullet()\y < 6 Then bullet()\alive=0
  If bullet()\y > 256+16 Then bullet()\alive=0

  If bullet()\alive =1
    bullet()\x=bullet()\x+bullet()\dx;
    bullet()\y=bullet()\y+bullet()\dy;
  Else
    KillItem bullet()
  EndIf
Wend
Return



.draw_bullets
ResetList bullet()
While NextItem(bullet())
  BBlit db,0,bullet()\x,bullet()\y;
Wend
Return


---------------------------------------------------------------------------------------------------------------------------------

The Display Library
The display library is similar in concept to the slice library described above, however it uses a more flexible approach, and also supports the extended capabilities of the AGA chipset. It translates more closely to how the Amiga display hardware actually works, which gives the programmer more control over its behaviour. Unfortunately this can also make it appear slightly more complicated to use.

Defining the display
To create a display, first you need to set up the Coplist. A Coplist is a set of low-level instructions used by the "Copper", a special circuit that controls how the on-screen display is built from information in Chip memory, line-by-line. Programming the copper allows for some interesting tricks and effects (such as changing colours of pens part of the way down the screen, reusing sprites further down the screen, etc.) The program itself is built internally by Blitz, but you need to tell it what type of display you require first. This is achieved using the InitCopList command. As with the Slice command, there are two versions of this, a short version which sets up the Coplist with typical values based on the flags you provide, and a long version that lets you control more aspects. The short version looks like this:

InitCopList 0, $10000+$20+$6 ; #sixbitplanes $ 06
The 0 is the ID of the Coplist object to create, and the second parameter is the flags value. Flag parameters should be added together, and the number of bitplanes required should be added to the flags as well.
The flags are listed in the Blitz manual, but the important ones are as follows:

Value Coplist Properties
$10 Enable smooth scrolling
$20 Dual playfield display
$40 Extra-halfbrite (EHB) display mode
$100 Make high resolution (640 pixels wide)
$400 Use low resolution sprites
$800 Use high resolution sprites
$1000 Enable fetch mode 1
$2000 Enable fetch mode 2
$3000 Enable fetch mode 3
$10000 Use AGA palette


Fetch mode refers to the access the Copper has to the Chip memory at the start of each display line, where it fetches the bitplane information it needs for the upcoming line of graphics to be drawn. The default is fetch mode 0,
which is the OCS/ECS chipset mode. Higher fetch modes are AGA only and allow more bitplane data to be read on every line, increasing the the number of bitplanes available in every resolution to 8 (256 colours),
including VGA-style 31kHz modes. However, they also reduce the bandwidth available for the rest of the display, so to have many large sprites displayed
at the same time, you'll need to reduce the horizontal width of your screen, otherwise sprites might go missing or other issues might crop up. Most other flags are self-explanatory.

AGA palette means that the RGB values possible range from 0-255 in each of the red, green and blue components (8 bits per channel for a 24-bit palette) instead of the OCS/ECS range of 0-15 (4 bits per channel for a 12-bit
palette). Obviously using any of the AGA-specific values (high resolution sprites, 8 bitplanes, fetch modes, AGA palette) means that your software will only work on AGA machines.

The longer form of the InitCopList command has the following template:

InitCopList CopList#, ypos, height, flags, sprites, colors, customs

CopList# is the ID of the Coplist to create, ypos is the vertical position on the screen, with 44 being a typical value as with slices. The height of the display is defined in pixels, and the flags parameter is described above.
Sprites is the number of sprite channels to use, and should normally be 8, even if you don't use them. Colours is the number of pens you want available, up to 256 on AGA machines or 32 on OCS/ECS machines. Note that this
refers to the number of palette registers allocated for the CopList, not the number of bitplanes as defined in the flags field. For using sprites for example, you will want to allocate 32 pens, even if you're only using
an eight-colour, three-bitplane display, because the sprites use pens 17-31. Finally, customs is the amount of memory to
allocate for custom copper commands. This can normally be set to 0 unless you intend to use a custom Coplist you write yourself, or one of the custom copper commands listed in the Blitz manual.

Once the Coplist is defined, the display can be opened using the CreateDisplay command:

CreateDisplay 0

This creates a display based on Coplist object ID 0. As for slices, more than one Coplist can be displayed, provided they are defined in vertical order and do not overlap. Multiple Coplists can be displayed by adding the required Coplists to the CreateDisplay command:

CreateDisplay 0, 1, 2

Displaying Bitmaps
Bitmaps can be shown on any Coplist using the DisplayBitmap command:

DisplayBitmap 0, 1

Shows Bitmap object ID 1 on Coplist display ID 0. The top left of the bitmap will be placed at the top left of the display. Similarly to the Slice methods, coordinates can be given to show a different area of the bitmap:

DisplayBitmap 0, 1, 50, 25

In this case, bitmap 1 will have coordinates 50x20 placed in the upper left corner of the display.

Dual playfield displays also use the DisplayBitmap command for showing the second bitmap:

DisplayBitmap 0, 1, 2
This will display bitmap 1 as the rear playfield with bitmap 2 in front, both on Coplist 0. Coordinates can also be added independently for both bitmaps to show another section of each bitmap:

DisplayBitmap 0, 1, 50, 25, 2, 30, 60
Coordinates 50x25 on the rear bitmap are positioned in the top left of the display, with coordinates 30x60 on the front bitmap positioned at the top left.

Note: On AGA machines, fractional arguments are allowed for the x coordinates, in which case bitmaps will be positioned using fractions of a pixel. This allows for super-smooth horizontal scrolling. To enable this however, the Coplist must have the smooth scroll flag set. Note that this flag will disable sprite channel 7 due to the DMA timing required for sub-pixel scrolling.

Sprites
Sprites have a separate set of commands for use with the Display Library. They can be created in the same way as covered in the Internal Graphics Commands page, but to display them, you need to use the DisplaySprite command:

DisplaySprite 0, 1, 150, 75, 5
This will display the Sprite object 1 on Coplist 0 at the coordinates 150x75, using sprite channel 5. Again, on AGA machines, fractions of pixels are possible for the x position in order to synchronise with a smooth scrolling display.

To use sprites wider than 16 pixels, you need to have the fetch mode for the sprites set appropriately; change the sprite mode using the SpriteMode command:

SpriteMode 2
This should be run before creating the CopList or any sprite objects. Sprite mode 0 is the same as OCS/ECS, and allows sprites 16 pixels wide. Sprite mode 1 allows up to 32 pixels wide, and sprite mode 2 allows up to 64 pixels wide.

Palette
To apply a Blitz Palette object to the coplist, use the DisplayPalette command:

DisplayPalette 0, 3
This copies the colours from Palette object ID 3 to Coplist 0.

------------------------------------------------------------------------------------------------------

#G     =16

BitMap 0,640,512,2
LoadBitMap 0,"ram:gfx_hero.iff",0

cnt.w=1000   ;      <<<<---- THIS ONE IS MAKING TROUBLE
For y.b=0 To 8
  For x.b=0 To 7
    GetaShape cnt,x*#G,y*#G,#G,#G
    cnt+1
  Next x
Next y

Free BitMap 0
Print "done"
MouseWait



----------------------------------


Problem solved!!  all the glitches are gone

In the early startup menu I had to tick "disable processor cache"



-------------------------------------------------------

Hi! What's the fastest way of testing bounding box collisions in BB2? Is there any built in functions for that or do I need to make my own system? I guess there is no
short-circuit evaluation going on in BB2 so it might be faster to check for bounding box collisions in multiple if clauses instead of combining them. Grateful for any insight!

I can't comment on the speed, but the RectsHit command might be what you're looking for:

RectsHit (X1,Y1,Width1,Height1,X2,Y2,Width2,Height2)

Returns true if they overlap.

I love that, in the manual, they actually say "Care should be taken with the pronunciation of this command."

------------------------------

http://www.david-mcminn.co.uk/blitz-2000/archives/mildred/

------------------------------------------------------------


WbToScreen 0
ShowScreen 0
WBStartup

BitMap 0,800,600,2
LoadBitMap 0,"ram:whitePicture.iff"

cnt.w=0
For x.w=0 To 9
  GetaShape cnt,x*16,0,16,16
  cnt+1
Next x

wFlags.l=$2|$4|$8|$400
Window 0,0,16,190,190,wFlags,"test",0,0

cnt.w=0
For y.w=0 To 7
  For x.w=0 To 9
    WBlit cnt,8+x*16,8+y*16
    cnt+1
    If cnt>9 Then cnt=0
  Next x
Next y

Repeat
  ev.l=WaitEvent
  If ev=$200
    Free Window 0
    End
  EndIf
Forever


---------------------------------------------------


WbToScreen 0
ShowScreen 0
WBStartup

BitMap 0,320,256,2
LoadBitMap 0,"ram:test.iff",0

wFlags.l=$2|$4|$8|$400
Window 0,0,16,190,50,wFlags,"test window",0,0

GetaShape 0,0,0,16,16
WBlit 0,0,0

Repeat
  ev.l=WaitEvent
  If ev=$200 Then End
Forever

----------------------------------------------

Quote:
Originally Posted by Toni Wilen  View Post
Sounds like you have weird/bad MMU setup that makes chip ram cacheable.
EDIT: Does anything change if you install this: http://aminet.net/util/libs/MMULib.lha
Thanks!!!
That package did the trick
The glitches are gone.

------------------------------------------

qblit 0,frame,posx,poy


--------------------------------------


Old 09 December 2015, 19:35   #1
idrougge
Registered User

Join Date: Sep 2007
Location: Stockholm
Posts: 3,678
Smooth vertical scrolling in AMOS
It seems people have asked about how to achieve smooth scrolling in AMOS, so I thought I'd share the code I sweated together a few years ago. Further comments below the code:
Code:
Set Buffer 32 : Rem Enlarge variable space to contain a larger map

MAPPATH$="Data:AMOS/bana.txt" : Rem -- Path to map file in ascii format

' Open main screen. It should be twice as tall as the visible portion, plus 32 pixels
Screen Open 0,320,512+32,16,Lowres
Screen Hide : Curs Off : Flash Off : Cls 0 : Colour Back $F : Hide : Screen Show
' Open small screen for debug output
Screen Open 1,320,8,2,Lowres
Screen Hide : Curs Off : Flash Off : Cls 0 : Colour Back $F : Hide : Screen Show
Screen Display 0,135,50,320,256
Screen Display 1,135,40,320,8
Screen 0

LäNGD=500 : Rem          -- Length of map
Dim MAP(9,LäNGD) : Rem   -- Set up map array
Global LäNGD,JAG_X,JAG_Y,FI_X,FI_Y,SK_Y,MAP(),VROW,VPOS,_DRAWX,_DRAWY,MAPPATH$
INIT : Rem               -- Initial setup
MAIN : Rem               -- Jump to main routine

Procedure INIT
   MAPDRAW : Rem                     -- Load and render map
   JAG_X=160-8 : JAG_Y=256-32 : Rem  -- Variables for player sprite
   FI_X=100 : FI_Y=10 : Rem          -- Variables for enemy sprite
   SK_Y=256+32 : Rem                 -- Counter for screen display coord
   VROW=8 : Rem                      -- Row in map to read
   VPOS=LäNGD-1 : Rem                -- Row in MAP array to count from
   _DRAWX=0 : _DRAWY=8 : Rem         -- Row and column for drawing blocks
   Bob Update Off
End Proc

Procedure MAPDRAW
   LADDATEXT : Rem                   -- Load map from disc
   Load "data:amos/shmup32x32_2.abk" : Rem    -- Load tiles
   Get Icon Palette
 
   ' Error handling in case icon 0 is missing
   For Y=0 To 499
      For X=0 To 9
         If MAP(X,Y)=0 Then MAP(X,Y)=1
      Next X
   Next Y
 
   ' Draw map on screen
   Y=LäNGD-1-(512/32)
   For V=0 To 512 Step 32
      For X=0 To 9
         Paste Icon X*32,V,MAP(X,Y)
      Next X
      Inc Y
   Next V
End Proc

Procedure LADDATEXT
   ' Load a map file in pure text format from disc.
   ' On Error Proc THEEND
   Open In 1,MAPPATH$ : Rem          -- Open map file
   For Y=0 To 499
      Line Input #1,ROW$
      For X=0 To 9
         CELL$=Mid$(ROW$,X*3,3)
         MAP(X,Y)=Val(CELL$)
      Next X
   Next Y
   Close 1
End Proc

Procedure MAIN
   Repeat
      INMATNING : Rem                -- Get input from player
      If SK_Y>0 Then Screen Offset 0,0,SK_Y Else RESETSCREEN
      Wait Vbl
      ' Write debug information      -- Comment out line below to gain speed
      Screen 1 : Locate 0,0 : Print "SK_Y:";SK_Y;" RX:";_DRAWX;" RY:";_DRAWY;" VR:";VROW;" VP:";VPOS;"   "; : Screen 0
   
      If SK_Y>256-64 : Rem           -- Top portion of screen not visible
         If _DRAWY=>0
            ' Comment out this line to get smooth performance on slow systems
            Screen 1 : Locate 36,0 : Print "/\"; : Screen 0
            ' Draw blocks from the middle upwards
            Paste Icon 32*_DRAWX,32*_DRAWY,MAP(_DRAWX,VPOS-VROW)
            ' Draw two blocks so that the scroll doesnt get ahead
            Paste Icon 32*_DRAWX+32,32*_DRAWY,MAP(_DRAWX+1,VPOS-VROW)
         End If
      End If
   
      If SK_Y<160 : Rem              -- Bottom portion of screen not visible
         If _DRAWY>8
            ' Comment out this line to get smooth performance on slow systems
            Screen 1 : Locate 36,0 : Print "\/"; : Screen 0
            ' Draw two blocks from below
            Paste Icon 32*_DRAWX,32*_DRAWY,MAP(_DRAWX,VPOS-VROW)
            Paste Icon 32*_DRAWX+32,32*_DRAWY,MAP(_DRAWX+1,VPOS-VROW)
         End If
      End If
   
      SPRITAR : Rem               -- Draw sprites
   
   Until Mouse Key
   Edit
End Proc

Procedure RESETSCREEN
   SK_Y=256+32 : Rem              -- Reset coarse counter 
   VROW=8 : Rem                   -- Reset row offset in map
   _DRAWX=0 : _DRAWY=8 : Rem      -- Reset screen coordinates for pasting
   Screen Offset 0,0,SK_Y : Rem   -- Reset screen Y offset to bottom
End Proc

Procedure INMATNING
   ' Input handler 
   If Jup(1)
      Dec SK_Y
      Dec SK_Y
      If _DRAWX<7
         Inc _DRAWX
         Inc _DRAWX
      Else
         _DRAWX=0
         Dec _DRAWY
         Inc VROW
      End If
   
      If SK_Y=100
         _DRAWX=0
         VROW=0
         _DRAWY=16
         VPOS=VPOS-9
      End If
   
      If SK_Y mod 32=0 : Rem      -- At border between blocks...
         'Bell 22
      End If
   
   End If
 
   If Jleft(1) and JAG_X>112 Then Dec JAG_X
   If Jright(1) and JAG_X<418 Then Inc JAG_X
   If Fire(1) Then End
End Proc


Procedure SPRITAR
   ' Draw player and enemy sprites
   Sprite 0,JAG_X,JAG_Y,1
   Sprite 8,FI_X+100,FI_Y,2
   Add FI_Y,4
   If FI_Y>300
      FI_X=Rnd(300)+30
      FI_Y=30
   End If
End Proc
How does it work? The principle is like double buffering, but on a single bitmap instead of two separate ones. The bitmap is twice the height of the visible screen, so that you may draw on the non-visible portion while scrolling the "viewport" along the bitmap. This makes for some unpretty code, since the program must decide whether to write on the upper or lower part of the screen, which also necessiates reading from different parts of the map file. The program would be a lot shorter and easier to read were it not for the requirement to handle these cases.
This example uses 32x32 pixel blocks for the background graphics. There are some debug lines for printing debug output which work on my A4000. If you remove those lines, the program scrolls smoothly even on a lowly A600.
Attached Files
File Type: lha AMOSScrollDemo.lha (11.7 KB, 127 views)

---------------------------------------------------------------------------------

Tried it out on a real 1200 (030@40mhz). Pretty impressive but does slow down quite a lot when blitting the big bobs - don't see so much slow down on bullets so if your intention was to create a bullet hell engine - looks a real possibilty.

One thing i have notice through my own efforts is that winuae seems to blit faster than a real Miggy (it may be a setting I have to change in Winuae) i.e. I have a working Doodle Jump engine which seems fast enough when tested through Winuae (and I do limit processor speed etc.) but is slower on real hardware. This is where sprites v bobs comes in...

I found an interesting sprite routine a while back (might have been here?) which might be worth investigating for more speed? It's call bb2vspr and can be found on the Aminet:

http://aminet.net/package/dev/basic/BlitzLstApr98

Just download the Blitzlist and unzip.

Keep up the good work!!!

----------------------------------------------------------------

Master484
Registered User
Master484's Avatar

Join Date: Nov 2015
Location: Vaasa, Finland
Posts: 330
I just uploaded an improved version, which has been added to the attachments of the first post.

Changes in version 2:

- Player sprite now always moves at 50 FPS.
- 15 % better BOB drawing speed and more consistent frame rate.
- added info texts to screen panel area, which show current Object amount (text updates every 4th seconds)
- 2 crash bugs fixed ( such as "move to up right corner and press space" )

---

Drawing speed is now much better. On A500 we can have 13 enemies or 29 bullets at 25 FPS.

And Player sprite is now updated from the VBlank interrupt, and it's always drawn at 50 FPS, even with 100+ objects on screen.

On A1200 speed is either 17 enemies and an amazing 50 bullets at 25 FPS. I guess A1200 is so good at drawing the bullets because the collision detection routines are so much faster thanks to the 2x faster CPU.

Also collisions and background draw is now done during frame 1, and object draw + bitmap "Show" is done during frame 2. This allowed 15 % more drawing power.

And speaking about the collisions, I currently use the standard collsion routine command of Blitz ( RectsHit ), which is good, but not the fastest possible way...so I think later I'll add the custom routines from my Megaman X project, and collision check speed should improve about 10%-20% from what it is now.

---

So, this looks quite good, a 32 color shmup is certainly possible with this techinque. And if everything would be drawn in 16 color mode instead of 32 colors, then we could draw maybe 15 % - 20 % more, and still have a separate 16 color sprite palette for 16 "extra" colors. I think I'll test this too, could even run at 50 FPS, at least on A1200.


----------------------------

ftp://grandis.nu/~Uploads/idrougge/

ftp://grandis.nu/~Uploads/BippyM/


map editor

http://eab.abime.net/showthread.php?t=80646

------------------------------------------------------------------------


; init code and img loading & shape adquiring...
; now the problematic code:
statement paintmap{bitmapnum, startx, starty}
  shared map()

  use bitmap bitmapnum
  for y=0 to 15
    for x=0 to 19
      blit map.b(startx + x, starty + y), x asl 4, y asl 4
    next
  next
end statement

blitz
slice 0,44,320,256,$fff8,5,8,32,320,320

paintmap{0,mapx,mapy}
show 0
use palette 0

mousewait
end


Just a shot in the dark, but is that a compile time error? Is it simply because blitz expects a Blit command after a BLITZ call in the program listing - even though it's in a statement?


-------------------------------------------------------------------
Hi!

This is what i have for now, i'll put some lines of code, not the entire source, as i try another things aside from tile map scrolling :-)

; my two main bitmaps
BitMap 0, 480, 416, 4 ; doble buffer 1
BitMap 1, 480, 416, 4 ; doble buffer 2

; my screen mode
Slice 0, 44, 320, 256, $fff8, 4, 8, 32, 480, 480

; my tile grabbing section (i use an iff image with all 16x16 tiles), i have
; first 24 shapes for soft sprites
Use BitMap 4
i=0
For y=0 To 2
For x=0 To 19
GetaShape 24 + i,x LSL 4,y LSL 4,16,16
i = i + 1
Next
Next

; my map, and the loading bit, i use map editor "tiled" for mac/pc and
; save the file as json, later i convert it to binary with a tool i made
; with lazarus (free delphi clone)
If ReadFile(0,"desierto3.map")
ReadMem 0,&maxmapax.b,1 ; width in tiles
ReadMem 0,&maxmapay.b,1 ; height in tiles
maxmapax = maxmapax - 1
maxmapay = maxmapay - 1
Dim mapa.b(maxmapax,maxmapay)
ReadMem 0,&mapa.b(0,0),(maxmapax+1)*(maxmapay+1)
CloseFile 0
End if

; main loop, currently i have only a gosub to update scx and scy vars
Repeat
VWait
Show db, scx,scy
db = 1 - db
; updatebackground is a flag to allow for doublebuffer replication
If updatebackground Then Gosub clonebackground
; now i call a subroutine to detect key strokes to move the screen
; left - right - top - bottom, so if i update scx and scy and if i reach
; the bitmap border i call drawmap to update bitmaps with new
; map tiles
Gosub moveScroll
Until RawStatus($45)

.drawmap:
; for now i repaint the entire bitmap, here i want to use blockscroll to move
; all tiles to the final position, and then add only new columns/rows
Use BitMap db
FlushBuffer db
For y=0 To 25
For x=0 To 29
Block 24+mapa(startx + x,starty + y),x LSL 4,y LSL 4
Next
Next
updatebackground = 1
Return

.clonebackground:
CopyBitMap 1 - db,db
updatebackground = 0
Return



-----------------------------------------------------------------------------------------------


WBStartup
DEFTYPE.w

imagew = 455
displayw = 320

BitMap 0,imagew,256,6
LoadBitMap 0,"school-ham.iff",0

InitCopList 0,44,256,$6 + $80 + $10,8,32,0

VWait 100

BLITZ

CreateDisplay 0
DisplayPalette 0,0
DisplayBitMap 0,0,0,0

While Joyb(0)=0
  VWait
Wend

QAMIGA

Free Palette 0
Free BitMap 0


End

Ok I tracked it down, it appears to be to do with having smooth scrolling enabled as even when I cropped the image to 320x256 it still was fringing on the left edge.

Disabling smooth scrolling seemed to work. ($86 instead of $96 for the copper list options)

-=----------------------------------


Zone Friend

Join Date: Aug 2005
Location: Germany
Age: 46
Posts: 424
or look http://www.back2roots.org/CDs/Tools/Update//240/

http://www.blitzbasic.com/


http://grandis.nu:81/eabsearch/search.php?_search_=1&search=Blitz+Basic+2&category_id=Commodore_Amiga&exclude=&limit=100


-----------------------------------------------


ASM frin mcgeezer

; Initialise Normal Sprite DMA
bsr INIT_COPPER_SPRITES

; Wait for line 26
move.l #$1a01ff00,(a1)+
;bsr RESET_COPPER_SPRITES

; Upper sprite zone
lea COPPTR_HARDWARE_UPPER_SPRITE_0-data(a4),a3
bsr CREATE_COPPER_SPRITE_POINTERS

; Set display properties, modulo, bitplanes...
move.l a1,COPPTR_BPLCON-data(a4)
move.w #BPLCON0,(a1)+ ; 0 ; This is play area
move.w #$0000,(a1)+    ; 2 ; 8 PLanes here
move.w #BPLCON1,(a1)+ ; 4
move.w #0,(a1)+  ; 6
move.w #BPLCON2,(a1)+ ; 8
move.w #$30,(a1)+ ; 10
move.w #BPL1MOD,(a1)+ ;
move.w #$9c,(a1)+ ; a0
move.w #BPL2MOD,(a1)+ ;
move.w #$9c,(a1)+ ; a0

; Load Main Palette
lea PAL_RYGAR_FG,a0
move.l #$180,d2
moveq #32-1,d7

.main_pal:
move.l #$01060c00,(a1)+
move.w d2,(a1)+
move.w (a0)+,(a1)+
move.l #$01060e00,(a1)+
move.w d2,(a1)+
move.w (a0)+,(a1)+
addq.w #2,d2
dbf d7,.main_pal



-----------------------------------------------------------------------


START:  MOVE.L #CUSTOM,A5
move.w DMACONR(A5),d0
or.w #$8000,d0
move.w d0,olddmareq

move.l 4,a6
move.l #gfxname,a1
jsr OldOpenLibrary(a6)
move.l d0,gfxbase
move.l d0,a6
move.l 38(a6),oldcopper

jsr WaitTOF(a6)
move.l 4,a6
jsr Disable(a6)
        ;MOVE.W #$7FFF,INTENA(A6) ;Clear interrupt enable
     
        MOVE.L #COPPERLIST,COP1LCH(A5) ;Write to Copper location register
        MOVE.W #(DMAF_SETCLR!DMAF_COPPER),DMACON(A5)

MOVE.L #$21000,a1 ;Point at beginning of bit-plane
        MOVE.L #$FF00FF00,d0 ;We will write $FF00FF00 long words
MOVE.W #2000,d1 ;2000 long words = 8000 bytes
LOOP:   MOVE.L d0,(a1)+ ;Write a long word
DBRA d1,LOOP ;Decrement counter and loop until done

LOOP1: btst.b #6,CIAAPRA ;if mouse button pressed then exit
beq exit
btst.b #7,CIAAPRA ;if joystick 1 or 2 pressed then exit
bne LOOP1

exit: move.w #$7fff,DMACON(A5)
move.w olddmareq,DMACON(A5)

move.l oldcopper,COP1LCH(A5)
move.l gfxbase,a6
jsr WaitTOF(a6)
move.l $4,a6
jmp Enable(a6)

gfxname DC.B 'graphics.library',0

CNOP 0,4
oldcopper: dc.l 0
gfxbase: dc.l 0
olddmareq: dc.w 0
oldintreq: dc.w 0
oldintena: dc.w 0
oldadkcon: dc.w 0

SECTION Copper,DATA_C
COPPERLIST:
DC.W BPL1PTH,$0002 ;Move $0002 to address $0E0 (BPL1PTH)
DC.W BPL1PTL,$1000 ;Move $1000 to address $0E2 (BPL1PTL)
DC.W BPLCON0,$1200 ; Bit-Plane control reg.
DC.W BPLCON1,$0000 ; Hor-Scroll
DC.W BPLCON2,$0010 ; Sprite/Gfx priority
DC.W BPL1MOD,$0000 ; Modolu (odd)
DC.W BPL2MOD,$0000 ; Modolu (even)
DC.W DIWSTRT,$2C81 ; Screen Size Start
DC.W DIWSTOP,$2CC1 ; Screen Size Stop
DC.W DDFSTRT,$0038 ; H-start
DC.W DDFSTOP,$00D0 ; H-stop
DC.W COLOR00,$0F00 ; Color #0 = red
DC.W COLOR01,$0FF0 ; Color #1 = yellow
DC.L $FFFFFFFE ;End of Copper list





-------------------------------------------------------

http://www.bombjack.org/amiga/index.htm

Assembly Course

http://www.palbo.dk/dataskolen/maskinsprog/

Read this thread

http://eab.abime.net/showthread.php?t=42091

English link
http://palbo.dk/dataskolen/maskinsprog



Old 22 April 2006, 19:43   #25
BippyM
Registered User
EAB Supporter !
BippyM display one advert, thanks
BippyM's Avatar

Join Date: Nov 2001
Location: Nottingham, UK
Age: 43
Posts: 8,714
Hey my FTP there.. IT's offline atm..

It's on my hom,epage tho

http://homepage.ntlworld.com/bippym/reqs/Programming/

Help yourself

No comments:

Post a Comment