English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 05 December 2014, 10:03   #1
jimmy2x2x
Beyond Mutton
jimmy2x2x's Avatar
 
Join Date: Mar 2011
Location: North West, UK
Age: 46
Posts: 347
Quick blitter refresher please!

I'm plodding away at my bruce Lee project and have been using hardware sprites exclusively up until now, the time has come to use the blitter! I haven't touched it for decades and was hoping for a quick refresher, pretty please ☺ Maybe something like a simple straight memory copy would be great, although any well documented source would be useful. Thanks!
jimmy2x2x is offline  
AdSense AdSense  
Old 05 December 2014, 12:17   #2
pmc
rebooting...
pmc's Avatar
 
Join Date: Apr 2007
Location: Elsewhere
Posts: 1,595
Don't usually come here anymore but spotted this on an infrequent visit and so, for old times sake:

Wait for blitter to be ready (might also be worth setting blitter priority bit first in dmacon (not shown in snippet below)):

Code:
.wait:    btst.b    #6,$dff002
            bne.b    .wait
then set required bits of blitter control regs, masks, modulos and pointers as relevant for the blit you want to do and then write to blitsize reg ($dff058) to set the blit running.

All very straightforward - check the well written docs as per the (what else...?) Hardware Ref Manual
pmc is offline  
Old 05 December 2014, 13:22   #3
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,019
Quote:
Originally Posted by jimmy2x2x View Post
Maybe something like a simple straight memory copy would be great,
For a simple memory copy on word-boundaries you would use channel A and D, which is the fastest mode. You have to set up BLTAFWM and BLTALWM to $ffff, turn on DMA for channel A and D in BLTCON0, clear BLTCON1, BLTAMOD, BLTDMOD, write the source pointer to BLTAPT and the destination pointer to BLTDPT and finally start with blit with writing the size to BLTSIZE.

In most cases you want to copy to a bitmap, so you need to set up the modulos (e.g. BLTDMOD = bytes_per_row - image_width). And when you want to blit to a not-word-aligned position in the bitmap then you have to shift the input stream by 0-15 bits. This requires to read/write one additional word per line to give room for the right-shifted bits (in ascending mode). You also need masking.

Quote:
although any well documented source would be useful.
Here is a simple example to copy a masked image into a bitmap. BPR defines the number of bytes per row in the bitmap. YOffTab is a table with bitmap offsets for each row (y*BPR). The WAITBLIT macro may be similar to the code pmc has given.

Code:
bltmasked:
; Copy a word-aligned, masked image to a bitmap position.
; Doesn't check whether height is greater than 1024!
; d0.w = xpos
; d1.w = ypos
; d2.w = width in words
; d3.w = height in lines (multiplied by PLANES for interleaved bitmaps)
; a0 = destination View's bitmap
; a1 = image pointer
; a2 = image mask pointer

        movem.l d2-d3/a3,-(sp)

        lsl.w   #6,d3
        addq.w  #1,d2                   ; extra word for shifting
        or.w    d2,d3
        swap    d3
        move.w  d2,d3
        add.w   d3,d3                   ; d3 BLTSIZE | width in bytes

        ; add ypos to bitmap pointer
        lea     YOffTab(a4),a3
        add.w   d1,d1
        add.w   d1,d1
        add.l   (a3,d1.w),a0

        ; make BLTCON0, BLTCON1
        moveq   #15,d2
        and.w   d0,d2
        ror.w   #4,d2                   ; ASH, BSH
        move.w  d2,d1
        or.w    #$0fca,d1               ; use ABCD, D=AB+/AC
        swap    d1
        move.w  d2,d1                   ; d1 BLTCON0 | BLTCON1

        ; add xpos to bitmap pointer
        asr.w   #4,d0
        add.w   d0,d0
        add.w   d0,a0                   ; a0 bitmap pointer

        ; BLTBMOD is -2, because we read an additional word for shifting.
        ; BLTCMOD and BLTDMOD are BPR - (width in bytes)
        moveq   #BPR,d0
        sub.w   d3,d0
        swap    d0
        subq.w  #2,d0                   ; d0 BLTCMOD | BLTBMOD

        moveq   #-1,d2
        clr.w   d2                      ; d2 BLTAFWM=$ffff | BLTALWM=$0000
        swap    d3                      ; d3 BLTSIZE
        move.l  a0,a3

        ; copy masked image
        WAITBLIT
        move.l  d0,BLTCMOD(a6)
        swap    d0
        move.l  d0,BLTAMOD(a6)
        movem.l d1-d2/a0-a3,BLTCON0(a6)
        move.w  d3,BLTSIZE(a6)

        movem.l (sp)+,d2-d3/a3
        rts
