diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-07-07 13:22:53 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-07-25 14:16:41 +0200 |
| commit | 14f60e4fd65c42f126eaee7e09cb4251c167c6ed (patch) | |
| tree | 313b5e16d7d99cf1518c953e2efe5e5fc920dfbf /src/drv/ps1 | |
| parent | 48a61c16eaa6dcfc75d00dba302537ce1492db98 (diff) | |
wiptty
Diffstat (limited to 'src/drv/ps1')
73 files changed, 2840 insertions, 0 deletions
diff --git a/src/drv/ps1/CMakeLists.txt b/src/drv/ps1/CMakeLists.txt new file mode 100644 index 0000000..9e408de --- /dev/null +++ b/src/drv/ps1/CMakeLists.txt @@ -0,0 +1,33 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +add_subdirectory(bios) +add_subdirectory(cd) +add_subdirectory(dma) +add_subdirectory(gpu) +add_subdirectory(interrupt) +add_subdirectory(mc) +add_subdirectory(pad) +add_subdirectory(rcnt) +add_subdirectory(time) +add_library(drv_ps1) +add_subdirectory(src) +target_include_directories(drv_ps1 PUBLIC include PRIVATE private_include) +target_link_libraries(drv_ps1 PUBLIC c drv_event PRIVATE + drv_ps1_cd + drv_ps1_mc + drv_ps1_pad +) diff --git a/src/drv/ps1/bios/CMakeLists.txt b/src/drv/ps1/bios/CMakeLists.txt new file mode 100644 index 0000000..255a27d --- /dev/null +++ b/src/drv/ps1/bios/CMakeLists.txt @@ -0,0 +1,19 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +add_library(drv_ps1_bios) +add_subdirectory(src) +target_include_directories(drv_ps1_bios INTERFACE include) diff --git a/src/drv/ps1/bios/include/drv/ps1/bios.h b/src/drv/ps1/bios/include/drv/ps1/bios.h new file mode 100644 index 0000000..2686f12 --- /dev/null +++ b/src/drv/ps1/bios/include/drv/ps1/bios.h @@ -0,0 +1,112 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef PS1_BIOS_H +#define PS1_BIOS_H + +#include <stdint.h> + +enum +{ + CLASS_IRQ0 = (long)0xf0000001, + CLASS_GPU, + CLASS_CDROM, + CLASS_DMA, + CLASS_RTC0 = (long)0xf2000000, + CLASS_RTC1, + CLASS_RTC2, + CLASS_VBLANK, + CLASS_CONTROLLER = (long)0xf0000008, + CLASS_SPU, + CLASS_PIO, + CLASS_SIO +}; + +enum +{ + MODE_EXECUTE = 0x1000, + MODE_READY = 0x2000 +}; + +enum +{ + SPEC_COUNTER_ZERO = 1, + SPEC_INTERRUPTED = 1 << 1, + SPEC_EOF = 1 << 2, + SPEC_FILE_CLOSED = 1 << 3, + SPEC_COMMAND_ACK = 1 << 4, + SPEC_COMMAND_COMPLETE = 1 << 5, + SPEC_DATA_READY = 1 << 6, + SPEC_DATA_END = 1 << 7, + SPEC_TIMEOUT = 1 << 8, + SPEC_UNKNOWN_CMD = 1 << 9, + SPEC_END_READ_BUF = 1 << 10, + SPEC_END_WRITE_BUF = 1 << 11, + SPEC_GENERAL_INTERRUPT = 1 << 12, + SPEC_NEW_DEVICE = 1 << 13, + SPEC_SYSCALL = 1 << 14, + SPEC_ERROR = 1 << 15, + SPEC_WRITE_ERROR, + SPEC_DOMAIN_ERROR = 0x301, + SPEC_RANGE_RNG +}; + +struct CdAsyncSeekL +{ + uint8_t minutes, seconds, frames; +}; + +union SetMode +{ + struct + { + uint8_t cdda :1, autopause :1, report :1, xa_filter :1, ignore :1, + whole_sector :1, xa_adpcm :1, speed :1; + } bits; + + uint8_t mask; +}; + +struct CdAsyncReadSector_mode +{ + union SetMode mode; + union + { + struct + { + uint8_t reads :1, :7; + } bits; + } read; + + uint16_t reserved; +}; + +void EnterCriticalSection(void); +void ExitCriticalSection(void); +int OpenEvent(int class, int spec, int mode, int (*f)(void)); +int EnableEvent(int event); +int DisableEvent(int event); +int CloseEvent(int event); +int TestEvent(int event); +int WaitEvent(int event); +int CdAsyncGetStatus(uint8_t *response); +int CdAsyncReadSector(unsigned count, void *dst, + struct CdAsyncReadSector_mode mode); +int CdAsyncSeekL(const struct CdAsyncSeekL *seekl); + +#endif diff --git a/src/drv/ps1/bios/src/CMakeLists.txt b/src/drv/ps1/bios/src/CMakeLists.txt new file mode 100644 index 0000000..b1ea9cd --- /dev/null +++ b/src/drv/ps1/bios/src/CMakeLists.txt @@ -0,0 +1,29 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +target_sources(drv_ps1_bios PRIVATE + CdAsyncGetStatus.s + CdAsyncReadSector.s + CdAsyncSeekL.s + CloseEvent.s + DisableEvent.s + EnableEvent.s + EnterCriticalSection.s + ExitCriticalSection.s + OpenEvent.s + TestEvent.s + WaitEvent.s +) diff --git a/src/drv/ps1/bios/src/CdAsyncGetStatus.s b/src/drv/ps1/bios/src/CdAsyncGetStatus.s new file mode 100644 index 0000000..77464ea --- /dev/null +++ b/src/drv/ps1/bios/src/CdAsyncGetStatus.s @@ -0,0 +1,21 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +.global CdAsyncGetStatus + +CdAsyncGetStatus: + li $9, 0x7c + j 0xa0 + nop diff --git a/src/drv/ps1/bios/src/CdAsyncReadSector.s b/src/drv/ps1/bios/src/CdAsyncReadSector.s new file mode 100644 index 0000000..c68b54a --- /dev/null +++ b/src/drv/ps1/bios/src/CdAsyncReadSector.s @@ -0,0 +1,21 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +.global CdAsyncReadSector + +CdAsyncReadSector: + li $9, 0x7e + j 0xa0 + nop diff --git a/src/drv/ps1/bios/src/CdAsyncSeekL.s b/src/drv/ps1/bios/src/CdAsyncSeekL.s new file mode 100644 index 0000000..cc20a32 --- /dev/null +++ b/src/drv/ps1/bios/src/CdAsyncSeekL.s @@ -0,0 +1,21 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +.global CdAsyncSeekL + +CdAsyncSeekL: + li $9, 0x78 + j 0xa0 + nop diff --git a/src/drv/ps1/bios/src/CloseEvent.s b/src/drv/ps1/bios/src/CloseEvent.s new file mode 100644 index 0000000..0ade6fa --- /dev/null +++ b/src/drv/ps1/bios/src/CloseEvent.s @@ -0,0 +1,21 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +.global CloseEvent + +CloseEvent: + li $9, 0x9 + j 0xb0 + nop diff --git a/src/drv/ps1/bios/src/DisableEvent.s b/src/drv/ps1/bios/src/DisableEvent.s new file mode 100644 index 0000000..b2d96ca --- /dev/null +++ b/src/drv/ps1/bios/src/DisableEvent.s @@ -0,0 +1,21 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +.global DisableEvent + +DisableEvent: + li $9, 0xd + j 0xb0 + nop diff --git a/src/drv/ps1/bios/src/EnableEvent.s b/src/drv/ps1/bios/src/EnableEvent.s new file mode 100644 index 0000000..bbff315 --- /dev/null +++ b/src/drv/ps1/bios/src/EnableEvent.s @@ -0,0 +1,23 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +.text + +.global EnableEvent + +EnableEvent: + li $9, 0xc + j 0xb0 + nop diff --git a/src/drv/ps1/bios/src/EnterCriticalSection.s b/src/drv/ps1/bios/src/EnterCriticalSection.s new file mode 100644 index 0000000..ebf2de9 --- /dev/null +++ b/src/drv/ps1/bios/src/EnterCriticalSection.s @@ -0,0 +1,25 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +.text + +.global EnterCriticalSection + +EnterCriticalSection: + li $a0, 1 + syscall + nop + jr $ra + nop diff --git a/src/drv/ps1/bios/src/ExitCriticalSection.s b/src/drv/ps1/bios/src/ExitCriticalSection.s new file mode 100644 index 0000000..53f307a --- /dev/null +++ b/src/drv/ps1/bios/src/ExitCriticalSection.s @@ -0,0 +1,23 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +.global ExitCriticalSection + +ExitCriticalSection: + li $a0, 2 + syscall + nop + jr $ra + nop diff --git a/src/drv/ps1/bios/src/OpenEvent.s b/src/drv/ps1/bios/src/OpenEvent.s new file mode 100644 index 0000000..89cc7d4 --- /dev/null +++ b/src/drv/ps1/bios/src/OpenEvent.s @@ -0,0 +1,21 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +.global OpenEvent + +OpenEvent: + li $9, 0x8 + j 0xb0 + nop diff --git a/src/drv/ps1/bios/src/TestEvent.s b/src/drv/ps1/bios/src/TestEvent.s new file mode 100644 index 0000000..4afe273 --- /dev/null +++ b/src/drv/ps1/bios/src/TestEvent.s @@ -0,0 +1,23 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +.text + +.global TestEvent + +TestEvent: + li $9, 0xb + j 0xb0 + nop diff --git a/src/drv/ps1/bios/src/WaitEvent.s b/src/drv/ps1/bios/src/WaitEvent.s new file mode 100644 index 0000000..1f2ca97 --- /dev/null +++ b/src/drv/ps1/bios/src/WaitEvent.s @@ -0,0 +1,23 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +.text + +.global WaitEvent + +WaitEvent: + li $9, 0xa + j 0xb0 + nop diff --git a/src/drv/ps1/cd/CMakeLists.txt b/src/drv/ps1/cd/CMakeLists.txt new file mode 100644 index 0000000..7459bc6 --- /dev/null +++ b/src/drv/ps1/cd/CMakeLists.txt @@ -0,0 +1,20 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +add_library(drv_ps1_cd) +add_subdirectory(src) +target_include_directories(drv_ps1_cd PUBLIC include PRIVATE private_include) +target_link_libraries(drv_ps1_cd PUBLIC c drv_event PRIVATE drv_ps1_bios) diff --git a/src/drv/ps1/cd/include/drv/ps1/cd.h b/src/drv/ps1/cd/include/drv/ps1/cd.h new file mode 100644 index 0000000..6bb48f1 --- /dev/null +++ b/src/drv/ps1/cd/include/drv/ps1/cd.h @@ -0,0 +1,28 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_CD_H +#define DRV_PS1_CD_H + +#include <drv/event.h> + +struct drv_ps1_cd *drv_ps1_cd_init(const struct drv_event *ev); +int drv_ps1_cd_update(struct drv_ps1_cd *cd); +void drv_ps1_cd_free(struct drv_ps1_cd *cd); + +#endif diff --git a/src/drv/ps1/cd/private_include/drv/ps1/cd/regs.h b/src/drv/ps1/cd/private_include/drv/ps1/cd/regs.h new file mode 100644 index 0000000..7d15f39 --- /dev/null +++ b/src/drv/ps1/cd/private_include/drv/ps1/cd/regs.h @@ -0,0 +1,66 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_CD_REGS_H +#define DRV_PS1_CD_REGS_H + +#include <stdint.h> + +struct cd_reg_status +{ + uint8_t index :2; + const uint8_t ADPBUSY :1, PRMEMPT :1, PRMWRDY :1, RSLRRDY :1, DRQSTS :1, + BUSYSTS :1; +}; + +struct cd_reg_cmd +{ + uint8_t cmd; +}; + +struct cd_reg_rsp +{ + uint8_t rsp; +}; + +struct cd_reg_param +{ + uint8_t param; +}; + +union cd_reg_if +{ + const struct + { + uint8_t response :3, :1, cmd_start :1, :3; + } r; + + struct + { + uint8_t ack: 5, :1, CLRPRM :1, :1; + } w; +}; + +#define CD_REG(x) (0x1f801800 + (x)) +#define CD_REG_STATUS ((volatile struct cd_reg_status *)CD_REG(0)) +#define CD_REG_CMD ((volatile struct cd_reg_cmd *)CD_REG(1)) +#define CD_REG_RSP ((const volatile struct cd_reg_rsp *)CD_REG(1)) +#define CD_REG_PARAM ((volatile struct cd_reg_param *)CD_REG(2)) +#define CD_REG_IF ((volatile union cd_reg_if *)CD_REG(3)) + +#endif diff --git a/src/drv/ps1/cd/private_include/drv/ps1/cd/routines.h b/src/drv/ps1/cd/private_include/drv/ps1/cd/routines.h new file mode 100644 index 0000000..0fce7dd --- /dev/null +++ b/src/drv/ps1/cd/private_include/drv/ps1/cd/routines.h @@ -0,0 +1,37 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_CD_ROUTINES_H +#define DRV_PS1_CD_ROUTINES_H + +#include <drv/ps1/cd/types.h> +#include <drv/ps1/bios.h> +#include <stddef.h> + +int drv_ps1_cd_send(const struct cmd *cmd); +int drv_ps1_cd_getstat(void); +int drv_ps1_cd_read(void *buf, size_t n, const struct drv_event_done *done, + void *args); +int drv_ps1_cd_seek(long offset, const struct drv_event_done *done, + void *args); +int drv_ps1_cd_write(const void *buf, size_t n, + const struct drv_event_done *done, void *args); +int drv_ps1_cd_next(void); +struct CdAsyncSeekL drv_ps1_cd_toseekl(unsigned i); + +#endif diff --git a/src/drv/ps1/cd/private_include/drv/ps1/cd/types.h b/src/drv/ps1/cd/private_include/drv/ps1/cd/types.h new file mode 100644 index 0000000..4446305 --- /dev/null +++ b/src/drv/ps1/cd/private_include/drv/ps1/cd/types.h @@ -0,0 +1,122 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_CD_TYPES_H +#define DRV_PS1_CD_TYPES_H + +#include <drv/event.h> +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +struct drv_ps1_cd +{ + bool available; + struct drv_event ev; +}; + +struct cmd +{ + enum + { + CMD_SYNC, + CMD_GETSTAT, + CMD_SETLOC, + } cmd; + + union cmd_param + { + struct cmd_setloc + { + uint8_t min, sec, sect; + } setloc; + } params; +}; + +struct cd_prv_getstat +{ + int event; + + union + { + struct + { + uint8_t invalid :1, motor :1, seek_error :1, id_error :1, + shell_open :1, reading :1, seeking :1, playing_cdda :1; + } bits; + + uint8_t byte; + } status; +}; + +struct cd_prv_read +{ + int event, endevent, errevent; +}; + +struct cd_prv_seek +{ + int event, errevent; +}; + +struct cd_req_read +{ + void *buf; + size_t n; +}; + +struct cd_req_seek +{ + long offset; +}; + +struct cd_req +{ + union + { + struct cd_req_read read; + struct cd_req_seek seek; + } u; + + int (*f)(void); + struct drv_event_done done; + struct cd_req *next; +}; + +enum {CD_SECTOR_SZ = 2048}; + +struct cd_prv +{ + bool available, has_cache; + int (*next)(void); + struct cmd cmd; + struct cd_req *head, *tail; + char sector[CD_SECTOR_SZ]; + unsigned offset; + + union + { + struct cd_prv_getstat getstat; + struct cd_prv_read read; + struct cd_prv_seek seek; + } u; +}; + +extern struct cd_prv drv_ps1_cd_prv; + +#endif diff --git a/src/drv/ps1/cd/src/CMakeLists.txt b/src/drv/ps1/cd/src/CMakeLists.txt new file mode 100644 index 0000000..074671d --- /dev/null +++ b/src/drv/ps1/cd/src/CMakeLists.txt @@ -0,0 +1,29 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +target_sources(drv_ps1_cd PRIVATE + free.c + getstat.c + init.c + next.c + prv.c + # send.c + read.c + seek.c + toseekl.c + update.c + write.c +) diff --git a/src/drv/ps1/cd/src/ensure_event.c b/src/drv/ps1/cd/src/ensure_event.c new file mode 100644 index 0000000..5e2f3a0 --- /dev/null +++ b/src/drv/ps1/cd/src/ensure_event.c @@ -0,0 +1,40 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/bios.h> +#include <drv/ps1/cd/types.h> +#include <stddef.h> + +int drv_ps1_cd_ensure_event(struct cd_prv *const p) +{ + if (p->event) + return 0; + + EnterCriticalSection(); + + const int event = OpenEvent(CLASS_CDROM, SPEC_COMMAND_COMPLETE, MODE_READY, + NULL); + + ExitCriticalSection(); + + if (event == -1) + return -1; + + EnableEvent(p->event = event); + return 0; +} diff --git a/src/drv/ps1/cd/src/free.c b/src/drv/ps1/cd/src/free.c new file mode 100644 index 0000000..44704d7 --- /dev/null +++ b/src/drv/ps1/cd/src/free.c @@ -0,0 +1,23 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/cd.h> + +void drv_ps1_cd_free(struct drv_ps1_cd *const cd) +{ +} diff --git a/src/drv/ps1/cd/src/getstat.c b/src/drv/ps1/cd/src/getstat.c new file mode 100644 index 0000000..6268f37 --- /dev/null +++ b/src/drv/ps1/cd/src/getstat.c @@ -0,0 +1,65 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/cd/routines.h> +#include <drv/ps1/bios.h> + +static int wait_event(void) +{ + struct cd_prv *const p = &drv_ps1_cd_prv; + struct cd_prv_getstat *const g = &p->u.getstat; + + if (TestEvent(g->event)) + { + p->available = !g->status.bits.shell_open; + DisableEvent(g->event); + CloseEvent(g->event); + + if (!p->head) + return drv_ps1_cd_getstat(); + + return p->head->f(); + } + + return 0; +} + +int drv_ps1_cd_getstat(void) +{ + struct cd_prv *const p = &drv_ps1_cd_prv; + struct cd_prv_getstat *const g = &p->u.getstat; + + EnterCriticalSection(); + + const int event = OpenEvent(CLASS_CDROM, SPEC_COMMAND_COMPLETE, + MODE_READY, NULL); + + ExitCriticalSection(); + + if (event == -1) + return -1; + + *g = (const struct cd_prv_getstat){.event = event}; + EnableEvent(event); + + if (!CdAsyncGetStatus(&g->status.byte)) + return -1; + + p->next = wait_event; + return 0; +} diff --git a/src/drv/ps1/cd/src/init.c b/src/drv/ps1/cd/src/init.c new file mode 100644 index 0000000..896e330 --- /dev/null +++ b/src/drv/ps1/cd/src/init.c @@ -0,0 +1,42 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/cd.h> +#include <drv/ps1/cd/routines.h> +#include <drv/ps1/cd/types.h> +#include <drv/event.h> +#include <stddef.h> +#include <stdlib.h> + +struct drv_ps1_cd *drv_ps1_cd_init(const struct drv_event *const ev) +{ + struct drv_ps1_cd *const ret = malloc(sizeof *ret); + struct cd_prv *const p = &drv_ps1_cd_prv; + + if (!ret) + return NULL; + else if (!p->next && drv_ps1_cd_getstat()) + goto failure; + + *ret = (const struct drv_ps1_cd){.ev = *ev}; + return ret; + +failure: + free(ret); + return NULL; +} diff --git a/src/drv/ps1/cd/src/next.c b/src/drv/ps1/cd/src/next.c new file mode 100644 index 0000000..0923be9 --- /dev/null +++ b/src/drv/ps1/cd/src/next.c @@ -0,0 +1,38 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/cd.h> +#include <drv/ps1/cd/routines.h> +#include <drv/ps1/cd/types.h> +#include <stdlib.h> + +int drv_ps1_cd_next(void) +{ + int ret = 0; + struct cd_prv *const p = &drv_ps1_cd_prv; + struct cd_req *const next = p->head->next; + + free(p->head); + + if (next && (ret = next->f())) + return -1; + else if (!(p->head = next)) + return drv_ps1_cd_getstat(); + + return ret; +} diff --git a/src/drv/ps1/cd/src/prv.c b/src/drv/ps1/cd/src/prv.c new file mode 100644 index 0000000..dd70709 --- /dev/null +++ b/src/drv/ps1/cd/src/prv.c @@ -0,0 +1,22 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/cd.h> +#include <drv/ps1/cd/types.h> + +struct cd_prv drv_ps1_cd_prv; diff --git a/src/drv/ps1/cd/src/read.c b/src/drv/ps1/cd/src/read.c new file mode 100644 index 0000000..251481e --- /dev/null +++ b/src/drv/ps1/cd/src/read.c @@ -0,0 +1,155 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/cd.h> +#include <drv/ps1/cd/routines.h> +#include <drv/ps1/cd/types.h> +#include <drv/event.h> +#include <errno.h> +#include <stdlib.h> +#include <string.h> + +static int deliver_event(struct cd_prv *const p, const int error) +{ + const struct cd_prv_read *const read = &p->u.read; + const struct cd_req *const req = p->head; + const struct drv_event_done *const d = &req->done; + + if (!error) + { + const struct cd_req_read *const rr = &req->u.read; + const long offset = p->offset % CD_SECTOR_SZ; + + memcpy(rr->buf, p->sector + offset, rr->n); + p->has_cache = true; + p->offset += rr->n; + } + + if (d->f(error, d->args) || drv_ps1_cd_next()) + return -1; + + return 0; +} + +static int wait_event(void) +{ + int ret = 0; + struct cd_prv *const p = &drv_ps1_cd_prv; + const struct cd_prv_read *const read = &p->u.read; + + if (TestEvent(read->event)) + return deliver_event(p, SUCCESS); + else if (TestEvent(read->errevent) || TestEvent(read->endevent)) + return deliver_event(p, EIO); + + return 0; +} + +static int start_read(void) +{ + struct cd_prv *const p = &drv_ps1_cd_prv; + struct cd_prv_read *const r = &p->u.read; + const struct cd_req_read *req = &p->head->u.read; + const struct CdAsyncReadSector_mode mode = + { + .mode.bits.speed = 1, + }; + + EnterCriticalSection(); + + const int + event = OpenEvent(CLASS_CDROM, SPEC_COMMAND_COMPLETE, MODE_READY, NULL), + endevent = OpenEvent(CLASS_CDROM, SPEC_DATA_END, MODE_READY, NULL), + errevent = OpenEvent(CLASS_CDROM, SPEC_ERROR, MODE_READY, NULL); + + ExitCriticalSection(); + + if (event == -1 || endevent == -1 || errevent == -1) + goto failure; + + *r = (const struct cd_prv_read) + { + .event = event, + .endevent = endevent, + .errevent = errevent + }; + + EnableEvent(event); + EnableEvent(endevent); + EnableEvent(errevent); + + if (!CdAsyncReadSector(1, p->sector, mode)) + goto failure; + + p->next = wait_event; + return 0; + +failure: + if (event != -1) + CloseEvent(event); + + if (endevent != -1) + CloseEvent(endevent); + + if (errevent != -1) + CloseEvent(errevent); + + return -1; +} + +static int read_cache(void) +{ + struct cd_prv *const p = &drv_ps1_cd_prv; + const struct cd_req *const req = p->head; + const struct cd_req_read *const rr = &req->u.read; + const long offset = p->offset % CD_SECTOR_SZ; + + memcpy(rr->buf, p->sector + offset, rr->n); + p->offset += rr->n; + return deliver_event(p, SUCCESS); +} + +int drv_ps1_cd_read(void *const buf, const size_t n, + const struct drv_event_done *const done, void *const args) +{ + struct cd_prv *const p = &drv_ps1_cd_prv; + struct cd_req *const r = malloc(sizeof *r); + + if (!r) + return -1; + + *r = (const struct cd_req) + { + .done = *done, + /* TODO: multi-sector reads, make sure cache can really be used */ + .f = p->has_cache ? read_cache : start_read, + .u.read = + { + .buf = buf, + .n = n + } + }; + + if (!p->head) + p->head = r; + else + p->tail->next = r; + + p->tail = r; + return 0; +} diff --git a/src/drv/ps1/cd/src/seek.c b/src/drv/ps1/cd/src/seek.c new file mode 100644 index 0000000..e26a684 --- /dev/null +++ b/src/drv/ps1/cd/src/seek.c @@ -0,0 +1,118 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/cd.h> +#include <drv/ps1/cd/routines.h> +#include <drv/ps1/cd/types.h> +#include <drv/ps1/bios.h> +#include <drv/event.h> +#include <errno.h> +#include <stdlib.h> + +static int wait_event(void) +{ + int ret = 0; + struct cd_prv *const p = &drv_ps1_cd_prv; + const struct cd_prv_seek *const s = &p->u.seek; + const struct cd_req *const r = p->head; + const struct drv_event_done *const d = &r->done; + + if (TestEvent(s->event)) + { + p->offset = r->u.seek.offset; + + if (d->f(0, d->args) || drv_ps1_cd_next()) + return -1; + } + else if (TestEvent(s->errevent)) + { + if (d->f(EIO, d->args) || drv_ps1_cd_next()) + return -1; + } + + return 0; +} + +static int seek(void) +{ + struct cd_prv *const p = &drv_ps1_cd_prv; + struct cd_prv_seek *const s = &p->u.seek; + const struct cd_req_seek *req = &p->head->u.seek; + const unsigned sector = req->offset / CD_SECTOR_SZ; + const struct CdAsyncSeekL seekl = drv_ps1_cd_toseekl(sector); + + EnterCriticalSection(); + + const int + event = OpenEvent(CLASS_CDROM, SPEC_COMMAND_COMPLETE, MODE_READY, NULL), + errevent = OpenEvent(CLASS_CDROM, SPEC_ERROR, MODE_READY, NULL); + + ExitCriticalSection(); + + if (event == -1 || errevent == -1) + goto failure; + + *s = (const struct cd_prv_seek) + { + .event = event, + .errevent = errevent + }; + + EnableEvent(event); + EnableEvent(errevent); + + if (!CdAsyncSeekL(&seekl)) + goto failure; + + p->next = wait_event; + return 0; + +failure: + if (event != -1) + CloseEvent(event); + + if (errevent != -1) + CloseEvent(errevent); + + return -1; +} + +int drv_ps1_cd_seek(const long offset, const struct drv_event_done *const done, + void *const args) +{ + struct cd_prv *const p = &drv_ps1_cd_prv; + struct cd_req *const r = malloc(sizeof *r); + + if (!r) + return -1; + + *r = (const struct cd_req) + { + .done = *done, + .u.seek = offset, + .f = seek + }; + + if (!p->head) + p->head = r; + else + p->tail->next = r; + + p->tail = r; + return 0; +} diff --git a/src/drv/ps1/cd/src/send.c b/src/drv/ps1/cd/src/send.c new file mode 100644 index 0000000..76b9730 --- /dev/null +++ b/src/drv/ps1/cd/src/send.c @@ -0,0 +1,100 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/cd.h> +#include <drv/ps1/bios.h> +#include <drv/ps1/cd/regs.h> +#include <drv/ps1/cd/routines.h> +#include <drv/ps1/cd/types.h> +#include <stdint.h> + +static int wait_event(void) +{ + struct cd_prv *const p = &drv_ps1_cd_prv; + + if (TestEvent(p->event)) + { + const union cd_prv_getstat g = {.status = CD_REG_RSP->rsp}; + + p->available = !g.bits.shell_open; + } + + return 0; +} + +static void send_params(const struct cd_prv *const p) +{ + static const size_t n[] = + { + [CMD_SETLOC] = sizeof (struct cmd_setloc) + }; + + const uint8_t cmd = p->cmd.cmd, index = CD_REG_STATUS->index; + + if (cmd < sizeof n / sizeof *n) + { + const void *const vbuf = &p->cmd.params; + const uint8_t *buf = vbuf; + + CD_REG_STATUS->index = 0; + + for (size_t i = 0; i < n[cmd]; i++) + CD_REG_PARAM->param = *buf++; + + CD_REG_STATUS->index = index; + } +} + +static int send_data(void) +{ + struct cd_prv *const p = &drv_ps1_cd_prv; + + if (CD_REG_STATUS->BUSYSTS) + return 0; + + send_params(p); + CD_REG_CMD->cmd = p->cmd.cmd; + p->next = wait_event; + return 0; +} + +static int reset_param_fifo(void) +{ + struct cd_prv *const p = &drv_ps1_cd_prv; + + if (CD_REG_STATUS->BUSYSTS) + return 0; + + CD_REG_IF->w.ack = 0x1f; + CD_REG_STATUS->index = 1; + CD_REG_IF->w.CLRPRM = 1; + p->next = send_data; + return 0; +} + +int drv_ps1_cd_send(const struct cmd *const cmd) +{ + struct cd_prv *const p = &drv_ps1_cd_prv; + + if (drv_ps1_cd_ensure_event(p)) + return -1; + + p->cmd = *cmd; + p->next = reset_param_fifo; + return 0; +} diff --git a/src/drv/ps1/cd/src/toseekl.c b/src/drv/ps1/cd/src/toseekl.c new file mode 100644 index 0000000..df35ff1 --- /dev/null +++ b/src/drv/ps1/cd/src/toseekl.c @@ -0,0 +1,54 @@ +/* Original functions from psn00bsdk, commit 5d9aa2d3 + * + * itob extracted from libpsn00b/include/psxcd.h + * CdIntToPos (here renamed to drv_ps1_cd_toseekl) extracted from + * libpsn00b/psxcd/misc.c + * + * Original copyright notice: + * + * PSn00bSDK CD-ROM library + * (C) 2020-2023 Lameguy64, spicyjpeg - MPL licensed + */ + +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/cd/routines.h> +#include <drv/ps1/bios.h> + +/** + * @brief Translates a decimal value to BCD. + * + * @details Translates a decimal integer in 0-99 range into a BCD format value. + */ +static int itob(const int i) +{ + return (i / 10 * 16) | (i % 10); +} + +struct CdAsyncSeekL drv_ps1_cd_toseekl(unsigned i) +{ + i += 150; + + return (const struct CdAsyncSeekL) + { + .minutes = itob(i / (75 * 60)), + .seconds = itob((i / 75) % 60), + .frames = itob(i % 75) + }; +} diff --git a/src/drv/ps1/cd/src/update.c b/src/drv/ps1/cd/src/update.c new file mode 100644 index 0000000..2c3d2ff --- /dev/null +++ b/src/drv/ps1/cd/src/update.c @@ -0,0 +1,46 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/cd.h> +#include <drv/ps1/cd/types.h> +#include <drv/ps1/cd/routines.h> +#include <drv/event.h> +#include <stdbool.h> + +int drv_ps1_cd_update(struct drv_ps1_cd *const cd) +{ + struct cd_prv *const p = &drv_ps1_cd_prv; + + if (p->next()) + return -1; + else if (p->available ^ cd->available) + { + const struct drv_event *const ev = &cd->ev; + static const struct drv_event_ops ops = + { + .read = drv_ps1_cd_read, + .write = drv_ps1_cd_write, + .seek = drv_ps1_cd_seek + }; + + ev->status("cd0", &ops, p->available, ev->args); + cd->available = p->available; + } + + return 0; +} diff --git a/src/drv/ps1/cd/src/write.c b/src/drv/ps1/cd/src/write.c new file mode 100644 index 0000000..008a13d --- /dev/null +++ b/src/drv/ps1/cd/src/write.c @@ -0,0 +1,31 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/cd.h> +#include <drv/ps1/cd/routines.h> +#include <drv/ps1/cd/types.h> +#include <drv/event.h> +#include <errno.h> + +int drv_ps1_cd_write(const void *const buf, const size_t n, + const struct drv_event_done *const done, void *const args) +{ + /* TODO: write event callback returning EROFS */ + errno = EROFS; + return -1; +} diff --git a/src/drv/ps1/dma/CMakeLists.txt b/src/drv/ps1/dma/CMakeLists.txt new file mode 100644 index 0000000..689beed --- /dev/null +++ b/src/drv/ps1/dma/CMakeLists.txt @@ -0,0 +1,18 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +add_library(drv_ps1_dma INTERFACE) +target_include_directories(drv_ps1_dma INTERFACE include) diff --git a/src/drv/ps1/dma/include/drv/ps1/dma.h b/src/drv/ps1/dma/include/drv/ps1/dma.h new file mode 100644 index 0000000..8ae1826 --- /dev/null +++ b/src/drv/ps1/dma/include/drv/ps1/dma.h @@ -0,0 +1,97 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_DMA_H +#define DRV_PS1_DMA_H + +#include <stdint.h> + +union dpcr +{ + struct + { + uint32_t mdecin_prio :3, mdecin_en :1, mdecout_prio :3, mdecout_en :1, + gpu_prio :3, gpu_en :1, cdrom_prio :3, cdrom_en :1, spu_prio :3, + spu_en :1, pio_prio :3, pio_en :1, otc_prio :3, otc_en :1, :4; + } bits; + + uint32_t mask; +}; + +union madr +{ + struct + { + uint32_t addr :24, :8; + } bits; + + uint32_t mask; +}; + +union bcr +{ + struct + { + uint16_t nwords, reserved; + } syncmode_0; + + struct + { + uint16_t blocksz, nblocks; + } syncmode_1; + + struct + { + uint32_t reserved; + } syncmode_2; + + uint32_t mask; +}; + +enum +{ + CHCR_DIR_TO_RAM, + CHCR_DIR_FROM_RAM +}; + +enum +{ + CHCR_SYNC_MODE_ALL, + CHCR_SYNC_MODE_BLOCKS, + CHCR_SYNC_MODE_LINKED_LIST +}; + +union chcr +{ + struct + { + uint32_t dir :1, memstep :1, :6, chopping :1, sync_mode :2, :5, + chopping_dma_window_sz :3, :1, chopping_cpu_window_sz :3, :1, + start_busy :1, :3, start_trigger :1, :3; + } bits; + + uint32_t mask; +}; + +#define DMA_BASE(dma, off) ((dma) * 0x10 + 0x1f801080 + (off)) +#define D2_MADR ((volatile union madr *)DMA_BASE(2, 0)) +#define D2_BCR ((volatile union bcr *)DMA_BASE(2, 4)) +#define D2_CHCR ((volatile union chcr *)DMA_BASE(2, 8)) +#define DPCR ((volatile union dpcr *)0x1f8010f0) + +#endif diff --git a/src/drv/ps1/gpu/CMakeLists.txt b/src/drv/ps1/gpu/CMakeLists.txt new file mode 100644 index 0000000..9dead67 --- /dev/null +++ b/src/drv/ps1/gpu/CMakeLists.txt @@ -0,0 +1,18 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +add_library(drv_ps1_gpu INTERFACE) +target_include_directories(drv_ps1_gpu INTERFACE include) diff --git a/src/drv/ps1/gpu/include/drv/ps1/gpu.h b/src/drv/ps1/gpu/include/drv/ps1/gpu.h new file mode 100644 index 0000000..0f64a7f --- /dev/null +++ b/src/drv/ps1/gpu/include/drv/ps1/gpu.h @@ -0,0 +1,167 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_GPU_H +#define DRV_PS1_GPU_H + +#include <stdint.h> + +enum +{ + GP0_TEXTRECT_VARSZ_OPAQ_RAW = 0x65, + GP0_COPY_RECT_CPU_VRAM = 0xa0, + GP0_COPY_RECT_VRAM_CPU = 0xc0, + GP0_DRAW_MODE = 0xe1, + GP0_TEX_WINDOW, + GP0_DRAW_AREA_TOP_LEFT, + GP0_DRAW_AREA_BOTTOM_RIGHT, + GP0_DRAW_OFFSET, + GP0_DRAW_MASK_BIT +}; + +enum +{ + GP1_RESET_GPU, + GP1_RESET_CMDBUF, + GP1_ACK_IRQ, + GP1_DISPLAY_ENABLE, + GP1_DMA_DIR, + GP1_START_DISPLAY_AREA, + GP1_H_DISPLAY_RANGE, + GP1_V_DISPLAY_RANGE, + GP1_DISPLAY_MODE +}; + +enum +{ + GP1_DMA_DIR_OFF, + GP1_DMA_DIR_FIFO, + GP1_DMA_DIR_CPU_TO_GP0, + GP1_DMA_DIR_GPUREAD_TO_CPU +}; + +union drv_ps1_gpu_gp0 +{ + uint32_t mask; + + struct + { + uint32_t :24, cmd :8; + } copy_rect; + + struct + { + uint16_t x, y; + } coord; + + struct + { + uint16_t w, h; + } size; + + struct + { + uint32_t page_x :4, page_y :1, stp :2, bpp :2, dither :1, + draw_to_display :1, tex_disable :1, xflip :1, yflip :1, :10, + cmd :8; + } draw_mode; + + struct + { + uint32_t mask_x :5, mask_y :5, off_x :5, off_y :5, :4, cmd :8; + } tex_window; + + struct + { + uint32_t x :10, y :9, :5, cmd :8; + } draw_area_tl, draw_area_br; + + struct + { + int32_t x :11, y :11, :2, cmd :8; + } offset; + + struct + { + uint32_t set :1, check :1, :22, cmd :8; + } mask_bit; +}; + +union drv_ps1_gpu_gp1 +{ + uint32_t mask; + + struct + { + uint32_t :24, cmd:8; + } reset_gpu, reset_cmdbuf, ack_irq; + + struct + { + uint32_t disable :1, :23, cmd :8; + } display; + + struct + { + uint32_t dir :2, :22, cmd :8; + } dma; + + struct + { + uint32_t x :10, y :9, :5, cmd :8; + } disparea; + + struct + { + uint32_t x1 :12, x2 :12, cmd :8; + } h_display_range; + + struct + { + uint32_t y1 :10, y2 :10, :4, cmd :8; + } v_display_range; + + struct + { + uint32_t hres :2, vres :1, vmode :1, coldepth :1, vinterlace :1, + hres2 :1, reverse :1, :16, cmd :8; + } display_mode; +}; + +union drv_ps1_gpu_stat +{ + struct + { + uint32_t x_base :4, y_base :1, stp :2, bpp :2, dither :1, + draw_to_display :1, set_mask :1, draw_pix :1, interlace :1, + reverse :1, disable :1, xres2 :1, xres1 :2, yres :1, vmode :1, + coldepth :1, vinterlace :1, display_enable :1, irq_req :1, + dma_req :1, ready_cmd :1, ready_send :1, ready_recv :1, + ready_dma :1, dma_dir :2, draw_odd :1; + } bits; + + uint32_t mask; +}; + +#define GPU_BASE 0x1f801810 +#define GPU_REG(x) (GPU_BASE + (x)) +#define GP0 ((volatile union drv_ps1_gpu_gp0 *)GPU_REG(0)) +#define GP1 ((volatile union drv_ps1_gpu_gp1 *)GPU_REG(4)) +#define GPUSTAT ((volatile const union drv_ps1_gpu_stat *)GPU_REG(4)) + +#endif diff --git a/src/drv/ps1/include/drv/ps1.h b/src/drv/ps1/include/drv/ps1.h new file mode 100644 index 0000000..951259a --- /dev/null +++ b/src/drv/ps1/include/drv/ps1.h @@ -0,0 +1,28 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_H +#define DRV_PS1_H + +#include <drv/event.h> + +struct drv_port *drv_ps1_init(const struct drv_event *ev); +int drv_ps1_update(struct drv_port *p); +void drv_ps1_free(struct drv_port *p); + +#endif diff --git a/src/drv/ps1/interrupt/CMakeLists.txt b/src/drv/ps1/interrupt/CMakeLists.txt new file mode 100644 index 0000000..29becb8 --- /dev/null +++ b/src/drv/ps1/interrupt/CMakeLists.txt @@ -0,0 +1,19 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +add_library(drv_ps1_interrupt INTERFACE) +target_include_directories(drv_ps1_interrupt INTERFACE include) +target_link_libraries(drv_ps1_interrupt INTERFACE c) diff --git a/src/drv/ps1/interrupt/include/drv/ps1/interrupt.h b/src/drv/ps1/interrupt/include/drv/ps1/interrupt.h new file mode 100644 index 0000000..9e0bfb4 --- /dev/null +++ b/src/drv/ps1/interrupt/include/drv/ps1/interrupt.h @@ -0,0 +1,39 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_INTERRUPT_H +#define DRV_PS1_INTERRUPT_H + +#include <stdint.h> + +union drv_ps1_interrupt +{ + struct + { + uint32_t vblank :1, gpu :1, cdrom :1, dma :1, tmr0 :1, tmr1 :1, tmr2 :1, + controller :1, sio :1, spu :1, lightpen :1, :21; + } bits; + + uint32_t mask; +}; + +#define I_BASE(x) (0x1f801070 + (x)) +#define I_STAT ((volatile union drv_ps1_interrupt *)I_BASE(0)) +#define I_MASK ((volatile union drv_ps1_interrupt *)I_BASE(4)) + +#endif diff --git a/src/drv/ps1/mc/CMakeLists.txt b/src/drv/ps1/mc/CMakeLists.txt new file mode 100644 index 0000000..13ae399 --- /dev/null +++ b/src/drv/ps1/mc/CMakeLists.txt @@ -0,0 +1,20 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +add_library(drv_ps1_mc) +add_subdirectory(src) +target_include_directories(drv_ps1_mc PUBLIC include PRIVATE private_include) +target_link_libraries(drv_ps1_mc PUBLIC c drv_event) diff --git a/src/drv/ps1/mc/include/drv/ps1/mc.h b/src/drv/ps1/mc/include/drv/ps1/mc.h new file mode 100644 index 0000000..637bd37 --- /dev/null +++ b/src/drv/ps1/mc/include/drv/ps1/mc.h @@ -0,0 +1,28 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_MC_H +#define DRV_PS1_MC_H + +#include <drv/event.h> + +struct drv_ps1_mc *drv_ps1_mc_init(const struct drv_event *ev); +int drv_ps1_mc_update(struct drv_ps1_mc *mc); +void drv_ps1_mc_free(struct drv_ps1_mc *mc); + +#endif diff --git a/src/drv/ps1/mc/private_include/drv/ps1/mc/types.h b/src/drv/ps1/mc/private_include/drv/ps1/mc/types.h new file mode 100644 index 0000000..920e55a --- /dev/null +++ b/src/drv/ps1/mc/private_include/drv/ps1/mc/types.h @@ -0,0 +1,37 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_MC_TYPES_H +#define DRV_PS1_MC_TYPES_H + +#include <drv/event.h> + +struct drv_ps1_mc +{ + const struct drv_event *ev; +}; + +enum +{ + MC_0, + MC_1, + + N_MC +}; + +#endif diff --git a/src/drv/ps1/mc/src/CMakeLists.txt b/src/drv/ps1/mc/src/CMakeLists.txt new file mode 100644 index 0000000..6eb62be --- /dev/null +++ b/src/drv/ps1/mc/src/CMakeLists.txt @@ -0,0 +1,21 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +target_sources(drv_ps1_mc PRIVATE + free.c + init.c + update.c +) diff --git a/src/drv/ps1/mc/src/free.c b/src/drv/ps1/mc/src/free.c new file mode 100644 index 0000000..924e1bf --- /dev/null +++ b/src/drv/ps1/mc/src/free.c @@ -0,0 +1,23 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/mc.h> + +void drv_ps1_mc_free(struct drv_ps1_mc *const mc) +{ +} diff --git a/src/drv/ps1/mc/src/init.c b/src/drv/ps1/mc/src/init.c new file mode 100644 index 0000000..4bb034a --- /dev/null +++ b/src/drv/ps1/mc/src/init.c @@ -0,0 +1,34 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/mc.h> +#include <drv/ps1/mc/types.h> +#include <drv/event.h> +#include <stddef.h> +#include <stdlib.h> + +struct drv_ps1_mc *drv_ps1_mc_init(const struct drv_event *const ev) +{ + struct drv_ps1_mc *const ret = malloc(sizeof *ret); + + if (!ret) + return NULL; + + *ret = (const struct drv_ps1_mc){.ev = ev}; + return ret; +} diff --git a/src/drv/ps1/mc/src/update.c b/src/drv/ps1/mc/src/update.c new file mode 100644 index 0000000..f4b29d9 --- /dev/null +++ b/src/drv/ps1/mc/src/update.c @@ -0,0 +1,26 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/mc.h> +#include <drv/event.h> + +int drv_ps1_mc_update(struct drv_ps1_mc *const mc) +{ + /* TODO */ + return 0; +} diff --git a/src/drv/ps1/pad/CMakeLists.txt b/src/drv/ps1/pad/CMakeLists.txt new file mode 100644 index 0000000..cd25672 --- /dev/null +++ b/src/drv/ps1/pad/CMakeLists.txt @@ -0,0 +1,20 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +add_library(drv_ps1_pad) +add_subdirectory(src) +target_include_directories(drv_ps1_pad PUBLIC include PRIVATE private_include) +target_link_libraries(drv_ps1_pad PUBLIC c drv_event) diff --git a/src/drv/ps1/pad/include/drv/ps1/pad.h b/src/drv/ps1/pad/include/drv/ps1/pad.h new file mode 100644 index 0000000..d8070de --- /dev/null +++ b/src/drv/ps1/pad/include/drv/ps1/pad.h @@ -0,0 +1,28 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_PAD_H +#define DRV_PS1_PAD_H + +#include <drv/event.h> + +struct drv_ps1_pad *drv_ps1_pad_init(const struct drv_event *ev); +int drv_ps1_pad_update(struct drv_ps1_pad *pad); +void drv_ps1_pad_free(struct drv_ps1_pad *pad); + +#endif diff --git a/src/drv/ps1/pad/private_include/drv/ps1/pad/types.h b/src/drv/ps1/pad/private_include/drv/ps1/pad/types.h new file mode 100644 index 0000000..b79e344 --- /dev/null +++ b/src/drv/ps1/pad/private_include/drv/ps1/pad/types.h @@ -0,0 +1,29 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_PAD_TYPES_H +#define DRV_PS1_PAD_TYPES_H + +#include <drv/event.h> + +struct drv_ps1_pad +{ + const struct drv_event *ev; +}; + +#endif diff --git a/src/drv/ps1/pad/src/CMakeLists.txt b/src/drv/ps1/pad/src/CMakeLists.txt new file mode 100644 index 0000000..9da3661 --- /dev/null +++ b/src/drv/ps1/pad/src/CMakeLists.txt @@ -0,0 +1,21 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +target_sources(drv_ps1_pad PRIVATE + free.c + init.c + update.c +) diff --git a/src/drv/ps1/pad/src/free.c b/src/drv/ps1/pad/src/free.c new file mode 100644 index 0000000..925e23a --- /dev/null +++ b/src/drv/ps1/pad/src/free.c @@ -0,0 +1,23 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/pad.h> + +void drv_ps1_pad_free(struct drv_ps1_pad *const pad) +{ +} diff --git a/src/drv/ps1/pad/src/init.c b/src/drv/ps1/pad/src/init.c new file mode 100644 index 0000000..3d2bd51 --- /dev/null +++ b/src/drv/ps1/pad/src/init.c @@ -0,0 +1,34 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/pad.h> +#include <drv/ps1/pad/types.h> +#include <drv/event.h> +#include <stddef.h> +#include <stdlib.h> + +struct drv_ps1_pad *drv_ps1_pad_init(const struct drv_event *const ev) +{ + struct drv_ps1_pad *const ret = malloc(sizeof *ret); + + if (!ret) + return NULL; + + *ret = (const struct drv_ps1_pad){.ev = ev}; + return ret; +} diff --git a/src/drv/ps1/pad/src/update.c b/src/drv/ps1/pad/src/update.c new file mode 100644 index 0000000..35fb7a7 --- /dev/null +++ b/src/drv/ps1/pad/src/update.c @@ -0,0 +1,26 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/pad.h> +#include <drv/event.h> + +int drv_ps1_pad_update(struct drv_ps1_pad *const pad) +{ + /* TODO */ + return 0; +} diff --git a/src/drv/ps1/private_include/drv/ps1/types.h b/src/drv/ps1/private_include/drv/ps1/types.h new file mode 100644 index 0000000..ffb3559 --- /dev/null +++ b/src/drv/ps1/private_include/drv/ps1/types.h @@ -0,0 +1,33 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_TYPES_H +#define DRV_PS1_TYPES_H + +#include <drv/ps1/cd.h> +#include <drv/ps1/mc.h> +#include <drv/ps1/pad.h> + +struct drv_port +{ + struct drv_ps1_mc *mc; + struct drv_ps1_cd *cd; + struct drv_ps1_pad *pad; +}; + +#endif diff --git a/src/drv/ps1/rcnt/CMakeLists.txt b/src/drv/ps1/rcnt/CMakeLists.txt new file mode 100644 index 0000000..65af1a4 --- /dev/null +++ b/src/drv/ps1/rcnt/CMakeLists.txt @@ -0,0 +1,22 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +add_library(drv_ps1_rcnt) +add_subdirectory(src) +target_include_directories(drv_ps1_rcnt PUBLIC include PRIVATE private_include) +target_link_libraries(drv_ps1_rcnt + PUBLIC c + PRIVATE drv_ps1_bios drv_ps1_interrupt) diff --git a/src/drv/ps1/rcnt/include/drv/ps1/rcnt.h b/src/drv/ps1/rcnt/include/drv/ps1/rcnt.h new file mode 100644 index 0000000..a4e8e1b --- /dev/null +++ b/src/drv/ps1/rcnt/include/drv/ps1/rcnt.h @@ -0,0 +1,45 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_RCNT_H +#define DRV_PS1_RCNT_H + +#include <stdint.h> + +union drv_ps1_rcnt_cfg +{ + struct + { + uint32_t sync_enable :1, sync_mode :2, reset :1, irq_tgt :1, + irq_max :1, repeat :1, pulse_toggle :1, clocksrc :2, intreq :1; + } bits; + + uint32_t word; +}; + +enum drv_ps1_rcnt +{ + DRV_PS1_RCNT0, + DRV_PS1_RCNT1, + DRV_PS1_RCNT2 +}; + +int drv_ps1_rcnt_init(enum drv_ps1_rcnt rcnt, uint16_t target, + const union drv_ps1_rcnt_cfg *cfg, int (*f)(void)); + +#endif diff --git a/src/drv/ps1/rcnt/private_include/drv/ps1/rcnt/regs.h b/src/drv/ps1/rcnt/private_include/drv/ps1/rcnt/regs.h new file mode 100644 index 0000000..443a487 --- /dev/null +++ b/src/drv/ps1/rcnt/private_include/drv/ps1/rcnt/regs.h @@ -0,0 +1,36 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_RCNT_REGS_H +#define DRV_PS1_RCNT_REGS_H + +#include <drv/ps1/rcnt.h> +#include <stdint.h> + +struct rcnt_value +{ + uint32_t value :16, :16; +}; + +#define RCNT_BASE(n) (0x1f801100 + (n << 4)) +#define RCNT_REG(n, m) (RCNT_BASE(n) + m) +#define RCNT_VALUE(n) ((volatile struct rcnt_value *)RCNT_REG(n, 0)) +#define RCNT_MODE(n) ((volatile union drv_ps1_rcnt_cfg *)RCNT_REG(n, 4)) +#define RCNT_TARGET(n) ((volatile struct rcnt_value *)RCNT_REG(n, 8)) + +#endif diff --git a/src/drv/ps1/rcnt/src/CMakeLists.txt b/src/drv/ps1/rcnt/src/CMakeLists.txt new file mode 100644 index 0000000..0254ed8 --- /dev/null +++ b/src/drv/ps1/rcnt/src/CMakeLists.txt @@ -0,0 +1,19 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +target_sources(drv_ps1_rcnt PRIVATE + init.c +) diff --git a/src/drv/ps1/rcnt/src/init.c b/src/drv/ps1/rcnt/src/init.c new file mode 100644 index 0000000..770cd15 --- /dev/null +++ b/src/drv/ps1/rcnt/src/init.c @@ -0,0 +1,59 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/rcnt.h> +#include <drv/ps1/rcnt/regs.h> +#include <drv/ps1/interrupt.h> +#include <drv/ps1/bios.h> +#include <stddef.h> +#include <stdint.h> + +int drv_ps1_rcnt_init(const enum drv_ps1_rcnt rcnt, const uint16_t target, + const union drv_ps1_rcnt_cfg *const cfg, int (*const f)(void)) +{ + int event, class; + + EnterCriticalSection(); + RCNT_TARGET(rcnt)->value = target; + *RCNT_MODE(rcnt) = *cfg; + + switch (rcnt) + { + case DRV_PS1_RCNT0: + I_MASK->bits.tmr0 = 1; + class = CLASS_RTC0; + break; + case DRV_PS1_RCNT1: + I_MASK->bits.tmr1 = 1; + class = CLASS_RTC1; + break; + case DRV_PS1_RCNT2: + I_MASK->bits.tmr2 = 1; + class = CLASS_RTC2; + break; + } + + event = OpenEvent(class, SPEC_INTERRUPTED, MODE_EXECUTE, f); + ExitCriticalSection(); + + if (event == -1) + return -1; + + EnableEvent(event); + return 0; +} diff --git a/src/drv/ps1/src/CMakeLists.txt b/src/drv/ps1/src/CMakeLists.txt new file mode 100644 index 0000000..4694191 --- /dev/null +++ b/src/drv/ps1/src/CMakeLists.txt @@ -0,0 +1,21 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +target_sources(drv_ps1 PRIVATE + free.c + init.c + update.c +) diff --git a/src/drv/ps1/src/free.c b/src/drv/ps1/src/free.c new file mode 100644 index 0000000..a1348d6 --- /dev/null +++ b/src/drv/ps1/src/free.c @@ -0,0 +1,24 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1.h> +#include <drv/ps1/types.h> + +void drv_ps1_free(struct drv_port *const p) +{ +} diff --git a/src/drv/ps1/src/init.c b/src/drv/ps1/src/init.c new file mode 100644 index 0000000..37a08be --- /dev/null +++ b/src/drv/ps1/src/init.c @@ -0,0 +1,53 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1.h> +#include <drv/ps1/types.h> +#include <drv/ps1/cd.h> +#include <drv/ps1/mc.h> +#include <drv/ps1/pad.h> +#include <stdlib.h> + +struct drv_port *drv_ps1_init(const struct drv_event *const ev) +{ + struct drv_port *ret = NULL; + struct drv_ps1_mc *mc = NULL; + struct drv_ps1_cd *cd = NULL; + struct drv_ps1_pad *pad = NULL; + + if (!(mc = drv_ps1_mc_init(ev)) + || !(cd = drv_ps1_cd_init(ev)) + || !(pad = drv_ps1_pad_init(ev)) + || !(ret = malloc(sizeof *ret))) + goto failure; + + *ret = (const struct drv_port) + { + .mc = mc, + .cd = cd, + .pad = pad + }; + + return ret; + +failure: + drv_ps1_mc_free(mc); + drv_ps1_cd_free(cd); + drv_ps1_pad_free(pad); + free(mc); +} diff --git a/src/drv/ps1/src/update.c b/src/drv/ps1/src/update.c new file mode 100644 index 0000000..c96d9de --- /dev/null +++ b/src/drv/ps1/src/update.c @@ -0,0 +1,33 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1.h> +#include <drv/ps1/types.h> +#include <drv/ps1/cd.h> +#include <drv/ps1/mc.h> +#include <drv/ps1/pad.h> + +int drv_ps1_update(struct drv_port *const p) +{ + if (drv_ps1_mc_update(p->mc) + || drv_ps1_cd_update(p->cd) + || drv_ps1_pad_update(p->pad)) + return -1; + + return 0; +} diff --git a/src/drv/ps1/time/CMakeLists.txt b/src/drv/ps1/time/CMakeLists.txt new file mode 100644 index 0000000..2746810 --- /dev/null +++ b/src/drv/ps1/time/CMakeLists.txt @@ -0,0 +1,22 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +add_library(drv_ps1_time) +add_subdirectory(src) +target_include_directories(drv_ps1_time PUBLIC include PRIVATE private_include) +target_link_libraries(drv_ps1_time + PUBLIC c + PRIVATE drv drv_ps1_bios drv_ps1_interrupt drv_ps1_rcnt) diff --git a/src/drv/ps1/time/include/drv/ps1/time.h b/src/drv/ps1/time/include/drv/ps1/time.h new file mode 100644 index 0000000..d08ff39 --- /dev/null +++ b/src/drv/ps1/time/include/drv/ps1/time.h @@ -0,0 +1,24 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_TIME_H +#define DRV_PS1_TIME_H + +int drv_ps1_time_tick(void); + +#endif diff --git a/src/drv/ps1/time/private_include/drv/ps1/time/types.h b/src/drv/ps1/time/private_include/drv/ps1/time/types.h new file mode 100644 index 0000000..ad420c6 --- /dev/null +++ b/src/drv/ps1/time/private_include/drv/ps1/time/types.h @@ -0,0 +1,26 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef DRV_PS1_TIME_TYPES_H +#define DRV_PS1_TIME_TYPES_H + +#include <time.h> + +extern volatile struct timespec drv_ps1_time; + +#endif diff --git a/src/drv/ps1/time/src/CMakeLists.txt b/src/drv/ps1/time/src/CMakeLists.txt new file mode 100644 index 0000000..0ab540e --- /dev/null +++ b/src/drv/ps1/time/src/CMakeLists.txt @@ -0,0 +1,23 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +target_sources(drv_ps1_time PRIVATE + gettime.c + getres.c + globals.c + settime.c + tick.c +) diff --git a/src/drv/ps1/time/src/getres.c b/src/drv/ps1/time/src/getres.c new file mode 100644 index 0000000..8dad204 --- /dev/null +++ b/src/drv/ps1/time/src/getres.c @@ -0,0 +1,34 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/time.h> +#include <errno.h> +#include <time.h> + +int drv_time_getres(const clockid_t id, struct timespec *const ts) +{ + if (id != CLOCK_REALTIME) + { + errno = EINVAL; + return -1; + } + else if (ts) + *ts = (const struct timespec){.tv_nsec = 1000000}; + + return 0; +} diff --git a/src/drv/ps1/time/src/gettime.c b/src/drv/ps1/time/src/gettime.c new file mode 100644 index 0000000..f01030f --- /dev/null +++ b/src/drv/ps1/time/src/gettime.c @@ -0,0 +1,37 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/time.h> +#include <drv/ps1/time/types.h> +#include <drv/ps1/bios.h> +#include <errno.h> +#include <time.h> + +int drv_time_gettime(const clockid_t id, struct timespec *const ts) +{ + if (id != CLOCK_REALTIME) + { + errno = EINVAL; + return -1; + } + + EnterCriticalSection(); + *ts = drv_ps1_time; + ExitCriticalSection(); + return 0; +} diff --git a/src/drv/ps1/time/src/globals.c b/src/drv/ps1/time/src/globals.c new file mode 100644 index 0000000..cb2a825 --- /dev/null +++ b/src/drv/ps1/time/src/globals.c @@ -0,0 +1,22 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/time/types.h> +#include <time.h> + +volatile struct timespec drv_ps1_time; diff --git a/src/drv/ps1/time/src/settime.c b/src/drv/ps1/time/src/settime.c new file mode 100644 index 0000000..25de76f --- /dev/null +++ b/src/drv/ps1/time/src/settime.c @@ -0,0 +1,37 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/time.h> +#include <drv/ps1/time/types.h> +#include <drv/ps1/bios.h> +#include <errno.h> +#include <time.h> + +int drv_time_settime(const clockid_t id, const struct timespec *const ts) +{ + if (id != CLOCK_REALTIME) + { + errno = EINVAL; + return -1; + } + + EnterCriticalSection(); + drv_ps1_time = *ts; + ExitCriticalSection(); + return 0; +} diff --git a/src/drv/ps1/time/src/tick.c b/src/drv/ps1/time/src/tick.c new file mode 100644 index 0000000..b80174b --- /dev/null +++ b/src/drv/ps1/time/src/tick.c @@ -0,0 +1,42 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <drv/ps1/time.h> +#include <drv/ps1/time/types.h> +#include <drv/ps1/interrupt.h> +#include <time.h> + +int drv_ps1_time_tick(void) +{ + int ret = 0; + struct timespec ts; + volatile struct timespec *const t = &drv_ps1_time; + + if (clock_getres(CLOCK_REALTIME, &ts)) + ret = -1; + else if (t->tv_nsec >= 1000000000 - ts.tv_nsec) + { + t->tv_sec++; + t->tv_nsec = 0; + } + else + t->tv_nsec += ts.tv_nsec; + + I_STAT->bits.tmr2 = 1; + return ret; +} |
