Commodore 64 · 1985 · Novagen Software

Mercenary

This minisite was contributed by air. 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…
  • ← → ↑ ↓ the joystick
  • F or right Ctrl fire
  • 1…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. Smooth motion draws the view at the screen's own frame rate, sliding it from each of the game's pictures to the next (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 car (object 2) and its land Dart (object 5)Along the roads of the game's road table, keeping left, from one place to another at up to the car'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, Palyar diamonds, jets 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 Palyar diamondsDrop 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, checked against the original at every pass

Nothing on this page emulates 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.

How it was checked

The original code runs in a 6502 simulator beside the port, from the same saved moment and with the same keys and joystick. At the start of every pass all 64 KB are compared, and the video chip's and sound chip's registers too. Only the stack and three bytes of scratch are left out.

SessionsPassesResult
The landing site: buying and boarding the Dart, taking off, walking, turning, carrying, the lift down4,140identical at every pass
Flying: cruising, climbing, turning, rolling on the ground, the Colony Craft's deck, falling from it, the descent2,700identical at every pass
Underground: doors, a locked door, the transporter booths, a dark room lit, the mirror rooms, walking and turning2,300identical at every pass but two (below)
Attacks: near, far and on foot, the hired ship, shooting a building, the brother-in-law's ship2,100identical at every pass

Each group of routines was first tested alone against the game's code: every square of the road table, every entry of the row fills, thousands of random states for each routine that projects, clips or draws.

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, from its code in the simulator: 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 were fitted on the original: 69,569 stretches of the main loop from fifteen sessions, timed on the simulator and counted on the port. For a whole pass the fit is within about 1 % nine times in ten, and within 2 % on sessions it was not fitted on.

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

Smooth motion

The C64 redraws the view once a pass: about twelve times a second in a room, five to eight times with the city in view. With Smooth motion on, the page draws the view at the screen's own rate, 60, 120 or 144 times a second, and the game underneath does not change.

This works because every picture the C64 shows is a pass behind the game. While a picture is on show, the next one is being drawn, from where the game moved you at the end of the pass before. So the page knows where the next picture looks from before it appears. It draws the picture on show from an eye part of the way there, and moves each craft, car and missile part of the way to where the game has already put it. By the time the C64 would flip to the next picture, the view has arrived at it.

How long a picture stays on show depends on how much the next pass draws, so the page cannot know it in advance. It follows the program through its pass and expects the rest to take as long as it did last time. One kind of pass runs much longer: the one that rebuilds the list of roads in view, when you fly into a new square or a new band of height. The page sees that coming from your course and slows the glide for it, where the C64 holds the picture.

What the game changes at once stays sudden: a door, a lift, boarding or leaving a craft. A craft's turn and a building's rotor keep the game's steps, since only positions slide. Without native resolution the page draws the view in the C64's pixels with its own lines and fill, which match the game's bitmaps to within a pixel.

Session, with smooth motion drawing at 144 frames a secondPassesThe game's memory
Walking and turning at the landing site1,221identical at every pass to a run without it
Boarding the Dart, climbing, banking, under attack554identical at every pass
Both again with Targ Traffic on1,221 and 519identical at every pass

04 · Differences

What differs from a C64