メモリダンプっぽい何か。


モニタ中、またはCPU実行中にリアルタイム表示するメモリダンパです。
ビルドには一昨日に公開したメモリモジュールも含める必要があります。


主要な描画をDumpDrawへまとめて、
初期化や状態切替はDumpでまとめてます。


モニタシーケンス内の
エディットシーケンス、CPU実行シーケンスが基本状態遷移であり、
基本遷移外で常に実行されるシーケンス(?)という想定です(分かり辛い)。

MONITOR
    DUMP<常に実行
    
    EDIT<状態1
    CPU <状態2


CPUコア、モニタがないので未実装ですが
カレントアドレスのカーソルなんかがあると親切かも、と思ってます。


dump memory sequence test


main.c

/*---------------------------------------------------------------------------------

	dump sequence test
	
	version.0.01
	Oct 12, 2009
	
	(C)2009 REGEKATSU
	
---------------------------------------------------------------------------------*/
#include <nds.h>
#include <stdio.h>

#include "dump.h"

#include "memory.h"	//メモリ初期化の為にインクルード


//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
	
	consoleDemoInit();
	
	Memory_ClearAll();
	
	Dump_ClearDump();
	
	while(1) {
		swiWaitForVBlank();
		
		scanKeys();
		
		if(keysDown() & KEY_SELECT){
			Dump_SwitchDump();
		}
		
		Dump_UpdateDump();
		
	}
	
}


dump.h

/*---------------------------------------------------------------------------------
	
	dump sequence header
	
	version 0.01
	Oct 12, 2009
	
	(C)2009 REGEKATSU
	
---------------------------------------------------------------------------------*/

#ifndef _DUMP_H_
#define _DUMP_H_


#ifdef __cplusplus
extern "C" {
#endif


void Dump_ClearDump(void);
void Dump_SwitchDump(void);
void Dump_UpdateDump(void);
bool Dump_IsStopDump(void);


#ifdef __cplusplus
}
#endif

#endif	// _DUMP_H_


dumpPrivate.h

/*---------------------------------------------------------------------------------
	
	dump sequence private header
	
	version 0.01
	Oct 12, 2009
	
	(C)2009 REGEKATSU
	
---------------------------------------------------------------------------------*/

#ifndef _DUMP_PRIVATE_H_
#define _DUMP_PRIVATE_H_


#include <nds/ndstypes.h>
#include <nds/arm9/input.h>
#include <stdio.h>

#include "dumpDraw.h"
#include "dump.h"


#ifdef __cplusplus
extern "C" {
#endif


void dump_SetDumpStatus(bool is_dump);
bool dump_GetDumpStatus(void);

void dump_ClearDumpStatus(void);


#ifdef __cplusplus
}
#endif

#endif	// _DUMP_PRIVATE_H_


dump.c

/*---------------------------------------------------------------------------------

	dump sequence routine
	
	version.0.01
	Oct 12, 2009
	
	(C)2009 REGEKATSU
	
---------------------------------------------------------------------------------*/

#include "dumpPrivate.h"


bool st_is_dump = false;


//---------------------------------------------------------------------------------
void dump_SetDumpStatus(bool is_dump) {
//---------------------------------------------------------------------------------
	st_is_dump = is_dump;
}

//---------------------------------------------------------------------------------
bool dump_GetDumpStatus(void) {
//---------------------------------------------------------------------------------
	return st_is_dump;
}



//---------------------------------------------------------------------------------
void dump_ClearDumpStatus(void) {
//---------------------------------------------------------------------------------
	dump_SetDumpStatus(false);
}



//---------------------------------------------------------------------------------
void Dump_ClearDump(void) {
//---------------------------------------------------------------------------------
	dump_ClearDumpStatus();
	DumpDraw_ClearIdx();
}

//---------------------------------------------------------------------------------
void Dump_SwitchDump(void) {
//---------------------------------------------------------------------------------
	
	if(st_is_dump){
		printf("\x01b[2J");
		st_is_dump = false;
	}else{
		printf("\x01b[0;10HDump memory");
		st_is_dump = true;
	}
	
}

//---------------------------------------------------------------------------------
void Dump_UpdateDump(void) {
//---------------------------------------------------------------------------------
		
	if(st_is_dump){
		
		DumpDraw_DrawMemory();
		
		DumpDraw_DrawPrev();
		DumpDraw_DrawNext();
		
		DumpDraw_DrawRegister();
		
		if(keysDown() & KEY_LEFT){
			DumpDraw_SetPrev();
		}
		
		if(keysDown() & KEY_RIGHT){
			DumpDraw_SetNext();
		}
		
	}
	
}

//---------------------------------------------------------------------------------
bool Dump_IsStopDump(void) {
//---------------------------------------------------------------------------------
	return (!dump_GetDumpStatus()) ? true:false;
}

//---------------------------------------------------------------------------------


dumpDraw.h

/*---------------------------------------------------------------------------------
	
	dump draw module header
	
	version 0.01
	Oct 12, 2009
	
	(C)2009 REGEKATSU
	
---------------------------------------------------------------------------------*/

