diff --git a/assets/sounds/kettle.wav b/assets/sounds/kettle.wav new file mode 100644 index 0000000..9f7f3ae Binary files /dev/null and b/assets/sounds/kettle.wav differ diff --git a/include/input/keyboard.hpp b/include/input/keyboard.hpp new file mode 100644 index 0000000..9f1b129 --- /dev/null +++ b/include/input/keyboard.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "libpad.h" +#include "tamtypes.h" + +namespace Input::Keyboard +{ +void init(); +void read_inputs(); +u8 get_key_status(char key); +} // namespace Input::Keyboard \ No newline at end of file diff --git a/src/Makefile b/src/Makefile index d460331..1d056d0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,7 +8,7 @@ EE_OBJS := $(patsubst %.cpp, build/%.o, $(EE_OBJS)) EE_INCS := -I$(PS2SDK)/ports/include -Iinclude -Ivu1 $(EE_INCS) EE_LDFLAGS += -L$(PS2SDK)/ports/lib #EE_LIBS = -ldebug -lpatches -lxcdvd -EE_LIBS = -ldebug -lpatches -lxcdvd -lnetman -lps2gl -lps2stuff -legg -lps2ip -ldraw -lgraph -lmath3d -ldma -lpad -lc -lstdc++ -lgs -ldebug -leedebug -laudsrv -lcdvd -lxcdvd +EE_LIBS = -ldebug -lpatches -lxcdvd -lnetman -lps2gl -lps2stuff -legg -lps2ip -ldraw -lgraph -lmath3d -ldma -lpad -lc -lstdc++ -lgs -ldebug -leedebug -laudsrv -lcdvd -lxcdvd -lkbd EE_OPTFLAGS = -O3 -g -std=gnu++20 EE_CFLAGS += -DNO_VU0_VECTORS -DNO_ASM EE_CXXFLAGS += -DNO_VU0_VECTORS -DNO_ASM -frtti diff --git a/src/Makefile.iso b/src/Makefile.iso index 0c48c69..919afcb 100644 --- a/src/Makefile.iso +++ b/src/Makefile.iso @@ -16,6 +16,12 @@ $(ISO_FOLDER_DIR)/DEV9.IRX: $(ISO_FOLDER_DIR) $(ISO_FOLDER_DIR)/NETMAN.IRX: $(ISO_FOLDER_DIR) cp $(PS2SDK)/iop/irx/netman.irx $@ +$(ISO_FOLDER_DIR)/USBD.IRX: $(ISO_FOLDER_DIR) + cp $(PS2SDK)/iop/irx/usbd.irx $@ + +$(ISO_FOLDER_DIR)/PS2KBD.IRX: $(ISO_FOLDER_DIR) + cp $(PS2SDK)/iop/irx/ps2kbd.irx $@ + $(ISO_FOLDER_DIR)/SMAP.IRX: $(ISO_FOLDER_DIR) cp $(PS2SDK)/iop/irx/smap.irx $@ @@ -23,7 +29,7 @@ $(ISO_FOLDER_DIR)/ps2client.exe: $(ISO_FOLDER_DIR) cp assets/ps2client.exe $@ .PHONY: copy_libs -copy_libs: $(ISO_FOLDER_DIR)/AUDSRV.IRX $(ISO_FOLDER_DIR)/DEV9.IRX $(ISO_FOLDER_DIR)/NETMAN.IRX $(ISO_FOLDER_DIR)/SMAP.IRX $(ISO_FOLDER_DIR)/PS2SND.IRX $(ISO_FOLDER_DIR)/ps2client.exe +copy_libs: $(ISO_FOLDER_DIR)/AUDSRV.IRX $(ISO_FOLDER_DIR)/DEV9.IRX $(ISO_FOLDER_DIR)/NETMAN.IRX $(ISO_FOLDER_DIR)/SMAP.IRX $(ISO_FOLDER_DIR)/PS2SND.IRX $(ISO_FOLDER_DIR)/USBD.IRX $(ISO_FOLDER_DIR)/PS2KBD.IRX $(ISO_FOLDER_DIR)/ps2client.exe # Sound files AUDIO_FILE_TYPE = wav diff --git a/src/engine.cc b/src/engine.cc index 87fc98b..0278eb5 100644 --- a/src/engine.cc +++ b/src/engine.cc @@ -140,10 +140,22 @@ void init(int argc, char* argv[]) load_asset_manifest(); + { + int ret = SifLoadModule("USBD.IRX"_p.to_full_filepath(), 0, nullptr); + printf("ret: %d\n", ret); + checkf(ret >= 0, "USBD.IRX"_p.to_full_filepath()); + } + + // { + // int ret = SifLoadModule("BDMMFS_F.IRX"_p.to_full_filepath(), 0, nullptr); + // printf("ret: %d\n", ret); + // checkf(ret >= 0, "BDMMFS_F.IRX"_p.to_full_filepath()); + // } + Stats::init(); Input::init(); //Filesystem::run_tests(); - //Sound::init(); + Sound::init(); GS::init(); printf("Graph mode (region): "); @@ -209,7 +221,7 @@ void run() if (Input::Gamepad::get_paddata() & PAD_START) { - Sound::set_music_volume(50); + Sound::set_music_volume(100); Stats::print_timer_stats(); } } diff --git a/src/input/input.cc b/src/input/input.cc index 2129e7b..9a10f31 100644 --- a/src/input/input.cc +++ b/src/input/input.cc @@ -1,15 +1,18 @@ #include "input/input.hpp" #include "input/gamepad.hpp" +#include "input/keyboard.hpp" namespace Input { void init() { Gamepad::init(); + Keyboard::init(); } void read_inputs() { Gamepad::read_inputs(); + Keyboard::read_inputs(); } } // namespace Input \ No newline at end of file diff --git a/src/input/keyboard.cpp b/src/input/keyboard.cpp new file mode 100644 index 0000000..62e9067 --- /dev/null +++ b/src/input/keyboard.cpp @@ -0,0 +1,49 @@ +#include "input/keyboard.hpp" + +#include +#include "egg/assert.hpp" +#include "egg/filesystem.hpp" + +#include "libkbd.h" +#include "ps2kbd.h" + +static u8 keyboard_status[256]; + +namespace Input +{ +void Keyboard::init() +{ + + memset(keyboard_status, sizeof(keyboard_status), 0); + + { + int ret = SifLoadModule("PS2KBD.IRX"_p.to_full_filepath(), 0, nullptr); + printf("ret: %d\n", ret); + checkf(ret >= 0, "PS2KBD.IRX"_p.to_full_filepath()); + } + + // Note: this depends on the USB modules being load (BSD.IRX) + if (PS2KbdInit() == 0) + { + checkf(false, "Failed to initialize"); + } + + PS2KbdSetReadmode(PS2KBD_READMODE_RAW); +} + +void Keyboard::read_inputs() +{ + PS2KbdRawKey key; + while (PS2KbdReadRaw(&key) != 0) + { + printf("New key: %u, %u\n", key.key, key.state); + keyboard_status[key.key] = key.state & 0xF; + } +} + +u8 Keyboard::get_key_status(char key) +{ + return keyboard_status[(key - 'a') + 4]; +} + +} // namespace Input \ No newline at end of file diff --git a/src/objects/movement.cc b/src/objects/movement.cc index ce1aa71..ef4417e 100644 --- a/src/objects/movement.cc +++ b/src/objects/movement.cc @@ -1,5 +1,6 @@ #include "objects/movement.hpp" #include "input/gamepad.hpp" +#include "input/keyboard.hpp" #include "egg/math_types.hpp" #include "objects/components/transform_component.hpp" #include "objects/components/collision_component.hpp" @@ -184,6 +185,12 @@ void ThirdPersonMovement::calculate_movement_input(float delta_time) input_vector += ((buttons.ljoy_h - 128.f) / 128.f) * right_movement_vector; input_vector += ((buttons.ljoy_v - 128.f) / 128.f) * forward_movement_vector; + input_vector += Input::Keyboard::get_key_status('a') * right_movement_vector * -1; + input_vector += Input::Keyboard::get_key_status('d') * right_movement_vector; + + input_vector += Input::Keyboard::get_key_status('s') * forward_movement_vector; + input_vector += Input::Keyboard::get_key_status('w') * forward_movement_vector * -1; + if (paddata & PAD_CROSS) { movement_vector.y += 1.f; diff --git a/src/sound/sound.cc b/src/sound/sound.cc index 8ec626a..0949769 100644 --- a/src/sound/sound.cc +++ b/src/sound/sound.cc @@ -104,7 +104,7 @@ void init() } } - song_file = std::ifstream("/assets/sounds/white_waking.wav"_p.to_full_filepath()); + song_file = std::ifstream("/assets/sounds/kettle.wav"_p.to_full_filepath()); check(song_file.is_open()); song_file.seekg(0x30, std::ios_base::beg); chunkReadStatus = -1; @@ -160,8 +160,13 @@ bool work_song() } } - if (chunkReadStatus < (s32)chunkSize) - song_playing = false; + if (chunkReadStatus == 0) + { + printf("looping song!\n"); + song_file.seekg(0x30, std::ios_base::beg); + chunkReadStatus = -1; + song_playing = true; + } return did_work; }