Load half a mode 7 screen

bbc micro/electron/atom/risc os coding queries and routines
User avatar
pixelblip
Posts: 2062
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Load half a mode 7 screen

Post by pixelblip » Mon Aug 10, 2020 11:44 am

The next stage.....I should try to animate some smoke or jet engine particles coming out of the back....maybe a starfield plottted over the top of the frames.....hmmmmm.....more difficult things to thing about!

User avatar
Richard Russell
Posts: 1658
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Load half a mode 7 screen

Post by Richard Russell » Mon Aug 10, 2020 11:46 am

pixelblip wrote:
Mon Aug 10, 2020 11:28 am
What would be good is a way of grabbing a sprite from a picture and being able to move it ( or it randomly move ) over a background.
The problem is that if you're blitting something other than complete rows (multiples of 40 characters) you can't do it in one hit. You have to split the 'sprite' up into separate strips, one for each character row occupied, and copy them to the screen memory separately. That will still be pretty fast on a modern platform, but obviously it isn't as fast as transferring a single block of memory (using assembler code isn't an option if you want it to run on iOS, because Apple don't allow it).

I could adapt the code I've already got to do that, if the speed reduction is acceptable. Currently I have a PROCblit7 routine which blits only whole rows (you tell it which row to start on and how many rows to blit) which is super-fast. It could be modified so that rather than telling it the range of rows you specify a rectangle to which it should blit, but that's bound to have a significant impact on performance.

I'm assuming, of course, that you're happy to move your 'sprites' by units of whole characters (so 2-sixel steps horizontally and 3-sixel steps vertically), moving them in sixel steps would be much more complicated.

User avatar
pixelblip
Posts: 2062
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Load half a mode 7 screen

Post by pixelblip » Mon Aug 10, 2020 11:55 am

I am happy to move my sprites in whole characters.
I will have to trust what you think is best as I am not sure how it will work in the end in terms of compression vs full frames.
Ideally I would like to animate the sprites say 2 or 3 frames over a moving background of 8 frames ( for example). That is the goal. I could make it simpler and say 8 frames for the sprite and 8 frames for the background. That might be much simpler to achieve.

If that is too adventurous for now then a static sprite is ok.....
I thought of a ship casting a shadow on the ground with a moving background....that kind of thing.....I'll have to do some designs and see.

Movie Maker does a lot of this on the BBC micro (animates mode 7 sprites) but the whole reason I am doing this is that I cannot load in my own backgrounds into the program. So the ship animation would be impossible. I also want it to be pure teletext not an animated gif.

Having a repeated background cycling around is very effective. It means you can just worry about moving some sprites over the top ( and even getting the computer to move them randomly ). It's knowing how to move these chunks of sprites/mode 7.
Gosh it's getting quite advanced now isn't it :) Thanks so far for all your help.

User avatar
Richard Russell
Posts: 1658
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Load half a mode 7 screen

Post by Richard Russell » Mon Aug 10, 2020 12:15 pm

pixelblip wrote:
Mon Aug 10, 2020 11:55 am
Ideally I would like to animate the sprites say 2 or 3 frames over a moving background of 8 frames ( for example).
Perhaps there needs to be two separate functions then: one to blit whole rows really quickly (for the backgrounds), and another to blit sprites which isn't quite as fast.

How will you capture the sprites in the first place? Do you currently have the technology to capture a rectangle of characters to a file (so if the sprite was x characters wide by y characters high, the resulting file would be x*y bytes long)?

User avatar
pixelblip
Posts: 2062
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Load half a mode 7 screen

Post by pixelblip » Mon Aug 10, 2020 12:57 pm

That sounds like a good idea.
I don't know how I will capture the sprites. I can count along in characters into the picture manually and vertically and count how wide they are......but not sure how I will capture those characters?

User avatar
pixelblip
Posts: 2062
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Load half a mode 7 screen

Post by pixelblip » Mon Aug 10, 2020 12:59 pm

Here is an example of the screen ( it ends up in )

https://edit.tf/#0:LoECBAgQIECBAgQB1SBA ... ECBAgQIECA

User avatar
tricky
Posts: 4560
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: Load half a mode 7 screen

