Page 1 of 3

New BASIC command/token in ROM

Posted: Fri Oct 23, 2020 12:06 pm
by JimmyDansbo

I have been trying to help the KERNAL development by creating the HEX$ and BIN$ BASIC commands/tokens, but I do not understand enough of the KERNAL source to actually figure out how to create a new command/token.

Kan anyone point me in the right direction as to what I am missing?

See my note on the issue here:

https://github.com/commanderx16/x16-rom/issues/49#issuecomment-714964134

Thanks in advance


New BASIC command/token in ROM

Posted: Fri Oct 23, 2020 1:07 pm
by desertfish

Hey I was wondering about the lack of HEX$ and BIN$ myself as well so this is an iteresting topic to me! I would like to see if I can perhaps help you with this but  I have zero experience with building a custom rom though right now.   I don't know if that is difficult to  set up?


New BASIC command/token in ROM

Posted: Fri Oct 23, 2020 1:50 pm
by JimmyDansbo

It is not too bad to setup the environment to build a custom rom, if you have a look at https://github.com/commanderx16/x16-rom the README.md tells you how to do it.

I have actually managed to create the HEX$ keyword in ROM, now I just need to figure out how to return a string. Aparently I can not return a multi-byte string the same way as CHR$ returns a single-byte string ?

You can follow my progress here: https://github.com/JimmyDansbo/x16-rom


New BASIC command/token in ROM

Posted: Fri Oct 23, 2020 4:58 pm
by desertfish

first reaction is: look at how left$  is returning a string?    (disclaimer: i have no idea at all how to look into the BASIC rom for how it executes certain tokens....)


New BASIC command/token in ROM

Posted: Fri Oct 23, 2020 5:03 pm
by JimmyDansbo


2 minutes ago, desertfish said:




first reaction is: look at how left$  is returning a string?



Yeah, I have been looking at CHR$, STR$, LEFT$, RIGHT$ and MID$ I still can not get my head around how a string gets allocated, populated and returned correctly.

The way it is done in CHR$ seems fairly simple, but when I try to allocate space for more than 1 byte, I get a type mismatch ?


New BASIC command/token in ROM

Posted: Fri Oct 23, 2020 5:04 pm
by desertfish

I'm intrigued ?    I hope to find some time this weekend to spend on this issue!


New BASIC command/token in ROM

Posted: Fri Oct 23, 2020 11:06 pm
by desertfish

@JimmyDansbo I made a pull request on GitHub to your repository, with what I think should be a working HEX$  including the ability to accept numbers up to 65535

I think it should use the existing routines from the Monitor, but that gave me a 'symbol undefined' error during building of the rom...   I dunno how to access it.  Also I am not sure if this is even possible because it is in a different memory bank perhaps??? (I'm a bit unfamiliar with how that works still)

So for now I simply copied the byte_to_hex_ascii routine from monitor.s almost verbatim into here


New BASIC command/token in ROM

Posted: Sat Oct 24, 2020 5:21 am
by JimmyDansbo

@desertfish That is great, I will look into if it is possible to just jump to the monitor code even though it is in another bank. Thanks


New BASIC command/token in ROM

Posted: Sat Oct 24, 2020 5:51 am
by JimmyDansbo


6 hours ago, desertfish said:




I think it should use the existing routines from the Monitor, but that gave me a 'symbol undefined' error during building of the rom...   I dunno how to access it.  Also I am not sure if this is even possible because it is in a different memory bank perhaps??? (I'm a bit unfamiliar with how that works still)



If you look close to the top of the x16additions.s file

https://github.com/JimmyDansbo/x16-rom/blob/1ab984f18aa5068af6be5368a997810fa1a4e666/basic/x16additions.s#L53

You can see how it goes about calling the monitor from BASIC.

When the ROM is compiled, the monitor.sym file tells us that the byte_to_hex_ascii function has address $C829 so what we can do is this:


Quote




jsr bjsrfar



.word $C829



.byte BANK_MONITOR



I have tested it and it does work, however I think it adds a lot of overhead and if the code in monitor is changed, our $C829 constant needs to be changed.

 


New BASIC command/token in ROM

Posted: Sat Oct 24, 2020 10:29 am
by JimmyDansbo

I have now implemented both HEX$ and BIN$ and there is NO more room in the 16KB BASIC ROM page.

I have had to change the functions to only accept a single byte and I have removed any preceding characters ('$' and '%').

Also it was necessary to to actually use the byte_to_hex_ascii function from the MONITOR code to make the functions fit in BASIC ROM.

Please have a look and let me know if there is anything that should be changed or improved. Otherwise I will do a pull request against the official branch.