In ML, how to convert a string to a number ?

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
nbla000
Salmon Run
Posts: 2582
Joined: Thu Oct 13, 2005 8:58 am
Location: Italy

In ML, how to convert a string to a number ?

Post by nbla000 »

Hi, in my new DIR program i need to convert a typed string to a number:
When you type:
$11+[RETURN]
working with $7a and $7b pointers i know that "$" is typed and where is the string null terminated to check, typically in $0200-$0258 range, but how to store the value $0B = #11 in any location/register.
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

I think one way to do it is to call $CD9E to evaluate Basic expression. It will set $0D depending on whether it is a number, string, variable (?) etc. I did this in the fastloader to pick up file name. I don't have more docs about this, but have a look what the mentioned routine does for different input.
Anders Carlsson

Image Image Image Image Image
User avatar
nbla000
Salmon Run
Posts: 2582
Joined: Thu Oct 13, 2005 8:58 am
Location: Italy

Post by nbla000 »

thanks carlsson
using the call $CD9E the basic in $0D set the value $ff if is a string like "9ABCD" but if i type 9ABCD without quote the value in $0d is $0 so since for my routines if i type A it's always a syntax error i check for myself if the user type number only (spaces and ":" accepted) and after to convert to a number i've used this method:

Code: Select all

lda $7a      ;write the string starting point present in $7a-$7b 
sta $22      ;to INDEX1 $0022-$0023, First utility pointer 
lda $7b 
sta $23
lda string_length 
jsr $d7b5 ;Convert string starting at $0022-$0023 of length (A) to FLPT value in (FAC)
jsr $d1aa ;Convert (FAC) to integer in (Y/A) lo/hi. 
now Y/A contain the 16bit integer value (low/high byte) NOT A/Y as in documentation.
Post Reply