Compare commits
49 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01ffa3a834 | ||
|
|
fce2815300 | ||
|
|
662a45d02f | ||
|
|
bb324dc12e | ||
|
|
017983f692 | ||
|
|
b4b1bd83d0 | ||
|
|
a85e1ff083 | ||
|
|
4c9ba704ea | ||
|
|
8fa2ef06ab | ||
|
|
4fc5193bc7 | ||
|
|
1df15b0192 | ||
|
|
6f539fff1e | ||
|
|
c90b99d650 | ||
|
|
49a1943cda | ||
|
|
4082d37cb0 | ||
|
|
146e2b2c1d | ||
|
|
698d960bed | ||
|
|
62c5812b34 | ||
|
|
7f7410c8f8 | ||
|
|
0e02ee829f | ||
|
|
4512def23a | ||
|
|
46e90dcca1 | ||
|
|
2e9685215b | ||
|
|
bddcaddf1f | ||
|
|
5559269387 | ||
|
|
b3c0a39d00 | ||
|
|
8ab6b20815 | ||
|
|
dd53d5bfd9 | ||
|
|
5ba3560378 | ||
|
|
ac3779e640 | ||
|
|
da26704390 | ||
|
|
2ced18d151 | ||
|
|
359b05a518 | ||
|
|
3771c65f2c | ||
|
|
4f4e4d148a | ||
|
|
cc1060775c | ||
|
|
4e5f796d6a | ||
|
|
3818e03e55 | ||
|
|
94dc2fc463 | ||
|
|
d45d838378 | ||
|
|
18d9038639 | ||
|
|
925bfd3b65 | ||
|
|
330262b55c | ||
|
|
357d4e4ede | ||
|
|
d45822951f | ||
|
|
864fda651d | ||
|
|
065849cf68 | ||
|
|
dbc7d6e940 | ||
|
|
432844304e |
38
.github/workflows/cmake.yml
vendored
Normal file
38
.github/workflows/cmake.yml
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
name: CMake
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
env:
|
||||||
|
BUILD_TYPE: Release
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
continue-on-error: ${{ matrix.allow_failure }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ ubuntu-18.04, ubuntu-20.04, ubuntu-latest ]
|
||||||
|
allow_failure: [ false ]
|
||||||
|
# include:
|
||||||
|
# - os: macos-latest
|
||||||
|
# allow_failure: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
|
||||||
|
- name: Install needed dependencies
|
||||||
|
run: sudo apt update && sudo apt install xorg-dev libglu1-mesa-dev
|
||||||
|
|
||||||
|
- name: Configure CMake
|
||||||
|
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
|
||||||
|
|
||||||
62
.github/workflows/codeql-analysis.yml
vendored
Normal file
62
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
# For most projects, this workflow file will not need changing; you simply need
|
||||||
|
# to commit it to your repository.
|
||||||
|
#
|
||||||
|
# You may wish to alter this file to override the set of languages analyzed,
|
||||||
|
# or to provide custom queries or build logic.
|
||||||
|
#
|
||||||
|
# ******** NOTE ********
|
||||||
|
# We have attempted to detect the languages in your repository. Please check
|
||||||
|
# the `language` matrix defined below to confirm you have the correct set of
|
||||||
|
# supported CodeQL languages.
|
||||||
|
#
|
||||||
|
name: "CodeQL"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: [ master ]
|
||||||
|
schedule:
|
||||||
|
- cron: '43 19 * * 5'
|
||||||
|
|
||||||
|
env:
|
||||||
|
BUILD_TYPE: Debug
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
name: Analyze
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
language: [ 'cpp' ]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
|
||||||
|
- name: Install needed dependencies
|
||||||
|
run: sudo apt update && sudo apt install xorg-dev libglu1-mesa-dev
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v1
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
|
||||||
|
- name: Running Cmake
|
||||||
|
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
|
||||||
|
|
||||||
|
- name: Building
|
||||||
|
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v1
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,6 +8,7 @@
|
|||||||
*.orig
|
*.orig
|
||||||
*.rej
|
*.rej
|
||||||
rom/
|
rom/
|
||||||
|
ROMs/
|
||||||
.idea/
|
.idea/
|
||||||
*.zip
|
*.zip
|
||||||
*.sav
|
*.sav
|
||||||
|
|||||||
71
.travis.yml
71
.travis.yml
@@ -1,38 +1,63 @@
|
|||||||
dist: bionic
|
|
||||||
language: c
|
language: c
|
||||||
os:
|
|
||||||
- linux
|
|
||||||
# - osx
|
|
||||||
#matrix:
|
|
||||||
# allow_failures:
|
|
||||||
# - os: osx
|
|
||||||
|
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
packages:
|
packages:
|
||||||
- libsdl1.2debian
|
- xorg-dev
|
||||||
- libsdl1.2-dev
|
- libglu1-mesa-dev
|
||||||
|
|
||||||
compiler:
|
|
||||||
- clang
|
|
||||||
- gcc
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- make
|
|
||||||
- mkdir build
|
- mkdir build
|
||||||
- cd build
|
- cd build
|
||||||
- cmake ..
|
- cmake ..
|
||||||
- make
|
- make
|
||||||
|
|
||||||
cache:
|
jobs:
|
||||||
directories:
|
include:
|
||||||
- '$HOME/.sonar/cache'
|
- os: linux
|
||||||
|
dist: bionic
|
||||||
|
arch: amd64
|
||||||
|
compiler: gcc
|
||||||
|
|
||||||
#before_install:
|
- os: linux
|
||||||
# - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
|
dist: bionic
|
||||||
# - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install glew; fi
|
arch: amd64
|
||||||
|
compiler: clang
|
||||||
|
|
||||||
#install: true
|
- os: linux
|
||||||
|
dist: focal
|
||||||
|
arch: amd64
|
||||||
|
compiler: gcc
|
||||||
|
|
||||||
#after_success:
|
- os: linux
|
||||||
# - bash <(curl -s https://codecov.io/bash)
|
dist: focal
|
||||||
|
arch: amd64
|
||||||
|
compiler: clang
|
||||||
|
|
||||||
|
|
||||||
|
- os: osx
|
||||||
|
compiler: clang
|
||||||
|
osx_image: xcode12.2
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
dist: focal
|
||||||
|
arch: arm64
|
||||||
|
compiler: gcc
|
||||||
|
|
||||||
|
- os: osx
|
||||||
|
compiler: clang
|
||||||
|
osx_image: xcode10.3
|
||||||
|
|
||||||
|
- os: osx
|
||||||
|
compiler: clang
|
||||||
|
osx_image: xcode11.6
|
||||||
|
|
||||||
|
- os: osx
|
||||||
|
compiler: clang
|
||||||
|
osx_image: xcode12
|
||||||
|
|
||||||
|
allow_failures:
|
||||||
|
- os: linux
|
||||||
|
arch: arm64
|
||||||
|
|
||||||
|
- os: osx
|
||||||
|
|||||||
@@ -29,15 +29,23 @@ set(CMAKE_CXX_FLAGS ${COMP_FLAGS})
|
|||||||
|
|
||||||
message("-- Building version ${VERSION}")
|
message("-- Building version ${VERSION}")
|
||||||
|
|
||||||
add_executable(wonderswan main.cpp)
|
add_executable(wonderswan main.c)
|
||||||
|
|
||||||
set_property(TARGET wonderswan PROPERTY CXX_STANDARD 98)
|
set_property(TARGET wonderswan PROPERTY CXX_STANDARD 98)
|
||||||
|
|
||||||
target_compile_definitions(wonderswan PUBLIC VERSION="${VERSION}")
|
target_compile_definitions(wonderswan PUBLIC VERSION="${VERSION}")
|
||||||
target_include_directories(wonderswan PUBLIC source)
|
target_include_directories(wonderswan PUBLIC source)
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
TARGET wonderswan POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
${CMAKE_SOURCE_DIR}/irom_stub/*.bin
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/
|
||||||
|
)
|
||||||
|
|
||||||
add_subdirectory(source)
|
add_subdirectory(source)
|
||||||
|
|
||||||
target_link_libraries(wonderswan wswan glfw ${OPENGL_glu_LIBRARY} ${OPENGL_gl_LIBRARY})
|
target_link_libraries(wonderswan wswan glfw ${OPENGL_glu_LIBRARY} ${OPENGL_gl_LIBRARY})
|
||||||
|
|
||||||
add_executable(dumpinfo dumpinfo.c)
|
add_executable(dumpinfo dumpinfo.c)
|
||||||
|
add_executable(testserial testserial.c)
|
||||||
57
Makefile
57
Makefile
@@ -1,57 +0,0 @@
|
|||||||
|
|
||||||
wonderswan_CXX_SRCS = main.cpp \
|
|
||||||
source/audio.cpp \
|
|
||||||
source/gpu.cpp \
|
|
||||||
source/io.cpp \
|
|
||||||
source/log.cpp \
|
|
||||||
source/memory.cpp \
|
|
||||||
source/emulate.cpp \
|
|
||||||
source/rom.cpp \
|
|
||||||
source/ws.cpp \
|
|
||||||
source/nec/nec.cpp
|
|
||||||
|
|
||||||
OBJS = $(wonderswan_CXX_SRCS:.cpp=.o)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
all: wonderswan dumpinfo
|
|
||||||
|
|
||||||
# CXX = g++
|
|
||||||
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 =
|
|
||||||
SDL_LIBS = `sdl-config --libs`
|
|
||||||
LIBS = -g $(LIBRARY_PATH) $(SDL_LIBS)
|
|
||||||
|
|
||||||
ALLCFLAGS = $(CFLAGS) $(CEXTRA) $(OPTIONS) $(ALLFLAGS)
|
|
||||||
ALLCXXFLAGS=$(CXXFLAGS) $(CXXEXTRA) $(OPTIONS) $(ALLFLAGS)
|
|
||||||
|
|
||||||
CLEAN_FILES = wonderswan
|
|
||||||
|
|
||||||
.SUFFIXES: .cpp
|
|
||||||
|
|
||||||
main.o: main.cpp
|
|
||||||
|
|
||||||
.c.o:
|
|
||||||
$(CC) -c $(ALLCFLAGS) -o $@ $<
|
|
||||||
|
|
||||||
.cpp.o:
|
|
||||||
$(CXX) -c $(ALLCXXFLAGS) -o $@ $<
|
|
||||||
|
|
||||||
.PHONY: all install uninstall clean distclean depend dummy
|
|
||||||
|
|
||||||
$(SUBDIRS:%=%/__clean__): dummy
|
|
||||||
cd `dirname $@` && $(MAKE) clean
|
|
||||||
|
|
||||||
$(EXTRASUBDIRS:%=%/__clean__): dummy
|
|
||||||
-cd `dirname $@` && $(RM) $(CLEAN_FILES)
|
|
||||||
|
|
||||||
clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
|
|
||||||
$(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(OBJS) $(EXES:%.exe=%) $(EXES:%=%.so) $(EXES:%=%.spec.o) $(DLLS:%=%.so) $(DLLS:%=%.spec.o)
|
|
||||||
|
|
||||||
dumpinfo: dumpinfo.o
|
|
||||||
$(CXX) $(LIBS) -o $@ $(<)
|
|
||||||
|
|
||||||
wonderswan: $(OBJS)
|
|
||||||
$(CXX) -o $@ $(OBJS) $(LIBS)
|
|
||||||
76
README.md
Normal file
76
README.md
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
NewOswan *(name likely to change)*
|
||||||
|
==================================
|
||||||
|
[](https://github.com/Godzil/NewOswan/actions/workflows/cmake.yml)
|
||||||
|
|
||||||
|
### What is this project?
|
||||||
|
NewOswan is a WonderSwan emulator originally based on oswan-unix and heavily modified to be more accurate and better
|
||||||
|
hardware support.
|
||||||
|
|
||||||
|
### I don't care about the blabla, just show me the thing running
|
||||||
|
|
||||||
|
Ok ok, here are some screenshots:
|
||||||
|
|
||||||
|
Using a Swan Crystal boot rom:
|
||||||
|

|
||||||
|
|
||||||
|
Wonderswan Crystal boot splash:
|
||||||
|

|
||||||
|
|
||||||
|
Clock Tower:
|
||||||
|

|
||||||
|
|
||||||
|
Star Hearts:
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
### What's different from oswan-unix?
|
||||||
|
|
||||||
|
A couple of things:
|
||||||
|
|
||||||
|
- NewOswan do properly support the internal EEPROM and cartridge EEPROM.
|
||||||
|
The original version was based in improper and innacurate hardware documentation and was accessing and storing the
|
||||||
|
information in an incorrect way.
|
||||||
|
- NewOswan support the internal bootrom of all the three model of the WonderSwan.
|
||||||
|
- NewOswan also provide stub version for the bootrom if you don't own the original console, you can still
|
||||||
|
use the emulator withtout copyright infreigement. (no copyrighted materiel is included with the emulator for obvious
|
||||||
|
reasons)
|
||||||
|
- NewOswan use OpenGL instead of SDL
|
||||||
|
- Sound is currently not supported
|
||||||
|
- NewOswan is currently not meant as a fully operational emulator as this project mostly started as a way to test game
|
||||||
|
and the original hardware. Still the idea is to make it overtime as accurate as possible
|
||||||
|
- It is now pure C (the original code was based on a C project with some unneeded C++ here and there)
|
||||||
|
- 64-Bit clean, the original code was making assumption on some type size that can break on a 64bit system
|
||||||
|
- Build and run on Mac OS X, Linux x86 and ARM, and probably more systems.
|
||||||
|
- Some crude debugging tools that can only be enabled at compile time
|
||||||
|
- Tons of fancy logs in the console! Like:
|
||||||
|
```
|
||||||
|
IEEP: RA:143F RD:0006 A:03F C:WRI - Write? Yes : 0006
|
||||||
|
IEEP: RA:1440 RD:0101 A:040 C:WRI - Write? Yes : 0101
|
||||||
|
IEEP: RA:1441 RD:0016 A:041 C:WRI - Write? Yes : 0016
|
||||||
|
IEEP: RA:1442 RD:0000 A:042 C:WRI - Write? Yes : 0000
|
||||||
|
WriteIO(6A, 00) [F000:0018h];
|
||||||
|
WriteIO(6B, 00) [F000:0018h];
|
||||||
|
Icons H
|
||||||
|
WriteIO(6A, 00) [F000:0018h];
|
||||||
|
WriteIO(6B, 00) [F000:0018h];
|
||||||
|
```
|
||||||
|
- And many more thing I probably forgot about as this project was originally not version managed as it was just a crude
|
||||||
|
hack on the original code and are not in the logs.
|
||||||
|
|
||||||
|
### Futur plans
|
||||||
|
- Complete refactor of the code.
|
||||||
|
- Add a proper CPU debugger
|
||||||
|
- Add other nice debugging tool like the GPU status and other things that could be needed. Acheiving the level of the tools
|
||||||
|
provided by the NES emulator [Mesen](https://www.mesen.ca) would be nice.
|
||||||
|
- Being able to rotate the screen
|
||||||
|
- Maybe being able to change the game at runtime instead of start time
|
||||||
|
- Full Audio support
|
||||||
|
|
||||||
|
|
||||||
|
### The boot rom stubs
|
||||||
|
You can find the source and file in the `irom_stub` folder.
|
||||||
|
They are identical and for now provide only the logic to boot a cart. There is no bootsplash nor configuration menu.
|
||||||
|
A bootsplash may be added later.
|
||||||
|
|
||||||
|
Feel free to use these stub for your own emulator if you wish, just be nice and put a line saying you are using it and
|
||||||
|
a link to this project in your documentation :)
|
||||||
BIN
doc/bootsplash.png
Normal file
BIN
doc/bootsplash.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 334 KiB |
BIN
doc/clocktower.png
Normal file
BIN
doc/clocktower.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 593 KiB |
BIN
doc/configmenu.png
Normal file
BIN
doc/configmenu.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 345 KiB |
BIN
doc/starhearts1.png
Normal file
BIN
doc/starhearts1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 576 KiB |
BIN
doc/starhearts2.png
Normal file
BIN
doc/starhearts2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 715 KiB |
25
dumpinfo.c
25
dumpinfo.c
@@ -1,3 +1,11 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* NewOswan
|
||||||
|
* dumpinfo.c: Tool to dump the metadata info about a cart rom image.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -69,12 +77,11 @@ int main(int argc, char *argv[])
|
|||||||
printf("%s:\n", argv[1]);
|
printf("%s:\n", argv[1]);
|
||||||
if (data->farjump[0] == 0xEA)
|
if (data->farjump[0] == 0xEA)
|
||||||
{
|
{
|
||||||
printf("[%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x]",
|
printf("[%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x]", data->publishId, data->gameId[0],
|
||||||
data->publishId, data->gameId[0], data->gameId[1], data->flags2, data->romInfo, data->saveInfo,
|
data->gameId[1], data->flags2, data->romInfo, data->saveInfo, data->flags & 0xFF,
|
||||||
data->flags & 0xFF, (data->flags>>8) & 0xFF, data->crc & 0xFF, (data->crc>>8) & 0xFF);
|
(data->flags >> 8) & 0xFF, data->crc & 0xFF, (data->crc >> 8) & 0xFF);
|
||||||
printf(" - Reset @ %02X%02X:%02X%02Xh\n",
|
printf(" - Reset @ %02X%02X:%02X%02Xh\n", data->farjump[4], data->farjump[3], data->farjump[2],
|
||||||
data->farjump[4], data->farjump[3],
|
data->farjump[1]);
|
||||||
data->farjump[2], data->farjump[1]);
|
|
||||||
|
|
||||||
printf(" - publisher: %02X, gameId: %01X%02X\n", data->publishId, data->gameId[0], data->gameId[1]);
|
printf(" - publisher: %02X, gameId: %01X%02X\n", data->publishId, data->gameId[0], data->gameId[1]);
|
||||||
printf(" - %s want to write to EEPROM\n", data->flags2 & 0x80 ? "Do" : "Do not");
|
printf(" - %s want to write to EEPROM\n", data->flags2 & 0x80 ? "Do" : "Do not");
|
||||||
@@ -82,10 +89,8 @@ int main(int argc, char *argv[])
|
|||||||
printf(" - Is %sbootable on a normal swan\n", data->flagExt & 0x0F ? "not " : "");
|
printf(" - Is %sbootable on a normal swan\n", data->flagExt & 0x0F ? "not " : "");
|
||||||
printf(" - ROM Size: %02Xh\n", data->romInfo);
|
printf(" - ROM Size: %02Xh\n", data->romInfo);
|
||||||
printf(" - Save type & Size: %02Xh\n", data->saveInfo);
|
printf(" - Save type & Size: %02Xh\n", data->saveInfo);
|
||||||
printf(" - Flags: %d cycles ROM, %d bit ROM bus, %sRTC, %s orientation\n",
|
printf(" - Flags: %d cycles ROM, %d bit ROM bus, %sRTC, %s orientation\n", data->flags & 0x004 ? 1 : 3,
|
||||||
data->flags & 0x004?1:3,
|
data->flags & 0x002 ? 8 : 16, data->flags & 0x100 ? "" : "No ",
|
||||||
data->flags & 0x002?8:16,
|
|
||||||
data->flags & 0x100?"":"No ",
|
|
||||||
data->flags & 0x001 ? "Vertical" : "Horizontal");
|
data->flags & 0x001 ? "Vertical" : "Horizontal");
|
||||||
printf(" - CRC: %04Xh\n", data->crc);
|
printf(" - CRC: %04Xh\n", data->crc);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|||||||
20
irom_stub/Makefile
Normal file
20
irom_stub/Makefile
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
.PHONY: all clean
|
||||||
|
|
||||||
|
all: ws_irom.bin wsc_irom.bin wc_irom.bin
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@echo " RM"
|
||||||
|
@rm -f *.bin
|
||||||
|
|
||||||
|
ws_irom.bin: irom_stub.asm
|
||||||
|
@echo " AS $@"
|
||||||
|
@nasm $^ -o $@ -DWONDERSWAN=1
|
||||||
|
|
||||||
|
wsc_irom.bin: irom_stub.asm
|
||||||
|
@echo " AS $@"
|
||||||
|
@nasm $^ -o $@ -DWONDERSWANCOLOR=1
|
||||||
|
|
||||||
|
wc_irom.bin: irom_stub.asm
|
||||||
|
@echo " AS $@"
|
||||||
|
@nasm $^ -o $@ -DSWANCRYSTAL=1
|
||||||
|
|
||||||
110
irom_stub/irom_stub.asm
Normal file
110
irom_stub/irom_stub.asm
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
; WonderSwan Internal ROM Stub
|
||||||
|
; --------------------------------------
|
||||||
|
; Version 1.0
|
||||||
|
|
||||||
|
; This is a replacement for the internal rom to prevent using/including any copyrighted material.
|
||||||
|
; It does nothing, just lauching the cartridge.
|
||||||
|
; It may later include a bootsplah.
|
||||||
|
|
||||||
|
%ifdef WONDERSWAN
|
||||||
|
%define ROM_SIZE 4096
|
||||||
|
%define ROM_SEG 0FF00h
|
||||||
|
%else
|
||||||
|
%define ROM_SIZE 8192
|
||||||
|
%define ROM_SEG 0FE00h
|
||||||
|
%endif
|
||||||
|
|
||||||
|
; Setup NASM for a 80186
|
||||||
|
bits 16
|
||||||
|
cpu 186
|
||||||
|
|
||||||
|
org 0000h
|
||||||
|
|
||||||
|
%define JUMPER_LOCATION 0000h:0400h
|
||||||
|
; ---------------------------------------------------------------------------------------------
|
||||||
|
; Boot ROM jumper
|
||||||
|
; ---------------------------------------------------------------------------------------------
|
||||||
|
; Lock the bootrom
|
||||||
|
; Clear a bit of itself
|
||||||
|
; Jump to FFFF:FFF0
|
||||||
|
;
|
||||||
|
; Must be copied to 0000:0400 then jmp 0000:0400
|
||||||
|
ram_jumper:
|
||||||
|
|
||||||
|
; Lock the boot rom away
|
||||||
|
IN al, 0A0h
|
||||||
|
OR al, 001h ; Bit 0 lock the boot rom
|
||||||
|
out 0A0h, al
|
||||||
|
|
||||||
|
mov ax, cs
|
||||||
|
mov es, ax
|
||||||
|
mov di, 0400h
|
||||||
|
mov cx, (.rm_te_end - ram_jumper)
|
||||||
|
xor ax, ax
|
||||||
|
xor bx, bx
|
||||||
|
.rm_te_end:
|
||||||
|
rep stosb
|
||||||
|
jmp 0FFFFh:00000h
|
||||||
|
ram_jumper_end:
|
||||||
|
|
||||||
|
_start:
|
||||||
|
cli
|
||||||
|
cld
|
||||||
|
push cs
|
||||||
|
pop ds
|
||||||
|
|
||||||
|
in al, 0A0h
|
||||||
|
; Bit 2 - 1 = cart using 16bit data bus
|
||||||
|
or al, 004h
|
||||||
|
out 0A0h, al
|
||||||
|
|
||||||
|
xor ax, ax
|
||||||
|
mov es, ax
|
||||||
|
|
||||||
|
; Clear the IRAM
|
||||||
|
mov di, 0
|
||||||
|
mov cx, 16384
|
||||||
|
xor al, al
|
||||||
|
rep stosb ; STOSB -> ES:DI
|
||||||
|
|
||||||
|
; Copy the jumper
|
||||||
|
mov si, ram_jumper
|
||||||
|
mov cx, (ram_jumper_end - ram_jumper)
|
||||||
|
mov di, 0400h
|
||||||
|
xor ax, ax
|
||||||
|
mov es, ax
|
||||||
|
rep movsb ; DS:SI -> ES:DI
|
||||||
|
|
||||||
|
; Do some register cleanup
|
||||||
|
mov al, 0FFh
|
||||||
|
out 0C0h, al
|
||||||
|
out 0C1h, al
|
||||||
|
out 0C2h, al
|
||||||
|
xor ax, ax
|
||||||
|
xor cx, cx
|
||||||
|
xor dx, dx
|
||||||
|
mov ds, ax
|
||||||
|
mov es, ax
|
||||||
|
|
||||||
|
; Jump to the jumper!
|
||||||
|
jmp JUMPER_LOCATION
|
||||||
|
|
||||||
|
%ifdef WONDERSWAN
|
||||||
|
db "WonderSwan"
|
||||||
|
%elifdef WONDERSWANCOLOR
|
||||||
|
db "WonderSwan Color"
|
||||||
|
%elifdef SWANCRYSTAL
|
||||||
|
db "WonderSwan Crystal"
|
||||||
|
%else
|
||||||
|
%endif
|
||||||
|
db " internal ROM Stub for NewOswan (c)2021 986-Studio"
|
||||||
|
; Create at the end of the block, add padding if needed
|
||||||
|
TIMES (ROM_SIZE - 16) - ($-$$) DB 0FFh
|
||||||
|
|
||||||
|
jmp ROM_SEG:_start ; 0
|
||||||
|
db 00 ; ?? ; 5
|
||||||
|
db 0F0h ; Dev ID ; 6
|
||||||
|
db 00 ; Min Swan type ; 7
|
||||||
|
db 00000100b ; flags ; C
|
||||||
|
db 01 ; No RTC ; D
|
||||||
|
dw 0FFFFh ; CRC (need to update it after, but as not used by the rom, no need for now)
|
||||||
BIN
irom_stub/wc_irom.bin
Normal file
BIN
irom_stub/wc_irom.bin
Normal file
Binary file not shown.
BIN
irom_stub/ws_irom.bin
Normal file
BIN
irom_stub/ws_irom.bin
Normal file
Binary file not shown.
BIN
irom_stub/wsc_irom.bin
Normal file
BIN
irom_stub/wsc_irom.bin
Normal file
Binary file not shown.
195
main.c
Normal file
195
main.c
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* NewOswan
|
||||||
|
* main.c: Entry point
|
||||||
|
* Based on the original Oswan-unix
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 13.04.2002: Fixed a small bug causing crashes
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "source/log.h"
|
||||||
|
#include "source/rom.h"
|
||||||
|
#include "source/nec/nec.h"
|
||||||
|
#include "source/memory.h"
|
||||||
|
#include "source/gpu.h"
|
||||||
|
#include "source/io.h"
|
||||||
|
#include "source/ws.h"
|
||||||
|
#include "source/emulate.h"
|
||||||
|
#include "source/audio.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#define LOG_PATH "oswan.log"
|
||||||
|
|
||||||
|
int sram_path_explicit = 0;
|
||||||
|
int ieep_path_explicit = 0;
|
||||||
|
|
||||||
|
int ws_mk_savpath()
|
||||||
|
{
|
||||||
|
char *w;
|
||||||
|
|
||||||
|
if (sram_path_explicit)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ws_sram_path != NULL)
|
||||||
|
{
|
||||||
|
free(ws_sram_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
ws_sram_path = (char *)malloc(strlen(ws_rom_path) + 2);
|
||||||
|
strcpy(ws_sram_path, ws_rom_path);
|
||||||
|
w = strrchr(ws_sram_path, '.');
|
||||||
|
|
||||||
|
if (NULL == w)
|
||||||
|
{
|
||||||
|
strcpy(ws_sram_path, "error.sav");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(w, ".sav");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ws_mk_ieppath()
|
||||||
|
{
|
||||||
|
char *w;
|
||||||
|
|
||||||
|
if (ieep_path_explicit)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ws_ieep_path != NULL)
|
||||||
|
{
|
||||||
|
free(ws_ieep_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
ws_ieep_path = (char *)malloc(strlen(ws_rom_path) + 2);
|
||||||
|
strcpy(ws_ieep_path, ws_rom_path);
|
||||||
|
w = strrchr(ws_ieep_path, '.');
|
||||||
|
|
||||||
|
if (NULL == w)
|
||||||
|
{
|
||||||
|
strcpy(ws_ieep_path, "error.iep");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(w, ".iep");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
wssystem_t ws_system = WS_SYSTEM_AUTODETECT;
|
||||||
|
|
||||||
|
snprintf(app_window_title, 255, "Oswan %s - Esc to return to GUI", VERSION);
|
||||||
|
|
||||||
|
Log(TLOG_ALWAYS, NULL, "NewOswan %s (built at: %s %s)", VERSION, __DATE__, __TIME__);
|
||||||
|
|
||||||
|
ws_rom_path = NULL;
|
||||||
|
|
||||||
|
for (int n = 1 ; n < argc ; ++n)
|
||||||
|
{
|
||||||
|
if (argv[n][0] == '-')
|
||||||
|
{
|
||||||
|
switch (argv[n][1])
|
||||||
|
{
|
||||||
|
case 'C':
|
||||||
|
if (++n < argc)
|
||||||
|
{
|
||||||
|
ws_cyclesByLine = atoi(argv[n]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log(TLOG_ALWAYS, "main", "Cycles by line set to %d", ws_cyclesByLine);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'w':
|
||||||
|
if (++n < argc)
|
||||||
|
{
|
||||||
|
ws_system = atoi(argv[n]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log(TLOG_ALWAYS, "main", "WonderSwan set to %d", ws_system);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
if (++n < argc)
|
||||||
|
{
|
||||||
|
ws_sram_path = argv[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
sram_path_explicit = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ws_rom_path = argv[n];
|
||||||
|
ws_mk_savpath();
|
||||||
|
ws_mk_ieppath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!app_terminate)
|
||||||
|
{
|
||||||
|
if (!ws_rom_path)
|
||||||
|
{
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ws_rom_path)
|
||||||
|
{
|
||||||
|
ws_set_system(ws_system);
|
||||||
|
if (ws_init(ws_rom_path))
|
||||||
|
{
|
||||||
|
ws_reset();
|
||||||
|
|
||||||
|
ws_emulate();
|
||||||
|
}
|
||||||
|
|
||||||
|
ws_done();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
216
main.cpp
216
main.cpp
@@ -1,216 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Wonderswan emulator
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// 13.04.2002: Fixed a small bug causing crashes
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include "source/log.h"
|
|
||||||
#include "source/rom.h"
|
|
||||||
#include "source/nec/nec.h"
|
|
||||||
#include "source/memory.h"
|
|
||||||
#include "source/gpu.h"
|
|
||||||
#include "source/io.h"
|
|
||||||
#include "source/ws.h"
|
|
||||||
#include "source/emulate.h"
|
|
||||||
#include "source/audio.h"
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
#define LOG_PATH "oswan.log"
|
|
||||||
|
|
||||||
|
|
||||||
int gui_command=GUI_COMMAND_NONE;
|
|
||||||
int gui_mainDialogRunning;
|
|
||||||
int gui_controls_configuration_Running;
|
|
||||||
int gui_get_key_Running;
|
|
||||||
int gui_get_key_key;
|
|
||||||
|
|
||||||
int ws_videoEnhancementType=0;
|
|
||||||
int ws_colourScheme=COLOUR_SCHEME_DEFAULT;
|
|
||||||
int ws_system=WS_SYSTEM_COLOR;
|
|
||||||
int sram_path_explicit = 0;
|
|
||||||
int ieep_path_explicit = 0;
|
|
||||||
|
|
||||||
int ws_mk_savpath()
|
|
||||||
{
|
|
||||||
char *w;
|
|
||||||
|
|
||||||
if (sram_path_explicit)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ws_sram_path != NULL)
|
|
||||||
{
|
|
||||||
free(ws_sram_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
ws_sram_path = (char *)malloc(strlen(ws_rom_path) + 2);
|
|
||||||
strcpy(ws_sram_path, ws_rom_path);
|
|
||||||
w = strrchr(ws_sram_path, '.');
|
|
||||||
|
|
||||||
if (NULL == w)
|
|
||||||
{
|
|
||||||
strcpy(ws_sram_path, "error.sav");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(w, ".sav");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ws_mk_ieppath()
|
|
||||||
{
|
|
||||||
char *w;
|
|
||||||
|
|
||||||
if (ieep_path_explicit)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ws_ieep_path != NULL)
|
|
||||||
{
|
|
||||||
free(ws_ieep_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
ws_ieep_path = (char *)malloc(strlen(ws_rom_path) + 2);
|
|
||||||
strcpy(ws_ieep_path, ws_rom_path);
|
|
||||||
w = strrchr(ws_ieep_path, '.');
|
|
||||||
|
|
||||||
if (NULL == w)
|
|
||||||
{
|
|
||||||
strcpy(ws_ieep_path, "error.iep");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(w, ".iep");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
if (!log_init(LOG_PATH))
|
|
||||||
{
|
|
||||||
printf("Warning: cannot open log file %s\n",LOG_PATH);
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(app_window_title, 255, "Oswan %s - Esc to return to GUI", VERSION);
|
|
||||||
|
|
||||||
fprintf(log_get(),"Oswan-unix %s (built at: %s %s)\n",VERSION , __DATE__,__TIME__);
|
|
||||||
|
|
||||||
ws_system = WS_SYSTEM_COLOR;
|
|
||||||
|
|
||||||
ws_rom_path = NULL;
|
|
||||||
|
|
||||||
for (int n = 1; n < argc; ++n)
|
|
||||||
{
|
|
||||||
if (argv[n][0] == '-')
|
|
||||||
{
|
|
||||||
switch(argv[n][1])
|
|
||||||
{
|
|
||||||
case 'C':
|
|
||||||
if (++n < argc)
|
|
||||||
{
|
|
||||||
ws_cyclesByLine = atoi(argv[n]);
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(log_get(), "Cycles by line set to %d\n", ws_cyclesByLine);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'w':
|
|
||||||
if (++n < argc)
|
|
||||||
{
|
|
||||||
ws_system = atoi(argv[n]);
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(log_get(), "WonderSwan set to %d\n", ws_system);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 's':
|
|
||||||
if (++n < argc)
|
|
||||||
{
|
|
||||||
ws_sram_path = argv[n];
|
|
||||||
}
|
|
||||||
|
|
||||||
sram_path_explicit = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ws_rom_path = argv[n];
|
|
||||||
ws_mk_savpath();
|
|
||||||
ws_mk_ieppath();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!app_terminate)
|
|
||||||
{
|
|
||||||
if (!ws_rom_path)
|
|
||||||
{
|
|
||||||
app_gameRunning=0;
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ws_rom_path)
|
|
||||||
{
|
|
||||||
ws_set_system(ws_system);
|
|
||||||
if (ws_init(ws_rom_path))
|
|
||||||
{
|
|
||||||
app_rotated=ws_rotated();
|
|
||||||
app_gameRunning=1;
|
|
||||||
|
|
||||||
if (ws_system == WS_SYSTEM_COLOR)
|
|
||||||
{
|
|
||||||
ws_gpu_operatingInColor=1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ws_set_colour_scheme(ws_colourScheme);
|
|
||||||
ws_reset();
|
|
||||||
|
|
||||||
ws_emulate();
|
|
||||||
}
|
|
||||||
|
|
||||||
ws_done();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log_done();
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
50
resource.h
50
resource.h
@@ -1,50 +0,0 @@
|
|||||||
//{{NO_DEPENDENCIES}}
|
|
||||||
// Microsoft Developer Studio generated include file.
|
|
||||||
// Used by gui.rc
|
|
||||||
//
|
|
||||||
#define IDD_DIALOG_MAIN 101
|
|
||||||
#define IDB_BITMAP1 102
|
|
||||||
#define IDB_BITMAP2 103
|
|
||||||
#define IDC_BUTTON_LOAD 1000
|
|
||||||
#define IDC_BUTTON_RESET 1001
|
|
||||||
#define IDC_BUTTON_EXIT 1002
|
|
||||||
#define IDC_RADIO1 1003
|
|
||||||
#define IDC_RADIO_WINDOWED 1003
|
|
||||||
#define IDC_RADIO2 1004
|
|
||||||
#define IDC_RADIO_FULLSCREEN 1004
|
|
||||||
#define IDC_BUTTON_LOADSTATE 1005
|
|
||||||
#define IDC_BUTTON_SAVESTATE 1006
|
|
||||||
#define IDC_RADIO3 1007
|
|
||||||
#define IDC_BUTTON_CONTINUE 1007
|
|
||||||
#define IDC_RADIO4 1008
|
|
||||||
#define IDC_BUTTON_CONTROLS 1008
|
|
||||||
#define IDC_RADIO5 1009
|
|
||||||
#define IDC_RADIO_STANDARD_MODE 1009
|
|
||||||
#define IDC_RADIO6 1010
|
|
||||||
#define IDC_RADIO_DOUBLESIZE_MODE 1010
|
|
||||||
#define IDC_RADIO7 1011
|
|
||||||
#define IDC_RADIO_SCANLINES_MODE 1011
|
|
||||||
#define IDC_RADIO8 1012
|
|
||||||
#define IDC_RADIO_50PRCTSCANLINES_MODE 1012
|
|
||||||
#define IDC_RADIO9 1013
|
|
||||||
#define IDC_RADIO_SPECIAL_MODE 1013
|
|
||||||
#define IDC_RADIO_SYSTEM_AUTODETECT 1014
|
|
||||||
#define IDC_RADIO_SYSTEM_MONO 1015
|
|
||||||
#define IDC_RADIO_SYSTEM_COLOR 1016
|
|
||||||
#define IDC_RADIO_2XSAI 1017
|
|
||||||
#define IDC_RADIO_SUPER2XSAI 1018
|
|
||||||
#define IDC_COLOUR_DEFAULT 1019
|
|
||||||
#define IDC_COLOUR_AMBER 1020
|
|
||||||
#define IDC_COLOUR_GREEN 1021
|
|
||||||
#define IDC_RADIO_SUPEREAGLE 1022
|
|
||||||
|
|
||||||
// Next default values for new objects
|
|
||||||
//
|
|
||||||
#ifdef APSTUDIO_INVOKED
|
|
||||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
|
||||||
#define _APS_NEXT_RESOURCE_VALUE 108
|
|
||||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
|
||||||
#define _APS_NEXT_CONTROL_VALUE 1021
|
|
||||||
#define _APS_NEXT_SYMED_VALUE 101
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
@@ -1,10 +1,16 @@
|
|||||||
set(SOURCES audio.cpp emulate.cpp gpu.cpp io.cpp log.cpp memory.cpp rom.cpp ws.cpp)
|
set(SOURCES audio.c emulate.c gpu.c io.c log.c memory.c rom.c ws.c)
|
||||||
set(HEADERS audio.h emulate.h gpu.h ieeprom.h initialIo.h io.h log.h memory.h rom.h ws.h)
|
set(HEADERS audio.h emulate.h gpu.h io.h log.h memory.h rom.h ws.h)
|
||||||
|
|
||||||
|
option(FAKE_DISPLAY "Disable OpenGL and fake displaying" OFF)
|
||||||
|
|
||||||
add_library(wswan ${SOURCES} ${HEADERS})
|
add_library(wswan ${SOURCES} ${HEADERS})
|
||||||
|
|
||||||
|
if (FAKE_DISPLAY)
|
||||||
|
target_compile_options(wswan PRIVATE -DPRETENT_DISPLAY)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_link_libraries(wswan nec_v30 glfw ${OPENGL_glu_LIBRARY} ${OPENGL_gl_LIBRARY})
|
target_link_libraries(wswan nec_v30 glfw ${OPENGL_glu_LIBRARY} ${OPENGL_gl_LIBRARY})
|
||||||
|
|
||||||
target_include_directories(wswan PUBLIC .)
|
target_include_directories(wswan PUBLIC . nec/)
|
||||||
|
|
||||||
add_subdirectory(nec)
|
add_subdirectory(nec)
|
||||||
1539
source/audio.c
Normal file
1539
source/audio.c
Normal file
File diff suppressed because it is too large
Load Diff
1514
source/audio.cpp
1514
source/audio.cpp
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,11 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
/*******************************************************************************
|
||||||
//
|
* NewOswan
|
||||||
|
* audio.h:
|
||||||
|
* Based on the original Oswan-unix
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@@ -12,6 +18,8 @@
|
|||||||
#ifndef __AUDIO_H__
|
#ifndef __AUDIO_H__
|
||||||
#define __AUDIO_H__
|
#define __AUDIO_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
void ws_audio_init();
|
void ws_audio_init();
|
||||||
void ws_audio_reset();
|
void ws_audio_reset();
|
||||||
void ws_audio_port_write(uint32_t port, uint8_t value);
|
void ws_audio_port_write(uint32_t port, uint8_t value);
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
/*******************************************************************************
|
||||||
// Main emulation loop
|
* NewOswan
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
* emulate.c:
|
||||||
|
* Based on the original Oswan-unix
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@@ -21,13 +27,16 @@
|
|||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#ifndef PRETENT_DISPLAY
|
||||||
#define GLFW_INCLUDE_GLEXT
|
#define GLFW_INCLUDE_GLEXT
|
||||||
#define GL_SILENCE_DEPRECATION
|
#define GL_SILENCE_DEPRECATION
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
/* "Apple" fix */
|
/* "Apple" fix */
|
||||||
#ifndef GL_TEXTURE_RECTANGLE
|
#ifndef GL_TEXTURE_RECTANGLE
|
||||||
#define GL_TEXTURE_RECTANGLE GL_TEXTURE_RECTANGLE_EXT
|
#define GL_TEXTURE_RECTANGLE GL_TEXTURE_RECTANGLE_EXT
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* PRETENT_DISPLAY */
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
@@ -40,14 +49,11 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
char app_window_title[256];
|
char app_window_title[256];
|
||||||
int app_gameRunning=0;
|
|
||||||
int app_terminate = 0;
|
int app_terminate = 0;
|
||||||
int app_fullscreen=0;
|
|
||||||
int app_rotated=0;
|
|
||||||
|
|
||||||
|
|
||||||
int ws_key_esc = 0;
|
int ws_key_esc = 0;
|
||||||
|
|
||||||
|
#ifndef PRETENT_DISPLAY
|
||||||
/* Open GL stuffs */
|
/* Open GL stuffs */
|
||||||
typedef struct GLWindow_t GLWindow;
|
typedef struct GLWindow_t GLWindow;
|
||||||
struct KeyArray
|
struct KeyArray
|
||||||
@@ -68,13 +74,13 @@ struct GLWindow_t
|
|||||||
};
|
};
|
||||||
static GLWindow mainWindow;
|
static GLWindow mainWindow;
|
||||||
static int window_num = 0;
|
static int window_num = 0;
|
||||||
|
|
||||||
static void ShowScreen(GLWindow *g, int w, int h)
|
static void ShowScreen(GLWindow *g, int w, int h)
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture);
|
glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture);
|
||||||
|
|
||||||
// glTexSubImage2D is faster when not using a texture range
|
// glTexSubImage2D is faster when not using a texture range
|
||||||
glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0, 0, 0, w, h,
|
glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, g->videoMemory);
|
||||||
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, g->videoMemory);
|
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
glTexCoord2f(0.0f, 0.0f);
|
glTexCoord2f(0.0f, 0.0f);
|
||||||
@@ -92,12 +98,14 @@ static void ShowScreen(GLWindow *g, int w, int h)
|
|||||||
|
|
||||||
glFlush();
|
glFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GLWindowInitEx(GLWindow *g, int w, int h)
|
static void GLWindowInitEx(GLWindow *g, int w, int h)
|
||||||
{
|
{
|
||||||
g->WIDTH = w;
|
g->WIDTH = w;
|
||||||
g->HEIGHT = h;
|
g->HEIGHT = h;
|
||||||
g->videoTexture = window_num++;
|
g->videoTexture = window_num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setupGL(GLWindow *g, int w, int h)
|
static void setupGL(GLWindow *g, int w, int h)
|
||||||
{
|
{
|
||||||
g->videoMemory = (uint8_t *)malloc(w * h * sizeof(uint16_t));
|
g->videoMemory = (uint8_t *)malloc(w * h * sizeof(uint16_t));
|
||||||
@@ -120,10 +128,6 @@ static void setupGL(GLWindow *g, int w, int h)
|
|||||||
glEnable(GL_TEXTURE_RECTANGLE);
|
glEnable(GL_TEXTURE_RECTANGLE);
|
||||||
glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture);
|
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_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_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_S, GL_CLAMP_TO_EDGE);
|
||||||
@@ -134,6 +138,7 @@ static void setupGL(GLWindow *g, int w, int h)
|
|||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
void restoreGL(GLWindow *g)
|
void restoreGL(GLWindow *g)
|
||||||
{
|
{
|
||||||
//Tell OpenGL how to convert from coordinates to pixel values
|
//Tell OpenGL how to convert from coordinates to pixel values
|
||||||
@@ -154,6 +159,7 @@ void restoreGL(GLWindow *g)
|
|||||||
glEnable(GL_TEXTURE_RECTANGLE);
|
glEnable(GL_TEXTURE_RECTANGLE);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kbHandler(GLFWwindow *window, int key, int scan, int action, int mod)
|
static void kbHandler(GLFWwindow *window, int key, int scan, int action, int mod)
|
||||||
{
|
{
|
||||||
struct KeyArray *keyArray;
|
struct KeyArray *keyArray;
|
||||||
@@ -174,16 +180,19 @@ static void kbHandler(GLFWwindow *window, int key, int scan, int action, int mod
|
|||||||
/*printf("key:%d, state:%d debounce:%d, laststate:%d\n", key, keyArray[key].curState,
|
/*printf("key:%d, state:%d debounce:%d, laststate:%d\n", key, keyArray[key].curState,
|
||||||
keyArray[key].debounced, keyArray[key].lastState);*/
|
keyArray[key].debounced, keyArray[key].lastState);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sizeHandler(GLFWwindow *window, int xs, int ys)
|
static void sizeHandler(GLFWwindow *window, int xs, int ys)
|
||||||
{
|
{
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
glViewport(0, 0, xs, ys);
|
glViewport(0, 0, xs, ys);
|
||||||
ShowScreen(&mainWindow, 244, 144);
|
ShowScreen(&mainWindow, 244, 144);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void error_callback(int error, const char *description)
|
static void error_callback(int error, const char *description)
|
||||||
{
|
{
|
||||||
puts(description);
|
puts(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void initDisplay(GLWindow *g)
|
static void initDisplay(GLWindow *g)
|
||||||
{
|
{
|
||||||
int h = g->HEIGHT;
|
int h = g->HEIGHT;
|
||||||
@@ -198,7 +207,7 @@ static void initDisplay(GLWindow *g)
|
|||||||
if (!(g->windows = glfwCreateWindow(g->WIDTH, g->HEIGHT, "Main", NULL, NULL)))
|
if (!(g->windows = glfwCreateWindow(g->WIDTH, g->HEIGHT, "Main", NULL, NULL)))
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
fprintf(stderr, "Window creation error...\n");
|
Log(TLOG_PANIC, "emulate", "Window creation error...");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,10 +225,12 @@ static void initDisplay(GLWindow *g)
|
|||||||
glfwSetKeyCallback(g->windows, kbHandler);
|
glfwSetKeyCallback(g->windows, kbHandler);
|
||||||
glfwSetWindowSizeCallback(g->windows, sizeHandler);
|
glfwSetWindowSizeCallback(g->windows, sizeHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clearScreen(GLWindow *g)
|
static void clearScreen(GLWindow *g)
|
||||||
{
|
{
|
||||||
memset(g->videoMemory, 0, sizeof(uint8_t) * g->WIDTH * g->HEIGHT * 4);
|
memset(g->videoMemory, 0, sizeof(uint16_t) * g->WIDTH * g->HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void updateScreen(GLWindow *g)
|
static void updateScreen(GLWindow *g)
|
||||||
{
|
{
|
||||||
/* Update windows code */
|
/* Update windows code */
|
||||||
@@ -228,17 +239,6 @@ static void updateScreen(GLWindow *g)
|
|||||||
glfwSwapBuffers(g->windows);
|
glfwSwapBuffers(g->windows);
|
||||||
glfwPollEvents();
|
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)
|
static inline int getKeyState(int key)
|
||||||
{
|
{
|
||||||
@@ -266,7 +266,7 @@ static void read_keys()
|
|||||||
|
|
||||||
if (getKeyState(GLFW_KEY_R))
|
if (getKeyState(GLFW_KEY_R))
|
||||||
{
|
{
|
||||||
printf("Boop\n");
|
Log(TLOG_DEBUG, "emulate", "Boop reset");
|
||||||
ws_reset();
|
ws_reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,6 +340,75 @@ static void read_keys()
|
|||||||
ws_cyclesByLine -= 10;
|
ws_cyclesByLine -= 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
typedef struct PseudoWindow_t
|
||||||
|
{
|
||||||
|
uint8_t *videoMemory;
|
||||||
|
int WIDTH;
|
||||||
|
int HEIGHT;
|
||||||
|
} PseudoWindow_t;
|
||||||
|
|
||||||
|
static PseudoWindow_t mainWindow;
|
||||||
|
|
||||||
|
static void GLWindowInitEx(PseudoWindow_t *g, int w, int h)
|
||||||
|
{
|
||||||
|
g->WIDTH = w;
|
||||||
|
g->HEIGHT = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void initDisplay(PseudoWindow_t *g)
|
||||||
|
{
|
||||||
|
int w = g->WIDTH;
|
||||||
|
int h = g->HEIGHT;
|
||||||
|
g->videoMemory = (uint8_t *)malloc(w * h * sizeof(uint16_t));
|
||||||
|
memset(g->videoMemory, 0, w * h * sizeof(uint16_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void clearScreen(PseudoWindow_t *g)
|
||||||
|
{
|
||||||
|
memset(g->videoMemory, 0, sizeof(uint16_t) * g->WIDTH * g->HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void updateScreen(PseudoWindow_t *g)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void read_keys()
|
||||||
|
{
|
||||||
|
static uint32_t i = 0;
|
||||||
|
|
||||||
|
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 (i > 1024)
|
||||||
|
{
|
||||||
|
ws_key_esc = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
#endif /* PRETENT_DISPLAY */
|
||||||
|
|
||||||
|
double getTicks()
|
||||||
|
{
|
||||||
|
struct timeval curTime;
|
||||||
|
double ticks;
|
||||||
|
/* Get datetime */
|
||||||
|
gettimeofday(&curTime, NULL);
|
||||||
|
|
||||||
|
ticks = (curTime.tv_sec * 1000.) + curTime.tv_usec / 1000.;
|
||||||
|
|
||||||
|
return ticks;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
@@ -368,7 +437,9 @@ void ws_emulate(void)
|
|||||||
int16_t *backBuffer = (int16_t *)mainWindow.videoMemory;
|
int16_t *backBuffer = (int16_t *)mainWindow.videoMemory;
|
||||||
|
|
||||||
|
|
||||||
dNormalLast = (double)getTicks();
|
dNormalLast = getTicks();
|
||||||
|
|
||||||
|
#define HCLK (1000. / 12000.)
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
@@ -376,18 +447,17 @@ void ws_emulate(void)
|
|||||||
dTemp = getTicks();
|
dTemp = getTicks();
|
||||||
dTime = dTemp - dNormalLast;
|
dTime = dTemp - dNormalLast;
|
||||||
|
|
||||||
|
nCount = (int32_t)(dTime * HCLK); // does this calculation make sense?
|
||||||
nCount = (int32_t)(dTime * 0.07547); // does this calculation make sense?
|
|
||||||
|
|
||||||
if (nCount <= 0)
|
if (nCount <= 0)
|
||||||
{
|
{
|
||||||
/* Sleep for 2ms */
|
/* Sleep for 500us */
|
||||||
usleep(2000);
|
usleep(500);
|
||||||
} // No need to do anything for a bit
|
} // No need to do anything for a bit
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
dNormalLast += nCount * (1 / 0.07547);
|
dNormalLast += nCount * (1 / HCLK);
|
||||||
|
|
||||||
if (nCount > 10)
|
if (nCount > 10)
|
||||||
{
|
{
|
||||||
@@ -406,7 +476,7 @@ void ws_emulate(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* What is this mess? Frameskip? */
|
||||||
for (i = 0 ; i < nCount - 1 ; i++)
|
for (i = 0 ; i < nCount - 1 ; i++)
|
||||||
{
|
{
|
||||||
while (!ws_executeLine(backBuffer, 0))
|
while (!ws_executeLine(backBuffer, 0))
|
||||||
@@ -1,30 +1,27 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* NewOswan
|
||||||
|
* emulate.h:
|
||||||
|
* Based on the original Oswan-unix
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
#ifndef EMULATE_H
|
#ifndef EMULATE_H
|
||||||
#define EMULATE_H
|
#define EMULATE_H
|
||||||
|
|
||||||
#define KEY_ENTER 0x0D
|
#include <stdint.h>
|
||||||
#define KEY_SPACE 0x20
|
|
||||||
#define KEY_ESC 0x1b
|
|
||||||
#define KEY_UP 0x26
|
|
||||||
#define KEY_DOWN 0x28
|
|
||||||
#define KEY_LEFT 0x25
|
|
||||||
#define KEY_RIGHT 0x27
|
|
||||||
#define KEY_BUTTON1 0x57
|
|
||||||
#define KEY_BUTTON2 0x58
|
|
||||||
|
|
||||||
#define GUI_COMMAND_NONE 0
|
|
||||||
#define GUI_COMMAND_RESET 1
|
|
||||||
#define GUI_COMMAND_SCHEME_CHANGE 2
|
|
||||||
#define GUI_COMMAND_FILTER_CHANGE 3
|
|
||||||
|
|
||||||
|
|
||||||
extern char app_window_title[256];
|
extern char app_window_title[256];
|
||||||
extern int app_gameRunning;
|
|
||||||
extern int app_terminate;
|
extern int app_terminate;
|
||||||
extern int app_fullscreen;
|
|
||||||
extern int app_rotated;
|
|
||||||
|
|
||||||
|
|
||||||
void ws_emulate(void);
|
void ws_emulate(void);
|
||||||
|
|
||||||
|
|
||||||
#endif /* EMULATE_H */
|
#endif /* EMULATE_H */
|
||||||
2082
source/gpu.c
Normal file
2082
source/gpu.c
Normal file
File diff suppressed because it is too large
Load Diff
2313
source/gpu.cpp
2313
source/gpu.cpp
File diff suppressed because it is too large
Load Diff
25
source/gpu.h
25
source/gpu.h
@@ -1,20 +1,15 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
/*******************************************************************************
|
||||||
//
|
* NewOswan
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
* gpu.h:
|
||||||
//
|
* Based on the original Oswan-unix
|
||||||
//
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
//
|
*
|
||||||
//
|
******************************************************************************/
|
||||||
//
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef __GPU_H__
|
#ifndef __GPU_H__
|
||||||
#define __GPU_H__
|
#define __GPU_H__
|
||||||
|
|
||||||
#define COLOUR_SCHEME_DEFAULT 0
|
#include <stdint.h>
|
||||||
#define COLOUR_SCHEME_AMBER 1
|
|
||||||
#define COLOUR_SCHEME_GREEN 2
|
|
||||||
|
|
||||||
extern uint8_t ws_gpu_scanline;
|
extern uint8_t ws_gpu_scanline;
|
||||||
extern uint8_t ws_gpu_operatingInColor;
|
extern uint8_t ws_gpu_operatingInColor;
|
||||||
@@ -26,7 +21,6 @@ extern unsigned int ws_gpu_unknownPort;
|
|||||||
|
|
||||||
extern uint32_t vblank_count;
|
extern uint32_t vblank_count;
|
||||||
|
|
||||||
|
|
||||||
void ws_gpu_init(void);
|
void ws_gpu_init(void);
|
||||||
void ws_gpu_done(void);
|
void ws_gpu_done(void);
|
||||||
void ws_gpu_reset(void);
|
void ws_gpu_reset(void);
|
||||||
@@ -35,10 +29,7 @@ void ws_gpu_changeVideoMode(uint8_t value);
|
|||||||
void ws_gpu_write_byte(uint32_t offset, uint8_t value);
|
void ws_gpu_write_byte(uint32_t offset, uint8_t value);
|
||||||
int ws_gpu_port_write(uint32_t port, uint8_t value);
|
int ws_gpu_port_write(uint32_t port, uint8_t value);
|
||||||
uint8_t ws_gpu_port_read(uint8_t port);
|
uint8_t ws_gpu_port_read(uint8_t port);
|
||||||
void ws_gpu_set_colour_scheme(int scheme);
|
|
||||||
void ws_gpu_changeVideoMode(uint8_t value);
|
void ws_gpu_changeVideoMode(uint8_t value);
|
||||||
void ws_gpu_forceColorSystem(void);
|
|
||||||
void ws_gpu_forceMonoSystem(void);
|
|
||||||
void ws_gpu_clearCache(void);
|
void ws_gpu_clearCache(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
191
source/ieeprom.h
191
source/ieeprom.h
@@ -1,191 +0,0 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
uint8_t DefaultBWEEprom[]=
|
|
||||||
{
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,192,0xff,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,127,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0x00,252,0xff,1,0xff,253,0xff,253,0xff,253,0xff,253,
|
|
||||||
0xff,253,0xff,253,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0x00,0x00,3,3,0x00,0x00,0x00,64,128,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
135,5,140,9,5,12,139,12,144,0x00,0x00,2,
|
|
||||||
0x00,76,165,0x00,128,0x00,0x00,0x00,0xff,127,0xff,127,
|
|
||||||
0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,
|
|
||||||
0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,
|
|
||||||
0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,
|
|
||||||
0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,
|
|
||||||
0xff,127,0xff,127,0xff,127,0xff,127,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0x00,0x00,6,6,6,6,6,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
1,128,15,0x00,1,1,1,15,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
'W'-54,'O'-54,'N'-54,'D'-54,'E'-54,'R'-54,'S'-54,'W'-54,'A'-54,'N'-54,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,32,1,1,33,1,4,0x00,1,
|
|
||||||
0x00,152,60,127,74,1,53,1,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t DefaultColorEEprom[]=
|
|
||||||
{
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,192,0xff,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,127,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0x00,252,0xff,1,0xff,253,0xff,253,0xff,253,0xff,253,
|
|
||||||
0xff,253,0xff,253,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0x00,0x00,3,3,0x00,0x00,0x00,64,128,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
135,5,140,9,5,12,139,12,144,0x00,0x00,2,
|
|
||||||
0x00,76,165,0x00,128,0x00,0x00,0x00,0xff,127,0xff,127,
|
|
||||||
0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,
|
|
||||||
0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,
|
|
||||||
0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,
|
|
||||||
0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,
|
|
||||||
0xff,127,0xff,127,0xff,127,0xff,127,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0x00,0x00,6,6,6,6,6,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
1,128,15,0x00,1,1,1,15,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
'W'-54,'O'-54,'N'-54,'D'-54,'E'-54,'R'-54,'S'-54,'W'-54,'A'-54,'N'-54,0x00,0x00,0x00,0x00,0x00,
|
|
||||||
0x00,32,1,1,33,1,4,0x00,1,
|
|
||||||
0x00,152,60,127,74,1,53,1,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
||||||
0xff,0xff,0xff,0xff
|
|
||||||
};
|
|
||||||
@@ -1,271 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Initial I/O values
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
uint8_t initialIoValue[256]=
|
|
||||||
{
|
|
||||||
0x00,//0
|
|
||||||
0x00,//1
|
|
||||||
0x9d,//2
|
|
||||||
0xbb,//3
|
|
||||||
0x00,//4
|
|
||||||
0x00,//5
|
|
||||||
0x00,//6
|
|
||||||
0x26,//7
|
|
||||||
0xfe,//8
|
|
||||||
0xde,//9
|
|
||||||
0xf9,//a
|
|
||||||
0xfb,//b
|
|
||||||
0xdb,//c
|
|
||||||
0xd7,//d
|
|
||||||
0x7f,//e
|
|
||||||
0xf5,//f
|
|
||||||
0x00,//10
|
|
||||||
0x00,//11
|
|
||||||
0x00,//12
|
|
||||||
0x00,//13
|
|
||||||
0x01,//14
|
|
||||||
0x00,//15
|
|
||||||
0x9e,//16
|
|
||||||
0x9b,//17
|
|
||||||
0x00,//18
|
|
||||||
0x00,//19
|
|
||||||
0x00,//1a
|
|
||||||
0x00,//1b
|
|
||||||
0x99,//1c
|
|
||||||
0xfd,//1d
|
|
||||||
0xb7,//1e
|
|
||||||
0xdf,//1f
|
|
||||||
0x30,//20
|
|
||||||
0x57,//21
|
|
||||||
0x75,//22
|
|
||||||
0x76,//23
|
|
||||||
0x15,//24
|
|
||||||
0x73,//25
|
|
||||||
0x77,//26
|
|
||||||
0x77,//27
|
|
||||||
0x20,//28
|
|
||||||
0x75,//29
|
|
||||||
0x50,//2a
|
|
||||||
0x36,//2b
|
|
||||||
0x70,//2c
|
|
||||||
0x67,//2d
|
|
||||||
0x50,//2e
|
|
||||||
0x77,//2f
|
|
||||||
0x57,//30
|
|
||||||
0x54,//31
|
|
||||||
0x75,//32
|
|
||||||
0x77,//33
|
|
||||||
0x75,//34
|
|
||||||
0x17,//35
|
|
||||||
0x37,//36
|
|
||||||
0x73,//37
|
|
||||||
0x50,//38
|
|
||||||
0x57,//39
|
|
||||||
0x60,//3a
|
|
||||||
0x77,//3b
|
|
||||||
0x70,//3c
|
|
||||||
0x77,//3d
|
|
||||||
0x10,//3e
|
|
||||||
0x73,//3f
|
|
||||||
0x00,//40
|
|
||||||
0x00,//41
|
|
||||||
0x00,//42
|
|
||||||
0x00,//43
|
|
||||||
0x00,//44
|
|
||||||
0x00,//45
|
|
||||||
0x00,//46
|
|
||||||
0x00,//47
|
|
||||||
0x00,//48
|
|
||||||
0x00,//49
|
|
||||||
0x00,//4a
|
|
||||||
0x00,//4b
|
|
||||||
0x00,//4c
|
|
||||||
0x00,//4d
|
|
||||||
0x00,//4e
|
|
||||||
0x00,//4f
|
|
||||||
0x00,//50
|
|
||||||
0x00,//51
|
|
||||||
0x00,//52
|
|
||||||
0x00,//53
|
|
||||||
0x00,//54
|
|
||||||
0x00,//55
|
|
||||||
0x00,//56
|
|
||||||
0x00,//57
|
|
||||||
0x00,//58
|
|
||||||
0x00,//59
|
|
||||||
0x00,//5a
|
|
||||||
0x00,//5b
|
|
||||||
0x00,//5c
|
|
||||||
0x00,//5d
|
|
||||||
0x00,//5e
|
|
||||||
0x00,//5f
|
|
||||||
0x0a,//60
|
|
||||||
0x00,//61
|
|
||||||
0x00,//62
|
|
||||||
0x00,//63
|
|
||||||
0x00,//64
|
|
||||||
0x00,//65
|
|
||||||
0x00,//66
|
|
||||||
0x00,//67
|
|
||||||
0x00,//68
|
|
||||||
0x00,//69
|
|
||||||
0x00,//6a
|
|
||||||
0x0f,//6b
|
|
||||||
0x00,//6c
|
|
||||||
0x00,//6d
|
|
||||||
0x00,//6e
|
|
||||||
0x00,//6f
|
|
||||||
0x00,//70
|
|
||||||
0x00,//71
|
|
||||||
0x00,//72
|
|
||||||
0x00,//73
|
|
||||||
0x00,//74
|
|
||||||
0x00,//75
|
|
||||||
0x00,//76
|
|
||||||
0x00,//77
|
|
||||||
0x00,//78
|
|
||||||
0x00,//79
|
|
||||||
0x00,//7a
|
|
||||||
0x00,//7b
|
|
||||||
0x00,//7c
|
|
||||||
0x00,//7d
|
|
||||||
0x00,//7e
|
|
||||||
0x00,//7f
|
|
||||||
0x00,//80
|
|
||||||
0x00,//81
|
|
||||||
0x00,//82
|
|
||||||
0x00,//83
|
|
||||||
0x00,//84
|
|
||||||
0x00,//85
|
|
||||||
0x00,//86
|
|
||||||
0x00,//87
|
|
||||||
0x00,//88
|
|
||||||
0x00,//89
|
|
||||||
0x00,//8a
|
|
||||||
0x00,//8b
|
|
||||||
0x00,//8c
|
|
||||||
0x1f,//8d 1d ?
|
|
||||||
0x00,//8e
|
|
||||||
0x00,//8f
|
|
||||||
0x00,//90
|
|
||||||
0x00,//91
|
|
||||||
0x00,//92
|
|
||||||
0x00,//93
|
|
||||||
0x00,//94
|
|
||||||
0x00,//95
|
|
||||||
0x00,//96
|
|
||||||
0x00,//97
|
|
||||||
0x00,//98
|
|
||||||
0x00,//99
|
|
||||||
0x00,//9a
|
|
||||||
0x00,//9b
|
|
||||||
0x00,//9c
|
|
||||||
0x00,//9d
|
|
||||||
0x03,//9e
|
|
||||||
0x00,//9f
|
|
||||||
0x80,//a0
|
|
||||||
0x00,//a1
|
|
||||||
0x00,//a2
|
|
||||||
0x00,//a3
|
|
||||||
0x0,//a4 2b
|
|
||||||
0x0,//a5 7f
|
|
||||||
0x4f,//a6
|
|
||||||
0xff,//a7 cf ?
|
|
||||||
0x00,//a8
|
|
||||||
0x00,//a9
|
|
||||||
0x00,//aa
|
|
||||||
0x00,//ab
|
|
||||||
0x00,//ac
|
|
||||||
0x00,//ad
|
|
||||||
0x00,//ae
|
|
||||||
0x00,//af
|
|
||||||
0x00,//b0
|
|
||||||
0xdb,//b1
|
|
||||||
0x00,//b2
|
|
||||||
0x00,//b3
|
|
||||||
0x00,//b4
|
|
||||||
0x40,//b5
|
|
||||||
0x00,//b6
|
|
||||||
0x00,//b7
|
|
||||||
0x00,//b8
|
|
||||||
0x00,//b9
|
|
||||||
0x01,//ba
|
|
||||||
0x00,//bb
|
|
||||||
0x42,//bc
|
|
||||||
0x00,//bd
|
|
||||||
0x83,//be
|
|
||||||
0x00,//bf
|
|
||||||
0x2f,//c0
|
|
||||||
0x3f,//c1
|
|
||||||
0xff,//c2
|
|
||||||
0xff,//c3
|
|
||||||
0x00,//c4
|
|
||||||
0x00,//c5
|
|
||||||
0x00,//c6
|
|
||||||
0x00,//c7
|
|
||||||
|
|
||||||
0xd1,//c8?
|
|
||||||
0xd1,//c9
|
|
||||||
0xd1,//ca
|
|
||||||
0xd1,//cb
|
|
||||||
0xd1,//cc
|
|
||||||
0xd1,//cd
|
|
||||||
0xd1,//ce
|
|
||||||
0xd1,//cf
|
|
||||||
0xd1,//d0
|
|
||||||
0xd1,//d1
|
|
||||||
0xd1,//d2
|
|
||||||
0xd1,//d3
|
|
||||||
0xd1,//d4
|
|
||||||
0xd1,//d5
|
|
||||||
0xd1,//d6
|
|
||||||
0xd1,//d7
|
|
||||||
0xd1,//d8
|
|
||||||
0xd1,//d9
|
|
||||||
0xd1,//da
|
|
||||||
0xd1,//db
|
|
||||||
0xd1,//dc
|
|
||||||
0xd1,//dd
|
|
||||||
0xd1,//de
|
|
||||||
0xd1,//df
|
|
||||||
0xd1,//e0
|
|
||||||
0xd1,//e1
|
|
||||||
0xd1,//e2
|
|
||||||
0xd1,//e3
|
|
||||||
0xd1,//e4
|
|
||||||
0xd1,//e5
|
|
||||||
0xd1,//e6
|
|
||||||
0xd1,//e7
|
|
||||||
0xd1,//e8
|
|
||||||
0xd1,//e9
|
|
||||||
0xd1,//ea
|
|
||||||
0xd1,//eb
|
|
||||||
0xd1,//ec
|
|
||||||
0xd1,//ed
|
|
||||||
0xd1,//ee
|
|
||||||
0xd1,//ef
|
|
||||||
0xd1,//f0
|
|
||||||
0xd1,//f1
|
|
||||||
0xd1,//f2
|
|
||||||
0xd1,//f3
|
|
||||||
0xd1,//f4
|
|
||||||
0xd1,//f5
|
|
||||||
0xd1,//f6
|
|
||||||
0xd1,//f7
|
|
||||||
0xd1,//f8
|
|
||||||
0xd1,//f9
|
|
||||||
0xd1,//fa
|
|
||||||
0xd1,//fb
|
|
||||||
0xd1,//fc
|
|
||||||
0xd1,//fd
|
|
||||||
0xd1,//fe
|
|
||||||
0xd1 //ff
|
|
||||||
};
|
|
||||||
1270
source/io.c
Normal file
1270
source/io.c
Normal file
File diff suppressed because it is too large
Load Diff
1114
source/io.cpp
1114
source/io.cpp
File diff suppressed because it is too large
Load Diff
23
source/io.h
23
source/io.h
@@ -1,5 +1,11 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
/*******************************************************************************
|
||||||
//
|
* NewOswan
|
||||||
|
* io.h:
|
||||||
|
* Based on the original Oswan-unix
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@@ -12,6 +18,8 @@
|
|||||||
#ifndef __IO_H__
|
#ifndef __IO_H__
|
||||||
#define __IO_H__
|
#define __IO_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
extern uint8_t *ws_ioRam;
|
extern uint8_t *ws_ioRam;
|
||||||
extern uint8_t ws_key_start;
|
extern uint8_t ws_key_start;
|
||||||
extern uint8_t ws_key_x4;
|
extern uint8_t ws_key_x4;
|
||||||
@@ -25,10 +33,13 @@ extern uint8_t ws_key_y3;
|
|||||||
extern uint8_t ws_key_button_a;
|
extern uint8_t ws_key_button_a;
|
||||||
extern uint8_t ws_key_button_b;
|
extern uint8_t ws_key_button_b;
|
||||||
|
|
||||||
void ws_io_init(void);
|
void io_init(void);
|
||||||
void ws_io_reset(void);
|
void io_reset(void);
|
||||||
void ws_io_flipControls(void);
|
void io_flipControls(void);
|
||||||
void ws_io_done(void);
|
void io_done(void);
|
||||||
|
|
||||||
|
uint8_t io_readport(uint8_t port);
|
||||||
|
void io_writeport(uint32_t port, uint8_t value);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
139
source/log.c
Normal file
139
source/log.c
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* NewOswan
|
||||||
|
* log.c: C Fancy Logger
|
||||||
|
* Copyright (c) 2009-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier on 20/01/2009.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#define __LOG_C_INTERNAL_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <log.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
|
void log_displayPanic(int signal)
|
||||||
|
{
|
||||||
|
size_t size = 0;
|
||||||
|
|
||||||
|
//size = backtrace(array, 30);
|
||||||
|
/* Now flood user with unusefull data. */
|
||||||
|
fprintf(stderr, FYELLOW "\n\n ----- " FYELLOW " YICK! ERROR YICK! [bt:%zu]" FYELLOW "----- \n", size);
|
||||||
|
|
||||||
|
// get void*'s for all entries on the stack
|
||||||
|
|
||||||
|
// print out all the frames to stderr
|
||||||
|
fprintf(stderr, " ----- Error: signal: %d -----\n" FRED, signal);
|
||||||
|
//backtrace_symbols_fd(array, size, 2);
|
||||||
|
fprintf(stderr, FYELLOW "\n\n ----- " FYELLOW " YICK! ERROR YICK! " FYELLOW "----- " CNORMAL "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void time_stamp_line(void)
|
||||||
|
{
|
||||||
|
/* Time "0" will be thefirst log line */
|
||||||
|
static char firstRun = 1;
|
||||||
|
static struct timeval firstTime;
|
||||||
|
struct timeval curTime;
|
||||||
|
|
||||||
|
int cMin, cSec;
|
||||||
|
long long cMSec;
|
||||||
|
|
||||||
|
/* Get datetime */
|
||||||
|
gettimeofday(&curTime, NULL);
|
||||||
|
|
||||||
|
if (firstRun == 1)
|
||||||
|
{
|
||||||
|
firstRun = 0;
|
||||||
|
firstTime.tv_sec = curTime.tv_sec;
|
||||||
|
firstTime.tv_usec = curTime.tv_usec;
|
||||||
|
}
|
||||||
|
|
||||||
|
cMSec = ((curTime.tv_sec - firstTime.tv_sec) * 1000) + (curTime.tv_usec - firstTime.tv_usec) / 1000;
|
||||||
|
cSec = (cMSec / 1000);
|
||||||
|
cMSec %= 1000;
|
||||||
|
|
||||||
|
cMin = cSec / 60;
|
||||||
|
|
||||||
|
cSec %= 60;
|
||||||
|
|
||||||
|
/* Put cursor at start of line */
|
||||||
|
fprintf(stderr, "%c[s", 0x1B);
|
||||||
|
fprintf(stderr, "%c[7000D", 0x1B);
|
||||||
|
fprintf(stderr, "%c[1C", 0x1B);
|
||||||
|
fprintf(stderr, FWHITE"[" FYELLOW "%03d" FRED "." FBLUE "%02d" FRED "." FGREEN "%03lld" FWHITE "]" CNORMAL, cMin,
|
||||||
|
cSec, cMSec);
|
||||||
|
fprintf(stderr, "%c[u", 0x1B);
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_real(int level, const char *user, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
va_list va;
|
||||||
|
|
||||||
|
/* The LOG_PANIC must always be displayed */
|
||||||
|
if ((level <= MAX_DEBUG_LEVEL) || (level <= TLOG_PANIC))
|
||||||
|
{
|
||||||
|
fprintf(stderr, CNORMAL);
|
||||||
|
time_stamp_line();
|
||||||
|
fprintf(stderr, CNORMAL " | ");
|
||||||
|
|
||||||
|
switch (level)
|
||||||
|
{
|
||||||
|
case TLOG_PANIC: fprintf(stderr, BRED FWHITE); break;
|
||||||
|
case TLOG_ERROR: fprintf(stderr, FRED); break;
|
||||||
|
case TLOG_WARNING: fprintf(stderr, FYELLOW); break;
|
||||||
|
default:
|
||||||
|
case TLOG_NORMAL: fprintf(stderr, FGREEN); break;
|
||||||
|
case TLOG_VERBOSE: fprintf(stderr, FCYAN); break;
|
||||||
|
case TLOG_DEBUG: fprintf(stderr, BBLUE FWHITE); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user != NULL)
|
||||||
|
{
|
||||||
|
i = strlen(user);
|
||||||
|
if (i < 12)
|
||||||
|
{
|
||||||
|
i = 12 - i;
|
||||||
|
for (; i >= 0 ; i--)
|
||||||
|
{
|
||||||
|
fprintf(stderr, " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fprintf(stderr, "%s", user);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (level)
|
||||||
|
{
|
||||||
|
case TLOG_PANIC: fprintf(stderr, " PANIC"); break;
|
||||||
|
case TLOG_ERROR: fprintf(stderr, " Error"); break;
|
||||||
|
case TLOG_WARNING: fprintf(stderr, " Warning"); break;
|
||||||
|
default:
|
||||||
|
case TLOG_NORMAL: fprintf(stderr, " Info"); break;
|
||||||
|
case TLOG_VERBOSE: fprintf(stderr, " Verbose"); break;
|
||||||
|
case TLOG_DEBUG: fprintf(stderr, " Debug"); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, CNORMAL " | ");
|
||||||
|
|
||||||
|
va_start(va, fmt);
|
||||||
|
vfprintf(stderr, fmt, va);
|
||||||
|
va_end(va);
|
||||||
|
|
||||||
|
if (fmt[0] != 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef LOG_ALWAYS_FFLUSH
|
||||||
|
/* Systematicaly flush */
|
||||||
|
fflush(stderr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
FILE *log_stream=NULL;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
int log_init(char *path)
|
|
||||||
{
|
|
||||||
//log_stream=fopen(path,"wrt");
|
|
||||||
log_stream = stdout;
|
|
||||||
|
|
||||||
if (log_stream==NULL)
|
|
||||||
{
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
FILE *log_get(void)
|
|
||||||
{
|
|
||||||
return(log_stream);
|
|
||||||
}
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
void log_done(void)
|
|
||||||
{
|
|
||||||
fclose(log_stream);
|
|
||||||
}
|
|
||||||
136
source/log.h
136
source/log.h
@@ -1,20 +1,124 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
/*******************************************************************************
|
||||||
//
|
* NewOswan
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
* log.h: C Fancy Logger
|
||||||
//
|
* Copyright (c) 2009-2021 986-Studio. All rights reserved.
|
||||||
//
|
*
|
||||||
//
|
* Created by Manoël Trapier on 20/01/2009.
|
||||||
//
|
******************************************************************************/
|
||||||
//
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef __LOG_H__
|
#ifndef _LOG_H
|
||||||
#define __LOG_H__
|
#define _LOG_H
|
||||||
|
|
||||||
int log_init(char *path);
|
|
||||||
FILE *log_get(void);
|
|
||||||
void log_done(void);
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define ALLOW_COLORS
|
||||||
|
|
||||||
|
#ifdef ALLOW_COLORS
|
||||||
|
#define __C(c) "\x1B[" c "m"
|
||||||
|
#else
|
||||||
|
#define __C(c) ""
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ANSI_COLOR __C
|
||||||
|
#define FBLACK ANSI_COLOR("30")
|
||||||
|
#define FRED ANSI_COLOR("31")
|
||||||
|
#define FGREEN ANSI_COLOR("32")
|
||||||
|
#define FYELLOW ANSI_COLOR("33")
|
||||||
|
#define FBLUE ANSI_COLOR("34")
|
||||||
|
#define FMAGENTA ANSI_COLOR("35")
|
||||||
|
#define FCYAN ANSI_COLOR("36")
|
||||||
|
#define FWHITE ANSI_COLOR("37")
|
||||||
|
|
||||||
|
#define BBLACK ANSI_COLOR("40")
|
||||||
|
#define BRED ANSI_COLOR("41")
|
||||||
|
#define BGREEN ANSI_COLOR("42")
|
||||||
|
#define BYELLOW ANSI_COLOR("43")
|
||||||
|
#define BBLUE ANSI_COLOR("44")
|
||||||
|
#define BMAGENTA ANSI_COLOR("45")
|
||||||
|
#define BCYAN ANSI_COLOR("46")
|
||||||
|
#define BWHITE ANSI_COLOR("47")
|
||||||
|
|
||||||
|
#define CNORMAL ANSI_COLOR("0")
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
TLOG_ALWAYS = -1,
|
||||||
|
TLOG_PANIC = 0,
|
||||||
|
TLOG_ERROR,
|
||||||
|
TLOG_WARNING,
|
||||||
|
TLOG_NORMAL,
|
||||||
|
TLOG_VERBOSE,
|
||||||
|
TLOG_DEBUG,
|
||||||
|
};
|
||||||
|
|
||||||
|
//#define LOG_ALWAYS_FFLUSH
|
||||||
|
#define DYNA_LOG_LEVEL
|
||||||
|
#define SET_DEBUG_LOG
|
||||||
|
|
||||||
|
/* Set if DYNALOG is set the maximum compiled log level */
|
||||||
|
#ifndef MAXIMUM_DEBUG_LEVEL
|
||||||
|
|
||||||
|
#ifndef SET_DEBUG_LOG
|
||||||
|
#define MAXIMUM_DEBUG_LEVEL TLOG_NORMAL
|
||||||
|
#else
|
||||||
|
#define MAXIMUM_DEBUG_LEVEL TLOG_DEBUG
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* MAXIMUM_DEBUG_LEVEL */
|
||||||
|
|
||||||
|
/* Set the default log level */
|
||||||
|
#ifndef SET_DEBUG_LOG
|
||||||
|
#define DEFAULT_DEBUG_LEVEL TLOG_PANIC
|
||||||
|
#else
|
||||||
|
#define DEFAULT_DEBUG_LEVEL TLOG_DEBUG
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/* DO NOT MESS AFTER THIS LINE */
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
#ifdef DYNA_LOG_LEVEL
|
||||||
|
# ifdef MAX_DEBUG_LEVEL
|
||||||
|
# undef MAX_DEBUG_LEVEL
|
||||||
|
# endif
|
||||||
|
# ifdef __LOG_C_INTERNAL_
|
||||||
|
int MAX_DEBUG_LEVEL = DEFAULT_DEBUG_LEVEL;
|
||||||
|
#else
|
||||||
|
extern int MAX_DEBUG_LEVEL;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
# ifndef MAX_DEBUG_LEVEL
|
||||||
|
# define MAX_DEBUG_LEVEL DEFAULT_DEBUG_LEVEL
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define Log(_level, _user, _fmt, ...)\
|
||||||
|
if (_level <= MAXIMUM_DEBUG_LEVEL)\
|
||||||
|
if ((_level <= MAX_DEBUG_LEVEL) || (_level <= TLOG_PANIC))\
|
||||||
|
do { log_real(_level, _user, _fmt, ##__VA_ARGS__); } while(0)
|
||||||
|
|
||||||
|
void log_real(int level, const char *user, const char *fmt, ...);
|
||||||
|
|
||||||
|
#define LOG(_level, _str, ...) if ((_level <= MAX_DEBUG_LEVEL) || (_level <= TLOG_PANIC)) do { fputs(_str, stderr); } while(0)
|
||||||
|
#define LOGCODE(_level, _user, _code)\
|
||||||
|
if (_level <= MAXIMUM_DEBUG_LEVEL) do{\
|
||||||
|
Log(_level, _user, "");\
|
||||||
|
if ((_level <= MAX_DEBUG_LEVEL) || (_level <= TLOG_PANIC))\
|
||||||
|
do { _code; fprintf(stderr, "\n"); } while(0); } while(0)
|
||||||
|
|
||||||
|
#define INFOL(_level, _fmt) LOGCODE(_level, "INFOL", { printf _fmt; })
|
||||||
|
|
||||||
|
#define FUNC_IN() Log(TLOG_VERBOSE, NULL, ">>%s", __func__)
|
||||||
|
#define FUNC_OUT() Log(TLOG_VERBOSE, NULL, "<<%s", __func__)
|
||||||
|
#define FUNC_OUTR(out) Log(TLOG_VERBOSE, NULL, "<<%s (%d)", __func__, out)
|
||||||
|
|
||||||
|
void log_displayPanic(int signal);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _LOG_H */
|
||||||
|
|
||||||
|
|||||||
613
source/memory.c
Normal file
613
source/memory.c
Normal file
@@ -0,0 +1,613 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* NewOswan
|
||||||
|
* memory.c: Memory implementation
|
||||||
|
* Based on the original Oswan-unix
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Notes: need to optimize mem_writemem20
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include "ws.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "rom.h"
|
||||||
|
#include "./nec/nec.h"
|
||||||
|
#include "io.h"
|
||||||
|
#include "gpu.h"
|
||||||
|
#include "audio.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#define IO_ROM_BANK_BASE_SELECTOR 0xC0
|
||||||
|
|
||||||
|
uint8_t *ws_rom;
|
||||||
|
uint8_t *ws_staticRam;
|
||||||
|
uint8_t *internalRam;
|
||||||
|
uint8_t *externalEeprom;
|
||||||
|
char *internalBWIRom;
|
||||||
|
char *internalColorIRom;
|
||||||
|
char *internalCrystalIRom;
|
||||||
|
|
||||||
|
char *internalBWEeprom;
|
||||||
|
char *internalColorEeprom;
|
||||||
|
char *internalCrystalEeprom;
|
||||||
|
|
||||||
|
uint16_t *internalEeprom;
|
||||||
|
|
||||||
|
extern uint8_t *ws_ioRam;
|
||||||
|
|
||||||
|
uint16_t ws_rom_checksum;
|
||||||
|
|
||||||
|
uint8_t ws_haveCrystalIRom;
|
||||||
|
uint8_t ws_haveColorIRom;
|
||||||
|
uint8_t ws_haveBWIRom;
|
||||||
|
|
||||||
|
uint32_t sramAddressMask;
|
||||||
|
uint32_t externalEepromAddressMask;
|
||||||
|
uint32_t romAddressMask;
|
||||||
|
uint32_t romSize;
|
||||||
|
uint32_t sramSize;
|
||||||
|
|
||||||
|
extern nec_Regs I;
|
||||||
|
|
||||||
|
void dump_memory()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
FILE *fp;
|
||||||
|
printf("Dumping memory....\n");
|
||||||
|
fp = fopen("iram.bin", "wb");
|
||||||
|
fwrite(internalRam, 1, 0x10000, fp);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
fp = fopen("sram.bin", "wb");
|
||||||
|
fwrite(ws_staticRam, 1, 0x10000, fp);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
fp = fopen("rom.bin", "wb");
|
||||||
|
fwrite(ws_rom, 1, romSize, fp);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
fp = fopen("memorydump.bin", "wb");
|
||||||
|
fwrite(internalRam, 1, 0x10000, fp);
|
||||||
|
/* page 1 */
|
||||||
|
fwrite(&(ws_staticRam[0 & sramAddressMask]), 1, 0x10000, fp);
|
||||||
|
fwrite(&(ws_rom[((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR + 2] & ((romSize >> 16) - 1)) << 16)]), 1, 0x10000, fp);
|
||||||
|
fwrite(&(ws_rom[((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR + 3] & ((romSize >> 16) - 1)) << 16)]), 1, 0x10000, fp);
|
||||||
|
|
||||||
|
for (i = 4 ; i < 0x10 ; i++)
|
||||||
|
{
|
||||||
|
int romBank = (256 - (((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR] & 0xf) << 4) | (i & 0xf)));
|
||||||
|
fwrite(&(ws_rom[(unsigned)(romSize - (romBank << 16))]), 1, 0x10000, fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
fp = fopen("registers.bin", "wb");
|
||||||
|
fwrite(ws_ioRam, 1, 256, fp);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
fp = fopen("cpuregs.bin", "wb");
|
||||||
|
/* CS */
|
||||||
|
fwrite(&I.sregs[CS], 1, 2, fp);
|
||||||
|
/* IP */
|
||||||
|
fwrite(&I.ip, 1, 2, fp);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef USE_PAGED_MEMORY_ACCESS
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void mem_writemem20(uint32_t addr, uint8_t value)
|
||||||
|
{
|
||||||
|
uint32_t offset = addr & 0xffff;
|
||||||
|
uint32_t bank = addr >> 16;
|
||||||
|
|
||||||
|
if (!bank)
|
||||||
|
{
|
||||||
|
// 0 - RAM - 16 KB (WS) / 64 KB (WSC) internal RAM
|
||||||
|
ws_gpu_write_byte(offset, value);
|
||||||
|
ws_audio_write_byte(offset, value);
|
||||||
|
}
|
||||||
|
else if (bank == 1)
|
||||||
|
{
|
||||||
|
// 1 - SRAM (cart)
|
||||||
|
ws_staticRam[offset & sramAddressMask] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// other banks are read-only
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
uint8_t mem_readmem20(uint32_t addr)
|
||||||
|
{
|
||||||
|
uint32_t offset = addr & 0xffff;
|
||||||
|
uint32_t bank = addr >> 16;
|
||||||
|
//uint16_t romBank;
|
||||||
|
uint8_t hwReg;
|
||||||
|
uint32_t temp;
|
||||||
|
uint8_t ret;
|
||||||
|
wssystem_t currentSystem = ws_get_system();
|
||||||
|
|
||||||
|
switch (bank)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
/*
|
||||||
|
* So the original WonderSwan, and Color/Crystal in B&W mode have 16KB of IRAM Mapped.
|
||||||
|
* Color/Crystal in color mode have 64 KB IRAM mapped.
|
||||||
|
*/
|
||||||
|
if (ws_gpu_operatingInColor)
|
||||||
|
{
|
||||||
|
return (internalRam[offset]);
|
||||||
|
}
|
||||||
|
else if (offset < 0x4000)
|
||||||
|
{
|
||||||
|
return (internalRam[offset]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0x90);
|
||||||
|
|
||||||
|
case 1: // 1 - SRAM (cart)
|
||||||
|
return ws_staticRam[offset & sramAddressMask];
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
// Bank 2
|
||||||
|
hwReg = ws_ioRam[0xC2];
|
||||||
|
temp = hwReg << 16;
|
||||||
|
temp += offset;
|
||||||
|
temp &= (romSize - 1);
|
||||||
|
return ws_rom[temp];
|
||||||
|
case 3:
|
||||||
|
// Bank 3
|
||||||
|
hwReg = ws_ioRam[0xC3];
|
||||||
|
temp = hwReg << 16;
|
||||||
|
temp += offset;
|
||||||
|
temp &= (romSize - 1);
|
||||||
|
return ws_rom[temp];
|
||||||
|
|
||||||
|
case 0xF:
|
||||||
|
hwReg = ws_ioRam[0xA0];
|
||||||
|
|
||||||
|
if (!(hwReg & 1))
|
||||||
|
{
|
||||||
|
if (currentSystem == WS_SYSTEM_COLOR && ws_haveColorIRom)
|
||||||
|
{
|
||||||
|
if (addr >= 0xFE000)
|
||||||
|
{
|
||||||
|
ret = internalColorIRom[addr & ~0xFE000];
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (currentSystem == WS_SYSTEM_CRYSTAL && ws_haveColorIRom)
|
||||||
|
{
|
||||||
|
if (addr >= 0xFE000)
|
||||||
|
{
|
||||||
|
ret = internalCrystalIRom[addr & ~0xFE000];
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (currentSystem == WS_SYSTEM_MONO && ws_haveBWIRom)
|
||||||
|
{
|
||||||
|
if (addr >= 0xFF000)
|
||||||
|
{
|
||||||
|
ret = internalBWIRom[addr & ~0xFF000];
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// fall through
|
||||||
|
|
||||||
|
default:
|
||||||
|
hwReg = ws_ioRam[0xC0];
|
||||||
|
temp = hwReg << 20;
|
||||||
|
temp += addr & 0xFFFFF;
|
||||||
|
temp &= (romSize - 1);
|
||||||
|
return ws_rom[temp];
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0x90);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/* 256 page of 12 bits */
|
||||||
|
uint8_t *pagedMemory[0x100];
|
||||||
|
|
||||||
|
/* Memory address is 20bit and split in 8 (page) - 12 (offset) */
|
||||||
|
void mem_writemem20(uint32_t addr, uint8_t value)
|
||||||
|
{
|
||||||
|
uint8_t page = addr >> 12;
|
||||||
|
uint16_t offset = addr & 0xFFF;
|
||||||
|
if (page < 0x30)
|
||||||
|
{
|
||||||
|
/* Unmapped will be NULL so just check to be sure */
|
||||||
|
if (pagedMemory[page])
|
||||||
|
{
|
||||||
|
pagedMemory[page][offset] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t mem_readmem20(uint32_t addr)
|
||||||
|
{
|
||||||
|
uint8_t page = addr >> 12;
|
||||||
|
uint16_t offset = addr & 0xFFF;
|
||||||
|
if (pagedMemory[page])
|
||||||
|
{
|
||||||
|
return pagedMemory[page][offset];
|
||||||
|
}
|
||||||
|
return 0x90;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set memory bank with a granularity of 4-16 as it is the most common on the WonderSwan */
|
||||||
|
void set_memory_bank(uint8_t bank, uint8_t *pointer)
|
||||||
|
{
|
||||||
|
uint8_t page = bank << 4;
|
||||||
|
for(int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
pagedMemory[page | i] = pointer + (i * 0x1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_memory_page(uint8_t page, uint8_t *pointer)
|
||||||
|
{
|
||||||
|
pagedMemory[page] = pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_irom_overlay()
|
||||||
|
{
|
||||||
|
/* Setup the boot rom */
|
||||||
|
if (ws_get_system() == WS_SYSTEM_MONO)
|
||||||
|
{
|
||||||
|
set_memory_page(0xFF, internalBWIRom);
|
||||||
|
}
|
||||||
|
else if (ws_get_system() == WS_SYSTEM_COLOR)
|
||||||
|
{
|
||||||
|
set_memory_page(0xFE, internalColorIRom);
|
||||||
|
set_memory_page(0xFF, internalColorIRom + 0x1000);
|
||||||
|
}
|
||||||
|
else if (ws_get_system() == WS_SYSTEM_CRYSTAL)
|
||||||
|
{
|
||||||
|
set_memory_page(0xFE, internalCrystalIRom);
|
||||||
|
set_memory_page(0xFF, internalCrystalIRom + 0x1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t *getRom(uint32_t *size)
|
||||||
|
{
|
||||||
|
*size = romSize;
|
||||||
|
return ws_rom;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t *getSram(uint32_t *size)
|
||||||
|
{
|
||||||
|
*size = sramSize;
|
||||||
|
return ws_staticRam;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
char *load_file(char *filename)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
char *ret_ptr;
|
||||||
|
struct stat FileStat;
|
||||||
|
|
||||||
|
fd = open(filename, O_RDWR);
|
||||||
|
|
||||||
|
fstat(fd, &FileStat);
|
||||||
|
|
||||||
|
Log(TLOG_DEBUG, "memory", "Trying to load %s, size = %lu...", filename, (unsigned long)FileStat.st_size);
|
||||||
|
|
||||||
|
ret_ptr = (char *)mmap(NULL, FileStat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
if (ret_ptr == MAP_FAILED)
|
||||||
|
{
|
||||||
|
ret_ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
char *create_file(char *filename, uint32_t size)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
uint32_t i;
|
||||||
|
char *ret_ptr;
|
||||||
|
char buf[] = {0};
|
||||||
|
|
||||||
|
Log(TLOG_DEBUG, "memory", "Trying to create %s, size = %u...\n", filename, size);
|
||||||
|
fd = open(filename, O_CREAT | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_TRUNC, 0644);
|
||||||
|
fchmod(fd, 0644);
|
||||||
|
close(fd);
|
||||||
|
sync();
|
||||||
|
|
||||||
|
fd = open(filename, O_RDWR);
|
||||||
|
|
||||||
|
for (i = 0 ; i < size ; i++)
|
||||||
|
{
|
||||||
|
write(fd, buf, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
sync();
|
||||||
|
|
||||||
|
fd = open(filename, O_RDWR);
|
||||||
|
ret_ptr = (char *)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
if (ret_ptr == MAP_FAILED)
|
||||||
|
{
|
||||||
|
ret_ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void ws_memory_init(uint8_t *rom, uint32_t wsRomSize)
|
||||||
|
{
|
||||||
|
ws_romHeaderStruct *ws_romHeader;
|
||||||
|
|
||||||
|
ws_rom = rom;
|
||||||
|
romSize = wsRomSize;
|
||||||
|
sramSize = ws_rom_sramSize(ws_rom, romSize);
|
||||||
|
ws_romHeader = ws_rom_getHeader(ws_rom, romSize);
|
||||||
|
ws_rom_checksum = ws_romHeader->checksum;
|
||||||
|
internalRam = (uint8_t *)malloc(0x10000);
|
||||||
|
sramAddressMask = 0x0;
|
||||||
|
externalEepromAddressMask = 0x0;
|
||||||
|
|
||||||
|
if (sramSize > 0)
|
||||||
|
{
|
||||||
|
sramAddressMask = ws_rom_sramSize(ws_rom, romSize) - 1;
|
||||||
|
}
|
||||||
|
if (ws_rom_eepromSize(ws_rom, romSize) > 0)
|
||||||
|
{
|
||||||
|
externalEepromAddressMask = ws_rom_eepromSize(ws_rom, romSize) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
internalBWIRom = load_file("ws_irom.bin");
|
||||||
|
internalColorIRom = load_file("wsc_irom.bin");
|
||||||
|
internalCrystalIRom = load_file("wc_irom.bin");
|
||||||
|
|
||||||
|
internalBWEeprom = load_file("ws_ieeprom.bin");
|
||||||
|
if (internalBWEeprom == NULL)
|
||||||
|
{
|
||||||
|
internalBWEeprom = create_file("ws_ieeprom.bin", BW_IEEPROM_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
internalColorEeprom = load_file("wsc_ieeprom.bin");
|
||||||
|
if (internalColorEeprom == NULL)
|
||||||
|
{
|
||||||
|
internalColorEeprom = create_file("wsc_ieeprom.bin", COLOR_IEEPROM_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
internalCrystalEeprom = load_file("wc_ieeprom.bin");
|
||||||
|
if (internalCrystalEeprom == NULL)
|
||||||
|
{
|
||||||
|
internalCrystalEeprom = create_file("wc_ieeprom.bin", COLOR_IEEPROM_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
internalEeprom = (uint16_t *)internalBWEeprom;
|
||||||
|
if (ws_get_system() == WS_SYSTEM_COLOR)
|
||||||
|
{
|
||||||
|
internalEeprom = (uint16_t *)internalColorEeprom;
|
||||||
|
}
|
||||||
|
else if (ws_get_system() == WS_SYSTEM_CRYSTAL)
|
||||||
|
{
|
||||||
|
internalEeprom = (uint16_t *)internalCrystalEeprom;
|
||||||
|
}
|
||||||
|
|
||||||
|
ws_haveBWIRom = false;
|
||||||
|
ws_haveColorIRom = false;
|
||||||
|
ws_haveCrystalIRom = false;
|
||||||
|
|
||||||
|
if (internalColorIRom != NULL)
|
||||||
|
{
|
||||||
|
Log(TLOG_DEBUG, "memory", "B&W IROM Found!");
|
||||||
|
ws_haveColorIRom = true;
|
||||||
|
}
|
||||||
|
if (internalBWIRom != NULL)
|
||||||
|
{
|
||||||
|
Log(TLOG_DEBUG, "memory", "Color IROM Found!");
|
||||||
|
ws_haveBWIRom = true;
|
||||||
|
}
|
||||||
|
if (internalCrystalIRom != NULL)
|
||||||
|
{
|
||||||
|
Log(TLOG_DEBUG, "memory", "Crystal IROM Found!");
|
||||||
|
ws_haveCrystalIRom = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
romAddressMask = romSize - 1;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef USE_PAGED_MEMORY_ACCESS
|
||||||
|
for(int i = 0; i < 0x100; i++)
|
||||||
|
{
|
||||||
|
pagedMemory[i] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* IRAM */
|
||||||
|
set_memory_bank(0, internalRam);
|
||||||
|
for(int i = 0x4; i < 0x10; i++)
|
||||||
|
{
|
||||||
|
set_memory_page(i, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cart SRAM */
|
||||||
|
if (sramSize > 0)
|
||||||
|
{
|
||||||
|
set_memory_bank(0x1, ws_get_page_ptr(ws_staticRam, sramSize, 0xFF));
|
||||||
|
}
|
||||||
|
|
||||||
|
set_memory_bank(0x2, ws_get_page_ptr(ws_rom, romSize, 0xFF));
|
||||||
|
set_memory_bank(0x3, ws_get_page_ptr(ws_rom, romSize, 0xFF));
|
||||||
|
|
||||||
|
for(int i = 0x04; i < 0x10; i++)
|
||||||
|
{
|
||||||
|
set_memory_bank(i, ws_get_page_ptr(ws_rom, romSize, 0xF0 + i));
|
||||||
|
}
|
||||||
|
|
||||||
|
set_irom_overlay();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void ws_memory_reset(void)
|
||||||
|
{
|
||||||
|
memset(internalRam, 0, 0x10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void ws_memory_done(void)
|
||||||
|
{
|
||||||
|
free(internalRam);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
uint8_t *memory_getRom(void)
|
||||||
|
{
|
||||||
|
return (ws_rom);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
uint32_t memory_getRomSize(void)
|
||||||
|
{
|
||||||
|
return (romSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
uint16_t memory_getRomCrc(void)
|
||||||
|
{
|
||||||
|
return (ws_rom_checksum);
|
||||||
|
}
|
||||||
@@ -1,448 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Memory
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Notes: need to optimize cpu_writemem20
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include "log.h"
|
|
||||||
#include "rom.h"
|
|
||||||
#include "./nec/nec.h"
|
|
||||||
#include "io.h"
|
|
||||||
#include "gpu.h"
|
|
||||||
#include "audio.h"
|
|
||||||
#include "memory.h"
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
#define IO_ROM_BANK_BASE_SELECTOR 0xC0
|
|
||||||
|
|
||||||
uint8_t *ws_rom;
|
|
||||||
uint8_t *ws_staticRam;
|
|
||||||
uint8_t *internalRam;
|
|
||||||
uint8_t *externalEeprom;
|
|
||||||
char *internalBWIRom;
|
|
||||||
char *internalColorIRom;
|
|
||||||
|
|
||||||
char *internalBWEeprom;
|
|
||||||
char *internalColorEeprom;
|
|
||||||
|
|
||||||
uint16_t *internalEeprom;
|
|
||||||
|
|
||||||
extern uint8_t *ws_ioRam;
|
|
||||||
|
|
||||||
uint16_t ws_rom_checksum;
|
|
||||||
|
|
||||||
uint8_t ws_haveColorIRom;
|
|
||||||
uint8_t ws_haveBWIRom;
|
|
||||||
|
|
||||||
uint32_t sramAddressMask;
|
|
||||||
uint32_t externalEepromAddressMask;
|
|
||||||
uint32_t romAddressMask;
|
|
||||||
uint32_t romSize;
|
|
||||||
|
|
||||||
int ws_sram_dirty = 0;
|
|
||||||
|
|
||||||
extern nec_Regs I;
|
|
||||||
|
|
||||||
void dump_memory()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
FILE *fp;
|
|
||||||
printf("Dumping memory....\n");
|
|
||||||
fp = fopen("iram.bin", "wb");
|
|
||||||
fwrite(internalRam, 1, 0x10000, fp);
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
fp = fopen("sram.bin", "wb");
|
|
||||||
fwrite(ws_staticRam, 1, 0x10000, fp);
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
fp = fopen("rom.bin", "wb");
|
|
||||||
fwrite(ws_rom, 1, romSize, fp);
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
fp = fopen("memorydump.bin", "wb");
|
|
||||||
fwrite(internalRam, 1, 0x10000, fp);
|
|
||||||
/* page 1 */
|
|
||||||
fwrite(&(ws_staticRam[0 & sramAddressMask]), 1, 0x10000, fp);
|
|
||||||
fwrite(&(ws_rom[((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR+2]&((romSize>>16)-1))<<16)]), 1, 0x10000, fp);
|
|
||||||
fwrite(&(ws_rom[((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR+3]&((romSize>>16)-1))<<16)]), 1, 0x10000, fp);
|
|
||||||
|
|
||||||
for(i = 4; i < 0x10; i++)
|
|
||||||
{
|
|
||||||
int romBank=(256-(((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR]&0xf)<<4)|(i&0xf)));
|
|
||||||
fwrite(&(ws_rom[(unsigned)(romSize-(romBank<<16))]), 1, 0x10000, fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
fp = fopen("registers.bin", "wb");
|
|
||||||
fwrite(ws_ioRam, 1, 256, fp);
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
fp = fopen("cpuregs.bin", "wb");
|
|
||||||
/* CS */
|
|
||||||
fwrite(&I.sregs[CS], 1, 2, fp);
|
|
||||||
/* IP */
|
|
||||||
fwrite(&I.ip, 1, 2, fp);
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
void cpu_writemem20(uint32_t addr, uint8_t value)
|
|
||||||
{
|
|
||||||
uint32_t offset=addr&0xffff;
|
|
||||||
uint32_t bank=addr>>16;
|
|
||||||
|
|
||||||
if (!bank)
|
|
||||||
{
|
|
||||||
// 0 - RAM - 16 KB (WS) / 64 KB (WSC) internal RAM
|
|
||||||
ws_gpu_write_byte(offset,value);
|
|
||||||
ws_audio_write_byte(offset,value);
|
|
||||||
}
|
|
||||||
else if (bank==1)
|
|
||||||
{
|
|
||||||
// 1 - SRAM (cart)
|
|
||||||
ws_staticRam[offset&sramAddressMask]=value;
|
|
||||||
ws_sram_dirty = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// other banks are read-only
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
uint8_t cpu_readmem20(uint32_t addr)
|
|
||||||
{
|
|
||||||
uint32_t offset=addr&0xffff;
|
|
||||||
uint32_t bank=addr>>16;
|
|
||||||
//uint16_t romBank;
|
|
||||||
uint8_t hwReg;
|
|
||||||
uint32_t temp;
|
|
||||||
uint8_t ret;
|
|
||||||
|
|
||||||
switch (bank)
|
|
||||||
{
|
|
||||||
case 0: // 0 - RAM - 16 KB (WS) / 64 KB (WSC) internal RAM
|
|
||||||
if (ws_gpu_operatingInColor)
|
|
||||||
{
|
|
||||||
return(internalRam[offset]);
|
|
||||||
}
|
|
||||||
else if (offset<0x4000)
|
|
||||||
{
|
|
||||||
return(internalRam[offset]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(0x90);
|
|
||||||
|
|
||||||
case 1: // 1 - SRAM (cart)
|
|
||||||
return ws_staticRam[offset&sramAddressMask];
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
// Bank 2
|
|
||||||
hwReg = ws_ioRam[0xC2];
|
|
||||||
temp = hwReg << 16;
|
|
||||||
temp += offset;
|
|
||||||
temp &= (romSize - 1);
|
|
||||||
return ws_rom[temp];
|
|
||||||
case 3:
|
|
||||||
// Bank 3
|
|
||||||
hwReg = ws_ioRam[0xC3];
|
|
||||||
temp = hwReg << 16;
|
|
||||||
temp += offset;
|
|
||||||
temp &= (romSize - 1);
|
|
||||||
return ws_rom[temp];
|
|
||||||
|
|
||||||
case 0xF:
|
|
||||||
hwReg = ws_ioRam[0xA0];
|
|
||||||
|
|
||||||
if (!(hwReg & 1))
|
|
||||||
{
|
|
||||||
if (ws_gpu_operatingInColor && ws_haveColorIRom)
|
|
||||||
{
|
|
||||||
if (addr >= 0xFE000)
|
|
||||||
{
|
|
||||||
ret = internalColorIRom[addr & ~0xFE000];
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!ws_gpu_operatingInColor && ws_haveBWIRom)
|
|
||||||
{
|
|
||||||
if (addr >= 0xFF000)
|
|
||||||
{
|
|
||||||
ret = internalBWIRom[addr & ~0xFF000];
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// fall through
|
|
||||||
|
|
||||||
default:
|
|
||||||
hwReg = ws_ioRam[0xC0];
|
|
||||||
temp = hwReg << 20;
|
|
||||||
temp += addr & 0xFFFFF;
|
|
||||||
temp &= (romSize - 1);
|
|
||||||
return ws_rom[temp];
|
|
||||||
}
|
|
||||||
|
|
||||||
return(0x90);
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
char *load_file(char *filename)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
char *ret_ptr;
|
|
||||||
struct stat FileStat;
|
|
||||||
|
|
||||||
fd = open(filename, O_RDWR);
|
|
||||||
|
|
||||||
fstat(fd, &FileStat);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
if (ret_ptr == MAP_FAILED)
|
|
||||||
{
|
|
||||||
ret_ptr = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret_ptr;
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
char *create_file(char *filename, uint32_t size)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
uint32_t i;
|
|
||||||
char *ret_ptr;
|
|
||||||
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, 0644);
|
|
||||||
fchmod(fd, 0644);
|
|
||||||
close(fd);
|
|
||||||
sync();
|
|
||||||
|
|
||||||
fd = open(filename, O_RDWR);
|
|
||||||
|
|
||||||
for(i = 0; i < size; i++)
|
|
||||||
{
|
|
||||||
write(fd, buf, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
sync();
|
|
||||||
|
|
||||||
fd = open(filename, O_RDWR);
|
|
||||||
ret_ptr = (char *)mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
if (ret_ptr == MAP_FAILED)
|
|
||||||
{
|
|
||||||
ret_ptr = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret_ptr;
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
void ws_memory_init(uint8_t *rom, uint32_t wsRomSize)
|
|
||||||
{
|
|
||||||
ws_romHeaderStruct *ws_romHeader;
|
|
||||||
|
|
||||||
ws_rom=rom;
|
|
||||||
romSize=wsRomSize;
|
|
||||||
ws_romHeader=ws_rom_getHeader(ws_rom,romSize);
|
|
||||||
ws_rom_checksum=ws_romHeader->checksum;
|
|
||||||
internalRam=(uint8_t*)malloc(0x10000);
|
|
||||||
sramAddressMask=ws_rom_sramSize(ws_rom,romSize)-1;
|
|
||||||
externalEepromAddressMask=ws_rom_eepromSize(ws_rom,romSize)-1;
|
|
||||||
|
|
||||||
internalBWIRom = load_file("ws_irom.bin");
|
|
||||||
internalColorIRom = load_file("wsc_irom.bin");
|
|
||||||
|
|
||||||
internalBWEeprom = load_file("ws_ieeprom.bin");
|
|
||||||
if ( internalBWEeprom == NULL )
|
|
||||||
{
|
|
||||||
internalBWEeprom = create_file("ws_ieeprom.bin", BW_IEEPROM_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
internalColorEeprom = load_file("wsc_ieeprom.bin");
|
|
||||||
if ( internalColorEeprom == NULL )
|
|
||||||
{
|
|
||||||
internalColorEeprom = create_file("wsc_ieeprom.bin", COLOR_IEEPROM_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
internalEeprom = (uint16_t *)internalBWEeprom;
|
|
||||||
if (ws_gpu_operatingInColor)
|
|
||||||
{
|
|
||||||
internalEeprom = (uint16_t *)internalColorEeprom;
|
|
||||||
}
|
|
||||||
|
|
||||||
ws_haveBWIRom = false;
|
|
||||||
ws_haveColorIRom = false;
|
|
||||||
|
|
||||||
if (internalBWIRom != NULL)
|
|
||||||
{
|
|
||||||
printf("Color IROM Found!\n");
|
|
||||||
ws_haveBWIRom = true;
|
|
||||||
}
|
|
||||||
if (internalColorIRom != NULL)
|
|
||||||
{
|
|
||||||
printf("B&W IROM Found!\n");
|
|
||||||
ws_haveColorIRom = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
romAddressMask=romSize-1;
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
void ws_memory_reset(void)
|
|
||||||
{
|
|
||||||
memset(internalRam,0,0x10000);
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
void ws_memory_done(void)
|
|
||||||
{
|
|
||||||
free(internalRam);
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
uint8_t *memory_getRom(void)
|
|
||||||
{
|
|
||||||
return(ws_rom);
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
uint32_t memory_getRomSize(void)
|
|
||||||
{
|
|
||||||
return(romSize);
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
uint16_t memory_getRomCrc(void)
|
|
||||||
{
|
|
||||||
return(ws_rom_checksum);
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
/*******************************************************************************
|
||||||
//
|
* NewOswan
|
||||||
|
* memory.h:
|
||||||
|
* Based on the original Oswan-unix
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@@ -12,6 +18,8 @@
|
|||||||
#ifndef __MEMORY_H__
|
#ifndef __MEMORY_H__
|
||||||
#define __MEMORY_H__
|
#define __MEMORY_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
extern uint8_t *ws_staticRam;
|
extern uint8_t *ws_staticRam;
|
||||||
extern uint8_t *internalRam;
|
extern uint8_t *internalRam;
|
||||||
extern uint8_t *externalEeprom;
|
extern uint8_t *externalEeprom;
|
||||||
@@ -29,6 +37,32 @@ char *create_file(char *filename, uint32_t size);
|
|||||||
char *load_file(char *filename);
|
char *load_file(char *filename);
|
||||||
|
|
||||||
void dump_memory();
|
void dump_memory();
|
||||||
|
//#define USE_PAGED_MEMORY_ACCESS
|
||||||
|
#ifdef USE_PAGED_MEMORY_ACCESS
|
||||||
|
/***
|
||||||
|
* Set a memory page with a ganularity of 4-16
|
||||||
|
* @param bank: the bank (0-F) to set
|
||||||
|
* @param pointer: a pointer to the memory to set
|
||||||
|
*/
|
||||||
|
void set_memory_bank(uint8_t bank, uint8_t *pointer);
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Set a memory page with a ganularity of 8-12
|
||||||
|
* @param bank: the bank (0-FF) to set
|
||||||
|
* @param pointer: a pointer to the memory to set
|
||||||
|
*/
|
||||||
|
void set_memory_page(uint8_t page, uint8_t *pointer);
|
||||||
|
|
||||||
|
void set_irom_overlay();
|
||||||
|
|
||||||
|
uint8_t *getRom(uint32_t *size);
|
||||||
|
uint8_t *getSram(uint32_t *size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define mem_readop mem_readmem20
|
||||||
|
#define mem_readop_arg mem_readmem20
|
||||||
|
void mem_writemem20(uint32_t addr, uint8_t value);
|
||||||
|
uint8_t mem_readmem20(uint32_t addr);
|
||||||
|
|
||||||
#define BW_IEEPROM_SIZE (128)
|
#define BW_IEEPROM_SIZE (128)
|
||||||
#define COLOR_IEEPROM_SIZE (2048)
|
#define COLOR_IEEPROM_SIZE (2048)
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
set(SOURCES nec.cpp)
|
set(SOURCES nec.c nec_debugger.c)
|
||||||
set(HEADERS nec.h necea.h necinstr.h necintrf.h necmodrm.h)
|
set(HEADERS nec.h necea.h necinstr.h necintrf.h necmodrm.h nec_debugger.h)
|
||||||
|
|
||||||
add_library(nec_v30 ${SOURCES} ${HEADERS})
|
add_library(nec_v30 ${SOURCES} ${HEADERS})
|
||||||
|
|
||||||
|
target_include_directories(nec_v30 PUBLIC . ..)
|
||||||
4255
source/nec/nec.c
Normal file
4255
source/nec/nec.c
Normal file
File diff suppressed because it is too large
Load Diff
3939
source/nec/nec.cpp
3939
source/nec/nec.cpp
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,30 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* NewOswan
|
||||||
|
* nec.h:
|
||||||
|
* Based on the original Oswan-unix
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
#ifndef __NEC_H_
|
#ifndef __NEC_H_
|
||||||
#define __NEC_H_
|
#define __NEC_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include "necintrf.h"
|
#include "necintrf.h"
|
||||||
|
|
||||||
typedef enum { ES, CS, SS, DS } SREGS;
|
typedef enum
|
||||||
typedef enum { AW, CW, DW, BW, SP, BP, IX, IY } WREGS;
|
{
|
||||||
typedef enum { AL,AH,CL,CH,DL,DH,BL,BH,SPL,SPH,BPL,BPH,IXL,IXH,IYL,IYH } BREGS;
|
ES, CS, SS, DS
|
||||||
|
} SREGS;
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
AW, CW, DW, BW, SP, BP, IX, IY
|
||||||
|
} WREGS;
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
AL, AH, CL, CH, DL, DH, BL, BH, SPL, SPH, BPL, BPH, IXL, IXH, IYL, IYH
|
||||||
|
} BREGS;
|
||||||
|
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
typedef union
|
typedef union
|
||||||
@@ -15,6 +33,7 @@ typedef union
|
|||||||
uint16_t w[8]; /* viewed as 16 bits registers */
|
uint16_t w[8]; /* viewed as 16 bits registers */
|
||||||
uint8_t b[16]; /* or as 8 bit registers */
|
uint8_t b[16]; /* or as 8 bit registers */
|
||||||
} necbasicregs;
|
} necbasicregs;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
necbasicregs regs;
|
necbasicregs regs;
|
||||||
@@ -42,11 +61,6 @@ typedef struct
|
|||||||
#define V30 8
|
#define V30 8
|
||||||
#define V20 16
|
#define V20 16
|
||||||
|
|
||||||
#ifndef FALSE
|
|
||||||
#define FALSE 0
|
|
||||||
#define TRUE 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* parameter x = result, y = source 1, z = source 2 */
|
/* parameter x = result, y = source 1, z = source 2 */
|
||||||
|
|
||||||
#define SetTF(x) (I.TF = (x))
|
#define SetTF(x) (I.TF = (x))
|
||||||
@@ -60,8 +74,6 @@ typedef struct
|
|||||||
#define SetAF(x, y, z) (I.AuxVal = ((x) ^ ((y) ^ (z))) & 0x10)
|
#define SetAF(x, y, z) (I.AuxVal = ((x) ^ ((y) ^ (z))) & 0x10)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define SetSF(x) (I.SignVal = (x))
|
#define SetSF(x) (I.SignVal = (x))
|
||||||
#define SetZF(x) (I.ZeroVal = (x))
|
#define SetZF(x) (I.ZeroVal = (x))
|
||||||
#define SetPF(x) (I.ParityVal = (x))
|
#define SetPF(x) (I.ParityVal = (x))
|
||||||
@@ -101,32 +113,32 @@ typedef struct
|
|||||||
|
|
||||||
#define SegBase(Seg) (I.sregs[Seg] << 4)
|
#define SegBase(Seg) (I.sregs[Seg] << 4)
|
||||||
|
|
||||||
#define DefaultBase(Seg) ((seg_prefix && (Seg==DS || Seg==SS)) ? prefix_base : I.sregs[Seg] << 4)
|
#define DefaultBase(Seg) ((seg_prefix && (Seg==DS || Seg==SS)) ? (prefix_base) : (uint32_t)(I.sregs[Seg] << 4))
|
||||||
|
|
||||||
#define GetMemB(Seg,Off) (/*nec_ICount-=((Off)&1)?1:0,*/ (uint8_t)cpu_readmem20((DefaultBase(Seg)+(Off))))
|
#define GetMemB(Seg, Off) (/*nec_ICount-=((Off)&1)?1:0,*/ (uint8_t)mem_readmem20((DefaultBase(Seg)+(Off))))
|
||||||
#define GetMemW(Seg,Off) (/*nec_ICount-=((Off)&1)?1:0,*/ (uint16_t) cpu_readmem20((DefaultBase(Seg)+(Off))) + (cpu_readmem20((DefaultBase(Seg)+((Off)+1)))<<8) )
|
#define GetMemW(Seg, Off) (/*nec_ICount-=((Off)&1)?1:0,*/ (uint16_t) mem_readmem20((DefaultBase(Seg)+(Off))) + (mem_readmem20((DefaultBase(Seg)+((Off)+1)))<<8) )
|
||||||
|
|
||||||
#define PutMemB(Seg,Off,x) { /*nec_ICount-=((Off)&1)?1:0*/; cpu_writemem20((DefaultBase(Seg)+(Off)),(x)); }
|
#define PutMemB(Seg, Off, x) { /*nec_ICount-=((Off)&1)?1:0*/; mem_writemem20((DefaultBase(Seg)+(Off)),(x)); }
|
||||||
#define PutMemW(Seg, Off, x) { /*nec_ICount-=((Off)&1)?1:0*/; PutMemB(Seg,Off,(x)&0xff); PutMemB(Seg,(Off)+1,(uint8_t)((x)>>8)); }
|
#define PutMemW(Seg, Off, x) { /*nec_ICount-=((Off)&1)?1:0*/; PutMemB(Seg,Off,(x)&0xff); PutMemB(Seg,(Off)+1,(uint8_t)((x)>>8)); }
|
||||||
|
|
||||||
/* Todo: Remove these later - plus readword could overflow */
|
/* Todo: Remove these later - plus readword could overflow */
|
||||||
#define ReadByte(ea) (/*nec_ICount-=((ea)&1)?1:0,*/ (uint8_t)cpu_readmem20((ea)))
|
#define ReadByte(ea) (/*nec_ICount-=((ea)&1)?1:0,*/ (uint8_t)mem_readmem20((ea)))
|
||||||
#define ReadWord(ea) (/*nec_ICount-=((ea)&1)?1:0,*/ cpu_readmem20((ea))+(cpu_readmem20(((ea)+1))<<8))
|
#define ReadWord(ea) (/*nec_ICount-=((ea)&1)?1:0,*/ mem_readmem20((ea))+(mem_readmem20(((ea)+1))<<8))
|
||||||
#define WriteByte(ea,val) { /*nec_ICount-=((ea)&1)?1:0*/; cpu_writemem20((ea),val); }
|
#define WriteByte(ea, val) { /*nec_ICount-=((ea)&1)?1:0*/; mem_writemem20((ea),val); }
|
||||||
#define WriteWord(ea,val) { /*nec_ICount-=((ea)&1)?1:0*/; cpu_writemem20((ea),(uint8_t)(val)); cpu_writemem20(((ea)+1),(val)>>8); }
|
#define WriteWord(ea, val) { /*nec_ICount-=((ea)&1)?1:0*/; mem_writemem20((ea),(uint8_t)(val)); mem_writemem20(((ea)+1),(val)>>8); }
|
||||||
|
|
||||||
#define read_port(port) cpu_readport(port)
|
#define read_port(port) io_readport(port)
|
||||||
#define write_port(port,val) cpu_writeport(port,val)
|
#define write_port(port, val) io_writeport(port,val)
|
||||||
|
|
||||||
#define FETCH (cpu_readop_arg((I.sregs[CS]<<4)+I.ip++))
|
#define FETCH (mem_readop_arg((I.sregs[CS]<<4)+I.ip++))
|
||||||
#define FETCHOP (cpu_readop((I.sregs[CS]<<4)+I.ip++))
|
#define FETCHOP (mem_readop((I.sregs[CS]<<4)+I.ip++))
|
||||||
#define FETCHWORD(var) { var=cpu_readop_arg((((I.sregs[CS]<<4)+I.ip)))+(cpu_readop_arg((((I.sregs[CS]<<4)+I.ip+1)))<<8); I.ip+=2; }
|
#define FETCHWORD(var) { var=mem_readop_arg((((I.sregs[CS]<<4)+I.ip)))+(mem_readop_arg((((I.sregs[CS]<<4)+I.ip+1)))<<8); I.ip+=2; }
|
||||||
#define PUSH(val) { I.regs.w[SP]-=2; WriteWord((((I.sregs[SS]<<4)+I.regs.w[SP])),val); }
|
#define PUSH(val) { I.regs.w[SP]-=2; WriteWord((((I.sregs[SS]<<4)+I.regs.w[SP])),val); }
|
||||||
#define POP(var) { var = ReadWord((((I.sregs[SS]<<4)+I.regs.w[SP]))); I.regs.w[SP]+=2; }
|
#define POP(var) { var = ReadWord((((I.sregs[SS]<<4)+I.regs.w[SP]))); I.regs.w[SP]+=2; }
|
||||||
#define PEEK(addr) ((uint8_t)cpu_readop_arg(addr))
|
#define PEEK(addr) ((uint8_t)mem_readop_arg(addr))
|
||||||
#define PEEKOP(addr) ((uint8_t)cpu_readop(addr))
|
#define PEEKOP(addr) ((uint8_t)mem_readop(addr))
|
||||||
|
|
||||||
#define GetModRM uint32_t ModRM=cpu_readop_arg((I.sregs[CS]<<4)+I.ip++)
|
#define GetModRM uint32_t ModRM=mem_readop_arg((I.sregs[CS]<<4)+I.ip++)
|
||||||
|
|
||||||
/* Cycle count macros:
|
/* Cycle count macros:
|
||||||
CLK - cycle count is the same on all processors
|
CLK - cycle count is the same on all processors
|
||||||
@@ -172,7 +184,6 @@ typedef struct
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define IncWordReg(Reg) \
|
#define IncWordReg(Reg) \
|
||||||
uint16_t tmp = (uint16_t)I.regs.w[Reg]; \
|
uint16_t tmp = (uint16_t)I.regs.w[Reg]; \
|
||||||
uint16_t tmp1 = tmp+1; \
|
uint16_t tmp1 = tmp+1; \
|
||||||
@@ -182,7 +193,6 @@ typedef struct
|
|||||||
I.regs.w[Reg]=tmp1
|
I.regs.w[Reg]=tmp1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define DecWordReg(Reg) \
|
#define DecWordReg(Reg) \
|
||||||
uint16_t tmp = (uint16_t)I.regs.w[Reg]; \
|
uint16_t tmp = (uint16_t)I.regs.w[Reg]; \
|
||||||
uint16_t tmp1 = tmp-1; \
|
uint16_t tmp1 = tmp-1; \
|
||||||
|
|||||||
1268
source/nec/nec_debugger.c
Normal file
1268
source/nec/nec_debugger.c
Normal file
File diff suppressed because it is too large
Load Diff
15
source/nec/nec_debugger.h
Normal file
15
source/nec/nec_debugger.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* NewOswan
|
||||||
|
* nec_debugger.h:
|
||||||
|
* Created by Manoël Trapier on 14/04/2021.
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NEWOSWAN_SOURCE_NEC_NEC_DEBUGGER_H
|
||||||
|
#define NEWOSWAN_SOURCE_NEC_NEC_DEBUGGER_H
|
||||||
|
|
||||||
|
|
||||||
|
int nec_decode_instruction(uint16_t segment, uint16_t offset, char *buffer, unsigned int bufferSize);
|
||||||
|
|
||||||
|
#endif /* NEWOSWAN_SOURCE_NEC_NEC_DEBUGGER_H */
|
||||||
@@ -1,3 +1,10 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* NewOswan
|
||||||
|
* necea.h:
|
||||||
|
* Based on the original Oswan-unix
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
static uint32_t EA;
|
static uint32_t EA;
|
||||||
static uint16_t EO;
|
static uint16_t EO;
|
||||||
@@ -9,36 +16,42 @@ static unsigned EA_000(void)
|
|||||||
EA = DefaultBase(DS) + EO;
|
EA = DefaultBase(DS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_001(void)
|
static unsigned EA_001(void)
|
||||||
{
|
{
|
||||||
EO = I.regs.w[BW] + I.regs.w[IY];
|
EO = I.regs.w[BW] + I.regs.w[IY];
|
||||||
EA = DefaultBase(DS) + EO;
|
EA = DefaultBase(DS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_002(void)
|
static unsigned EA_002(void)
|
||||||
{
|
{
|
||||||
EO = I.regs.w[BP] + I.regs.w[IX];
|
EO = I.regs.w[BP] + I.regs.w[IX];
|
||||||
EA = DefaultBase(SS) + EO;
|
EA = DefaultBase(SS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_003(void)
|
static unsigned EA_003(void)
|
||||||
{
|
{
|
||||||
EO = I.regs.w[BP] + I.regs.w[IY];
|
EO = I.regs.w[BP] + I.regs.w[IY];
|
||||||
EA = DefaultBase(SS) + EO;
|
EA = DefaultBase(SS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_004(void)
|
static unsigned EA_004(void)
|
||||||
{
|
{
|
||||||
EO = I.regs.w[IX];
|
EO = I.regs.w[IX];
|
||||||
EA = DefaultBase(DS) + EO;
|
EA = DefaultBase(DS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_005(void)
|
static unsigned EA_005(void)
|
||||||
{
|
{
|
||||||
EO = I.regs.w[IY];
|
EO = I.regs.w[IY];
|
||||||
EA = DefaultBase(DS) + EO;
|
EA = DefaultBase(DS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_006(void)
|
static unsigned EA_006(void)
|
||||||
{
|
{
|
||||||
EO = FETCH;
|
EO = FETCH;
|
||||||
@@ -46,6 +59,7 @@ static unsigned EA_006(void)
|
|||||||
EA = DefaultBase(DS) + EO;
|
EA = DefaultBase(DS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_007(void)
|
static unsigned EA_007(void)
|
||||||
{
|
{
|
||||||
EO = I.regs.w[BW];
|
EO = I.regs.w[BW];
|
||||||
@@ -59,42 +73,49 @@ static unsigned EA_100(void)
|
|||||||
EA = DefaultBase(DS) + EO;
|
EA = DefaultBase(DS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_101(void)
|
static unsigned EA_101(void)
|
||||||
{
|
{
|
||||||
EO = (I.regs.w[BW] + I.regs.w[IY] + (int8_t)FETCH);
|
EO = (I.regs.w[BW] + I.regs.w[IY] + (int8_t)FETCH);
|
||||||
EA = DefaultBase(DS) + EO;
|
EA = DefaultBase(DS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_102(void)
|
static unsigned EA_102(void)
|
||||||
{
|
{
|
||||||
EO = (I.regs.w[BP] + I.regs.w[IX] + (int8_t)FETCH);
|
EO = (I.regs.w[BP] + I.regs.w[IX] + (int8_t)FETCH);
|
||||||
EA = DefaultBase(SS) + EO;
|
EA = DefaultBase(SS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_103(void)
|
static unsigned EA_103(void)
|
||||||
{
|
{
|
||||||
EO = (I.regs.w[BP] + I.regs.w[IY] + (int8_t)FETCH);
|
EO = (I.regs.w[BP] + I.regs.w[IY] + (int8_t)FETCH);
|
||||||
EA = DefaultBase(SS) + EO;
|
EA = DefaultBase(SS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_104(void)
|
static unsigned EA_104(void)
|
||||||
{
|
{
|
||||||
EO = (I.regs.w[IX] + (int8_t)FETCH);
|
EO = (I.regs.w[IX] + (int8_t)FETCH);
|
||||||
EA = DefaultBase(DS) + EO;
|
EA = DefaultBase(DS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_105(void)
|
static unsigned EA_105(void)
|
||||||
{
|
{
|
||||||
EO = (I.regs.w[IY] + (int8_t)FETCH);
|
EO = (I.regs.w[IY] + (int8_t)FETCH);
|
||||||
EA = DefaultBase(DS) + EO;
|
EA = DefaultBase(DS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_106(void)
|
static unsigned EA_106(void)
|
||||||
{
|
{
|
||||||
EO = (I.regs.w[BP] + (int8_t)FETCH);
|
EO = (I.regs.w[BP] + (int8_t)FETCH);
|
||||||
EA = DefaultBase(SS) + EO;
|
EA = DefaultBase(SS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_107(void)
|
static unsigned EA_107(void)
|
||||||
{
|
{
|
||||||
EO = (I.regs.w[BW] + (int8_t)FETCH);
|
EO = (I.regs.w[BW] + (int8_t)FETCH);
|
||||||
@@ -110,6 +131,7 @@ static unsigned EA_200(void)
|
|||||||
EA = DefaultBase(DS) + EO;
|
EA = DefaultBase(DS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_201(void)
|
static unsigned EA_201(void)
|
||||||
{
|
{
|
||||||
E16 = FETCH;
|
E16 = FETCH;
|
||||||
@@ -118,6 +140,7 @@ static unsigned EA_201(void)
|
|||||||
EA = DefaultBase(DS) + EO;
|
EA = DefaultBase(DS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_202(void)
|
static unsigned EA_202(void)
|
||||||
{
|
{
|
||||||
E16 = FETCH;
|
E16 = FETCH;
|
||||||
@@ -126,6 +149,7 @@ static unsigned EA_202(void)
|
|||||||
EA = DefaultBase(SS) + EO;
|
EA = DefaultBase(SS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_203(void)
|
static unsigned EA_203(void)
|
||||||
{
|
{
|
||||||
E16 = FETCH;
|
E16 = FETCH;
|
||||||
@@ -134,6 +158,7 @@ static unsigned EA_203(void)
|
|||||||
EA = DefaultBase(SS) + EO;
|
EA = DefaultBase(SS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_204(void)
|
static unsigned EA_204(void)
|
||||||
{
|
{
|
||||||
E16 = FETCH;
|
E16 = FETCH;
|
||||||
@@ -142,6 +167,7 @@ static unsigned EA_204(void)
|
|||||||
EA = DefaultBase(DS) + EO;
|
EA = DefaultBase(DS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_205(void)
|
static unsigned EA_205(void)
|
||||||
{
|
{
|
||||||
E16 = FETCH;
|
E16 = FETCH;
|
||||||
@@ -150,6 +176,7 @@ static unsigned EA_205(void)
|
|||||||
EA = DefaultBase(DS) + EO;
|
EA = DefaultBase(DS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_206(void)
|
static unsigned EA_206(void)
|
||||||
{
|
{
|
||||||
E16 = FETCH;
|
E16 = FETCH;
|
||||||
@@ -158,6 +185,7 @@ static unsigned EA_206(void)
|
|||||||
EA = DefaultBase(SS) + EO;
|
EA = DefaultBase(SS) + EO;
|
||||||
return EA;
|
return EA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned EA_207(void)
|
static unsigned EA_207(void)
|
||||||
{
|
{
|
||||||
E16 = FETCH;
|
E16 = FETCH;
|
||||||
@@ -169,30 +197,21 @@ static unsigned EA_207(void)
|
|||||||
|
|
||||||
static unsigned (*GetEA[192])(void) =
|
static unsigned (*GetEA[192])(void) =
|
||||||
{
|
{
|
||||||
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007,
|
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, EA_000, EA_001, EA_002, EA_003, EA_004, EA_005,
|
||||||
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007,
|
EA_006, EA_007, EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, EA_000, EA_001, EA_002, EA_003,
|
||||||
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007,
|
EA_004, EA_005, EA_006, EA_007, EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, EA_000, EA_001,
|
||||||
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007,
|
EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007,
|
||||||
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007,
|
|
||||||
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007,
|
|
||||||
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007,
|
|
||||||
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007,
|
EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007,
|
||||||
|
|
||||||
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107,
|
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, EA_100, EA_101, EA_102, EA_103, EA_104, EA_105,
|
||||||
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107,
|
EA_106, EA_107, EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, EA_100, EA_101, EA_102, EA_103,
|
||||||
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107,
|
EA_104, EA_105, EA_106, EA_107, EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, EA_100, EA_101,
|
||||||
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107,
|
EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107,
|
||||||
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107,
|
|
||||||
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107,
|
|
||||||
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107,
|
|
||||||
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107,
|
EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107,
|
||||||
|
|
||||||
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207,
|
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, EA_200, EA_201, EA_202, EA_203, EA_204, EA_205,
|
||||||
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207,
|
EA_206, EA_207, EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, EA_200, EA_201, EA_202, EA_203,
|
||||||
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207,
|
EA_204, EA_205, EA_206, EA_207, EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, EA_200, EA_201,
|
||||||
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207,
|
EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207,
|
||||||
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207,
|
|
||||||
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207,
|
|
||||||
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207,
|
|
||||||
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207
|
EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* NewOswan
|
||||||
|
* necinstr.h:
|
||||||
|
* Based on the original Oswan-unix
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
static void i_add_br8(void);
|
static void i_add_br8(void);
|
||||||
static void i_add_wr16(void);
|
static void i_add_wr16(void);
|
||||||
static void i_add_r8b(void);
|
static void i_add_r8b(void);
|
||||||
@@ -263,7 +271,7 @@ void (*nec_instruction[256])(void) =
|
|||||||
i_or_ald8, /* 0x0c */
|
i_or_ald8, /* 0x0c */
|
||||||
i_or_axd16, /* 0x0d */
|
i_or_axd16, /* 0x0d */
|
||||||
i_push_cs, /* 0x0e */
|
i_push_cs, /* 0x0e */
|
||||||
i_pre_nec /* 0x0f */,
|
i_pre_nec, /* 0x0f */
|
||||||
i_adc_br8, /* 0x10 */
|
i_adc_br8, /* 0x10 */
|
||||||
i_adc_wr16, /* 0x11 */
|
i_adc_wr16, /* 0x11 */
|
||||||
i_adc_r8b, /* 0x12 */
|
i_adc_r8b, /* 0x12 */
|
||||||
@@ -462,7 +470,7 @@ void (*nec_instruction[256])(void) =
|
|||||||
i_rotshft_wcl, /* 0xd3 */
|
i_rotshft_wcl, /* 0xd3 */
|
||||||
i_aam, /* 0xd4 */
|
i_aam, /* 0xd4 */
|
||||||
i_aad, /* 0xd5 */
|
i_aad, /* 0xd5 */
|
||||||
i_setalc,
|
i_setalc, /* 0xd6 */
|
||||||
i_trans, /* 0xd7 */
|
i_trans, /* 0xd7 */
|
||||||
i_fpo, /* 0xd8 */
|
i_fpo, /* 0xd8 */
|
||||||
i_fpo, /* 0xd9 */
|
i_fpo, /* 0xd9 */
|
||||||
|
|||||||
@@ -1,65 +1,43 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* NewOswan
|
||||||
|
* necintrf.h:
|
||||||
|
* Based on the original Oswan-unix
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
/* ASG 971222 -- rewrote this interface */
|
/* ASG 971222 -- rewrote this interface */
|
||||||
#ifndef __NECITRF_H_
|
#ifndef __NECITRF_H_
|
||||||
#define __NECITRF_H_
|
#define __NECITRF_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
NEC_IP=1, NEC_AW, NEC_CW, NEC_DW, NEC_BW, NEC_SP, NEC_BP, NEC_IX, NEC_IY,
|
NEC_IP = 1,
|
||||||
NEC_FLAGS, NEC_ES, NEC_CS, NEC_SS, NEC_DS,
|
NEC_AW,
|
||||||
NEC_VECTOR, NEC_PENDING, NEC_NMI_STATE, NEC_IRQ_STATE
|
NEC_CW,
|
||||||
|
NEC_DW,
|
||||||
|
NEC_BW,
|
||||||
|
NEC_SP,
|
||||||
|
NEC_BP,
|
||||||
|
NEC_IX,
|
||||||
|
NEC_IY,
|
||||||
|
NEC_FLAGS,
|
||||||
|
NEC_ES,
|
||||||
|
NEC_CS,
|
||||||
|
NEC_SS,
|
||||||
|
NEC_DS,
|
||||||
|
NEC_VECTOR,
|
||||||
|
NEC_PENDING,
|
||||||
|
NEC_NMI_STATE,
|
||||||
|
NEC_IRQ_STATE
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Public variables */
|
/* Public variables */
|
||||||
extern int nec_ICount;
|
extern int nec_ICount;
|
||||||
|
|
||||||
/* Public functions */
|
/* Public functions */
|
||||||
|
|
||||||
/*
|
|
||||||
#define v20_ICount nec_ICount
|
|
||||||
extern void v20_init(void);
|
|
||||||
extern void v20_reset(void *param);
|
|
||||||
extern void v20_exit(void);
|
|
||||||
extern int v20_execute(int cycles);
|
|
||||||
extern unsigned v20_get_context(void *dst);
|
|
||||||
extern void v20_set_context(void *src);
|
|
||||||
extern unsigned v20_get_reg(int regnum);
|
|
||||||
extern void v20_set_reg(int regnum, unsigned val);
|
|
||||||
extern void v20_set_irq_line(int irqline, int state);
|
|
||||||
extern void v20_set_irq_callback(int (*callback)(int irqline));
|
|
||||||
extern const char *v20_info(void *context, int regnum);
|
|
||||||
extern unsigned v20_dasm(char *buffer, unsigned pc);
|
|
||||||
|
|
||||||
#define v30_ICount nec_ICount
|
|
||||||
extern void v30_init(void);
|
|
||||||
extern void v30_reset(void *param);
|
|
||||||
extern void v30_exit(void);
|
|
||||||
extern int v30_execute(int cycles);
|
|
||||||
extern unsigned v30_get_context(void *dst);
|
|
||||||
extern void v30_set_context(void *src);
|
|
||||||
extern unsigned v30_get_reg(int regnum);
|
|
||||||
extern void v30_set_reg(int regnum, unsigned val);
|
|
||||||
extern void v30_set_irq_line(int irqline, int state);
|
|
||||||
extern void v30_set_irq_callback(int (*callback)(int irqline));
|
|
||||||
extern const char *v30_info(void *context, int regnum);
|
|
||||||
extern unsigned v30_dasm(char *buffer, unsigned pc);
|
|
||||||
|
|
||||||
#define v33_ICount nec_ICount
|
|
||||||
extern void v33_init(void);
|
|
||||||
extern void v33_reset(void *param);
|
|
||||||
extern void v33_exit(void);
|
|
||||||
extern int v33_execute(int cycles);
|
|
||||||
extern unsigned v33_get_context(void *dst);
|
|
||||||
extern void v33_set_context(void *src);
|
|
||||||
extern unsigned v33_get_reg(int regnum);
|
|
||||||
extern void v33_set_reg(int regnum, unsigned val);
|
|
||||||
extern void v33_set_irq_line(int irqline, int state);
|
|
||||||
extern void v33_set_irq_callback(int (*callback)(int irqline));
|
|
||||||
extern const char *v33_info(void *context, int regnum);
|
|
||||||
extern unsigned v33_dasm(char *buffer, unsigned pc);
|
|
||||||
*/
|
|
||||||
|
|
||||||
void nec_set_irq_line(int irqline, int state);
|
void nec_set_irq_line(int irqline, int state);
|
||||||
void nec_set_reg(int regnum, uint32_t val);
|
void nec_set_reg(int regnum, uint32_t val);
|
||||||
int nec_execute(int cycles);
|
int nec_execute(int cycles);
|
||||||
@@ -67,11 +45,4 @@ unsigned nec_get_reg(int regnum);
|
|||||||
void nec_reset(void *param);
|
void nec_reset(void *param);
|
||||||
void nec_int(uint16_t vector);
|
void nec_int(uint16_t vector);
|
||||||
|
|
||||||
uint8_t cpu_readport(uint8_t);
|
|
||||||
void cpu_writeport(uint32_t, uint8_t);
|
|
||||||
#define cpu_readop cpu_readmem20
|
|
||||||
#define cpu_readop_arg cpu_readmem20
|
|
||||||
void cpu_writemem20(uint32_t, uint8_t);
|
|
||||||
uint8_t cpu_readmem20(uint32_t);
|
|
||||||
|
|
||||||
#endif /* __NECITRF_H_ */
|
#endif /* __NECITRF_H_ */
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* NewOswan
|
||||||
|
* necmodrm.h:
|
||||||
|
* Based on the original Oswan-unix
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
static struct
|
static struct
|
||||||
{
|
{
|
||||||
struct
|
struct
|
||||||
|
|||||||
204
source/rom.c
Normal file
204
source/rom.c
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* NewOswan
|
||||||
|
* rom.c:
|
||||||
|
* Based on the original Oswan-unix
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include "log.h"
|
||||||
|
#include "rom.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
uint8_t *ws_rom_load(char *path, uint32_t *romSize)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
uint8_t *ret_ptr;
|
||||||
|
struct stat FileStat;
|
||||||
|
|
||||||
|
fd = open(path, O_RDWR);
|
||||||
|
|
||||||
|
fstat(fd, &FileStat);
|
||||||
|
|
||||||
|
*romSize = FileStat.st_size;
|
||||||
|
|
||||||
|
ret_ptr = (uint8_t *)mmap(NULL, FileStat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
if (ret_ptr == MAP_FAILED)
|
||||||
|
{
|
||||||
|
ret_ptr = NULL;
|
||||||
|
*romSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
const char *eepromSizeName[] =
|
||||||
|
{
|
||||||
|
[WS_EEPROM_SIZE_NONE] = "none",
|
||||||
|
[WS_EEPROM_SIZE_1k] = "1kbits",
|
||||||
|
[WS_EEPROM_SIZE_16k] = "16kbits",
|
||||||
|
[WS_EEPROM_SIZE_8k] = "8kbits",
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *sramSizeName[] =
|
||||||
|
{
|
||||||
|
[WS_SRAM_SIZE_NONE] = "none",
|
||||||
|
[WS_SRAM_SIZE_64k] = "64kbit",
|
||||||
|
[WS_SRAM_SIZE_256k] = "256kbit",
|
||||||
|
[WS_SRAM_SIZE_1M] = "1Mbits",
|
||||||
|
[WS_SRAM_SIZE_2M] = "2Mbits",
|
||||||
|
[WS_SRAM_SIZE_4M] = "4Mbits",
|
||||||
|
};
|
||||||
|
|
||||||
|
void ws_rom_dumpInfo(uint8_t *wsrom, uint32_t romSize)
|
||||||
|
{
|
||||||
|
ws_romHeaderStruct *romHeader = ws_rom_getHeader(wsrom, romSize);
|
||||||
|
|
||||||
|
Log(TLOG_NORMAL, "rom", "developper Id 0x%.2x", romHeader->developperId);
|
||||||
|
Log(TLOG_NORMAL, "rom", "cart Id 0x%.2x", romHeader->cartId);
|
||||||
|
Log(TLOG_NORMAL, "rom", "minimum system %s", (romHeader->minimumSupportSystem == 0) ? "Wonderswan mono" : "Wonderswan color");
|
||||||
|
Log(TLOG_NORMAL, "rom", "size %i Mbits", (romSize >> 20) << 3);
|
||||||
|
Log(TLOG_NORMAL, "rom", "eeprom %s", eepromSizeName[romHeader->saveSize & 0xf]);
|
||||||
|
Log(TLOG_NORMAL, "rom", "sram %s", sramSizeName[romHeader->saveSize & 0xF0]);
|
||||||
|
Log(TLOG_NORMAL, "rom", "rtc %s", (romHeader->realtimeClock) ? "Yes" : "None");
|
||||||
|
Log(TLOG_NORMAL, "rom", "checksum 0x%.4x", romHeader->checksum);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
ws_romHeaderStruct *ws_rom_getHeader(uint8_t *wsrom, uint32_t wsromSize)
|
||||||
|
{
|
||||||
|
ws_romHeaderStruct *wsromHeader = (ws_romHeaderStruct *)(wsrom + wsromSize - sizeof(ws_romHeaderStruct));
|
||||||
|
|
||||||
|
return (wsromHeader);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
uint32_t ws_rom_sramSize(uint8_t *wsrom, uint32_t wsromSize)
|
||||||
|
{
|
||||||
|
ws_romHeaderStruct *romHeader = ws_rom_getHeader(wsrom, wsromSize);
|
||||||
|
|
||||||
|
switch (romHeader->saveSize & 0x0f)
|
||||||
|
{
|
||||||
|
case WS_SRAM_SIZE_NONE:
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case WS_SRAM_SIZE_64k:
|
||||||
|
return 0x2000;
|
||||||
|
|
||||||
|
case WS_SRAM_SIZE_256k:
|
||||||
|
return 0x8000;
|
||||||
|
|
||||||
|
case WS_SRAM_SIZE_1M:
|
||||||
|
return 0x20000;
|
||||||
|
|
||||||
|
case WS_SRAM_SIZE_2M:
|
||||||
|
return 0x40000;
|
||||||
|
|
||||||
|
case WS_SRAM_SIZE_4M:
|
||||||
|
return 0x80000;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Log(TLOG_PANIC, "ROM", "Invalid SRAM size (%02X)! Please check cart metadata!", romHeader->saveSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
uint32_t ws_rom_eepromSize(uint8_t *wsrom, uint32_t wsromSize)
|
||||||
|
{
|
||||||
|
ws_romHeaderStruct *romHeader = ws_rom_getHeader(wsrom, wsromSize);
|
||||||
|
|
||||||
|
switch (romHeader->saveSize & 0xf0)
|
||||||
|
{
|
||||||
|
case WS_EEPROM_SIZE_NONE:
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case WS_EEPROM_SIZE_1k:
|
||||||
|
return 0x80;
|
||||||
|
|
||||||
|
case WS_EEPROM_SIZE_16k:
|
||||||
|
return 0x800;
|
||||||
|
|
||||||
|
case WS_EEPROM_SIZE_8k:
|
||||||
|
return 0x100;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Log(TLOG_PANIC, "ROM", "Invalid SRAM size (%02X)! Please check cart metadata!", romHeader->saveSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
214
source/rom.cpp
214
source/rom.cpp
@@ -1,214 +0,0 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include "log.h"
|
|
||||||
#include "rom.h"
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
uint8_t *ws_rom_load(char *path, uint32_t *romSize)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
uint8_t *ret_ptr;
|
|
||||||
struct stat FileStat;
|
|
||||||
|
|
||||||
fd = open(path, O_RDWR);
|
|
||||||
|
|
||||||
fstat(fd, &FileStat);
|
|
||||||
|
|
||||||
*romSize = FileStat.st_size;
|
|
||||||
|
|
||||||
ret_ptr = (uint8_t *)mmap(NULL, FileStat.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
if (ret_ptr == MAP_FAILED)
|
|
||||||
{
|
|
||||||
ret_ptr = NULL;
|
|
||||||
*romSize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret_ptr;
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
void ws_rom_dumpInfo(uint8_t *wsrom, uint32_t romSize)
|
|
||||||
{
|
|
||||||
ws_romHeaderStruct *romHeader=ws_rom_getHeader(wsrom,romSize);
|
|
||||||
|
|
||||||
fprintf(log_get(),"rom: developper Id 0x%.2x\n",romHeader->developperId);
|
|
||||||
fprintf(log_get(),"rom: cart Id 0x%.2x\n",romHeader->cartId);
|
|
||||||
fprintf(log_get(),"rom: minimum system %s\n",(romHeader->minimumSupportSystem==WS_SYSTEM_MONO)?"Wonderswan mono":"Wonderswan color");
|
|
||||||
fprintf(log_get(),"rom: size %i Mbits\n",(romSize>>20)<<3);
|
|
||||||
fprintf(log_get(),"rom: eeprom ");
|
|
||||||
|
|
||||||
switch (romHeader->eepromSize&0xf)
|
|
||||||
{
|
|
||||||
case WS_EEPROM_SIZE_NONE:
|
|
||||||
{
|
|
||||||
fprintf(log_get(),"none\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case WS_EEPROM_SIZE_64k:
|
|
||||||
{
|
|
||||||
fprintf(log_get(),"64 kb\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case WS_EEPROM_SIZE_256k:
|
|
||||||
{
|
|
||||||
fprintf(log_get(),"256 kb\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(log_get(),"rom: sram ");
|
|
||||||
|
|
||||||
switch (romHeader->eepromSize&0xf0)
|
|
||||||
{
|
|
||||||
case WS_SRAM_SIZE_NONE:
|
|
||||||
{
|
|
||||||
fprintf(log_get(),"none\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case WS_SRAM_SIZE_1k:
|
|
||||||
{
|
|
||||||
fprintf(log_get(),"1 kb\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case WS_SRAM_SIZE_16k:
|
|
||||||
{
|
|
||||||
fprintf(log_get(),"16 kb\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case WS_SRAM_SIZE_8k:
|
|
||||||
{
|
|
||||||
fprintf(log_get(),"8 kn\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(log_get(),"rom: rtc %s\n",(romHeader->realtimeClock)?"Yes":"None");
|
|
||||||
fprintf(log_get(),"checksum 0x%.4x\n",romHeader->checksum);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
ws_romHeaderStruct *ws_rom_getHeader(uint8_t *wsrom, uint32_t wsromSize)
|
|
||||||
{
|
|
||||||
ws_romHeaderStruct *wsromHeader = (ws_romHeaderStruct *)(wsrom + wsromSize - 10);
|
|
||||||
|
|
||||||
return(wsromHeader);
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
uint32_t ws_rom_sramSize(uint8_t *wsrom, uint32_t wsromSize)
|
|
||||||
{
|
|
||||||
ws_romHeaderStruct *romHeader=ws_rom_getHeader(wsrom,wsromSize);
|
|
||||||
|
|
||||||
switch (romHeader->eepromSize&0xf0)
|
|
||||||
{
|
|
||||||
case WS_SRAM_SIZE_NONE:
|
|
||||||
return(0);
|
|
||||||
|
|
||||||
case WS_SRAM_SIZE_1k:
|
|
||||||
return(0x400);
|
|
||||||
|
|
||||||
case WS_SRAM_SIZE_16k:
|
|
||||||
return(0x4000);
|
|
||||||
|
|
||||||
case WS_SRAM_SIZE_8k:
|
|
||||||
return(0x2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
uint32_t ws_rom_eepromSize(uint8_t *wsrom, uint32_t wsromSize)
|
|
||||||
{
|
|
||||||
ws_romHeaderStruct *romHeader=ws_rom_getHeader(wsrom,wsromSize);
|
|
||||||
|
|
||||||
switch (romHeader->eepromSize&0xf)
|
|
||||||
{
|
|
||||||
case WS_EEPROM_SIZE_NONE:
|
|
||||||
return(0);
|
|
||||||
|
|
||||||
case WS_EEPROM_SIZE_64k:
|
|
||||||
return(0x10000);
|
|
||||||
|
|
||||||
case WS_EEPROM_SIZE_256k:
|
|
||||||
return(0x40000);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
61
source/rom.h
61
source/rom.h
@@ -1,5 +1,11 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
/*******************************************************************************
|
||||||
//
|
* NewOswan
|
||||||
|
* rom.h:
|
||||||
|
* Based on the original Oswan-unix
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@@ -12,8 +18,7 @@
|
|||||||
#ifndef __ROM_H__
|
#ifndef __ROM_H__
|
||||||
#define __ROM_H__
|
#define __ROM_H__
|
||||||
|
|
||||||
#define WS_SYSTEM_MONO 0
|
#include <stdint.h>
|
||||||
#define WS_SYSTEM_COLOR 1
|
|
||||||
|
|
||||||
#define WS_ROM_SIZE_2MBIT 1
|
#define WS_ROM_SIZE_2MBIT 1
|
||||||
#define WS_ROM_SIZE_4MBIT 2
|
#define WS_ROM_SIZE_4MBIT 2
|
||||||
@@ -26,26 +31,36 @@
|
|||||||
#define WS_ROM_SIZE_128MBIT 9
|
#define WS_ROM_SIZE_128MBIT 9
|
||||||
|
|
||||||
#define WS_EEPROM_SIZE_NONE 0
|
#define WS_EEPROM_SIZE_NONE 0
|
||||||
|
#define WS_EEPROM_SIZE_1k 0x10
|
||||||
|
#define WS_EEPROM_SIZE_16k 0x20
|
||||||
|
#define WS_EEPROM_SIZE_32k 0x30
|
||||||
|
/* 40 is not valid */
|
||||||
|
#define WS_EEPROM_SIZE_8k 0x50
|
||||||
|
#define WS_EEPROM_SIZE_4k 0x60
|
||||||
|
#define WS_EEPROM_SIZE_2k 0x70
|
||||||
|
|
||||||
#define WS_SRAM_SIZE_NONE 0
|
#define WS_SRAM_SIZE_NONE 0
|
||||||
#define WS_EEPROM_SIZE_64k 1
|
#define WS_SRAM_SIZE_64k 0x01
|
||||||
#define WS_EEPROM_SIZE_256k 2
|
#define WS_SRAM_SIZE_256k 0x02
|
||||||
#define WS_SRAM_SIZE_1k 10
|
#define WS_SRAM_SIZE_1M 0x03
|
||||||
#define WS_SRAM_SIZE_16k 20
|
#define WS_SRAM_SIZE_2M 0x04
|
||||||
#define WS_SRAM_SIZE_8k 50
|
#define WS_SRAM_SIZE_4M 0x05
|
||||||
|
|
||||||
|
|
||||||
|
#pragma pack(1)
|
||||||
typedef struct ws_romHeaderStruct
|
typedef struct ws_romHeaderStruct
|
||||||
{
|
{
|
||||||
uint8_t developperId;
|
/* Miss "Fixed Data" (F5h) */
|
||||||
uint8_t minimumSupportSystem;
|
uint8_t developperId; /* Maker Code L */
|
||||||
uint8_t cartId;
|
uint8_t minimumSupportSystem; /* Maker Code H */
|
||||||
uint8_t romSize;
|
uint8_t cartId; /* Title code */
|
||||||
uint8_t eepromSize;
|
uint8_t gameVersion; /* Version */
|
||||||
uint8_t additionnalCapabilities;
|
uint8_t romSize; /* ROM Size */
|
||||||
uint8_t realtimeClock;
|
uint8_t saveSize; /* XROM/XEROM Size */
|
||||||
uint16_t checksum;
|
uint8_t cartFlags; /* Boot loader */
|
||||||
|
uint8_t realtimeClock; /* Syb System LSI */
|
||||||
|
uint16_t checksum; /* Checksum */
|
||||||
} ws_romHeaderStruct;
|
} ws_romHeaderStruct;
|
||||||
|
#pragma pack()
|
||||||
|
|
||||||
uint8_t *ws_rom_load(char *path, uint32_t *romSize);
|
uint8_t *ws_rom_load(char *path, uint32_t *romSize);
|
||||||
void ws_rom_dumpInfo(uint8_t *wsrom, uint32_t wsromSize);
|
void ws_rom_dumpInfo(uint8_t *wsrom, uint32_t wsromSize);
|
||||||
@@ -53,5 +68,11 @@ ws_romHeaderStruct *ws_rom_getHeader(uint8_t *wsrom, uint32_t wsromSize);
|
|||||||
uint32_t ws_rom_sramSize(uint8_t *wsrom, uint32_t wsromSize);
|
uint32_t ws_rom_sramSize(uint8_t *wsrom, uint32_t wsromSize);
|
||||||
uint32_t ws_rom_eepromSize(uint8_t *wsrom, uint32_t wsromSize);
|
uint32_t ws_rom_eepromSize(uint8_t *wsrom, uint32_t wsromSize);
|
||||||
|
|
||||||
#endif
|
static inline uint8_t *ws_get_page_ptr(uint8_t *wsrom, uint32_t romSize, uint16_t page)
|
||||||
|
{
|
||||||
|
uint32_t temp = page << 16;
|
||||||
|
temp &= (romSize - 1);
|
||||||
|
return &wsrom[temp];
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
505
source/ws.c
Normal file
505
source/ws.c
Normal file
@@ -0,0 +1,505 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* NewOswan
|
||||||
|
* ws.c: Base wonderswan implementation
|
||||||
|
* Based on the original Oswan-unix
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// 07.04.2002: speed problems partially fixed
|
||||||
|
// 13.04.2002: Set cycles by line to 256 (according to toshi)
|
||||||
|
// this seems to work well in most situations with
|
||||||
|
// the new nec v30 cpu core
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "log.h"
|
||||||
|
#include "rom.h"
|
||||||
|
#include "./nec/nec.h"
|
||||||
|
#include "./nec/necintrf.h"
|
||||||
|
#include "memory.h"
|
||||||
|
#include "gpu.h"
|
||||||
|
#include "io.h"
|
||||||
|
#include "audio.h"
|
||||||
|
#include "ws.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
uint32_t ws_cycles;
|
||||||
|
uint32_t ws_skip;
|
||||||
|
uint32_t ws_cyclesByLine = 0;
|
||||||
|
uint32_t vblank_count = 0;
|
||||||
|
|
||||||
|
char *ws_sram_path = NULL;
|
||||||
|
char *ws_ieep_path = NULL;
|
||||||
|
char *ws_rom_path = NULL;
|
||||||
|
wssystem_t systemType;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void ws_patchRom(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint8_t *rom = memory_getRom();
|
||||||
|
uint32_t romSize = memory_getRomSize();
|
||||||
|
|
||||||
|
Log(TLOG_DEBUG, "ws", "developper Id: 0x%.2x", rom[romSize - 10]);
|
||||||
|
Log(TLOG_DEBUG, "ws", "Game Id: 0x%.2x", rom[romSize - 8]);
|
||||||
|
|
||||||
|
if (!ws_cyclesByLine)
|
||||||
|
{
|
||||||
|
ws_cyclesByLine = 256;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
int ws_init(char *rompath)
|
||||||
|
{
|
||||||
|
uint8_t *rom;
|
||||||
|
uint32_t romSize;
|
||||||
|
|
||||||
|
if ((rom = ws_rom_load(rompath, &romSize)) == NULL)
|
||||||
|
{
|
||||||
|
Log(TLOG_PANIC, "ws", "Error: cannot load %s", rompath);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ws_staticRam = (uint8_t *)load_file(ws_sram_path);
|
||||||
|
if (ws_staticRam == NULL)
|
||||||
|
{
|
||||||
|
ws_staticRam = (uint8_t *)create_file(ws_sram_path, 0x10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ws_staticRam == NULL)
|
||||||
|
{
|
||||||
|
Log(TLOG_PANIC, "ws", "Card SRAM load error!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
externalEeprom = (uint8_t *)load_file(ws_ieep_path);
|
||||||
|
if (externalEeprom == NULL)
|
||||||
|
{
|
||||||
|
externalEeprom = (uint8_t *)create_file(ws_ieep_path, 0x100000);
|
||||||
|
}
|
||||||
|
if (externalEeprom == NULL)
|
||||||
|
{
|
||||||
|
Log(TLOG_PANIC, "ws", "Card EEPROM load error!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ws_memory_init(rom, romSize);
|
||||||
|
ws_patchRom();
|
||||||
|
|
||||||
|
io_init();
|
||||||
|
ws_audio_init();
|
||||||
|
ws_gpu_init();
|
||||||
|
|
||||||
|
if (ws_rotated())
|
||||||
|
{
|
||||||
|
io_flipControls();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void ws_reset(void)
|
||||||
|
{
|
||||||
|
ws_memory_reset();
|
||||||
|
io_reset();
|
||||||
|
ws_audio_reset();
|
||||||
|
ws_gpu_reset();
|
||||||
|
nec_reset(NULL);
|
||||||
|
nec_set_reg(NEC_SP, 0x2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
int ws_executeLine(int16_t *framebuffer, int renderLine)
|
||||||
|
{
|
||||||
|
int drawWholeScreen = 0;
|
||||||
|
|
||||||
|
ws_audio_process();
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
|
||||||
|
if (ws_cycles >= ws_cyclesByLine + ws_cyclesByLine)
|
||||||
|
{
|
||||||
|
ws_skip = ws_cycles / ws_cyclesByLine;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ws_skip = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ws_cycles %= ws_cyclesByLine;
|
||||||
|
|
||||||
|
for (uint32_t uI = 0 ; uI < ws_skip ; uI++)
|
||||||
|
{
|
||||||
|
if (renderLine)
|
||||||
|
{
|
||||||
|
ws_gpu_renderScanline(framebuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
ws_gpu_scanline++;
|
||||||
|
|
||||||
|
if (ws_gpu_scanline == 144)
|
||||||
|
{
|
||||||
|
drawWholeScreen = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ws_gpu_scanline > 158)
|
||||||
|
{
|
||||||
|
ws_gpu_scanline = 0;
|
||||||
|
{
|
||||||
|
if ((ws_ioRam[0xb2] & 32)) /* VBLANK Timer */
|
||||||
|
{
|
||||||
|
/* TODO: REPAIR THAT SHIT */
|
||||||
|
ws_ioRam[0xb6] &= ~32;
|
||||||
|
nec_int((ws_ioRam[0xb0] + 5) * 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ws_ioRam[2] = ws_gpu_scanline;
|
||||||
|
|
||||||
|
if (drawWholeScreen)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (ws_ioRam[0xb2] & 64) /* VBLANK INT */
|
||||||
|
{
|
||||||
|
ws_ioRam[0xb6] &= ~64;
|
||||||
|
nec_int((ws_ioRam[0xb0] + 6) * 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
vblank_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ws_ioRam[0xa4] && (ws_ioRam[0xb2] & 128)) /*HBLANK TMR*/
|
||||||
|
{
|
||||||
|
/* TODO: Check that shit */
|
||||||
|
if (!ws_ioRam[0xa5])
|
||||||
|
{
|
||||||
|
ws_ioRam[0xa5] = ws_ioRam[0xa4];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ws_ioRam[0xa5])
|
||||||
|
{
|
||||||
|
ws_ioRam[0xa5]--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!ws_ioRam[0xa5]) && (ws_ioRam[0xb2] & 128))
|
||||||
|
{
|
||||||
|
|
||||||
|
ws_ioRam[0xb6] &= ~128;
|
||||||
|
nec_int((ws_ioRam[0xb0] + 7) * 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ws_ioRam[0x2] == ws_ioRam[0x3]) && (ws_ioRam[0xb2] & 16)) /*SCANLINE INT*/
|
||||||
|
{
|
||||||
|
ws_ioRam[0xb6] &= ~16;
|
||||||
|
nec_int((ws_ioRam[0xb0] + 4) * 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (drawWholeScreen);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void ws_done(void)
|
||||||
|
{
|
||||||
|
ws_memory_done();
|
||||||
|
io_done();
|
||||||
|
ws_audio_done();
|
||||||
|
ws_gpu_done();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void ws_set_system(wssystem_t system)
|
||||||
|
{
|
||||||
|
if (system == WS_SYSTEM_AUTODETECT)
|
||||||
|
{
|
||||||
|
system = WS_SYSTEM_CRYSTAL;
|
||||||
|
}
|
||||||
|
systemType = system;
|
||||||
|
}
|
||||||
|
|
||||||
|
wssystem_t ws_get_system()
|
||||||
|
{
|
||||||
|
return systemType;
|
||||||
|
}
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#define MacroLoadNecRegisterFromFile(F, R) \
|
||||||
|
read(fp,&value,sizeof(value)); \
|
||||||
|
nec_set_reg(R,value);
|
||||||
|
|
||||||
|
int ws_loadState(char *statepath)
|
||||||
|
{
|
||||||
|
Log(TLOG_NORMAL, "ws", "loading %s\n", statepath);
|
||||||
|
uint16_t crc = memory_getRomCrc();
|
||||||
|
uint16_t newCrc;
|
||||||
|
unsigned value;
|
||||||
|
uint8_t ws_newVideoMode;
|
||||||
|
|
||||||
|
int fp = open(statepath, O_RDONLY);
|
||||||
|
|
||||||
|
if (fp == -1)
|
||||||
|
{
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
read(fp, &newCrc, 2);
|
||||||
|
|
||||||
|
if (newCrc != crc)
|
||||||
|
{
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_IP);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_AW);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_BW);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_CW);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_DW);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_CS);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_DS);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_ES);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_SS);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_IX);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_IY);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_BP);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_SP);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_FLAGS);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_VECTOR);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_PENDING);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_NMI_STATE);
|
||||||
|
MacroLoadNecRegisterFromFile(fp, NEC_IRQ_STATE);
|
||||||
|
|
||||||
|
read(fp, internalRam, 65536);
|
||||||
|
read(fp, ws_staticRam, 65536);
|
||||||
|
read(fp, ws_ioRam, 256);
|
||||||
|
read(fp, ws_paletteColors, 8);
|
||||||
|
read(fp, ws_palette, 16 * 4 * 2);
|
||||||
|
read(fp, wsc_palette, 16 * 16 * 2);
|
||||||
|
read(fp, &ws_newVideoMode, 1);
|
||||||
|
read(fp, &ws_gpu_scanline, 1);
|
||||||
|
read(fp, externalEeprom, 131072);
|
||||||
|
|
||||||
|
ws_audio_readState(fp);
|
||||||
|
close(fp);
|
||||||
|
|
||||||
|
// force a video mode change to make all tiles dirty
|
||||||
|
ws_gpu_clearCache();
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#define MacroStoreNecRegisterToFile(F, R) \
|
||||||
|
value=nec_get_reg(R); \
|
||||||
|
write(fp,&value,sizeof(value));
|
||||||
|
|
||||||
|
int ws_saveState(char *statepath)
|
||||||
|
{
|
||||||
|
uint16_t crc = memory_getRomCrc();
|
||||||
|
uint32_t value;
|
||||||
|
char newPath[1024];
|
||||||
|
Log(TLOG_DEBUG, "ws", "saving %s\n", statepath);
|
||||||
|
|
||||||
|
if (strlen(statepath) < 4)
|
||||||
|
{
|
||||||
|
sprintf(newPath, "%s.wss", statepath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int len = strlen(statepath);
|
||||||
|
|
||||||
|
if ((statepath[len - 1] != 's') && (statepath[len - 1] != 'S'))
|
||||||
|
{
|
||||||
|
sprintf(newPath, "%s.wss", statepath);
|
||||||
|
}
|
||||||
|
else if ((statepath[len - 2] != 's') && (statepath[len - 2] != 'S'))
|
||||||
|
{
|
||||||
|
sprintf(newPath, "%s.wss", statepath);
|
||||||
|
}
|
||||||
|
else if ((statepath[len - 3] != 'w') && (statepath[len - 3] != 'w'))
|
||||||
|
{
|
||||||
|
sprintf(newPath, "%s.wss", statepath);
|
||||||
|
}
|
||||||
|
else if (statepath[len - 4] != '.')
|
||||||
|
{
|
||||||
|
sprintf(newPath, "%s.wss", statepath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sprintf(newPath, "%s", statepath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int fp = open(newPath, O_RDWR | O_CREAT, 0644);
|
||||||
|
|
||||||
|
if (fp == -1)
|
||||||
|
{
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
write(fp, &crc, 2);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_IP);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_AW);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_BW);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_CW);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_DW);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_CS);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_DS);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_ES);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_SS);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_IX);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_IY);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_BP);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_SP);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_FLAGS);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_VECTOR);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_PENDING);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_NMI_STATE);
|
||||||
|
MacroStoreNecRegisterToFile(fp, NEC_IRQ_STATE);
|
||||||
|
|
||||||
|
write(fp, internalRam, 65536);
|
||||||
|
write(fp, ws_staticRam, 65536);
|
||||||
|
write(fp, ws_ioRam, 256);
|
||||||
|
write(fp, ws_paletteColors, 8);
|
||||||
|
write(fp, ws_palette, 16 * 4 * 2);
|
||||||
|
write(fp, wsc_palette, 16 * 16 * 2);
|
||||||
|
write(fp, &ws_videoMode, 1);
|
||||||
|
write(fp, &ws_gpu_scanline, 1);
|
||||||
|
write(fp, externalEeprom, 131072);
|
||||||
|
|
||||||
|
ws_audio_writeState(fp);
|
||||||
|
close(fp);
|
||||||
|
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
int ws_rotated(void)
|
||||||
|
{
|
||||||
|
uint8_t *rom = memory_getRom();
|
||||||
|
uint32_t romSize = memory_getRomSize();
|
||||||
|
|
||||||
|
return (rom[romSize - 4] & 1);
|
||||||
|
}
|
||||||
523
source/ws.cpp
523
source/ws.cpp
@@ -1,523 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Wonderswan emulator
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// 07.04.2002: speed problems partially fixed
|
|
||||||
// 13.04.2002: Set cycles by line to 256 (according to toshi)
|
|
||||||
// this seems to work well in most situations with
|
|
||||||
// the new nec v30 cpu core
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include "log.h"
|
|
||||||
#include "rom.h"
|
|
||||||
#include "./nec/nec.h"
|
|
||||||
#include "./nec/necintrf.h"
|
|
||||||
#include "memory.h"
|
|
||||||
#include "gpu.h"
|
|
||||||
#include "io.h"
|
|
||||||
#include "audio.h"
|
|
||||||
#include "ws.h"
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
uint32_t ws_cycles;
|
|
||||||
uint32_t ws_skip;
|
|
||||||
uint32_t ws_cyclesByLine=0;
|
|
||||||
uint32_t vblank_count=0;
|
|
||||||
|
|
||||||
char *ws_sram_path = NULL;
|
|
||||||
char *ws_ieep_path = NULL;
|
|
||||||
char *ws_rom_path = NULL;
|
|
||||||
extern int ws_gpu_forceColorSystemBool;
|
|
||||||
extern int ws_gpu_forceMonoSystemBool;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
void ws_patchRom(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
uint8_t *rom=memory_getRom();
|
|
||||||
uint32_t romSize=memory_getRomSize();
|
|
||||||
|
|
||||||
fprintf(log_get(),"developper Id: 0x%.2x\nGame Id: 0x%.2x\n",rom[romSize-10],rom[romSize-8]);
|
|
||||||
|
|
||||||
if (!ws_cyclesByLine)
|
|
||||||
{
|
|
||||||
ws_cyclesByLine=256;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
int ws_init(char *rompath)
|
|
||||||
{
|
|
||||||
uint8_t *rom;
|
|
||||||
uint32_t romSize;
|
|
||||||
|
|
||||||
if ((rom=ws_rom_load(rompath,&romSize))==NULL)
|
|
||||||
{
|
|
||||||
printf("Error: cannot load %s\n",rompath);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((ws_gpu_forceColorSystemBool == 0) && (ws_gpu_forceMonoSystemBool == 0))
|
|
||||||
{
|
|
||||||
/* Nothing forced try to "auto detect" */
|
|
||||||
if (rompath[strlen(rompath)-1]=='c')
|
|
||||||
{
|
|
||||||
ws_gpu_operatingInColor=1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ws_gpu_operatingInColor=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ws_memory_init(rom, romSize);
|
|
||||||
ws_patchRom();
|
|
||||||
|
|
||||||
ws_staticRam = (uint8_t *)load_file(ws_ieep_path);
|
|
||||||
if (ws_staticRam == NULL)
|
|
||||||
{
|
|
||||||
ws_staticRam = (uint8_t *)create_file(ws_sram_path, 0x10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ws_staticRam == NULL)
|
|
||||||
{
|
|
||||||
printf("Card SRAM load error!\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
externalEeprom = (uint8_t *)load_file(ws_ieep_path);
|
|
||||||
if (externalEeprom == NULL)
|
|
||||||
{
|
|
||||||
externalEeprom = (uint8_t *)create_file(ws_ieep_path, 0x100000);
|
|
||||||
}
|
|
||||||
if (externalEeprom == NULL)
|
|
||||||
{
|
|
||||||
printf("Card EEPROM load error!\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ws_io_init();
|
|
||||||
ws_audio_init();
|
|
||||||
ws_gpu_init();
|
|
||||||
|
|
||||||
if (ws_rotated())
|
|
||||||
{
|
|
||||||
ws_io_flipControls();
|
|
||||||
}
|
|
||||||
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
void ws_reset(void)
|
|
||||||
{
|
|
||||||
ws_memory_reset();
|
|
||||||
ws_io_reset();
|
|
||||||
ws_audio_reset();
|
|
||||||
ws_gpu_reset();
|
|
||||||
nec_reset(NULL);
|
|
||||||
nec_set_reg(NEC_SP,0x2000);
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
int ws_executeLine(int16_t *framebuffer, int renderLine)
|
|
||||||
{
|
|
||||||
int drawWholeScreen=0;
|
|
||||||
|
|
||||||
ws_audio_process();
|
|
||||||
|
|
||||||
// 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));
|
|
||||||
|
|
||||||
if(ws_cycles>=ws_cyclesByLine+ws_cyclesByLine)
|
|
||||||
{
|
|
||||||
ws_skip=ws_cycles/ws_cyclesByLine;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ws_skip=1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ws_cycles%=ws_cyclesByLine;
|
|
||||||
|
|
||||||
for(uint32_t uI=0; uI<ws_skip; uI++)
|
|
||||||
{
|
|
||||||
if (renderLine)
|
|
||||||
{
|
|
||||||
ws_gpu_renderScanline(framebuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
ws_gpu_scanline++;
|
|
||||||
|
|
||||||
if(ws_gpu_scanline==144)
|
|
||||||
{
|
|
||||||
drawWholeScreen=1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ws_gpu_scanline>158)
|
|
||||||
{
|
|
||||||
ws_gpu_scanline=0;
|
|
||||||
{
|
|
||||||
if((ws_ioRam[0xb2]&32)) /* VBLANK Timer */
|
|
||||||
{
|
|
||||||
/* TODO: REPAIR THAT SHIT */
|
|
||||||
ws_ioRam[0xb6]&=~32;
|
|
||||||
nec_int((ws_ioRam[0xb0]+5)*4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ws_ioRam[2]=ws_gpu_scanline;
|
|
||||||
|
|
||||||
if(drawWholeScreen)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(ws_ioRam[0xb2]&64) /* VBLANK INT */
|
|
||||||
{
|
|
||||||
ws_ioRam[0xb6]&=~64;
|
|
||||||
nec_int((ws_ioRam[0xb0]+6)*4);
|
|
||||||
}
|
|
||||||
|
|
||||||
vblank_count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ws_ioRam[0xa4]&&(ws_ioRam[0xb2]&128)) /*HBLANK TMR*/
|
|
||||||
{
|
|
||||||
/* TODO: Check that shit */
|
|
||||||
if(!ws_ioRam[0xa5])
|
|
||||||
{
|
|
||||||
ws_ioRam[0xa5]=ws_ioRam[0xa4];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ws_ioRam[0xa5])
|
|
||||||
{
|
|
||||||
ws_ioRam[0xa5]--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((!ws_ioRam[0xa5])&&(ws_ioRam[0xb2]&128))
|
|
||||||
{
|
|
||||||
|
|
||||||
ws_ioRam[0xb6]&=~128;
|
|
||||||
nec_int((ws_ioRam[0xb0]+7)*4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if((ws_ioRam[0x2]==ws_ioRam[0x3])&&(ws_ioRam[0xb2]&16)) /*SCANLINE INT*/
|
|
||||||
{
|
|
||||||
ws_ioRam[0xb6]&=~16;
|
|
||||||
nec_int((ws_ioRam[0xb0]+4)*4);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(drawWholeScreen);
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
void ws_done(void)
|
|
||||||
{
|
|
||||||
ws_memory_done();
|
|
||||||
ws_io_done();
|
|
||||||
ws_audio_done();
|
|
||||||
ws_gpu_done();
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
void ws_set_colour_scheme(int scheme)
|
|
||||||
{
|
|
||||||
ws_gpu_set_colour_scheme(scheme);
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
void ws_set_system(int system)
|
|
||||||
{
|
|
||||||
if (system==WS_SYSTEM_COLOR)
|
|
||||||
{
|
|
||||||
ws_gpu_forceColorSystem();
|
|
||||||
}
|
|
||||||
else if (system==WS_SYSTEM_MONO)
|
|
||||||
{
|
|
||||||
ws_gpu_forceMonoSystem();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
#define MacroLoadNecRegisterFromFile(F,R) \
|
|
||||||
read(fp,&value,sizeof(value)); \
|
|
||||||
nec_set_reg(R,value);
|
|
||||||
|
|
||||||
int ws_loadState(char *statepath)
|
|
||||||
{
|
|
||||||
fprintf(log_get(),"loading %s\n",statepath);
|
|
||||||
uint16_t crc=memory_getRomCrc();
|
|
||||||
uint16_t newCrc;
|
|
||||||
unsigned value;
|
|
||||||
uint8_t ws_newVideoMode;
|
|
||||||
|
|
||||||
int fp = open(statepath, O_RDONLY);
|
|
||||||
|
|
||||||
if (fp == -1)
|
|
||||||
{
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
read(fp, &newCrc, 2);
|
|
||||||
|
|
||||||
if (newCrc!=crc)
|
|
||||||
{
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_IP);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_AW);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_BW);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_CW);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_DW);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_CS);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_DS);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_ES);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_SS);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_IX);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_IY);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_BP);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_SP);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_FLAGS);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_VECTOR);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_PENDING);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_NMI_STATE);
|
|
||||||
MacroLoadNecRegisterFromFile(fp,NEC_IRQ_STATE);
|
|
||||||
|
|
||||||
read(fp,internalRam,65536);
|
|
||||||
read(fp,ws_staticRam,65536);
|
|
||||||
read(fp,ws_ioRam,256);
|
|
||||||
read(fp,ws_paletteColors,8);
|
|
||||||
read(fp,ws_palette,16*4*2);
|
|
||||||
read(fp,wsc_palette,16*16*2);
|
|
||||||
read(fp,&ws_newVideoMode,1);
|
|
||||||
read(fp,&ws_gpu_scanline,1);
|
|
||||||
read(fp,externalEeprom,131072);
|
|
||||||
|
|
||||||
ws_audio_readState(fp);
|
|
||||||
close(fp);
|
|
||||||
|
|
||||||
// force a video mode change to make all tiles dirty
|
|
||||||
ws_gpu_clearCache();
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
#define MacroStoreNecRegisterToFile(F,R) \
|
|
||||||
value=nec_get_reg(R); \
|
|
||||||
write(fp,&value,sizeof(value));
|
|
||||||
|
|
||||||
int ws_saveState(char *statepath)
|
|
||||||
{
|
|
||||||
uint16_t crc=memory_getRomCrc();
|
|
||||||
uint32_t value;
|
|
||||||
char *newPath;
|
|
||||||
fprintf(log_get(),"saving %s\n",statepath);
|
|
||||||
|
|
||||||
newPath=new char[1024];
|
|
||||||
|
|
||||||
if (strlen(statepath)<4)
|
|
||||||
{
|
|
||||||
sprintf(newPath,"%s.wss",statepath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int len=strlen(statepath);
|
|
||||||
|
|
||||||
if ((statepath[len-1]!='s')&&(statepath[len-1]!='S'))
|
|
||||||
{
|
|
||||||
sprintf(newPath,"%s.wss",statepath);
|
|
||||||
}
|
|
||||||
else if ((statepath[len-2]!='s')&&(statepath[len-2]!='S'))
|
|
||||||
{
|
|
||||||
sprintf(newPath,"%s.wss",statepath);
|
|
||||||
}
|
|
||||||
else if ((statepath[len-3]!='w')&&(statepath[len-3]!='w'))
|
|
||||||
{
|
|
||||||
sprintf(newPath,"%s.wss",statepath);
|
|
||||||
}
|
|
||||||
else if (statepath[len-4]!='.')
|
|
||||||
{
|
|
||||||
sprintf(newPath,"%s.wss",statepath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sprintf(newPath,"%s",statepath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int fp=open(newPath, O_RDWR|O_CREAT, 0644);
|
|
||||||
delete newPath;
|
|
||||||
|
|
||||||
if (fp==-1)
|
|
||||||
{
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
write(fp,&crc,2);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_IP);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_AW);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_BW);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_CW);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_DW);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_CS);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_DS);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_ES);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_SS);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_IX);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_IY);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_BP);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_SP);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_FLAGS);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_VECTOR);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_PENDING);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_NMI_STATE);
|
|
||||||
MacroStoreNecRegisterToFile(fp,NEC_IRQ_STATE);
|
|
||||||
|
|
||||||
write(fp,internalRam,65536);
|
|
||||||
write(fp,ws_staticRam,65536);
|
|
||||||
write(fp,ws_ioRam,256);
|
|
||||||
write(fp,ws_paletteColors,8);
|
|
||||||
write(fp,ws_palette,16*4*2);
|
|
||||||
write(fp,wsc_palette,16*16*2);
|
|
||||||
write(fp,&ws_videoMode,1);
|
|
||||||
write(fp,&ws_gpu_scanline,1);
|
|
||||||
write(fp,externalEeprom,131072);
|
|
||||||
|
|
||||||
ws_audio_writeState(fp);
|
|
||||||
close(fp);
|
|
||||||
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
int ws_rotated(void)
|
|
||||||
{
|
|
||||||
uint8_t *rom=memory_getRom();
|
|
||||||
uint32_t romSize=memory_getRomSize();
|
|
||||||
|
|
||||||
return(rom[romSize-4]&1);
|
|
||||||
}
|
|
||||||
23
source/ws.h
23
source/ws.h
@@ -1,5 +1,11 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
/*******************************************************************************
|
||||||
//
|
* NewOswan
|
||||||
|
* ws.h:
|
||||||
|
* Based on the original Oswan-unix
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@@ -12,16 +18,19 @@
|
|||||||
#ifndef __WS_H__
|
#ifndef __WS_H__
|
||||||
#define __WS_H__
|
#define __WS_H__
|
||||||
|
|
||||||
#define WS_SYSTEM_MONO 0
|
#include <stdint.h>
|
||||||
#define WS_SYSTEM_COLOR 1
|
|
||||||
#define WS_SYSTEM_AUTODETECT 2
|
typedef enum wssystem_t
|
||||||
|
{
|
||||||
|
WS_SYSTEM_AUTODETECT = 0, WS_SYSTEM_MONO, WS_SYSTEM_COLOR, WS_SYSTEM_CRYSTAL,
|
||||||
|
} wssystem_t;
|
||||||
|
|
||||||
extern uint32_t ws_cyclesByLine;
|
extern uint32_t ws_cyclesByLine;
|
||||||
|
|
||||||
int ws_init(char *rompath);
|
int ws_init(char *rompath);
|
||||||
int ws_rotated(void);
|
int ws_rotated(void);
|
||||||
void ws_set_colour_scheme(int scheme);
|
void ws_set_system(wssystem_t system);
|
||||||
void ws_set_system(int system);
|
wssystem_t ws_get_system();
|
||||||
void ws_reset(void);
|
void ws_reset(void);
|
||||||
int ws_executeLine(int16_t *framebuffer, int renderLine);
|
int ws_executeLine(int16_t *framebuffer, int renderLine);
|
||||||
void ws_patchRom(void);
|
void ws_patchRom(void);
|
||||||
|
|||||||
12
testserial.c
12
testserial.c
@@ -1,3 +1,11 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* NewOswan
|
||||||
|
* testserial.c: A simple tool to test serial in/out
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014-2021 986-Studio. All rights reserved.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -7,6 +15,10 @@
|
|||||||
#include <errno.h> /* Error number definitions */
|
#include <errno.h> /* Error number definitions */
|
||||||
#include <termios.h> /* POSIX terminal control definitions */
|
#include <termios.h> /* POSIX terminal control definitions */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The code, as is, was part of a fuzzer for the WonderSwan Tetris game.
|
||||||
|
*/
|
||||||
|
|
||||||
/* Serial port */
|
/* Serial port */
|
||||||
#define BDR_9600 (0)
|
#define BDR_9600 (0)
|
||||||
#define BDR_38400 (1)
|
#define BDR_38400 (1)
|
||||||
|
|||||||
Reference in New Issue
Block a user