diff --git a/App2/test.cc b/App2/test.cc deleted file mode 100644 index 6e6a6c0e03..0000000000 --- a/App2/test.cc +++ /dev/null @@ -1,144 +0,0 @@ -/* - Copyright 2012 Wolfgang Thaller. - - This file is part of Retro68. - - Retro68 is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Retro68 is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Retro68. If not, see . -*/ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "MacUtils.h" -#include "Console.h" - -QDGlobals qd; -__attribute((constructor)) -void cons() -{ - SysBeep(20); -} - -//float something = 6.0; - -class Foo -{ -}; - -void foobar() -{ - throw Foo(); -} - -void foobaz() -{ -} - -extern ssize_t (*__write_hook)(int fd, const void*buf, size_t count); - -extern "C" ssize_t consolewrite(int fd, const void *buf, size_t count) -{ - const char *p = (const char*)buf; - for(int i = 0; i < count; i++) - Console::currentInstance->putch(*p++); - return count; -} - -extern ssize_t (*__read_hook)(int fd, void*buf, size_t count); - -extern "C" ssize_t consoleread(int fd, void *buf, size_t count) -{ - static std::string consoleBuf; - if(consoleBuf.size() == 0) - { - consoleBuf = Console::currentInstance->ReadLine() + "\n"; - } - if(count > consoleBuf.size()) - count = consoleBuf.size(); - memcpy(buf, consoleBuf.data(), count); - consoleBuf = consoleBuf.substr(count); - return count; -} - -int main(int argc, char** argv) -{ - //GrafPort port; - WindowPtr win; - InitGraf(&qd.thePort); - InitFonts(); - InitWindows(); - InitMenus(); - - Rect r; - SetRect(&r, qd.screenBits.bounds.left + 5, qd.screenBits.bounds.top + 45, qd.screenBits.bounds.right - 5, qd.screenBits.bounds.bottom -5); - win = NewWindow(NULL, &r, PSTR("Retro68 Console"), true, 0, (WindowPtr)-1, false, 0); - - SetPort(win); - EraseRect(&win->portRect); - new char[32]; - Console console(win, win->portRect); - __write_hook = &consolewrite; - __read_hook = &consoleread; - - printf("Hello, world.\n"); - std::cout << "Hello, world, again.\n"; - - printf("Say something: "); - fflush(stdout); - printf("You said: %s\n", console.ReadLine().c_str()); - - char buffer[100]; - printf("Say something else: "); - fflush(stdout); - fgets(buffer, 100, stdin); - printf("You said: %s\n", buffer); - - - for(int i = 0; i < 5; i++) - { - int n = i == 0 ? 1 : 100; - printf("Exception speed test (%3d iterations): ", n); fflush(stdout); - long start = TickCount(); - for(int j = 0; j < n; j++) - { - try { foobar(); } catch(...) {} - } - long end = TickCount(); - - printf("%g ms per throw/catch\n",(end-start)*1000 / 60.0 / n); - } - - const int n = 3; - printf("Click mouse %d times...\n", n); - for(int i = 0; i < n; i++) - { - while(!Button()) - ; - while(Button()) - ; - printf("Click #%d\n", i+1); - } - FlushEvents(everyEvent, 0); - return 0; -} diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a375c3a98..8856d83b79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,8 @@ project(Retro) if(CMAKE_SYSTEM_NAME MATCHES Retro68) add_subdirectory(libretro) -add_subdirectory(App2) +add_subdirectory(Console) +add_subdirectory(TestApps) add_subdirectory(Raytracer) add_subdirectory(Launcher) else() diff --git a/Console/CMakeLists.txt b/Console/CMakeLists.txt new file mode 100644 index 0000000000..650a671542 --- /dev/null +++ b/Console/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright 2014 Wolfgang Thaller. +# +# This file is part of Retro68. +# +# Retro68 is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Retro68 is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Retro68. If not, see . + +cmake_minimum_required(VERSION 2.8) +set(CMAKE_CXX_FLAGS "-std=c++11") + +add_library(RetroConsole + Console.cc + Console.h + MacUtils.h + InitConsole.cc + ) + +add_executable(HelloWorld + hello.c + ) + +target_link_libraries(HelloWorld RetroConsole retrocrt) +add_custom_command( + OUTPUT HelloWorld.bin + COMMAND ${MAKE_APPL} -c HelloWorld -o HelloWorld + DEPENDS HelloWorld) +add_custom_target(HelloWorldAPPL ALL DEPENDS HelloWorld.bin) diff --git a/App2/Console.cc b/Console/Console.cc similarity index 100% rename from App2/Console.cc rename to Console/Console.cc diff --git a/App2/Console.h b/Console/Console.h similarity index 100% rename from App2/Console.h rename to Console/Console.h diff --git a/App2/InitConsole.cc b/Console/InitConsole.cc similarity index 100% rename from App2/InitConsole.cc rename to Console/InitConsole.cc diff --git a/App2/MacUtils.h b/Console/MacUtils.h similarity index 100% rename from App2/MacUtils.h rename to Console/MacUtils.h diff --git a/App2/hello.c b/Console/hello.c similarity index 100% rename from App2/hello.c rename to Console/hello.c diff --git a/Raytracer/raytracer2.cc b/Raytracer/raytracer2.cc index 76ebfe9d77..28338f4af4 100644 --- a/Raytracer/raytracer2.cc +++ b/Raytracer/raytracer2.cc @@ -20,8 +20,6 @@ #ifdef __APPLE__ #include #include -#define PSTR(x) ("\p" x) - #else #include @@ -32,10 +30,7 @@ #include #ifdef __GNUC__ -#include "MacUtils.h" QDGlobals qd; -#else -#define PSTR(x) ("\p" x) #endif #endif diff --git a/App2/AsmTest.s b/TestApps/AsmTest.s similarity index 100% rename from App2/AsmTest.s rename to TestApps/AsmTest.s diff --git a/App2/CMakeLists.txt b/TestApps/CMakeLists.txt similarity index 68% rename from App2/CMakeLists.txt rename to TestApps/CMakeLists.txt index 4b442e8a28..7a43a405ae 100644 --- a/App2/CMakeLists.txt +++ b/TestApps/CMakeLists.txt @@ -18,22 +18,17 @@ cmake_minimum_required(VERSION 2.8) set(CMAKE_CXX_FLAGS "-std=c++11") # -fomit-frame-pointer") -add_library(RetroConsole - Console.cc - Console.h - MacUtils.h - InitConsole.cc - ) +add_executable(ExceptionTest + ExceptionTest.cc + ) + +target_link_libraries(ExceptionTest RetroConsole retrocrt) +add_custom_command( + OUTPUT ExceptionTest.bin + COMMAND ${MAKE_APPL} -c ExceptionTest -o ExceptionTest + DEPENDS ExceptionTest) +add_custom_target(ExceptionTestAPPL ALL DEPENDS ExceptionTest.bin) -add_executable(Test - test.cc - Console.cc - Console.h - MacUtils.h - ) -add_executable(HelloWorld - hello.c - ) enable_language(ASM) add_executable(AsmTest @@ -41,22 +36,6 @@ add_executable(AsmTest ) set_target_properties(AsmTest PROPERTIES LINKER_LANGUAGE C) -#target_link_libraries(Test :retrocrt.o) - -target_link_libraries(Test retrocrt) -add_custom_command( - OUTPUT Test.bin - COMMAND ${MAKE_APPL} -c Test - DEPENDS Test) -add_custom_target(TestAPPL ALL DEPENDS Test.bin) - -target_link_libraries(HelloWorld RetroConsole retrocrt) -add_custom_command( - OUTPUT HelloWorld.bin - COMMAND ${MAKE_APPL} -c HelloWorld -o HelloWorld - DEPENDS HelloWorld) -add_custom_target(HelloWorldAPPL ALL DEPENDS HelloWorld.bin) - target_link_libraries(AsmTest retrocrt) add_custom_command( OUTPUT AsmTest.bin diff --git a/TestApps/ExceptionTest.cc b/TestApps/ExceptionTest.cc new file mode 100644 index 0000000000..91a39bc6f3 --- /dev/null +++ b/TestApps/ExceptionTest.cc @@ -0,0 +1,61 @@ +/* + Copyright 2012 Wolfgang Thaller. + + This file is part of Retro68. + + Retro68 is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Retro68 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Retro68. If not, see . +*/ + +#include + +#include + +class Foo +{ +}; + +void foobar() +{ + throw Foo(); +} + +int main(int argc, char** argv) +{ + for(int i = 0; i < 5; i++) + { + int n = i == 0 ? 1 : 100; + printf("Exception speed test (%3d iterations): ", n); fflush(stdout); + long start = TickCount(); + for(int j = 0; j < n; j++) + { + try { foobar(); } catch(...) {} + } + long end = TickCount(); + + printf("%g ms per throw/catch\n",(end-start)*1000 / 60.0 / n); + } + + const int n = 3; + printf("Click mouse %d times...\n", n); + for(int i = 0; i < n; i++) + { + while(!Button()) + ; + while(Button()) + ; + printf("Click #%d\n", i+1); + } + FlushEvents(everyEvent, 0); + return 0; +}