Skip to content

Commit

Permalink
Improve code quality - correct usage of volatile in src/
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Aug 10, 2023
1 parent fa6984a commit 24e6bbf
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// Custom implementation of fuji_screen_write
#if 0
void fuji_screen_write_(char *text, int x, int y, int fg, int bg) {
struct RstText *rst = (struct RstText *)MEM_TEXT_LAYERS;
struct RstText *rst = (volatile struct RstText *)MEM_TEXT_LAYERS;
struct RstTextEntry *entry = MEM_TEXT_LAYERS + sizeof(struct RstText);
entry[rst->length].y = y * 2 - 1;
entry[rst->length].x = x;
Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main_menu() {
ui_text("- Shutter button remap", 0xffff11);
ui_text("- Extend record limit", 0xffff11);

struct FujiInputMap *m = (struct FujiInputMap *)MEM_INPUT_MAP;
struct FujiInputMap *m = (volatile struct FujiInputMap *)MEM_INPUT_MAP;
char buffer[64];
sprintf(buffer, "[-] Keys: %X %X", m->key_code, m->key_status);
ui_text(buffer, 0xffff11);
Expand Down Expand Up @@ -79,7 +79,7 @@ int hijack_menu() {
return 1;
}

struct FujiInputMap *m = (struct FujiInputMap *)MEM_INPUT_MAP;
struct FujiInputMap *m = (volatile struct FujiInputMap *)MEM_INPUT_MAP;
if (m->key_code == KEY_DISPBACK) {
if (m->key_status == 0x80) {
// NOP out dev mmode hijack function to disable menu
Expand Down
8 changes: 4 additions & 4 deletions src/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

#include "ff_io.h"

void *heap_end = NULL;
uint8_t *heap_end = NULL;

void sys_init_mem() {
heap_end = (void *)MEM_UNUSED_SPACE + (1 * 1024 * 1024);
heap_end = (uint8_t *)MEM_UNUSED_SPACE + (1 * 1024 * 1024);
}

void *_sbrk(int incr) {
void *prev = heap_end;
uint8_t *_sbrk(int incr) {
uint8_t *prev = heap_end;
heap_end += incr;
return prev;
}
47 changes: 32 additions & 15 deletions src/remap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,48 @@
#include <string.h>
#include <stdint.h>

#include <fujihack.h>
#include <ff_io.h>
#include <ff_task.h>

static struct FujiTaskBuffer buf;

static int last_input = 0;
static int last_key_status = -1;
//static int last_input = 0;
//static int last_key_status = -1;

#define COUNTDOWN 7
static int seconds_held = 0;

static void remap_func() {
struct FujiInputMap *f = (struct FujiInputMap *)MEM_INPUT_MAP;
// Listen for OK
if (last_input == 0x816 && f->key_code == 1 && f->key_status == 0 && last_key_status == 0) {
fuji_press_key_alias("S2", "ON");
fuji_press_key_alias("S2", "OFF");
last_input = 0;
last_key_status = -1;
}
struct FujiInputMap *f = (volatile struct FujiInputMap *)MEM_INPUT_MAP;

// Listen to shutter button
if (f->key_status == 0 && f->key_code != 0x82e) {
last_input = f->key_code;
last_key_status = 0;
if (f->key_code == 0x82e && f->key_status == 0) {
if (!fh_state.active) fh_screendbg("%d", seconds_held);
seconds_held--;

if (seconds_held == 0) {
fuji_press_key_alias("S2", "ON");
fuji_press_key_alias("S2", "OFF");
seconds_held = COUNTDOWN;
}
}

// // Listen for OK
// if (last_input == 0x816 && f->key_code == 1 && f->key_status == 0 && last_key_status == 0) {
// fuji_press_key_alias("S2", "ON");
// fuji_press_key_alias("S2", "OFF");
// last_input = 0;
// last_key_status = -1;
// }
//
// // Listen to shutter button
// if (f->key_status == 0 && f->key_code != 0x82e) {
// last_input = f->key_code;
// last_key_status = 0;
// }
}

int fh_start_remap_shutter() {
fuji_wait_task_start(100, 1, &remap_func, &buf);
seconds_held = COUNTDOWN;
fuji_wait_task_start(500, 1, &remap_func, &buf);
}
8 changes: 4 additions & 4 deletions src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ void bmp_pixel(int x, int y, uint32_t rgb) {
// Fuji uses 3 buffers for double buffering. Need to paint to all 3 since I don't
// know how to do double buffering.
for (int i = 0; i < 3; i++) {
uintptr_t *ptr = (uintptr_t *)(MEM_OPENGL_BUFFERS);
volatile uintptr_t *ptr = (volatile uintptr_t *)(MEM_OPENGL_BUFFERS);
screen_buffer = ptr[i];

uint32_t *buf = (uint32_t *)((uintptr_t)screen_buffer);
volatile uint32_t *buf = (volatile uint32_t *)((uintptr_t)screen_buffer);
buf[SCREEN_WIDTH * y + x] = (rgb << 8) | 0xff;
}
}

void bmp_clear(uint32_t rgb) {
for (int i = 0; i < 3; i++) {
uintptr_t *ptr = (uintptr_t *)(MEM_OPENGL_BUFFERS);
volatile uintptr_t *ptr = (volatile uintptr_t *)(MEM_OPENGL_BUFFERS);
screen_buffer = ptr[i];

uint32_t *buf = (uint32_t *)((uintptr_t)screen_buffer);
volatile uint32_t *buf = (volatile uint32_t *)((uintptr_t)screen_buffer);
for (int i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++) {
buf[i] = rgb;
}
Expand Down
4 changes: 2 additions & 2 deletions src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int sys_check_key(int key) {
key = KEY_OK;
}

struct FujiInputMap *m = (struct FujiInputMap *)MEM_INPUT_MAP;
struct FujiInputMap *m = (volatile struct FujiInputMap *)MEM_INPUT_MAP;
if (m->key_code == key && m->key_status == 0x0) {
return 1;
} else {
Expand All @@ -48,7 +48,7 @@ void abort() {
}

long int sys_get_ticks() {
return ((long int *)MEM_MS_TIMER)[0];
return ((volatile long int *)MEM_MS_TIMER)[0];
}

int _gettimeofday() {
Expand Down
1 change: 1 addition & 0 deletions src/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <ff_io.h>

static int record_limit() {
// 666 minutes
return 60 * 60 * 666;
}

Expand Down

0 comments on commit 24e6bbf

Please sign in to comment.