mirror of
https://github.com/irmen/prog8.git
synced 2025-01-14 01:29:55 +00:00
string to byte
This commit is contained in:
parent
f070dc22bb
commit
a499ac6def
118
compiler/examples/comparison_ifs_byte.p8
Normal file
118
compiler/examples/comparison_ifs_byte.p8
Normal file
@ -0,0 +1,118 @@
|
||||
%import c64utils
|
||||
%import mathlib
|
||||
%option enable_floats
|
||||
|
||||
|
||||
~ main {
|
||||
|
||||
sub start() {
|
||||
|
||||
byte v1
|
||||
byte v2
|
||||
|
||||
c64scr.print_byte_decimal(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
v1 = 100
|
||||
v2 = 127
|
||||
if v1==v2
|
||||
c64.STROUT("error in 100==127!\n")
|
||||
else
|
||||
c64.STROUT("ok: 100 not == 127\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("ok: 100 != 127\n")
|
||||
else
|
||||
c64.STROUT("error in 100!=127!\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("ok: 100 < 127\n")
|
||||
else
|
||||
c64.STROUT("error in 100<127!\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("ok: 100 <= 127\n")
|
||||
else
|
||||
c64.STROUT("error in 100<=127!\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("error in 100>127!\n")
|
||||
else
|
||||
c64.STROUT("ok: 100 is not >127\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("error in 100>=127!\n")
|
||||
else
|
||||
c64.STROUT("ok: 100 is not >=127\n")
|
||||
|
||||
|
||||
v1 = 125
|
||||
v2 = 22
|
||||
if v1==v2
|
||||
c64.STROUT("error in 125==22!\n")
|
||||
else
|
||||
c64.STROUT("ok: 125 not == 22\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("ok: 125 != 22\n")
|
||||
else
|
||||
c64.STROUT("error in 125!=22!\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("error in 125<22!\n")
|
||||
else
|
||||
c64.STROUT("ok: 125 is not < 22\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("error in 125<=22!\n")
|
||||
else
|
||||
c64.STROUT("ok: 125 is not <= 22\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("ok: 125 > 22\n")
|
||||
else
|
||||
c64.STROUT("error in 125>22!\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("ok: 125 >= 22\n")
|
||||
else
|
||||
c64.STROUT("error in 125>=22!\n")
|
||||
|
||||
v1 = 22
|
||||
v2 = 22
|
||||
if v1==v2
|
||||
c64.STROUT("ok: 22 == 22\n")
|
||||
else
|
||||
c64.STROUT("error in 22==22!\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("error in 22!=22!\n")
|
||||
else
|
||||
c64.STROUT("ok: 22 is not != 22\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("error in 22<22!\n")
|
||||
else
|
||||
c64.STROUT("ok: 22 is not < 22\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("ok: 22 <= 22\n")
|
||||
else
|
||||
c64.STROUT("error in 22<=22!\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("error in 22>22!\n")
|
||||
else
|
||||
c64.STROUT("ok: 22 is not > 22\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("ok: 22 >= 22\n")
|
||||
else
|
||||
c64.STROUT("error in 22>=22!\n")
|
||||
|
||||
c64scr.print_byte_decimal(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
}
|
||||
|
||||
}
|
118
compiler/examples/comparison_ifs_float.p8
Normal file
118
compiler/examples/comparison_ifs_float.p8
Normal file
@ -0,0 +1,118 @@
|
||||
%import c64utils
|
||||
%import mathlib
|
||||
%option enable_floats
|
||||
|
||||
|
||||
~ main {
|
||||
|
||||
sub start() {
|
||||
|
||||
float v1
|
||||
float v2
|
||||
|
||||
c64scr.print_byte_decimal(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
v1 = 1.11
|
||||
v2 = 699.99
|
||||
if v1==v2
|
||||
c64.STROUT("error in 1.11==699.99!\n")
|
||||
else
|
||||
c64.STROUT("ok: 1.11 not == 699.99\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("ok: 1.11 != 699.99\n")
|
||||
else
|
||||
c64.STROUT("error in 1.11!=699.99!\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("ok: 1.11 < 699.99\n")
|
||||
else
|
||||
c64.STROUT("error in 1.11<699.99!\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("ok: 1.11 <= 699.99\n")
|
||||
else
|
||||
c64.STROUT("error in 1.11<=699.99!\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("error in 1.11>699.99!\n")
|
||||
else
|
||||
c64.STROUT("ok: 1.11 is not >699.99\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("error in 1.11>=699.99!\n")
|
||||
else
|
||||
c64.STROUT("ok: 1.11 is not >=699.99\n")
|
||||
|
||||
|
||||
v1 = 555.5
|
||||
v2 = -22.2
|
||||
if v1==v2
|
||||
c64.STROUT("error in 555.5==-22.2!\n")
|
||||
else
|
||||
c64.STROUT("ok: 555.5 not == -22.2\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("ok: 555.5 != -22.2\n")
|
||||
else
|
||||
c64.STROUT("error in 555.5!=-22.2!\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("error in 555.5<-22.2!\n")
|
||||
else
|
||||
c64.STROUT("ok: 555.5 is not < -22.2\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("error in 555.5<=-22.2!\n")
|
||||
else
|
||||
c64.STROUT("ok: 555.5 is not <= -22.2\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("ok: 555.5 > -22.2\n")
|
||||
else
|
||||
c64.STROUT("error in 555.5>-22.2!\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("ok: 555.5 >= -22.2\n")
|
||||
else
|
||||
c64.STROUT("error in 555.5>=-22.2!\n")
|
||||
|
||||
v1 = -22.2
|
||||
v2 = -22.2
|
||||
if v1==v2
|
||||
c64.STROUT("ok: -22.2 == -22.2\n")
|
||||
else
|
||||
c64.STROUT("error in -22.2==-22.2!\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("error in -22.2!=-22.2!\n")
|
||||
else
|
||||
c64.STROUT("ok: -22.2 is not != -22.2\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("error in -22.2<-22.2!\n")
|
||||
else
|
||||
c64.STROUT("ok: -22.2 is not < -22.2\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("ok: -22.2 <= -22.2\n")
|
||||
else
|
||||
c64.STROUT("error in -22.2<=-22.2!\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("error in -22.2>-22.2!\n")
|
||||
else
|
||||
c64.STROUT("ok: -22.2 is not > -22.2\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("ok: -22.2 >= -22.2\n")
|
||||
else
|
||||
c64.STROUT("error in -22.2>=-22.2!\n")
|
||||
|
||||
c64scr.print_byte_decimal(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
}
|
||||
|
||||
}
|
118
compiler/examples/comparison_ifs_uword.p8
Normal file
118
compiler/examples/comparison_ifs_uword.p8
Normal file
@ -0,0 +1,118 @@
|
||||
%import c64utils
|
||||
%import mathlib
|
||||
%option enable_floats
|
||||
|
||||
|
||||
~ main {
|
||||
|
||||
sub start() {
|
||||
|
||||
uword v1
|
||||
uword v2
|
||||
|
||||
c64scr.print_byte_decimal(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
v1 = 100
|
||||
v2 = 64444
|
||||
if v1==v2
|
||||
c64.STROUT("error in 100==64444!\n")
|
||||
else
|
||||
c64.STROUT("ok: 100 not == 64444\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("ok: 100 != 64444\n")
|
||||
else
|
||||
c64.STROUT("error in 100!=64444!\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("ok: 100 < 64444\n")
|
||||
else
|
||||
c64.STROUT("error in 100<64444!\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("ok: 100 <= 64444\n")
|
||||
else
|
||||
c64.STROUT("error in 100<=64444!\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("error in 100>64444!\n")
|
||||
else
|
||||
c64.STROUT("ok: 100 is not >64444\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("error in 100>=64444!\n")
|
||||
else
|
||||
c64.STROUT("ok: 100 is not >=64444\n")
|
||||
|
||||
|
||||
v1 = 5555
|
||||
v2 = 322
|
||||
if v1==v2
|
||||
c64.STROUT("error in 5555==322!\n")
|
||||
else
|
||||
c64.STROUT("ok: 5555 not == 322\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("ok: 5555 != 322\n")
|
||||
else
|
||||
c64.STROUT("error in 5555!=322!\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("error in 5555<322!\n")
|
||||
else
|
||||
c64.STROUT("ok: 5555 is not < 322\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("error in 5555<=322!\n")
|
||||
else
|
||||
c64.STROUT("ok: 5555 is not <= 322\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("ok: 5555 > 322\n")
|
||||
else
|
||||
c64.STROUT("error in 5555>322!\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("ok: 5555 >= 322\n")
|
||||
else
|
||||
c64.STROUT("error in 5555>=322!\n")
|
||||
|
||||
v1 = 322
|
||||
v2 = 322
|
||||
if v1==v2
|
||||
c64.STROUT("ok: 322 == 322\n")
|
||||
else
|
||||
c64.STROUT("error in 322==322!\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("error in 322!=322!\n")
|
||||
else
|
||||
c64.STROUT("ok: 322 is not != 322\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("error in 322<322!\n")
|
||||
else
|
||||
c64.STROUT("ok: 322 is not < 322\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("ok: 322 <= 322\n")
|
||||
else
|
||||
c64.STROUT("error in 322<=322!\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("error in 322>322!\n")
|
||||
else
|
||||
c64.STROUT("ok: 322 is not > 322\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("ok: 322 >= 322\n")
|
||||
else
|
||||
c64.STROUT("error in 322>=322!\n")
|
||||
|
||||
c64scr.print_byte_decimal(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
}
|
||||
|
||||
}
|
118
compiler/examples/comparsion_ifs_ubyte.p8
Normal file
118
compiler/examples/comparsion_ifs_ubyte.p8
Normal file
@ -0,0 +1,118 @@
|
||||
%import c64utils
|
||||
%import mathlib
|
||||
%option enable_floats
|
||||
|
||||
|
||||
~ main {
|
||||
|
||||
sub start() {
|
||||
|
||||
ubyte v1
|
||||
ubyte v2
|
||||
|
||||
c64scr.print_byte_decimal(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
v1 = 100
|
||||
v2 = 200
|
||||
if v1==v2
|
||||
c64.STROUT("error in 100==200!\n")
|
||||
else
|
||||
c64.STROUT("ok: 100 not == 200\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("ok: 100 != 200\n")
|
||||
else
|
||||
c64.STROUT("error in 100!=200!\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("ok: 100 < 200\n")
|
||||
else
|
||||
c64.STROUT("error in 100<200!\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("ok: 100 <= 200\n")
|
||||
else
|
||||
c64.STROUT("error in 100<=200!\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("error in 100>200!\n")
|
||||
else
|
||||
c64.STROUT("ok: 100 is not >200\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("error in 100>=200!\n")
|
||||
else
|
||||
c64.STROUT("ok: 100 is not >=200\n")
|
||||
|
||||
|
||||
v1 = 155
|
||||
v2 = 22
|
||||
if v1==v2
|
||||
c64.STROUT("error in 155==22!\n")
|
||||
else
|
||||
c64.STROUT("ok: 155 not == 22\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("ok: 155 != 22\n")
|
||||
else
|
||||
c64.STROUT("error in 155!=22!\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("error in 155<22!\n")
|
||||
else
|
||||
c64.STROUT("ok: 155 is not < 22\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("error in 155<=22!\n")
|
||||
else
|
||||
c64.STROUT("ok: 155 is not <= 22\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("ok: 155 > 22\n")
|
||||
else
|
||||
c64.STROUT("error in 155>22!\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("ok: 155 >= 22\n")
|
||||
else
|
||||
c64.STROUT("error in 155>=22!\n")
|
||||
|
||||
v1 = 22
|
||||
v2 = 22
|
||||
if v1==v2
|
||||
c64.STROUT("ok: 22 == 22\n")
|
||||
else
|
||||
c64.STROUT("error in 22==22!\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("error in 22!=22!\n")
|
||||
else
|
||||
c64.STROUT("ok: 22 is not != 22\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("error in 22<22!\n")
|
||||
else
|
||||
c64.STROUT("ok: 22 is not < 22\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("ok: 22 <= 22\n")
|
||||
else
|
||||
c64.STROUT("error in 22<=22!\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("error in 22>22!\n")
|
||||
else
|
||||
c64.STROUT("ok: 22 is not > 22\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("ok: 22 >= 22\n")
|
||||
else
|
||||
c64.STROUT("error in 22>=22!\n")
|
||||
|
||||
c64scr.print_byte_decimal(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
}
|
||||
|
||||
}
|
118
compiler/examples/comparsion_ifs_word.p8
Normal file
118
compiler/examples/comparsion_ifs_word.p8
Normal file
@ -0,0 +1,118 @@
|
||||
%import c64utils
|
||||
%import mathlib
|
||||
%option enable_floats
|
||||
|
||||
|
||||
~ main {
|
||||
|
||||
sub start() {
|
||||
|
||||
word v1
|
||||
word v2
|
||||
|
||||
c64scr.print_byte_decimal(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
v1 = 100
|
||||
v2 = 30333
|
||||
if v1==v2
|
||||
c64.STROUT("error in 100==30333!\n")
|
||||
else
|
||||
c64.STROUT("ok: 100 not == 30333\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("ok: 100 != 30333\n")
|
||||
else
|
||||
c64.STROUT("error in 100!=30333!\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("ok: 100 < 30333\n")
|
||||
else
|
||||
c64.STROUT("error in 100<30333!\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("ok: 100 <= 30333\n")
|
||||
else
|
||||
c64.STROUT("error in 100<=30333!\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("error in 100>30333!\n")
|
||||
else
|
||||
c64.STROUT("ok: 100 is not >30333\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("error in 100>=30333!\n")
|
||||
else
|
||||
c64.STROUT("ok: 100 is not >=30333\n")
|
||||
|
||||
|
||||
v1 = 125
|
||||
v2 = -222
|
||||
if v1==v2
|
||||
c64.STROUT("error in 125==-222!\n")
|
||||
else
|
||||
c64.STROUT("ok: 125 not == -222\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("ok: 125 != -222\n")
|
||||
else
|
||||
c64.STROUT("error in 125!=-222!\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("error in 125<-222!\n")
|
||||
else
|
||||
c64.STROUT("ok: 125 is not < -222\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("error in 125<=-222!\n")
|
||||
else
|
||||
c64.STROUT("ok: 125 is not <= -222\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("ok: 125 > -222\n")
|
||||
else
|
||||
c64.STROUT("error in 125>-222!\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("ok: 125 >= -222\n")
|
||||
else
|
||||
c64.STROUT("error in 125>=-222!\n")
|
||||
|
||||
v1 = -222
|
||||
v2 = -222
|
||||
if v1==v2
|
||||
c64.STROUT("ok: -222 == -222\n")
|
||||
else
|
||||
c64.STROUT("error in -222==-222!\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("error in -222!=-222!\n")
|
||||
else
|
||||
c64.STROUT("ok: -222 is not != -222\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("error in -222<-222!\n")
|
||||
else
|
||||
c64.STROUT("ok: -222 is not < -222\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("ok: -222 <= -222\n")
|
||||
else
|
||||
c64.STROUT("error in -222<=-222!\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("error in -222>-222!\n")
|
||||
else
|
||||
c64.STROUT("ok: -222 is not > -222\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("ok: -222 >= -222\n")
|
||||
else
|
||||
c64.STROUT("error in -222>=-222!\n")
|
||||
|
||||
c64scr.print_byte_decimal(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -38,7 +38,7 @@ ask_guess:
|
||||
if(attempts_left>0) c64.STROUT("es")
|
||||
|
||||
c64.STROUT(" left.\nWhat is your next guess? ")
|
||||
c64scr.input_chars(guessstr)
|
||||
Y=c64scr.input_chars(guessstr)
|
||||
c64.CHROUT('\n')
|
||||
freadstr_arg = guessstr
|
||||
c64.FREADSTR(Y)
|
||||
@ -46,12 +46,12 @@ ask_guess:
|
||||
guess=A
|
||||
c64.EXTCOL=guess ; @debug
|
||||
c64.BGCOL0=secretnumber ;@debug
|
||||
if(guess==secretnumber) { ; @todo equal_b doesn't work
|
||||
if(guess==secretnumber) {
|
||||
c64.STROUT("\nThat's my number, impressive!\n")
|
||||
goto goodbye
|
||||
}
|
||||
c64.STROUT("\nThat is too ")
|
||||
if(guess > secretnumber) ; @todo greater_ub doesn't work?
|
||||
if(guess > secretnumber)
|
||||
c64.STROUT("low!\n")
|
||||
else
|
||||
c64.STROUT("high!\n")
|
||||
|
@ -16,6 +16,11 @@
|
||||
c64scr.print_string(".\nLet's play a number guessing game.\nI am thinking of a number from 1 to 100!You'll have to guess it!\n")
|
||||
|
||||
for ubyte attempts_left in 10 to 1 step -1 {
|
||||
|
||||
|
||||
c64scr.print_byte_decimal(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64scr.print_string("\nYou have ")
|
||||
c64scr.print_byte_decimal(attempts_left)
|
||||
c64scr.print_string(" guess")
|
||||
@ -23,6 +28,21 @@
|
||||
c64scr.print_string(" left.\nWhat is your next guess? ")
|
||||
c64scr.input_chars(guess)
|
||||
ubyte guessednumber = str2ubyte(guess)
|
||||
|
||||
; debug info
|
||||
c64scr.print_string(" > attempts left=")
|
||||
c64scr.print_byte_decimal(attempts_left)
|
||||
c64scr.print_string("\n > secretnumber=")
|
||||
c64scr.print_byte_decimal(secretnumber)
|
||||
c64scr.print_string("\n > guess=")
|
||||
c64scr.print_string(guess)
|
||||
c64scr.print_string("\n > guessednumber=")
|
||||
c64scr.print_byte_decimal(guessednumber)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print_byte_decimal(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
|
||||
if guessednumber==secretnumber {
|
||||
c64scr.print_string("\n\nYou guessed it, impressive!\n")
|
||||
c64scr.print_string("Thanks for playing, ")
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
~ main {
|
||||
sub start() {
|
||||
str name = " "
|
||||
str guess = "000000"
|
||||
str name = "????????????????????????????????????????"
|
||||
str guessstr = "??????????"
|
||||
ubyte secretnumber = rnd() % 100
|
||||
|
||||
vm_write_str("Let's play a number guessing game!\n")
|
||||
|
@ -9,113 +9,110 @@
|
||||
|
||||
float v1
|
||||
float v2
|
||||
ubyte cr
|
||||
|
||||
; check stack usage:
|
||||
c64.STROUT("floating point ")
|
||||
c64scr.print_byte_decimal(X)
|
||||
c64.CHROUT(' ')
|
||||
|
||||
cr=v1==v2
|
||||
cr=v1==v2
|
||||
cr=v1==v2
|
||||
cr=v1!=v2
|
||||
cr=v1!=v2
|
||||
cr=v1!=v2
|
||||
cr=v1<v2
|
||||
cr=v1<v2
|
||||
cr=v1<v2
|
||||
cr=v1<v2
|
||||
cr=v1>v2
|
||||
cr=v1>v2
|
||||
cr=v1>v2
|
||||
cr=v1>v2
|
||||
cr=v1>v2
|
||||
cr=v1<=v2
|
||||
cr=v1<=v2
|
||||
cr=v1<=v2
|
||||
cr=v1<=v2
|
||||
cr=v1>=v2
|
||||
cr=v1>=v2
|
||||
cr=v1>=v2
|
||||
cr=v1>=v2
|
||||
cr=v1>=v2
|
||||
|
||||
c64scr.print_byte_decimal(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
; comparisons:
|
||||
v1=20
|
||||
v2=666.66
|
||||
c64.STROUT("v1=20, v2=666.66\n")
|
||||
compare()
|
||||
|
||||
v1=-20
|
||||
v2=666.66
|
||||
c64.STROUT("v1=-20, v2=666.66\n")
|
||||
compare()
|
||||
|
||||
v1=666.66
|
||||
v2=555.55
|
||||
c64.STROUT("v1=666.66, v2=555.55\n")
|
||||
compare()
|
||||
|
||||
v1=3.1415
|
||||
v2=-3.1415
|
||||
c64.STROUT("v1 = 3.1415, v2 = -3.1415\n")
|
||||
compare()
|
||||
|
||||
v1=3.1415
|
||||
v2=3.1415
|
||||
c64.STROUT("v1 = v2 = 3.1415\n")
|
||||
compare()
|
||||
|
||||
v1=0
|
||||
v2=0
|
||||
c64.STROUT("v1 = v2 = 0\n")
|
||||
compare()
|
||||
|
||||
c64scr.print_byte_decimal(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
return
|
||||
|
||||
sub compare() {
|
||||
c64.STROUT(" == != < > <= >=\n")
|
||||
|
||||
v1 = 1.11
|
||||
v2 = 699.99
|
||||
if v1==v2
|
||||
c64.STROUT(" Q ")
|
||||
c64.STROUT("error in 1.11==699.99!\n")
|
||||
else
|
||||
c64.STROUT(" . ")
|
||||
c64.STROUT("ok: 1.11 not == 699.99\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT(" Q ")
|
||||
c64.STROUT("ok: 1.11 != 699.99\n")
|
||||
else
|
||||
c64.STROUT(" . ")
|
||||
c64.STROUT("error in 1.11!=699.99!\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT(" Q ")
|
||||
c64.STROUT("ok: 1.11 < 699.99\n")
|
||||
else
|
||||
c64.STROUT(" . ")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT(" Q ")
|
||||
else
|
||||
c64.STROUT(" . ")
|
||||
c64.STROUT("error in 1.11<699.99!\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT(" Q ")
|
||||
c64.STROUT("ok: 1.11 <= 699.99\n")
|
||||
else
|
||||
c64.STROUT(" . ")
|
||||
c64.STROUT("error in 1.11<=699.99!\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("error in 1.11>699.99!\n")
|
||||
else
|
||||
c64.STROUT("ok: 1.11 is not >699.99\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT(" Q ")
|
||||
c64.STROUT("error in 1.11>=699.99!\n")
|
||||
else
|
||||
c64.STROUT(" . ")
|
||||
c64.STROUT("ok: 1.11 is not >=699.99\n")
|
||||
|
||||
|
||||
v1 = 555.5
|
||||
v2 = -22.2
|
||||
if v1==v2
|
||||
c64.STROUT("error in 555.5==-22.2!\n")
|
||||
else
|
||||
c64.STROUT("ok: 555.5 not == -22.2\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("ok: 555.5 != -22.2\n")
|
||||
else
|
||||
c64.STROUT("error in 555.5!=-22.2!\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("error in 555.5<-22.2!\n")
|
||||
else
|
||||
c64.STROUT("ok: 555.5 is not < -22.2\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("error in 555.5<=-22.2!\n")
|
||||
else
|
||||
c64.STROUT("ok: 555.5 is not <= -22.2\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("ok: 555.5 > -22.2\n")
|
||||
else
|
||||
c64.STROUT("error in 555.5>-22.2!\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("ok: 555.5 >= -22.2\n")
|
||||
else
|
||||
c64.STROUT("error in 555.5>=-22.2!\n")
|
||||
|
||||
v1 = -22.2
|
||||
v2 = -22.2
|
||||
if v1==v2
|
||||
c64.STROUT("ok: -22.2 == -22.2\n")
|
||||
else
|
||||
c64.STROUT("error in -22.2==-22.2!\n")
|
||||
|
||||
if v1!=v2
|
||||
c64.STROUT("error in -22.2!=-22.2!\n")
|
||||
else
|
||||
c64.STROUT("ok: -22.2 is not != -22.2\n")
|
||||
|
||||
if v1<v2
|
||||
c64.STROUT("error in -22.2<-22.2!\n")
|
||||
else
|
||||
c64.STROUT("ok: -22.2 is not < -22.2\n")
|
||||
|
||||
if v1<=v2
|
||||
c64.STROUT("ok: -22.2 <= -22.2\n")
|
||||
else
|
||||
c64.STROUT("error in -22.2<=-22.2!\n")
|
||||
|
||||
if v1>v2
|
||||
c64.STROUT("error in -22.2>-22.2!\n")
|
||||
else
|
||||
c64.STROUT("ok: -22.2 is not > -22.2\n")
|
||||
|
||||
if v1>=v2
|
||||
c64.STROUT("ok: -22.2 >= -22.2\n")
|
||||
else
|
||||
c64.STROUT("error in -22.2>=-22.2!\n")
|
||||
|
||||
c64scr.print_byte_decimal(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -654,11 +654,13 @@ private class StatementTranslator(private val prog: IntermediateProgram,
|
||||
prog.instr(Opcode.CALL, callLabel = targetStmt.scopedname)
|
||||
is Subroutine -> {
|
||||
translateSubroutineCall(targetStmt, stmt.arglist, stmt.position)
|
||||
// make sure we clean up the unused result values from the stack.
|
||||
for(rv in targetStmt.returntypes) {
|
||||
val opcode=opcodeDiscard(rv)
|
||||
prog.instr(opcode)
|
||||
}
|
||||
// make sure we clean up the unused result values from the stack
|
||||
// only if they're non-register return values!
|
||||
if(targetStmt.asmReturnvaluesRegisters.isEmpty())
|
||||
for(rv in targetStmt.returntypes) {
|
||||
val opcode=opcodeDiscard(rv)
|
||||
prog.instr(opcode)
|
||||
}
|
||||
}
|
||||
else ->
|
||||
throw AstException("invalid call target node type: ${targetStmt::class}")
|
||||
|
@ -168,6 +168,7 @@ asmsub word2decimal (dataword: uword @ XY) -> clobbers(A,X,Y) -> () {
|
||||
iny
|
||||
rts
|
||||
}}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -810,22 +811,22 @@ _pr_decimal
|
||||
}
|
||||
|
||||
|
||||
asmsub input_chars (buffer: uword @ AX) -> clobbers(A) -> (ubyte @ Y) {
|
||||
; ---- Input a string (max. 80 chars) from the keyboard. Returns length.
|
||||
; It assumes the keyboard is selected as I/O channel!!
|
||||
asmsub input_chars (buffer: uword @ AY) -> clobbers(A, X) -> (ubyte @ Y) {
|
||||
; ---- Input a string (max. 80 chars) from the keyboard. Returns length in Y.
|
||||
; It assumes the keyboard is selected as I/O channel!
|
||||
|
||||
%asm {{
|
||||
sta c64.SCRATCH_ZPB1
|
||||
stx c64.SCRATCH_ZPREG
|
||||
sta c64.SCRATCH_ZPWORD1
|
||||
sty c64.SCRATCH_ZPWORD1+1
|
||||
ldy #0 ; char counter = 0
|
||||
- jsr c64.CHRIN
|
||||
cmp #$0d ; return (ascii 13) pressed?
|
||||
beq + ; yes, end.
|
||||
sta (c64.SCRATCH_ZPB1),y ; else store char in buffer
|
||||
sta (c64.SCRATCH_ZPWORD1),y ; else store char in buffer
|
||||
iny
|
||||
bne -
|
||||
+ lda #0
|
||||
sta (c64.SCRATCH_ZPB1),y ; finish string with 0 byte
|
||||
sta (c64.SCRATCH_ZPWORD1),y ; finish string with 0 byte
|
||||
rts
|
||||
|
||||
}}
|
||||
|
@ -743,6 +743,15 @@ func_str2byte .proc
|
||||
.pend
|
||||
|
||||
func_str2ubyte .proc
|
||||
;-- convert string (address on stack) to ubyte number
|
||||
; @todo load address into $22/$23
|
||||
; @todo length of string in A
|
||||
;jsr c64.FREADSTR ; string to fac1
|
||||
;jsr c64.GETADR ; fac1 to unsigned word in Y/A
|
||||
inx
|
||||
lda #99 ; @todo
|
||||
sta ESTACK_LO,x
|
||||
dex
|
||||
rts
|
||||
.warn "not implemented"
|
||||
.pend
|
||||
|
Loading…
x
Reference in New Issue
Block a user