summaryrefslogtreecommitdiff
path: root/src/Dolphin/GBA/GBAWrite.c
blob: f040f9224b91d14cb44d55c090915811beb2fe27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "dolphin/GBAPriv.h"

void WriteProc(s32 chan) {
  GBA* gba;
  gba = &__GBA[chan];

  if (gba->result != 0) {
    return;
  }

  gba->status[0] = gba->dst[0] & GBA_JSTAT_MASK;
}

s32 GBAWriteAsync(s32 chan, u8* src, u8* status, GBACallback callback) {
  GBA* gba;
  s32 ret;
  gba = &__GBA[chan];

  if (gba->callback != NULL) {
    ret = GBA_BUSY;
  } else {
    gba->command = 0x15;
    memcpy(gba->src, src, 4);
    gba->buffer = src;
    gba->status = status;
    gba->callback = callback;
    ret = __GBATransfer(chan, 5, 1, WriteProc);
  }

  return ret;
}


s32 GBAWrite(s32 chan, u8* src, u8* status) {
  s32 ret;
  s32 tmp;
  ret = GBAWriteAsync(chan, src, status, __GBASyncCallback);
  if (ret != GBA_READY) {
    return ret;
  }
  return __GBASync(chan);
}