Proportional Text Print (catchy name TBA)

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
arkannoyed
Microbot
Posts: 111
Joined: Mon Feb 05, 2018 9:56 am

Proportional Text Print (catchy name TBA)

Post by arkannoyed » Wed Aug 22, 2018 1:15 pm

Been doing some messin' with some text printing. Very much a work in progress, though it seems to work quite well for a morning work! 8-)

Image

Need to optimise the way the characters are stored a bit and add the ability to read a 'plasma' file so that some nice effects can be achieved.

Currently the CHR set is full 96 characters and 1536 bytes

Print routine is a bit basic, but only 70 bytes.
Last edited by arkannoyed on Wed Aug 22, 2018 2:48 pm, edited 1 time in total.
6 x

User avatar
Ast A. Moore
Manic Miner
Posts: 713
Joined: Mon Nov 13, 2017 3:16 pm

Re: Proportional Text Print (catchy name TBA)

Post by Ast A. Moore » Wed Aug 22, 2018 2:43 pm

Looks gorgeous, but the spacing between words needs to be a tad wider.
0 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
arkannoyed
Microbot
Posts: 111
Joined: Mon Feb 05, 2018 9:56 am

Re: Proportional Text Print (catchy name TBA)

Post by arkannoyed » Wed Aug 22, 2018 2:59 pm

Yes, you're probably right, bit squished.

Hang on....

Any better?

Image
3 x

User avatar
arkannoyed
Microbot
Posts: 111
Joined: Mon Feb 05, 2018 9:56 am

Re: Proportional Text Print (catchy name TBA)

Post by arkannoyed » Wed Aug 22, 2018 3:27 pm

Just in case its not obvious what its doing, I'll explain.

Each character consists of up to 15 frames of 'animation' where its drawn onto the screen pixel by pixel. This means that a text string must be printed 15 times in order to print fully all of the characters within it. As the characters are XOR'ed onto the screen, by actually repeating the process, we can clear the text via the exact same process.

As the printing is proportional, it gives it a nicer look I think, and its actually not that much more tricky to program. Each character occupies 16 bytes, with the first byte being the width in pixels, which is essential for calculating the next X offset. The following 15 bytes consist of an X-offset from the current position and a Y offset. the pixel there is XOR'ed.

An early version used a plasma table to achieve print effects, but that needs work, as it all got a wee bit complicated!

As speed isn't actually paramount, there is probably quite a bit of scope to compress the character set to possibly less than half its current size, with no noticeable slow-down in performance.
1 x

User avatar
Ast A. Moore
Manic Miner
Posts: 713
Joined: Mon Nov 13, 2017 3:16 pm

Re: Proportional Text Print (catchy name TBA)

Post by Ast A. Moore » Wed Aug 22, 2018 8:03 pm

arkannoyed wrote:
Wed Aug 22, 2018 2:59 pm
Yes, you're probably right, bit squished.

Hang on....

Any better?

Image
Oh, yes. Looks great now!
1 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
Ast A. Moore
Manic Miner
Posts: 713
Joined: Mon Nov 13, 2017 3:16 pm

Re: Proportional Text Print (catchy name TBA)

Post by Ast A. Moore » Wed Aug 22, 2018 8:09 pm

Does it auto-split words and start a new line when it reaches the righthand edge of the screen? I remember it took me a couple of tries to implement that just right in my proportional-width font printing routine. (I haven’t revisited it since, so the code is bit on the ugly side.)
0 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
arkannoyed
Microbot
Posts: 111
Joined: Mon Feb 05, 2018 9:56 am

Re: Proportional Text Print (catchy name TBA)

Post by arkannoyed » Thu Aug 23, 2018 7:26 am

Ast A. Moore wrote:
Wed Aug 22, 2018 8:09 pm
Does it auto-split words and start a new line when it reaches the righthand edge of the screen? I remember it took me a couple of tries to implement that just right in my proportional-width font printing routine. (I haven’t revisited it since, so the code is bit on the ugly side.)
Currently nothing as advanced or clever as splitting words. It uses 3 bytes at the start of a line, bit no. (80,40,20,10 etc), then screen address, followed by the text. the line ends with a control character to indicate that theres either a new print position, or its the end of printing.

Its not quite the look I was after. I want more control over the rate of printing on individual lines, but thats next in line for development.
0 x

User avatar
djnzx48
Microbot
Posts: 190
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Proportional Text Print (catchy name TBA)

Post by djnzx48 » Thu Aug 23, 2018 7:27 am

Looks good! Although 1.5K for a font seems quite a lot. Could you somehow use an LFSR to select the pixels that turned on in each character, and so avoid storing them all one by one? The main problem is that it would involve a lot more iterations over each character, unless you somehow got it to only pick from the pixels that actually get drawn, and ignore all the empty space.

Instead of storing an x and y coordinate for each pixel, you could try storing an wrap-around x offset from the previous pixel. Then you could potentially store each pixel using 4 bits or less. Characters like i and j that have 'gaps' in them might pose problems though, and it would slow down as more pixels get drawn. If there aren't many characters using all 15 pixels it might not be too bad.
1 x

User avatar
arkannoyed
Microbot
Posts: 111
Joined: Mon Feb 05, 2018 9:56 am

Re: Proportional Text Print (catchy name TBA)

Post by arkannoyed » Thu Aug 23, 2018 8:00 am

To store the pixels in a linear manor would actually still use 6 bits, which is basically what it uses now for each frame ( 3 for x, 3 for y). If we assume the largest character (M or W) to be 5 bits wide and of a maximum of 7 high (if we take the descenders and taller characters into account), that gives 5x7=35 bits, which encodes in 6 bits. An LFSR would be a nightmare to code for each character, no idea how that might work at the moment, but I agree, it would potentially save a lot as a progression. There are other methods, such as using 3 bits to determine where the next pixel is drawn. This gives the possibility of any of 8 neighbors to set next, but doesn't allow for changing position within the matrix. If the smaller characters could use Elias Gamma or Delta encoding, that might give a slight advantage, but actually when you consider that there aren't many smaller characters, then any local advantage would be wiped out with bigger characters.

In fact, though 15 frames are possible (max) per character, only about 10-12 are used in most cases, sometimes less, so if either indexing or some other direct addressing method were used, then quite a chunk could be saved. A standard CHR set of 8x8 is around 768 bytes, and something around that might be possible. As I said, speed isn't actually the point here, so something a bit slow that has to do a lot of faffing for each character and its associated frame isn't going to spoil the effect much really. Another possibility that actually just popped into my head as I type this is maybe using an index of sequences, as a lot of the characters adopt the same patterns for significant parts of their structure. Therefore, 'a' for instance adopts 10 of the 11 frames that 'd' does, 'i' uses much of 'l' etc. Indexing those sequences could potentially save very large chunks, though would mean a less amorphous look to the progressing of each letter maybe, though that depends entirely upon the actual text being printed.

With this method of referencing sequences, I might achieve something quite useful in size.
0 x

User avatar
arkannoyed
Microbot
Posts: 111
Joined: Mon Feb 05, 2018 9:56 am

Re: Proportional Text Print (catchy name TBA)

Post by arkannoyed » Thu Aug 23, 2018 9:58 am

Oh yes, and by the way, the video (GIF) above is slowed down a touch to better show the animation. It actually runs a little faster than that.
0 x

Post Reply