Skip to content

Commit

Permalink
Merge branch 'master' into feature/rom3M
Browse files Browse the repository at this point in the history
  • Loading branch information
Gericom committed Sep 11, 2019
2 parents cfc6525 + ce32975 commit 371815e
Show file tree
Hide file tree
Showing 54 changed files with 1,689 additions and 151 deletions.
1 change: 1 addition & 0 deletions arm7/source/gbsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ static void updateChannelFreq(int channel)
div = 4;
div *= 2 << sChannel4ShiftFreq;
int freq = 4194304 / div;
freq *= 8;
if (freq == 0)
{
REG_SOUND[GB_CHANNEL_4_HW_L].TMR = 0;
Expand Down
13 changes: 12 additions & 1 deletion arm7/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "gbsound.h"
#include "save.h"
#include "dldi_handler.h"
#include "fifo.h"
#include "../../common/fifo.h"
#include "../../common/common_defs.s"

static void vblank_handler()
Expand Down Expand Up @@ -186,6 +186,17 @@ int main()
}
break;
}
case 0xAA550100: //get rtc data
{
u8 dateTime[8];
u8 cmd = READ_TIME_AND_DATE;
rtcTransaction(&cmd, 1, dateTime, 7);
cmd = READ_STATUS_REG1;
rtcTransaction(&cmd, 1, &dateTime[7], 1);
REG_SEND_FIFO = *(u32*)&dateTime[0];
REG_SEND_FIFO = *(u32*)&dateTime[4];
break;
}
case 0x040000A0:
while (REG_FIFO_CNT & FIFO_CNT_EMPTY);
val = REG_RECV_FIFO;
Expand Down
4 changes: 3 additions & 1 deletion arm7/source/sound.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <nds.h>
#include <string.h>
#include "timer.h"
#include "fifo.h"
#include "../../common/fifo.h"
#include "../../common/sd_vram.h"
#include "lock.h"
#include "sound.h"
Expand Down Expand Up @@ -222,6 +222,8 @@ void gba_sound_fifo_write(uint32_t samps)

