From ae6c1c61c1e66d3834f4a97b97b416b7f9d63dcc Mon Sep 17 00:00:00 2001 From: d0k3 Date: Tue, 6 Feb 2018 00:40:54 +0100 Subject: [PATCH] Fix all occurences of VCART_BUFFER --- arm9/source/common/common.h | 3 --- arm9/source/virtual/vcart.c | 10 ++++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arm9/source/common/common.h b/arm9/source/common/common.h index 4b2f654..de1c541 100644 --- a/arm9/source/common/common.h +++ b/arm9/source/common/common.h @@ -55,9 +55,6 @@ // buffer area defines (in use by vgame.c) #define VGAME_BUFFER ((u8*)0x20400000) #define VGAME_BUFFER_SIZE (0x200000) // 2MB, big RomFS -// buffer area defines (in use by vcart.c) -#define VCART_BUFFER ((u8*)0x20600000) -#define VCART_BUFFER_SIZE (0x20000) // 128kB, this is more than enough // buffer area defines (in use by image.c, for RAMdrive) #define RAMDRV_BUFFER ((u8*)0x22800000) // top of STACK diff --git a/arm9/source/virtual/vcart.c b/arm9/source/virtual/vcart.c index 6753e6e..3309522 100644 --- a/arm9/source/virtual/vcart.c +++ b/arm9/source/virtual/vcart.c @@ -4,11 +4,16 @@ #define FAT_LIMIT 0x100000000 #define VFLAG_PRIV_HDR (1UL<<31) -static CartData* cdata = (CartData*) VCART_BUFFER; // 128kB reserved (~64kB required) +static CartData* cdata = NULL; static bool cart_init = false; u32 InitVCartDrive(void) { - cart_init = ((InitCardRead(cdata) == 0) && (cdata->cart_size <= FAT_LIMIT)); + if (!cdata) cdata = (CartData*) malloc(sizeof(CartData)); + cart_init = (cdata && (InitCardRead(cdata) == 0) && (cdata->cart_size <= FAT_LIMIT)); + if (!cart_init && cdata) { + free(cdata); + cdata = NULL; + } return cart_init ? cdata->cart_id : 0; } @@ -56,6 +61,7 @@ bool ReadVCartDir(VirtualFile* vfile, VirtualDir* vdir) { int ReadVCartFile(const VirtualFile* vfile, void* buffer, u64 offset, u64 count) { u32 foffset = vfile->offset + offset; + if (!cdata) return -1; if (vfile->flags & VFLAG_PRIV_HDR) return ReadCartPrivateHeader(buffer, foffset, count, cdata); else return ReadCartBytes(buffer, foffset, count, cdata);