summaryrefslogtreecommitdiff
path: root/src/Dolphin/dvd/fstload.c
blob: 1f7a81b20ed43c97c69d7c0e8a4093077c4b70b9 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <dolphin/DVDPriv.h>
#include <dolphin/dvd.h>
#include <dolphin/dvd_regs.h>
#include <dolphin/os.h>
#include <dolphin/os/OSBootInfo.h>
#include <string.h>

static s32 status = 0;

static u8 bb2Buf[OSRoundUp32B(sizeof(DVDBB2)) + 31];
static DVDBB2* bb2 = 0;
static DVDDiskID* idTmp = NULL;

static void cb(s32 result, DVDCommandBlock* block) {
  if (result > 0) {
    switch (status) {
    case 0:
      status = 1;
      DVDReadAbsAsyncForBS(block, bb2, OSRoundUp32B(sizeof(bb2)), 0x420, cb);
      break;
    case 1:
      status = 2;
      DVDReadAbsAsyncForBS(block, bb2->FSTAddress, OSRoundUp32B(bb2->FSTLength), bb2->FSTPosition,
                           cb);
    }
  } else if (result == -1) {

  } else if (result == -4) {
    status = 0;
    DVDReset();
    DVDReadDiskID(block, idTmp, cb);
  }
}

void __fstLoad() {
  OSBootInfo* bootInfo;
  DVDDiskID* id;
  u8 idTmpBuf[sizeof(DVDDiskID) + 31];
  static DVDCommandBlock block;
  void* arenaHi;

  arenaHi = OSGetArenaHi();
  bootInfo = (OSBootInfo*)OSPhysicalToCached(0);

  idTmp = (DVDDiskID*)(OSRoundUp32B(idTmpBuf));
  bb2 = (DVDBB2*)(OSRoundUp32B(bb2Buf));

  DVDReset();
  DVDReadDiskID(&block, idTmp, cb);
  while (DVDGetDriveStatus() != 0);

  bootInfo->FSTLocation = bb2->FSTAddress;
  bootInfo->FSTMaxLength = bb2->FSTMaxLength;

  id = &bootInfo->DVDDiskID;

  memcpy(id, idTmp, sizeof(DVDDiskID));
  OSReport("\n");
  OSReport("  Game Name ... %c%c%c%c\n", id->gameName[0], id->gameName[1], id->gameName[2],
           id->gameName[3]);
  OSReport("  Company ..... %c%c\n", id->company[0], id->company[1]);
  OSReport("  Disk # ...... %d\n", id->diskNumber);
  OSReport("  Game ver .... %d\n", id->gameVersion);
  OSReport("  Streaming ... %s\n", (id->streaming == 0) ? "OFF" : "ON");
  OSReport("\n");
  OSSetArenaHi(bb2->FSTAddress);
}