Skip to content

Commit 5cfbaf6

Browse files
authored
Chores (#70)
* use size correctly on windows open_file_dialog implementation * improve size and error handling of open_file_dialog funcs * fix pointer reference * increase upper limit on cpu frequency to 9000 hz * comment * change to bool and comment * use bool * tidy up and reuse vars * windows NMAKE only supplies `$<` from inference rules
1 parent 223ea66 commit 5cfbaf6

File tree

12 files changed

+68
-55
lines changed

12 files changed

+68
-55
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ The following must be installed and added to your **PATH**:
113113

114114
## Building on Linux (Debian)
115115

116-
The following must be added to your **PATH**:
116+
The following must be installed and added to your **PATH**:
117117

118118
>gcc<br>
119119
>g++<br>

linux/makefile

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ SDL_LIB = ../external/sdl/build/lib/libSDL2-2.0.so.0
6262
# Generated headers
6363
LICENSE_HEADER = ../shared/license.h
6464
BOOTROM_HEADER = ../shared/bootrom.h
65-
BOOTROM_SOURCE = ../roms/Kiwi8_logo_2.ch8
65+
66+
# ROM Profiles database (source of truth)
67+
PROFILES_INI = ../shared/profiles.ini
6668

6769
OBJS = audio.o \
6870
chip8.o \
@@ -79,11 +81,8 @@ OBJS = audio.o \
7981
imgui_impl_sdl.o \
8082
sha256.o
8183

82-
DEPS = $(OBJS:.o=.d)
83-
84-
PROFILES_INI = ../shared/profiles.ini
85-
8684
# Include auto-generated dependency files (must be before targets)
85+
DEPS = $(OBJS:.o=.d)
8786
-include $(DEPS)
8887

8988
.DEFAULT_GOAL := all
@@ -100,11 +99,11 @@ $(SDL_LIB):
10099

101100
# Generate license header from LICENSE file
102101
$(LICENSE_HEADER): ../LICENSE
103-
python3 ../tools/generate_license_header.py ../LICENSE $(LICENSE_HEADER)
102+
python3 ../tools/generate_license_header.py $< $@
104103

105104
# Generate bootrom header from ROM file
106-
$(BOOTROM_HEADER): $(BOOTROM_SOURCE)
107-
python3 ../tools/generate_bootrom_header.py $(BOOTROM_SOURCE) $(BOOTROM_HEADER)
105+
$(BOOTROM_HEADER): ../roms/Kiwi8_logo_2.ch8
106+
python3 ../tools/generate_bootrom_header.py $< $@
108107

109108
# Pattern rules for incremental compilation
110109
%.o: src/%.cc
@@ -127,11 +126,11 @@ $(BOOTROM_HEADER): $(BOOTROM_SOURCE)
127126

128127
debug/profiles.ini: $(PROFILES_INI)
129128
mkdir -p debug
130-
cp $(PROFILES_INI) debug/profiles.ini
129+
cp $(PROFILES_INI) $@
131130

132131
release/profiles.ini: $(PROFILES_INI)
133132
mkdir -p release
134-
cp $(PROFILES_INI) release/profiles.ini
133+
cp $(PROFILES_INI) $@
135134

136135
# debug executable
137136
debug/$(APP_EXE): $(SDL_LIB) $(OBJS)
@@ -145,10 +144,10 @@ release/$(APP_EXE): $(SDL_LIB) $(OBJS)
145144
cp $(SDL_LIB) release/libSDL2-2.0.so.0
146145
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) $(OBJS) -o $@ $(LDFLAGS)
147146

148-
run-debug: debug/$(APP_EXE)
147+
run-debug: debug/$(APP_EXE) debug/profiles.ini
149148
./debug/$(APP_EXE)
150149

151-
run-release: release/$(APP_EXE)
150+
run-release: release/$(APP_EXE) release/profiles.ini
152151
./release/$(APP_EXE)
153152

154153
# Removes build artifacts (objects, executables) but keeps SDL

linux/src/open_file_dialog.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ std::vector<std::string> open_file_dialog(const std::string &title, const std::s
7070
}
7171

