mirror of
https://github.com/irmen/prog8.git
synced 2024-11-22 15:33:02 +00:00
added conv.str2byte and conv.str2ubyte
This commit is contained in:
parent
4cd5e8c378
commit
ec9e722927
@ -249,6 +249,28 @@ output .text "0000", $00 ; 0-terminated output buffer (to make printing ea
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
asmsub str2ubyte(str string @ AY) clobbers(Y) -> ubyte @A {
|
||||
; -- returns the unsigned byte value of the string number argument in AY
|
||||
; the number may NOT be preceded by a + sign and may NOT contain spaces
|
||||
; (any non-digit character will terminate the number string that is parsed)
|
||||
; TODO implement optimized custom version of this instead of simply reusing str2uword
|
||||
%asm {{
|
||||
jmp str2uword
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
asmsub str2byte(str string @ AY) clobbers(Y) -> ubyte @A {
|
||||
; -- returns the signed byte value of the string number argument in AY
|
||||
; the number may be preceded by a + or - sign but may NOT contain spaces
|
||||
; (any non-digit character will terminate the number string that is parsed)
|
||||
; TODO implement optimized custom version of this instead of simply reusing str2word
|
||||
%asm {{
|
||||
jmp str2word
|
||||
}}
|
||||
}
|
||||
|
||||
asmsub str2uword(str string @ AY) -> uword @ AY {
|
||||
; -- returns the unsigned word value of the string number argument in AY
|
||||
; the number may NOT be preceded by a + sign and may NOT contain spaces
|
||||
|
@ -30,7 +30,7 @@ main {
|
||||
txt.print("es")
|
||||
txt.print(" left.\nWhat is your next guess? ")
|
||||
void txt.input_chars(input)
|
||||
ubyte guess = lsb(conv.str2uword(input))
|
||||
ubyte guess = conv.str2ubyte(input)
|
||||
|
||||
if guess==secretnumber {
|
||||
ending(true)
|
||||
|
@ -11,18 +11,15 @@ main {
|
||||
str name = "irmen de jong"
|
||||
uword strptr = &name
|
||||
|
||||
txt.print("ubyte? ")
|
||||
void txt.input_chars(name)
|
||||
ubyte ub = conv.str2ubyte(name)
|
||||
txt.print_ub(ub)
|
||||
|
||||
txt.print_ub(strlen("1234"))
|
||||
txt.chrout('\n')
|
||||
txt.print_ub(strlen(name))
|
||||
txt.chrout('\n')
|
||||
txt.print_uwhex(strptr, 1)
|
||||
txt.chrout('\n')
|
||||
txt.print(strptr)
|
||||
txt.chrout('\n')
|
||||
txt.print_ub(strlen(strptr))
|
||||
txt.chrout('\n')
|
||||
|
||||
txt.print("\nbyte? ")
|
||||
void txt.input_chars(name)
|
||||
byte bb = conv.str2byte(name)
|
||||
txt.print_b(bb)
|
||||
|
||||
}
|
||||
|
||||
|
@ -78,6 +78,13 @@ trader {
|
||||
}
|
||||
|
||||
sub do_buy() {
|
||||
txt.print("\nBuy what commodity? ")
|
||||
str commodity = "???????????????"
|
||||
void txt.input_chars(commodity)
|
||||
txt.print("\nHow much?")
|
||||
void txt.input_chars(input)
|
||||
ubyte buy_fuel = 10*conv.str2ubyte(input)
|
||||
ubyte amount = lsb()
|
||||
txt.print("\nTODO BUY\n") ; TODO
|
||||
}
|
||||
|
||||
@ -88,7 +95,7 @@ trader {
|
||||
sub do_fuel() {
|
||||
txt.print("\nBuy fuel. Amount? ")
|
||||
void txt.input_chars(input)
|
||||
ubyte buy_fuel = 10*lsb(conv.str2uword(input))
|
||||
ubyte buy_fuel = 10*conv.str2ubyte(input)
|
||||
ubyte max_fuel = ship.Max_fuel - ship.fuel
|
||||
if buy_fuel > max_fuel
|
||||
buy_fuel = max_fuel
|
||||
@ -110,7 +117,7 @@ trader {
|
||||
sub do_hold() {
|
||||
txt.print("\nCheat! Set cargohold size: ")
|
||||
void txt.input_chars(input)
|
||||
ship.Max_cargo = lsb(conv.str2uword(input))
|
||||
ship.Max_cargo = conv.str2ubyte(input)
|
||||
}
|
||||
|
||||
sub do_next_galaxy() {
|
||||
|
Loading…
Reference in New Issue
Block a user