//
// Generated by dtk
// Translation Unit: JASTrackInterrupt.cpp
//

#include "JSystem/JSystem.h" // IWYU pragma: keep

#include "JSystem/JAudio/JASTrackInterrupt.h"

/* 80284118-80284158       .text init__Q28JASystem8TIntrMgrFv */
void JASystem::TIntrMgr::init() {
    field_0x0 = 1;
    field_0x1 = 0;
    field_0x2 = 0;
    field_0x3 = 0;
    field_0x4 = 0;
    field_0x8 = 0;
    for (int i = 0; i < 8; i++) {
        field_0xc[i] = NULL;
    }
}

/* 80284158-8028417C       .text request__Q28JASystem8TIntrMgrFUl */
void JASystem::TIntrMgr::request(u32 param_1) {
    if ((field_0x2 & 1 << param_1) == 0) {
        return;
    }
    field_0x1 |= 1 << param_1;
}

/* 8028417C-802841A0       .text setIntr__Q28JASystem8TIntrMgrFUlPv */
void JASystem::TIntrMgr::setIntr(u32 param_1, void* param_2) {
    field_0x2 |= 1 << param_1;
    field_0xc[param_1] = param_2;
}

/* 802841A0-802841B8       .text resetInter__Q28JASystem8TIntrMgrFUl */
void JASystem::TIntrMgr::resetInter(u32 param_1) {
    /* Nonmatching */
    field_0x2 &= ~(1 << param_1);
}

/* 802841B8-80284224       .text checkIntr__Q28JASystem8TIntrMgrFv */
void* JASystem::TIntrMgr::checkIntr() {
    if (field_0x0 == 0) {
        return NULL;
    }
    u32 r4 = field_0x2 & field_0x1;
    for (u32 i = 0; r4; i++) {
        if (r4 & 1) {
            field_0x1 &= ~(1 << i);
            return field_0xc[i];
        }
        r4 >>= 1;
    }
    return NULL;
}

/* 80284224-802842A8       .text timerProcess__Q28JASystem8TIntrMgrFv */
void JASystem::TIntrMgr::timerProcess() {
    if (field_0x4 == 0) {
        return;
    }
    field_0x4--;
    if (field_0x4 != 0) {
        return;
    }
    request(REQUEST_UNK_6);
    if (field_0x3) {
        field_0x3--;
        if (field_0x3) {
            field_0x4 = field_0x8;
        }
    } else {
        field_0x4 = field_0x8;
    }
}
