Skip to content

Commit 9b61b91

Browse files
authored
Menu refactor (#4)
* 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
1 parent af7897d commit 9b61b91

File tree

14 files changed

+713
-285
lines changed

14 files changed

+713
-285
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11

22
/build
33
*.z64
4+
/filesystem
5+
*.bin
6+
*.chf
7+
*.rom

Makefile

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,66 @@ all: Press-F.z64
44
CFLAGS += \
55
-DPF_BIG_ENDIAN=1 \
66
-DPF_HAVE_HLE_BIOS=0 \
7-
-DPF_SOUND_FREQUENCY=22050 \
7+
-DPF_SOUND_FREQUENCY=44100 \
88
-DPF_ROMC=0 \
9-
-O2 -funroll-loops
9+
-O2 -funroll-loops \
10+
-std=c89 -Wall -Wextra
1011

1112
BUILD_DIR = build
1213
SRC_DIR = src
1314
include $(N64_INST)/include/n64.mk
15+
include src/libpressf/libpressf.mk
1416

15-
OBJS = $(BUILD_DIR)/src/main.o \
16-
$(BUILD_DIR)/src/libpressf/src/debug.o \
17-
$(BUILD_DIR)/src/libpressf/src/dma.o \
18-
$(BUILD_DIR)/src/libpressf/src/emu.o \
19-
$(BUILD_DIR)/src/libpressf/src/font.o \
20-
$(BUILD_DIR)/src/libpressf/src/hle.o \
21-
$(BUILD_DIR)/src/libpressf/src/input.o \
22-
$(BUILD_DIR)/src/libpressf/src/romc.o \
23-
$(BUILD_DIR)/src/libpressf/src/screen.o \
24-
$(BUILD_DIR)/src/libpressf/src/software.o \
25-
$(BUILD_DIR)/src/libpressf/src/wave.o \
26-
$(BUILD_DIR)/src/libpressf/src/hw/2102.o \
27-
$(BUILD_DIR)/src/libpressf/src/hw/2114.o \
28-
$(BUILD_DIR)/src/libpressf/src/hw/3850.o \
29-
$(BUILD_DIR)/src/libpressf/src/hw/3851.o \
30-
$(BUILD_DIR)/src/libpressf/src/hw/beeper.o \
31-
$(BUILD_DIR)/src/libpressf/src/hw/f8_device.o \
32-
$(BUILD_DIR)/src/libpressf/src/hw/fairbug_parallel.o \
33-
$(BUILD_DIR)/src/libpressf/src/hw/hand_controller.o \
34-
$(BUILD_DIR)/src/libpressf/src/hw/schach_led.o \
35-
$(BUILD_DIR)/src/libpressf/src/hw/selector_control.o \
36-
$(BUILD_DIR)/src/libpressf/src/hw/system.o \
37-
$(BUILD_DIR)/src/libpressf/src/hw/vram.o
17+
assets_fnt = $(wildcard assets/*.fnt)
18+
assets_ttf = $(wildcard assets/*.ttf)
19+
assets_png = $(wildcard assets/*.png)
20+
21+
assets_bin = $(wildcard roms/*.bin)
22+
assets_chf = $(wildcard roms/*.chf)
23+
assets_rom = $(wildcard roms/*.rom)
24+
25+
assets_conv = \
26+
$(addprefix filesystem/,$(notdir $(assets_ttf:%.ttf=%.font64))) \
27+
$(addprefix filesystem/,$(notdir $(assets_fnt:%.fnt=%.font64))) \
28+
$(addprefix filesystem/,$(notdir $(assets_png:%.png=%.sprite))) \
29+
$(addprefix filesystem/roms/,$(notdir $(assets_bin:%.bin=%.bin))) \
30+
$(addprefix filesystem/roms/,$(notdir $(assets_chf:%.chf=%.chf))) \
31+
$(addprefix filesystem/roms/,$(notdir $(assets_rom:%.rom=%.rom)))
32+
33+
MKSPRITE_FLAGS ?=
34+
MKFONT_FLAGS ?= --range all
35+
36+
src = \
37+
$(SRC_DIR)/emu.c \
38+
$(SRC_DIR)/main.c \
39+
$(SRC_DIR)/menu.c
40+
41+
src += $(PRESS_F_SOURCES)
42+
43+
filesystem/%.font64: assets/%.ttf
44+
@mkdir -p $(dir $@)
45+
@echo " [FONT] $@"
46+
$(N64_MKFONT) $(MKFONT_FLAGS) -o filesystem "$<"
47+
48+
filesystem/%.font64: assets/%.fnt
49+
@mkdir -p $(dir $@)
50+
@echo " [FONT] $@"
51+
$(N64_MKFONT) $(MKFONT_FLAGS) -o filesystem "$<"
52+
53+
filesystem/%.sprite: assets/%.png
54+
@mkdir -p $(dir $@)
55+
@echo " [SPRITE] $@"
56+
$(N64_MKSPRITE) $(MKSPRITE_FLAGS) -o filesystem "$<"
57+
58+
filesystem/roms/%: roms/%
59+
@mkdir -p "$(dir $@)"
60+
@echo " [ROM] $@"
61+
@cp "$<" "$@"
62+
63+
filesystem/Tuffy_Bold.font64: MKFONT_FLAGS += --size 18 --outline 1
64+
65+
$(BUILD_DIR)/Press-F.dfs: $(assets_conv)
66+
$(BUILD_DIR)/Press-F.elf: $(src:%.c=$(BUILD_DIR)/%.o)
3867

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

4574
Press-F.z64: N64_ROM_TITLE = $(N64_ROM_TITLE_WITH_VERSION)
46-
47-
$(BUILD_DIR)/Press-F.elf: $(OBJS)
75+
Press-F.z64: $(BUILD_DIR)/Press-F.dfs
4876

4977
clean:
50-
rm -rf $(BUILD_DIR) *.z64
51-
.PHONY: clean
78+
rm -rf $(BUILD_DIR) filesystem *.z64
5279

5380
-include $(wildcard $(BUILD_DIR)/*.d)
81+
82+
.PHONY: clean

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
### Nintendo 64 Flashcart
1010

1111
- Download the [latest release](https://github.com/celerizer/Press-F-Ultra/releases/).
12-
- 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:
12+
- 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:
1313
- `sl31253.bin`
1414
- `sl31254.bin`
1515
- Boot `Press-F.z64` and choose a game to play.
1616

1717
### Emulator
1818

19-
- 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`.
20-
- Build the ROM per the instructions below.
19+
- Add the files `sl31253.bin` and `sl31254.bin` to the `roms` directory, as well as any additional cartridge ROM files.
20+
- Build `Press-F.z64` per the instructions below.
2121
- Load in the Ares emulator.
2222

2323
## Controls

assets/LICENSE.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
We, the copyright holders of this work, hereby release it into the
2+
public domain. This applies worldwide.
3+
4+
In case this is not legally possible,
5+
6+
We grant any entity the right to use this work for any purpose, without
7+
any conditions, unless such conditions are required by law.
8+
9+
Thatcher Ulrich <tu@tulrich.com> http://tulrich.com
10+
Karoly Barta bartakarcsi@gmail.com
11+
Michael Evans http://www.evertype.com

assets/Tuffy_Bold.ttf

92.4 KB
Binary file not shown.

assets/icon.png

1.86 KB
Loading

roms/readme.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Place Channel F ROM files here to compile them into the emulator filesystem.
2+
3+
ROM files must have .chf, .rom, or .bin extensions.
4+
5+
The Channel F BIOS can be included here as well.

src/emu.c

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#include <libdragon.h>
2+
3+
#include "libpressf/src/emu.h"
4+
#include "libpressf/src/input.h"
5+
#include "libpressf/src/screen.h"
6+
#include "libpressf/src/hw/beeper.h"
7+
#include "libpressf/src/hw/vram.h"
8+
9+
#include "main.h"
10+
#include "emu.h"
11+
12+
static void pfu_video_render_1_1(void)
13+
{
14+
surface_t *disp = display_get();
15+
16+
rdpq_attach_clear(disp, NULL);
17+
rdpq_set_mode_standard();
18+
rdpq_tex_blit(&emu.video_frame, 14, 66, &(rdpq_blitparms_t){ .scale_x = 6.0f, .scale_y = 6.0f});
19+
rdpq_detach_show();
20+
}
21+
22+
static void pfu_video_render_4_3(void)
23+
{
24+
surface_t *disp = display_get();
25+
26+
rdpq_attach_clear(disp, NULL);
27+
rdpq_set_mode_standard();
28+
rdpq_tex_blit(&emu.video_frame, 0, 0, &(rdpq_blitparms_t){ .scale_x = 640.0f / SCREEN_WIDTH, .scale_y = 480.0f / SCREEN_HEIGHT});
29+
rdpq_detach_show();
30+
}
31+
32+
static void pfu_emu_input(void)
33+
{
34+
joypad_buttons_t buttons;
35+
36+
joypad_poll();
37+
buttons = joypad_get_buttons(JOYPAD_PORT_1);
38+
39+
/* Handle hotkeys */
40+
if (buttons.l)
41+
{
42+
pfu_menu_switch_roms();
43+
return;
44+
}
45+
else if (buttons.r)
46+
{
47+
pfu_menu_switch_settings();
48+
return;
49+
}
50+
51+
/* Handle console input */
52+
set_input_button(0, INPUT_TIME, buttons.a);
53+
set_input_button(0, INPUT_MODE, buttons.b);
54+
set_input_button(0, INPUT_HOLD, buttons.z);
55+
set_input_button(0, INPUT_START, buttons.start);
56+
57+
/* Handle player 1 input */
58+
set_input_button(4, INPUT_RIGHT, buttons.d_right);
59+
set_input_button(4, INPUT_LEFT, buttons.d_left);
60+
set_input_button(4, INPUT_BACK, buttons.d_down);
61+
set_input_button(4, INPUT_FORWARD, buttons.d_up);
62+
set_input_button(4, INPUT_ROTATE_CCW, buttons.c_left);
63+
set_input_button(4, INPUT_ROTATE_CW, buttons.c_right);
64+
set_input_button(4, INPUT_PULL, buttons.c_up);
65+
set_input_button(4, INPUT_PUSH, buttons.c_down);
66+
67+
buttons = joypad_get_buttons(JOYPAD_PORT_2);
68+
69+
/* Handle player 2 input */
70+
set_input_button(1, INPUT_RIGHT, buttons.d_right);
71+
set_input_button(1, INPUT_LEFT, buttons.d_left);
72+
set_input_button(1, INPUT_BACK, buttons.d_down);
73+
set_input_button(1, INPUT_FORWARD, buttons.d_up);
74+
set_input_button(1, INPUT_ROTATE_CCW, buttons.c_left);
75+
set_input_button(1, INPUT_ROTATE_CW, buttons.c_right);
76+
set_input_button(1, INPUT_PULL, buttons.c_up);
77+
set_input_button(1, INPUT_PUSH, buttons.c_down);
78+
}
79+
80+
void pfu_emu_run(void)
81+
{
82+
/* Input */
83+
pfu_emu_input();
84+
85+
/* Emulation */
86+
pressf_run(&emu.system);
87+
88+
/* Video */
89+
draw_frame_rgb5551(((vram_t*)emu.system.f8devices[3].device)->data, emu.video_buffer);
90+
91+
/* Audio */
92+
audio_push(((f8_beeper_t*)emu.system.f8devices[7].device)->samples, PF_SOUND_SAMPLES, true);
93+
94+
/* Blit the frame */
95+
if (emu.video_scaling == PFU_SCALING_1_1)
96+
pfu_video_render_1_1();
97+
else
98+
pfu_video_render_4_3();
99+
}

src/emu.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef PRESS_F_ULTRA_EMU_H
2+
#define PRESS_F_ULTRA_EMU_H
3+
4+
void pfu_emu_run(void);
5+
6+
#endif

src/libpressf

0 commit comments

Comments
 (0)