New BASIC command/token in ROM

All aspects of programming on the Commander X16.
User avatar
JimmyDansbo
Posts: 476
Joined: Sun Apr 26, 2020 8:10 pm
Location: Denmark
Contact:

New BASIC command/token in ROM

Post 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

Visit my Github repo
or my personal site with CX16/C64/6502 related information.
Feel free to contact me regarding any of my projects or even about meeting up somewhere near Denmark
User avatar
desertfish
Posts: 1123
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

New BASIC command/token in ROM

Post 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?

User avatar
JimmyDansbo
Posts: 476
Joined: Sun Apr 26, 2020 8:10 pm
Location: Denmark
Contact:

New BASIC command/token in ROM

Post 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

Visit my Github repo
or my personal site with CX16/C64/6502 related information.
Feel free to contact me regarding any of my projects or even about meeting up somewhere near Denmark
User avatar
desertfish
Posts: 1123
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

New BASIC command/token in ROM

Post 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....)

User avatar
JimmyDansbo
Posts: 476
Joined: Sun Apr 26, 2020 8:10 pm
Location: Denmark
Contact:

New BASIC command/token in ROM

Post 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 ?

Visit my Github repo
or my personal site with CX16/C64/6502 related information.
Feel free to contact me regarding any of my projects or even about meeting up somewhere near Denmark
User avatar
desertfish
Posts: 1123
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

New BASIC command/token in ROM

Post by desertfish »


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

User avatar
desertfish
Posts: 1123
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

New BASIC command/token in ROM

Post 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

User avatar
JimmyDansbo
Posts: 476
Joined: Sun Apr 26, 2020 8:10 pm
Location: Denmark
Contact:

New BASIC command/token in ROM

Post 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

Visit my Github repo
or my personal site with CX16/C64/6502 related information.
Feel free to contact me regarding any of my projects or even about meeting up somewhere near Denmark
User avatar
JimmyDansbo
Posts: 476
Joined: Sun Apr 26, 2020 8:10 pm
Location: Denmark
Contact:

New BASIC command/token in ROM

Post 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.

 

Visit my Github repo
or my personal site with CX16/C64/6502 related information.
Feel free to contact me regarding any of my projects or even about meeting up somewhere near Denmark
User avatar
JimmyDansbo
Posts: 476
Joined: Sun Apr 26, 2020 8:10 pm
Location: Denmark
Contact:

New BASIC command/token in ROM

Post 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.

Visit my Github repo
or my personal site with CX16/C64/6502 related information.
Feel free to contact me regarding any of my projects or even about meeting up somewhere near Denmark
Post Reply