improved DMA display and dump to filesystem using BFile

This commit is contained in:
Lephe 2020-05-31 15:56:22 +02:00
parent e921c6874e
commit abeaeb882b
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
4 changed files with 162 additions and 63 deletions

View File

@ -12,14 +12,8 @@
#define DMA SH7305_DMA
#define dprint(x, y, ...) dprint(x, y, C_BLACK, C_NONE, __VA_ARGS__)
void show_dma(int x, int y, int channel)
void show_dma(int x, int y, int channel, sh7305_dma_channel_t *dma)
{
sh7305_dma_channel_t *addr[6] = {
&DMA.DMA0, &DMA.DMA1, &DMA.DMA2,
&DMA.DMA3, &DMA.DMA4, &DMA.DMA5,
};
sh7305_dma_channel_t *dma = addr[channel];
#ifdef FX9860G
dma->SAR = 0x12345678;
dma->DAR = 0x9abcdef0;
@ -81,11 +75,16 @@ void gintctl_gint_dma(void)
#endif
#ifdef FXCG50
sh7305_dma_channel_t *addr[6] = {
&DMA.DMA0, &DMA.DMA1, &DMA.DMA2,
&DMA.DMA3, &DMA.DMA4, &DMA.DMA5,
};
row_title("Direct Memory Access status");
show_dma(6, 24, 0);
show_dma(138, 24, 1);
show_dma(270, 24, 2);
show_dma(6, 24, 0, addr[0]);
show_dma(138, 24, 1, addr[1]);
show_dma(270, 24, 2, addr[2]);
dprint(6, 102, "DMAOR: %08X", DMA.OR);

View File

@ -1,7 +1,9 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/bfile.h>
#include <gint/gint.h>
#include <gint/std/stdio.h>
#include <gint/hardware.h>
#include <gintctl/util.h>
#include <gintctl/gint.h>
@ -10,103 +12,144 @@ struct region {
char const *name;
uint32_t start;
uint32_t end;
int segment_count;
};
struct {
int region;
int segment;
char filename[30];
int retcode;
} dump;
static struct region const regs[] = {
{ "ROM", 0x80000000, 0x807fffff },
{ "RAM", 0x88000000, 0x88040000 },
{ "RS", 0xfd800000, 0xfd8007ff },
#ifdef FX9860G
{ "ROM", 0x80000000, 0x807fffff, 8 },
{ "RAM", 0x88000000, 0x88040000, 1 },
{ "RS", 0xfd800000, 0xfd8007ff, 1 },
#endif
#ifdef FXCG50
{ "ROM", 0x80000000, 0x81ffffff, 32 },
{ "RAM", 0x88000000, 0x881fffff, 2 },
{ "RS", 0xfd800000, 0xfd8007ff, 1 },
#endif
};
static void filename(char *out, int region_id, int rom_segment)
static void switch_dump(void)
{
if(region_id == 0)
{
sprintf(out, "ROM-%d.bin", rom_segment);
}
else
{
sprintf(out, "%s.bin", regs[region_id].name);
}
}
uint32_t start = regs[dump.region].start;
int size = regs[dump.region].end + 1 - start;
#ifdef FX9860G
static void dump(int region_id, int rom_segment)
{
uint32_t start = regs[region_id].start;
int size = regs[region_id].end + 1 - start;
if(region_id == 0)
/* For segmented regions, use blocks of 1M */
if(regs[dump.region].segment_count > 1)
{
start += rom_segment << 20;
start += dump.segment << 20;
size = 1 << 20;
}
/* Make sure the size is *even* */
size &= ~1;
uint16_t file[30];
char file_u8[30] = "\\\\fls0\\";
uint16_t file[30] = { 0 };
for(int i = 0; i < 30; i++) file[i] = dump.filename[i];
filename(file_u8 + 7, region_id, rom_segment);
for(int i = 0; i < 30; i++) file[i] = file_u8[i];
dump.retcode = 1;
BFile_Remove(file);
BFile_Create(file, BFile_File, &size);
int x = BFile_Remove(file);
if(x < 0 && x != -1) { dump.retcode = x; return; }
x = BFile_Create(file, BFile_File, &size);
if(x < 0) { dump.retcode = x; return; }
int fd = BFile_Open(file, BFile_WriteOnly);
BFile_Write(fd, (void *)start, size);
if(fd < 0) { dump.retcode = fd; return; }
x = BFile_Write(fd, (void *)start, size);
if(x < 0) { dump.retcode = x; return; }
BFile_Close(fd);
}
#endif
static int do_dump(int region, int segment)
{
/* Pass around parameters through the global variable */
dump.region = region;
dump.segment = segment;
sprintf(dump.filename, "\\\\fls0\\%s%02x.bin", regs[region].name,
segment);
gint_switch(switch_dump);
return dump.retcode;
}
/* gintctl_gint_dump(): Dump memory to filesystem */
void gintctl_gint_dump(void)
{
int region_id=0, rom_segment=0;
char output_file[20];
int region=0, segment=0;
char filename[30];
int retcode = 0;
int key = 0;
while(key != KEY_EXIT)
{
filename(output_file, region_id, rom_segment);
sprintf(filename, "%s%02x.bin", regs[region].name, segment);
dclear(C_WHITE);
#ifdef FX9860G
row_print(1, 1, "Memory dump");
row_print(3, 1, "Region: %s", regs[region_id].name);
if(region_id == 0)
row_print(4, 1, "Segment: %d", rom_segment);
row_print(5, 1, "File: %s", output_file);
row_print(3, 1, "Region: %s", regs[region].name);
row_print(4, 1, "Segment: %d (total %d)", segment,
regs[region].segment_count);
row_print(5, 1, "File: %s", filename);
extern image_t img_opt_dump;
dimage(0, 56, &img_opt_dump);
if(retcode == 1) dprint(77, 56, C_BLACK,C_NONE, "Done!");
if(retcode < 0) dprint(77, 56, C_BLACK,C_NONE, "E%d",retcode);
#endif
#ifdef FXCG50
row_title("Memory dump to filesystem");
row_print(1, 1, "Region:");
row_print(2, 1, "Segment:");
row_print(3, 1, "File:");
row_print(1, 10, "%s", regs[region].name);
row_print(2, 10, "%d (total %d)", segment,
regs[region].segment_count);
row_print(3, 10, "%s", filename);
fkey_button(1, "ROM");
fkey_button(2, "RAM");
fkey_button(3, "RS");
// fkey_action(6, "DUMP");
fkey_action(6, "DUMP");
#endif
dupdate();
key = getkey().key;
if(key == KEY_F1)
{
if(region_id == 0) rom_segment = (rom_segment + 1) % 8;
region_id = 0;
}
if(key == KEY_F2) region_id = 1;
if(key == KEY_F3) region_id = 2;
#ifdef FX9860G
if(key == KEY_F6) dump(region_id, rom_segment);
#endif
int select = -1;
if(key == KEY_F1) select = 0;
if(key == KEY_F2) select = 1;
if(key == KEY_F3) select = 2;
if(select >= 0 && select == region)
{
segment = (segment + 1) % regs[region].segment_count;
}
else if(select >= 0 && select != region)
{
region = select;
segment = 0;
}
retcode = 0;
if(key == KEY_F6) retcode = do_dump(region, segment);
}
}

View File

@ -4,6 +4,7 @@
#include <gint/drivers.h>
#include <gint/clock.h>
#include <gint/mpu/tmu.h>
#include <gint/mpu/dma.h>
#include <gint/std/string.h>
#include <gintctl/gint.h>
@ -83,12 +84,58 @@ static void ctx_etmu(int start)
#ifdef FXCG50
static void ctx_tmu()
{
tmu_t *t = driver_ctx("TMU");
etmu_t *e = (void *)(t + 3);
uint8_t *TSTR = (void *)(e + 6);
int const x[] = { 6, 138, 270, 6, 138, 270, 6, 138, 270 };
int const y[] = { 24, 24, 24, 84, 84, 84, 144, 144, 144 };
tmu_print(x[0], y[0], "TMU0", t+0, *TSTR & 0x1);
tmu_print(x[1], y[1], "TMU1", t+1, *TSTR & 0x2);
tmu_print(x[2], y[2], "TMU2", t+2, *TSTR & 0x4);
etmu_print(x[3], y[3], "ETMU0", e+0);
etmu_print(x[4], y[4], "ETMU1", e+1);
etmu_print(x[5], y[5], "ETMU2", e+2);
etmu_print(x[6], y[6], "ETMU3", e+3);
etmu_print(x[7], y[7], "ETMU4", e+4);
etmu_print(x[8], y[8], "ETMU5", e+5);
}
static void ctx_dd()
{
uint16_t *win = driver_ctx("R61524");
uint16_t HSA = win[0], HEA = win[1], VSA = win[2], VEA = win[3];
row_print(1, 1, "Horizontal range: %d..%d", HSA, HEA);
row_print(2, 1, "Vertical range: %d..%d", VSA, VEA);
}
static void ctx_rtc()
{
uint8_t *ctx = driver_ctx("RTC");
uint8_t RCR1=ctx[0], RCR2=ctx[1];
row_print(1, 1, "RCR1:%02x", RCR1);
row_print(2, 1, "RCR2:%02x", RCR2);
}
static void ctx_dma()
{
sh7305_dma_channel_t *ch = driver_ctx("DMA0");
int *clock = (void *)(ch + 6);
uint16_t *OR = (void *)(clock + 1);
show_dma(6, 24, 0, ch+0);
show_dma(138, 24, 1, ch+1);
show_dma(270, 24, 2, ch+2);
show_dma(6, 104, 3, ch+3);
show_dma(138, 104, 4, ch+4);
show_dma(270, 104, 5, ch+5);
dprint(6, 184, C_BLACK, C_WHITE, "DMAOR: %08X", *OR);
dprint(198, 184, C_BLACK, C_WHITE, "Clock enabled: %s",
(*clock ? "No" : "Yes"));
}
#endif /* FXCG50 */
@ -110,6 +157,7 @@ static void system_contexts(void)
fkey_button(1, "TMU");
fkey_button(2, "R61524");
fkey_button(3, "RTC");
fkey_button(4, "DMA");
#endif
if(tab == 0) ctx_tmu();
@ -121,15 +169,19 @@ static void system_contexts(void)
if(tab == 4) ctx_etmu(3);
#endif
#ifdef FXCG50
if(tab == 3) ctx_dma();
#endif
dupdate();
key = getkey().key;
if(key == KEY_F1) tab = 0;
if(key == KEY_F2) tab = 1;
if(key == KEY_F3) tab = 2;
if(key == KEY_F4) tab = 3;
#ifdef FX9860G
if(key == KEY_F4) tab = 3;
if(key == KEY_F5) tab = 4;
#endif
}

View File

@ -3,6 +3,7 @@
#include <gint/timer.h>
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/clock.h>
#include <gintctl/util.h>
#include <gintctl/gint.h>
@ -132,10 +133,14 @@ void gintctl_gint_timer(void)
#endif
dupdate();
clearevents();
int timeout = 1;
key_event_t ev = getkey_opt(GETKEY_DEFAULT, &timeout);
if(ev.type == KEYEV_NONE) continue;
key = ev.key;
/* On F1, pretend to sleep and just see what happens */
if(keydown(KEY_F1))
if(key == KEY_F1)
{
volatile int flag = 0;
int free = timer_setup(tid, timer_delay(tid, 1000000),
@ -145,9 +150,9 @@ void gintctl_gint_timer(void)
#ifdef FX9860G
/* On F4, F5 and F6, switch tabs */
if(keydown(KEY_F4)) tab = 1;
if(keydown(KEY_F5)) tab = 2;
if(keydown(KEY_F6)) tab = 3;
if(key == KEY_F4) tab = 1;
if(key == KEY_F5) tab = 2;
if(key == KEY_F6) tab = 3;
#endif
if(key == KEY_UP) tid = (tid+timer_count()-1) % timer_count();