├── test ├── rom │ ├── axp_correct.log │ ├── es40.cfg │ ├── test.ps1 │ └── test.sh ├── disk │ └── unwritable │ │ ├── axp_correct.log │ │ ├── es40.cfg │ │ └── test.sh └── run ├── .gitignore ├── cmake ├── TestWindowsFSeek.c ├── TestFileOffsetBits.c └── TestLargeFiles.c.cmake.in ├── .travis.yml ├── sonar-project.properties ├── src ├── make_unique.hpp ├── cpu_vax.hpp ├── gui │ ├── scancodes.hpp │ ├── keymap.hpp │ └── plugin.hpp ├── ShrinkingChoiceQuestion.hpp ├── VGA.hpp ├── DiskController.hpp ├── VGA.cpp ├── DiskRam.hpp ├── lockstep.hpp ├── Main.cpp ├── SystemComponent.cpp ├── DiskDevice.hpp ├── DiskFile.hpp ├── DiskController.cpp ├── DPR.hpp ├── SystemComponent.hpp ├── Port80.hpp ├── Flash.hpp ├── AliM1543C_usb.hpp ├── SCSIDevice.hpp ├── Question.hpp ├── FreeTextQuestion.hpp ├── DMA.hpp ├── DiskRam.cpp ├── SCSIBus.hpp ├── Ethernet.hpp ├── base │ ├── Poco.hpp │ ├── Event.cpp │ ├── RWLock_POSIX.cpp │ ├── Semaphore.cpp │ ├── RWLock.cpp │ ├── RefCountedObject.cpp │ ├── Platform_POSIX.hpp │ ├── RWLock_WIN32.hpp │ ├── Semaphore_WIN32.hpp │ ├── ScopedLock.hpp │ ├── Event_WIN32.cpp │ ├── Mutex_WIN32.cpp │ ├── Semaphore_WIN32.cpp │ ├── Event_WIN32.hpp │ ├── Mutex_WIN32.hpp │ ├── Bugcheck.cpp │ ├── SingletonHolder.hpp │ ├── Semaphore_POSIX.hpp │ ├── Event_POSIX.hpp │ ├── Foundation.hpp │ ├── Mutex_POSIX.hpp │ ├── RefCountedObject.hpp │ └── Platform_VMS.hpp ├── Serial.hpp ├── Configurator.hpp ├── cpu_memory.hpp ├── NumberQuestion.hpp ├── PCIDevice.hpp ├── cpu_control.hpp ├── cpu_logical.hpp ├── Port80.cpp ├── es40_endian.hpp ├── es40_debug.cpp ├── config_debug.hpp ├── FloppyController.hpp └── telnet.hpp ├── README.md └── .clang-format /test/rom/axp_correct.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RaymiiOrg/axpbox/main/test/rom/axp_correct.log -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | cmake-build-debug/ 2 | cmake-build-release/ 3 | build**/ 4 | .idea/ 5 | .vs/ 6 | CMakeSettings.json 7 | run/ 8 | img/ 9 | -------------------------------------------------------------------------------- /cmake/TestWindowsFSeek.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | __int64 off=0; 6 | 7 | _fseeki64(NULL, off, SEEK_SET); 8 | 9 | return 0; 10 | } -------------------------------------------------------------------------------- /test/disk/unwritable/axp_correct.log: -------------------------------------------------------------------------------- 1 | %FLS-F-NOREST: Flash could not be restored from flash.rom 2 | Emulator Failure: Runtime exception: pci0.15(ali_ide).disk0.0(file): file disk-unwritable.img is not writable: DiskFile.cpp, line L 3 | Stop threads: 4 | Freeing memory in use by system... 5 | -------------------------------------------------------------------------------- /cmake/TestFileOffsetBits.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* Cause a compile-time error if off_t is smaller than 64 bits */ 4 | #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) 5 | int off_t_is_large[ (LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1 ]; 6 | 7 | int main(int argc, char **argv) 8 | { 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | dist: focal 3 | compiler: clang 4 | 5 | before_install: sudo apt-get install cmake libpcap-dev libsdl-dev netcat-openbsd 6 | install: 7 | - mkdir build 8 | - cd build 9 | - cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Wall -Werror" 10 | - make 11 | - cd .. 12 | script: 13 | - test/run 14 | 15 | -------------------------------------------------------------------------------- /test/rom/es40.cfg: -------------------------------------------------------------------------------- 1 | sys0 = tsunami 2 | { 3 | memory.bits = 26; 4 | rom.srm = "cl67srmrom.exe"; 5 | rom.decompressed = "decompressed.rom"; 6 | rom.flash = "flash.rom"; 7 | rom.dpr = "dpr.rom"; 8 | 9 | cpu0 = ev68cb 10 | { 11 | speed = 800M; 12 | icache = false; 13 | } 14 | 15 | serial0 = serial 16 | { 17 | address = "127.0.0.1"; 18 | port = 21000; 19 | } 20 | 21 | 22 | pci0.15 = ali_ide 23 | { 24 | } 25 | 26 | pci0.7 = ali 27 | { 28 | } 29 | 30 | pci0.19 = ali_usb 31 | { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectKey=rve_axpbox 2 | sonar.organization=rve 3 | 4 | # This is the name and version displayed in the SonarCloud UI. 5 | sonar.projectName=AXPBox 6 | sonar.projectVersion=1.1.3 7 | 8 | 9 | # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. 10 | sonar.sources=src/ 11 | 12 | # use complation database 13 | sonar.cfamily.compile-commands=../build/compile_commands.json 14 | 15 | # Encoding of the source code. Default is default system encoding 16 | #sonar.sourceEncoding=UTF-8 -------------------------------------------------------------------------------- /test/disk/unwritable/es40.cfg: -------------------------------------------------------------------------------- 1 | sys0 = tsunami 2 | { 3 | memory.bits = 26; 4 | rom.srm = "cl67srmrom.exe"; 5 | rom.decompressed = "decompressed.rom"; 6 | rom.flash = "flash.rom"; 7 | rom.dpr = "dpr.rom"; 8 | 9 | cpu0 = ev68cb 10 | { 11 | speed = 800M; 12 | icache = false; 13 | } 14 | 15 | serial0 = serial 16 | { 17 | address = "127.0.0.1"; 18 | port = 21000; 19 | } 20 | 21 | 22 | pci0.15 = ali_ide 23 | { 24 | disk0.0 = file 25 | { 26 | file = "disk-unwritable.img"; 27 | read_only = false; 28 | cdrom = false; 29 | autocreate_size = 100M; 30 | } 31 | } 32 | 33 | pci0.7 = ali 34 | { 35 | } 36 | 37 | pci0.19 = ali_usb 38 | { 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /cmake/TestLargeFiles.c.cmake.in: -------------------------------------------------------------------------------- 1 | #cmakedefine _LARGEFILE_SOURCE 2 | #cmakedefine _LARGE_FILES 3 | #cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | int main(int argc, char **argv) 10 | { 11 | /* Cause a compile-time error if off_t is smaller than 64 bits, 12 | * and make sure we have ftello / fseeko. 13 | */ 14 | #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) 15 | int off_t_is_large[ (LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1 ]; 16 | FILE *fp = fopen(argv[0],"r"); 17 | off_t offset = ftello( fp ); 18 | 19 | fseeko( fp, offset, SEEK_CUR ); 20 | fclose(fp); 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /test/run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | success=0 3 | 4 | function message() { 5 | echo -n -e '\033[1;36m' >&2 6 | echo $1 >&2 7 | echo -n -e '\033[0m' >&2 8 | } 9 | 10 | function run_test() { 11 | local old_pwd=$(pwd) 12 | 13 | message "[test] Started test $1 at $(date)" 14 | 15 | cd "test/$1" 16 | ./test.sh 17 | local result=$? 18 | cd "$old_pwd" 19 | 20 | if [ "$result" -eq "0" ] 21 | then 22 | message "[test] Test $1 finished at $(date)" >&2 23 | else 24 | success=1 25 | message "[test] Test $1 failed at $(date)" >&2 26 | fi 27 | } 28 | 29 | message "[test] This is the AXPbox test script" 30 | 31 | run_test rom 32 | run_test disk/unwritable 33 | 34 | if [ "$success" -ne "0" ] 35 | then 36 | message "[test] Some tests failed, please check the log" 37 | else 38 | message "[test] All tests passed" 39 | fi 40 | 41 | exit "$success" 42 | -------------------------------------------------------------------------------- /test/disk/unwritable/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | touch disk-unwritable.img 4 | chmod 400 disk-unwritable.img 5 | 6 | # Download the firmware 7 | if [[ ! -f "cl67srmrom.exe" ]]; then 8 | wget 'http://raymii.org/s/inc/downloads/es40-srmon/cl67srmrom.exe' 9 | fi 10 | 11 | # Start AXPbox 12 | if [[ -f ../../../build/axpbox ]]; then 13 | ../../../build/axpbox run | tee axp.log 14 | elif [[ -f ../../../../build/axpbox ]]; then 15 | ../../../../build/axpbox run | tee axp.log; 16 | else 17 | ../../build/axpbox run | tee axp.log 18 | fi 19 | 20 | chmod 700 disk-unwritable.img 21 | rm disk-unwritable.img 22 | 23 | # OS X github runner has weiro sed version, use gnu one there. 24 | SED=/usr/bin/sed 25 | if [[ -f "/usr/local/opt/gnu-sed/libexec/gnubin/sed" ]]; then 26 | SED=/usr/local/opt/gnu-sed/libexec/gnubin/sed 27 | fi 28 | 29 | ${SED} -i -e 's$/[^ ]*/DiskFile.cpp$DiskFile.cpp$g' -e 's/line [0-9]*/line L/g' -e '/$Id/d' axp.log 30 | 31 | echo -n -e '\033[1;31m' 32 | diff -c axp_correct.log axp.log && echo -e '\033[1;32mdiff clean\033[0m' 33 | result=$? 34 | echo -n -e '\033[0m' 35 | 36 | rm -f axp.log cl67* *.rom 37 | exit $result 38 | -------------------------------------------------------------------------------- /test/rom/test.ps1: -------------------------------------------------------------------------------- 1 | # Download the firmware 2 | Invoke-WebRequest -Uri 'http://raymii.org/s/inc/downloads/es40-srmon/cl67srmrom.exe' -OutFile 'cl67srmrom.exe' 3 | 4 | # Start AXPbox 5 | Start-Process '..\..\..\build\Release\axpbox' -ArgumentList 'run' -NoNewWindow -RedirectStandardOutput stdout.txt -RedirectStandardError stderr.txt 6 | 7 | # Wait for AXPbox to start 8 | Start-Sleep -Seconds 5 9 | 10 | # Connect to terminal 11 | Start-Process -FilePath 'nc' -ArgumentList '-t', '127.0.0.1', '21000' -NoNewWindow -RedirectStandardOutput 'axp.log' 12 | 13 | # Wait for the last line of log to become P00>>> 14 | $timeout = 300 15 | while ($true) { 16 | if ($timeout -eq 0) { 17 | Write-Host "waiting for SRM prompt timed out" -ForegroundColor Red 18 | exit 1 19 | } 20 | 21 | # echo "=== start axp.log ===" 22 | # Get-Content -Path 'axp.log' -Raw 23 | # echo "=== end axp.log ===" 24 | 25 | $content = Get-Content -Path 'axp.log' -Raw 26 | $contentWithoutNullBytes = $content -replace '\0', '' 27 | 28 | if ($contentWithoutNullBytes -match "P00>>>") { 29 | exit 0 30 | } 31 | 32 | Start-Sleep -Seconds 1 33 | $timeout-- 34 | } 35 | 36 | Stop-Process -Name 'nc' 37 | -------------------------------------------------------------------------------- /test/rom/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export LC_CTYPE=C 3 | export LANG=C 4 | export LC_ALL=C 5 | 6 | # Download the firmware 7 | wget 'http://raymii.org/s/inc/downloads/es40-srmon/cl67srmrom.exe' 8 | 9 | # Start AXPbox 10 | if [[ -f ../../../build/axpbox ]]; then 11 | ../../../build/axpbox run & 12 | AXPBOX_PID=$! 13 | else # Travis 14 | ../../build/axpbox run & 15 | AXPBOX_PID=$! 16 | fi 17 | 18 | # Wait for AXPbox to start 19 | sleep 5 20 | 21 | # Connect to terminal 22 | nc -t 127.0.0.1 21000 | tee axp.log & 23 | NETCAT_PID=$! 24 | 25 | # Wait for the last line of log to become P00>>> 26 | timeout=600 27 | while true 28 | do 29 | if [ $timeout -eq 0 ] 30 | then 31 | echo "waiting for SRM prompt timed out" >&2 32 | exit 1 33 | fi 34 | 35 | # print last line and remove null byte from it 36 | if [ "$(LC_ALL=C sed -n '$p' axp.log | LC_ALL=C sed 's/\x00//g')" == "P00>>>" ] 37 | then 38 | echo 39 | break 40 | fi 41 | 42 | sleep 1 43 | timeout=$(($timeout - 1)) 44 | done 45 | 46 | kill $NETCAT_PID 47 | kill $AXPBOX_PID 48 | 49 | echo -n -e '\033[1;31m' 50 | diff -c axp_correct.log axp.log && echo -e '\033[1;32mdiff clean\033[0m' 51 | result=$? 52 | echo -n -e '\033[0m' 53 | 54 | rm -f axp.log cl67* *.rom 55 | exit $result 56 | -------------------------------------------------------------------------------- /src/make_unique.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Copyright (C) 2020 Remy van Elst 4 | * Website: https://github.com/lenticularis39/axpbox 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 19 | * USA. 20 | * 21 | * Although this is not required, the author would appreciate being notified of, 22 | * and receiving any modifications you may make to the source code that might 23 | * serve the general public. 24 | */ 25 | 26 | #ifndef AXPBOX_MAKE_UNIQUE_H 27 | #define AXPBOX_MAKE_UNIQUE_H 28 | #include 29 | /* Allow C++11 code to use std::make_unique 30 | * example ifdef: #if __cplusplus < 201402L 31 | */ 32 | namespace std 33 | { 34 | template 35 | std::unique_ptr make_unique( Args&& ...args ) 36 | { 37 | return std::unique_ptr( new T( std::forward(args)... ) ); 38 | } 39 | } 40 | #endif // AXPBOX_MAKE_UNIQUE_H 41 | -------------------------------------------------------------------------------- /src/cpu_vax.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #define DO_RC \ 30 | state.r[REG_1] = state.bIntrFlag ? 1 : 0; \ 31 | state.bIntrFlag = false; 32 | 33 | #define DO_RS \ 34 | state.r[REG_1] = state.bIntrFlag ? 1 : 0; \ 35 | state.bIntrFlag = true; 36 | -------------------------------------------------------------------------------- /src/gui/scancodes.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This file is based upon Bochs. 10 | * 11 | * Copyright (C) 2002 MandrakeSoft S.A. 12 | * 13 | * MandrakeSoft S.A. 14 | * 43, rue d'Aboukir 15 | * 75002 Paris - France 16 | * http://www.linux-mandrake.com/ 17 | * http://www.mandrakesoft.com/ 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library; if not, write to the Free Software 31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 32 | */ 33 | 34 | #include "gui.hpp" 35 | #ifndef BX_SCANCODES_H 36 | #define BX_SCANCODES_H 37 | 38 | // Translation table of the 8042 39 | extern unsigned char translation8042[256]; 40 | 41 | typedef struct { 42 | const char *make; 43 | const char *brek; 44 | } scancode; 45 | 46 | // Scancodes table 47 | extern scancode scancodes[BX_KEY_NBKEYS][3]; 48 | #endif 49 | -------------------------------------------------------------------------------- /src/ShrinkingChoiceQuestion.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | /** 30 | * Question class implementing a "Shrinking Choice" question. 31 | * 32 | * A shrinking choice question is a multiple choice question 33 | * where each answer given is removed from the list of valid 34 | * answers. 35 | **/ 36 | class ShrinkingChoiceQuestion : public MultipleChoiceQuestion { 37 | /** 38 | * Overridden to remove the answer that was given from the 39 | * allowed answer set. 40 | **/ 41 | virtual void haveChosen(string choice) { dropChoice(choice); } 42 | }; 43 | -------------------------------------------------------------------------------- /src/VGA.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(__VGA_H__) 30 | #define __VGA_H__ 31 | 32 | #include "PCIDevice.hpp" 33 | 34 | /** 35 | * \brief Abstract base class for PCI VGA cards. 36 | **/ 37 | class CVGA : public CPCIDevice { 38 | public: 39 | CVGA(class CConfigurator *cfg, class CSystem *c, int pcibus, int pcidev); 40 | ~CVGA(void); 41 | 42 | virtual u8 get_actl_palette_idx(u8 index) = 0; 43 | virtual void redraw_area(unsigned x0, unsigned y0, unsigned width, 44 | unsigned height) = 0; 45 | }; 46 | 47 | extern CVGA *theVGA; 48 | #endif 49 | -------------------------------------------------------------------------------- /src/DiskController.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(__DISKCONTROLLER_H__) 30 | #define __DISKCONTROLLER_H__ 31 | 32 | /** 33 | * \brief Abstract base class for disk controllers (uses CDisk's) 34 | **/ 35 | class CDiskController { 36 | public: 37 | CDiskController(int num_busses, int num_devs); 38 | ~CDiskController(void); 39 | 40 | virtual void register_disk(class CDisk *dsk, int bus, int dev); 41 | class CDisk *get_disk(int bus, int dev); 42 | 43 | private: 44 | int num_bus; 45 | int num_dev; 46 | 47 | class CDisk **disks; 48 | }; 49 | #endif //! defined(__DISKCONTROLLER_H__) 50 | -------------------------------------------------------------------------------- /src/VGA.cpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #include "VGA.hpp" 30 | #include "StdAfx.hpp" 31 | 32 | /** 33 | * Constructor. 34 | * 35 | * Checks if more than one VGA card is present. If so, throws a failure. 36 | **/ 37 | CVGA::CVGA(class CConfigurator *cfg, class CSystem *c, int pcibus, int pcidev) 38 | : CPCIDevice(cfg, c, pcibus, pcidev) { 39 | if (theVGA != 0) 40 | FAILURE(Configuration, "More than one VGA"); 41 | theVGA = this; 42 | } 43 | 44 | /** 45 | * Destructor. 46 | **/ 47 | CVGA::~CVGA(void) {} 48 | 49 | /** 50 | * Variable pointer to the one and only VGA card. 51 | **/ 52 | CVGA *theVGA = 0; 53 | -------------------------------------------------------------------------------- /src/DiskRam.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(__DISKRAM_H__) 30 | #define __DISKRAM_H__ 31 | 32 | #include "Disk.hpp" 33 | 34 | /** 35 | * \brief Emulated disk that uses RAM. 36 | **/ 37 | class CDiskRam : public CDisk { 38 | public: 39 | CDiskRam(CConfigurator *cfg, CSystem *sys, CDiskController *c, int idebus, 40 | int idedev); 41 | virtual ~CDiskRam(void); 42 | 43 | virtual bool seek_byte(off_t_large byte); 44 | virtual size_t read_bytes(void *dest, size_t bytes); 45 | virtual size_t write_bytes(void *src, size_t bytes); 46 | 47 | protected: 48 | void *ramdisk; 49 | }; 50 | #endif //! defined(__DISKFILE_H__) 51 | -------------------------------------------------------------------------------- /src/lockstep.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(INCLUDED_LOCKSTEP_H) 30 | #define INCLUDED_LOCKSTEP_H 31 | 32 | #include "telnet.hpp" 33 | 34 | #if defined(IDB) && (defined(LS_MASTER) || defined(LS_SLAVE)) 35 | extern int ls_Socket; 36 | 37 | #if defined(LS_MASTER) 38 | extern char ls_IP[30]; 39 | #else 40 | extern int ls_listenSocket; 41 | #endif 42 | void lockstep_init(); 43 | void lockstep_sync_m2s(char *s); 44 | void lockstep_sync_s2m(char *s); 45 | void lockstep_compare(char *s); 46 | void lockstep_send(char *s); 47 | void lockstep_receive(char *s, int sz); 48 | #endif // defined(IDB) && (defined(LS_MASTER) || defined(LS_SLAVE)) 49 | #endif // !defined(INCLUDED_LOCKSTEP_H) 50 | -------------------------------------------------------------------------------- /src/Main.cpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Copyright (C) 2020 Remy van Elst 4 | * Website: https://github.com/lenticularis39/axpbox 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 19 | * USA. 20 | * 21 | * Although this is not required, the author would appreciate being notified of, 22 | * and receiving any modifications you may make to the source code that might 23 | * serve the general public. 24 | */ 25 | 26 | #include "config.hpp" 27 | #include 28 | #include 29 | 30 | int main_sim(int argc, char *argv[]); 31 | int main_cfg(int argc, char *argv[]); 32 | 33 | int main(int argc, char **argv) { 34 | if (argc <= 1 || (strcmp(argv[1], "run") && strcmp(argv[1], "configure"))) { 35 | std::cerr << "AXPBox Alpha Emulator"; 36 | #ifdef PACKAGE_GITSHA 37 | std::cerr << " (commit " << std::string(PACKAGE_GITSHA) << ")"; 38 | #endif 39 | std::cerr << std::endl; 40 | std::cerr << "Usage: " << argv[0] << " run|configure " << std::endl; 41 | return 0; 42 | } 43 | 44 | if (strcmp(argv[1], "run") == 0) { 45 | return main_sim(argc - 1, ++argv); 46 | } 47 | 48 | if (strcmp(argv[1], "configure") == 0) { 49 | return main_cfg(argc - 1, ++argv); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/SystemComponent.cpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #include "SystemComponent.hpp" 30 | #include "StdAfx.hpp" 31 | #include "System.hpp" 32 | 33 | /** 34 | * Constructor. 35 | **/ 36 | CSystemComponent::CSystemComponent(CConfigurator *cfg, CSystem *system) { 37 | char *a; 38 | char *b; 39 | 40 | system->RegisterComponent(this); 41 | cSystem = system; 42 | myCfg = cfg; 43 | 44 | a = myCfg->get_myName(); 45 | b = myCfg->get_myValue(); 46 | 47 | CHECK_ALLOCATION(devid_string = (char *)malloc(strlen(a) + strlen(b) + 3)); 48 | sprintf(devid_string, "%s(%s)", a, b); 49 | } 50 | 51 | /** 52 | * destructor. 53 | **/ 54 | CSystemComponent::~CSystemComponent() { 55 | cSystem->UnregisterComponent(this); 56 | free(devid_string); 57 | devid_string = nullptr; 58 | } 59 | -------------------------------------------------------------------------------- /src/DiskDevice.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(__DISKDEV_H__) 30 | #define __DISKDEV_H__ 31 | 32 | #include "Disk.hpp" 33 | 34 | /** 35 | * \brief Emulated disk that uses a raw device. 36 | **/ 37 | class CDiskDevice : public CDisk { 38 | public: 39 | CDiskDevice(CConfigurator *cfg, CSystem *sys, CDiskController *c, int idebus, 40 | int idedev); 41 | virtual ~CDiskDevice(void); 42 | 43 | virtual bool seek_byte(off_t_large byte); 44 | virtual size_t read_bytes(void *dest, size_t bytes); 45 | virtual size_t write_bytes(void *src, size_t bytes); 46 | 47 | protected: 48 | #if defined(_WIN32) 49 | HANDLE handle; 50 | char *buffer; 51 | size_t buffer_size; 52 | size_t dev_block_size; 53 | #else 54 | FILE *handle; 55 | #endif 56 | char *filename; 57 | }; 58 | #endif //! defined(__DISKFILE_H__) 59 | -------------------------------------------------------------------------------- /src/DiskFile.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Copyright (C) 2020 Remy van Elst 4 | * Website: https://github.com/lenticularis39/axpbox 5 | * 6 | * Forked from: ES40 emulator 7 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 8 | * Copyright (C) 2007 by Camiel Vanderhoeven 9 | * 10 | * This program is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU General Public License 12 | * as published by the Free Software Foundation; either version 2 13 | * of the License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 23 | * USA. 24 | * 25 | * Although this is not required, the author would appreciate being notified of, 26 | * and receiving any modifications you may make to the source code that might 27 | * serve the general public. 28 | */ 29 | 30 | #if !defined(__DISKFILE_H__) 31 | #define __DISKFILE_H__ 32 | 33 | #include "Disk.hpp" 34 | 35 | /** 36 | * \brief Emulated disk that uses an image file. 37 | **/ 38 | class CDiskFile : public CDisk { 39 | public: 40 | CDiskFile(CConfigurator *cfg, CSystem *sys, CDiskController *c, int idebus, 41 | int idedev); 42 | virtual ~CDiskFile(void); 43 | 44 | virtual bool seek_byte(off_t_large byte); 45 | virtual size_t read_bytes(void *dest, size_t bytes); 46 | virtual size_t write_bytes(void *src, size_t bytes); 47 | 48 | FILE *get_handle() { return handle; }; 49 | 50 | protected: 51 | FILE *handle; 52 | char *filename; 53 | 54 | void createDiskFile(const std::string &filename, u64 diskFileSize); 55 | std::string defaultFilename; 56 | void checkFileWritable(const std::string& filename) const; 57 | }; 58 | #endif //! defined(__DISKFILE_H__) 59 | -------------------------------------------------------------------------------- /src/DiskController.cpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #include "DiskController.hpp" 30 | #include "Disk.hpp" 31 | #include "StdAfx.hpp" 32 | 33 | CDiskController::CDiskController(int num_busses, int num_devices) { 34 | num_bus = num_busses; 35 | num_dev = num_devices; 36 | 37 | disks = (CDisk **)calloc(num_bus * num_dev, sizeof(CDisk *)); 38 | } 39 | 40 | CDiskController::~CDiskController(void) { free(disks); } 41 | 42 | void CDiskController::register_disk(class CDisk *dsk, int bus, int dev) { 43 | if (bus >= num_bus) 44 | FAILURE(Configuration, "Can't register disk: bus number out of range"); 45 | if (dev >= num_dev) 46 | FAILURE(Configuration, "Can't register disk: device number out of range"); 47 | 48 | disks[bus * num_bus + dev] = dsk; 49 | } 50 | 51 | class CDisk *CDiskController::get_disk(int bus, int dev) { 52 | if (bus >= num_bus) 53 | return 0; 54 | if (dev >= num_dev) 55 | return 0; 56 | 57 | return disks[bus * num_bus + dev]; 58 | } 59 | -------------------------------------------------------------------------------- /src/DPR.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(INCLUDED_DPR_H) 30 | #define INCLUDED_DPR_H 31 | 32 | #include "SystemComponent.hpp" 33 | 34 | /** 35 | * \brief Emulated dual-port RAM and management controller. 36 | **/ 37 | class CDPR : public CSystemComponent { 38 | public: 39 | CDPR(CConfigurator *cfg, class CSystem *c); 40 | virtual ~CDPR(); 41 | virtual void init(); 42 | virtual void WriteMem(int index, u64 address, int dsize, u64 data); 43 | virtual u64 ReadMem(int index, u64 address, int dsize); 44 | virtual int SaveState(FILE *f); 45 | virtual int RestoreState(FILE *f); 46 | void SaveStateF(); 47 | void RestoreStateF(); 48 | void SaveStateF(char *fn); 49 | void RestoreStateF(char *fn); 50 | 51 | protected: 52 | /// The state structure contains all elements that need to be saved to the 53 | /// statefile. 54 | struct SDPR_state { 55 | u8 ram[16 * 1024]; 56 | } state; 57 | }; 58 | 59 | extern CDPR *theDPR; 60 | #endif // !defined(INCLUDED_DPR_H_) 61 | -------------------------------------------------------------------------------- /src/SystemComponent.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(INCLUDED_SYSTEMCOMPONENT_H) 30 | #define INCLUDED_SYSTEMCOMPONENT_H 31 | 32 | #include "Configurator.hpp" 33 | 34 | /** 35 | * \brief Abstract base class for devices that connect to the Typhoon chipset. 36 | **/ 37 | class CSystemComponent { 38 | public: 39 | virtual int RestoreState(FILE *f) = 0; 40 | virtual int SaveState(FILE *f) = 0; 41 | 42 | CSystemComponent(class CConfigurator *cfg, class CSystem *system); 43 | virtual ~CSystemComponent(); 44 | 45 | //=== abstract === 46 | virtual u64 ReadMem(int index, u64 address, int dsize) { return 0; }; 47 | virtual void WriteMem(int index, u64 address, int dsize, u64 data){}; 48 | virtual void check_state(){}; 49 | virtual void ResetPCI(){}; 50 | virtual void init(){}; 51 | virtual void start_threads(){}; 52 | virtual void stop_threads(){}; 53 | 54 | char *devid_string; 55 | 56 | protected: 57 | class CSystem *cSystem; 58 | class CConfigurator *myCfg; 59 | }; 60 | #endif // !defined(INCLUDED_SYSTEMCOMPONENT_H) 61 | -------------------------------------------------------------------------------- /src/Port80.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(INCLUDED_PORT80_H) 30 | #define INCLUDED_PORT80_H 31 | 32 | #include "SystemComponent.hpp" 33 | 34 | /** 35 | * \brief Emulated port 80. 36 | * 37 | * Port 80 is a port without a real function, that is used to slow things down. 38 | * Since our emulator is slow enough already ;-) this port has no function at 39 | * all, but it needs to be there to avoid error messages about non-existing 40 | * hardware. 41 | **/ 42 | class CPort80 : public CSystemComponent { 43 | public: 44 | CPort80(CConfigurator *cfg, class CSystem *c); 45 | virtual ~CPort80(); 46 | virtual u64 ReadMem(int index, u64 address, int dsize); 47 | virtual void WriteMem(int index, u64 address, int dsize, u64 data); 48 | virtual int SaveState(FILE *f); 49 | virtual int RestoreState(FILE *f); 50 | 51 | protected: 52 | /// The state structure contains all elements that need to be saved to the 53 | /// statefile. 54 | struct SPort80_state { 55 | u8 p80; /**< Last value written.*/ 56 | } state; 57 | }; 58 | #endif // !defined(INCLUDED_PORT80_H) 59 | -------------------------------------------------------------------------------- /src/Flash.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(INCLUDED_FLASH_H) 30 | #define INCLUDED_FLASH_H 31 | 32 | #include "SystemComponent.hpp" 33 | 34 | /** 35 | * \brief Emulated flash memory. 36 | * 37 | * Flash memory is only used for storing configuration data (such as SRM console 38 | *variables), it is not used for firmware. 39 | **/ 40 | class CFlash : public CSystemComponent { 41 | public: 42 | virtual void WriteMem(int index, u64 address, int dsize, u64 data); 43 | virtual u64 ReadMem(int index, u64 address, int dsize); 44 | CFlash(CConfigurator *cfg, class CSystem *c); 45 | virtual ~CFlash(); 46 | virtual int SaveState(FILE *f); 47 | virtual int RestoreState(FILE *f); 48 | void SaveStateF(); 49 | void RestoreStateF(); 50 | void SaveStateF(char *fn); 51 | void RestoreStateF(char *fn); 52 | 53 | protected: 54 | /// The state structure contains all elements that need to be saved to the 55 | /// statefile. 56 | struct SFlash_state { 57 | u8 Flash[2 * 1024 * 1024]; 58 | int mode; 59 | } state; 60 | }; 61 | 62 | extern CFlash *theSROM; 63 | #endif // !defined(INCLUDED_FLASH_H) 64 | -------------------------------------------------------------------------------- /src/gui/keymap.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This file is based upon Bochs. 10 | * 11 | * Copyright (C) 2002 MandrakeSoft S.A. 12 | * 13 | * MandrakeSoft S.A. 14 | * 43, rue d'Aboukir 15 | * 75002 Paris - France 16 | * http://www.linux-mandrake.com/ 17 | * http://www.mandrakesoft.com/ 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library; if not, write to the Free Software 31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 32 | */ 33 | 34 | #include "../Configurator.hpp" 35 | 36 | // In case of unknown symbol 37 | #define BX_KEYMAP_UNKNOWN 0xFFFFFFFF 38 | 39 | /// Structure of an element of the keymap table 40 | typedef struct { 41 | u32 baseKey; // base key 42 | u32 modKey; // modifier key that must be held down 43 | s32 ascii; // ascii equivalent, if any 44 | u32 hostKey; // value that the host's OS or library recognizes 45 | } BXKeyEntry; 46 | 47 | /** 48 | * \brief Keymap, used to map host keys to scancodes. 49 | **/ 50 | class bx_keymap_c { 51 | public: 52 | bx_keymap_c(CConfigurator *cfg); 53 | ~bx_keymap_c(void); 54 | 55 | void loadKeymap(u32 stringToSymbol(const char *)); 56 | void loadKeymap(u32 stringToSymbol(const char *), const char *filename); 57 | bool isKeymapLoaded(); 58 | 59 | BXKeyEntry *findHostKey(u32 hostkeynum); 60 | BXKeyEntry *findAsciiChar(u8 ascii); 61 | const char *getBXKeyName(u32 key); 62 | 63 | private: 64 | u32 convertStringToBXKey(const char *); 65 | CConfigurator *myCfg; 66 | 67 | BXKeyEntry *keymapTable; 68 | u16 keymapCount; 69 | }; 70 | 71 | extern bx_keymap_c *bx_keymap; 72 | -------------------------------------------------------------------------------- /src/gui/plugin.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * Copyright (C) 2002 MandrakeSoft S.A. 10 | * 11 | * MandrakeSoft S.A. 12 | * 43, rue d'Aboukir 13 | * 75002 Paris - France 14 | * http://www.linux-mandrake.com/ 15 | * http://www.mandrakesoft.com/ 16 | * 17 | * This library is free software; you can redistribute it and/or 18 | * modify it under the terms of the GNU Lesser General Public 19 | * License as published by the Free Software Foundation; either 20 | * version 2 of the License, or (at your option) any later version. 21 | * 22 | * This library is distributed in the hope that it will be useful, 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * Lesser General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU Lesser General Public 28 | * License along with this library; if not, write to the Free Software 29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 30 | */ 31 | 32 | ///////////////////////////////////////////////////////////////////////// 33 | // 34 | // This file provides macros and types needed for plugins. It is based on 35 | // the plugin.h file from plex86, but with significant changes to make 36 | // it work in Bochs. 37 | // Plex86 is Copyright (C) 1999-2000 The plex86 developers team 38 | // 39 | ///////////////////////////////////////////////////////////////////////// 40 | #ifndef __PLUGIN_H 41 | #define __PLUGIN_H 42 | 43 | #define PLUG_load_plugin(cfg, name) \ 44 | { lib##name##_LTX_plugin_init(cfg); } 45 | #define PLUG_unload_plugin(name) \ 46 | { lib##name##_LTX_plugin_fini(); } 47 | 48 | #define DECLARE_PLUGIN_INIT_FINI_FOR_MODULE(mod) \ 49 | int lib##mod##_LTX_plugin_init(CConfigurator *cfg); \ 50 | void lib##mod##_LTX_plugin_fini(void); 51 | 52 | #if defined(HAVE_SDL) 53 | DECLARE_PLUGIN_INIT_FINI_FOR_MODULE(sdl) 54 | #endif 55 | #if defined(_WIN32) 56 | DECLARE_PLUGIN_INIT_FINI_FOR_MODULE(win32) 57 | #endif 58 | #if defined(HAVE_X11) 59 | DECLARE_PLUGIN_INIT_FINI_FOR_MODULE(x11) 60 | #endif 61 | #endif /* __PLUGIN_H */ 62 | -------------------------------------------------------------------------------- /src/AliM1543C_usb.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(INCLUDED_ALIM1543C_USB_H_) 30 | #define INCLUDED_ALIM1543C_USB_H_ 31 | 32 | #include "PCIDevice.hpp" 33 | 34 | /** 35 | * \brief Emulated USB part of ALi M1543C multi-function device. 36 | * 37 | * \todo This device is just a stub. Not functional yet. 38 | * 39 | * Documentation consulted: 40 | * - Ali M1543C B1 South Bridge Version 1.20 41 | * (http://mds.gotdns.com/sensors/docs/ali/1543dScb1-120.pdf) 42 | * . 43 | **/ 44 | class CAliM1543C_usb : public CPCIDevice { 45 | public: 46 | virtual int SaveState(FILE *f); 47 | virtual int RestoreState(FILE *f); 48 | 49 | CAliM1543C_usb(CConfigurator *cfg, class CSystem *c, int pcibus, int pcidev); 50 | virtual ~CAliM1543C_usb(); 51 | virtual void WriteMem_Bar(int func, int bar, u32 address, int dsize, 52 | u32 data); 53 | virtual u32 ReadMem_Bar(int func, int bar, u32 address, int dsize); 54 | 55 | private: 56 | u64 usb_hci_read(u64 address, int dsize); 57 | void usb_hci_write(u64 address, int dsize, u64 data); 58 | 59 | /// The state structure contains all elements that need to be saved to the 60 | /// statefile. 61 | struct SUSB_state { 62 | u32 usb_data[0x110 / 4]; 63 | } state; 64 | }; 65 | #endif // !defined(INCLUDED_ALIM1543C_USB_H) 66 | -------------------------------------------------------------------------------- /src/SCSIDevice.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(__SCSIDEVICE__H__) 30 | #define __SCSIDEVICE__H__ 31 | 32 | #include "StdAfx.hpp" 33 | 34 | /** 35 | * \brief Base class for emulated SCSI devices. 36 | * 37 | * Connects to one or more SCSI busses (class CSCSIBus) together; derived 38 | * SCSI devices are disks and controllers. 39 | **/ 40 | class CSCSIDevice { 41 | public: 42 | CSCSIDevice(void); 43 | virtual ~CSCSIDevice(void); 44 | 45 | void scsi_register(int busno, class CSCSIBus *with, int target); 46 | 47 | bool scsi_arbitrate(int bus); 48 | bool scsi_select(int bus, int target); 49 | virtual void scsi_select_me(int bus); 50 | void scsi_set_phase(int bus, int phase); 51 | int scsi_get_phase(int bus); 52 | void scsi_free(int bus); 53 | 54 | virtual size_t scsi_expected_xfer_me(int bus); 55 | size_t scsi_expected_xfer(int bus); 56 | 57 | virtual void *scsi_xfer_ptr_me(int bus, size_t bytes); 58 | void *scsi_xfer_ptr(int bus, size_t bytes); 59 | 60 | virtual void scsi_xfer_done_me(int bus); 61 | void scsi_xfer_done(int bus); 62 | 63 | protected: 64 | class CSCSIBus *scsi_bus[10]; /**< SCSI busses this device connects to. Disks 65 | connect to 1 bus only, controllers can have 66 | several SCSI busses. **/ 67 | int scsi_initiator_id[10]; /**< Main SCSI id of this device on each of the 68 | busses. **/ 69 | }; 70 | #endif 71 | -------------------------------------------------------------------------------- /src/Question.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(INCLUDED_QUESTION_H) 30 | #define INCLUDED_QUESTION_H 31 | 32 | /** 33 | * Abstract Question base class. 34 | **/ 35 | class Question { 36 | public: 37 | /** 38 | * Return the answer previously given. 39 | **/ 40 | string getAnswer() { return mAnswer; } 41 | 42 | /** 43 | * Set the answer. 44 | **/ 45 | void setAnswer(string answer) { mAnswer = answer; } 46 | 47 | /** 48 | * Define an explanation for the question, that will be shown when 49 | * the question is answered with '?'. 50 | **/ 51 | void setExplanation(string explanation) { mExplanation = explanation; } 52 | 53 | /** 54 | * Define the question to ask. 55 | **/ 56 | void setQuestion(string question) { mQuestion = question; } 57 | 58 | /** 59 | * Define a default value to use when the question is answered 60 | * with a . 61 | **/ 62 | void setDefault(string defval) { mDefault = defval; } 63 | 64 | /** 65 | * Ask the question, and return the value given. 66 | **/ 67 | virtual string ask() = 0; 68 | 69 | /** 70 | * Display the explanation. 71 | **/ 72 | virtual void explain() { 73 | cout << "\nEXPLANATION:\n" << mExplanation << "\n\n"; 74 | } 75 | 76 | protected: 77 | /** The stored answer. */ 78 | string mAnswer; 79 | 80 | /** An explanation for the question. */ 81 | string mExplanation; 82 | 83 | /** The question to ask. */ 84 | string mQuestion; 85 | 86 | /** Default value. */ 87 | string mDefault; 88 | }; 89 | 90 | #endif // !defined(INCLUDED_QUESTION_H) 91 | -------------------------------------------------------------------------------- /src/FreeTextQuestion.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #include "Question.hpp" 30 | 31 | /** 32 | * Question class that allows free-format text input. 33 | **/ 34 | class FreeTextQuestion : public Question { 35 | public: 36 | /** 37 | * Define a list of options to show following the question, 38 | * to show the user what values are acceptable. 39 | **/ 40 | void setOptions(string options) { mOptions = options; } 41 | 42 | /** 43 | * Ask the question, and return the answer. 44 | **/ 45 | virtual string ask() { 46 | for (;;) { 47 | cout << mQuestion; 48 | 49 | /* If there is an options list, display it after the 50 | * question enclosed in (). 51 | */ 52 | if (mOptions != "") 53 | cout << " (" << mOptions << ")"; 54 | 55 | /* If there is a default value, display it after the 56 | * question enclosed in []. 57 | */ 58 | if (mDefault != "") 59 | cout << " [" << mDefault << "]"; 60 | 61 | cout << ": "; 62 | 63 | /* Get the answer. 64 | */ 65 | getline(cin, mAnswer); 66 | 67 | /* If the question is answered with '?', display the 68 | * explanation, then ask again. 69 | */ 70 | if (mAnswer == "?") { 71 | explain(); 72 | continue; 73 | } 74 | 75 | /* If the question is answered with , set the 76 | * answer to the default answer. 77 | */ 78 | if (mAnswer == "") 79 | mAnswer = mDefault; 80 | 81 | /* Return the answer. 82 | */ 83 | return mAnswer; 84 | } 85 | } 86 | 87 | protected: 88 | /** List of options to show after the question. */ 89 | string mOptions; 90 | }; 91 | -------------------------------------------------------------------------------- /src/DMA.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(INCLUDED_DMA_H) 30 | #define INCLUDED_DMA_H 31 | 32 | #include "SystemComponent.hpp" 33 | 34 | /** 35 | * \brief Emulated DMA controller. 36 | **/ 37 | 38 | class CDMA : public CSystemComponent { 39 | public: 40 | CDMA(CConfigurator *cfg, CSystem *c); 41 | virtual ~CDMA(); 42 | 43 | virtual int DoClock(); 44 | virtual void WriteMem(int index, u64 address, int dsize, u64 data); 45 | virtual u64 ReadMem(int index, u64 address, int dsize); 46 | virtual int SaveState(FILE *f); 47 | virtual int RestoreState(FILE *f); 48 | 49 | void set_request(int index, int channel, int data); 50 | void send_data(int channel, void *data); 51 | void recv_data(int channel, void *data); 52 | int get_count(int channel) { return state.channel[channel].count; }; 53 | 54 | private: 55 | void do_dma(); 56 | 57 | /// The state structure contains all elements that need to be saved to the 58 | /// statefile. 59 | struct SDMA_state { 60 | /// DMA channel state 61 | struct SDMA_chan { 62 | bool a_lobyte; // address lobyte expected 63 | bool c_lobyte; // count lobyte expected 64 | u16 current; 65 | u16 base; 66 | u16 pagebase; 67 | u16 count; 68 | u8 mode; 69 | } channel[8]; 70 | 71 | /// DMA controller state 72 | struct SDMA_ctrl { 73 | u8 status; 74 | u8 command; 75 | u8 request; 76 | u8 mask; 77 | } controller[2]; 78 | } state; 79 | }; 80 | 81 | #define DMA_IO_BASE 0x1000 82 | #define DMA0_IO_MAIN DMA_IO_BASE + 0 83 | #define DMA1_IO_MAIN DMA_IO_BASE + 1 84 | #define DMA_IO_LPAGE DMA_IO_BASE + 2 85 | #define DMA_IO_HPAGE DMA_IO_BASE + 3 86 | #define DMA0_IO_CHANNEL DMA_IO_BASE + 4 87 | #define DMA1_IO_CHANNEL DMA_IO_BASE + 5 88 | #define DMA0_IO_EXT DMA_IO_BASE + 6 89 | #define DMA1_IO_EXT DMA_IO_BASE + 7 90 | 91 | extern CDMA *theDMA; 92 | 93 | #endif // !defined(INCLUDED_DMA_H) 94 | -------------------------------------------------------------------------------- /src/DiskRam.cpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #include "DiskRam.hpp" 30 | #include "StdAfx.hpp" 31 | 32 | CDiskRam::CDiskRam(CConfigurator *cfg, CSystem *sys, CDiskController *c, 33 | int idebus, int idedev) 34 | : CDisk(cfg, sys, c, idebus, idedev) { 35 | byte_size = myCfg->get_num_value("size", false, 512 * 1024 * 1024); 36 | 37 | CHECK_ALLOCATION(ramdisk = malloc((size_t)byte_size)); 38 | 39 | state.byte_pos = 0; 40 | 41 | sectors = 32; 42 | heads = 8; 43 | 44 | // calc_cylinders(); 45 | determine_layout(); 46 | 47 | model_number = myCfg->get_text_value("model_number", "ES40RAMDISK"); 48 | 49 | printf("%s: Mounted RAMDISK, %" PRId64 " %zd-byte blocks, %" PRId64 "/%ld/%ld.\n", 50 | devid_string, byte_size / state.block_size, state.block_size, 51 | cylinders, heads, sectors); 52 | } 53 | 54 | CDiskRam::~CDiskRam(void) { 55 | if (ramdisk) { 56 | printf("%s: RAMDISK freed.\n", devid_string); 57 | free(ramdisk); 58 | ramdisk = 0; 59 | } 60 | } 61 | 62 | bool CDiskRam::seek_byte(off_t_large byte) { 63 | if (byte >= byte_size) { 64 | FAILURE_1(InvalidArgument, "%s: Seek beyond end of file!\n", devid_string); 65 | } 66 | 67 | state.byte_pos = byte; 68 | return true; 69 | } 70 | 71 | size_t CDiskRam::read_bytes(void *dest, size_t bytes) { 72 | if (state.byte_pos >= byte_size) 73 | return 0; 74 | 75 | while (state.byte_pos + bytes >= byte_size) 76 | bytes--; 77 | 78 | memcpy(dest, &(((char *)ramdisk)[state.byte_pos]), bytes); 79 | state.byte_pos += (unsigned long)bytes; 80 | return bytes; 81 | } 82 | 83 | size_t CDiskRam::write_bytes(void *src, size_t bytes) { 84 | if (state.byte_pos >= byte_size) 85 | return 0; 86 | 87 | while (state.byte_pos + bytes >= byte_size) 88 | bytes--; 89 | 90 | memcpy(&(((char *)ramdisk)[state.byte_pos]), src, bytes); 91 | state.byte_pos += (unsigned long)bytes; 92 | return bytes; 93 | } 94 | -------------------------------------------------------------------------------- /src/SCSIBus.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(__SCSIBUS__H__) 30 | #define __SCSIBUS__H__ 31 | 32 | #include "SCSIDevice.hpp" 33 | #include "StdAfx.hpp" 34 | #include "SystemComponent.hpp" 35 | 36 | /** 37 | * \brief Emulated SCSI bus. 38 | * 39 | * connects SCSI Devices (class CSCSIDevice) together; SCSI devices are 40 | * disks and controllers. 41 | **/ 42 | class CSCSIBus : public CSystemComponent { 43 | public: 44 | CSCSIBus(CConfigurator *cfg, CSystem *c); 45 | ~CSCSIBus(void); 46 | virtual int SaveState(FILE *f); 47 | virtual int RestoreState(FILE *f); 48 | 49 | void scsi_register(CSCSIDevice *dev, int bus, int target); 50 | void scsi_unregister(CSCSIDevice *dev, int target); 51 | 52 | bool arbitrate(int initiator); 53 | bool select(int initiator, int target); 54 | void set_phase(int target, int phase); 55 | int get_phase() { return state.phase; }; 56 | 57 | /**< Get current SCSI bus phase **/ 58 | void free_bus(int initiator); 59 | 60 | CSCSIDevice *targets[16]; /**< pointers to the SCSI devices that respond to 61 | the 15 possible target id's. **/ 62 | int target_bus_no[16]; /**< indicates what bus this is for each connected SCSI 63 | device. always 0 for disks, but controllers could have 64 | multiple SCSI busses. **/ 65 | 66 | /// The state structure contains all elements that need to be saved to the 67 | /// statefile 68 | struct SSCSI_state { 69 | int initiator; /**< SCSI id of the initiator. **/ 70 | int target; /**< SCSI id of the target. **/ 71 | int phase; /**< SCSI bus phase. **/ 72 | } state; 73 | }; 74 | 75 | #define SCSI_PHASE_FREE -2 76 | #define SCSI_PHASE_ARBITRATION -1 77 | #define SCSI_PHASE_DATA_OUT 0 78 | #define SCSI_PHASE_DATA_IN 1 79 | #define SCSI_PHASE_COMMAND 2 80 | #define SCSI_PHASE_STATUS 3 81 | #define SCSI_PHASE_MSG_OUT 6 82 | #define SCSI_PHASE_MSG_IN 7 83 | #endif 84 | -------------------------------------------------------------------------------- /src/Ethernet.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon GXemul, which is Copyright (C) 2004-2007 29 | * Anders Gavare. All rights reserved. 30 | */ 31 | 32 | #if !defined(INCLUDED_ETHERNET_H) 33 | #define INCLUDED_ETHERNET_H 34 | 35 | #include "StdAfx.hpp" 36 | 37 | #define ETH_MAX_PACKET_RAW 1514 38 | #define ETH_MAX_PACKET_CRC 1518 39 | 40 | struct eth_frame { // ethernet (wire) frame 41 | u8 src[6]; // source address 42 | u8 dst[6]; // destination address 43 | u8 protocol[2]; // protocol 44 | u8 data[1500]; // data: variable 46-1500 bytes 45 | u8 crc_fill[4]; // space for max packet crc 46 | }; 47 | 48 | struct eth_packet { // ethernet packet 49 | int len; // size of packet 50 | int used; // bytes used (consumed) 51 | u8 frame[ETH_MAX_PACKET_CRC]; // ethernet frame 52 | }; 53 | 54 | /** 55 | * \brief Packet Queue for Ethernet packets. 56 | **/ 57 | class CPacketQueue { // Ethernet Packet Queue 58 | 59 | // private: 60 | public: 61 | const char *name; // queue name 62 | int max; // maximum items allowed in queue 63 | int head; // first item in queue 64 | int tail; // last item in queue 65 | int cnt; // current item count 66 | int highwater; // highwater mark (statistics) 67 | int dropped; // packets dropped because queue was full 68 | eth_packet *packets; // packet array; dynamically allocated 69 | public: 70 | inline int count() { return cnt; } 71 | 72 | // get current count 73 | inline int lost() { return dropped; } 74 | 75 | // get number of lost packets 76 | void flush(); // empties packet queue 77 | bool add_tail(const u8 *packet_data, int packet_len, bool calc_crc, 78 | bool need_crc); // adds pcap packet to queue 79 | bool get_head(eth_packet &packet); // get packet at head 80 | CPacketQueue(const char *name, int max); // constructor 81 | ~CPacketQueue(); // destructor 82 | }; 83 | #endif // !defined(INCLUDED_ETHERNET_H) 84 | -------------------------------------------------------------------------------- /src/base/Poco.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // Poco.h 34 | // 35 | // $Id: Poco.h,v 1.1 2008/05/31 15:47:26 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Core 39 | // Module: Foundation 40 | // 41 | // Basic definitions for the POCO libraries. 42 | // 43 | // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. 44 | // and Contributors. 45 | // 46 | // Permission is hereby granted, free of charge, to any person or organization 47 | // obtaining a copy of the software and accompanying documentation covered by 48 | // this license (the "Software") to use, reproduce, display, distribute, 49 | // execute, and transmit the Software, and to prepare derivative works of the 50 | // Software, and to permit third-parties to whom the Software is furnished to 51 | // do so, all subject to the following: 52 | // 53 | // The copyright notices in the Software and this entire statement, including 54 | // the above license grant, this restriction and the following disclaimer, 55 | // must be included in all copies of the Software, in whole or in part, and 56 | // all derivative works of the Software, unless such copies or derivative 57 | // works are solely in the form of machine-executable object code generated by 58 | // a source language processor. 59 | // 60 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 61 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 62 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 63 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 64 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 65 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 66 | // DEALINGS IN THE SOFTWARE. 67 | // 68 | 69 | #ifndef Foundation_Poco_INCLUDED 70 | #define Foundation_Poco_INCLUDED 71 | 72 | #include "Foundation.hpp" 73 | 74 | #endif // Foundation_Poco_INCLUDED 75 | -------------------------------------------------------------------------------- /src/base/Event.cpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // Event.cpp 34 | // 35 | // $Id: Event.cpp,v 1.1 2008/05/31 15:47:21 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Threading 39 | // Module: Event 40 | // 41 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 42 | // and Contributors. 43 | // 44 | // Permission is hereby granted, free of charge, to any person or organization 45 | // obtaining a copy of the software and accompanying documentation covered by 46 | // this license (the "Software") to use, reproduce, display, distribute, 47 | // execute, and transmit the Software, and to prepare derivative works of the 48 | // Software, and to permit third-parties to whom the Software is furnished to 49 | // do so, all subject to the following: 50 | // 51 | // The copyright notices in the Software and this entire statement, including 52 | // the above license grant, this restriction and the following disclaimer, 53 | // must be included in all copies of the Software, in whole or in part, and 54 | // all derivative works of the Software, unless such copies or derivative 55 | // works are solely in the form of machine-executable object code generated by 56 | // a source language processor. 57 | // 58 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 59 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 60 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 61 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 62 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 63 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 64 | // DEALINGS IN THE SOFTWARE. 65 | // 66 | 67 | #include "Event.hpp" 68 | 69 | #if defined(POCO_OS_FAMILY_WINDOWS) 70 | #include "Event_WIN32.cpp" 71 | #else 72 | #include "Event_POSIX.cpp" 73 | #endif 74 | 75 | CEvent::CEvent(bool autoReset) : CEventImpl(autoReset) {} 76 | 77 | CEvent::~CEvent() {} 78 | -------------------------------------------------------------------------------- /src/base/RWLock_POSIX.cpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // RWLock_POSIX.cpp 34 | // 35 | // $Id: RWLock_POSIX.cpp,v 1.1 2008/05/31 15:47:26 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Threading 39 | // Module: RWLock 40 | // 41 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 42 | // and Contributors. 43 | // 44 | // Permission is hereby granted, free of charge, to any person or organization 45 | // obtaining a copy of the software and accompanying documentation covered by 46 | // this license (the "Software") to use, reproduce, display, distribute, 47 | // execute, and transmit the Software, and to prepare derivative works of the 48 | // Software, and to permit third-parties to whom the Software is furnished to 49 | // do so, all subject to the following: 50 | // 51 | // The copyright notices in the Software and this entire statement, including 52 | // the above license grant, this restriction and the following disclaimer, 53 | // must be included in all copies of the Software, in whole or in part, and 54 | // all derivative works of the Software, unless such copies or derivative 55 | // works are solely in the form of machine-executable object code generated by 56 | // a source language processor. 57 | // 58 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 59 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 60 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 61 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 62 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 63 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 64 | // DEALINGS IN THE SOFTWARE. 65 | // 66 | 67 | #include "RWLock_POSIX.hpp" 68 | 69 | CRWLockImpl::CRWLockImpl() { 70 | if (pthread_rwlock_init(&_rwl, NULL)) 71 | throw CSystemException("cannot create reader/writer lock"); 72 | } 73 | 74 | CRWLockImpl::~CRWLockImpl() { pthread_rwlock_destroy(&_rwl); } 75 | -------------------------------------------------------------------------------- /src/Serial.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(INCLUDED_SERIAL_H) 30 | #define INCLUDED_SERIAL_H 31 | 32 | #include "SystemComponent.hpp" 33 | #include "telnet.hpp" 34 | 35 | /** 36 | * \brief Emulated serial port. 37 | * 38 | * The serial port is translated to a telnet port. 39 | **/ 40 | class CSerial : public CSystemComponent { 41 | public: 42 | void write(const char *s); 43 | virtual void WriteMem(int index, u64 address, int dsize, u64 data); 44 | virtual u64 ReadMem(int index, u64 address, int dsize); 45 | CSerial(CConfigurator *cfg, CSystem *c, u16 number); 46 | virtual ~CSerial(); 47 | void receive(const char *data); 48 | virtual void check_state(); 49 | virtual int SaveState(FILE *f); 50 | virtual int RestoreState(FILE *f); 51 | void eval_interrupts(); 52 | void WaitForConnection(); 53 | void run(); 54 | void execute(); 55 | 56 | virtual void init(); 57 | virtual void start_threads(); 58 | virtual void stop_threads(); 59 | 60 | private: 61 | void serial_menu(); 62 | std::unique_ptr myThread; 63 | std::atomic_bool myThreadDead{false}; 64 | bool StopThread = false; 65 | bool acceptingSocket = false; 66 | bool breakHit; 67 | 68 | /// The state structure contains all elements that need to be saved to the 69 | /// statefile. 70 | struct SSrl_state { 71 | u8 bTHR; /**< Transmit Hold Register */ 72 | u8 bRDR; /**< Received Data Register */ 73 | u8 bBRB_LSB; 74 | u8 bBRB_MSB; 75 | u8 bIER; /**< Interrupt Enable Register */ 76 | u8 bIIR; /**< Interrupt Identification Register */ 77 | u8 bFCR; 78 | u8 bLCR; /**< Line Control Register (Data Format Register) */ 79 | u8 bMCR; /**< Modem Control Register */ 80 | u8 bLSR; /**< Line Status Register */ 81 | u8 bMSR; /**< Modem Status Register */ 82 | u8 bSPR; /**< Scratch Pad Register */ 83 | int serial_cycles; 84 | char rcvBuffer[1024]; 85 | int rcvW; 86 | int rcvR; 87 | int iNumber; 88 | bool irq_active; 89 | } state; 90 | int listenPort; 91 | const char *listenAddress; 92 | int listenSocket; 93 | int connectSocket; 94 | #if defined(IDB) && defined(LS_MASTER) 95 | int throughSocket; 96 | #endif 97 | }; 98 | #endif // !defined(INCLUDED_SERIAL_H) 99 | -------------------------------------------------------------------------------- /src/base/Semaphore.cpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // Semaphore.cpp 34 | // 35 | // $Id: Semaphore.cpp,v 1.1 2008/05/31 15:47:28 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Threading 39 | // Module: Semaphore 40 | // 41 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 42 | // and Contributors. 43 | // 44 | // Permission is hereby granted, free of charge, to any person or organization 45 | // obtaining a copy of the software and accompanying documentation covered by 46 | // this license (the "Software") to use, reproduce, display, distribute, 47 | // execute, and transmit the Software, and to prepare derivative works of the 48 | // Software, and to permit third-parties to whom the Software is furnished to 49 | // do so, all subject to the following: 50 | // 51 | // The copyright notices in the Software and this entire statement, including 52 | // the above license grant, this restriction and the following disclaimer, 53 | // must be included in all copies of the Software, in whole or in part, and 54 | // all derivative works of the Software, unless such copies or derivative 55 | // works are solely in the form of machine-executable object code generated by 56 | // a source language processor. 57 | // 58 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 59 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 60 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 61 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 62 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 63 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 64 | // DEALINGS IN THE SOFTWARE. 65 | // 66 | 67 | #include "Semaphore.hpp" 68 | 69 | #if defined(POCO_OS_FAMILY_WINDOWS) 70 | #include "Semaphore_WIN32.cpp" 71 | #else 72 | #include "Semaphore_POSIX.cpp" 73 | #endif 74 | 75 | CSemaphore::CSemaphore(int n) : CSemaphoreImpl(n, n) {} 76 | 77 | CSemaphore::CSemaphore(int n, int max) : CSemaphoreImpl(n, max) {} 78 | 79 | CSemaphore::~CSemaphore() {} 80 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AXPbox Alpha emulator 2 | 3 | AXPbox is a fork of the discontinued es40 emulator. It could theoretically used for running any operating system that runs on the OpenVMS or Tru64 PALcode (e.g. OpenVMS, Tru64 UNIX, Linux, NetBSD), however as of now only OpenVMS and some versions of NetBSD can be installed (for more details see [Guest support](https://github.com/lenticularis39/axpbox/wiki/Guest-support)). 4 | 5 | The emulator supports SCSI, IDE, serial ports, Ethernet (using PCAP) and [VGA graphics](https://github.com/lenticularis39/axpbox/wiki/VGA) (using SDL). 6 | 7 | ![OpenVMS 8.4 desktop](https://i.ibb.co/zQh35hm/Sn-mek-z-2021-01-24-14-18-41.png) 8 | 9 | OpenVMS 8.4 desktop in AXPbox. [Here is a wiki page showing you how to get this CDE desktop running](https://github.com/lenticularis39/axpbox/wiki/GUI-Desktop-Environment-(CDE)) 10 | 11 | ## Getting AXPbox 12 | 13 | Pre-built binaries for generic Linux amd64, Windows 10 amd64 and macOS amd64 are available for each release, and also as artifacts produced for each commit in CI. T2 SDE has an [official package](http://t2sde.org/packages/axpbox) for AXPbox, and openSUSE's Emulators project has an [AXPbox package](https://build.opensuse.org/package/show/Emulators/axpbox), too. The former gets updated the same day when a release happens, while requests are submitted now the latter that undergo approval of Emulators maintainers. 14 | 15 | You can also build from source using CMake; you need a C++ 11 compiler, optional dependencies are PCAP for networking and SDL or X11 for graphics support. 16 | 17 | ## Usage 18 | 19 | First invoke the interactive configuration file generator: 20 | ``` 21 | axpbox configure 22 | ``` 23 | This creates a file named es40.cfg, which you can now modify (the generator UI doesn't allow to set all options). After the configuration file and the required ROM image are ready, you can start the emulation: 24 | ``` 25 | axpbox run 26 | ``` 27 | 28 | Please read the [Installation Guide](https://github.com/lenticularis39/axpbox/wiki/OpenVMS-installation-guide) for information to get OpenVMS installed in the emulator. A guide for NetBSD is [also available on the Wiki](https://github.com/lenticularis39/axpbox/wiki/NetBSD-9.2-install-guide) 29 | 30 | ## Changes in comparison with es40 31 | 32 | - Renamed from es40 to AXPbox to avoid confusion with the physical machine (AlphaServer ES40) 33 | - CMake is used for compilation instead of autotools 34 | - OpenVMS host support was dropped 35 | - es40 and es40_cfg were merged into one executable (axpbox) 36 | - The code was cleaned to compile without warnings on most compilers 37 | - Code modernizing, replacing POCO framework parts by native C++11 counterparts not available in 2008 (std::threads, etc) 38 | - Incorporate various patches from other es40 forks, for example, added MC146818 periodic interrupt to allow netbsd to boot and install, skip_memtest for faster booting. 39 | - Bug fixes, less segfaults, overall less crashes. 40 | - [More](https://github.com/lenticularis39/axpbox/wiki/) documentation and usage information on the various features and operating systems 41 | 42 | ## What doesn't work (also see issues) 43 | 44 | - Some guest operating systems (see [Guest support](https://github.com/lenticularis39/axpbox/wiki/Guest-support)) 45 | - ARC 46 | - VGA in OpenVMS 47 | - SDL keyboard (partly works, but easily breaks) 48 | - Multiple CPU system emulation 49 | - Running on big endian platforms 50 | - Some SCSI and IDE commands 51 | - Copying large files between IDE CD-ROM to IDE hard drive (this usually doesn't affect OpenVMS installation) 52 | -------------------------------------------------------------------------------- /src/base/RWLock.cpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // RWLock.cpp 34 | // 35 | // $Id: RWLock.cpp,v 1.3 2008/06/12 06:58:24 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Threading 39 | // Module: RWLock 40 | // 41 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 42 | // and Contributors. 43 | // 44 | // Permission is hereby granted, free of charge, to any person or organization 45 | // obtaining a copy of the software and accompanying documentation covered by 46 | // this license (the "Software") to use, reproduce, display, distribute, 47 | // execute, and transmit the Software, and to prepare derivative works of the 48 | // Software, and to permit third-parties to whom the Software is furnished to 49 | // do so, all subject to the following: 50 | // 51 | // The copyright notices in the Software and this entire statement, including 52 | // the above license grant, this restriction and the following disclaimer, 53 | // must be included in all copies of the Software, in whole or in part, and 54 | // all derivative works of the Software, unless such copies or derivative 55 | // works are solely in the form of machine-executable object code generated by 56 | // a source language processor. 57 | // 58 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 59 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 60 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 61 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 62 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 63 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 64 | // DEALINGS IN THE SOFTWARE. 65 | // 66 | 67 | #include "RWLock.hpp" 68 | #include 69 | 70 | #if defined(POCO_OS_FAMILY_WINDOWS) 71 | #include "RWLock_WIN32.cpp" 72 | #else 73 | #include "RWLock_POSIX.cpp" 74 | #endif 75 | 76 | CRWLock::CRWLock() { lockName = strdup("anon"); } 77 | 78 | CRWLock::CRWLock(const char *lName) { lockName = strdup(lName); } 79 | 80 | CRWLock::~CRWLock() { free(lockName); } 81 | -------------------------------------------------------------------------------- /src/Configurator.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(__CONFIGURATOR_H__) 30 | #define __CONFIGURATOR_H__ 31 | 32 | #define CFG_MAX_CHILDREN 25 33 | #define CFG_MAX_VALUES 50 34 | 35 | #include "StdAfx.hpp" 36 | 37 | typedef enum { 38 | c_none, 39 | 40 | // chipsets 41 | c_tsunami, 42 | 43 | // system devices 44 | c_ev68cb, 45 | c_serial, 46 | c_floppy, 47 | 48 | // pci devices 49 | c_ali, 50 | c_ali_ide, 51 | c_ali_usb, 52 | c_s3, 53 | c_cirrus, 54 | c_radeon, 55 | c_dec21143, 56 | c_sym53c895, 57 | c_sym53c810, 58 | 59 | // disk devices 60 | c_file, 61 | c_device, 62 | c_ramdisk, 63 | 64 | // gui's 65 | c_sdl, 66 | c_win32, 67 | c_x11 68 | } classid; 69 | 70 | class CConfigurator { 71 | public: 72 | CConfigurator(class CConfigurator *parent, char *name, char *value, 73 | char *text, size_t textlen); 74 | ~CConfigurator(void); 75 | 76 | char *strip_string(char *c); 77 | void add_value(char *n, char *v); 78 | 79 | char *get_text_value(const char *n) { return get_text_value(n, (char *)0); }; 80 | char *get_text_value(const char *n, const char *def); 81 | 82 | bool get_bool_value(const char *n) { return get_bool_value(n, false); }; 83 | bool get_bool_value(const char *n, bool def); 84 | 85 | u64 get_num_value(const char *n, bool decimal_suffixes) { 86 | return get_num_value(n, decimal_suffixes, 0); 87 | }; 88 | u64 get_num_value(const char *n, bool decimal_suffixes, u64 def); 89 | 90 | classid get_class_id() { return myClassId; }; 91 | void *get_device() { return myDevice; }; 92 | int get_flags() { return myFlags; }; 93 | 94 | char *get_myName() { return myName; }; 95 | char *get_myValue() { return myValue; }; 96 | CConfigurator *get_myParent() { return pParent; }; 97 | 98 | void initialize(); 99 | 100 | private: 101 | class CConfigurator *pParent; 102 | class CConfigurator *pChildren[CFG_MAX_CHILDREN]; 103 | int iNumChildren; 104 | char *myName; 105 | char *myValue; 106 | void *myDevice; 107 | classid myClassId; 108 | int myFlags; 109 | int iNumValues; 110 | struct SCfg_Value { 111 | char *name; 112 | char *value; 113 | } pValues[CFG_MAX_VALUES]; 114 | }; 115 | #endif //! defined(__CONFIGURATOR_H__) 116 | -------------------------------------------------------------------------------- /src/cpu_memory.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #define DO_LDA state.r[REG_1] = state.r[REG_2] + DISP_16; 30 | 31 | #define DO_LDAH state.r[REG_1] = state.r[REG_2] + (DISP_16 << 16); 32 | 33 | #define DO_LDBU READ_VIRT(state.r[REG_2] + DISP_16, 8, state.r[REG_1]); 34 | 35 | #define DO_LDL \ 36 | READ_VIRT_F(state.r[REG_2] + DISP_16, 32, state.r[REG_1], sext_u64_32); 37 | 38 | #define DO_LDL_L \ 39 | READ_VIRT_LOCK_F(state.r[REG_2] + DISP_16, 32, state.r[REG_1], sext_u64_32); 40 | 41 | #define DO_LDQ READ_VIRT(state.r[REG_2] + DISP_16, 64, state.r[REG_1]); 42 | 43 | #define DO_LDQ_L READ_VIRT_LOCK(state.r[REG_2] + DISP_16, 64, state.r[REG_1]); 44 | 45 | #define DO_LDQ_U \ 46 | READ_VIRT((state.r[REG_2] + DISP_16) & ~U64(0x7), 64, state.r[REG_1]); 47 | 48 | #define DO_LDWU READ_VIRT(state.r[REG_2] + DISP_16, 16, state.r[REG_1]); 49 | 50 | #define DO_STB WRITE_VIRT(state.r[REG_2] + DISP_16, 8, state.r[REG_1]); 51 | 52 | #define DO_STL WRITE_VIRT(state.r[REG_2] + DISP_16, 32, state.r[REG_1]); 53 | 54 | #define DO_STL_C \ 55 | if (cSystem->cpu_unlock(state.iProcNum)) { \ 56 | WRITE_VIRT(state.r[REG_2] + DISP_16, 32, state.r[REG_1]); \ 57 | state.r[REG_1] = 1; \ 58 | } else \ 59 | state.r[REG_1] = 0; 60 | 61 | #define DO_STQ WRITE_VIRT(state.r[REG_2] + DISP_16, 64, state.r[REG_1]); 62 | 63 | #define DO_STQ_C \ 64 | if (cSystem->cpu_unlock(state.iProcNum)) { \ 65 | WRITE_VIRT(state.r[REG_2] + DISP_16, 64, state.r[REG_1]); \ 66 | state.r[REG_1] = 1; \ 67 | } else \ 68 | state.r[REG_1] = 0; 69 | 70 | #define DO_STQ_U \ 71 | WRITE_VIRT((state.r[REG_2] + DISP_16) & ~U64(0x07), 64, state.r[REG_1]); 72 | 73 | #define DO_STW WRITE_VIRT(state.r[REG_2] + DISP_16, 16, state.r[REG_1]); 74 | -------------------------------------------------------------------------------- /src/base/RefCountedObject.cpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // RefCountedObject.cpp 34 | // 35 | // $Id: RefCountedObject.cpp,v 1.1 2008/05/31 15:47:27 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Core 39 | // Module: RefCountedObject 40 | // 41 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 42 | // and Contributors. 43 | // 44 | // Permission is hereby granted, free of charge, to any person or organization 45 | // obtaining a copy of the software and accompanying documentation covered by 46 | // this license (the "Software") to use, reproduce, display, distribute, 47 | // execute, and transmit the Software, and to prepare derivative works of the 48 | // Software, and to permit third-parties to whom the Software is furnished to 49 | // do so, all subject to the following: 50 | // 51 | // The copyright notices in the Software and this entire statement, including 52 | // the above license grant, this restriction and the following disclaimer, 53 | // must be included in all copies of the Software, in whole or in part, and 54 | // all derivative works of the Software, unless such copies or derivative 55 | // works are solely in the form of machine-executable object code generated by 56 | // a source language processor. 57 | // 58 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 59 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 60 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 61 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 62 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 63 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 64 | // DEALINGS IN THE SOFTWARE. 65 | // 66 | 67 | #include "RefCountedObject.hpp" 68 | #include "Mutex.hpp" 69 | 70 | CRefCountedObject::CRefCountedObject() : _rc(1), _rcMutex("rc") {} 71 | 72 | CRefCountedObject::~CRefCountedObject() {} 73 | 74 | void CRefCountedObject::duplicate() const { 75 | _rcMutex.lock(); 76 | ++_rc; 77 | _rcMutex.unlock(); 78 | } 79 | 80 | void CRefCountedObject::release() const { 81 | _rcMutex.lock(); 82 | int rc = --_rc; 83 | _rcMutex.unlock(); 84 | if (rc == 0) 85 | delete this; 86 | } 87 | -------------------------------------------------------------------------------- /src/NumberQuestion.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | /** 30 | * Convert an integer to a string. 31 | **/ 32 | inline string i2s(int x) { 33 | ostringstream o; 34 | o << x; 35 | return o.str(); 36 | } 37 | 38 | /** 39 | * Convert a string to an integer. 40 | * 41 | * Throws a CLogicException when the input is not numeric. 42 | **/ 43 | inline int s2i(const string x) { 44 | istringstream i(x); 45 | int x1; 46 | char c; 47 | if (!(i >> x1) || i.get(c)) 48 | FAILURE(Logic, "invalid conversion"); 49 | ; 50 | return x1; 51 | } 52 | 53 | /** 54 | * Question class that accepts a numeric answer within 55 | * a defined range. 56 | **/ 57 | class NumberQuestion : public FreeTextQuestion { 58 | public: 59 | /** 60 | * Define the allowable range for the answer. 61 | **/ 62 | void setRange(int low, int high) { 63 | mLow = low; 64 | mHigh = high; 65 | } 66 | 67 | /** 68 | * Convert the answer to a number. 69 | **/ 70 | int getNum() { return s2i(mAnswer); } 71 | 72 | /** 73 | * Ask the question and return the answer. 74 | **/ 75 | virtual string ask() { 76 | /* Set the options list to (low-high). 77 | */ 78 | setOptions(i2s(mLow) + "-" + i2s(mHigh)); 79 | 80 | /* Keep repeating the question until a valid 81 | * answer is received. 82 | */ 83 | for (;;) { 84 | int value; 85 | 86 | /* Ask the question as a FreeTextQuestion. This 87 | * takes care of the explanation and default 88 | * value handling. 89 | */ 90 | FreeTextQuestion::ask(); 91 | 92 | try { 93 | /* Convert the answer to an integer. 94 | */ 95 | value = s2i(mAnswer); 96 | 97 | /* If the answer is within the allowed range, 98 | * return it. 99 | */ 100 | if (value >= mLow && value <= mHigh) 101 | return mAnswer; 102 | 103 | /* The answer is out of range. 104 | */ 105 | cout << "\nPlease enter a value that is within the indicated range, or " 106 | "'?' for help.\n\n"; 107 | } catch (CLogicException) { 108 | /* The answer is not a number. 109 | */ 110 | cout << "\nPlease enter an integer value.\n\n"; 111 | } 112 | } 113 | } 114 | 115 | protected: 116 | /** Low limit of the allowed range. */ 117 | int mLow; 118 | /** High limit of the allowed range. */ 119 | int mHigh; 120 | }; 121 | -------------------------------------------------------------------------------- /src/base/Platform_POSIX.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // Platform_POSIX.h 34 | // 35 | // $Id: Platform_POSIX.h,v 1.1 2008/05/31 15:47:25 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Core 39 | // Module: Platform 40 | // 41 | // Platform and architecture identification macros 42 | // and platform-specific definitions for various POSIX platforms 43 | // 44 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 45 | // and Contributors. 46 | // 47 | // Permission is hereby granted, free of charge, to any person or organization 48 | // obtaining a copy of the software and accompanying documentation covered by 49 | // this license (the "Software") to use, reproduce, display, distribute, 50 | // execute, and transmit the Software, and to prepare derivative works of the 51 | // Software, and to permit third-parties to whom the Software is furnished to 52 | // do so, all subject to the following: 53 | // 54 | // The copyright notices in the Software and this entire statement, including 55 | // the above license grant, this restriction and the following disclaimer, 56 | // must be included in all copies of the Software, in whole or in part, and 57 | // all derivative works of the Software, unless such copies or derivative 58 | // works are solely in the form of machine-executable object code generated by 59 | // a source language processor. 60 | // 61 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 62 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 63 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 64 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 65 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 66 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 67 | // DEALINGS IN THE SOFTWARE. 68 | // 69 | 70 | #ifndef Foundation_Platform_POSIX_INCLUDED 71 | #define Foundation_Platform_POSIX_INCLUDED 72 | 73 | // 74 | // PA-RISC based HP-UX platforms have some issues... 75 | // 76 | #if defined(hpux) || defined(_hpux) 77 | #if defined(__hppa) || defined(__hppa__) 78 | #define POCO_NO_SYS_SELECT_H 1 79 | #if defined(__HP_aCC) 80 | #define POCO_NO_TEMPLATE_ICOMPARE 1 81 | #endif 82 | #endif 83 | #endif 84 | 85 | #endif // Foundation_Platform_POSIX_INCLUDED 86 | -------------------------------------------------------------------------------- /src/PCIDevice.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(__PCIDEVICE_H__) 30 | #define __PCIDEVICE_H__ 31 | 32 | #define MAX_DEV_RANGES 50 33 | 34 | #define PCI_RANGE_BASE 0x0800 35 | 36 | #include "SystemComponent.hpp" 37 | 38 | /** 39 | * \brief Abstract base class for devices on the PCI-bus. 40 | **/ 41 | class CPCIDevice : public CSystemComponent { 42 | public: 43 | CPCIDevice(class CConfigurator *cfg, class CSystem *c, int pcibus, 44 | int pcidev); 45 | ~CPCIDevice(void); 46 | virtual int SaveState(FILE *f); 47 | virtual int RestoreState(FILE *f); 48 | virtual void ResetPCI(); 49 | virtual u64 ReadMem(int index, u64 address, int dsize); 50 | virtual void WriteMem(int index, u64 address, int dsize, u64 data); 51 | 52 | virtual u32 ReadMem_Legacy(int index, u32 address, int dsize); 53 | virtual void WriteMem_Legacy(int index, u32 address, int dsize, u32 data); 54 | 55 | virtual u32 ReadMem_Bar(int func, int bar, u32 address, int dsize); 56 | virtual void WriteMem_Bar(int func, int bar, u32 address, int dsize, 57 | u32 data); 58 | 59 | u32 config_read(int func, u32 address, int dsize); 60 | void config_write(int func, u32 address, int dsize, u32 data); 61 | 62 | virtual u32 config_read_custom(int func, u32 address, int dsize, u32 data) { 63 | return data; 64 | }; 65 | virtual void config_write_custom(int func, u32 address, int dsize, 66 | u32 old_data, u32 new_data, u32 data){}; 67 | void register_bar(int func, int bar, u32 data, u32 mask); 68 | 69 | void do_pci_read(u32 address, void *dest, size_t element_size, 70 | size_t element_count); 71 | void do_pci_write(u32 address, void *source, size_t element_size, 72 | size_t element_count); 73 | 74 | protected: 75 | bool do_pci_interrupt(int func, bool asserted); 76 | void add_function(int func, u32 data[64], u32 mask[64]); 77 | void add_legacy_io(int id, u32 base, u32 length); 78 | void add_legacy_mem(int id, u32 base, u32 length); 79 | 80 | int myPCIBus; 81 | int myPCIDev; 82 | 83 | u32 std_config_data[8][64]; 84 | u32 std_config_mask[8][64]; 85 | bool device_at[8]; 86 | 87 | bool dev_range_is_io[MAX_DEV_RANGES]; 88 | bool pci_range_is_io[8][8]; 89 | 90 | /// The PCI state structure contains all elements that need to be saved to the 91 | /// statefile. 92 | struct SPCI_state { 93 | u32 config_data[8][64]; 94 | u32 config_mask[8][64]; 95 | } pci_state; 96 | }; 97 | #endif //! defined(__PCIDEVICE_H__) 98 | -------------------------------------------------------------------------------- /src/cpu_control.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #define DO_BEQ \ 30 | if (!state.r[REG_1]) \ 31 | add_pc(DISP_21 * 4); 32 | 33 | #define DO_BGE \ 34 | if ((s64)state.r[REG_1] >= 0) \ 35 | add_pc(DISP_21 * 4); 36 | 37 | #define DO_BGT \ 38 | if ((s64)state.r[REG_1] > 0) \ 39 | add_pc(DISP_21 * 4); 40 | 41 | #define DO_BLBC \ 42 | if (!(state.r[REG_1] & 1)) \ 43 | add_pc(DISP_21 * 4); 44 | 45 | #define DO_BLBS \ 46 | if (state.r[REG_1] & 1) \ 47 | add_pc(DISP_21 * 4); 48 | 49 | #define DO_BLE \ 50 | if ((s64)state.r[REG_1] <= 0) \ 51 | add_pc(DISP_21 * 4); 52 | 53 | #define DO_BLT \ 54 | if ((s64)state.r[REG_1] < 0) \ 55 | add_pc(DISP_21 * 4); 56 | 57 | #define DO_BNE \ 58 | if (state.r[REG_1]) \ 59 | add_pc(DISP_21 * 4); 60 | 61 | #define DO_BR \ 62 | { \ 63 | state.r[REG_1] = state.pc & ~U64(0x3); \ 64 | add_pc(DISP_21 * 4); \ 65 | } 66 | 67 | #define DO_BSR DO_BR 68 | 69 | #define DO_JMP \ 70 | { \ 71 | temp_64 = state.r[REG_2] & ~U64(0x3); \ 72 | state.r[REG_1] = state.pc & ~U64(0x3); \ 73 | set_pc(temp_64 | (state.pc & 3)); \ 74 | } 75 | 76 | // JSR, RET and JSR_COROUTINE is really JMP, just with different prediction 77 | // bits. 78 | -------------------------------------------------------------------------------- /src/cpu_logical.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #define DO_AND state.r[REG_3] = state.r[REG_1] & V_2; 30 | #define DO_BIC state.r[REG_3] = state.r[REG_1] & ~V_2; 31 | #define DO_BIS state.r[REG_3] = state.r[REG_1] | V_2; 32 | #define DO_EQV state.r[REG_3] = state.r[REG_1] ^ ~V_2; 33 | #define DO_ORNOT state.r[REG_3] = state.r[REG_1] | ~V_2; 34 | #define DO_XOR state.r[REG_3] = state.r[REG_1] ^ V_2; 35 | 36 | #define DO_CMOVEQ \ 37 | if (!state.r[REG_1]) \ 38 | state.r[REG_3] = V_2; 39 | #define DO_CMOVGE \ 40 | if ((s64)state.r[REG_1] >= 0) \ 41 | state.r[REG_3] = V_2; 42 | #define DO_CMOVGT \ 43 | if ((s64)state.r[REG_1] > 0) \ 44 | state.r[REG_3] = V_2; 45 | #define DO_CMOVLBC \ 46 | if (!(state.r[REG_1] & U64(0x1))) \ 47 | state.r[REG_3] = V_2; 48 | #define DO_CMOVLBS \ 49 | if (state.r[REG_1] & U64(0x1)) \ 50 | state.r[REG_3] = V_2; 51 | #define DO_CMOVLE \ 52 | if ((s64)state.r[REG_1] <= 0) \ 53 | state.r[REG_3] = V_2; 54 | #define DO_CMOVLT \ 55 | if ((s64)state.r[REG_1] < 0) \ 56 | state.r[REG_3] = V_2; 57 | #define DO_CMOVNE \ 58 | if (state.r[REG_1]) \ 59 | state.r[REG_3] = V_2; 60 | 61 | #define DO_SLL state.r[REG_3] = state.r[REG_1] << (V_2 & 63); 62 | #define DO_SRA \ 63 | state.r[REG_3] = \ 64 | (V_2 & 63) \ 65 | ? ((state.r[REG_1] >> (V_2 & 63)) | \ 66 | ((state.r[REG_1] >> 63) ? (X64_QUAD << (64 - (V_2 & 63))) : 0)) \ 67 | : state.r[REG_1]; 68 | #define DO_SRL state.r[REG_3] = state.r[REG_1] >> (V_2 & 63); 69 | -------------------------------------------------------------------------------- /src/Port80.cpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #include "Port80.hpp" 30 | #include "StdAfx.hpp" 31 | #include "System.hpp" 32 | 33 | /** 34 | * Constructor. 35 | **/ 36 | CPort80::CPort80(CConfigurator *cfg, CSystem *c) : CSystemComponent(cfg, c) { 37 | c->RegisterMemory(this, 0, U64(0x00000801fc000080), 1); 38 | state.p80 = 0; 39 | } 40 | 41 | /** 42 | * Destructor. 43 | **/ 44 | CPort80::~CPort80() {} 45 | 46 | /** 47 | * Read from port 80. 48 | * Returns the value last written to port 80. 49 | **/ 50 | u64 CPort80::ReadMem(int index, u64 address, int dsize) { return state.p80; } 51 | 52 | /** 53 | * Write to port 80. 54 | **/ 55 | void CPort80::WriteMem(int index, u64 address, int dsize, u64 data) { 56 | state.p80 = (u8)data; 57 | } 58 | 59 | static u32 p80_magic1 = 0x80FFAA80; 60 | static u32 p80_magic2 = 0xAA8080FF; 61 | 62 | /** 63 | * Save state to a Virtual Machine State file. 64 | **/ 65 | int CPort80::SaveState(FILE *f) { 66 | long ss = sizeof(state); 67 | 68 | fwrite(&p80_magic1, sizeof(u32), 1, f); 69 | fwrite(&ss, sizeof(long), 1, f); 70 | fwrite(&state, sizeof(state), 1, f); 71 | fwrite(&p80_magic2, sizeof(u32), 1, f); 72 | printf("%s: %ld bytes saved.\n", devid_string, ss); 73 | return 0; 74 | } 75 | 76 | /** 77 | * Restore state from a Virtual Machine State file. 78 | **/ 79 | int CPort80::RestoreState(FILE *f) { 80 | long ss; 81 | u32 m1; 82 | u32 m2; 83 | size_t r; 84 | 85 | r = fread(&m1, sizeof(u32), 1, f); 86 | if (r != 1) { 87 | printf("%s: unexpected end of file!\n", devid_string); 88 | return -1; 89 | } 90 | 91 | if (m1 != p80_magic1) { 92 | printf("%s: MAGIC 1 does not match!\n", devid_string); 93 | return -1; 94 | } 95 | 96 | r = fread(&ss, sizeof(long), 1, f); 97 | if (r != 1) { 98 | printf("%s: unexpected end of file!\n", devid_string); 99 | return -1; 100 | } 101 | 102 | if (ss != sizeof(state)) { 103 | printf("%s: STRUCT SIZE does not match!\n", devid_string); 104 | return -1; 105 | } 106 | 107 | r = fread(&state, sizeof(state), 1, f); 108 | if (r != 1) { 109 | printf("%s: unexpected end of file!\n", devid_string); 110 | return -1; 111 | } 112 | 113 | r = fread(&m2, sizeof(u32), 1, f); 114 | if (r != 1) { 115 | printf("%s: unexpected end of file!\n", devid_string); 116 | return -1; 117 | } 118 | 119 | if (m2 != p80_magic2) { 120 | printf("%s: MAGIC 1 does not match!\n", devid_string); 121 | return -1; 122 | } 123 | 124 | printf("%s: %ld bytes restored.\n", devid_string, ss); 125 | return 0; 126 | } 127 | -------------------------------------------------------------------------------- /src/base/RWLock_WIN32.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // RWLock_WIN32.h 34 | // 35 | // $Id: RWLock_WIN32.h,v 1.1 2008/05/31 15:47:27 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Threading 39 | // Module: RWLock 40 | // 41 | // Definition of the RWLockImpl class for WIN32. 42 | // 43 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 44 | // and Contributors. 45 | // 46 | // Permission is hereby granted, free of charge, to any person or organization 47 | // obtaining a copy of the software and accompanying documentation covered by 48 | // this license (the "Software") to use, reproduce, display, distribute, 49 | // execute, and transmit the Software, and to prepare derivative works of the 50 | // Software, and to permit third-parties to whom the Software is furnished to 51 | // do so, all subject to the following: 52 | // 53 | // The copyright notices in the Software and this entire statement, including 54 | // the above license grant, this restriction and the following disclaimer, 55 | // must be included in all copies of the Software, in whole or in part, and 56 | // all derivative works of the Software, unless such copies or derivative 57 | // works are solely in the form of machine-executable object code generated by 58 | // a source language processor. 59 | // 60 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 61 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 62 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 63 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 64 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 65 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 66 | // DEALINGS IN THE SOFTWARE. 67 | // 68 | 69 | #ifndef Foundation_RWLock_WIN32_INCLUDED 70 | #define Foundation_RWLock_WIN32_INCLUDED 71 | 72 | #include "Exception.hpp" 73 | #include "Foundation.hpp" 74 | #include "UnWindows.hpp" 75 | 76 | class CRWLockImpl { 77 | protected: 78 | CRWLockImpl(); 79 | ~CRWLockImpl(); 80 | void readLockImpl(); 81 | bool tryReadLockImpl(); 82 | void writeLockImpl(); 83 | bool tryWriteLockImpl(); 84 | void unlockImpl(); 85 | 86 | private: 87 | void addWriter(); 88 | void removeWriter(); 89 | 90 | HANDLE _mutex; 91 | HANDLE _readEvent; 92 | HANDLE _writeEvent; 93 | unsigned _readers; 94 | unsigned _writers; 95 | }; 96 | 97 | #endif // Foundation_RWLock_WIN32_INCLUDED 98 | -------------------------------------------------------------------------------- /src/base/Semaphore_WIN32.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // Semaphore_WIN32.h 34 | // 35 | // $Id: Semaphore_WIN32.h,v 1.1 2008/05/31 15:47:28 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Threading 39 | // Module: Semaphore 40 | // 41 | // Definition of the SemaphoreImpl class for WIN32. 42 | // 43 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 44 | // and Contributors. 45 | // 46 | // Permission is hereby granted, free of charge, to any person or organization 47 | // obtaining a copy of the software and accompanying documentation covered by 48 | // this license (the "Software") to use, reproduce, display, distribute, 49 | // execute, and transmit the Software, and to prepare derivative works of the 50 | // Software, and to permit third-parties to whom the Software is furnished to 51 | // do so, all subject to the following: 52 | // 53 | // The copyright notices in the Software and this entire statement, including 54 | // the above license grant, this restriction and the following disclaimer, 55 | // must be included in all copies of the Software, in whole or in part, and 56 | // all derivative works of the Software, unless such copies or derivative 57 | // works are solely in the form of machine-executable object code generated by 58 | // a source language processor. 59 | // 60 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 61 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 62 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 63 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 64 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 65 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 66 | // DEALINGS IN THE SOFTWARE. 67 | // 68 | 69 | #ifndef Foundation_Semaphore_WIN32_INCLUDED 70 | #define Foundation_Semaphore_WIN32_INCLUDED 71 | 72 | #include "Exception.hpp" 73 | #include "Foundation.hpp" 74 | #include "UnWindows.hpp" 75 | 76 | class CSemaphoreImpl { 77 | protected: 78 | CSemaphoreImpl(int n, int max); 79 | ~CSemaphoreImpl(); 80 | void setImpl(); 81 | void waitImpl(); 82 | bool waitImpl(long milliseconds); 83 | 84 | private: 85 | HANDLE _sema; 86 | }; 87 | 88 | // 89 | // inlines 90 | // 91 | inline void CSemaphoreImpl::setImpl() { 92 | if (!ReleaseSemaphore(_sema, 1, NULL)) { 93 | throw CSystemException("cannot signal semaphore"); 94 | } 95 | } 96 | 97 | #endif // Foundation_Semaphore_WIN32_INCLUDED 98 | -------------------------------------------------------------------------------- /src/base/ScopedLock.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // ScopedLock.h 34 | // 35 | // $Id: ScopedLock.h,v 1.1 2008/05/31 15:47:27 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Threading 39 | // Module: Mutex 40 | // 41 | // Definition of the ScopedLock template class. 42 | // 43 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 44 | // and Contributors. 45 | // 46 | // Permission is hereby granted, free of charge, to any person or organization 47 | // obtaining a copy of the software and accompanying documentation covered by 48 | // this license (the "Software") to use, reproduce, display, distribute, 49 | // execute, and transmit the Software, and to prepare derivative works of the 50 | // Software, and to permit third-parties to whom the Software is furnished to 51 | // do so, all subject to the following: 52 | // 53 | // The copyright notices in the Software and this entire statement, including 54 | // the above license grant, this restriction and the following disclaimer, 55 | // must be included in all copies of the Software, in whole or in part, and 56 | // all derivative works of the Software, unless such copies or derivative 57 | // works are solely in the form of machine-executable object code generated by 58 | // a source language processor. 59 | // 60 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 61 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 62 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 63 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 64 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 65 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 66 | // DEALINGS IN THE SOFTWARE. 67 | // 68 | 69 | #ifndef Foundation_ScopedLock_INCLUDED 70 | #define Foundation_ScopedLock_INCLUDED 71 | 72 | #include "Foundation.hpp" 73 | 74 | /** 75 | * \brief A class that simplifies thread synchronization with a mutex or 76 | *fastmutex. 77 | * 78 | * The constructor accepts a Mutex and locks it. 79 | * The destructor unlocks the mutex. 80 | **/ 81 | template class CScopedLock { 82 | public: 83 | inline CScopedLock(M *mutex) : _mutex(mutex) { 84 | _mutex->lock(LOCK_TIMEOUT_MS); 85 | } 86 | inline ~CScopedLock() { _mutex->unlock(); } 87 | 88 | private: 89 | M *_mutex; 90 | 91 | CScopedLock(); 92 | CScopedLock(const CScopedLock &); 93 | CScopedLock &operator=(const CScopedLock &); 94 | }; 95 | 96 | #endif // Foundation_ScopedLock_INCLUDED 97 | -------------------------------------------------------------------------------- /src/es40_endian.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU General Public License 10 | * as published by the Free Software Foundation; either version 2 11 | * of the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 21 | * USA. 22 | * 23 | * Although this is not required, the author would appreciate being notified of, 24 | * and receiving any modifications you may make to the source code that might 25 | * serve the general public. 26 | */ 27 | 28 | #if !defined(INCLUDED_ENDIAN_H) 29 | #define INCLUDED_ENDIAN_H 30 | 31 | #if !defined(ES40_LITTLE_ENDIAN) && !defined(ES40_BIG_ENDIAN) 32 | #if defined(_WIN32) || defined(__VMS) 33 | #define ES40_LITTLE_ENDIAN 34 | #else // defined (_WIN32) || defined(__VMS) 35 | #include 36 | 37 | #if !defined(__BYTE_ORDER) && defined(BYTE_ORDER) 38 | #define __BYTE_ORDER BYTE_ORDER 39 | #if !defined(__BIG_ENDIAN) && defined(BIG_ENDIAN) 40 | #define __BIG_ENDIAN BIG_ENDIAN 41 | #endif 42 | #if !defined(__LITTLE_ENDIAN) && defined(LITTLE_ENDIAN) 43 | #define __LITTLE_ENDIAN LITTLE_ENDIAN 44 | #endif 45 | #endif 46 | #if (defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN)) || defined(sparc) 47 | #define ES40_BIG_ENDIAN 48 | #else // assume little endian 49 | #define ES40_LITTLE_ENDIAN 50 | #endif 51 | #endif // defined (_WIN32) || defined(__VMS) 52 | #endif // !defined(ES40_LITTLE_ENDIAN) && !defined(ES40_BIG_ENDIAN) 53 | #define swap_64(x) \ 54 | ((((x)&U64(0x00000000000000ff)) << 56) | \ 55 | (((x)&U64(0x000000000000ff00)) << 40) | \ 56 | (((x)&U64(0x0000000000ff0000)) << 24) | \ 57 | (((x)&U64(0x00000000ff000000)) << 8) | \ 58 | (((x)&U64(0x000000ff00000000)) >> 8) | \ 59 | (((x)&U64(0x0000ff0000000000)) >> 24) | \ 60 | (((x)&U64(0x00ff000000000000)) >> 40) | \ 61 | (((x)&U64(0xff00000000000000)) >> 56)) 62 | #define swap_32(x) \ 63 | ((((x)&0x000000ff) << 24) | (((x)&0x0000ff00) << 8) | \ 64 | (((x)&0x00ff0000) >> 8) | (((x)&0xff000000) >> 24)) 65 | #define swap_16(x) ((((x)&0x00ff) << 8) | (((x)&0xff00) >> 8)) 66 | #define swap_8(x) ((x)&0xff) 67 | #if defined(ES40_BIG_ENDIAN) 68 | #define endian_64(x) swap_64(x) 69 | #define endian_32(x) swap_32(x) 70 | #define endian_16(x) swap_16(x) 71 | #define endian_8(x) swap_8(x) 72 | #else // defined(ES40_BIG_ENDIAN) 73 | #define endian_64(x) (x) 74 | #define endian_32(x) ((x)&0xffffffff) 75 | #define endian_16(x) ((x)&0xffff) 76 | #define endian_8(x) ((x)&0xff) 77 | #endif // defined(ES40_BIG_ENDIAN) 78 | inline u64 endian_bits(u64 x, int numbits) { 79 | switch (numbits) { 80 | case 64: 81 | return endian_64(x); 82 | case 32: 83 | return endian_32(x); 84 | case 16: 85 | return endian_16(x); 86 | case 8: 87 | return endian_8(x); 88 | default: 89 | FAILURE(InvalidArgument, "Weird numbits in endian_bits"); 90 | } 91 | } 92 | #endif // INCLUDED_ENDIAN_H 93 | -------------------------------------------------------------------------------- /src/base/Event_WIN32.cpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // Event_WIN32.cpp 34 | // 35 | // $Id: Event_WIN32.cpp,v 1.1 2008/05/31 15:47:21 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Threading 39 | // Module: Event 40 | // 41 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 42 | // and Contributors. 43 | // 44 | // Permission is hereby granted, free of charge, to any person or organization 45 | // obtaining a copy of the software and accompanying documentation covered by 46 | // this license (the "Software") to use, reproduce, display, distribute, 47 | // execute, and transmit the Software, and to prepare derivative works of the 48 | // Software, and to permit third-parties to whom the Software is furnished to 49 | // do so, all subject to the following: 50 | // 51 | // The copyright notices in the Software and this entire statement, including 52 | // the above license grant, this restriction and the following disclaimer, 53 | // must be included in all copies of the Software, in whole or in part, and 54 | // all derivative works of the Software, unless such copies or derivative 55 | // works are solely in the form of machine-executable object code generated by 56 | // a source language processor. 57 | // 58 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 59 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 60 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 61 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 62 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 63 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 64 | // DEALINGS IN THE SOFTWARE. 65 | // 66 | 67 | #include "Event_WIN32.hpp" 68 | 69 | CEventImpl::CEventImpl(bool autoReset) { 70 | _event = CreateEventW(NULL, autoReset ? FALSE : TRUE, FALSE, NULL); 71 | if (!_event) 72 | throw CSystemException("cannot create event"); 73 | } 74 | 75 | CEventImpl::~CEventImpl() { CloseHandle(_event); } 76 | 77 | void CEventImpl::waitImpl() { 78 | switch (WaitForSingleObject(_event, INFINITE)) { 79 | case WAIT_OBJECT_0: 80 | return; 81 | default: 82 | throw CSystemException("wait for event failed"); 83 | } 84 | } 85 | 86 | bool CEventImpl::waitImpl(long milliseconds) { 87 | switch (WaitForSingleObject(_event, milliseconds + 1)) { 88 | case WAIT_TIMEOUT: 89 | return false; 90 | case WAIT_OBJECT_0: 91 | return true; 92 | default: 93 | throw CSystemException("wait for event failed"); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/base/Mutex_WIN32.cpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // Mutex_WIN32.cpp 34 | // 35 | // $Id: Mutex_WIN32.cpp,v 1.1 2008/05/31 15:47:24 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Threading 39 | // Module: Mutex 40 | // 41 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 42 | // and Contributors. 43 | // 44 | // Permission is hereby granted, free of charge, to any person or organization 45 | // obtaining a copy of the software and accompanying documentation covered by 46 | // this license (the "Software") to use, reproduce, display, distribute, 47 | // execute, and transmit the Software, and to prepare derivative works of the 48 | // Software, and to permit third-parties to whom the Software is furnished to 49 | // do so, all subject to the following: 50 | // 51 | // The copyright notices in the Software and this entire statement, including 52 | // the above license grant, this restriction and the following disclaimer, 53 | // must be included in all copies of the Software, in whole or in part, and 54 | // all derivative works of the Software, unless such copies or derivative 55 | // works are solely in the form of machine-executable object code generated by 56 | // a source language processor. 57 | // 58 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 59 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 60 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 61 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 62 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 63 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 64 | // DEALINGS IN THE SOFTWARE. 65 | // 66 | 67 | #include "Mutex_WIN32.hpp" 68 | #include "Timestamp.hpp" 69 | 70 | CMutexImpl::CMutexImpl() { 71 | // the fct has a boolean return value under WInnNt/2000/XP but not on Win98 72 | // the return only checks if the input address of &_cs was valid, so it is 73 | // safe to omit it 74 | InitializeCriticalSectionAndSpinCount(&_cs, 4000); 75 | } 76 | 77 | CMutexImpl::~CMutexImpl() { DeleteCriticalSection(&_cs); } 78 | 79 | bool CMutexImpl::tryLockImpl(long milliseconds) { 80 | const int sleepMillis = 5; 81 | CTimestamp now; 82 | CTimestamp::TimeDiff diff(CTimestamp::TimeDiff(milliseconds) * 1000); 83 | do { 84 | try { 85 | if (TryEnterCriticalSection(&_cs) == TRUE) 86 | return true; 87 | } catch (...) { 88 | throw CSystemException("cannot lock mutex"); 89 | } 90 | Sleep(sleepMillis); 91 | } while (!now.isElapsed(diff)); 92 | return false; 93 | } 94 | -------------------------------------------------------------------------------- /src/base/Semaphore_WIN32.cpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // Semaphore_WIN32.cpp 34 | // 35 | // $Id: Semaphore_WIN32.cpp,v 1.1 2008/05/31 15:47:28 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Threading 39 | // Module: Semaphore 40 | // 41 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 42 | // and Contributors. 43 | // 44 | // Permission is hereby granted, free of charge, to any person or organization 45 | // obtaining a copy of the software and accompanying documentation covered by 46 | // this license (the "Software") to use, reproduce, display, distribute, 47 | // execute, and transmit the Software, and to prepare derivative works of the 48 | // Software, and to permit third-parties to whom the Software is furnished to 49 | // do so, all subject to the following: 50 | // 51 | // The copyright notices in the Software and this entire statement, including 52 | // the above license grant, this restriction and the following disclaimer, 53 | // must be included in all copies of the Software, in whole or in part, and 54 | // all derivative works of the Software, unless such copies or derivative 55 | // works are solely in the form of machine-executable object code generated by 56 | // a source language processor. 57 | // 58 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 59 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 60 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 61 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 62 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 63 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 64 | // DEALINGS IN THE SOFTWARE. 65 | // 66 | 67 | #include "Semaphore_WIN32.hpp" 68 | 69 | CSemaphoreImpl::CSemaphoreImpl(int n, int max) { 70 | poco_assert(n >= 0 && max > 0 && n <= max); 71 | 72 | _sema = CreateSemaphoreW(NULL, n, max, NULL); 73 | if (!_sema) { 74 | throw CSystemException("cannot create semaphore"); 75 | } 76 | } 77 | 78 | CSemaphoreImpl::~CSemaphoreImpl() { CloseHandle(_sema); } 79 | 80 | void CSemaphoreImpl::waitImpl() { 81 | switch (WaitForSingleObject(_sema, INFINITE)) { 82 | case WAIT_OBJECT_0: 83 | return; 84 | default: 85 | throw CSystemException("wait for semaphore failed"); 86 | } 87 | } 88 | 89 | bool CSemaphoreImpl::waitImpl(long milliseconds) { 90 | switch (WaitForSingleObject(_sema, milliseconds + 1)) { 91 | case WAIT_TIMEOUT: 92 | return false; 93 | case WAIT_OBJECT_0: 94 | return true; 95 | default: 96 | throw CSystemException("wait for semaphore failed"); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/es40_debug.cpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | This file is based upon GXemul. 9 | * 10 | * Copyright (C) 2004-2007 Anders Gavare. All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * 3. The name of the author may not be used to endorse or promote products 21 | * derived from this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | * SUCH DAMAGE. 34 | */ 35 | 36 | /***************************************************************************** 37 | * 38 | * NOTE: debug(), fatal(), and debug_indentation() are not re-entrant. 39 | * The global variable quiet_mode can be used to suppress the output 40 | * of debug(), but not the output of fatal(). 41 | * 42 | *****************************************************************************/ 43 | #include "StdAfx.hpp" 44 | 45 | // int verbose = 0; 46 | int quiet_mode = 0; 47 | 48 | static int debug_indent = 0; 49 | static int debug_currently_at_start_of_line = 1; 50 | 51 | /* 52 | * va_debug(): 53 | * 54 | * Used internally by debug() and fatal(). 55 | */ 56 | static void va_debug(va_list argp, char *fmt) { 57 | char buf[DEBUG_BUFSIZE + 1]; 58 | char *s; 59 | int i; 60 | 61 | buf[0] = buf[DEBUG_BUFSIZE] = 0; 62 | 63 | // vsnprintf(buf, DEBUG_BUFSIZE, fmt, argp); 64 | sprintf(buf, fmt, argp); 65 | 66 | s = buf; 67 | while (*s) { 68 | if (debug_currently_at_start_of_line) { 69 | for (i = 0; i < debug_indent; i++) 70 | printf(" "); 71 | } 72 | 73 | printf("%c", *s); 74 | 75 | debug_currently_at_start_of_line = 0; 76 | if (*s == '\n' || *s == '\r') 77 | debug_currently_at_start_of_line = 1; 78 | s++; 79 | } 80 | } 81 | 82 | /* 83 | * debug_indentation(): 84 | * 85 | * Modify the debug indentation. 86 | */ 87 | void debug_indentation(int diff) { 88 | debug_indent += diff; 89 | if (debug_indent < 0) 90 | fprintf(stderr, "WARNING: debug_indent less than 0!\n"); 91 | } 92 | 93 | /* 94 | * debug(): 95 | * 96 | * Debug output (ignored if quiet_mode is set). 97 | */ 98 | void debug(char *fmt, ...) { 99 | va_list argp; 100 | 101 | if (quiet_mode) 102 | return; 103 | 104 | va_start(argp, fmt); 105 | va_debug(argp, fmt); 106 | va_end(argp); 107 | } 108 | 109 | /* 110 | * fatal(): 111 | * 112 | * Fatal works like debug(), but doesn't care about the quiet_mode 113 | * setting. 114 | */ 115 | void fatal(char *fmt, ...) { 116 | va_list argp; 117 | 118 | va_start(argp, fmt); 119 | va_debug(argp, fmt); 120 | va_end(argp); 121 | } 122 | -------------------------------------------------------------------------------- /src/base/Event_WIN32.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // Event_WIN32.h 34 | // 35 | // $Id: Event_WIN32.h,v 1.1 2008/05/31 15:47:22 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Threading 39 | // Module: Event 40 | // 41 | // Definition of the EventImpl class for WIN32. 42 | // 43 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 44 | // and Contributors. 45 | // 46 | // Permission is hereby granted, free of charge, to any person or organization 47 | // obtaining a copy of the software and accompanying documentation covered by 48 | // this license (the "Software") to use, reproduce, display, distribute, 49 | // execute, and transmit the Software, and to prepare derivative works of the 50 | // Software, and to permit third-parties to whom the Software is furnished to 51 | // do so, all subject to the following: 52 | // 53 | // The copyright notices in the Software and this entire statement, including 54 | // the above license grant, this restriction and the following disclaimer, 55 | // must be included in all copies of the Software, in whole or in part, and 56 | // all derivative works of the Software, unless such copies or derivative 57 | // works are solely in the form of machine-executable object code generated by 58 | // a source language processor. 59 | // 60 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 61 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 62 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 63 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 64 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 65 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 66 | // DEALINGS IN THE SOFTWARE. 67 | // 68 | 69 | #ifndef Foundation_Event_WIN32_INCLUDED 70 | #define Foundation_Event_WIN32_INCLUDED 71 | 72 | #include "Exception.hpp" 73 | #include "Foundation.hpp" 74 | #include "UnWindows.hpp" 75 | 76 | class CEventImpl { 77 | protected: 78 | CEventImpl(bool autoReset = false); 79 | ~CEventImpl(); 80 | void setImpl(); 81 | void waitImpl(); 82 | bool waitImpl(long milliseconds); 83 | void resetImpl(); 84 | 85 | private: 86 | HANDLE _event; 87 | }; 88 | 89 | // 90 | // inlines 91 | // 92 | inline void CEventImpl::setImpl() { 93 | if (!SetEvent(_event)) { 94 | throw CSystemException("cannot signal event"); 95 | } 96 | } 97 | 98 | inline void CEventImpl::resetImpl() { 99 | if (!ResetEvent(_event)) { 100 | throw CSystemException("cannot reset event"); 101 | } 102 | } 103 | 104 | #endif // Foundation_Event_WIN32_INCLUDED 105 | -------------------------------------------------------------------------------- /src/config_debug.hpp: -------------------------------------------------------------------------------- 1 | // This is config_debug.h 2 | // 3 | // This file contains the debug configuration options. 4 | // This file was generated by configure_1.sh 5 | // 6 | // $Id: config_debug.h,v 1.5 2010/03/11 22:44:13 iamcamiel Exp $ 7 | 8 | // Define to 1 if you want to show the cycle counter 9 | #define HIDE_COUNTER 1 10 | 11 | // Define to 1 if you want to show estimate speed 12 | #undef MIPS_ESTIMATE 13 | 14 | // Define to 1 if you want to show memory map 15 | #undef DUMP_MEMMAP 16 | 17 | // Define to 1 if you want to check for overlapping of memory ranges 18 | #define CHECK_MEM_RANGES 1 19 | 20 | // Define to 1 if you want to use the new floating-point implementation 21 | #undef HAVE_NEW_FP 22 | 23 | // Define to 1 if you want to enable VGA debugging 24 | #undef DEBUG_VGA 25 | 26 | // Define to 1 if you want to enable Serial Port debugging 27 | #undef DEBUG_SERIAL 28 | 29 | // Define to 1 if you want to enable IDE General debugging 30 | #undef DEBUG_IDE 31 | 32 | // Define to 1 if you want to enable IDE Busmaster debugging 33 | #undef DEBUG_IDE_BUSMASTER 34 | 35 | // Define to 1 if you want to enable IDE Command debugging 36 | #undef DEBUG_IDE_COMMAND 37 | 38 | // Define to 1 if you want to enable IDE CMD debugging 39 | #undef DEBUG_IDE_CMD 40 | 41 | // Define to 1 if you want to enable IDE DMA debugging 42 | #undef DEBUG_IDE_DMA 43 | 44 | // Define to 1 if you want to enable IDE Interrupt debugging 45 | #undef DEBUG_IDE_INTERRUPT 46 | 47 | // Define to 1 if you want to enable IDE Command Register debugging 48 | #undef DEBUG_IDE_REG_COMMAND 49 | 50 | // Define to 1 if you want to enable IDE Control Register debugging 51 | #undef DEBUG_IDE_REG_CONTROL 52 | 53 | // Define to 1 if you want to enable IDE ATAPI Packet debugging 54 | #undef DEBUG_IDE_PACKET 55 | 56 | // Define to 1 if you want to enable IDE Thread debugging 57 | #undef DEBUG_IDE_THREADS 58 | 59 | // Define to 1 if you want to enable IDE Mutexes debugging 60 | #undef DEBUG_IDE_LOCKS 61 | 62 | // Define to 1 if you want to enable IDE Multiple debugging 63 | #undef DEBUG_IDE_MULTIPLE 64 | 65 | // Define to 1 if you want to enable Floating Point conversions debugging 66 | #undef DEBUG_FP_CONVERSION 67 | 68 | // Define to 1 if you want to enable Floating Point load/store debugging 69 | #undef DEBUG_FP_LOADSTORE 70 | 71 | // Define to 1 if you want to enable General NIC debugging 72 | #undef DEBUG_NIC 73 | 74 | // Define to 1 if you want to enable NIC Filter debugging 75 | #undef DEBUG_NIC_FILTER 76 | 77 | // Define to 1 if you want to enable NIC Serial ROM debugging 78 | #undef DEBUG_NIC_SROM 79 | 80 | // Define to 1 if you want to enable unknown memory access debugging 81 | #undef DEBUG_UNKMEM 82 | 83 | // Define to 1 if you want to enable PCI debugging 84 | #undef DEBUG_PCI 85 | 86 | // Define to 1 if you want to enable Translationbuffer debugging 87 | #undef DEBUG_TB 88 | 89 | // Define to 1 if you want to enable I/O Port Access debugging 90 | #undef DEBUG_PORTACCESS 91 | 92 | // Define to 1 if you want to enable Keyboard debugging 93 | #undef DEBUG_KBD 94 | 95 | // Define to 1 if you want to enable Programmable Interrupt Controller (PIC) 96 | // debugging 97 | #undef DEBUG_PIC 98 | 99 | // Define to 1 if you want to enable Printer port debugging 100 | #undef DEBUG_LPT 101 | 102 | // Define to 1 if you want to enable USB Controller debugging 103 | #undef DEBUG_USB 104 | 105 | // Define to 1 if you want to enable SCSI Device debugging 106 | #undef DEBUG_SCSI 107 | 108 | // Define to 1 if you want to enable Symbios SCSI Controller debugging 109 | #undef DEBUG_SYM 110 | 111 | // Define to 1 if you want to enable Symbios Registers debugging 112 | #undef DEBUG_SYM_REGS 113 | 114 | // Define to 1 if you want to enable Symbios SCRIPTS Execution debugging 115 | #undef DEBUG_SYM_SCRIPTS 116 | 117 | // Define to 1 if you want to enable DMA Controller debugging 118 | #undef DEBUG_DMA 119 | 120 | // Define to 1 if you want to enable backtrace on SIGSEGV debugging 121 | #undef DEBUG_BACKTRACE 122 | 123 | // Define to 1 if you want to enable mutex debugging 124 | #undef DEBUG_LOCKS 125 | 126 | // Define to 1 if you want to enable SDL Key translation debugging 127 | #undef DEBUG_SDL_KEY 128 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: LLVM 4 | AccessModifierOffset: -2 5 | AlignAfterOpenBracket: Align 6 | AlignConsecutiveMacros: false 7 | AlignConsecutiveAssignments: false 8 | AlignConsecutiveDeclarations: false 9 | AlignEscapedNewlines: Right 10 | AlignOperands: true 11 | AlignTrailingComments: true 12 | AllowAllArgumentsOnNextLine: true 13 | AllowAllConstructorInitializersOnNextLine: true 14 | AllowAllParametersOfDeclarationOnNextLine: true 15 | AllowShortBlocksOnASingleLine: false 16 | AllowShortCaseLabelsOnASingleLine: false 17 | AllowShortFunctionsOnASingleLine: All 18 | AllowShortLambdasOnASingleLine: All 19 | AllowShortIfStatementsOnASingleLine: Never 20 | AllowShortLoopsOnASingleLine: false 21 | AlwaysBreakAfterDefinitionReturnType: None 22 | AlwaysBreakAfterReturnType: None 23 | AlwaysBreakBeforeMultilineStrings: false 24 | AlwaysBreakTemplateDeclarations: MultiLine 25 | BinPackArguments: true 26 | BinPackParameters: true 27 | BraceWrapping: 28 | AfterCaseLabel: false 29 | AfterClass: false 30 | AfterControlStatement: false 31 | AfterEnum: false 32 | AfterFunction: false 33 | AfterNamespace: false 34 | AfterObjCDeclaration: false 35 | AfterStruct: false 36 | AfterUnion: false 37 | AfterExternBlock: false 38 | BeforeCatch: false 39 | BeforeElse: false 40 | IndentBraces: false 41 | SplitEmptyFunction: true 42 | SplitEmptyRecord: true 43 | SplitEmptyNamespace: true 44 | BreakBeforeBinaryOperators: None 45 | BreakBeforeBraces: Attach 46 | BreakBeforeInheritanceComma: false 47 | BreakInheritanceList: BeforeColon 48 | BreakBeforeTernaryOperators: true 49 | BreakConstructorInitializersBeforeComma: false 50 | BreakConstructorInitializers: BeforeColon 51 | BreakAfterJavaFieldAnnotations: false 52 | BreakStringLiterals: true 53 | ColumnLimit: 80 54 | CommentPragmas: '^ IWYU pragma:' 55 | CompactNamespaces: false 56 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 57 | ConstructorInitializerIndentWidth: 4 58 | ContinuationIndentWidth: 4 59 | Cpp11BracedListStyle: true 60 | DerivePointerAlignment: false 61 | DisableFormat: false 62 | ExperimentalAutoDetectBinPacking: false 63 | FixNamespaceComments: true 64 | ForEachMacros: 65 | - foreach 66 | - Q_FOREACH 67 | - BOOST_FOREACH 68 | IncludeBlocks: Preserve 69 | IncludeCategories: 70 | - Regex: '^"(llvm|llvm-c|clang|clang-c)/' 71 | Priority: 2 72 | - Regex: '^(<|"(gtest|gmock|isl|json)/)' 73 | Priority: 3 74 | - Regex: '.*' 75 | Priority: 1 76 | IncludeIsMainRegex: '(Test)?$' 77 | IndentCaseLabels: false 78 | IndentPPDirectives: None 79 | IndentWidth: 2 80 | IndentWrappedFunctionNames: false 81 | JavaScriptQuotes: Leave 82 | JavaScriptWrapImports: true 83 | KeepEmptyLinesAtTheStartOfBlocks: true 84 | MacroBlockBegin: '' 85 | MacroBlockEnd: '' 86 | MaxEmptyLinesToKeep: 1 87 | NamespaceIndentation: None 88 | ObjCBinPackProtocolList: Auto 89 | ObjCBlockIndentWidth: 2 90 | ObjCSpaceAfterProperty: false 91 | ObjCSpaceBeforeProtocolList: true 92 | PenaltyBreakAssignment: 2 93 | PenaltyBreakBeforeFirstCallParameter: 19 94 | PenaltyBreakComment: 300 95 | PenaltyBreakFirstLessLess: 120 96 | PenaltyBreakString: 1000 97 | PenaltyBreakTemplateDeclaration: 10 98 | PenaltyExcessCharacter: 1000000 99 | PenaltyReturnTypeOnItsOwnLine: 60 100 | PointerAlignment: Right 101 | ReflowComments: true 102 | SortIncludes: true 103 | SortUsingDeclarations: true 104 | SpaceAfterCStyleCast: false 105 | SpaceAfterLogicalNot: false 106 | SpaceAfterTemplateKeyword: true 107 | SpaceBeforeAssignmentOperators: true 108 | SpaceBeforeCpp11BracedList: false 109 | SpaceBeforeCtorInitializerColon: true 110 | SpaceBeforeInheritanceColon: true 111 | SpaceBeforeParens: ControlStatements 112 | SpaceBeforeRangeBasedForLoopColon: true 113 | SpaceInEmptyParentheses: false 114 | SpacesBeforeTrailingComments: 1 115 | SpacesInAngles: false 116 | SpacesInContainerLiterals: true 117 | SpacesInCStyleCastParentheses: false 118 | SpacesInParentheses: false 119 | SpacesInSquareBrackets: false 120 | Standard: Cpp11 121 | StatementMacros: 122 | - Q_UNUSED 123 | - QT_REQUIRE_VERSION 124 | TabWidth: 8 125 | UseTab: Never 126 | ... 127 | 128 | -------------------------------------------------------------------------------- /src/base/Mutex_WIN32.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // Mutex_WIN32.h 34 | // 35 | // $Id: Mutex_WIN32.h,v 1.1 2008/05/31 15:47:24 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Threading 39 | // Module: Mutex 40 | // 41 | // Definition of the MutexImpl and FastMutexImpl classes for WIN32. 42 | // 43 | // Copyright (c) 2004-2008, Applied Informatics Software Engineering GmbH. 44 | // and Contributors. 45 | // 46 | // Permission is hereby granted, free of charge, to any person or organization 47 | // obtaining a copy of the software and accompanying documentation covered by 48 | // this license (the "Software") to use, reproduce, display, distribute, 49 | // execute, and transmit the Software, and to prepare derivative works of the 50 | // Software, and to permit third-parties to whom the Software is furnished to 51 | // do so, all subject to the following: 52 | // 53 | // The copyright notices in the Software and this entire statement, including 54 | // the above license grant, this restriction and the following disclaimer, 55 | // must be included in all copies of the Software, in whole or in part, and 56 | // all derivative works of the Software, unless such copies or derivative 57 | // works are solely in the form of machine-executable object code generated by 58 | // a source language processor. 59 | // 60 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 61 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 62 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 63 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 64 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 65 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 66 | // DEALINGS IN THE SOFTWARE. 67 | // 68 | 69 | #ifndef Foundation_Mutex_WIN32_INCLUDED 70 | #define Foundation_Mutex_WIN32_INCLUDED 71 | 72 | #include "Exception.hpp" 73 | #include "Foundation.hpp" 74 | #include "UnWindows.hpp" 75 | 76 | class CMutexImpl { 77 | protected: 78 | CMutexImpl(); 79 | ~CMutexImpl(); 80 | void lockImpl(); 81 | bool tryLockImpl(); 82 | bool tryLockImpl(long milliseconds); 83 | void unlockImpl(); 84 | 85 | private: 86 | CRITICAL_SECTION _cs; 87 | }; 88 | 89 | typedef CMutexImpl CFastMutexImpl; 90 | 91 | // 92 | // inlines 93 | // 94 | inline void CMutexImpl::lockImpl() { 95 | try { 96 | EnterCriticalSection(&_cs); 97 | } catch (...) { 98 | throw CSystemException("cannot lock mutex"); 99 | } 100 | } 101 | 102 | inline bool CMutexImpl::tryLockImpl() { 103 | try { 104 | return TryEnterCriticalSection(&_cs) == TRUE; 105 | } catch (...) { 106 | } 107 | throw CSystemException("cannot lock mutex"); 108 | } 109 | 110 | inline void CMutexImpl::unlockImpl() { LeaveCriticalSection(&_cs); } 111 | 112 | #endif // Foundation_Mutex_WIN32_INCLUDED 113 | -------------------------------------------------------------------------------- /src/FloppyController.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(INCLUDED_FLOPPYCONTROLLER_H) 30 | #define INCLUDED_FLOPPYCONTROLLER_H 31 | 32 | #include "DMA.hpp" 33 | #include "DiskController.hpp" 34 | #include "SystemComponent.hpp" 35 | 36 | /** 37 | * \brief Emulated floppy-drive controller. 38 | **/ 39 | class CFloppyController : public CSystemComponent, public CDiskController { 40 | public: 41 | virtual u64 ReadMem(int index, u64 address, int dsize); 42 | virtual void WriteMem(int index, u64 address, int dsize, u64 data); 43 | CFloppyController(class CConfigurator *cfg, class CSystem *c, int id); 44 | virtual ~CFloppyController(); 45 | virtual int RestoreState(FILE *f); 46 | virtual int SaveState(FILE *f); 47 | 48 | private: 49 | void do_interrupt(); 50 | u8 get_status(); 51 | 52 | struct { 53 | struct { 54 | int seeking; 55 | int cylinder; 56 | bool motor; 57 | } drive[2]; 58 | 59 | u8 write_precomp; 60 | u8 drive_select; 61 | bool dma; 62 | u8 datarate; 63 | 64 | struct { 65 | bool rqm; 66 | bool dio; 67 | bool nondma; 68 | bool busy; 69 | bool seeking[2]; 70 | } status; 71 | 72 | int busy; 73 | u8 cmd_parms[16]; 74 | u8 cmd_parms_ptr; 75 | u8 cmd_res[16]; 76 | u8 cmd_res_ptr; 77 | u8 cmd_res_max; 78 | 79 | bool interrupt; 80 | 81 | } state; 82 | }; 83 | 84 | #define FDC_REG_STATUS_A 0 85 | #define FDC_REG_STATUS_B 1 86 | #define FDC_REG_DOR 2 87 | #define FDC_REG_TAPE 3 88 | #define FDC_REG_STATUS 4 89 | #define FDC_REG_COMMAND 5 90 | #define FDC_REG_DIR 7 91 | 92 | #define SEL_DRIVE state.drive[state.drive_select] 93 | #define SEL_FDISK get_disk(0, state.drive_select) 94 | #define DRIVE(i) state.drive[i] 95 | #define FDISK(i) get_disk(0, i) 96 | 97 | // 98 | // These defines were stolen from the Linux 1.0 fdreg.h file :) 99 | // 100 | /* Bits of FD_ST0 */ 101 | #define ST0_DS 0x03 /* drive select mask */ 102 | #define ST0_HA 0x04 /* Head (Address) */ 103 | #define ST0_NR 0x08 /* Not Ready */ 104 | #define ST0_ECE 0x10 /* Equipment chech error */ 105 | #define ST0_SE 0x20 /* Seek end */ 106 | #define ST0_INTR 0xC0 /* Interrupt code mask */ 107 | 108 | /* Bits of FD_ST1 */ 109 | #define ST1_MAM 0x01 /* Missing Address Mark */ 110 | #define ST1_WP 0x02 /* Write Protect */ 111 | #define ST1_ND 0x04 /* No Data - unreadable */ 112 | #define ST1_OR 0x10 /* OverRun */ 113 | #define ST1_CRC 0x20 /* CRC error in data or addr */ 114 | #define ST1_EOC 0x80 /* End Of Cylinder */ 115 | 116 | /* Bits of FD_ST2 */ 117 | #define ST2_MAM 0x01 /* Missing Addess Mark (again) */ 118 | #define ST2_BC 0x02 /* Bad Cylinder */ 119 | #define ST2_SNS 0x04 /* Scan Not Satisfied */ 120 | #define ST2_SEH 0x08 /* Scan Equal Hit */ 121 | #define ST2_WC 0x10 /* Wrong Cylinder */ 122 | #define ST2_CRC 0x20 /* CRC error in data field */ 123 | #define ST2_CM 0x40 /* Control Mark = deleted */ 124 | 125 | /* Bits of FD_ST3 */ 126 | #define ST3_HA 0x04 /* Head (Address) */ 127 | #define ST3_TZ 0x10 /* Track Zero signal (1=track 0) */ 128 | #define ST3_WP 0x40 /* Write Protect */ 129 | 130 | #endif // !defined(INCLUDED_FLOPPYCONTROLLER_H) 131 | -------------------------------------------------------------------------------- /src/base/Bugcheck.cpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // Bugcheck.cpp 34 | // 35 | // $Id: Bugcheck.cpp,v 1.1 2008/05/31 15:47:19 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Core 39 | // Module: Bugcheck 40 | // 41 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 42 | // and Contributors. 43 | // 44 | // Permission is hereby granted, free of charge, to any person or organization 45 | // obtaining a copy of the software and accompanying documentation covered by 46 | // this license (the "Software") to use, reproduce, display, distribute, 47 | // execute, and transmit the Software, and to prepare derivative works of the 48 | // Software, and to permit third-parties to whom the Software is furnished to 49 | // do so, all subject to the following: 50 | // 51 | // The copyright notices in the Software and this entire statement, including 52 | // the above license grant, this restriction and the following disclaimer, 53 | // must be included in all copies of the Software, in whole or in part, and 54 | // all derivative works of the Software, unless such copies or derivative 55 | // works are solely in the form of machine-executable object code generated by 56 | // a source language processor. 57 | // 58 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 59 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 60 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 61 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 62 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 63 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 64 | // DEALINGS IN THE SOFTWARE. 65 | // 66 | 67 | #include "Bugcheck.hpp" 68 | #include "Exception.hpp" 69 | #include 70 | 71 | void CBugcheck::assertion(const char *cond, const char *file, int line) { 72 | throw CAssertionViolationException(what(cond, file, line)); 73 | } 74 | 75 | void CBugcheck::nullPointer(const char *ptr, const char *file, int line) { 76 | throw CNullPointerException(what(ptr, file, line)); 77 | } 78 | 79 | void CBugcheck::bugcheck(const char *file, int line) { 80 | throw CBugcheckException(what(0, file, line)); 81 | } 82 | 83 | void CBugcheck::bugcheck(const char *msg, const char *file, int line) { 84 | std::string m("Bugcheck"); 85 | if (msg) { 86 | m.append(": "); 87 | m.append(msg); 88 | } 89 | throw CBugcheckException(what(msg, file, line)); 90 | } 91 | 92 | void CBugcheck::debugger(const char *file, int line) { 93 | // Debugger::enter(file, line); 94 | } 95 | 96 | void CBugcheck::debugger(const char *msg, const char *file, int line) { 97 | // Debugger::enter(msg, file, line); 98 | } 99 | 100 | std::string CBugcheck::what(const char *msg, const char *file, int line) { 101 | std::ostringstream str; 102 | if (msg) 103 | str << msg << " "; 104 | str << "in file \"" << file << "\", line " << line; 105 | return str.str(); 106 | } 107 | -------------------------------------------------------------------------------- /src/base/SingletonHolder.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // SingletonHolder.h 34 | // 35 | // $Id: SingletonHolder.h,v 1.1 2008/05/31 15:47:28 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Core 39 | // Module: SingletonHolder 40 | // 41 | // Definition of the SingletonHolder template. 42 | // 43 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 44 | // and Contributors. 45 | // 46 | // Permission is hereby granted, free of charge, to any person or organization 47 | // obtaining a copy of the software and accompanying documentation covered by 48 | // this license (the "Software") to use, reproduce, display, distribute, 49 | // execute, and transmit the Software, and to prepare derivative works of the 50 | // Software, and to permit third-parties to whom the Software is furnished to 51 | // do so, all subject to the following: 52 | // 53 | // The copyright notices in the Software and this entire statement, including 54 | // the above license grant, this restriction and the following disclaimer, 55 | // must be included in all copies of the Software, in whole or in part, and 56 | // all derivative works of the Software, unless such copies or derivative 57 | // works are solely in the form of machine-executable object code generated by 58 | // a source language processor. 59 | // 60 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 61 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 62 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 63 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 64 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 65 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 66 | // DEALINGS IN THE SOFTWARE. 67 | // 68 | 69 | #ifndef Foundation_SingletonHolder_INCLUDED 70 | #define Foundation_SingletonHolder_INCLUDED 71 | 72 | #include "Foundation.hpp" 73 | #include "Mutex.hpp" 74 | 75 | template 76 | class CSingletonHolder 77 | /// This is a helper template class for managing 78 | /// singleton objects allocated on the heap. 79 | /// The class ensures proper deletion (including 80 | /// calling of the destructor) of singleton objects 81 | /// when the application that created them terminates. 82 | { 83 | public: 84 | CSingletonHolder() 85 | /// Creates the SingletonHolder. 86 | { 87 | _pS = 0; 88 | } 89 | ~CSingletonHolder() 90 | /// Destroys the SingletonHolder and the singleton 91 | /// object that it holds. 92 | { 93 | delete _pS; 94 | } 95 | S *get() 96 | /// Returns a pointer to the singleton object 97 | /// hold by the SingletonHolder. The first call 98 | /// to get will create the singleton. 99 | { 100 | CFastMutex::CScopedLock lock(&_m); 101 | if (!_pS) 102 | _pS = new S; 103 | return _pS; 104 | } 105 | 106 | private: 107 | S *_pS; 108 | CFastMutex _m; 109 | }; 110 | 111 | #endif // Foundation_SingletonHolder_INCLUDED 112 | -------------------------------------------------------------------------------- /src/base/Semaphore_POSIX.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // Semaphore_POSIX.h 34 | // 35 | // $Id: Semaphore_POSIX.h,v 1.1 2008/05/31 15:47:28 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Threading 39 | // Module: Semaphore 40 | // 41 | // Definition of the SemaphoreImpl class for POSIX Threads. 42 | // 43 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 44 | // and Contributors. 45 | // 46 | // Permission is hereby granted, free of charge, to any person or organization 47 | // obtaining a copy of the software and accompanying documentation covered by 48 | // this license (the "Software") to use, reproduce, display, distribute, 49 | // execute, and transmit the Software, and to prepare derivative works of the 50 | // Software, and to permit third-parties to whom the Software is furnished to 51 | // do so, all subject to the following: 52 | // 53 | // The copyright notices in the Software and this entire statement, including 54 | // the above license grant, this restriction and the following disclaimer, 55 | // must be included in all copies of the Software, in whole or in part, and 56 | // all derivative works of the Software, unless such copies or derivative 57 | // works are solely in the form of machine-executable object code generated by 58 | // a source language processor. 59 | // 60 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 61 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 62 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 63 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 64 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 65 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 66 | // DEALINGS IN THE SOFTWARE. 67 | // 68 | 69 | #ifndef Foundation_Semaphore_POSIX_INCLUDED 70 | #define Foundation_Semaphore_POSIX_INCLUDED 71 | 72 | #include "Exception.hpp" 73 | #include "Foundation.hpp" 74 | #include 75 | #include 76 | 77 | class CSemaphoreImpl { 78 | protected: 79 | CSemaphoreImpl(int n, int max); 80 | ~CSemaphoreImpl(); 81 | void setImpl(); 82 | void waitImpl(); 83 | bool waitImpl(long milliseconds); 84 | 85 | private: 86 | volatile int _n; 87 | int _max; 88 | pthread_mutex_t _mutex; 89 | pthread_cond_t _cond; 90 | }; 91 | 92 | // 93 | // inlines 94 | // 95 | inline void CSemaphoreImpl::setImpl() { 96 | if (pthread_mutex_lock(&_mutex)) 97 | throw CSystemException("cannot signal semaphore (lock)"); 98 | if (_n < _max) { 99 | ++_n; 100 | } else { 101 | pthread_mutex_unlock(&_mutex); 102 | throw CSystemException( 103 | "cannot signal semaphore: count would exceed maximum"); 104 | } 105 | if (pthread_cond_signal(&_cond)) { 106 | pthread_mutex_unlock(&_mutex); 107 | throw CSystemException("cannot signal semaphore"); 108 | } 109 | pthread_mutex_unlock(&_mutex); 110 | } 111 | 112 | #endif // Foundation_Semaphore_POSIX_INCLUDED 113 | -------------------------------------------------------------------------------- /src/base/Event_POSIX.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // Event_POSIX.h 34 | // 35 | // $Id: Event_POSIX.h,v 1.1 2008/05/31 15:47:21 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Threading 39 | // Module: Event 40 | // 41 | // Definition of the EventImpl class for POSIX Threads. 42 | // 43 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 44 | // and Contributors. 45 | // 46 | // Permission is hereby granted, free of charge, to any person or organization 47 | // obtaining a copy of the software and accompanying documentation covered by 48 | // this license (the "Software") to use, reproduce, display, distribute, 49 | // execute, and transmit the Software, and to prepare derivative works of the 50 | // Software, and to permit third-parties to whom the Software is furnished to 51 | // do so, all subject to the following: 52 | // 53 | // The copyright notices in the Software and this entire statement, including 54 | // the above license grant, this restriction and the following disclaimer, 55 | // must be included in all copies of the Software, in whole or in part, and 56 | // all derivative works of the Software, unless such copies or derivative 57 | // works are solely in the form of machine-executable object code generated by 58 | // a source language processor. 59 | // 60 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 61 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 62 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 63 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 64 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 65 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 66 | // DEALINGS IN THE SOFTWARE. 67 | // 68 | 69 | #ifndef Foundation_Event_POSIX_INCLUDED 70 | #define Foundation_Event_POSIX_INCLUDED 71 | 72 | #include "Exception.hpp" 73 | #include "Foundation.hpp" 74 | #include 75 | #include 76 | 77 | class CEventImpl { 78 | protected: 79 | CEventImpl(bool autoReset); 80 | ~CEventImpl(); 81 | void setImpl(); 82 | void waitImpl(); 83 | bool waitImpl(long milliseconds); 84 | void resetImpl(); 85 | 86 | private: 87 | bool _auto; 88 | volatile bool _state; 89 | pthread_mutex_t _mutex; 90 | pthread_cond_t _cond; 91 | }; 92 | 93 | // 94 | // inlines 95 | // 96 | inline void CEventImpl::setImpl() { 97 | if (pthread_mutex_lock(&_mutex)) 98 | throw CSystemException("cannot signal event (lock)"); 99 | _state = true; 100 | if (pthread_cond_broadcast(&_cond)) { 101 | pthread_mutex_unlock(&_mutex); 102 | throw CSystemException("cannot signal event"); 103 | } 104 | pthread_mutex_unlock(&_mutex); 105 | } 106 | 107 | inline void CEventImpl::resetImpl() { 108 | if (pthread_mutex_lock(&_mutex)) 109 | throw CSystemException("cannot reset event"); 110 | _state = false; 111 | pthread_mutex_unlock(&_mutex); 112 | } 113 | 114 | #endif // Foundation_Event_POSIX_INCLUDED 115 | -------------------------------------------------------------------------------- /src/base/Foundation.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // Foundation.h 34 | // 35 | // $Id: Foundation.h,v 1.2 2010/03/11 22:44:16 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Core 39 | // Module: Foundation 40 | // 41 | // Basic definitions for the POCO Foundation library. 42 | // This file must be the first file included by every other Foundation 43 | // header file. 44 | // 45 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 46 | // and Contributors. 47 | // 48 | // Permission is hereby granted, free of charge, to any person or organization 49 | // obtaining a copy of the software and accompanying documentation covered by 50 | // this license (the "Software") to use, reproduce, display, distribute, 51 | // execute, and transmit the Software, and to prepare derivative works of the 52 | // Software, and to permit third-parties to whom the Software is furnished to 53 | // do so, all subject to the following: 54 | // 55 | // The copyright notices in the Software and this entire statement, including 56 | // the above license grant, this restriction and the following disclaimer, 57 | // must be included in all copies of the Software, in whole or in part, and 58 | // all derivative works of the Software, unless such copies or derivative 59 | // works are solely in the form of machine-executable object code generated by 60 | // a source language processor. 61 | // 62 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 63 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 64 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 65 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 66 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 67 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 68 | // DEALINGS IN THE SOFTWARE. 69 | // 70 | 71 | #ifndef Foundation_Foundation_INCLUDED 72 | #define Foundation_Foundation_INCLUDED 73 | 74 | // 75 | // Include library configuration 76 | // 77 | // CAVA #include "Config.h" 78 | 79 | // 80 | // Include platform-specific definitions 81 | // 82 | #include "Platform.hpp" 83 | #if defined(_WIN32) 84 | #include "Platform_WIN32.hpp" 85 | #elif defined(__VMS) 86 | #include "Platform_VMS.hpp" 87 | #elif defined(POCO_OS_FAMILY_UNIX) 88 | #include "Platform_POSIX.hpp" 89 | #endif 90 | 91 | // 92 | // POCO_JOIN 93 | // 94 | // The following piece of macro magic joins the two 95 | // arguments together, even when one of the arguments is 96 | // itself a macro (see 16.3.1 in C++ standard). The key 97 | // is that macro expansion of macro arguments does not 98 | // occur in POCO_DO_JOIN2 but does in POCO_DO_JOIN. 99 | // 100 | #define POCO_JOIN(X, Y) POCO_DO_JOIN(X, Y) 101 | #define POCO_DO_JOIN(X, Y) POCO_DO_JOIN2(X, Y) 102 | #define POCO_DO_JOIN2(X, Y) X##Y 103 | 104 | // 105 | // Pull in basic definitions 106 | // 107 | #include "Bugcheck.hpp" 108 | #include "Types.hpp" 109 | #include 110 | #include 111 | 112 | #endif // Foundation_Foundation_INCLUDED 113 | -------------------------------------------------------------------------------- /src/base/Mutex_POSIX.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // Mutex_POSIX.h 34 | // 35 | // $Id: Mutex_POSIX.h,v 1.1 2008/05/31 15:47:24 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Threading 39 | // Module: Mutex 40 | // 41 | // Definition of the MutexImpl and FastMutexImpl classes for POSIX Threads. 42 | // 43 | // Copyright (c) 2004-2008, Applied Informatics Software Engineering GmbH. 44 | // and Contributors. 45 | // 46 | // Permission is hereby granted, free of charge, to any person or organization 47 | // obtaining a copy of the software and accompanying documentation covered by 48 | // this license (the "Software") to use, reproduce, display, distribute, 49 | // execute, and transmit the Software, and to prepare derivative works of the 50 | // Software, and to permit third-parties to whom the Software is furnished to 51 | // do so, all subject to the following: 52 | // 53 | // The copyright notices in the Software and this entire statement, including 54 | // the above license grant, this restriction and the following disclaimer, 55 | // must be included in all copies of the Software, in whole or in part, and 56 | // all derivative works of the Software, unless such copies or derivative 57 | // works are solely in the form of machine-executable object code generated by 58 | // a source language processor. 59 | // 60 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 61 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 62 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 63 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 64 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 65 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 66 | // DEALINGS IN THE SOFTWARE. 67 | // 68 | 69 | #ifndef Foundation_Mutex_POSIX_INCLUDED 70 | #define Foundation_Mutex_POSIX_INCLUDED 71 | 72 | #include "Exception.hpp" 73 | #include "Foundation.hpp" 74 | #include 75 | #include 76 | 77 | class CMutexImpl { 78 | protected: 79 | CMutexImpl(); 80 | CMutexImpl(bool fast); 81 | ~CMutexImpl(); 82 | void lockImpl(); 83 | bool tryLockImpl(); 84 | bool tryLockImpl(long milliseconds); 85 | void unlockImpl(); 86 | 87 | private: 88 | pthread_mutex_t _mutex; 89 | }; 90 | 91 | class CFastMutexImpl : public CMutexImpl { 92 | protected: 93 | CFastMutexImpl(); 94 | ~CFastMutexImpl(); 95 | }; 96 | 97 | // 98 | // inlines 99 | // 100 | inline void CMutexImpl::lockImpl() { 101 | if (pthread_mutex_lock(&_mutex)) 102 | throw CSystemException("cannot lock mutex"); 103 | } 104 | 105 | inline bool CMutexImpl::tryLockImpl() { 106 | int rc = pthread_mutex_trylock(&_mutex); 107 | if (rc == 0) 108 | return true; 109 | else if (rc == EBUSY) 110 | return false; 111 | else 112 | throw CSystemException("cannot lock mutex"); 113 | } 114 | 115 | inline void CMutexImpl::unlockImpl() { 116 | if (pthread_mutex_unlock(&_mutex)) 117 | throw CSystemException("cannot unlock mutex"); 118 | } 119 | 120 | #endif // Foundation_Mutex_POSIX_INCLUDED 121 | -------------------------------------------------------------------------------- /src/base/RefCountedObject.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // RefCountedObject.h 34 | // 35 | // $Id: RefCountedObject.h,v 1.1 2008/05/31 15:47:27 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Core 39 | // Module: RefCountedObject 40 | // 41 | // Definition of the RefCountedObject class. 42 | // 43 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 44 | // and Contributors. 45 | // 46 | // Permission is hereby granted, free of charge, to any person or organization 47 | // obtaining a copy of the software and accompanying documentation covered by 48 | // this license (the "Software") to use, reproduce, display, distribute, 49 | // execute, and transmit the Software, and to prepare derivative works of the 50 | // Software, and to permit third-parties to whom the Software is furnished to 51 | // do so, all subject to the following: 52 | // 53 | // The copyright notices in the Software and this entire statement, including 54 | // the above license grant, this restriction and the following disclaimer, 55 | // must be included in all copies of the Software, in whole or in part, and 56 | // all derivative works of the Software, unless such copies or derivative 57 | // works are solely in the form of machine-executable object code generated by 58 | // a source language processor. 59 | // 60 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 61 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 62 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 63 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 64 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 65 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 66 | // DEALINGS IN THE SOFTWARE. 67 | // 68 | 69 | #ifndef Foundation_RefCountedObject_INCLUDED 70 | #define Foundation_RefCountedObject_INCLUDED 71 | 72 | #include "Foundation.hpp" 73 | #include "Mutex.hpp" 74 | 75 | class CRefCountedObject 76 | /// A base class for objects that employ 77 | /// reference counting based garbage collection. 78 | /// 79 | /// Reference-counted objects inhibit construction 80 | /// by copying and assignment. 81 | { 82 | public: 83 | CRefCountedObject(); 84 | /// Creates the RefCountedObject. 85 | /// The initial reference count is one. 86 | 87 | void duplicate() const; 88 | /// Increments the object's reference count. 89 | 90 | void release() const; 91 | /// Decrements the object's reference count 92 | /// and deletes the object if the count 93 | /// reaches zero. 94 | 95 | int referenceCount() const; 96 | /// Returns the reference count. 97 | 98 | protected: 99 | virtual ~CRefCountedObject(); 100 | /// Destroys the RefCountedObject. 101 | 102 | private: 103 | CRefCountedObject(const CRefCountedObject &); 104 | CRefCountedObject &operator=(const CRefCountedObject &); 105 | 106 | mutable int _rc; 107 | mutable CFastMutex _rcMutex; 108 | }; 109 | 110 | // 111 | // inlines 112 | // 113 | inline int CRefCountedObject::referenceCount() const { return _rc; } 114 | 115 | #endif // Foundation_RefCountedObject_INCLUDED 116 | -------------------------------------------------------------------------------- /src/telnet.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | */ 28 | 29 | #if !defined(INCLUDED_TELNET_H) 30 | #define INCLUDED_TELNET_H 31 | 32 | #if defined(HAVE_WINSOCK2_H) 33 | #include 34 | #endif 35 | 36 | #if defined(HAVE_WS2TCPIP_H) 37 | #include 38 | #endif 39 | 40 | #if defined(HAVE_SYS_SOCKET_H) 41 | #include 42 | #endif 43 | 44 | #if defined(HAVE_SOCKET_H) 45 | #include 46 | #endif 47 | 48 | #if defined(HAVE_IN_H) 49 | #include 50 | #endif 51 | 52 | #if defined(HAVE_INET_H) 53 | #include 54 | #endif 55 | 56 | #if defined(HAVE_ARPA_INET_H) 57 | #include 58 | #endif 59 | 60 | #if defined(HAVE_ARPA_TELNET_H) 61 | #include 62 | #endif 63 | 64 | #if defined(HAVE_NETINET_IN_H) 65 | #include 66 | #endif 67 | 68 | #if defined(HAVE_SYS_SELECT_H) 69 | #include 70 | #endif 71 | 72 | #if defined(HAVE_ERRNO_H) 73 | #include 74 | #endif 75 | 76 | #if defined(HAVE_FCNTL_H) 77 | #include 78 | #endif 79 | 80 | #if defined(HAVE_SIGNAL_H) 81 | #include 82 | #endif 83 | 84 | #if defined(_WIN32) && !defined(__GNUWIN32__) 85 | typedef size_t ssize_t; 86 | typedef int socklen_t; 87 | #endif // _WIN32 88 | 89 | #if defined(__VMS) 90 | #define INVALID_SOCKET -1 91 | typedef unsigned int socklen_t; 92 | #endif // __VMS 93 | 94 | #if defined(_WIN32) || defined(__VMS) 95 | #define IAC 255 /* interpret as command: */ 96 | #define DONT 254 /* you are not to use option */ 97 | #define DO 253 /* please, you use option */ 98 | #define WONT 252 /* I won't use option */ 99 | #define WILL 251 /* I will use option */ 100 | #define SB 250 /* interpret as subnegotiation */ 101 | #define GA 249 /* you may reverse the line */ 102 | #define EL 248 /* erase the current line */ 103 | #define EC 247 /* erase the current character */ 104 | #define AYT 246 /* are you there */ 105 | #define AO 245 /* abort output--but let prog finish */ 106 | #define IP 244 /* interrupt process--permanently */ 107 | #define BREAK 243 /* break */ 108 | #define DM 242 /* data mark--for connect. cleaning */ 109 | #define NOP 241 /* nop */ 110 | #define SE 240 /* end sub negotiation */ 111 | #define EOR 239 /* end of record (transparent mode) */ 112 | #define ABORT 238 /* Abort process */ 113 | #define SUSP 237 /* Suspend process */ 114 | #define xEOF 236 /* End of file: EOF is already used... */ 115 | 116 | #define SYNCH 242 /* for telfunc calls */ 117 | #define TELOPT_ECHO 1 /* echo */ 118 | #define TELOPT_SGA 3 /* suppress go ahead */ 119 | #define TELOPT_NAWS 31 /* window size */ 120 | #define TELOPT_LFLOW 33 /* remote flow control */ 121 | 122 | #else // defined(_WIN32) || defined(__VMS) 123 | #define INVALID_SOCKET 1 124 | #endif // defined (_WIN32) || defined(__VMS) 125 | 126 | /* inet_aton -- Emulate BSD inet_aton via inet_addr. 127 | * 128 | * Useful on systems that don't have inet_aton, such as Solaris, 129 | * to let your code use the better inet_aton interface and use autoconf 130 | * and AC_REPLACE_FUNCS([inet_aton]). 131 | * 132 | * Copyright (C) 2003 Matthias Andree 133 | */ 134 | #if !defined(HAVE_INET_ATON) 135 | inline int inet_aton(const char *name, struct in_addr *addr) { 136 | unsigned long a = inet_addr(name); 137 | addr->s_addr = a; 138 | return a != (unsigned int)-1; 139 | } 140 | #endif 141 | #endif // !defined(INCLUDED_TELNET_H) 142 | -------------------------------------------------------------------------------- /src/base/Platform_VMS.hpp: -------------------------------------------------------------------------------- 1 | /* AXPbox Alpha Emulator 2 | * Copyright (C) 2020 Tomáš Glozar 3 | * Website: https://github.com/lenticularis39/axpbox 4 | * 5 | * Forked from: ES40 emulator 6 | * Copyright (C) 2007-2008 by the ES40 Emulator Project 7 | * Copyright (C) 2007 by Camiel Vanderhoeven 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU General Public License 11 | * as published by the Free Software Foundation; either version 2 12 | * of the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 | * USA. 23 | * 24 | * Although this is not required, the author would appreciate being notified of, 25 | * and receiving any modifications you may make to the source code that might 26 | * serve the general public. 27 | * 28 | * Parts of this file based upon the Poco C++ Libraries, which is Copyright (C) 29 | * 2004-2006, Applied Informatics Software Engineering GmbH. and Contributors. 30 | */ 31 | 32 | // 33 | // Platform_VMS.h 34 | // 35 | // $Id: Platform_VMS.h,v 1.1 2008/05/31 15:47:26 iamcamiel Exp $ 36 | // 37 | // Library: Foundation 38 | // Package: Core 39 | // Module: Platform 40 | // 41 | // Platform and architecture identification macros 42 | // and platform-specific definitions for OpenVMS. 43 | // 44 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 45 | // and Contributors. 46 | // 47 | // Permission is hereby granted, free of charge, to any person or organization 48 | // obtaining a copy of the software and accompanying documentation covered by 49 | // this license (the "Software") to use, reproduce, display, distribute, 50 | // execute, and transmit the Software, and to prepare derivative works of the 51 | // Software, and to permit third-parties to whom the Software is furnished to 52 | // do so, all subject to the following: 53 | // 54 | // The copyright notices in the Software and this entire statement, including 55 | // the above license grant, this restriction and the following disclaimer, 56 | // must be included in all copies of the Software, in whole or in part, and 57 | // all derivative works of the Software, unless such copies or derivative 58 | // works are solely in the form of machine-executable object code generated by 59 | // a source language processor. 60 | // 61 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 62 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 63 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 64 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 65 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 66 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 67 | // DEALINGS IN THE SOFTWARE. 68 | // 69 | 70 | #ifndef Foundation_Platform_VMS_INCLUDED 71 | #define Foundation_Platform_VMS_INCLUDED 72 | 73 | // Define the POCO_DESCRIPTOR_STRING and POCO_DESCRIPTOR_LITERAL 74 | // macros which we use instead of $DESCRIPTOR and $DESCRIPTOR64. 75 | // Our macros work with both 32bit and 64bit pointer sizes. 76 | #if __INITIAL_POINTER_SIZE != 64 77 | #define POCO_DESCRIPTOR_STRING(name, string) \ 78 | struct dsc$descriptor_s name = {string.size(), DSC$K_DTYPE_T, DSC$K_CLASS_S, \ 79 | (char *)string.data()} 80 | #define POCO_DESCRIPTOR_LITERAL(name, string) \ 81 | struct dsc$descriptor_s name = {sizeof(string) - 1, DSC$K_DTYPE_T, \ 82 | DSC$K_CLASS_S, (char *)string} 83 | #else 84 | #define POCO_DESCRIPTOR_STRING(name, string) \ 85 | struct dsc64$descriptor_s name = { \ 86 | 1, DSC64$K_DTYPE_T, DSC64$K_CLASS_S, \ 87 | -1, string.size(), (char *)string.data()} 88 | #define POCO_DESCRIPTOR_LITERAL(name, string) \ 89 | struct dsc64$descriptor_s name = {1, DSC64$K_DTYPE_T, DSC64$K_CLASS_S, \ 90 | -1, sizeof(string) - 1, (char *)string} 91 | #endif 92 | 93 | // No header file 94 | #define POCO_NO_SYS_SELECT_H 95 | 96 | #endif // Foundation_Platform_VMS_INCLUDED 97 | --------------------------------------------------------------------------------