void gba_sound_set_src(uint32_t address)
{
if(srcAddress == address - 16 || srcAddress == address || srcAddress == address + 16)
return;
srcAddress = address;
REG_TM[3].CNT_H = 0;
sampcnter = 0;
Expand Down
7 changes: 7 additions & 0 deletions arm9/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ ifdef ENABLE_WRAM_ICACHE
CFLAGS += -DENABLE_WRAM_ICACHE
endif

GIT_HASH := $(shell git rev-parse HEAD)
GIT_DATE := $(shell git log -1 "--date=format:%d-%m-%Y\ %H:%M" --pretty=format:%cd)
GIT_BRANCH := $(shell git describe --all --exact-match | sed 's/heads\///' | sed 's/remotes\/origin\///')

CFLAGS += -DGIT_COMMIT_HASH=$(GIT_HASH) -DGIT_COMMIT_DATE=$(GIT_DATE) -DGIT_BRANCH=$(GIT_BRANCH)


CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fnon-call-exceptions

ASFLAGS := -g $(ARCH) -march=armv5te -mtune=arm946e-s $(INCLUDE)
Expand Down
Binary file added arm9/data/CheckboxMarked.nbfc
Binary file not shown.
Binary file added arm9/data/CheckboxOutline.nbfc
Binary file not shown.
Binary file added arm9/data/IconGamepad.nbfc
Binary file not shown.
Binary file added arm9/data/IconInformation.nbfc
Binary file not shown.
Binary file added arm9/data/IconPlayCircle.nbfc
Binary file not shown.
Binary file added arm9/data/RobotoRegular9.ntft
Binary file not shown.
10 changes: 10 additions & 0 deletions arm9/source/INIReader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once
#include "fat/ff.h"

typedef void (*inir_callback_t)(void* arg, const char* section, const char* key, const char* value);

class INIReader
{
public:
static bool Parse(FIL* file, inir_callback_t callback, void* arg);
};
31 changes: 31 additions & 0 deletions arm9/source/INIReader.vram.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "vram.h"
#include "vramheap.h"
#include "string.h"
#include "fat/ff.h"
#include "INIReader.h"

bool INIReader::Parse(FIL* file, inir_callback_t callback, void* arg)
{
char line[128];
char section[128];
while (f_gets(line, sizeof(line), file))
{
if(line[0] == ';')
continue;
char* newLine = strchr(line, '\n');
*newLine = 0;
if(line[0] == '[')
{
int len = strlen(line) - 2;
for(int i = 0; i < len; i++)
section[i] = line[i + 1];
section[len] = 0;
continue;
}
char* equals = strchr(line, '=');
if(!equals)
continue;
*equals = 0;
callback(arg, section, line, equals + 1);
}
}
14 changes: 14 additions & 0 deletions arm9/source/INIWriter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include "fat/ff.h"

class INIWriter
{
FIL* _file;
public:
explicit INIWriter(FIL* file);

void WriteSection(const char* name);
void WriteProperty(const char* key, const char* value);
void WriteBooleanProperty(const char* key, bool value);
void WriteIntegerProperty(const char* key, int value);
};
30 changes: 30 additions & 0 deletions arm9/source/INIWriter.vram.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "vram.h"
#include "vramheap.h"
#include "fat/ff.h"
#include "INIWriter.h"

INIWriter::INIWriter(FIL* file)
: _file(file)
{

}

void INIWriter::WriteSection(const char* name)
{
f_printf(_file, "[%s]\n", name);
}

void INIWriter::WriteProperty(const char* key, const char* value)
{
f_printf(_file, "%s=%s\n", key, value);
}

void INIWriter::WriteBooleanProperty(const char* key, bool value)
{
WriteProperty(key, value ? "true" : "false");
}

void INIWriter::WriteIntegerProperty(const char* key, int value)
{
f_printf(_file, "%s=%d\n", key, value);
}
2 changes: 2 additions & 0 deletions arm9/source/bios.vram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ BiosLoadResult bios_load()
FRESULT result = f_open(&vram_cd->fil, "0:/bios.bin", FA_OPEN_EXISTING | FA_READ);
if (result != FR_OK)
result = f_open(&vram_cd->fil, "0:/gba/bios.bin", FA_OPEN_EXISTING | FA_READ);
if (result != FR_OK)
result = f_open(&vram_cd->fil, "0:/_gba/bios.bin", FA_OPEN_EXISTING | FA_READ);
if (result != FR_OK)
return BIOS_LOAD_RESULT_NOT_FOUND;
if (vram_cd->fil.obj.objsize != BIOS_SIZE)
Expand Down
5 changes: 4 additions & 1 deletion arm9/source/dtcm_data.s
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ cpu_mode_switch_dtcm:
.word pu_data_permissions
.word data_abort_handler_cont_finish
.word 0x08088008 //arm low instruction mask
.rept 12
.global dbgDatarightsTmp
dbgDatarightsTmp:
.word 0
.rept 11
.word 0
.endr
.word data_abort_handler_arm_usr_sys //usr
Expand Down
17 changes: 16 additions & 1 deletion arm9/source/emu/handle_address_write.s
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ write_address_from_handler_16bit:
.word write_address_ignore
.word write_address_from_handler_vram_16
.word write_address_ignore
.word write_address_ignore
.word write_address_from_handler_rom_gpio_16
.word write_address_ignore
.word write_address_ignore
.word write_address_ignore
Expand Down Expand Up @@ -144,6 +144,21 @@ write_address_from_handler_vram_16:
strh r11, [r10]
bx lr

write_address_from_handler_rom_gpio_16:
ldr r13,= 0x080000C4
subs r13, r9, r13
bxlt lr
cmp r13, #0x4
bxgt lr
ldr sp,= address_dtcm + (16 * 1024)
push {r0-r3,lr}
mov r0, r9
mov r1, r11
ldr r12,= rio_write
blx r12
pop {r0-r3,lr}
bx lr

write_address_from_handler_sram_16:
ldr r12,= 0x01FF0000
bic r10, r9, r12
Expand Down
8 changes: 8 additions & 0 deletions arm9/source/emu/irq.s
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,18 @@ irq_handler_arm7_irq:
ldrh lr, [r0, #0x16]
tst lr, #(1 << 14)
orrne r1, #(1 << 9) //dma 1
//if no repeat, stop dma
tst lr, #(1 << 9)
biceq lr, #0x8000
streqh lr, [r0, #0x16]

ldrh lr, [r0, #0x22]
tst lr, #(1 << 14)
orrne r1, #(1 << 10) //dma 2
//if no repeat, stop dma
tst lr, #(1 << 9)
biceq lr, #0x8000
streqh lr, [r0, #0x22]

str r1, [r2]

Expand Down
15 changes: 15 additions & 0 deletions arm9/source/emu/romGpio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

typedef u16 RomGpioHwMask;

#define RIO_NONE 0
#define RIO_RTC (1 << 0)
#define RIO_LIGHT (1 << 1)

extern u16 gRioGpioData;
extern u16 gRioGpioDirection;
extern u16 gRioGpioControl;

void rio_init(RomGpioHwMask forceHwMask);
extern "C" void rio_write(u32 addr, u16 val);
void rio_invalidate();
130 changes: 130 additions & 0 deletions arm9/source/emu/romGpio.vram.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#include "vram.h"
#include "consts.s"
#include "romGpioRtc.h"
#include "romGpio.h"

struct game_hw_info_t
{
u32 gameCode;
RomGpioHwMask hardware;
};

#define GAMECODE(x) ((((x) & 0xFF) << 24) | ((((x) >> 8) & 0xFF) << 16) | ((((x) >> 16) & 0xFF) << 8) | ((x) >> 24))

static game_hw_info_t sGameHardwareTable[] =
{
// Boktai: The Sun is in Your Hand
{ GAMECODE('U3IJ'), RIO_RTC | RIO_LIGHT },
{ GAMECODE('U3IE'), RIO_RTC | RIO_LIGHT },
{ GAMECODE('U3IP'), RIO_RTC | RIO_LIGHT },

// Boktai 2: Solar Boy Django
{ GAMECODE('U32J'), RIO_RTC | RIO_LIGHT },
{ GAMECODE('U32E'), RIO_RTC | RIO_LIGHT },
{ GAMECODE('U32P'), RIO_RTC | RIO_LIGHT },

// Pokemon Ruby
{ GAMECODE('AXVJ'), RIO_RTC },
{ GAMECODE('AXVE'), RIO_RTC },
{ GAMECODE('AXVP'), RIO_RTC },
{ GAMECODE('AXVI'), RIO_RTC },
{ GAMECODE('AXVS'), RIO_RTC },
{ GAMECODE('AXVD'), RIO_RTC },
{ GAMECODE('AXVF'), RIO_RTC },

// Pokemon Sapphire
{ GAMECODE('AXPJ'), RIO_RTC },
{ GAMECODE('AXPE'), RIO_RTC },
{ GAMECODE('AXPP'), RIO_RTC },
{ GAMECODE('AXPI'), RIO_RTC },
{ GAMECODE('AXPS'), RIO_RTC },
{ GAMECODE('AXPD'), RIO_RTC },
{ GAMECODE('AXPF'), RIO_RTC },

// Pokemon Emerald
{ GAMECODE('BPEJ'), RIO_RTC },
{ GAMECODE('BPEE'), RIO_RTC },
{ GAMECODE('BPEP'), RIO_RTC },
{ GAMECODE('BPEI'), RIO_RTC },
{ GAMECODE('BPES'), RIO_RTC },
{ GAMECODE('BPED'), RIO_RTC },
{ GAMECODE('BPEF'), RIO_RTC },

// RockMan EXE 4.5 - Real Operation
{ GAMECODE('BR4J'), RIO_RTC },

// Sennen Kazoku
{ GAMECODE('BKAJ'), RIO_RTC },

// Shin Bokura no Taiyou: Gyakushuu no Sabata
{ GAMECODE('U33J'), RIO_RTC | RIO_LIGHT },
};

#define RIO_REG_DATA 0xC4
#define RIO_REG_DIRECTION 0xC6
#define RIO_REG_CONTROL 0xC8

static RomGpioHwMask sGpioHwMask;

u16 gRioGpioData;
u16 gRioGpioDirection;
u16 gRioGpioControl;

void rio_init(RomGpioHwMask forceHwMask)
{
sGpioHwMask = forceHwMask;
u32 gameCode = *(u32*)(MAIN_MEMORY_ADDRESS_ROM_DATA + 0xAC);
for(int i = 0; i < sizeof(sGameHardwareTable) / sizeof(sGameHardwareTable[0]); i++)
{
if(sGameHardwareTable[i].gameCode == gameCode)
{
sGpioHwMask = sGameHardwareTable[i].hardware | forceHwMask;
break;
}
}
gRioGpioData = 0;
gRioGpioDirection = 0;
gRioGpioControl = 0;
if(sGpioHwMask & RIO_RTC)
rio_rtcInit();
}

static void updateHardware()
{
if(sGpioHwMask & RIO_RTC)
rio_rtcUpdate();
}

extern "C" void rio_write(u32 addr, u16 val)
{
switch(addr - 0x08000000)
{
case RIO_REG_DATA:
gRioGpioData = (gRioGpioData & ~gRioGpioDirection) | (val & gRioGpioDirection);
updateHardware();
break;
case RIO_REG_DIRECTION:
gRioGpioDirection = val & 0xF;
break;
case RIO_REG_CONTROL:
gRioGpioControl = val & 1;
break;
}
rio_invalidate();
}

void rio_invalidate()
{
if(gRioGpioControl)
{
*(u16*)(MAIN_MEMORY_ADDRESS_ROM_DATA + RIO_REG_DATA) = gRioGpioData;
*(u16*)(MAIN_MEMORY_ADDRESS_ROM_DATA + RIO_REG_DIRECTION) = gRioGpioDirection;
*(u16*)(MAIN_MEMORY_ADDRESS_ROM_DATA + RIO_REG_CONTROL) = gRioGpioControl;
}
else
{
*(u16*)(MAIN_MEMORY_ADDRESS_ROM_DATA + RIO_REG_DATA) = 0;
*(u16*)(MAIN_MEMORY_ADDRESS_ROM_DATA + RIO_REG_DIRECTION) = 0;
*(u16*)(MAIN_MEMORY_ADDRESS_ROM_DATA + RIO_REG_CONTROL) = 0;
}
}
4 changes: 4 additions & 0 deletions arm9/source/emu/romGpioRtc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

void rio_rtcInit();
void rio_rtcUpdate();
Loading

0 comments on commit 371815e

Please sign in to comment.