English Amiga Board


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

 
 
Thread Tools
Old 26 January 2023, 00:06   #1
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,160
blitting & Y-flipping

I have a working blitter routine (cookie cut) and I wanted to adapt it so when height is negative, it copies the data but flips it.


Code:
* < A5: custom
* < D0.W,D1.W: x,y
* < A0: source
* < A1: destination
* < A2: background to mix with cookie cut
* < A3: source mask for cookie cut
* < D2: width in bytes (inc. 2 extra for shifting)
* < D3: blit mask
* < D4: height. If negative, source is copied with negative modulo (flip)
*       if D4 < 0, A1 and A2 must point to the last line of the data
* blit mask set
* returns: start of destination in A1 (computed from old A1+X,Y)
* trashes: a1

blit_plane_any_internal_cookie_cut:
    movem.l d0-d6/a2/a4,-(a7)
    * pre-compute the maximum of shit here
    lea        mulNB_BYTES_PER_ROW_table,a4
    swap    d1
    clr.w   d1
    swap    d1
    beq   .d1_zero    | optim
    .ifdef    NO68020
    add.w    d1,d1
    move.w  (a4,d1.w),d1    | y times 40
    .else
    move.w  (a4,d1.w*2),d1    | y times 40
    .endif
    add.w    d1,a2            | Y plane position for background
.d1_zero:
    move.l  #0x0fca0000,d5    | B+C-A->D cookie cut   

    move    d0,d6
    beq   .d0_zero
    asr.w   #3,d0
    bclr    #0,d0
    and.w   #0xF,d6
    beq    .no_shifting

    lsl.l   #8,d6
    lsl.l   #4,d6
    or.w    d6,d5            | add shift to mask (bplcon1)
    swap    d6
    clr.w   d6
    or.l    d6,d5            | add shift
.no_shifting:   
    move.w  d0,d6
    add.w   d0,d1
    
.d0_zero:
    * make offset even. Blitter will ignore odd address
    * but a 68000 CPU doesn't and since we RETURN A1...
    bclr    #0,d1
    add.l   d1,a1       | plane position (long: allow unsigned D1)

    add.w   d6,a2       | X offset for background

    move.w    #NB_BYTES_PER_ROW,d0

    sub.w   d2,d0       | blit width
    tst.w    d4
    bpl.b    1f
    * negative modulo: flipped image
    neg.w    d0
    neg.w    d4
1:
    lsl.w   #6,d4
    lsr.w   #1,d2
    add.w   d2,d4       | blit height

    * always the same settings (ATM)

    * now just wait for blitter ready to write all registers
    bsr    wait_blit
    
    * blitter registers set

    move.l  d3,bltafwm(a5)
    clr.w bltamod(a5)        |A modulo=bytes to skip between lines
    clr.w bltbmod(a5)        |A modulo=bytes to skip between lines
    move.l d5,bltcon0(a5)    | sets con0 and con1

    move.w  d0,bltcmod(a5)    |C modulo
    move.w  d0,bltdmod(a5)    |D modulo
                            
    move.l a3,bltapt(a5)    |source graphic top left corner (mask)
    move.l a0,bltbpt(a5)    |source graphic top left corner
    move.l a2,bltcpt(a5)    |pristine background top (bottom) left corner
    move.l a1,bltdpt(a5)    |destination top (bottom) left corner
    move.w  d4,bltsize(a5)    |rectangle size, starts blit
    
    movem.l (a7)+,d0-d6/a2/a4
    rts

I just added this:


Code:
    tst.w    d4
    bpl.b    1f
    * negative modulo: flipped image
    neg.w    d0
    neg.w    d4
1:

Instead of NB_BYTES_PER_ROW-4 (36 here) I'm setting -36 to be added to C & D after each line copy. Seems very simple.



so for 16x16, standard I'm calling it as is


Code:
    move.l d2,d3        |masking of first/last word    
    move.w  #4,d2       | 16 pixels + 2 shift bytes
    move.w  #16,d4      | 16 pixels height   
    bsr blit_plane_any_internal_cookie_cut

now if I want to display data flipped, I thought that would work


Code:
    move.l d2,d3        |masking of first/last word    
    move.w  #4,d2       | 16 pixels + 2 shift bytes
    move.w  #-16,d4      | 16 pixels height
    add.w    #15,d1     | Y += 15 points on last data line
    bsr blit_plane_any_internal_cookie_cut


the 15 offset is to make data point on the last line of the source/background. But the blit is complete bogus.


Any ideas?
jotd is offline  
Old 26 January 2023, 00:22   #2
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,038
You have to compensate for auto-increment (after each word), so e.g. for a 320px wide bitmap and a 256px wide blit the modulo, instead of (320-256)/8=8, is (-256-320)/8=-72 (or the original modulo minus 2 full lines).
Offset 15 is not needed since you are still blitting in the same direction horizontally (also, 15 is not even/word offset).
a/b is offline  
Old 26 January 2023, 21:34   #3
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,160
Quote:
Originally Posted by a/b View Post
You have to compensate for auto-increment (after each word), so e.g. for a 320px wide bitmap and a 256px wide blit the modulo, instead of (320-256)/8=8, is (-256-320)/8=-72 (or the original modulo minus 2 full lines).
Thank you! that works. Not very intuitive for me.

Quote:

Offset 15 is not needed since you are still blitting in the same direction horizontally (also, 15 is not even/word offset).
Yes it is needed or the coordinates of the blit are wrong, the pic is blitted too high. I'm adding 15 lines not 15 bytes (D1=Y dest, there's a multiplication by nb_rows in the routine). But I have the height already, no need to add it before hand.


anyway, that helped a lot!
jotd is offline  
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Image flipping/draw direction Brick Nash Coders. Asm / Hardware 4 13 May 2021 23:08
Fast tile flipping on CD32 mcgeezer Coders. Asm / Hardware 32 07 August 2019 16:42
Workaround to X-Flipping issue found. No actual solution as yet. Brick Nash Coders. AMOS 12 13 October 2017 19:01
flipping through screens using middle mouse button Yulquen74 request.Apps 5 27 June 2014 21:31
Flipping floppies Dave_wb support.Hardware 8 03 December 2006 12:36

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

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.06885 seconds with 13 queries