7272
int open_file_dialog(char *rom_filepath, size_t size) {
73+
if (rom_filepath == nullptr || size == 0) return -1;
74+
7375
std::vector<std::string> fileTypes = {"ch8", "CH8", "chip-8", "CHIP-8", "Chip-8"};
7476
const char* defaultDir = ""; // unify behavior: let OS choose last-used/home
7577
std::vector<std::string> files = open_file_dialog("Chip8", defaultDir, fileTypes);

macos/makefile

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ SDL_LIB = ../external/sdl/build/lib/libSDL2-2.0.0.dylib
4343
# Generated headers
4444
LICENSE_HEADER = ../shared/license.h
4545
BOOTROM_HEADER = ../shared/bootrom.h
46-
BOOTROM_SOURCE = ../roms/Kiwi8_logo_2.ch8
46+
47+
# ROM Profiles database (source of truth)
48+
PROFILES_INI = ../shared/profiles.ini
4749

4850
OBJS = audio.o \
4951
chip8.o \
@@ -60,11 +62,8 @@ OBJS = audio.o \
6062
imgui_impl_sdl.o \
6163
sha256.o
6264

63-
DEPS = $(OBJS:.o=.d)
64-
65-
PROFILES_INI = ../shared/profiles.ini
66-
6765
# Include auto-generated dependency files (must be before targets)
66+
DEPS = $(OBJS:.o=.d)
6867
-include $(DEPS)
6968

7069
.DEFAULT_GOAL := all
@@ -81,14 +80,14 @@ $(SDL_LIB):
8180

8281
# Generate license header from LICENSE file
8382
$(LICENSE_HEADER): ../LICENSE
84-
python3 ../tools/generate_license_header.py ../LICENSE $(LICENSE_HEADER)
83+
python3 ../tools/generate_license_header.py $< $@
8584

8685
# Generate bootrom header from ROM file
87-
$(BOOTROM_HEADER): $(BOOTROM_SOURCE)
88-
python3 ../tools/generate_bootrom_header.py $(BOOTROM_SOURCE) $(BOOTROM_HEADER)
86+
$(BOOTROM_HEADER): ../roms/Kiwi8_logo_2.ch8
87+
python3 ../tools/generate_bootrom_header.py $< $@
8988

9089
# Generate Info.plist from template with version substitution
91-
$(APP_MANIFEST): $(APP_MANIFEST).in
90+
$(APP_MANIFEST): src/Info.plist.in
9291
sed -e 's/@APP_NAME@/$(APP_NAME)/g' -e 's/@VERSION@/$(VERSION)/g' -e 's/@SUB_VERSION@/$(SUB_VERSION)/g' $< > $@
9392

9493
# Pattern rules for incremental compilation
@@ -110,13 +109,16 @@ $(APP_MANIFEST): $(APP_MANIFEST).in
110109
%.o: ../shared/%.cc $(LICENSE_HEADER) $(BOOTROM_HEADER)
111110
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@
112111

112+
%.i: %.c $(LICENSE_HEADER) $(BOOTROM_HEADER)
113+
$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -E $< -o $@
114+
113115
debug/profiles.ini: $(PROFILES_INI)
114116
mkdir -p debug
115-
cp $(PROFILES_INI) debug/profiles.ini
117+
cp $(PROFILES_INI) $@
116118

117119
release/$(APP_BUNDLE)/Contents/Resources/profiles.ini: $(PROFILES_INI)
118120
mkdir -p release/$(APP_BUNDLE)/Contents/Resources
119-
cp $(PROFILES_INI) release/$(APP_BUNDLE)/Contents/Resources/profiles.ini
121+
cp $(PROFILES_INI) $@
120122

121123
# debug executable
122124
debug/$(APP_EXE): $(SDL_LIB) $(OBJS)
@@ -161,10 +163,10 @@ release/$(APP_BUNDLE)/Contents/Frameworks/libSDL2-2.0.0.dylib: $(SDL_LIB)
161163
# .app bundle
162164
release/$(APP_BUNDLE): release/$(APP_BUNDLE)/Contents/MacOS/$(APP_EXE) release/$(APP_BUNDLE)/Contents/Info.plist release/$(APP_BUNDLE)/Contents/Resources/Kiwi8.icns release/$(APP_BUNDLE)/Contents/Frameworks/libSDL2-2.0.0.dylib
163165

164-
run-debug: debug/$(APP_EXE)
166+
run-debug: debug/$(APP_EXE) debug/profiles.ini
165167
./debug/$(APP_EXE)
166168

167-
run-release: release/$(APP_BUNDLE)
169+
run-release: release/$(APP_BUNDLE) release/$(APP_BUNDLE)/Contents/Resources/profiles.ini
168170
open release/$(APP_BUNDLE)
169171

170172
# Removes build artifacts (objects, app bundle) but keeps SDL

macos/src/open_file_dialog.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
}
4646

4747
int open_file_dialog(char *rom_filepath, size_t size) {
48+
if (rom_filepath == nullptr || size == 0) return -1;
49+
4850
std::vector<std::string> fileTypes = {"ch8", "CH8", "chip-8", "CHIP-8", "Chip-8"};
4951
const char* defaultDir = ""; // unify behavior: let OS choose last-used/home
5052
std::vector<std::string> files = open_file_dialog("Chip8", defaultDir, fileTypes);

shared/chip8.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ int chip8_load_bootrom() {
119119
memcpy(chip8.memory + ENTRY_POINT, bootrom, BOOTROM_SIZE);
120120

121121
/* Mark as bootrom (not user ROM) */
122-
chip8.rom_loaded = 0;
122+
chip8.rom_loaded = false;
123123
chip8.rom_filename[0] = '\0';
124124

125125
return 0;
@@ -174,7 +174,7 @@ int chip8_load_rom(const char *rom_filepath) {
174174
chip8.rom_filename[sizeof(chip8.rom_filename) - 1] = '\0';
175175

176176
/* Mark as user ROM (not bootrom) */
177-
chip8.rom_loaded = 1;
177+
chip8.rom_loaded = true;
178178
char notif_msg[TOAST_MSG_MAX];
179179
snprintf(notif_msg, sizeof(notif_msg), "ROM loaded: %s", chip8.rom_filename);
180180
toast_show(TOAST_SUCCESS, notif_msg);

shared/chip8.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern "C" {
1818
#define FONTS_SIZE 80
1919
#define CYCLES_PER_STEP 12 /* ~720 inst/sec if ticking at 60hz */
2020
#define MIN_CYCLES_PER_STEP 1
21-
#define MAX_CYCLES_PER_STEP 50
21+
#define MAX_CYCLES_PER_STEP 150 /* You've reached level 9000! */
2222
#define TICKS 60 /* hz - Timer count down rate */
2323

2424
static const unsigned char chip8_fontset[FONTS_SIZE] = {
@@ -46,7 +46,7 @@ struct chip8 {
4646
/* whether or not cpu is currently halted by opcode FX0A */
4747
bool cpu_halt;
4848

49-
/* whether or not emulation is currently paused. */
49+
/* whether or not emulation is currently paused via user. */
5050
bool paused;
5151

5252
/* All quirk toggles */
@@ -64,7 +64,7 @@ struct chip8 {
6464

6565
/* rom profile tracking */
6666
char rom_filename[PATH_MAX]; /* basename of currently loaded ROM */
67-
int rom_loaded; /* 1 if user ROM loaded, 0 if bootrom */
67+
bool rom_loaded;
6868

6969
/* registers */
7070
unsigned char V[NUM_REGISTERS];

shared/gui.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static void gui_help_windows(void) {
6464
"A cross-platform Chip-8 interpreter written\n"
6565
"in C-Style C++ using SDL2, ImGui, and OpenGL.\n"
6666
"\n"
67-
"<https://github.com/Diesel-Net/kiwi-8>\n"
67+
"https://github.com/Diesel-Net/kiwi-8\n"
6868
);
6969

7070
ImGui::End();

shared/open_file_dialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern "C" {
1010
/* Opens a file dialog to select a ROM file.
1111
* The selected file path is copied to `rom_filepath`.
1212
* The `size` parameter specifies the size of the `rom_filepath` buffer.
13-
* Returns 1 if a file was selected, 0 if cancelled, or -1 on error.
13+
* Returns 0 if a file was selected, 1 if cancelled, or -1 on error.
1414
*/
1515
int open_file_dialog(char *rom_filepath, size_t size);
1616

shared/profiles.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ const struct profile* profile_lookup(const sha256_hash_t *sha256) {
229229

230230
char matched_hash_hex[65];
231231
bytes_to_hex(profile_map[idx].key.bytes, matched_hash_hex, sizeof(matched_hash_hex));
232-
printf("Lookup result: found idx=%td name=%s\n", idx, matched_hash_hex, profile_map[idx].value.rom_name);
232+
printf("Lookup result: found idx=%td name=%s\n", idx, profile_map[idx].value.rom_name);
233233
quirks_print(&profile_map[idx].value.quirks, "Lookup quirks:");
234234
return &profile_map[idx].value;
235235
}

0 commit comments

Comments
 (0)