gba-sprite-engine/src/engine/gba_engine.h

82 lines
2.1 KiB
C
Raw Normal View History

2018-08-01 16:03:16 +02:00
//
// Created by Wouter Groeneveld on 28/07/18.
//
#ifndef GBA_SPRITE_ENGINE_GBAENGINE_H
#define GBA_SPRITE_ENGINE_GBAENGINE_H
#include <engine/sprites/sprite_manager.h>
#include <engine/gba/tonc_memmap.h>
2018-08-07 09:23:00 +02:00
#include <engine/gba/tonc_memdef.h>
2018-08-04 10:43:27 +02:00
#include <engine/effects/scene_effect.h>
2018-08-01 16:03:16 +02:00
#include "Scene.h"
2018-08-07 09:23:00 +02:00
#define CLOCK 16777216
#define CYCLES_PER_BLANK 280806
#define OVERFLOW_16_BIT_VALUE 65536
#define DISPLAY_INTERRUPT_VBLANK_ENABLE 0x08
#define INTERRUPT_VBLANK 0x1
#define DMA_SYNC_TO_TIMER 0x30000000
#define IRQ_CALLBACK ((volatile unsigned int*) 0x3007FFC)
enum SoundChannel {
ChannelA, ChannelB
};
struct SoundControl {
vu32* DMAControl; // ex. &REG_DMA1CNT
vu32* DMASourceAddress; // ex. &REG_DMA1SAD
vu32* DMADestinationAddress; // ex. &REG_DMA1DAD
vu32* FiFoBuffer; // ex. &REG_FIFOA
u16 ControlFlags;
};
void onvblank();
2018-08-01 16:03:16 +02:00
class GBAEngine {
private:
2018-08-05 13:47:37 +02:00
// WHY raw pointers? the engine does the transition and cleanup work itself
2018-08-01 16:03:16 +02:00
Scene* currentScene;
2018-08-04 10:43:27 +02:00
Scene* sceneToTransitionTo;
SceneEffect* currentEffectForTransition;
2018-08-05 13:47:37 +02:00
SpriteManager spriteManager;
2018-08-01 16:03:16 +02:00
void vsync() {
while (REG_VCOUNT >= 160);
while (REG_VCOUNT < 160);
}
2018-08-07 09:23:00 +02:00
SoundControl channelAControl();
SoundControl channelBControl();
SoundControl soundControl(SoundChannel channel) {
return channel == ChannelA ? channelAControl() : channelBControl();
};
2018-08-05 13:47:37 +02:00
void cleanupPreviousScene();
2018-08-07 09:23:00 +02:00
void queueSound(const s8* data, int totalSamples, int sampleRate, SoundControl control);
2018-08-01 16:03:16 +02:00
public:
GBAEngine();
void setScene(Scene* scene);
2018-08-04 10:43:27 +02:00
void transitionIntoScene(Scene* scene, SceneEffect* effect);
2018-08-07 09:23:00 +02:00
void queueMusic(const s8* data, int totalSamples) {
queueSound(data, totalSamples, 16000, soundControl(ChannelA));
}
void queueSound(const s8* data, int totalSamples) {
queueSound(data, totalSamples, 16000, soundControl(ChannelB));
}
u16 readKeys();
void update();
2018-08-01 16:03:16 +02:00
void delay(int times) {
for(int i = 0; i < times; i++){}
}
};
#endif //GBA_SPRITE_ENGINE_GBAENGINE_H