PDA

View Full Version : Code interpretation



Art
- 10th June 2017, 15:58
Hi Guys :)
I’m trying to port PBP code for Tetris I wrote some years ago to C,
and have come across this:


digits var byte [4] '
D0 var digits[0] '
D1 var digits[1] '
D2 var digits[2] '
D3 var digits[3] '

IF D0.0(valuea + valueb) = 1 THEN '
valuec = 1 '
ENDIF ‘



Does it do what I think it does and check any bit at offset (value + valueb) in the array?
At some stage I knew for sure :D It will take more trickery to do it in C, it’s not too accommodating at accessing bits.
Cheers, Brek.

pedja089
- 10th June 2017, 16:26
Yes :)
And some text to make post longer than 10 chars...

Art
- 13th June 2017, 15:17
Thanks :D
I think the code didn’t ever make it try to look outside the first byte in the array anyway,
and the input value never added up to more than 7, but if it can look into other bytes, that’s useful.

pedja089
- 13th June 2017, 15:36
PBP doesn't check array limits. That is true for all variables types. So you can scan thru all pins of all ports with PORTA.0[i]...

Art
- 20th June 2017, 18:49
That was interesting.
The Tetris was monochrome for an LED board, so the Tetris shapes and the well were all arrays of bits.
To write the same thing in C inflates the program, but uses no more RAM.
Rewriting it in C dealing with bytes instead of bits uses less program memory on the C platform, but much more RAM.