CASE statement

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
Ric
Posts: 316
Joined: Tue 17 Apr 2018, 21:03

CASE statement

Post by Ric »

I have coded the following,

Code: Select all

61790 DEF PROCrotateOccluShadow(oRotation%,oShadowIn%,oSideIn%,RETURN oShadowOut%,RETURN oSideOut%)
61800
61810 REM "rotation 01" RWB (front, top, right)
61820 REM "rotation 02" BWO
61830 REM "rotation 03" OWG
61840 REM "rotation 04" GWR
61850
61860 REM "rotation 05" YRB
61870 REM "rotation 06" YGR
61880 REM "rotation 07" YOG
61890 REM "rotation 08" YBO
61900
61910 REM "rotation 09" OYB
61920 REM "rotation 10" BYR
61930 REM "rotation 11" RYG
61940 REM "rotation 12" GYO
61950
61960 REM "rotation 13" WOB
61970 REM "rotation 14" WGO
61980 REM "rotation 15" WRG
61990 REM "rotation 16" WBR
62000
62010 REM "rotation 17" RBY
62020 REM "rotation 18" BOY
62030 REM "rotation 19" OGY
62040 REM "rotation 20" GRY
62050
62060 REM "rotation 21" RGW
62070 REM "rotation 22" GOW
62080 REM "rotation 23" OBW
62090 REM "rotation 24" BRW
62100 oRot% = oRotation%
62110 CASE oSideIn% OF
62120     REM Number of bits displacement for the side not the side number
62130   WHEN 4:
62140     CASE oRotation% OF
62150       WHEN 1: oShadowOut% = oShadowIn%
62160       WHEN 2: oShadowOut% = oShadowIn%
62170       WHEN 3: oShadowOut% = oShadowIn%
62180       WHEN 4: oShadowOut% = oShadowIn%
62190       WHEN 5: PROCrotateOccShadow(2)
62200       WHEN 6: PROCrotateOccShadow(3)
62210       WHEN 7: oShadowOut% = oShadowIn%
62220       WHEN 8: PROCrotateOccShadow(1)
62230       WHEN 9: PROCrotateOccShadow(2)
62240       WHEN 1O: mk;MK PROCrotateOccShadow(2)    kjoihu
62250       WHEN 11: PROCrotateOccShadow(2)
62260       WHEN 12: PROCrotateOccShadow(2)
62270       WHEN 13: PROCrotateOccShadow(2)
62280       WHEN 14: PROCrotateOccShadow(3)
62290       WHEN 15: oShadowOut% = oShadowIn%
62300       WHEN 16: PROCrotateOccShadow(1)
62310       WHEN 17: PROCrotateOccShadow(3)
62320       WHEN 18: PROCrotateOccShadow(3)
62330       WHEN 19: PROCrotateOccShadow(3)
62340       WHEN 2O: njkb; PROCrotateOccShadow(3)  bhj
62350       WHEN 21: PROCrotateOccShadow(1)
62360       WHEN 22: PROCrotateOccShadow(1)
62370       WHEN 23: PROCrotateOccShadow(1)
62380       WHEN 24: PROCrotateOccShadow(1)
62390     ENDCASE
62400   WHEN 8:
62410   WHEN 12:
62420   WHEN 16:
62430   WHEN 20:
62440   WHEN 24:
62450   OTHERWISE : BHJKL
62460 ENDCASE
62470 IF (((oRotation% =10) OR (oRotation%=20)) AND (oSideIn% = 4)) THEN VDJVBHJ
62480
62490 oSideOut% = oSideIn%
62500 ENDPROC
Could someone cast an eye over it and explain why if oRotaion%=10 or 20 and oSideIn% = 4 the proceedure fails at line 62470 and not at 62240 or 662340?

I should say that in all other inputs for oRotation% (1 to 24) the routine works fine!

Kind regards Ric
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Ric
Posts: 316
Joined: Tue 17 Apr 2018, 21:03

Re: CASE statement

Post by Ric »

I have know changed the code to

Code: Select all

62110 oSideIn% = 4
      FOR oRotation% = 1 TO 24
        CASE oSideIn% OF
62120       REM Number of bits displacement for the side not the side number
62130     WHEN 4:
62140       CASE oRotation% OF
62150         WHEN 1: oShadowOut% = oShadowIn%
62160         WHEN 2: oShadowOut% = oShadowIn%
62170         WHEN 3: oShadowOut% = oShadowIn%
62180         WHEN 4: oShadowOut% = oShadowIn%
62190         WHEN 5: PROCrotateOccShadow(2)
62200         WHEN 6: PROCrotateOccShadow(3)
62210         WHEN 7: oShadowOut% = oShadowIn%
62220         WHEN 8: PROCrotateOccShadow(1)
62230         WHEN 9: PROCrotateOccShadow(2)
62240         WHEN 1O: mk;MK PROCrotateOccShadow(2)    kjoihu
62250         WHEN 11: PROCrotateOccShadow(2)
62260         WHEN 12: PROCrotateOccShadow(2)
62270         WHEN 13: PROCrotateOccShadow(2)
62280         WHEN 14: PROCrotateOccShadow(3)
62290         WHEN 15: oShadowOut% = oShadowIn%
62300         WHEN 16: PROCrotateOccShadow(1)
62310         WHEN 17: PROCrotateOccShadow(3)
62320         WHEN 18: PROCrotateOccShadow(3)
62330         WHEN 19: PROCrotateOccShadow(3)
62340         WHEN 2O: njkb; PROCrotateOccShadow(3)  bhj
62350         WHEN 21: PROCrotateOccShadow(1)
62360         WHEN 22: PROCrotateOccShadow(1)
62370         WHEN 23: PROCrotateOccShadow(1)
62380         WHEN 24: PROCrotateOccShadow(1)
62390       ENDCASE
62400     WHEN 8:
62410     WHEN 12:
62420     WHEN 16:
62430     WHEN 20:
62440     WHEN 24:
62450     OTHERWISE : BHJKL
62460   ENDCASE
62470   IF (((oRotation% =10) OR (oRotation%=20)) AND (oSideIn% = 4)) THEN VDJVBHJ
62480 NEXT
62490 END
62500 PROCrotateOccShadow(X)
62510 ENDPROC
to eliminate all other variables a possible influences, but it still fails at 62470 and not 62240 or 62340.
If I change another of the WHEN statements to say
WHEN 8: njk; PROCrotateOccShadow(1)
this then fails at this line
However if i corrupt a line after WHEN 10: then it doesnt fail, as if its not doing the WHEN statements after WHEN 9:
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
User avatar
hellomike
Posts: 205
Joined: Sat 09 Jun 2018, 09:47
Location: Amsterdam

Re: CASE statement

Post by hellomike »

Hi,

Well, what I see straight away is that the zero-characters in the line numbers are real zero's. The zero-characters in the WHENs itself are not, i.e. not ASCII 48 characters.... They seem to be a capital "O".
The zero in the

Code: Select all

62430   WHEN 20:
is ASCII 48 again.

Not sure what's going on.

Mike