X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=lib%2Fccdbg-memory.c;h=d74726fb11e8bd875a03a0da423b24eb50aac565;hp=105295db7c8dc238606a84f859ba1c4b5f76bb31;hb=23aca1fcbc169184e32d4ec19f28dd4fd4cfda36;hpb=9025eb792861930e6af918d2727c4f5d97a69936 diff --git a/lib/ccdbg-memory.c b/lib/ccdbg-memory.c index 105295db..d74726fb 100644 --- a/lib/ccdbg-memory.c +++ b/lib/ccdbg-memory.c @@ -23,9 +23,14 @@ */ static uint8_t memory_init[] = { + 2, MOV_direct_A, 0x7f, + 3, MOV_direct1_direct2, 0x7e, SFR_DPL0, + 3, MOV_direct1_direct2, 0x7d, SFR_DPH0, + 3, MOV_direct1_direct2, 0x7c, SFR_DPL1, + 3, MOV_direct1_direct2, 0x7b, SFR_DPH1, 3, MOV_DPTR_data16, 0, 0, -#define HIGH_START 2 -#define LOW_START 3 +#define HIGH_START 21 +#define LOW_START 22 0, }; @@ -44,6 +49,15 @@ static uint8_t read8[] = { 0, }; +static uint8_t memory_fini[] = { + 2, MOV_A_direct, 0x7f, + 3, MOV_direct1_direct2, SFR_DPL0, 0x7e, + 3, MOV_direct1_direct2, SFR_DPH0, 0x7d, + 3, MOV_direct1_direct2, SFR_DPL1, 0x7c, + 3, MOV_direct1_direct2, SFR_DPH1, 0x7b, + 0, +}; + uint8_t ccdbg_write_memory(struct ccdbg *dbg, uint16_t addr, uint8_t *bytes, int nbytes) { @@ -54,10 +68,19 @@ ccdbg_write_memory(struct ccdbg *dbg, uint16_t addr, uint8_t *bytes, int nbytes) for (i = 0; i < nbytes; i++) { write8[DATA_BYTE] = *bytes++; ccdbg_execute(dbg, write8); - if ((i & 0xf) == 0xf) { printf ("."); fflush(stdout); nl = 1; } - if ((i & 0xff) == 0xff) { printf ("\n"); nl = 0; } + if ((i & 0xf) == 0xf) { + ccdbg_debug(CC_DEBUG_MEMORY, "."); + ccdbg_flush(); + nl = 1; + } + if ((i & 0xff) == 0xff) { + ccdbg_debug(CC_DEBUG_MEMORY, "\n"); + nl = 0; + } } - if (nl) printf ("\n"); + (void) ccdbg_execute(dbg, memory_fini); + if (nl) + ccdbg_debug(CC_DEBUG_MEMORY, "\n"); return 0; } @@ -70,10 +93,19 @@ ccdbg_read_memory(struct ccdbg *dbg, uint16_t addr, uint8_t *bytes, int nbytes) (void) ccdbg_execute(dbg, memory_init); for (i = 0; i < nbytes; i++) { *bytes++ = ccdbg_execute(dbg, read8); - if ((i & 0xf) == 0xf) { printf ("."); fflush(stdout); nl = 1; } - if ((i & 0xff) == 0xff) { printf ("\n"); nl = 0; } + if ((i & 0xf) == 0xf) { + ccdbg_debug(CC_DEBUG_MEMORY, "."); + ccdbg_flush(); + nl = 1; + } + if ((i & 0xff) == 0xff) { + ccdbg_debug(CC_DEBUG_MEMORY, "\n"); + nl = 0; + } } - if (nl) printf ("\n"); + (void) ccdbg_execute(dbg, memory_fini); + if (nl) + ccdbg_debug(CC_DEBUG_MEMORY, "\n"); return 0; } @@ -102,3 +134,52 @@ ccdbg_read_hex_image(struct ccdbg *dbg, uint16_t address, uint16_t length) ccdbg_read_memory(dbg, address, image->data, length); return image; } + +static uint8_t sfr_init[] = { + 2, MOV_direct_A, 0x7f, + 0, +}; + +static uint8_t sfr_fini[] = { + 2, MOV_A_direct, 0x7f, + 0, +}; + +static uint8_t sfr_read[] = { + 2, MOV_A_direct, 0, +#define SFR_READ_ADDR 2 + 0, +}; + +static uint8_t sfr_write[] = { + 3, MOV_direct_data, 0, 0, +#define SFR_WRITE_ADDR 2 +#define SFR_WRITE_DATA 3 + 0, +}; + +uint8_t +ccdbg_read_sfr(struct ccdbg *dbg, uint8_t addr, uint8_t *bytes, int nbytes) +{ + int i; + (void) ccdbg_execute(dbg, sfr_init); + for (i = 0; i < nbytes; i++) { + sfr_read[SFR_READ_ADDR] = addr + i; + *bytes++ = ccdbg_execute(dbg, sfr_read); + } + (void) ccdbg_execute(dbg, sfr_fini); + return 0; +} + +uint8_t +ccdbg_write_sfr(struct ccdbg *dbg, uint8_t addr, uint8_t *bytes, int nbytes) +{ + int i; + + for (i = 0; i < nbytes; i++) { + sfr_write[SFR_WRITE_ADDR] = addr + i; + sfr_write[SFR_WRITE_DATA] = *bytes++; + ccdbg_execute(dbg, sfr_write); + } + return 0; +}