Skip to content

Commit

Permalink
Menu refactor (#4)
Browse files Browse the repository at this point in the history
* init

* kindly working on my happy code

* its darius day

* make icon look nicer

* various menu improvements

* use key held state not key pressed state

* add a freaking sweet drop shadow to highlighted option

* add menu behavior for left/right on bools, files

* bounds check the cursor only once

* add ability to compile roms into the program

* combine sd and romfs when browsing roms

* bump libpressf version

* remove old libdragon trunk code

* have multiple menus persist between state change

* kill the old keys code

* prevent $s in filenames being read as control code

* Update README.md

* fiddle with settings to make audio sound nicer

* add functionality for "return to bios" button
  • Loading branch information
celerizer authored Nov 26, 2024
1 parent af7897d commit 9b61b91
Show file tree
Hide file tree
Showing 14 changed files with 713 additions and 285 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

/build
*.z64
/filesystem
*.bin
*.chf
*.rom
87 changes: 58 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,66 @@ all: Press-F.z64
CFLAGS += \
-DPF_BIG_ENDIAN=1 \
-DPF_HAVE_HLE_BIOS=0 \
-DPF_SOUND_FREQUENCY=22050 \
-DPF_SOUND_FREQUENCY=44100 \
-DPF_ROMC=0 \
-O2 -funroll-loops
-O2 -funroll-loops \
-std=c89 -Wall -Wextra

BUILD_DIR = build
SRC_DIR = src
include $(N64_INST)/include/n64.mk
include src/libpressf/libpressf.mk

OBJS = $(BUILD_DIR)/src/main.o \
$(BUILD_DIR)/src/libpressf/src/debug.o \
$(BUILD_DIR)/src/libpressf/src/dma.o \
$(BUILD_DIR)/src/libpressf/src/emu.o \
$(BUILD_DIR)/src/libpressf/src/font.o \
$(BUILD_DIR)/src/libpressf/src/hle.o \
$(BUILD_DIR)/src/libpressf/src/input.o \
$(BUILD_DIR)/src/libpressf/src/romc.o \
$(BUILD_DIR)/src/libpressf/src/screen.o \
$(BUILD_DIR)/src/libpressf/src/software.o \
$(BUILD_DIR)/src/libpressf/src/wave.o \
$(BUILD_DIR)/src/libpressf/src/hw/2102.o \
$(BUILD_DIR)/src/libpressf/src/hw/2114.o \
$(BUILD_DIR)/src/libpressf/src/hw/3850.o \
$(BUILD_DIR)/src/libpressf/src/hw/3851.o \
$(BUILD_DIR)/src/libpressf/src/hw/beeper.o \
$(BUILD_DIR)/src/libpressf/src/hw/f8_device.o \
$(BUILD_DIR)/src/libpressf/src/hw/fairbug_parallel.o \
$(BUILD_DIR)/src/libpressf/src/hw/hand_controller.o \
$(BUILD_DIR)/src/libpressf/src/hw/schach_led.o \
$(BUILD_DIR)/src/libpressf/src/hw/selector_control.o \
$(BUILD_DIR)/src/libpressf/src/hw/system.o \
$(BUILD_DIR)/src/libpressf/src/hw/vram.o
assets_fnt = $(wildcard assets/*.fnt)
assets_ttf = $(wildcard assets/*.ttf)
assets_png = $(wildcard assets/*.png)

assets_bin = $(wildcard roms/*.bin)
assets_chf = $(wildcard roms/*.chf)
assets_rom = $(wildcard roms/*.rom)

assets_conv = \
$(addprefix filesystem/,$(notdir $(assets_ttf:%.ttf=%.font64))) \
$(addprefix filesystem/,$(notdir $(assets_fnt:%.fnt=%.font64))) \
$(addprefix filesystem/,$(notdir $(assets_png:%.png=%.sprite))) \
$(addprefix filesystem/roms/,$(notdir $(assets_bin:%.bin=%.bin))) \
$(addprefix filesystem/roms/,$(notdir $(assets_chf:%.chf=%.chf))) \
$(addprefix filesystem/roms/,$(notdir $(assets_rom:%.rom=%.rom)))

MKSPRITE_FLAGS ?=
MKFONT_FLAGS ?= --range all

src = \
$(SRC_DIR)/emu.c \
$(SRC_DIR)/main.c \
$(SRC_DIR)/menu.c

src += $(PRESS_F_SOURCES)

filesystem/%.font64: assets/%.ttf
@mkdir -p $(dir $@)
@echo " [FONT] $@"
$(N64_MKFONT) $(MKFONT_FLAGS) -o filesystem "$<"

filesystem/%.font64: assets/%.fnt
@mkdir -p $(dir $@)
@echo " [FONT] $@"
$(N64_MKFONT) $(MKFONT_FLAGS) -o filesystem "$<"

filesystem/%.sprite: assets/%.png
@mkdir -p $(dir $@)
@echo " [SPRITE] $@"
$(N64_MKSPRITE) $(MKSPRITE_FLAGS) -o filesystem "$<"

filesystem/roms/%: roms/%
@mkdir -p "$(dir $@)"
@echo " [ROM] $@"
@cp "$<" "$@"

filesystem/Tuffy_Bold.font64: MKFONT_FLAGS += --size 18 --outline 1

$(BUILD_DIR)/Press-F.dfs: $(assets_conv)
$(BUILD_DIR)/Press-F.elf: $(src:%.c=$(BUILD_DIR)/%.o)

# Get the current git version
GIT_VERSION := $(shell git describe --tags --dirty --always)
Expand All @@ -43,11 +72,11 @@ GIT_VERSION := $(shell git describe --tags --dirty --always)
N64_ROM_TITLE_WITH_VERSION := "Press F $(GIT_VERSION)"

Press-F.z64: N64_ROM_TITLE = $(N64_ROM_TITLE_WITH_VERSION)

$(BUILD_DIR)/Press-F.elf: $(OBJS)
Press-F.z64: $(BUILD_DIR)/Press-F.dfs

clean:
rm -rf $(BUILD_DIR) *.z64
.PHONY: clean
rm -rf $(BUILD_DIR) filesystem *.z64

-include $(wildcard $(BUILD_DIR)/*.d)

.PHONY: clean
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
### Nintendo 64 Flashcart

- Download the [latest release](https://github.com/celerizer/Press-F-Ultra/releases/).
- Place the Channel F BIOS images and any additional cartridge ROMs in a "press-f" subdirectory on the root of the SD Card. Make sure the two BIOS images have these exact filenames:
- Place the Channel F BIOS images and any additional cartridge ROMs in a "press-f" directory on the root of the SD Card. Make sure the two BIOS images have these exact filenames:
- `sl31253.bin`
- `sl31254.bin`
- Boot `Press-F.z64` and choose a game to play.

### Emulator

- Add the binary data of `sl31253.bin` and `sl31254.bin` to the source code of `main.c`, as `bios_a`, `bios_a_size`, `bios_b`, and `bios_b_size`.
- Build the ROM per the instructions below.
- Add the files `sl31253.bin` and `sl31254.bin` to the `roms` directory, as well as any additional cartridge ROM files.
- Build `Press-F.z64` per the instructions below.
- Load in the Ares emulator.

## Controls
Expand Down
11 changes: 11 additions & 0 deletions assets/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
We, the copyright holders of this work, hereby release it into the
public domain. This applies worldwide.

In case this is not legally possible,

We grant any entity the right to use this work for any purpose, without
any conditions, unless such conditions are required by law.

Thatcher Ulrich <[email protected]> http://tulrich.com
Karoly Barta [email protected]
Michael Evans http://www.evertype.com
Binary file added assets/Tuffy_Bold.ttf
Binary file not shown.
Binary file added assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions roms/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Place Channel F ROM files here to compile them into the emulator filesystem.

ROM files must have .chf, .rom, or .bin extensions.

The Channel F BIOS can be included here as well.
99 changes: 99 additions & 0 deletions src/emu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include <libdragon.h>

#include "libpressf/src/emu.h"
#include "libpressf/src/input.h"
#include "libpressf/src/screen.h"
#include "libpressf/src/hw/beeper.h"
#include "libpressf/src/hw/vram.h"

#include "main.h"
#include "emu.h"

static void pfu_video_render_1_1(void)
{
surface_t *disp = display_get();

rdpq_attach_clear(disp, NULL);
rdpq_set_mode_standard();
rdpq_tex_blit(&emu.video_frame, 14, 66, &(rdpq_blitparms_t){ .scale_x = 6.0f, .scale_y = 6.0f});
rdpq_detach_show();
}

static void pfu_video_render_4_3(void)
{
surface_t *disp = display_get();

rdpq_attach_clear(disp, NULL);
rdpq_set_mode_standard();
rdpq_tex_blit(&emu.video_frame, 0, 0, &(rdpq_blitparms_t){ .scale_x = 640.0f / SCREEN_WIDTH, .scale_y = 480.0f / SCREEN_HEIGHT});
rdpq_detach_show();
}

static void pfu_emu_input(void)
{
joypad_buttons_t buttons;

joypad_poll();
buttons = joypad_get_buttons(JOYPAD_PORT_1);

/* Handle hotkeys */
if (buttons.l)
{
pfu_menu_switch_roms();
return;
}
else if (buttons.r)
{
pfu_menu_switch_settings();
return;
}

/* Handle console input */
set_input_button(0, INPUT_TIME, buttons.a);
set_input_button(0, INPUT_MODE, buttons.b);
set_input_button(0, INPUT_HOLD, buttons.z);
set_input_button(0, INPUT_START, buttons.start);

/* Handle player 1 input */
set_input_button(4, INPUT_RIGHT, buttons.d_right);
set_input_button(4, INPUT_LEFT, buttons.d_left);
set_input_button(4, INPUT_BACK, buttons.d_down);
set_input_button(4, INPUT_FORWARD, buttons.d_up);
set_input_button(4, INPUT_ROTATE_CCW, buttons.c_left);
set_input_button(4, INPUT_ROTATE_CW, buttons.c_right);
set_input_button(4, INPUT_PULL, buttons.c_up);
set_input_button(4, INPUT_PUSH, buttons.c_down);

buttons = joypad_get_buttons(JOYPAD_PORT_2);

/* Handle player 2 input */
set_input_button(1, INPUT_RIGHT, buttons.d_right);
set_input_button(1, INPUT_LEFT, buttons.d_left);
set_input_button(1, INPUT_BACK, buttons.d_down);
set_input_button(1, INPUT_FORWARD, buttons.d_up);
set_input_button(1, INPUT_ROTATE_CCW, buttons.c_left);
set_input_button(1, INPUT_ROTATE_CW, buttons.c_right);
set_input_button(1, INPUT_PULL, buttons.c_up);
set_input_button(1, INPUT_PUSH, buttons.c_down);
}

void pfu_emu_run(void)
{
/* Input */
pfu_emu_input();

/* Emulation */
pressf_run(&emu.system);

/* Video */
draw_frame_rgb5551(((vram_t*)emu.system.f8devices[3].device)->data, emu.video_buffer);

/* Audio */
audio_push(((f8_beeper_t*)emu.system.f8devices[7].device)->samples, PF_SOUND_SAMPLES, true);

/* Blit the frame */
if (emu.video_scaling == PFU_SCALING_1_1)
pfu_video_render_1_1();
else
pfu_video_render_4_3();
}
6 changes: 6 additions & 0 deletions src/emu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef PRESS_F_ULTRA_EMU_H
#define PRESS_F_ULTRA_EMU_H

void pfu_emu_run(void);

#endif
2 changes: 1 addition & 1 deletion src/libpressf
Loading

0 comments on commit 9b61b91

Please sign in to comment.