Anyway, Commodore BASIC returns 0 as false and -1 as true, which seems odd when you're exposed to C-derived languages so much. So, here's an example that returns 1 as true and 0 as false, and also moves a ball around the screen using the keys Z, X, P and L for left, right, up and down respectively. Space will toggle 'rub out' or 'draw'. This is the sort of program that I'd write on the VIC-20 in the Science labs, or when I got bored with Computing Studies using the BBCs (except I'd use plot x,y rather than print out a character).
Code: Select all
10 def fn b(x) = abs(x)
20 x = y = a = s = d = i = a$="": a = 81: s = 1024: d = 40
30 print"{clear}": for i=0 to 1
40 poke s + x + y * d, a: get a$
45 x = x + fn b (a$ = "x") - fn b ( a$ = "z"): y = y + fn b (a$ = "l") - fn b(a$ = "p")
50 x = x + fn b (x < 0) - fn b (x > 39): y = y + fn b (y < 0) - fn b (y > 24)
60 if a$ = " " and a = 81 then a = 32: a$ = ""
70 if a$ = " " and a = 32 then a = 81
80 i = 0: next
I'm assuming that the not(x) is simply flipping the bits, so -1 in two's compliment will be ff, which is 11111111, so flipping the bits then adding one will give you 1 as true if using the function. It's been a while since I did anything with logic gates so I may be wrong or have explained it poorly.
Regards,
Shaun.