X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=src%2Fmemory.c;h=0b69e320b5d02d6e566c176dd6c6fc45eb4abdbf;hb=9b40aee50be61b462dcaa0a075d4f7fd66f9262d;hp=922b9aa674f6e0e96e07d14a6ee42412390e43c0;hpb=a78a174393ff9c8dbc0d5212576507f25d7e9bf1;p=emu8051.git diff --git a/src/memory.c b/src/memory.c index 922b9aa..0b69e32 100644 --- a/src/memory.c +++ b/src/memory.c @@ -20,7 +20,11 @@ */ #include +#include +#include "common.h" +#include "cpu8051.h" +#include "hexfile.h" #include "memory.h" #define PGM_MEM_SIZE 65536 @@ -33,36 +37,33 @@ static u_int8_t int_mem[INT_MEM_SIZE]; static u_int8_t ext_mem[EXT_MEM_SIZE]; void -memory_write8( int memory_id, unsigned long address, u_int8_t value ) +memory_write8(int memory_id, unsigned long address, u_int8_t value) { - switch( memory_id ) { + switch (memory_id) { case PGM_MEM_ID: - if( address >= PGM_MEM_SIZE ) { - printf("Address is greater than PGM_MEM_SIZE\n"); + if (address >= PGM_MEM_SIZE) { + printf("Address (%lu) is greater than PGM_MEM_SIZE\n", + address); return; - } - else { + } else pgm_mem[address] = value; - } break; case INT_MEM_ID: - if( address >= INT_MEM_SIZE) { - printf("Address is greater than INT_MEM_SIZE\n"); + if (address >= INT_MEM_SIZE) { + printf("Address (%lu) is greater than INT_MEM_SIZE\n", + address); return; - } - else { + } else int_mem[address] = value; - } break; case EXT_MEM_ID: - if( address >= EXT_MEM_SIZE ) { - printf("Address is greater than EXT_MEM_SIZE\n"); + if (address >= EXT_MEM_SIZE) { + printf("Address (%lu) is greater than EXT_MEM_SIZE\n", + address); return; - } - else { + } else ext_mem[address] = value; - } - break; + break; default: /* Error. */ break; @@ -70,39 +71,88 @@ memory_write8( int memory_id, unsigned long address, u_int8_t value ) } u_int8_t -memory_read8( int memory_id, unsigned long address ) +memory_read8(int memory_id, unsigned long address) { - switch( memory_id ) { + switch (memory_id) { case PGM_MEM_ID: - if( address < PGM_MEM_SIZE ) { + if (address < PGM_MEM_SIZE) return pgm_mem[address]; - } else { - printf("Address is greater than PGM_MEM_SIZE\n"); + printf("Address (%lu) is greater than PGM_MEM_SIZE\n", + address); return 0; } break; case INT_MEM_ID: - if( address < INT_MEM_SIZE ) { + if (address < INT_MEM_SIZE) return int_mem[address]; - } else { - printf("Address is greater than INT_MEM_SIZE\n"); + printf("Address (%lu) is greater than INT_MEM_SIZE\n", + address); return 0; } break; case EXT_MEM_ID: - if( address < EXT_MEM_SIZE ) { + if (address < EXT_MEM_SIZE) return ext_mem[address]; - } else { - printf("Address is greater than EXT_MEM_SIZE\n"); + printf("Address (%lu) is greater than EXT_MEM_SIZE\n", + address); return 0; } - break; + break; default: /* Error. */ return 0; break; } } + +/* Dump memory */ +void +DumpMem(char *buf, char *Address, int memory_id) +{ + unsigned int MemAddress; + int Offset, Column; + int size = 256; + int k = 0; + + if (strlen(Address) != 0) { + if (STREQ(Address, "PC")) + MemAddress = cpu8051.pc; + else + MemAddress = Ascii2Hex(Address, strlen(Address)); + } else { + MemAddress = 0; + } + + for (Offset = 0; Offset < size; Offset += 16) { + unsigned char data[16]; + + sprintf(&buf[k], "%.4X ", MemAddress + Offset); + k = strlen(buf); + + for (Column = 0; Column < 16; Column++) { + data[Column] = memory_read8(memory_id, MemAddress + + Offset + Column); + sprintf(&buf[k], " %.2X", (int) data[Column]); + k = strlen(buf); + } + sprintf(&buf[k], " "); + k = strlen(buf); + + /* Display any ASCII characters */ + for (Column = 0; Column < 16; Column++) { + if ((int) data[Column] >= 32 && + (int) data[Column] <= 126) { + sprintf(&buf[k], "%c", data[Column]); + k = strlen(buf); + } else { + sprintf(&buf[k], "."); + k = strlen(buf); + } + } + sprintf(&buf[k], "\n"); + k = strlen(buf); + } +}