| 244 | } |
| 245 | |
| 246 | static bool loadCodeFromFile(String codeFile, tic_cartridge* cart) { |
| 247 | if (!cart) return false; |
| 248 | |
| 249 | auto codeData = SharedContent.load(codeFile); |
| 250 | if (!codeData.first || codeData.second == 0) { |
| 251 | Error("TIC80Node: failed to load code file: {}", codeFile.toString()); |
| 252 | return false; |
| 253 | } |
| 254 | |
| 255 | s32 codeSize = s_cast<s32>(codeData.second); |
| 256 | if (codeSize > TIC_CODE_SIZE) { |
| 257 | Error("TIC80Node: failed to load code file: {}\ncode file size ({}) exceeds TIC_CODE_SIZE ({})", codeFile.toString(), codeSize, TIC_CODE_SIZE); |
| 258 | return false; |
| 259 | } |
| 260 | |
| 261 | memcpy(cart->code.data, codeData.first.get(), codeSize); |
| 262 | if (codeSize < TIC_CODE_SIZE) { |
| 263 | cart->code.data[codeSize] = '\0'; |
| 264 | } |
| 265 | |
| 266 | return true; |
| 267 | } |
| 268 | |
| 269 | static bool mergeCartResources(tic_cartridge* target, const tic_cartridge* source) { |
| 270 | if (!target || !source) return false; |