src/ds/wifi.c (view raw)
1/* Copyright (c) 2013-2017 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#include <mgba/internal/ds/wifi.h>
7
8#include <mgba/internal/arm/macros.h>
9#include <mgba/internal/ds/ds.h>
10
11mLOG_DEFINE_CATEGORY(DS_WIFI, "DS Wi-Fi", "ds.wifi");
12
13void DSWifiReset(struct DS* ds) {
14 memset(ds->wifi.io, 0, sizeof(ds->wifi.io));
15 memset(ds->wifi.wram, 0, sizeof(ds->wifi.wram));
16}
17
18static void DSWifiWriteBB(struct DS* ds, uint8_t address, uint8_t value) {
19 mLOG(DS_WIFI, STUB, "Stub Wi-Fi baseband register write: %02X:%02X", address, value);
20 ds->wifi.baseband[address] = value;
21}
22
23static uint8_t DSWifiReadBB(struct DS* ds, uint8_t address) {
24 mLOG(DS_WIFI, STUB, "Stub Wi-Fi baseband register read: %02X", address);
25 return ds->wifi.baseband[address];
26}
27
28static void DSWifiWriteReg(struct DS* ds, uint32_t address, uint16_t value) {
29 switch (address) {
30 case 0x040:
31 value &= 0x8001;
32 if (value & 0x8000) {
33 uint16_t state = ds->wifi.io[0x03C >> 1];
34 if (value & 0x1) {
35 state |= 0x200;
36 state &= ~0x100;
37 } else {
38 mLOG(DS_WIFI, STUB, "Stub Wi-Fi I/O register write: %06X:%04X", address, value);
39 state &= ~0x200;
40 }
41 ds->wifi.io[0x03C >> 1] = state;
42 }
43 break;
44 case 0x158:
45 if (value & 0x1000) {
46 DSWifiWriteBB(ds, value & 0xFF, ds->wifi.io[0x15A >> 1]);
47 }
48 if (value & 0x2000) {
49 ds->wifi.io[0x15C >> 1] = DSWifiReadBB(ds, value & 0xFF);
50 }
51 break;
52 case 0x15A:
53 break;
54 default:
55 mLOG(DS_WIFI, STUB, "Stub Wi-Fi I/O register write: %06X:%04X", address, value);
56 break;
57 }
58 ds->wifi.io[address >> 1] = value;
59}
60
61static uint16_t DSWifiReadReg(struct DS* ds, uint32_t address) {
62 switch (address) {
63 case 0x040:
64 case 0x15C:
65 break;
66 default:
67 mLOG(DS_WIFI, STUB, "Stub Wi-Fi I/O register read: %06X", address);
68 break;
69 }
70 return ds->wifi.io[address >> 1];
71}
72
73void DSWifiWriteIO(struct DS* ds, uint32_t address, uint16_t value) {
74 switch (address >> 12) {
75 case 0:
76 case 1:
77 case 6:
78 case 7:
79 DSWifiWriteReg(ds, address & 0xFFF, value);
80 break;
81 case 4:
82 case 5:
83 STORE_16(value, address & 0x1FFE, ds->wifi.wram);
84 break;
85 }
86}
87
88uint16_t DSWifiReadIO(struct DS* ds, uint32_t address) {
89 uint16_t value = 0;
90 switch (address >> 12) {
91 case 0:
92 case 1:
93 case 6:
94 case 7:
95 value = DSWifiReadReg(ds, address & 0xFFF);
96 break;
97 case 4:
98 case 5:
99 LOAD_16(value, address & 0x1FFE, ds->wifi.wram);
100 break;
101 }
102 return value;
103}