I use bit masks, suck it! (Really though, programming on an embedded CPU might be reasonable to do this, depending on the situation, but on a PC, trying to not waste bits wastes time)
Store only bits using word-length ints (32 bits in most modern architectures), and program everything to do math using arrays of 32 int-bits to numbers!
I once had to reverse engineer a database to make an invoice integration. They had an int named flags. It contained all status booleans in the entire system. Took me a while to figure that one out.
Only because 6502 has no BIT immediate – only BIT zero page and BIT absolute. But the contemporary z80 and gameboy cpu too have dedicated bit instructions, e.g. BIT c,6 (set z flag to bit 6 of register c).
I think it’s intended for checking the same bit in multiple bytes. You load the mask instead of the data.
So much 6502 ASM involves turning your brain inside-out… despite being simple, clever, and friendly. Like how you can’t do a strided array sensibly because there’s no address register(s). There is no “next byte.” Naively, you want separate varied data at the same index is separate arrays. Buuut because each read address is absolute, you can do *(&array+1)[n], for free.
What I really miss on NES versus Game Boy is SWAP.
I use bit masks, suck it! (Really though, programming on an embedded CPU might be reasonable to do this, depending on the situation, but on a PC, trying to not waste bits wastes time)
Unlikely. Most of the time on modern hardware, you’re going to be cache-limited, not cycle-limited. Checking one bit in a register is insanely fast.
exactly! it is more costly for your pc cpu to check for a bit inside a byte, than just get the byte itself, because adresses only point to bytes
Store 8 bits in the same byte then 👌
Wrong direction!
Store only bits using word-length ints (32 bits in most modern architectures), and program everything to do math using arrays of 32 int-bits to numbers!
Oh man! That took me down memory lane!
I once had to reverse engineer a database to make an invoice integration. They had an int named flags. It contained all status booleans in the entire system. Took me a while to figure that one out.
We’ve all been there, friend. The bit arrays can’t hurt you now.
Even on 6502, the BIT command is useless 99% of the time, and AND ~which_bit is the right answer.
Interestingly the Intel MCS-51 ISA did have several bit-addressable bytes. Like a weird zero page.
Only because 6502 has no BIT immediate – only BIT zero page and BIT absolute. But the contemporary z80 and gameboy cpu too have dedicated bit instructions, e.g. BIT c,6 (set z flag to bit 6 of register c).
I think it’s intended for checking the same bit in multiple bytes. You load the mask instead of the data.
So much 6502 ASM involves turning your brain inside-out… despite being simple, clever, and friendly. Like how you can’t do a strided array sensibly because there’s no address register(s). There is no “next byte.” Naively, you want separate varied data at the same index is separate arrays. Buuut because each read address is absolute, you can do *(&array+1)[n], for free.
What I really miss on NES versus Game Boy is SWAP.