From ee61062aa13d5b7c090d22cb7c01494a5c784e37 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 17 Apr 2022 14:53:57 +0200 Subject: [PATCH] basic provision for feeding external pictures to the cameras --- src/DSi_Camera.cpp | 24 ++++++++++++++++++++++++ src/DSi_Camera.h | 2 ++ src/NDS.cpp | 15 +++++++++++++++ src/NDS.h | 1 + src/frontend/qt_sdl/main.cpp | 8 +++++++- 5 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/DSi_Camera.cpp b/src/DSi_Camera.cpp index f2d75211..06549396 100644 --- a/src/DSi_Camera.cpp +++ b/src/DSi_Camera.cpp @@ -758,6 +758,30 @@ void Camera::MCU_Write(u16 addr, u8 val) MCURegs[addr] = val; } + +void Camera::InputFrame(u32* data, int width, int height) +{ + // TODO: double-buffering? + + if (width == 640 && height == 480) + { + memcpy(FrameBuffer, data, 640*480*sizeof(u32)); + return; + } + + for (int dy = 0; dy < 480; dy++) + { + int sy = (dy * height) / 480; + + for (int dx = 0; dx < 640; dx++) + { + int sx = (dx * width) / 640; + + FrameBuffer[dy*640 + dx] = data[sy*width + sx]; + } + } +} + } diff --git a/src/DSi_Camera.h b/src/DSi_Camera.h index 554d41f5..ed2342be 100644 --- a/src/DSi_Camera.h +++ b/src/DSi_Camera.h @@ -68,6 +68,8 @@ public: u8 I2C_Read(bool last); void I2C_Write(u8 val, bool last); + void InputFrame(u32* data, int width, int height); + u32 Num; private: diff --git a/src/NDS.cpp b/src/NDS.cpp index b6d0171c..9d436cbb 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -1261,6 +1261,21 @@ void SetLidClosed(bool closed) } } +void CamInputFrame(int cam, u32* data, int width, int height) +{ + // TODO: support things like the GBA-slot camera addon + // whenever these are emulated + + if (ConsoleType == 1) + { + switch (cam) + { + case 0: return DSi_CamModule::Camera0->InputFrame(data, width, height); + case 1: return DSi_CamModule::Camera1->InputFrame(data, width, height); + } + } +} + void MicInputFrame(s16* data, int samples) { return SPI_TSC::MicInputFrame(data, samples); diff --git a/src/NDS.h b/src/NDS.h index 80a1c6d7..5b6e083e 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -260,6 +260,7 @@ void SetKeyMask(u32 mask); bool IsLidClosed(); void SetLidClosed(bool closed); +void CamInputFrame(int cam, u32* data, int width, int height); void MicInputFrame(s16* data, int samples); void ScheduleEvent(u32 id, bool periodic, s32 delay, void (*func)(u32), u32 param); diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index c6eebf29..4282f644 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -430,6 +430,9 @@ void EmuThread::run() char melontitle[100]; + QImage testimg("test.jpg"); + QImage testimg_conv = testimg.convertToFormat(QImage::Format_RGB32); + while (EmuRunning != 0) { Input::Process(); @@ -510,6 +513,9 @@ void EmuThread::run() OSD::AddMessage(0, lid ? "Lid closed" : "Lid opened"); } + // camera input test + NDS::CamInputFrame(0, (u32*)testimg_conv.bits(), testimg_conv.width(), testimg_conv.height()); + // microphone input micProcess(); @@ -1834,7 +1840,7 @@ void MainWindow::keyPressEvent(QKeyEvent* event) if (event->isAutoRepeat()) return; // TODO!! REMOVE ME IN RELEASE BUILDS!! - //if (event->key() == Qt::Key_F11) NDS::debug(0); + if (event->key() == Qt::Key_F11) NDS::debug(0); Input::KeyPress(event); }