console_dump_sfr_registers_compact(void)
{
int id;
- unsigned char PSW = memory_read_direct(_PSW_);
+ unsigned char PSW = mem_read_direct(_PSW_);
int bank_sel = (PSW & 0x18);
printf("----------------------------------------------------------------------\n");
printf("| PC | SP | DPTR | ACC | B | PSW: CY AC F0 RS1 RS0 OV - P |\n");
printf("| %.4X | %.2X | %.4X | %.2X | %.2X |", cpu8051.pc,
- memory_read_direct(_SP_), memory_sfr_read_dptr(),
- memory_read_direct(_ACC_), memory_read_direct(_B_));
+ mem_read_direct(_SP_), mem_sfr_read_dptr(),
+ mem_read_direct(_ACC_), mem_read_direct(_B_));
printf(" %d %d %d %d %d %d %d %d |",
(PSW >> 7) & 1, (PSW >> 6) & 1, (PSW >> 5) & 1, (PSW >> 4) & 1,
(PSW >> 3) & 1, (PSW >> 2) & 1, (PSW >> 1) & 1, PSW & 1);
printf("----------------------------------------------------------------------\n");
printf("| TCON | TMOD | IE | IP | R0 | R1 | R2 | R3 | R4 | R5 | R6 | R7 | |\n");
- printf("| %.2X | %.2X | %.2X | %.2X ", memory_read_direct(_TCON_),
- memory_read_direct(_TMOD_), memory_read_direct(_IE_), memory_read_direct(_IP_));
+ printf("| %.2X | %.2X | %.2X | %.2X ", mem_read_direct(_TCON_),
+ mem_read_direct(_TMOD_), mem_read_direct(_IE_), mem_read_direct(_IP_));
printf("| %.2X | %.2X | %.2X | %.2X ",
- memory_read_direct(bank_sel + _R0_),
- memory_read_direct(bank_sel + _R1_),
- memory_read_direct(bank_sel + _R2_),
- memory_read_direct(bank_sel + _R3_));
+ mem_read_direct(bank_sel + _R0_),
+ mem_read_direct(bank_sel + _R1_),
+ mem_read_direct(bank_sel + _R2_),
+ mem_read_direct(bank_sel + _R3_));
printf("| %.2X | %.2X | %.2X | %.2X ",
- memory_read_direct(bank_sel + _R4_),
- memory_read_direct(bank_sel + _R5_),
- memory_read_direct(bank_sel + _R6_),
- memory_read_direct(bank_sel + _R7_));
+ mem_read_direct(bank_sel + _R4_),
+ mem_read_direct(bank_sel + _R5_),
+ mem_read_direct(bank_sel + _R6_),
+ mem_read_direct(bank_sel + _R7_));
printf("| |\n");
printf("----------------------------------------------------------------------\n");
TOK_DE NUMBER NUMBER TOK_ENTER
{
log_debug(" Dump External Data Memory at $%04X, len %d", $2, $3);
- memory_dump($2, $3, EXT_MEM_ID);
+ mem_dump($2, $3, EXT_MEM_ID);
}
|
TOK_DI NUMBER NUMBER TOK_ENTER
{
log_debug(" Dump Internal Data Memory at $%04X, len %d", $2, $3);
- memory_dump($2, $3, INT_MEM_ID);
+ mem_dump($2, $3, INT_MEM_ID);
}
|
TOK_DP NUMBER NUMBER TOK_ENTER
{
log_debug(" Dump Program Memory at $%04X, len %d", $2, $3);
- memory_dump($2, $3, PGM_MEM_ID);
+ mem_dump($2, $3, PGM_MEM_ID);
}
;
TOK_MOD_EXT NUMBER NUMBER TOK_ENTER
{
log_debug(" Modify external memory");
- memory_write8(EXT_MEM_ID, $2, $3);
+ mem_write8(EXT_MEM_ID, $2, $3);
}
|
TOK_MOD_INT NUMBER NUMBER TOK_ENTER
{
log_debug(" Modify internal memory");
- memory_write8(INT_MEM_ID, $2, $3);
+ mem_write8(INT_MEM_ID, $2, $3);
}
|
TOK_MOD_PROG NUMBER NUMBER TOK_ENTER
{
log_debug(" Modify program memory");
- memory_write8(PGM_MEM_ID, $2, $3);
+ mem_write8(PGM_MEM_ID, $2, $3);
}
|
TOK_MOD_REG WORD NUMBER TOK_ENTER
{
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);
+ mem_sfr_write8(_SP_, 0x07);
}
static int
cpu8051_interrupt_fire(int interrupt_no, int priority)
{
- if (memory_read_direct(_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 (memory_read_direct(_IE_) & INTERRUPT_MASK(interrupt_no)) ?
+ return (mem_read_direct(_IE_) & INTERRUPT_MASK(interrupt_no)) ?
1 : 0;
}
{
int i;
- if ((memory_read_direct(_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) &&
- (memory_read_direct(_TCON_) & 0x20)) {
- memory_write_direct(
+ (mem_read_direct(_TCON_) & 0x20)) {
+ mem_write_direct(
_TCON_,
- memory_read_direct(_TCON_) & 0xDF);
+ 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) &&
- (memory_read_direct(_TCON_) & 0x80)) {
- memory_write_direct(
+ (mem_read_direct(_TCON_) & 0x80)) {
+ mem_write_direct(
_TCON_,
- memory_read_direct(_TCON_) & 0x7F);
+ 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) &&
- (memory_read_direct(_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) &&
- (memory_read_direct(_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;
- memory_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);
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;
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;
}
/* Display address. */
len += sprintf(text, " %.4X ", address);
- opcode = memory_read8(PGM_MEM_ID, address);
+ opcode = mem_read8(PGM_MEM_ID, address);
inst_size = 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;)
if (rec_type == 0) {
for (j = 0; j < rec_len; j++) {
data = asciihex2int_len(&line[i], 2);
- memory_write8(PGM_MEM_ID,
- (unsigned int) (load_offset + j),
- (unsigned char) data);
+ mem_write8(PGM_MEM_ID,
+ (unsigned int) (load_offset + j),
+ (unsigned char) data);
i += 2;
checksum += data;
}
/* Init each 8051 memory sections. */
void
-memory_init(void)
+mem_init(void)
{
int k;
struct mem_infos_t *m;
/* Return true if address is valid, false otherwise. */
int
-memory_check_address(enum mem_id_t id, unsigned long address, int display_error)
+mem_check_address(enum mem_id_t id, unsigned long address, int display_error)
{
if (address >= (unsigned long) mem_infos[id].max_size) {
if (display_error == DISPLAY_ERROR_YES)
}
void
-memory_convert_bit_address(uint8_t bit_address, uint8_t *byte_address,
- uint8_t *bit_number)
+mem_convert_bit_address(uint8_t bit_address, uint8_t *byte_address,
+ uint8_t *bit_number)
{
if (bit_address > 0x7F) {
/* SFR 80-FF */
}
u_int8_t *
-memory_getbuf(enum mem_id_t id, unsigned long address)
+mem_getbuf(enum mem_id_t id, unsigned long address)
{
return &mem_infos[id].buf[address];
}
void
-memory_clear(enum mem_id_t id)
+mem_clear(enum mem_id_t id)
{
memset(mem_infos[id].buf, 0, mem_infos[id].size);
}
void
-memory_write8(enum mem_id_t id, unsigned long address, u_int8_t value)
+mem_write8(enum mem_id_t id, unsigned long address, u_int8_t value)
{
if (address >= (unsigned long) mem_infos[id].max_size) {
log_err("Error writing to memory ID: %d\n"
/* Write with a direct addressing mode at Address the new Value */
void
-memory_write_direct(unsigned int address, unsigned char value)
+mem_write_direct(unsigned int address, unsigned char value)
{
- memory_write8(INT_MEM_ID, address, value);
+ mem_write8(INT_MEM_ID, address, value);
}
/* Write with an indirect addressing mode at Address the new Value */
void
-memory_write_indirect(unsigned int address, unsigned char value)
+mem_write_indirect(unsigned int address, unsigned char value)
{
if (address > 0x7F) {
- memory_write8(EXT_MEM_ID, address, value);
+ mem_write8(EXT_MEM_ID, address, value);
return;
}
- memory_write8(INT_MEM_ID, address, value);
+ mem_write8(INT_MEM_ID, address, value);
}
/* Write with a bit addressing mode at BitAddress the new Value */
void
-memory_write_bit(uint8_t bit_address, uint8_t value)
+mem_write_bit(uint8_t bit_address, uint8_t value)
{
uint8_t byte_address;
uint8_t bit_number;
unsigned char byte_val, byte_mask;
- memory_convert_bit_address(bit_address, &byte_address, &bit_number);
+ mem_convert_bit_address(bit_address, &byte_address, &bit_number);
byte_mask = ((1 << bit_number) ^ 0xFF);
- byte_val = memory_read_direct(byte_address) & byte_mask;
+ byte_val = mem_read_direct(byte_address) & byte_mask;
byte_val += value << bit_number;
- memory_write_direct(byte_address, byte_val);
+ mem_write_direct(byte_address, byte_val);
}
void
-memory_sfr_write8(unsigned long address, u_int8_t value)
+mem_sfr_write8(unsigned long address, u_int8_t value)
{
/* SFR registers are from addresses $80 to $FF. */
- memory_write8(INT_MEM_ID, address, value);
+ mem_write8(INT_MEM_ID, address, value);
}
void
-memory_sfr_write_dptr(u_int16_t value)
+mem_sfr_write_dptr(u_int16_t value)
{
- memory_write8(INT_MEM_ID, _DPTRHIGH_, value >> 8);
- memory_write8(INT_MEM_ID, _DPTRLOW_, (uint8_t) value);
+ mem_write8(INT_MEM_ID, _DPTRHIGH_, value >> 8);
+ mem_write8(INT_MEM_ID, _DPTRLOW_, (uint8_t) value);
}
u_int8_t
-memory_read8(enum mem_id_t id, unsigned long address)
+mem_read8(enum mem_id_t id, unsigned long address)
{
if (address >= (unsigned long) mem_infos[id].max_size) {
log_err("Error reading from memory ID: %d\n"
/* Read with a direct addressing mode at Address */
unsigned char
-memory_read_direct(unsigned int address)
+mem_read_direct(unsigned int address)
{
if (address > 0xFF)
- return memory_read8(EXT_MEM_ID, address);
+ return mem_read8(EXT_MEM_ID, address);
else
- return memory_read8(INT_MEM_ID, address);
+ return mem_read8(INT_MEM_ID, address);
}
/* Read with a indirect addressing mode at Address */
unsigned char
-memory_read_indirect(unsigned int address)
+mem_read_indirect(unsigned int address)
{
if (address > 0x7F)
- return memory_read8(EXT_MEM_ID, address);
+ return mem_read8(EXT_MEM_ID, address);
else
- return memory_read8(INT_MEM_ID, address);
+ return mem_read8(INT_MEM_ID, address);
}
/* Read with a bit addressing mode at bit_address */
unsigned char
-memory_read_bit(uint8_t bit_address)
+mem_read_bit(uint8_t bit_address)
{
uint8_t byte_address;
uint8_t bit_number;
unsigned char bit_value;
- memory_convert_bit_address(bit_address, &byte_address, &bit_number);
+ mem_convert_bit_address(bit_address, &byte_address, &bit_number);
- bit_value = (memory_read_direct(byte_address) >> bit_number);
+ bit_value = (mem_read_direct(byte_address) >> bit_number);
bit_value &= 1;
return bit_value;
}
u_int8_t
-memory_sfr_read8(unsigned long address)
+mem_sfr_read8(unsigned long address)
{
/* SFR registers are from addresses $80 to $FF. */
- return memory_read8(INT_MEM_ID, address);
+ return mem_read8(INT_MEM_ID, address);
}
u_int16_t
-memory_sfr_read_dptr(void)
+mem_sfr_read_dptr(void)
{
- return (memory_read8(INT_MEM_ID, _DPTRHIGH_) << 8) +
- memory_read8(INT_MEM_ID, _DPTRLOW_);
+ return (mem_read8(INT_MEM_ID, _DPTRHIGH_) << 8) +
+ mem_read8(INT_MEM_ID, _DPTRLOW_);
}
void
{
uint8_t sp;
- sp = memory_read8(INT_MEM_ID, _SP_);
+ sp = mem_read8(INT_MEM_ID, _SP_);
- memory_write8(INT_MEM_ID, ++sp, value);
- memory_write8(INT_MEM_ID, _SP_, sp); /* Save new stack pointer */
+ mem_write8(INT_MEM_ID, ++sp, value);
+ mem_write8(INT_MEM_ID, _SP_, sp); /* Save new stack pointer */
}
void
{
uint8_t sp;
- sp = memory_read8(INT_MEM_ID, _SP_);
+ sp = mem_read8(INT_MEM_ID, _SP_);
- memory_write8(INT_MEM_ID, ++sp, (uint8_t) value); /* Write LSB */
- memory_write8(INT_MEM_ID, ++sp, value >> 8); /* Write MSB */
- memory_write8(INT_MEM_ID, _SP_, sp); /* Save new stack pointer */
+ mem_write8(INT_MEM_ID, ++sp, (uint8_t) value); /* Write LSB */
+ mem_write8(INT_MEM_ID, ++sp, value >> 8); /* Write MSB */
+ mem_write8(INT_MEM_ID, _SP_, sp); /* Save new stack pointer */
}
uint8_t
uint8_t sp;
uint8_t value;
- sp = memory_read8(INT_MEM_ID, _SP_);
+ sp = mem_read8(INT_MEM_ID, _SP_);
- value = memory_read8(INT_MEM_ID, sp--);
- memory_write8(INT_MEM_ID, _SP_, sp); /* Save new stack pointer */
+ value = mem_read8(INT_MEM_ID, sp--);
+ mem_write8(INT_MEM_ID, _SP_, sp); /* Save new stack pointer */
return value;
}
uint8_t sp;
uint16_t value;
- sp = memory_read8(INT_MEM_ID, _SP_);
+ sp = mem_read8(INT_MEM_ID, _SP_);
- value = memory_read8(INT_MEM_ID, sp--) << 8; /* Read MSB */
- value |= memory_read8(INT_MEM_ID, sp--); /* Read LSB */
- memory_write8(INT_MEM_ID, _SP_, sp); /* Save new stack pointer */
+ value = mem_read8(INT_MEM_ID, sp--) << 8; /* Read MSB */
+ value |= mem_read8(INT_MEM_ID, sp--); /* Read LSB */
+ mem_write8(INT_MEM_ID, _SP_, sp); /* Save new stack pointer */
return value;
}
{
uint16_t addr;
- addr = memory_read8(PGM_MEM_ID, base) << 8; /* MSB */
- addr |= memory_read8(PGM_MEM_ID, base + 1); /* LSB */
+ addr = mem_read8(PGM_MEM_ID, base) << 8; /* MSB */
+ addr |= mem_read8(PGM_MEM_ID, base + 1); /* LSB */
return addr;
}
/* Dump memory */
void
-memory_dump(unsigned int address, int size, int memory_id)
+mem_dump(unsigned int address, int size, enum mem_id_t id)
{
int rc;
int offset, col;
}
/* Validate start address. */
- rc = memory_check_address(memory_id, address, DISPLAY_ERROR_YES);
+ rc = mem_check_address(id, address, DISPLAY_ERROR_YES);
if (!rc) {
/* Validate end address. */
- rc = memory_check_address(memory_id, address + (size - 1),
- DISPLAY_ERROR_NO);
+ rc = mem_check_address(id, address + (size - 1),
+ DISPLAY_ERROR_NO);
if (!rc)
log_err("Trying to read beyond memory limit");
}
printf("%.4X ", address + offset);
for (col = 0; col < 16; col++) {
- data[col] = memory_read8(memory_id, address +
- offset + col);
+ data[col] = mem_read8(id, address + offset + col);
printf(" %.2X", (int) data[col]);
}
printf(" ");
#define DISPLAY_ERROR_YES 1
void
-memory_init(void);
+mem_init(void);
int
-memory_check_address(enum mem_id_t id, unsigned long address,
- int display_error);
+mem_check_address(enum mem_id_t id, unsigned long address, int display_error);
void
-memory_convert_bit_address(uint8_t bit_address, uint8_t *byte_address,
- uint8_t *bit_number);
+mem_convert_bit_address(uint8_t bit_address, uint8_t *byte_address,
+ uint8_t *bit_number);
u_int8_t *
-memory_getbuf(enum mem_id_t id, unsigned long address);
+mem_getbuf(enum mem_id_t id, unsigned long address);
void
-memory_clear(enum mem_id_t id);
+mem_clear(enum mem_id_t id);
void
-memory_write8(enum mem_id_t id, unsigned long address, u_int8_t value);
+mem_write8(enum mem_id_t id, unsigned long address, u_int8_t value);
void
-memory_write_direct(unsigned int address, unsigned char value);
+mem_write_direct(unsigned int address, unsigned char value);
void
-memory_write_indirect(unsigned int address, unsigned char value);
+mem_write_indirect(unsigned int address, unsigned char value);
void
-memory_write_bit(uint8_t bit_address, uint8_t value);
+mem_write_bit(uint8_t bit_address, uint8_t value);
void
-memory_sfr_write8(unsigned long address, u_int8_t value);
+mem_sfr_write8(unsigned long address, u_int8_t value);
void
-memory_sfr_write_dptr(u_int16_t value);
+mem_sfr_write_dptr(u_int16_t value);
u_int8_t
-memory_read8(enum mem_id_t id, unsigned long address);
+mem_read8(enum mem_id_t id, unsigned long address);
unsigned char
-memory_read_direct(unsigned int address);
+mem_read_direct(unsigned int address);
unsigned char
-memory_read_indirect(unsigned int address);
+mem_read_indirect(unsigned int address);
unsigned char
-memory_read_bit(uint8_t bit_address);
+mem_read_bit(uint8_t bit_address);
u_int8_t
-memory_sfr_read8(unsigned long address);
+mem_sfr_read8(unsigned long address);
u_int16_t
-memory_sfr_read_dptr(void);
+mem_sfr_read_dptr(void);
void
stack_push8(uint8_t value);
pgm_read_addr16(uint16_t base);
void
-memory_dump(unsigned int address, int size, int memory_id);
+mem_dump(unsigned int address, int size, enum mem_id_t id);
#endif /* MEMORY_H */
if( $i == 0x85 ) {
# Cas particulier pour MOV direct,direct -> src et dest sont inverses dans la memoire
- print INST_IMP " unsigned char srcaddr = memory_read8( PGM_MEM_ID, cpu8051.pc++ );\n";
- print INST_IMP " unsigned char source = memory_read_direct( srcaddr );\n";
- print INST_IMP " unsigned char destaddr = memory_read8( PGM_MEM_ID, cpu8051.pc++ );\n";
- print INST_IMP " unsigned char destination = memory_read_direct( destaddr );\n";
+ print INST_IMP " unsigned char srcaddr = mem_read8( PGM_MEM_ID, cpu8051.pc++ );\n";
+ print INST_IMP " unsigned char source = mem_read_direct( srcaddr );\n";
+ print INST_IMP " unsigned char destaddr = mem_read8( PGM_MEM_ID, cpu8051.pc++ );\n";
+ print INST_IMP " unsigned char destination = mem_read_direct( destaddr );\n";
print INST_IMP " destination = source;\n";
- print INST_IMP " memory_write_direct( destaddr, destination );\n";
+ print INST_IMP " mem_write_direct( destaddr, destination );\n";
}
else {
if ($instargs[$i*4] > 0) {
$op_destination=$instargs[$i*4+1];
if ($op_destination == 0) { # addr11
- cfw("unsigned int addr11 = ( ( memory_read8( PGM_MEM_ID, cpu8051.pc - 1 ) << 3 ) & 0xF00 ) + memory_read8( PGM_MEM_ID, cpu8051.pc );");
+ cfw("unsigned int addr11 = ( ( mem_read8( PGM_MEM_ID, cpu8051.pc - 1 ) << 3 ) & 0xF00 ) + mem_read8( PGM_MEM_ID, cpu8051.pc );");
cfw("cpu8051.pc++;");
}
if ($op_destination == 1) { # addr16
cfw("cpu8051.pc += 2;");
}
if ($op_destination == 2) { # A
- cfw("unsigned char destination = memory_read_direct( _ACC_ );");
+ cfw("unsigned char destination = mem_read_direct( _ACC_ );");
}
if ($op_destination == 3) { # direct
- cfw("unsigned char destaddr = memory_read8( PGM_MEM_ID, cpu8051.pc++ );");
- cfw("unsigned char destination = memory_read_direct( destaddr );");
+ cfw("unsigned char destaddr = mem_read8( PGM_MEM_ID, cpu8051.pc++ );");
+ cfw("unsigned char destination = mem_read_direct( destaddr );");
}
if ($op_destination == 4) { # @R0
- cfw("unsigned char destination = memory_read_indirect ( memory_read_direct( BANKPSW + _R0_ ) );");
+ cfw("unsigned char destination = mem_read_indirect ( mem_read_direct( BANKPSW + _R0_ ) );");
}
if ($op_destination == 5) { # @R1
- cfw("unsigned char destination = memory_read_indirect ( memory_read_direct( BANKPSW + _R1_ ) );");
+ cfw("unsigned char destination = mem_read_indirect ( mem_read_direct( BANKPSW + _R1_ ) );");
}
if ($op_destination == 6) { # R0
- cfw("unsigned char destination = memory_read_direct( BANKPSW + _R0_ );");
+ cfw("unsigned char destination = mem_read_direct( BANKPSW + _R0_ );");
}
if ($op_destination == 7) { # R1
- cfw("unsigned char destination = memory_read_direct( BANKPSW + _R1_ );");
+ cfw("unsigned char destination = mem_read_direct( BANKPSW + _R1_ );");
}
if ($op_destination == 8) { # R2
- cfw("unsigned char destination = memory_read_direct( BANKPSW + _R2_ );");
+ cfw("unsigned char destination = mem_read_direct( BANKPSW + _R2_ );");
}
if ($op_destination == 9) { # R3
- cfw("unsigned char destination = memory_read_direct( BANKPSW + _R3_ );");
+ cfw("unsigned char destination = mem_read_direct( BANKPSW + _R3_ );");
}
if ($op_destination == 10) { # R4
- cfw("unsigned char destination = memory_read_direct( BANKPSW + _R4_ );");
+ cfw("unsigned char destination = mem_read_direct( BANKPSW + _R4_ );");
}
if ($op_destination == 11) { # R5
- cfw("unsigned char destination = memory_read_direct( BANKPSW + _R5_ );");
+ cfw("unsigned char destination = mem_read_direct( BANKPSW + _R5_ );");
}
if ($op_destination == 12) { # R6
- cfw("unsigned char destination = memory_read_direct( BANKPSW + _R6_ );");
+ cfw("unsigned char destination = mem_read_direct( BANKPSW + _R6_ );");
}
if ($op_destination == 13) { # R7
- cfw("unsigned char destination = memory_read_direct( BANKPSW + _R7_ );");
+ cfw("unsigned char destination = mem_read_direct( BANKPSW + _R7_ );");
}
if ($op_destination == 14) { # bitaddr
- cfw("unsigned char destination, dstbitaddr = memory_read8( PGM_MEM_ID, cpu8051.pc++ );");
- cfw("destination = memory_read_bit( dstbitaddr );");
+ cfw("unsigned char destination, dstbitaddr = mem_read8( PGM_MEM_ID, cpu8051.pc++ );");
+ cfw("destination = mem_read_bit( dstbitaddr );");
}
if ($op_destination == 15) { # reladdr
cfw("cpu8051.pc++;");
- cfw("unsigned int destination = ((char) memory_read8(PGM_MEM_ID, cpu8051.pc - 1)) + cpu8051.pc;");
+ cfw("unsigned int destination = ((char) mem_read8(PGM_MEM_ID, cpu8051.pc - 1)) + cpu8051.pc;");
}
if ($op_destination == 16) { # #data
- cfw("unsigned char destination = memory_read8( PGM_MEM_ID, cpu8051.pc++ );");
+ cfw("unsigned char destination = mem_read8( PGM_MEM_ID, cpu8051.pc++ );");
}
if ($op_destination == 17) { # C
cfw("unsigned char destination = psw_read_cy();");
}
if ($op_destination == 18) { # @A+DPTR
- cfw("unsigned int destination = memory_read_direct( _ACC_ ) + memory_sfr_read_dptr();");
+ cfw("unsigned int destination = mem_read_direct( _ACC_ ) + mem_sfr_read_dptr();");
}
if ($op_destination == 20) { # AB
- cfw("unsigned char destination = memory_read_direct( _ACC_ );");
- cfw("unsigned char source = memory_read_direct( _B_ );");
+ cfw("unsigned char destination = mem_read_direct( _ACC_ );");
+ cfw("unsigned char source = mem_read_direct( _B_ );");
}
if ($op_destination == 21) { # DPTR
- cfw("unsigned int destination = memory_sfr_read_dptr();");
+ cfw("unsigned int destination = mem_sfr_read_dptr();");
}
if ($op_destination == 23) { # /bitaddr
- cfw("unsigned char destination, dstbitaddr = memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );");
- cfw("destination = ( memory_read_bit( dstbitaddr ) ^ 1 );");
+ cfw("unsigned char destination, dstbitaddr = mem_read8( PGM_MEM_ID, (cpu8051.pc)++ );");
+ cfw("destination = ( mem_read_bit( dstbitaddr ) ^ 1 );");
}
if ($op_destination == 24) { # @DPTR
- cfw("unsigned char destination = memory_read_indirect(memory_sfr_read_dptr());");
+ cfw("unsigned char destination = mem_read_indirect(mem_sfr_read_dptr());");
}
}
if ($instargs[$i*4] > 1) {
$op_source=$instargs[$i*4+2];
if ($op_source == 0) { # addr11
- cfw("unsigned int addr11 = ( ( memory_read8( PGM_MEM_ID, cpu8051.pc - 1 ) << 3 ) & 0xF00 ) + memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );");
+ cfw("unsigned int addr11 = ( ( mem_read8( PGM_MEM_ID, cpu8051.pc - 1 ) << 3 ) & 0xF00 ) + mem_read8( PGM_MEM_ID, (cpu8051.pc)++ );");
}
if ($op_source == 1) { # addr16
cfw("uint16_t addr16 = pgm_read_addr16(cpu8051.pc);");
cfw("cpu8051.pc += 2;");
}
if ($op_source == 2) { # A
- cfw("unsigned char source = memory_read_direct( _ACC_ );");
+ cfw("unsigned char source = mem_read_direct( _ACC_ );");
}
if ($op_source == 3) { # direct
- cfw("unsigned char srcaddr = memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );");
- cfw("unsigned char source = memory_read_direct( srcaddr );");
+ cfw("unsigned char srcaddr = mem_read8( PGM_MEM_ID, (cpu8051.pc)++ );");
+ cfw("unsigned char source = mem_read_direct( srcaddr );");
}
if ($op_source == 4) { # @R0
- cfw("unsigned char source = memory_read_indirect ( memory_read_direct( BANKPSW + _R0_ ) );");
+ cfw("unsigned char source = mem_read_indirect ( mem_read_direct( BANKPSW + _R0_ ) );");
}
if ($op_source == 5) { # @R1
- cfw("unsigned char source = memory_read_indirect ( memory_read_direct( BANKPSW + _R1_ ) );");
+ cfw("unsigned char source = mem_read_indirect ( mem_read_direct( BANKPSW + _R1_ ) );");
}
if ($op_source == 6) { # R0
- cfw("unsigned char source = memory_read_direct( BANKPSW + _R0_ );");
+ cfw("unsigned char source = mem_read_direct( BANKPSW + _R0_ );");
}
if ($op_source == 7) { # R1
- cfw("unsigned char source = memory_read_direct( BANKPSW + _R1_ );");
+ cfw("unsigned char source = mem_read_direct( BANKPSW + _R1_ );");
}
if ($op_source == 8) { # R2
- cfw("unsigned char source = memory_read_direct( BANKPSW + _R2_ );");
+ cfw("unsigned char source = mem_read_direct( BANKPSW + _R2_ );");
}
if ($op_source == 9) { # R3
- cfw("unsigned char source = memory_read_direct( BANKPSW + _R3_ );");
+ cfw("unsigned char source = mem_read_direct( BANKPSW + _R3_ );");
}
if ($op_source == 10) { # R4
- cfw("unsigned char source = memory_read_direct( BANKPSW + _R4_ );");
+ cfw("unsigned char source = mem_read_direct( BANKPSW + _R4_ );");
}
if ($op_source == 11) { # R5
- cfw("unsigned char source = memory_read_direct( BANKPSW + _R5_ );");
+ cfw("unsigned char source = mem_read_direct( BANKPSW + _R5_ );");
}
if ($op_source == 12) { # R6
- cfw("unsigned char source = memory_read_direct( BANKPSW + _R6_ );");
+ cfw("unsigned char source = mem_read_direct( BANKPSW + _R6_ );");
}
if ($op_source == 13) { # R7
- cfw("unsigned char source = memory_read_direct( BANKPSW + _R7_ );");
+ cfw("unsigned char source = mem_read_direct( BANKPSW + _R7_ );");
}
if ($op_source == 14) { # bitaddr
- cfw("unsigned char source, srcbitaddr = memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );");
- cfw("source = memory_read_bit( srcbitaddr );");
+ cfw("unsigned char source, srcbitaddr = mem_read8( PGM_MEM_ID, (cpu8051.pc)++ );");
+ cfw("source = mem_read_bit( srcbitaddr );");
}
if ($op_source == 15) { # reladdr
cfw("(cpu8051.pc)++;");
- cfw("unsigned int source = ((char) memory_read8(PGM_MEM_ID, cpu8051.pc - 1)) + cpu8051.pc;");
+ cfw("unsigned int source = ((char) mem_read8(PGM_MEM_ID, cpu8051.pc - 1)) + cpu8051.pc;");
}
if ($op_source == 16) { # #data
- cfw("unsigned char source = memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );");
+ cfw("unsigned char source = mem_read8( PGM_MEM_ID, (cpu8051.pc)++ );");
}
if ($op_source == 17) { # C
cfw("unsigned char source = psw_read_cy();");
}
if ($op_source == 18) { # @A+DPTR
- cfw("unsigned char source = memory_read8( PGM_MEM_ID, memory_read_direct( _ACC_ ) + memory_sfr_read_dptr());");
+ cfw("unsigned char source = mem_read8( PGM_MEM_ID, mem_read_direct( _ACC_ ) + mem_sfr_read_dptr());");
}
if ($op_source == 19) { # @A+PC
- cfw("unsigned char source = memory_read8( PGM_MEM_ID, memory_read_direct( _ACC_ ) + ( ++cpu8051.pc ) );");
+ cfw("unsigned char source = mem_read8( PGM_MEM_ID, mem_read_direct( _ACC_ ) + ( ++cpu8051.pc ) );");
}
if ($op_source == 21) { # DPTR
- cfw("unsigned int source = memory_sfr_read_dptr();");
+ cfw("unsigned int source = mem_sfr_read_dptr();");
}
if ($op_source == 22) { # #data16
cfw("uint16_t source = pgm_read_addr16(cpu8051.pc);");
cfw("cpu8051.pc += 2;");
}
if ($op_source == 23) { # /bitaddr
- cfw("unsigned char source, srcbitaddr = memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );");
- cfw("source = ( memory_read_bit( srcbitaddr ) ^ 1 );");
+ cfw("unsigned char source, srcbitaddr = mem_read8( PGM_MEM_ID, (cpu8051.pc)++ );");
+ cfw("source = ( mem_read_bit( srcbitaddr ) ^ 1 );");
}
if ($op_source == 24) { # @DPTR
- cfw("unsigned char source = memory_read_indirect(memory_sfr_read_dptr());");
+ cfw("unsigned char source = mem_read_indirect(mem_sfr_read_dptr());");
}
}
# JZ
if ($insttype[$i] == 22) {
- cfw("if ( memory_read_direct( _ACC_ ) == 0 ) { cpu8051.pc = destination; }");
+ cfw("if ( mem_read_direct( _ACC_ ) == 0 ) { cpu8051.pc = destination; }");
}
# XRL
# JNZ
if ($insttype[$i] == 24) {
- cfw("if ( memory_read_direct( _ACC_ ) != 0 ) { cpu8051.pc = destination; }");
+ cfw("if ( mem_read_direct( _ACC_ ) != 0 ) { cpu8051.pc = destination; }");
}
# JMP
# If B is zero, the OV flag will be set indicating a
# division-by-zero error
cfw("if (source != 0) {");
- cfw(" memory_write_direct(_ACC_, destination/source);");
- cfw(" memory_write_direct( _B_, destination%source);");
+ cfw(" mem_write_direct(_ACC_, destination/source);");
+ cfw(" mem_write_direct( _B_, destination%source);");
cfw(" psw_clr_ov();");
cfw("} else {");
cfw(" psw_set_ov();");
# A = destination
# B = source
cfw("psw_clr_cy();");
- cfw("memory_write_direct(_ACC_, destination * source);");
- cfw("memory_write_direct(_B_, (destination * source) / 0x100);");
- cfw("if (memory_read_direct(_B_) > 0)");
+ cfw("mem_write_direct(_ACC_, destination * source);");
+ cfw("mem_write_direct(_B_, (destination * source) / 0x100);");
+ cfw("if (mem_read_direct(_B_) > 0)");
cfw(" psw_set_ov();");
cfw("else");
cfw(" psw_clr_ov();");
# CJNE
if ($insttype[$i] == 34) {
- cfw("unsigned int reladdr = ((char) memory_read8(PGM_MEM_ID, cpu8051.pc)) + (cpu8051.pc + 1);");
+ cfw("unsigned int reladdr = ((char) mem_read8(PGM_MEM_ID, cpu8051.pc)) + (cpu8051.pc + 1);");
cfw("psw_clr_cy();");
cfw("if ( destination < source ) psw_set_cy();");
cfw("if ( destination != source ) cpu8051.pc = reladdr; else cpu8051.pc++;");
cfw("cpu8051.pc = addr16;");
}
if ($op_destination == 2) { # A
- cfw("memory_write_direct( _ACC_, destination );");
+ cfw("mem_write_direct( _ACC_, destination );");
}
if ($op_destination == 3) { # direct
- cfw("memory_write_direct( destaddr, destination );");
+ cfw("mem_write_direct( destaddr, destination );");
}
if ($op_destination == 4) { # @R0
- cfw("memory_write_indirect( memory_read_direct( BANKPSW + _R0_ ), destination );");
+ cfw("mem_write_indirect( mem_read_direct( BANKPSW + _R0_ ), destination );");
}
if ($op_destination == 5) { # @R1
- cfw("memory_write_indirect( memory_read_direct( BANKPSW + _R1_ ), destination );");
+ cfw("mem_write_indirect( mem_read_direct( BANKPSW + _R1_ ), destination );");
}
if ($op_destination == 6) { # R0
- cfw("memory_write_direct( BANKPSW + _R0_, destination );");
+ cfw("mem_write_direct( BANKPSW + _R0_, destination );");
}
if ($op_destination == 7) { # R1
- cfw("memory_write_direct( BANKPSW + _R1_, destination );");
+ cfw("mem_write_direct( BANKPSW + _R1_, destination );");
}
if ($op_destination == 8) { # R2
- cfw("memory_write_direct( BANKPSW + _R2_, destination );");
+ cfw("mem_write_direct( BANKPSW + _R2_, destination );");
}
if ($op_destination == 9) { # R3
- cfw("memory_write_direct( BANKPSW + _R3_, destination );");
+ cfw("mem_write_direct( BANKPSW + _R3_, destination );");
}
if ($op_destination == 10) { # R4
- cfw("memory_write_direct( BANKPSW + _R4_, destination );");
+ cfw("mem_write_direct( BANKPSW + _R4_, destination );");
}
if ($op_destination == 11) { # R5
- cfw("memory_write_direct( BANKPSW + _R5_, destination );");
+ cfw("mem_write_direct( BANKPSW + _R5_, destination );");
}
if ($op_destination == 12) { # R6
- cfw("memory_write_direct( BANKPSW + _R6_, destination );");
+ cfw("mem_write_direct( BANKPSW + _R6_, destination );");
}
if ($op_destination == 13) { # R7
- cfw("memory_write_direct( BANKPSW + _R7_, destination );");
+ cfw("mem_write_direct( BANKPSW + _R7_, destination );");
}
if ($op_destination == 14) { # bitaddr
- cfw("memory_write_bit( dstbitaddr, destination );");
+ cfw("mem_write_bit( dstbitaddr, destination );");
}
if ($op_destination == 17) { # C
cfw("psw_write_cy(destination);");
}
if ($op_destination == 21) { # DPTR
- cfw("memory_sfr_write_dptr(destination);");
+ cfw("mem_sfr_write_dptr(destination);");
}
if ($op_destination == 23) { # /bitaddr
- cfw("memory_write_bit( dstbitaddr, destination );");
+ cfw("mem_write_bit( dstbitaddr, destination );");
}
if ($op_destination == 24) { # @DPTR
- cfw("memory_write_indirect(memory_sfr_read_dptr(), destination);");
+ cfw("mem_write_indirect(mem_sfr_read_dptr(), destination);");
}
}
cfw("cpu8051.pc = addr16;");
}
if ($op_source == 2) { # A
- cfw("memory_write_direct( _ACC_, source );");
+ cfw("mem_write_direct( _ACC_, source );");
}
if ($op_source == 3) { # direct
- cfw("memory_write_direct( srcaddr, source );");
+ cfw("mem_write_direct( srcaddr, source );");
}
if ($op_source == 4) { # @R0
- cfw("memory_write_indirect( memory_read_direct( BANKPSW + _R0_ ), source );");
+ cfw("mem_write_indirect( mem_read_direct( BANKPSW + _R0_ ), source );");
}
if ($op_source == 5) { # @R1
- cfw("memory_write_indirect( memory_read_direct( BANKPSW + _R1_ ), source );");
+ cfw("mem_write_indirect( mem_read_direct( BANKPSW + _R1_ ), source );");
}
if ($op_source == 6) { # R0
- cfw("memory_write_direct( BANKPSW + _R0_, source );");
+ cfw("mem_write_direct( BANKPSW + _R0_, source );");
}
if ($op_source == 7) { # R1
- cfw("memory_write_direct( BANKPSW + _R1_, source );");
+ cfw("mem_write_direct( BANKPSW + _R1_, source );");
}
if ($op_source == 8) { # R2
- cfw("memory_write_direct( BANKPSW + _R2_, source );");
+ cfw("mem_write_direct( BANKPSW + _R2_, source );");
}
if ($op_source == 9) { # R3
- cfw("memory_write_direct( BANKPSW + _R3_, source );");
+ cfw("mem_write_direct( BANKPSW + _R3_, source );");
}
if ($op_source == 10) { # R4
- cfw("memory_write_direct( BANKPSW + _R4_, source );");
+ cfw("mem_write_direct( BANKPSW + _R4_, source );");
}
if ($op_source == 11) { # R5
- cfw("memory_write_direct( BANKPSW + _R5_, source );");
+ cfw("mem_write_direct( BANKPSW + _R5_, source );");
}
if ($op_source == 12) { # R6
- cfw("memory_write_direct( BANKPSW + _R6_, source );");
+ cfw("mem_write_direct( BANKPSW + _R6_, source );");
}
if ($op_source == 13) { # R7
- cfw("memory_write_direct( BANKPSW + _R7_, source );");
+ cfw("mem_write_direct( BANKPSW + _R7_, source );");
}
if ($op_source == 14) { # bitaddr
- cfw("memory_write_bit( srcbitaddr, source );");
+ cfw("mem_write_bit( srcbitaddr, source );");
}
if ($op_source == 17) { # C
cfw("psw_write_cy(source);");
}
if ($op_source == 21) { # DPTR
- cfw("memory_sfr_write_dptr(source);");
+ cfw("mem_sfr_write_dptr(source);");
}
if ($op_source == 23) { # /bitaddr
- cfw("memory_write_bit( srcbitaddr, source );");
+ cfw("mem_write_bit( srcbitaddr, source );");
}
if ($op_source == 24) { # @DPTR
- cfw("memory_write_indirect(memory_sfr_read_dptr(), source);");
+ cfw("mem_write_indirect(mem_sfr_read_dptr(), source);");
}
}
}
write_header(INST_DEF);
print INST_DEF "#ifndef INSTRUCTIONS_8051_H\n";
print INST_DEF "#define INSTRUCTIONS_8051_H 1\n\n\n";
-print INST_DEF "#define BANKPSW (memory_read_direct(_PSW_) & 0x18)\n\n";
+print INST_DEF "#define BANKPSW (mem_read_direct(_PSW_) & 0x18)\n\n";
print INST_DEF "typedef int (*OPCODE_FP)(void);\n\n\n";
for( $i=0; $i<256; $i++ ) {
print INST_DEF "int\n";
int
psw_read_bit(int bit)
{
- return (memory_read8(INT_MEM_ID, _PSW_) >> bit) & 0x01;
+ return (mem_read8(INT_MEM_ID, _PSW_) >> bit) & 0x01;
}
void
psw_write_bit(int bit, int val)
{
- u_int8_t psw = memory_read8(INT_MEM_ID, _PSW_);
+ u_int8_t psw = mem_read8(INT_MEM_ID, _PSW_);
if (val)
psw |= (1 << bit); /* Set */
else
psw &= ~(1 << bit); /* Clear */
- memory_write8(INT_MEM_ID, _PSW_, psw); /* Save updated value */
+ mem_write8(INT_MEM_ID, _PSW_, psw); /* Save updated value */
}
/* Returns 0 or 1 */
psw_compute_parity_bit(void)
{
int parity = 0;
- uint8_t acc = memory_read8(INT_MEM_ID, _ACC_);
+ uint8_t acc = mem_read8(INT_MEM_ID, _ACC_);
while (acc) {
parity = !parity;
static unsigned int
regwin_read_timer(int timer_low_addr)
{
- return (memory_sfr_read8(timer_low_addr + 2) << 8) |
- memory_sfr_read8(timer_low_addr);
+ return (mem_sfr_read8(timer_low_addr + 2) << 8) |
+ mem_sfr_read8(timer_low_addr);
}
static void
regwin_write_timer(int timer_low_addr, int val)
{
- memory_sfr_write8(timer_low_addr + 2,
- (u_int8_t) ((val & 0x0000FFFF) >> 8));
- memory_sfr_write8(timer_low_addr, (u_int8_t) val);
+ mem_sfr_write8(timer_low_addr + 2,
+ (u_int8_t) ((val & 0x0000FFFF) >> 8));
+ mem_sfr_write8(timer_low_addr, (u_int8_t) val);
}
static u_int8_t
regwin_read_bank_offset(void)
{
- return memory_sfr_read8(_PSW_) & 0x18;
+ return mem_sfr_read8(_PSW_) & 0x18;
}
static unsigned int
static void
regwin_write_bank(int param, int bank_number)
{
- u_int8_t psw = memory_sfr_read8(_PSW_);
+ u_int8_t psw = mem_sfr_read8(_PSW_);
(void) param; /* Remove compiler warning about unused variable. */
bank_number = 0;
}
- memory_sfr_write8(_PSW_, (psw & ~0x18) | (bank_number << 3));
+ mem_sfr_write8(_PSW_, (psw & ~0x18) | (bank_number << 3));
}
/* Indirect read of R0 - R7 in current bank from internal memory. */
static unsigned int
regwin_read_rx(int offset)
{
- return memory_read8(INT_MEM_ID, regwin_read_bank_offset() + offset);
+ return mem_read8(INT_MEM_ID, regwin_read_bank_offset() + offset);
}
/* Indirect write to R0 - R7 in current bank to internal memory. */
static void
regwin_write_rx(int offset, int val)
{
- memory_write8(INT_MEM_ID, regwin_read_bank_offset() + offset,
- (u_int8_t) val);
+ mem_write8(INT_MEM_ID, regwin_read_bank_offset() + offset,
+ (u_int8_t) val);
}
/* This array defines how to read value for each register. */
regwin_read_generic(int addr, int width)
{
if (width == 2) {
- return memory_sfr_read8(addr);
+ return mem_sfr_read8(addr);
} else if (width == 4) {
/* Address is low address. */
- return (memory_sfr_read8(addr + 1) << 8) |
- memory_sfr_read8(addr);
+ return (mem_sfr_read8(addr + 1) << 8) |
+ mem_sfr_read8(addr);
} else {
return 0xFFFFFFFF;
}
regwin_write_generic(int addr, int val, int width)
{
if (width == 2) {
- memory_sfr_write8(addr, (u_int8_t) val);
+ mem_sfr_write8(addr, (u_int8_t) val);
} else if (width == 4) {
/* Address is low address. */
- memory_sfr_write8(addr + 1,
- (u_int8_t) ((val & 0x0000FFFF) >> 8));
- memory_sfr_write8(addr, (u_int8_t) val);
+ mem_sfr_write8(addr + 1, (u_int8_t) ((val & 0x0000FFFF) >> 8));
+ mem_sfr_write8(addr, (u_int8_t) val);
}
}
{
unsigned int tmp;
- tmp = memory_read_direct(counter_address);
+ tmp = mem_read_direct(counter_address);
tmp++;
tmp &= 0xFF;
if (tmp == 0) {
/* If overflow set TFx */
- memory_write_direct(_TCON_,
- memory_read_direct(_TCON_) | tf_mask);
+ mem_write_direct(_TCON_,
+ mem_read_direct(_TCON_) | tf_mask);
}
- memory_write_direct(counter_address, tmp); /* Save new value. */
+ mem_write_direct(counter_address, tmp); /* Save new value. */
}
static void
{
unsigned int prescaler;
- prescaler = memory_read_direct(tl);
+ prescaler = mem_read_direct(tl);
prescaler++;
prescaler &= (1 << prescaler_width) - 1; /* Keep only required bits */
- memory_write_direct(tl, prescaler);
+ mem_write_direct(tl, prescaler);
if (prescaler == 0)
timer_increment_check_overflow(th, tf_mask);
break;
case 2:
/* Mode 2, 8-bits counter with Auto-Reload */
- tmp = memory_read_direct(tl);
+ tmp = mem_read_direct(tl);
tmp++;
tmp &= 0xFF;
if (tmp == 0) {
/* If overflow -> reload and set TF0 */
- memory_write_direct(
+ mem_write_direct(
_TCON_,
- memory_read_direct(_TCON_) | tf_mask);
- memory_write_direct(tl, memory_read_direct(th));
+ mem_read_direct(_TCON_) | tf_mask);
+ mem_write_direct(tl, mem_read_direct(th));
} else {
- memory_write_direct(tl, tmp);
+ mem_write_direct(tl, tmp);
}
break;
case 3:
timer_increment_check_overflow(tl, tf_mask);
/* TH0 uses TR1 et TF1. */
- TR = memory_read_direct(_TCON_) & 0x40;
+ TR = mem_read_direct(_TCON_) & 0x40;
if (TR)
timer_increment_check_overflow(th, 0x80);
unsigned int timer_counter;
/* Timer 0 */
- tr = memory_read_direct(_TCON_) & 0x10;
- mode = memory_read_direct(_TMOD_) & 0x03;
- gate = memory_read_direct(_TMOD_) & 0x08;
- timer_counter = memory_read_direct(_TMOD_) & 0x04;
+ tr = mem_read_direct(_TCON_) & 0x10;
+ mode = mem_read_direct(_TMOD_) & 0x03;
+ gate = mem_read_direct(_TMOD_) & 0x08;
+ timer_counter = mem_read_direct(_TMOD_) & 0x04;
if ((tr && !gate && !timer_counter) || (mode == 3))
process_timer(_TL0_, _TH0_, 0x20, tr, mode, gate,
timer_counter);
/* Timer 1 */
- tr = memory_read_direct(_TCON_) & 0x40;
- mode = (memory_read_direct(_TMOD_) & 0x30) >> 4;
- gate = memory_read_direct(_TMOD_) & 0x80;
- timer_counter = memory_read_direct(_TMOD_) & 0x40;
+ tr = mem_read_direct(_TCON_) & 0x40;
+ mode = (mem_read_direct(_TMOD_) & 0x30) >> 4;
+ gate = mem_read_direct(_TMOD_) & 0x80;
+ timer_counter = mem_read_direct(_TMOD_) & 0x40;
if (tr && !gate && !timer_counter)
process_timer(_TL1_, _TH1_, 0x80, tr, mode, gate,
gchar *new_str, gpointer model)
{
guint column;
- guint memory_id;
+ enum mem_id_t memory_id;
gpointer columnptr;
gpointer memory_id_ptr;
GtkTreeIter iter;
/* Convert column number (1, 2, 3...) to index (0, 1, 2...) */
address += (column - COL_DATA0);
- old = memory_read8(memory_id, address);
+ old = mem_read8(memory_id, address);
log_info("Address: $%02X", address);
log_info(" old value: $%02X", old);
}
/* Store new value in emulator memory. */
- memory_write8(memory_id, address, new);
+ mem_write8(memory_id, address, new);
/* Convert to text. */
int2asciihex(new, str, 2);
};
static void
-memwin_init_columns(GtkWidget *listview, int memory_id)
+memwin_init_columns(GtkWidget *listview, enum mem_id_t memory_id)
{
int i;
GtkCellRenderer *renderer;
}
static void
-memwin_infos_select(int memory_id)
+memwin_infos_select(enum mem_id_t memory_id)
{
if (memory_id == INT_MEM_ID) {
log_debug("memory ID = INTERNAL");
}
GtkWidget *
-memwin_init(char *title, int memory_id)
+memwin_init(char *title, enum mem_id_t memory_id)
{
GtkWidget *frame;
GtkWidget *scrollwin;
* rows which have been modified.
*/
static int
-memwin_row_changed(int memory_id, int row, unsigned int address)
+memwin_row_changed(enum mem_id_t memory_id, int row, unsigned int address)
{
int row_changed;
u_int32_t crc_new = 0;
u_int8_t *buf8;
- buf8 = memory_getbuf(memory_id, address);
+ buf8 = mem_getbuf(memory_id, address);
crc_new = crc32(0L, Z_NULL, 0);
crc_new = crc32(crc_new, buf8, cfg->bytes_per_row);
/* Dump internal or external memory. */
void
-memwin_refresh(int memory_id)
+memwin_refresh(enum mem_id_t memory_id)
{
int row;
unsigned int address = 0;
for (col = 0; col < cfg->bytes_per_row; col++) {
u_int8_t data;
- data = memory_read8(memory_id, address + col);
+ data = mem_read8(memory_id, address + col);
/* Display hex data */
int2asciihex(data, str, 2);
#include <gtk/gtk.h>
GtkWidget *
-memwin_init(char *title, int memory_id);
+memwin_init(char *title, enum mem_id_t memory_id);
void
-memwin_refresh(int memory_id);
+memwin_refresh(enum mem_id_t memory_id);
#endif /* MEMWIN_H */
int2asciihex(address, str, 4);
gtk_list_store_set(store, &iter, COL_ADDR, str, -1);
- opcode = memory_read8(PGM_MEM_ID, address);
+ opcode = mem_read8(PGM_MEM_ID, address);
inst_size = cpu8051_get_instruction_size(opcode);
/* Display instruction hex bytes. */
for (k = 0, col_id = COL_B0; k < 3; k++, col_id++) {
if (k < inst_size)
- int2asciihex(memory_read8(PGM_MEM_ID,
- address + k),
+ int2asciihex(mem_read8(PGM_MEM_ID,
+ address + k),
str, 2);
else
str[0] = '\0';