Skip to content

Commit ead8e96

Browse files
committed
pick up ROMs from executable directory on Mac; Makefile cleanups, ship docs
1 parent aad8c94 commit ead8e96

File tree

4 files changed

+76
-28
lines changed

4 files changed

+76
-28
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
*.o
22
x16emu
3+
x16emu.exe
4+
x16emu_mac.zip
5+
x16emu_win.zip
36
rom_labels.h

Makefile

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
# https://blog.wasin.io/2018/10/21/cross-compile-sdl2-library-and-app-on-windows-from-macos.html
55
# for details on how to install mingw and libsdl2.
66

7+
# the mingw32 path on macOS installed through homebrew
8+
MINGW32=/usr/local/Cellar/mingw-w64/6.0.0_2/toolchain-i686/i686-w64-mingw32
9+
# the Windows SDL2 path on macOS installed through ./configure --prefix=... && make && make install
10+
WIN_SDL2=~/tmp/sdl2-win32
11+
712
ifeq ($(CROSS_COMPILE_WINDOWS),1)
8-
SDL2CONFIG=~/tmp/sdl2-win32/bin/sdl2-config
13+
SDL2CONFIG=$(WIN_SDL2)/bin/sdl2-config
914
else
1015
SDL2CONFIG=sdl2-config
1116
endif
@@ -18,7 +23,9 @@ ifeq ($(MAC_STATIC),1)
1823
endif
1924

2025
ifeq ($(CROSS_COMPILE_WINDOWS),1)
21-
LDFLAGS+=-L/usr/local/Cellar/mingw-w64/6.0.0_2/toolchain-i686/i686-w64-mingw32/lib -Wl,--subsystem,console
26+
LDFLAGS+=-L$(MINGW32)/lib
27+
# this enables printf() to show, but also forces a console window
28+
LDFLAGS+=-Wl,--subsystem,console
2229
CC=i686-w64-mingw32-gcc
2330
endif
2431

@@ -31,28 +38,37 @@ all: $(OBJS) $(HEADERS)
3138
%.o: %.c
3239
$(CC) $(CFLAGS) -c $< -o $@
3340

41+
42+
# Packaging requires pandoc:
43+
# brew install pandoc
44+
45+
package: package_mac package_win
46+
make clean
47+
3448
package_mac:
3549
(cd ../x16-kernalbasic/; ./build.sh)
3650
MAC_STATIC=1 make clean all
37-
rm -rf ~x16emu-package
51+
rm -rf ~x16emu-package x16emu_mac.zip
3852
mkdir ~x16emu-package
3953
cp x16emu ~x16emu-package
4054
cp ../x16-kernalbasic/rom.bin ~x16emu-package
4155
cp -p ~/tmp/chargen ~x16emu-package/chargen.bin
56+
pandoc --from gfm --to html --standalone README.md --output ~x16emu-package/README.html
4257
(cd ~x16emu-package/; zip "../x16emu_mac.zip" *)
4358
rm -rf ~x16emu-package
4459

4560
package_win:
4661
(cd ../x16-kernalbasic/; ./build.sh)
4762
CROSS_COMPILE_WINDOWS=1 make clean all
48-
rm -rf ~x16emu-package
63+
rm -rf ~x16emu-package x16emu_win.zip
4964
mkdir ~x16emu-package
5065
cp x16emu.exe ~x16emu-package
51-
cp /usr/local/Cellar/mingw-w64/6.0.0_2/toolchain-i686/i686-w64-mingw32/lib/libgcc_s_sjlj-1.dll ~x16emu-package/
52-
cp /usr/local/Cellar/mingw-w64/6.0.0_2/toolchain-i686/i686-w64-mingw32/bin/libwinpthread-1.dll ~x16emu-package/
53-
cp ~/tmp/sdl2-win32/bin/SDL2.dll ~x16emu-package/
66+
cp $(MINGW32)/lib/libgcc_s_sjlj-1.dll ~x16emu-package/
67+
cp $(MINGW32)/bin/libwinpthread-1.dll ~x16emu-package/
68+
cp $(WIN_SDL2)/bin/SDL2.dll ~x16emu-package/
5469
cp ../x16-kernalbasic/rom.bin ~x16emu-package
5570
cp -p ~/tmp/chargen ~x16emu-package/chargen.bin
71+
pandoc --from gfm --to html --standalone README.md --output ~x16emu-package/README.html
5672
(cd ~x16emu-package/; zip "../x16emu_win.zip" *)
5773
rm -rf ~x16emu-package
5874

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ This is an emulator for the Commander X16 computer system. It only depends on SD
44

55
## Starting
66

7-
* When starting `x16emu` without arguments, it will pick up the system ROM (`rom.bin`) and the character ROM (`chargen.bin`).
7+
You can start `x16emu`/`x16emu.exe` either by double-clicking it, or from the command line. The latter allows you to specify additional arguments.
8+
9+
* When starting `x16emu` without arguments, it will pick up the system ROM (`rom.bin`) and the character ROM (`chargen.bin`) from the executable's directory.
810
* The system ROM and character ROM filenames/paths can be overridden with the `-rom` and `-char` command line arguments.
911
* `-sdcard` lets you specify an SD card image (partition table + FAT32).
1012
* `-prg` leys you specify a `.prg` file that gets injected into RAM after start.
@@ -76,6 +78,7 @@ Copyright (c) 2019 Michael Steil. All rights reserved. License: 2-clause BSD
7678
* Command line overhaul. Supports `-rom`, `-char`, `-sdcard` and `-prg`.
7779
* ROM and char filename defaults, so x16emu can be started without arguments.
7880
* Host Filesystem Interface supports LOAD"$"
81+
* macOS and Windows packaging logic in Makefile
7982

