23 February 2022, 17:13 | #1 |
Registered User
Join Date: Feb 2022
Location: Athens, Greece
Posts: 41
|
Help with BLTSIZE and image width (in words): do we have to add 1 word to it?
Hi.
I've been playing with the template code for Visual Studio Code + WinUAE (found here: https://github.com/BartmanAbyss/vsco...emplate/main.c). At line 476, the code is: Code:
custom->bltsize = ((16 * 5) << HSIZEBITS) | (32/16); I.e. the number of words given to the BLTSIZE register for width is 2, while the graphic is 16 pixels, and that number should be 1. Is that because the graphic is actually interleaved? i.e. because each row contains image bitplane data followed by mask data? do we have to add the mask size to the image size to get the proper width to pass to BLTSIZE if the image is interleaved? I've seen in various source code examples that sometimes 1 is added to the number of words given to BLTSIZE and sometimes it is not. I've been searching online for a lot of hours but I can't find an answer to this...neither could I find answer to this in this forum...any help will be appreciated. |
23 February 2022, 17:29 | #2 |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,213
|
You usually have to have an extra word to shift into, so if the source image is 16 pixels (1 word) wide, your blitsize width will be 2 words.
This only applies if you are shifting (for example masked bobs etc..) |
23 February 2022, 17:44 | #3 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,360
|
Even with a zero shift value you have to add 2 bytes at the end of each line of the source.
If it's possible to do without that, that would interest me (same for rectangle fill) |
23 February 2022, 18:06 | #4 |
Registered User
Join Date: Dec 2017
Location: Austin, TX
Age: 41
Posts: 412
|
My math for the BLTSIZE width is here (width_words).
It calculates which word the first pixel falls in. Then which word the pixel beyond the last pixel falls in. Subtract the two. Repeat for source/destination and take the larger of the two, to account for any shift. I think it's correct for all shifts, but the HRM's vague descriptions led to much head scratching. |
23 February 2022, 18:54 | #5 | |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,213
|
Quote:
and (for example) a 24 pixel wide object (with a BLTSIZE of 2 words), could be shifted from 0-7 without adding the extra word too |
|
23 February 2022, 19:27 | #6 |
Registered User
Join Date: Jan 2012
Location: USA
Posts: 373
|
The width is determined by the needs of the destination and not by the source.
Even a two-pixel-wide source will need an extra word on each line if there is any possibility that the blitter will have to touch two words per line at the destination. For example, if bit 15 of the source (first pixel) needs to be written to bit 0 of the destination (last pixel of a word) then the second pixel needs to be written to bit 15 of the next word in the bitplane. The two.pixels from one source word span two words at the destination. Basically if the last pixels of a line of the source ever need to cross a word boundary at the destination, then an extra source word is required. Conversely, if the last pixels of a line of the source NEVER need to cross a word boundary at the destination, then no extra word is needed. |
24 February 2022, 00:44 | #7 |
Registered User
Join Date: Feb 2022
Location: Athens, Greece
Posts: 41
|
So, the blit width has nothing to do with the source, it has to do with how many words per line the blitter will affect in the destination?
|
24 February 2022, 02:16 | #8 | |
Registered User
Join Date: Jan 2012
Location: USA
Posts: 373
|
Quote:
You can even store the source image with the extra words for use with some blits but ignore them for others where the last pixels on a source line don't cross a word boundary at the destination -- as long as you take care to properly adjust the modulo values. This will save blitter cycles on average. Lets say you have a 24 pixel wide object. For shifts up to 7 you only affect two words in the destination. For larger shifts it affects three words. The width and modulos used will be different in the two cases. |
|
24 February 2022, 13:03 | #9 | |
Registered User
Join Date: Feb 2022
Location: Athens, Greece
Posts: 41
|
Quote:
So if there is no shift to be involved, the bltsize should be equal to the width of the source image (in words)? So if line 476 is changed to this (i.e. given bltsize is 16 if no shift is involved, otherwise 32): Code:
custom->bltsize = ((16 * 5) << HSIZEBITS) | (((x & 15) == 0 ? 16 : 32)/16); https://ibb.co/CMqVxZ5 So it does not seem to me that it is correct that one word is added to BLTSIZE if only a shift is involved. Unless I have misunderstood something. Could it be that the additional word is needed due to the bitmap being interleaved? |
|
24 February 2022, 13:07 | #10 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,360
|
C expressions aren't making code any clearer
No it's not because of interleaved. It's bad input data. You have to add 2 words in your source too. |
24 February 2022, 13:26 | #11 |
Registered User
Join Date: Feb 2022
Location: Athens, Greece
Posts: 41
|
Sorry, what is not clear?
'x' is the destination position. 'x & 15' is extracting the lower 15 bits. This is compared to 0: if true, then 16 is divided to 16, so the result is 1 word, otherwise, if there is a shift involved, 32 is divided to 16. Eh? what does this mean? what two words to the source? why? the source pointer is computed as needed in the loop. |
24 February 2022, 13:31 | #12 |
Inviyya Dude!
Join Date: Sep 2016
Location: Amiga Island
Posts: 2,793
|
|
24 February 2022, 13:51 | #13 |
Registered User
Join Date: Feb 2022
Location: Athens, Greece
Posts: 41
|
Hey, no problem with that, although I haven't written much MC68000 assembly, I can read such code.
What I can't understand through is why in the example given, the blit size is 2 words and not 1. Shifting does not seem to play a role, as mentioned earlier, because I have already tested the case shift being 0 and it's 2 words for that case as well. |
24 February 2022, 13:55 | #14 | |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,436
|
Indeed, I wrote C code profesionally for a decade and both during that time and afterwards, I've never liked the ? : operator. It just doesn't 'read' nicely for me and I always have to think twice about what it means.
Lot's of people do love it though, so it's clearly a personal preference Quote:
*) note that I'm not going into the example given earlier of an object that has some empty room around it. Such objects can shifted without always needing the extra word, but I feel this muddles the basic discussion so I'll leave it here for 'tricks' and 'advanced use' - my post assumes only objects that are exact multiples of 16 pixels wide Last edited by roondar; 24 February 2022 at 14:02. |
|
24 February 2022, 14:30 | #15 |
Registered User
Join Date: Jan 2012
Location: USA
Posts: 373
|
Are your modulo values correct? If your width is one word less then the modulo value must be increased by one (assuming the source is stored as a rectangular bitmap).
|
24 February 2022, 14:31 | #16 |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,213
|
Modulo needs adjusting depending on BLTSIZE width...
|
24 February 2022, 14:57 | #17 | |
Registered User
Join Date: Feb 2022
Location: Athens, Greece
Posts: 41
|
Quote:
But I just did this and it doesn't work like that. |
|
24 February 2022, 15:02 | #18 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,360
|
create some simple example so people can check.
Every time I had problems either I found the problem (usually wrong data source, wrong modulo, wrong size...) or provided a simple example so everyone can check what's wrong |
24 February 2022, 15:02 | #19 |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,436
|
It could be (as DanScott & mc6809e pointed out) an error in the modulo values: if you have a 2 word blit, the modulo values aren't going to be the same as for a 1 word blit. But the basic point, no shift means no extra word required, does hold.
Last edited by roondar; 24 February 2022 at 15:20. |
24 February 2022, 15:05 | #20 |
Registered User
Join Date: Feb 2022
Location: Athens, Greece
Posts: 41
|
Indeed, the modulo needed fixing!
THANKS A LOT GUYS, much obliged. Here is the code that currently works: Code:
for(short i = 0; i < 16; i++) { const short x = i * 16 + sinus32[(frameCounter + i) % sizeof(sinus32)] * 2; const short y = sinus40[((frameCounter + i) * 2) & 63] / 2; const APTR src = (APTR)bob + 32 / 8 * 10 * 16 * (i % 6); const short w = (x & 15) == 0 ? 16 : 32; WaitBlt(); custom->bltcon0 = 0xca | SRCA | SRCB | SRCC | DEST | ((x & 15) << ASHIFTSHIFT); // A = source, B = mask, C = background, D = destination custom->bltcon1 = ((x & 15) << BSHIFTSHIFT); custom->bltapt = src; custom->bltamod = w / 8; custom->bltbpt = src + w / 8 * 1; custom->bltbmod = w / 8; custom->bltbdat = 0xffff; custom->bltcpt = custom->bltdpt = (APTR)image + 320 / 8 * 5 * (200 + y) + x / 8; custom->bltcmod = custom->bltdmod = (320 - w) / 8; custom->bltafwm = custom->bltalwm = 0xffff; custom->bltsize = ((16 * 5) << HSIZEBITS) | (w/16); } Superb! Thanks again! |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Floppy disk image wont add | leeslangley | support.FS-UAE | 2 | 22 January 2017 12:46 |
Easily add CD ISO image as hardfile | mark_k | request.UAE Wishlist | 4 | 16 March 2014 19:11 |
Word vs not word aligned playfield question | nandius_c | Coders. Asm / Hardware | 8 | 03 December 2013 12:03 |
How in the World do you add an image? | RocketMack | project.EAB | 9 | 08 May 2002 00:48 |
Swear words | Kodoichi | project.EAB | 19 | 14 December 2001 00:53 |
|
|