English Amiga Board


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

 
 
Thread Tools
Old 11 December 2016, 04:20   #21
LuigiThirty
Registered User
 
Join Date: Dec 2016
Location: USA
Posts: 101
Oh! I'd have never thought of that. The Copper should be made to update the bitplane pointers just before we hit the visible area, shouldn't it?

Programming the Atari 800's ANTIC is starting to come back to me, hah.
LuigiThirty is offline  
Old 11 December 2016, 19:48   #22
LuigiThirty
Registered User
 
Join Date: Dec 2016
Location: USA
Posts: 101
I found the problem and we both missed it. The frame loop does this every coarse scroll:

Code:
for(int i=0;i<NUM_BITPLANES; i++){
	B_BlitTileRow(BPScreen1, levelTileMap, bgTileGraphics, screenPointerRowOffset);
}
...but B_BlitTileRow already takes bitplanes into account:

Code:
for(int i=0;i<4;i++){
	for(int column=0;column<20;column++){		
		int tileIndex = tileIndices[rowTilemapOffset + column];
		B_BlitTile_ASM(bitplanes[i], column*16, rowBitplaneOffset, bgTileGraphics[i], tileIndex);
	}
}
So we were doing 320 blits instead of 80. Removed the extra loop and added a WAIT to the Copperlist and it's perfectly smooth now before I do any more optimization.
LuigiThirty is offline  
Old 12 December 2016, 11:45   #23
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,545
Great you finally found it!

You might want to consider switching to interleaved bitplanes nevertheless. And do some optimizations to the inner core assembler routines, like blit.s. For example replace the mulu #20 with lsl #2 and lsl #4, or better, use a table for all y line offsets on the screeen.
phx is offline  
Old 12 December 2016, 14:35   #24
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,437
Quote:
Originally Posted by LuigiThirty View Post
I found the problem and we both missed it. The frame loop does this every coarse scroll:

Code:
for(int i=0;i<NUM_BITPLANES; i++){
    B_BlitTileRow(BPScreen1, levelTileMap, bgTileGraphics, screenPointerRowOffset);
}
...but B_BlitTileRow already takes bitplanes into account:

Code:
for(int i=0;i<4;i++){
    for(int column=0;column<20;column++){        
        int tileIndex = tileIndices[rowTilemapOffset + column];
        B_BlitTile_ASM(bitplanes[i], column*16, rowBitplaneOffset, bgTileGraphics[i], tileIndex);
    }
}
So we were doing 320 blits instead of 80. Removed the extra loop and added a WAIT to the Copperlist and it's perfectly smooth now before I do any more optimization.
Ah, yes.. That would seem to be a small optimisation on your part
Great that it works now!

That said, I would like to echo PHX's comments about interleaved bitmaps. They do speed up blitting by a sizable margin (especially on slower machines) and are usually worth the small extra memory use.
roondar is offline  
Old 12 December 2016, 18:54   #25
DanScott
Lemon. / Core Design
 
DanScott's Avatar
 
Join Date: Mar 2016
Location: Tier 5
Posts: 1,213
Also, with interleaved, you can always blit plane by plane for masked bobs, if you don't want to store the interleaved mask (especially for large objects)
DanScott is offline  
Old 12 December 2016, 19:36   #26
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,200
Personally, I wouldn't use bitplane interleave for transparent blits. For opaque blits like tiles it is great!
Samurai_Crow is offline  
Old 12 December 2016, 23:59   #27
LuigiThirty
Registered User
 
Join Date: Dec 2016
Location: USA
Posts: 101
It took me a while but I've got it all set up for interleaved bitplanes now and can draw my tilemaps much faster It's not much to look at yet but it's really cool to me!
LuigiThirty is offline  
Old 13 December 2016, 00:13   #28
DanScott
Lemon. / Core Design
 
DanScott's Avatar
 
