Skip to content

Commit

Permalink
Merge branch 'nesbox:main' into fsisdir
Browse files Browse the repository at this point in the history
  • Loading branch information
anescient authored Sep 9, 2024
2 parents c0b34f6 + 70ee0b6 commit 9e1aee3
Show file tree
Hide file tree
Showing 17 changed files with 227 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ CMakeSettings.json
tic_mruby_build_config.rb.lock
tic_mruby_wasm_build_config.rb.lock
build/mruby_vendor-prefix/
**/zig-cache
**/.zig-cache
**/zig-out
.cache
*~
Expand Down
9 changes: 4 additions & 5 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
path = vendor/lua
url = https://github.com/lua/lua.git
shallow = true
[submodule "vendor/sdl-gpu"]
path = vendor/sdl-gpu
url = https://github.com/aliceisjustplaying/sdl-gpu.git
shallow = true
branch = glew-update
[submodule "vendor/squirrel"]
path = vendor/squirrel
url = https://github.com/albertodemichelis/squirrel.git
Expand Down Expand Up @@ -91,3 +86,7 @@
path = vendor/jsmn
url = https://github.com/zserge/jsmn.git
shallow = true
[submodule "vendor/sdl-gpu"]
path = vendor/sdl-gpu
url = https://github.com/aliceisjustplaying/sdl-gpu.git
branch = master
24 changes: 14 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ if(NOT TIC80_TARGET)
set(TIC80_TARGET tic80)
endif()

if (BUILD_NO_OPTIMIZATION)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
endif()

if (BUILD_ASAN_DEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
endif()

if(NOT BUILD_SDL)
set(BUILD_SDLGPU OFF)
endif()
Expand Down Expand Up @@ -90,6 +80,20 @@ if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN AND NOT ANDROID AND NOT N3DS)
endif()
endif()

if (BUILD_NO_OPTIMIZATION)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
endif()

if (BUILD_ASAN_DEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")

if (LINUX AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -shared-libasan")
endif()
endif()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
Expand Down
140 changes: 140 additions & 0 deletions debug-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/bin/bash

FRESH=false
ASAN=false
PRO=false
DEBUG=false
STATIC=false
WARNINGS=false
USE_CLANG=false
BUILD_TYPE="MinSizeRel"
COMPILER_FLAGS=""
DEBUG_FLAGS=""
PRO_VERSION_FLAG=""
STATIC_FLAG=""
WARNING_FLAGS="-Wall -Wextra"

THREADS=$(nproc)

while (( "$#" )); do
case "$1" in
-f|--fresh)
FRESH=true
shift
;;
-a|--asan)
ASAN=true
shift
;;
-p|--pro)
PRO=true
shift
;;
-d|--debug)
DEBUG=true
shift
;;
-s|--static)
STATIC=true
shift
;;
-w|--warnings)
WARNINGS=true
shift
;;
-c|--clang)
USE_CLANG=true
shift
;;
-j|--jobs)
THREADS="$2"
shift 2
;;
--)
shift
break
;;
-*)
echo "Unknown option: $1" >&2
exit 1
;;
*)
echo "Invalid argument: $1" >&2
exit 1
;;
esac
done

if [ "$USE_CLANG" = true ]; then
CLANG=$(which clang)
CLANGPP=$(which clang++)
if [ -z "$CLANG" ] || [ -z "$CLANGPP" ]; then
echo "clang or clang++ not found. Please ensure they are installed and in your PATH."
exit 1
fi
COMPILER_FLAGS="-DCMAKE_C_COMPILER=$CLANG -DCMAKE_CXX_COMPILER=$CLANGPP"
echo "Using clang at $CLANG and clang++ at $CLANGPP"
else
GCC=$(which gcc)
GPP=$(which g++)
if [ -z "$GCC" ] || [ -z "$GPP" ]; then
echo "gcc or g++ not found. Please ensure they are installed and in your PATH."
exit 1
fi
COMPILER_FLAGS="-DCMAKE_C_COMPILER=$GCC -DCMAKE_CXX_COMPILER=$GPP"
echo "Using gcc at $GCC and g++ at $GPP"
fi

if [ "$FRESH" = true ]; then
rm -rf .cache CMakeCache.txt CMakeFiles/ cmake_install.cmake
rm -rf build && git restore 'build/*'
fi

if [ "$ASAN" = true ]; then
DEBUG=true
DEBUG_FLAGS="-DBUILD_NO_OPTIMIZATION=On -DBUILD_ASAN_DEBUG=On"
fi

