20 November 2019, 21:10 | #1 |
Registered User
Join Date: Oct 2019
Location: Eydelstedt / Germany
Age: 44
Posts: 114
|
why does my setPixel method not work correctly?
Hi,
Who can tell me what's wrong with my method? It works, but only for lines < 187. Ok, I think in principle i know whats wrong: each lines consists of 44 Bytes in my case (16 Pixel hidden space on each side), and i use interleaved bitplanes (4 bitplanes). Thus, i have to multiply y by 4x44 = 176 to get the correct offset. At line 186, this gives 176x186 = 32736. At line 187, the value is more than word size. But, i use longwords. So what's wrong? SetPixel: * d0 : x * d1 : y move.l BITPLANE,a0 add.w #2,a0 divu #8,d0 mulu.w #4*44,d1 add.l d0,d1 Swap d0 Move.b #-1,d2 Sub.b d0,d2 move.w #3,d3 plane_loop: bset d2,(a0,d1) add.w #44,d1 dbra d3,plane_loop rts |
20 November 2019, 21:15 | #2 |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
I don't think you're specifying that you're using longs:
bset d2,(a0,d1) might need to be: bset d2,(a0,d1.L) |
20 November 2019, 21:21 | #3 |
Going nowhere
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
|
Your error is to do with your division.
You haven't allowed for your DIVU to have a remainder in the high word of D0. If your number divides equally with no remainder, your add.l d0,d1 will be ok. If your number has a remainder, your add.l d0,d1 will NOT be ok, because you will be essentially adding a really big longword instead (it will interpret the remainder as a memory address) |
21 November 2019, 09:20 | #4 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Your routine would be better written this way :
Code:
move.l BITPLANE,a0 addq.w #2,a0 moveq #-1,d2 sub.b d0,d2 lsr.l #3,d0 mulu.w #4*44,d1 add.l d0,d1 add.l d1,a0 moveq #3,d3 plane_loop: bset d2,(a0) add.w #44,a0 dbra d3,plane_loop rts - as said, (a0,d1) instead of (a0,d1.l) - as said, remainder of divu - and a nice time bomb : add.w #44,d1 instead of add.l #44,d1 |
21 November 2019, 10:06 | #5 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Or to be picky
Code:
moveq #3,d3 plane_loop: bset d2,(a0) lea 44(a0),a0 dbra d3,plane_loop rts |
21 November 2019, 14:56 | #6 |
Registered User
Join Date: Jul 2014
Location: Warsaw/Poland
Posts: 171
|
Instead of that:
Code:
moveq #3,d3 plane_loop: bset d2,(a0) lea 44(a0),a0 dbra d3,plane_loop Code:
bset d2,(a0) bset d2,44(a0) bset d2,88(a0) bset d2,132(a0) |
21 November 2019, 15:51 | #7 |
Registered User
Join Date: Sep 2019
Location: Leicester / England
Posts: 201
|
Divides and multiplies are also quite slow. I can't remember the cycle timings off the top of my head, but you would replace:
Code:
divu #8,d0 ; Divide by 8 is shift 3 places right Code:
moveq.l #7,d3 and.l d0,d3 ; d3 = remainder for use later asr.l #3,d0 ; d0 = d0 / 8 Code:
mulu.w #4*44,d1 Code:
asl.l #4,d1 ; d1 = 'y' * 16 add.l d1,a0 ; add *16 add.l d1,a0 ; add *16 add.l d1,a0 ; add *16 asl.l #3,d1 ; d1 = 'y' * 128 add.l d1,a0 ; add *128 add.l d0,a0 ; a0 now points to the first memory address |
21 November 2019, 22:02 | #8 |
Registered User
Join Date: Oct 2019
Location: Eydelstedt / Germany
Age: 44
Posts: 114
|
Ok.....think i got it. Thanks! But another question: if i want to set a complete Byte to 1 (white), why can't i use
move.b $FF,(a0,d1.l) instead of bset d2,(a0,d1.l). It does not crash, but it's drawing some pixels white, and some pixels black. I don't understand that. And if i use instead move.w $FFFF,(a0,d1.l) or move.l $FFFFFFFF,(a0,d1.l) my program crashes. Why? |
21 November 2019, 22:21 | #9 | ||
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
This:
or in a more compact form: Quote:
If you have four plane you need to do four of this instructions, a write for every plane (and color 15 is then used). This: Quote:
but for the intended immediate form (#$) could also end up to a word/longword write to an odd memory address, depending on d1.l value. Both crash on bare 68k processor. Last edited by ross; 21 November 2019 at 23:36. |
||
21 November 2019, 23:10 | #10 |
Registered User
Join Date: Oct 2019
Location: Eydelstedt / Germany
Age: 44
Posts: 114
|
Ok. But
move.b $FF,(a0,d1.l) and st (a0,d1.l) doesn't do the same Only the second method does what i want. |
21 November 2019, 23:13 | #11 |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,960
|
|
21 November 2019, 23:17 | #12 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Thanks Don.
@geldo79, of course I meant #$ff for the st equivalency $ff is a memory location. Last edited by ross; 21 November 2019 at 23:41. Reason: sorry Don, I called you Dan :) I am sleepy ;) |
21 November 2019, 23:40 | #13 |
Registered User
Join Date: Oct 2019
Location: Eydelstedt / Germany
Age: 44
Posts: 114
|
Ooops....yes, of course!
|
22 November 2019, 10:49 | #14 | |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
Quote:
$FFFF/$FFFFFFFF are odd addresses - you can only access even addresses with word or longword size. As mentioned above, you probably meant #$FFFF, but even then it would crash if a0+d1 is odd. on 68020+ odd addressing for word/long is allowed. |
|
22 November 2019, 13:16 | #15 |
Registered User
Join Date: Oct 2019
Location: Eydelstedt / Germany
Age: 44
Posts: 114
|
Ok. So, my next question is : If i would like to set a graphic of 3x3 pixel size, how can I set it properly if it overlaps two bytes? Of course, i could calculate the fraction which is in the first byte and set it, and calculate the fraction for the second byte and set it. But is there an easier way to do it? Would be nice if i could just set a word, and if the shift to e.g. the right side is big enough to show the graphic completely on the next byte, i would set the word on the next byte location. But this is not allowed it it is an odd number.....
|
22 November 2019, 13:47 | #16 |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,212
|
you could store your 3 pixel wide data in a low word of a data register, shifted to the pixel position
and then: move.b d0,1(a0) ror.w #8,d0 move.b d0,0(a0) a0 can point to an odd address then |
22 November 2019, 14:05 | #17 | |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
Quote:
No matter whether you access memory 8, 16, 32 bits at a time, you will have to account for your objects wrapping past the edge of your words. For such small objects I would consider pre-calculating the shifts across a word - there's only 16 of them, and only 2 of them involve overlapping into a second word. Edit: You'd probably get some savings by making your objects 4x4, even if you never used that last pixel. Last edited by deimos; 22 November 2019 at 17:09. |
|
23 November 2019, 18:24 | #18 |
Registered User
Join Date: Oct 2019
Location: Eydelstedt / Germany
Age: 44
Posts: 114
|
I'll try to precalculate. But at the moment, I wonder if my project is possible on the amiga. I try to code some spacewar like game. My spaceship is a sprite....and it moves very smoothly. But now as i try to implement the shooting mechanism of the ship, it seems to be difficult to keep the game speed at the actual level. Problem is that every laser cannon bob (or at least graphic object...not sure if i will use the blitter or cpu) has to be updated concerning its position for every frame. Up to now, the cpu does not seem to be able to calculate everything in time. I use a bresenham algorithm to calculate the positions. And in order to be able to detect collisions, i do an update pixel by pixel. Otherwise i could increase or decrease x or y of the bob by a larger amount (depending on its speed), but then collision detection will be difficult. Its a bit frustrating at the moment.
|
24 November 2019, 07:30 | #19 | |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
Quote:
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Millennium 2.2 doesn't work correctly in WinUAE | Nicko | support.WinUAE | 8 | 30 January 2011 12:47 |
ADF to Disk doesn't work correctly | Doomman2008 | support.Hardware | 17 | 11 October 2010 16:04 |
New imaging method? | Pheonix | request.Apps | 2 | 27 August 2009 05:41 |
Best capture method | DJ_OXyGeNe_9 | project.Amiga Demo DVD | 16 | 11 May 2009 23:28 |
|
|