ヘッダインクルードしたソースのみに
グローバル変数を公開するという仕様が頂けないのは承知ですが
よさ気な実装が浮かばず。
とりあえずメモリに影響を与える処理の為にこさえてみた暫定版です。
必要あるのか謎な定数群は性格の問題でしょうかね。>俺
プライベート公開する内容とそうでない内容とで
ヘッダ分けしてるのはこの規模なら好みの問題です。
モジュールのCソース内でも十分だと思います。
モジュール規模が大きいなら分けた方が良いかも知れませんが。
main.c
/*--------------------------------------------------------------------------------- memory module test version 0.01 Oct 11, 2009 (C)2009 REGEKATSU ---------------------------------------------------------------------------------*/ #include <nds.h> #include <stdio.h> #include "memory.h" //--------------------------------------------------------------------------------- int main(void){ //--------------------------------------------------------------------------------- int i; consoleDemoInit(); Memory_ClearAll(); printf("DrawMemory\n"); for(i = 0;i < 16;i++){ printf(" %02X:%1X %02X:%1X %02X:%1X %02X:%1X %02X:%1X %02X:%1X \n", 0x00 + i, st_gmc4.memory[0x00 + i], 0x10 + i, st_gmc4.memory[0x10 + i], 0x20 + i, st_gmc4.memory[0x20 + i], 0x30 + i, st_gmc4.memory[0x30 + i], 0x40 + i, st_gmc4.memory[0x40 + i], 0x50 + i, st_gmc4.memory[0x50 + i]); } printf("\nDrawRegister\n"); printf(" Ar %02X:%01X A'r %02X:%01X PC :%02X\n", Ar, st_gmc4.memory[Ar], A_r, st_gmc4.memory[A_r], st_gmc4.pc); printf(" Br %02X:%01X B'r %02X:%01X Flag:%01X\n", Br, st_gmc4.memory[Br], B_r, st_gmc4.memory[B_r], st_gmc4.flag); printf(" Yr %02X:%01X Y'r %02X:%01X\n", Yr, st_gmc4.memory[Yr], Y_r, st_gmc4.memory[Y_r]); printf(" Zr %02X:%01X Z'r %02X:%01X\n", Zr, st_gmc4.memory[Zr], Z_r, st_gmc4.memory[Z_r]); while(1) { swiWaitForVBlank(); } } //---------------------------------------------------------------------------------
memory.h
/*--------------------------------------------------------------------------------- memory module header version 0.01 Oct 11, 2009 (C)2009 REGEKATSU ---------------------------------------------------------------------------------*/ #ifndef _MEMORY_H_ #define _MEMORY_H_ #include <nds/ndstypes.h> typedef enum{ GMC4_MEMORY_MIN = 0x00, GMC4_MEMORY_MAX = 0x7F, GMC4_MEMORY_SIZE = 0x80, PROGRAM_MEMORY_MIN = 0x00, PROGRAM_MEMORY_MAX = 0x4F, PROGRAM_MEMORY_SIZE = 0x50, DATA_MEMORY_MIN = 0x00, DATA_MEMORY_MAX = 0x0F, DATA_MEMORY_SIZE = 0x10, DATA_MEMORY_FIRST = 0x50, DATA_MEMORY_LAST = 0x5F, DATA_MEMORY_RANGE = 0x60, USER_MEMORY_MIN = 0x00, USER_MEMORY_MAX = 0x5F, USER_MEMORY_SIZE = 0x60, MAIN_MEMORY_MIN = 0x00, MAIN_MEMORY_MAX = 0x6F, MAIN_MEMORY_SIZE = 0x70 }GMC4_MEMORY; typedef enum{ Ar = 0x6F, Br = 0x6C, Yr = 0x6E, Zr = 0x6D, A_r = 0x69, B_r = 0x67, Y_r = 0x68, Z_r = 0x66 }GMC4_REGISTER; typedef struct{ u8 memory[GMC4_MEMORY_SIZE]; u8 pc; bool flag; }MemoryStatus; extern MemoryStatus st_gmc4; #ifdef __cplusplus extern "C" { #endif void Memory_ClearAll(void); #ifdef __cplusplus } #endif #endif // _MEMORY_H_
memoryPrivate.h
/*--------------------------------------------------------------------------------- memory module private header version 0.01 Oct 11, 2009 (C)2009 REGEKATSU ---------------------------------------------------------------------------------*/ #ifndef _MEMORY_PRIVATE_H_ #define _MEMORY_PRIVATE_H_ #include <nds/ndstypes.h> #include "memory.h" #ifdef __cplusplus extern "C" { #endif void memory_SetPc(u8 pc); u8 memory_GetPc(void); void memory_SetFlag(bool flag); bool memory_GetFlag(void); void memory_SetMemory(u8 address, u8 data); u8 memory_GetMemory(u8 address); void memory_ClearPc(void); void memory_ClearFlag(void); void memory_SelectClearMemory(u8 first, u8 last); void memory_ClearMemory(void); #ifdef __cplusplus } #endif #endif // _MEMORY_PRIVATE_H_
memory.c
/*--------------------------------------------------------------------------------- memory module routine version 0.01 Oct 11, 2009 (C)2009 REGEKATSU ---------------------------------------------------------------------------------*/ #include "memoryPrivate.h" //--------------------------------------------------------------------------------- MemoryStatus st_gmc4; //--------------------------------------------------------------------------------- void memory_SetPc(u8 pc){ //--------------------------------------------------------------------------------- st_gmc4.pc = pc; } //--------------------------------------------------------------------------------- u8 memory_GetPc(void){ //--------------------------------------------------------------------------------- return st_gmc4.pc; } //--------------------------------------------------------------------------------- void memory_SetFlag(u8 flag){ //--------------------------------------------------------------------------------- st_gmc4.flag = flag; } //--------------------------------------------------------------------------------- u8 memory_GetFlag(void){ //--------------------------------------------------------------------------------- return st_gmc4.flag; } //--------------------------------------------------------------------------------- void memory_SetMemory(u8 address, u8 data){ //--------------------------------------------------------------------------------- st_gmc4.memory[(address & 0x7F)] = data; } //--------------------------------------------------------------------------------- u8 memory_GetMemory(u8 address){ //--------------------------------------------------------------------------------- return st_gmc4.memory[(address & 0x7F)]; } //--------------------------------------------------------------------------------- void memory_ClearPc(void){ //--------------------------------------------------------------------------------- memory_SetPc(0x00); } //--------------------------------------------------------------------------------- void memory_ClearFlag(void){ //--------------------------------------------------------------------------------- memory_SetFlag(true); } //--------------------------------------------------------------------------------- void memory_SelectClearMemory(u8 first, u8 last){ //--------------------------------------------------------------------------------- u8 i; for(i = first;i < last;i++){ st_gmc4.memory[i] = 0x0F; } } //--------------------------------------------------------------------------------- void memory_ClearMemory(void){ //--------------------------------------------------------------------------------- memory_SelectClearMemory(GMC4_MEMORY_MIN, GMC4_MEMORY_SIZE); } //--------------------------------------------------------------------------------- void Memory_ClearAll(void){ //--------------------------------------------------------------------------------- memory_ClearPc(); memory_ClearFlag(); memory_ClearMemory(); } //---------------------------------------------------------------------------------