Article #1: Beginner's guide to programming front-ends

Author:
Article Version: 1.0
Skill Level: Beginner


Okay, I had some "problems" with this article. Though it should be basic, there was always the problem of letting it become "too" complicated. A basic article should provide you, the starting front-end author, with a good start, but yet not let it sound trivial or even ridiculous. I hope I could adjust this article rightly between a "good starter's guide" and "useless rubbish". Enjoy.

This tutorial will thus focus on the following topics:


Chaptor 1: A comparison of different development languages and environments

Well, this is a basic tutorial, so it should focus on languages that are easy to learn. Anyways, writing a front-end is an excellent way to learn programming. So basically all you have to do is pick your favorite, but if you are uncertain, here's a listing of the advantages/disadvantages of the most commonly used languages. You already need knowledge of basics like variables, data types, and such for understanding this listing.

Visual Basic is very easy to learn, and it is the most powerful BASIC dialect available. The major drawback is, though it now features a real compiler, programs compiled in VB still have to use a rather huge runtime DLL. So if your program doesn't need all of the functionality provided in the runtime library, you still have to deliver it with your program. Visual Basic is your best pick if you haven't got a clue about programming yet. The most current version is 6.0.

Delphi has an application development environment similar to VB. It is a bit more difficult to master than Visual Basic, but features more functionality (like an inline assembler). Delphi is based on the Borland C++ compiler engine, and produces efficient and fast code which rivals even Assembler, and also makes compact executables. It has true Object-Oriented Programming, so you can add new classes or components if you want. If you already have Visual Basic and basic programming knowledge, this might be a good choice.

C/C++ isn't the choice for the beginner. It is a bit more powerful than Delphi, adding things like custom operators, and it is a fast low-level language. It is the best interface to Windows though (but it isn't as forgiving as other languages with data types). C++ Builder might be the choice for you if you choose C/C++. It features the IDE known from Delphi, and is compatible with the Delphi Visual Component Library (VCL). In fact, C++Builder even features the Delphi compiler so you can add new components written in Delphi into C++Builder.

Back to introduction


Chapter 2: What a front-end is and how it basically works

Hmm, well you have chosen your language, but you still don't know what a front-end is? Okay, here's da help.

A front-end is basically a program that let's you make the use of another program (usually a commandline-based DOS program) easier. In our case, we are talking about front-ends for emulators (there are also front-ends for mp3-encoders, compression tools, and more). An emulator is a program that runs software made for another computer (like videogame consoles). It basically translates the code of the software (in our case called 'ROM images') that is in the executable format for another type of computer into appropiate actions/instruction on the target computer. Usually the emulators are DOS based and/or make heavy use of commandlines.

Command Lines can be quite a pain sometimes, if you have to quickly switch settings (to test the speed), or if you want to individually set the settings for each ROM. This is the point front-ends join in.

There are 2 types of front-ends:

Both types can either be multi-emulator front-ends (supporting many to unlimited emulators) or single-emulator front-ends.

For a start, a single-emulator front-end is easier. You can either choose an emulator-based or game-based front-end.

Back to introduction


Chapter 3: A basic front-end

What you'll already need to know:

  1. How to program in any given development language.
  2. How the emulator(s) that your front-end will support uses the command line parameters.
  3. What all the parameters your front-end will use are for and how they work.

I will use Delphi for this example, but Visual Basic and C++Builder work similarly. And Pascal was intended to be a language for learners so I'd say we follow Wirth's good ol' tradition :)

We will make the base for a front-end here. Don't expect it too be complete or advanced, it's just a start.

Step 1: Create an interface

If you are using either VB, Delphi or C++Builder, the first step is to create a nice interface. This interface should provide the user with all the settings necessary to adjust the emulator settings (resolution, frame skip, display options, sound options, and such).

Basically, for a command line based emulator, there are switches like -s for sound, or -v 5 for video mode. For boolean switches (meaning 2-state switches, which either can be set/enabled or not set/disabled... e.g. True or False), you might want to create a checkbox control which also has 2 states. For multi-state settings like video resolution, you might want to either use a list box control or a radio button group:

Create your controls accordingly to the different settings of an emulator. Name the controls accordingly, for example, you would name the checkbox control that sets the sound something liks "chkSoundEnabled".

Step 2: The inner workings

Next thing you have to do is the actual front-end functionality. This steps adds the actual execution code. This should be done shortly before the emulator is executed by the front-end. The front-end checks all settings and makes an appropiate command line out of it:

procedure ExecuteEmulator;
var
  commmandline: string;
begin
  commandline := 'ZSNES.EXE'; // 'ZSNES.EXE is the minimum command line

  if chkSoundEnabled.Checked then  // is the chkSoundEnabled Checkbox checked?
    commandline := commandline + ' -s';   // if the user selected "enable sound", add the -s parameter

  // set the videomode the user selected
  // check if lstVideoMode.ItemIndex is in the valid range. 
  // The ItemIndex holds the 0-based index of the currently selected list item in a list box

  if lstVideoMode.ItemIndex in [0..7] then
    commandline := commandline + ' -v ' + IntToStr(lstVideoMode.ItemIndex);

  // Do this with every other control/setting...

  ....

  // execute the commandline
  WinExec(PChar(commandline), SW_NORMAL);

end;

Step 3: Features to add

This would be a fronte-nd with basic functionality which can configure and launch the emulator. Now you can think of many features to add, features that would improve the front-end. Some suggestions:

Back to introduction


I hope this little guide will help you creating your first front-end. Stay tuned!

x-sykodad