-static void
-cpu8051_convert_bit_address(uint8_t bit_address, uint8_t *byte_address,
- uint8_t *bit_number)
-{
- if (bit_address > 0x7F) {
- /* SFR 80-FF */
- *byte_address = bit_address & 0xF8;
- *bit_number = bit_address & 0x07;
- } else {
- /* 20-2F */
- *byte_address = (bit_address >> 3) + 0x20;
- *bit_number = bit_address & 0x07;
- }
-}
-
-/* Write with a direct addressing mode at Address the new Value */
-void
-cpu8051_WriteD(unsigned int address, unsigned char value)
-{
- memory_write8(INT_MEM_ID, address, value);
-}
-
-/* Write with an indirect addressing mode at Address the new Value */
-void
-cpu8051_WriteI(unsigned int address, unsigned char value)
-{
- if (address > 0x7F) {
- memory_write8(EXT_MEM_ID, address, value);
- return;
- }
-
- memory_write8(INT_MEM_ID, address, value);
-}
-
-/* Write with a bit addressing mode at BitAddress the new Value */
-void
-cpu8051_WriteB(uint8_t bit_address, uint8_t value)
-{
- uint8_t byte_address;
- uint8_t bit_number;
- unsigned char byte_val, byte_mask;
-
- cpu8051_convert_bit_address(bit_address, &byte_address, &bit_number);
-
- byte_mask = ((1 << bit_number) ^ 0xFF);
- byte_val = cpu8051_ReadD(byte_address) & byte_mask;
- byte_val += value << bit_number;
- cpu8051_WriteD(byte_address, byte_val);
-}
-
-/* Read with a direct addressing mode at Address */
-unsigned char
-cpu8051_ReadD(unsigned int address)
-{
- if (address > 0xFF)
- return memory_read8(EXT_MEM_ID, address);
- else
- return memory_read8(INT_MEM_ID, address);
-}
-
-/* Read with a indirect addressing mode at Address */
-unsigned char
-cpu8051_ReadI(unsigned int address)
-{
- if (address > 0x7F)
- return memory_read8(EXT_MEM_ID, address);
- else
- return memory_read8(INT_MEM_ID, address);
-}
-
-/* Read with a bit addressing mode at BitAddress */
-unsigned char
-cpu8051_ReadB(uint8_t bit_address)
-{
- uint8_t byte_address;
- uint8_t bit_number;
- unsigned char bit_value;
-
- cpu8051_convert_bit_address(bit_address, &byte_address, &bit_number);
-
- bit_value = (cpu8051_ReadD(byte_address) >> bit_number);
- bit_value &= 1;
- return bit_value;
-}
-