1985 · Novagen Software

Mercenary

This minisite was contributed by air, unorig. It’s currently claimed by air who is editing it to reach a Gold tier standard.

The whole of Targ, playable in the browser: the city, the wasteland outside it, the Colony Craft far above, all 174 rooms underground and every craft, ported routine by routine from the game's 6502 code and checked against the original pass by pass.

Loading the game's bytes…
  • Tap a key in this list to press it in the game. Shift stays down for the key you tap after it.
  • ← → ↑ ↓ the joystick
  • F fire
  • 1 2 3 4 5 6 7 8 9 0 thrust
  • Shift + digit reverse
  • = − thrust up and down, Space stop
  • T take, D drop, B board, L leave
  • E the lift, Y yes
  • Esc pause (CTRL + RETURN)
  • CTRL + Q, CTRL + S and CTRL + L: the buttons
X --:--:-- · Y --:--:-- · H --:--:--

The game's own screen, drawn from the port's memory each frame the way the video chip would: the view's two bitmaps, the panel in the game's character set, the gun sight sprite. Native resolution draws the same view (the same edges, dots and horizon, from the same positions) as sharp lines at the screen's own resolution. Fast CPU plays the game as a C64 with a much faster processor would: a new frame from the game's own code every video frame, at the C64's pace, or the game's own where the C64 falls behind it (section 03).

01 · Mod

Targ Traffic: traffic on the roads and in the sky

Targ's roads are empty and its sky nearly so. This mod fills them with cars and craft the game already knows how to draw. Each one belongs to the Palyars or the Mechanoids, and shooting one brings that side's attack ship after you.

What moves

TrafficWhere it goes
44 cars: the game's Hovercar (object 2) and its Sprintcar (object 5)Along the roads of the game's road table, keeping left, from one place to another at up to the Hovercar's own top speed: SPEED 825 on the panel, which shows 100/256 of the units a pass, so 2,112 units a pass. They slow for corners, queue behind the car in front, stop when you stand in the road, and pull in to the kerb when they arrive.
14 craft: Darts, Hexapods, Concord 111s and CHEESEsFrom a stand at the airbase (08-08) or Jordan Airport (12-13), or from a lift, to another one. They roll and take off from the runways, rise out of the lifts and sink back into them, and cruise at a third to a half of the craft's top speed in the game's table.
4 HexapodsDrop from the Colony Craft's deck, fly a short way below it and dock again.
1 Palyar DartFlies in formation with the brother-in-law's new ship, 700 units to its west, down column 00. Shoot his ship and the escort breaks away and joins the traffic.

Cars head for the Coach and Horses (15-02), for the other named places, or anywhere on the road network. Every so often it is match day: most of the cars that set off then drive to Bosher Stadium (08-07) and park there until the game is over.

Shooting one

Your missile hits a car or a craft by the rule it hits the attack ship with: within 1,024 units on every axis, tested once a pass. It samples its path every 4,096 units, so a straight shot can pass through a small target, in the mod as in the game. Benson then prints YOU HAVE JUST DESTROYED, A PALYAR CRAFT or A MECHANOID CRAFT, and the owner's line from the landmarks' scripts: PALYAR SHIP ATTACKING or MECHANOID SHIP ATTACK. The game's own attack ship follows.

How it joins the game

02 · The port

Every routine of the game, written again in JavaScript

This page does not emulate a 6502. The game's 294 routines are written out in JavaScript, one function each, named by the listing's labels, and run on the game's own 64 KB of memory.

The page loads that memory from the listing, the same bytes the Source code tab shows, and puts back the original disk's first message (the listing was made from a copy that says ABC UNLIMITED in the same 26 bytes). From then on the port reads and writes the game's variables where the game keeps them, draws into the game's two bitmaps, and runs the game's event scripts, messages and save files as bytes. Every value the game computes, the port computes with the same arithmetic: its truncating floating point, its sine tables, and the operands its code rewrites in itself.

Where the original depends on its interrupts

The port runs the raster interrupts between the steps of a pass; the C64 runs them wherever they fall. Two routines in the game give different results depending on where, and the port shows the case where the interrupt came after the step.

