Skip to content

Commit

Permalink
Merge pull request #6 from burhanr13/c23
Browse files Browse the repository at this point in the history
c23
  • Loading branch information
burhanr13 authored Jan 8, 2025
2 parents 57b4370 + 92a0d9e commit 2b87ce2
Show file tree
Hide file tree
Showing 37 changed files with 380 additions and 267,741 deletions.
20 changes: 10 additions & 10 deletions .github/mac-bundle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ PATH="$PATH:/usr/libexec"

# Construct the app iconset.
mkdir icon.iconset
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 72 -resize 16x16 -composite icon.iconset/icon_16x16.png
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 144 -resize 32x32 -composite icon.iconset/[email protected]
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 72 -resize 32x32 -composite icon.iconset/icon_32x32.png
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 144 -resize 64x64 -composite icon.iconset/[email protected]
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 72 -resize 128x128 -composite icon.iconset/icon_128x128.png
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 144 -resize 256x256 -composite icon.iconset/[email protected]
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 72 -resize 256x256 -composite icon.iconset/icon_256x256.png
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 144 -resize 512x512 -composite icon.iconset/[email protected]
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 72 -resize 512x512 -composite icon.iconset/icon_512x512.png
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 144 -resize 1024x1024 -composite icon.iconset/[email protected]
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 72 -resize 16x16 icon.iconset/icon_16x16.png
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 144 -resize 32x32 icon.iconset/[email protected]
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 72 -resize 32x32 icon.iconset/icon_32x32.png
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 144 -resize 64x64 icon.iconset/[email protected]
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 72 -resize 128x128 icon.iconset/icon_128x128.png
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 144 -resize 256x256 icon.iconset/[email protected]
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 72 -resize 256x256 icon.iconset/icon_256x256.png
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 144 -resize 512x512 icon.iconset/[email protected]
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 72 -resize 512x512 icon.iconset/icon_512x512.png
convert images/logo.png -alpha on -background none -units PixelsPerInch -density 144 -resize 1024x1024 icon.iconset/[email protected]
iconutil --convert icns icon.iconset
rm -r icon.iconset

Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: install dependencies
run: sudo apt install libsdl2-dev libglew-dev libxxhash-dev libxbyak-dev libcapstone-dev
run: |
sudo apt install libsdl2-dev libglew-dev libxxhash-dev libxbyak-dev libcapstone-dev
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 19
- name: build
run: make USER=1
- uses: actions/upload-artifact@v4
Expand All @@ -24,7 +28,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: install dependencies
run: brew install sdl2 glew xxhash xbyak capstone
run: brew install llvm sdl2 glew xxhash xbyak capstone
- name: build
run: make USER=1

Expand Down
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
TARGET_EXEC := ctremu

CC := gcc
CXX := g++
CC := clang-19
CXX := clang++-19

CSTD := -std=gnu17
CXXSTD := -std=gnu++17
CSTD := -std=gnu23
CXXSTD := -std=gnu++23
CFLAGS := -Wall -Wimplicit-fallthrough -Wno-format -Wno-unused-variable -Wno-unused-result -Werror
CFLAGS_RELEASE := -O3 -DJIT_FASTMEM
CFLAGS_DEBUG := -g -fsanitize=address
Expand All @@ -21,8 +21,10 @@ else
endif

ifeq ($(shell uname),Darwin)
CFLAGS += -arch x86_64
CPPFLAGS += -I/opt/homebrew/include
CC := /usr/local/opt/llvm/bin/clang
CXX := /usr/local/opt/llvm/bin/clang++
CFLAGS += -target x86_64-apple-darwin
CPPFLAGS += -I/usr/local/include -I/opt/homebrew/include
LDFLAGS := -L/usr/local/lib -L/opt/homebrew/lib $(LDFLAGS)
LDFLAGS += -framework OpenGL -lGLEW
else
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ You need the following dependencies installed to build and run:

They can all be installed with your local package manager (brew on macos, apt on ubuntu, etc).

To build use `make`. You can pass some options to make, `USER=1` to compile a user build with lto, and `DEBUG=1` for unoptimized build with debug symbols. I have tested on both Linux with gcc and MacOS with Apple clang. Currently Windows is not natively supported, but you should be able to use the emulator on Windows through WSL (Windows Subsystem for Linux).
To build use `make`. You can pass some options to make, `USER=1` to compile a user build with lto, and `DEBUG=1` for unoptimized build with debug symbols. You need a new compiler that supports C23 such as `clang-19`. Right now we use clang on both linux and MacOS. Currently Windows is not natively supported, but you should be able to use the emulator on Windows through WSL (Windows Subsystem for Linux).

Note for M1 Mac users: we currently only have x86 JIT backends, so you will need to install the x86 version of brew. A guide can be found [here](https://gist.github.com/progrium/b286cd8c82ce0825b2eb3b0b3a0720a0).

Expand Down
2 changes: 1 addition & 1 deletion src/3ds.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void e3ds_update_datetime(E3DS* s) {
u32 unk[4];
}* datetime = PTR(SHARED_PAGE + 0x20);

datetime->time = (time(NULL) + 2208988800) * 1000;
datetime->time = (time(nullptr) + 2'208'988'800) * 1000;
datetime->systemtick = s->sched.now;
datetime->unk[0] = 0xffb0ff0;
}
Expand Down
12 changes: 5 additions & 7 deletions src/3ds.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ typedef struct _3DS {
#define FCRAMSIZE BIT(27)
#define VRAMSIZE (6 * BIT(20))

#define FCRAM_PBASE BIT(29)
#define VRAM_PBASE 0x18000000
#define FCRAM_PBASE 0x2000'0000
#define VRAM_PBASE 0x1800'0000

#define HEAP_BASE BIT(27)

#define STACK_BASE BIT(28)
#define STACK_BASE 0x1000'0000
#define STACK_SIZE BIT(14)

#define LINEAR_HEAP_BASE 0x14000000
#define LINEAR_HEAP_BASE 0x1400'0000

#define VRAMBASE 0x1f000000
#define VRAMBASE 0x1f00'0000

#define DSPMEM 0x1ff50000
#define DSPMEMSIZE BIT(15)
Expand Down
6 changes: 3 additions & 3 deletions src/arm/arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ ArmInstrFormat arm_lookup[BIT(8)][BIT(4)];

// ArmExecFunc func_lookup[BIT(8)][BIT(4)];

__attribute__((constructor)) void arm_generate_lookup() {
[[gnu::constructor]] void arm_generate_lookup() {
for (int dechi = 0; dechi < BIT(8); dechi++) {
for (int declo = 0; declo < BIT(4); declo++) {
arm_lookup[dechi][declo] =
arm_decode_instr((ArmInstr){.dechi = dechi, .declo = declo});
arm_decode_instr((ArmInstr) {.dechi = dechi, .declo = declo});
// func_lookup[dechi][declo] = exec_funcs[arm_lookup[dechi][declo]];
}
}
Expand Down Expand Up @@ -741,7 +741,7 @@ ArmInstrFormat arm_decode_instr(ArmInstr instr) {
// }
// if (reg == 13) return &cpu->banked_sp[0];
// if (reg == 14) return &cpu->banked_lr[0];
// return NULL;
// return nullptr;
// }

// DECL_ARM_EXEC(block_trans) {
Expand Down
10 changes: 5 additions & 5 deletions src/arm/jit/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void destroy_jit_block(JITBlock* block) {
#endif

block->cpu->jit_cache[block->attrs][block->start_addr >> 16]
[(block->start_addr & 0xffff) >> 1] = NULL;
[(block->start_addr & 0xffff) >> 1] = nullptr;
backend_free(block->backend);
Vec_foreach(l, block->linkingblocks) {
if (!(block->cpu->jit_cache[l->attrs] &&
Expand Down Expand Up @@ -127,7 +127,7 @@ JITBlock* get_jitblock(ArmCore* cpu, u32 attrs, u32 addr) {
cpu->jit_cache[attrs][addrhi] = calloc(BIT(16) >> 1, sizeof(JITBlock*));
}

JITBlock* block = NULL;
JITBlock* block = nullptr;
if (!cpu->jit_cache[attrs][addrhi][addrlo]) {
u32 old = cpu->cpsr.jitattrs;
cpu->cpsr.jitattrs = attrs;
Expand All @@ -149,15 +149,15 @@ void jit_free_all(ArmCore* cpu) {
for (int k = 0; k < BIT(16) >> 1; k++) {
if (cpu->jit_cache[i][j][k]) {
destroy_jit_block(cpu->jit_cache[i][j][k]);
cpu->jit_cache[i][j][k] = NULL;
cpu->jit_cache[i][j][k] = nullptr;
}
}
free(cpu->jit_cache[i][j]);
cpu->jit_cache[i][j] = NULL;
cpu->jit_cache[i][j] = nullptr;
}
}
free(cpu->jit_cache[i]);
cpu->jit_cache[i] = NULL;
cpu->jit_cache[i] = nullptr;
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/arm/jit/translator.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,15 @@ DECL_ARM_COMPILE(data_proc) {
shiftc = EMITVV(GETCIFZ, shamt, shiftc);
} else {
op2 = compile_shifter(block, cpu, shift_type, op2, shamt,
immshift, NULL);
immshift, nullptr);
}
} else {
if (usingop1) op1 = EMIT_LOAD_REG(instr.data_proc.rn);
op2 = EMIT_LOAD_REG(rm);

shamt = shift >> 3;
op2 = compile_shifter(block, cpu, shift_type, op2, shamt, immshift,
instr.data_proc.s ? &shiftc : NULL);
instr.data_proc.s ? &shiftc : nullptr);
}
}
if (usingop1 && instr.data_proc.rn == 15 && instr.data_proc.rd != 15 &&
Expand Down Expand Up @@ -885,7 +885,8 @@ DECL_ARM_COMPILE(single_trans) {
u8 shift = instr.single_trans.offset >> 4;
u8 shamt = shift >> 3;
u8 op = (shift >> 1) & 3;
voffset = compile_shifter(block, cpu, op, voffset, shamt, true, NULL);
voffset =
compile_shifter(block, cpu, op, voffset, shamt, true, nullptr);
} else {
voffset = instr.single_trans.offset;
}
Expand Down
2 changes: 1 addition & 1 deletion src/arm/thumb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ArmInstr thumb_lookup[BIT(16)];

__attribute__((constructor)) void thumb_generate_lookup() {
[[gnu::constructor]] void thumb_generate_lookup() {
for (int i = 0; i < BIT(16); i++) {
thumb_lookup[i] = thumb_decode_instr((ThumbInstr){i});
}
Expand Down
8 changes: 3 additions & 5 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#ifndef TYPES_H
#define TYPES_H

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define eprintf(format, ...) fprintf(stderr, format __VA_OPT__(, ) __VA_ARGS__)
#define println() printf("\n")
#define printfln(format, ...) printf(format "\n"__VA_OPT__(, ) __VA_ARGS__)

extern bool g_infologs;
Expand Down Expand Up @@ -85,7 +83,7 @@ typedef float fvec2[2];
size_t cap; \
}

#define Vec_init(v) ((v).d = NULL, (v).size = 0, (v).cap = 0)
#define Vec_init(v) ((v).d = nullptr, (v).size = 0, (v).cap = 0)
#define Vec_assn(v1, v2) \
((v1).d = (v2).d, (v1).size = (v2).size, (v1).cap = (v2).cap)
#define Vec_free(v) (free((v).d), Vec_init(v))
Expand Down Expand Up @@ -123,7 +121,7 @@ typedef float fvec2[2];
({ \
(n)->next->prev = (n)->prev; \
(n)->prev->next = (n)->next; \
(n)->prev = (n)->next = NULL; \
(n)->prev = (n)->next = nullptr; \
})

#define LRU_use(c, e) \
Expand All @@ -142,7 +140,7 @@ typedef float fvec2[2];
typeof(&(c).root) e = (c).root.prev; \
(c).root.prev = (c).root.prev->prev; \
(c).root.prev->next = &(c).root; \
e->next = e->prev = NULL; \
e->next = e->prev = nullptr; \
(c).size--; \
e; \
})
Expand Down
2 changes: 1 addition & 1 deletion src/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void kobject_destroy(E3DS* s, KObject* o) {
klist_remove(cur);
}

s->process.threads[t->id] = NULL;
s->process.threads[t->id] = nullptr;

thread_reschedule(s);
break;
Expand Down
4 changes: 2 additions & 2 deletions src/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ u32 handle_new(E3DS* s);
#define HANDLE_SET(h, o) (s->process.handles[h - HANDLE_BASE] = (KObject*) (o))
#define HANDLE_GET(h) \
(((h - HANDLE_BASE) < HANDLE_MAX) ? s->process.handles[h - HANDLE_BASE] \
: NULL)
: nullptr)
#define HANDLE_GET_TYPED(h, t) \
(((h - HANDLE_BASE) < HANDLE_MAX && s->process.handles[h - HANDLE_BASE] && \
s->process.handles[h - HANDLE_BASE]->type == t) \
? (void*) s->process.handles[h - HANDLE_BASE] \
: NULL)
: nullptr)

void klist_insert(KListNode** l, KObject* o);
void klist_remove(KListNode** l);
Expand Down
2 changes: 1 addition & 1 deletion src/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ u32 load_elf(E3DS* s, char* filename) {

fclose(fp);

s->romimage.fp = NULL;
s->romimage.fp = nullptr;

e3ds_vmmap(s, STACK_BASE - STACK_SIZE, STACK_SIZE, PERM_RW, MEMST_PRIVATE,
false);
Expand Down
15 changes: 8 additions & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void hotkey_press(SDL_KeyCode key) {
}

void update_input(E3DS* s, SDL_GameController* controller) {
const Uint8* keys = SDL_GetKeyboardState(NULL);
const Uint8* keys = SDL_GetKeyboardState(nullptr);

PadState btn;
btn.a = keys[SDL_SCANCODE_L];
Expand Down Expand Up @@ -123,7 +123,7 @@ int main(int argc, char** argv) {

SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER);

SDL_GameController* controller = NULL;
SDL_GameController* controller = nullptr;
if (SDL_NumJoysticks() > 0) {
controller = SDL_GameControllerOpen(0);
}
Expand All @@ -150,17 +150,18 @@ int main(int argc, char** argv) {
#ifdef GLDEBUGCTX
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(glDebugOutput, NULL);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL,
glDebugMessageCallback(glDebugOutput, nullptr);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr,
GL_TRUE);
#endif

#ifdef USE_TFD
if (!ctremu.romfile) {
const char* filetypes[] = {"*.3ds", "*.cci", "*.cxi", "*.app", "*.elf"};
ctremu.romfile = tinyfd_openFileDialog(
EMUNAME ": Open Game", NULL, sizeof filetypes / sizeof filetypes[0],
filetypes, "3DS Executables", false);
ctremu.romfile =
tinyfd_openFileDialog(EMUNAME ": Open Game", nullptr,
sizeof filetypes / sizeof filetypes[0],
filetypes, "3DS Executables", false);
}
#endif

Expand Down
Loading

0 comments on commit 2b87ce2

Please sign in to comment.