Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pico: More metadata #770

Merged
merged 5 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -113,8 +113,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 @@ -7,6 +7,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 @@ -73,24 +74,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 @@ -7,6 +7,8 @@
#include "hardware/sync.h"
#include "pico/binary_info.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 @@ -15,7 +17,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