Author Topic: Plotting Graphics  (Read 694 times)

0 Members and 1 Guest are viewing this topic.

Offline IndyUK

  • CPC464
  • **
  • Posts: 17
  • Country: gb
  • Liked: 0
  • Likes Given: 1
Plotting Graphics
« on: 14:10, 22 June 20 »
 Hi Folks,
 

Need some advice about plotting graphics to the screen.
 
I have been reading up on various methods of plotting sprites and what the pros and cons of these methods are. I don’t have much experience with the CPC (yet) but, based on my previous x86 C programming (which btw I haven’t done in a long time) it was evident even back then that direct screen addressing was the way to go even if you had a fast CPU. So having used this method with the CPC, I noticed that it didn’t take long for the humble CPC to start crawling. I started with a sprite (4 bytes wide and 10 lines in height in Mode 0) which worked perfectly, however. I then upped the ante and plotted a full background (Mode 0 still) and plotted the sprite on top and this is when it almost ground to a halt. So, as a quick test I kept reducing the size of the amount of the background I was printing and found that roughly 1K pixels could be plotted (animated) on the screen before what could be deemed as unplayable. I then thought ok, this is going to be my limit (maybe a little less) so I need to come up with a way of speeding up what I have. In all honestly I fully expected this to happen as our poor humble CPC wasn’t equipped with any GPU type hardware, and had to fully rely upon the programmer to come up with clever ways of helping out.
 
So, again doing some digging around (mainly here :D and over at Chibiakumas site (thanks Keith)) it was obvious that using the Stack was the way to go. However, I started to wonder – although that method has been proven to help but, how much does it actually make a difference? In other words, is it worth investing time in doing the work and only seeing a modest difference or, will it double my speed. I'll probably pursue the Stack method anyway since it can't make things slower but, I just wanted to get peoples thoughts

 
BTW - Does anyone have any demo to show how much faster the output is when using the Stack as opposed to direct screen access?
 
Thanks
 

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1157
  • Likes Given: 1924
Re: Plotting Graphics
« Reply #1 on: 12:23, 23 June 20 »
My Assembly game Star Sweeper is only simple and it has the Slowest Graphics Driver, perhaps the Slowest of everything (except SCR HW ROLL, which is faster than SCR SW ROLL), though it plays just fine: https://www.cpcwiki.eu/index.php/Programming:Coding_a_simple_BASIC_game_into_Assembly


Though if your throwing in everything and the kitchen sink, then every bit of speed may matter. I used to get through Level 3 and 4 and still manage to complete Wizard Willy, though on Level 3 & 4 where the Nasties drained your energy and hurdle Fireballs, the game would slow down and that wasn't even using the entire screen. I don't remember how much had to be onscreen before the game slowed down, maybe 5 or 6 and with Fireballs maybe 10 in all, when that happened all you could do was keep moving.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline IndyUK

  • CPC464
  • **
  • Posts: 17
  • Country: gb
  • Liked: 0
  • Likes Given: 1
Re: Plotting Graphics
« Reply #2 on: 18:34, 23 June 20 »
Hi,
I like your game however, as you say, there's lots of flicker. Is this because the screen is animating too fast? Apart from the HW scroll for the background, what technique did you use to plot the sprites? I already have a block of code that prints direct to the screen and it's ok. I'm now working on converting the same code but this time using the Stack to do the printing. I've got it working but just need to fix the vertical screen wrapping logic so it wraps around when any sprite exceeds top or bottom of the screen.

Also I'm very much intrigued on the HW scrolling you adopted. I can't find any real documentation on how the &BC4D call is used. I have put a small program together in which I scroll up/down 10 lines but of course that just prints garbage to the screen as I don't know where to build the background. I was trying to follow your code but couldn't work out how you created a screens full of boulders and then continously scrolled them. I'd like to use the HW scroll for a scrolling star background. Could you give me any pointers on how to setup the background?
Thanks

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.939
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1157
  • Likes Given: 1924
Re: Plotting Graphics
« Reply #3 on: 13:49, 24 June 20 »
Hi,
I like your game however, as you say, there's lots of flicker. Is this because the screen is animating too fast?


Well sort of, the game screen rolls and everything has to move including the space ship. How fast the Sprite Driver is may improve that, though any rolling game screen suffers with it I guess unless it's updated on a 2nd screen or not moved at all, which involves moving all relevant bits. My game suffers a bit like Harrier Attack, which the aircraft you fly is repeably updated as is flies through the scenary.


Quote
Apart from the HW scroll for the background, what technique did you use to plot the sprites?



It's an Assembly equivalent of what I been doing in BASIC as found here:
https://www.cpcwiki.eu/forum/programming/multicoloured-graphics-in-basic-discuss/


which involves redefining the character set, assigning colours and then using Transparent Mode to overlap the graphic, they aren't true sprites in the sense because sprites are made up as a series of bytes, a 4x8 mode 0 sprite will produce 8x8 image, to one of my images which requires 8,16,24 and so on, the more colours needed the more bytes are used and if a line has none of the relevant colours 0 is used, a typical sprite would be drawn quicker.


Quote
I already have a block of code that prints direct to the screen and it's ok. I'm now working on converting the same code but this time using the Stack to do the printing. I've got it working but just need to fix the vertical screen wrapping logic so it wraps around when any sprite exceeds top or bottom of the screen.

I'm unsure what to suggest, the game I made last year had a Sprite Driver I wrote, which had to include checks where the graphics were and a few times data ended up corrupting or crashing the computer, I wasn't using the stack for that, but writing everything to screen, even though it looked like a text coordinated game.

Quote
Also I'm very much intrigued on the HW scrolling you adopted. I can't find any real documentation on how the &BC4D call is used. I have put a small program together in which I scroll up/down 10 lines but of course that just prints garbage to the screen as I don't know where to build the background. I was trying to follow your code but couldn't work out how you created a screens full of boulders and then continously scrolled them. I'd like to use the HW scroll for a scrolling star background. Could you give me any pointers on how to setup the background?
Thanks


It's all in the Amstrad CPC Firmware Guide, it's on the CPC-Wiki in the BIOS Functions section under  BIOS Screen Functions under Further Stuff.


SCR HW ROLL uses 'a' register for a Paper Colour, which needs to be set to 0 and 'b' register for the direction. If b=0 the roll is down and if b equals any other value, the roll is up.


I also converted an old BASIC 10-Liner into Assembly as well as Pascal & Small-C, which used SCR HW ROLL along with a Star Field. The interesting thing about that is a routine to generate 16bit numbers between 0 and the 640 range, but I haven't been able to find it in here.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3