Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Logical operators bugged? (*solved*)
#1
I can't see why this doesn't work:

Code:
dim a as uByte FUNCTION get (capitalise as byte) as uByte DIM lastK AS uByte AT 23560: REM LAST_K System VAR lastK=0 DO LOOP until lastK <> 0 : REM Wait for a keypress IF capitalise >0 AND lastK >= 97 AND lastK <= 122 THEN: LET lastK = lastK - 32 END IF IF capitalise <0 AND lastK >=65 AND lastK <= 90 THEN: LET lastK=lastK + 32 END IF RETURN lastK END FUNCTION let a=get(1) print a,chr$(a)

Without fail this doesn't capitalise the key I pressed. get(-1) should only produce lower case (a-z), get(0) should produce what's pressed (a-Z) and get(1) should produce UPPER case (A-Z). It doesn't seem to be changing it. I've proved the IF works - I think the AND is failing.

I tried
Code:
IF ((capitalise >0 AND lastK >= 97) AND lastK <= 122) THEN:
in order to see if' it's something in the multiple AND options. Any one of the three conditions, without the AND seems to come out true.

Are logical functions misbehaving?
Reply
#2
Code:
dim i as uByte FUNCTION CONTRAST (colour as uByte) as uByte IF colour <=3 then return 7: END IF return 0 END FUNCTION FOR i = 0 to 7 PRINT "SENT ";i;" GOT ";CONTRAST(i) NEXT i

This comes back with:
Code:
Sent 0 Got 0 Should be Sent 0 got 7 Sent 1 Got 0 Should be Sent 1 got 7 Sent 2 Got 0 Should be Sent 2 got 7 Sent 3 Got 7 Should be Sent 3 got 7 Sent 4 Got 7 Should be Sent 4 got 0 Sent 5 Got 7 Should be Sent 5 got 0 Sent 6 Got 7 Should be Sent 6 got 0 Sent 7 Got 7 Should be Sent 7 got 0

Okay... with "<=3" at least 3 should be the same as 2...yes? And why do 0,1,2 get a return of 0 when they should get a return of 7?

Things get weirder:

Assuming that it was some weird return issue, I decided to return a variable instead:
Code:
dim i as uByte FUNCTION CONTRAST (colour as uByte) as uByte DIM rt as uByte IF colour <=3 then rt=7: END IF IF colour >=4 then rt=0: END IF return rt END FUNCTION FOR i = 0 to 7 PRINT "SENT ";i;" GOT ";CONTRAST(i) NEXT i

This gave me:

This comes back with:
Code:
Sent 0 Got 0 Sent 1 Got 0 Sent 2 Got 0 Sent 3 Got 7 Sent 4 Got 0 Sent 5 Got 0 Sent 6 Got 0 Sent 7 Got 0

I mean. SRSLY? My opinion of what that code does is clearly disagreeing with zxb's version..

Perhaps it's because we didn't initialise rt?

Code:
dim i as uByte FUNCTION CONTRAST (colour as uByte) as uByte DIM rt as uByte rt=9 IF colour <=3 then rt=7: END IF IF colour >=4 then rt=0: END IF return rt END FUNCTION FOR i = 0 to 7 PRINT "SENT ";i;" GOT ";CONTRAST(i) NEXT i

Gives us a little bit of a clearer picture:
Code:
Sent 0 Got 9 Sent 1 Got 9 Sent 2 Got 9 Sent 3 Got 7 Sent 4 Got 0 Sent 5 Got 0 Sent 6 Got 0 Sent 7 Got 0



So. We seem to have a complete logic failure.

0 <= 3 is FALSE and under certain circumstances 7<=3 is TRUE.

I am so going to bed. I've programmed myself into something psychedelic.

Incidentally:

Code:
FUNCTION CONTRAST (colour as uByte) as uByte DIM rt as uByte IF colour <4 then LET rt = 7: END IF IF colour >3 then let rt = 0: END IF return rt END FUNCTION

Seems to be working.

I suppose just asking for PAPER 9 and INK 9 to work is out of the question?
Reply
#3
britlion Wrote:
Code:
dim i as uByte FUNCTION CONTRAST (colour as uByte) as uByte IF colour <=3 then return 7: END IF return 0 END FUNCTION FOR i = 0 to 7 PRINT "SENT ";i;" GOT ";CONTRAST(i) NEXT i

This comes back with:
Code:
Sent 0 Got 0 Should be Sent 0 got 7 Sent 1 Got 0 Should be Sent 1 got 7 Sent 2 Got 0 Should be Sent 2 got 7 Sent 3 Got 7 Should be Sent 3 got 7 Sent 4 Got 7 Should be Sent 4 got 0 Sent 5 Got 7 Should be Sent 5 got 0 Sent 6 Got 7 Should be Sent 6 got 0 Sent 7 Got 7 Should be Sent 7 got 0

Okay... with "<=3" at least 3 should be the same as 2...yes? And why do 0,1,2 get a return of 0 when they should get a return of 7?

You've found another bug. If you use Byte types instead, it works ok. The <= operator was bugged of Ubyte type. It's been fixed.
I guess relational operators need an intensive test :oops: The problem is I can't create tests (I currently run more than 200 test by hand on each compile). Tests need to be automatized. The problem is you can't check the tests results, since they must be run on a real Z80 or on a Z80 emulator. I'm currently developing one. Wink
Reply
#4
I think I have this listed as an issue in my summary post. Glad that I'm not the only one seeing issues with it, though. I was beginning to think I was going crazy Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)