Odds and ends that don't really deserve their own page.
Simple SWF information C program
Here's a (very) small program to output some basic information about Adobe Flash (SWF) files. It's only 900 bytes in size, and doesn't do much error checking...
To compile this program, simply save it as "swfinfo.c" and type the following into BASH:
You can then run the program as follows:
This program should be fully portable across all operating systems and architectures.
Cross-platform milliseconds function (C/C++)
Something that I didn't realise for a long time was that the clock() function in C/C++ doesn't always return results in milliseconds - it actually varies by platform. The value returned is actually determined by CLOCKS_PER_SEC.
When CLOCKS_PER_SEC is 1000, there isn't a problem - every second is divided into 1000 units AKA milliseconds. However, if a platform defines CLOCKS_PER_SEC as 100, two seconds would be represented as 200 rather than 2000.
Windows NT systems (including XP, Vista, and 7) define CLOCKS_PER_SEC as 1000. However, MacOSX and GNU/Linux do not, which can be a problem for programmers wanting to write cross-platform, time-sensitive applications.
In order to avoid running into this issue when porting a program from one platform to another, the following code can be used:
This code simply multiplies the result of clock() by 1000 (i.e. the number of milliseconds in one second) and then divides the result by the original number reported.
For platforms where CLOCKS_PER_SEC is 1000, this function would simply multiply the value by 1000 before dividing it again so that the original value was returned.
However, if CLOCKS_PER_SEC were to be 1 (i.e. 1 clock = 1 second) then this code would multiply the result by 1000 (converting it to milliseconds) before dividing it by 1 - which would have no effect, leaving the result in milliseconds.
Microsoft Xbox 360 Controller Definitions (Windows)
The following file can be used in combination with the official Microsoft DirectInput driver on Windows platforms. It was written and tested using Windows XP.
Note that the triggers are treated as a single axis, so that pressing both at the same time causes the two inputs to cancel each other out. This is a limitation of the DirectInput driver - if you need access to each trigger individually, consider using the newer XInput method instead.
Also, the central Xbox 360 Menu button can't be used, due to Microsoft reserving it for possible future use.
Microsoft Xbox 360 Controller Definitions (GNU/Linux)
Xbox 360 pads do not behave in the same way on UNIX-like systems. The input mappings are different, the central logo button is accessible, and the triggers are separated so that each has an individual axis.
The following information was compiled and tested using Trisquel 4.5 (64-bit):
Sony PlayStation 3 SIXAXIS Pad Definitions (GNU/Linux)
Similar to the above, but for PS3 controllers. This was written and tested on Trisquel GNU/Linux and will probably work on most variations of the GNU/Linux family of operating systems.
Unfortunately, it doesn't look like the tilt sensor functionality can be accessed using the current version of the driver. However, all other buttons (including the central "PS Logo" button can be accessed.
Being a former Sony employee, I have attempted to label all buttons using the "official" names that we were instructed to use for internal communications. For example, it's the "Cross" button, not the "Ecks" button. Likewise, the "PS Logo" button is not called the "Menu" button or "XMB" button.
You might have noticed that some of the buttons are also present as axes. This is so that you can either use them as normal on/off buttons or read them as pressure-sensitive buttons instead (I seem to recall that the PlayStation 2 did something similar).
As for what the unused buttons are for: I have no idea.
As a side note: I'm not sure that it's possible to use a SIXAXIS pad wirelessly (by using a bluetooth connection) on a GNU/Linux system, but if you connect it directly to a USB port and the pad does not seem to be responding (despite the red lights flashing on and off), try pressing the PS Logo button to "activate" it and it should work.
Don't - A program that doesn't do things.
See this quote on bash.org for details:
<@charlie_x> i have a command line program on my pc called dont.com
<@charlie_x> if you type dont format c:\
<@charlie_x> it says
<@charlie_x> "ok i wont"
Here's an implementation of it in C:
...and in Python:
...and in Java:
...and, finally, a simple MS Windows .BAT file version:
As part of my work on Hitoha, I needed some information on how a "proper" SWF should work, including it's constraints and limitations. What I have learned is provided here for anyone else who might find it useful.