Annoyance with the MIPS linker: relocation overflows

gcc disasm.o audio.o configuration.o dialog.o file.o hostcall.o keymap.o main.o memAlloc.o misc.o screen.o screenConvert.o sdlgui.o shortcut.o scalebit.o input.o fe2.o ../fe2.part1.o ../fe2.part2.o -L/usr/lib/mips64el-linux-gnuabi64 -lSDL -o ../frontier

/usr/bin/ld: ../fe2.part1.o: in function <code>load_binfile': fe2.s.c:(.text+0x180): relocation truncated to fit: R_MIPS_CALL16 against</code>fopen@@GLIBC_2.2'
/usr/bin/ld: fe2.s.c:(.text+0x19c): relocation truncated to fit: R_MIPS_CALL16 against <code>fseek@@GLIBC_2.0' /usr/bin/ld: fe2.s.c:(.text+0x1a8): relocation truncated to fit: R_MIPS_CALL16 against</code>ftell@@GLIBC_2.0'
/usr/bin/ld: fe2.s.c:(.text+0x1c0): relocation truncated to fit: R_MIPS_CALL16 against <code>fseek@@GLIBC_2.0' /usr/bin/ld: fe2.s.c:(.text+0x1e4): relocation truncated to fit: R_MIPS_CALL16 against</code>fread@@GLIBC_2.0'
/usr/bin/ld: fe2.s.c:(.text+0x1f0): relocation truncated to fit: R_MIPS_CALL16 against <code>fclose@@GLIBC_2.2' /usr/bin/ld: fe2.s.c:(.text+0x280): relocation truncated to fit: R_MIPS_GOT_DISP against</code>stderr@@GLIBC_2.0'
/usr/bin/ld: fe2.s.c:(.text+0x284): relocation truncated to fit: R_MIPS_CALL16 against <code>fprintf@@GLIBC_2.0' /usr/bin/ld: fe2.s.c:(.text+0x290): relocation truncated to fit: R_MIPS_CALL16 against</code>exit@@GLIBC_2.0'
/usr/bin/ld: fe2.s.c:(.text+0x2b4): relocation truncated to fit: R_MIPS_CALL16 against `__assert_fail@@GLIBC_2.0'
/usr/bin/ld: fe2.s.c:(.text+0x2c4): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:18: ../frontier] Error 1

I’d never heard or seen this before, and yeah it’s some MIPS’isim.

Apparently it’s something called a “global offset table” which of course has a 64k entery limit which can cause an overflow if you are doing something crazy like running a disassembler and having tens of thousands of instructions.

Looking at the GCC MIPS options page, there is hope, one can opt for a more iniffecient and larger table with the simple option of -mxgot

FrontVM-2 20061120

And now I can link frontvm.

Elite: Dangerous is going to get made!

Project Update #31: Update #31 – We’ve made it!

Posted by Frontier DevelopmentsLike

This is just a mini-update to thank everyone for their amazing support. As I write, we are at a pledge total of just over £1,287,000 and 21,816 pledges.

Astonishingly we crossed the line on my 49th birthday yesterday, which really made my day. I was really touched, delighted, excited, relieved by the news. It is really really great.

There will be a further update later today. Another £113,000 and we hit the Macintosh stretch goal too.

Huge thanks once again.

David

More fun with Janus!

Frontier Elite, on Janus

Frontier Elite, on Janus

So, I came across this great page, Frontierverse, which has download links for all the versions of Frontier Elite which were released out as shareware.  So what is cool, is that using the AROS Kickstart replacement ROM, it’ll boot up and work!

Just be sure to increase the default amount of chip memory, as it seems the AROS Kickstart ROM consumes more RAM than the Commodore ROM.  But heck the AROS ROM is opensource, and free!

Pretty cool, and more interesting than say the normal, yippie a view of the AROS cat..

 

AROS Kickstart ROM

AROS Kickstart ROM

Again very cool stuff!

And lastly, I slapped together a disk that’ll boot up aclock, although it works only with a Kickstart 2 or higher ROM.. 1.3 kinda freaks out, and I didn’t feel the need to go all over the top on this one.  Booting the aclock disk with the Aros ROM though loads up, but the clock doesn’t tick..

On OS X, I’ve been using the FS-UAE emulator to some degree of success, I’ve found it a tad cumbersome for swapping floppy disks, and I’ve had a major issue where making updates on an ADF that while they all look like the changes are reflected, going to the filesystem proved otherwise.  So I wound up having to make DMS disk images, and running some ancient MS-DOS program to convert DMS to ADF‘s.  Naturally the compression programs were in turn.. compressed.  So with enough fooling around with various archivers I found here, I was finally able to get where I needed to be.

At the same time, looking at how the AROS kickstart replacement ROM is quite capable, it may be time to revisit AROS, and I would imagine it has become far more capable than that last time I had looked at it.

Frontier Dangerous – update

Part one

Part two

Another update by David Braben about the future of Frontier Dangerous and Chris Robberts of Wing Commander fame.

Interesting take on one project that met its goals, and another that is half way in terms of time and ‘donations’ …  Or more importantly the return of the space combat genre, and of course the ultimate ‘sandbox’ being in the scope of an entire galaxy.

Fun times.

Elite Dangerous

There has been some buzz about for years (decades?) about a new Elite game.  Sure the Frontier sequels were simply amazing, but now that PC’s are far more advanced than they’ve ever been, what would Elite look like today?

 

So here is a small taste!

Unlike other video games, there has been a movement afoot of the end customer directly financing the upstart cost for projects to get them off the ground.  The idea being that people themselves may be interested in a product, and they can cut out the middle men of marketers & financiers, and do so in a mob fashion.  Kickstarter is one of many sites built for this purpose.

So I was surprised to find that David Braben (Of recent Raspberry Pi fame), had started one for the future of Elite, right here.  He is trying to raise a hefty £1,250,000 to directly fund this new version of Elite.  Right now he is £683,487 short but has 41 days to go.  I would imagine that one of the reasons of why they want to go this way, is that during the Frontier days when GameTek went bankrupt, leaving much of their distribution and marketing in the air.

Is this madness?  Maybe a tad, but the original developers behind Wing Commander managed to fun their project, Star Citizen on Kickstarter as well!

Of course here is the original pitch video:

 

And be sure to check out the projects website.

Oh yeah, and as part of my jdosbox rescue, I’ve cleaned up the Frontier Elite & First Encounters images so they work now!

GLFrontier

FWIW I was checking links, and Tom’s site has moved to

http://tom.noflag.org.uk/glfrontier.html, which of course itself is now gone.  However with a lot of leg work, I did manage to snag the source to a few versions, and put them onto my CVS server, linked here: on unix.superglobalmegacorp.com.  And of course you can replicate it via CVS.

As mentioned over here, the steps basically are:

cvs -d:pserver:[email protected]:/frontvm login
cvs -d:pserver:[email protected]:/frontvm checkout frontvm
cvs -d:pserver:[email protected]:/frontvm log -h | grep -P '^\t' | awk '{print $1}' | sort|uniq| sed -e 's/://g'

With the last step showing you the various commit levels….
In this case they are:

  • frontvm-20040517
  • frontvm2-20061120
  • frontvm3-20060613
  • frontvm3-20060623

So to checkout the first and oldest code I’ve found, you would execute:

cvs -d:pserver:[email protected]:/frontvm checkout -r frontvm-20040517 frontvm

And there you go.

The Frontier wiki is still here.

Frontier Elite II for NeXTSTEP

Well I couldn’t resist. Currently there is no keyboard input, but after hacking the ObjectiveC from UAE, I was able to get GLFrontier to compile and run it’s intoduction under NeXTSTEP 3.3 on VirtualBOX…

I guess I’ll have to break down and order some new hard disks, and a PCI video card to rebuild me a whitebox.

In the meantime, here is a two bit picture:

Image of Frontier Elite II on NeXTSTEP 3.3

Amiga Days

Do you remember the Commodore Amiga?

I certainly do!

While I was busy fiddling with my Commodore 64, a friend of mine got an Amiga in high school. The 64 was cool, but I was simply blown away by the Amiga. To say there was a gulf between the 8 bit machine, and the quasi 32/16 bit machine would be a massive understatement. His Amiga 2000 could do all kinds of neat things, from talk, run IBM XT software at 100% speed via a “bridge board”, not to mention play super snazzy games. It took me a few years to save up to buy my very own Amiga 500, and once I was ready I didn’t have enough money for a bus ride home, so I walked the FIVE miles home toting my Amiga! I was so happy to say the least!! (At least it was summer, it was flat, and there weren’t any tropical waves/hurricanes around…)

While there are a few emulation alternatives for running the old m68000 software on all kinds of machines, I’m going to talk about AROS today.

AROS is to AmigaDOS what Wine is to Windows. Once it became clear that Commodore was going to die, and that AmigaDOS and the Amiga were lost a few brave people decided that they had to take matters into their own hands. Sadly there was lots of in fighting, a tradition of the comp.sys.amiga.advocacy news group where some people get too tied into little details and let little things (like the rise of Microsoft Windows) pass them by. At any rate, Aaron Digulla knuckled down, and start to write a bug for bug clone of AmigaDOS 3.1 in C to run on the IBM PC. The result of which is AROS. It currently will either run hosted on Linux/NetBSD or natively on the i386. There is a port to the Amd64 undergoing right now. AROS even has SDL support.

So this got me thinking..

What if I were to remove all the OpenGL calls from GLFrontier, and ran it as a strictly 2d app on AROS?

So I took the first step, and I trimmed out the OpenGL support from Tom’s fix of Frontier, so it’s completely SDL 2d friendly, and cross compiled it to AROS. I built the first pass on MinGW, and got frame rates of upwards of 1000 on Vista 64!

Now for the fun part of building an AROS version. While there is now a native GCC for AROS it cannot compile the assembly listing from GLFrontier.. I suspect it’s a heap overflow. This means you have to cross compile. I have cygwin installed in a Windows 2000 VM I use with Virtual PC 2007. I’m not sure if cygwin installs on Vista, let alone Vista 64, however I do suspect it MAY have issues… I keep my dev stuff in a VM so I can move it around without losing my settings.

I downloaded and unpacked the following files into my cygwin installation:

i386-aros-cross-gcc-3.3.1-cygwin.zip

libsdl.a

And the SDL include directory from cygwin.. I think its SDL version 1.2

I did have to find all the ‘exe’ files and make sure they were chmoded +x as the compiler would not run (chmod +x /usr/local/bin/exe /usr/local/i386-aros/bin/ /usr/local/lib/gcc-lib/i386-aros/3.3.1/*exe ). Once you are ready you should be able to build files with

i386-aros-gcc

I’m not sure how to build stripped files, but I suspect it’s out there somewhere. At any rate, I did this to compile my SDL 2d version of FrontierGL:

$ cd as68k

$ make
gcc -O2 -g -Wall -c -o output.o output.c
gcc -O2 -g -Wall -c -o output_c.o output_c.c
gcc -O2 -g -Wall -c -o output_i386.o output_i386.c
output_i386.c:981:1: warning: “_S” redefined
In file included from output_i386.c:6:
/usr/include/ctype.h:35:1: warning: this is the location of the previous definition
output_i386.c: In function x_loadea':
output_i386.c:1373: warning: 'out_reg' might be used uninitialized in this function
output_i386.c: In function
x_loadval’:
output_i386.c:1474: warning: ‘reg3’ might be used uninitialized in this function
output_i386.c:1474: warning: ‘out_reg’ might be used uninitialized in this function
gcc -O2 -g -Wall -c -o as68k.o as68k.c
as68k.c: In function `asm_pass1′:
as68k.c:663: warning: ‘size’ might be used uninitialized in this function
as68k.c:671: warning: ‘coutput_label’ might be used uninitialized in this function
gcc -O2 -g -Wall -c -o dict.o dict.c
gcc -O2 -g -Wall output.o output_c.o output_i386.o as68k.o dict.o -o as68k

