Questions about FZX

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
Seven.FFF
Manic Miner
Posts: 287
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Questions about FZX

Post by Seven.FFF » Tue Jul 24, 2018 10:43 pm

Yes, sorry. That’ll teach me to copy my own code without reading it or checking it’s the correct version.
0 x
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
seven-fff.com/blog

User avatar
Alessandro
Manic Miner
Posts: 266
Joined: Wed Nov 15, 2017 11:10 am
Location: Messina, Italy
Contact:

Re: Questions about FZX

Post by Alessandro » Tue Jul 24, 2018 11:24 pm

Seven.FFF wrote:
Tue Jul 24, 2018 10:43 pm
Yes, sorry. That’ll teach me to copy my own code without reading it or checking it’s the correct version.
No probs at all :) you showed me the right direction after all.

Now, there is only question 2 left...
1 x

User avatar
Seven.FFF
Manic Miner
Posts: 287
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Questions about FZX

Post by Seven.FFF » Wed Jul 25, 2018 1:42 am

In promotional FZX fonts, I define a few alternate width spaces: -1px, +1px, +2px, etc. Then I try to adjust my words with these spaces so they fit better on the character boundaries.

In this way, you can still use attributes to highlight words, and the variable spacing is not very noticeable.

Sometimes I even change the horizontal spacing for an individual letter, if this will make the character boundaries align.

Defining a blank char (space) in FZX only ever takes three extra bytes, even if it is the largest possible size of 16px wide and 256px high. So having alternate width spaces is a nice easy cheap thing to do.
0 x
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
seven-fff.com/blog

User avatar
Alessandro
Manic Miner
Posts: 266
Joined: Wed Nov 15, 2017 11:10 am
Location: Messina, Italy
Contact:

Re: Questions about FZX

Post by Alessandro » Tue Jul 31, 2018 10:16 am

Any ideas on how to implement FZX in ZX-Basic?
0 x

oblo
Berk
Posts: 23
Joined: Mon Dec 10, 2018 9:24 pm

Re: Questions about FZX

Post by oblo » Wed Dec 12, 2018 7:37 pm

Alessandro wrote:
Tue Jul 31, 2018 10:16 am
Any ideas on how to implement FZX in ZX-Basic?
Sorry to bring up an old post and I hope you get a way to to that (at least I couldn't)
What I do to edit customized fonts is to use the Font Editor that BorIDE provides.

Image

Once you have the set of fonts you want, just click on File -> Export -> Export Byte Clipboard (or whatever other format you want) and you can paste them on your favourite text editor something like this:

Dim font (767) As uByte => { _
0, 0, 0, 0, 0, 0, 0, 0, _
24, 24, 24, 24, 24, 0, 24, 0, _
...................................
...................................
118,220, 0, 0, 0, 0, 0, 0, _
204, 51,204, 51,204, 51,204, 51 _
}
Poke uInteger 23606, (@font (0)) - 256


HTH
0 x

User avatar
Alessandro
Manic Miner
Posts: 266
Joined: Wed Nov 15, 2017 11:10 am
Location: Messina, Italy
Contact:

Re: Questions about FZX

Post by Alessandro » Sun Dec 16, 2018 12:57 pm

Thank you for the answer, but I am not confortable with BorIDE. I prefer to edit files through Notepad++.

In the end I could not find a way to do it and left FZX fonts aside altogether.
0 x

Alcoholics Anonymous
Berk
Posts: 12
Joined: Mon Oct 08, 2018 2:36 am

Re: Questions about FZX

Post by Alcoholics Anonymous » Wed Dec 19, 2018 6:19 am

Seven.FFF wrote:
Tue Jul 24, 2018 4:06 pm
AA has greatly extended the capabilities of the FZX driver in z88dk, and also provited a stdout crt that uses it. But I don't code in C either. I'm pretty sure you can get z88dk to emit intermediate asm, which you could incorporate into your own framework. But that seems too fiddly for me.
z88dk is not just about C; C is one component of the toolset that includes assembler, linker, macro processor, librarian, etc. It has about 1000 assembly language subroutines that are easily available in library form. To use an asm subroutine you just indicate you want to use it with an EXTERN directive and then you call it. The linker automatically pulls that asm routine out of the library and into your binary and only that asm routine plus its dependencies. It's how all commercial tools work.

The fzx implementation in z88dk is expanded quite a bit:

* colour printing with masked attributes
* pixels are mixed with the display using OR, XOR or CLEAR modes
* printing is done to a window on screen defined by a rectangle
* left margin is definable
* spaces can be expanded by a definable number of pixels

This information, along with current x/y coord, is carried in a structure (in asm this is a collection of bytes) that acts like a print context. This structure is used to remember state between calls; multiple structures can be used for independent print state.

A bunch of utility functions accompany this. Functions return size related information about the font, individual characters of a font, pixel width of strings or buffers, and word wrap functions that tell you how to split a string or buffer at spaces given available number of pixels. You can print strings or buffers left justified like usual or fully justified with space padding.

As an example of usage, the fzx putc function for the spectrum 256x192 display is located here.

To call it, you'd just do this:

Code: Select all

   EXTERN asm_fzx_putc   ;; inform the assembler & linker that this subroutine is elsewhere (it's in the library)

   ld ix,fzx_state   ;; address of structure holding fzx state
   ld c,'H'   ;; ascii code to print
   
   call asm_fzx_putc
And that's it. The linker will pull in the code shown above and its minimum set of dependencies exactly once in your project.

On top of this, fzx terminals are implemented. Terminals are text streams for display devices. In Sinclair-speak they're like channels. Channel 2 on the spectrum is for printing to the top part of the screen. Channel 3 is normally printer iirc. The io model in C is the one implemented in unix (C was created to write unix after all). stdin is the stream for typing input and stdout is the stream for printing to the standard display. The fzx terminal allows printing and text entry via keyboard with the text entry editable. There can be multiple text terminals in windows so you could create, for example, multiple fzx windows on screen with independent printing. The print stream can optionally contain control codes for things like setting colour, changing print position, whether to generate a scroll prompt and so on.

Anyway, that's the overview.
2 x

User avatar
Seven.FFF
Manic Miner
Posts: 287
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Questions about FZX

Post by Seven.FFF » Wed Dec 19, 2018 12:56 pm

Thanks for the good explanation :)
0 x
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
seven-fff.com/blog

Post Reply