When using the Blitter it is recommended to do all calculations before waiting and then write all registers as quickly as possible.
phx is offline  
Old 05 December 2014, 13:23   #4
BippyM
Global Moderator

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 42
Posts: 8,621
Why do you not visit pmc? (soorry for OT post)
BippyM is online now  
Old 05 December 2014, 15:27   #5
Photon
Moderator
Photon's Avatar
 
Join Date: Nov 2004
Location: Hult / Sweden
Posts: 4,452
Seemed like a good topic for Coppershade, so I added it. It should get you started. Hope you like it!

> Programming the Blitter
Photon is offline  
Old 05 December 2014, 16:55   #6
jimmy2x2x
Beyond Mutton
jimmy2x2x's Avatar
 
Join Date: Mar 2011
Location: North West, UK
Age: 46
Posts: 347
Brilliant support, that's why I love this forum. Thanks very much guys, it would be easy to give up re-learning the Amiga on my own. I will try and get some useful blits working tonight!
jimmy2x2x is offline  
Old 05 December 2014, 22:01   #7
Lonewolf10
AMOS Extensions Developer
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 38
Posts: 1,917
Quote:
Originally Posted by bippym View Post
Why do you not visit pmc? (soorry for OT post)
I was going to ask that too, then realised he probably won't see the message for months (if at all).


Quote:
Originally Posted by Photon View Post
Seemed like a good topic for Coppershade, so I added it. It should get you started. Hope you like it!
Always good to have a reference from the pro's as a reminder/fresher
Lonewolf10 is offline  
Old 06 December 2014, 00:26   #8
jimmy2x2x
Beyond Mutton
jimmy2x2x's Avatar
 
Join Date: Mar 2011
Location: North West, UK
Age: 46
Posts: 347
Getting somewhere how, got the blitter doing some of the heavy lifting! Quick question about bobs or software sprites, do you need to store them with a separate mask or is that only of you want to display color0, and do you need to store a blank 16 pixel area (word aligned) with the sprite data? I'm working through the provided documentation, cheers
jimmy2x2x is offline  
Old 06 December 2014, 11:16   #9
Leffmann

 
Join Date: Jul 2008
Location: Sweden
Posts: 2,025
Unless the shape of your sprite is a solid rectangle, you will need to store a mask for it. You can generate the mask at startup however, if you can make use of color-keying and say that f.ex color 15 indicates transparency. Also, if you're doing interleaved blits then you will have to duplicate the mask for each bitplane.

The so called "Blitter words" is a solution to a non-existing problem, and misinformation that has been kept alive in the Amiga programming community since forever. The intended way is to put the mask in source A and cut off that 16-pixel area on the right by setting the source A mask value to $FFFF 0000 and subtracting 2 from the source A and B modulos, just like in phx's code example.
Leffmann is offline  
Old 06 December 2014, 18:12   #10
jimmy2x2x
Beyond Mutton
jimmy2x2x's Avatar
 
Join Date: Mar 2011
Location: North West, UK
Age: 46
Posts: 347
Thanks, I'm getting my head around it slowly, it's been a while and the old grey matter isn't what it used to be!
jimmy2x2x is offline  
AdSense AdSense  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Blitter problem zeGouky Coders. Asm / Hardware 7 26 March 2014 15:12
Blitter busy flag with blitter DMA off? NorthWay Coders. Asm / Hardware 9 23 February 2014 22:05
Blitter queues h0ffman Coders. General 13 05 April 2011 05:23
Help, need a CWB refresher please! rave project.ClassicWB 9 03 January 2011 17:08
Blitter Question. cdoty Coders. General 11 06 May 2005 16:22

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 08:10.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Page generated in 0.15564 seconds with 12 queries