Re: A86: integer input


[Prev][Next][Index][Thread]

Re: A86: integer input



In a message dated 97-11-01 18:41:23 EST, you write:

> ok.. here's the thing.. i want to do integer input.. i'm considering one of
>  two methods..  using _inputExpr and doing some weird manipulation of the
>  resulting mantissa to get an integer, or something like this
>  
>  
>  ld a, 0
>  
>  keyloop
>  <check for key>
>  <if enter key quit>
>  multiply a by 10
>  add the value of the key pressed
>  jp keyloop
>  
>  maybe using some kind of table
>  
>  any suggestions out there?
>  
>  thanks
>  David Dollar
>  <ibarawn@geocities.com>
>  TI Hobbyist Extrodinaire
>  

I, personally, would tend to stay away from _inputExpr because (a) it puts up
a prompt equal to the last one used by BASIC's last Input statement, and (b)
because it allows the inputting of non-integers.  Here is a routine to get
integers as input and puts it in B.  I'm sure it could be adapted to get a
number -> bc or hl or something:

<snip from Chem86>
PTNLoop:
        push bc
        call GET_KEY            ;Get key - destroys bc!
        pop bc
        or a
        jr z, PTNLoop           ;0? back.
        cp K_EXIT
	jp z,Exit
        cp K_ENTER              ;Enter?
        jr z,DoneNumIn          ;Done.
	ld hl,NumTable		;(hl)->Numtable
	ld e,a			;de<-keypress(a)
	ld d,0			;	" "
	add hl,de		;(hl)->NumTable[a]
	ld a,(hl)		;a-># pressed.
	cp $FF			;Is it $FF? (not a number)
        jr z,PTNLoop            ;Then go back
        push af                 ;save last # pressed            SP:Num\Num
	push af			;twice
        ld a,b                  ;Put total in a for use.        B:Total
        add a,a                 ;2b
        add a,a                 ;4b
	add a,b			;5b
	add a,a			;10b
        ld b,a                  ;10b->b                         B:10Total
        pop af                  ;Get back a (#) for the 1st time A:Num
        add a,b                 ;Plus just inputted #.          A:New tot!
        ld b,a                  ;And save it in b               B:New tot!
	pop af			;Now get it back again
	add a,$30		;"0"+#.
        call _putc              ;Put
        jr PTNLoop              ;Get next
DoneNumIn:

;# is now in BC


NumTable:					;Converts Scancode -> Number
	.db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
        .db $FF,$FF,$03,$06,$09,$FF,$FF,$FF,$FF,$FF,$02,$05,$08,$FF,$FF,$FF
        .db $FF,$00,$01,$04,$07,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
	.db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF


<snip>

Also, if you DID use _inputExpr, you could just use _convOP1 to convert it to
an integer...

~Steve