English Amiga Board Amiga Lore


Go Back   English Amiga Board > Coders > Coders. General > Coders. Tutorials

 
 
Thread Tools
Old 21 February 2013, 23:48   #1
Lonewolf10
AMOS Extensions Developer
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 38
Posts: 1,917
Blitter Objects (bobs)

Hi,

I am in need of assistance again

I have managed to get the blitter to blit most of the tiles for my game, but the tiles on an odd byte are causing me problems. The reason being is that they overlap tiles that start on an even byte and I'm failing to merge the 2
A simple example (in ASCII) of what I am trying to do:

-XX


- represents the start of the tile that starts on an even byte
XX represents the tile that starts on an odd byte and overlaps the previous tile (tiles are drawn in the order top-left to bottom-right).


Code:
SCREEN_WIDTH    equ    320
HARDWARE_WIDTH    equ    SCREEN_WIDTH/8            ;bytes per line
TILE_WIDTH    equ    2                ;width in bytes
TILE_BLTDMOD    equ    HARDWARE_WIDTH-TILE_WIDTH

TILE_IFF_WIDTH    equ    320
TILE_HARDWIDTH    equ    TILE_IFF_WIDTH/8        ;TileIFF bytes per line
TILE_BLTAMOD    equ    TILE_HARDWIDTH-TILE_WIDTH

...

    move.w    #TILE_BLTAMOD,d4    ;BLTAMOD value set
    move.w    #TILE_BLTDMOD,d5    ;BLTDMOD value set
    move.w    #%0000001000000001,d6    ;size in BLTSIZE format
                    ;%hhhhhhhhhhwwwwww (8 lines, 1 word)


drawbob:
    btst    #6,DMACONR
    bne.s    drawbob            ;blitter finished?
    move.l    a6,BLTDPTH        ;destination
    move.l    a5,BLTAPTH        ;source A
    move.w    d5,BLTDMOD        ;destination MOD value
    move.w    d4,BLTAMOD
    move.l    #$FFFFFFFF,BLTAFWM
***\
    move.l    a6,d3
    btst    #0,d3
    bne.w    .not_even
***/
    move.w    #$09F0,BLTCON0        ;D=A, use A & D
    move.w    #$0000,BLTCON1        ;no FX
    move.w    d6,BLTSIZE        ;set size & autostart blitter
    rts

*****\
.not_even

                ; temp workaround

    move.l    a5,temp_store1
    move.l    a6,temp_store2
    move.b    (a5)+,(a6)+    ;line 1
    move.b    (a5)+,(a6)+
    adda.l    d4,a5
    adda.l    d5,a6
    move.b    (a5)+,(a6)+    ;line 2
    move.b    (a5)+,(a6)+
    adda.l    d4,a5
    adda.l    d5,a6
    move.b    (a5)+,(a6)+    ;line 3
    move.b    (a5)+,(a6)+
    adda.l    d4,a5
    adda.l    d5,a6
    move.b    (a5)+,(a6)+    ;line 4
    move.b    (a5)+,(a6)+
    adda.l    d4,a5
    adda.l    d5,a6
    move.b    (a5)+,(a6)+    ;line 5
    move.b    (a5)+,(a6)+
    adda.l    d4,a5
    adda.l    d5,a6
    move.b    (a5)+,(a6)+    ;line 6
    move.b    (a5)+,(a6)+
    adda.l    d4,a5
    adda.l    d5,a6
    move.b    (a5)+,(a6)+    ;line 7
    move.b    (a5)+,(a6)+
    adda.l    d4,a5
    adda.l    d5,a6
    move.b    (a5)+,(a6)+    ;line 8
    move.b    (a5)+,(a6)+
    move.l    temp_store1,a5
    move.l    temp_store2,a6

                ; end workaround

;    move.l    #$FFFFFFFF,BLTAFWM
;    move.l    tile_mask,BLTAPTH
;    move.w    #0,BLTAMOD
;    move.l    a5,BLTBPTH        ;source B
;    move.w    d4,BLTBMOD
;    move.l    -2(a5),BLTCPTH        ;source C
;    move.w    d5,BLTCMOD
                    ;a=mask, b=tile, c=background
;    move.w    #$8FCA,BLTCON0        ;D=AB + (NOT A)C, use A & B & D
                    ;shift A 8 pixels right    
;    move.w    #$8000,BLTCON1        ;shift B 8 pixels right
;    move.w    d6,BLTSIZE        ;set size & autostart blitter
    rts
*****/

;tile_mask:    dc.w    $FF00,$FF00,$FF00,$FF00,$FF00,$FF00,$FF00,$FF00
temp_store1:    dc.l    0
temp_store2:    dc.l    0
As you can see, I have a temporary workaround where the CPU draws the tiles starting on an even byte, but I would like to learn how to do it properly with the blitter

Each tile is 16 pixels (2 bytes) wide by 8 lines.

Last edited by Lonewolf10; 21 February 2013 at 23:52. Reason: made code easier to read
Lonewolf10 is offline  
AdSense AdSense  
Old 22 February 2013, 10:15   #2
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 694
I am not sure, I understand you 100%, but you cannot use odd addresses with the blitter.. if you need to blit something to a position that corresponds to an odd address, you need to add 2 to your dest address and then use the A or B source shift to move it 8 pixels left.
hooverphonique is online now  
Old 22 February 2013, 12:40   #3
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 996
As hooverphonique already mentioned you will use the Blitter's barrel shifter when you want to write a BOb to an x-position which is not word-aligned.

To make shifting work you have to read and write an extra word. This is the space where the barrel shifter will shift the bits. You will choose a BLTAFWM of $ffff and a BLTALWM of $0000 to ignore the extra word being read and written. The ASH value shifts the mask in BLTAFWM/BLTALWM as well as the source A, which is preloaded with $ffff, to function as a mask for your BOb (A can also be pointed to a variable mask in memory).

The minterm used is $CA, for D = (A & B) | (!A & C).

You see that you also need the B and the C channel. B is the source which is pointing to the image of your BOB. The A channel defines which pixels are blitted from B onto the screen (D). The C channel is used to read the screen destination, so a pixel from the screen will be preserved in those regions where the mask is 0.

BSH must be used to shift the B source by the same amount as A. In your case it would be 0 when the destination pointer is word aligned and 8 when not.

Below you find a quick draft of what to do (unfortunately I didn't test it). But it can easily be extended to place masked BOBs at arbitrary coordinates on the screen.

Code:
TILE_BLTDMOD    equ    HARDWARE_WIDTH-(TILE_WIDTH+2)
TILE_BLTAMOD    equ    TILE_HARDWIDTH-(TILE_WIDTH+2)

    moveq    #-1,d4
    clr.w    d4            ; BLTAFWM=$ffff, BLTALWM=$0000

    move.l    #TILE_BLTAMOD<<16|TILE_BLTDMOD,d5
    move.w    #8<<6|2,d6        ; 8 lines, 1 word (+1 extra word)

    move.l    #$07ca0000,d7        ; BLTCON0: use B,C,D, D=AB+/AC, CON1=0

    ; word-align source and destination pointer
    moveq    #-2,d2
    move.l    a5,d1
    and.l    d2,d1            ; d1 source
    move.l    a6,d0
    btst    #0,d0
    beq    aligned
    or.l    #$80008000,d7        ; set BLTCON0 ASH=8, BLTCON1 BSH=8
aligned:
    and.l    d2,d0            ; d0 destination

drawbob:
    btst    #6,DMACONR
    bne    drawbob

    move.l    d7,BLTCON0
    move.l    d5,BLTAMOD        ; set AMOD and DMOD
    swap    d5
    move.l    d5,BLTCMOD        ; set CMOD=DMOD and BMOD=AMOD
    movem.l    d0-d1,BLTAPTH        ; set BLTCPT and BLTBPT
    move.l    d0,BLTDPTH        ; BLTDPT==BLTCPT
    move.w    #$ffff,BLTADAT        ; always read $ffff from A as src mask
    move.l    d4,BLTAFWM
    move.w    d6,BLTSIZE
phx is offline  
Old 22 February 2013, 22:24   #4
Lonewolf10
AMOS Extensions Developer
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 38
Posts: 1,917
Quote:
Originally Posted by hooverphonique View Post
I am not sure, I understand you 100%, but you cannot use odd addresses with the blitter.. if you need to blit something to a position that corresponds to an odd address, you need to add 2 to your dest address and then use the A or B source shift to move it 8 pixels left.
I knew that you can't use the blitter on odd addresses - I did forgot to correct that in my .not_even routine though However, I was rusty with the barrel shifting technique.


phx,

Thanks for the lengthy explaination, that is exactly what I needed. I did read something along those lines in the Amiga HRM yesterday, but for some reason it didn't sink in properly

I started changing my original code based on what you said, but still couldn't get it to work. Then I started again from scratch with more organised code and direct values for the modulo's and BLTSIZE values.
It worked. I carefully replaced the direct values by adjusting the original modulo's (in d4 and d5) and BLTSIZE value (in d6) as necessary and it still works The resulting code is below:

Code:
.not_even
    move.l    #$FFFF0000,BLTAFWM    ;mask, blocks out first word & draws
                                    ;last word of bob
    move.w    #$FFFF,BLTADAT        ;source A mask (always $FFFF)
    move.l    a5,BLTBPTH        ;source B = Bob (tiles)
                                 ;          (compared with source A)
    move.l    a6,BLTCPTH        ;source C = Screen dest
                                 ;          (to merge with source B)
    move.l    a6,BLTDPTH        ;source D = Screen dest
    subq.w    #2,d4            ;d4=36
    subq.w    #2,d5            ;d5=36
    move.w    d4,BLTAMOD
    move.w    d4,BLTBMOD
    move.w    d5,BLTCMOD
    move.w    d5,BLTDMOD
    move.w    #$87CA,BLTCON0        ;D = (A & B) | (!A & C)
                                    ;use B,C & D   (A is set directly)
                                    ;shift A source right 8 pixels
    move.w    #$8000,BLTCON1        ;shift B source right 8 pixels
    addq.w    #1,d6
    move.w    d6,BLTSIZE        ;d6=$0202 (8 lines, 2 words)
    rts
Lonewolf10 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
Background Image and Bobs!! Sparticle Coders. General 3 29 July 2013 11:22
FS: A4000/30 plus bits and bobs Interceptor MarketPlace 0 22 October 2011 22:52
FS: Various bits n bobs jujasi MarketPlace 0 12 July 2009 19:13
Some of my techy bits and bobs up on eaby turk182 MarketPlace 0 17 August 2004 10:59
Bobs Garden Big-Byte Amiga scene 7 26 October 2002 11:24

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 11:03.


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