Skip to content

Instantly share code, notes, and snippets.

View ITotalJustice's full-sized avatar
💜
Coding away...

ITotalJustice

💜
Coding away...
View GitHub Profile
auto LZ77UnCompReadNormalWrite(Gba& gba, auto fetch_and_write, auto calc_offset) -> bool
{
auto src = arm7tdmi::get_reg(gba, 0);
auto dst = arm7tdmi::get_reg(gba, 1);
const auto header = mem::read32(gba, src);
auto len = bit::get_range<8, 31>(header);
src += 4; // skip over header
if (!IsValidRange(gba, len, src))
@ITotalJustice
ITotalJustice / jni_stuff.cpp
Last active December 24, 2022 14:28
dumping ground for some jni functions i write
#include "native_helper.hpp"
#include <android_native_app_glue.h>
#include <android/log.h>
#include <string>
namespace {
struct JniHelper
{
JniHelper(struct android_app* app)
struct JniHelper
{
JniHelper()
{
vm = g_App->activity->vm;
if (vm->GetEnv((void**)&env, JNI_VERSION_1_6))
{
if (!vm->AttachCurrentThread(&env, NULL))
{
__android_log_print(ANDROID_LOG_INFO, "JNI-TEST", "attaching thread\n");
struct GlFormat
{
GLint sized_format; // eg, RGBA8
GLenum format; // eg, RGBA
GLenum packing; // eg, GL_UNSIGNED_INT_8_8_8_8_REV or GL_UNSIGNED_SHORT_1_5_5_5_REV
};
struct Format
{
SDL_PixelFormatEnum sdl;
@ITotalJustice
ITotalJustice / wav_writer.hpp
Last active November 29, 2022 20:54
simple wav writer to a buffer
#pragma once
#include <cstdint>
#include <cstring>
#include <vector>
template<typename T>
struct WavWriter
{
void init()
@ITotalJustice
ITotalJustice / wav_writer.c
Last active November 29, 2022 11:12
simple wav writer in c99, useful for dumping audio output of an emulator
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
static FILE* file;
static size_t number_of_samples;
static uint32_t sample_rate;
static uint8_t channels;
@ITotalJustice
ITotalJustice / envelope.c
Created November 28, 2022 12:41
nes square
#include "apu.h"
uint8_t envelope_get_volume(const struct Nes_ApuEnvelope* envelope)
{
return envelope->constant_volume_flag ? envelope->volume : envelope->counter;
}
void envelope_reload(struct Nes_ApuEnvelope* envelope)
{
envelope->start_flag = true;
@ITotalJustice
ITotalJustice / console.c
Created October 29, 2022 08:19
this is what killed my ezflash. !!DO NOT RUN THIS CODE ON YOUR EZFLASH!!!
#include <gba_console.h>
#include <gba_video.h>
#include <gba_interrupt.h>
#include <gba_systemcalls.h>
#include <gba.h>
#include <stdio.h>
enum NorS71InfoOffset
@ITotalJustice
ITotalJustice / scheduler.cpp
Last active October 23, 2022 17:01
simple-ish, fast-ish, generic-ish scheduler implementation
#include "scheduler.hpp"
#include <algorithm>
namespace scheduler {
namespace {
// s32 overflows at 0x7FFFFFFF, just over 100 million gap
constexpr s32 TIMEOUT_VALUE = 0x70000000;
void reset_event(void* user, [[maybe_unused]] s32 _)
#ifndef MGBA_LOG_H
#define MGBA_LOG_H
#include <stdio.h> /* needed for snprintf */
#define MGBA_LOG_ON 0xC0DE
#define MGBA_LOG_OFF 0x0000
#define MGBA_LOG_ON_RESULT 0x1DEA
#define MGBA_LOG_STDOUT ((char*)0x4FFF600)