#include "common.h"
#include "memory.h"
+/* Convert integer to ASCII hex string. */
+void
+int2asciihex(int val, char *str, int width)
+{
+ if (width == 2)
+ sprintf(str , "%.2X", (u_int8_t) val);
+ else if (width == 4)
+ sprintf(str , "%.4X", (u_int16_t) val);
+}
+
+/* Convert ASCII hex string to integer. */
+int
+asciihex2int(char *str)
+{
+ int val;
+
+ sscanf(str, "%X", &val);
+
+ return val;
+}
+
/* Convert an ascii string to an hexadecimal number. */
unsigned int
Ascii2Hex(char *istring, int length)
#ifndef HEXFILE_H
#define HEXFILE_H 1
+void
+int2asciihex(int val, char *str, int width);
+
+int
+asciihex2int(char *str);
+
unsigned int
Ascii2Hex(char *istring, int length);
/* Get base address. */
gtk_tree_model_get(model, &iter, COL_ADDRESS, &str, -1);
- sscanf(str, "%x", &address);
+ address = asciihex2int(str);
/* Convert column number (1, 2, 3...) to index (0, 1, 2...) */
address += (column - COL_DATA0);
log_info(" old value: $%02X", old);
/* Convert new value (asciihex) to integer. */
- sscanf(new_str, "%x", &new);
-
+ new = asciihex2int(new_str);
if ((new < 0) || (new > 255)) {
log_info(" new value: out of range");
new = old; /* Put back old value... */
cpu8051_WriteD(address, new);
/* Convert to text. */
- sprintf(str, "%.2X", new);
+ int2asciihex(new, str, 2);
/* Store new value in gtk model. */
gtk_list_store_set(GTK_LIST_STORE(model), &iter, column, str, -1);
}
/* Display base address. */
- sprintf(str, "%.4X", Address);
+ int2asciihex(Address, str, 4);
+
gtk_list_store_set(store, &iter, COL_ADDRESS, str, -1);
for (col = 0; col < DATA_COLS; col++) {
data = cpu8051_ReadD(Address + col);
/* Display hex data */
- sprintf(str, "%.2X", (u_int8_t) data);
+ int2asciihex(data, str, 2);
+
gtk_list_store_set(store, &iter, col + 1, str, -1);
/* Append to ASCII string (if applicable). */
#include "memory.h"
#include "cpu8051.h"
#include "pgmwin.h"
+#include "hexfile.h"
static GtkWidget *pgmlist;
gtk_tree_model_get(model, &iter, COL_ADDR, &str_addr, -1);
/* Convert hex address in ASCII to integer. */
- sscanf(str_addr, "%x", &val);
+ val = asciihex2int(str_addr);
log_debug(" row address is: $%04X", val);
gtk_list_store_set(store, &iter, COL_BREAKPT, str, -1);
/* Display base address. */
- sprintf(str, "%.4X", Address);
+ int2asciihex(Address, str, 4);
+
gtk_list_store_set(store, &iter, COL_ADDR, str, -1);
OpCode = memory_read8(PGM_MEM_ID, Address);
/* Display instruction hex bytes. */
for (k = 0, col_id = COL_B0; k < InstSize; k++, col_id++) {
- sprintf(str, "%.2X", memory_read8(PGM_MEM_ID,
- Address + k));
+ int2asciihex(memory_read8(PGM_MEM_ID, Address + k),
+ str, 2);
gtk_list_store_set(store, &iter, col_id, str, -1);
}
#include "regwin.h"
#include "memwin.h"
#include "instructions_8051.h"
+#include "hexfile.h"
static GtkWidget *reglist;
/* Address is low address. */
return (cpu8051_ReadD(addr + 1) << 8) +
cpu8051_ReadD(addr);
- }
+ } else
+ return 0xFFFFFFFF;
}
static void
/* Read current (old) value. */
gtk_tree_model_get(model, &iter, COL_VAL, &str, -1);
- /* Convert old value (asciihex) to integer. */
- sscanf(str, "%x", &old);
+ old = asciihex2int(str);
if (regwin_infos[row].w == 2)
log_info(" old value: $%02X", old);
else if (regwin_infos[row].w == 4)
log_info(" old value: $%04X", old);
- /* Convert new value (asciihex) to integer. */
- sscanf(new_str, "%x", &new);
+ new = asciihex2int(new_str);
if (regwin_infos[row].w == 2) {
if ((new < 0) || (new > 0xFF)) {
}
/* Convert new value to text. */
- if (regwin_infos[row].w == 2)
- sprintf(str, "%02X", new);
- else if (regwin_infos[row].w == 4)
- sprintf(str, "%04X", new);
+ int2asciihex(new, str, regwin_infos[row].w);
/* Store new value in emulator register. */
if (regwin_infos[row].write_func == NULL) {
regwin_infos[row].w);
} else {
/* Read register value using custom function pointer. */
- val = regwin_infos[row].read_func(regwin_infos[row].param);
+ val = regwin_infos[row].read_func(
+ regwin_infos[row].param);
}
/* Convert to specified number of hex digits. */
- if (regwin_infos[row].w == 2)
- sprintf(str , "%.2X", (u_int8_t) val);
- else if (regwin_infos[row].w == 4)
- sprintf(str , "%.4X", (u_int16_t) val);
+ int2asciihex(val, str, regwin_infos[row].w);
gtk_list_store_set(store, &iter,
COL_NAME, regwin_infos[row].name,