Skip to content

Commit 9fb8d65

Browse files
committed
Merge branch 'riiz'
2 parents 90b8ab2 + 8c375f9 commit 9fb8d65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1458
-145
lines changed

.clang-format

-18
This file was deleted.

.gitignore

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
*build*/
2-
.cache/
3-
CMakeFiles
4-
.vscode
5-
CMakeCache.txt
6-
*.o
1+
zig-cache/
2+
zig-out/

README.md

+58-44

build.zig

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.build.Builder) void {
4+
const target = b.standardTargetOptions(.{});
5+
const mode = b.standardReleaseOptions();
6+
7+
const exe = b.addExecutable("reckless-drivin", "src/main.zig");
8+
9+
exe.linkLibC();
10+
exe.addIncludeDir("src/c/");
11+
exe.addCSourceFile("src/c/lzrw.c", &.{
12+
// The default is to enable undefined behavior detection in C code. I have
13+
// verified that the packs are all decompressed fine, so there is no need
14+
// to sanitize. See https://github.com/ziglang/zig/wiki/FAQ#why-do-i-get-illegal-instruction-when-using-with-zig-cc-to-build-c-code
15+
// for more details.
16+
"-fno-sanitize=undefined",
17+
});
18+
19+
exe.setTarget(target);
20+
exe.setBuildMode(mode);
21+
exe.install();
22+
23+
const run_cmd = exe.run();
24+
run_cmd.step.dependOn(b.getInstallStep());
25+
if (b.args) |args| {
26+
run_cmd.addArgs(args);
27+
}
28+
29+
const run_step = b.step("run", "Run Reckless Drivin'");
30+
run_step.dependOn(&run_cmd.step);
31+
32+
const exe_tests = b.addTest("src/main.zig");
33+
exe_tests.linkLibC();
34+
exe_tests.addIncludeDir("src/c/");
35+
exe_tests.addCSourceFile("src/c/lzrw.c", &.{
36+
"-fno-sanitize=undefined",
37+
});
38+
39+
exe_tests.setTarget(target);
40+
exe_tests.setBuildMode(mode);
41+
42+
const test_step = b.step("test", "Run tests");
43+
test_step.dependOn(&exe_tests.step);
44+
}

CMakeLists.txt c/CMakeLists.txt

File renamed without changes.

Makefile c/Makefile

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/error.c c/src/error.c

File renamed without changes.
File renamed without changes.

src/gameframe.c c/src/gameframe.c

File renamed without changes.
File renamed without changes.

src/high.c c/src/high.c

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/initexit.c c/src/initexit.c

File renamed without changes.

src/input.c c/src/input.c

File renamed without changes.

src/interface.c c/src/interface.c

File renamed without changes.

src/main.c c/src/main.c

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/objects.c c/src/objects.c

File renamed without changes.

src/packs.c c/src/packs.c

File renamed without changes.
File renamed without changes.

src/pause.c c/src/pause.c

File renamed without changes.
File renamed without changes.

src/quickdraw.c c/src/quickdraw.c

File renamed without changes.

src/random.c c/src/random.c

File renamed without changes.

src/register.c c/src/register.c

File renamed without changes.
File renamed without changes.
File renamed without changes.

src/resource.c c/src/resource.c

File renamed without changes.

src/rle.c c/src/rle.c

File renamed without changes.

src/roaddraw.c c/src/roaddraw.c

File renamed without changes.

src/screen.c c/src/screen.c

File renamed without changes.

src/screenfx.c c/src/screenfx.c

File renamed without changes.

src/sound.c c/src/sound.c

File renamed without changes.

src/sprites.c c/src/sprites.c

File renamed without changes.

src/textfx.c c/src/textfx.c

File renamed without changes.

src/trig.c c/src/trig.c

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

scripts/generate-code.py

-51
This file was deleted.

src/lzrw.c src/c/lzrw.c

+19-15
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,26 @@ static struct compress_identity identity = {
102102
"Public Domain" /* Vendor of algorithm. */
103103
};
104104

