CPCWiki forum

General Category => Programming => Topic started by: logiker on 17:47, 10 March 19

Title: Read Charset from BASIC
Post by: logiker on 17:47, 10 March 19
Hi!


Is there an easy way to read (e.g. with peek) the values of the charset in BASIC?
For example I would like to get the 8 byte values of a certain character or symbol.
I know I can create my own ones with SYMBOL, but I want to read the given ones.


Thanks


Logiker
Title: Re: Read Charset from BASIC
Post by: TomEtJerry on 19:06, 10 March 19
Hum, I am not quite sure of what you really want to do. If it's the ability to read system chars, it's easy to do in Basic. You just have to set a SYMBOL AFTER 32 command to put in RAM the font. Then you can read it. Little example :

10 SYMBOL AFTER 32
11 d=HIMEM+1
20 INPUT "Char to read ";c
30 PRINT
40 PRINT "Char values : ";
50 FOR i=0 TO 7:PRINT HEX$(PEEK(d+(c-32)*8+i));",";:NEXT
60 b=8:PRINT CHR$(b);" ";

The only possible "problem" is to know where is the font in memory. You need to get the HIMEM value immediatly after having set the SYMBOL buffer with SYMBOL AFTER command.
Title: Re: Read Charset from BASIC
Post by: logiker on 19:23, 10 March 19
Thank you very much. That is exactly what I was looking for!
Title: Re: Read Charset from BASIC
Post by: logiker on 20:17, 10 March 19
Now I am really currious how this memory stuff works. Can the address of the system chars change? Why is it so? Are the system chars just at the border after the "normal" BASIC memory?
Title: Re: Read Charset from BASIC
Post by: AMSDOS on 22:28, 10 March 19
It's all to do with how HIMEM is set when the Computer is powered up. On a Disk Based system PRINT HIMEM may return a value of 42619, that's with AMSDOS in play, I'm not sure if the same is true with ParaDOS. By default though BASIC allocates a little bit of memory to Redefine the Character set, so Characters 240 to 255 can be Redefined.
If you specified that you don't want any characters to be redefined, you can type SYMBOL AFTER 256, and if you PRINT HIMEM again you will see that value is now 42747.
The problem in BASIC and the SYMBOL AFTER statement is you cannot specify where you want your Redefined Character set, unlike the Firmware equivalent, which gives you the control of where to have your Redefined Character set.
Another problem occurs when using MEMORY followed by an address, which is used to Protect any M/C routines from being overwritten by BASIC. Once MEMORY has been set, the HIMEM is set to that value, though trying to use SYMBOL AFTER will return the Improper Argument Error, the reason for this is SYMBOL AFTER places the Character Set what appears to be above HIMEM and once MEMORY has been set, HIMEM is adjusted to the value and nothing above it can be written there from BASIC.

I hope that makes sense.
Title: Re: Read Charset from BASIC
Post by: logiker on 22:41, 10 March 19
Thanks for your detailed answere! It makes sense to me.
I have one further question:
As I only want to read, I do still have to do whole procedure with SYMBOL AFTER and HIMEM, right?
That's because I can't read from the ROM but only from the copied RAM, isn't it?
Title: Re: Read Charset from BASIC
Post by: AMSDOS on 23:17, 10 March 19
To my knowledge, I've only seen the ROM from inside an Disassembler written in Assembly (unless somebody else knows otherwise). The SYMBOL AFTER statement as TomEtJerry explains does place the contents of the font in RAM and has correctly assigned the variable 'd' in line 11 to point to the start of the Font in RAM.
Title: Re: Read Charset from BASIC
Post by: logiker on 11:42, 11 March 19
Thank you all for explanations and the code!
Powered by SMFPacks Menu Editor Mod