(no subject) [entries|reading|network|archive]
simont

[ userinfo | dreamwidth userinfo ]
[ archive | journal archive ]

Mon 2002-07-22 09:54

In other news, I've been making some progress on the Playstation 2 Linux front. I think I'm now within spitting distance of actually being able to make a start on porting the various old games I wrote for the PC and BBC to run on the PS2, which will be cool.

Most of the work was done for me by the PS2 port of libSDL. For those who don't know what SDL is, it's a library that attempts to allow direct framebuffer access while still being portable to abstracted sorts of operating systems such as X and Windows. It achieves this by having a "lock" call, which returns you a pointer to a framebuffer or something looking very like one. You then modify the memory pointed to by that pointer, call "unlock" and "update", and your changes appear on the screen. So on a system that provides direct framebuffer access, "unlock" and "update" do nothing while "lock" simply hands you a pointer to the real framebuffer; and on a system where you're several security barriers away from anything resembling real hardware, "lock" gives you a pointer to a chunk of ordinary memory owned by SDL and "update" uses the local bitmap-handling functions to copy your changes on to the window your program is displaying.

Given that surely the whole point of a dedicated games machine is that you should be able to directly access the framebuffer, it therefore seems a bit strange that the PS2 port of libSDL doesn't give you direct access; instead it appears to do a bulk copy when you call "update". I speculate that Linux is getting in the way here, blocking access to real memory and forcing everything to be mediated through system calls. Still, I seem to be able to shift a whole screenful of data around in every frame (running at 50 fps to match the TV) and still have about 3/5 of my CPU time free, so that ought to be more than enough for any games I plan to port. It may constrain my options if and when I wonder about writing some new ones, though; particularly since I can only achieve this performance in the 8-bit paletted video mode and can't manage anything so good in true colour. Ah well; such is life.

Meanwhile, SDL has some trouble accessing the controllers; it can cheerfully get at the direction buttons and eight of the fire buttons, but the mushroom-shaped analogue things give it more trouble. It can't see the right-hand one at all; it can't see the two extra fire buttons you get by pushing the tops of the mushrooms; and it can't turn on analogue mode in the first place so I have to do it manually with the button on the controller. All of this exactly matches what happens when I open /dev/js0 myself and monitor input fron it, though, so it doesn't seem to be SDL's fault. I assume you need to send something back to the controller to change its mode. Again, this won't impair porting of my old games, but will restrict what I might wonder about writing in future.

Timing off the vertical retrace was no picnic either; SDL seems to contain no facility for doing this. I remain incredulous that nobody except me seems to think vsync timing is remotely necessary in a games platform; how else are you supposed to get decently smooth movement, eh? I suppose it might be less important in modern 3D-type games, and it was almost useless on the PC because (a) the PC won't give you a vsync interrupt and even finding out when they're happening is CPU-intensive, and (b) vsyncs happen at a different rate depending on your graphics hardware, which makes it hard to write a game that uses them and is consistent on all machines; but in pretty much everything I used to write, the video frame was the natural unit of time around which to base everything that happened in the game. Fortunately the PS2 hardware will give you a vsync interrupt, even if SDL doesn't know anything about it; so I was eventually able to look up the vsync interupt in the PS2 hardware manuals, search through the kernel source until I found the code that received it, and then look for the ioctl that provided user access to the facility. And thankfully it can be done - there is an ioctl which lets you wait for a vsync, and another which lets you count the vsyncs as they pass. Phew.

So I now have adequate video, controller access and timing facilities to start porting my old games (the only remaining difficulty being that half of them are written in BBC machine code and the other half in Borland Pascal!). Of course what I really wish is that someone would port a Spectrum emulator ... :-)

LinkReply
[identity profile] ex-lark-asc.livejournal.comMon 2002-07-22 03:29
Speccy games, Speccy games *bounce*bounce* :)

Google knows about several Speccy emulators for Linux, is PS2 Linux significantly different?

And by the way, if you ever decide you do want to change jobs, you should come and work for the engine team here, that lot could have been one of the conversations from our kitchen :)
Link Reply to this | Thread
[personal profile] simontMon 2002-07-22 03:42
What, you mean your lot aren't depressingly obsessed with 3D games which I'd find terribly boring? :-)

I don't know how hard it would be to port a Speccy emulator: it probably depends on the emulator. If there's one that runs over SDL and already uses the SDL calls to access video, audio and joysticks, then it might very well be a near-trivial matter of fiddling with the precise screen resolution and making sure the controller buttons are mapped in some sensible manner. If they all use different libraries to get at the various I/O facilities, though, it'd be harder to get something useful working.

Someone's already ported MAME to PS2 Linux, which is a good start; but I never managed to get a great deal of decent stuff to run under that, and most of my early gaming history was on the Spectrum rather than arcade machines, so I'd prefer a Spectrum emulator. An Amiga one would be kinda nice too, though perhaps harder to get running at a decent speed, particularly given the ludicrous custom graphics hardware which would be orders of magnitude slower to emulate on a less insanely designed machine...
Link Reply to this | Parent | Thread
[identity profile] ex-lark-asc.livejournal.comMon 2002-07-22 04:33
3D > Point, although it sounds to me as if the low-level stuff's more fun than the chrome.

MAME was always kind of buggy that I recall, mind you I've not seen it in a few years. As far as the internal workings of Speccy emulators go, well, look at what Google comes up with for yourself :)
Link Reply to this | Parent | Thread
[personal profile] simontMon 2002-07-22 05:17
Can't seem to find any SDL-based Spectrum emulators, which is a minor pain.

From a medium-effort web search, the best bet looks like Spectemu, on the grounds that (a) it's GPLed and seems to be reasonably well linked to so it might actually work, and (b) although it doesn't support SDL, it does support both X and SVGAlib - so it probably already has a decent separation between the interchangeable back ends and everything else, which might mean writing an SDL back end isn't too horrid.
Link Reply to this | Parent
navigation
[ go | Previous Entry | Next Entry ]
[ add | to Memories ]