Join Date: Mar 2016
Location: Tier 5
Posts: 1,213
Quote:
Originally Posted by Samurai_Crow View Post
Personally, I wouldn't use bitplane interleave for transparent blits. For opaque blits like tiles it is great!
I can't think of anytime i would not use interleaved planes these days

And if you're plotting tiles... then by reason, you are probably going to want to plot masked bobs over the top.. and then also to save and restore the background... for 4 a bitplane screen that's 3 blits (interleaved) compared to 12 (non-interleaved) for each object plotted
DanScott is offline  
Old 15 December 2016, 05:36   #29
LuigiThirty
Registered User
 
Join Date: Dec 2016
Location: USA
Posts: 101
I haven't tried interleaved masked bobs yet but I did figure out how to import maps from Tiled using my tile set and can draw backgrounds of any length! Now I just need to fix my blit routine to use a source tilemap (256x256 4 bitplanes interleaved) of more than 16 tiles...
LuigiThirty is offline  
Old 15 December 2016, 22:58   #30
DanScott
Lemon. / Core Design
 
DanScott's Avatar
 
Join Date: Mar 2016
Location: Tier 5
Posts: 1,213
Don't forget, you can pre-calculate your tile offsets and store those in the map (rather than a tile index)... there's some other easy and quick optimisations I can see in that ASM tile plotter too
DanScott is offline  
Old 15 December 2016, 23:17   #31
LuigiThirty
Registered User
 
Join Date: Dec 2016
Location: USA
Posts: 101
That's just because I haven't updated the remote repository in a while.

I'm proud of myself for even getting this far considering I've never programmed an Amiga (or owned a real one!) since I bought my A2000 last month or so. I've done some ST stuff, wrote a dinky disk operating system for Easy68K (okay, a console with three or four commands that can run binaries off a floppy disk) a while back - that's all buried somewhere in my Github.
LuigiThirty is offline  
Old 20 December 2016, 04:03   #32
LuigiThirty
Registered User
 
Join Date: Dec 2016
Location: USA
Posts: 101
And here's where we're at now!



I think I'm going to make a cheap River Raid knockoff. No interleaved bobs yet but I've got a 1-color text area now as a status bar. It's magic compared to VGA - just wait for the right scanline and change the bitplane pointers, no mucking with scroll registers or anything. I'm sure 99% of NTSC systems these days can do 320x224...
LuigiThirty is offline  
Old 01 January 2017, 21:28   #33
LuigiThirty
Registered User
 
Join Date: Dec 2016
Location: USA
Posts: 101
So now I'm trying to do cookie-cutter shifted blits onto my interleaved screen and having some trouble getting it working.

Here's the routine I've got that's not working. It draws a squished bob with garbage below it so we're reading past the end of the bitmap data. The modulos are wrong maybe?

destination is a pointer to the start of the visible screen.
source for this example is a 32x32 4-bitplane bitmap (so 32x128 here).

