![]() |
Bool - Printable Version +- Forum (https://www.boriel.com/forum) +-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11) +---- Forum: Wishlist (https://www.boriel.com/forum/forumdisplay.php?fid=14) +---- Thread: Bool (/showthread.php?tid=460) |
Bool - slenkar - 04-30-2012 Are bools supported by zxbasic? If so, would an array of bools take up only 1/8 of the room as an array of Bytes? Re: Bool - boriel - 05-01-2012 Bools are not supported, and if they were, for performance reasons they will be bytes or uBytes. If you want syntactic sugar, just #define Bool uByte will do. Re: Bool - LCD - 05-01-2012 Bools are better stored in Memory "by hand", where you can manipulate single bits of each byte really easy since the compiler supports binary operations BOR,BAND,... and bit shifting - SHL,SHR. I'm fine with this. So if you want to save memory and keep good speed, this is the best way. Re: Bool - slenkar - 05-01-2012 so one byte is 8 bits or 8 'switches'? so how would you say read or write a 'switch' in a byte? say I wanted to read switch 4 and read switch 5 if i have a byte array that is the size of the screen that is 32,24 which is 768 bytes if I set up an array of bools it would only be 96 bytes ![]() Re: Bool - boriel - 05-01-2012 slenkar Wrote:so one byte is 8 bits or 8 'switches'?ZX Basic supports BAND and bit shifting with SHR and SHL. In this case, you should use an array of 24 x 4 bytes => 24 Ulong and do the following (Note: This is *UNTESTED* :oops: ) Code: DIM ar(23, 3) as Ubyte ' 24 x 32 bits. Re: Bool - slenkar - 05-02-2012 Code: DIM ar(23, 3) as Ubyte ' 24 x 32 bits. how does 23,3 translate into 24,32 Code: IF GetBool(ar, 3, 20) THEN thanks for the help Re: Bool - boriel - 05-02-2012 slenkar Wrote:The array goes from 0 to 23 (24 rows) and from 0 to 3 (4 bytes = 32bits). So you have 24 x 32bits (1 bit per screen cell). slenkar Wrote:Yep, the are screen coordinates, and ar your byte array. Re: Bool - LCD - 05-02-2012 slenkar Wrote:so one byte is 8 bits or 8 'switches'?Yes. Reading: Code: switch4=(byte>>4)&1 Code: switch5=(byte>>5)&1 Code: poke address,(peek address)|(switch4<<4) Code: poke address,(peek address)|(switch5<<5) Code: switch4=byte>>4&1 <!-- l --><a class="postlink-local" href="http://www.boriel.com/forum/post2064.html#p2064">post2064.html#p2064</a><!-- l --> I found the english precedence table of Freebasic which shows that SHL and SHR have higher priority than +/- and binary AND, OR etc. <!-- m --><a class="postlink" href="http://www.freebasic.net/wiki/wikka.php?wakka=OpPrecedence">http://www.freebasic.net/wiki/wikka.php ... Precedence</a><!-- m --> Re: Bool - slenkar - 05-02-2012 thanks, what is the value of 'address'? on the line that starts with:poke address Re: Bool - LCD - 05-03-2012 slenkar Wrote:thanks, what is the value of 'address'?Any address or pointer... Code: poke @booltable+1,(peek booltable+1)|(switch4<<4) 'use second bytes 4 th bit Re: Bool - boriel - 08-07-2012 LCD Wrote:In fact, FreeBASIC implements them as Macros. You can also implement them as macros using #define as explained above (I've updated ZX Basic operator priorities to reflect FreeBasic's ones, but you can always enforce priorities using parenthesis; this won't affect performance).slenkar Wrote:thanks, what is the value of 'address'?Any address or pointer... Re: Bool - LCD - 08-07-2012 boriel Wrote:You can also implement them as macros using #define as explained above (I've updated ZX Basic operator priorities to reflect FreeBasic's ones, but you can always enforce priorities using parenthesis; this won't affect performance).Great!!! I will check it today. |