The game's view with its lower two thirds white instead of green ground, while Benson prints YOU HAVE 9000 CREDITS
The game's own frame: Benson was printing a figure (YOU HAVE 9000 CREDITS) while the view was filled with ground, and the fill went on with 0 from the row the interrupt fell on.

03 · Speed

It runs at the C64's speed, pass for pass

The game moves you a fixed step each pass of its main loop, and a pass takes as long as the drawing does: about four frames in a room, six to ten with the city in view. A port that ran as fast as the browser can would be a different game.

So the page keeps a PAL machine's clock: 312 lines of 63 cycles, 50.12 frames a second, with the raster interrupts on their lines. The port does not execute instructions, so it cannot count their cycles. Instead each routine it calls adds a fixed number of cycles, that routine's own, and each pixel drawn, row filled and far dot plotted adds its cost. The costs come from the game's own timings, and for a whole pass the page is within about 1 % of the C64 nine times in ten.

SceneFramesPasses, originalPasses, this page
Standing at the landing site5003939
Walking at the landing site5006262
Walking in a room4009191
Cruising in the Dart4005050
On the Colony Craft's deck4004948
The descent4004645

Fast CPU

With Fast CPU on, the page plays the game as a C64 with a much faster processor would. The main loop goes round once every video frame, 50 times a second, where the C64 manages four to twelve passes. Each pass draws a new frame into the game's own bitmaps, so every frame on screen is one the game drew.

A faster C64 would also be a faster game, since the game moves you a fixed step each pass. Fast CPU keeps the C64's pace instead. After each pass the page works out, from what that pass drew, how many frames the C64 would have taken over it, as its clock does for the C64 itself. That many of Fast CPU's passes stand for one of the C64's, and each takes its share of the step: of a walk, a turn, a climb, a missile's flight. The shares go through the game's own movement code and add up to the C64's step exactly, so the last of them ends where the C64's pass ends. A craft's bank, which the game sets once a pass from its rate of turn, moves to each new angle the same way, a share at a time, and so do Targ Traffic's cars and craft, which the mod moves once a pass.

Fast CPU follows the C64 down only as far as the pace the game itself plans for. The game brings the interstellar ship down in 780 passes, and its panel calls that 2 MINS: six and a half passes a second. Where the C64 takes longer over a pass, with many objects or much of the city in view, its processor has fallen behind the game, and a faster one would not. So Fast CPU holds each of the C64's passes to eight frames, 6.27 a second. Standing at the crash site, the C64 makes 5.05 passes a second and Fast CPU 6.25. Put seven keys down in front of you and the C64 slows to 3.60, while Fast CPU stays at 6.25. Walking north, where the C64 makes seven and a half, Fast CPU keeps its pace.

What the game counts in passes happens once for each of the C64's passes: the event scripts' next operation, the lifetimes of the missiles and the attack ship, a building's collapse, the damping of a craft's turn and speed, and a held = or −. What the game times by its clock keeps its time, since the raster interrupts still come 50.12 times a second on their lines: the panel's seconds, Benson's printing, the lift ride.

From the crash siteC64Fast CPU
Walking for 20 seconds13,120 units13,146 units
Turning on foot for 20 seconds1,632 steps of 1,024 to a turn2,022 steps
Flying the Dart level for 10 seconds48,990 units66,297 units
Passes a second, standing5.056.25
Passes a second, seven keys in view3.606.25
The panel's clock after 20 seconds1,002 frames1,001 frames
A turn key pressed to the view turning, on footabout 290 msabout 30 ms

The keys are read every frame, so the view answers in the next frame or the one after, and letting go stops you in the next. The C64 reads them once a pass, after drawing, so a move first shows in the next pass's view, up to two passes after the press. A press shorter than three frames is held for three, so that a pass reads it.

Some things change with the finer steps. What the game tests once a pass it now tests at each share of the move: whether your missile has struck a building, whether the attack ship's missile has reached you, whether you have walked into a door. The game's frames come at the C64's 50.12 a second: a display at 50 or 100 Hz shows each for the same time, and skips one about every eight seconds since it runs 0.25 % slower; at 60 Hz one frame in five stays up for two refreshes. Switched off, the game is the C64's again from where it stands.

04 · Differences

What differs from a C64