Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check in BizHawk build scripts #3272

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

YoshiRulz
Copy link

@YoshiRulz YoshiRulz commented Aug 10, 2024

Based on d82fc3d, which was the last change we pulled, and doesn't include more recent commits to master. So in the unlikely event that this works, it may break after merge.

How much of this you keep, or drop, or keep with modifications is up to you. The C FFI can be changed slightly too.

re: TASEmulators/BizHawk#2312

Copy link
Member

@endrift endrift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should remove the XCode project if no one is using it. Further, I can already confirm this won't build. I'd like to at least try to make sure the bizinterface DLL builds via CI so I know when I'm gonna be breaking things for you. It looks like the last time this was downstreamed was several months ago, as you reference some files I've removed, so I'd like it if you can get it building again before I merge this.

cinema/gb/mooneye-gb/misc/boot_hwio-C/xbaseline_0000.png Outdated Show resolved Hide resolved
@YoshiRulz
Copy link
Author

YoshiRulz commented Aug 14, 2024

Removed files and dropped one source entry from the .mak. Though I don't think it will build anyway because it assumes it's in a submodule in the BizHawk repo.

Copy link
Member

@endrift endrift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of my concerns are about if this builds, if it continues to build (I might want to set up some sort of CI?) and that it doesn't diverge from downstream (at least, not for too long).

I'm A-OK with it being upstreamed if these things can be managed adequately.

cd "$BASEDIR/src/platform/bizhawk/mingw"
fi
make clean
make -j4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommendation:

Suggested change
make -j4
make -j${JOBS:-4}

This lets you override the job number from the environment if desired, but defaults to 4 if it's not present.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gentoo and Arch have established a precedent for something like make ${MAKEOPTS:-j4}

-Wall -Wno-stringop-overflow -Wno-lto-type-mismatch \
-Wno-ignored-optimization-argument -Wno-unknown-warning-option \
-DMINIMAL_CORE=2 -DDISABLE_THREADING -DM_CORE_GBA \
-DCOLOR_16_BIT -DMGBA_STANDALONE -DENABLE_DEBUGGERS \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to need to test if this compiles. I changed a bunch of the build flags somewhat recently, so this may not work anymore.

src/platform/bizhawk/base.mak Show resolved Hide resolved
src/platform/bizhawk/bizinterface.c Outdated Show resolved Hide resolved
@endrift
Copy link
Member

endrift commented Jan 2, 2025

I believe CPP just merged some new changes into BizHawk a few days ago. Could you rebase this PR on those changes?

@YoshiRulz
Copy link
Author

changes in force-push
--- old.patch
+++ new.patch
@@ -1,21 +1,21 @@
-From ff542cbb07d1ff7e34023c681a178f0d790b675b Mon Sep 17 00:00:00 2001
+From 980e0209da83b2287f17a54ea14bfd635dabcfe9 Mon Sep 17 00:00:00 2001
 From: YoshiRulz <OSSYoshiRulz+git@gmail.com>
-Date: Sat, 10 Aug 2024 11:32:08 +1000
+Date: Thu, 2 Jan 2025 22:42:51 +1000
 Subject: [PATCH] Rebase branch bizhawk-0.11
 
 ---
  bizhawk-make-install.sh             |  11 +
  src/platform/bizhawk/.gitignore     |   2 +
- src/platform/bizhawk/base.mak       | 130 ++++++
- src/platform/bizhawk/bizinterface.c | 623 ++++++++++++++++++++++++++++
+ src/platform/bizhawk/base.mak       | 134 ++++++
+ src/platform/bizhawk/bizinterface.c | 655 ++++++++++++++++++++++++++++
  src/platform/bizhawk/linux/Makefile |  30 ++
  src/platform/bizhawk/localtime_r.c  | 179 ++++++++
  src/platform/bizhawk/mingw/Makefile |  31 ++
- 7 files changed, 1006 insertions(+)
+ 7 files changed, 1042 insertions(+)
  create mode 100755 bizhawk-make-install.sh
  create mode 100644 src/platform/bizhawk/.gitignore
  create mode 100644 src/platform/bizhawk/base.mak
  create mode 100644 src/platform/bizhawk/bizinterface.c
  create mode 100644 src/platform/bizhawk/linux/Makefile
  create mode 100644 src/platform/bizhawk/localtime_r.c
  create mode 100644 src/platform/bizhawk/mingw/Makefile
