Skip to content

Commit

Permalink
Fix bug with -no-lm-aux where it wouldn't generate _customsize.bin
Browse files Browse the repository at this point in the history
  • Loading branch information
Atari2 committed Jan 22, 2025
1 parent 39fe7a1 commit 9d3dc7d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Version 1.43 (TBD)
- (Atari2.0) Fix bug with -no-lm-aux where it wouldn't generate \_customsize.bin and thus fail insertion.
- (Atari2.0) Revert a change from 1.41 where CFG sprites would always show up in the custom sprite collection in LM, instead now to have a CFG sprite display in the LM custom sprite collection, append "display" to the corresponding list entry.

## Version 1.42 (March 27, 2024)
Expand Down
4 changes: 2 additions & 2 deletions src/file_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ unsigned char *read_all(const char *file_name, bool text_mode, unsigned int mini
return file_data;
}

patchfile write_all(unsigned char* data, std::string_view file_name, unsigned int size) {
patchfile write_all(const unsigned char* data, std::string_view file_name, unsigned int size) {
patchfile file{std::string{file_name}, static_cast<patchfile::openflags>(std::ios::out | std::ios::binary)};
file.fwrite(data, size);
file.close();
return file;
}

patchfile write_all(unsigned char* data, std::string_view dir, std::string_view file_name, unsigned int size) {
patchfile write_all(const unsigned char* data, std::string_view dir, std::string_view file_name, unsigned int size) {
std::string fullpath{dir};
fullpath += file_name;
return write_all(data, fullpath, size);
Expand Down
20 changes: 13 additions & 7 deletions src/file_io.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#ifndef FILES_IO_H
#define FILES_IO_H

#include "structs.h"
#include <cstdio>
#include <cstdlib>
#include <string_view>
#include "structs.h"

FILE *open(const char *name, const char *mode);
size_t file_size(FILE *file);
[[nodiscard]] unsigned char *read_all(const char *file_name, bool text_mode = false, unsigned int minimum_size = 0u);
[[nodiscard]] patchfile write_all(unsigned char *data, std::string_view file_name, unsigned int size);
[[nodiscard]] patchfile write_all(unsigned char* data, std::string_view dir, std::string_view file_name,
FILE* open(const char* name, const char* mode);
size_t file_size(FILE* file);
[[nodiscard]] unsigned char* read_all(const char* file_name, bool text_mode = false, unsigned int minimum_size = 0u);
[[nodiscard]] patchfile write_all(const unsigned char* data, std::string_view file_name, unsigned int size);
[[nodiscard]] patchfile write_all(const unsigned char* data, std::string_view dir, std::string_view file_name,
unsigned int size);

template <size_t N>
[[nodiscard]] patchfile write_all(const unsigned char (&data)[N], std::string_view dir, std::string_view file_name) {
return write_all(data, dir, file_name, N);
}
template <size_t N> [[nodiscard]] patchfile write_all(const unsigned char (&data)[N], std::string_view file_name) {
return write_all(data, file_name, N);
}
#endif
34 changes: 29 additions & 5 deletions src/lmdata.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "lmdata.h"
#include "iohandler.h"
#include <sstream>
#include <cstdio>
#include <sstream>

static const sprite* from_table(const sprite (&sprite_list)[MAX_SPRITE_COUNT], int level, int number, bool perlevel) {
if (!perlevel)
Expand All @@ -16,7 +16,8 @@ static const sprite* from_table(const sprite (&sprite_list)[MAX_SPRITE_COUNT], i
return nullptr;
}

std::pair<size_t, std::span<const map16>> generate_s16_data(const sprite* spr, const map16* const map, size_t map_size) {
std::pair<size_t, std::span<const map16>> generate_s16_data(const sprite* spr, const map16* const map,
size_t map_size) {
size_t map16_tile = find_free_map(map, map_size, spr->map_data.size());
auto map16_span = std::span{spr->map_data.data(), spr->map_data.size()};
return std::make_pair(map16_tile, map16_span);
Expand Down Expand Up @@ -88,7 +89,7 @@ std::string generate_ssc_data(const sprite* spr, int i, size_t map16_tile) {
const auto& gfx = d.gfx_files;
ssc << fstring("%02X %02X ", i, prefix + 0x8);
ssc << fstring("%X,%X,%X,%X ", gfx.gfx_files[0].value(), gfx.gfx_files[1].value(), gfx.gfx_files[2].value(),
gfx.gfx_files[3].value());
gfx.gfx_files[3].value());
ssc << '\n';
}

Expand Down Expand Up @@ -116,8 +117,8 @@ std::string generate_ssc_data(const sprite* spr, int i, size_t map16_tile) {
return ssc.str();
}


bool generate_lm_data(const sprite (&sprite_list)[MAX_SPRITE_COUNT], map16 (&map)[MAP16_SIZE], unsigned char (&extra_bytes)[0x200], FILE* ssc, FILE* mwt, FILE* mw2, FILE* s16, bool perlevel) {
bool generate_lm_data(const sprite (&sprite_list)[MAX_SPRITE_COUNT], map16 (&map)[MAP16_SIZE],
unsigned char (&extra_bytes)[0x200], FILE* ssc, FILE* mwt, FILE* mw2, FILE* s16, bool perlevel) {
auto& io = iohandler::get_global();
for (int i = 0; i < 0x100; i++) {
auto* spr = from_table(sprite_list, 0x200, i, perlevel);
Expand Down Expand Up @@ -170,4 +171,27 @@ bool generate_lm_data(const sprite (&sprite_list)[MAX_SPRITE_COUNT], map16 (&map
fputc(0xFF, mw2); // binary data ends with 0xFF (see SMW level data format)
fwrite(map, sizeof(map16), MAP16_SIZE, s16);
return true;
}

bool generate_lm_data_ex_bytes_only(const sprite (&sprite_list)[MAX_SPRITE_COUNT], unsigned char (&extra_bytes)[0x200],
bool perlevel) {
for (int i = 0; i < 0x100; i++) {
auto* spr = from_table(sprite_list, 0x200, i, perlevel);
if (!spr || (perlevel && i >= 0xB0 && i < 0xC0)) {
extra_bytes[i] = 7; // 3 bytes + 4 extra bytes because the old one broke basically any sprite that wasn't
// using exactly 9 extra bytes
extra_bytes[i + 0x100] = 7; // 12 was wrong anyway, should've been 15
} else {
// line number within the list file indicates we've got a filled out sprite
if (spr->line) {
extra_bytes[i] = (unsigned char)(3 + spr->byte_count);
extra_bytes[i + 0x100] = (unsigned char)(3 + spr->extra_byte_count);
// no line means unused sprite, so just set to default 3.
} else {
extra_bytes[i] = 3;
extra_bytes[i + 0x100] = 3;
}
}
}
return true;
}
3 changes: 2 additions & 1 deletion src/lmdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

bool generate_lm_data(const sprite (&sprite_list)[MAX_SPRITE_COUNT], map16 (&map)[MAP16_SIZE],
unsigned char (&extra_bytes)[0x200], FILE* ssc, FILE* mwt, FILE* mw2, FILE* s16, bool perlevel);

bool generate_lm_data_ex_bytes_only(const sprite (&sprite_list)[MAX_SPRITE_COUNT], unsigned char (&extra_bytes)[0x200],
bool perlevel);
std::pair<size_t, std::span<const map16>> generate_s16_data(const sprite* spr, const map16* map, size_t map_size);
std::string generate_mwt_data(const sprite* spr, const collection& c, bool first);
std::vector<char> generate_mw2_data(const sprite* spr, const collection& c);
Expand Down
7 changes: 6 additions & 1 deletion src/sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2027,12 +2027,17 @@ PIXI_EXPORT int pixi_run(int argc, const char** argv, bool skip_first) {
if (!generate_lm_data(sprite_list, map, extra_bytes, ssc, mwt, mw2, s16, cfg.PerLevel))
return EXIT_FAILURE;

binfiles.push_back(write_all(extra_bytes, asm_path, "_customsize.bin", 0x200));
binfiles.push_back(write_all(extra_bytes, asm_path, "_customsize.bin"));
// close all the files.
fclose(s16);
fclose(ssc);
fclose(mwt);
fclose(mw2);
} else {
if (!generate_lm_data_ex_bytes_only(sprite_list, extra_bytes, cfg.PerLevel))
return EXIT_FAILURE;

binfiles.push_back(write_all(extra_bytes, asm_path, "_customsize.bin"));
}

// apply the actual patches
Expand Down

0 comments on commit 9d3dc7d

Please sign in to comment.