105-
static void lzrw3a_compress_compress(uint8_t *, uint8_t *, uint32_t, uint8_t *,
105+
static void lzrw3a_compress_compress(uint8_t *, const uint8_t *, uint32_t, uint8_t *,
106106
uint64_t *);
107-
static void lzrw3a_compress_decompress(uint8_t *, uint8_t *, uint32_t,
107+
static void lzrw3a_compress_decompress(uint8_t *, const uint8_t *, uint32_t,
108108
uint8_t *, uint64_t *);
109109

110+
111+
/******************************************************************************/
112+
113+
struct compress_identity lzrw_identity() {
114+
return identity;
115+
}
116+
110117
/******************************************************************************/
111118

112119
/* This function is the only function exported by this module. */
113120
/* Depending on its first parameter, the function can be requested to */
114121
/* compress a block of memory, decompress a block of memory, or to identify */
115122
/* itself. For more information, see the specification file "compress.h". */
116123

117-
void lzrw3a_compress(uint16_t action, uint8_t *wrk_mem, uint8_t *src_adr,
124+
void lzrw3a_compress(uint16_t action, uint8_t *wrk_mem, const uint8_t *src_adr,
118125
uint32_t src_len, uint8_t *dst_adr, uint64_t *p_dst_len) {
119126
switch (action) {
120127
case COMPRESS_ACTION_COMPRESS:
@@ -386,7 +393,7 @@ void lzrw3a_compress(uint16_t action, uint8_t *wrk_mem, uint8_t *src_adr,
386393

387394
/******************************************************************************/
388395

389-
static void lzrw3a_compress_compress(uint8_t *p_wrk_mem, uint8_t *p_src_first,
396+
static void lzrw3a_compress_compress(uint8_t *p_wrk_mem, const uint8_t *p_src_first,
390397
uint32_t src_len, uint8_t *p_dst_first,
391398
uint64_t *p_dst_len)
392399
/* Input : Hand over the required amount of working memory in p_wrk_mem. */
@@ -680,7 +687,7 @@ static void lzrw3a_compress_compress(uint8_t *p_wrk_mem, uint8_t *p_src_first,
680687

681688
/******************************************************************************/
682689

683-
static void lzrw3a_compress_decompress(uint8_t *p_wrk_mem, uint8_t *p_src_first,
690+
static void lzrw3a_compress_decompress(uint8_t *p_wrk_mem, const uint8_t *p_src_first,
684691
uint32_t src_len, uint8_t *p_dst_first,
685692
uint64_t *p_dst_len)
686693
/* Input : Hand over the required amount of working memory in p_wrk_mem. */
@@ -738,11 +745,10 @@ static void lzrw3a_compress_decompress(uint8_t *p_wrk_mem, uint8_t *p_src_first,
738745

739746
/* Check the leading copy flag to see if the compressor chose to use a copy */
740747
/* operation instead of a compression operation. If a copy operation was */
741-
/* used, then all we need to do is copy the data over, set the output length
742-
*/
748+
/* used, then all we need to do is copy the data over, set the output length */
743749
/* and return. */
744750
if (*p_src_first == FLAG_COPY) {
745-
memcpy(p_src_first, p_src_first + FLAG_BYTES, src_len - FLAG_BYTES);
751+
memcpy(p_dst_first, p_src_first + FLAG_BYTES, src_len - FLAG_BYTES);
746752
*p_dst_len = src_len - FLAG_BYTES;
747753
return;
748754
}
@@ -873,12 +879,9 @@ static void lzrw3a_compress_decompress(uint8_t *p_wrk_mem, uint8_t *p_src_first,
873879
/* End of LZRW3-A.C */
874880
/******************************************************************************/
875881

876-
#include <stdio.h>
877-
878-
#include "resource.h"
879-
882+
/*
880883
void LZRWDecodeHandle(Handle *handle) {
881-
/* Need the handle size to properly decompress. */
884+
// Need the handle size to properly decompress.
882885
uint32_t handle_len = GetHandleSize(*handle);
883886
884887
unsigned char *working_mem = malloc(sizeof *working_mem * identity.memory);
@@ -897,13 +900,14 @@ void LZRWDecodeHandle(Handle *handle) {
897900
handle_len - 4, dst_mem, &dst_len);
898901
free(working_mem);
899902
900-
/* Reallocate the dst block to be exactly the right size. */
903+
// Reallocate the dst block to be exactly the right size.
901904
dst_mem = realloc(dst_mem, dst_len);
902905
if (!dst_mem) {
903906
return;
904907
}
905908
906909
**handle = dst_mem;
907-
/* Store the new handle length. */
910+
// Store the new handle length.
908911
SetHandleSize(*handle, dst_len);
909912
}
913+
*/

src/include/lzrw.h src/c/lzrw.h

+5-11
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
#ifndef LZRW_H
123123
#define LZRW_H
124124

125+
#include <stdbool.h>
125126
#include <stdint.h>
126127
#include <string.h>
127128

@@ -155,11 +156,14 @@ struct compress_identity {
155156
char *vendor; /* Where the algorithm can be obtained. */
156157
};
157158

159+
/* returns id information for the compression algorithm */
160+
struct compress_identity lzrw_identity();
161+
158162
void lzrw3a_compress(/* Single function interface to compression algorithm. */
159163
uint16_t action, /* Action to be performed. */
160164
uint8_t *wrk_mem, /* Working memory temporarily given to
161165
routine to use. */
162-
uint8_t *src_adr, /* Address of input data. */
166+
const uint8_t *src_adr, /* Address of input data. */
163167
uint32_t src_len, /* Length of input data. */
164168
uint8_t *dst_adr, /* Address of output data. */
165169
uint64_t *p_dst_len /* Pointer to a longword where routine
@@ -173,14 +177,4 @@ void lzrw3a_compress(/* Single function interface to compression algorithm. */
173177
/* End of COMPRESS.H */
174178
/******************************************************************************/
175179

176-
#include "defines.h"
177-
178-
/**
179-
* Decompress the bytes referenced by a handle.
180-
*
181-
* On success, the given Resource Handle is converted to a Memory Handle and
182-
* will need to be freed with DisposeHandle.
183-
*/
184-
void LZRWDecodeHandle(Handle *handle);
185-
186180
#endif /* LZRW_H */

0 commit comments

Comments
 (0)