From 1c2e6f9e4cf79e41b7176ee30bf0fe7e1655ce11 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Wed, 21 Apr 2021 20:21:58 +0200 Subject: [PATCH] lower() and upper() now also return the lenght of the processed string. --- compiler/res/prog8lib/string.p8 | 8 ++++---- examples/animals.p8 | 8 ++++---- examples/test.p8 | 13 ++++++++++++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/compiler/res/prog8lib/string.p8 b/compiler/res/prog8lib/string.p8 index c9480b4bc..d5fc170bf 100644 --- a/compiler/res/prog8lib/string.p8 +++ b/compiler/res/prog8lib/string.p8 @@ -190,8 +190,8 @@ _found sty P8ZP_SCRATCH_B1 }} } - asmsub lower(uword st @AY) { - ; Lowercases the petscii string in-place. + asmsub lower(uword st @AY) -> ubyte @Y { + ; Lowercases the petscii string in-place. Returns length of the string. ; (for efficiency, non-letter characters > 128 will also not be left intact, ; but regular text doesn't usually contain those characters anyway.) %asm {{ @@ -213,8 +213,8 @@ _done rts }} } - asmsub upper(uword st @AY) { - ; Uppercases the petscii string in-place. + asmsub upper(uword st @AY) -> ubyte @Y { + ; Uppercases the petscii string in-place. Returns length of the string. %asm {{ sta P8ZP_SCRATCH_W1 sty P8ZP_SCRATCH_W1+1 diff --git a/examples/animals.p8 b/examples/animals.p8 index b269c3db3..0e72c7926 100644 --- a/examples/animals.p8 +++ b/examples/animals.p8 @@ -91,7 +91,7 @@ main { txt.print("is it a ") txt.print(animals[animal_number]) txt.print("? ") - txt.input_chars(userinput) + void txt.input_chars(userinput) if userinput[0] == 'y' { txt.print("\n\nsee, i knew it!\n") return @@ -99,18 +99,18 @@ main { str name = "x"*30 txt.print("\n\ni give up. what is it? ") - txt.input_chars(name) + void txt.input_chars(name) txt.print("\nwhat yes-no question would best articulate the difference\nbetween a ") txt.print(animals[animal_number]) txt.print(" and a ") txt.print(name) txt.print("? ") - txt.input_chars(userinput) + void txt.input_chars(userinput) txt.print("\nfor a ") txt.print(name) txt.print(", what is the answer to that; yes or no? ") str answer = "x"*10 - txt.input_chars(answer) + void txt.input_chars(answer) animals[new_animal_number] = animal_names_ptr questions[new_question_number] = questions_ptr diff --git a/examples/test.p8 b/examples/test.p8 index 42a9c65ca..22c25dc38 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,11 +1,22 @@ %import textio +%import string %zeropage basicsafe %import test_stack +%option no_sysinit main { sub start() { - txt.print("♠♥♣♦π▚●○╳") + ubyte xx=existing_entry(1,2) + } + + ; TODO FIX COMPILER ERROR ABOUT MISSING RETURN + + sub existing_entry(ubyte hash, uword symbol) -> ubyte { + if hash>10 + return 44 + else + return false } }