Skip to content

Commit

Permalink
Merge pull request #770 from Daft-Freak/pico-more-meta
Browse files Browse the repository at this point in the history
pico: More metadata
  • Loading branch information
Gadgetoid authored Jan 16, 2023
2 parents 28c221a + fd24d88 commit 24e6f24
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 20 deletions.
2 changes: 1 addition & 1 deletion 32blit-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if (NOT DEFINED BLIT_ONCE)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(BLIT_MINIMUM_TOOLS_VERSION "0.7.2")
set(BLIT_MINIMUM_TOOLS_VERSION "0.7.3")

find_package(PythonInterp 3.6 REQUIRED)

Expand Down
16 changes: 12 additions & 4 deletions 32blit-pico/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,16 @@ function(blit_metadata TARGET FILE)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -m ttblit cmake --config ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} --cmake ${CMAKE_CURRENT_BINARY_DIR}/metadata.cmake)
include(${CMAKE_CURRENT_BINARY_DIR}/metadata.cmake)

pico_set_program_name(${TARGET} "${METADATA_TITLE}")
pico_set_program_description(${TARGET} "${METADATA_DESCRIPTION}")
pico_set_program_version(${TARGET} "${METADATA_VERSION}")
pico_set_program_url(${TARGET} "${METADATA_URL}")
# create metadata/binary info source at build time
set(METADATA_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_binary_info.cpp")

add_custom_command(
OUTPUT ${METADATA_SOURCE}
COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${PYTHON_EXECUTABLE} -m ttblit metadata --force --config ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} --pico-bi ${METADATA_SOURCE}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
)

# add the generated source
target_sources(${TARGET} PRIVATE ${METADATA_SOURCE})

endfunction()
6 changes: 6 additions & 0 deletions 32blit-pico/binary_info.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#define BINARY_INFO_TAG_32BLIT BINARY_INFO_MAKE_TAG('3', 'B')

#define BINARY_INFO_ID_32BLIT_AUTHOR 0x79707D17
#define BINARY_INFO_ID_32BLIT_CATEGORY 0xF02802B0
40 changes: 26 additions & 14 deletions 32blit-pico/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "pico/stdlib.h"

#include "audio.hpp"
#include "binary_info.hpp"
#include "config.h"
#include "display.hpp"
#include "file.hpp"
Expand Down Expand Up @@ -74,24 +75,35 @@ static GameMetadata get_metadata() {
extern binary_info_t *__binary_info_start, *__binary_info_end;

for(auto tag_ptr = &__binary_info_start; tag_ptr != &__binary_info_end ; tag_ptr++) {
if((*tag_ptr)->type != BINARY_INFO_TYPE_ID_AND_STRING || (*tag_ptr)->tag != BINARY_INFO_TAG_RASPBERRY_PI)
if((*tag_ptr)->type != BINARY_INFO_TYPE_ID_AND_STRING)
continue;

auto id_str_tag = (binary_info_id_and_string_t *)*tag_ptr;

switch(id_str_tag->id) {
case BINARY_INFO_ID_RP_PROGRAM_NAME:
ret.title = id_str_tag->value;
break;
case BINARY_INFO_ID_RP_PROGRAM_VERSION_STRING:
ret.version = id_str_tag->value;
break;
case BINARY_INFO_ID_RP_PROGRAM_URL:
ret.url = id_str_tag->value;
break;
case BINARY_INFO_ID_RP_PROGRAM_DESCRIPTION:
ret.description = id_str_tag->value;
break;
if((*tag_ptr)->tag == BINARY_INFO_TAG_RASPBERRY_PI) {
switch(id_str_tag->id) {
case BINARY_INFO_ID_RP_PROGRAM_NAME:
ret.title = id_str_tag->value;
break;
case BINARY_INFO_ID_RP_PROGRAM_VERSION_STRING:
ret.version = id_str_tag->value;
break;
case BINARY_INFO_ID_RP_PROGRAM_URL:
ret.url = id_str_tag->value;
break;
case BINARY_INFO_ID_RP_PROGRAM_DESCRIPTION:
ret.description = id_str_tag->value;
break;
}
} else if((*tag_ptr)->tag == BINARY_INFO_TAG_32BLIT) {
switch(id_str_tag->id) {
case BINARY_INFO_ID_32BLIT_AUTHOR:
ret.author = id_str_tag->value;
break;
case BINARY_INFO_ID_32BLIT_CATEGORY:
ret.category = id_str_tag->value;
break;
}
}

}
Expand Down
4 changes: 3 additions & 1 deletion 32blit-pico/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "pico/binary_info.h"
#include "pico/multicore.h"

#include "binary_info.hpp"

static const uint32_t storage_size = PICO_FLASH_SIZE_BYTES / 4;
static const uint32_t storage_offset = PICO_FLASH_SIZE_BYTES - storage_size;

Expand All @@ -18,7 +20,7 @@ void get_storage_size(uint16_t &block_size, uint32_t &num_blocks) {
num_blocks = storage_size / FLASH_SECTOR_SIZE;

bi_decl(bi_block_device(
BINARY_INFO_MAKE_TAG('3', 'B'),
BINARY_INFO_TAG_32BLIT,
"32Blit",
XIP_BASE + storage_offset,
storage_size,
Expand Down

0 comments on commit 24e6f24

Please sign in to comment.