/*---------------------------------------------------------------------------* Project: Horizon File: fs.cpp Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 46365 $ *---------------------------------------------------------------------------*/ #include #include "fs.h" #include "applet.h" void FsDemo::Initialize(demo::RenderSystemDrawing* p_RenderSystem, nn::fnd::ExpHeap* p_AppHeap) { Device::Initialize(p_RenderSystem); mp_AppHeap = p_AppHeap; } void FsDemo::Finalize(void) { Device::Finalize(); } void FsDemo::Start(void) { Device::Start(); m_ExitEvent.Initialize(false); // Open the file m_RomFsFile.Initialize(L"rom:/test.txt"); // Create buffer to load file contents s64 fileSize = m_RomFsFile.GetSize(); m_FileBuffer = reinterpret_cast(mp_AppHeap->Allocate(fileSize)); m_Thread.Start(FsDemo::ThreadFunc, this, m_Stack); } void FsDemo::End(void) { // Destroy the buffer mp_AppHeap->Free(m_FileBuffer); m_ExitEvent.Signal(); m_Thread.Join(); // Close the file m_RomFsFile.Finalize(); Device::End(); } void FsDemo::DrawFrame(void) { } void FsDemo::ThreadFuncImpl() { // Because file reads automatically stop in Sleep Mode, we do not need an exclusive lock of some kind. // while ( !m_ExitEvent.TryWait() ) { TransitionHandler::Lock(); { // Move to start of file m_RomFsFile.SetPosition(0); // Copy file contents to buffer s64 fileSize = m_RomFsFile.GetSize(); m_RomFsFile.Read(m_FileBuffer, fileSize); } TransitionHandler::Unlock(); nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromMilliSeconds(100)); } } void FsDemo::ThreadFunc(FsDemo* pFsDemo) { pFsDemo->ThreadFuncImpl(); } /*---------------------------------------------------------------------------* End of file *---------------------------------------------------------------------------*/