Add ability to read media section
This commit is contained in:
parent
ae5b199b1f
commit
fd5beb2adf
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ build/current
|
||||
build/gba
|
||||
build/*-release
|
||||
build/*-debug
|
||||
tags
|
||||
|
@ -13,6 +13,8 @@ endif()
|
||||
set(CMAKE_C_COMPILER ${DEVKITARM}/bin/arm-none-eabi-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${DEVKITARM}/bin/arm-none-eabi-g++)
|
||||
set(CMAKE_OBJCOPY ${DEVKITARM}/bin/arm-none-eabi-objcopy)
|
||||
set(CMAKE_PADBIN ${DEVKITARM}/bin/padbin)
|
||||
set(CMAKE_GBAFIX ${DEVKITARM}/bin/gbafix)
|
||||
set(CMAKE_FIND_ROOT_PATH ${DEVKITARM})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
@ -38,18 +40,21 @@ macro(OBJCOPY_FILE EXE_NAME)
|
||||
set(FO ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME}.bin)
|
||||
set(FI ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME})
|
||||
message(STATUS ${FO})
|
||||
|
||||
# run objcopy
|
||||
add_custom_command(
|
||||
OUTPUT "${FO}"
|
||||
COMMAND ${CMAKE_OBJCOPY}
|
||||
ARGS -O binary ${FI} ${FO}
|
||||
DEPENDS ${FI}
|
||||
DEPENDS "${FI}"
|
||||
)
|
||||
|
||||
get_filename_component(TGT "${EXE_NAME}" NAME)
|
||||
add_custom_target("TargetObjCopy_${TGT}" ALL DEPENDS ${FO} VERBATIM)
|
||||
get_directory_property(extra_clean_files ADDITIONAL_MAKE_CLEAN_FILES)
|
||||
set_directory_properties(
|
||||
PROPERTIES
|
||||
ADDITIONAL_MAKE_CLEAN_FILES "${extra_clean_files};${FO}"
|
||||
ADDITIONAL_MAKE_CLEAN_FILES "${extra_clean_files};${FO};"
|
||||
)
|
||||
set_source_files_properties("${FO}" PROPERTIES GENERATED TRUE)
|
||||
endmacro(OBJCOPY_FILE)
|
||||
|
@ -5,6 +5,7 @@ if(WOMBAT_BUILD_TYPE STREQUAL "GBA")
|
||||
set(
|
||||
CPP
|
||||
gba/gfx.cpp
|
||||
gba/media.cpp
|
||||
gba/dirt.s
|
||||
)
|
||||
elseif(WOMBAT_BUILD_TYPE STREQUAL "Native")
|
||||
|
48
src/core/gba/addresses.hpp
Normal file
48
src/core/gba/addresses.hpp
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/types.hpp>
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// I/O Registers
|
||||
|
||||
#define REG_DISPCNT *((volatile uint32_t*) 0x04000000)
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// background registers
|
||||
|
||||
// background control registers
|
||||
#define REG_BG0CNT *((volatile uint32_t*) 0x04000008)
|
||||
#define REG_BG1CNT *((volatile uint32_t*) 0x0400000a)
|
||||
#define REG_BG2CNT *((volatile uint32_t*) 0x0400000c)
|
||||
#define REG_BG3CNT *((volatile uint32_t*) 0x0400000e)
|
||||
|
||||
// background horizontal scrolling registers
|
||||
#define REG_BG0HOFS *((volatile uint32_t*) 0x04000010)
|
||||
#define REG_BG1HOFS *((volatile uint32_t*) 0x04000014)
|
||||
#define REG_BG2HOFS *((volatile uint32_t*) 0x04000018)
|
||||
#define REG_BG3HOFS *((volatile uint32_t*) 0x0400001c)
|
||||
|
||||
// background vertical scrolling registers
|
||||
#define REG_BG0VOFS *((volatile uint32_t*) 0x04000012)
|
||||
#define REG_BG1VOFS *((volatile uint32_t*) 0x04000016)
|
||||
#define REG_BG2VOFS *((volatile uint32_t*) 0x0400001a)
|
||||
#define REG_BG3VOFS *((volatile uint32_t*) 0x0400001e)
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// Memory Addresses
|
||||
|
||||
#define MEM_PALLETE_BG *((unsigned short*) 0x05000000)
|
||||
#define MEM_PALLETE_SPRITE *((unsigned short*) 0x05000200)
|
||||
|
||||
typedef uint16_t BgMapTile[1024];
|
||||
#define MEM_BG_MAP ((BgMapTile*) 0x06000000)
|
||||
|
||||
#define MEM_ROM *((uint8_t*) 0x08000000)
|
@ -6,13 +6,16 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <ox/std/types.hpp>
|
||||
#include "registers.hpp"
|
||||
#include <ox/fs/filesystem.hpp>
|
||||
#include <ox/std/std.hpp>
|
||||
#include "addresses.hpp"
|
||||
#include "media.hpp"
|
||||
#include "dirt.h"
|
||||
|
||||
namespace nostalgia {
|
||||
namespace core {
|
||||
|
||||
using namespace ox::fs;
|
||||
using namespace ox::std;
|
||||
|
||||
typedef struct { uint32_t data[8]; } Tile, Tile4;
|
||||
@ -26,12 +29,6 @@ typedef Tile8 CharBlock8[256];
|
||||
#define TILE_ADDR ((CharBlock*) 0x06000000)
|
||||
#define TILE8_ADDR ((CharBlock8*) 0x06000000)
|
||||
|
||||
#define PALLETE_BG ((unsigned short*) 0x05000000)
|
||||
#define PALLETE_SPRITE ((unsigned short*) 0x05000200)
|
||||
|
||||
typedef uint16_t BgMapTile[1024];
|
||||
#define BG_MAP ((BgMapTile*) 0x06000000)
|
||||
|
||||
ox::std::Error initGfx() {
|
||||
/* Sprite Mode ----\ */
|
||||
/* ---\| */
|
||||
@ -43,11 +40,22 @@ ox::std::Error initGfx() {
|
||||
TILE_ADDR[0][1] = *(Tile*) dirtTiles;
|
||||
|
||||
for (auto i = 0; i < (dirtPalLen / 2); i++) {
|
||||
PALLETE_BG[i] = dirtPal[i];
|
||||
(&MEM_PALLETE_BG)[i] = dirtPal[i];
|
||||
}
|
||||
|
||||
BG_MAP[28][52] = 1;
|
||||
auto fs = (FileStore32*) findMedia();
|
||||
REG_BG0CNT = (28 << 8) | 1;
|
||||
MEM_BG_MAP[28][106] = 1;
|
||||
MEM_BG_MAP[28][107] = 1;
|
||||
if (fs) {
|
||||
char out[6];
|
||||
FileStore32::FsSize_t outSize = 0;
|
||||
fs->read(3, out, &outSize);
|
||||
if (outSize == 5 && ox_strcmp(out, "narf") == 0) {
|
||||
MEM_BG_MAP[28][138] = 1;
|
||||
MEM_BG_MAP[28][139] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
36
src/core/gba/media.cpp
Normal file
36
src/core/gba/media.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <ox/fs/filesystem.hpp>
|
||||
#include <ox/std/std.hpp>
|
||||
#include "addresses.hpp"
|
||||
#include "media.hpp"
|
||||
|
||||
namespace nostalgia {
|
||||
namespace core {
|
||||
|
||||
uint8_t *findMedia() {
|
||||
// put the header in the wrong order to prevent mistaking this code for the
|
||||
// media section
|
||||
const static auto headerP2 = "_HEADER_________";
|
||||
const static auto headerP1 = "NOSTALGIA_MEDIA";
|
||||
const static auto headerP1Len = 15;
|
||||
const static auto headerP2Len = 16;
|
||||
const static auto headerLen = headerP1Len + headerP2Len + 1;
|
||||
|
||||
for (uint8_t *current = &MEM_ROM; current < ((uint8_t*) 0x0a000000); current += headerLen) {
|
||||
if (ox_memcmp(current, headerP1, headerP1Len) == 0 ||
|
||||
ox_memcmp(current + headerP1Len, headerP2, headerP2Len) == 0) {
|
||||
return current + headerLen;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
19
src/core/gba/media.hpp
Normal file
19
src/core/gba/media.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/types.hpp>
|
||||
|
||||
namespace nostalgia {
|
||||
namespace core {
|
||||
|
||||
uint8_t *findMedia();
|
||||
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
#ifndef NOSTALGIA_CORE_GBA_REGISTERS_HPP
|
||||
#define NOSTALGIA_CORE_GBA_REGISTERS_HPP
|
||||
|
||||
#define REG_DISPCNT *((volatile unsigned int*) 0x04000000)
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// background registers
|
||||
|
||||
// control registers
|
||||
#define REG_BG0CNT *((volatile unsigned int*) 0x04000008)
|
||||
#define REG_BG1CNT *((volatile unsigned int*) 0x0400000a)
|
||||
#define REG_BG2CNT *((volatile unsigned int*) 0x0400000c)
|
||||
#define REG_BG3CNT *((volatile unsigned int*) 0x0400000e)
|
||||
|
||||
// horizontal scrolling registers
|
||||
#define REG_BG0HOFS *((volatile unsigned int*) 0x04000010)
|
||||
#define REG_BG1HOFS *((volatile unsigned int*) 0x04000014)
|
||||
#define REG_BG2HOFS *((volatile unsigned int*) 0x04000018)
|
||||
#define REG_BG3HOFS *((volatile unsigned int*) 0x0400001c)
|
||||
|
||||
// vertical scrolling registers
|
||||
#define REG_BG0VOFS *((volatile unsigned int*) 0x04000012)
|
||||
#define REG_BG1VOFS *((volatile unsigned int*) 0x04000016)
|
||||
#define REG_BG2VOFS *((volatile unsigned int*) 0x0400001a)
|
||||
#define REG_BG3VOFS *((volatile unsigned int*) 0x0400001e)
|
||||
|
||||
#endif
|
@ -7,18 +7,20 @@ add_executable(
|
||||
main.cpp
|
||||
)
|
||||
|
||||
if(COMMAND objcopy_file)
|
||||
if(COMMAND OBJCOPY_FILE)
|
||||
set_target_properties(nostalgia
|
||||
PROPERTIES
|
||||
LINK_FLAGS ${LINKER_FLAGS}
|
||||
COMPILER_FLAGS "-mthumb -mthumb-interwork"
|
||||
)
|
||||
|
||||
objcopy_file(nostalgia)
|
||||
OBJCOPY_FILE(nostalgia)
|
||||
#PADBIN_FILE(nostalgia)
|
||||
endif()
|
||||
|
||||
target_link_libraries(
|
||||
nostalgia
|
||||
NostalgiaCore
|
||||
${OxStd_LIBRARY}
|
||||
${OxFS_LIBRARY}
|
||||
)
|
||||
|
@ -12,5 +12,6 @@ using namespace nostalgia;
|
||||
|
||||
int main() {
|
||||
core::init();
|
||||
while (1);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user