#ifndef _DUMP_DRAW_H_
#define _DUMP_DRAW_H_


#ifdef __cplusplus
extern "C" {
#endif


void DumpDraw_DrawMemory(void);
void DumpDraw_DrawRegister(void);

void DumpDraw_SetPrev(void);
void DumpDraw_SetNext(void);

void DumpDraw_DrawPrev(void);
void DumpDraw_DrawNext(void);

void DumpDraw_ClearIdx(void);


#ifdef __cplusplus
}
#endif

#endif	// _DUMP_DRAW_H_


dumpDrawPrivate.h

/*---------------------------------------------------------------------------------
	
	dump draw module private header
	
	version 0.01
	Oct 12, 2009
	
	(C)2009 REGEKATSU
	
---------------------------------------------------------------------------------*/

#ifndef _DUMP_DRAW_PRIVATE_H_
#define _DUMP_DRAW_PRIVATE_H_


#include <stdio.h>

#include "memory.h"
#include "dumpDraw.h"


#ifdef __cplusplus
extern "C" {
#endif


#ifdef __cplusplus
}
#endif

#endif	// _DUMP_DRAW_PRIVATE_H_

dumpDraw.c

/*---------------------------------------------------------------------------------
	
	dump draw module routine
	
	version 0.01
	Oct 12, 2009
	
	(C)2009 REGEKATSU
	
---------------------------------------------------------------------------------*/

#include "dumpDrawPrivate.h"


typedef struct{
	int i;
	int j;
}Idx;

static Idx st_idx = {0x00, 0x00};


//---------------------------------------------------------------------------------
void DumpDraw_DrawMemory(void) {
//---------------------------------------------------------------------------------
	
	for(st_idx.i = 0;st_idx.i < 16;st_idx.i++){
		printf("\x01b[%d;1H%02X:%1X %02X:%1X %02X:%1X %02X:%1X %02X:%1X %02X:%1X \n", 2 + st_idx.i, 
			(0x00 + st_idx.j) + st_idx.i, st_gmc4.memory[(0x00 + st_idx.j) + st_idx.i], 
			(0x10 + st_idx.j) + st_idx.i, st_gmc4.memory[(0x10 + st_idx.j) + st_idx.i], 
			(0x20 + st_idx.j) + st_idx.i, st_gmc4.memory[(0x20 + st_idx.j) + st_idx.i], 
			(0x30 + st_idx.j) + st_idx.i, st_gmc4.memory[(0x30 + st_idx.j) + st_idx.i], 
			(0x40 + st_idx.j) + st_idx.i, st_gmc4.memory[(0x40 + st_idx.j) + st_idx.i], 
			(0x50 + st_idx.j) + st_idx.i, st_gmc4.memory[(0x50 + st_idx.j) + st_idx.i]);
	}
	
}

//---------------------------------------------------------------------------------
void DumpDraw_DrawRegister(void) {
//---------------------------------------------------------------------------------
	
	printf("\x01b[19;3HAr %02X:%01X  A'r %02X:%01X  PC  :%02X", 
		Ar, st_gmc4.memory[Ar], A_r, st_gmc4.memory[A_r], st_gmc4.pc);
	printf("\x01b[20;3HBr %02X:%01X  B'r %02X:%01X  Flag:%01X", 
		Br, st_gmc4.memory[Br], B_r, st_gmc4.memory[B_r], st_gmc4.flag);
	printf("\x01b[21;3HYr %02X:%01X  Y'r %02X:%01X", 
		Yr, st_gmc4.memory[Yr], Y_r, st_gmc4.memory[Y_r]);
	printf("\x01b[22;3HZr %02X:%01X  Z'r %02X:%01X", 
		Zr, st_gmc4.memory[Zr], Z_r, st_gmc4.memory[Z_r]);
	
}



//---------------------------------------------------------------------------------
void DumpDraw_SetPrev(void) {
//---------------------------------------------------------------------------------
	
	if(st_idx.j > 0x00){
		st_idx.j -= 0x10;
	}
	
}

//---------------------------------------------------------------------------------
void DumpDraw_DrawPrev(void) {
//---------------------------------------------------------------------------------
	
	if(st_idx.j <= 0x10){
		//Show
		printf("\x01b[18;0H<L prev");
	}else{
		//Hide
		printf("\x01b[18;0H       ");
	}
	
}



//---------------------------------------------------------------------------------
void DumpDraw_SetNext(void) {
//---------------------------------------------------------------------------------
	
	if(st_idx.j < 0x20){
		st_idx.j += 0x10;
	}
	
}

//---------------------------------------------------------------------------------
void DumpDraw_DrawNext(void) {
//---------------------------------------------------------------------------------
	
	if(st_idx.j >= 0x10){
		//Show
		printf("\x01b[18;25Hnext R>");
	}else{
		//Hide
		printf("\x01b[18;25H       ");
	}
	
}



//---------------------------------------------------------------------------------
void DumpDraw_ClearIdx(void) {
//---------------------------------------------------------------------------------
	
	st_idx.i = 0x00;
	st_idx.j = 0x00;
	
}

//---------------------------------------------------------------------------------