101 lines
2.4 KiB
C

/*
* This file is part of open_agb_firm
* Copyright (C) 2021 derrek, profi200
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "fs.h"
#include "arm11/open_agb_firm.h"
#include "drivers/gfx.h"
#include "arm11/drivers/mcu.h"
#include "arm11/console.h"
#include "arm11/drivers/codec.h"
#include "arm11/drivers/hid.h"
#include "arm11/power.h"
#include "arm11/acf.h"
// @MERGE 231006 START
#include "oaf_error_codes.h"
// @MERGE 231006 END
static void setBacklight(void)
{
u16 backlightMax;
u16 backlightMin;
if(MCU_getSystemModel() >= 4)
{
backlightMax=800;
backlightMin=50;
}
else
{
backlightMax=500;
backlightMin=20;
}
const u16 backlight = oafGetBacklightConfig();
if (backlight > backlightMax) GFX_setBrightness(backlightMax, backlightMax);
else if (backlight < backlightMin) GFX_setBrightness(backlightMin, backlightMin);
else GFX_setBrightness(backlight, backlight);
}
Result fReadSize( FHandle file, void *buff, unsigned size, uint32_t *readout )
{
uint32_t fill = 0;
uint32_t readed;
do{
Result res;
if( RES_OK != (res=fRead(file, buff+fill, size-fill < 256 ? size-fill : 256, &readed)) ){
*readout = fill;
return res;
}
fill += readed;
} while( fill < size );
*readout = fill;
return RES_OK;
}
int main(void)
{
Result res = fMount(FS_DRIVE_SDMC);
if(res == RES_OK) res = oafParseConfigEarly();
GFX_init(GFX_BGR8, GFX_RGB565);
setBacklight();
consoleInit(SCREEN_BOT, NULL);
//CODEC_init();
if(res == RES_OK && (res = oafInitAndRun()) == RES_OK)
{
do
{
hidScanInput();
if(hidGetExtraKeys(0) & (KEY_POWER_HELD | KEY_POWER)) break;
oafUpdate();
} while(1);
oafFinish();
}
else printErrorWaitInput(res, 0);
CODEC_deinit();
GFX_deinit();
fUnmount(FS_DRIVE_SDMC);
power_off();
return 0;
}