21 December 2013, 19:53 | #1 |
Fernando Cabrera
Join Date: Oct 2013
Location: Spain
Posts: 106
|
Double question about saving background
Hi everyone,
As I said in earlier posts I'm developing a simple arkanoid type game for Amiga in assembly. I would like to ask you a couple of questions about saving the background before drawing a bob: 1) Which is the best way to manage the save buffer allocation? I think that could be calling Exec to allocate the memory needed each time you have to save background for a bob and keep the pointer returned by that call as part of the bob data. Do you think there is a better way of doing this? 2) Here comes the tricky one... Something I couldn't solve properly. I have a 320x200 background with 4 bitplanes. I want to save a 16x8 area of this background before drawing a bob of that size. Problem is that this bob has to be drawn to an odd memory address. I thought I had solved it using some negative modulos. It seemed to work on paper but when I implemented it, to my surprise, it didn't work. After reading again 'Blitter hardware' in Amiga Hardware Reference Manual I realised it wouldn't work because of the blitter working as 2 chips connected by a pipeline. Here is the not working source code: saveBrickBackgroundNotEven: move.l a5,-(a7) lea.l _custom,a5 move.w #$07CA,bltcon0(a5) ;enable B, C and D, A*B + ¬A*C move.w #$8000,bltcon1(a5) ;B shift 8 right move.w #$0000,bltafwm(a5) ;first word mask move.w #$FFFF,bltalwm(a5) ;last word mask move.w #$FFFF,bltadat(a5) ;A channel contains mask in data register move.l a0,bltbpt(a5) ;B channel points to screen move.w #36,bltbmod(a5) ;40 bytes per bitplane and line ;4 bytes read per bitplane and line ;40 - 4 = 36 move.l a1,bltcpt(a5) ;C channel points to save buffer move.w #-2,bltcmod(a5) ;go 2 bytes back because we read 4 move.l a1,bltdpt(a5) ;D channel points to save buffer move.w #-2,bltdmod(a5) ;go 2 bytes back because we read 4 move.w #$0802,bltsize(a5) ;8 lines high ;1 word wide (+1 extra word for shift) .saveBrickBackgroundNotEvenEnd: move.l (a7)+,a5 rts So, I haven't been able to save the background using a 16x8x4 save buffer. The only way I could finaly do it was using a 32x8x4 save buffer, copying 2 words instead of one: the object but also the byte before (that's in an even address) and after it. Here is my final solution, but would it be possible using a buffer same size of the source area though it's at an odd address? saveBrickBackgroundNotEven: move.l a5,-(a7) lea.l _custom,a5 move.w #$09F0,bltcon0(a5) ;enable A and D, direct copy = $F0 move.w #$0000,bltcon1(a5) ;no special modes move.w #$00FF,bltafwm(a5) ;first word mask move.w #$FF00,bltalwm(a5) ;last word mask move.l a0,bltapt(a5) ;A channel points to screen move.w #36,bltamod(a5) ;40 bytes per bitplane and line ;4 bytes read per bitplane and line ;40 - 4 = 36 move.l a1,bltdpt(a5) ;D channel points to save buffer move.w #0,bltdmod(a5) move.w #$0802,bltsize(a5) ;8 lines high x 4 bitplanes per line ;2 words wide .saveBrickBackgroundNotEvenEnd: move.l (a7)+,a5 rts I'm sorry about any mistake in my explanation, hope it's complete enough... Any help on any or all of these 2 questions appreciated. Thanks in advance! |
21 December 2013, 21:51 | #2 |
2 contact me: email only!
Join Date: May 2001
Location: Auckland / New Zealand
Posts: 3,187
|
Personally I wouldn't bother with all the complications of saving just the width behind the object. If the object is always 16 pixels wide, then 32 pixels will always save the entire background, so just do that.
You should be able to take the coordinate (let's say it's 46 pixels indented), mask off the low bits (with and.w #$fff0,d0) which would give the value 32. Now you divide by 8 (with shifts) so you need to skip 4 bytes, and then simply save your 4 bytes across, skipping (40 - 4 = 36) bytes between each plane. And leave the masks as $ffff for both first and last word mask. Done! |
22 December 2013, 12:56 | #3 | |
Fernando Cabrera
Join Date: Oct 2013
Location: Spain
Posts: 106
|
Quote:
|
|
22 December 2013, 13:26 | #4 | |
2 contact me: email only!
Join Date: May 2001
Location: Auckland / New Zealand
Posts: 3,187
|
Quote:
|
|
22 December 2013, 15:10 | #5 | |
Fernando Cabrera
Join Date: Oct 2013
Location: Spain
Posts: 106
|
Quote:
@Codetapper: thank you so much for your help and I hope to see updates in your awesome site. I also started using Maptapper recently and I think it's a fantastic tool. Thanks! |
|
15 January 2014, 10:34 | #6 |
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,655
|
If your background doesn't change and you have plenty of chipmem left, just copy the entire background after the screen is setup. Then you can skip the save background step.
If you don't have enough chipmem and need to save the background: Modulos must be even, because the blitter only works with words. This means widths must be rounded up to the next even 16px - but if the bob shift is 0, you don't have to add one word to the width. Another way to save to memory spent is to only save away the bitplanes of the background that are changed when you blit the bob. So if the background is 3 bitplanes and the bob is 5 bitplanes, you can save away just 3 and clear the other two bitplanes. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Double PAL / Double NTSC, oficially supported by WHDLoad... | Shoonay | project.WHDLoad | 3 | 15 May 2021 19:42 |
Double dragon II and Leander adf question | trydowave | support.Games | 5 | 03 May 2013 16:28 |
WHD games and saving question | Lorfarius | support.Games | 4 | 22 February 2010 23:48 |
PS2UAE - question about saving state | samtam90 | Retrogaming General Discussion | 1 | 23 March 2007 18:20 |
Question on Saving... | DontGoAway17 | New to Emulation or Amiga scene | 5 | 09 March 2006 23:18 |
|
|