Changing Fonts in ZX Spectrum :)
Posted: Fri Jun 28, 2019 3:40 pm
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