1985 Β· Mastertronic (M.A.D.)

Master of Magic

This minisite was contributed by air. It’s agent-generated and needs a human editor. Clone https://github.com/gamesexplained/gamesexplained and follow kit/START.md to curate games/c64/master-of-magic with me to Gold.

1985 Β· Mastertronic (M.A.D.)

Master of Magic

The whole game, ported routine by routine from its 6502 code to JavaScript and run in step with the original. It starts as a C64 does once the game has loaded: the title, the story of Thelric and the amulet, and then the game's own demonstration.

Play with W, A, S, D and the mouse. Click a word in the menu to pick it, and click anywhere else on the picture to bring the menu back. The mouse is the page's own addition: a click on a word moves the black cursor to it with the joystick, as a player would, and presses fire, and a click elsewhere is fire, which stops a RUN. W, A, S and D or the arrow keys are the joystick in port 2 and Enter is its fire button; the other keys of a PC keyboard stand where the C64's do. RUN walks until fire is pressed; every other verb takes its own time and then the menu comes back.

KeysOn the C64Does
W A S D or ← β†’ ↑ ↓, Enterthe joystick in port 2, its fire buttonmoves the player, or the menu's cursor; fire stops a RUN and picks from a menu
a click on a menu's wordthe joystick, moved to it, and firepicks it
a click anywhere else on the picturefirestops a RUN, and the menu comes back; in a menu, picks the cursor's word; on the title and its pages, goes on
SpaceSPACEfire
H BH and Bup and down; on the page of controls, B shows the five pages of instructions
Shift, left AltSHIFT and the Commodore keyright and left
M, or 🎡 MusicM, in playthe music off and on; with it off, the footsteps are heard. The page keeps it off when the game starts a new game or the tune after a death, and turns the sound chip down on the title, where the game has no key for it
Ctrl and RCTRL and R, on the titlea game recorded as you play it, which the title plays back as its demonstration after the story
FFends the recording

01 Β· The port

What runs here

Nothing on this page emulates a 6502. The game is written out in JavaScript, one function for each routine of the listing, from its first instruction at $07F9: the title $5B27 with its picture and story scroller, the page of controls and the five pages of instructions, the main menu $11A2 and its chooser $1320, every verb, the line of sight $0B25, the player's movement $0D44, the creatures with their pursuit and attacks $2205, the four spells, the potions, the picture strip $1515, the clock and the bars, the death, the win and the wait after them $0876. The demonstration is the game's own recorder and player $179D, which replays its recorded controls wherever the game reads the joystick, and records yours after CTRL and R.

The interrupts are ported too. On the title one handler $5D08 splits the screen between the picture and the story's line, moving the line two pixels a frame; in play another $2653 splits it three ways, the view with its sprites, the message window and menu, and the picture strip, and plays the music or, with the music off, the footsteps. The music driver at $C000 runs on the game's own memory, as the interrupt calls it. The game calls a few routines of the C64's ROMs (the screen clear, CHROUT for the instructions and the keyboard scan); they are written out here too.

The port runs on the game's own 64 KB, loaded from the bytes the Source code tab shows, and keeps every variable where the game keeps it: the objects' and creatures' tables at $3D45, the map at $9000, the demonstration's recording at $A540 and the operands the game rewrites in its own code. The screen is drawn by the site's model of the video chip from that memory, with each write to the chip at the line and cycle where the page's clock stood, and the sound is the port's writes to the SID, played through the site's model of it.

02 Β· Speed

Walls, speed and the screen work as on the C64

Walls are found by the video chip. Each frame the play interrupt copies its sprite-to-background collision register $D01F into $038D, and the game reads it before each step. The site's model of the collisions, collide.js, works them out as the beam draws the sprites and the graphics. The page keeps the C64's pace by keeping a clock: each piece of work the port does moves it on by what the game's own code takes for it, the interrupts run on their raster lines and on CIA 1's timer, and the video chip takes its cycles from the processor on each bad line and each sprite's fetch. On that clock the page plays the game's demonstration, all 2,371 passes of it, 0.21 % faster than the C64.

The screen is drawn by the site's model of the video chip from the port's memory, with each change to memory where the game's code made it. On the title the picture half of the interrupt, at line $30, shows video bank 3 and moves the story's line a character on in bank 0, which the scroller half, at line $EE, shows with the fine scroll it writes.

03 Β· Not ported

What is left out

  • The RESTORE key and the reset button, which on a C64 restart the game at its title through the cartridge vectors it leaves at $8000.
  • An NTSC machine. The game slows its music and its story scroller to keep their pace there; the page is a PAL C64.
  • The ROM routines beyond what the game uses of them: the screen clear, the characters CHROUT prints for the instructions, and of the keyboard scan the key held in $C5 and the SHIFT, Commodore and CTRL keys in $028D, the only results the game reads.