English Amiga Board


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

 
 
Thread Tools
Old 13 December 2013, 14:55   #1
AGS
XoXo/Tasko Developer
 
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 48
Posts: 450
Happy shift pattern

Hello,

I am filling a rectangle with a pattern. The pattern starts always in the left top corner of my rectangular block. Now, when I move the block, the pattern moves with it. What I would like to get is, that the pattern stays fixed, but is only visible within my block. I did this with this pattern and it worked:

Code:
vscrollpattern
        dc.w    %1010101010101010
        dc.w    %0101010101010101

vscrollpattern_shifted
        dc.w    %0101010101010101
        dc.w    %1010101010101010
When the coordinate is odd, then i simply use the shifted pattern.

But now I would like to do the same with a pattern that does NOT repeat after two pixels:

Code:
.ghostpattern    dc.w    %1000100010001000
        dc.w    %0010001000100010
I can't work with even/odd here. But how can I get the same effect of a fixed pattern? I would use differently shifted patterns for this purpose (as above with the 2 pixel pattern, but how to decide when which of those should be used?

Thanks in advance,
ags
AGS is offline  
Old 13 December 2013, 15:13   #2
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Divide the x coordinate of the left edge of your block by the width of the pattern and use the remainder as the number of bits you have to shift the pattern horizontally.

Do the same with the top edge of your block and the height of the pattern to shift the pattern vertically.
thomas is offline  
Old 13 December 2013, 16:16   #3
AGS
XoXo/Tasko Developer
 
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 48
Posts: 450
Question

That's a good idea. I am trying to calc and apply the x-shift for a pattern that is 16 pixels wide and 2 pixels high:

Code:
		lea	.ghostpattern(pc),a0

.y		move.w	oxNB_top(a3),d0
		btst	#0,d0
		beq	.x
		addq.l	#2,a0

.x		movem.w	(a0),d0/d1	; read pattern

		move.w	oxNB_left(a3),d2
		move.w	d2,d3
		lsr.w	#4,d3
		lsl.w	#4,d3
		sub.w	d3,d2
		rol.w	d2,d0		; shift pattern horizontally
		rol.w	d2,d1

		movem.w	d0/d1,-(a7)	; put pattern on stack

		move.l	a7,rp_AreaPtrn(a2)

...
...

.ghostpattern	dc.w	%1000100010001000
		dc.w	%0010001000100010
		dc.w	%1000100010001000
For y I simply look even/odd and step one line further in the pattern data (higher than needed by one line).

For x I think I divide by 16, multiply by 16, then substract the result from the left coordiante to get the remainder and then shift the pattern by that.

For y it works, but for x not. What now?

ags


EDIT: I found it! Must be ROR. not ROL. lol
AGS is offline  
Old 13 December 2013, 16:39   #4
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
What about this to get the remainder for x:

Code:
	moveq	#15,d2
	and.w	oxNB_left(a3),d2
thomas is offline  
Old 13 December 2013, 16:48   #5
AGS
XoXo/Tasko Developer
 
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 48
Posts: 450
LOL, it works!
AGS is offline  
Old 16 December 2013, 15:29   #6
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,959
Writing Amiga GUI slowest than MUI has no big sense, especially in ASM.
You can try to use next code, if you want:

Code:
		lea	.ghostpattern(pc),a0

.y		move.w	oxNB_top(a3),d0
		btst	#0,d0
		beq	.x
		addq.l	#2,a0

.x		move.l	(a0),d0	; read pattern
                moveq     #15,D1
		and.w	oxNB_left(a3),d1
		ror.w	        d1,d0		; shift pattern horizontally
		move.w	d0,-(a7)	; put pattern on stack
                swap        d0
		ror.w	        d1,d0		; shift pattern horizontally
		move.w	d0,-(a7)	; put pattern on stack


		move.l	a7,rp_AreaPtrn(a2)

...
...

.ghostpattern	dc.w	%1000100010001000
		dc.w	%0010001000100010
		dc.w	%1000100010001000
Don_Adan is offline  
Old 16 December 2013, 16:58   #7
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
Why not simply put the pattern data into rp_AreaPtrn(a2) directly?

Code:
.x
    move.l  (a0),d0
    moveq   #15,d1
    and.w   oxNB_left(a3),d1
    rol.w   d1,d0
    swap    d0
    rol.w   d1,d0
    move.l  d0,rp_AreaPtrn(a2)

Last edited by Thorham; 16 December 2013 at 18:07.
Thorham is offline  
Old 16 December 2013, 17:28   #8
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Because rp_AreaPtrn is an address (a pointer), not a value.
thomas is offline  
Old 16 December 2013, 18:03   #9
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
Quote:
Originally Posted by thomas View Post
Because rp_AreaPtrn is an address (a pointer), not a value.
That's quite obvious, of course. The question is why you should point to the pattern when you can store it directly? If the pointer always points to two words (or a long word), then you can store it directly. This also avoids putting the stack pointer into this member. It's about avoiding indirection if you don't have to go to lengths to avoid it, and this seems to be such a case.
Thorham is offline  
Old 16 December 2013, 18:07   #10
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
To AGS:

You can also do it like this (uses the stack as in your code):

Code:
.y
    moveq   #1,d0
    and.w   oxNB_top(a3),d0
    add.w   d0,d0
    lea     .ghostpattern(pc,d0.w),a0

    move.l  (a0),d0
    moveq   #15,d1
    and.w   oxNB_left(a3),d1
    rol.w   d1,d0
    swap    d0
    rol.w   d1,d0
    move.l  d0,-(sp)
    move.l  sp,rp_AreaPtrn(a2)

    ...
    ...
    ...

.ghostpattern
    dc.w    %1000100010001000
    dc.w    %0010001000100010
    dc.w    %1000100010001000
Thorham is offline  
Old 16 December 2013, 18:35   #11
AGS
XoXo/Tasko Developer
 
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 48
Posts: 450
Thanks Thorham, now I use your code. I think it is faster but did not count it. Actually this piece of code is only called when a button is drawn in ghost-state. This is seldom. There are core routines in my lib that eat up most of the valuable time. Optimizing these would be fine, but I don't think it is possible. Please look into the GUI thread.
AGS is offline  
Old 16 December 2013, 18:38   #12
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
Quote:
Originally Posted by AGS View Post
Actually this piece of code is only called when a button is drawn in ghost-state.
Is the code called only once per button?
Thorham is offline  
Old 16 December 2013, 18:39   #13
AGS
XoXo/Tasko Developer
 
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 48
Posts: 450
Yes.
AGS is offline  
Old 16 December 2013, 19:11   #14
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
Good
Thorham is offline  
Old 16 December 2013, 20:10   #15
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Quote:
Originally Posted by Thorham View Post
That's quite obvious, of course. The question is why you should point to the pattern when you can store it directly? If the pointer always points to two words (or a long word), then you can store it directly. This also avoids putting the stack pointer into this member. It's about avoiding indirection if you don't have to go to lengths to avoid it, and this seems to be such a case.
Erm, the RastPort is part of the API. You cannot change the API of AmigaOS (graphics.library).

Furthermore the pattern can have any height, as long as it is a power of 2.
thomas is offline  
Old 16 December 2013, 20:43   #16
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
Quote:
Originally Posted by thomas View Post
Erm, the RastPort is part of the API. You cannot change the API of AmigaOS (graphics.library).
Thought the member is part of the program itself
Thorham is offline  
Old 16 December 2013, 21:27   #17
AGS
XoXo/Tasko Developer
 
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 48
Posts: 450
Thorham, just to let you know, in your source it must be ROR, not ROL.
AGS 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
TAR with file name pattern handling pintcat support.Apps 5 25 February 2013 18:32
Workbench PAttern Image robpotts New to Emulation or Amiga scene 3 06 June 2011 18:47
Right Shift+Right Amiga works, but not Left shift+Left Amiga Photon support.WinUAE 13 22 November 2010 21:43
Sector fill pattern absence Coders. General 7 21 March 2009 21:50
Error on setting Magic Workbench Pattern fc.studio support.Apps 7 17 September 2008 16:39

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

Top

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