├── .ci_files ├── .travis_yml ├── Jenkinsfile └── Vagrantfile ├── .editorconfig ├── .gitignore ├── Brewfile ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CreativeEngine.cmake ├── LICENSE ├── README.md ├── cmake.files ├── FindBoost.cmake ├── FindSDL2.cmake └── FindSDL2_image.cmake ├── component.mk ├── examples ├── .gitignore ├── create.sh ├── fonts │ ├── CMakeLists.txt │ ├── Makefile │ ├── partitions.csv │ ├── resources │ │ ├── charset_16x16.bmp │ │ ├── charset_8x8.bmp │ │ └── component.mk │ ├── sdkconfig.linux │ ├── sdkconfig.osx │ └── src │ │ ├── GGame.cpp │ │ ├── GGame.h │ │ ├── GGameState.cpp │ │ ├── GGameState.h │ │ ├── GResources.h │ │ ├── GSplashState.cpp │ │ ├── GSplashState.h │ │ ├── Game.h │ │ ├── Resources.r │ │ ├── component.mk │ │ └── main.cpp └── template │ ├── CMakeLists.txt │ ├── Makefile │ ├── partitions.csv │ ├── resources │ ├── charset_16x16.bmp │ ├── charset_8x8.bmp │ └── component.mk │ ├── sdkconfig.linux │ ├── sdkconfig.osx │ └── src │ ├── GGame.cpp │ ├── GGame.h │ ├── GGameState.cpp │ ├── GGameState.h │ ├── GResources.h │ ├── GSplashState.cpp │ ├── GSplashState.h │ ├── Game.h │ ├── Resources.r │ ├── component.mk │ └── main.cpp ├── md └── img │ ├── boing-gameplay.gif │ ├── brickout-gameplay.gif │ ├── genus-block-diagram.jpg │ ├── genus-gameplay.gif │ ├── image1.png │ ├── image2.png │ ├── image3.png │ ├── image4.png │ ├── image5.png │ ├── image6.png │ └── modus.logo.svg ├── references └── random-number-generator.pdf ├── scripts ├── Dockerfile ├── README.md ├── build.sh ├── common.sh ├── docker-build.sh ├── docker-install-debian-prerequisites.sh └── env.sh ├── src ├── Audio │ └── mixer │ │ ├── Audio_Mixer.h │ │ ├── mixer.c │ │ └── mixer.h ├── BAnimSprite.cpp ├── BAnimSprite.h ├── BApplication.cpp ├── BApplication.h ├── BBase.cpp ├── BBase.h ├── BBitmap.cpp ├── BBitmap.h ├── BEvents.cpp ├── BEvents.h ├── BFont.cpp ├── BFont.h ├── BGameEngine.cpp ├── BGameEngine.h ├── BList.cpp ├── BList.h ├── BMapPlayfield.cpp ├── BMapPlayfield.h ├── BMemoryStream.cpp ├── BMemoryStream.h ├── BPlayfield.cpp ├── BPlayfield.h ├── BProcess.cpp ├── BProcess.h ├── BResourceManager.cpp ├── BResourceManager.h ├── BSoundEngine.cpp ├── BSoundEngine.h ├── BSprite.cpp ├── BSprite.h ├── BSpriteSheet.cpp ├── BSpriteSheet.h ├── BStore │ ├── BStore.cpp │ ├── BStore.h │ ├── BStoreBase.cpp │ ├── BStoreBase.h │ ├── DesktopStore │ │ ├── DesktopStore.cpp │ │ └── DesktopStore.h │ └── OdroidStore │ │ ├── OdroidStore.cpp │ │ └── OdroidStore.h ├── BTileMap.cpp ├── BTileMap.h ├── BTypes.cpp ├── BTypes.h ├── BViewPort.cpp ├── BViewPort.h ├── Controls │ ├── Controls.cpp │ ├── Controls.h │ ├── DesktopControls │ │ ├── DesktopControls.cpp │ │ └── DesktopControls.h │ ├── DirectLinuxControls │ │ ├── DirectLinuxControls.cpp │ │ ├── DirectLinuxControls.h │ │ ├── axbtnmap.c │ │ └── axbtnmap.h │ ├── LDKControls │ │ ├── LDKControls.cpp │ │ └── LDKControls.h │ └── OdroidControls │ │ ├── OdroidControls.cpp │ │ └── OdroidControls.h ├── CreativeEngine.h ├── Display │ ├── DesktopDisplay │ │ ├── DesktopDisplay.cpp │ │ └── DesktopDisplay.h │ ├── Display.cpp │ ├── Display.h │ ├── DisplayDefines.h │ ├── LDKDisplay │ │ ├── LDKDisplay.cpp │ │ └── LDKDisplay.h │ ├── NetworkDisplay │ │ ├── NetworkDisplay.cpp │ │ ├── NetworkDisplay.h │ │ ├── RemoteMatrixDisplay.cpp │ │ ├── RemoteMatrixDisplay.h │ │ ├── RemoteMatrixSegment.cpp │ │ └── RemoteMatrixSegment.h │ └── OdroidDisplay │ │ ├── OdroidDisplay.cpp │ │ └── OdroidDisplay.h ├── Memory.cpp ├── Memory.h ├── Panic.cpp ├── Panic.h ├── Types │ ├── TBCD.cpp │ ├── TBCD.h │ ├── TNumber.h │ ├── TRGB.h │ ├── TRect.cpp │ └── TRect.h ├── Widgets │ ├── BButtonWidget.cpp │ ├── BButtonWidget.h │ ├── BContainerWidget.cpp │ ├── BContainerWidget.h │ ├── BDialogWidget.cpp │ ├── BDialogWidget.h │ ├── BMenuWidget.cpp │ ├── BMenuWidget.h │ ├── BNumberWidget.cpp │ ├── BNumberWidget.h │ ├── BSelectWidget.cpp │ ├── BSelectWidget.h │ ├── BSliderWidget.cpp │ ├── BSliderWidget.h │ ├── BWidget.cpp │ ├── BWidget.h │ ├── BWidgetTheme.cpp │ ├── BWidgetTheme.h │ └── Widgets.h └── libxmp │ ├── README │ ├── common.h │ ├── component.mk │ ├── control.c │ ├── dataio.c │ ├── depacker.h │ ├── effects.c │ ├── effects.h │ ├── filter.c │ ├── fnmatch.c │ ├── fnmatch.h │ ├── format.c │ ├── format.h │ ├── hio.c │ ├── hio.h │ ├── lfo.c │ ├── lfo.h │ ├── list.h │ ├── load.c │ ├── load_helpers.c │ ├── loaders │ ├── asif.c │ ├── asif.h │ ├── common.c │ ├── component.mk │ ├── iff.c │ ├── iff.h │ ├── it.h │ ├── it_load.c │ ├── itsex.c │ ├── loader.h │ ├── mod.h │ ├── mod_load.c │ ├── s3m.h │ ├── s3m_load.c │ ├── sample.c │ ├── voltable.c │ ├── xm.h │ └── xm_load.c │ ├── md5.c │ ├── md5.h │ ├── mdataio.h │ ├── memio.c │ ├── memio.h │ ├── mix_all.c │ ├── mix_paula.c │ ├── mixer.c │ ├── mixer.h │ ├── mkstemp.c │ ├── paula.h │ ├── period.c │ ├── period.h │ ├── player.c │ ├── player.h │ ├── precomp_blep.h │ ├── precomp_lut.h │ ├── read_event.c │ ├── scan.c │ ├── smix.c │ ├── tempfile.c │ ├── tempfile.h │ ├── virtual.c │ ├── virtual.h │ └── xmp.h ├── test ├── src │ ├── GResources.h │ ├── Resources.r │ ├── main.cpp │ ├── resources │ │ ├── charset │ │ │ ├── charset_16x16.bmp │ │ │ └── charset_8x8.bmp │ │ ├── music │ │ │ └── EmptySong.xm │ │ ├── sound_effects │ │ │ └── SFX_rotate_block_right.wav │ │ ├── splash.bmp │ │ ├── splash_sprites.bmp │ │ ├── sprites │ │ │ └── mid_boss │ │ │ │ ├── mid_boss_death_explosion.bmp │ │ │ │ ├── mid_boss_earth_brown.bmp │ │ │ │ ├── mid_boss_earth_projectile.bmp │ │ │ │ ├── mid_boss_energy.bmp │ │ │ │ ├── mid_boss_energy_projectile.bmp │ │ │ │ ├── mid_boss_fire.bmp │ │ │ │ ├── mid_boss_fire_projectile.bmp │ │ │ │ ├── mid_boss_water.bmp │ │ │ │ ├── mid_boss_water_projectile.bmp │ │ │ │ └── unused │ │ │ │ └── mid_boss_earth_green.bmp │ │ ├── tilemaps │ │ │ ├── 256 │ │ │ │ ├── MAP_LAYER.bmp │ │ │ │ ├── MAP_LAYER.tsx │ │ │ │ ├── mutli-screen-map-wip │ │ │ │ │ ├── _process │ │ │ │ │ │ ├── RMVX │ │ │ │ │ │ │ ├── tileA1_dungeon.bmp │ │ │ │ │ │ │ ├── tileA1_outside.bmp │ │ │ │ │ │ │ ├── tileA1_town.bmp │ │ │ │ │ │ │ ├── tileA2_dungeons.bmp │ │ │ │ │ │ │ ├── tileA2_outside.bmp │ │ │ │ │ │ │ ├── tileA5_desert.bmp │ │ │ │ │ │ │ ├── tileA5_dungeon1.bmp │ │ │ │ │ │ │ ├── tileA5_dungeon2.bmp │ │ │ │ │ │ │ ├── tileA5_outside.bmp │ │ │ │ │ │ │ ├── tileA5_outside2.bmp │ │ │ │ │ │ │ ├── tileB_desert.bmp │ │ │ │ │ │ │ ├── tileB_dungeon.bmp │ │ │ │ │ │ │ ├── tileB_outside.bmp │ │ │ │ │ │ │ └── tileD_castle.bmp │ │ │ │ │ │ ├── castle.bmp │ │ │ │ │ │ ├── desert.bmp │ │ │ │ │ │ ├── dungeon.bmp │ │ │ │ │ │ ├── guide.png │ │ │ │ │ │ ├── house.bmp │ │ │ │ │ │ ├── inside.bmp │ │ │ │ │ │ ├── outside.bmp │ │ │ │ │ │ ├── terrain.bmp │ │ │ │ │ │ └── water.bmp │ │ │ │ │ ├── ashlands │ │ │ │ │ │ └── ashlands.bmp │ │ │ │ │ ├── atlantis │ │ │ │ │ │ └── atlantis.bmp │ │ │ │ │ ├── beach │ │ │ │ │ │ └── beach.bmp │ │ │ │ │ ├── cloud │ │ │ │ │ │ └── cloud_tileset.bmp │ │ │ │ │ ├── darkdimension │ │ │ │ │ │ └── tf_darkdimension_sheet.bmp │ │ │ │ │ ├── jungle │ │ │ │ │ │ └── tf_jungle_tileset.bmp │ │ │ │ │ ├── ruin-dungeons │ │ │ │ │ │ └── tf_ruindungeons_sheet_full.bmp │ │ │ │ │ ├── town │ │ │ │ │ │ ├── beach.tsx │ │ │ │ │ │ ├── east-woods.tmx │ │ │ │ │ │ ├── north-woods-blade.tmx │ │ │ │ │ │ ├── north-woods.tmx │ │ │ │ │ │ ├── south-beach.tmx │ │ │ │ │ │ ├── south_beach.bmp │ │ │ │ │ │ ├── town.bmp │ │ │ │ │ │ ├── town.tmx │ │ │ │ │ │ ├── town_MAP_LAYER.bmp │ │ │ │ │ │ ├── town_MAP_LAYER.tsx │ │ │ │ │ │ └── west-woods.tmx │ │ │ │ │ └── winter │ │ │ │ │ │ ├── tf_winter_terrain.bmp │ │ │ │ │ │ ├── tf_winter_tileB.bmp │ │ │ │ │ │ ├── tf_winter_tileC.bmp │ │ │ │ │ │ ├── tf_winter_tileD.bmp │ │ │ │ │ │ └── tf_winter_water.bmp │ │ │ │ ├── overworld.tmx │ │ │ │ ├── overworld.txt │ │ │ │ └── puzzle.png │ │ │ └── tilesets │ │ │ │ ├── MAP_LAYER.bmp │ │ │ │ ├── MAP_LAYER.json │ │ │ │ ├── MAP_LAYER.tsx │ │ │ │ ├── OBJECT_ATTRIBUTES_LAYER.bmp │ │ │ │ ├── OBJECT_ATTRIBUTES_LAYER.tsx │ │ │ │ ├── OBJECT_LAYER.bmp │ │ │ │ ├── OBJECT_LAYER.orig.bmp │ │ │ │ ├── OBJECT_LAYER.tsx │ │ │ │ ├── dungeon_tileset_objects.bmp │ │ │ │ └── shared palette.pal │ │ └── title.bmp │ ├── test.h │ └── tests │ │ ├── Lists.cpp │ │ └── Sprites.cpp └── test.cmake └── tools ├── README.md ├── output.png ├── p1.bmp ├── playernew.bmp ├── rcomp-src ├── BMPFile.cpp ├── BMPFile.h ├── Makefile ├── RawFile.cpp ├── RawFile.h ├── ResourceFile.cpp ├── ResourceFile.h ├── SpriteSheet.cpp ├── SpriteSheet.h ├── TMXFile.cpp ├── TMXFile.h ├── TileMap.cpp ├── TileMap.h ├── lib │ ├── BSymbolTable.cpp │ ├── BSymbolTable.h │ ├── RawBitmap.cpp │ ├── RawBitmap.h │ ├── utils.cpp │ └── utils.h ├── rcomp.cpp ├── rcomp.h ├── run.sh └── tmx │ ├── TMXLayer.cpp │ ├── TMXLayer.h │ ├── TMXMap.cpp │ ├── TMXMap.h │ ├── TMXTileSet.cpp │ └── TMXTileSet.h ├── strdump-src ├── Makefile └── stmdump.cpp ├── test-orig.png ├── test.bmp ├── test.png └── tools.cmake /.ci_files/.travis_yml: -------------------------------------------------------------------------------- 1 | sudo: enabled 2 | os: osx 3 | language: cpp 4 | 5 | before_install: git clone git@github.com:ModusCreateOrg/creative-engine.git 6 | 7 | script: ./scripts/build.sh 8 | -------------------------------------------------------------------------------- /.ci_files/Jenkinsfile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env groovy 2 | pipeline { 3 | agent any 4 | 5 | stages { 6 | stage('Clean') { 7 | steps { 8 | sh 'git clean -fdx' 9 | } 10 | } 11 | stage('Build') { 12 | steps { 13 | sh ''' 14 | OS="$(uname)" 15 | if [ "$OS" == "Darwin" ]; then 16 | scripts/build.sh 17 | else 18 | scripts/docker-build.sh 19 | fi 20 | ''' 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.ci_files/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # This Vagrantfile is here to make it easier to test the build scripts with 5 | # a variety of operating systems, including Ubuntu 18.04 and Arch linux. 6 | 7 | box = ENV["BOX"] || "bento/ubuntu-18.04" 8 | # To build with arch linux, run: 9 | # BOX=archlinux/archlinux vagrant up 10 | Vagrant.configure("2") do |config| 11 | config.vm.box = box 12 | config.vm.network "private_network", ip: "192.168.50.4" 13 | # These are type "nfs" because when using vboxsf on archlinux/archlinux 14 | # cmake blocks on: 15 | # openat(AT_FDCWD, "/vagrant/build/CMakeFiles/3.12.2/CompilerIdC/CMakeCCompilerId.c", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3 16 | # writev(3, [{iov_base=NULL, iov_len=0}, {iov_base="#ifdef __cplusplus\n# error \"A C+"..., iov_len=18988}], 2 17 | # See https://www.virtualbox.org/ticket/17757 18 | config.vm.synced_folder "../creative-engine", "/creative-engine", type: "nfs" 19 | config.vm.synced_folder ".", "/vagrant", type: "nfs" 20 | config.vm.provision "shell", inline: "/vagrant/scripts/build.sh clean" 21 | end 22 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | [*] 3 | end_of_line = lf 4 | insert_final_newline = true 5 | 6 | [*.js] 7 | charset = utf-8 8 | indent_style = space 9 | indent_size = 2 10 | continuation_indent_size = 6 11 | 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ignore all files starting with . or ~ 2 | .* 3 | ~* 4 | 5 | # ignore node/grunt dependency directories 6 | node_modules/ 7 | 8 | # ignore composer vendor directory 9 | /vendor 10 | 11 | # ignore components loaded via Bower 12 | /bower_components 13 | 14 | # ignore OS generated files 15 | ehthumbs.db 16 | Thumbs.db 17 | .DS_Store 18 | 19 | # ignore Editor files 20 | *.sublime-project 21 | *.sublime-workspace 22 | *.komodoproject 23 | .idea 24 | .vscode/& 25 | !.vscode/settings.json 26 | !.vscode/tasks.json 27 | !.vscode/launch.json 28 | !.vscode/extensions.json 29 | 30 | # ignore log files 31 | *.log 32 | 33 | # ignore packaged files 34 | *.7z 35 | *.dmg 36 | *.gz 37 | *.iso 38 | *.jar 39 | *.rar 40 | *.tar 41 | *.zip 42 | 43 | # ignore common folders (uncomment to enable) 44 | # build/ 45 | # public/ 46 | # screenshots/ 47 | # coverage/ 48 | # reports/ 49 | # *cache/ 50 | 51 | # wordpress 52 | wp-config.php 53 | wp-content/advanced-cache.php 54 | wp-content/backup-db/ 55 | wp-content/backups/ 56 | wp-content/blogs.dir/ 57 | wp-content/cache/ 58 | wp-content/upgrade/ 59 | wp-content/uploads/ 60 | wp-content/mu-plugins/ 61 | wp-content/wp-cache-config.php 62 | wp-content/plugins/hello.php 63 | 64 | # common web 65 | /.htaccess 66 | /sitemap.xml 67 | /sitemap.xml.gz 68 | 69 | # ------------------------- 70 | # BEGIN Whitelisted Files 71 | # ------------------------- 72 | 73 | # track these files, if they exist 74 | !.gitignore 75 | !.editorconfig 76 | !.travis.yml 77 | 78 | test/Resources.bin 79 | test/Resources.h 80 | build 81 | cmake-build-debug 82 | cmake-build-debug/* 83 | cmake-build-release 84 | cmake-build-release/* 85 | tools/rcomp 86 | tools/stmdump 87 | tools/rcomp-src/rcomp 88 | tools/strdump-src/stmpdump 89 | *.o 90 | sdkconfig 91 | sdkconfig.old 92 | CMakeFiles 93 | CMake.Cache.txt 94 | cmake_install.cmake 95 | 96 | clion-log.txt 97 | test/src/Resources.bin 98 | test/src/Resources.h 99 | test/Makefile 100 | *.store 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /Brewfile: -------------------------------------------------------------------------------- 1 | tap "homebrew/cask" 2 | brew "cmake" 3 | brew "sdl2" 4 | brew "sdl2_image" 5 | brew "doxygen" 6 | brew "imagemagick" 7 | brew "pkgconfig" 8 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | #project(tools/rcomp-src/rcomp) 3 | project(creative-engine) 4 | 5 | set(CMAKE_BUILD_TYPE Debug) 6 | set(CMAKE_CXX_STANDARD 11) 7 | 8 | #FIND_PACKAGE(SDL2 REQUIRED) 9 | 10 | # use all the CPU cores and threads 11 | include (ProcessorCount) 12 | ProcessorCount(N) 13 | if (NOT N EQUAL 0) 14 | set(N, N*2) # use hyperthreads - processor count is 4 on an i7 that has 8 cores including hyperthreads 15 | set(${PROJECT_NAME}_FLAGS -j${N}) 16 | set(${PROJECT_NAME}_args ${${PROJECT_NAME}_args} PARALLEL_LEVEL ${N}) 17 | endif () 18 | 19 | # creative-engine path 20 | if (EXISTS $ENV{CREATIVE_ENGINE_PATH}) 21 | # SET ENV variable in CLion project SETtings 22 | SET(CREATIVE_ENGINE_PATH $ENV{CREATIVE_ENGINE_PATH}) 23 | # message(STATUS "********************************* Using user-defined creative-engine path: ${CREATIVE_ENGINE_PATH}") 24 | else () 25 | # SET(CREATIVE_ENGINE_PATH "${CMAKE_SOURCE_DIR}/../creative-engine") # This broke debugging in clion! 26 | SET(CREATIVE_ENGINE_PATH ${PROJECT_SOURCE_DIR}) 27 | # message(STATUS "<<<<<<<<<<<<<<<<<<<<<<<<<< Falling back to default creative-engine path: ${CREATIVE_ENGINE_PATH}") 28 | endif () 29 | 30 | SET(CREATIVE_ENGINE_INCLUDE_DIRS 31 | ${CREATIVE_ENGINE_PATH}/src 32 | ${CREATIVE_ENGINE_PATH}/src/BStore 33 | ${CREATIVE_ENGINE_PATH}/src/BStore/DesktopStore 34 | ${CREATIVE_ENGINE_PATH}/src/Audio 35 | ${CREATIVE_ENGINE_PATH}/src/Audio/SDL2Audio 36 | ${CREATIVE_ENGINE_PATH}/src/Audio/LDKAudio 37 | ${CREATIVE_ENGINE_PATH}/src/Audio/mixer 38 | ${CREATIVE_ENGINE_PATH}/src/Display 39 | ${CREATIVE_ENGINE_PATH}/src/Display/DesktopDisplay 40 | ${CREATIVE_ENGINE_PATH}/src/Display/LDKDisplay 41 | ${CREATIVE_ENGINE_PATH}/src/Controls 42 | ${CREATIVE_ENGINE_PATH}/src/Controls/DesktopControls 43 | ${CREATIVE_ENGINE_PATH}/src/Controls/LDKControls 44 | ${CREATIVE_ENGINE_PATH}/src/Widgets 45 | ${CREATIVE_ENGINE_PATH}/src/libxmp 46 | ${CREATIVE_ENGINE_PATH}/src/libxmp/loaders 47 | ) 48 | 49 | INCLUDE_DIRECTORIES( 50 | ${CREATIVE_ENGINE_INCLUDE_DIRS} 51 | ${SDL2_INCLUDE_DIR} 52 | ${SDL2_IMAGE_INCLUDE_DIR} 53 | ) 54 | 55 | file(GLOB_RECURSE CREATIVE_ENGINE_SOURCE_FILES 56 | ${CREATIVE_ENGINE_PATH}/src/*.cpp 57 | ${CREATIVE_ENGINE_PATH}/src/*.c 58 | ) 59 | 60 | #INCLUDE( ${CMAKE_CURRENT_SOURCE_DIR}/tools/tools.cmake ) 61 | #INCLUDE( ${CMAKE_CURRENT_SOURCE_DIR}/test/test.cmake ) 62 | 63 | 64 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright 2018 Modus Create Inc. https://moduscreate.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /component.mk: -------------------------------------------------------------------------------- 1 | # VAR = $(wildcard ../src/*) 2 | # $(info VAR is ${VAR}) 3 | 4 | 5 | COMPONENT_NAME = creative-engine 6 | 7 | CFLAGS += -DLIBXMP_CORE_PLAYER 8 | #COMPONENT_ADD_INCLUDEDIRS= . src src/Types src/Widgets src/libxmp src/libxmp/loaders src/BStore src/BStore/OdroidStore src/Audio src/Audio/OdroidAudio src/Display src/Display/OdroidDisplay src/Controls src/Controls/OdroidControls 9 | 10 | COMPONENT_ADD_INCLUDEDIRS= . \ 11 | src \ 12 | src/Types \ 13 | src/Widgets \ 14 | src/libxmp \ 15 | src/libxmp/loaders \ 16 | src/BStore \ 17 | src/BStore/OdroidStore \ 18 | src/Audio \ 19 | src/Audio/OdroidAudio \ 20 | src/Display \ 21 | src/Display/OdroidDisplay \ 22 | src/Controls \ 23 | src/Controls/OdroidControls 24 | 25 | # COMPONENT_EXTRA_INCLUDES=../src ../../src ../../../src ../../../../src 26 | COMPONENT_SRCDIRS=${COMPONENT_ADD_INCLUDEDIRS} 27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | **/build 2 | **/sdkconfig 3 | **/src/Resources.bin 4 | **/src/Resources.h 5 | -------------------------------------------------------------------------------- /examples/create.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Set bash unofficial strict mode http://redsymbol.net/articles/unofficial-bash-strict-mode/ 4 | set -euo pipefail 5 | 6 | if [ $# = 0 ]; then 7 | echo "Example name is required" 8 | echo "Usage: create.sh foobar" 9 | exit 1 10 | fi 11 | 12 | # Example names 13 | NAME_LOWER=$(echo ${1} | tr '[:upper:]' '[:lower:]') 14 | NAME_UPPER=$(echo ${1} | tr '[:lower:]' '[:upper:]') 15 | # Credit to Stack Overflow https://stackoverflow.com/a/12487465/426540 16 | NAME_CAPITALIZED="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}" 17 | 18 | # Base example dir 19 | # Credit to Stack Overflow questioner Jiarro and answerer Dave Dopson 20 | # http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in 21 | # http://stackoverflow.com/a/246128/424301 22 | BASE_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)" 23 | EXAMPLE_DIR=${BASE_DIR}/${NAME_LOWER} 24 | 25 | # Create exaple dir 26 | cp -r ${BASE_DIR}/template ${EXAMPLE_DIR} 27 | 28 | # Replace stubs with example name provided 29 | if [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then 30 | echo "32 bit Windows not supported" 31 | exit 1 32 | elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then 33 | echo "64 bit Windows not supported" 34 | exit 1 35 | elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then 36 | sed -i -- "s/{stub}/${NAME_LOWER}/g" ${EXAMPLE_DIR}/CMakeLists.txt 37 | sed -i -- "s/{STUB}/${NAME_UPPER}/g" ${EXAMPLE_DIR}/CMakeLists.txt ${EXAMPLE_DIR}/Makefile 38 | sed -i -- "s/{Stub}/${NAME_CAPITALIZED}/g" ${EXAMPLE_DIR}/src/GSplashState.cpp 39 | else 40 | # Assume BSD or MacOS 41 | sed -i '' -- "s/{stub}/${NAME_LOWER}/g" ${EXAMPLE_DIR}/CMakeLists.txt 42 | sed -i '' -- "s/{STUB}/${NAME_UPPER}/g" ${EXAMPLE_DIR}/CMakeLists.txt ${EXAMPLE_DIR}/Makefile 43 | sed -i '' -- "s/{Stub}/${NAME_CAPITALIZED}/g" ${EXAMPLE_DIR}/src/GSplashState.cpp 44 | fi 45 | 46 | echo "Successfully created '${NAME_LOWER}' example" 47 | echo "Before building compile your resources with 'make resources'" 48 | echo "Use CLion to build locally or 'make flash' for ODroid-GO" 49 | -------------------------------------------------------------------------------- /examples/fonts/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | project(creative_engine_font_example) 3 | 4 | set(CMAKE_CXX_STANDARD 11) 5 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-implicit-exception-spec-mismatch") 6 | set(CMAKE_VERBOSE_MAKEFILE ON) 7 | 8 | # resource compiler 9 | set(RCOMP "${CMAKE_CURRENT_SOURCE_DIR}/../../tools/rcomp-src") 10 | 11 | INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS} ${SDL2IMAGE_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/../../src ${CMAKE_BINARY_DIR} /usr/local/include) 12 | 13 | # external libraries 14 | INCLUDE(FindPkgConfig) 15 | PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2) 16 | PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image>=2.0.0) 17 | 18 | # build rcomp-src 19 | add_custom_command(OUTPUT rcomp 20 | COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/../../tools && make 21 | OUTPUTS rcomp 22 | COMMENT "Building rcomp" 23 | ) 24 | 25 | # build Resources.bin 26 | add_custom_command(OUTPUT Resources.bin 27 | COMMAND @echo 28 | COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/src && ${RCOMP} Resources.r 29 | OUTPUTS Resources.bin 30 | DEPENDS rcomp 31 | COMMENT "Compiling Resources ${CMAKE_CURRENT_SOURCE_DIR}" 32 | ) 33 | 34 | # gather creative-engine sources 35 | file(GLOB_RECURSE CREATIVE_ENGINE RELATIVE ${CMAKE_SOURCE_DIR} "../../src/*.cpp") 36 | 37 | # gather example sources 38 | file(GLOB_RECURSE SRC RELATIVE ${CMAKE_SOURCE_DIR} "src/*.cpp") 39 | 40 | # LibXMP 41 | add_compile_definitions(LIBXMP_CORE_PLAYER=true) 42 | add_compile_definitions(LIBXMP_CORE_DISABLE_IT=true) 43 | include_directories( 44 | ${CMAKE_SOURCE_DIR}/src 45 | ${CMAKE_SOURCE_DIR}/../../src/libxmp/loaders/prowizarde 46 | ${CMAKE_SOURCE_DIR}/../../src/libxmp/loaders 47 | ${CMAKE_SOURCE_DIR}/../../src/libxmp 48 | ) 49 | 50 | file(GLOB LIBXMP_SRC 51 | "${CMAKE_SOURCE_DIR}/../../src/libxmp/loaders/*.h" 52 | "${CMAKE_SOURCE_DIR}/../../src/libxmp/loaders/*.c" 53 | "${CMAKE_SOURCE_DIR}/../../src/libxmp/*.h" 54 | "${CMAKE_SOURCE_DIR}/../../src/libxmp/*.c" 55 | ) 56 | 57 | file(GLOB_RECURSE CREATIVE_ENGINE_FONT_EXAMPLE RELATIVE ${CMAKE_SOURCE_DIR} "src/*.cpp") 58 | 59 | add_executable( 60 | creative_engine_font_example 61 | Resources.bin 62 | ${LIBXMP_SRC} 63 | ${CREATIVE_ENGINE} 64 | ${CREATIVE_ENGINE_FONT_EXAMPLE} 65 | ) 66 | 67 | # make app 68 | if(APPLE) 69 | SET_TARGET_PROPERTIES(creative_engine_font_example PROPERTIES MACOSX_BUNDLE TRUE) 70 | INSTALL(TARGETS creative_engine_font_example DESTINATION ".") 71 | endif(APPLE) 72 | 73 | TARGET_LINK_LIBRARIES(${PROJECT_NAME} -L/usr/local/lib ${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARIES}) 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /examples/fonts/Makefile: -------------------------------------------------------------------------------- 1 | # ESP-IDF Makefile for game project 2 | 3 | PROJECT_NAME=GENUS_FONT_EXAMPLE 4 | EXTRA_COMPONENT_DIRS=$(abspath ${PROJECT_PATH}/../..) ${PROJECT_PATH}/src 5 | 6 | include $(IDF_PATH)/make/project.mk 7 | 8 | rcomp: FORCE 9 | echo "Building rcomp" 10 | cd ../../tools && make 11 | 12 | resources: rcomp FORCE 13 | echo "Compiling resources" 14 | cd src && ../../../tools/rcomp Resources.r 15 | 16 | FORCE: 17 | 18 | -------------------------------------------------------------------------------- /examples/fonts/partitions.csv: -------------------------------------------------------------------------------- 1 | # Espressif ESP32 Partition Table 2 | # Name, Type, SubType, Offset, Size, Flags 3 | nvs, data, nvs, 0x9000, 0x6000, 4 | phy_init, data, phy, 0xf000, 0x1000, 5 | factory, app, factory, 0x10000, 12M, 6 | -------------------------------------------------------------------------------- /examples/fonts/resources/charset_16x16.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/examples/fonts/resources/charset_16x16.bmp -------------------------------------------------------------------------------- /examples/fonts/resources/charset_8x8.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/examples/fonts/resources/charset_8x8.bmp -------------------------------------------------------------------------------- /examples/fonts/resources/component.mk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/examples/fonts/resources/component.mk -------------------------------------------------------------------------------- /examples/fonts/src/GGame.cpp: -------------------------------------------------------------------------------- 1 | #include "GGame.h" 2 | 3 | GGame::GGame() { 4 | gResourceManager.LoadBitmap(CHARSET_16X16_BMP, FONT_16x16_SLOT, IMAGE_16x16); 5 | gResourceManager.LoadBitmap(CHARSET_8X8_BMP, FONT_8x8_SLOT, IMAGE_8x8); 6 | 7 | gViewPort = new BViewPort(); 8 | gViewPort->Offset(25, 50); 9 | gViewPort->SetRect(TRect(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1)); 10 | 11 | mState = mNextState = -1; 12 | gGameEngine = ENull; 13 | SetState(GAME_STATE_SPLASH); 14 | } 15 | 16 | GGame::~GGame() { 17 | delete gGameEngine; 18 | delete gViewPort; 19 | gResourceManager.ReleaseBitmapSlot(FONT_8x8_SLOT); 20 | gResourceManager.ReleaseBitmapSlot(FONT_16x16_SLOT); 21 | } 22 | 23 | void GGame::SetState(TInt aNewState) { 24 | mNextState = aNewState; 25 | } 26 | 27 | void GGame::Run() { 28 | while (1) { 29 | Random(); // randomize 30 | 31 | if (mNextState != mState) { 32 | switch (mNextState) { 33 | case GAME_STATE_SPLASH: 34 | delete gGameEngine; 35 | gGameEngine = new GSplashState(); 36 | break; 37 | case GAME_STATE_GAME: 38 | delete gGameEngine; 39 | gGameEngine = new GGameState(); 40 | break; 41 | default: 42 | continue; 43 | } 44 | 45 | // reset dKeys so next state doesn't react to any keys already pressed 46 | gControls.dKeys = 0; 47 | mState = mNextState; 48 | } 49 | 50 | gGameEngine->GameLoop(); 51 | gDisplay.Update(); 52 | 53 | if (gControls.WasPressed(BUTTONQ)) { 54 | break; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /examples/fonts/src/GGame.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_GGAME_H 2 | #define GENUS_GGAME_H 3 | 4 | #include "Game.h" 5 | 6 | enum { 7 | GAME_STATE_SPLASH, 8 | GAME_STATE_GAME, 9 | }; 10 | 11 | class GGame : public BApplication { 12 | public: 13 | GGame(); 14 | virtual ~GGame(); 15 | public: 16 | void Run(); 17 | public: 18 | void SetState(TInt aNewState); 19 | 20 | protected: 21 | TInt mState; 22 | TInt mNextState; 23 | }; 24 | 25 | extern GGame *gGame; 26 | 27 | #endif //GENUS_GGAME_H 28 | -------------------------------------------------------------------------------- /examples/fonts/src/GGameState.cpp: -------------------------------------------------------------------------------- 1 | #include "Game.h" 2 | #include "cmath" 3 | 4 | class GGameProcess : public BProcess { 5 | public: 6 | GGameProcess() : BProcess() { 7 | mFont = new BFont(gResourceManager.GetBitmap(FONT_16x16_SLOT), FONT_16x16); 8 | } 9 | 10 | ~GGameProcess() { 11 | delete mFont; 12 | } 13 | 14 | TBool RunBefore() { 15 | return ETrue; 16 | } 17 | 18 | TBool RunAfter() { 19 | mX += 4; 20 | 21 | if (mX >= SCREEN_WIDTH) { 22 | mX = -224; 23 | mY += 16; 24 | 25 | if (mY >= SCREEN_HEIGHT) { 26 | mY = 0; 27 | } 28 | } 29 | 30 | // Clipping 31 | gDisplay.renderBitmap->DrawString(ENull, "CreativeEngine", mFont, mX, mY, 0, 1); 32 | 33 | // Letter spacing 34 | if (mLetterSpacing == 4.0) { 35 | mIncrement = EFalse; 36 | } else if (mLetterSpacing == -4.0) { 37 | mIncrement = ETrue; 38 | } 39 | 40 | const char *str = "Modus Create"; 41 | mLetterSpacing += mIncrement ? 0.25 : -0.25; 42 | TInt centerX = (SCREEN_WIDTH - strlen(str) * mFont->mWidth) / 2; 43 | TInt centerY = (SCREEN_HEIGHT - mFont->mHeight) / 2; 44 | 45 | gDisplay.renderBitmap->DrawString(ENull, str, mFont, centerX, centerY, 1, -1, TInt(round(mLetterSpacing))); 46 | 47 | return ETrue; 48 | } 49 | 50 | TInt mX = 0; 51 | TInt mY = 0; 52 | TFloat mLetterSpacing = 0; 53 | TBool mIncrement = ETrue; 54 | BFont *mFont; 55 | }; 56 | 57 | class GGamePlayfield : public BPlayfield { 58 | public: 59 | GGamePlayfield() { 60 | gDisplay.SetPalette(gResourceManager.GetBitmap(FONT_8x8_SLOT)); 61 | } 62 | 63 | void Render() { 64 | gDisplay.renderBitmap->Clear(); 65 | } 66 | }; 67 | 68 | GGameState::GGameState() : BGameEngine(gViewPort) { 69 | mPlayfield = new GGamePlayfield(); 70 | auto *p = new GGameProcess(); 71 | AddProcess(p); 72 | } 73 | -------------------------------------------------------------------------------- /examples/fonts/src/GGameState.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_GGAMESTATE_H 2 | #define GENUS_GGAMESTATE_H 3 | 4 | #include 5 | 6 | class GGameState : public BGameEngine { 7 | public: 8 | GGameState(); 9 | }; 10 | 11 | #endif //GENUS_GGAMESTATE_H 12 | -------------------------------------------------------------------------------- /examples/fonts/src/GResources.h: -------------------------------------------------------------------------------- 1 | #ifndef GRESOURCES_H 2 | #define GRESOURCES_H 3 | 4 | #include 5 | #include "Resources.h" 6 | 7 | // Font Slots 8 | static const TUint16 FONT_8x8_SLOT = 3; 9 | static const TUint16 FONT_16x16_SLOT = 4; 10 | 11 | #endif //GRESOURCES_H 12 | -------------------------------------------------------------------------------- /examples/fonts/src/GSplashState.cpp: -------------------------------------------------------------------------------- 1 | #include "Game.h" 2 | #include "cstring" 3 | 4 | class GSplashProcess : public BProcess { 5 | public: 6 | GSplashProcess() : BProcess() {} 7 | 8 | public: 9 | TBool RunBefore() { 10 | return ETrue; 11 | } 12 | 13 | TBool RunAfter() { 14 | if (gControls.WasPressed(BUTTON_ANY)) { 15 | gGame->SetState(GAME_STATE_GAME); 16 | return EFalse; 17 | } 18 | return ETrue; 19 | } 20 | }; 21 | 22 | class GSplashPlayfield : public BPlayfield { 23 | public: 24 | GSplashPlayfield() { 25 | // Init fonts 26 | mFont8 = new BFont(gResourceManager.GetBitmap(FONT_8x8_SLOT), FONT_8x8); 27 | mFont16 = new BFont(gResourceManager.GetBitmap(FONT_16x16_SLOT), FONT_16x16); 28 | 29 | // Text X coords 30 | mTitleX = (SCREEN_WIDTH - strlen(mTitle) * mFont16->mWidth) / 2; 31 | mSubTitleX = (SCREEN_WIDTH - strlen(mSubTitle) * mFont16->mWidth) / 2; 32 | mInitTextX = (SCREEN_WIDTH - strlen(mInitText) * mFont8->mWidth) / 2; 33 | 34 | gDisplay.SetPalette(gResourceManager.GetBitmap(FONT_8x8_SLOT)); 35 | } 36 | 37 | ~GSplashPlayfield() { 38 | delete mFont8; 39 | delete mFont16; 40 | } 41 | 42 | void Render() { 43 | gDisplay.renderBitmap->Clear(); 44 | gDisplay.renderBitmap->DrawString(ENull, mTitle, mFont16, mTitleX, 70, 1); 45 | gDisplay.renderBitmap->DrawString(ENull, mSubTitle, mFont16, mSubTitleX, 110, 0, 1); 46 | 47 | if (mTimer-- > 0) { 48 | gDisplay.renderBitmap->DrawString(ENull, mInitText, mFont8, mInitTextX, 170, 1); 49 | return; 50 | } 51 | 52 | if (mDelay-- > 0) { 53 | return; 54 | } 55 | 56 | mTimer = 20; 57 | mDelay = 10; 58 | } 59 | 60 | TInt mTimer = 20; 61 | TInt mDelay = 10; 62 | const char *mTitle = "CreativeEngine"; 63 | const char *mSubTitle = "Font Example"; 64 | const char *mInitText = "Press any button"; 65 | TInt mTitleX; 66 | TInt mSubTitleX; 67 | TInt mInitTextX; 68 | BFont *mFont8; 69 | BFont *mFont16; 70 | }; 71 | 72 | GSplashState::GSplashState() : BGameEngine(gViewPort) { 73 | mPlayfield = new GSplashPlayfield(); 74 | auto *p = new GSplashProcess(); 75 | AddProcess(p); 76 | } 77 | -------------------------------------------------------------------------------- /examples/fonts/src/GSplashState.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_GSPLASH_H 2 | #define GENUS_GSPLASH_H 3 | 4 | #include 5 | 6 | class GSplashState : public BGameEngine { 7 | public: 8 | GSplashState(); 9 | }; 10 | 11 | 12 | #endif //GENUS_GSPLASH_H 13 | -------------------------------------------------------------------------------- /examples/fonts/src/Game.h: -------------------------------------------------------------------------------- 1 | #ifndef GAME_H 2 | #define GAME_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include "Resources.h" 10 | 11 | // Game specific includes 12 | #include "GResources.h" 13 | #include "GGame.h" 14 | 15 | // GGameEngine states 16 | #include "GGameState.h" 17 | #include "GSplashState.h" 18 | 19 | extern BViewPort *gViewPort; 20 | extern BGameEngine *gGameEngine; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /examples/fonts/src/Resources.r: -------------------------------------------------------------------------------- 1 | # Resource source file 2 | PATH ../resources # path to resource files 3 | 4 | BITMAP charset_8x8.bmp 5 | BITMAP charset_16x16.bmp 6 | -------------------------------------------------------------------------------- /examples/fonts/src/component.mk: -------------------------------------------------------------------------------- 1 | .PHONY: Resources.bin 2 | echo "THERE" 3 | cd ../../tools && make 4 | ../../tools/rcomp Resources.r 5 | 6 | COMPONENT_NAME=CreativeEngineExample 7 | COMPONENT_PRIV_INCLUDEDIRS=../../../src 8 | COMPONENT_EMBED_FILES := Resources.bin 9 | -------------------------------------------------------------------------------- /examples/fonts/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Game.h" 2 | 3 | BViewPort *gViewPort; 4 | BGameEngine *gGameEngine; 5 | 6 | GGame *gGame; 7 | 8 | /** @file 9 | * \brief Main entry point for game engine. 10 | * 11 | * Initializes the engine and runs the main event loop. 12 | */ 13 | extern "C" void app_main() { 14 | gGame = new GGame(); 15 | gGame->Run(); 16 | } 17 | 18 | #ifndef __XTENSA__ 19 | 20 | int main() { 21 | app_main(); 22 | return 0; 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /examples/template/Makefile: -------------------------------------------------------------------------------- 1 | # ESP-IDF Makefile for game project 2 | 3 | PROJECT_NAME=GENUS_{STUB}_EXAMPLE 4 | EXTRA_COMPONENT_DIRS=$(abspath ${PROJECT_PATH}/../..) ${PROJECT_PATH}/src 5 | 6 | include $(IDF_PATH)/make/project.mk 7 | 8 | rcomp: FORCE 9 | echo "Building rcomp" 10 | cd ../../tools && make 11 | 12 | resources: rcomp FORCE 13 | echo "Compiling resources" 14 | cd src && ../../../tools/rcomp Resources.r 15 | 16 | FORCE: 17 | 18 | -------------------------------------------------------------------------------- /examples/template/partitions.csv: -------------------------------------------------------------------------------- 1 | # Espressif ESP32 Partition Table 2 | # Name, Type, SubType, Offset, Size, Flags 3 | nvs, data, nvs, 0x9000, 0x6000, 4 | phy_init, data, phy, 0xf000, 0x1000, 5 | factory, app, factory, 0x10000, 12M, 6 | -------------------------------------------------------------------------------- /examples/template/resources/charset_16x16.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/examples/template/resources/charset_16x16.bmp -------------------------------------------------------------------------------- /examples/template/resources/charset_8x8.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/examples/template/resources/charset_8x8.bmp -------------------------------------------------------------------------------- /examples/template/resources/component.mk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/examples/template/resources/component.mk -------------------------------------------------------------------------------- /examples/template/src/GGame.cpp: -------------------------------------------------------------------------------- 1 | #include "GGame.h" 2 | 3 | GGame::GGame() { 4 | gResourceManager.LoadBitmap(CHARSET_16X16_BMP, FONT_16x16_SLOT, IMAGE_16x16); 5 | gResourceManager.LoadBitmap(CHARSET_8X8_BMP, FONT_8x8_SLOT, IMAGE_8x8); 6 | 7 | gViewPort = new BViewPort(); 8 | gViewPort->Offset(25, 50); 9 | gViewPort->SetRect(TRect(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1)); 10 | 11 | mState = mNextState = -1; 12 | gGameEngine = ENull; 13 | SetState(GAME_STATE_SPLASH); 14 | } 15 | 16 | GGame::~GGame() { 17 | delete gGameEngine; 18 | delete gViewPort; 19 | gResourceManager.ReleaseBitmapSlot(FONT_8x8_SLOT); 20 | gResourceManager.ReleaseBitmapSlot(FONT_16x16_SLOT); 21 | } 22 | 23 | void GGame::SetState(TInt aNewState) { 24 | mNextState = aNewState; 25 | } 26 | 27 | void GGame::Run() { 28 | while (1) { 29 | Random(); // randomize 30 | 31 | if (mNextState != mState) { 32 | switch (mNextState) { 33 | case GAME_STATE_SPLASH: 34 | delete gGameEngine; 35 | gGameEngine = new GSplashState(); 36 | break; 37 | case GAME_STATE_GAME: 38 | delete gGameEngine; 39 | gGameEngine = new GGameState(); 40 | break; 41 | default: 42 | continue; 43 | } 44 | 45 | // reset dKeys so next state doesn't react to any keys already pressed 46 | gControls.dKeys = 0; 47 | mState = mNextState; 48 | } 49 | 50 | gGameEngine->GameLoop(); 51 | gDisplay.Update(); 52 | 53 | if (gControls.WasPressed(BUTTONQ)) { 54 | break; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /examples/template/src/GGame.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_GGAME_H 2 | #define GENUS_GGAME_H 3 | 4 | #include "Game.h" 5 | 6 | enum { 7 | GAME_STATE_SPLASH, 8 | GAME_STATE_GAME, 9 | }; 10 | 11 | class GGame : public BApplication { 12 | public: 13 | GGame(); 14 | virtual ~GGame(); 15 | public: 16 | void Run(); 17 | public: 18 | void SetState(TInt aNewState); 19 | 20 | protected: 21 | TInt mState; 22 | TInt mNextState; 23 | }; 24 | 25 | extern GGame *gGame; 26 | 27 | #endif //GENUS_GGAME_H 28 | -------------------------------------------------------------------------------- /examples/template/src/GGameState.cpp: -------------------------------------------------------------------------------- 1 | #include "Game.h" 2 | 3 | class GGameProcess : public BProcess { 4 | public: 5 | GGameProcess() : BProcess() {} 6 | ~GGameProcess() {} 7 | 8 | TBool RunBefore() { 9 | return ETrue; 10 | } 11 | 12 | TBool RunAfter() { 13 | return ETrue; 14 | } 15 | }; 16 | 17 | class GGamePlayfield : public BPlayfield { 18 | public: 19 | GGamePlayfield() { 20 | gDisplay.SetPalette(gResourceManager.GetBitmap(FONT_8x8_SLOT)); 21 | } 22 | 23 | void Render() { 24 | gDisplay.renderBitmap->Clear(); 25 | } 26 | }; 27 | 28 | GGameState::GGameState() : BGameEngine(gViewPort) { 29 | mPlayfield = new GGamePlayfield(); 30 | auto *p = new GGameProcess(); 31 | AddProcess(p); 32 | } 33 | -------------------------------------------------------------------------------- /examples/template/src/GGameState.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_GGAMESTATE_H 2 | #define GENUS_GGAMESTATE_H 3 | 4 | #include 5 | 6 | class GGameState : public BGameEngine { 7 | public: 8 | GGameState(); 9 | }; 10 | 11 | #endif //GENUS_GGAMESTATE_H 12 | -------------------------------------------------------------------------------- /examples/template/src/GResources.h: -------------------------------------------------------------------------------- 1 | #ifndef GRESOURCES_H 2 | #define GRESOURCES_H 3 | 4 | #include 5 | #include "Resources.h" 6 | 7 | // Font Slots 8 | static const TUint16 FONT_8x8_SLOT = 3; 9 | static const TUint16 FONT_16x16_SLOT = 4; 10 | 11 | #endif //GRESOURCES_H 12 | -------------------------------------------------------------------------------- /examples/template/src/GSplashState.cpp: -------------------------------------------------------------------------------- 1 | #include "Game.h" 2 | #include "cstring" 3 | 4 | class GSplashProcess : public BProcess { 5 | public: 6 | GSplashProcess() : BProcess() {} 7 | 8 | public: 9 | TBool RunBefore() { 10 | return ETrue; 11 | } 12 | 13 | TBool RunAfter() { 14 | if (gControls.WasPressed(BUTTON_ANY)) { 15 | gGame->SetState(GAME_STATE_GAME); 16 | return EFalse; 17 | } 18 | return ETrue; 19 | } 20 | }; 21 | 22 | class GSplashPlayfield : public BPlayfield { 23 | public: 24 | GSplashPlayfield() { 25 | // Init fonts 26 | mFont8 = new BFont(gResourceManager.GetBitmap(FONT_8x8_SLOT), FONT_8x8); 27 | mFont16 = new BFont(gResourceManager.GetBitmap(FONT_16x16_SLOT), FONT_16x16); 28 | 29 | // Text X coords 30 | mTitleX = (SCREEN_WIDTH - strlen(mTitle) * mFont16->mWidth) / 2; 31 | mSubTitleX = (SCREEN_WIDTH - strlen(mSubTitle) * mFont16->mWidth) / 2; 32 | mInitTextX = (SCREEN_WIDTH - strlen(mInitText) * mFont8->mWidth) / 2; 33 | 34 | gDisplay.SetPalette(gResourceManager.GetBitmap(FONT_8x8_SLOT)); 35 | } 36 | 37 | ~GSplashPlayfield() { 38 | delete mFont8; 39 | delete mFont16; 40 | } 41 | 42 | void Render() { 43 | gDisplay.renderBitmap->Clear(); 44 | gDisplay.renderBitmap->DrawString(ENull, mTitle, mFont16, mTitleX, 70, 1); 45 | gDisplay.renderBitmap->DrawString(ENull, mSubTitle, mFont16, mSubTitleX, 110, 0, 1); 46 | 47 | if (mTimer-- > 0) { 48 | gDisplay.renderBitmap->DrawString(ENull, mInitText, mFont8, mInitTextX, 170, 1); 49 | return; 50 | } 51 | 52 | if (mDelay-- > 0) { 53 | return; 54 | } 55 | 56 | mTimer = 20; 57 | mDelay = 10; 58 | } 59 | 60 | TInt mTimer = 20; 61 | TInt mDelay = 10; 62 | const char *mTitle = "CreativeEngine"; 63 | const char *mSubTitle = "{Stub} Example"; 64 | const char *mInitText = "Press any button"; 65 | TInt mTitleX; 66 | TInt mSubTitleX; 67 | TInt mInitTextX; 68 | BFont *mFont8; 69 | BFont *mFont16; 70 | }; 71 | 72 | GSplashState::GSplashState() : BGameEngine(gViewPort) { 73 | mPlayfield = new GSplashPlayfield(); 74 | auto *p = new GSplashProcess(); 75 | AddProcess(p); 76 | } 77 | -------------------------------------------------------------------------------- /examples/template/src/GSplashState.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_GSPLASH_H 2 | #define GENUS_GSPLASH_H 3 | 4 | #include 5 | 6 | class GSplashState : public BGameEngine { 7 | public: 8 | GSplashState(); 9 | }; 10 | 11 | 12 | #endif //GENUS_GSPLASH_H 13 | -------------------------------------------------------------------------------- /examples/template/src/Game.h: -------------------------------------------------------------------------------- 1 | #ifndef GAME_H 2 | #define GAME_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include "Resources.h" 10 | 11 | // Game specific includes 12 | #include "GResources.h" 13 | #include "GGame.h" 14 | 15 | // GGameEngine states 16 | #include "GGameState.h" 17 | #include "GSplashState.h" 18 | 19 | extern BViewPort *gViewPort; 20 | extern BGameEngine *gGameEngine; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /examples/template/src/Resources.r: -------------------------------------------------------------------------------- 1 | # Resource source file 2 | PATH ../resources # path to resource files 3 | 4 | BITMAP charset_8x8.bmp 5 | BITMAP charset_16x16.bmp 6 | -------------------------------------------------------------------------------- /examples/template/src/component.mk: -------------------------------------------------------------------------------- 1 | .PHONY: Resources.bin 2 | echo "THERE" 3 | cd ../../tools && make 4 | ../../tools/rcomp Resources.r 5 | 6 | COMPONENT_NAME=CreativeEngineExample 7 | COMPONENT_PRIV_INCLUDEDIRS=../../../src 8 | COMPONENT_EMBED_FILES := Resources.bin 9 | -------------------------------------------------------------------------------- /examples/template/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Game.h" 2 | 3 | BViewPort *gViewPort; 4 | BGameEngine *gGameEngine; 5 | 6 | GGame *gGame; 7 | 8 | /** @file 9 | * \brief Main entry point for game engine. 10 | * 11 | * Initializes the engine and runs the main event loop. 12 | */ 13 | extern "C" void app_main() { 14 | gGame = new GGame(); 15 | gGame->Run(); 16 | } 17 | 18 | #ifndef __XTENSA__ 19 | 20 | int main() { 21 | app_main(); 22 | return 0; 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /md/img/boing-gameplay.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/md/img/boing-gameplay.gif -------------------------------------------------------------------------------- /md/img/brickout-gameplay.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/md/img/brickout-gameplay.gif -------------------------------------------------------------------------------- /md/img/genus-block-diagram.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/md/img/genus-block-diagram.jpg -------------------------------------------------------------------------------- /md/img/genus-gameplay.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/md/img/genus-gameplay.gif -------------------------------------------------------------------------------- /md/img/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/md/img/image1.png -------------------------------------------------------------------------------- /md/img/image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/md/img/image2.png -------------------------------------------------------------------------------- /md/img/image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/md/img/image3.png -------------------------------------------------------------------------------- /md/img/image4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/md/img/image4.png -------------------------------------------------------------------------------- /md/img/image5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/md/img/image5.png -------------------------------------------------------------------------------- /md/img/image6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/md/img/image6.png -------------------------------------------------------------------------------- /references/random-number-generator.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/references/random-number-generator.pdf -------------------------------------------------------------------------------- /scripts/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | RUN mkdir -p /opt/creative-engine/scripts 3 | COPY scripts/docker-install-debian-prerequisites.sh scripts/common.sh /opt/creative-engine/scripts/ 4 | RUN /bin/bash /opt/creative-engine/scripts/docker-install-debian-prerequisites.sh 5 | RUN rm -rf /opt/creative-engine/scripts 6 | COPY . /opt/creative-engine 7 | RUN /bin/bash /opt/creative-engine/scripts/build.sh docker-build 8 | -------------------------------------------------------------------------------- /scripts/README.md: -------------------------------------------------------------------------------- 1 | This is the root directory for the build scripts. -------------------------------------------------------------------------------- /scripts/docker-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Because Docker hates symlinks we need to write a wrapper script 3 | # to run Docker from the TOP_DIR directory instead. Grr. 4 | 5 | ######################### Debugging and Directory Scaffolding ######### 6 | 7 | # Set bash unofficial strict mode http://redsymbol.net/articles/unofficial-bash-strict-mode/ 8 | set -euo pipefail 9 | IFS=$'\n\t' 10 | 11 | # Enable for enhanced debugging 12 | #set -vx 13 | 14 | # Credit to https://stackoverflow.com/a/17805088 15 | # and http://wiki.bash-hackers.org/scripting/debuggingtips 16 | export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' 17 | 18 | # Credit to Stack Overflow questioner Jiarro and answerer Dave Dopson 19 | # http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in 20 | # http://stackoverflow.com/a/246128/424301 21 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 22 | BASE_DIR="$DIR/.." 23 | TOP_DIR="$BASE_DIR/.." 24 | export DIR BUILD_DIR TOP_DIR 25 | 26 | ######################### Main build ################################## 27 | 28 | #shellcheck disable=SC2086,SC2048 29 | docker build . -t creative-engine -f "$DIR/Dockerfile" 30 | 31 | -------------------------------------------------------------------------------- /scripts/docker-install-debian-prerequisites.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ######################### Debugging and Directory Scaffolding ######### 4 | 5 | # Set bash unofficial strict mode http://redsymbol.net/articles/unofficial-bash-strict-mode/ 6 | set -euo pipefail 7 | IFS=$'\n\t' 8 | 9 | # Enable for enhanced debugging 10 | #set -vx 11 | 12 | # Credit to https://stackoverflow.com/a/17805088 13 | # and http://wiki.bash-hackers.org/scripting/debuggingtips 14 | export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' 15 | 16 | # Credit to Stack Overflow questioner Jiarro and answerer Dave Dopson 17 | # http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in 18 | # http://stackoverflow.com/a/246128/424301 19 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 20 | BASE_DIR="$DIR/.." 21 | BUILD_DIR="$BASE_DIR/build" 22 | TOP_DIR="$BASE_DIR/.." 23 | CREATIVE_ENGINE_DIR="$TOP_DIR/creative-engine" 24 | export DIR BUILD_DIR TOP_DIR CREATIVE_ENGINE_DIR 25 | #shellcheck disable=SC1090 26 | . "$DIR/common.sh" 27 | 28 | ######################### Main build ################################## 29 | 30 | ensure_debian_devtools_installed 31 | -------------------------------------------------------------------------------- /scripts/env.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ -z "$GENUS_ROOT" ]; then export GENUS_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/.." && pwd )"; fi 4 | if [ -z "$ENGINE_ROOT" ]; then export ENGINE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/../creative-engine" && pwd )"; fi 5 | -------------------------------------------------------------------------------- /src/Audio/mixer/mixer.h: -------------------------------------------------------------------------------- 1 | // Heavily based on SDL2 Mixer 2 | // https://www.libsdl.org/projects/SDL_mixer/ 3 | /* 4 | SDL_mixer: An audio mixer library based on the SDL library 5 | Copyright (C) 1997-2018 Sam Lantinga 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | */ 23 | 24 | /* Locking wrapper functions */ 25 | extern void Mixer_LockAudio(void); 26 | extern void Mixer_UnlockAudio(void); 27 | 28 | extern void add_chunk_decoder(const char *decoder); 29 | 30 | /* vi: set ts=4 sw=4 expandtab: */ 31 | -------------------------------------------------------------------------------- /src/BApplication.cpp: -------------------------------------------------------------------------------- 1 | #include "Display/Display.h" 2 | #include "BApplication.h" 3 | 4 | BApplication::BApplication() { 5 | SeedRandom(time(ENull)); 6 | gDisplay.Init(); 7 | 8 | }; 9 | 10 | BApplication::~BApplication() {} 11 | 12 | static void Exit(TInt aExitCode) { 13 | exit(aExitCode); 14 | } 15 | -------------------------------------------------------------------------------- /src/BApplication.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Michael Schwartz on 10/19/18. 3 | // 4 | 5 | #ifndef GENUS_BAPPLICATION_H 6 | #define GENUS_BAPPLICATION_H 7 | 8 | #include "BBase.h" 9 | 10 | class BApplication : public BBase { 11 | public: 12 | BApplication(); 13 | virtual ~BApplication(); 14 | public: 15 | static void Exit(TInt aExitCode); 16 | }; 17 | 18 | 19 | #endif //GENUS_BAPPLICATION_H 20 | -------------------------------------------------------------------------------- /src/BBase.h: -------------------------------------------------------------------------------- 1 | #ifndef BBASE_H 2 | #define BBASE_H 3 | 4 | // Uncomment for production build 5 | // #define PRODUCTION 6 | 7 | #include "BTypes.h" 8 | #include "Memory.h" 9 | #include 10 | 11 | extern void ByteDump(TUint8 *ptr, TInt len, TInt width=8); 12 | extern void WordDump(TUint16 *ptr, TInt len, TInt width=8); 13 | extern void LongDump(TUint32 *ptr, TInt len, TInt width=8); 14 | 15 | /** 16 | * BBase is the base class for EVERYTHING. 17 | */ 18 | class BBase { 19 | public: 20 | BBase(); 21 | 22 | ~BBase(); 23 | }; 24 | 25 | //////// RANDOM NUMBER GENERATOR 26 | 27 | /** 28 | * \brief SeedRandom 29 | * 30 | * Seed random number generator. 31 | * 32 | * @param aSeed 33 | */ 34 | void SeedRandom(TUint32 aSeed); 35 | 36 | /** 37 | * Get random seed 38 | */ 39 | TUint32 GetRandomSeed(); 40 | 41 | /** 42 | * Generate a random number 43 | * @return 44 | */ 45 | TUint32 Random(); 46 | 47 | /** 48 | * Generate a random number in given range. 49 | * 50 | * Note: this routine produces signed result and takes signed arguments. This allows a range of something like -10 to 100. 51 | * 52 | * @param aMin 53 | * @param aMax 54 | * @return 55 | */ 56 | TInt32 Random(TInt32 aMin, TInt32 aMax); 57 | 58 | /** 59 | * Return random number between 0 and 1 (floating point) 60 | * @return 61 | */ 62 | TFloat RandomFloat(); 63 | 64 | #ifdef __XTENSA__ 65 | inline void *operator new(size_t size) { return AllocMem(size, MEMF_SLOW); } 66 | 67 | inline void *operator new[](size_t size) { return AllocMem(size, MEMF_SLOW); } 68 | 69 | inline void operator delete(void *ptr) { 70 | // 71 | FreeMem(ptr); 72 | } 73 | 74 | inline void operator delete[](void *ptr) { 75 | // 76 | FreeMem(ptr); 77 | } 78 | #else 79 | #if __cplusplus > 199711L 80 | // C++11 deprecates throw 81 | extern void *operator new(size_t size); 82 | extern void *operator new[](size_t size); 83 | #else 84 | // < C++11: throw not deprecated 85 | extern void *operator new(size_t size) throw(std::bad_alloc); 86 | extern void *operator new[](size_t size) throw(std::bad_alloc); 87 | #endif 88 | 89 | #ifdef __linux__ 90 | extern void operator delete(void *ptr) _GLIBCXX_USE_NOEXCEPT; 91 | 92 | extern void operator delete[](void *ptr) _GLIBCXX_USE_NOEXCEPT; 93 | #else 94 | extern void operator delete(void *ptr) throw(); 95 | 96 | extern void operator delete[](void *ptr) throw(); 97 | #endif 98 | 99 | 100 | #endif 101 | 102 | extern TUint32 Milliseconds(); 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /src/BEvents.cpp: -------------------------------------------------------------------------------- 1 | #include "BEvents.h" 2 | #include "BProcess.h" 3 | 4 | // Events / Event Emitter 5 | BEventEmitter gEventEmitter; 6 | 7 | TBool BEventEmitter::Listen(TUint16 aType, BProcess *aProcess) { 8 | for (BEventListener *l = mListeners.First(); !mListeners.End(l); l = mListeners.Next(l)) { 9 | if (l->mType == aType && l->mProcess == aProcess) { 10 | return EFalse; 11 | } 12 | } 13 | BEventListener *n = new BEventListener(aType, aProcess); 14 | mListeners.AddTail(*n); 15 | return ETrue; 16 | } 17 | 18 | TBool BEventEmitter::UnListen(TUint16 aType, BProcess *aProcess) { 19 | for (BEventListener *l = mListeners.First(); !mListeners.End(l); l = mListeners.Next(l)) { 20 | if (l->mType == aType && l->mProcess == aProcess) { 21 | l->Remove(); 22 | delete l; 23 | return ETrue; 24 | } 25 | } 26 | return EFalse; 27 | } 28 | 29 | void BEventEmitter::UnListenAll(BProcess *aProcess) { 30 | for (BEventListener *l = mListeners.First(); !mListeners.End(l);) { 31 | BEventListener *next_l = mListeners.Next(l); 32 | if (l->mProcess == aProcess) { 33 | l->Remove(); 34 | delete l; 35 | } 36 | l = next_l; 37 | } 38 | } 39 | 40 | TBool BEventEmitter::FireEvent(BProcess *aSender, TUint16 aType, TAny *aMessage) { 41 | TBool sent = EFalse; 42 | for (BEventListener *l = mListeners.First(); !mListeners.End(l); l = mListeners.Next(l)) { 43 | if (l->mType == aType && l->mProcess != aSender) { 44 | BEventMessage *m = new BEventMessage(aType, aSender, aMessage); 45 | l->mProcess->ReceiveMessage(m); 46 | sent = ETrue; 47 | } 48 | } 49 | return sent; 50 | } 51 | -------------------------------------------------------------------------------- /src/BEvents.h: -------------------------------------------------------------------------------- 1 | #ifndef BEVENTS_H 2 | #define BEVENTS_H 3 | 4 | // Events / Event Emitte 5 | 6 | #include "BBase.h" 7 | #include "BList.h" 8 | 9 | class BProcess; 10 | 11 | // Event Listener Node 12 | class BEventListener : public BNode { 13 | public: 14 | BEventListener(TUint16 aType, BProcess *aProcess) : mType(aType), mProcess(aProcess) {} 15 | 16 | public: 17 | TUint16 mType; 18 | BProcess *mProcess; // process that will listen 19 | }; 20 | 21 | // list of Event Listeners 22 | class BEventListenerList : public BList { 23 | public: 24 | BEventListenerList() : BList() {} 25 | virtual ~BEventListenerList() {} 26 | 27 | public: 28 | // void AddTail(BEventListener *listener) { AddTail((BNode *)listener); } 29 | 30 | BEventListener *First() { return (BEventListener *)next; } 31 | 32 | BEventListener *Next(BEventListener *curr) { return (BEventListener *)curr->next; } 33 | 34 | BEventListener *Last() { return (BEventListener *)prev; } 35 | 36 | BEventListener *Prev(BEventListener *curr) { return (BEventListener *)curr->prev; } 37 | 38 | TBool End(BEventListener *curr) { return curr == (BEventListener *)this; } 39 | }; 40 | 41 | // Event Message Node 42 | class BEventMessage : public BNode { 43 | public: 44 | BEventMessage(TUint16 aType, BProcess *aSender, TAny *aMessage) : mType(aType), mSender(aSender), mMessage(aMessage) {} 45 | 46 | public: 47 | TUint16 mType; 48 | BProcess *mSender; 49 | TAny *mMessage; 50 | }; 51 | 52 | class BEventMessageList : public BList { 53 | public: 54 | BEventMessageList() : BList() {} 55 | virtual ~BEventMessageList() {} 56 | 57 | public: 58 | // void AddTail(BEventMessageList *listener) { AddTail((BNode *)listener); } 59 | 60 | BEventMessageList *First() { return (BEventMessageList *)next; } 61 | 62 | BEventMessageList *Next(BEventMessageList *curr) { return (BEventMessageList *)curr->next; } 63 | 64 | BEventMessageList *Last() { return (BEventMessageList *)prev; } 65 | 66 | BEventMessageList *Prev(BEventMessageList *curr) { return (BEventMessageList *)curr->prev; } 67 | 68 | TBool End(BEventMessageList *curr) { return curr == (BEventMessageList *)this; } 69 | }; 70 | 71 | // The Event Emitter 72 | class BEventEmitter : public BBase { 73 | 74 | public: 75 | TBool Listen(TUint16 type, BProcess *aProcess); 76 | TBool UnListen(TUint16 type, BProcess *aProcess); 77 | void UnListenAll(BProcess *aProcess); 78 | 79 | // Trigger/fire an event 80 | TBool FireEvent(BProcess *aSender, TUint16 aType, TAny *aMessage); 81 | 82 | protected: 83 | BEventListenerList mListeners; 84 | }; 85 | 86 | extern BEventEmitter gEventEmitter; 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /src/BFont.cpp: -------------------------------------------------------------------------------- 1 | #include "BFont.h" 2 | #include "BBitmap.h" 3 | 4 | static const TUint8 widthTable[] = { 5 | 8, 16, 32, 64, 8, 16, 8, 32, 8, 64, 16, 32, 16, 64, 32, 64, 32 6 | }; 7 | static const TUint8 heightTable[] = { 8 | 8, 16, 32, 64, 16, 8, 32, 8, 64, 8, 32, 16, 64, 16, 64, 32, 40 9 | }; 10 | 11 | BFont::BFont(BBitmap *b, TInt16 aFontType) : mWidth(TUint(widthTable[aFontType])), mHeight(TUint(heightTable[aFontType])){ 12 | mBitmap = b; 13 | mFontType = aFontType; 14 | } 15 | 16 | BFont::~BFont() { 17 | 18 | } 19 | 20 | TRect BFont::GetCharRect(const char c) { 21 | TInt row = c / 16; 22 | TInt col = c % 16; 23 | TInt x1 = col * mWidth; 24 | TInt y1 = row * mHeight; 25 | 26 | return TRect(x1, y1, x1 + (mWidth - 1), y1 + (mHeight - 1)); 27 | } 28 | -------------------------------------------------------------------------------- /src/BFont.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Michael Schwartz on 9/27/18. 3 | // 4 | 5 | #ifndef GENUS_BFONT_H 6 | #define GENUS_BFONT_H 7 | 8 | #include "BTypes.h" 9 | 10 | class BBitmap; 11 | 12 | // Font sizes 13 | static const TInt16 FONT_8x8 = 0; // bitmap contains individual images, each 8x8, on a grid 14 | static const TInt16 FONT_16x16 = 1; // 16x16 on a grid 15 | static const TInt16 FONT_32x32 = 2; // etc. 16 | static const TInt16 FONT_64x64 = 3; 17 | static const TInt16 FONT_8x16 = 4; 18 | static const TInt16 FONT_16x8 = 5; 19 | static const TInt16 FONT_8x32 = 6; 20 | static const TInt16 FONT_32x8 = 7; 21 | static const TInt16 FONT_8x64 = 8; 22 | static const TInt16 FONT_64x8 = 9; 23 | static const TInt16 FONT_16x32 = 10; 24 | static const TInt16 FONT_32x16 = 11; 25 | static const TInt16 FONT_16x64 = 12; 26 | static const TInt16 FONT_64x16 = 13; 27 | static const TInt16 FONT_32x64 = 14; 28 | static const TInt16 FONT_64x32 = 15; 29 | static const TInt16 FONT_32x40 = 16; 30 | 31 | /** 32 | * BFont references the slots in a bitmap that contain fonts. 33 | */ 34 | class BFont { 35 | public: 36 | BFont(BBitmap *b, TInt16 fontType); 37 | ~BFont(); 38 | public: 39 | TRect GetCharRect(const char c); 40 | public: 41 | BBitmap *mBitmap; 42 | TInt16 mFontType; 43 | const TUint mWidth; 44 | const TUint mHeight; 45 | }; 46 | 47 | #endif //GENUS_BFONT_H 48 | -------------------------------------------------------------------------------- /src/BGameEngine.cpp: -------------------------------------------------------------------------------- 1 | #include "BGameEngine.h" 2 | #include "Display/Display.h" 3 | #include "Controls.h" 4 | 5 | BGameEngine::BGameEngine(BViewPort *aViewPort) { 6 | mWorldXX = mWorldYY = 0; 7 | mPlayfield = ENull; 8 | mPauseFlag = EFalse; 9 | mEnabled = ETrue; 10 | mFrameCounter = 0; 11 | mDisplay = &gDisplay; 12 | mViewPort = aViewPort; 13 | } 14 | 15 | BGameEngine::~BGameEngine() { 16 | // assure processes and sprites get freed 17 | Reset(); 18 | if (mPlayfield) { 19 | delete mPlayfield; 20 | mPlayfield = ENull; 21 | } 22 | } 23 | 24 | // you can set viewport here for game area 25 | void BGameEngine::PreRender() { 26 | } 27 | 28 | // and use score/status viewport here 29 | // typically games will use this to draw the score/status area, too 30 | void BGameEngine::PostRender() { 31 | } 32 | 33 | /** 34 | * Resets the engine 35 | * 36 | * 37 | */ 38 | void BGameEngine::Reset() { 39 | mProcessList.Genocide(); 40 | mSpriteList.Reset(); 41 | } 42 | 43 | void BGameEngine::AddProcess(BProcess *aProcess) { 44 | mProcessList.AddProcess(aProcess); 45 | } 46 | 47 | void BGameEngine::RunProcessesBefore() { 48 | mProcessList.RunBefore(); 49 | } 50 | 51 | void BGameEngine::RunProcessesAfter() { 52 | mProcessList.RunAfter(); 53 | } 54 | 55 | void BGameEngine::GameLoop() { 56 | if (!mPauseFlag) { 57 | gControls.Poll(); 58 | } 59 | 60 | mFrameCounter++; 61 | PreRender(); 62 | 63 | if (mEnabled) { 64 | if (mPlayfield) { 65 | // animate the playfield 66 | mPlayfield->Animate(); 67 | } 68 | 69 | if (!mPauseFlag) { 70 | mSpriteList.Move(); 71 | mSpriteList.Animate(); 72 | mProcessList.RunBefore(); 73 | } 74 | // allow inheritor to set mWorldXX,mWorldYY as desired 75 | PositionCamera(); 76 | 77 | if (mPlayfield != ENull) { 78 | mPlayfield->Render(); 79 | } 80 | mSpriteList.Render(mViewPort); 81 | 82 | if (!mPauseFlag) { 83 | mProcessList.RunAfter(); 84 | } 85 | } 86 | 87 | PostRender(); 88 | } 89 | -------------------------------------------------------------------------------- /src/BMapPlayfield.h: -------------------------------------------------------------------------------- 1 | #ifndef BMAPPLAYFIELD_H 2 | #define BMAPPLAYFIELD_H 3 | 4 | #include 5 | 6 | class BMapTileset; 7 | 8 | const TInt MAX_TILEMAPS = 512; 9 | 10 | // 32x32 tiles, 64x64 tiles, etc. 11 | const TInt TILESIZE = 32; 12 | 13 | class BMapPlayfield : public BPlayfield { 14 | public: 15 | // Create a playfield with tilemap. If aCache is true, the map data is cached and reused if 16 | // the same tilemap is instantiated again. 17 | BMapPlayfield(BViewPort *aViewPort, TUint16 aResourceId, TInt16 aSlot, TBool aCache = EFalse); 18 | 19 | virtual ~BMapPlayfield(); 20 | 21 | public: 22 | // in pixels 23 | inline TUint16 TileSize() { return TILESIZE; } 24 | 25 | TUint16 MapWidth() { return mMapWidth * TILESIZE; } 26 | 27 | TUint16 MapHeight() { return mMapHeight * TILESIZE; } 28 | 29 | TUint16 MapMaxX() { return mMapWidth * TILESIZE - SCREEN_WIDTH; } 30 | 31 | TUint16 MapMaxY() { return mMapHeight * TILESIZE - SCREEN_HEIGHT; } 32 | 33 | // in tiles 34 | TUint16 MapWidthTiles() { return mMapWidth; } 35 | 36 | TUint16 MapHeightTiles() { return mMapHeight; } 37 | 38 | public: 39 | /** 40 | * Write cached ObjectPrograms to stream 41 | */ 42 | static void WriteToStream(BMemoryStream *aStream, TInt aNumResources); 43 | static void ReadFromStream(BMemoryStream *aStream, TInt aNumResources); 44 | static void ResetCache(); 45 | 46 | public: 47 | // render section of map to viewport 48 | void Render(); 49 | 50 | // cell is tile number | (attribute << 16) 51 | TUint32 GetCell(TFloat aWorldX, TFloat aWorldY); 52 | TUint32 GetCell(TInt aRow, TInt aCol); 53 | 54 | void SetAttribute(TFloat aWorldX, TFloat aWorldY, TUint aAttribute); 55 | 56 | TUint16 mObjectCount; 57 | BObjectProgram *mObjectProgram; 58 | 59 | BBitmap *GetTilesBitmap() { return mTileset; } 60 | TUint16 GetMapWidth() { return mMapWidth; } 61 | TUint16 GetMapHeight() { return mMapHeight; } 62 | 63 | protected: 64 | BViewPort *mViewPort; 65 | BTileMap *mTileMap; 66 | TInt mResourceId, mSlot; 67 | BBitmap *mTileset; 68 | TUint16 mMapWidth, mMapHeight; 69 | TUint32 *mMapData; 70 | }; 71 | 72 | #endif //BMAPPLAYFIELD_H 73 | -------------------------------------------------------------------------------- /src/BMemoryStream.cpp: -------------------------------------------------------------------------------- 1 | #include "BMemoryStream.h" 2 | #include "Panic.h" 3 | 4 | BMemoryStream::BMemoryStream(TUint32 aGrowSize) { 5 | mGrowSize = aGrowSize; 6 | mSize = 0; 7 | mData = (TUint8 *)AllocMem(mGrowSize, MEMF_SLOW); 8 | mAllocated = aGrowSize; 9 | mReadIndex = 0; 10 | } 11 | 12 | BMemoryStream::BMemoryStream(TUint8 *aData, TUint32 aSize, TUint32 aGrowSize) { 13 | mData = new TUint8[aSize]; 14 | mSize = aSize; 15 | memcpy(mData, aData, mSize); 16 | mGrowSize = aGrowSize; 17 | mAllocated = aSize; 18 | mGrowSize = aGrowSize; 19 | mReadIndex = 0; 20 | } 21 | 22 | BMemoryStream::~BMemoryStream() { 23 | delete[] mData; 24 | mData = ENull; 25 | mSize = 0; 26 | } 27 | 28 | void BMemoryStream::Write(TAny *aData, TUint32 aSize) { 29 | TUint8 *data = (TUint8 *)aData; 30 | TUint32 new_size = mSize + aSize; 31 | 32 | // grow buffer is data doesn't fit in the free space 33 | if (new_size > mAllocated) { 34 | mData = (TUint8 *)ReallocMem(mData, new_size + STREAM_GROW_SIZE, MEMF_SLOW); 35 | mAllocated = new_size + mGrowSize; 36 | } 37 | 38 | memcpy(&mData[mSize], (TUint8 *)aData, aSize); 39 | mSize = new_size; 40 | } 41 | 42 | void BMemoryStream::Read(TAny *aData, TUint32 aSize) { 43 | if (mReadIndex > mSize) { 44 | Panic("BMemoryStream::Read beyond end of stream\n"); 45 | } 46 | TUint8 *dst = (TUint8 *)aData; 47 | memcpy(dst, &mData[mReadIndex], aSize); 48 | mReadIndex += aSize; 49 | } 50 | 51 | 52 | void BMemoryStream::ReadWithNoFFWD(TAny *aData, TUint32 aSize, TUint32 aOffset) { 53 | if (mReadIndex > mSize) { 54 | Panic("BMemoryStream::Read beyond end of stream\n"); 55 | } 56 | TUint8 *dst = (TUint8 *)aData; 57 | memcpy(dst, &mData[mReadIndex + aOffset], aSize); 58 | } 59 | 60 | -------------------------------------------------------------------------------- /src/BMemoryStream.h: -------------------------------------------------------------------------------- 1 | #ifndef BMEMORYSTREAM_H 2 | #define BMEMORYSTREAM_H 3 | 4 | #include "BBase.h" 5 | 6 | /** 7 | * BMemoryStream 8 | * 9 | * Implements a growable raw TUint8 buffer. 10 | * As yuu Write() to it, it will grow in size to be able to hold all the data you add. 11 | * 12 | * The buffer typically is larger than the data it holds, to reduce calling ReallocMem(). 13 | */ 14 | const TInt32 STREAM_GROW_SIZE = 4096; 15 | 16 | class BMemoryStream : public BBase { 17 | public: 18 | BMemoryStream(TUint32 aSize = STREAM_GROW_SIZE); 19 | BMemoryStream(TUint8 *aData, TUint32 aSize, TUint32 aGrowSize = STREAM_GROW_SIZE); 20 | ~BMemoryStream(); 21 | 22 | public: 23 | TInt32 Size() { return mSize; } 24 | TInt32 ReadOffset() { return mReadIndex; } 25 | TUint8 *Data() { return mData; } 26 | void Dump(const char *filename) { 27 | int fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644); 28 | write(fd, mData, mSize); 29 | close(fd); 30 | } 31 | 32 | 33 | 34 | public: 35 | // Methods to write to stream 36 | void Write(TAny *aData, TUint32 aSize); 37 | 38 | public: 39 | // methods to read from stream 40 | void Read(TAny *aData, TUint32 aSize); 41 | void ReadWithNoFFWD(TAny *aData, TUint32 aSize, TUint32 aOffset = 0); 42 | 43 | void PrintReadIndex() { printf("\tBMemoryStream->mReadIndex = %i\n", mReadIndex); } 44 | void PrintMSize() { printf("\tBMemoryStream->mSize = %i\n", mSize); } 45 | 46 | protected: 47 | // mSize is the number of bytes added to the buffer via Write(), mAllocated is the buffer's actual size 48 | TInt32 mSize, mAllocated, mGrowSize, mReadIndex; 49 | TUint8 *mData; 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/BPlayfield.cpp: -------------------------------------------------------------------------------- 1 | #include "BPlayfield.h" 2 | #include "BGameEngine.h" 3 | 4 | BPlayfield::BPlayfield() { 5 | } 6 | 7 | BPlayfield::~BPlayfield() { 8 | } 9 | 10 | void BPlayfield::Animate() { 11 | } -------------------------------------------------------------------------------- /src/BPlayfield.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Michael Schwartz on 9/5/18. 3 | // 4 | 5 | #ifndef GAME_ENGINE_BPLAYFIELD_H 6 | #define GAME_ENGINE_BPLAYFIELD_H 7 | 8 | #include "BBase.h" 9 | 10 | class BGameEngine; 11 | class Display; 12 | 13 | /** 14 | * Abstract BPlayfield class. 15 | * 16 | * Inherit from this. Implement a Render() function that renders the current state of the backtground/playfield 17 | * to the Display's renderBitmap. 18 | * 19 | * Sprites will be rendered on top 20 | */ 21 | class BPlayfield : public BBase { 22 | public: 23 | BPlayfield(); 24 | 25 | virtual ~BPlayfield(); 26 | 27 | virtual void Animate(); 28 | 29 | virtual void Render() = 0; 30 | }; 31 | 32 | 33 | #endif //GAME_ENGINE_BPLAYFIELD_H 34 | -------------------------------------------------------------------------------- /src/BProcess.cpp: -------------------------------------------------------------------------------- 1 | #include "BProcess.h" 2 | 3 | // #define DEBUG_ME 4 | 5 | // BProcessList gProcessList; 6 | 7 | BProcess::~BProcess() { 8 | mMessageList.Reset(); 9 | gEventEmitter.UnListenAll(this); 10 | } 11 | 12 | BProcessList::BProcessList() : BListPri() { 13 | mResetFlag = ETrue; 14 | } 15 | 16 | BProcessList::~BProcessList() { Reset(); } 17 | 18 | void BProcessList::Reset() { 19 | BProcess *p; 20 | while (p = RemHead(), p) 21 | delete p; 22 | mResetFlag = ETrue; 23 | } 24 | 25 | void BProcessList::AddProcess(BProcess *aProcess) { 26 | Add(*aProcess); 27 | mResetFlag = EFalse; 28 | } 29 | 30 | void BProcessList::Genocide() { 31 | BProcess *p = First(); 32 | while (!End(p)) { 33 | if (p != mCurrentProcess) { 34 | if (p->Type() != PTYPE_SYSTEM) { 35 | BProcess *pp = Prev(p); 36 | p->Remove(); 37 | delete p; 38 | p = pp; 39 | } 40 | } 41 | p = Next(p); 42 | } 43 | } 44 | 45 | void BProcessList::RunBefore() { 46 | if (mResetFlag) 47 | return; 48 | for (mCurrentProcess = First(); !End(mCurrentProcess); 49 | mCurrentProcess = Next(mCurrentProcess)) { 50 | TBool resumeFlag = mCurrentProcess->RunBefore(); 51 | if (mResetFlag) 52 | return; 53 | if (!resumeFlag) { 54 | BProcess *newp = Prev(mCurrentProcess); 55 | mCurrentProcess->Remove(); 56 | delete mCurrentProcess; 57 | mCurrentProcess = newp; 58 | } 59 | } 60 | mCurrentProcess = ENull; 61 | } 62 | 63 | void BProcessList::RunAfter() { 64 | if (mResetFlag) 65 | return; 66 | for (mCurrentProcess = First(); !End(mCurrentProcess); 67 | mCurrentProcess = Next(mCurrentProcess)) { 68 | TBool resumeFlag = mCurrentProcess->RunAfter(); 69 | if (mResetFlag) 70 | return; 71 | if (!resumeFlag) { 72 | BProcess *newp = Prev(mCurrentProcess); 73 | mCurrentProcess->Remove(); 74 | delete mCurrentProcess; 75 | mCurrentProcess = newp; 76 | } 77 | } 78 | mCurrentProcess = ENull; 79 | } 80 | -------------------------------------------------------------------------------- /src/BProcess.h: -------------------------------------------------------------------------------- 1 | #ifndef BPROCESS_H 2 | #define BPROCESS_H 3 | 4 | #include "BList.h" 5 | #include "BEvents.h" 6 | 7 | // process types 8 | // USER is destroyed by Genocide() 9 | // SYSTEM is not destroyed by Genocide() 10 | #define PTYPE_USER 0 11 | #define PTYPE_SYSTEM 1 12 | 13 | class BProcess : public BNodePri { 14 | public: 15 | BProcess(TInt aPri = 0, TInt aType = PTYPE_USER) : BNodePri(aPri) { 16 | mType = aType; 17 | } 18 | 19 | virtual ~BProcess(); 20 | 21 | TInt Type() { return mType; } 22 | 23 | public: 24 | // Thesefunctions must be provided by inheritor 25 | // They return EFalse if the process is to be removed from 26 | // the list and deleted. 27 | // RunBefore() gets called before Sprites are rendered 28 | // RunAfter() gets called after Sprites are rendered 29 | virtual TBool RunBefore() = 0; 30 | 31 | virtual TBool RunAfter() = 0; 32 | 33 | public: 34 | void Listen(TUint16 aType) { gEventEmitter.Listen(aType, this); } 35 | 36 | // add message to this process' message queue 37 | void ReceiveMessage(BEventMessage *aMessage) { mMessageList.AddTail(*aMessage); } 38 | 39 | // send message directly to a process 40 | void SendMessage(BProcess *aOther, BEventMessage *aMessage) { aOther->ReceiveMessage(aMessage); } 41 | 42 | // fetch next message from inbound message queue 43 | BEventMessage *GetMessage() { return (BEventMessage *)mMessageList.RemHead(); } 44 | 45 | // fire a message/event 46 | TBool FireEvent(TUint16 aType, TAny *aMessage) { return gEventEmitter.FireEvent(this, aType, aMessage); } 47 | 48 | protected: 49 | TInt mType; 50 | BEventMessageList mMessageList; 51 | }; 52 | 53 | class BProcessList : public BListPri { 54 | public: 55 | BProcessList(); 56 | 57 | virtual ~BProcessList(); 58 | 59 | void Reset(); 60 | 61 | void AddProcess(BProcess *aProcess); 62 | 63 | void Genocide(); 64 | 65 | public: 66 | BProcess *RemHead() { return (BProcess *)BListPri::RemHead(); } 67 | 68 | BProcess *First() { return (BProcess *)next; } 69 | 70 | BProcess *Next(BProcess *curr) { return (BProcess *)curr->next; } 71 | 72 | BProcess *Last() { return (BProcess *)prev; } 73 | 74 | BProcess *Prev(BProcess *curr) { return (BProcess *)curr->prev; } 75 | 76 | TBool End(BProcess *curr) { return curr == (BProcess *)this; } 77 | 78 | public: 79 | void RunBefore(); 80 | 81 | void RunAfter(); 82 | 83 | protected: 84 | TBool mResetFlag; // true if Reset() has been called 85 | BProcess *mCurrentProcess; 86 | }; 87 | 88 | // extern BProcessList gProcessList; 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /src/BSpriteSheet.cpp: -------------------------------------------------------------------------------- 1 | #include "BSpriteSheet.h" 2 | 3 | BSpriteSheet::BSpriteSheet(TUint8 *aROM) { 4 | mInfo = (BSpriteInfoROM *)&aROM[0]; 5 | // Dump(); 6 | } 7 | 8 | void BSpriteSheet::Dump() { 9 | printf("\nBSpriteSheet @%p - %d Sprites\n", this, mInfo->numSprites); 10 | for (TInt i=0; inumSprites; i++) { 11 | char buf[256]; 12 | sprintf(buf, "info [%-5d] = ", i); 13 | mInfo->info[i].Dump(buf); 14 | } 15 | } -------------------------------------------------------------------------------- /src/BSpriteSheet.h: -------------------------------------------------------------------------------- 1 | #ifndef MODITE_BSPRITESHEET_H 2 | #define MODITE_BSPRITESHEET_H 3 | 4 | #include "BBase.h" 5 | #include "BBitmap.h" 6 | 7 | struct BSpriteInfo { 8 | TInt16 dx, dy; 9 | TInt16 x1, y1, x2, y2; // rect that perfectly fits the image data 10 | void Dump(const char *s = ENull) { 11 | if (s) { 12 | printf("%s", s); 13 | } 14 | printf("%d,%d %d,%d\n", x1, y1, x2, y2); 15 | } 16 | }; 17 | 18 | struct BSpriteInfoROM { 19 | TUint16 resourceId; // ID of the BBitmap in the binary resource 20 | TUint16 imageType; // e.g. IMAGE_32x32 21 | TUint16 numSprites; // number of sprites in the sprite sheet 22 | BSpriteInfo info[1]; // array of numSprites BSpriteInfo structs 23 | }; 24 | 25 | class BSpriteSheet : public BBase { 26 | public: 27 | BSpriteSheet(TUint8 *aRom); 28 | 29 | public: 30 | TInt NumSprites() { return mInfo->numSprites; } 31 | 32 | TUint16 BitmapID() { return mInfo->resourceId; } 33 | 34 | BSpriteInfo *GetSpriteInfo(TInt16 aImageNumber) { 35 | return &mInfo->info[aImageNumber]; 36 | } 37 | 38 | public: 39 | void Dump(); 40 | 41 | public: 42 | BSpriteInfoROM *mInfo; 43 | }; 44 | 45 | #endif //MODITE_BSPRITESHEET_H 46 | -------------------------------------------------------------------------------- /src/BStore/BStore.cpp: -------------------------------------------------------------------------------- 1 | #include "BStore.h" 2 | 3 | -------------------------------------------------------------------------------- /src/BStore/BStore.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_BSTORE_H 2 | #define GENUS_BSTORE_H 3 | 4 | // ODROID GO 5 | #ifdef __XTENSA__ 6 | #include "OdroidStore/OdroidStore.h" 7 | class BStore : public OdroidStore { 8 | public: 9 | explicit BStore(const char *aStoreName) : OdroidStore(aStoreName) {}; 10 | ~BStore() { 11 | 12 | } 13 | }; 14 | #endif 15 | 16 | 17 | #ifndef __XTENSA__ 18 | #include "DesktopStore/DesktopStore.h" 19 | class BStore : public DesktopStore { 20 | public: 21 | EXPLICIT BStore(const char *aStoreName) : DesktopStore(aStoreName) {}; 22 | ~BStore() { 23 | 24 | } 25 | }; 26 | #endif 27 | 28 | #endif //GENUS_BSTORE_H 29 | -------------------------------------------------------------------------------- /src/BStore/BStoreBase.cpp: -------------------------------------------------------------------------------- 1 | #include "BStoreBase.h" 2 | 3 | 4 | TBool BStoreBase::mInitialized = EFalse; 5 | -------------------------------------------------------------------------------- /src/BStore/BStoreBase.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_BSTOREBASE_H 2 | #define GENUS_BSTOREBASE_H 3 | 4 | 5 | 6 | #include "BTypes.h" 7 | #include "BBase.h" 8 | #include 9 | #include 10 | #include 11 | 12 | class BStoreBase : public BBase { 13 | public: 14 | explicit BStoreBase(const char *aStoreName) : mStoreName(strdup(aStoreName)) { 15 | mInitialized = EFalse; 16 | }; 17 | 18 | virtual void Initialize() = 0; 19 | 20 | ~BStoreBase() { 21 | FreeMem((TAny*)mStoreName); 22 | }; 23 | 24 | public: 25 | // Get a blob of data named by key into aValue, of given size 26 | virtual TBool Get(const char *aKey, void *aValue, TUint32 aSize) = 0; 27 | 28 | // Set a blob of data named by key to value of given size 29 | virtual TBool Set(const char *aKey, void *aValue, TUint32 aSize) = 0; 30 | 31 | // Remove a blob of data named by key 32 | virtual TBool Remove(const char *aKey) = 0; 33 | public: 34 | const char *mStoreName; 35 | 36 | protected: 37 | static TBool mInitialized; 38 | }; 39 | 40 | 41 | #endif //GENUS_BSTOREBASE_H 42 | -------------------------------------------------------------------------------- /src/BStore/DesktopStore/DesktopStore.cpp: -------------------------------------------------------------------------------- 1 | #include "DesktopStore.h" 2 | -------------------------------------------------------------------------------- /src/BStore/DesktopStore/DesktopStore.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_DESKTOPSTORE_H 2 | #define GENUS_DESKTOPSTORE_H 3 | 4 | #include 5 | #include 6 | 7 | #include "BStoreBase.h" 8 | 9 | class DesktopStore : public BStoreBase { 10 | public: 11 | explicit DesktopStore(const char *aStoreName) : BStoreBase(aStoreName) { 12 | Initialize(); 13 | } 14 | 15 | public: 16 | char mTargetDir[4096]; 17 | 18 | public: 19 | void Initialize() OVERRIDE { 20 | char *homeDir = getenv("HOME"); 21 | 22 | strcpy(mTargetDir, homeDir); 23 | strcat(mTargetDir, "/.modus"); 24 | 25 | DIR *dir = opendir(mTargetDir); 26 | if (dir) { 27 | closedir(dir); 28 | } 29 | else { 30 | mkdir(mTargetDir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH); 31 | } 32 | 33 | mInitialized = ETrue; 34 | } 35 | 36 | TUint32 Size(const char *aKey) { 37 | char name[4096]; 38 | sprintf(name, "%s/%s.%s.store", mTargetDir, mStoreName, aKey); 39 | struct stat stat_buf; 40 | if (stat(name, &stat_buf) != 0) { 41 | return 0; 42 | } 43 | return TUint32(stat_buf.st_size); 44 | } 45 | 46 | TBool Get(const char *aKey, void *aValue, TUint32 aSize) OVERRIDE { 47 | char name[4096]; 48 | sprintf(name, "%s/%s.%s.store", mTargetDir, mStoreName, aKey); 49 | 50 | FILE *fp = fopen(name, "r"); 51 | if (!fp) { 52 | return EFalse; 53 | } 54 | if (fread(aValue, 1, aSize, fp) != aSize) { 55 | fclose(fp); 56 | return EFalse; 57 | } 58 | fclose(fp); 59 | return ETrue; 60 | } 61 | 62 | TBool Set(const char *aKey, void *aValue, TUint32 aSize) OVERRIDE { 63 | char name[4096]; 64 | sprintf(name, "%s/%s.%s.store", mTargetDir, mStoreName, aKey); 65 | 66 | FILE *fp = fopen(name, "w"); 67 | if (!fp || fwrite(aValue, aSize, 1, fp) != aSize) { 68 | fclose(fp); 69 | return EFalse; 70 | } 71 | fclose(fp); 72 | return ETrue; 73 | } 74 | 75 | TBool Remove(const char *aKey) OVERRIDE { 76 | char name[4096]; 77 | sprintf(name, "%s/%s.%s.store", mTargetDir, mStoreName, aKey); 78 | return unlink(name) == 0; 79 | } 80 | }; 81 | 82 | #endif //GENUS_DESKTOPSTORE_H 83 | -------------------------------------------------------------------------------- /src/BStore/OdroidStore/OdroidStore.cpp: -------------------------------------------------------------------------------- 1 | #ifdef __XTENSA__ 2 | 3 | #include "OdroidStore.h" 4 | 5 | #endif -------------------------------------------------------------------------------- /src/BStore/OdroidStore/OdroidStore.h: -------------------------------------------------------------------------------- 1 | #ifdef __XTENSA__ 2 | #ifndef GENUS_ODROIDSTORE_H 3 | #define GENUS_ODROIDSTORE_H 4 | 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "BStoreBase.h" 14 | 15 | class OdroidStore : public BStoreBase { 16 | public: 17 | explicit OdroidStore(const char *aStoreName) : BStoreBase(aStoreName){ 18 | Initialize(); 19 | } 20 | 21 | void Initialize() OVERRIDE { 22 | if (!mInitialized) { 23 | esp_err_t err = nvs_flash_init(); 24 | if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) { 25 | // NVS partition was truncated and needs to be erased 26 | // Retry nvs_flash_init 27 | ESP_ERROR_CHECK(nvs_flash_erase()); 28 | err = nvs_flash_init(); 29 | } 30 | ESP_ERROR_CHECK(err); 31 | mInitialized = ETrue; 32 | } 33 | } 34 | 35 | TBool Get(const char *aKey, void *aValue, TUint32 aSize) override { 36 | nvs_handle my_handle; 37 | esp_err_t err; 38 | 39 | err = nvs_open(mStoreName, NVS_READWRITE, &my_handle); 40 | if (err != ESP_OK) { 41 | return EFalse; 42 | } 43 | 44 | TUint32 size = 0; 45 | err = nvs_get_blob(my_handle, aKey, NULL, &size); 46 | if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND) { 47 | return EFalse; 48 | } 49 | if (size != aSize) { 50 | return EFalse; 51 | } 52 | 53 | err = nvs_get_blob(my_handle, aKey, aValue, &size); 54 | nvs_close(my_handle); 55 | return err == ESP_OK; 56 | } 57 | 58 | TBool Set(const char *aKey, void *aValue, TUint32 aSize) override { 59 | nvs_handle my_handle; 60 | esp_err_t err; 61 | 62 | err = nvs_open(mStoreName, NVS_READWRITE, &my_handle); 63 | if (err != ESP_OK) { 64 | #ifndef PRODUCTION 65 | #if (defined(__XTENSA__) && defined(DEBUGME)) || !defined(__XTENSA__) 66 | printf("Set: nvs_open failed, returned %d\n", err); 67 | #endif 68 | #endif 69 | return EFalse; 70 | } 71 | 72 | err = nvs_set_blob(my_handle, aKey, aValue, aSize); 73 | if (err == ESP_OK) { 74 | err = nvs_commit(my_handle); 75 | } 76 | else { 77 | #ifndef PRODUCTION 78 | #if (defined(__XTENSA__) && defined(DEBUGME)) || !defined(__XTENSA__) 79 | printf("Set: nvs_set_blob failed, returned %d\n", err); 80 | #endif 81 | #endif 82 | } 83 | nvs_close(my_handle); 84 | return err == ESP_OK; 85 | } 86 | 87 | }; 88 | 89 | 90 | 91 | #endif //GENUS_ODROIDSTORE_H 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /src/BTileMap.cpp: -------------------------------------------------------------------------------- 1 | #include "CreativeEngine.h" 2 | 3 | BTileMap::BTileMap(void *aRomData, TInt16 aTilesetSlot) { 4 | TUint16 *rom = (TUint16 *)aRomData; 5 | mTilesetSlot = aTilesetSlot; 6 | mTilesetId = *rom++; 7 | if (!gResourceManager.LoadBitmap(mTilesetId, aTilesetSlot, IMAGE_32x32)) { 8 | Panic("Can't loadBitmap(%d)\n", mTilesetSlot); 9 | } 10 | mTiles = gResourceManager.GetBitmap(aTilesetSlot); 11 | mObjectCount = *rom++; 12 | mObjectProgram = (BObjectProgram *)&rom[0]; 13 | rom = (TUint16 *)&mObjectProgram[mObjectCount]; 14 | mWidth = *rom++; 15 | mHeight = *rom++; 16 | mMapData = new TUint32[mWidth * mHeight]; 17 | memcpy(mMapData, &rom[0], mWidth * mHeight * sizeof(TUint32)); 18 | } 19 | 20 | BTileMap::~BTileMap() { 21 | // delete mTiles; 22 | delete[] this->mMapData; 23 | } 24 | 25 | TUint8 *BTileMap::TilePtr(TInt aRow, TInt aCol) { 26 | const TInt index = aRow * mWidth + aCol, 27 | tileNumber = mMapData[index] & TUint32(0xffff); 28 | 29 | const TInt tw = mTiles->Width() / TILESIZE, 30 | row = tileNumber / tw, 31 | col = tileNumber % tw; 32 | 33 | const TInt offset = row * TILESIZE * mTiles->Width() + col * TILESIZE; 34 | return &mTiles->mPixels[offset]; 35 | } 36 | -------------------------------------------------------------------------------- /src/BTileMap.h: -------------------------------------------------------------------------------- 1 | #ifndef BTILEMAP_H 2 | #define BTILEMAP_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define TILE_INDEX(n) (TUint16((n)&0xffff)) 9 | 10 | struct BObjectProgram { 11 | TUint32 mCode; 12 | TUint16 mRow, mCol; 13 | void WriteToStream(BMemoryStream *aStream) { 14 | aStream->Write(&mCode, sizeof(mCode)); 15 | aStream->Write(&mRow, sizeof(mRow)); 16 | aStream->Write(&mCol, sizeof(mCol)); 17 | } 18 | void ReadFromStream(BMemoryStream *aStream) { 19 | aStream->Read(&mCode, sizeof(mCode)); 20 | aStream->Read(&mRow, sizeof(mRow)); 21 | aStream->Read(&mCol, sizeof(mCol)); 22 | } 23 | void Dump(TInt ndx) { 24 | printf("%5d %24.24s: %08x(%d:%d) %d,%d\n", ndx, "Code, row,col", mCode, LOWORD(mCode), HIWORD(mCode), mRow, mCol); 25 | } 26 | }; 27 | 28 | class BTileMap : BBase { 29 | public: 30 | BTileMap(void *aRomData, TInt16 aTilesetSlot); 31 | 32 | ~BTileMap(); 33 | 34 | public: 35 | TUint8 *TilePtr(TInt aRow, TInt aCol); 36 | 37 | public: 38 | TUint16 mWidth, mHeight; 39 | TUint32 *mMapData; 40 | TUint16 mObjectCount; 41 | BObjectProgram *mObjectProgram; 42 | TUint16 mTilesetId, mTilesetSlot; 43 | BBitmap *mTiles; 44 | }; 45 | 46 | #endif //BTILEMAP_H 47 | -------------------------------------------------------------------------------- /src/BTypes.cpp: -------------------------------------------------------------------------------- 1 | #include "BTypes.h" 2 | 3 | #if 0 4 | TBool TRect::Overlaps(TRect &aOther) { 5 | if (x1 > aOther.x2 || x2 < aOther.x1) { 6 | return EFalse; 7 | } 8 | if (y1 > aOther.y2 || y2 < aOther.y1) { 9 | return EFalse; 10 | } 11 | return ETrue; 12 | } 13 | 14 | void TRect::Normalize() { 15 | TRect t = *this; 16 | x1 = MIN(t.x1, t.x2); 17 | x2 = MAX(t.x1, t.x2); 18 | y1 = MIN(t.y1, t.y2); 19 | y2 = MAX(t.y1, t.y2); 20 | } 21 | 22 | // enlarge this rect to encompass given rect 23 | void TRect::Union(const TRect &aRect) { 24 | x1 = MIN(x1, aRect.x1); 25 | y1 = MIN(y1, aRect.y1); 26 | x2 = MAX(x2, aRect.x2); 27 | y2 = MAX(y2, aRect.y2); 28 | } 29 | 30 | // set this rect to the overlapping region between given src rects 31 | TBool TRect::Intersection(const TRect &aSrcRect1, const TRect &aSrcRect2) { 32 | *this = aSrcRect1; 33 | return Intersection(aSrcRect2); 34 | } 35 | 36 | // set this rect to the overlapping region between this rect and given src rect 37 | TBool TRect::Intersection(const TRect &aSrcRect) { 38 | x1 = MAX(x1, aSrcRect.x1); 39 | x2 = MIN(x2, aSrcRect.x2); 40 | y1 = MAX(y1, aSrcRect.y1); 41 | y2 = MIN(y2, aSrcRect.y2); 42 | if (x2 < x1 || y2 < y1) { 43 | x1 = x2 = y1 = y2 = -1; // no overlap^M 44 | return EFalse; 45 | } 46 | Normalize(); 47 | return ETrue; 48 | } 49 | 50 | // move this rect in X centered around given X 51 | void TRect::CenterX(TInt32 aX) { 52 | TInt32 dx = aX - MID(x1, x2); 53 | x1 += dx; 54 | x2 += dx; 55 | } 56 | 57 | // move this rect in Y centered around given Y 58 | void TRect::CenterY(TInt32 aY) { 59 | TInt32 dy = aY - MID(y1, y2); 60 | y1 += dy; 61 | y2 += dy; 62 | } 63 | 64 | // move this rect in X and Y centered around given X,Y 65 | void TRect::Center(TInt32 aX, TInt32 aY) { 66 | TInt32 dx = aX - MID(x1, x2); 67 | x1 += dx; 68 | x2 += dx; 69 | 70 | TInt32 dy = aY - MID(y1, y2); 71 | y1 += dy; 72 | y2 += dy; 73 | } 74 | 75 | // move this rect in X centered around given Rect 76 | void TRect::CenterInX(TRect &aRect) { 77 | CenterX(MID(aRect.x1, aRect.x2)); 78 | x1 -= aRect.x1; 79 | x2 -= aRect.x1; 80 | } 81 | 82 | // move this rect in Y centered around given Rect 83 | void TRect::CenterInY(TRect &aRect) { 84 | CenterY(MID(aRect.y1, aRect.y2)); 85 | y1 -= aRect.y1; 86 | y2 -= aRect.y1; 87 | } 88 | 89 | // move this rect in X and Y centered around given Rect 90 | void TRect::CenterIn(TRect &aRect) { 91 | Center(MID(aRect.x1, aRect.x2), MID(aRect.y1, aRect.y2)); 92 | x1 -= aRect.x1; 93 | x2 -= aRect.x1; 94 | y1 -= aRect.y1; 95 | y2 -= aRect.y1; 96 | } 97 | #endif 98 | -------------------------------------------------------------------------------- /src/BViewPort.cpp: -------------------------------------------------------------------------------- 1 | #include "BViewPort.h" 2 | 3 | BViewPort::BViewPort() { 4 | // initialize ILI9341 5 | mWorldX = mWorldY = 0; 6 | mOffsetX = mOffsetY = 0; 7 | } 8 | 9 | BViewPort::~BViewPort() { 10 | // release any resources 11 | } 12 | 13 | void BViewPort::Dump() { 14 | mRect.Dump(); 15 | } 16 | -------------------------------------------------------------------------------- /src/Controls/Controls.cpp: -------------------------------------------------------------------------------- 1 | #include "Controls.h" 2 | 3 | 4 | Controls::Controls() { 5 | Reset(); 6 | } 7 | 8 | Controls::~Controls() = default; 9 | 10 | // ODROID 11 | #ifdef __XTENSA__ 12 | #include "./OdroidControls/OdroidControls.h" 13 | static OdroidControls child; 14 | Controls &gControls = child; 15 | #define DISPLAY 16 | #endif 17 | 18 | #ifdef __DINGUX__ 19 | #include "./LDKControls/LDKControls.h" 20 | static LDKControls child; 21 | Controls &gControls = child; 22 | #define DISPLAY 23 | #endif 24 | 25 | // Networked RGB Matrix 26 | #ifdef __MODUS_TARGET_NETWORK_DISPLAY__ 27 | #include "./NetworkControls/NetworkControls.h" 28 | static NetworkControls child; 29 | Controls &gControls = child; 30 | #define DISPLAY 31 | #endif 32 | 33 | // Desktop only 34 | #ifndef DISPLAY 35 | #include "./DesktopControls/DesktopControls.h" 36 | static DesktopControls child; 37 | Controls &gControls = child; 38 | #endif 39 | -------------------------------------------------------------------------------- /src/Controls/Controls.h: -------------------------------------------------------------------------------- 1 | #ifndef CONTROLS_H 2 | #define CONTROLS_H 3 | 4 | #include "BTypes.h" 5 | 6 | const TUint16 BUTTON1 = TUint16(1<<0); 7 | const TUint16 BUTTON2 = TUint16(1<<1); 8 | const TUint16 BUTTON3 = TUint16(1<<2); 9 | const TUint16 BUTTON4 = TUint16(1<<3); 10 | const TUint16 BUTTONA = TUint16(1<<4); 11 | const TUint16 BUTTONB = TUint16(1<<5); 12 | const TUint16 BUTTONX = TUint16(1<<6); 13 | const TUint16 BUTTONY = TUint16(1<<7); 14 | const TUint16 JOYUP = TUint16(1<<8); 15 | const TUint16 JOYDOWN = TUint16(1<<9); 16 | const TUint16 JOYLEFT = TUint16(1<<10); 17 | const TUint16 JOYRIGHT = TUint16(1<<11); 18 | const TUint16 BUTTONQ = TUint16(1<<12); 19 | const TUint16 BUTTONL = TUint16(1<<13); // left shoulder 20 | const TUint16 BUTTONR = TUint16(1<<14); // right shoulder 21 | 22 | const TUint16 BUTTON_MENU = (BUTTON1); 23 | const TUint16 BUTTON_SOUND = (BUTTON2); 24 | const TUint16 BUTTON_SELECT = (BUTTON3); 25 | const TUint16 BUTTON_START = (BUTTON4); 26 | 27 | const TUint16 BUTTON_ANY = (BUTTON1|BUTTON2|BUTTON3|BUTTON4|BUTTONA|BUTTONB); 28 | const TUint16 JOY_ANY = (JOYUP|JOYDOWN|JOYLEFT|JOYRIGHT); 29 | const TUint16 BUTTON_JOY_ANY = (BUTTON_ANY|JOY_ANY); 30 | 31 | class Controls { 32 | public: 33 | Controls(); 34 | virtual ~Controls(); 35 | 36 | public: 37 | void Reset() { 38 | bKeys = cKeys = dKeys = 0; 39 | } 40 | 41 | 42 | TBool WasPressed(TUint16 bits) { 43 | if (dKeys & bits) { 44 | dKeys &= ~bits; 45 | return ETrue; 46 | } 47 | return EFalse; 48 | } 49 | 50 | TBool IsPressed(TUint16 bits) { 51 | return (cKeys & bits) ? ETrue : EFalse; 52 | } 53 | 54 | void Rumble(TFloat aStrength, TInt aTime) {} 55 | 56 | virtual TBool Poll() = 0; 57 | 58 | 59 | public: 60 | TUint16 bKeys, cKeys, dKeys; 61 | 62 | }; 63 | 64 | 65 | extern Controls &gControls; 66 | 67 | #endif //CONTROLS_H 68 | -------------------------------------------------------------------------------- /src/Controls/DesktopControls/DesktopControls.h: -------------------------------------------------------------------------------- 1 | #ifdef __MODUS_TARGET_DESKTOP_CONTROLS__ 2 | 3 | #ifndef DESKTOPCONTROLS_H 4 | #define DESKTOPCONTROLS_H 5 | 6 | 7 | #include "Controls.h" 8 | #include 9 | 10 | #define CONTROLLER_SUPPORT 11 | 12 | #define CONTROLLER_AXIS_MIN 24000 13 | 14 | class DesktopControls : public Controls { 15 | public: 16 | DesktopControls(); 17 | ~DesktopControls(); 18 | 19 | void Rumble(TFloat aStrength, TInt aTime); 20 | 21 | TBool Poll() final; 22 | 23 | #ifdef CONTROLLER_SUPPORT 24 | SDL_Haptic *haptic; 25 | SDL_GameController *ctrl; 26 | #endif 27 | }; 28 | 29 | #endif // DESKTOPCONTROLS_H 30 | 31 | #endif //__MODUS_TARGET_DESKTOP__ -------------------------------------------------------------------------------- /src/Controls/DirectLinuxControls/DirectLinuxControls.h: -------------------------------------------------------------------------------- 1 | #ifdef __MODUS_TARGET_DIRECT_LINUX_CONTROLS__ 2 | 3 | #ifndef DIRECTLINUXCONTROLS_H 4 | #define DIRECTLINUXCONTROLS_H 5 | 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include "axbtnmap.h" 25 | 26 | 27 | class DirectLinuxControls : public Controls { 28 | 29 | public: 30 | DirectLinuxControls(); 31 | ~DirectLinuxControls(); 32 | 33 | TBool Poll() final; 34 | 35 | void PollingThread(DirectLinuxControls *myControls); 36 | void ParseEvent(struct js_event *event); 37 | 38 | 39 | // Is this too much for an int?? 40 | void LockMutex() { 41 | pthread_mutex_lock(&mMutex); 42 | } 43 | 44 | void UnlockMutex() { 45 | pthread_mutex_unlock(&mMutex); 46 | } 47 | 48 | void StartThread() { 49 | mThreadRunning = true; 50 | mThread = std::thread(&DirectLinuxControls::PollingThread, this, this); 51 | mThread.detach(); 52 | } 53 | 54 | 55 | void StopThread() { 56 | mThreadRunning = false; 57 | if (mThread.joinable()) { 58 | mThread.join(); 59 | } 60 | usleep(100); 61 | } 62 | 63 | private: 64 | 65 | TBool mThreadRunning; 66 | int fd; 67 | pthread_mutex_t mMutex; 68 | std::thread mThread; 69 | }; 70 | 71 | 72 | 73 | #endif //DIRECTLINUXCONTROLS_H 74 | 75 | #endif // __MODUS_TARGET_DIRECT_LINUX_CONTROLS__ -------------------------------------------------------------------------------- /src/Controls/LDKControls/LDKControls.h: -------------------------------------------------------------------------------- 1 | #ifdef __DINGUX__ 2 | 3 | #ifndef MODITE_LDKCONTROLS_H 4 | #define MODITE_LDKCONTROLS_H 5 | #include "Controls.h" 6 | #include 7 | 8 | class LDKControls : public Controls { 9 | public: 10 | LDKControls(); 11 | ~LDKControls(); 12 | 13 | TBool Poll() final; 14 | }; 15 | 16 | 17 | #endif //MODITE_LDKCONTROLS_H 18 | 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /src/Controls/OdroidControls/OdroidControls.cpp: -------------------------------------------------------------------------------- 1 | #ifdef __XTENSA__ 2 | #include "OdroidControls.h" 3 | 4 | 5 | 6 | #define ODROID_GAMEPAD_IO_X ADC1_CHANNEL_6 7 | #define ODROID_GAMEPAD_IO_Y ADC1_CHANNEL_7 8 | #define ODROID_GAMEPAD_IO_SELECT GPIO_NUM_27 9 | #define ODROID_GAMEPAD_IO_START GPIO_NUM_39 10 | #define ODROID_GAMEPAD_IO_A GPIO_NUM_32 11 | #define ODROID_GAMEPAD_IO_B GPIO_NUM_33 12 | #define ODROID_GAMEPAD_IO_MENU GPIO_NUM_13 13 | #define ODROID_GAMEPAD_IO_VOLUME GPIO_NUM_0 14 | 15 | 16 | OdroidControls::OdroidControls() : ControlsBase() { 17 | gpio_set_direction(ODROID_GAMEPAD_IO_SELECT, GPIO_MODE_INPUT); 18 | gpio_set_pull_mode(ODROID_GAMEPAD_IO_SELECT, GPIO_PULLUP_ONLY); 19 | 20 | gpio_set_direction(ODROID_GAMEPAD_IO_START, GPIO_MODE_INPUT); 21 | 22 | gpio_set_direction(ODROID_GAMEPAD_IO_A, GPIO_MODE_INPUT); 23 | gpio_set_pull_mode(ODROID_GAMEPAD_IO_A, GPIO_PULLUP_ONLY); 24 | 25 | gpio_set_direction(ODROID_GAMEPAD_IO_B, GPIO_MODE_INPUT); 26 | gpio_set_pull_mode(ODROID_GAMEPAD_IO_B, GPIO_PULLUP_ONLY); 27 | 28 | adc1_config_width(ADC_WIDTH_12Bit); 29 | adc1_config_channel_atten(ODROID_GAMEPAD_IO_X, ADC_ATTEN_11db); 30 | adc1_config_channel_atten(ODROID_GAMEPAD_IO_Y, ADC_ATTEN_11db); 31 | 32 | gpio_set_direction(ODROID_GAMEPAD_IO_MENU, GPIO_MODE_INPUT); 33 | gpio_set_pull_mode(ODROID_GAMEPAD_IO_MENU, GPIO_PULLUP_ONLY); 34 | 35 | gpio_set_direction(ODROID_GAMEPAD_IO_VOLUME, GPIO_MODE_INPUT); 36 | } 37 | 38 | 39 | TBool OdroidControls::Poll() { 40 | TUint16 buttons = 0; 41 | 42 | TInt joyX = adc1_get_raw(ODROID_GAMEPAD_IO_X), 43 | joyY = adc1_get_raw(ODROID_GAMEPAD_IO_Y); 44 | 45 | if (joyX > 2048 + 1024) { 46 | buttons |= JOYLEFT; 47 | } 48 | else if (joyX > 1024) { 49 | buttons |= JOYRIGHT; 50 | } 51 | if (joyY > 2048 + 1024) { 52 | buttons |= JOYUP; 53 | } 54 | else if (joyY > 1024) { 55 | buttons |= JOYDOWN; 56 | } 57 | 58 | buttons |= gpio_get_level(ODROID_GAMEPAD_IO_SELECT) ? 0 : BUTTON3; 59 | buttons |= gpio_get_level(ODROID_GAMEPAD_IO_START) ? 0 : BUTTON4; 60 | 61 | buttons |= gpio_get_level(ODROID_GAMEPAD_IO_A) ? 0 : BUTTONA; 62 | buttons |= gpio_get_level(ODROID_GAMEPAD_IO_B) ? 0 : BUTTONB; 63 | 64 | buttons |= gpio_get_level(ODROID_GAMEPAD_IO_MENU) ? 0 : BUTTON1; 65 | buttons |= gpio_get_level(ODROID_GAMEPAD_IO_VOLUME) ? 0 : BUTTON2; 66 | 67 | dKeys = (buttons ^ cKeys) & buttons; 68 | cKeys = buttons; 69 | bKeys = buttons; 70 | return ETrue; 71 | } 72 | 73 | 74 | 75 | #endif -------------------------------------------------------------------------------- /src/Controls/OdroidControls/OdroidControls.h: -------------------------------------------------------------------------------- 1 | #ifdef __XTENSA__ 2 | 3 | #ifndef ODROIDCONTROLS_H 4 | #define ODROIDCONTROLS_H 5 | 6 | 7 | #include "Controls.h" 8 | 9 | #include "driver/gpio.h" 10 | #include "driver/i2c.h" 11 | #include "esp_adc_cal.h" 12 | #include "freertos/FreeRTOS.h" 13 | #include 14 | 15 | class OdroidControls : public Controls { 16 | 17 | public: 18 | OdroidControls(); 19 | 20 | ~OdroidControls() = default; 21 | TBool Poll() override; 22 | }; 23 | 24 | 25 | #endif //ODROIDCONTROLS_H 26 | 27 | #endif // __MODUS_TARGET_ODROID__ 28 | -------------------------------------------------------------------------------- /src/CreativeEngine.h: -------------------------------------------------------------------------------- 1 | #ifndef CREATIVEENGINE_H 2 | #define CREATIVEENGINE_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/Display/DesktopDisplay/DesktopDisplay.h: -------------------------------------------------------------------------------- 1 | #ifdef __MODUS_TARGET_DESKTOP_DISPLAY__ 2 | 3 | #ifndef DESKTOPDISPLAY_H 4 | #define DESKTOPDISPLAY_H 5 | 6 | #include "DisplayDefines.h" 7 | #include "Display.h" 8 | 9 | #include "BBase.h" 10 | #include "BBitmap.h" 11 | 12 | struct SDL_Window; 13 | struct SDL_Renderer; 14 | struct SDL_Texture; 15 | 16 | class DesktopDisplay : public Display { 17 | 18 | public: 19 | DesktopDisplay(); 20 | 21 | ~DesktopDisplay(); 22 | 23 | void Update() override; 24 | 25 | // For compatibility 26 | void Init() override {}; 27 | 28 | TUint16 color565(TUint8 red, TUint8 green, TUint8 blue) override{ 29 | // lifted from Display2.cpp 30 | // maybe we want to return something else for SDL 31 | return ((blue & 0xF8) << 8) | ((red & 0xFC) << 3) | ((green & 0xF8) >> 3); 32 | } 33 | public: 34 | SDL_Window *screen = ENull; 35 | SDL_Renderer *renderer = ENull; 36 | SDL_Texture *texture = ENull; 37 | 38 | }; 39 | 40 | 41 | #endif //DESKTOPDISPLAY_H 42 | 43 | #endif -------------------------------------------------------------------------------- /src/Display/Display.cpp: -------------------------------------------------------------------------------- 1 | #include "Display.h" 2 | 3 | // ODROID 4 | #ifdef __XTENSA__ 5 | #include "./OdroidDisplay/OdroidDisplay.h" 6 | static OdroidDisplay child; 7 | Display &gDisplay = child; 8 | #define DISPLAY 9 | #endif 10 | 11 | #ifdef __DINGUX__ 12 | #include "./LDKDisplay/LDKDisplay.h" 13 | static LDKDisplay child; 14 | Display &gDisplay = child; 15 | #define DISPLAY 16 | #endif 17 | 18 | // Networked RGB Matrix 19 | #ifdef __MODUS_TARGET_NETWORK_DISPLAY__ 20 | #include "./NetworkDisplay/NetworkDisplay.h" 21 | static NetworkDisplay child; 22 | Display &gDisplay = child; 23 | #define DISPLAY 24 | #endif 25 | 26 | // Desktop only 27 | #ifndef DISPLAY 28 | #include "./DesktopDisplay/DesktopDisplay.h" 29 | static DesktopDisplay child; 30 | Display &gDisplay = child; 31 | #endif 32 | -------------------------------------------------------------------------------- /src/Display/DisplayDefines.h: -------------------------------------------------------------------------------- 1 | #ifndef DISPLAYDEFINES_H 2 | #define DISPLAYDEFINES_H 3 | 4 | #define SCREEN_WIDTH 320 5 | #define SCREEN_HEIGHT 240 6 | 7 | #define DISPLAY_WIDTH (SCREEN_WIDTH) 8 | #define DISPLAY_HEIGHT (SCREEN_HEIGHT) 9 | 10 | #ifndef SCREEN_DEPTH 11 | #ifdef __DINGUX__ 12 | #define SCREEN_DEPTH 8 13 | #else 14 | #define SCREEN_DEPTH 8 15 | #endif 16 | #endif 17 | 18 | #endif //DISPLAYDEFINES_H 19 | -------------------------------------------------------------------------------- /src/Display/LDKDisplay/LDKDisplay.cpp: -------------------------------------------------------------------------------- 1 | #include "LDKDisplay.h" 2 | -------------------------------------------------------------------------------- /src/Display/LDKDisplay/LDKDisplay.h: -------------------------------------------------------------------------------- 1 | #ifdef __DINGUX__ 2 | 3 | #ifndef MODITE_LDKDISPLAY_H 4 | #define MODITE_LDKDISPLAY_H 5 | 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "Display.h" 13 | #include "DisplayDefines.h" 14 | 15 | 16 | 17 | class LDKDisplay : public Display { 18 | public: 19 | LDKDisplay() { 20 | SDL_ShowCursor(SDL_DISABLE); 21 | 22 | if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) == -1) { 23 | fprintf(stderr, "Could Initiate SDL! %s\n", SDL_GetError()); 24 | fprintf(stderr, "EXITING..."); 25 | exit(-1); 26 | } 27 | 28 | atexit(SDL_Quit); 29 | 30 | mSDLScreen = SDL_SetVideoMode( 31 | SCREEN_WIDTH, 32 | SCREEN_HEIGHT, 33 | 16, 34 | SDL_HWSURFACE | 35 | 36 | #ifdef SDL_TRIPLEBUF 37 | SDL_TRIPLEBUF 38 | #else 39 | SDL_DOUBLEBUF 40 | #endif 41 | ); 42 | 43 | 44 | } 45 | 46 | void Init() override { 47 | mSLastTicks = SDL_GetTicks(); 48 | }; 49 | 50 | void Update() override { 51 | SwapBuffers(); 52 | 53 | TUint16 colors[256]; 54 | auto *screenPixels = (TInt16 *) mSDLScreen->pixels; 55 | TRGB *palette = displayBitmap->GetPalette(); 56 | 57 | for (TInt c = 0; c < 256; c++) { 58 | colors[c] = palette[c].rgb565(); 59 | } 60 | 61 | for (TInt y = 0; y < SCREEN_HEIGHT; y++) { 62 | TUint8 *src = &displayBitmap->mPixels[y * displayBitmap->GetPitch()]; 63 | 64 | for (TInt x = 0; x < SCREEN_WIDTH; x++) { 65 | TUint8 pixel = *src++; 66 | *screenPixels++ = colors[pixel]; 67 | } 68 | } 69 | 70 | if (SDL_MUSTLOCK(mSDLScreen)) SDL_UnlockSurface(mSDLScreen); 71 | SDL_Flip(mSDLScreen); 72 | if (SDL_MUSTLOCK(mSDLScreen)) SDL_LockSurface(mSDLScreen); 73 | 74 | NextFrameDelay(); 75 | } 76 | 77 | ~LDKDisplay() { 78 | SDL_FreeSurface(mSDLScreen); 79 | SDL_Quit(); 80 | } 81 | 82 | SDL_Surface *mSDLScreen; 83 | 84 | TUint16 color565(TUint8 red, TUint8 green, TUint8 blue) override{ 85 | // lifted from Display2.cpp 86 | // maybe we want to return something else for SDL 87 | return ((blue & 0xF8) << 8) | ((red & 0xFC) << 3) | ((green & 0xF8) >> 3); 88 | } 89 | 90 | }; 91 | 92 | 93 | 94 | #endif //MODITE_LDKDISPLAY_H 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /src/Display/NetworkDisplay/NetworkDisplay.h: -------------------------------------------------------------------------------- 1 | #ifdef __MODUS_TARGET_NETWORK_DISPLAY__ 2 | 3 | #ifndef GENUS_MATRIX_DISPLAY_NETWORKDISPLAY_H 4 | #define GENUS_MATRIX_DISPLAY_NETWORKDISPLAY_H 5 | 6 | 7 | #include "BBase.h" 8 | #include "BBitmap.h" 9 | 10 | 11 | #include "Display.h" 12 | 13 | // screen attributes 14 | #define SCREEN_WIDTH 320 15 | #define SCREEN_HEIGHT 240 16 | #define SCREEN_DEPTH 8 17 | 18 | #define DISPLAY_WIDTH (SCREEN_WIDTH) 19 | #define DISPLAY_HEIGHT (SCREEN_HEIGHT) 20 | 21 | class NetworkDisplay : public Display { 22 | public: 23 | NetworkDisplay(); 24 | ~NetworkDisplay(); 25 | 26 | void Update() override; 27 | void UpdateSDL(); 28 | 29 | // For compatibility 30 | void Init() override; 31 | 32 | TUint16 color565(TUint8 red, TUint8 green, TUint8 blue) override{ 33 | // lifted from Display2.cpp 34 | // maybe we want to return something else for SDL 35 | return ((blue & 0xF8) << 8) | ((red & 0xFC) << 3) | ((green & 0xF8) >> 3); 36 | } 37 | }; 38 | 39 | //extern NetworkDisplay gNetworkDisplay; 40 | 41 | 42 | 43 | #endif //GENUS_MATRIX_DISPLAY_NETWORKDISPLAY_H 44 | 45 | #endif //#ifdef __MODUS_TARGET_NETWORK_DISPLAY__ -------------------------------------------------------------------------------- /src/Display/NetworkDisplay/RemoteMatrixDisplay.h: -------------------------------------------------------------------------------- 1 | #ifdef __MODUS_TARGET_NETWORK_DISPLAY__ 2 | 3 | #ifndef GENUS_NETWORKED_MATRIX_DISPLAY_MATRIXDISPLAY_H 4 | #define GENUS_NETWORKED_MATRIX_DISPLAY_MATRIXDISPLAY_H 5 | #include 6 | #include 7 | #include 8 | 9 | #include "BBase.h" 10 | 11 | #include "RemoteMatrixSegment.h" 12 | 13 | 14 | struct RemoteMatrixDisplayConfig { 15 | std::vector segments; 16 | size_t inputBufferSize; 17 | TUint16 inputScreenWidth; 18 | TUint16 inputScreenHeight; 19 | TUint16 outputScreenWidth; 20 | TUint16 outputScreenHeight; 21 | TUint16 singlePanelHeight; 22 | TUint16 singlePanelWidth; 23 | TUint16 totalPanelsWide; 24 | TUint16 totalPanelsTall; 25 | }; 26 | 27 | class RemoteMatrixDisplay { 28 | 29 | public: 30 | 31 | bool mRunning; 32 | 33 | explicit RemoteMatrixDisplay(const RemoteMatrixDisplayConfig config); 34 | ~RemoteMatrixDisplay(); 35 | 36 | void ThreadFunction(RemoteMatrixDisplay *remoteDisplay); 37 | 38 | void LockMutex(); 39 | 40 | void UnlockMutex(); 41 | void DescribeSegments(); 42 | void Update(); 43 | 44 | TUint16 *GetInputBuffer(); 45 | 46 | 47 | void CopyDataToBuffer(TUint16 *buffer); 48 | 49 | void WritePixel(TUint16 index, TUint16 color); 50 | void StartThread(); 51 | 52 | TUint16 GetFrameCount() { 53 | return mFrameCount; 54 | } 55 | 56 | TUint16 *mCurrentInputBuffer; 57 | 58 | bool GetThreadRunnning() { 59 | return mThreadRunning; 60 | } 61 | std::thread mThread; 62 | 63 | protected: 64 | 65 | 66 | private: 67 | size_t mInputBufferSize; 68 | TUint16 *mInputBuffer1; 69 | TUint16 *mInputBuffer2; 70 | 71 | size_t mOutputBufferSize; 72 | TUint16 *mOutputBuffer1; 73 | TUint16 *mOutputBuffer2; 74 | TUint16 *mCurrentOutputBuffer; 75 | 76 | TUint16 mOutputScreenWidth; 77 | TUint16 mOutputScreenHeight; 78 | TUint16 mInputScreenWidth; 79 | TUint16 mInputScreenHeight; 80 | 81 | TUint16 mSinglePanelWidth; 82 | TUint16 mSinglePanelHeight; 83 | 84 | std::vector mSegments; 85 | TUint16 mFrameCount; 86 | 87 | bool mThreadRunning; 88 | pthread_mutex_t mMutex; 89 | }; 90 | 91 | 92 | #endif //GENUS_MATRIX_DISPLAY_MATRIXDISPLAY_H 93 | 94 | #endif //#ifdef __MODUS_TARGET_NETWORK_DISPLAY__ -------------------------------------------------------------------------------- /src/Display/OdroidDisplay/OdroidDisplay.h: -------------------------------------------------------------------------------- 1 | #ifdef __XTENSA__ 2 | 3 | #ifndef ODROIDDISPLAY_H 4 | #define ODROIDDISPLAY_H 5 | 6 | 7 | #include "DisplayDefines.h" 8 | #include "Display.h" 9 | 10 | #include "freertos/FreeRTOS.h" 11 | #include "esp_system.h" 12 | #include "esp_event.h" 13 | #include "driver/gpio.h" 14 | #include "driver/spi_master.h" 15 | #include "driver/ledc.h" 16 | #include "driver/rtc_io.h" 17 | 18 | #include 19 | 20 | class OdroidDisplay : public Display { 21 | 22 | public: 23 | OdroidDisplay() = default; 24 | 25 | void Init() override; 26 | 27 | void Update() override; 28 | 29 | static void DisplayTask(void* arg); 30 | static void SpiTask(void* arg); 31 | static void LockDisplay(); 32 | static void UnlockDisplay(); 33 | static void WriteFrame(TUint8* frameBuffer, TUint16* palette); 34 | static spi_transaction_t* GetSpiTransaction(); 35 | static void PutSpiTransaction(spi_transaction_t *t); 36 | static void InitializeSPI(); 37 | 38 | static TUint16* GetLineBufferQueue(); 39 | static void PutLineBufferQueue(TUint16 *buffer); 40 | static void SendDisplayCommand(const TUint8 cmd); 41 | static void SendDisplayData(const TUint8 *data, int len); 42 | static void SpiPreTransferCallback(spi_transaction_t *t); 43 | static void SendDisplayBootProgram(); 44 | static void SendResetDrawing(TUint8 left, TUint8 top, TUint16 width, TUint8 height); 45 | static void SendContinueWait(); 46 | static void SendContinueLine(TUint16 *line, TInt width, TInt lineCount); 47 | static void InitializeBacklight(); 48 | static void Clear(TUint16 color); // Doesn't seem to be used. 49 | 50 | TUint16 color565(TUint8 b, TUint8 r, TUint8 g) override { 51 | // lifted from Display2.cpp 52 | TUint16 blue = (b & 0b11111000) << 5; 53 | TUint16 red = (r & 0b11111000); 54 | 55 | TUint16 g2 = (g & 0b00011100) << 11; 56 | TUint16 g1 = (g & 0b11100000) >> 5; 57 | TUint16 green = g1 + g2; 58 | 59 | 60 | // For the ILI9341 display , data is organized like this: 61 | // 000 00000 00000 000 62 | // G456 B12345 R12345 G123 63 | // Green high bits (4 - 6), Blue bits, Red bits, Green low bits (1 - 3) 64 | TUint16 final = (TUint16)(red + green + blue); 65 | return final; 66 | } 67 | 68 | void SetBrightness(int value); 69 | 70 | 71 | }; 72 | 73 | 74 | 75 | #endif //ODROIDDISPLAY_H 76 | 77 | 78 | #endif -------------------------------------------------------------------------------- /src/Memory.cpp: -------------------------------------------------------------------------------- 1 | #include "BTypes.h" 2 | #include "Memory.h" 3 | #include "stdlib.h" 4 | 5 | // Global Versions 6 | extern "C" TAny *AllocMem(size_t size, TUint16 aType) { 7 | #ifdef __XTENSA__ 8 | TAny *ptr = heap_caps_malloc(size, aType); 9 | #else 10 | // printf("AllocMem %lu\n", size); 11 | TAny *ptr = malloc(size); 12 | #endif 13 | // bzero(ptr, size); 14 | return ptr; 15 | } 16 | 17 | extern "C" TAny *CallocMem(size_t numElements, size_t size, TUint16 aType) { 18 | #ifdef __XTENSA__ 19 | return heap_caps_calloc(numElements, size, aType); 20 | #else 21 | TAny *ptr = malloc(numElements * size); 22 | if (ptr == nullptr) { 23 | return ptr; 24 | } 25 | 26 | bzero(ptr, numElements * size); 27 | return ptr; 28 | #endif 29 | 30 | 31 | } 32 | 33 | extern "C" void FreeMem(TAny *ptr) { 34 | free(ptr); 35 | } 36 | 37 | extern "C" TAny *ReallocMem(TAny *aPtr, size_t aSize, TInt16 aType) { 38 | #ifdef __XTENSA__ 39 | return heap_caps_realloc(aPtr, aSize, aType); 40 | #else 41 | return realloc(aPtr, aSize); 42 | #endif 43 | } 44 | 45 | extern "C" TUint32 AvailMem(TUint16 aType) { 46 | #ifdef __XTENSA__ 47 | return (TUint32)heap_caps_get_free_size(aType); 48 | #else 49 | // we probably don't care :) 50 | return 4 * 1024 * 1024; 51 | #endif 52 | } 53 | 54 | -------------------------------------------------------------------------------- /src/Memory.h: -------------------------------------------------------------------------------- 1 | #ifndef CREATIVE_ENGINE_MEMORY_H 2 | #define CREATIVE_ENGINE_MEMORY_H 3 | 4 | #ifdef __cplusplus 5 | /** 6 | * Allocate memory of specified size and type 7 | * 8 | * @param aSize 9 | * @param aFlags MEMF_FAST or MEMF_SLOW 10 | * @return 11 | */ 12 | extern "C" TAny *AllocMem(size_t aSize, TUint16 aFlags); 13 | 14 | /** 15 | * Free memory allocated with AllocMem 16 | * @param ptr 17 | */ 18 | extern "C" void FreeMem(TAny *ptr); 19 | 20 | /** 21 | * Resize memory allocated with AllocMem 22 | */ 23 | extern "C" TAny *ReallocMem(TAny *aPtr, size_t aSize, TInt16 aType); 24 | 25 | /** 26 | * Return available memory of specified type 27 | */ 28 | extern "C" TUint32 AvailMem(TUint16 aFlags); 29 | 30 | #else 31 | #include 32 | typedef void TAny; 33 | typedef unsigned short TUint16; 34 | typedef short TInt16; 35 | typedef unsigned int TUint32; 36 | #define EFalse (0) 37 | #define ETrue (!0) 38 | typedef int TBool; 39 | 40 | /** 41 | * Allocate memory of specified size and type 42 | * 43 | * @param aSize 44 | * @param aFlags MEMF_FAST or MEMF_SLOW 45 | * @return 46 | */ 47 | extern TAny *AllocMem(size_t aSize, TUint16 aType); 48 | extern TAny *CallocMem(size_t numElements, size_t aSize, TUint16 aType); 49 | /** 50 | * Free memory allocated with AllocMem 51 | * @param ptr 52 | */ 53 | extern void FreeMem(TAny *ptr); 54 | 55 | /** 56 | * Resize memory allocated with AllocMem 57 | */ 58 | extern TAny *ReallocMem(TAny *aPtr, size_t aSize, TInt16 aType); 59 | 60 | /** 61 | * Return available memory of specified type 62 | */ 63 | extern TUint32 AvailMem(TUint16 aFlags); 64 | #endif 65 | 66 | #ifdef __XTENSA__ 67 | #include "freertos/FreeRTOS.h" 68 | #define MEMF_SLOW (MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM) 69 | #define MEMF_FAST (MALLOC_CAP_8BIT | MALLOC_CAP_DMA) 70 | 71 | #else 72 | 73 | #define MEMF_SLOW 0 74 | #define MEMF_FAST (1 << 0) 75 | 76 | #endif 77 | 78 | #endif //CREATIVE_ENGINE_MEMORY_H 79 | -------------------------------------------------------------------------------- /src/Panic.cpp: -------------------------------------------------------------------------------- 1 | #include "Panic.h" 2 | 3 | #ifndef __XTENSA__ 4 | #include 5 | #include 6 | #else 7 | #include "freertos/FreeRTOS.h" 8 | #include "freertos/task.h" 9 | #endif 10 | 11 | #include 12 | #include 13 | 14 | void Panic(const char *aFmt, ...) { 15 | #ifndef PRODUCTION 16 | #if (defined(__XTENSA__) && defined(DEBUGME)) || !defined(__XTENSA__) 17 | char msg[4096]; 18 | va_list args; 19 | va_start(args, aFmt); 20 | vsprintf(msg, aFmt, args); 21 | printf("PANIC: %s\n", msg); 22 | #endif 23 | #endif 24 | 25 | #ifndef __XTENSA__ 26 | exit(1); 27 | #else 28 | while (true) { 29 | vTaskDelay(10000); 30 | } 31 | #endif 32 | } 33 | 34 | void Dump(TUint32 *ptr, int width, int height) { 35 | #ifndef PRODUCTION 36 | #if (defined(__XTENSA__) && defined(DEBUGME)) || !defined(__XTENSA__) 37 | TUint32 addr = 0; 38 | for (int r = 0; r < height; r++) { 39 | printf("%08x ", addr); 40 | addr += width; 41 | for (int i=0; i> ((7 - i) * 4)) & 0x0f; 29 | if (aZeroPad || v || nonZero) { 30 | *pd++ = '0' + TInt8(v); 31 | } 32 | if (v) { 33 | nonZero = ETrue; 34 | } 35 | } 36 | 37 | TInt v = mValue & 0x0f; 38 | *pd++ = '0' + TInt8(v); 39 | *pd = '\0'; 40 | } 41 | 42 | void TBCD::Add(TBCD &aValue) { 43 | TUint32 t1 = mValue + 0x06666666; 44 | TUint32 t2 = t1 + aValue.mValue; 45 | TUint32 t3 = t1 ^aValue.mValue; 46 | TUint32 t4 = t2 ^t3; 47 | TUint32 t5 = ~t4 & 0x11111110; 48 | TUint32 t6 = (t5 >> 2) | (t5 >> 3); 49 | mValue = t2 - t6; 50 | } 51 | 52 | void TBCD::FromUint32(TUint32 v) { 53 | mValue = 0; 54 | TInt shift = 0; 55 | while (v > 0) { 56 | mValue |= (v % 10) << (shift++ << 2); 57 | v /= 10; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Types/TBCD.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_TBCD_H 2 | #define GENUS_TBCD_H 3 | 4 | #include "BTypes.h" 5 | 6 | // useful for scores and other numbers printed on screen 7 | struct TBCD { 8 | TBCD(TUint32 aValue); 9 | 10 | TBCD(TBCD &aValue); 11 | 12 | TBCD(const char *aValue); 13 | 14 | TBCD(); 15 | 16 | public: 17 | void ToString(char aDest[], TBool aZeroPad = ETrue); 18 | 19 | void Add(TBCD &aValue); 20 | 21 | void FromUint32(TUint32 v); 22 | 23 | TUint32 operator*() { 24 | return mValue; 25 | } 26 | 27 | TUint32 mValue; 28 | }; 29 | 30 | 31 | #endif //GENUS_TBCD_H 32 | -------------------------------------------------------------------------------- /src/Types/TRGB.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_TRGB_H 2 | #define GENUS_TRGB_H 3 | 4 | #include "BBase.h" 5 | #include "BTypes.h" 6 | 7 | struct TRGB { 8 | TInt16 r, g, b; 9 | 10 | public: 11 | TRGB() { 12 | r = g = b = 0; 13 | } 14 | 15 | TRGB(TInt aVal) { 16 | r = g = b = aVal; 17 | } 18 | 19 | TRGB(TUint32 aColor) { 20 | r = TUint8((aColor >> 16) & 0xff); 21 | g = TUint8((aColor >> 8) & 0xff); 22 | b = TUint8((aColor >> 0) & 0xff); 23 | } 24 | 25 | TRGB(TUint8 aRed, TUint8 aGreen, TUint8 aBlue) { 26 | r = aRed; 27 | g = aGreen; 28 | b = aBlue; 29 | } 30 | 31 | TRGB(const TRGB &aOther) { 32 | r = aOther.r; 33 | g = aOther.g; 34 | b = aOther.b; 35 | } 36 | 37 | public: 38 | void Set(TUint8 aRed, TUint8 aGreen, TUint8 aBlue) { 39 | r = aRed; 40 | g = aGreen; 41 | b = aBlue; 42 | } 43 | 44 | void Set(const TRGB &aOther) { 45 | r = aOther.r; 46 | g = aOther.g; 47 | b = aOther.b; 48 | } 49 | 50 | void Set(TUint32 aColor) { 51 | r = TUint8((aColor >> 16) & 0xff); 52 | g = TUint8((aColor >> 8) & 0xff); 53 | b = TUint8((aColor >> 0) & 0xff); 54 | } 55 | 56 | void Scale(TUint aScale) { 57 | r = TUint8(r * aScale) >> 8; 58 | g = TUint8(g * aScale) >> 8; 59 | b = TUint8(b * aScale) >> 8; 60 | } 61 | 62 | void SetScaled(TUint8 aRed, TUint8 aGreen, TUint8 aBlue, TUint aScale) { 63 | r = TUint8(aRed * aScale) >> 8; 64 | g = TUint8(aGreen * aScale) >> 8; 65 | b = TUint8(aBlue * aScale) >> 8; 66 | } 67 | 68 | public: 69 | TUint32 rgb888() const { return (TUint8(r) << 16) | (TUint8(g) << 8) | (TUint8(b) << 0); } 70 | 71 | TUint16 rgb565() const { 72 | return ((TUint16(r & 0b11111000) << 8)) | ((TUint16(g & 0b11111100) << 3)) | (TUint16(b) >> 3); 73 | } 74 | 75 | TUint16 bgr565() const { 76 | return ((b & 0b11111000) << 8) | ((g & 0b11111100) << 3) | (r >> 3); 77 | } 78 | 79 | TUint16 brg565() const { 80 | return ((b & 0b11111000) << 8) | ((r & 0b11111100) << 3) | (g >> 3); 81 | } 82 | 83 | TBool operator==(const TRGB &aOther) { 84 | return (r == aOther.r && g == aOther.g && b == aOther.b); 85 | } 86 | 87 | TBool operator==(TInt aInt) const { 88 | return (r == aInt && g == aInt && b == aInt); 89 | } 90 | 91 | public: 92 | void Dump() { 93 | #ifndef PRODUCTION 94 | #if (defined(__XTENSA__) && defined(DEBUGME)) || !defined(__XTENSA__) 95 | printf("%02x:%02x:%02x\n", r, g, b); 96 | #endif 97 | #endif 98 | } 99 | }; 100 | 101 | typedef struct TRGB TPalette; 102 | 103 | #endif //GENUS_TRGB_H 104 | -------------------------------------------------------------------------------- /src/Types/TRect.cpp: -------------------------------------------------------------------------------- 1 | #include "TRect.h" 2 | 3 | TBool TRect::Overlaps(TRect &aOther) { 4 | if (x1 > aOther.x2 || x2 < aOther.x1) { 5 | return EFalse; 6 | } 7 | if (y1 > aOther.y2 || y2 < aOther.y1) { 8 | return EFalse; 9 | } 10 | return ETrue; 11 | } 12 | 13 | void TRect::Normalize() { 14 | TRect t = *this; 15 | x1 = MIN(t.x1, t.x2); 16 | x2 = MAX(t.x1, t.x2); 17 | y1 = MIN(t.y1, t.y2); 18 | y2 = MAX(t.y1, t.y2); 19 | } 20 | 21 | // enlarge this rect to encompass given rect 22 | void TRect::Union(const TRect &aRect) { 23 | x1 = MIN(x1, aRect.x1); 24 | y1 = MIN(y1, aRect.y1); 25 | x2 = MAX(x2, aRect.x2); 26 | y2 = MAX(y2, aRect.y2); 27 | } 28 | 29 | // set this rect to the overlapping region between given src rects 30 | TBool TRect::Intersection(const TRect &aSrcRect1, const TRect &aSrcRect2) { 31 | *this = aSrcRect1; 32 | return Intersection(aSrcRect2); 33 | } 34 | 35 | // set this rect to the overlapping region between this rect and given src rect 36 | TBool TRect::Intersection(const TRect &aSrcRect) { 37 | x1 = MAX(x1, aSrcRect.x1); 38 | x2 = MIN(x2, aSrcRect.x2); 39 | y1 = MAX(y1, aSrcRect.y1); 40 | y2 = MIN(y2, aSrcRect.y2); 41 | if (x2 < x1 || y2 < y1) { 42 | x1 = x2 = y1 = y2 = -1; // no overlap^M 43 | return EFalse; 44 | } 45 | Normalize(); 46 | return ETrue; 47 | } 48 | 49 | // move this rect in X centered around given X 50 | void TRect::CenterX(TInt32 aX) { 51 | TInt32 dx = aX - MID(x1, x2); 52 | x1 += dx; 53 | x2 += dx; 54 | } 55 | 56 | // move this rect in Y centered around given Y 57 | void TRect::CenterY(TInt32 aY) { 58 | TInt32 dy = aY - MID(y1, y2); 59 | y1 += dy; 60 | y2 += dy; 61 | } 62 | 63 | // move this rect in X and Y centered around given X,Y 64 | void TRect::Center(TInt32 aX, TInt32 aY) { 65 | TInt32 dx = aX - MID(x1, x2); 66 | x1 += dx; 67 | x2 += dx; 68 | 69 | TInt32 dy = aY - MID(y1, y2); 70 | y1 += dy; 71 | y2 += dy; 72 | } 73 | 74 | // move this rect in X centered around given Rect 75 | void TRect::CenterInX(TRect &aRect) { 76 | CenterX(MID(aRect.x1, aRect.x2)); 77 | x1 -= aRect.x1; 78 | x2 -= aRect.x1; 79 | } 80 | 81 | // move this rect in Y centered around given Rect 82 | void TRect::CenterInY(TRect &aRect) { 83 | CenterY(MID(aRect.y1, aRect.y2)); 84 | y1 -= aRect.y1; 85 | y2 -= aRect.y1; 86 | } 87 | 88 | // move this rect in X and Y centered around given Rect 89 | void TRect::CenterIn(TRect &aRect) { 90 | Center(MID(aRect.x1, aRect.x2), MID(aRect.y1, aRect.y2)); 91 | x1 -= aRect.x1; 92 | x2 -= aRect.x1; 93 | y1 -= aRect.y1; 94 | y2 -= aRect.y1; 95 | } 96 | -------------------------------------------------------------------------------- /src/Widgets/BButtonWidget.cpp: -------------------------------------------------------------------------------- 1 | #include "BButtonWidget.h" 2 | #include "Display/Display.h" 3 | #include "Controls.h" 4 | #include 5 | 6 | BButtonWidget::BButtonWidget(char *aText, TInt aForeground, TInt aBackground) : BWidget() { 7 | mText = aText; 8 | } 9 | 10 | BButtonWidget::BButtonWidget(const char *aText, TInt aForeground, TInt aBackground) : BWidget() { 11 | mText = (char *) aText; 12 | mHeight = 40; 13 | } 14 | 15 | BButtonWidget::~BButtonWidget() {} 16 | 17 | TInt BButtonWidget::Render(TInt aX, TInt aY) { 18 | const BFont *font = gWidgetTheme.GetFont(WIDGET_TEXT_FONT); 19 | const TInt fg = gWidgetTheme.GetInt(WIDGET_TEXT_FG), 20 | bg = gWidgetTheme.GetInt(WIDGET_TEXT_BG); 21 | 22 | if (IsActive()) { 23 | gDisplay.renderBitmap->DrawString(ENull, mText, font, aX, aY, bg, fg); 24 | } else { 25 | gDisplay.renderBitmap->DrawString(ENull, mText, font, aX, aY, fg, bg); 26 | } 27 | 28 | return font->mHeight; 29 | } 30 | 31 | void BButtonWidget::Run() { 32 | if (IsActive() && gControls.WasPressed(BUTTONA | BUTTONB | BUTTON_START)) { 33 | Select(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Widgets/BButtonWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_BBUTTONWIDGET_H 2 | #define GENUS_BBUTTONWIDGET_H 3 | 4 | #include 5 | #include 6 | 7 | /** 8 | * Widget implementing a select UI. Presents a list of options and allows the user to pick one. 9 | */ 10 | 11 | class BButtonWidget : public BWidget { 12 | public: 13 | BButtonWidget(char *aText, TInt aForeground, TInt aBackground = -1); 14 | 15 | BButtonWidget(const char *aText, TInt aForeground, TInt aBackground = -1); 16 | 17 | ~BButtonWidget(); 18 | 19 | public: 20 | TInt Render(TInt aX, TInt aY); 21 | void Run(); 22 | 23 | public: 24 | virtual void Select() = 0; 25 | 26 | public: 27 | char *mText; 28 | }; 29 | 30 | 31 | #endif //GENUS_BBUTTONWIDGET_H 32 | -------------------------------------------------------------------------------- /src/Widgets/BContainerWidget.cpp: -------------------------------------------------------------------------------- 1 | #include "BContainerWidget.h" 2 | #include "Controls.h" 3 | 4 | BContainerWidget::BContainerWidget(TInt aX, TInt aY) : BWidget(aX, aY, ENull) { 5 | mCurrentWidget = ENull; 6 | mNextY = 0; 7 | } 8 | 9 | BContainerWidget::~BContainerWidget() { 10 | BWidget *w = (BWidget *) mList.First(); 11 | while (!(BWidget *) mList.End(w)) { 12 | BWidget *n = (BWidget *) mList.Next(w); 13 | delete w; 14 | w = n; 15 | } 16 | mList.Reset(); 17 | } 18 | 19 | void BContainerWidget::AddWidget(BWidget &aWidget) { 20 | aWidget.mX = mX; 21 | aWidget.mY = mNextY; 22 | mNextY += aWidget.mHeight; 23 | mList.AddTail(aWidget); 24 | if (!mCurrentWidget) { 25 | mCurrentWidget = &aWidget; 26 | mCurrentWidget->Activate(); 27 | } 28 | } 29 | 30 | TInt BContainerWidget::Render(TInt aX, TInt aY) { 31 | TInt h = 0; 32 | for (BWidget *w = mList.First(); !mList.End(w); w = mList.Next(w)) { 33 | 34 | TInt dy = w->RenderTitle(aX + mX, aY + mY, w == mCurrentWidget); 35 | aY += dy; 36 | h += dy; 37 | 38 | dy =w->Render(aX + mX, aY + mY); // render relative to mY 39 | aY += dy; 40 | h += dy; 41 | 42 | } 43 | return h; 44 | } 45 | 46 | void BContainerWidget::Run() { 47 | for (BWidget *w = (BWidget *) mList.First(); !mList.End(w); w = (BWidget *) mList.Next(w)) { 48 | w->Run(); 49 | } 50 | 51 | if (gControls.WasPressed(JOYUP) && OnNavigate(JOYUP) && mCurrentWidget->OnNavigate(JOYUP)) { 52 | mCurrentWidget->Deactivate(); 53 | if (mCurrentWidget == mList.First()) { 54 | mCurrentWidget = (BWidget *) mList.Last(); 55 | } else { 56 | mCurrentWidget = (BWidget *) mList.Prev(mCurrentWidget); 57 | } 58 | mCurrentWidget->Activate(); 59 | 60 | // reset dKeys so next state doesn't react to any keys already pressed 61 | gControls.dKeys = 0; 62 | } 63 | 64 | if (gControls.WasPressed(JOYDOWN | BUTTON_SELECT) && OnNavigate(JOYDOWN) && mCurrentWidget->OnNavigate(JOYDOWN)) { 65 | mCurrentWidget->Deactivate(); 66 | if (mCurrentWidget == mList.Last()) { 67 | mCurrentWidget = (BWidget *) mList.First(); 68 | } else { 69 | mCurrentWidget = (BWidget *) mList.Next(mCurrentWidget); 70 | } 71 | mCurrentWidget->Activate(); 72 | 73 | // reset dKeys so next state doesn't react to any keys already pressed 74 | gControls.dKeys = 0; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Widgets/BContainerWidget.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget that is a container of other widgets. 3 | * 4 | * Container is a BNode linked list. 5 | * 6 | * Run() runs all the widgets in the list. 7 | * 8 | * Joy Up/Down advances to the next widget, and activates it. 9 | */ 10 | #ifndef GENUS_BCONTAINERWIDGET_H 11 | #define GENUS_BCONTAINERWIDGET_H 12 | 13 | #include "BWidget.h" 14 | #include "BList.h" 15 | 16 | class BContainerWidget : public BWidget { 17 | public: 18 | BContainerWidget(TInt aX, TInt aY); 19 | 20 | virtual ~BContainerWidget(); 21 | 22 | public: 23 | void AddWidget(BWidget &aWidget); 24 | 25 | BWidget *RemHead() { return (BWidget *) mList.RemHead(); } 26 | 27 | BWidget *First() { return (BWidget *) mList.First(); } 28 | 29 | BWidget *Last() { return (BWidget *) mList.Last(); } 30 | 31 | BWidget *Next(BWidget *aWidget) { return (BWidget *) mList.Next(aWidget); } 32 | 33 | BWidget *Prev(BWidget *aWidget) { return (BWidget *) mList.Next(aWidget); } 34 | 35 | TBool End(BWidget *aWidget) { return (BWidget *) mList.End(aWidget); } 36 | 37 | public: 38 | TInt Render(TInt aX, TInt aY); 39 | 40 | void Run(); 41 | 42 | protected: 43 | BWidgetList mList; 44 | TInt mNextY; 45 | BWidget *mCurrentWidget; 46 | }; 47 | 48 | #endif //GENUS_BCONTAINERWIDGET_H 49 | -------------------------------------------------------------------------------- /src/Widgets/BDialogWidget.cpp: -------------------------------------------------------------------------------- 1 | #include "BDialogWidget.h" 2 | #include "Display/Display.h" 3 | 4 | BDialogWidget::BDialogWidget(char *aTitle, TInt aX, TInt aY) : BContainerWidget(aX, aY) { 5 | mTitle = aTitle; 6 | } 7 | 8 | BDialogWidget::BDialogWidget(const char *aTitle, TInt aX, TInt aY) : BContainerWidget(aX, aY) { 9 | mTitle = (char *) aTitle; 10 | } 11 | 12 | BDialogWidget::~BDialogWidget() { 13 | 14 | } 15 | 16 | TInt BDialogWidget::Render(TInt aX, TInt aY) { 17 | BBitmap *bm = gDisplay.renderBitmap; 18 | TInt t = TUint8(bm->TransparentColor()); 19 | 20 | // calculate window dimensions 21 | TInt h = 0, 22 | width = SCREEN_WIDTH - (aX+mX)*2; 23 | 24 | for (BWidget *w = First(); !End(w); w = Next(w)) { 25 | h += w->mHeight; 26 | } 27 | h += 20; 28 | if (h > SCREEN_HEIGHT) { 29 | h = SCREEN_HEIGHT; 30 | } 31 | 32 | // render dialog 33 | TUint8 bg = TUint8(gWidgetTheme.GetInt(WIDGET_WINDOW_BG)), 34 | fg = TUint8(gWidgetTheme.GetInt(WIDGET_WINDOW_FG)); 35 | 36 | // draw Dialog background 37 | TRect rect(mX+aX, mY+aY, (mX + aX) + width - 1, (mY+aY) + h - 1); 38 | 39 | if (bg != t) { 40 | bm->FillRect(ENull, (mX + aX), (mY+aY), rect.x2, rect.y2, bg); 41 | } 42 | // draw Dialog border 43 | if (fg != t) { 44 | bm->DrawFastHLine(ENull, (mX + aX), (mY+aY), (TUint)rect.Width(), fg); 45 | bm->DrawFastHLine(ENull, (mX + aX), rect.y2, (TUint)rect.Width(), fg); 46 | 47 | bm->DrawFastVLine(ENull, (mX + aX), (mY + aY), (TUint)rect.Height(), fg); 48 | bm->DrawFastVLine(ENull, (mX + aX + rect.Width() -1), (mY + aY), (TUint)rect.Height(), fg); 49 | } 50 | 51 | // render content area 52 | // TInt save = gWidgetTheme.GetInt(WIDGET_TITLE_FG); 53 | // gWidgetTheme.Configure(WIDGET_TITLE_FG, fg, WIDGET_END_TAG); 54 | // aY += BWidget::RenderTitle(mX + aX + 2, mY + aY + 2); 55 | // gWidgetTheme.Configure(WIDGET_TITLE_FG, save, WIDGET_END_TAG); 56 | BContainerWidget::Render(aX + 2, aY+2); 57 | return h; 58 | } 59 | 60 | 61 | -------------------------------------------------------------------------------- /src/Widgets/BDialogWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_BDIALOGWIDGET_H 2 | #define GENUS_BDIALOGWIDGET_H 3 | 4 | #include "BWidgetTheme.h" 5 | #include "BContainerWidget.h" 6 | 7 | class BDialogWidget : public BContainerWidget { 8 | public: 9 | BDialogWidget(char *aTitle, TInt aX, TInt aY); 10 | BDialogWidget(const char *aTitle, TInt aX, TInt aY); 11 | virtual ~BDialogWidget(); 12 | public: 13 | TInt Render(TInt aX, TInt aY); 14 | }; 15 | 16 | 17 | #endif //GENUS_BDIALOGWIDGET_H 18 | -------------------------------------------------------------------------------- /src/Widgets/BMenuWidget.cpp: -------------------------------------------------------------------------------- 1 | #include "BMenuWidget.h" 2 | 3 | -------------------------------------------------------------------------------- /src/Widgets/BMenuWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_BMENUWIDGET_H 2 | #define GENUS_BMENUWIDGET_H 3 | 4 | #include "BWidget.h" 5 | #include "BFont.h" 6 | 7 | class BMenuWidget : public BWidget { 8 | public: 9 | BMenuWidget(TInt aX, TInt aY, BFont *aFont, TUint8 aForeground, TUint8 aBackground); 10 | ~BMenuWidget(); 11 | public: 12 | // add child widgets for the menu 13 | void AddWidget(BWidget& aWidget) { 14 | mList.AddTail(aWidget); 15 | } 16 | protected: 17 | BWidgetList mList; 18 | }; 19 | 20 | 21 | #endif //GENUS_BMENUWIDGET_H 22 | -------------------------------------------------------------------------------- /src/Widgets/BNumberWidget.cpp: -------------------------------------------------------------------------------- 1 | #include "BNumberWidget.h" 2 | #include "Display/Display.h" 3 | #include "Controls.h" 4 | 5 | BNumberWidget::BNumberWidget(char *aTitle, const TNumberOpts *aOpts, TInt aForeground, TInt aBackground) : BWidget(aTitle), mOpts(aOpts) { 6 | mSelectedValue = TNumber(mOpts->range.start, mOpts->range.precision); 7 | } 8 | 9 | BNumberWidget::BNumberWidget(const char *aTitle, const TNumberOpts *aOpts, TInt aForeground, TInt aBackground) : BWidget(), mOpts(aOpts) { 10 | mSelectedValue = TNumber(mOpts->range.start, mOpts->range.precision); 11 | mTitle = (char *) aTitle; 12 | mHeight = 40; 13 | } 14 | 15 | BNumberWidget::~BNumberWidget() = default; 16 | 17 | TInt BNumberWidget::Render(TInt aX, TInt aY) { 18 | const BFont *font = gWidgetTheme.GetFont(WIDGET_TEXT_FONT); 19 | const TInt fg = gWidgetTheme.GetInt(WIDGET_TEXT_FG), 20 | bg = gWidgetTheme.GetInt(WIDGET_TEXT_BG); 21 | char c[20]; 22 | 23 | // Number to string 24 | mSelectedValue.ToString(c, &mOpts->pad); 25 | 26 | // Draw string 27 | gDisplay.renderBitmap->DrawString(ENull, c, font, aX * 2, aY, bg, fg); 28 | 29 | return font->mHeight; 30 | } 31 | 32 | void BNumberWidget::Run() { 33 | if (!IsActive()) { 34 | return; 35 | } 36 | 37 | // Decrement, check min value 38 | if (gControls.WasPressed(JOYLEFT)) { 39 | mSelectedValue.mVal = MAX(mOpts->range.start, mSelectedValue.mVal - mOpts->range.step); 40 | Select(mSelectedValue.ToInt()); 41 | return; 42 | } 43 | 44 | // Increment, check max value 45 | if (gControls.WasPressed(JOYRIGHT)) { 46 | mSelectedValue.mVal = MIN(mOpts->range.end, mSelectedValue.mVal + mOpts->range.step); 47 | Select(mSelectedValue.ToInt()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Widgets/BNumberWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_BNUMBERWIDGET_H 2 | #define GENUS_BNUMBERWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | struct TNumberOpts { 10 | TRange range; 11 | TPad pad; 12 | }; 13 | 14 | /** 15 | * Widget implementing a number UI. 16 | * Presents a number. 17 | * Allows the user to pick a value between start and end in increments of step. 18 | * Allows the number to be floating point and padded. 19 | */ 20 | 21 | class BNumberWidget : public BWidget { 22 | public: 23 | BNumberWidget(char *aTitle, const TNumberOpts *aOpts, TInt aForeground, TInt aBackground = -1); 24 | 25 | BNumberWidget(const char *aTitle, const TNumberOpts *aOpts, TInt aForeground, TInt aBackground = -1); 26 | 27 | ~BNumberWidget(); 28 | 29 | public: 30 | TInt Render(TInt aX, TInt aY); 31 | 32 | void Run(); 33 | 34 | public: 35 | virtual void Select(TInt aValue) = 0; 36 | 37 | protected: 38 | const TNumberOpts *mOpts; 39 | TNumber mSelectedValue; 40 | }; 41 | 42 | 43 | #endif //GENUS_BNUMBERWIDGET_H 44 | -------------------------------------------------------------------------------- /src/Widgets/BSelectWidget.cpp: -------------------------------------------------------------------------------- 1 | #include "BSelectWidget.h" 2 | #include "Display/Display.h" 3 | #include "Controls.h" 4 | #include 5 | 6 | BSelectWidget::BSelectWidget(char *aTitle, const TSelectOption *aOptions, TInt aForeground, TInt aBackground) 7 | : BWidget(aTitle), mOptions(aOptions) { 8 | mSelectedIndex = 0; 9 | } 10 | 11 | BSelectWidget::BSelectWidget(const char *aTitle, const TSelectOption *aOptions, TInt aForeground, TInt aBackground) 12 | : BWidget(), mOptions(aOptions) { 13 | mSelectedIndex = 0; 14 | mTitle = (char *) aTitle; 15 | mHeight = 40; 16 | } 17 | 18 | BSelectWidget::~BSelectWidget() {} 19 | 20 | TInt BSelectWidget::Render(TInt aX, TInt aY) { 21 | const BFont *font = gWidgetTheme.GetFont(WIDGET_TEXT_FONT); 22 | const TInt fg = gWidgetTheme.GetInt(WIDGET_TEXT_FG), 23 | bg = gWidgetTheme.GetInt(WIDGET_TEXT_BG); 24 | 25 | // TODO: center and add spaces between options, based upon strlen(); pad left/right, too 26 | TInt ndx = 0, x = aX; 27 | while (mOptions[ndx].text) { 28 | if (ndx != mSelectedIndex) { 29 | gDisplay.renderBitmap->DrawString(ENull, 30 | mOptions[ndx].text, 31 | font, 32 | x + aX, aY, 33 | fg, bg); 34 | } else { 35 | gDisplay.renderBitmap->DrawString(ENull, 36 | mOptions[ndx].text, 37 | font, 38 | x + aX, aY, 39 | bg, fg); 40 | } 41 | 42 | x += font->mWidth * strlen(mOptions[ndx].text) + 20; 43 | ndx++; 44 | } 45 | return font->mHeight; 46 | } 47 | 48 | void BSelectWidget::Run() { 49 | if (!IsActive()) { 50 | return; 51 | } 52 | 53 | // Move selection left, circle back if on 1st option 54 | if (gControls.WasPressed(JOYLEFT)) { 55 | if (mSelectedIndex == 0) { 56 | while(mOptions[mSelectedIndex + 1].text) { 57 | mSelectedIndex++; 58 | } 59 | } else { 60 | mSelectedIndex--; 61 | } 62 | Select(mSelectedIndex); 63 | return; 64 | } 65 | 66 | // Move selection right, circle back if on last option 67 | if (gControls.WasPressed(JOYRIGHT)) { 68 | if (mOptions[mSelectedIndex].text != ENull) { 69 | mSelectedIndex++; 70 | if (mOptions[mSelectedIndex].text == ENull) { 71 | mSelectedIndex = 0; 72 | } 73 | } 74 | 75 | Select(mSelectedIndex); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Widgets/BSelectWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_BSELECTWIDGET_H 2 | #define GENUS_BSELECTWIDGET_H 3 | 4 | #include 5 | #include 6 | 7 | /** 8 | * Widget implementing a select UI. Presents a list of options and allows the user to pick one. 9 | */ 10 | 11 | struct TSelectOption { 12 | const char *text; 13 | const TInt value; 14 | }; 15 | 16 | #define TSELECT_END_OPTIONS { ENull, 0 } 17 | 18 | class BSelectWidget : public BWidget { 19 | public: 20 | BSelectWidget(char *aTitle, const TSelectOption *aOptions, TInt aForeground, TInt aBackground = -1); 21 | 22 | BSelectWidget(const char *aTitle, const TSelectOption *aOptions, TInt aForeground, TInt aBackground = -1); 23 | 24 | ~BSelectWidget(); 25 | 26 | public: 27 | TInt Render(TInt aX, TInt aY); 28 | 29 | void Run(); 30 | 31 | public: 32 | virtual void Select(TInt aValue) = 0; 33 | 34 | protected: 35 | const TSelectOption *mOptions; 36 | TInt mSelectedIndex; 37 | }; 38 | 39 | 40 | #endif //GENUS_BSELECTWIDGET_H 41 | -------------------------------------------------------------------------------- /src/Widgets/BSliderWidget.cpp: -------------------------------------------------------------------------------- 1 | #include "BSliderWidget.h" 2 | #include "Display/Display.h" 3 | #include "Controls.h" 4 | 5 | BSliderWidget::BSliderWidget(char *aTitle, const TRange *aRange, TInt aForeground, TInt aBackground) 6 | : BWidget(aTitle), mRange(aRange) { 7 | mSelectedValue = mRange->start; 8 | } 9 | 10 | BSliderWidget::BSliderWidget(const char *aTitle, const TRange *aRange, TInt aForeground, TInt aBackground) 11 | : BWidget(), mRange(aRange) { 12 | mSelectedValue = mRange->start; 13 | mTitle = (char *) aTitle; 14 | mHeight = 40; 15 | } 16 | 17 | BSliderWidget::~BSliderWidget() {} 18 | 19 | TInt BSliderWidget::Render(TInt aX, TInt aY) { 20 | const TUint8 fg = gWidgetTheme.GetInt(WIDGET_TEXT_FG), 21 | maxWidth = (SCREEN_WIDTH - aX * 2); 22 | 23 | gDisplay.renderBitmap->DrawRect(ENull, aX, aY, aX + maxWidth - 1, aY + 4, fg); 24 | 25 | if (mSelectedValue == mRange->end) { 26 | gDisplay.renderBitmap->FillRect(ENull, aX + 2, aY + 2, aX + maxWidth - 3, aY + 2, fg); 27 | } else if (mSelectedValue > mRange->start) { 28 | TUint base = mRange->precision ? mRange->precision : 100; 29 | TInt width = maxWidth * (mSelectedValue / base); 30 | gDisplay.renderBitmap->FillRect(ENull, aX + 2, aY + 2, aX + 2 + width, aY + 2, fg); 31 | } 32 | 33 | return 16; 34 | } 35 | 36 | void BSliderWidget::Run() { 37 | if (!IsActive()) { 38 | return; 39 | } 40 | 41 | // Decrement, check min value and convert to TFloat if needed 42 | if (gControls.WasPressed(JOYLEFT)) { 43 | mSelectedValue = MAX(mRange->start, mSelectedValue - mRange->step); 44 | Select(mSelectedValue); 45 | return; 46 | } 47 | 48 | // Increment, check max value and convert to TFloat if needed 49 | if (gControls.WasPressed(JOYRIGHT)) { 50 | mSelectedValue = MIN(mRange->end, mSelectedValue + mRange->step); 51 | Select(mSelectedValue); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Widgets/BSliderWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_BSLIDERWIDGET_H 2 | #define GENUS_BSLIDERWIDGET_H 3 | 4 | #include 5 | #include 6 | 7 | /** 8 | * Widget implementing a slider UI. 9 | * Presents a range slider. 10 | * Allows the user to pick a value between start and end in increments of step. 11 | */ 12 | 13 | struct TRange { 14 | TInt start; 15 | TInt end; 16 | TInt step; 17 | TInt precision; 18 | 19 | TRange(TInt aStart, TInt aEnd, TInt aStep, TInt aPrecision = 1) { 20 | start = aStart; 21 | end = aEnd; 22 | step = aStep; 23 | precision = aPrecision; 24 | } 25 | }; 26 | 27 | class BSliderWidget : public BWidget { 28 | public: 29 | BSliderWidget(char *aTitle, const TRange *aRange, TInt aForeground, TInt aBackground = -1); 30 | 31 | BSliderWidget(const char *aTitle, const TRange *aRange, TInt aForeground, TInt aBackground = -1); 32 | 33 | ~BSliderWidget(); 34 | 35 | public: 36 | TInt Render(TInt aX, TInt aY); 37 | 38 | void Run(); 39 | 40 | public: 41 | virtual void Select(TInt aValue) = 0; 42 | 43 | protected: 44 | const TRange *mRange; 45 | TFloat mSelectedValue; 46 | }; 47 | 48 | 49 | #endif //GENUS_BSLIDERWIDGET_H 50 | -------------------------------------------------------------------------------- /src/Widgets/BWidget.cpp: -------------------------------------------------------------------------------- 1 | #include "BWidget.h" 2 | #include 3 | 4 | // BWidgetList 5 | 6 | BWidgetList::BWidgetList() { 7 | 8 | } 9 | 10 | BWidgetList::~BWidgetList() { 11 | 12 | } 13 | 14 | // run all the widgets in this list 15 | void BWidgetList::Run() { 16 | for (BWidget *w = (BWidget *) First(); !End(w); w = (BWidget *) Next(w)) { 17 | w->Run(); 18 | } 19 | } 20 | 21 | // BWidget 22 | 23 | BWidget::BWidget(TInt aX, TInt aY, char *aTitle) : BNode() { 24 | mX = aX; 25 | mY = aY; 26 | mActive = EFalse; 27 | mHeight = 16; 28 | mTitle = aTitle; 29 | } 30 | 31 | BWidget::BWidget(char *aTitle) : BNode(), mTitle(aTitle) { 32 | mTitle = aTitle; 33 | mX = mY = 0; 34 | mActive = EFalse; 35 | mHeight = 16; 36 | } 37 | 38 | 39 | BWidget::BWidget() : BNode(), mX(0), mY(0), mTitle(ENull) { 40 | mActive = EFalse; 41 | mHeight = 20; 42 | } 43 | 44 | BWidget::~BWidget() {} 45 | 46 | TInt BWidget::RenderTitle(TInt aX, TInt aY, TBool aActive) { 47 | if (!mTitle) { 48 | return 0; 49 | } 50 | const BFont *f = gWidgetTheme.GetFont(WIDGET_TITLE_FONT); 51 | if (aActive) { 52 | gDisplay.renderBitmap->DrawString(ENull, 53 | mTitle, 54 | f, 55 | aX, aY, 56 | gWidgetTheme.GetInt(WIDGET_TITLE_BG), 57 | gWidgetTheme.GetInt(WIDGET_TITLE_FG)); 58 | 59 | } else { 60 | gDisplay.renderBitmap->DrawString(ENull, 61 | mTitle, 62 | f, 63 | aX, aY, 64 | gWidgetTheme.GetInt(WIDGET_TITLE_FG), 65 | gWidgetTheme.GetInt(WIDGET_TITLE_BG)); 66 | } 67 | return f->mHeight + 4; 68 | } 69 | 70 | TBool BWidget::OnNavigate(TUint16 bits) { 71 | return ETrue; 72 | } 73 | -------------------------------------------------------------------------------- /src/Widgets/BWidgetTheme.cpp: -------------------------------------------------------------------------------- 1 | #include "BWidgetTheme.h" 2 | 3 | #include 4 | #include 5 | 6 | BWidgetTheme gWidgetTheme; 7 | 8 | BWidgetTheme::BWidgetTheme() {} 9 | BWidgetTheme::~BWidgetTheme() {} 10 | 11 | void BWidgetTheme::Configure(TInt aTag, ...) { 12 | TInt tag = aTag; 13 | va_list args; 14 | va_start(args, aTag); 15 | 16 | while (tag != WIDGET_END_TAG) { 17 | switch (tag) { 18 | case WIDGET_TEXT_FONT: 19 | mTextFont = (BFont *)va_arg(args, void *); 20 | break; 21 | case WIDGET_TEXT_FG: 22 | mTextFG = va_arg(args, TInt); 23 | break; 24 | case WIDGET_TEXT_BG: 25 | mTextBG = va_arg(args, TInt); 26 | break; 27 | case WIDGET_TITLE_FONT: 28 | mTitleFont = (BFont *)va_arg(args, void *); 29 | break; 30 | case WIDGET_TITLE_FG: 31 | mTitleFG = va_arg(args, TInt); 32 | break; 33 | case WIDGET_TITLE_BG: 34 | mTitleBG = va_arg(args, TInt); 35 | break; 36 | case WIDGET_WINDOW_FG: 37 | mWindowFG = va_arg(args, TInt); 38 | break; 39 | case WIDGET_WINDOW_BG: 40 | mWindowBG = va_arg(args, TInt); 41 | break; 42 | case WIDGET_SLIDER_FG: 43 | mSliderFG = va_arg(args, TInt); 44 | break; 45 | case WIDGET_SLIDER_BG: 46 | mSliderBG = va_arg(args, TInt); 47 | break; 48 | default: 49 | Panic("Invalid BWidgetTheme configure tag: %d\n", tag); 50 | } 51 | tag = va_arg(args, TInt); 52 | } 53 | } 54 | 55 | TInt BWidgetTheme::GetInt(TInt aTag){ 56 | switch (aTag) { 57 | case WIDGET_TEXT_FG: 58 | return mTextFG; 59 | case WIDGET_TEXT_BG: 60 | return mTextBG; 61 | case WIDGET_TITLE_FG: 62 | return mTitleFG; 63 | case WIDGET_TITLE_BG: 64 | return mTitleBG; 65 | case WIDGET_WINDOW_FG: 66 | return mWindowFG; 67 | case WIDGET_WINDOW_BG: 68 | return mWindowBG; 69 | case WIDGET_SLIDER_FG: 70 | return mSliderFG; 71 | case WIDGET_SLIDER_BG: 72 | return mSliderBG; 73 | default: 74 | Panic("Invalid BWidgetTheme GertInt tag: %d\n", aTag); 75 | } 76 | return 0; 77 | } 78 | 79 | BFont *BWidgetTheme::GetFont(TInt aTag) { 80 | switch (aTag) { 81 | case WIDGET_TEXT_FONT: 82 | return mTextFont; 83 | case WIDGET_TITLE_FONT: 84 | return mTitleFont; 85 | default: 86 | Panic("Invalid BWidgetTheme GertFont tag: %d\n", aTag); 87 | } 88 | return ENull; 89 | } 90 | -------------------------------------------------------------------------------- /src/Widgets/BWidgetTheme.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_BWIDGETTHEME_H 2 | #define GENUS_BWIDGETTHEME_H 3 | 4 | #include "BBase.h" 5 | #include "BFont.h" 6 | 7 | enum { 8 | WIDGET_END_TAG, 9 | WIDGET_TEXT_FONT, 10 | WIDGET_TEXT_FG, 11 | WIDGET_TEXT_BG, 12 | WIDGET_TITLE_FONT, 13 | WIDGET_TITLE_FG, 14 | WIDGET_TITLE_BG, 15 | WIDGET_WINDOW_BG, // color of body of window 16 | WIDGET_WINDOW_FG, // window decoration color 17 | WIDGET_SLIDER_FG, 18 | WIDGET_SLIDER_BG, 19 | }; 20 | 21 | class BWidgetTheme : public BBase { 22 | public: 23 | BWidgetTheme(); 24 | 25 | virtual ~BWidgetTheme(); 26 | 27 | public: 28 | void Configure(TInt aTag, ...); 29 | 30 | TInt GetInt(TInt aTag); 31 | BFont *GetFont(TInt aTag); 32 | 33 | protected: 34 | BFont *mTextFont; 35 | TInt mTextFG, mTextBG; 36 | BFont *mTitleFont; 37 | TInt mTitleFG, mTitleBG; 38 | TInt mWindowFG, mWindowBG; 39 | TInt mSliderFG, mSliderBG; 40 | 41 | }; 42 | 43 | extern BWidgetTheme gWidgetTheme; 44 | 45 | 46 | #endif //GENUS_BWIDGETTHEME_H 47 | -------------------------------------------------------------------------------- /src/Widgets/Widgets.h: -------------------------------------------------------------------------------- 1 | #ifndef GENUS_WIDGETS_H 2 | #define GENUS_WIDGETS_H 3 | 4 | #include "BWidgetTheme.h" 5 | #include "BWidget.h" 6 | #include "BSelectWidget.h" 7 | #include "BMenuWidget.h" 8 | #include "BContainerWidget.h" 9 | #include "BDialogWidget.h" 10 | #include "BSliderWidget.h" 11 | #include "BNumberWidget.h" 12 | #include "BButtonWidget.h" 13 | 14 | #endif //GENUS_WIDGETS_H 15 | -------------------------------------------------------------------------------- /src/libxmp/README: -------------------------------------------------------------------------------- 1 | __ _ __ ___ __ 2 | / / (_) / __ __ __ _ ___ ____/ (_) /____ 3 | / /__/ / _ \\ \ // ' \/ _ \/___/ / / __/ -_) 4 | /____/_/_.__/_\_\/_/_/_/ .__/ /_/_/\__/\__/ 5 | /_/ 6 | 7 | Libxmp-lite is a lean and lightweight subset of Libxmp that plays MOD, S3M, 8 | XM, and IT modules and retains full compatibility with the original API. 9 | It's intended for games and small or embedded applications where module 10 | format diversity and file depacking are not required. 11 | 12 | Library size can be further reduced by disabling Impulse Tracker format 13 | support (configure with --disable-it). This option will also disable IT 14 | effects and lowpass filtering. 15 | 16 | Please refer to http://xmp.sf.net/libxmp.html for details on the current 17 | Libxmp API. 18 | 19 | 20 | LICENSE 21 | 22 | Extended Module Player Lite 23 | Copyright (C) 1996-2016 Claudio Matsuoka and Hipolito Carraro Jr 24 | 25 | Permission is hereby granted, free of charge, to any person obtaining a 26 | copy of this software and associated documentation files (the "Software"), 27 | to deal in the Software without restriction, including without limitation 28 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 29 | and/or sell copies of the Software, and to permit persons to whom the 30 | Software is furnished to do so, subject to the following conditions: 31 | 32 | The above copyright notice and this permission notice shall be included in 33 | all copies or substantial portions of the Software. 34 | 35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 38 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 40 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 41 | THE SOFTWARE. 42 | -------------------------------------------------------------------------------- /src/libxmp/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := . ./loaders/ 2 | COMPONENT_ADD_SRCDIRS := . ./loaders/ -------------------------------------------------------------------------------- /src/libxmp/depacker.h: -------------------------------------------------------------------------------- 1 | #ifndef XMP_DEPACKER_H 2 | #define XMP_DEPACKER_H 3 | 4 | #include 5 | 6 | extern struct depacker libxmp_depacker_zip; 7 | extern struct depacker libxmp_depacker_lha; 8 | extern struct depacker libxmp_depacker_gzip; 9 | extern struct depacker libxmp_depacker_bzip2; 10 | extern struct depacker libxmp_depacker_xz; 11 | extern struct depacker libxmp_depacker_compress; 12 | extern struct depacker libxmp_depacker_pp; 13 | extern struct depacker libxmp_depacker_sqsh; 14 | extern struct depacker libxmp_depacker_arc; 15 | extern struct depacker libxmp_depacker_arcfs; 16 | extern struct depacker libxmp_depacker_mmcmp; 17 | extern struct depacker libxmp_depacker_muse; 18 | extern struct depacker libxmp_depacker_lzx; 19 | extern struct depacker libxmp_depacker_s404; 20 | extern struct depacker libxmp_depacker_xfd; 21 | extern struct depacker libxmp_depacker_oxm; 22 | 23 | struct depacker { 24 | int (*const test)(unsigned char *); 25 | int (*const depack)(FILE *, FILE *); 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/libxmp/fnmatch.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1992, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 4. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _FNMATCH_H_ 31 | #define _FNMATCH_H_ 32 | 33 | #define FNM_NOMATCH 1 /* Match failed. */ 34 | 35 | #define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */ 36 | #define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */ 37 | #define FNM_PERIOD 0x04 /* Period must be matched by period. */ 38 | #define FNM_LEADING_DIR 0x08 /* Ignore / after Imatch. */ 39 | #define FNM_CASEFOLD 0x10 /* Case insensitive search. */ 40 | #define FNM_PREFIX_DIRS 0x20 /* Directory prefixes of pattern match too. */ 41 | 42 | int fnmatch(const char *pattern, const char *string, int flags); 43 | 44 | #endif /* !_FNMATCH_H_ */ 45 | -------------------------------------------------------------------------------- /src/libxmp/format.c: -------------------------------------------------------------------------------- 1 | /* Extended Module Player 2 | * Copyright (C) 1996-2016 Claudio Matsuoka and Hipolito Carraro Jr 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include "format.h" 26 | 27 | extern const struct format_loader libxmp_loader_xm; 28 | extern const struct format_loader libxmp_loader_mod; 29 | extern const struct format_loader libxmp_loader_it; 30 | extern const struct format_loader libxmp_loader_s3m; 31 | 32 | extern const struct pw_format *const pw_format[]; 33 | 34 | const struct format_loader *const format_loader[5] = { 35 | &libxmp_loader_xm, 36 | &libxmp_loader_mod, 37 | 38 | &libxmp_loader_s3m, 39 | NULL 40 | }; 41 | 42 | static const char *_farray[5] = { NULL }; 43 | 44 | char **format_list() 45 | { 46 | int count, i; 47 | 48 | if (_farray[0] == NULL) { 49 | for (count = i = 0; format_loader[i] != NULL; i++) { 50 | _farray[count++] = format_loader[i]->name; 51 | } 52 | 53 | _farray[count] = NULL; 54 | } 55 | 56 | return (char **)_farray; 57 | } 58 | -------------------------------------------------------------------------------- /src/libxmp/format.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBXMP_FORMAT_H 2 | #define LIBXMP_FORMAT_H 3 | 4 | #include 5 | #include "common.h" 6 | #include "hio.h" 7 | 8 | struct format_loader { 9 | const char *name; 10 | int (*const test)(HIO_HANDLE *, char *, const int); 11 | int (*const loader)(struct module_data *, HIO_HANDLE *, const int); 12 | }; 13 | 14 | char **format_list(void); 15 | 16 | #ifndef LIBXMP_CORE_PLAYER 17 | 18 | #define NUM_FORMATS 52 19 | #define NUM_PW_FORMATS 43 20 | 21 | int pw_test_format(HIO_HANDLE *, char *, const int, struct xmp_test_info *); 22 | #endif 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /src/libxmp/hio.h: -------------------------------------------------------------------------------- 1 | #ifndef XMP_HIO_H 2 | #define XMP_HIO_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "memio.h" 8 | 9 | #define HIO_HANDLE_TYPE(x) ((x)->type) 10 | 11 | typedef struct { 12 | #define HIO_HANDLE_TYPE_FILE 0 13 | #define HIO_HANDLE_TYPE_MEMORY 1 14 | int type; 15 | long size; 16 | union { 17 | FILE *file; 18 | MFILE *mem; 19 | } handle; 20 | int error; 21 | } HIO_HANDLE; 22 | 23 | int8 hio_read8s (HIO_HANDLE *); 24 | uint8 hio_read8 (HIO_HANDLE *); 25 | uint16 hio_read16l (HIO_HANDLE *); 26 | uint16 hio_read16b (HIO_HANDLE *); 27 | uint32 hio_read24l (HIO_HANDLE *); 28 | uint32 hio_read24b (HIO_HANDLE *); 29 | uint32 hio_read32l (HIO_HANDLE *); 30 | uint32 hio_read32b (HIO_HANDLE *); 31 | size_t hio_read (void *, size_t, size_t, HIO_HANDLE *); 32 | int hio_seek (HIO_HANDLE *, long, int); 33 | long hio_tell (HIO_HANDLE *); 34 | int hio_eof (HIO_HANDLE *); 35 | int hio_error (HIO_HANDLE *); 36 | HIO_HANDLE *hio_open (const void *, const char *); 37 | HIO_HANDLE *hio_open_mem (const void *, long); 38 | HIO_HANDLE *hio_open_file (FILE *); 39 | int hio_close (HIO_HANDLE *); 40 | long hio_size (HIO_HANDLE *); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/libxmp/lfo.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBXMP_LFO_H 2 | #define LIBXMP_LFO_H 3 | 4 | #include "common.h" 5 | 6 | struct lfo { 7 | int type; 8 | int rate; 9 | int depth; 10 | int phase; 11 | }; 12 | 13 | int libxmp_lfo_get(struct context_data *, struct lfo *, int); 14 | void libxmp_lfo_update(struct lfo *); 15 | void libxmp_lfo_set_phase(struct lfo *, int); 16 | void libxmp_lfo_set_depth(struct lfo *, int); 17 | void libxmp_lfo_set_rate(struct lfo *, int); 18 | void libxmp_lfo_set_waveform(struct lfo *, int); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/libxmp/loaders/asif.h: -------------------------------------------------------------------------------- 1 | #ifndef XMP_ASIF_H 2 | #define XMP_ASIF_H 3 | 4 | #include 5 | #include "common.h" 6 | #include "hio.h" 7 | 8 | int asif_load(struct module_data *, HIO_HANDLE *, int); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/libxmp/loaders/component.mk: -------------------------------------------------------------------------------- 1 | #Empty component.mk file used for the ESP32-IDF 2 | COMPONENT_ADD_SRCDIRS := . 3 | COMPONENT_ADD_INCLUDEDIRS := . -------------------------------------------------------------------------------- /src/libxmp/loaders/iff.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBXMP_IFF_H 2 | #define LIBXMP_IFF_H 3 | 4 | #include "list.h" 5 | #include "hio.h" 6 | 7 | #define IFF_NOBUFFER 0x0001 8 | 9 | #define IFF_LITTLE_ENDIAN 0x01 10 | #define IFF_FULL_CHUNK_SIZE 0x02 11 | #define IFF_CHUNK_ALIGN2 0x04 12 | #define IFF_CHUNK_ALIGN4 0x08 13 | #define IFF_SKIP_EMBEDDED 0x10 14 | #define IFF_CHUNK_TRUNC4 0x20 15 | 16 | #define IFF_MAX_CHUNK_SIZE 0x400000 17 | 18 | typedef void *iff_handle; 19 | 20 | struct iff_header { 21 | char form[4]; /* FORM */ 22 | int len; /* File length */ 23 | char id[4]; /* IFF type identifier */ 24 | }; 25 | 26 | struct iff_info { 27 | char id[4]; 28 | int (*loader)(struct module_data *, int, HIO_HANDLE *, void *); 29 | struct list_head list; 30 | }; 31 | 32 | iff_handle libxmp_iff_new(void); 33 | int libxmp_iff_load(iff_handle, struct module_data *, HIO_HANDLE *, void *); 34 | /* int libxmp_iff_chunk(iff_handle, struct module_data *, HIO_HANDLE *, void *); */ 35 | int libxmp_iff_register(iff_handle, const char *, 36 | int (*loader)(struct module_data *, int, HIO_HANDLE *, void *)); 37 | void libxmp_iff_id_size(iff_handle, int); 38 | void libxmp_iff_set_quirk(iff_handle, int); 39 | void libxmp_iff_release(iff_handle); 40 | /* int libxmp_iff_process(iff_handle, struct module_data *, char *, long, 41 | HIO_HANDLE *, void *); */ 42 | 43 | #endif /* LIBXMP_IFF_H */ 44 | -------------------------------------------------------------------------------- /src/libxmp/loaders/mod.h: -------------------------------------------------------------------------------- 1 | /* Extended Module Player 2 | * Copyright (C) 1996-2016 Claudio Matsuoka and Hipolito Carraro Jr 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | struct mod_instrument { 24 | uint8 name[22]; /* Instrument name */ 25 | uint16 size; /* Sample length in 16-bit words */ 26 | int8 finetune; /* Finetune (signed nibble) */ 27 | int8 volume; /* Linear playback volume */ 28 | uint16 loop_start; /* Loop start in 16-bit words */ 29 | uint16 loop_size; /* Loop length in 16-bit words */ 30 | }; 31 | 32 | struct mod_header { 33 | uint8 name[20]; 34 | struct mod_instrument ins[31]; 35 | uint8 len; 36 | uint8 restart; /* Number of patterns in Soundtracker, 37 | * Restart in Noisetracker/Startrekker, 38 | * 0x7F in Protracker 39 | */ 40 | uint8 order[128]; 41 | uint8 magic[4]; 42 | }; 43 | 44 | 45 | #ifndef LIBXMP_CORE_PLAYER 46 | /* Soundtracker 15-instrument module header */ 47 | 48 | struct st_header { 49 | uint8 name[20]; 50 | struct mod_instrument ins[15]; 51 | uint8 len; 52 | uint8 restart; 53 | uint8 order[128]; 54 | }; 55 | #endif 56 | -------------------------------------------------------------------------------- /src/libxmp/md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This code implements the MD5 message-digest algorithm. 3 | * The algorithm is due to Ron Rivest. This code was 4 | * written by Colin Plumb in 1993, no copyright is claimed. 5 | * This code is in the public domain; do with it what you wish. 6 | * 7 | * Equivalent code is available from RSA Data Security, Inc. 8 | * This code has been tested against that, and is equivalent, 9 | * except that you don't need to include two pages of legalese 10 | * with every copy. 11 | */ 12 | 13 | #ifndef LIBXMP_MD5_H 14 | #define LIBXMP_MD5_H 15 | 16 | #include "common.h" 17 | 18 | #define MD5_BLOCK_LENGTH 64 19 | #define MD5_DIGEST_LENGTH 16 20 | #define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1) 21 | 22 | typedef struct MD5Context { 23 | uint32 state[4]; /* state */ 24 | uint64 count; /* number of bits, mod 2^64 */ 25 | uint8 buffer[MD5_BLOCK_LENGTH]; /* input buffer */ 26 | } MD5_CTX; 27 | 28 | void MD5Init(MD5_CTX *); 29 | void MD5Update(MD5_CTX *, const unsigned char *, size_t); 30 | void MD5Final(uint8[MD5_DIGEST_LENGTH], MD5_CTX *); 31 | 32 | #endif /* LIBXMP_MD5_H */ 33 | 34 | -------------------------------------------------------------------------------- /src/libxmp/mdataio.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBXMP_MDATAIO_H 2 | #define LIBXMP_MDATAIO_H 3 | 4 | #include 5 | #include "common.h" 6 | 7 | static inline ptrdiff_t CAN_READ(MFILE *m) 8 | { 9 | if (m->size >= 0) 10 | return m->pos >= 0 ? m->size - m->pos : 0; 11 | 12 | return INT_MAX; 13 | } 14 | 15 | static inline uint8 mread8(MFILE *m) 16 | { 17 | uint8 x = 0xff; 18 | mread(&x, 1, 1, m); 19 | return x; 20 | } 21 | 22 | static inline int8 mread8s(MFILE *m) 23 | { 24 | return (int8)mgetc(m); 25 | } 26 | 27 | static inline uint16 mread16l(MFILE *m) 28 | { 29 | ptrdiff_t can_read = CAN_READ(m); 30 | if (can_read >= 2) { 31 | uint16 n = readmem16l(m->start + m->pos); 32 | m->pos += 2; 33 | return n; 34 | } else { 35 | m->pos += can_read; 36 | return EOF; 37 | } 38 | } 39 | 40 | static inline uint16 mread16b(MFILE *m) 41 | { 42 | ptrdiff_t can_read = CAN_READ(m); 43 | if (can_read >= 2) { 44 | uint16 n = readmem16b(m->start + m->pos); 45 | m->pos += 2; 46 | return n; 47 | } else { 48 | m->pos += can_read; 49 | return EOF; 50 | } 51 | } 52 | 53 | static inline uint32 mread24l(MFILE *m) 54 | { 55 | ptrdiff_t can_read = CAN_READ(m); 56 | if (can_read >= 3) { 57 | uint32 n = readmem24l(m->start + m->pos); 58 | m->pos += 3; 59 | return n; 60 | } else { 61 | m->pos += can_read; 62 | return EOF; 63 | } 64 | } 65 | 66 | static inline uint32 mread24b(MFILE *m) 67 | { 68 | ptrdiff_t can_read = CAN_READ(m); 69 | if (can_read >= 3) { 70 | uint32 n = readmem24b(m->start + m->pos); 71 | m->pos += 3; 72 | return n; 73 | } else { 74 | m->pos += can_read; 75 | return EOF; 76 | } 77 | } 78 | 79 | static inline uint32 mread32l(MFILE *m) 80 | { 81 | ptrdiff_t can_read = CAN_READ(m); 82 | if (can_read >= 4) { 83 | uint32 n = readmem32l(m->start + m->pos); 84 | m->pos += 4; 85 | return n; 86 | } else { 87 | m->pos += can_read; 88 | return EOF; 89 | } 90 | } 91 | 92 | static inline uint32 mread32b(MFILE *m) 93 | { 94 | ptrdiff_t can_read = CAN_READ(m); 95 | if (can_read >= 4) { 96 | uint32 n = readmem32b(m->start + m->pos); 97 | m->pos += 4; 98 | return n; 99 | } else { 100 | m->pos += can_read; 101 | return EOF; 102 | } 103 | } 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /src/libxmp/memio.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBXMP_MEMIO_H 2 | #define LIBXMP_MEMIO_H 3 | 4 | #include 5 | 6 | typedef struct { 7 | const unsigned char *start; 8 | ptrdiff_t pos; 9 | ptrdiff_t size; 10 | } MFILE; 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | MFILE *mopen(const void *, long); 17 | int mgetc(MFILE *stream); 18 | size_t mread(void *, size_t, size_t, MFILE *); 19 | int mseek(MFILE *, long, int); 20 | long mtell(MFILE *); 21 | int mclose(MFILE *); 22 | int meof(MFILE *); 23 | #ifndef LIBXMP_CORE_PLAYER 24 | int mstat(MFILE *, struct stat *); 25 | #endif 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/libxmp/mkstemp.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/src/libxmp/mkstemp.c -------------------------------------------------------------------------------- /src/libxmp/paula.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBXMP_PAULA_H 2 | #define LIBXMP_PAULA_H 3 | 4 | /* 131072 to 0, 2048 entries */ 5 | #define PAULA_HZ 3546895 6 | #define MINIMUM_INTERVAL 16 7 | #define BLEP_SCALE 17 8 | #define BLEP_SIZE 2048 9 | #define MAX_BLEPS (BLEP_SIZE / MINIMUM_INTERVAL) 10 | 11 | /* the structure that holds data of bleps */ 12 | struct blep_state { 13 | int16 level; 14 | int16 age; 15 | }; 16 | 17 | struct paula_state { 18 | /* the instantenous value of Paula output */ 19 | int16 global_output_level; 20 | 21 | /* count of simultaneous bleps to keep track of */ 22 | unsigned int active_bleps; 23 | 24 | /* place to keep our bleps in. MAX_BLEPS should be 25 | * defined as a BLEP_SIZE / MINIMUM_EVENT_INTERVAL. 26 | * For Paula, minimum event interval could be even 1, but it makes 27 | * sense to limit it to some higher value such as 16. */ 28 | struct blep_state blepstate[MAX_BLEPS]; 29 | 30 | double remainder; 31 | double fdiv; 32 | }; 33 | 34 | 35 | void libxmp_paula_init (struct context_data *, struct paula_state *); 36 | 37 | #endif /* !LIBXMP_PAULA_H */ 38 | -------------------------------------------------------------------------------- /src/libxmp/period.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBXMP_PERIOD_H 2 | #define LIBXMP_PERIOD_H 3 | 4 | #define PERIOD_BASE 13696.0 /* C0 period */ 5 | 6 | /* Macros for period conversion */ 7 | #define NOTE_B0 11 8 | #define NOTE_Bb0 (NOTE_B0 + 1) 9 | #define MAX_NOTE (NOTE_B0 * 8) 10 | #define MAX_PERIOD 0x1c56 11 | #define MIN_PERIOD_A 0x0071 12 | #define MAX_PERIOD_A 0x0358 13 | #define MIN_PERIOD_L 0x0000 14 | #define MAX_PERIOD_L 0x1e00 15 | #define MIN_NOTE_MOD 48 16 | #define MAX_NOTE_MOD 83 17 | 18 | double libxmp_note_to_period (struct context_data *, int, int, double); 19 | double libxmp_note_to_period_mix (int, int); 20 | int libxmp_period_to_note (int); 21 | int libxmp_period_to_bend (struct context_data *, double, int, double); 22 | void libxmp_c2spd_to_note (int, int *, int *); 23 | 24 | #endif /* LIBXMP_PERIOD_H */ 25 | -------------------------------------------------------------------------------- /src/libxmp/tempfile.h: -------------------------------------------------------------------------------- 1 | #ifndef XMP_PLATFORM_H 2 | #define XMP_PLATFORM_H 3 | 4 | FILE *make_temp_file(char **); 5 | void unlink_temp_file(char *); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /src/libxmp/virtual.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBXMP_VIRTUAL_H 2 | #define LIBXMP_VIRTUAL_H 3 | 4 | #include "common.h" 5 | 6 | #define VIRT_ACTION_CUT XMP_INST_NNA_CUT 7 | #define VIRT_ACTION_CONT XMP_INST_NNA_CONT 8 | #define VIRT_ACTION_OFF XMP_INST_NNA_OFF 9 | #define VIRT_ACTION_FADE XMP_INST_NNA_FADE 10 | 11 | #define VIRT_ACTIVE 0x100 12 | #define VIRT_INVALID -1 13 | 14 | int libxmp_virt_on (struct context_data *, int); 15 | void libxmp_virt_off (struct context_data *); 16 | int libxmp_virt_mute (struct context_data *, int, int); 17 | int libxmp_virt_setpatch (struct context_data *, int, int, int, int, 18 | int, int, int); 19 | int libxmp_virt_cvt8bit (void); 20 | void libxmp_virt_setnote (struct context_data *, int, int); 21 | void libxmp_virt_setsmp (struct context_data *, int, int); 22 | void libxmp_virt_setnna (struct context_data *, int, int); 23 | void libxmp_virt_pastnote (struct context_data *, int, int); 24 | void libxmp_virt_setvol (struct context_data *, int, int); 25 | void libxmp_virt_voicepos (struct context_data *, int, double); 26 | double libxmp_virt_getvoicepos (struct context_data *, int); 27 | void libxmp_virt_setperiod (struct context_data *, int, double); 28 | void libxmp_virt_setpan (struct context_data *, int, int); 29 | void libxmp_virt_seteffect (struct context_data *, int, int, int); 30 | int libxmp_virt_cstat (struct context_data *, int); 31 | int libxmp_virt_mapchannel (struct context_data *, int); 32 | void libxmp_virt_resetchannel(struct context_data *, int); 33 | void libxmp_virt_resetvoice (struct context_data *, int, int); 34 | void libxmp_virt_reset (struct context_data *); 35 | void libxmp_virt_release (struct context_data *, int, int); 36 | int libxmp_virt_getroot (struct context_data *, int); 37 | 38 | #endif /* LIBXMP_VIRTUAL_H */ 39 | -------------------------------------------------------------------------------- /test/src/GResources.h: -------------------------------------------------------------------------------- 1 | #ifndef CREATIVE_ENGINE_GRESOURCES_H 2 | #define CREATIVE_ENGINE_GRESOURCES_H 3 | 4 | #include "Resources.h" 5 | 6 | enum { 7 | SPLASH_SLOT, 8 | }; 9 | 10 | #endif //CREATIVE_ENGINE_GRESOURCES_H 11 | -------------------------------------------------------------------------------- /test/src/Resources.r: -------------------------------------------------------------------------------- 1 | # 2 | ### FONTS 3 | # 4 | PATH resources/charset 5 | BITMAP charset_8x8.bmp 6 | BITMAP charset_16x16.bmp 7 | 8 | # 9 | ### SPLASH, TITLE, ETC. 10 | # 11 | PATH resources/ 12 | BITMAP splash.bmp 13 | BITMAP splash_sprites.bmp 14 | BITMAP title.bmp 15 | 16 | # 17 | ### MID BOSSES 18 | # 19 | PATH resources/sprites/mid_boss 20 | SPRITESHEET 64x64 mid_boss_death_explosion.bmp 21 | SPRITESHEET 128x128 mid_boss_earth_brown.bmp 22 | SPRITESHEET 32x32 mid_boss_earth_projectile.bmp 23 | SPRITESHEET 128x128 mid_boss_energy.bmp 24 | SPRITESHEET 32x32 mid_boss_energy_projectile.bmp 25 | SPRITESHEET 128x128 mid_boss_fire.bmp 26 | SPRITESHEET 32x32 mid_boss_fire_projectile.bmp 27 | SPRITESHEET 128x128 mid_boss_water.bmp 28 | SPRITESHEET 32x32 mid_boss_water_projectile.bmp 29 | 30 | # 31 | ### TILEMAPS 32 | # 33 | # PATH resources/tilemaps/DevDungeon_0 34 | # TILEMAP DevDungeon_0.filelist.txt 35 | PATH resources/tilemaps/256 36 | TMX overworld.txt 37 | 38 | ########### SOUND :: MUSIC ########### 39 | PATH resources/music/ 40 | RAW EmptySong.xm 41 | 42 | ########### SOUND :: SFX ########### 43 | PATH resources/sound_effects/ 44 | RAW SFX_rotate_block_right.wav 45 | -------------------------------------------------------------------------------- /test/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | #include 3 | #include 4 | #include "./GResources.h" 5 | 6 | test_t tests[] = { 7 | {TestLists, "Test Lists"}, 8 | {TestSprites, "Test Sprites"}, 9 | {0, 0} 10 | }; 11 | 12 | int main() { 13 | // preload a bitmap into a slot for test purposes 14 | gResourceManager.LoadBitmap(SPLASH_SPRITES_BMP, SPLASH_SLOT, IMAGE_16x16); 15 | test_t *tst = tests; 16 | int cnt = 0; 17 | while (tst->func && tst->label) { 18 | cnt++; 19 | printf("%s\n", tst->label); 20 | if ((*tst->func)()) { 21 | printf(" == %s - PASSED\n", tst->label); 22 | } else { 23 | printf(" == %s - FAILED\n", tst->label); 24 | return 1; 25 | } 26 | tst++; 27 | } 28 | 29 | printf("\nALL TESTS PASSED"); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /test/src/resources/charset/charset_16x16.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/charset/charset_16x16.bmp -------------------------------------------------------------------------------- /test/src/resources/charset/charset_8x8.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/charset/charset_8x8.bmp -------------------------------------------------------------------------------- /test/src/resources/music/EmptySong.xm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/music/EmptySong.xm -------------------------------------------------------------------------------- /test/src/resources/sound_effects/SFX_rotate_block_right.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/sound_effects/SFX_rotate_block_right.wav -------------------------------------------------------------------------------- /test/src/resources/splash.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/splash.bmp -------------------------------------------------------------------------------- /test/src/resources/splash_sprites.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/splash_sprites.bmp -------------------------------------------------------------------------------- /test/src/resources/sprites/mid_boss/mid_boss_death_explosion.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/sprites/mid_boss/mid_boss_death_explosion.bmp -------------------------------------------------------------------------------- /test/src/resources/sprites/mid_boss/mid_boss_earth_brown.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/sprites/mid_boss/mid_boss_earth_brown.bmp -------------------------------------------------------------------------------- /test/src/resources/sprites/mid_boss/mid_boss_earth_projectile.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/sprites/mid_boss/mid_boss_earth_projectile.bmp -------------------------------------------------------------------------------- /test/src/resources/sprites/mid_boss/mid_boss_energy.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/sprites/mid_boss/mid_boss_energy.bmp -------------------------------------------------------------------------------- /test/src/resources/sprites/mid_boss/mid_boss_energy_projectile.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/sprites/mid_boss/mid_boss_energy_projectile.bmp -------------------------------------------------------------------------------- /test/src/resources/sprites/mid_boss/mid_boss_fire.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/sprites/mid_boss/mid_boss_fire.bmp -------------------------------------------------------------------------------- /test/src/resources/sprites/mid_boss/mid_boss_fire_projectile.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/sprites/mid_boss/mid_boss_fire_projectile.bmp -------------------------------------------------------------------------------- /test/src/resources/sprites/mid_boss/mid_boss_water.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/sprites/mid_boss/mid_boss_water.bmp -------------------------------------------------------------------------------- /test/src/resources/sprites/mid_boss/mid_boss_water_projectile.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/sprites/mid_boss/mid_boss_water_projectile.bmp -------------------------------------------------------------------------------- /test/src/resources/sprites/mid_boss/unused/mid_boss_earth_green.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/sprites/mid_boss/unused/mid_boss_earth_green.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/MAP_LAYER.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/MAP_LAYER.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA1_dungeon.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA1_dungeon.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA1_outside.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA1_outside.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA1_town.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA1_town.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA2_dungeons.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA2_dungeons.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA2_outside.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA2_outside.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA5_desert.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA5_desert.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA5_dungeon1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA5_dungeon1.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA5_dungeon2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA5_dungeon2.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA5_outside.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA5_outside.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA5_outside2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileA5_outside2.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileB_desert.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileB_desert.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileB_dungeon.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileB_dungeon.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileB_outside.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileB_outside.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileD_castle.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/RMVX/tileD_castle.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/castle.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/castle.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/desert.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/desert.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/dungeon.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/dungeon.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/guide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/guide.png -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/house.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/house.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/inside.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/inside.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/outside.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/outside.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/terrain.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/terrain.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/water.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/_process/water.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/ashlands/ashlands.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/ashlands/ashlands.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/atlantis/atlantis.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/atlantis/atlantis.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/beach/beach.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/beach/beach.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/cloud/cloud_tileset.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/cloud/cloud_tileset.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/darkdimension/tf_darkdimension_sheet.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/darkdimension/tf_darkdimension_sheet.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/jungle/tf_jungle_tileset.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/jungle/tf_jungle_tileset.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/ruin-dungeons/tf_ruindungeons_sheet_full.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/ruin-dungeons/tf_ruindungeons_sheet_full.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/town/beach.tsx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/town/south_beach.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/town/south_beach.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/town/town.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/town/town.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/town/town_MAP_LAYER.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/town/town_MAP_LAYER.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/town/town_MAP_LAYER.tsx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/winter/tf_winter_terrain.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/winter/tf_winter_terrain.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/winter/tf_winter_tileB.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/winter/tf_winter_tileB.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/winter/tf_winter_tileC.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/winter/tf_winter_tileC.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/winter/tf_winter_tileD.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/winter/tf_winter_tileD.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/mutli-screen-map-wip/winter/tf_winter_water.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/mutli-screen-map-wip/winter/tf_winter_water.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/overworld.txt: -------------------------------------------------------------------------------- 1 | ./overworld.tmx -------------------------------------------------------------------------------- /test/src/resources/tilemaps/256/puzzle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/256/puzzle.png -------------------------------------------------------------------------------- /test/src/resources/tilemaps/tilesets/MAP_LAYER.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/tilesets/MAP_LAYER.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/tilesets/OBJECT_ATTRIBUTES_LAYER.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/tilesets/OBJECT_ATTRIBUTES_LAYER.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/tilesets/OBJECT_LAYER.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/tilesets/OBJECT_LAYER.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/tilesets/OBJECT_LAYER.orig.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/tilesets/OBJECT_LAYER.orig.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/tilesets/dungeon_tileset_objects.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/tilesets/dungeon_tileset_objects.bmp -------------------------------------------------------------------------------- /test/src/resources/tilemaps/tilesets/shared palette.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/tilemaps/tilesets/shared palette.pal -------------------------------------------------------------------------------- /test/src/resources/title.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/test/src/resources/title.bmp -------------------------------------------------------------------------------- /test/src/test.h: -------------------------------------------------------------------------------- 1 | #ifndef TEST_H 2 | #define TEST_H 3 | 4 | #include 5 | 6 | typedef TBool (*test_func_t)(); 7 | 8 | typedef struct{ 9 | test_func_t func; 10 | const char* label; 11 | } test_t; 12 | 13 | extern TBool TestLists(); 14 | extern TBool TestSprites(); 15 | 16 | #endif -------------------------------------------------------------------------------- /test/src/tests/Lists.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "../test.h" 3 | 4 | #include 5 | 6 | static TBool is_ascending(BListPri &list) { 7 | if (list.End(list.First())) { 8 | printf("The list is empty!\n"); 9 | return EFalse; 10 | } 11 | 12 | TInt v = list.First()->pri; 13 | for (auto *s = list.First(); !list.End(s); s = list.Next(s)) { 14 | if (s->pri >= v) { 15 | v = s->pri; 16 | } 17 | else { 18 | return EFalse; 19 | } 20 | } 21 | return ETrue; 22 | } 23 | 24 | // BListPri ascending order 25 | static TBool test_001() { 26 | printf(" Add ascending should create list sorted ascending\n"); 27 | 28 | BListPri list; 29 | BNodePri node1(1), node2(2), node3(3), node4(4), node5(5); 30 | 31 | list.Add(node1); 32 | list.Add(node5); 33 | list.Add(node2); 34 | list.Add(node4); 35 | list.Add(node3); 36 | 37 | 38 | if (list.End(list.First())) { 39 | printf("The list is empty!\n"); 40 | return EFalse; 41 | } 42 | 43 | if (!is_ascending(list)) { 44 | printf("Failed, list is not ascending\n"); 45 | list.Dump(); 46 | } 47 | 48 | list.Reset(); 49 | return ETrue; 50 | } 51 | 52 | TBool TestLists() { 53 | return test_001(); 54 | } 55 | -------------------------------------------------------------------------------- /test/test.cmake: -------------------------------------------------------------------------------- 1 | ADD_COMPILE_DEFINITIONS(CE_SDL2_WINDOW_TITLE="CE Tests") 2 | 3 | ADD_COMPILE_DEFINITIONS(__MODUS_TARGET_SDL2_AUDIO__=true) 4 | ADD_COMPILE_DEFINITIONS(__MODUS_TARGET_DESKTOP_CONTROLS__=true) 5 | ADD_COMPILE_DEFINITIONS(__MODUS_TARGET_DESKTOP_DISPLAY__=true) 6 | ADD_COMPILE_DEFINITIONS(LIBXMP_CORE_PLAYER=true) 7 | 8 | FILE(GLOB_RECURSE TESTS "${CREATIVE_ENGINE_PATH}/test/src/tests/*.cpp") 9 | 10 | # resource compiler 11 | SET(RCOMP "${CREATIVE_ENGINE_PATH}/tools/rcomp") 12 | 13 | # build Resources.bin 14 | ADD_CUSTOM_COMMAND( 15 | OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/test/src/Resources.bin 16 | # COMMAND find ${CMAKE_CURRENT_SOURCE_DIR}/test/src -name "Resources.bin" -exec rm -f {} + 17 | # COMMAND find ${CMAKE_CURRENT_SOURCE}/test/src -name "BResourceManager.cpp.o" -exec rm -f {} + 18 | COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/test/src && ls && ${RCOMP} Resources.r 19 | DEPENDS rcomp 20 | COMMENT "Compiling Resources ${CMAKE_CURRENT_SOURCE_DIR}/test/src" 21 | ) 22 | 23 | ADD_EXECUTABLE( 24 | test 25 | # Resources.bin 26 | ${CREATIVE_ENGINE_PATH}/test/src/main.cpp 27 | ${CREATIVE_ENGINE_PATH}/test/src/test.h 28 | ${TESTS} 29 | ${CREATIVE_ENGINE_SOURCE_FILES} 30 | ${CMAKE_CURRENT_SOURCE_DIR}/test/src/Resources.bin 31 | ${CREATIVE_ENGINE_PATH}/test/src/GResources.h 32 | ) 33 | 34 | TARGET_INCLUDE_DIRECTORIES(test PUBLIC 35 | ${CREATIVE_ENGINE_INCLUDE_DIRS} 36 | ${SDL2_INCLUDE_DIRS} 37 | ${CREATIVE_ENGINE_PATH}/test/src 38 | ) 39 | 40 | TARGET_LINK_LIBRARIES(test ${SDL2_LIBRARIES}) -------------------------------------------------------------------------------- /tools/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/tools/README.md -------------------------------------------------------------------------------- /tools/output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/tools/output.png -------------------------------------------------------------------------------- /tools/p1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/tools/p1.bmp -------------------------------------------------------------------------------- /tools/playernew.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/tools/playernew.bmp -------------------------------------------------------------------------------- /tools/rcomp-src/BMPFile.h: -------------------------------------------------------------------------------- 1 | #ifndef MODITE_BMPFILE_H 2 | #define MODITE_BMPFILE_H 3 | 4 | #include "lib/RawBitmap.h" 5 | #include "rcomp.h" 6 | 7 | class BMPHEADER; 8 | class ResourceFile; 9 | 10 | class BMPFile : public RawBitmap { 11 | private: 12 | TUint8 *rawFile; 13 | BMPHEADER *bmp; 14 | 15 | public: 16 | BMPFile(const char *filename); 17 | ~BMPFile(); 18 | 19 | public: 20 | void Write(ResourceFile &resourceFile); 21 | TUint8 ReadPixel(TInt x, TInt y); 22 | }; 23 | 24 | #endif //MODITE_BMPFILE_H 25 | -------------------------------------------------------------------------------- /tools/rcomp-src/Makefile: -------------------------------------------------------------------------------- 1 | OBJ= ResourceFile.o SpriteSheet.o RawFile.o BMPFile.o TileMap.o TMXFile.o rcomp.o 2 | 3 | TMX= tmx/TMXMap.o tmx/TMXTileSet.o tmx/TMXLayer.o 4 | 5 | LIB= lib/BSymbolTable.o lib/utils.o lib/RawBitmap.o 6 | 7 | CE= ../../src/Panic.o ../../src/BBase.o ../../src/BBitmap.o ../../src/Memory.o ../../src/BList.o 8 | 9 | .cpp.o: 10 | g++ -c -O3 -I. -I ../../src -I../../src/Display -o $*.o $*.cpp 11 | 12 | all: rcomp 13 | 14 | rcomp: $(LIB) $(OBJ) $(TMX) $(CE) 15 | g++ -o rcomp $(OBJ) $(LIB) $(TMX) $(CE) 16 | cp rcomp .. 17 | 18 | clean: 19 | @rm -f *.o rcomp 20 | -------------------------------------------------------------------------------- /tools/rcomp-src/RawFile.cpp: -------------------------------------------------------------------------------- 1 | #include "RawFile.h" 2 | #include 3 | 4 | RawFile::RawFile(const char *aFilename) { 5 | filename = strdup(aFilename); 6 | alive = EFalse; 7 | int fd = open(filename, O_RDONLY | O_BINARY); 8 | if (fd < 1) { 9 | return; 10 | } 11 | this->size = (TUint32) lseek(fd, 0, 2); 12 | lseek(fd, 0, 0); 13 | this->data = new TUint8[size]; 14 | read(fd, this->data, size); 15 | close(fd); 16 | alive = ETrue; 17 | Rewind(); 18 | } 19 | 20 | RawFile::~RawFile() { 21 | this->input = ENull; 22 | delete[] this->data; 23 | alive = EFalse; 24 | } 25 | 26 | TUint32 RawFile::OutputSize() { 27 | return sizeof(size) + size; 28 | } 29 | 30 | char *RawFile::ReadLine(char *line) { 31 | if (!alive || input == ENull) { 32 | return ENull; 33 | } 34 | 35 | auto *dst = (TUint8 *) line; 36 | while (input - data < size) { 37 | if (*input == '\r') { 38 | input++; 39 | continue; 40 | } 41 | if (*input == '\n') { 42 | input++; 43 | *dst = '\0'; 44 | break; 45 | } 46 | *dst++ = *input++; 47 | } 48 | *dst = '\0'; 49 | if (input - data >= size) { 50 | input = ENull; 51 | } 52 | // printf("`%s`\n", line); 53 | return line; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /tools/rcomp-src/RawFile.h: -------------------------------------------------------------------------------- 1 | /** 2 | * RawFile 3 | * 4 | * Reads a file into memory. 5 | * Can access size, filename, data, etc., once instantiated. 6 | */ 7 | #ifndef MODITE_RAWFILE_H 8 | #define MODITE_RAWFILE_H 9 | 10 | #include "rcomp.h" 11 | 12 | 13 | class RawFile { 14 | public: 15 | RawFile(const char *aFilename); 16 | virtual ~RawFile(); 17 | public: 18 | TUint32 OutputSize(); 19 | char *ReadLine(char *line); 20 | void Rewind() { input = data;} 21 | public: 22 | TBool alive; 23 | char *filename; 24 | TUint32 size; 25 | TUint8 *data; 26 | TUint8 *input; // next byte of data for reading 27 | }; 28 | 29 | 30 | #endif //MODITE_RAWFILE_H 31 | -------------------------------------------------------------------------------- /tools/rcomp-src/ResourceFile.cpp: -------------------------------------------------------------------------------- 1 | #include "ResourceFile.h" 2 | #include 3 | 4 | ResourceFile resourceFile; 5 | 6 | ResourceFile::ResourceFile() { 7 | defines = fopen("Resources.h", "w"); 8 | if (!defines) { 9 | printf("Can't open output file resourceFile.h (%d)\n", errno); 10 | exit(1); 11 | } 12 | 13 | bin = fopen("Resources.bin", "w"); 14 | if (!bin) { 15 | printf("Can't open binary file resourceFile.bin (%d)\n", errno); 16 | exit(1); 17 | } 18 | 19 | strcpy(path, ""); 20 | 21 | resource_number = 0; // resource_number into offset table at beginning of compiled data 22 | offset = 0; 23 | output = (uint8_t *) malloc(4096); 24 | output_size = 4096; 25 | } 26 | 27 | TUint16 ResourceFile::StartResource(char *define_name) { 28 | char def[2048]; 29 | TUint16 ret = resource_number; 30 | symbol_name(def, define_name); 31 | if (symbols.LookupSymbol(def)) { 32 | Panic("*** Trying to add duplicate resource (%s)\n", def); 33 | } 34 | symbols.AddSymbol(define_name, ret); 35 | fprintf(defines, "#define %-64.64s %d\n", def, resource_number); 36 | offsets[resource_number++] = offset; 37 | return ret; 38 | } 39 | 40 | void ResourceFile::Write(void *data, long size) { 41 | uint32_t next_offset = offset + size; 42 | if (next_offset > output_size) { 43 | output_size = next_offset; 44 | output = (uint8_t *) realloc(output, output_size); 45 | } 46 | memcpy(&output[offset], data, size); 47 | offset += size; 48 | } 49 | 50 | void ResourceFile::Finish() { 51 | fwrite(&resource_number, sizeof(resource_number), 1, bin); 52 | fwrite(offsets, resource_number, sizeof(offsets[0]), bin); 53 | fwrite(output, offset, 1, bin); 54 | fprintf(defines, "\n#define %-64.64s %d\n", "NUM_RESOURCES", resource_number); 55 | fclose(defines); 56 | fclose(bin); 57 | 58 | struct stat buf; 59 | if (!stat("Resources.bin", &buf)) { 60 | printf("-----> Resource.bin is %lld bytes\n", buf.st_size); 61 | } 62 | else { 63 | Panic("*** Can't stat Resources.bin\n"); 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /tools/rcomp-src/ResourceFile.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by mschwartz on 7/25/19. 3 | // 4 | 5 | #ifndef MODITE_RESOURCEFILE_H 6 | #define MODITE_RESOURCEFILE_H 7 | 8 | #include "rcomp.h" 9 | #include "lib/BSymbolTable.h" 10 | 11 | // maximum number of resources allowed in a .bin file 12 | const TInt MAX_RESOURCE_FILES=1024; 13 | 14 | class ResourceFile { 15 | public: 16 | ResourceFile(); 17 | public: 18 | TUint16 StartResource(char *define_name); 19 | void Write(void *data, long size); 20 | void Finish(); 21 | public: 22 | char path[MAX_STRING_LENGTH]; 23 | 24 | FILE *defines; 25 | FILE *bin; 26 | 27 | uint32_t resource_number; // resource_number into offset table at beginning of compiled data 28 | uint32_t offset; 29 | uint32_t offsets[MAX_RESOURCE_FILES]; 30 | uint8_t *output; 31 | uint32_t output_size; 32 | BSymbolTable symbols; 33 | }; 34 | 35 | extern ResourceFile resourceFile; 36 | 37 | #endif //MODITE_RESOURCEFILE_H 38 | -------------------------------------------------------------------------------- /tools/rcomp-src/SpriteSheet.h: -------------------------------------------------------------------------------- 1 | #ifndef RCOMP_SPRITESHEET_H 2 | #define RCOMP_SPRITESHEET_H 3 | 4 | #include "rcomp.h" 5 | 6 | #if 0 7 | struct BSpriteInfo { 8 | TInt dx, dy; // delta from upper left of sprite to upper left of fit rect 9 | TInt x1, y1, x2, y2; // rect that perfectly fits the image data 10 | }; 11 | 12 | struct BSpriteInfoROM { 13 | TUint16 resourceId; 14 | TUint16 imageType; 15 | TUint16 numSprites; 16 | BSpriteInfo info[1]; 17 | }; 18 | #endif 19 | 20 | class BSpriteInfo; 21 | 22 | class SpriteSheet { 23 | public: 24 | SpriteSheet(char *aDimensions, char *aBitmap); 25 | 26 | ~SpriteSheet(); 27 | 28 | public: 29 | void Write(ResourceFile &r); 30 | 31 | protected: 32 | BMPFile *bmp; 33 | BSpriteInfo *info; 34 | TUint16 resourceId; 35 | TInt16 image_type; 36 | TUint16 num_sprites; 37 | }; 38 | 39 | #endif //RCOMP_SPRITESHEET_H 40 | -------------------------------------------------------------------------------- /tools/rcomp-src/TMXFile.cpp: -------------------------------------------------------------------------------- 1 | #include "rcomp.h" 2 | #include "TMXFile.h" 3 | #include "lib/utils.h" 4 | #include "tmx/TMXMap.h" 5 | 6 | TMXFile::TMXFile(const char *path, const char *filename) { 7 | char fn[MAX_STRING_LENGTH], 8 | line[MAX_STRING_LENGTH], 9 | token[MAX_STRING_LENGTH], 10 | attr[MAX_STRING_LENGTH], value[MAX_STRING_LENGTH]; 11 | 12 | sprintf(fn, "%s/%s", path, filename); 13 | printf("TMXFile '%s' '%s' = '%s'\n", path, filename, fn); 14 | RawFile txt(fn); 15 | if (!txt.alive) { 16 | Panic("Could not open %s\n", fn); 17 | } 18 | 19 | while (txt.ReadLine(line)) { 20 | auto *map = new TMXMap(path, line); 21 | map->Write(resourceFile); 22 | delete map; 23 | } 24 | 25 | } 26 | 27 | TMXFile::~TMXFile() { 28 | // 29 | } 30 | -------------------------------------------------------------------------------- /tools/rcomp-src/TMXFile.h: -------------------------------------------------------------------------------- 1 | #ifndef RCOMP_TMXFILE_H 2 | #define RCOMP_TMXFILE_H 3 | 4 | class BMPFile; 5 | 6 | class TMXMap; 7 | //#include "tmx/TMXTileSet.h" 8 | //#include "tmx/TMXMap.h" 9 | 10 | /** 11 | * This represents the .txt file for TileEd created mapped playfields. 12 | * 13 | * The .txt file lists a number of .tmx files. The .tmx files each contain 14 | * a number of tileset definitions, and 4 layers. A layer is a 2 dimsensional map of 15 | * indexes into the tileset. 16 | * 17 | */ 18 | class TMXFile { 19 | public: 20 | TMXFile(const char *path, const char *filename); 21 | ~TMXFile(); 22 | public: 23 | const char *filename; 24 | TMXMap *mLevels[MAX_LEVELS]; 25 | }; 26 | 27 | 28 | #endif //RCOMP_TMXFILE_H 29 | -------------------------------------------------------------------------------- /tools/rcomp-src/TileMap.h: -------------------------------------------------------------------------------- 1 | #ifndef RCOMP_TILEMAP_H 2 | #define RCOMP_TILEMAP_H 3 | 4 | //#include "rcomp.h" 5 | //#include "LayerInfo.h" 6 | //#include "TileMapBase.h" 7 | 8 | class LayerInfo; 9 | class BMPFile; 10 | class RawFile; 11 | 12 | class TileMap { 13 | public: 14 | TileMap(const char *path, const char *filename); 15 | 16 | ~TileMap(); 17 | 18 | public: 19 | void Write(ResourceFile &resourceFile); 20 | 21 | public: 22 | const char *filename; 23 | BMPFile *bmp; 24 | LayerInfo *mLevels[MAX_LEVELS]; 25 | RawFile *mapAttributes; // .tlc file contents = num_tiles_in_bmp words 26 | }; 27 | 28 | #endif //RCOMP_TILEMAP_H 29 | -------------------------------------------------------------------------------- /tools/rcomp-src/lib/BSymbolTable.cpp: -------------------------------------------------------------------------------- 1 | #include "BSymbolTable.h" 2 | 3 | // hash a string to a value between 0-255 4 | static TInt16 hash(const char *s) { 5 | // this routine is stupid simple. There are other hash algorithms that produce a better distribution of hash values. 6 | // better distribution makes it so one bucket list doesn't get huge while others are empty. 7 | // better distribution probably comes at a CPU processing cost, though. 8 | // for our purposes, this is fine. 9 | TInt v = 0; 10 | while (*s != '\0') { 11 | v += *s; 12 | s++; 13 | } 14 | return v%256; 15 | } 16 | 17 | BSymbolTable::BSymbolTable() { 18 | // 19 | } 20 | 21 | BSymbolTable::~BSymbolTable() { 22 | // 23 | } 24 | 25 | BSymbol *BSymbolTable::LookupSymbol(const char *name) { 26 | TInt h = hash(name); 27 | BSymbolList &bucket = buckets[h]; 28 | for (BSymbol *sym = bucket.First(); !bucket.End(sym); sym=bucket.Next(sym)) { 29 | if (strcmp(sym->name, name) == 0) { 30 | return sym; 31 | } 32 | } 33 | return ENull; 34 | } 35 | 36 | TBool BSymbolTable::AddSymbol(const char *aName, TUint32 aValue, TAny *aPtr) { 37 | BSymbol *sym = LookupSymbol(aName); 38 | if (sym) { 39 | // already exists 40 | if (sym->value == aValue && sym->aptr == aPtr) { 41 | // trying to add a duplicate, pretend it succeeded) 42 | return ETrue; 43 | } 44 | else { 45 | // trying to add same name with different value! 46 | return EFalse; 47 | } 48 | } 49 | // doesn't exist, we'll add it 50 | TInt h = hash(aName); 51 | sym = new BSymbol(aName, aValue, aPtr); 52 | buckets[h].AddTail(*sym); 53 | return ETrue; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /tools/rcomp-src/lib/BSymbolTable.h: -------------------------------------------------------------------------------- 1 | #ifndef RCOMP_BSYMBOLTABLE_H 2 | #define RCOMP_BSYMBOLTABLE_H 3 | 4 | #include "BList.h" 5 | 6 | const TInt HASH_SIZE = 256; 7 | 8 | struct BSymbol : public BNode { 9 | BSymbol(const char *aName, TUint32 aValue, void *aPtr = ENull) { 10 | name = strdup(aName); 11 | value = aValue; 12 | aptr = aPtr; 13 | } 14 | 15 | ~BSymbol() { 16 | delete[] name; 17 | } 18 | 19 | char *name; 20 | void *aptr; // ptr to anything you want to be able to lookup 21 | TUint32 value; 22 | }; 23 | 24 | struct BSymbolList : public BList { 25 | public: 26 | ~BSymbolList() { 27 | while (BSymbol *s = RemHead()) { 28 | delete s; 29 | } 30 | } 31 | 32 | public: 33 | BSymbol *RemHead() { return (BSymbol *) BList::RemHead(); } 34 | 35 | BSymbol *First() { return (BSymbol *) next; } 36 | 37 | BSymbol *Next(BSymbol *curr) { return (BSymbol *) curr->next; } 38 | 39 | BSymbol *Last() { return (BSymbol *) prev; } 40 | 41 | BSymbol *Prev(BSymbol *curr) { return (BSymbol *) curr->prev; } 42 | 43 | TBool End(BSymbol *curr) { return curr == (BSymbol *) this; } 44 | }; 45 | 46 | class BSymbolTable { 47 | public: 48 | BSymbolTable(); 49 | 50 | ~BSymbolTable(); 51 | 52 | public: 53 | BSymbol *LookupSymbol(const char *name); 54 | 55 | TBool AddSymbol(const char *aName, TUint32 aValue, TAny *aPtr = ENull); 56 | 57 | protected: 58 | BSymbolList buckets[HASH_SIZE]; 59 | }; 60 | 61 | 62 | #endif //RCOMP_BSYMBOLTABLE_H 63 | -------------------------------------------------------------------------------- /tools/rcomp-src/lib/RawBitmap.cpp: -------------------------------------------------------------------------------- 1 | #include "../rcomp.h" 2 | 3 | TUint32 RawBitmap::BytesInBitmap() { 4 | return (TUint32(bytesPerRow) * TUint32(height)); 5 | } 6 | 7 | TUint32 RawBitmap::OutputSize() { 8 | TUint32 size = 0; 9 | size += sizeof(width); 10 | size += sizeof(height); 11 | size += sizeof(depth); 12 | size += sizeof(bytesPerRow); 13 | size += sizeof(palette_size); 14 | size += palette_size * 3; 15 | size += BytesInBitmap(); 16 | return size; 17 | } 18 | 19 | void RawBitmap::Dump(const char *pad) { 20 | printf("%s%-64.64s %dx%d %d-bit %dc %d raw ", pad, 21 | filename, width, height, depth, palette_size, 22 | OutputSize()); 23 | #if 0 24 | for (int i = 0; i < palette_size; i++) { 25 | printf("%02x: %02x %02x %02x\n", i, palette[i * 3 + 0], 26 | palette[i * 3 + 1], palette[i * 3 + 2]); 27 | } 28 | #endif 29 | #if 0 30 | printf("Pixels:\n"); 31 | for (int y = 0; y < height; y++) { 32 | printf("%4d ", y); 33 | for (int resources = 0; resources < width; resources++) { 34 | printf("%02x ", pixels[y * width + resources]); 35 | } 36 | printf("\n\n"); 37 | } 38 | #endif 39 | } 40 | 41 | -------------------------------------------------------------------------------- /tools/rcomp-src/lib/RawBitmap.h: -------------------------------------------------------------------------------- 1 | #ifndef MODITE_RAWBITMAP_H 2 | #define MODITE_RAWBITMAP_H 3 | 4 | #include "rcomp.h" 5 | 6 | #include "../../../src/BTypes.h" 7 | #include "../../../src/Memory.h" 8 | 9 | class RawBitmap { 10 | public: 11 | char *filename; 12 | TUint16 width, height, depth, bytesPerRow; 13 | TUint16 palette_size; // number of colors 14 | TUint8 *palette; 15 | TUint8 *pixels; 16 | 17 | public: 18 | TUint32 BytesInBitmap(); 19 | TUint32 OutputSize(); 20 | 21 | public: 22 | void Dump(const char *aPad = ""); 23 | }; 24 | 25 | #endif //MODITE_RAWBITMAP_H 26 | -------------------------------------------------------------------------------- /tools/rcomp-src/lib/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILS_H 2 | #define UTILS_H 3 | 4 | #include "../../src/BTypes.h" 5 | 6 | // TODO: add these to CE proper 7 | extern void HexDump(TUint8 *ptr, TInt length, TInt width=8); 8 | extern void HexDump(TUint16 *ptr, TInt length, TInt width=8); 9 | extern void HexDump(TUint32 *ptr, TInt length, TInt width=8); 10 | 11 | extern char *skipbl(char *p); 12 | extern char *parse_token(char *dst, char *src); 13 | extern char *trim(char *p); 14 | extern void symbol_name(char *dst, char *base); 15 | 16 | // XML helpers 17 | 18 | // parse xml attribute, e.g. foo="bar", into attr[] = foo, value = bar 19 | extern void parse_attr(char *s, char *attr, char *value); 20 | // parse xml value for given attribute - e.g. given attribute "foo" and xml contains foo="bar", then value is set to "bar" 21 | extern TBool parse_value(char *s, const char *attribute, char *value); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /tools/rcomp-src/rcomp.h: -------------------------------------------------------------------------------- 1 | #ifndef MODITE_RCOMP_H 2 | #define MODITE_RCOMP_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | // 16 | #include "../../src/BTypes.h" 17 | #include "../../src/Memory.h" 18 | #include "../../src/Panic.h" 19 | #include "../../src/BBitmap.h" 20 | // 21 | const int MAX_LEVELS = 10; 22 | const int MAX_STRING_LENGTH = 4096; 23 | 24 | // 25 | #include "RawFile.h" 26 | #include "lib/RawBitmap.h" 27 | #include "BMPFile.h" 28 | #include "ResourceFile.h" 29 | #include "TileMap.h" 30 | #include "TMXFile.h" 31 | #include "SpriteSheet.h" 32 | 33 | #ifndef O_BINARY 34 | #define O_BINARY (0) 35 | #endif 36 | 37 | 38 | #include "lib/utils.h" 39 | 40 | #endif //MODITE_RCOMP_H 41 | -------------------------------------------------------------------------------- /tools/rcomp-src/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | HERE=$PWD 4 | cd ../../../src 5 | ls 6 | $HERE/rcomp Resources.r 7 | cd $HERE 8 | 9 | -------------------------------------------------------------------------------- /tools/rcomp-src/tmx/TMXLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "rcomp.h" 2 | #include "TMXLayer.h" 3 | 4 | TMXLayer::TMXLayer(RawFile &aFile, char line[MAX_STRING_LENGTH]) { 5 | char value[MAX_STRING_LENGTH]; 6 | data = ENull; 7 | 8 | parse_value(line, "id", value); 9 | id = atol(value); 10 | 11 | parse_value(line, "name", name); 12 | 13 | parse_value(line, "width", value); 14 | width = atol(value); 15 | 16 | parse_value(line, "height", value); 17 | height = atol(value); 18 | 19 | printf(" layer: %s is %dx%d\n", name, width, height); 20 | data = new TUint32[width * height]; 21 | 22 | // tag 23 | if (!aFile.ReadLine(line)) { 24 | Panic("Unexpected EOF\n"); 25 | } 26 | 27 | TUint32 *ptr = data; 28 | for (TInt h = 0; h < height; h++) { 29 | if (!aFile.ReadLine(line)) { 30 | Panic("Unexpected EOF\n"); 31 | } 32 | char *src = line; 33 | while (*src) { 34 | TUint32 n = 0; 35 | while (*src && *src != ',') { 36 | n *= 10; 37 | n += *src++ - '0'; 38 | } 39 | *ptr++ = n; 40 | if (*src == ',') { 41 | src++; 42 | } 43 | } 44 | } 45 | 46 | // tag 47 | if (!aFile.ReadLine(line)) { 48 | Panic("Unexpected EOF\n"); 49 | } 50 | // tag 51 | if (!aFile.ReadLine(line)) { 52 | Panic("Unexpected EOF\n"); 53 | } 54 | 55 | } 56 | 57 | TMXLayer::~TMXLayer() { 58 | delete[] data; 59 | } 60 | 61 | void TMXLayer::Dump() { 62 | printf("\n TMXLayer(%s) is %dx%d\n", name, width, height); 63 | TUint32 *ptr = data; 64 | for (TInt h=0; h 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #ifndef O_BINARY 14 | #define O_BINARY (0) 15 | #endif 16 | 17 | void usage(int ac, char *av[]) { 18 | printf("Usage:\n"); 19 | printf("\t%s \n", av[0]); 20 | printf("Dumps an stm tile map file\n"); 21 | exit(1); 22 | } 23 | 24 | int main(int ac, char *av[]) { 25 | if (ac < 2) { 26 | usage(ac, av); 27 | } 28 | 29 | int fd = open(av[1], O_RDONLY | O_BINARY); 30 | ssize_t size = lseek(fd, 0, 2); 31 | lseek(fd, 0, 0); 32 | unsigned char data[size]; 33 | read(fd, &data[0], size); 34 | close(fd); 35 | 36 | struct STMPFILE { 37 | char stmp[4]; 38 | short width; 39 | short height; 40 | unsigned long entries[]; 41 | } *map = (STMPFILE *) &data[0]; 42 | 43 | if (strncmp(map->stmp, "STMP", 4)) { 44 | printf("%s is not an stmp file\n", av[1]); 45 | exit(1); 46 | } 47 | 48 | printf("%s is %d by %d tiles\n", av[1], map->width, map->height); 49 | 50 | unsigned long *entries = &map->entries[0]; 51 | for (int h = 0; h < map->height; h++) { 52 | for (int w = 0; w < map->width; w++) { 53 | printf("%04x ", *entries++); 54 | } 55 | printf("\n"); 56 | } 57 | exit(0); 58 | } 59 | -------------------------------------------------------------------------------- /tools/test-orig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/tools/test-orig.png -------------------------------------------------------------------------------- /tools/test.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/tools/test.bmp -------------------------------------------------------------------------------- /tools/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ModusCreateOrg/creative-engine/4f55709ceafb9b32e29b2ead07116c56d4ad5a73/tools/test.png -------------------------------------------------------------------------------- /tools/tools.cmake: -------------------------------------------------------------------------------- 1 | 2 | FILE(GLOB RCOMP_SOURCE_FILES 3 | ${CREATIVE_ENGINE_PATH}/tools/rcomp-src/*.cpp 4 | ${CREATIVE_ENGINE_PATH}/tools/rcomp-src/*.h 5 | ${CREATIVE_ENGINE_PATH}/tools/rcomp-src/tmx/*.cpp 6 | ${CREATIVE_ENGINE_PATH}/tools/rcomp-src/tmx/*.h 7 | ${CREATIVE_ENGINE_PATH}/tools/rcomp-src/lib/*.cpp 8 | ${CREATIVE_ENGINE_PATH}/tools/rcomp-src/lib/*.h 9 | ) 10 | 11 | ADD_EXECUTABLE(rcomp 12 | ${RCOMP_SOURCE_FILES} 13 | ${CREATIVE_ENGINE_PATH}/src/Panic.cpp ${CREATIVE_ENGINE_PATH}/src/Panic.h 14 | ${CREATIVE_ENGINE_PATH}/src/Memory.cpp ${CREATIVE_ENGINE_PATH}/src/Memory.h 15 | ${CREATIVE_ENGINE_PATH}/src/BBase.cpp ${CREATIVE_ENGINE_PATH}/src/BBase.h 16 | ${CREATIVE_ENGINE_PATH}/src/BBitmap.cpp ${CREATIVE_ENGINE_PATH}/src/BBitmap.h 17 | ${CREATIVE_ENGINE_PATH}/src/BList.cpp ${CREATIVE_ENGINE_PATH}/src/BList.h 18 | ) 19 | TARGET_INCLUDE_DIRECTORIES( rcomp PUBLIC ${CREATIVE_ENGINE_PATH}/tools/rcomp-src ) 20 | --------------------------------------------------------------------------------