if [ "$PRO" = true ]; then
PRO_VERSION_FLAG="-DBUILD_PRO=On"
fi

if [ "$DEBUG" = true ]; then
BUILD_TYPE="Debug"
fi

if [ "$STATIC" = true ]; then
STATIC_FLAG="-DBUILD_STATIC=On"
fi

if [ "$WARNINGS" = true ]; then
COMPILER_FLAGS="$COMPILER_FLAGS -DCMAKE_C_FLAGS=$WARNING_FLAGS -DCMAKE_CXX_FLAGS=$WARNING_FLAGS"
fi

echo
echo "+--------------------------------+-------+"
echo "| Build Options | Value |"
echo "+--------------------------------+-------+"
echo "| Fresh build (-f, --fresh) | $(printf "%-5s" $([ "$FRESH" = true ] && echo "Yes" || echo "No")) |"
echo "| Address Sanitizer (-a, --asan) | $(printf "%-5s" $([ "$ASAN" = true ] && echo "Yes" || echo "No")) |"
echo "| Pro version (-p, --pro) | $(printf "%-5s" $([ "$PRO" = true ] && echo "Yes" || echo "No")) |"
echo "| Debug build (-d, --debug) | $(printf "%-5s" $([ "$DEBUG" = true ] && echo "Yes" || echo "No")) |"
echo "| Static build (-s, --static) | $(printf "%-5s" $([ "$STATIC" = true ] && echo "Yes" || echo "No")) |"
echo "| Warnings (-w, --warnings) | $(printf "%-5s" $([ "$WARNINGS" = true ] && echo "Yes" || echo "No")) |"
echo "| Use Clang (-c, --clang) | $(printf "%-5s" $([ "$USE_CLANG" = true ] && echo "Yes" || echo "No")) |"
echo "| Parallel jobs (-j, --jobs) | $(printf "%-5s" "$THREADS") |"
echo "+--------------------------------+-------+"
echo

cd ./build || exit

cmake -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
$PRO_VERSION_FLAG \
-DBUILD_SDLGPU=On \
$DEBUG_FLAGS \
$COMPILER_FLAGS \
$STATIC_FLAG \
-DBUILD_WITH_ALL=On \
-DCMAKE_EXPORT_COMPILE_COMMANDS=On \
.. && \
cmake --build . --config "$BUILD_TYPE" --parallel "$THREADS"
2 changes: 1 addition & 1 deletion demos/bunny/wasmmark/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Bunnymark in Zig / WASM

This is a Zig project. To build it you'll need Zig 0.12 or newer.
This is a Zig project. To build it you'll need the latest Zig development release (`0.14.0-dev.1421+f87dd43c1` or newer).

### Building

