Changing Fonts in ZX Spectrum :)
- alban lusitanae
- Drutt
- Posts: 28
- Joined: Fri Jun 28, 2019 1:49 pm
- Location: Portugal
- Contact:
Changing Fonts in ZX Spectrum :)
Hi to all
This will be my first programming post on this forum Please note I just started a little bit of programming learning
and in my concept I am reducing myself only to BASIC, no Assembler. So I'm creating a "game" to test where my knowledge goes at the moment.
Appologies if it is long but I will try to be as detailed as possible.
In the "game" test I am creating, I have my idea figured out, but I would like to use a different font, just for fun, and to see how difficult it is.
At first glance, it shouldn't really be THAT difficult, since it involves drawing each of the characters as you do for UDGs, storing them in a memory
and then using what I like to call Zedex's Biggest Secret, tampering with the system variables through POKE to basically shift the ROM's CHARS into reading the previous allocated memory.
This is where it gets confusing. I chose to use BASINc to code and it actually has FONTs binaries inside, mainly from Damien Guard who is a very cool guy and shared his work for people to use at https://damieng.com/typography/zx-origi ... aEYiiW6HU8 . When you try to extract the data out of it (the BASINc version), this is an example of what comes out (considering you chose 255 bytes per line and 64000 as the memory to send the data to):
10 RESTORE 11: FOR F=64000 TO 64767: READ A: POKE F,A: NEXT F
[ALL DATA STATEMENTS starting at 20]
This is pretty normal stuff you would also see while drawing UDGs, the start decimal drawing in data and allocation to the right place.
Then you would add the two POKE instructions, POKE 23606,low byte + POKE 23607,high byte.
I thought that you could just get the data above and mix it with the CHARS redirect to avoid having to load "" code the whole font from TAP,
and when I queried, someone at another "forum" came with this:
10 LET f=64000: CLEAR f-1
100 RESTORE 101: FOR F=64000 TO 64767: READ A: POKE F,A: NEXT F
[ALL DATA STATEMENTS]
and then for the CHARS redirect they send me this:
200 POKE 23607,INT (f/256)-1: POKE 23606,f-256*INT (f/256)
which it is supposed to save me the trouble of matching the value of the POKE statement precisely with these equations to make the CHARS align perfectly to the memory location I chose (on this case 64000). I then added a 210 PRINT "THIS IS A TEST" statement to test the font allocation to the screen file. To my surprise, There was no error, but there was nothing printed as well!
I went to Damien's page and extracted a TAP file, where he LOAD "" CODE what I believe to be all the data before the CHARS redirect
from a memory allocation of 49152,768 and then uses POKE 29606,0; POKE 29607,191 and strangely POKE 29607,60 again after print test the FONT to the screen. And yeah the TAP has two LOAD "" CODE 49152,768 blocks which are the two variants, and which you can actually click L and it loads a new FONT overiding the previous one.
So after all of this, my questions are:
1 - Can you or can you not trigger the FONT without LOADing it from TAP with a memory allocation
2 - What is the best memory placement to place fonts (so you can BASIC code without a problem)
3 - What is the best code to use, both in creating the FONT and in the valuing of variables ?
Thank you guys for everything you can help me with, I would like to LEARN how to use it, not keep replicating code I really don't get (even if it works).
Best Regards
Alban
This will be my first programming post on this forum Please note I just started a little bit of programming learning
and in my concept I am reducing myself only to BASIC, no Assembler. So I'm creating a "game" to test where my knowledge goes at the moment.
Appologies if it is long but I will try to be as detailed as possible.
In the "game" test I am creating, I have my idea figured out, but I would like to use a different font, just for fun, and to see how difficult it is.
At first glance, it shouldn't really be THAT difficult, since it involves drawing each of the characters as you do for UDGs, storing them in a memory
and then using what I like to call Zedex's Biggest Secret, tampering with the system variables through POKE to basically shift the ROM's CHARS into reading the previous allocated memory.
This is where it gets confusing. I chose to use BASINc to code and it actually has FONTs binaries inside, mainly from Damien Guard who is a very cool guy and shared his work for people to use at https://damieng.com/typography/zx-origi ... aEYiiW6HU8 . When you try to extract the data out of it (the BASINc version), this is an example of what comes out (considering you chose 255 bytes per line and 64000 as the memory to send the data to):
10 RESTORE 11: FOR F=64000 TO 64767: READ A: POKE F,A: NEXT F
[ALL DATA STATEMENTS starting at 20]
This is pretty normal stuff you would also see while drawing UDGs, the start decimal drawing in data and allocation to the right place.
Then you would add the two POKE instructions, POKE 23606,low byte + POKE 23607,high byte.
I thought that you could just get the data above and mix it with the CHARS redirect to avoid having to load "" code the whole font from TAP,
and when I queried, someone at another "forum" came with this:
10 LET f=64000: CLEAR f-1
100 RESTORE 101: FOR F=64000 TO 64767: READ A: POKE F,A: NEXT F
[ALL DATA STATEMENTS]
and then for the CHARS redirect they send me this:
200 POKE 23607,INT (f/256)-1: POKE 23606,f-256*INT (f/256)
which it is supposed to save me the trouble of matching the value of the POKE statement precisely with these equations to make the CHARS align perfectly to the memory location I chose (on this case 64000). I then added a 210 PRINT "THIS IS A TEST" statement to test the font allocation to the screen file. To my surprise, There was no error, but there was nothing printed as well!
I went to Damien's page and extracted a TAP file, where he LOAD "" CODE what I believe to be all the data before the CHARS redirect
from a memory allocation of 49152,768 and then uses POKE 29606,0; POKE 29607,191 and strangely POKE 29607,60 again after print test the FONT to the screen. And yeah the TAP has two LOAD "" CODE 49152,768 blocks which are the two variants, and which you can actually click L and it loads a new FONT overiding the previous one.
So after all of this, my questions are:
1 - Can you or can you not trigger the FONT without LOADing it from TAP with a memory allocation
2 - What is the best memory placement to place fonts (so you can BASIC code without a problem)
3 - What is the best code to use, both in creating the FONT and in the valuing of variables ?
Thank you guys for everything you can help me with, I would like to LEARN how to use it, not keep replicating code I really don't get (even if it works).
Best Regards
Alban
Re: Changing Fonts in ZX Spectrum :)
1. Not really, not unless you 'write' directly to the new font location to 'build' it live. A bit like that character thickener routine that's been used in a few bits of Basic. Not unless you change it in the ROM that is.
2. As high as sensibly possible really just before the UDG's if you are using those. If you have any code then you'll probably want that as high as possible too. This will allow as much space as possible for Basic, assuming you are using CLEAR x-1 (x being the start of any code and/or the font code)
3. I have something that may help the charset finder but its quite easy to use, can't attach in this forum area for some reason.
EDIT... Regarding (1) you can have as many in memory as you can sanely fit and switch between them via 23606/23607 if you want.
2. As high as sensibly possible really just before the UDG's if you are using those. If you have any code then you'll probably want that as high as possible too. This will allow as much space as possible for Basic, assuming you are using CLEAR x-1 (x being the start of any code and/or the font code)
3. I have something that may help the charset finder but its quite easy to use, can't attach in this forum area for some reason.
EDIT... Regarding (1) you can have as many in memory as you can sanely fit and switch between them via 23606/23607 if you want.
- alban lusitanae
- Drutt
- Posts: 28
- Joined: Fri Jun 28, 2019 1:49 pm
- Location: Portugal
- Contact:
Re: Changing Fonts in ZX Spectrum :)
First of all, many thanks for the quick answer, much appreciated by this noobspider wrote: ↑Fri Jun 28, 2019 4:14 pm 1. Not really, not unless you 'write' directly to the new font location to 'build' it live. A bit like that character thickener routine that's been used in a few bits of Basic. Not unless you change it in the ROM that is.
2. As high as sensibly possible really just before the UDG's if you are using those. If you have any code then you'll probably want that as high as possible too. This will allow as much space as possible for Basic, assuming you are using CLEAR x-1 (x being the start of any code and/or the font code)
3. I have something that may help the charset finder but its quite easy to use, can't attach in this forum area for some reason.
EDIT... Regarding (1) you can have as many in memory as you can sanely fit and switch between them via 23606/23607 if you want.
Ok, so I just have to know how to properly save and load the blocks, that is ok, if it is how you do it, it's how you do it.
I AM using a SERIOUS amount of UDG usage (we're talking about multiple draw and redraw of the 21 UDGs during the program)
but if I load the Font at the start of the program before anything say at 64000, then the several UDG redraws at 65000+ and prints to the screen file won't actually touch the FONT at 64000 correct? I normally don't do memory allocation or anything else (because... yeah, I don't know how noob), I just type the program, with some subroutines and stuff, but I don't think I will EVER reach the 64000 allocation with the program code...
What are your thoughts on that (and can I see that code? )
- Einar Saukas
- Bugaboo
- Posts: 3185
- Joined: Wed Nov 15, 2017 2:48 pm
Re: Changing Fonts in ZX Spectrum :)
It's quite easy:
- In your favorite emulator, insert a tape containing fonts. For instance file "ZX-ALFA(Fonts).tzx.zip" from here.
- Type this program:
Code: Select all
10 CLEAR 63999 20 LOAD ""CODE 64000 30 POKE 23607,249 40 PRINT "OK!"
- Execute this program above typing "RUN"
- alban lusitanae
- Drutt
- Posts: 28
- Joined: Fri Jun 28, 2019 1:49 pm
- Location: Portugal
- Contact:
Re: Changing Fonts in ZX Spectrum :)
Well thanks Einar"!! And I'll be... I actually chose the EXACT SAME high address as the ZX SOFT team chose (of which you are one of the two)... I must be doing something right! This basically tells me that I might have been thrown off path with all of the other forum's responses... why the whole complicated algorithm??Einar Saukas wrote: ↑Fri Jun 28, 2019 4:51 pm It's quite easy:
That's all.
- In your favorite emulator, insert a tape containing fonts. For instance file "ZX-ALFA(Fonts).tzx.zip" from here.
- Type this program:
Code: Select all
10 CLEAR 63999 20 LOAD ""CODE 64000 30 POKE 23607,249 40 PRINT "OK!"
- Execute this program above typing "RUN"
I'll test all of this and then report back thanks a lot.
- Einar Saukas
- Bugaboo
- Posts: 3185
- Joined: Wed Nov 15, 2017 2:48 pm
Re: Changing Fonts in ZX Spectrum :)
You are welcome!
Re: Changing Fonts in ZX Spectrum :)
Welcome alban!alban lusitanae wrote: ↑Fri Jun 28, 2019 5:06 pm I'll test all of this and then report back thanks a lot.
ZX-Alfa is an absolute treasure trove for using fonts (I think "COUNTDOWN" is my favourite); I've used it many times myself. Einar's code is almost correct, but it has one small bug, corrected here:
Code: Select all
10 CLEAR 63999
20 LOAD ""CODE 64000
30 POKE 23607,249
40 PRINT "Hello World"
- alban lusitanae
- Drutt
- Posts: 28
- Joined: Fri Jun 28, 2019 1:49 pm
- Location: Portugal
- Contact:
Re: Changing Fonts in ZX Spectrum :)
Hi to all
Just tested and it works trhank you very much for all your help, you will be credited of course on any TAP I make.
Just one thing, when I decide to actually draw 768 bytes of my own, do I SAVE "" CODE 64000 or 64000,768? I'm assuming 64000,768
best regards
Just tested and it works trhank you very much for all your help, you will be credited of course on any TAP I make.
Just one thing, when I decide to actually draw 768 bytes of my own, do I SAVE "" CODE 64000 or 64000,768? I'm assuming 64000,768
best regards
Re: Changing Fonts in ZX Spectrum :)
The first option: SAVE "FONTNAME" CODE 64000,768alban lusitanae wrote: ↑Sat Jun 29, 2019 10:35 pm Hi to all
Just tested and it works trhank you very much for all your help, you will be credited of course on any TAP I make.
Just one thing, when I decide to actually draw 768 bytes of my own, do I SAVE "" CODE 64000 or 64000,768? I'm assuming 64000,768
best regards
In fact BASIC won't let you do anything else: when saving a codeblock you have to specify FILENAME, START LOCATION, LENGTH.
- Einar Saukas
- Bugaboo
- Posts: 3185
- Joined: Wed Nov 15, 2017 2:48 pm
Re: Changing Fonts in ZX Spectrum :)
I'm glad it workedalban lusitanae wrote: ↑Sat Jun 29, 2019 10:35 pmJust tested and it works trhank you very much for all your help, you will be credited of course on any TAP I make.
There's no need to credit me for providing help.
It's only if you use any of my fonts or someone else's, then it's good practice to credit it.
- alban lusitanae
- Drutt
- Posts: 28
- Joined: Fri Jun 28, 2019 1:49 pm
- Location: Portugal
- Contact:
Re: Changing Fonts in ZX Spectrum :)
I will use them, dont have time to write one of my own at the moment
- alban lusitanae
- Drutt
- Posts: 28
- Joined: Fri Jun 28, 2019 1:49 pm
- Location: Portugal
- Contact:
Re: Changing Fonts in ZX Spectrum :)
just one question, it takes how much, 1k? I am always struggling for memory
- Einar Saukas
- Bugaboo
- Posts: 3185
- Joined: Wed Nov 15, 2017 2:48 pm
Re: Changing Fonts in ZX Spectrum :)
A complete font is 768 bytes.
If you don't need lowercase letters, then loading only characters from SPACE to Z will take 472 bytes.
If you don't need lowercase letters, then loading only characters from SPACE to Z will take 472 bytes.
Re: Changing Fonts in ZX Spectrum :)
I’ve been searching for a character thickening routine, but this is the only mention I’ve seen of one. Can anybody point me in the right direction? I had a routine to make text bolder back in the eighties, but that’s lost in the mists of time. I’m hoping the one mentioned is the same thing (or similar).
I’m getting back into Spectrum programming after a 30+ year break, so any help would be appreciated
Thanks
Neil
Re: Changing Fonts in ZX Spectrum :)
Something similar to this one? Your mention of "thickening" fits the bill here. But there are plenty of people on this forum who know a lot more about this than I do, so I'm sure someone will have better help. All the best of luck with the programming though. I'm another one who's returned to it after decades and I still find it great fun.Neil48k wrote: ↑Thu Sep 26, 2019 4:25 pmI’ve been searching for a character thickening routine, but this is the only mention I’ve seen of one. Can anybody point me in the right direction? I had a routine to make text bolder back in the eighties, but that’s lost in the mists of time. I’m hoping the one mentioned is the same thing (or similar).
I’m getting back into Spectrum programming after a 30+ year break, so any help would be appreciated
Thanks
Neil
www.fahnn.co.uk / Trine Michelson's Hot Parts: www.fahnn.co.uk/trine.txt / Big Deal (demo): http://www.fahnn.co.uk/big_deal.tap / tw@tter: http://www.fahnn.co.uk/[email protected]
Re: Changing Fonts in ZX Spectrum :)
Not mine but I modded it a tad to make it a bit more helpful! Note I could of made it a lot more effecient but it causes confusion if I type PRINT "" vs PRINT '''' as the former is " and the latter is 'Neil48k wrote: ↑Thu Sep 26, 2019 4:25 pmI’ve been searching for a character thickening routine, but this is the only mention I’ve seen of one. Can anybody point me in the right direction? I had a routine to make text bolder back in the eighties, but that’s lost in the mists of time. I’m hoping the one mentioned is the same thing (or similar).
I’m getting back into Spectrum programming after a 30+ year break, so any help would be appreciated
Thanks
Neil
1. If using standard font ignore this step and step 2
2. Load your new font in and 23606/23607 to 'enable' it. Ensure its loaded into higher memory area say above 32768 as otherwise will be overwritten
3. Ready ? Here:
Code: Select all
10 CLEAR 31600 : LET A=31744
20 FOR N=32 TO 127
30 PRINT AT 21,0;CHR$ N
40 FOR Y=7 TO 0 STEP -1
50 FOR X=6 TO 0 STEP -1
60 IF POINT (X,Y) THEN PLOT X+1,Y
70 NEXT X
80 POKE A , PEEK (22432-256*Y)
90 LET A=A+1
100 NEXT Y
110 NEXT I : CLS
120 POKE 23607,60: PRINT : FOR A=32 TO 127: PRINT CHR$ A; : NEXT A
130 POKE 23607,123 : PRINT : PRINT
140 FOR A=32 TO 127 : PRINT CHR$ A; : NEXT A
4. You can "save" the font (try LIST if needed) via SAVE " name " CODE 31744 , 768
5. POKE 23607 , 123 to enable it (at 31744) , POKE 23607 , 60 to switch to default rom one.
Tip: Just try it with the default one first. There's no check for the font in use at the time so if you have a custom one (see '2') make sure its out the way etc.
6. Enjoy!
- Ast A. Moore
- Rick Dangerous
- Posts: 2643
- Joined: Mon Nov 13, 2017 3:16 pm
Re: Changing Fonts in ZX Spectrum :)
Not exactly what you’re looking for, but since you’re getting back to coding, you might find this interesting nevertheless.
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.
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.
Re: Changing Fonts in ZX Spectrum :)
Thanks to everyone who responded. I’m amazed by the quickness of your kind replies.
I think I may be using this forum a lot!
I think I may be using this forum a lot!
Re: Changing Fonts in ZX Spectrum :)
I think it was exactly that. The same routine I copied from a magazine back in the early eighties. Thank you so muchFahnn wrote: ↑Thu Sep 26, 2019 5:28 pmSomething similar to this one? Your mention of "thickening" fits the bill here. But there are plenty of people on this forum who know a lot more about this than I do, so I'm sure someone will have better help. All the best of luck with the programming though. I'm another one who's returned to it after decades and I still find it great fun.Neil48k wrote: ↑Thu Sep 26, 2019 4:25 pm I’ve been searching for a character thickening routine, but this is the only mention I’ve seen of one. Can anybody point me in the right direction? I had a routine to make text bolder back in the eighties, but that’s lost in the mists of time. I’m hoping the one mentioned is the same thing (or similar).
I’m getting back into Spectrum programming after a 30+ year break, so any help would be appreciated
Thanks
Neil
Re: Changing Fonts in ZX Spectrum :)
Thanks for all the work you’ve put into answering my question. Am I right in thinking this relates to emulators? I haven’t tried those yet. I’m using an original 48k Spectrum. I think I may have to investigate thisspider wrote: ↑Thu Sep 26, 2019 5:43 pmNot mine but I modded it a tad to make it a bit more helpful! Note I could of made it a lot more effecient but it causes confusion if I type PRINT "" vs PRINT '''' as the former is " and the latter is 'Neil48k wrote: ↑Thu Sep 26, 2019 4:25 pm I’ve been searching for a character thickening routine, but this is the only mention I’ve seen of one. Can anybody point me in the right direction? I had a routine to make text bolder back in the eighties, but that’s lost in the mists of time. I’m hoping the one mentioned is the same thing (or similar).
I’m getting back into Spectrum programming after a 30+ year break, so any help would be appreciated
Thanks
Neil
1. If using standard font ignore this step and step 2
2. Load your new font in and 23606/23607 to 'enable' it. Ensure its loaded into higher memory area say above 32768 as otherwise will be overwritten
3. Ready ? Here:Note I had to type that in here!Code: Select all
10 CLEAR 31600 : LET A=31744 20 FOR N=32 TO 127 30 PRINT AT 21,0;CHR$ N 40 FOR Y=7 TO 0 STEP -1 50 FOR X=6 TO 0 STEP -1 60 IF POINT (X,Y) THEN PLOT X+1,Y 70 NEXT X 80 POKE A , PEEK (22432-256*Y) 90 LET A=A+1 100 NEXT Y 110 NEXT I : CLS 120 POKE 23607,60: PRINT : FOR A=32 TO 127: PRINT CHR$ A; : NEXT A 130 POKE 23607,123 : PRINT : PRINT 140 FOR A=32 TO 127 : PRINT CHR$ A; : NEXT A
4. You can "save" the font (try LIST if needed) via SAVE " name " CODE 31744 , 768
5. POKE 23607 , 123 to enable it (at 31744) , POKE 23607 , 60 to switch to default rom one.
Tip: Just try it with the default one first. There's no check for the font in use at the time so if you have a custom one (see '2') make sure its out the way etc.
6. Enjoy!
Thank you
Re: Changing Fonts in ZX Spectrum :)
You're welcome.
No that will work on a real machine. Just type it in and RUN it
Takes about a minute / minute and a half or so to 'work' as it has to 'draw' onto each character row.
At the end it will show the normal default font (or whatever was chosen at the time) then the 'new' one and leave the new one active. See POKE's provided and the SAVE if needed.
Note you can run it again to thicken the font again! But it gets very messy.
If you're stuck and can type blind then POKE 23607 , 60 and (not needed here but worth knowing) POKE 23606 , 0 should restore normality.
Re: Changing Fonts in ZX Spectrum :)
If anything posted does not make sense or you cannot get it to work, don't struggle - just post back and someone will likely try to assist.
- presuminged
- Drutt
- Posts: 11
- Joined: Fri Dec 13, 2019 10:54 am
- Location: Leeds
- Contact:
Re: Changing Fonts in ZX Spectrum :)
Newbie here, how do you calculate the value to poke 23607? For example, I am working on an AGD project with a basic loader and I'd like to use the font in the AGD code in the loader. I know that the font address is 31232. Thanks.
Re: Changing Fonts in ZX Spectrum :)
Hello!presuminged wrote: ↑Fri Dec 13, 2019 10:58 am Newbie here, how do you calculate the value to poke 23607?
Here's how it works:
The 16bit font address is stored in memory as two 8bit bytes, at 23606 and 23607.
Here's how to work it out:
-take your font address and minus 256 from it*
-divide it by 256, put the whole number in 23607
-whatever's left goes in 23606
So if your font is at 31232
23606: 0
23607: 121
Or if your font is at 64126, then it should be this:
23606: 126
23607: 249
*this is because your first printable character is ASCII 32 (a space), so you need 23606/7 to point to 256 bytes below where your font actually is. It's 256 because each character is 8 bytes, so it's 32 x 8.
Trouble there is, you'll need a loader to load the font, before your loader that loads your game uses it! (If I understand right)For example, I am working on an AGD project with a basic loader and I'd like to use the font in the AGD code in the loader. I know that the font address is 31232. Thanks.
- presuminged
- Drutt
- Posts: 11
- Joined: Fri Dec 13, 2019 10:54 am
- Location: Leeds
- Contact:
Re: Changing Fonts in ZX Spectrum :)
Thanks for the quick reply. Yes, my basic loader loads the code and then I'm going to build a menu in basic to handle things like define keys, etc. Anyway, I tried what you suggested and it works perfectly, thank you!