Code:
void B_Blit(PLANEPTR destination, int destX, int destY, APTR source, int srcX, int srcY, int sizeW, int sizeH, PLANEPTR oldBackground) {
	
	destY = destY*2; //?
	
	UWORD shift = (destX % 16) << 12;
	UWORD firstwordmask = 0xFFFF >> shift;
	UWORD lastwordmask = 0xFFFF << (16-shift);
	
	int bltW_words = sizeW/16;
	int bltW_bytes = sizeW/8;
	APTR srcPointer = (APTR)((UBYTE *)source + (srcY * (sizeH/16)) + srcX/8);
	APTR destPointer= (APTR)((destination + (destY * SCREEN_WIDTH_WORDS) + destX/8));
	
	//Increase blit size by 1 word to account for shifts. I think these numbers are wrong
	//UWORD sourceSkip = bltW_bytes - 2;
	UWORD destinationSkip = SCREEN_WIDTH_BYTES - bltW_bytes;
	UWORD blitsize = (sizeH << 6) + bltW_words + 1;
	
	BlitWait(); //wait for the blitter to become available
	
	Hardware->dmacon 	= 0x8040; //make sure blit DMA is enabled	
	Hardware->bltcon0	= 0x0FCA | shift; //AB + /AC
	Hardware->bltcon1	= 0x0000 | shift; //shifting the B source
	
	Hardware->bltadat 	= 0x0000; //preload with 0xFFFF for cookie cutting;
	Hardware->bltafwm	= firstwordmask;
	Hardware->bltalwm	= lastwordmask;
	
	Hardware->bltapt	= srcPointer;
	Hardware->bltbpt	= srcPointer;
	if(oldBackground == NULL)
		Hardware->bltcpt= destPointer; //if we don't have a background, use the destination
	else
		Hardware->bltcpt= oldBackground; //if we do have a background, use it
	Hardware->bltdpt	= destPointer;
	
	Hardware->bltamod	= sourceSkip;
	Hardware->bltbmod	= sourceSkip;
	if(oldBackground == NULL)
		Hardware->bltcmod = destinationSkip; //screen size
	else
		Hardware->bltcmod = 0; //we have a background, so don't skip any bytes
	Hardware->bltdmod	= destinationSkip;
	Hardware->bltsize	= blitsize; //execute
}
If I leave out the shifting and cookie cutting, I have a working blit routine for the 32x32 4bpp graphic. This routine draws my bob correctly.

Code:
void B_BlitOverwrite(PLANEPTR destination, int destX, int destY, APTR source, int srcX, int srcY, int sizeW, int sizeH) {
	
	destY = destY*2; //?
	
	int bltW = sizeW/16;
	APTR srcPointer = (APTR)((UBYTE *)source + (srcY * (sizeH/16)) + srcX/8);
	APTR destPointer= (APTR)((destination + (destY * SCREEN_WIDTH_WORDS) + destX/8));
	
	//Increase blit size by 1 word to account for shifts
	UWORD sourceSkip = 0;
	UWORD destinationSkip = SCREEN_WIDTH_BYTES - bltW*2;	
	UWORD blitsize = (sizeH << 6) + bltW;
	
	BlitWait(); //wait for the blitter to become available
	
	Hardware->dmacon 	= (UWORD)0x8040; //make sure blit DMA is enabled	
	Hardware->bltcon0	= (UWORD)0x09F0; //D = A
	Hardware->bltcon1	= (UWORD)0x0000;
	
	Hardware->bltadat 	= (UWORD)0x0000;
	Hardware->bltafwm	= (UWORD)0xFFFF;
	Hardware->bltalwm	= (UWORD)0xFFFF;
	
	Hardware->bltapt	= srcPointer;
	Hardware->bltdpt	= destPointer;
	
	Hardware->bltamod	= sourceSkip;
	Hardware->bltdmod	= destinationSkip;
	Hardware->bltsize	= blitsize; //execute
}
LuigiThirty is offline  
Old 01 January 2017, 22:12   #34
alpine9000
Registered User
 
Join Date: Mar 2016
Location: Australia
Posts: 882
You need to blit an extra word per line for shifting, and your modulo doesn't reflex this.

If you put the extra word in your bltW_* and fix everything from there it should work.

Also, the last word mask should be 0x0000.

Last edited by alpine9000; 01 January 2017 at 22:17.
alpine9000 is offline  
Old 01 January 2017, 22:16   #35
Pat the Cat
Banned
 
Join Date: Dec 2016
Location: Nottingham, UK
Posts: 481
Eh, LuigiThirty, if you do want to start "hitting the metal" with machine code, there was a series run in Ace magazine, or maybe Amiga Format called "Davy Jones Locker". From the guy that did Menace, I think.

Quote:
Originally Posted by kamelito View Post
Source code is here : http://amr.abime.net/issue_165_coverdisks Kamelito

and here http://amr.abime.net/issue_164_coverdisks http://amr.abime.net/issue_163_coverdisks