Post by tricky » Mon Aug 10, 2020 1:23 pm

pixelblip wrote:
Mon Aug 10, 2020 11:22 am
Ahh sorry I don't know if that was my mistake from the advice Tricky gave ( with the memory ).
Sorry, I was just trying to make the *SAVE and *LOAD as simple as possible.

One thought, do you like authoring these in MODE 7 or would you prefer to draw them in another way.
I think I know the answer (MODE 7) but it is the game dev in me trying to make it easier for the artists :)

Either way, I'm really looking forward to seeing what you produce with your budding animation system.

User avatar
Richard Russell
Posts: 1658
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Load half a mode 7 screen

Post by Richard Russell » Mon Aug 10, 2020 1:40 pm

pixelblip wrote:
Mon Aug 10, 2020 12:57 pm
I don't know how I will capture the sprites.
If you're capturing them from a MODE 7 screen isn't it as simple as using the code you've already got in your Teletext Paint application, for example as suggested by 'Soruk'? The core would be something like:

Code: Select all

      FOR Y% = top% TO bottom%
        FOR X% = left% TO right%
          BPUT#file%, GET(X%,Y%)
        NEXT X%
      NEXT Y%
(substituting the OSBYTE 135 method if you want it to run on older systems).

User avatar
pixelblip
Posts: 2062
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Load half a mode 7 screen

Post by pixelblip » Mon Aug 10, 2020 3:10 pm

Yes I could use that Richard.
Even better would be a variable called shape or something that could be stored in the program that contains this sprite data and moved around on screen

User avatar
Richard Russell
Posts: 1658
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Load half a mode 7 screen

Post by Richard Russell » Mon Aug 10, 2020 3:56 pm

pixelblip wrote:
Mon Aug 10, 2020 3:10 pm
Even better would be a variable called shape or something that could be stored in the program that contains this sprite data and moved around on screen
So when you say "variable" what exactly do you mean? A string? An array? Do you not want to store the sprite in a file at all now?

