2 TOSHIBA PASOPIA Emulator 'EmuPIA'
3 TOSHIBA PASOPIA 7 Emulator 'EmuPIA7'
5 Author : Takeda.Toshiya
8 [ ram pac 2 (32kbytes) ]
12 #include "../../fileio.h"
14 static const uint8 header[16] = {
15 0xaa, 0x1f, 0x04, 0x00, 0x04, 0x80, 0x00, 0x01, 0x04, 0x04, 0x01, 0x03, 0x08, 0x00, 0x00, 0x00
18 void RAMPAC2::initialize(int id)
20 opened = modified = false;
22 // note: rampac2 id must be 1 or 2 !!!
23 if(_tcscmp(config.recent_binary_path[id - 1][0], _T("")) != 0) {
25 open_file(config.recent_binary_path[id - 1][0]);
27 // open default rampac2 file
28 _TCHAR file_path[_MAX_PATH];
29 _stprintf_s(file_path, _MAX_PATH, _T("%sRAMPAC%d.BIN"), emu->application_path(), id);
34 void RAMPAC2::release()
37 if(opened && modified) {
38 FILEIO* fio = new FILEIO();
39 if(fio->Fopen(path, FILEIO_WRITE_BINARY)) {
40 fio->Fwrite(ram, sizeof(ram), 1);
52 void RAMPAC2::write_io8(uint32 addr, uint32 data)
56 ptr = (ptr & 0x7f00) | data;
59 ptr = (ptr & 0x00ff) | ((data & 0x7f) << 8);
62 if(ram[ptr & 0x7fff] != data) {
65 ram[ptr & 0x7fff] = data;
70 uint32 RAMPAC2::read_io8(uint32 addr)
72 return ram[ptr & 0x7fff];
75 void RAMPAC2::open_file(_TCHAR* file_path)
80 // load specified file
81 FILEIO* fio = new FILEIO();
82 if(fio->Fopen(file_path, FILEIO_READ_BINARY)) {
83 fio->Fread(ram, sizeof(ram), 1);
86 // initialize formatted image
87 memset(ram, 0, sizeof(ram));
88 memcpy(ram, header, sizeof(header));
89 memset(ram + 0x20, 0xff, 0x200);
90 memset(ram + 0x300, 0xfe, 0x004);
91 memset(ram + 0x304, 0xff, 0x0fc);
95 _tcscpy_s(path, _MAX_PATH, file_path);
100 #define STATE_VERSION 1
102 void RAMPAC2::save_state(FILEIO* state_fio)
104 state_fio->FputUint32(STATE_VERSION);
106 state_fio->Fwrite(ram, sizeof(ram), 1);
107 state_fio->FputUint32(ptr);
108 state_fio->FputBool(opened);
109 state_fio->FputBool(modified);
112 bool RAMPAC2::load_state(FILEIO* state_fio)
114 if(state_fio->FgetUint32() != STATE_VERSION) {
117 state_fio->Fread(ram, sizeof(ram), 1);
118 ptr = state_fio->FgetUint32();
119 opened = state_fio->FgetBool();
120 modified = state_fio->FgetBool();