Today you implement SET and RES, the instructions that turn a single bit on or off without disturbing any other bit or flag. Together with yesterday's BIT, they give you full control over individual bits and complete the CB-prefixed instruction table.
Implement SET 1, B and RES 1, B so they change one bit each and touch no flags.
SET b, r turns a single bit on; RES b, r (reset) turns it off. Both
leave every other bit - and every flag - alone. SET 1, B OR-s in 1 << 1;
RES 1, B AND-s out the same mask. Together with yesterday’s BIT, they give you
full read/modify/write control over any individual bit in any register.
These complete the CB table and, with it, the entire instruction set your CPU
needs. Games use SET/RES to toggle hardware feature bits - turning the LCD or
a sound channel on and off - without disturbing the neighboring bits in the same
register. Now that the processor is complete, the rest of the project turns
outward: the cartridge, then the hardware the CPU talks to.
case 0xC8: // SET 1, Bc.B |= 1 << 1case 0x88: // RES 1, Bc.B &^= 1 << 1// neither touches any flag
SET and RES - turn a single bit on or off; no flags affected.