Hello, I'm new to asm and I was wondering what is the best way of getting a floating number from a user. I would also like for it to be able to accept expressions. So basically assembly's version of TI-BASIC'S input command.

I've tried looking in the documentation and ParseInp seems close to what I need but I still need to input a string and I'm not sure if that is the best way.
Welcome to Cemetech, Mr. Giggum! What you're asking is rather complicated; one option would be to use the edit buffer system. If you just want to get integers from the user, then this topic has some code that might help, but expanding that to do floating-point input would be hard. I wouldn't be surprised if the Prompt/Input method is exposed as a BCALL somewhere, but I'm not sure exactly where. There are also these BCALLS that might help:

Code:
_setNumWindow      equ 452Bh ;based on current cursor position, sets winleft and similar (for input prompts)
_GetStringInput      equ 4E5Eh
_GetStringInput2   equ 4E61h
It might be easier (or at least faster for the time being) to write your own input routine. Instead of accepting all the letters you would just search the numbers and the decimal point. You could take the value input and convert it to whatever format you use after the user presses [Enter]. The _GetCSC key values are organized pretty well for this sort of thing.

For example here's a quick code i wrote:

Code:
;ix = where to store number
inputFloat:
   bcall(_GetCSC)
   or a
    jr z,inputFloat
   cp $9         ;enter
    ret z
   sub $12         ;key 3 is value $12, set to 0
    jr c,inputFloat
   cp $3         ;if < 3 it's in the first row
    jr c,drawNum
   sub $4         ;skip the next 4 buttons (non-number)
   cp $3
    jr c,inputFloat
   cp $7
    jr c,drawNum
   sub $4         ;skip the next 4 buttons
   cp 11         ;if it's > the last number (7) then quit
    jr nc,inputFloat
drawNum:
   ld e,a
   ld d,0
   ld hl,ascii
   add hl,de
   ld a,(hl)
   bcall(_PutC)
   sub $30
   ld (ix),a
   inc ix
   jr inputFloat

ascii:
.db "369"
.db ".258"
.db "0147"
It'll just store the number digit by digit at the address pointed to by ix. A dot is represented by $FE. You can figure out how you want to format the numbers from there or incorporate it into the actual routine. You'll probably also want to add a backspace feature.
This took a lot longer than it should to debug (probably because I'm still getting used to assembly) but I have what I need. Thanks to Kerm for showing me _GetStringInput and to BrandonW for the only documentation I could find on it along with example code (here).

Any way here is my code:

Code:
    ld hl, promptString
    ld de, ioPrompt
    bcall(_strcopy)
    ld b, (iy+9)
    ld c, (iy+1Ch)
    push bc   ;back up old flag values
    res 6, (iy+1Ch)
    set 7, (iy+9)
    bcall(_GetStringInput)
    pop bc
    res OnInterrupt, b   ;restore old flag values
    ld (iy+9), b
    ld (iy+1Ch), c
    ld hl, 2Dh
    ld (OP1+1), hl
    rst rFindSym   ;look up temporary equation 04h,2Dh,00h,00h
    bcall(_ParseInp)
    bcall(_StoAns)
    bcall(_JForceCmdNoChar)
promptString:
    .db "PROMPT:",0

Input: promptString
Output: Ans

This function can still use some improving. Firstly, I haven't implemented any error handlers and secondly, _GetStringInput has its limits (see quote).
brandonw wrote:
It's just like BASIC's Prompt or Input, and it's a little bit clunky, especially if you use [2nd]+[QUIT] (you'll get a memory leak because the program didn't end properly), so probably the smartest thing to do is jump into saferam and delete yourself, so that if you exit too early, you don't get a memory leak. But this also makes leaving the program a little bizarre, so it's up to you (you could set a keyhook earlier to block [2nd]+[QUIT] and stuff like that).
I have been running into a lot of problems with crashes most likely due to memory leaks. The following code is used in an application and if I trigger the error code and make it repeat the code will crash after the second time.


Code:
Start:
   bcall(_CleanAll)
   ld hl,PromptString
   ld de,ioPrompt
   bcall(_strcopy);copy prompt string
   ld b,(iy+9)
   ld c,(iy+1Ch)
   push bc;back up old flag values
   res 6,(iy+1Ch)
   set 7,(iy+9)
   bcall(4E5Eh);_GetStringInput
   pop bc
   res 4,b;restore old flag values
   ld (iy+9),b
   ld (iy+1Ch),c
   ld hl,2Dh
   ld (OP1+1),hl
   rst rFindSym   ;look up temporary equation 04h,2Dh,00h,00h
   AppOnErr(Start)
   bcall(_ParseInp)
   bcall(_StoAns)
   AppOffErr
   bcall(_CleanAll)
   bcall(_JForceCmdNoChar) ;done, return to OS
PromptString:
   .db "PROMPT:",0


How can I fix this?
I have tried to do a lot of trouble shooting but I still haven't gotten the above code to work in an application. It works in a normal assembly program but as soon as I run the _getStringInput bcall a second time during an application the calculator crashes. It does this even if I run the code from saferam. I don't understand why running the code from an application changes weather it works or not. How do I make this work with an application?
I finally figured out how to use it with an application.

You have to use this instead of bcall(4E5Eh)

Code:
    ld a, 50h
    bcall(_newContext)
    bcall(_mon)
    ld a, 3Fh
    bcall(_newContext)
That's great, you figured it out! Does this mean your routine is completely functional now?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement