Fixed the Wii port so that it compiles.
[rpn.git] / src / psp / port.h
blob434199ece29d911e4d81b6480a293da0344590cc
1 /*******************************************************************************
2 * Reverse Polish Notation calculator. *
3 * Copyright (c) 2007-2008, Samuel Fredrickson <kinghajj@gmail.com> *
4 * All rights reserved. *
5 * *
6 * Redistribution and use in source and binary forms, with or without *
7 * modification, are permitted provided that the following conditions are met: *
8 * * Redistributions of source code must retain the above copyright *
9 * notice, this list of conditions and the following disclaimer. *
10 * * 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 * *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS *
15 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY *
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
24 * DAMAGE. *
25 ******************************************************************************/
27 /*******************************************************************************
28 * port.h - specialized ports for the psp version. *
29 ******************************************************************************/
31 #ifndef DOXYGEN_SKIP
32 #ifndef _CONSOLE_PORT_H_
33 #define _CONSOLE_PORT_H_
35 extern "C" {
36 #include <pspctrl.h>
37 #include <pspdebug.h>
38 #include <pspdisplay.h>
39 #include <pspkernel.h>
42 #include <cstdarg>
43 #include <cstdio>
44 #include <map>
45 #include <string>
47 namespace RPN
49 class Port
51 //! Holds information on how a certain button press on the PSP maps to
52 //! characters. The alternate form is accessed by pressing the
53 //! right trigger.
54 struct CharPair
56 char chr, alt_chr;
58 CharPair(char chr = '\0', char alt_chr = '\0')
59 : chr(chr), alt_chr(alt_chr) {}
62 // Executed on exit; used for cleanup.
63 static int ExitCallback(int arg1, int arg2, void *common);
64 // Thread to create and register callbacks.
65 static int CallbackThread(SceSize args, void *argp);
66 // Starts thread to create callbacks.
67 static int SetupCallbacks();
69 //! Gets button pushes.
70 /**
71 * This reports multiple button pushes, so this does not return until
72 * all buttons have been released.
74 * @return An integer with button press flags.
76 static int GetButtonPushes();
78 // Returns a key that matches the given buttons.
79 // Simple but fast on a small map.
80 static CharPair* FindPair(int buttons);
82 // 64 characters is a reasonable limit for the buffer.
83 const static size_t buf_size = 64;
84 // To press "enter", press the triggers simultaneously.
85 static int enter;
86 // To cancel input, press the left trigger.
87 static int cancel;
88 // To switch to alternate characters, press the right trigger.
89 static int alternate;
90 // Don't start in alternate mode.
91 static bool alternateMode;
92 // Holds a map of button presses to characters.
93 static std::map<int, CharPair> keyMap;
95 //! Get one character; map special characters so they can be handled
96 //! later.
97 /**
98 * @return The typed character or 0 if invalid.
100 static char GetCharacter();
102 static char output_buffer[1024];
104 public:
106 static bool CanRun()
108 return true;
111 static std::string GetLine();
113 static void Post()
115 sceKernelExitGame();
118 static void Print(const char* str, ...)
120 va_list args;
122 va_start(args, str);
123 vsprintf(output_buffer, str, args);
124 pspDebugScreenPrintf(output_buffer);
125 va_end(args);
126 //pspDebugScreenPrintf(str);
129 static void Setup();
133 #endif
134 #endif