From b5488bacba6456b0dc17088833827fdff2589b45 Mon Sep 17 00:00:00 2001 From: Godzil Date: Fri, 7 Feb 2020 17:56:27 +0000 Subject: [PATCH 01/32] Add portaudio for futur audio work. --- .gitmodules | 3 +++ external/portaudio | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 external/portaudio diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e6a4e31 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "external/portaudio"] + path = external/portaudio + url = https://git.assembla.com/portaudio.git diff --git a/external/portaudio b/external/portaudio new file mode 160000 index 0000000..c5d2c51 --- /dev/null +++ b/external/portaudio @@ -0,0 +1 @@ +Subproject commit c5d2c51bd6fe354d0ee1119ba932bfebd3ebfacc From cf80c9624cc29fe952b6af4e7b82fe6382d47871 Mon Sep 17 00:00:00 2001 From: Godzil Date: Fri, 7 Feb 2020 17:58:12 +0000 Subject: [PATCH 02/32] Add tentative travis build script --- .travis.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..874a93a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,33 @@ +dist: trusty +language: c +os: + - linux +# - osx +#matrix: +# allow_failures: +# - os: osx + +addons: + apt: + packages: + - libsdl1.2-dev + +compiler: + - clang + - gcc + +script: + - make + +cache: + directories: + - '$HOME/.sonar/cache' + +#before_install: +# - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi +# - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install glew; fi + +#install: true + +#after_success: +# - bash <(curl -s https://codecov.io/bash) From 0fadff165b83a41639503ed6045f768d0fc0f41f Mon Sep 17 00:00:00 2001 From: Godzil Date: Fri, 7 Feb 2020 18:00:54 +0000 Subject: [PATCH 03/32] Update travis to use latest ubuntu instead of the old 14.04 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 874a93a..953ce01 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -dist: trusty +dist: bionic language: c os: - linux From 3e6f09619189b6b9dac1b930b3ce43a8232c46c3 Mon Sep 17 00:00:00 2001 From: Godzil Date: Mon, 10 Feb 2020 23:58:18 +0000 Subject: [PATCH 04/32] Add CMake module to get Git version. --- .../cmake/GetGitRevisionDescription.cmake | 168 ++++++++++++++++++ .../cmake/GetGitRevisionDescription.cmake.in | 41 +++++ 2 files changed, 209 insertions(+) create mode 100644 external/cmake/GetGitRevisionDescription.cmake create mode 100644 external/cmake/GetGitRevisionDescription.cmake.in diff --git a/external/cmake/GetGitRevisionDescription.cmake b/external/cmake/GetGitRevisionDescription.cmake new file mode 100644 index 0000000..0a6cb5f --- /dev/null +++ b/external/cmake/GetGitRevisionDescription.cmake @@ -0,0 +1,168 @@ +# - Returns a version string from Git +# +# These functions force a re-configure on each git commit so that you can +# trust the values of the variables in your build system. +# +# get_git_head_revision( [ ...]) +# +# Returns the refspec and sha hash of the current head revision +# +# git_describe( [ ...]) +# +# Returns the results of git describe on the source tree, and adjusting +# the output so that it tests false if an error occurs. +# +# git_get_exact_tag( [ ...]) +# +# Returns the results of git describe --exact-match on the source tree, +# and adjusting the output so that it tests false if there was no exact +# matching tag. +# +# git_local_changes() +# +# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes. +# Uses the return code of "git diff-index --quiet HEAD --". +# Does not regard untracked files. +# +# Requires CMake 2.6 or newer (uses the 'function' command) +# +# Original Author: +# 2009-2010 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2009-2010. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +if(__get_git_revision_description) + return() +endif() +set(__get_git_revision_description YES) + +# We must run the following at "include" time, not at function call time, +# to find the path to this module rather than the path to a calling list file +get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) + +function(get_git_head_revision _refspecvar _hashvar) + set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + set(GIT_DIR "${GIT_PARENT_DIR}/.git") + while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories + set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") + get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) + if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) + # We have reached the root directory, we are not in git + set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) + set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) + return() + endif() + set(GIT_DIR "${GIT_PARENT_DIR}/.git") + endwhile() + # check if this is a submodule + if(NOT IS_DIRECTORY ${GIT_DIR}) + file(READ ${GIT_DIR} submodule) + string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule}) + get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH) + get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE) + endif() + set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") + if(NOT EXISTS "${GIT_DATA}") + file(MAKE_DIRECTORY "${GIT_DATA}") + endif() + + if(NOT EXISTS "${GIT_DIR}/HEAD") + return() + endif() + set(HEAD_FILE "${GIT_DATA}/HEAD") + configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) + + configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" + "${GIT_DATA}/grabRef.cmake" + @ONLY) + include("${GIT_DATA}/grabRef.cmake") + + set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE) + set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE) +endfunction() + +function(git_describe _var) + if(NOT GIT_FOUND) + find_package(Git QUIET) + endif() + get_git_head_revision(refspec hash) + if(NOT GIT_FOUND) + set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) + return() + endif() + if(NOT hash) + set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) + return() + endif() + + # TODO sanitize + #if((${ARGN}" MATCHES "&&") OR + # (ARGN MATCHES "||") OR + # (ARGN MATCHES "\\;")) + # message("Please report the following error to the project!") + # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") + #endif() + + #message(STATUS "Arguments to execute_process: ${ARGN}") + + execute_process(COMMAND + "${GIT_EXECUTABLE}" + describe + #${hash} + ${ARGN} + WORKING_DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}" + RESULT_VARIABLE + res + OUTPUT_VARIABLE + out + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT res EQUAL 0) + set(out "${out}-${res}-NOTFOUND") + endif() + + set(${_var} "${out}" PARENT_SCOPE) +endfunction() + +function(git_get_exact_tag _var) + git_describe(out --exact-match ${ARGN}) + set(${_var} "${out}" PARENT_SCOPE) +endfunction() + +function(git_local_changes _var) + if(NOT GIT_FOUND) + find_package(Git QUIET) + endif() + get_git_head_revision(refspec hash) + if(NOT GIT_FOUND) + set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) + return() + endif() + if(NOT hash) + set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) + return() + endif() + + execute_process(COMMAND + "${GIT_EXECUTABLE}" + diff-index --quiet HEAD -- + WORKING_DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}" + RESULT_VARIABLE + res + OUTPUT_VARIABLE + out + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(res EQUAL 0) + set(${_var} "CLEAN" PARENT_SCOPE) + else() + set(${_var} "DIRTY" PARENT_SCOPE) + endif() +endfunction() diff --git a/external/cmake/GetGitRevisionDescription.cmake.in b/external/cmake/GetGitRevisionDescription.cmake.in new file mode 100644 index 0000000..6d8b708 --- /dev/null +++ b/external/cmake/GetGitRevisionDescription.cmake.in @@ -0,0 +1,41 @@ +# +# Internal file for GetGitRevisionDescription.cmake +# +# Requires CMake 2.6 or newer (uses the 'function' command) +# +# Original Author: +# 2009-2010 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2009-2010. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +set(HEAD_HASH) + +file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024) + +string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS) +if(HEAD_CONTENTS MATCHES "ref") + # named branch + string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") + if(EXISTS "@GIT_DIR@/${HEAD_REF}") + configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) + else() + configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY) + file(READ "@GIT_DATA@/packed-refs" PACKED_REFS) + if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}") + set(HEAD_HASH "${CMAKE_MATCH_1}") + endif() + endif() +else() + # detached HEAD + configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY) +endif() + +if(NOT HEAD_HASH) + file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) + string(STRIP "${HEAD_HASH}" HEAD_HASH) +endif() From 667f655d22a569a26deefa44be2594a17301340c Mon Sep 17 00:00:00 2001 From: Godzil Date: Mon, 10 Feb 2020 23:59:01 +0000 Subject: [PATCH 05/32] Add preliminary CMake build. Not replacing the makefile for now, will in the future. --- CMakeLists.txt | 26 ++++++++++++++++++++++++++ source/CMakeLists.txt | 11 +++++++++++ source/nec/CMakeLists.txt | 4 ++++ 3 files changed, 41 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 source/CMakeLists.txt create mode 100644 source/nec/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f282c41 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.1) + +# External cmake modules +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/external/cmake ${CMAKE_MODULE_PATH}) + +project("NewOswan") + +include(GetGitRevisionDescription) +git_describe(VERSION --tags --dirty=-dirty) + +find_package(SDL 1.2 REQUIRED) + +set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-unused-result -Wno-write-strings -Werror") +set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-unused-result -Wno-write-strings -Werror") + +message("-- Building version ${VERSION}") + +add_executable(wonderswan main.cpp) + +target_compile_definitions(wonderswan PUBLIC VERSION="${VERSION}") +target_include_directories(wonderswan PUBLIC source) +target_include_directories(wonderswan PUBLIC ${SDL_INCLUDE_DIR}) + +add_subdirectory(source) + +target_link_libraries(wonderswan wswan ${SDL_LIBRARY}) \ No newline at end of file diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt new file mode 100644 index 0000000..466b0a4 --- /dev/null +++ b/source/CMakeLists.txt @@ -0,0 +1,11 @@ +set(SOURCES audio.cpp emulate.cpp gpu.cpp io.cpp log.cpp memory.cpp rom.cpp ws.cpp) +set(HEADERS audio.h emulate.h gpu.h ieeprom.h initialIo.h io.h log.h memory.h rom.h SDLptc.h ws.h) + +add_library(wswan ${SOURCES} ${HEADERS}) + +target_link_libraries(wswan nec_v30) + +target_include_directories(wswan PUBLIC .) +target_include_directories(wswan PUBLIC ${SDL_INCLUDE_DIR}) + +add_subdirectory(nec) \ No newline at end of file diff --git a/source/nec/CMakeLists.txt b/source/nec/CMakeLists.txt new file mode 100644 index 0000000..4ff600e --- /dev/null +++ b/source/nec/CMakeLists.txt @@ -0,0 +1,4 @@ +set(SOURCES nec.cpp) +set(HEADERS nec.h necea.h necinstr.h necintrf.h necmodrm.h) + +add_library(nec_v30 ${SOURCES} ${HEADERS}) \ No newline at end of file From 6d5658eb682b8c26fbdfdc7e1a6f293d26562b64 Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 11 Feb 2020 00:00:23 +0000 Subject: [PATCH 06/32] Make gcc happy (and fix a potential issue) --- source/io.cpp | 4 +++- source/nec/nec.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source/io.cpp b/source/io.cpp index 71e3bfa..400b816 100644 --- a/source/io.cpp +++ b/source/io.cpp @@ -329,6 +329,7 @@ uint8_t cpu_readport(uint8_t port) int w1,w2; uint8_t retVal = 0; +/* if (port > 0x100) { port &= 0xFF; @@ -337,7 +338,7 @@ uint8_t cpu_readport(uint8_t port) return 0x00; } } - +*/ switch (port) { @@ -1046,6 +1047,7 @@ void cpu_writeport(uint32_t port,uint8_t value) } fflush(stdout); } + break; case 0xca: if(value==0x15) diff --git a/source/nec/nec.cpp b/source/nec/nec.cpp index d7fa45a..ff79ac1 100644 --- a/source/nec/nec.cpp +++ b/source/nec/nec.cpp @@ -3889,7 +3889,7 @@ void nec_set_reg(int regnum, uint32_t val) } } -char *instructionsName[256] = +const char *instructionsName[256] = { "ADD ", "ADD ", "ADD ", "ADD ", "ADD ", "ADD ", "PUSH", "POP ", "OR ", "OR ", "OR ", "OR ", "OR ", "OR ", "PUSH", "----", "ADC ", "ADC ", "ADC ", "ADC ", "ADC ", "ADC ", "PUSH", "POP ", "SBB ", "SBB ", "SBB ", "SBB ", "SBB ", "SBB ", "PUSH", "POP ", From 6d7819903142f1f0faf9bde69a17a3053f14fcaf Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 11 Feb 2020 00:04:42 +0000 Subject: [PATCH 07/32] Update .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index e9ebc7d..674985d 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,7 @@ rom/ dumpinfo testserial wonderswan + +# Build folder +cmake-*/ +build*/ \ No newline at end of file From a0e5006a1829cdcedb0578542e6523317df12c7b Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 11 Feb 2020 00:05:22 +0000 Subject: [PATCH 08/32] Add dumpinfo to cmake, and set the CXX standard to C++98 as it should on that project. --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f282c41..5e3e042 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,10 +17,14 @@ message("-- Building version ${VERSION}") add_executable(wonderswan main.cpp) +set_property(TARGET wonderswan PROPERTY CXX_STANDARD 98) + target_compile_definitions(wonderswan PUBLIC VERSION="${VERSION}") target_include_directories(wonderswan PUBLIC source) target_include_directories(wonderswan PUBLIC ${SDL_INCLUDE_DIR}) add_subdirectory(source) -target_link_libraries(wonderswan wswan ${SDL_LIBRARY}) \ No newline at end of file +target_link_libraries(wonderswan wswan ${SDL_LIBRARY}) + +add_executable(dumpinfo dumpinfo.c) \ No newline at end of file From 4967dcab2106cbae396f36925345c009855b1c38 Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 11 Feb 2020 00:07:16 +0000 Subject: [PATCH 09/32] I honestly don't care about the return value of write. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b69208f..04afaee 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ OBJS = $(wonderswan_CXX_SRCS:.cpp=.o) all: wonderswan dumpinfo CXX = g++ -CXXFLAGS = -g -O2 `sdl-config --cflags` -Wall -Werror -std=c++98 -Wno-write-strings +CXXFLAGS = -g -O2 `sdl-config --cflags` -Wall -Werror -std=c++98 -Wno-write-strings -Wno-unused-result OPTIONS = -D_REENTRANT -I. -DVERSION=\"`git describe --tags --long --dirty`\" LIBRARY_PATH = From c26f935072c98752a23ecad7241d4fd635904ada Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 11 Feb 2020 00:14:36 +0000 Subject: [PATCH 10/32] Interesting that not all GCC versions complain here. --- source/memory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/memory.cpp b/source/memory.cpp index 5504577..38130f4 100644 --- a/source/memory.cpp +++ b/source/memory.cpp @@ -284,7 +284,7 @@ char *create_file(char *filename, uint32_t size) char buf[] = { 0 }; printf("Trying to create %s, size = %u...\n",filename, size); - fd = open(filename, O_CREAT | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_TRUNC); + fd = open(filename, O_CREAT | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_TRUNC, 0644); fchmod(fd, 0644); close(fd); sync(); From a5ce89d14f76fcc71975137dc1d109fe6966e6bf Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 11 Feb 2020 00:17:38 +0000 Subject: [PATCH 11/32] Hmmm it was lurking in other places! --- source/ws.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/ws.cpp b/source/ws.cpp index 49e5365..788abb5 100644 --- a/source/ws.cpp +++ b/source/ws.cpp @@ -459,7 +459,7 @@ int ws_saveState(char *statepath) } } - int fp=open(newPath, O_RDWR|O_CREAT); + int fp=open(newPath, O_RDWR|O_CREAT, 0644); delete newPath; if (fp==-1) From 466f910c9a15aa5aad43a0598e92c8ffd90acb11 Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 11 Feb 2020 00:18:06 +0000 Subject: [PATCH 12/32] Try to also build cmake build. --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 953ce01..f46f930 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,10 @@ compiler: script: - make + - make build + - cd build + - cmake .. + - make cache: directories: From 3552bb8bf9b8869a3e28c211a3eaabf7db70ca4f Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 11 Feb 2020 00:20:36 +0000 Subject: [PATCH 13/32] Silly me... --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f46f930..b753a06 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ compiler: script: - make - - make build + - mkdir build - cd build - cmake .. - make From 62c43f311c171bcf139266af9c02f8714755f56a Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 11 Feb 2020 00:21:17 +0000 Subject: [PATCH 14/32] Trying to add SDL lib package (seems -dev don't install it) --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index b753a06..bb3ba34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ os: addons: apt: packages: + - libsdl1.2 - libsdl1.2-dev compiler: From 6e857bf63096e27b472b25635b29812fe985bb97 Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 11 Feb 2020 00:24:04 +0000 Subject: [PATCH 15/32] Stupid names ubuntu; "libsdl1.2debian", seriously? --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bb3ba34..62f718b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ os: addons: apt: packages: - - libsdl1.2 + - libsdl1.2debian - libsdl1.2-dev compiler: From ed93d90c516399778456bbd2bc11ece03ba9fafc Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 11 Feb 2020 00:29:34 +0000 Subject: [PATCH 16/32] Make sure we are not forcing to GCC and add a bit of debug. CMake find the proper lib but not the makefile? WTF --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 04afaee..75ca5c4 100644 --- a/Makefile +++ b/Makefile @@ -16,12 +16,13 @@ OBJS = $(wonderswan_CXX_SRCS:.cpp=.o) all: wonderswan dumpinfo -CXX = g++ +# CXX = g++ CXXFLAGS = -g -O2 `sdl-config --cflags` -Wall -Werror -std=c++98 -Wno-write-strings -Wno-unused-result OPTIONS = -D_REENTRANT -I. -DVERSION=\"`git describe --tags --long --dirty`\" LIBRARY_PATH = -LIBS = -g $(LIBRARY_PATH) `sdl-config --libs` +SDL_LIBS = `sdl-config --libs` +LIBS = -g $(LIBRARY_PATH) $(SDL_LIBS) ALLCFLAGS = $(CFLAGS) $(CEXTRA) $(OPTIONS) $(ALLFLAGS) ALLCXXFLAGS=$(CXXFLAGS) $(CXXEXTRA) $(OPTIONS) $(ALLFLAGS) @@ -53,4 +54,5 @@ dumpinfo: dumpinfo.o $(CXX) $(LIBS) -o $@ $(<) wonderswan: $(OBJS) + @echo "SDL Libs>> $(SDL_LIBS)" $(CXX) $(LIBS) -o $@ $(OBJS) From e8d7d8473e58b68ab3236ff2d6cb69d424541218 Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 11 Feb 2020 00:38:17 +0000 Subject: [PATCH 17/32] GCC quirkness makes no sense sometimes. --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 75ca5c4..b80df9c 100644 --- a/Makefile +++ b/Makefile @@ -54,5 +54,4 @@ dumpinfo: dumpinfo.o $(CXX) $(LIBS) -o $@ $(<) wonderswan: $(OBJS) - @echo "SDL Libs>> $(SDL_LIBS)" - $(CXX) $(LIBS) -o $@ $(OBJS) + $(CXX) -o $@ $(OBJS) $(LIBS) From 2802e6469786fd779fb5331144af5d2c63739660 Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 11 Feb 2020 00:42:33 +0000 Subject: [PATCH 18/32] clang don't like these unused tables. --- source/audio.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/audio.cpp b/source/audio.cpp index 120713f..5855553 100644 --- a/source/audio.cpp +++ b/source/audio.cpp @@ -91,6 +91,7 @@ int RandData[BUFSIZEN]; int CntSwp=0; int PcmWrPos=0; +/* const long TblChVol[16]= // n/15 n=0~15 { -10000,-2352,-1750,-1398,-1148,-954,-796,-662, @@ -101,6 +102,7 @@ const long TblMainVol[4]= // 1,1/2,1/4,1/8 { 0,-602,-1204,-1806 }; +*/ //////////////////////////////////////////////////////////////////////////////// // seal audio specific From 8c79f6f41717c0e1b97fef2d18fb2a395e87e9a6 Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 11 Feb 2020 00:53:32 +0000 Subject: [PATCH 19/32] Clang should be happy now? --- source/emulate.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/emulate.cpp b/source/emulate.cpp index 1d57121..30f46f6 100644 --- a/source/emulate.cpp +++ b/source/emulate.cpp @@ -263,8 +263,8 @@ static void read_keys() //////////////////////////////////////////////////////////////////////////////// static void ws_drawDoubledScanline(int16_t *vs, int16_t *backbuffer_alias) { - register int32_t *vs_alias = (int32_t *)vs; - register int32_t data; + int32_t *vs_alias = (int32_t *)vs; + int32_t data; for (int pixel = 0 ; pixel < 224 ; pixel += 8) { @@ -308,8 +308,8 @@ static void ws_drawDoubledScanline(int16_t *vs, int16_t *backbuffer_alias) //////////////////////////////////////////////////////////////////////////////// static void ws_drawDoubledRotatedScanline(int16_t *vs, int16_t *backbuffer_alias) { - register int32_t *vs_alias = (int32_t *)vs; - register int32_t data; + int32_t *vs_alias = (int32_t *)vs; + int32_t data; for (int pixel = 0 ; pixel < 144 ; pixel += 8) { From 02c16b7987366d668b199435ce1f3a09b9565bb5 Mon Sep 17 00:00:00 2001 From: Godzil Date: Sat, 14 Nov 2020 19:36:54 +0000 Subject: [PATCH 20/32] Add glfw as an external module --- .gitmodules | 3 +++ external/glfw | 1 + 2 files changed, 4 insertions(+) create mode 160000 external/glfw diff --git a/.gitmodules b/.gitmodules index e6a4e31..9a4e00b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "external/portaudio"] path = external/portaudio url = https://git.assembla.com/portaudio.git +[submodule "external/glfw"] + path = external/glfw + url = https://github.com/glfw/glfw.git diff --git a/external/glfw b/external/glfw new file mode 160000 index 0000000..0ef149c --- /dev/null +++ b/external/glfw @@ -0,0 +1 @@ +Subproject commit 0ef149c8f2451fbc8e866834675a075cfc295b6c From 9035a922c3c8c6dfca71b8372c09f154348657df Mon Sep 17 00:00:00 2001 From: Godzil Date: Sat, 14 Nov 2020 20:14:57 +0000 Subject: [PATCH 21/32] Add GLFW in the CMakeLists, and remove all SDL references. --- CMakeLists.txt | 12 +++++++++--- source/CMakeLists.txt | 1 - 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e3e042..709090d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,14 @@ project("NewOswan") include(GetGitRevisionDescription) git_describe(VERSION --tags --dirty=-dirty) -find_package(SDL 1.2 REQUIRED) +# Include GLFW3 +set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) +set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) +set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) +add_subdirectory("external/glfw") +find_package(OpenGL REQUIRED) + +include_directories(${OPENGL_INCLUDE_DIR}) set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-unused-result -Wno-write-strings -Werror") set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-unused-result -Wno-write-strings -Werror") @@ -21,10 +28,9 @@ set_property(TARGET wonderswan PROPERTY CXX_STANDARD 98) target_compile_definitions(wonderswan PUBLIC VERSION="${VERSION}") target_include_directories(wonderswan PUBLIC source) -target_include_directories(wonderswan PUBLIC ${SDL_INCLUDE_DIR}) add_subdirectory(source) -target_link_libraries(wonderswan wswan ${SDL_LIBRARY}) +target_link_libraries(wonderswan wswan glfw ${OPENGL_glu_LIBRARY} ${OPENGL_gl_LIBRARY}) add_executable(dumpinfo dumpinfo.c) \ No newline at end of file diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 466b0a4..ecab385 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -6,6 +6,5 @@ add_library(wswan ${SOURCES} ${HEADERS}) target_link_libraries(wswan nec_v30) target_include_directories(wswan PUBLIC .) -target_include_directories(wswan PUBLIC ${SDL_INCLUDE_DIR}) add_subdirectory(nec) \ No newline at end of file From ece8a07dcfb631712c539144e75550d7a18a9c47 Mon Sep 17 00:00:00 2001 From: Godzil Date: Sat, 14 Nov 2020 20:15:50 +0000 Subject: [PATCH 22/32] Remove SDL refenrence in the non working audio emulation. --- source/audio.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/audio.cpp b/source/audio.cpp index 5855553..739a4c9 100644 --- a/source/audio.cpp +++ b/source/audio.cpp @@ -29,8 +29,6 @@ #include "io.h" #include "audio.h" -#include "SDL.h" - #define SNDP ws_ioRam[0x80] #define SNDV ws_ioRam[0x88] #define SNDSWP ws_ioRam[0x8C] @@ -144,7 +142,6 @@ void ws_audio_init(void) ws_audio_log=0; //ws_audio_seal_init(); ws_audio_reset(); - SDL_PauseAudio(0); } //////////////////////////////////////////////////////////////////////////////// // From f3aca9a3c7b41c610beabed69cf71cdfeb84d749 Mon Sep 17 00:00:00 2001 From: Godzil Date: Sat, 14 Nov 2020 20:16:46 +0000 Subject: [PATCH 23/32] Start working on implementing the video interface. First disabling/removing all the SDL related function call/variables Also removing some nonsensical dunction (line doubling and rotation are useless in GL mode) --- source/emulate.cpp | 251 ++++----------------------------------------- 1 file changed, 20 insertions(+), 231 deletions(-) diff --git a/source/emulate.cpp b/source/emulate.cpp index 30f46f6..6015f87 100644 --- a/source/emulate.cpp +++ b/source/emulate.cpp @@ -20,8 +20,6 @@ #include /* POSIX terminal control definitions */ #include -#include "SDL.h" -#include "SDLptc.h" #include "log.h" #include "io.h" #include "ws.h" @@ -32,12 +30,10 @@ #include "audio.h" #include "memory.h" -SDL_Joystick *joystick=NULL; char app_window_title[256]; int app_gameRunning=0; int app_terminate=0; int app_fullscreen=0; -SDL_Event app_input_event; int app_rotated=0; @@ -46,32 +42,7 @@ int ws_key_esc = 0; static void read_keys() { - static int testJoystick=1; - - if (testJoystick==1) - { - testJoystick=0; - fprintf(log_get(),"%i joysticks were found.\n\n", SDL_NumJoysticks() ); - fprintf(log_get(),"The names of the joysticks are:\n"); - - for(int tti=0; tti < SDL_NumJoysticks(); tti++ ) - { - fprintf(log_get()," %s\n", SDL_JoystickName(tti)); - } - - SDL_JoystickEventState(SDL_ENABLE); - joystick = SDL_JoystickOpen(0); - } - else - { - if (joystick!=NULL) - { - SDL_JoystickClose(0); - SDL_JoystickEventState(SDL_ENABLE); - joystick = SDL_JoystickOpen(0); - } - } - +#if 0 while ( SDL_PollEvent(&app_input_event) ) { if ( app_input_event.type == SDL_QUIT ) @@ -80,91 +51,20 @@ static void read_keys() } } - if (joystick) - { - if (SDL_JoystickGetButton(joystick,0)) - { - ws_key_start=1; - } - else - { - ws_key_start=0; - } - - if (SDL_JoystickGetButton(joystick,1)) - { - ws_key_button_a=1; - } - else - { - ws_key_button_a=0; - } - - if (SDL_JoystickGetButton(joystick,2)) - { - ws_key_button_b=1; - } - else - { - ws_key_button_b=0; - } - - - if (SDL_JoystickGetAxis(joystick,0)<-7000) - { - ws_key_x4=1; - } - else - { - ws_key_x4=0; - } - - if (SDL_JoystickGetAxis(joystick,0)>7000) - { - ws_key_x2=1; - } - else - { - ws_key_x2=0; - } - - if (SDL_JoystickGetAxis(joystick,1)<-7000) - { - ws_key_x1=1; - } - else - { - ws_key_x1=0; - } - - if (SDL_JoystickGetAxis(joystick,1)>7000) - { - ws_key_x3=1; - } - else - { - ws_key_x3=0; - } - ws_key_y4=0; - ws_key_y2=0; - ws_key_y1=0; - ws_key_y3=0; - } - else - { - ws_key_start=0; - ws_key_x4=0; - ws_key_x2=0; - ws_key_x1=0; - ws_key_x3=0; - ws_key_y4=0; - ws_key_y2=0; - ws_key_y1=0; - ws_key_y3=0; - ws_key_button_a=0; - ws_key_button_b=0; - } +#endif + ws_key_start=0; + ws_key_x4=0; + ws_key_x2=0; + ws_key_x1=0; + ws_key_x3=0; + ws_key_y4=0; + ws_key_y2=0; + ws_key_y1=0; + ws_key_y3=0; + ws_key_button_a=0; + ws_key_button_b=0; +#if 0 uint8_t *keystate = SDL_GetKeyState(NULL); if ( keystate[SDLK_e]) @@ -247,121 +147,9 @@ static void read_keys() { ws_cyclesByLine-=10; } - +#endif } -//////////////////////////////////////////////////////////////////////////////// -// -//////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -// -//////////////////////////////////////////////////////////////////////////////// -static void ws_drawDoubledScanline(int16_t *vs, int16_t *backbuffer_alias) -{ - int32_t *vs_alias = (int32_t *)vs; - int32_t data; - - for (int pixel = 0 ; pixel < 224 ; pixel += 8) - { - data = *backbuffer_alias++; - data |= (data << 16); - *vs_alias++ = data; - data = *backbuffer_alias++; - data |= (data << 16); - *vs_alias++ = data; - data = *backbuffer_alias++; - data |= (data << 16); - *vs_alias++ = data; - data = *backbuffer_alias++; - data |= (data << 16); - *vs_alias++ = data; - data = *backbuffer_alias++; - data |= (data << 16); - *vs_alias++ = data; - data = *backbuffer_alias++; - data |= (data << 16); - *vs_alias++ = data; - data = *backbuffer_alias++; - data |= (data << 16); - *vs_alias++ = data; - data = *backbuffer_alias++; - data |= (data << 16); - *vs_alias++ = data; - } -} - -//////////////////////////////////////////////////////////////////////////////// -// -//////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -// -//////////////////////////////////////////////////////////////////////////////// -static void ws_drawDoubledRotatedScanline(int16_t *vs, int16_t *backbuffer_alias) -{ - int32_t *vs_alias = (int32_t *)vs; - int32_t data; - - for (int pixel = 0 ; pixel < 144 ; pixel += 8) - { - data = *backbuffer_alias++; - data |= (data << 16); - *vs_alias++ = data; - data = *backbuffer_alias++; - data |= (data << 16); - *vs_alias++ = data; - data = *backbuffer_alias++; - data |= (data << 16); - *vs_alias++ = data; - data = *backbuffer_alias++; - data |= (data << 16); - *vs_alias++ = data; - data = *backbuffer_alias++; - data |= (data << 16); - *vs_alias++ = data; - data = *backbuffer_alias++; - data |= (data << 16); - *vs_alias++ = data; - data = *backbuffer_alias++; - data |= (data << 16); - *vs_alias++ = data; - data = *backbuffer_alias++; - data |= (data << 16); - *vs_alias++ = data; - } -} -//////////////////////////////////////////////////////////////////////////////// -// -//////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -// -//////////////////////////////////////////////////////////////////////////////// -void ws_rotate_backbuffer(int16_t *backbuffer) -{ - static int16_t temp[224*144]; - - memcpy(temp,backbuffer,224*144*2); - - for (int line=0; line<144; line++) - for (int column=0; column<224; column++) - { - backbuffer[line+((223-column)<<7)+((223-column)<<4)]=temp[column+(line<<7)+(line<<6)+(line<<5)]; - } -} //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// @@ -375,6 +163,7 @@ void ws_rotate_backbuffer(int16_t *backbuffer) //////////////////////////////////////////////////////////////////////////////// void ws_emulate(void) { +#if 0 int32_t nCount = 0; int i = 0; @@ -382,10 +171,9 @@ void ws_emulate(void) int32_t surfacePitch; // 15 bits RGB555 - Format format(16, 0x007c00, 0x00003e0, 0x0000001f); - Console console; - Surface *surface; - + //Format format(16, 0x007c00, 0x00003e0, 0x0000001f); + //Console console; + //Surface *surface; if (app_rotated) { surface = new Surface(144 * 2, 224 * 2, format); @@ -557,4 +345,5 @@ void ws_emulate(void) console.close(); delete surface; } +#endif } From 8976d4363f1df1a25599efa3c81d0959d8e59934 Mon Sep 17 00:00:00 2001 From: Godzil Date: Sat, 14 Nov 2020 20:27:25 +0000 Subject: [PATCH 24/32] Remove SDLptc.h, the "Console" class and related code. --- main.cpp | 1 - source/SDLptc.h | 314 --------------------------------------------- source/emulate.cpp | 1 - 3 files changed, 316 deletions(-) delete mode 100644 source/SDLptc.h diff --git a/main.cpp b/main.cpp index 5665cd6..2348391 100644 --- a/main.cpp +++ b/main.cpp @@ -16,7 +16,6 @@ #include #include #include "SDL.h" -#include "source/SDLptc.h" #include "source/log.h" #include "source/rom.h" #include "source/nec/nec.h" diff --git a/source/SDLptc.h b/source/SDLptc.h deleted file mode 100644 index bdee461..0000000 --- a/source/SDLptc.h +++ /dev/null @@ -1,314 +0,0 @@ - -/* Some simple emulation classes to get PTC code running on SDL */ - -#include -#include -#include - -#include "SDL.h" - -#define randomize() srand(time(NULL)) -#define random(max) (rand()%(max)) - -#ifndef stricmp -#define stricmp strcasecmp -#endif - -class Error -{ - -public: - Error(const char *message) - { - strcpy(_message, message); - } - - void report(void) - { - printf("Error: %s\n", _message); - } - -private: - - char _message[1024]; -}; - -class Area -{ - -public: - Area(int left, int top, int right, int bottom) - { - _left = left; - _top = top; - _right = right; - _bottom = bottom; - } - - int left(void) const - { - return(_left); - } - int right(void) const - { - return(_right); - } - int top(void) const - { - return(_top); - } - int bottom(void) const - { - return(_bottom); - } - int width(void) const - { - return(_right-_left); - } - int height(void) const - { - return(_bottom-_top); - } - -private: - int _left, _top, _right, _bottom; -}; - - -class Format -{ - -public: - Format(int bpp, int maskR = 0, int maskG = 0, int maskB = 0) - { - _bpp = bpp; - _maskR = maskR; - _maskG = maskG; - _maskB = maskB; - } - - Uint8 BPP(void) const - { - return(_bpp); - } - Uint32 MaskR(void) const - { - return(_maskR); - } - Uint32 MaskG(void) const - { - return(_maskG); - } - Uint32 MaskB(void) const - { - return(_maskB); - } - -private: - Uint8 _bpp; - Uint32 _maskR, _maskG, _maskB; -}; - -class Surface -{ - -public: - Surface(int w, int h, const Format &format) - { - surface = SDL_AllocSurface(SDL_SWSURFACE, w, h, format.BPP(), - format.MaskR(),format.MaskG(),format.MaskB(),0); - - if ( surface == NULL ) - { - throw Error(SDL_GetError()); - } - - nupdates = 0; - is_console = 0; - } - Surface(void) - { - nupdates = 0; - is_console = 1; - } - virtual ~Surface() - { - if ( ! is_console ) - { - SDL_FreeSurface(surface); - } - } - - virtual int width(void) - { - return surface->w; - } - virtual int height(void) - { - return surface->h; - } - virtual int pitch(void) - { - return surface->pitch; - } - - virtual void palette(int32_t *pcolors) - { - SDL_Color colors[256]; - - for ( int i=0; i<256; ++i ) - { - colors[i].r = (pcolors[i]>>16)&0xFF; - colors[i].g = (pcolors[i]>>8)&0xFF; - colors[i].b = (pcolors[i]>>0)&0xFF; - } - - SDL_SetColors(surface, colors, 0, 256); - } - - virtual void *lock(void) - { - if ( SDL_MUSTLOCK(surface) ) - { - while ( SDL_LockSurface(surface) < 0 ) - { - SDL_Delay(10); - } - } - - return (Uint8 *)surface->pixels; - } - - virtual void unlock(void) - { - if ( SDL_MUSTLOCK(surface) ) - { - SDL_UnlockSurface(surface); - } - } - - virtual void copy(Surface &dst, - const Area &srcarea, const Area &dstarea) - { - SDL_Rect srcrect, dstrect; - srcrect.x = srcarea.left(); - srcrect.y = srcarea.top(); - srcrect.w = srcarea.width(); - srcrect.h = srcarea.height(); - dstrect.x = dstarea.left(); - dstrect.y = dstarea.top(); - dstrect.w = dstarea.width(); - dstrect.h = dstarea.height(); - SDL_BlitSurface(surface, &srcrect, dst.surface, &dstrect); - dst.updates[dst.nupdates++] = dstrect; - } - virtual void copy(Surface &dst) - { - SDL_Rect srcrect, dstrect; - srcrect.x = 0; - srcrect.y = 0; - srcrect.w = surface->w; - srcrect.h = surface->h; - dstrect.x = 0; - dstrect.y = 0; - dstrect.w = surface->w; - dstrect.h = surface->h; - SDL_LowerBlit(surface, &srcrect, dst.surface, &dstrect); - dst.updates[dst.nupdates++] = dstrect; - } - - virtual void update(void) - { - SDL_UpdateRects(surface, nupdates, updates); - nupdates = 0; - } - -protected: - SDL_Surface *surface; - int nupdates; - SDL_Rect updates[1]; /* Definitely increase this.. */ - int is_console; -}; - -class Console : public Surface -{ - int fullscreen; -public: - Console() : Surface() - { - fullscreen=0; - } - ~Console() - { - - SDL_Quit(); - } - void close(void) - { - SDL_Quit(); - } - void option(char *option) - { - if (!stricmp(option,"fullscreen output")) - { - fullscreen=1; - } - else if (!stricmp(option,"windowed output")) - { - fullscreen=0; - } - } - void open(const char *title, int width, int height, const Format &format) - { - uint32_t flags; - - if ( SDL_InitSubSystem(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0 ) - { - throw Error(SDL_GetError()); - } - - flags = (SDL_HWSURFACE|SDL_HWPALETTE); - - if (fullscreen) - { - flags|=SDL_FULLSCREEN; - } - - surface = SDL_SetVideoMode(width, height, 0, flags); - - if ( surface == NULL ) - { - throw Error(SDL_GetError()); - } - - SDL_WM_SetCaption(title, title); - } - - int key(void) - { - SDL_Event event; - int keyevent; - - keyevent = 0; - - while ( SDL_PollEvent(&event) ) - { - /* Real key events trigger this function */ - if ( event.type == SDL_KEYDOWN ) - { - keyevent = 1; - } - - /* So do quit events -- let the app know about it */ - if ( event.type == SDL_QUIT ) - { - keyevent = 1; - } - } - - return(keyevent); - } - -private: - -}; diff --git a/source/emulate.cpp b/source/emulate.cpp index 6015f87..ac45f5d 100644 --- a/source/emulate.cpp +++ b/source/emulate.cpp @@ -172,7 +172,6 @@ void ws_emulate(void) // 15 bits RGB555 //Format format(16, 0x007c00, 0x00003e0, 0x0000001f); - //Console console; //Surface *surface; if (app_rotated) { From 564e0ea2e6dfe46390b3ced58e167ff6709177c0 Mon Sep 17 00:00:00 2001 From: Godzil Date: Sat, 14 Nov 2020 20:27:58 +0000 Subject: [PATCH 25/32] Remove more SDL references --- main.cpp | 4 ---- source/CMakeLists.txt | 2 +- source/emulate.h | 1 - 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/main.cpp b/main.cpp index 2348391..52fca57 100644 --- a/main.cpp +++ b/main.cpp @@ -15,7 +15,6 @@ #include #include #include -#include "SDL.h" #include "source/log.h" #include "source/rom.h" #include "source/nec/nec.h" @@ -122,9 +121,6 @@ int ws_mk_ieppath() int main(int argc, char *argv[]) { - atexit(SDL_Quit); - SDL_Init(SDL_INIT_TIMER); - if (!log_init(LOG_PATH)) { printf("Warning: cannot open log file %s\n",LOG_PATH); diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index ecab385..5c39c49 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -1,5 +1,5 @@ set(SOURCES audio.cpp emulate.cpp gpu.cpp io.cpp log.cpp memory.cpp rom.cpp ws.cpp) -set(HEADERS audio.h emulate.h gpu.h ieeprom.h initialIo.h io.h log.h memory.h rom.h SDLptc.h ws.h) +set(HEADERS audio.h emulate.h gpu.h ieeprom.h initialIo.h io.h log.h memory.h rom.h ws.h) add_library(wswan ${SOURCES} ${HEADERS}) diff --git a/source/emulate.h b/source/emulate.h index 296a9c1..339e8ff 100644 --- a/source/emulate.h +++ b/source/emulate.h @@ -21,7 +21,6 @@ extern char app_window_title[256]; extern int app_gameRunning; extern int app_terminate; extern int app_fullscreen; -extern SDL_Event app_input_event; extern int app_rotated; From 8bd2170f44a1bd1b08ff205e3987156214e1bd50 Mon Sep 17 00:00:00 2001 From: Godzil Date: Sat, 14 Nov 2020 20:28:31 +0000 Subject: [PATCH 26/32] Remove some of the Rotation code. And add a call placeholder for read_key for now to make the compiler happy. --- source/emulate.cpp | 211 +++++++++++++-------------------------------- 1 file changed, 60 insertions(+), 151 deletions(-) diff --git a/source/emulate.cpp b/source/emulate.cpp index ac45f5d..0a42162 100644 --- a/source/emulate.cpp +++ b/source/emulate.cpp @@ -163,6 +163,8 @@ static void read_keys() //////////////////////////////////////////////////////////////////////////////// void ws_emulate(void) { + // Placeholder + read_keys(); #if 0 int32_t nCount = 0; int i = 0; @@ -173,176 +175,83 @@ void ws_emulate(void) // 15 bits RGB555 //Format format(16, 0x007c00, 0x00003e0, 0x0000001f); //Surface *surface; - if (app_rotated) + surface = new Surface(224 * 2, 144 * 2, format); + int16_t *backbuffer = (int16_t *)malloc(224 * 144 * sizeof(int16_t)); + memset(backbuffer, 0x00, 224 * 144 * sizeof(int16_t)); + surfacePitch = (surface->pitch() >> 1); + + dNormalLast = (double)SDL_GetTicks(); + + //console.open(app_window_title, 224 * 2, 144 * 2, format); + + while (1) { - surface = new Surface(144 * 2, 224 * 2, format); - int16_t *backbuffer = (int16_t *)malloc(224 * 144 * sizeof(int16_t)); - memset(backbuffer, 0x00, 224 * 144 * sizeof(int16_t)); - surfacePitch = (surface->pitch() >> 1); - dNormalLast = (double)SDL_GetTicks(); + dTemp = (double)SDL_GetTicks(); + dTime = dTemp - dNormalLast; - console.open(app_window_title, 144 * 2, 224 * 2, format); - while (1) + nCount = (int32_t)(dTime * 0.07547); // does this calculation make sense? + + if (nCount <= 0) + { + SDL_Delay(2); + } // No need to do anything for a bit + else { - dTemp = (double)SDL_GetTicks(); - dTime = dTemp - dNormalLast; + dNormalLast += nCount * (1 / 0.07547); - nCount = (int32_t)(dTime * 0.07547); // does this calculation make sense? - - if (nCount <= 0) + if (nCount > 10) { - SDL_Delay(2); - } // No need to do anything for a bit - else - { - - dNormalLast += nCount * (1 / 0.07547); - - if (nCount > 10) - { - nCount = 10; - } - - read_keys(); - - if (ws_key_esc) - { - console.close(); - - app_terminate = 1; - - if ((ws_rom_path != NULL) || (app_terminate)) - { - break; - } - - console.open(app_window_title, 144 * 2, 224 * 2, format); - - } - - - for (i = 0 ; i < nCount - 1 ; i++) - { - while (!ws_executeLine(backbuffer, 0)) - { - } - } - - while (!ws_executeLine(backbuffer, 1)) - { - } - - - ws_rotate_backbuffer(backbuffer); - - int16_t *vs = (int16_t *)surface->lock(); - int16_t *backbuffer_alias = backbuffer; - - for (int line = 0 ; line < 224 ; line++) - { - ws_drawDoubledRotatedScanline(vs, backbuffer_alias); - vs += surfacePitch; - ws_drawDoubledRotatedScanline(vs, backbuffer_alias); - vs += surfacePitch; - backbuffer_alias += 144; - } - - surface->unlock(); - surface->copy(console); - console.update(); + nCount = 10; } - } - console.close(); - delete surface; + read_keys(); - } - else - { - surface = new Surface(224 * 2, 144 * 2, format); - int16_t *backbuffer = (int16_t *)malloc(224 * 144 * sizeof(int16_t)); - memset(backbuffer, 0x00, 224 * 144 * sizeof(int16_t)); - surfacePitch = (surface->pitch() >> 1); - - dNormalLast = (double)SDL_GetTicks(); - - console.open(app_window_title, 224 * 2, 144 * 2, format); - - while (1) - { - - dTemp = (double)SDL_GetTicks(); - dTime = dTemp - dNormalLast; - - - nCount = (int32_t)(dTime * 0.07547); // does this calculation make sense? - - if (nCount <= 0) + if (ws_key_esc) { - SDL_Delay(2); - } // No need to do anything for a bit - else - { - - dNormalLast += nCount * (1 / 0.07547); + app_terminate = 1; - if (nCount > 10) + if ((ws_rom_path != NULL) || (app_terminate)) { - nCount = 10; + break; } - read_keys(); + //console.open(app_window_title, 224 * 2, 144 * 2, format); - if (ws_key_esc) - { - console.close(); - - app_terminate = 1; - - if ((ws_rom_path != NULL) || (app_terminate)) - { - break; - } - - console.open(app_window_title, 224 * 2, 144 * 2, format); - - } - - - for (i = 0 ; i < nCount - 1 ; i++) - { - while (!ws_executeLine(backbuffer, 0)) - { - } - } - - while (!ws_executeLine(backbuffer, 1)) - { - } - - int16_t *vs = (int16_t *)surface->lock(); - int16_t *backbuffer_alias = backbuffer; - - for (int line = 0 ; line < 144 ; line++) - { - ws_drawDoubledScanline(vs, backbuffer_alias); - vs += surfacePitch; - ws_drawDoubledScanline(vs, backbuffer_alias); - vs += surfacePitch; - backbuffer_alias += 224; - } - - surface->unlock(); - surface->copy(console); - console.update(); } - } - console.close(); - delete surface; + + for (i = 0 ; i < nCount - 1 ; i++) + { + while (!ws_executeLine(backbuffer, 0)) + { + } + } + + while (!ws_executeLine(backbuffer, 1)) + { + } + + int16_t *vs = (int16_t *)surface->lock(); + int16_t *backbuffer_alias = backbuffer; + + for (int line = 0 ; line < 144 ; line++) + { + ws_drawDoubledScanline(vs, backbuffer_alias); + vs += surfacePitch; + ws_drawDoubledScanline(vs, backbuffer_alias); + vs += surfacePitch; + backbuffer_alias += 224; + } + + //surface->unlock(); + //surface->copy(console); + //console.update(); + } + //console.close(); + //delete surface; } #endif } From 875f0edb46a7ee91a4a6a696458ec860702a13bd Mon Sep 17 00:00:00 2001 From: Godzil Date: Sat, 14 Nov 2020 20:30:09 +0000 Subject: [PATCH 27/32] printf can be a pain at time. --- source/memory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/memory.cpp b/source/memory.cpp index 38130f4..931a77a 100644 --- a/source/memory.cpp +++ b/source/memory.cpp @@ -252,7 +252,7 @@ char *load_file(char *filename) fstat(fd, &FileStat); - printf("Trying to load %s, size = %lu...\n",filename, FileStat.st_size); + printf("Trying to load %s, size = %lu...\n",filename, (unsigned long)FileStat.st_size); ret_ptr = (char *)mmap(NULL, FileStat.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); From 88468d602822df20479eb3d4de99d245f745f96a Mon Sep 17 00:00:00 2001 From: Godzil Date: Sat, 12 Dec 2020 19:28:21 +0000 Subject: [PATCH 28/32] Now build without SDL But of course, display nothing. --- Makefile | 2 +- source/emulate.cpp | 27 ++++++++------------------- source/ws.cpp | 1 + 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index b80df9c..62f72a7 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ OBJS = $(wonderswan_CXX_SRCS:.cpp=.o) all: wonderswan dumpinfo # CXX = g++ -CXXFLAGS = -g -O2 `sdl-config --cflags` -Wall -Werror -std=c++98 -Wno-write-strings -Wno-unused-result +CXXFLAGS = -g -O2 `sdl-config --cflags` -Wall -std=c++98 -Wno-write-strings -Wno-unused-result OPTIONS = -D_REENTRANT -I. -DVERSION=\"`git describe --tags --long --dirty`\" LIBRARY_PATH = diff --git a/source/emulate.cpp b/source/emulate.cpp index 0a42162..4e9f486 100644 --- a/source/emulate.cpp +++ b/source/emulate.cpp @@ -165,29 +165,29 @@ void ws_emulate(void) { // Placeholder read_keys(); -#if 0 + int32_t nCount = 0; int i = 0; double dTime = 0.0, dNormalLast = 0.0, dTemp; - int32_t surfacePitch; + //int32_t surfacePitch; // 15 bits RGB555 //Format format(16, 0x007c00, 0x00003e0, 0x0000001f); //Surface *surface; - surface = new Surface(224 * 2, 144 * 2, format); + //surface = new Surface(224 * 2, 144 * 2, format); int16_t *backbuffer = (int16_t *)malloc(224 * 144 * sizeof(int16_t)); memset(backbuffer, 0x00, 224 * 144 * sizeof(int16_t)); - surfacePitch = (surface->pitch() >> 1); + //surfacePitch = (surface->pitch() >> 1); - dNormalLast = (double)SDL_GetTicks(); + //dNormalLast = (double)SDL_GetTicks(); //console.open(app_window_title, 224 * 2, 144 * 2, format); while (1) { - dTemp = (double)SDL_GetTicks(); + dTemp = 1;//(double)SDL_GetTicks(); dTime = dTemp - dNormalLast; @@ -195,7 +195,7 @@ void ws_emulate(void) if (nCount <= 0) { - SDL_Delay(2); + //SDL_Delay(2); } // No need to do anything for a bit else { @@ -234,17 +234,7 @@ void ws_emulate(void) { } - int16_t *vs = (int16_t *)surface->lock(); - int16_t *backbuffer_alias = backbuffer; - - for (int line = 0 ; line < 144 ; line++) - { - ws_drawDoubledScanline(vs, backbuffer_alias); - vs += surfacePitch; - ws_drawDoubledScanline(vs, backbuffer_alias); - vs += surfacePitch; - backbuffer_alias += 224; - } + //int16_t *backbuffer_alias = backbuffer; //surface->unlock(); //surface->copy(console); @@ -253,5 +243,4 @@ void ws_emulate(void) //console.close(); //delete surface; } -#endif } diff --git a/source/ws.cpp b/source/ws.cpp index 788abb5..6a40147 100644 --- a/source/ws.cpp +++ b/source/ws.cpp @@ -191,6 +191,7 @@ int ws_executeLine(int16_t *framebuffer, int renderLine) // update scanline register ws_ioRam[2]=ws_gpu_scanline; + /* Why twice like that and random cycle count???? */ ws_cycles=nec_execute((ws_cyclesByLine>>1)+(rand()&7)); ws_cycles+=nec_execute((ws_cyclesByLine>>1)+(rand()&7)); From a89e253d9cc542092f9c350a95b5f197cc6a2392 Mon Sep 17 00:00:00 2001 From: Godzil Date: Sun, 4 Apr 2021 20:55:40 +0100 Subject: [PATCH 29/32] Now use glfw/OpenGL for displaying. Code is a bit crude, but the whole emulator would need a proper refactor at some point anyway. --- source/CMakeLists.txt | 2 +- source/emulate.cpp | 290 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 235 insertions(+), 57 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 5c39c49..1fdb108 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -3,7 +3,7 @@ set(HEADERS audio.h emulate.h gpu.h ieeprom.h initialIo.h io.h log.h memory.h ro add_library(wswan ${SOURCES} ${HEADERS}) -target_link_libraries(wswan nec_v30) +target_link_libraries(wswan nec_v30 glfw ${OPENGL_glu_LIBRARY} ${OPENGL_gl_LIBRARY}) target_include_directories(wswan PUBLIC .) diff --git a/source/emulate.cpp b/source/emulate.cpp index 4e9f486..9557a79 100644 --- a/source/emulate.cpp +++ b/source/emulate.cpp @@ -19,6 +19,15 @@ #include /* Error number definitions */ #include /* POSIX terminal control definitions */ #include +#include + +#define GLFW_INCLUDE_GLEXT +#define GL_SILENCE_DEPRECATION +#include +/* "Apple" fix */ +#ifndef GL_TEXTURE_RECTANGLE +#define GL_TEXTURE_RECTANGLE GL_TEXTURE_RECTANGLE_EXT +#endif #include "log.h" #include "io.h" @@ -39,19 +48,205 @@ int app_rotated=0; int ws_key_esc = 0; +/* Open GL stuffs */ +typedef struct GLWindow_t GLWindow; +struct KeyArray +{ + uint8_t lastState; + uint8_t curState; + uint8_t debounced; + GLFWwindow *window; +}; +struct GLWindow_t +{ + struct KeyArray keyArray[512]; + GLFWwindow *windows; + uint8_t *videoMemory; + GLuint videoTexture; + int WIDTH; + int HEIGHT; +}; +static GLWindow mainWindow; +static int window_num = 0; +static void ShowScreen(GLWindow *g, int w, int h) +{ + glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture); + + // glTexSubImage2D is faster when not using a texture range + glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0, 0, 0, w, h, + GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, g->videoMemory); + glBegin(GL_QUADS); + + glTexCoord2f(0.0f, 0.0f); + glVertex2f(-1.0f, 1.0f); + + glTexCoord2f(0.0f, h); + glVertex2f(-1.0f, -1.0f); + + glTexCoord2f(w, h); + glVertex2f(1.0f, -1.0f); + + glTexCoord2f(w, 0.0f); + glVertex2f(1.0f, 1.0f); + glEnd(); + + glFlush(); +} +static void GLWindowInitEx(GLWindow *g, int w, int h) +{ + g->WIDTH = w; + g->HEIGHT = h; + g->videoTexture = window_num++; +} +static void setupGL(GLWindow *g, int w, int h) +{ + g->videoMemory = (uint8_t *)malloc(w * h * sizeof(uint16_t)); + memset(g->videoMemory, 0, w * h * sizeof(uint16_t)); + //Tell OpenGL how to convert from coordinates to pixel values + glViewport(0, 0, w, h); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glClearColor(1.0f, 0.f, 1.0f, 1.0f); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glDisable(GL_TEXTURE_2D); + glEnable(GL_TEXTURE_RECTANGLE); + glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture); + + // glTextureRangeAPPLE(GL_TEXTURE_RECTANGLE_NV_EXT, 0, NULL); + + // glTexParameteri(GL_TEXTURE_RECTANGLE_NV_EXT, GL_TEXTURE_STORAGE_HINT_APPLE , GL_STORAGE_CACHED_APPLE); + // glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE); + glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + + glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, g->videoMemory); + + glDisable(GL_DEPTH_TEST); +} +void restoreGL(GLWindow *g) +{ + //Tell OpenGL how to convert from coordinates to pixel values + glViewport(0, 0, g->WIDTH, g->HEIGHT); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glClearColor(1.0f, 0.f, 1.0f, 1.0f); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glDisable(GL_TEXTURE_2D); + glEnable(GL_TEXTURE_RECTANGLE); + glDisable(GL_DEPTH_TEST); +} +static void kbHandler(GLFWwindow *window, int key, int scan, int action, int mod) +{ + struct KeyArray *keyArray; + + keyArray = (struct KeyArray *)glfwGetWindowUserPointer(window); + + keyArray[key].lastState = keyArray[key].curState; + if (action == GLFW_RELEASE) + { + keyArray[key].curState = GLFW_RELEASE; + } + else + { + keyArray[key].curState = GLFW_PRESS; + } + keyArray[key].debounced |= (keyArray[key].lastState == GLFW_RELEASE) && (keyArray[key].curState == GLFW_PRESS); + keyArray[key].window = window; + /*printf("key:%d, state:%d debounce:%d, laststate:%d\n", key, keyArray[key].curState, + keyArray[key].debounced, keyArray[key].lastState);*/ +} +static void sizeHandler(GLFWwindow *window, int xs, int ys) +{ + glfwMakeContextCurrent(window); + glViewport(0, 0, xs, ys); + ShowScreen(&mainWindow, 244, 144); +} +static void error_callback(int error, const char *description) +{ + puts(description); +} +static void initDisplay(GLWindow *g) +{ + int h = g->HEIGHT; + int w = g->WIDTH; + + /// Initialize GLFW + glfwInit(); + + glfwSetErrorCallback(error_callback); + + // Open screen OpenGL window + if (!(g->windows = glfwCreateWindow(g->WIDTH, g->HEIGHT, "Main", NULL, NULL))) + { + glfwTerminate(); + fprintf(stderr, "Window creation error...\n"); + abort(); + } + + glfwSetWindowAspectRatio(g->windows, 244, 144); + + glfwMakeContextCurrent(g->windows); + setupGL(g, g->WIDTH, g->HEIGHT); + + glfwSwapInterval(1); // We need vsync + + glfwGetWindowSize(g->windows, &w, &h); + + glfwSetWindowUserPointer(g->windows, g->keyArray); + + glfwSetKeyCallback(g->windows, kbHandler); + glfwSetWindowSizeCallback(g->windows, sizeHandler); +} +static void clearScreen(GLWindow *g) +{ + memset(g->videoMemory, 0, sizeof(uint8_t) * g->WIDTH * g->HEIGHT * 4); +} +static void updateScreen(GLWindow *g) +{ + /* Update windows code */ + glfwMakeContextCurrent(g->windows); + ShowScreen(g, g->WIDTH, g->HEIGHT); + glfwSwapBuffers(g->windows); + glfwPollEvents(); +} +uint64_t getTicks() +{ + struct timeval curTime; + uint64_t ticks; + /* Get datetime */ + gettimeofday(&curTime, NULL); + + ticks = (curTime.tv_sec* 1000) + curTime.tv_usec / 1000; + + return ticks; +} + +static inline int getKeyState(int key) +{ + return mainWindow.keyArray[key].curState; +} static void read_keys() { -#if 0 - while ( SDL_PollEvent(&app_input_event) ) - { - if ( app_input_event.type == SDL_QUIT ) - { - ws_key_esc = 1; - } - } - -#endif ws_key_start=0; ws_key_x4=0; ws_key_x2=0; @@ -64,90 +259,86 @@ static void read_keys() ws_key_button_a=0; ws_key_button_b=0; -#if 0 - uint8_t *keystate = SDL_GetKeyState(NULL); - - if ( keystate[SDLK_e]) + if (getKeyState(GLFW_KEY_E)) { dump_memory(); } - if ( keystate[SDLK_r]) + if (getKeyState(GLFW_KEY_R)) { printf("Boop\n"); ws_reset(); } - if ( keystate[SDLK_ESCAPE] ) + if (getKeyState(GLFW_KEY_ESCAPE)) { ws_key_esc = 1; } - if ( keystate[SDLK_UP] ) + if ( getKeyState(GLFW_KEY_UP)) { ws_key_x1=1; } - if ( keystate[SDLK_DOWN] ) + if ( getKeyState(GLFW_KEY_DOWN)) { ws_key_x3=1; } - if ( keystate[SDLK_RIGHT] ) + if (getKeyState(GLFW_KEY_RIGHT)) { ws_key_x2=1; } - if ( keystate[SDLK_LEFT] ) + if (getKeyState(GLFW_KEY_LEFT)) { ws_key_x4=1; } - if (keystate[SDLK_RETURN]) + if (getKeyState(GLFW_KEY_ENTER)) { ws_key_start=1; } - if (keystate[SDLK_c]) + if (getKeyState(GLFW_KEY_C)) { ws_key_button_a=1; } - if (keystate[SDLK_x]) + if (getKeyState(GLFW_KEY_X)) { ws_key_button_b=1; } - if (keystate[SDLK_w]) + if (getKeyState(GLFW_KEY_W)) { ws_key_y1=1; } - if (keystate[SDLK_a]) + if (getKeyState(GLFW_KEY_A)) { ws_key_y4=1; } - if (keystate[SDLK_s]) + if (getKeyState(GLFW_KEY_S)) { ws_key_y3=1; } - if (keystate[SDLK_d]) + if (getKeyState(GLFW_KEY_D)) { ws_key_y2=1; } - if (keystate[SDLK_o]) + if (getKeyState(GLFW_KEY_O)) { ws_cyclesByLine+=10; } - if (keystate[SDLK_l]) + if (getKeyState(GLFW_KEY_L)) { ws_cyclesByLine-=10; } -#endif } //////////////////////////////////////////////////////////////////////////////// @@ -163,31 +354,26 @@ static void read_keys() //////////////////////////////////////////////////////////////////////////////// void ws_emulate(void) { - // Placeholder - read_keys(); - int32_t nCount = 0; int i = 0; double dTime = 0.0, dNormalLast = 0.0, dTemp; - //int32_t surfacePitch; -// 15 bits RGB555 + // 15 bits RGB555 //Format format(16, 0x007c00, 0x00003e0, 0x0000001f); - //Surface *surface; - //surface = new Surface(224 * 2, 144 * 2, format); - int16_t *backbuffer = (int16_t *)malloc(224 * 144 * sizeof(int16_t)); - memset(backbuffer, 0x00, 224 * 144 * sizeof(int16_t)); - //surfacePitch = (surface->pitch() >> 1); + GLWindowInitEx(&mainWindow, 224, 144); + initDisplay(&mainWindow); + clearScreen(&mainWindow); + updateScreen(&mainWindow); + int16_t *backBuffer = (int16_t *)mainWindow.videoMemory; - //dNormalLast = (double)SDL_GetTicks(); - //console.open(app_window_title, 224 * 2, 144 * 2, format); + dNormalLast = (double)getTicks(); while (1) { - dTemp = 1;//(double)SDL_GetTicks(); + dTemp = getTicks(); dTime = dTemp - dNormalLast; @@ -195,7 +381,8 @@ void ws_emulate(void) if (nCount <= 0) { - //SDL_Delay(2); + /* Sleep for 2ms */ + usleep(2000); } // No need to do anything for a bit else { @@ -217,30 +404,21 @@ void ws_emulate(void) { break; } - - //console.open(app_window_title, 224 * 2, 144 * 2, format); - } for (i = 0 ; i < nCount - 1 ; i++) { - while (!ws_executeLine(backbuffer, 0)) + while (!ws_executeLine(backBuffer, 0)) { } } - while (!ws_executeLine(backbuffer, 1)) + while (!ws_executeLine(backBuffer, 1)) { } - //int16_t *backbuffer_alias = backbuffer; - - //surface->unlock(); - //surface->copy(console); - //console.update(); + updateScreen(&mainWindow); } - //console.close(); - //delete surface; } } From e4cf98bfe1b811abec1ffd9a3195e94b5c041dfc Mon Sep 17 00:00:00 2001 From: Godzil Date: Sun, 4 Apr 2021 21:05:48 +0100 Subject: [PATCH 30/32] Add a debug function to log all access to IO regs. --- source/io.cpp | 22 ++++++++++++++++++++++ source/nec/nec.cpp | 10 ++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/source/io.cpp b/source/io.cpp index 400b816..7cc3be8 100644 --- a/source/io.cpp +++ b/source/io.cpp @@ -29,10 +29,13 @@ #include "audio.h" #include "memory.h" +#define IO_DUMP + extern uint8_t *externalEeprom; extern uint32_t romAddressMask; extern uint16_t *internalEeprom; extern nec_Regs I; +extern uint64_t nec_monotonicCycles; enum { @@ -86,6 +89,8 @@ uint8_t ws_key_flipped; int rtcDataRegisterReadCount=0; +FILE *ioLogFp = NULL; + //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// @@ -139,6 +144,10 @@ void ws_io_init(void) ws_io_reset(); ws_key_flipped=0; + +#ifdef IO_DUMP + ioLogFp = fopen("iodump.csv", "wt"); +#endif } //////////////////////////////////////////////////////////////////////////////// // @@ -172,6 +181,10 @@ void ws_io_done(void) { free(ws_ioRam); } + +#ifdef IO_DUMP + fclose(ioLogFp); +#endif } /* Serial port */ @@ -582,6 +595,10 @@ uint8_t cpu_readport(uint8_t port) exit: + if (ioLogFp) + { + fprintf(ioLogFp, "%ld, R, %02X, %02X\n", nec_monotonicCycles, port, retVal); + } return retVal; } //////////////////////////////////////////////////////////////////////////////// @@ -600,6 +617,11 @@ void cpu_writeport(uint32_t port,uint8_t value) int unknown_io_port=0; + if (ioLogFp) + { + fprintf(ioLogFp, "%ld, W, %02X, %02X\n", nec_monotonicCycles, port, value); + } + if (port > 0x100) { port &= 0xFF; diff --git a/source/nec/nec.cpp b/source/nec/nec.cpp index ff79ac1..1f4b76f 100644 --- a/source/nec/nec.cpp +++ b/source/nec/nec.cpp @@ -38,6 +38,7 @@ /* cpu state */ /***************************************************************************/ +uint64_t nec_monotonicCycles; int nec_ICount; nec_Regs I; @@ -65,6 +66,7 @@ void nec_reset (void *param) unsigned int i,j,c; BREGS reg_name[8]= { AL, CL, DL, BL, AH, CH, DH, BH }; + nec_monotonicCycles = 0; memset( &I, 0, sizeof(I) ); @@ -3912,7 +3914,7 @@ const char *instructionsName[256] = int nec_execute(int cycles) { - + int done; nec_ICount=cycles; // cpu_type=V30; @@ -3928,6 +3930,10 @@ int nec_execute(int cycles) // nec_ICount++; } - return cycles - nec_ICount; + done = cycles - nec_ICount; + + nec_monotonicCycles += done; + + return done; } From f32928b0c3a9cef5442ca39d98a85e0f4da071a2 Mon Sep 17 00:00:00 2001 From: Godzil Date: Sun, 4 Apr 2021 21:14:53 +0100 Subject: [PATCH 31/32] Remove -Werror by default and add a cmake option to enable them. --- CMakeLists.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 709090d..ea3f693 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,8 +17,15 @@ find_package(OpenGL REQUIRED) include_directories(${OPENGL_INCLUDE_DIR}) -set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-unused-result -Wno-write-strings -Werror") -set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-unused-result -Wno-write-strings -Werror") +option(WARN_AS_ERROR "Enable warning as error" OFF) + +set(COMP_FLAGS "-march=native -Wall -Wextra -Wno-unused-parameter -Wno-unused-result -Wno-write-strings") +if (WARN_AS_ERROR) + set(COMP_FLAGS "${COMP_FLAGS} -Werror") +endif() + +set(CMAKE_C_FLAGS ${COMP_FLAGS}) +set(CMAKE_CXX_FLAGS ${COMP_FLAGS}) message("-- Building version ${VERSION}") From e28317d29ebbedab3e7f54cc51359d29fb0a2cb8 Mon Sep 17 00:00:00 2001 From: Godzil Date: Sun, 4 Apr 2021 21:17:34 +0100 Subject: [PATCH 32/32] Disable the IO Dump by default. --- source/io.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/io.cpp b/source/io.cpp index 7cc3be8..9191c79 100644 --- a/source/io.cpp +++ b/source/io.cpp @@ -29,7 +29,7 @@ #include "audio.h" #include "memory.h" -#define IO_DUMP +//#define IO_DUMP extern uint8_t *externalEeprom; extern uint32_t romAddressMask;