Vector like asm draw routines.

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Vector like asm draw routines.

Post by Nomad »

Ok I admit I am to much of a potato to get my head round the rom draw routines. :lol:

Having seen the 3D basic one liner I thought to myself 'wouldn't it be great to have a draw routine in assembly. to be a kind of building block for a vector library.

I assume that someone has done this already in the past but looking through the magazines I can't seem to find much on the topic.

What I was hoping to do was have 2 registers for the X,Y and another for the length of the line.

Doing some googling found some examples but they seem extremely complicated and slow.

Then again the rom routine is somewhat of a nightmare to comprehend.

https://skoolkid.github.io/rom/asm/2382.html

It's seems a curious design choice why they didn't have vector support on external hardware. Doing this in software just seems wrong. That could have made things so much easier. Even sprite support on hardware would have been all kinds of awesome.
Ralf
Rick Dangerous
Posts: 2283
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Vector like asm draw routines.

Post by Ralf »

When you need to make your own line drawing routine, drawing it pixel by pixel, you'll almost for sure need Bresenham algorithm:

https://en.wikipedia.org/wiki/Bresenham ... _algorithm

There is a lot of info about it, just try googling and you'll eventually find the explanation that would be friendly enough for you.

And when you are ready with Bresenham, there is next question - are you drawing directly to Spectrum screen or to some buffer.

Vector graphics on Spectrum are generally slow, too slow to do it 50 fps or 25 fps. So games like Star Wars which use vectors draw everything into buffer and when the picture is ready dump buffer to the screen, at a rate maybe 8 fps or so.

And your buffer may be differently organised than Spectrum screen, especially it can be linear. In such case you drawing code will be a bit different to adjust to your ogranisation and make optimisations.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Vector like asm draw routines.

Post by Nomad »

I found a circle draw routine, but its still over 200 lines of code, using a bunch of tables/baked values.

https://github.com/ibancg/zxcircle

In fairness to the author it seems easy enough to actually use in the program.

I will keep looking for a similar simple Bresenham code

Edit:

Surprise surprise, when I go to test the tap file, nothing works. :lol: I'll have a look and see if its just the tap file that is borked. I am now suspicious if this code assembles.

Ok done!

That is pretty slick.

Image

the RANDOMIZE USR 53000 works

when restarting fuse, I can get the circle to work..

Image

hmmm interesting.

With a bit of playing around...

Image

Image
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Vector like asm draw routines.

Post by Nomad »

Because the asm code contains the equivalent to a plot function, you can create a kind of 'poor man's LOGO' by using simple loops to generate lines, from the lines can be made polygons... This mashup of basic and assembly is still slower than what could be done in straight assembly. Still the above circle code is miles faster that doing it with the BASIC's CIRCLE function.
Spoiler
I did contemplate just building entire menu's using circles - but the ability to have lines, triangles, and random polygons was just too much to say no to. Plus nobody wants to play a wargame with circles :lol: hexagon or bust!
Spoiler
But thinking about this further many of the calculations for things like burst effect of ordinance works with spheres... hmmm...
Image
User avatar
MonkZy
Manic Miner
Posts: 279
Joined: Thu Feb 08, 2018 1:01 pm

Re: Vector like asm draw routines.

Post by MonkZy »

There is some great .asm libraries for spectrum vector graphics and other really useful stuff here :

http://www.breakintoprogram.co.uk/progr ... y-routines
Post Reply