8083
### Release 26
8184

main.c

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <stdio.h>
99
#include <string.h>
1010
#include <unistd.h>
11+
#include <limits.h>
1112
#include "fake6502.h"
1213
#include "disasm.h"
1314
#include "memory.h"
@@ -91,22 +92,47 @@ main(int argc, char **argv)
9192
uint16_t trace_address = 0;
9293
#endif
9394

95+
char *rom_filename = "/rom.bin";
96+
char *char_filename = "/chargen.bin";
97+
char rom_path_data[PATH_MAX];
98+
char char_path_data[PATH_MAX];
99+
100+
char *rom_path = rom_path_data;
101+
char *char_path = char_path_data;
102+
char *prg_path = NULL;
103+
char *sdcard_path = NULL;
104+
105+
#ifdef __APPLE__
106+
// on macOS, double clicking runs an executable in the user's
107+
// home directory, so we prepend the executable's path to
108+
// the rom filenames
109+
if (argv[0][0] == '/') {
110+
*strrchr(argv[0], '/') = 0;
111+
112+
strncpy(rom_path, argv[0], PATH_MAX);
113+
strncpy(rom_path + strlen(rom_path), rom_filename, PATH_MAX - strlen(rom_path));
114+
strncpy(char_path, argv[0], PATH_MAX);
115+
strncpy(char_path + strlen(char_path), char_filename, PATH_MAX - strlen(char_path));
116+
} else
117+
#endif
118+
{
119+
strncpy(rom_path, rom_filename + 1, PATH_MAX);
120+
strncpy(char_path, char_filename + 1, PATH_MAX);
121+
}
122+
123+
printf("%s / %s\n", rom_path, char_path);
124+
94125
argc--;
95126
argv++;
96127

97-
char *rom_filename = "rom.bin";
98-
char *char_filename = "chargen.bin";
99-
char *prg_filename = NULL;
100-
char *sdcard_filename = NULL;
101-
102128
while (argc > 0) {
103129
if (!strcmp(argv[0], "-rom")) {
104130
argc--;
105131
argv++;
106132
if (!argc) {
107133
usage();
108134
}
109-
rom_filename = argv[0];
135+
rom_path = argv[0];
110136
argc--;
111137
argv++;
112138
} else if (!strcmp(argv[0], "-char")) {
@@ -115,7 +141,7 @@ main(int argc, char **argv)
115141
if (!argc) {
116142
usage();
117143
}
118-
char_filename = argv[0];
144+
char_path = argv[0];
119145
argc--;
120146
argv++;
121147
} else if (!strcmp(argv[0], "-prg")) {
@@ -124,7 +150,7 @@ main(int argc, char **argv)
124150
if (!argc) {
125151
usage();
126152
}
127-
prg_filename = argv[0];
153+
prg_path = argv[0];
128154
argc--;
129155
argv++;
130156
} else if (!strcmp(argv[0], "-sdcard")) {
@@ -133,7 +159,7 @@ main(int argc, char **argv)
133159
if (!argc) {
134160
usage();
135161
}
136-
sdcard_filename = argv[0];
162+
sdcard_path = argv[0];
137163
argc--;
138164
argv++;
139165
#ifdef TRACE
@@ -156,43 +182,43 @@ main(int argc, char **argv)
156182
}
157183
}
158184

159-
FILE *f = fopen(rom_filename, "r");
185+
FILE *f = fopen(rom_path, "r");
160186
if (!f) {
161-
printf("Cannot open %s!\n", rom_filename);
187+
printf("Cannot open %s!\n", rom_path);
162188
exit(1);
163189
}
164190
fread(ROM, 1, ROM_SIZE, f);
165191
fclose(f);
166192

167-
f = fopen(char_filename, "r");
193+
f = fopen(char_path, "r");
168194
if (!f) {
169-
printf("Cannot open %s!\n", char_filename);
195+
printf("Cannot open %s!\n", char_path);
170196
exit(1);
171197
}
172198
uint8_t chargen[4096];
173199
fread(chargen, 1, sizeof(chargen), f);
174200
fclose(f);
175201

176-
if (sdcard_filename) {
177-
sdcard_file = fopen(sdcard_filename, "r");
202+
if (sdcard_path) {
203+
sdcard_file = fopen(sdcard_path, "r");
178204
if (!sdcard_file) {
179-
printf("Cannot open %s!\n", sdcard_filename);
205+
printf("Cannot open %s!\n", sdcard_path);
180206
exit(1);
181207
}
182208
}
183209

184210
FILE *prg_file = NULL;
185211
int prg_override_start = -1;
186-
if (prg_filename) {
187-
char *comma = strchr(prg_filename, ',');
212+
if (prg_path) {
213+
char *comma = strchr(prg_path, ',');
188214
if (comma) {
189215
prg_override_start = (uint16_t)strtol(comma + 1, NULL, 16);
190216
*comma = 0;
191217
}
192218

193-
prg_file = fopen(prg_filename, "r");
219+
prg_file = fopen(prg_path, "r");
194220
if (!prg_file) {
195-
printf("Cannot open %s!\n", prg_filename);
221+
printf("Cannot open %s!\n", prg_path);
196222
exit(1);
197223
}
198224
}

0 commit comments

Comments
 (0)