$ cd ..

$ as68k/as68k.exe –output-i386 fe2.s
Pass 1
Pass 2
Done! 539337 bytes and 759 relocations.

$ i386-aros-gcc -c fe2.s.S

$ i386-aros-gcc -O2 -I /usr/local/i386-aros/sys-include/sdl -c audio.c
audio.c: In function Audio_Init':
audio.c:334: warning: passing arg 5 of
SDL_LoadWAV_RW’ from incompatible pointer type

$ cd src

$ i386-aros-gcc -O2 -I /usr/local/i386-aros/sys-include/sdl -c hostcall.c

$ i386-aros-gcc -O2 -I /usr/local/i386-aros/sys-include/sdl -c input.c

$ i386-aros-gcc -O2 -I /usr/local/i386-aros/sys-include/sdl -c keymap.c

$ i386-aros-gcc -O2 -I /usr/local/i386-aros/sys-include/sdl -c main.c

$ i386-aros-gcc -O2 -I /usr/local/i386-aros/sys-include/sdl -c screen.c
screen.c: In function `draw_control_panel’:
screen.c:274: warning: assignment makes integer from pointer without a cast

$ i386-aros-gcc -O2 -I /usr/local/i386-aros/sys-include/sdl -c shortcut.c

$ i386-aros-gcc *.o ../fe2.s.o -lsdl -o ../frontier

$ cd ..

$ file frontier
frontier: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped

$ i386-aros-size frontier
text data bss dec hex filename
2580672 2036 1422076 4004784 3d1bb0 frontier

*REMEMBER as68k has to actually run on the host machine, so it needs to be native, you cannot use a cross compiler for that. However you do cross compile it’s output.

Naturally you’ll now want to run your exe!

For testing the binaries you’ll need some kind of Aros system, I recommend WinAROS, it’s a pre-built Qemu package, so the disk will work on all kinds of platforms. You can download it here: WinAros Developer

This is a pretty snazzy setup, I recommend booting into a 32bit depth display option, however you will want to modify the default script to look like this at the last line:

qemu.exe -L . -m 256 -localtime -boot c -hda WinArosHD.img -no-kqemu -net nic -net user

The next thing you’ll want to do is enable the networking. I don’t know why it’s disabled by default, but with a few moments in the CLI, and edit you can have it running:

To get the network running you have to go into Extras:Networking/Stacks/AROSTCP/db and edit static-routes, netbd-myhost, and interfaces.

First edit interfaces and uncomment the line that has device prm-rtl8029 and change the IP to 10.0.2.15

Second edit netbd-myhost and make it look like this:
HOST 10.0.2.15 arosbox.arosnet arosbox
DOMAIN arosnet 10.0.2.
NAMESERVER 10.0.2.3

Third edit static-routes and change the address to 10.0.2.2

Last add the following line to your user-startup
Execute Extras:Networking/Stacks/AROSTCP/S/startnet.

Now reboot. Open a shell and verify that you have a connection with “ifconfig -a”
You can also try to ping a website, but you might not get any return packets because of QEMU’s built in firewall. You should at least see the ip address for the site you ping. Or ping 10.0.2.2 to make sure you network is communicating with Qemu.

Now for the final moment, put your exe on a web server, and simply use wget to get it! I’d recommend zipping up your work directory, so it includes the ‘bin’ file, and the structure that GLFrontier expects. I like the zip file format as WinAROS includes unzip.

I do the following from AROS

Wget http://192.168.1.10/front.zip
Unzip front.zip

It’s that easy! Now you can either ‘cd’ or click on your frontier, and away it should go!

The video is a bit wonky in that it seems to only work in 8 bit or 24bit depths. So far I’ve only tested this in WinArosDeveloper.

It actually works, the keyboard is buggy as hell, but you can play with the mouse. The first key code seems to work, then it gets stuck, so I recommend the ‘enter’ key so you can thrust…

I’ve published my zip up to The AROS Archives with any luck when it’s there I’ll update it with a link to it. In the mean time, I’ll provide a dump of the screen.c that I fixed to remove the OpenGL support. Naturally blogspot will screw up the formatting, however it should work…

#include
#include “main.h”
#include “../m68000.h”
#include “screen.h”

/* new stuff */
enum RENDERERS use_renderer = R_OLD;
int len_main_palette;
unsigned short MainPalette[256];
unsigned short CtrlPalette[16];
int fe2_bgcol;
int mouse_shown = 0;
unsigned long logscreen, logscreen2, physcreen, physcreen2;
unsigned long VideoBase;
unsigned char *VideoRaster;
unsigned int MainRGBPalette[256];
unsigned int CtrlRGBPalette[16];
int screen_w=320;
int screen_h=200;
BOOL bGrabMouse = FALSE;
BOOL bInFullScreen = FALSE;
SDL_Surface *sdlscrn;

static const unsigned char font_bmp[] = {
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x80,0x80,0x80,0x80,0x80,0x0,
0x80,0x0,0x0,0x2,0xa0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x4,0x0,0x50,
0xf8,0x50,0x50,0xf8,0x50,0x0,0x0,0x6,0x20,0xf0,0xa0,0xa0,0xa0,0xa0,0xf0,0x20,
0x0,0x5,0x0,0xc8,0xd8,0x30,0x60,0xd8,0x98,0x0,0x0,0x6,0xa0,0x0,0xe0,0xa0,
0xa0,0xa0,0xe0,0x0,0x0,0x4,0x80,0x0,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0x4,0xe0,0x20,0x20,0xe0,0x80,0x0,0x80,0x0,0x0,0x4,
0xfe,0x82,0xba,0xa2,0xba,0x82,0xfe,0x0,0x0,0x8,0xf0,0x90,0x90,0x90,0xf0,0x90,
0x90,0x0,0x0,0x5,0xf0,0x90,0x90,0xf8,0x88,0x88,0xf8,0x0,0x0,0x6,0xe0,0x80,
0x80,0x80,0x80,0x80,0xe0,0x0,0x0,0x4,0xf8,0x48,0x48,0x48,0x48,0x48,0xf8,0x0,
0x0,0x6,0xf0,0x80,0x80,0xe0,0x80,0x80,0xf0,0x0,0x0,0x5,0xf0,0x80,0x80,0xe0,
0x80,0x80,0x80,0x0,0x0,0x4,0xf0,0x80,0x80,0x80,0xb0,0x90,0xf0,0x0,0x0,0x5,
0x90,0x90,0x90,0xf0,0x90,0x90,0x90,0x0,0x0,0x5,0xe0,0x40,0x40,0x40,0x40,0x40,
0xe0,0x0,0x0,0x4,0xf0,0x20,0x20,0x20,0x20,0x20,0xe0,0x0,0x0,0x4,0x90,0xb0,
0xe0,0xc0,0xe0,0xb0,0x90,0x0,0x0,0x5,0x80,0x80,0x80,0x80,0x80,0x80,0xe0,0x0,
0x0,0x4,0x88,0xd8,0xf8,0xa8,0x88,0x88,0x88,0x0,0x0,0x6,0x90,0xd0,0xf0,0xb0,
0x90,0x90,0x90,0x0,0x0,0x5,0xf0,0x90,0x90,0x90,0x90,0x90,0xf0,0x0,0x0,0x5,
0xf0,0x90,0x90,0xf0,0x80,0x80,0x80,0x0,0x0,0x5,0xf0,0x90,0x90,0x90,0x90,0xb0,
0xf0,0x18,0x0,0x5,0xf0,0x90,0x90,0xf0,0xe0,0xb0,0x90,0x0,0x0,0x5,0xf0,0x80,
0x80,0xf0,0x10,0x10,0xf0,0x0,0x0,0x5,0xe0,0x40,0x40,0x40,0x40,0x40,0x40,0x0,
0x0,0x3,0x90,0x90,0x90,0x90,0x90,0x90,0xf0,0x0,0x0,0x5,0x90,0x90,0x90,0xb0,
0xe0,0xc0,0x80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
0x0,0x4,0x40,0xa0,0x40,0x40,0x40,0x40,0x40,0x0,0x0,0x4,0x40,0xa0,0xe0,0x20,
0xe0,0xa0,0xe0,0x0,0x0,0x4,0x40,0xa0,0xe0,0xa0,0xa0,0xa0,0xe0,0x0,0x0,0x4,
0x40,0xa0,0xe0,0xa0,0xe0,0x80,0xe0,0x0,0x0,0x4,0xe0,0x0,0xa0,0xa0,0xa0,0xa0,
0xe0,0x0,0x0,0x4,0xc0,0x0,0xe0,0x20,0xe0,0xa0,0xe0,0x0,0x0,0x4,0xe0,0xa0,
0xa0,0xa0,0xe0,0xa0,0xa0,0x0,0x0,0x4,0xc0,0xa0,0xa0,0xc0,0xa0,0xa0,0xc0,0x0,
0x0,0x4,0xe0,0x80,0x80,0x80,0x80,0x80,0xe0,0x0,0x0,0x4,0xc0,0xa0,0xa0,0xa0,
0xa0,0xa0,0xc0,0x0,0x0,0x4,0xe0,0x80,0x80,0xe0,0x80,0x80,0xe0,0x0,0x0,0x4,
0xe0,0x80,0x80,0xe0,0x80,0x80,0x80,0x0,0x0,0x4
};

static inline void read_m68k_vertex (int st_vptr, int output[3])
{
output[0] = STMemory_ReadLong (st_vptr);
output[1] = STMemory_ReadLong (st_vptr+4);
output[2] = -STMemory_ReadLong (st_vptr+8);
}

struct ZNode {
unsigned int z;
struct ZNode *less, *more;
void *data;
};

#define MAX_OBJ_DATA (2<<17)
static unsigned char obj_data_area[MAX_OBJ_DATA];
static int obj_data_pos;
#define MAX_ZNODES 1000
static struct ZNode znode_buf[MAX_ZNODES];
static int znode_buf_pos;
static struct ZNode *znode_start;
static struct ZNode *znode_cur;

enum NuPrimitive {
NU_END,
NU_TRIANGLE,
NU_QUAD,
NU_LINE,
NU_BEZIER_LINE,
NU_TEARDROP,
NU_COMPLEX_SNEXT,
NU_COMPLEX_START,
NU_COMPLEX_END,
NU_COMPLEX_INNER,
NU_COMPLEX_BEZIER,
NU_TWINKLYCIRCLE,
NU_PLANET,
NU_CIRCLE,
NU_CYLINDER,
NU_BLOB,
NU_OVALTHINGY,
NU_POINT,
NU_2DLINE,
NU_MAX
};

#define MAX_QUEUED_STRINGS 200
struct QueuedString {
int x, y, col;
unsigned char str[64];
} queued_strings[MAX_QUEUED_STRINGS];
int queued_string_pos;
static bool no_znodes_kthx;

/*********PROTOTYPES****************/
static void _BuildRGBPalette (unsigned int *rgb, unsigned short *st, int len);
static void draw_3dview (struct ZNode *node);
static int DrawChar (int col, int xoffset, char *scrline, int chr);
static void Nu_DrawPrimitive (void *data);
static inline int znode_rdlong (void **data);
static void add_node (struct ZNode **node, unsigned int zval);
static void znode_insert (struct ZNode *node, unsigned int zval);
static inline void end_node ();
static inline void znode_databegin ();
static inline void znode_wrlong (int val);

int DrawStr (int xpos, int ypos, int col, unsigned char *str, bool shadowed)
{
int x, y, chr;
char *screen;

x = xpos;
y = ypos;

if ((y > 192) || (y<0)) return x;
set_line:
screen = LOGSCREEN2;
screen += SCREENBYTES_LINE * y;

while (*str) {
chr = *(str++);

if (chr < 0x1e) {
if (chr == ‘\r’) {
y += 10;
x = xpos;
goto set_line;
}
else if (chr == 1) col = *(str++);
continue;
} else if (chr == 0x1e) {
/* read new xpos */
x = *(str++);
x *= 2;
continue;
} else if (chr < 0x20) {
/* Read new position */
x = *(str++);
x *= 2;
y = *(str++);
goto set_line;
}

//if (x > 316) continue;

if (shadowed) {
DrawChar (0, x+1, screen+SCREENBYTES_LINE, chr-0x20);
}
x = DrawChar (col, x, screen, chr-0x20);
}

return x;
printf (“DrawStr [%s]\n”,str);
return 0;
}

void Nu_PutColoredPoint()
{}

void Nu_ComplexSNext()
{}
void Nu_DrawComplexSNext()
{}

void Nu_DrawComplexStart()
{}
void Nu_DrawComplexEnd()
{}

void Nu_ComplexStartInner()
{}
void Nu_DrawComplexStartInner()
{}
void Nu_ComplexBezier()
{}
void Nu_DrawComplexBezier()
{}

void draw_control_panel()
{
unsigned int *pal;
// Lock surface if needed
if (SDL_MUSTLOCK(sdlscrn))
if (SDL_LockSurface(sdlscrn) < 0)
return;

// Declare a couple of variables
int y, x, yofs, ofs;

// Draw to screen
yofs = 0;
pal=MainRGBPalette;
for (y = 0; y < screen_h; y++)
{
if(y==168)pal=CtrlRGBPalette; //bottom has differnet palette
for (x = 0, ofs = yofs; x < screen_w; x++, ofs++)
{
//((unsigned int*)sdlscrn->pixels)[ofs] = pal[VideoRaster[ofs]];

switch (sdlscrn->format->BytesPerPixel)
{
case 1: // 8-bpp
{
Uint8 *bufp;
bufp = (Uint8 *)sdlscrn->pixels + y*sdlscrn->pitch + x;
*bufp =(Uint8*) pal[VideoRaster[ofs]];
}
break;
case 2: // 15-bpp or 16-bpp
{
Uint16 *bufp;
bufp = (Uint16 *)sdlscrn->pixels + y*sdlscrn->pitch/2 + x;
*bufp = pal[VideoRaster[ofs]];
}
break;
case 3: // 24-bpp mode, usually not used
{
Uint8 *bufp;
bufp = (Uint8 *)sdlscrn->pixels + y*sdlscrn->pitch + x * 3;
if(SDL_BYTEORDER == SDL_LIL_ENDIAN)
{
bufp[0] = pal[VideoRaster[ofs]];
bufp[1] = pal[VideoRaster[ofs]] >> 8;
bufp[2] = pal[VideoRaster[ofs]] >> 16;
} else {
bufp[2] = pal[VideoRaster[ofs]];
bufp[1] = pal[VideoRaster[ofs]] >> 8;
bufp[0] = pal[VideoRaster[ofs]] >> 16;
}
}
break;
case 4: // 32-bpp
{
Uint32 *bufp;
bufp = (Uint32 *)sdlscrn->pixels + y*sdlscrn->pitch/4 + x;
*bufp = pal[VideoRaster[ofs]];
}
break;
}

}
//yofs += sdlscrn->pitch / 4;
yofs += sdlscrn->pitch / sdlscrn->format->BytesPerPixel;
}

// Unlock if needed
if (SDL_MUSTLOCK(sdlscrn))
SDL_UnlockSurface(sdlscrn);

// Tell SDL to update the whole screen
SDL_UpdateRect(sdlscrn, 0, 0, screen_w, screen_h);

//printf(“draw_control_panel\n”);
}

void Nu_DrawScreen()
{
_BuildRGBPalette (MainRGBPalette, MainPalette, len_main_palette);
_BuildRGBPalette (CtrlRGBPalette, CtrlPalette, 16);
//printf (“Frame: %d znodex.\n”,znode_buf_pos);
//draw_3dview (znode_start);
if (mouse_shown) {
SDL_ShowCursor (SDL_ENABLE);
mouse_shown = 0;
} else {
SDL_ShowCursor (SDL_DISABLE);
}
draw_control_panel();
//set_main_viewport();

//printf(“Nu_DrawScreen\n”);

}

void Nu_PutBezierLine()
{}
void Nu_DrawBezierLine()
{}

void Nu_3DViewInit()
{
queued_string_pos = 0;
//printf (“3dviewinit()\n”);
znode_buf_pos = 0;
//printf (“%d bytes object data\n”, obj_data_pos);
obj_data_pos = 0;

znode_start = NULL;
znode_cur = NULL;
no_znodes_kthx = FALSE;
}
void Nu_InsertZNode()
{
unsigned int zval = GetReg (4);
if (use_renderer == R_OLD) return;
if (no_znodes_kthx) return;
if (znode_start == NULL) {
add_node (&znode_start, zval);
} else {
znode_insert (znode_start, zval);
}
}

void Nu_PutCircle()
{}
void Nu_DrawCircle()
{}

void Nu_PutOval()
{}
void Nu_DrawOval()
{}

void Nu_PutCylinder()
{}
void Nu_DrawCylinder()
{}

void Nu_QueueDrawStr()
{}
void Nu_IsGLRenderer()
{
SetReg(0,0);
}

void Nu_PutPlanet()
{}
void Nu_DrawPlanet()
{}

void Nu_Put2Line()
{}
void Nu_Draw2Line()
{}

void Nu_PutQuad()
{}
void Nu_DrawQuad()
{}

void Nu_GLClearArea()
{}
void Nu_PutBlob()
{use_renderer=R_OLD;}
void Nu_DrawBlob()
{}

void Nu_Put2DLine()
{}
void Nu_Draw2DLine()
{}

void Nu_PutLine()
{}
void Nu_DrawLine()
{}

void Nu_UnInit()
{}

void Nu_PutTeardrop()
{}
void Nu_DrawTeardrop()
{}

void Nu_PutPoint()
{
printf(“Nu_PutPoint\n”);
}
void Nu_DrawPoint()
{}

void Nu_PutTwinklyCircle()
{}
void Nu_DrawTwinklyCircle()
{}

void Nu_ComplexStart()
{}

void Nu_PutTriangle()
{}
void Nu_DrawTriangle()
{}

void Nu_ComplexSBegin()
{}

void Nu_ComplexEnd()
{}

void Nu_32ViewInit()
{}

void Screen_ToggleRenderer ()
{
use_renderer = R_OLD;
}

void change_vidmode(void);

void Screen_Init(void)
{
change_vidmode();
SDL_WM_SetCaption(PROG_NAME, “Frontier”);
SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_ENABLE);
SDL_EventState(SDL_MOUSEBUTTONUP, SDL_ENABLE);
SDL_ShowCursor(SDL_ENABLE);
use_renderer=R_OLD;
printf(“Screen_Init\n”);
}

void change_vidmode (void)
{
const SDL_VideoInfo *info = NULL;
int modes;

info = SDL_GetVideoInfo ();

assert (info != NULL);

modes = SDL_SWSURFACE;// SDL_ANYFORMAT | (bInFullScreen ? SDL_FULLSCREEN : 0 );

if ((sdlscrn = SDL_SetVideoMode (screen_w, screen_h,
info->vfmt->BitsPerPixel, modes)) == 0) {
fprintf (stderr, “Video mode set failed: %s\n”, SDL_GetError ());
SDL_Quit ();
exit (-1);
}
printf(“change_vidmode %d x %d %d deep\n”,screen_w,screen_h,info->vfmt->BitsPerPixel);
}

void Screen_UnInit(void)
{}
void Screen_ToggleFullScreen()
{
}

static void _BuildRGBPalette (unsigned int *rgb, unsigned short *st, int len)
{
int i;
int st_col, r, g, b;

for (i=0; i>4;
rgb[i] = 0xff000000 | (b<<16) | (g<<8) | (r);
}
}

static int DrawChar (int col, int xoffset, char *scrline, int chr)
{
const char *font_pos;
char *pix;
int i;

font_pos = font_bmp;
font_pos += (chr&0xff)*10;
scrline += xoffset;

if (xoffset < 0) {
font_pos += 9;
return xoffset + *font_pos;
}

for (i=0; i<8; i++, font_pos++, scrline += SCREENBYTES_LINE) {
pix = scrline;
if (xoffset > 319) continue;
if (*font_pos & 0x80) *pix = col;
pix++;
if (xoffset+1 > 319) continue;
if (*font_pos & 0x40) *pix = col;
pix++;
if (xoffset+2 > 319) continue;
if (*font_pos & 0x20) *pix = col;
pix++;
if (xoffset+3 > 319) continue;
if (*font_pos & 0x10) *pix = col;
pix++;
if (xoffset+4 > 319) continue;
if (*font_pos & 0x8) *pix = col;
pix++;
if (xoffset+5 > 319) continue;
if (*font_pos & 0x4) *pix = col;
pix++;
if (xoffset+6 > 319) continue;
if (*font_pos & 0x2) *pix = col;
pix++;
if (xoffset+7 > 319) continue;
if (*font_pos & 0x1) *pix = col;
}
/* width of character */
font_pos++;
i = *font_pos;
return xoffset + i;
}
/*
* znode_start is the head of a btree of znodes, each with a linked list
* of GL display lists to draw (in list order).
*
* Draw this crap starting from biggest value znodes.
*/
static void draw_3dview (struct ZNode *node)
{
if (node == NULL) return;
if (node->more) draw_3dview (node->more);

if (use_renderer) {
printf (“Z=%d “, node->z);
Nu_DrawPrimitive (node->data);
}

if (node->less) draw_3dview (node->less);
printf(“draw_3dview\n”);
}

typedef void (*NU_DRAWFUNC) (void **);
NU_DRAWFUNC nu_drawfuncs[NU_MAX] = {
NULL,
&Nu_DrawTriangle,
&Nu_DrawQuad,
&Nu_DrawLine,
&Nu_DrawBezierLine,
&Nu_DrawTeardrop,
&Nu_DrawComplexSNext, // 6
&Nu_DrawComplexStart,
&Nu_DrawComplexEnd,
&Nu_DrawComplexStartInner, // 9
&Nu_DrawComplexBezier,
&Nu_DrawTwinklyCircle,
&Nu_DrawPlanet,
&Nu_DrawCircle,
&Nu_DrawCylinder,
&Nu_DrawBlob,
&Nu_DrawOval,
&Nu_DrawPoint,
&Nu_Draw2DLine
};

static void Nu_DrawPrimitive (void *data)
{
int fnum;

for (;;) {
fnum = znode_rdlong (&data);
//fprintf (stderr, “%d “, fnum);
if (!fnum) return;
nu_drawfuncs[fnum] (&data);
}
}

static inline int znode_rdlong (void **data)
{
int val = *((int*)(*data));
(*data) += 4;
return val;
}

static void add_node (struct ZNode **node, unsigned int zval)
{
assert (znode_buf_pos < MAX_ZNODES);
/* end previous znode display list!!!!!!! */
if (znode_cur) end_node ();

*node = znode_cur = &znode_buf[znode_buf_pos++];
znode_cur->z = zval;
znode_cur->less = NULL;
znode_cur->more = NULL;
znode_databegin ();
}

static inline void end_node ()
{
znode_wrlong (0);
}

static void znode_insert (struct ZNode *node, unsigned int zval)
{
if (zval > node->z) {
if (node->more) {
znode_insert (node->more, zval);
} else {
add_node (&node->more, zval);
}
} else {
if (node->less) {
znode_insert (node->less, zval);
} else {
add_node (&node->less, zval);
}
}
}

static inline void znode_databegin ()
{
znode_cur->data = &obj_data_area[obj_data_pos];
}

static inline void znode_wrlong (int val)
{
*((int*)(obj_data_area+obj_data_pos)) = val;
obj_data_pos+=4;
}

GLFrontier

Frontier Elite

GLFrontier

While on the topic of Frontier Elite this week, I was wondering if they by any chance ever released the source code… It appears not, however there were largely two versions the original being in 68000 assembly then a port to 80286 real mode ASM.
But then I found this:
Tom Morton has taken the Atari ST version of Frontier, and removed the hardware access from the assembly, then tweaked a m68k assembler to either output in C or i386 asm… So he’s basically reversed a copy of Frontier to allow it to run natively!
And he’s added OpenGL support to some degree! It’s VERY cool!
At a minimum I bet there are people out there that would LOVE this guys programs to convert m68k assembly listings into either C or i386 asm. Or a chance to hack the ‘source’ like crazy.
I’ve also come across this great site http://www.jongware.com/galaxy1.html which goes over various algorithms from the game.