all repos — mgba @ c5212970935a527355a36a84e1577409e66bf421

mGBA Game Boy Advance Emulator

DS Wi-Fi: Begin stubbing
Vicki Pfau vi@endrift.com
Mon, 06 Mar 2017 02:43:14 -0800
commit

c5212970935a527355a36a84e1577409e66bf421

parent

60fb32b71f7716a1be7ac88f58db82bb06f1c927

M include/mgba/internal/ds/ds.hinclude/mgba/internal/ds/ds.h

@@ -18,6 +18,7 @@ #include <mgba/internal/ds/gx.h>

#include <mgba/internal/ds/memory.h> #include <mgba/internal/ds/timer.h> #include <mgba/internal/ds/video.h> +#include <mgba/internal/ds/wifi.h> extern const uint32_t DS_ARM946ES_FREQUENCY; extern const uint32_t DS_ARM7TDMI_FREQUENCY;

@@ -85,6 +86,7 @@ struct DSCommon ds9;

struct DSMemory memory; struct DSVideo video; struct DSGX gx; + struct DSWifi wifi; struct mCoreSync* sync; struct mTimingEvent slice;
M include/mgba/internal/ds/io.hinclude/mgba/internal/ds/io.h

@@ -122,6 +122,9 @@ DS7_REG_BIOSPROT_LO = 0x308,

DS7_REG_BIOSPROT_HI = 0x30A, DS7_REG_MAX = 0x51E, + + DS7_IO_BASE_WIFI = 0x800000, + DS7_IO_END_WIFI = 0x810000, }; enum DS9IORegisters {
A include/mgba/internal/ds/wifi.h

@@ -0,0 +1,30 @@

+/* Copyright (c) 2013-2017 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef DS_WIFI_H +#define DS_WIFI_H + +#include <mgba-util/common.h> + +CXX_GUARD_START + +#include <mgba/core/log.h> + +mLOG_DECLARE_CATEGORY(DS_WIFI); + +struct DSWifi { + uint16_t io[0x800]; + uint16_t wram[0x1000]; + uint8_t baseband[0x100]; +}; + +struct DS; +void DSWifiReset(struct DS* ds); +void DSWifiWriteIO(struct DS* ds, uint32_t address, uint16_t value); +uint16_t DSWifiReadIO(struct DS* ds, uint32_t address); + +CXX_GUARD_END + +#endif
M src/ds/io.csrc/ds/io.c

@@ -282,6 +282,10 @@ } else if (v2 & 0x20000) {

return; } } + if (address >= DS7_IO_BASE_WIFI && address < DS7_IO_END_WIFI) { + DSWifiWriteIO(ds, address & 0x7FFF, value); + return; + } mLOG(DS_IO, STUB, "Stub DS7 I/O register write: %06X:%04X", address, value); if (address >= DS7_REG_MAX) { mLOG(DS_IO, GAME_ERROR, "Write to unused DS7 I/O register: %06X:%04X", address, value);

@@ -391,11 +395,15 @@ mLOG(DS_IO, GAME_ERROR, "Invalid cart access");

return 0; } default: + if (address >= DS7_IO_BASE_WIFI && address < DS7_IO_END_WIFI) { + return DSWifiReadIO(ds, address & 0x7FFF); + } mLOG(DS_IO, STUB, "Stub DS7 I/O register read: %06X", address); } if (address < DS7_REG_MAX) { return ds->memory.io7[address >> 1]; } + return 0; }
A src/ds/wifi.c

@@ -0,0 +1,88 @@

+/* Copyright (c) 2013-2017 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <mgba/internal/ds/wifi.h> + +#include <mgba/internal/arm/macros.h> +#include <mgba/internal/ds/ds.h> + +mLOG_DEFINE_CATEGORY(DS_WIFI, "DS Wi-Fi", "ds.wifi"); + +void DSWifiReset(struct DS* ds) { + memset(ds->wifi.io, 0, sizeof(ds->wifi.io)); + memset(ds->wifi.wram, 0, sizeof(ds->wifi.wram)); +} + +static void DSWifiWriteBB(struct DS* ds, uint8_t address, uint8_t value) { + mLOG(DS_WIFI, STUB, "Stub Wi-Fi baseband register write: %02X:%02X", address, value); + ds->wifi.baseband[address] = value; +} + +static uint8_t DSWifiReadBB(struct DS* ds, uint8_t address) { + mLOG(DS_WIFI, STUB, "Stub Wi-Fi baseband register read: %02X", address); + return ds->wifi.baseband[address]; +} + +static void DSWifiWriteReg(struct DS* ds, uint32_t address, uint16_t value) { + switch (address) { + case 0x158: + if (value & 0x1000) { + DSWifiWriteBB(ds, value & 0xFF, ds->wifi.io[0x15A >> 1]); + } + if (value & 0x2000) { + ds->wifi.io[0x15C >> 1] = DSWifiReadBB(ds, value & 0xFF); + } + break; + case 0x15A: + break; + default: + mLOG(DS_WIFI, STUB, "Stub Wi-Fi I/O register write: %06X:%04X", address, value); + break; + } + ds->wifi.io[address >> 1] = value; +} + +static uint16_t DSWifiReadReg(struct DS* ds, uint32_t address) { + switch (address) { + case 0x15C: + break; + default: + mLOG(DS_WIFI, STUB, "Stub Wi-Fi I/O register read: %06X", address); + break; + } + return ds->wifi.io[address >> 1]; +} + +void DSWifiWriteIO(struct DS* ds, uint32_t address, uint16_t value) { + switch (address >> 12) { + case 0: + case 1: + case 6: + case 7: + DSWifiWriteReg(ds, address & 0xFFF, value); + break; + case 4: + case 5: + STORE_16(value, address & 0x1FFE, ds->wifi.wram); + break; + } +} + +uint16_t DSWifiReadIO(struct DS* ds, uint32_t address) { + uint16_t value = 0; + switch (address >> 12) { + case 0: + case 1: + case 6: + case 7: + value = DSWifiReadReg(ds, address & 0xFFF); + break; + case 4: + case 5: + LOAD_16(value, address & 0x1FFE, ds->wifi.wram); + break; + } + return value; +}