ROMDIR env variables

This commit is contained in:
nobuh 2017-03-23 01:53:43 +09:00
parent 8c791a116c
commit 47d76b9493
5 changed files with 56 additions and 4 deletions

View File

@ -1,6 +1,9 @@
CHANGELOG
=========
2.3
- ROM can be loaded from the directory of ROMDIR environment variable.
2.2.1
- Fix leaking memory on fd of loadBasic() function
- Fix some coding style issue in memory.c and msgbuf.c

17
README
View File

@ -19,6 +19,23 @@ How to install on Linux
3. Run
./napple1
Optional ROM Directory
======================
napple1 contain basic.rom and monitor.rom files on
the ./rom directory. However, If you want to put
basic.rom and monitor.rom on another directory.
Please use ROMDIR environmental variable.
For example, if you want to put basic.rom and monitor.rom
on current directory, the command is:
ROMDIR=. ./napple1
Default value of the ROMDIR is ./rom
You can use an absolute path for the ROM Directory.
ROMDIR=/home/username/my_rom_files ./napple1
How to uninstall
================
cd napple1/src

View File

@ -37,11 +37,14 @@ int main()
attron(A_REVERSE);
init_screen();
init_msgbuf();
/* initialize apple1 screen */
resetScreen();
setSpeed(1000000, 50); /* 1M Hz. Sync emulation every 50 msec */
/* set Rom Files */
setRomFiles();
/* Load monitor rom */
if (!loadMonitor()) {
print_msgbuf("Failed loading rom/monitor.rom");

View File

@ -84,10 +84,14 @@
#include "msgbuf.h"
#define MEMMAX 0xFFFF
#define FNAME_LEN_MAX 1024
static unsigned char mem[65536];
static int mode = 8; /* 8 = Apple I 8K mode, 32 = napple1 32K mode */
char rombasic[FNAME_LEN_MAX];
char rommonitor[FNAME_LEN_MAX];
void flipMode(void)
{
if (mode == 8)
@ -106,11 +110,11 @@ int memMode(void)
void loadBasic(void)
{
FILE *fd = fopen("rom/basic.rom", "rb");
FILE *fd = fopen(rombasic, "rb");
char input[MSG_LEN_MAX +1];
if (!fd) {
gets_msgbuf("Failed to open rom/basic.rom: ", input);
gets_msgbuf("Failed to open basic.rom", input);
return;
}
@ -130,7 +134,7 @@ void loadBasic(void)
int loadMonitor(void)
{
FILE *fd = fopen("rom/monitor.rom", "rb");
FILE *fd = fopen(rommonitor, "rb");
if (fd) {
fread(&mem[0xFF00], 1, 256, fd);
@ -246,3 +250,25 @@ int loadCore(void)
}
return 1;
}
/* set ROM file name using ROMDIR env variable
* default path is ./rom
* need to be called before loadBasic() and loadMonitor()
*/
void setRomFiles(void)
{
char env[FNAME_LEN_MAX];
char *p;
strcpy(rombasic, "rom/basic.rom");
strcpy(rommonitor, "rom/monitor.rom");
p = env;
if (getenv("ROMDIR")) {
p = getenv("ROMDIR");
sprintf(rombasic, "%s/basic.rom", p);
sprintf(rommonitor, "%s/monitor.rom", p);
}
}

View File

@ -16,6 +16,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#define FNAME_LEN_MAX 1024
void loadBasic(void);
int loadMonitor(void);
void resetMemory(void);
@ -25,3 +27,4 @@ void dumpCore(void);
int loadCore(void);
int memMode(void);
void flipMode(void);
void setRomFiles(void);