As your earlier efforts stored the backgrounds in files I assumed that you wanted to do the same with sprites (there's not fundamentally any difference, just one of size) and the code I've written so far makes that assumption. If you want sprites to be treated very differently from backgrounds the whole approach will have to change. :(

User avatar
pixelblip
Posts: 2062
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Load half a mode 7 screen

Post by pixelblip » Mon Aug 10, 2020 4:32 pm

Sorry for the confusion.
I just want to be able to move it around but Im not sure what the best approach is for this. If it is to store it in in a file so be it. I would appreciate some guidance or opinion on what you think is best here. Thanks

User avatar
Richard Russell
Posts: 1658
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Load half a mode 7 screen

Post by Richard Russell » Mon Aug 10, 2020 4:46 pm

pixelblip wrote:
Mon Aug 10, 2020 4:32 pm
I just want to be able to move it around but Im not sure what the best approach is for this.
I said previously: "Currently I have a PROCblit7 routine which blits only whole rows (you tell it which row to start on and how many rows to blit) which is super-fast. It could be modified so that rather than telling it the range of rows you specify a rectangle to which it should blit". It was this suggestion to which you responded "That sounds like a good idea" so I thought it was relatively settled.

Moving the sprite around is just a case of changing the coordinates of the rectangle to which it is blitted (you need to blit the background first to erase the sprite in its previous position of course, which is why it has to be fast). What is it that you're no longer sure about?

User avatar
Richard Russell
Posts: 1658
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Load half a mode 7 screen

Post by Richard Russell » Mon Aug 10, 2020 9:03 pm

Here the ship is a sprite, moved independently of the background:

bbcsdl_sprites.gif

User avatar
pixelblip
Posts: 2062
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Load half a mode 7 screen

Post by pixelblip » Mon Aug 10, 2020 10:14 pm

That is so awesome Richard!

User avatar
pixelblip
Posts: 2062
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Load half a mode 7 screen

Post by pixelblip » Mon Aug 10, 2020 10:14 pm

I will re-read what you said. Sorry if I sounded confused. I just need to get my head around it a bit.

User avatar
pixelblip
Posts: 2062
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Load half a mode 7 screen

Post by pixelblip » Mon Aug 10, 2020 10:44 pm

I'll have to try to get some colour into this pic I think
Attachments
colour.PNG

User avatar
pixelblip
Posts: 2062
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Load half a mode 7 screen

Post by pixelblip » Tue Aug 11, 2020 10:01 am

Hi there
I've got another animation done. I've yet to see it animated.

I've got 7 frames here and a ship.
What is the best of of grabbing the ship and plotting it over these frames please so they show underneath please?

The ship needs to be 'cut out' somehow and placed over the mode 7 moving background. So I guess it has to have a square row of character pixels around it as the cutout shape.
I think it will look really good!
Thanks for your help.
Attachments
animation2.zip
(2.65 KiB) Downloaded 7 times

User avatar
Richard Russell
Posts: 1658
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Load half a mode 7 screen

Post by Richard Russell » Tue Aug 11, 2020 10:24 am

pixelblip wrote:
Tue Aug 11, 2020 10:01 am
What is the best of of grabbing the ship and plotting it over these frames please so they show underneath please?
You already know my suggestion: save the 'sprite' (e.g. to file) as a rectangular block of characters, then blit it at specified x,y coordinates.

I've implemented this here (BBCSDL-specific, sadly), the program is completely working, I showed you the resulting GIF.

But you said "I just need to get my head around it a bit" so my code is in limbo at the moment waiting for you to do that and be happy with the approach I've taken.

User avatar
pixelblip
Posts: 2062
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Load half a mode 7 screen

Post by pixelblip » Tue Aug 11, 2020 10:30 am

Hi Richard.
Thanks for replying.
Please can you post your code with the blit...cheers.
So you need me to save my code ( the ship ) as some characters before you can proceed from what I understand of your post....

User avatar
Richard Russell
Posts: 1658
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Load half a mode 7 screen

Post by Richard Russell » Tue Aug 11, 2020 11:06 am

pixelblip wrote:
Tue Aug 11, 2020 10:30 am
Please can you post your code with the blit...cheers.

Code: Select all

      REM Animated MODE 7 sprites (requires BBC BASIC for SDL 2.0)
      MODE 7
      IF POS REM SDL thread sync
      OFF

      DIM frame$(7)
      upper$ = FNread7(@dir$ + "Upper.bin", 40, 13)
      ship$ = FNread7(@dir$ + "Ship.bin", 16, 3)

      FOR frame% = 1 TO 7
        frame$(frame%) = FNread7(@dir$ + "Frame" + STR$frame% + ".bin", 40, 12)
      NEXT

      REPEAT
        FOR frame% = 1 TO 7
          PROCblit7(upper$, 0, 0, 40, 13)
          PROCblit7(ship$, 12 + ABS(frame%-4), 2, 16, 3)
          PROCblit7(frame$(frame%), 0, 13, 40, 12)
          PROCrefresh7
          WAIT 10
        NEXT
      UNTIL FALSE
      END

      REM Refresh MODE 7 screen after blitting:
      DEF PROCrefresh7
      VDU 23,18,3|
      *REFRESH
      IF POS REM SDL thread sync
      ENDPROC

      REM Read MODE 7 sprite file into a string:
      DEF FNread7(f$, W%, H%)
      LOCAL F%, P%, S%, Y%, s$
      F% = OPENIN(f$)
      IF F% = 0 ERROR 100, "Couldn't open file " + f$
      IF EXT#F% <> W%*H% ERROR 101, "File size doesn't match dimensions " + f$
      IF W% = 40 S% = H% * &200 ELSE S% = H% * W% * 2
      s$ = STRING$(S%, " ")
      FOR Y% = 0 TO H%-1
        IF W% = 40 S% = Y% * &200 ELSE S% = Y% * W% * 2
        FOR P% = S% + 1 TO S% + 2*W% - 1 STEP 2
          MID$(s$, P%, 1) = CHR$(BGET#F%)
        NEXT
      NEXT Y%
      CLOSE #F%
      = s$

      REM Blit sprite string into MODE 7 buffer:
      DEF PROCblit7(s$, X%, Y%, W%, H%)
      LOCAL I%
      IF W% = 40 SYS "SDL_memcpy", @chrmap% + Y% * &200, PTR(s$), H% * &200 : ENDPROC
      FOR I% = 0 TO H% -1
        SYS "SDL_memcpy", @chrmap% + (I% + Y%) * &200 + X% * 2, PTR(s$) + I% * W% * 2, W% * 2
      NEXT
      ENDPROC
animate7.zip
(3.91 KiB) Downloaded 6 times

User avatar
pixelblip
Posts: 2062
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Load half a mode 7 screen

Post by pixelblip » Tue Aug 11, 2020 11:07 am

Thank you.

User avatar
pixelblip
Posts: 2062
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Load half a mode 7 screen

Post by pixelblip » Wed Aug 12, 2020 5:17 am

Morning.
May I ask what changes need to be made to the code You just posted that allows full screen loading of the background picture instead of top and bottom?
I will try to get a second animation done.

Thanks.

User avatar
pixelblip
Posts: 2062
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Load half a mode 7 screen

Post by pixelblip » Wed Aug 12, 2020 7:43 am

I mocked it up in a video package to give everyone an idea of what it might look like - it's reasonably successful.....
Attachments
fs7.gif

User avatar
Richard Russell
Posts: 1658
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Load half a mode 7 screen

Post by Richard Russell » Wed Aug 12, 2020 9:11 am

pixelblip wrote:
Wed Aug 12, 2020 5:17 am
May I ask what changes need to be made to the code You just posted that allows full screen loading of the background picture
None, other than changing the dimensions (it checks that the dimensions and file size match); it will accept any size up to and including full-screen. I tested it with the background files in your animation2.zip and it worked fine.

The only 'cheat' I use, to make it faster, is that if it sees the width is 40 it doesn't bother to check the X-coordinate, since obviously in that case it's a full-width background and X is assumed to be zero.

User avatar
pixelblip
Posts: 2062
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Load half a mode 7 screen

Post by pixelblip » Wed Aug 12, 2020 9:27 am

Ok thanks Richard that is good to know. I can try out some more now knowing that.

User avatar
Richard Russell
Posts: 1658
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Load half a mode 7 screen

Post by Richard Russell » Wed Aug 12, 2020 9:36 am

Richard Russell wrote:
Wed Aug 12, 2020 9:11 am
None, other than changing the dimensions
I should add that I know it's a bit strange to have to pass the dimensions to both FNread7() and PROCblit7(), especially considering that they must be the same, but I was lazy and couldn't be bothered to work out a way of passing the dimensions automatically from one to the other. Sorry about that.

User avatar
pixelblip
Posts: 2062
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Load half a mode 7 screen

Post by pixelblip » Wed Aug 12, 2020 10:10 am

Well I wouldn't have a scoobie doo so don't worry about that :D

I am going to try some parallax scrolling next and pre-render it rather than try to scroll the screen.....let's see how far I get.

User avatar
Richard Russell
Posts: 1658
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Load half a mode 7 screen

Post by Richard Russell » Wed Aug 12, 2020 10:41 pm

I thought by now we might be seeing some marvellous animations from you using my MODE 7 sprite routines. I hope you're not having any trouble with them; I tried to learn my lesson from the Paint thread and make the code relatively bomb proof.

User avatar
BigEd
Posts: 3340
Joined: Sun Jan 24, 2010 10:24 am
Location: West
Contact:

Re: Load half a mode 7 screen

Post by BigEd » Wed Aug 12, 2020 11:00 pm

It has been a terribly hot day - I for one have been completely useless all day.

User avatar
Richard Russell
Posts: 1658
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Load half a mode 7 screen

Post by Richard Russell » Wed Aug 12, 2020 11:06 pm

BigEd wrote:
Wed Aug 12, 2020 11:00 pm
It has been a terribly hot day - I for one have been completely useless all day.
I didn't mean to be pushy, just concerned that I might have once again cocked up an attempt to make code user-friendly. We're lucky here (although the planet is less so!) to have air conditioning, I hate to think what it would have been like without it.

Post Reply

Return to “programming”