for info coverdisk 40b and 41b covers Bullfrog programming tutorials.
I daresay there are much more recent tutorials than that on the subject, but certainly, a lot of people did such games on the Amiga. Better than a lot of other platforms.

None of 'em used C, as I recall. Not my kind of game though. Some did use AMOS Basic, that's for sure.

But, if you are having success and fun using C, good luck with your endeavour.

What flavour of C are you using?

Last edited by Pat the Cat; 01 January 2017 at 22:38.
Pat the Cat is offline  
Old 01 January 2017, 22:29   #36
LuigiThirty
Registered User
 
Join Date: Dec 2016
Location: USA
Posts: 101
Quote:
Originally Posted by Pat the Cat View Post
Eh, LuigiThirty, if you do want to start "hitting the metal" with machine code, there was a series run in Amiga Format called "Davy Jones Locker". From the guy that did Menace, I think.

I daresay there are much more recent tutorials than that on the subject, but certainly, a lot of people did such games on the Amiga. Better than a lot of other platforms.

None of 'em used C, as I recall. Not my kind of game though. Some did use AMOS Basic, that's for sure.

But, if you are having success and fun using C, good luck with your endeavour.

What flavour of C are you using?
C99 via VBCC. The actual tile blit routine is in 68K along with some other stuff. Basically I'm writing my new graphics routines in C and translating them to ASM for efficiency once they actually work. The game logic is in C.
LuigiThirty is offline  
Old 03 January 2017, 06:22   #37
LuigiThirty
Registered User
 
Join Date: Dec 2016
Location: USA
Posts: 101
Cool, I got it working! Now if I could figure out how to get Grafx2 to spit out a mask layer in the ILBM file I'll be set. I could generate the mask layers on the fly when the image is loaded but I'm sure someone's ran into this before.
LuigiThirty is offline  
Old 04 January 2017, 15:09   #38
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,545
Quote:
Originally Posted by LuigiThirty View Post
Cool, I got it working!
What was the problem? These lines definitely look wrong:
Code:
    UWORD shift = (destX % 16) << 12;
    UWORD firstwordmask = 0xFFFF >> shift;
    UWORD lastwordmask = 0xFFFF << (16-shift);
"shift" is multiplied by 4096.

Quote:
Now if I could figure out how to get Grafx2 to spit out a mask layer in the ILBM file I'll be set. I could generate the mask layers on the fly when the image is loaded but I'm sure someone's ran into this before.
Yes, there are certainly various tools for that task. Everybody has their own.

In my last games we were using Gimp to draw the animation phases into a BMP picture and I wrote a portable C program to convert the picture into raw graphics data and masks. bmptoraw.c in Solid Gold (source on Aminet).
phx is offline  
Old 04 January 2017, 23:25   #39
LuigiThirty
Registered User
 
Join Date: Dec 2016
Location: USA
Posts: 101
Quote:
Originally Posted by phx View Post
What was the problem? These lines definitely look wrong:
Code:
    UWORD shift = (destX % 16) << 12;
    UWORD firstwordmask = 0xFFFF >> shift;
    UWORD lastwordmask = 0xFFFF << (16-shift);
"shift" is multiplied by 4096.
I meant it works where it doesn't have to do any shifting. The problem with blitting to (0,0) seemed to be the incorrect modulo.
LuigiThirty 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
Smooth vertical scrolling in AMOS idrougge Coders. AMOS 43 21 February 2021 12:58
Horizontal vs vertical scrolling Amiga1992 Coders. General 20 26 October 2015 11:15
infinite money in ishar 2 Jacobson support.Games 7 19 April 2012 12:42
[Found: Insanity Fight] Vertical Scrolling Shootemup capehorn Looking for a game name ? 5 13 March 2009 08:18
Vertical scrolling motorcycle game.. Anyone? Thrash75 Looking for a game name ? 11 18 May 2005 19:44

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 18:35.

Top

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