diff --git a/include/c64_basic.mfk b/include/c64_basic.mfk index 2e455c03..700d7a72 100644 --- a/include/c64_basic.mfk +++ b/include/c64_basic.mfk @@ -3,4 +3,39 @@ import c64_kernal // print a 16-bit number on the standard output -asm void putword(word xa) @$BDCD extern \ No newline at end of file +asm void putword(word xa) @$BDCD extern +asm void readline() @$A560 extern +const pointer readline_out = $200 + +byte readword_err + +word readword() { + readline() + readword_err = 0 + word result + word four + result = 0 + byte char + byte i + i = 0 + while true { + char = readline_out[i] + if char == 0 { + if i == 0 { + readword_err = 1 + } + return result + } + if 48 <= char <= 48+9 { + four = result + four <<= 2 + result += four + result <<= 1 + result += char - 48 + } else { + readword_err = 1 + return result + } + i += 1 + } +} diff --git a/include/stdio.mfk b/include/stdio.mfk index 16161f2d..81eeff51 100644 --- a/include/stdio.mfk +++ b/include/stdio.mfk @@ -7,4 +7,22 @@ void putstr(pointer str, byte len) { putchar(str[index]) index += 1 } -} \ No newline at end of file +} + +void putstrz(pointer str) { + byte index + index = 0 + while str[index] != 0 { + putchar(str[index]) + index += 1 + } +} + +byte strzlen(pointer str) { + byte index + index = 0 + while str[index] != 0 { + index += 1 + } + return index +}