2017-12-06 23:23:30 +00:00
|
|
|
// Routines from C64 BASIC ROM
|
|
|
|
|
|
|
|
import c64_kernal
|
|
|
|
|
|
|
|
// print a 16-bit number on the standard output
|
2018-01-20 21:03:56 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|