@@ -44,18 +44,18 @@
 +++ b/src/platform/bizhawk/.gitignore
 @@ -0,0 +1,2 @@
 +codeblocks/*
 +mingw/obj/*
 \ No newline at end of file
 diff --git a/src/platform/bizhawk/base.mak b/src/platform/bizhawk/base.mak
 new file mode 100644
-index 000000000..39bc815dc
+index 000000000..b9a03daf8
 --- /dev/null
 +++ b/src/platform/bizhawk/base.mak
-@@ -0,0 +1,130 @@
+@@ -0,0 +1,134 @@
 +CCFLAGS = \
 +	-O3 -fomit-frame-pointer -fexpensive-optimizations -flto \
 +	-I../../../../include -I../../.. -std=gnu11 \
 +	-Wall -Wno-stringop-overflow -Wno-lto-type-mismatch \
 +	-Wno-ignored-optimization-argument -Wno-unknown-warning-option \
 +	-DMINIMAL_CORE=2 -DDISABLE_THREADING -DM_CORE_GBA \
 +	-DCOLOR_16_BIT -DMGBA_STANDALONE -DENABLE_DEBUGGERS \
@@ -110,43 +110,47 @@
 +	$(ROOT_DIR)/gba/sharkport.c \
 +	$(ROOT_DIR)/gba/sio.c \
 +	$(ROOT_DIR)/gba/timer.c \
 +	$(ROOT_DIR)/gba/video.c \
 +	$(ROOT_DIR)/gba/cart/ereader.c \
 +	$(ROOT_DIR)/gba/cart/gpio.c \
 +	$(ROOT_DIR)/gba/cart/matrix.c \
++	$(ROOT_DIR)/gba/cart/unlicensed.c \
 +	$(ROOT_DIR)/gba/cart/vfame.c \
 +	$(ROOT_DIR)/gba/cheats/codebreaker.c \
 +	$(ROOT_DIR)/gba/cheats/gameshark.c \
 +	$(ROOT_DIR)/gba/cheats/parv3.c \
 +	$(ROOT_DIR)/gba/debugger/cli.c \
 +	$(ROOT_DIR)/gba/renderers/cache-set.c \
 +	$(ROOT_DIR)/gba/renderers/common.c \
 +	$(ROOT_DIR)/gba/renderers/software-bg.c \
 +	$(ROOT_DIR)/gba/renderers/software-mode0.c \
 +	$(ROOT_DIR)/gba/renderers/software-obj.c \
 +	$(ROOT_DIR)/gba/renderers/video-software.c \
 +	$(ROOT_DIR)/gba/sio/gbp.c \
-+	$(ROOT_DIR)/gba/sio/joybus.c \
 +	$(ROOT_DIR)/gba/sio/lockstep.c \
 +	$(ROOT_DIR)/debugger/debugger.c \
 +	$(ROOT_DIR)/debugger/stack-trace.c \
 +	$(ROOT_DIR)/debugger/cli-debugger.c \
 +	$(ROOT_DIR)/debugger/symbols.c \
 +	$(ROOT_DIR)/debugger/parser.c \
 +	$(ROOT_DIR)/third-party/inih/ini.c \
++	$(ROOT_DIR)/util/audio-buffer.c \
++	$(ROOT_DIR)/util/audio-resampler.c \
 +	$(ROOT_DIR)/util/circle-buffer.c \
 +	$(ROOT_DIR)/util/configuration.c \
 +	$(ROOT_DIR)/util/crc32.c \
 +	$(ROOT_DIR)/util/elf-read.c \
 +	$(ROOT_DIR)/util/formatting.c \
 +	$(ROOT_DIR)/util/gbk-table.c \
 +	$(ROOT_DIR)/util/gui.c \
 +	$(ROOT_DIR)/util/hash.c \
 +	$(ROOT_DIR)/util/image/png-io.c \
++	$(ROOT_DIR)/util/interpolator.c \
++	$(ROOT_DIR)/util/md5.c \
 +	$(ROOT_DIR)/util/patch-fast.c \
 +	$(ROOT_DIR)/util/patch-ips.c \
 +	$(ROOT_DIR)/util/patch-ups.c \
 +	$(ROOT_DIR)/util/patch.c \
 +	$(ROOT_DIR)/util/ring-fifo.c \
 +	$(ROOT_DIR)/util/string.c \
 +	$(ROOT_DIR)/util/table.c \
@@ -180,47 +184,48 @@
 +	$(CP) $(TARGET) $(DESTCOPY_$(ARCH))
 +endif
 +
 +print-%:
 +	@echo $* = $($*)
 diff --git a/src/platform/bizhawk/bizinterface.c b/src/platform/bizhawk/bizinterface.c
 new file mode 100644
-index 000000000..933f277c7
+index 000000000..a7e38d35c
 --- /dev/null
 +++ b/src/platform/bizhawk/bizinterface.c
-@@ -0,0 +1,623 @@
+@@ -0,0 +1,655 @@
 +#include <stdlib.h>
 +#include <stdint.h>
 +#include "mgba/core/core.h"
 +#include "mgba/core/log.h"
 +#include "mgba/core/timing.h"
 +#include "mgba/core/serialize.h"
-+#include "mgba/core/blip_buf.h"
 +#include "mgba/gba/core.h"
 +#include "mgba/gba/interface.h"
 +#include "mgba/internal/gba/gba.h"
 +#include "mgba/internal/gba/video.h"
 +#include "mgba/internal/gba/overrides.h"
 +#include "mgba/internal/arm/isa-inlines.h"
 +#include "mgba/debugger/debugger.h"
++#include <mgba-util/audio-resampler.h>
 +#include "mgba-util/common.h"
 +#include "mgba-util/vfs.h"
 +
 +// interop sanity checks
 +static_assert(sizeof(bool) == 1, "Wrong bool size!");
-+static_assert(sizeof(color_t) == 2, "Wrong color_t size!");
++static_assert(sizeof(mColor) == 2, "Wrong mColor size!");
 +static_assert(sizeof(enum mWatchpointType) == 4, "Wrong mWatchpointType size!");
 +static_assert(sizeof(enum GBASavedataType) == 4, "Wrong GBASavedataType size!");
 +static_assert(sizeof(enum GBAHardwareDevice) == 4, "Wrong GBAHardwareDevice size!");
 +static_assert(sizeof(ssize_t) == 8, "Wrong ssize_t size!");
 +static_assert(sizeof(void*) == 8, "Wrong pointer size!");
 +
 +const char* const binaryName = "mgba";
 +const char* const projectName = "mGBA BizHawk";
 +const char* const projectVersion = "(unknown)";
++const int maxSamples = 1024;
 +
 +#ifdef _WIN32
 +#define EXP __declspec(dllexport)
 +#else
 +#define EXP __attribute__((visibility("default")))
 +#endif
 +
@@ -237,39 +242,44 @@
 +struct VFile* VFileOpenFD(const char* path, int flags) { return NULL; }
 +
 +typedef struct
 +{
 +	struct mCore* core;
 +	struct mLogger logger;
 +	struct GBA* gba; // anything that uses this will be deprecated eventually
-+	color_t vbuff[GBA_VIDEO_HORIZONTAL_PIXELS * GBA_VIDEO_VERTICAL_PIXELS];
++	mColor vbuff[GBA_VIDEO_HORIZONTAL_PIXELS * GBA_VIDEO_VERTICAL_PIXELS];
++	struct mAudioBuffer abuf;
++	struct mAVStream stream;
 +	void* rom;
 +	struct VFile* romvf;
 +	uint8_t bios[0x4000];
 +	struct VFile* biosvf;
 +	uint8_t sram[0x20000 + 16];
 +	struct VFile* sramvf;
 +	struct mKeyCallback keysource;
 +	struct mRotationSource rotsource;
++	struct mRumbleIntegrator rumble;
 +	struct mRTCSource rtcsource;
 +	struct GBALuminanceSource lumasource;
 +	struct mDebugger debugger;
 +	struct mDebuggerModule module;
++	struct mAudioResampler resampler;
 +	bool attached;
 +	struct GBACartridgeOverride override;
 +	int16_t tiltx;
 +	int16_t tilty;
 +	int16_t tiltz;
 +	int64_t time;
 +	uint8_t light;
 +	uint16_t keys;
 +	bool lagged;
 +	bool skipbios;
 +	uint32_t palette[0x10000];
 +	void (*input_callback)(void);
++	void (*rumble_callback)(int value);
 +	void (*trace_callback)(const char *buffer);
 +	void (*exec_callback)(uint32_t pc);
 +	void (*mem_callback)(uint32_t addr, enum mWatchpointType type, uint32_t oldValue, uint32_t newValue);
 +} bizctx;
 +
 +static int32_t GetX(struct mRotationSource* rotationSource)
 +{
@@ -300,14 +310,25 @@
 +}
 +static void RotationCB(struct mRotationSource* rotationSource)
 +{
 +	bizctx* ctx = container_of(rotationSource, bizctx, rotsource);
 +	ctx->input_callback();
 +	ctx->lagged = false;
 +}
++static void SetRumble(struct mRumbleIntegrator* rumble, float value)
++{
++	bizctx* ctx = container_of(rumble, bizctx, rumble);
++	ctx->rumble_callback(value * (double)INT_MAX);
++}
++static void AudioRateChangedCB(struct mAVStream* stream, unsigned rate)
++{
++    bizctx* ctx = container_of(stream, bizctx, stream);
++    mAudioResamplerProcess(&ctx->resampler);
++    mAudioResamplerSetSource(&ctx->resampler, ctx->core->getAudioBuffer(ctx->core), rate, true);
++}
 +static void LightCB(struct GBALuminanceSource* luminanceSource)
 +{
 +	bizctx* ctx = container_of(luminanceSource, bizctx, lumasource);
 +	ctx->input_callback();
 +	ctx->lagged = false;
 +}
 +static void TimeCB(struct mRTCSource* rtcSource)
@@ -346,14 +367,15 @@
 +	{
 +		ctx->core->detachDebugger(ctx->core);
 +		mDebuggerDetachModule(&ctx->debugger, &ctx->module);
 +		mDebuggerDeinit(&ctx->debugger);
 +	}
 +
 +	ctx->core->deinit(ctx->core);
++	mAudioResamplerDeinit(&ctx->resampler);
 +	free(ctx->rom);
 +	free(ctx);
 +}
 +
 +typedef struct
 +{
 +	enum GBASavedataType savetype;
@@ -383,14 +405,19 @@
 +}
 +
 +EXP void BizSetInputCallback(bizctx* ctx, void(*callback)(void))
 +{
 +	ctx->input_callback = callback;
 +}
 +
++EXP void BizSetRumbleCallback(bizctx* ctx, void(*callback)(int value))
++{
++	ctx->rumble_callback = callback;
++}
++
 +EXP void BizSetTraceCallback(bizctx* ctx, void(*callback)(const char *buffer))
 +{
 +	ctx->trace_callback = callback;
 +}
 +
 +EXP void BizSetExecCallback(bizctx* ctx, void(*callback)(uint32_t pc))
 +{
@@ -476,18 +503,23 @@
 +		BizDestroy(ctx);
 +		return NULL;
 +	}
 +
 +	ctx->gba = ctx->core->board;
 +
 +	ctx->core->setVideoBuffer(ctx->core, ctx->vbuff, GBA_VIDEO_HORIZONTAL_PIXELS);
-+	ctx->core->setAudioBufferSize(ctx->core, 1024);
++	ctx->core->setAudioBufferSize(ctx->core, maxSamples);
++
++	mAudioBufferInit(&ctx->abuf, maxSamples, 2);
++	mAudioResamplerInit(&ctx->resampler, mINTERPOLATOR_SINC);
++	mAudioResamplerSetSource(&ctx->resampler, ctx->core->getAudioBuffer(ctx->core), ctx->core->audioSampleRate(ctx->core), true);
++	mAudioResamplerSetDestination(&ctx->resampler, &ctx->abuf, 44100);
 +
-+	blip_set_rates(ctx->core->getAudioChannel(ctx->core, 0), ctx->core->frequency(ctx->core), 44100);
-+	blip_set_rates(ctx->core->getAudioChannel(ctx->core, 1), ctx->core->frequency(ctx->core), 44100);
++	ctx->stream.audioRateChanged = AudioRateChangedCB;
++	ctx->core->setAVStream(ctx->core, &ctx->stream);
 +
 +	if (!ctx->core->loadROM(ctx->core, ctx->romvf))
 +	{
 +		BizDestroy(ctx);
 +		return NULL;
 +	}
 +
@@ -502,25 +534,29 @@
 +	ctx->core->loadSave(ctx->core, ctx->sramvf);
 +
 +	mCoreSetRTC(ctx->core, &ctx->rtcsource);
 +
 +	ctx->gba->idleOptimization = IDLE_LOOP_IGNORE; // Don't do "idle skipping"
 +	ctx->gba->keyCallback = &ctx->keysource; // Callback for key reading
 +
++	mRumbleIntegratorInit(&ctx->rumble);
++
 +	ctx->keysource.readKeys = GetKeys;
 +	ctx->rotsource.sample = RotationCB;
 +	ctx->rotsource.readTiltX = GetX;
 +	ctx->rotsource.readTiltY = GetY;
 +	ctx->rotsource.readGyroZ = GetZ;
++	ctx->rumble.setRumble = SetRumble;
 +	ctx->lumasource.sample = LightCB;
 +	ctx->lumasource.readLuminance = GetLight;
 +	ctx->rtcsource.sample = TimeCB;
 +	ctx->rtcsource.unixTime = GetTime;
-+	
++
 +	ctx->core->setPeripheral(ctx->core, mPERIPH_ROTATION, &ctx->rotsource);
++	ctx->core->setPeripheral(ctx->core, mPERIPH_RUMBLE, &ctx->rumble.d);
 +	ctx->core->setPeripheral(ctx->core, mPERIPH_GBA_LUMINANCE, &ctx->lumasource);
 +
 +	if (bios)
 +	{
 +		memcpy(ctx->bios, bios, sizeof(ctx->bios));
 +		ctx->biosvf = VFileFromMemory(ctx->bios, sizeof(ctx->bios));
 +		/*if (!GBAIsBIOS(ctx->biosvf))
@@ -636,15 +672,15 @@
 +}
 +
 +EXP void BizReset(bizctx* ctx)
 +{
 +	resetinternal(ctx);
 +}
 +
-+static void blit(uint32_t* dst, const color_t* src, const uint32_t* palette)
++static void blit(uint32_t* dst, const mColor* src, const uint32_t* palette)
 +{
 +	uint32_t* dst_end = dst + GBA_VIDEO_HORIZONTAL_PIXELS * GBA_VIDEO_VERTICAL_PIXELS;
 +
 +	while (dst < dst_end)
 +	{
 +		*dst++ = palette[*src++];
 +	}
@@ -663,19 +699,19 @@
 +	ctx->lagged = true;
 +
 +	ctx->module.needsCallback = ctx->trace_callback || ctx->exec_callback;
 +	ctx->debugger.state = ctx->module.needsCallback ? DEBUGGER_CALLBACK : DEBUGGER_RUNNING;
 +	mDebuggerRunFrame(&ctx->debugger);
 +
 +	blit(vbuff, ctx->vbuff, ctx->palette);
-+	*nsamp = blip_samples_avail(ctx->core->getAudioChannel(ctx->core, 0));
-+	if (*nsamp > 1024)
-+		*nsamp = 1024;
-+	blip_read_samples(ctx->core->getAudioChannel(ctx->core, 0), sbuff, 1024, true);
-+	blip_read_samples(ctx->core->getAudioChannel(ctx->core, 1), sbuff + 1, 1024, true);
++	mAudioResamplerProcess(&ctx->resampler);
++	*nsamp = mAudioBufferAvailable(&ctx->abuf);
++	if (*nsamp > maxSamples)
++		*nsamp = maxSamples;
++	mAudioBufferRead(&ctx->abuf, sbuff, maxSamples);
 +	return ctx->lagged;
 +}
 +
 +EXP void BizSetPalette(bizctx* ctx, const uint32_t* palette)
 +{
 +	memcpy(ctx->palette, palette, sizeof(ctx->palette));
 +}

Also opened TASEmulators#10 so I don't have to do that again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants