#include "memory.h"
#include "psw.h"
#include "timers.h"
-#include "disasm.h"
+#include "opcodes.h"
#include "options.h"
#include "instructions_8051.h"
{
int rc;
- rc = memory_check_address(PGM_MEM_ID, address, DISPLAY_ERROR_YES);
+ rc = mem_check_address(PGM_MEM_ID, address, DISPLAY_ERROR_YES);
if (!rc)
return; /* Error */
int k;
int rc;
- rc = memory_check_address(PGM_MEM_ID, address, DISPLAY_ERROR_YES);
+ rc = mem_check_address(PGM_MEM_ID, address, DISPLAY_ERROR_YES);
if (!rc)
return; /* Error */
{
int id;
- memory_init();
+ mem_init();
for (id = 0; id < GP_TIMERS_COUNT; id++)
gp_timer_reset(id);
cpu8051.active_priority = -1;
/* Clear IRAM and SFR. */
- memory_clear(INT_MEM_ID);
+ mem_clear(INT_MEM_ID);
- memory_sfr_write8(_P0_, 0xFF);
- memory_sfr_write8(_P1_, 0xFF);
- memory_sfr_write8(_P2_, 0xFF);
- memory_sfr_write8(_P3_, 0xFF);
+ mem_sfr_write8(_P0_, 0xFF);
+ mem_sfr_write8(_P1_, 0xFF);
+ mem_sfr_write8(_P2_, 0xFF);
+ mem_sfr_write8(_P3_, 0xFF);
/* The default value of SP (after system reset) is 07 */
- memory_sfr_write8(_SP_, 0x07);
-}
-
-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;
+ mem_sfr_write8(_SP_, 0x07);
}
static int
cpu8051_interrupt_fire(int interrupt_no, int priority)
{
- if (cpu8051_ReadD(_IP_) & INTERRUPT_MASK(interrupt_no))
+ if (mem_read_direct(_IP_) & INTERRUPT_MASK(interrupt_no))
return priority;
else
return !priority;
static int
cpu8051_interrupt_enabled(int interrupt_no)
{
- return (cpu8051_ReadD(_IE_) & INTERRUPT_MASK(interrupt_no)) ? 1 : 0;
+ return (mem_read_direct(_IE_) & INTERRUPT_MASK(interrupt_no)) ?
+ 1 : 0;
}
static void
{
int i;
- if ((cpu8051_ReadD(_IE_) & 0x80) == 0)
+ if ((mem_read_direct(_IE_) & 0x80) == 0)
return;
for (i = INTERRUPT_PRIORITY_HIGH; i >= INTERRUPT_PRIORITY_LOW; i--) {
/* Interrupt timer 0 */
if (cpu8051_interrupt_enabled(INTERRUPT_1) &&
cpu8051_interrupt_fire(INTERRUPT_1, i) &&
- (cpu8051_ReadD(_TCON_) & 0x20)) {
- cpu8051_WriteD(_TCON_,
- cpu8051_ReadD(_TCON_) & 0xDF);
+ (mem_read_direct(_TCON_) & 0x20)) {
+ mem_write_direct(
+ _TCON_,
+ mem_read_direct(_TCON_) & 0xDF);
cpu8051_process_interrupt(0x0B, i);
return;
}
/* Interrupt timer 1 */
if (cpu8051_interrupt_enabled(INTERRUPT_3) &&
cpu8051_interrupt_fire(INTERRUPT_3, i) &&
- (cpu8051_ReadD(_TCON_) & 0x80)) {
- cpu8051_WriteD(_TCON_,
- cpu8051_ReadD(_TCON_) & 0x7F);
+ (mem_read_direct(_TCON_) & 0x80)) {
+ mem_write_direct(
+ _TCON_,
+ mem_read_direct(_TCON_) & 0x7F);
cpu8051_process_interrupt(0x1B, i);
return;
}
/* Serial Interrupts */
if (cpu8051_interrupt_enabled(INTERRUPT_4) &&
cpu8051_interrupt_fire(INTERRUPT_4, i) &&
- (cpu8051_ReadD(_SCON_) & 0x03)) {
+ (mem_read_direct(_SCON_) & 0x03)) {
cpu8051_process_interrupt(0x23, i);
return;
}
/* Interrupt timer 2 */
if (cpu8051_interrupt_enabled(INTERRUPT_5) &&
cpu8051_interrupt_fire(INTERRUPT_5, i) &&
- (cpu8051_ReadD(_T2CON_) & 0x80)) {
+ (mem_read_direct(_T2CON_) & 0x80)) {
cpu8051_process_interrupt(0x2B, i);
return;
}
int insttiming;
/* Basic address check (may fail later if opcode has operands). */
- rc = memory_check_address(PGM_MEM_ID, cpu8051.pc, DISPLAY_ERROR_NO);
+ rc = mem_check_address(PGM_MEM_ID, cpu8051.pc, DISPLAY_ERROR_NO);
if (!rc) {
log_err("Trying to run past program memory limit");
return false; /* Error */
}
- opcode = memory_read8(PGM_MEM_ID, cpu8051.pc);
+ opcode = mem_read8(PGM_MEM_ID, cpu8051.pc);
cpu8051.pc++;
insttiming = (*opcode_table[opcode])(); /* Function callback. */
uint8_t bit_number;
int len;
- cpu8051_convert_bit_address(bit_address, &byte_address, &bit_number);
+ mem_convert_bit_address(bit_address, &byte_address, &bit_number);
len = cpu8051_sfr_mem_info(byte_address, text);
sprintf(&text[len], ".%X", bit_address);
}
-/* Get instruction size from opcode */
-int
-cpu8051_get_instruction_size(unsigned char opcode)
-{
- return InstSizesTbl[opcode];
-}
-
/* Display instruction mnemonic. */
int
cpu8051_disasm_mnemonic(unsigned char opcode, char *buf)
{
- return sprintf(buf, "%s", InstTextTbl[InstTypesTbl[opcode]]);
+ return sprintf(buf, "%s", opcodes_get_instr_type_str(opcode));
}
/* Disasm instruction arguments starting at address into a text string */
buf[0] = '\0';
- opcode = memory_read8(PGM_MEM_ID, address);
+ opcode = mem_read8(PGM_MEM_ID, address);
args_table_offset = opcode << 2;
address++;
* are inverted
*/
if (opcode == 0x85) {
- cpu8051_sfr_mem_info(memory_read8(PGM_MEM_ID, address + 1),
+ cpu8051_sfr_mem_info(mem_read8(PGM_MEM_ID, address + 1),
str);
len += sprintf(&buf[len], "%s,", str);
- cpu8051_sfr_mem_info(memory_read8(PGM_MEM_ID, address),
+ cpu8051_sfr_mem_info(mem_read8(PGM_MEM_ID, address),
str);
len += sprintf(&buf[len], "%s", str);
address += 2;
return;
}
- for (i = 1; i <= InstArgTbl[args_table_offset]; i++) {
- switch (InstArgTbl[args_table_offset + i]) {
+ for (i = 1; i <= opcodes_get_instr_arg_type_id(args_table_offset);
+ i++) {
+ switch (opcodes_get_instr_arg_type_id(args_table_offset + i)) {
case ADDR11: {
len += sprintf(&buf[len],
"%.4XH", ((opcode << 3) & 0xF00) +
- (memory_read8(PGM_MEM_ID, address)));
+ (mem_read8(PGM_MEM_ID, address)));
address++;
break;
}
case ADDR16: {
len += sprintf(
&buf[len], "%.4XH",
- ((memory_read8(PGM_MEM_ID, address) << 8) +
- memory_read8(PGM_MEM_ID, address + 1)));
+ ((mem_read8(PGM_MEM_ID, address) << 8) +
+ mem_read8(PGM_MEM_ID, address + 1)));
address += 2;
break;
}
case DIRECT: {
- cpu8051_sfr_mem_info(memory_read8(PGM_MEM_ID, address),
+ cpu8051_sfr_mem_info(mem_read8(PGM_MEM_ID, address),
str);
len += sprintf(&buf[len], "%s", str);
address++;
}
case BITADDR: {
cpu8051_int_mem_bit_info(
- (memory_read8(PGM_MEM_ID, address) & 0xF8),
+ (mem_read8(PGM_MEM_ID, address) & 0xF8),
str);
len += sprintf(&buf[len], "%s.%X" , str,
- (memory_read8(PGM_MEM_ID, address) & 7));
+ (mem_read8(PGM_MEM_ID, address) & 7));
address++;
break;
}
address++;
len += sprintf(&buf[len], "%.4XH", (address & 0xFF00) +
(((address & 0xFF) +
- memory_read8(PGM_MEM_ID,
- address - 1)) & 0xFF));
+ mem_read8(PGM_MEM_ID,
+ address - 1)) & 0xFF));
break;
}
case DATAIMM: {
len += sprintf(&buf[len], "#%.2XH",
- memory_read8(PGM_MEM_ID, address));
+ mem_read8(PGM_MEM_ID, address));
address++;
break;
}
case DATA16: {
len += sprintf(&buf[len], "#%.4XH",
- ((memory_read8(PGM_MEM_ID,
- address) << 8) +
- memory_read8(PGM_MEM_ID, address+1)));
+ ((mem_read8(PGM_MEM_ID,
+ address) << 8) +
+ mem_read8(PGM_MEM_ID, address+1)));
address += 2;
break;
}
case CBITADDR: {
- cpu8051_int_mem_bit_info((memory_read8(PGM_MEM_ID,
- address) & 0xF8),
+ cpu8051_int_mem_bit_info((mem_read8(PGM_MEM_ID,
+ address) & 0xF8),
str);
len += sprintf(&buf[len], "/%s.%X", str,
- (memory_read8(PGM_MEM_ID, address) & 7));
+ (mem_read8(PGM_MEM_ID, address) & 7));
address++;
break;
}
default: {
- len += sprintf(
- &buf[len], "%s",
- ArgsTextTbl[InstArgTbl[args_table_offset + i]]);
+ len += sprintf(&buf[len], "%s",
+ opcodes_get_instr_arg_type_str(
+ args_table_offset + i));
}
}
- if (i < InstArgTbl[args_table_offset])
+ if (i < opcodes_get_instr_arg_type_id(args_table_offset))
len += sprintf(&buf[len], ",");
}
}
/* Display address. */
len += sprintf(text, " %.4X ", address);
- opcode = memory_read8(PGM_MEM_ID, address);
- inst_size = InstSizesTbl[opcode];
+ opcode = mem_read8(PGM_MEM_ID, address);
+ inst_size = opcodes_get_instr_size(opcode);
/* Display hex bytes. */
for (i = 0; i < inst_size; i++)
len += sprintf(&text[len], " %.2X",
- memory_read8(PGM_MEM_ID, address + i));
+ mem_read8(PGM_MEM_ID, address + i));
/* Padd remaining area with spaces. */
for (; len < 17;)