Expand Down
2 changes: 1 addition & 1 deletion demos/bunny/wasmmark/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) !void {
const target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
const exe = b.addExecutable(.{
.name = "cart",
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
Expand Down
8 changes: 4 additions & 4 deletions demos/bunny/wasmmark/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

const tic = @import("tic80.zig");
const std = @import("std");
const RndGen = std.rand.DefaultPrng;
var rnd: std.rand.Random = undefined;
const RndGen = std.Random.DefaultPrng;
var rnd: std.Random = undefined;

const screenWidth = 240;
const screenHeight = 136;
Expand Down Expand Up @@ -150,14 +150,14 @@ export fn TIC() void {
}
}

// -- Update
// -- Update
var i: u32 = 0;
while (i < bunnyCount) {
bunnies[i].update();
i += 1;
}

// -- Draw
// -- Draw
tic.cls(15);
i = 0;
while (i < bunnyCount) {
Expand Down
2 changes: 1 addition & 1 deletion demos/wasm/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) !void {
const target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
const exe = b.addExecutable(.{
.name = "cart",
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
Expand Down
22 changes: 9 additions & 13 deletions demos/wasm/src/main.zig
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
const tic = @import("tic80.zig");

const TICGuy = struct {
x : i32 = 96,
y : i32 = 24,
x: i32 = 96,
y: i32 = 24,
};

var t : u16 = 0;
var mascot : TICGuy = .{};
var t: u16 = 0;
var mascot: TICGuy = .{};

export fn BOOT() void {}

export fn TIC() void {
tic.sync(.{
.sections = .{.tiles = true},
.bank = 1,
.toCartridge = true
});
tic.sync(.{ .sections = .{ .tiles = true }, .bank = 1, .toCartridge = true });

if (tic.btn(0)) {
mascot.y -= 1;
}
if (tic.btn(1)) {
mascot.y +=1;
mascot.y += 1;
}
if (tic.btn(2)) {
mascot.x -= 1;
Expand All @@ -31,17 +27,17 @@ export fn TIC() void {
}

tic.cls(13);
tic.spr(@as(i32, 1+t%60/30*2),mascot.x,mascot.y,.{
tic.spr(@as(i32, 1 + t % 60 / 30 * 2), mascot.x, mascot.y, .{
.transparent = &.{14},
.scale = 3,
.w = 2,
.h = 2,
});
_ = tic.print("HELLO WORLD!", 84, 84, .{.fixed = true});
_ = tic.print("HELLO WORLD!", 84, 84, .{ .fixed = true });

t += 1;
}

export fn BDR() void {}

export fn OVR() void {}
export fn OVR() void {}
20 changes: 8 additions & 12 deletions src/core/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,8 @@ static void drawMap(tic_core* core, const tic_map* src, s32 x, s32 y, s32 width,
for (s32 j = y, jj = sy; j < y + height; j++, jj += size)
for (s32 i = x, ii = sx; i < x + width; i++, ii += size)
{
s32 mi = i;
s32 mj = j;

while (mi < 0) mi += TIC_MAP_WIDTH;
while (mj < 0) mj += TIC_MAP_HEIGHT;
while (mi >= TIC_MAP_WIDTH) mi -= TIC_MAP_WIDTH;
while (mj >= TIC_MAP_HEIGHT) mj -= TIC_MAP_HEIGHT;
s32 mi = tic_modulo(i, TIC_MAP_WIDTH);
s32 mj = tic_modulo(j, TIC_MAP_HEIGHT);

s32 index = mi + mj * TIC_MAP_WIDTH;
RemapResult retile = { *(src->data + index), tic_no_flip, tic_no_rotate };
Expand Down Expand Up @@ -807,8 +802,8 @@ static tic_color triTexMapShader(const ShaderAttr* a, s32 pixel)
enum { MapWidth = TIC_MAP_WIDTH * TIC_SPRITESIZE, MapHeight = TIC_MAP_HEIGHT * TIC_SPRITESIZE,
WMask = TIC_SPRITESIZE - 1, HMask = TIC_SPRITESIZE - 1 };

s32 iu = tic_modulo(vars.x, MapWidth);
s32 iv = tic_modulo(vars.y, MapHeight);
s32 iu = tic_modulo(floor(vars.x), MapWidth);
s32 iv = tic_modulo(floor(vars.y), MapHeight);

u8 idx = data->map[(iv >> 3) * TIC_MAP_WIDTH + (iu >> 3)];
tic_tileptr tile = tic_tilesheet_gettile(&data->sheet, idx, true);
Expand All @@ -826,7 +821,8 @@ static tic_color triTexTileShader(const ShaderAttr* a, s32 pixel)

enum { WMask = TIC_SPRITESHEET_SIZE - 1, HMask = TIC_SPRITESHEET_SIZE * TIC_SPRITE_BANKS - 1 };

return shaderEnd(a, &vars, pixel, data->mapping[tic_tilesheet_getpix(&data->sheet, (s32)vars.x & WMask, (s32)vars.y & HMask)]);
return shaderEnd(a, &vars, pixel, data->mapping[tic_tilesheet_getpix(&data->sheet,
(s32)floor(vars.x) & WMask, (s32)floor(vars.y) & HMask)]);
}

static tic_color triTexVbankShader(const ShaderAttr* a, s32 pixel)
Expand All @@ -837,8 +833,8 @@ static tic_color triTexVbankShader(const ShaderAttr* a, s32 pixel)
if(!shaderStart(a, &vars, pixel))
return TRANSPARENT_COLOR;

s32 iu = tic_modulo(vars.x, TIC80_WIDTH);
s32 iv = tic_modulo(vars.y, TIC80_HEIGHT);
s32 iu = tic_modulo(floor(vars.x), TIC80_WIDTH);
s32 iv = tic_modulo(floor(vars.y), TIC80_HEIGHT);

return shaderEnd(a, &vars, pixel, data->mapping[tic_tool_peek4(data->vram->data, iv * TIC80_WIDTH + iu)]);
}
Expand Down
Loading

0 comments on commit 9e1aee3

Please sign in to comment.