-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4d1c54d
Showing
16 changed files
with
560 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "lib/tamalib"] | ||
path = lib/tamalib | ||
url = https://github.com/GMMan/tamalib.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Tamagotchi P1 Emulator for Flipper Zero | ||
======================================= | ||
|
||
This is a Tamagotchi P1 Emulator app for Flipper Zero, based on [TamaLIB](https://github.com/jcrona/tamalib/). | ||
|
||
How to play | ||
----------- | ||
Create a `tama_p1` folder in your microSD card, and put the ROM as `rom.bin`. | ||
Left button is A, OK is B, and right button is C. Hold the back button to exit. | ||
There is currently no saving, so your progress will be reset when you exit the | ||
app. | ||
|
||
Implemented | ||
----------- | ||
- Basic emulation | ||
- Input | ||
- Sound | ||
|
||
To-do | ||
----- | ||
- Saving/loading | ||
- Multiple slots? | ||
- In-game reset | ||
- Test mode? | ||
- Volume adjustment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
App( | ||
appid="tamagotchi_p1", | ||
name="Tamagotchi", | ||
apptype=FlipperAppType.EXTERNAL, | ||
entry_point="tamagotchi_p1_app", | ||
cdefines=["APP_TAMAGOTCHI_P1"], | ||
requires=["gui", "storage"], | ||
stack_size=1 * 1024, | ||
icon="A_Plugins_14", | ||
fap_version=(0,1), | ||
fap_category="Games", | ||
fap_description="Tamagotchi P1 emulator", | ||
fap_author="cyanic", | ||
fap_weburl="https://github.com/GMMan/flipperzero-tamagotch-p1", | ||
fap_private_libs=[ | ||
Lib( | ||
name="tamalib", | ||
cflags=["-Wno-unused-parameter"], | ||
), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#include <furi.h> | ||
#include <furi_hal.h> | ||
#include <stdlib.h> | ||
#include <m-string.h> | ||
#include <stm32wbxx_ll_tim.h> | ||
#include "tama.h" | ||
|
||
#define TAG_HAL "TamaLIB" | ||
|
||
static void* tamagotchi_p1_hal_malloc(u32_t size) { | ||
return malloc(size); | ||
} | ||
|
||
static void tamagotchi_p1_hal_free(void* ptr) { | ||
free(ptr); | ||
} | ||
|
||
static void tamagotchi_p1_hal_halt(void) { | ||
g_ctx->halted = true; | ||
} | ||
|
||
static bool_t tamagotchi_p1_hal_is_log_enabled(log_level_t level) { | ||
switch(level) { | ||
case LOG_ERROR: | ||
return true; | ||
case LOG_INFO: | ||
return true; | ||
case LOG_MEMORY: | ||
return false; | ||
case LOG_CPU: | ||
return false; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
static void tamagotchi_p1_hal_log(log_level_t level, char* buff, ...) { | ||
if(!tamagotchi_p1_hal_is_log_enabled(level)) return; | ||
|
||
string_t string; | ||
va_list args; | ||
va_start(args, buff); | ||
string_init_vprintf(string, buff, args); | ||
va_end(args); | ||
|
||
switch(level) { | ||
case LOG_ERROR: | ||
FURI_LOG_E(TAG_HAL, "%s", string_get_cstr(string)); | ||
break; | ||
case LOG_INFO: | ||
FURI_LOG_I(TAG_HAL, "%s", string_get_cstr(string)); | ||
break; | ||
case LOG_MEMORY: | ||
case LOG_CPU: | ||
default: | ||
FURI_LOG_D(TAG_HAL, "%s", string_get_cstr(string)); | ||
break; | ||
} | ||
|
||
string_clear(string); | ||
} | ||
|
||
static void tamagotchi_p1_hal_sleep_until(timestamp_t ts) { | ||
while(true) { | ||
uint32_t count = LL_TIM_GetCounter(TIM2); | ||
uint32_t delay = ts - count; | ||
// FURI_LOG_D(TAG, "delay: %x", delay); | ||
// Stolen from furi_delay_until_tick | ||
if(delay != 0 && 0 == (delay >> (8 * sizeof(uint32_t) - 1))) { | ||
// Not the best place to release mutex, but this is the only place we know whether | ||
// we're ahead or behind, otherwise around the step call we'll always have to | ||
// delay a tick and run more and more behind. | ||
furi_mutex_release(g_state_mutex); | ||
furi_delay_tick(1); | ||
while(furi_mutex_acquire(g_state_mutex, FuriWaitForever) != FuriStatusOk) | ||
furi_delay_tick(1); | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
static timestamp_t tamagotchi_p1_hal_get_timestamp(void) { | ||
return LL_TIM_GetCounter(TIM2); | ||
} | ||
|
||
static void tamagotchi_p1_hal_update_screen(void) { | ||
// Do nothing, covered by main loop | ||
} | ||
|
||
static void tamagotchi_p1_hal_set_lcd_matrix(u8_t x, u8_t y, bool_t val) { | ||
if(val) | ||
g_ctx->framebuffer[y] |= 1 << x; | ||
else | ||
g_ctx->framebuffer[y] &= ~(1 << x); | ||
} | ||
|
||
static void tamagotchi_p1_hal_set_lcd_icon(u8_t icon, bool_t val) { | ||
if(val) | ||
g_ctx->icons |= 1 << icon; | ||
else | ||
g_ctx->icons &= ~(1 << icon); | ||
} | ||
|
||
static void tamagotchi_p1_hal_play_frequency(bool_t en) { | ||
if(en) | ||
furi_hal_speaker_start(g_ctx->frequency, 0.5f); | ||
else | ||
furi_hal_speaker_stop(); | ||
|
||
g_ctx->buzzer_on = en; | ||
} | ||
|
||
static void tamagotchi_p1_hal_set_frequency(u32_t freq) { | ||
g_ctx->frequency = freq / 10.0F; | ||
if(g_ctx->buzzer_on) tamagotchi_p1_hal_play_frequency(true); | ||
} | ||
|
||
static int tamagotchi_p1_hal_handler(void) { | ||
// Do nothing | ||
return 0; | ||
} | ||
|
||
void tamagotchi_p1_hal_init(hal_t* hal) { | ||
hal->malloc = tamagotchi_p1_hal_malloc; | ||
hal->free = tamagotchi_p1_hal_free; | ||
hal->halt = tamagotchi_p1_hal_halt; | ||
hal->is_log_enabled = tamagotchi_p1_hal_is_log_enabled; | ||
hal->log = tamagotchi_p1_hal_log; | ||
hal->sleep_until = tamagotchi_p1_hal_sleep_until; | ||
hal->get_timestamp = tamagotchi_p1_hal_get_timestamp; | ||
hal->update_screen = tamagotchi_p1_hal_update_screen; | ||
hal->set_lcd_matrix = tamagotchi_p1_hal_set_lcd_matrix; | ||
hal->set_lcd_icon = tamagotchi_p1_hal_set_lcd_icon; | ||
hal->set_frequency = tamagotchi_p1_hal_set_frequency; | ||
hal->play_frequency = tamagotchi_p1_hal_play_frequency; | ||
hal->handler = tamagotchi_p1_hal_handler; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* TamaLIB - A hardware agnostic Tamagotchi P1 emulation library | ||
* | ||
* Copyright (C) 2021 Jean-Christophe Rona <[email protected]> | ||
* | ||
* 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 2 | ||
* 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, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
#ifndef _HAL_TYPES_H_ | ||
#define _HAL_TYPES_H_ | ||
|
||
#include <furi.h> | ||
|
||
typedef bool bool_t; | ||
typedef uint8_t u4_t; | ||
typedef uint8_t u5_t; | ||
typedef uint8_t u8_t; | ||
typedef uint16_t u12_t; | ||
typedef uint16_t u13_t; | ||
typedef uint32_t u32_t; | ||
typedef uint32_t | ||
timestamp_t; // WARNING: Must be an unsigned type to properly handle wrapping (u32 wraps in around 1h11m when expressed in us) | ||
|
||
#endif /* _HAL_TYPES_H_ */ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include <input/input.h> | ||
#include <tamalib.h> | ||
|
||
#define TAG "TamaP1" | ||
#define TAMA_ROM_PATH EXT_PATH("tama_p1/rom.bin") | ||
#define TAMA_SCREEN_SCALE_FACTOR 2 | ||
#define TAMA_LCD_ICON_SIZE 14 | ||
#define TAMA_LCD_ICON_MARGIN 1 | ||
|
||
typedef struct { | ||
FuriThread* thread; | ||
hal_t hal; | ||
uint8_t* rom; | ||
// 32x16 screen, perfectly represented through uint32_t | ||
uint32_t framebuffer[16]; | ||
uint8_t icons; | ||
bool halted; | ||
bool fast_forward_done; | ||
bool buzzer_on; | ||
float frequency; | ||
} TamaApp; | ||
|
||
typedef enum { | ||
EventTypeInput, | ||
EventTypeTick, | ||
} EventType; | ||
|
||
typedef struct { | ||
EventType type; | ||
InputEvent input; | ||
} TamaEvent; | ||
|
||
extern TamaApp* g_ctx; | ||
extern FuriMutex* g_state_mutex; | ||
|
||
void tamagotchi_p1_hal_init(hal_t* hal); |
Oops, something went wrong.