decoding repton

51
Decoding Repton Compiled by Gerald J Holdsworth Page 1 22 December 2017 Decoding Repton Compiled by Gerald J Holdsworth

Upload: others

Post on 29-Nov-2021

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page1 22December2017

Decoding Repton

CompiledbyGeraldJHoldsworth

Page 2: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page2 22December2017

ContentsIntroduction...........................................................................5

ConventionsandNomenclature.............................................6Keywords....................................................................................................6NumericNotation.......................................................................................6EndianNotation..........................................................................................6

HowTheMapsAreStored......................................................7MethodOne................................................................................................7MethodTwo...............................................................................................7

HowTheGraphicsAreStored.................................................8BBCMicro/AcornElectron...........................................................................8Commodore64...........................................................................................8ZXSpectrum................................................................................................8Archimedes/RISCOS...................................................................................9

BBCandElectronRepton......................................................10FileFormat(BBC)......................................................................................10FileFormat(Electron)................................................................................10Characters................................................................................................10Maps........................................................................................................11MapCharacters........................................................................................11Passwords.................................................................................................11Palette......................................................................................................11TimeLimits...............................................................................................11

DesktopRepton....................................................................12EncryptionKey..........................................................................................12FileLayout................................................................................................13Characters................................................................................................13

ArchimedesandRiscPCRepton............................................14FileLayout................................................................................................14Characters................................................................................................14Maps........................................................................................................14TimeLimits...............................................................................................14Passwords.................................................................................................14Palette......................................................................................................14

BBCandElectronRepton2...................................................15FileLayout(BBC).......................................................................................15FileLayout(Electron,DFSformat).............................................................15LevelData.................................................................................................15PuzzlePieceDefinitions.............................................................................16Transporters.............................................................................................16

Page 3: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page3 22December2017

StartPosition............................................................................................16Palette......................................................................................................16GameSpritesandPuzzlePieceSprites.......................................................16

DesktopRepton2.................................................................18EncryptionKey..........................................................................................18FileFormat...............................................................................................19Co-ordinates.............................................................................................19Maps........................................................................................................19Edges........................................................................................................19Palette......................................................................................................19PuzzlePieces.............................................................................................19Transporters.............................................................................................19Characters................................................................................................19

ArchimedesandRiscPCRepton2..........................................21FileFormat(Archimedes)..........................................................................21FileFormat(RiscPC)..................................................................................21Maps........................................................................................................21Edges........................................................................................................21Characters................................................................................................21Transporters.............................................................................................21PuzzlePieces.............................................................................................21Palette......................................................................................................22

Repton3...............................................................................23FileLayout(BBC/Electron).........................................................................23FileLayout(Archimedes/DesktopRepton).................................................23FileLayout(Commodore)..........................................................................23Passwords.................................................................................................24EditCodes.................................................................................................24TimeLimits...............................................................................................24Transporters.............................................................................................24ColourPalette...........................................................................................25Maps........................................................................................................25Characters................................................................................................25CompetitionCodes....................................................................................25

ReptonInfinity.....................................................................27G.gameformat.........................................................................................27eG.gameformat.......................................................................................27E.gamefileformat....................................................................................28M.gameformat........................................................................................28S.gamefileformat....................................................................................28eS.gamefileformat..................................................................................28O.gamefileformat...................................................................................29T.gamefileformat....................................................................................31Passwords.................................................................................................32

Page 4: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page4 22December2017

SinclairZXSpectrumReptonMania......................................33DSKandMemoryUsage............................................................................33Maps........................................................................................................34Transporters,PuzzlePiecesandSpirits......................................................34Z80format................................................................................................35

EGO:Repton4......................................................................36Passwords.................................................................................................36Leveldata.................................................................................................36

PCRepton3Graphics...........................................................37WindowsBitmapLayout...........................................................................37

ReptonTheLostRealms.......................................................38FileLayout................................................................................................38Encoding...................................................................................................38ScreenData..............................................................................................38CharacterData.........................................................................................38Characters................................................................................................38

ClonesandSimilarGames:Ripton........................................40Characters................................................................................................40Maps........................................................................................................40Palette......................................................................................................40Passwords.................................................................................................40Timelimits................................................................................................40

ClonesandSimilarGames:HWRepton3..............................41FileStatus.................................................................................................41EDITFormat..............................................................................................41LOCKformat.............................................................................................41LockPassword..........................................................................................41LOCKedMaps............................................................................................41FinalNotes................................................................................................42Graphics...................................................................................................42

ClonesandSimilarGames:Bonecruncher.............................43BONE2/BONE_2........................................................................................43SCREENx...................................................................................................44Spriteorder...............................................................................................44MaptiletospriteLookupTable.................................................................45

UsefulPrograms...................................................................46ArchimedesandDesktopRepton3Decoder..............................................46HWRepton3Decoder...............................................................................47

Acknowledgements..............................................................50

Page 5: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page5 22December2017

IntroductionReptonhasbeendescribedas“thethinkingman’sarcadegame”andwasoriginallypublished, for the BBC Micro and Acorn Electron, in 1985 by Superior Software.Writtenby15-year-oldTimTyler,thisquicklybecameasmashhitandwasfollowedbyRepton2. Lateron,Repton3 followed,and thenRepton InfinitybeforeReptonmovedontotheArchimedeswithEGO:Repton4.Recently,RetroSoftwarereleasedRepton:TheLostRealms,withanewsetofscreenstofollowinthenearfuture.

Superior Software, Superior Interactive, Retro Software and Alligata have alsopublished various other versions, for the Acorn Atom, Sinclair Spectrum,Commodore64,AcornArchimedes&RISCPC,andMicrosoftWindows.

This is a guide to the various formats of file used by the many incarnations ofRepton, or the arrangement of themap and sprite datawithin the code.What itdoesnotcoverarethePCReptonformats,exceptforthegraphics.Thefollowingarecovered:

• BBCMicroRepton,Repton2,Repton3andReptonInfinity• AcornElectronRepton,Repton2,Repton3andReptonInfinity• SinclairSpectrumReptonandRepton2• Commodore64Repton3• AcornArchimedesRepton,Repton2andRepton3• DesktopRepton1,2,and3• PCRepton3graphics

In addition, I have researched and present here some other formats for gamessimilartotheReptonseries:

• Ripton (fromA&B Computing),whichwas a direct copy of Repton, for theBBCMicro

• HarryWood’sRepton3,whichwasHarry’sattemptataPCversionofRepton3,beforeSuperiorInteractiveproducedtheir’s

• Bonecruncher, a different game entirely, but very similar gameplay, fromSuperiorSoftware

Page 6: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page6 22December2017

ConventionsandNomenclatureTheguideiswrittenfromtheviewpointofprogramminginC++,althoughIactuallyprogram inDelphi (Pascal). As Repton ismainly from theAcornworld,most codewouldbeshownasBBCBASICVorARMassembly.

KeywordsThroughoutthisguide,Ihaveusedsomecommonkeywords:XOR:bitwiseeXclusiveORAND:bitwiseANDOR:bitwiseORAlso,inBBCBASICsections,EORisthesameasXOR.

NumericNotationIhavealsousedC++conventionstorepresenthexadecimalnotation…i.e.0x10is10inhexadecimal(whichisequivalentto16indecimal).Bitsandbytesarecountedfrom0,withbit0beingtheleastsignificant,orrightmostbit.Bytes,ontheotherhand,arecountedasyouencounterthem.Sobyte0wouldbetheleftmostbyte(whichisnormallythemostsignificantbyte).

EndianNotationWithahexnumberof0x1234,0x12wouldbeconsideredtheMSB(mostsignificantbyte), while 0x34 would be the LSB (least significant byte). This would berepresented, and stored in these data files, as LSB/MSB. Therefore, you wouldencounterthemas0x34,0x12–thisisknownas“LittleEndian”.IfitwereMSB/LSB,thenthisisknownas“BigEndian”,andwillbenotedassuch.

Page 7: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page7 22December2017

HowTheMapsAreStoredTheleveldata,ormaps,arestoredasacommonformatonallplatformscoveredbythisbook,exceptforEGO:Repton4,whichhasadifferentformatcompletely(asitwasoriginallyanothergameentirely,andhad it’snameandcharacterschangedtobeanotherRepton).

The sizeof each level changesbetween levels (ReptonandRepton2being32x32,and Repton 3 being 24x28 characters), but the actual storage is the same. Eightcharactersarepackedintofivebytes,whichbasicallyallowsforupto32charactersonthemaps.Inreality,therearemorecharacters,buttheextrasaretheanimationoneswhichdonotneedtobe includedonamap.Thissaid,thereareactuallytwovariationsonthismethod.

MethodOneTheeightcharactersareplacedonthemapasyouwouldread,i.e.fromlefttoright.Thebitsthatmakeupthecharacternumber0-31aresplitthus:

Byte0isptr+0;Byte1isptr+1;etc.

Byte4 Byte3 Byte2 Byte1 Byte07 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0

4 3 2 1 0 4 3 2 1 0 4 3 2 1 0 4 3 2 1 0 4 3 2 1 0 4 3 2 1 0 4 3 2 1 0 4 3 2 1 0

Char7 Char6 Char5 Char4 Char3 Char2 Char1 Char0

Char0isx+0,y;Char1isx+1,y;etc.andbits5-7ofeachcharacterare0.

MethodTwoByte0isptr+0;Byte1isptr+1;etc.

Byte0 Byte1 Byte2 Byte3 Byte47 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0

4 3 2 1 0 4 3 2 1 0 4 3 2 1 0 4 3 2 1 0 4 3 2 1 0 4 3 2 1 0 4 3 2 1 0 4 3 2 1 0

Char0 Char1 Char2 Char3 Char4 Char5 Char6 Char7

Page 8: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page8 22December2017

HowTheGraphicsAreStoredHow the graphics are stored will depend on the target machine. With the 8 bitmachines, the character sizes are 16x32 pixels (12x24 for Electron Repton 3, and8x16 forElectronRepton1,2and Infinity).TheArchimedesandRISCOSaremuchsimpler, although the character sizes are now 32x32 pixels, as they have morecolourstoplaywith.Each4bitsrepresentasinglepixel,soyoucanget2pixelsfroma singlebyte,andeachpixelhasapossible16colours tochoose from.TheHi-Resformat of Desktop Repton 3 goes even further, not only doubling the size of thecharacters (to 64x64), but also doubling the bit storage. Each byte represents asinglepixel(oneof256possiblecolours).

ThisformatofstoringmapsandcharacterschangedwithRepton:TheLostRealms,although the ‘retro’ graphics for the PC version remained. However, the high-resolutiongraphics for thePCutilised64x64px8bppWindowsBitmap format (ther3g files being a series of Windows Bitmaps with the headers and paletteinformationstrippedoff).

BBCMicro/AcornElectronThe BBCMicro and Acorn Electron versions of the games all run inMODE 5 and,hence,matchthewaythattheMODE5memoryisarranged.Eachtwobitsofdatamakeupasinglepixelallowinganyoneofthe4MODE5colours:

Pixel0 Pixel1 Pixel2 Pixel3

Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0

Commodore64TheCommodoreusesadifferentarrangementofbitstopixels:

Pixel0 Pixel1 Pixel2 Pixel3

Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0

ZXSpectrumTheZX Spectrumuses separatedata todefine thegraphics. Thepixel data canbeeitherforeground(bitisset)orbackground(bitisclear).Eachbyte,inthepixeldata,willthereforerepresent8pixels.Theneach8x8pxblockisdescribedbyasinglebyte:bit7=Flashingbit6=Brightbits5,4&3=Paper(background)bits2,1&0=Ink(foreground)The3bitcolourdefinitionsaredescribedasGreen,RedthenBlueforbits2,1and0respectively.Thiswillmakethecolours:0:Black 1:Blue 2:Red 3:Magenta4:Green 5:Cyan 6:Yellow 7:WhiteCombinedwiththeBrightflag,thiswillgiveatotalof16colours.

Page 9: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page9 22December2017

TheZXSpectrumscreenshavearesolutionof256x192pixels.Thememoryismadeupthus:15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 0 1 0 Y7 Y6 Y2 Y1 Y0 Y5 Y4 Y3 X4 X3 X2 X1 X0 The 010xxxxxxxxxxxxx is the base address of 0x4000 (start of screen memory)

TheYco-ordinatesareinpixelsdown,whiletheXco-ordinatesareinbytesacross.Thescreenmemoryisfrom0x4000to0x57FF,withthecolourdatafrom0x5800to0x5AFF.

Archimedes/RISCOSForthetwopixelsperbytemethodusedwithArchimedesRepton1,2,and3;RiscPCRepton2;&DesktopRepton1,2,and3(lowres),thebyteissplitintwowithbits0-3beingthefirstpixel,and4-7beingtheadjacentpixel.

Page 10: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page10 22December2017

BBCandElectronReptonDataisspreadacrossthetwofilesREPTON1andREPTON2ontheBBC.Themajorityofthedataisinthesecondfile,whilstaminimalamountistobefoundinthefirst.AllofthedatafortheElectronversionsmustbeXORedwith0xFFfirst.

FileFormat(BBC)Offset DescriptionFile:REPTON10x1702 Gameplayingspritestilelookup0x1754 Palette0x17BF SmallmapcharacterstilelookupFile:REPTON20x1C58 Passwords0x1EC0 Spritedefinitions0x2F00 Mapspritetileoffsets0x3100 Maps

FileFormat(Electron)Offset Description0x00E9 Palette0x00F5 Smallmapcharacterstilelookup0x1B70 Passwords0x2500 Spritedefinitions0x2AC0 Mapspritetileoffsets0x2C00 Maps

CharactersSpritesaremadeupofanumberoftiles.Thesetiles,assprites,arestoredas4x8pxtiles,ofwhichthereare520(224inElectron)ofthem:

There is then a lookup table to define which tiles make up the appropriatecharacters,ofwhichthereare52.Asthecharactersareultimately16x32px(8x16pxforElectron),thismeans16tiles(4x4),or4tiles(2x2)forElectron,makeupasinglecharacter.TheformatofthespritesisMethodOneasdescribedonpage7.

ThegameplayingspritesontheBBChasdirectpointerstothetoplefttile.However,thisonlyhas10ofthe14sprites,andtheyareall4x4.ThefirstlocationcontainstheLSB,whilethesecondcontainstheMSB.Youwillneedtoadd0x0F00fortheoffset

Page 11: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page11 22December2017

into the file (as the address given is the direct memory address when the file isloadedintomemory).

MapsThese are stored, as Method One, described on page 7, to make up the 32x32charactermaps,ofwhichthereare12intotal,makingeachlevelatotalof640byteseach. One thing to note is that Repton does not actually appear on the leveldefinitions,ashebeginsfromthesamespotoneverylevel(beingat5,5).

MapCharactersThese are stored the same as the main characters, with the tile lookup pointingtowardswhere the definition is. This time, themap characters only take up 1 tileeach.

PasswordsThepasswordsarestoredunencrypted,andareamaximumof12characters long,terminatedbyCarriageReturn(13or0x0D).

PaletteThepalette is simply1byteper screen,witheachbyte representing aBBC colour(seepage25),whichwillredefinelogicalcolour1(Repton’strousers).

TimeLimitsThetimelimitsforallscreensinReptonaresetat6000.

Page 12: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page12 22December2017

DesktopReptonThedatafileforDesktopReptonisencodedusingdatafromthespritefile.Thisfileitselfhashadsomeencryptiondonetoittoproducethefinalkey,whichisthenusedtodecryptthedata.

Asthisfile,encrypted,canbesavedandusedasakey,itseemssensibletousethecode foundwithin theDesktopReptondirectory structure to encrypt it once, andsavedforfutureuse.

EncryptionKeyBBCBASICprogramtoproduceakeytodecodethemaps:REM Program to process the Desktop Repton 1 Sprite file REM for use as a key to decode the maps REM REM This code is taken directly from the DR1 main program : ONERRORREPORT:PRINT" at line ";ERL:END savepath$="ADFS::RISCOS4.$" : REM First we'll extract the code REM This is stored as code length, code, code function names and pointers Z%=OPENIN"<Repton$Dir>.Resources.Code" INPUT#Z%,A% DIMcode% A% size=A% SYS"OS_GBPB",4,Z%,code%,A%TO,,,A% : REM Read bytes from current pointer : REM Now we need to load the Sprite file in and process it SYS"OS_File",17,"<Repton$Dir>.Resources.Sprites" TO,,,,D% : REM Get file length D%+=48+655360 DIM sprs% D% !sprs%=D% SYS"OS_File",16,"<Repton$Dir>.Resources.Sprites",sprs%+4 : REM Load file into sprs%+4 : REM These are the functions within the code that we'll be using sprtab=&C74+code% process=&1590+code% map=&500+code% DIM map% 1600 B%=map% !map=B% sprtab!-4=sprs% FORn%=0TO50 SYS"OS_SpriteOp",256+24,sprs%,STR$n% TO,,A A%+=&2C sprtab!(n%*4)=A% CALLprocess IF A%!-8>A%!-12 THEN A%+=512:CALLprocess NEXT : REM Now we save the key to a file SYS"OS_File",0,savepath$+".DR1Key",,,sprs%+4,sprs%+18004 PRINT"Desktop Repton 1 decode key saved in "savepath$

You will then need to use this key to decrypt the file, as shown in the followingPascalcode.Forthecryptprocedure:procedure crypt(var data,enc_data: array of Char;ptr,enc_ptr,amt,seed: Integer); dataisthedatablockwherethefileisloadedinto.enc_dataisthedatablockfortheabovekey.ptristhepointerintodatathatwillbedecoded.enc_ptristhepointerintoenc_datathatwillbeused.amtisthesizeofdatathatneedsdecoding.seedisthedecryptionseed.

Fortheinitialdecryption,whichisdoneovertheentirefile,theseedisthelastword(fourbytes)ofthedatablockORedwithitselfshiftedleft16times,or:

Page 13: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page13 22December2017

seed=seed OR (seed<<16)

Aftertheentirefilehasbeendecrypted,youwillthenneedtodecryptthepasswordandauthorarea.begin temp:=Ord(data[size-4])+Ord(data[size-3])shl 8+Ord(data[size-2])shl 16+Ord(data[size-1])shl 24; temp:=temp OR (temp shl 16); getResource('DR1Decode',spr_data); {Get the decryption key} crypt(data,spr_data,0,12,size-4,temp); for screen:=0 to levels-1 do crypt(data,data,(((levels*1024)+levels+3)AND-4) +(screen*68),screen*1024,68,29); end; procedure crypt(var data,enc_data: array of Char;ptr,enc_ptr,amt,seed: Integer); var c,d: Integer; begin repeat c:=Ord(enc_data[enc_ptr])+Ord(enc_data[enc_ptr+1])shl 8+Ord(enc_data[enc_ptr+2])shl 16+Ord(enc_data[enc_ptr+3])shl 24; enc_ptr:=enc_ptr+4; d:=Ord(data[ptr])+Ord(data[ptr+1])shl 8+Ord(data[ptr+2])shl 16+Ord(data[ptr+3])shl 24; c:=seed+(seed*c); d:=d+seed; d:=d XOR ((c shr 12)+(c shl 20)); d:=d XOR ((c shr 20)+(c shl 12)); d:=d-seed; data[ptr+3]:=chr((d AND $FF000000)shr 24); data[ptr+2]:=chr((d AND $00FF0000)shr 16); data[ptr+1]:=chr((d AND $0000FF00)shr 8); data[ptr+0]:=chr(d AND $000000FF); ptr:=ptr+4; amt:=amt-4; Until amt=0; end;

FileLayoutSizeoffileis(((levelsx1093)+7)AND-4)Offset Length Description0x0000 0x400*levels Maps(32x32chars)((levels*0x400)+3)AND-4 0x44*levels Infoblock(seebelow),encodedtwicelength-4 0x04 EncryptionseedLevelInfoBlock0x00 0x20 Password0x20 0x20 Author0x40 0x04 TimeLimit

CharactersThecharactersusedforDesktopReptonarestoredasstandardRISCOSspritesinaseparatefile,Resources.Sprites.YouwillneedtorefertotheRISCOSProgrammer’sReferenceManualfordetailsonhowthesearestored.

Page 14: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page14 22December2017

ArchimedesandRiscPCReptonFileLayoutOffset Length Description0x03A44 0x01080 MapCharacters0x04AC4 0x01E00 Maps0x068E4 0x1A000 Characters0x208E4 0x00084 Passwords0x20968 0x00300 Palette0x20C74 0x00030 TimeLimits

CharactersThecharacterstodisplaythemapare16x16px,with2pxperbyte.Thismeanseachcharacterisstoredin128bytes,ofwhichthereare33ofthem.Thecharactersusedforplayingare64x64px,andagain,2pxperbyte.Eachcharacteruses2048bytesofspaceofwhichthereare52ofthem.Eachpixelisacolournumber,referencedintothepalettedata.

MapsThese are stored, as Method One, described on page 7, to make up the 32x32charactermaps,ofwhichthereare12intotal,makingeachlevelatotalof640byteseach.

TimeLimitsThesearestoredas4byteseach:LSB,MSB,0x00,0x00.Note,thatthesearenotall6000,asBBC/ElectronRepton.

PasswordsThepasswordsarestoredas11bytesper level foreachof the12 levels.Theyareencodedusingthemapdata:character:ASCIIvalueofeachcharacterx:offsetintothepassword(0..10)passwords[]:passworddataforscreenmapdata[]:mapdataforscreencharacter = ( passwords[x] XOR mapdata[47 * (x+1)] ) AND 0x1F OR 64

then,ifcharacter>13:character = character AND 0xDF

finally,ifcharacterisan'@'thenreplaceforASCII13

PaletteThevaluesstoredatthislocationarethered,greenandbluecomponentsforeachofthe16coloursperlevel.Theyarestored0x10,RR,GG,andBB.

Page 15: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page15 22December2017

BBCandElectronRepton2The BBC file D.RepB needs to be XORed with 0x66 to get any useable data. TheElectronversionofRepton2 issplit intotwofilesontheDFSversion,whileontheADFSversionitisasinglefile.

FileLayout(BBC)Offset Description0x014A Spritesizes0x0169 Spritepositionoffsets(LSB)0x0188 Spritepositionoffsets(MSB)0x01C5 Palette0x0FD2 StartPosition(x)0x0FD6 StartPosition(y)0x1B00 LevelDataoffsets0x1B40 Transporters0x1CF8 PuzzlePieceDefinitions0x1DA0 SpriteTileoffsets0x2240 SpriteandPuzzlePieceDefinitions0x2680 Palette0x3500 LevelDefinitions

FileLayout(Electron,DFSformat)File Offset DescriptionReptonA 0x187A SpritesizesReptonA 0x1899 Spritepositionoffsets(LSB)ReptonA 0x1939 Spritepositionoffsets(LSB)ReptonA 0x1958 Spritepositionoffsets(MSB)ReptonA 0x1AB3 PaletteReptonB 0x0B60 StartPosition(x)ReptonB 0x0B64 StartPosition(y)ReptonB 0x1600 SpriteandPuzzlePieceDefinitionsReptonB 0x1720 PuzzlePieceSpritesReptonB 0x18A0 PuzzlePieceDefinitionsReptonB 0x1950 TransportersReptonB 0x1B00 LevelDataoffsetsReptonB 0x1B40 TextcharactersReptonB 0x1E40 SpriteTileoffsetsReptonB 0x24C0 PaletteReptonB 0x2900 LevelDefinitions

LevelDataThe offset data is 4 bytes per level, with each byte being an offset into the leveldefinitions:addr+(offsetx160).Each level is32x32,andeachoffsetrepresenting8rowsofamap.

Character numbers are shared on three occasions – the Finish character onlyappearsonScreenA,whileontheotherscreens it isaspirit;andtransportersand

Page 16: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page16 22December2017

puzzlepiecesdonotappearonthe leveldata,soyouwillneedto fallbackontherespectivedata(seebelow).

Any offset byte of 0x80 or more is eight rows of repeating character, the leastsignificantfourbitsindicatingthecharacternumber(0=blank,6=diamond,etc.)

TheleveldefinitionsareusesMethodOne,asdescribedonpage7.

PuzzlePieceDefinitionsThesearestoredinpuzzlepieceorder(asputtogetherusingthespritedatabelow),andeachoneisstoredasfourbytes:screen,x,y,andlocationonscreenA.YouwillneedtoANDthescreenbytewith0x0F.Thereare42puzzlepieces.Thefinalbyte,locationon screenA, is apairof co-ordinateswith the xbeingbits0-3, and theybeingbits4-7.Thisisanoffsetfromposition10,24.

TransportersThesearestoredassixbytes:sourcescreen,x,andy(i.e.wherethetransporteris)anddestinationscreen,x,y(i.e.whereittakesReptonto).Thereare64transporters.

StartPositionWhereReptonstartsthegame,onScreenA(asx,yco-ordinates)–shouldbe16,7.

PaletteThepalette is stored in two locations. The first location is fourbytes. Eachbyte ismadeupofthelogicalcolour(topfourbits),andtheactualcolour(lowerfourbits).Togettheappropriatepaletteforthelevel,youwillneedtoANDthelevelnumberwith3(withthelevelnumberbeing0..15)toproduceanoffsetof0,1,2or3.

However, this data is only valid for levels 2..15. For 0 and 1, there is a secondlocationwithtwobytes.Also, logicalcolour0 isalwaysactualcolour0(black),andlogicalcolour3isalwaysactualcolour2(green).Andfinally,levelP(15)appearstobeacombinationofoffset2and3ofthefirstlocation.

GameSpritesandPuzzlePieceSpritesAsReptonbeforeit,thesearestoredintiledformat.Thespritetilesare4x8pxtilesofwhichthereare600ofthem.Thesemakeupthefinalspritesbytakingthespritedefinitiondata,whereeachbyteisanoffsetintothesetiles.

Page 17: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page17 22December2017

Theseareforthemapandpuzzlepiecespritesonly.Theplayingspritesarestoreddifferently.Forthese,thereareanumberofbytesthatdeterminehowbigeachoneis – there are 30 on theBBC and 31on the Electron (althoughonly 25 are used).Thesecanbe1,2,3or4(for1x1,2x2,3x3or4x4).Followingonfromthisaretheaddresses of the offsets for the top left tile. This offsetwill be the direct addressafter the file is loaded intomemory. To get the offset into the file, just subtract0x0D00fortheBBCand0x1100fortheElectron.

However,theElectronisnotsoassimpleasthat,astherearetwolocationsfortheLSBaddress.Theguideseemstobe:

Validforwhenxisfrom0to3,and9to30.What4to8areusedforisunclearatthetimeofwriting.

1. Readthespritesizefromlocation0x187A+x;2. ReadtheMSBaddressfromlocation0x1958+x;3. Whenx<=22,readtheLSBaddressfromlocation0x1899+x;and4. Whenx>=23,readtheLSBaddressfromlocation0x1939+x.

Page 18: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page18 22December2017

DesktopRepton2EncryptionKeyAs Desktop Repton 1, the data is encoded with the processed sprite file. Theencoding,andprocessing,ofRepton2isalmostidenticaltoRepton1.Therefore,thefollowingisanalmostidenticalBBCBASICprogramtoextractandprocesstheSpritefileforuseasakeytodecodetheMapsdatafile:REM Program to process the Desktop Repton 2 Sprite file REM for use as a key to decode the map REM REM This code is taken directly from the DR2 main program : ONERRORREPORT:PRINT" at line ";ERL:END savepath$="ADFS::RISCOS4.$" : REM First we'll extract the code REM This is stored as code length, code, code function names and pointers : DIMmap% 1920,map1% 1920 Z%=OPENIN"<Repton2$Dir>.Resources.Code" INPUT#Z%,A% DIMcode% A% size=A% SYS"OS_GBPB",4,Z%,code%,A% TO,,,A% : REM Read bytes from current pointer : REM Now we need to load the Sprite file in and process it SYS"OS_File",5,"<Repton2$Dir>.Sprites" TO,,A%,,D% IF (A%>>8)=&FFFFFFCA THEN B%=OPENIN"<Repton2$Dir>.Sprites" SYS"OS_GBPB",4,B%,&860C,20 A%=EXT#B%-20 SYS"Squash_Decompress",8,D% TO wksz% D%+=41136 DIMsprs% D% !sprs%=D% C%=END+1024 SYS"OS_GBPB",4,B%,C%,A% CLOSE#B% B%=-1 SYS"Squash_Decompress",,code%,C%,A%,sprs%+4,D% ELSE D%+=41136 DIMsprs% D% !sprs%=D% SYS"OS_File",255,"<Repton2$Dir>.Sprites",sprs%+4 ENDIF : sprtab=&9F4+code% process=&13CC+code% map=&DDC+code% sprtab!-4=sprs% B%=map% !map=B% FOR n%=0 TO 54 SYS"OS_SpriteOp",256+24,sprs%,STR$n% TO,,A% A%+=&2C sprtab!(n%*4)=A% CALLprocess IF A%!-8>A%!-12 THEN A%+=512:CALLprocess NEXT : REM Now we save the key to a file SYS"OS_File",0,savepath$+".DR2Key",,,sprs%+4,sprs%+26316 PRINT"Desktop Repton 2 decode key saved in "savepath$

And,asDesktopRepton1 ,thefilewillneedtobedecryptedtwice–onceoverall,thenonceeachforeachlevel:temp:=Ord(data[size-4])+Ord(data[size-3])shl 8+Ord(data[size-2])shl 16+Ord(data[size-1])shl 24; temp:=temp OR (temp shl 16);

Page 19: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page19 22December2017

crypt(data,spr_data,0,12,size-4,temp); for screen:=0 to levelinfo[1]-1 do crypt(data,data,(((levelinfo[1]*1024)+levelinfo[1]+3)AND-4) +(screen*68),screen*1024,68,29);

FileFormatOffset Length Description0x0000 0x6000 Maps0x6000 0x0048 Offsetstoleveldata0x6084 0x0011 Paletteoffsets0x60A4 0x0011 Edge0x63C4 0x00FC Puzzlepiecedefinitions0x6544 0x0180 Transporterdata

Co-ordinatesThexandyco-ordinatesarenotscreenco-ordinates,butrefertoadirectmemorylocation intothe leveldata.However, this leveldatahasbeenalteredto include4rowsofedgewallsoneitherside.Toconvertfromthesex,ytoactuallevelx,ypositionsuse:screen_x = (( y * 10) + (x DIV 4) - 164) DIV 40 screen_y = (( y * 10) + (x DIV 4) - 164) MOD 40

MapsForeachofthe17levels,thereare4byteswhichdeterminetheoffsetintothefilewherethemapdataisheld(LSB/MSB/0x00/0x00).However,thereare18entries–theoffsettothenextlevelisusedtodeterminelevelsize.

EdgesThisdetermineswhethertheedgeisawall(0x18)orabarrier(0x19).However,thiscanbeanycharacter,asthevaluestoredhereisjustthecharacternumber.

PaletteThisis1byteperlevel,whichisanindicationtowhichofthe48bytesintheRepPalfilethatthecolourdataisheldforthislevel(3bytespercolour,ofwhichthereare16).

PuzzlePiecesThese are 6 bytes for each of the 42 pieces. They are stored as two sets of data:wherefound,whereplaced.Eachsetislevel,x,y.Normally,wherethepiecewillbeplacedwillbeonlevelA,atthebottom.

TransportersSimply,theseare6bytesforeachofthe64transporters.Asthepuzzlepieces,theyarein2sets:from,to.Eachsetisthen,asthepuzzlepieces,level,x,y.

CharactersThecharactersusedforDesktopReptonarestoredasstandardRISCOSspritesinaseparatefile,Sprites.YouwillneedtorefertotheRISCOSProgrammer’sReferenceManualfordetailsonhowthesearestored.Thepuzzlepiecesarestoredasasinglespritecalled‘puz’.

Page 20: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page20 22December2017

ThisreportsitselftoRISCOSasaMode0spritewithawidthof64andaheightof42.However,ifyoulookatthedatafromoffset0xF4E8intothefile,youcanseethatitisaseriesofbits.Each8byteswilldescribeasinglepuzzlepiece-8bytesx8bits=64bitsor64pixels,with42pixelheight=arowforeachpiece.

So, a value of 0xFE is 11111110 in binary that translates to 7 solid pixels and anemptypixel.Asalltheothertilesare32x32px,eachbitisusedfourtimesacross,andfourtimesdown(4x8=32).Thecolouring isappliedafterwards-generally,DesktopReptoncolourthesolidpixelsalternateyellowandgreen(colours2and8fromtheRepPalfile).

Page 21: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page21 22December2017

ArchimedesandRiscPCRepton2FileFormat(Archimedes)Offset Length Description0x04D88 0x2800 Maps0x07588 0xD400 Characters0x14988 0x0200 Transporterlocations0x14B88 0x00A8 PuzzlePiecedata0x14C30 0x0400 Levelcolourpalettes0x15030 0x0010 Edges

FileFormat(RiscPC)Offset Length Description0x00FA0 0x02800 Maps0x037A0 0x35000 Characters0x387A0 0x00200 Transporterlocations0x389A0 0x000A8 PuzzlePiecedata0x38A48 0x00400 Levelcolourpalettes0x38E48 0x00010 Edges

MapsThesearestoredpacked,asMethodOneonpage7.Thismakeseachofthe16levels640byteseach.

EdgesTheseare ignored in theRiscPC version,butdictatewhat character surrounds thelevel.Thisisquitesimplythecharacternumber.

CharactersOntheRiscPC,theseare64x64pxwitheachbytebeing2px,torepresentoneofthe16colours.TheArchimedescharactersareaquarterthesize,at32x32px.Thereare106charactersonbothversions.

TransportersTheTransportersarestoredas8byteseach,splitintotwosets–fromandto.Eachsetisscreen,x,y,0x00.Theco-ordinatesareworkedoutthus:y = ((byte1 + (byte2 * 256)) – 324) DIV 40 x = ((byte1 + (byte2 * 256)) – 324) – (40 * y)

PuzzlePiecesThefourbytesarescreen,x,y,ScreenAposition.Similartothetransporters,theco-ordinateswillneedtobeconverted:y = ((byte1 + ((byte2 AND $F) * 256)) – 324) DIV 40 x = ((byte1 + ((byte2 AND $F) * 256)) – 324) – (40 * y)

TheScreenApositionco-ordinatesareworkedout:y = ((((byte2 AND $F0) >> 4) + (byte3 * 16)) – 84) DIV 40 x = ((((byte2 AND $F0) >> 4) + (byte3 * 16)) – 84) – (40 * y)

Page 22: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page22 22December2017

PaletteForeachlevel,thereare16coloursandeacharestoredintheirRed,GreenandBluecomponentform:0x10,RR,GG,BB.

Page 23: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page23 22December2017

Repton3The format for the Electron, BBC, Archimedes and Desktop Repton versions arelargelysimilar.TheCommodore64versiondiffersslightly.Theonemaindifferenceisthereareextrabytes,seeminglyunused,intheCommodorefile:0x0000:0xA0 0x0001:0x67 0x2752:16bytesof0x00

Also,eachformatoffilehasaspecificsize.Thiswillbe:BBCMicro:9,760bytes(0x2620)AcornElectron:7,712bytes(0x1E20)Commodore64:10,210bytes(0x27E2)AcornArchimedesandDesktopReptonLowRes:28,832bytes(0x70A0)DesktopReptonHighRes:102,560bytes(0x0190A0)

FileLayout(BBC/Electron)Offset Length Use0x0000 0x40 Passwords0x0040 0x10 TimeLimits0x0050 0x10 EditCodes0x0060 0x80 Transporters0x00E0 0x20 ColourPalette0x0100 0xD20 Maps0x0E20 0x1800 Characters(BBC)0x0E20 0xD80 Characters(Electron)

FileLayout(Archimedes/DesktopRepton)Offset Length Use0000 0x40 Passwords0040 0x20 TimeLimits0060 0x10 EditCodes0080 0x100 Transporters0180 0x200 ColourPalette0380 0xD20 Maps10A0 0x6000 Characters

FileLayout(Commodore)Offset Length Use0x0000 0x02 Unused(shouldbe0xA0and0x67)0x0002 0x40 EditCodes0x0042 0x20 ColourPalette0x0062 0x1800 Characters0x1862 0x180 MapCharacters0x19E2 0x10 TimeLimits0x19F2 0x40 Passwords0x1A32 0xD20 Maps0x2752 0x10 Unused(shouldallbe0x00)0x2762 0x80 Transporters

Page 24: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page24 22December2017

PasswordsOn the Commodore 64, these are not encoded in anyway, and are paddedwithSpaces (0x20). Theother versions are terminatedbyaCarriageReturn (0x0D) andarenotpadded–theextrabytesareignored.

FortheBBCandElectron,eachbyteisXORedwith63-offset:Byte0XOR63 Byte1XOR62 to Byte63XOR0

therebycoveringalleightpasswords,eachonebeinguptoeightcharacterslong.

TheArchimedesandDesktopReptonversionsuseaformulatoencode/decodethedata:Archimedes/DRLowRes:char XOR (mapdata[(charoffset+1) * 0x2F] AND 0x1F

DRHighRes:char XOR (mapdata[((charoffset+1) * 0x2E)-3] AND 0x1F

EditCodesThe BBC and Electron is simply 2 bytes per Edit Code, arranged as LSB/MSB. TheCommodore stores them as a string, padded by zeros at the beginning (to 5characters). However, as the user cannot enter an edit code in the Commodoreversionofthegame,theeditcodesarefivebytesofASCII0x00perscreenwithuser-definedscenarios.

The Archimedes andDesktop Repton versions, although are storedwithin the file(whicharearedherring),areactuallyworkedoutfromthemapdata:

“If the rawmap data byte has bit 2 set then add double the rawmap data byte,otherwisejustaddtherawmapdatabyte.”Or,inBBCBASIC:REM screen is the screen number (0-7) REM and data is a memory location where the data file is loaded code=0 FOR x=0 to 419 ptr=&380+(screen*420)+x IF (data?ptr AND 4) THEN code=code+(data?ptr)*2 ELSE code=code+data?ptr NEXT

TimeLimitsThe BBC and Electron versions are 2 bytes per screen, while the Archimedes andDesktopRepton versions are4bytesper screen, butwithonly the first twobytesused (the last two should be 0x00). These 2 bytes are the time limit stored asLSB/MSB.

TheCommodorestoresthemasBinaryCodedDecimal…i.e.,0x12and0x34wouldbeatimelimitof1234.

TransportersThe4transportersperscreenarestoredinfourbyteseachontheBBC,ElectronandCommodoreas source x, sourcey,destination x,destinationy. If unused, the firstbyteshouldbe0xFF.

TheArchimedesandDesktopReptonversionsarestoredas8bytespertransporter,withbytes0and1asthesource,andbytes4and5asthedestination.Bytes2,3,6,and7shouldbe0x00.Thexandyareworkedoutthus:y = ((byte0 + byte1 * 256) – 148) DIV 36

Page 25: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page25 22December2017

x = ((byte0 + byte1 * 256) – 148) – (36 * y)

It would be worth validating this data once you have unpacked themap data toensurethatthereisactuallyatransporteratthesourcelocation.

ColourPaletteEachscreencanbeadifferentcolour,soeachofthefourcoloursarestoredinthislocation.FortheBBCandElectron,eachofthe4coloursperscreenarestoredasasingle byte per colour (meaning 4 bytes per screen). Each byte represents a BBCactualcolour:0:Black 1:Red 2:Green 3:Yellow 4:Blue 5:Magenta 6:Cyan 7:White(or,bit0:red,bit1:green,andbit2:bluecomponentsi.e.2bitsperpixel)

TheCommodoreissimilar,butthecoloursaredifferent:0:Black 1:White 2:Red 3:Cyan 4:Purple5:Green 6:Blue 7:Yellow 8:Orange 9:LightOrange10:LightRed 11:LightCyan 12:LightPurple 13:LightGreen 14:LightBlue15:LightYellow

TheArchimedesandDesktopReptonstoresthemas4bytespercolour,16coloursperscreen.Byte0 isunused,while the first4bitsofbytes1,2and3are the red,greenandbluecomponentsofthecolour,i.e.4bitsperpixel.TheHighResversionofDesktopReptongoesthatstepfurtherwithalleightbitsbeingused,makingit8bitsperpixel.

MapsThe map data across all four platforms is exactly the same, and is encoded asMethodOnedescribedonpage7.TheRepton3mapsare28charactersacrossby24charactersdown,whichmeansthateachscreentakesup420byteseach.

CharactersThecharacterdataisstoredasdescribedonpage8.However,theyaredifferenttopreviousReptonsinthattheyarenotstoredastiles,buttheentirecharactercanbefoundinasingle16x32pixeldefinition,percharacter(12x24forElectron,32x32forArchimedesandDesktopLowRes,and64x64forDesktopHighRes).

CompetitionCodesThecompetitioncode,ontheBBCandElectron, isworkedout fromthemaximumpossiblescore,andahashtablecalculatedfromthefirst255bytesofthefile.

Forthemaximumpossiblescore,diamonds(and,hence,safesandcages)arescoredat5points,eggsare20,andcrownsare50.ThefollowingC++function(wherebufferis theareaofmemorythefile is loaded into,andscore is theaggregatemaximumpossiblescoreofall8screens):void calculate_competition_code(unsigned char *buffer, unsigned int score) { unsigned char codelen; unsigned char comp[20]; uint32_t roller; uint16_t hash; uint16_t loop; unsigned char output; // Start with the maximum score for this level set roller=score; // Seed the hash hash=0xeeff;

Page 26: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page26 22December2017

// Calculate "HASH" of first 255 bytes of level file // PASSWORDS/TIME_LIMITS/EDIT_CODES/TRANSPORTERS/COLOUR_PALETTE for (loop=0; loop<=0xff; loop++) { // Read byte from level file output=buffer[loop]; // Update HASH LOW byte output^=(hash&0x00ff); hash=(hash&0xff00)|output; // Update HASH HIGH byte output^=((hash&0xff00)>>8); hash=(hash&0x00ff)|(output<<8); } // Add the hash to the roller roller|=(hash<<16); codelen=0x00; while (roller != 0x00) { output=0x00; for (loop=0x00; loop<0x20; loop++) { // Shift output by 1 bit output=output<<1; // If roller MSB then add to output if (roller&0x80000000) output++; // Shift roller by 1 bit roller=roller<<1; // If output overflows 0..9 then add bit to roller LSB if (output>=0x0a) { output-=0x0a; roller++; } } // Add output number to storage stack if (codelen<sizeof(comp)) comp[codelen++]=output; } // Read numbers off stack to output competition code do { codelen--; printf("%d", comp[codelen]); } while (codelen>0); printf("\n"); }

Page 27: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page27 22December2017

ReptonInfinityTheRepton Infinity filesare separated intodirectoriesondisc,dependingon theircontents.Thefilesareusuallyreferredtobytheirfilenameincludingthisdirectory:E Thumbnailsprites(fortheeditors)G Linkedgamefile(i.e.Runthistoplay)M MapsO CompiledobjectcodefromthesourceS Fullsizesprites(forthegame)T TokenisedsourcecodeD Combinedfileforsource(Masteronly)

TheAcornElectronversionwillhavean‘e’beforethisletter(i.e.eE,eG,eM,etc.).AllElectronfilesareidenticaltotheBBCfiles,exceptforthoseindicatedbelow.

G.gameformatThewholefileisencryptedwithabasicEORschemeof:byte EOR key

Thekeystartsat0andisdecreasedby3eachcycle,sowehave:byte0 EOR 0 byte1 EOR 0xFD byte2 EOR 0xFA

As‘junk’bytesareputintofillinspace,thefileshouldalwaysbethesamesize:0x0000 Sprites(as0x114fromS.*)0x1800 [junkbyte]MapAuthorName(as0x000fromM.*)0x1810 [junkbyte]SpriteAuthorName(as0x004fromS.*)0x1820 [junkbyte]CodeAuthorName(as0x000fromO.*)0x1830 [junkbyte]GameTitle(assuppliedbyLinker)0x1850 [junkbyte]EndingMessage(assuppliedbyLinker)0x1870 [junkbyte]Filename(e.g.Rep3A)0x1880 ObjectCode(as0x0F0fromO.*)paddedwithNULL0x1B50 Mapdata(as0x010fromM.*)0x2350 MapSprites(as0x014fromS.*)0x2450 ObjectCodelookuptable(from0x010inO.*)

eG.gameformatAsG.*format,except:0x0000 Sprites(as0x114fromeS.*)0x0600 [junkbyte]MapAuthorName(as0x000fromeM.*)0x0610 [junkbyte]SpriteAuthorName(as0x004fromeS.*)0x0620 [junkbyte]CodeAuthorName(as0x000fromeO.*)0x0630 [junkbyte]GameTitle(assuppliedbyLinker)0x0650 [junkbyte]EndingMessage(assuppliedbyLinker)0x0670 [junkbyte]Filename(e.g.Rep3A)0x0680 ObjectCode(as0x0F0fromeO.*)paddedwithNULL0x0950 Mapdata(as0x010fromeM.*)0x1150 MapSprites(as0x014fromeS.*)0x1250 ObjectCodelookuptable(from0x010ineO.*)

Page 28: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page28 22December2017

E.gamefileformat48blocksof16bytes,eachisaMode1screendumpofthumbnail(at2bpp=4ppB)(thumbnailis8x8pixels),asdescribedonpage8.

M.gameformatHeaderOffset LengthUse0x000 0x010 Nameofauthorterminatedwitha0x0D;therestofthelineisjunk.0x010 0x200 Mapscreen10x210 0x200 Mapscreen20x410 0x200 Mapscreen30x610 0x200 Mapscreen4ScreenformatsOffset LengthUse0x000 0x1E0 Mapdata0x1E0 0x018 Teleporters0x1F8 0x001 Mapvisibleflag(01=mapvisible)0x1F9 0x001 Passwordflag(01=requiresapassword)0x1FA 0x002 Score-a16bitnumberinLSB/MSBform0x1FC 0x004 Palette:1byteforeachcolour

Repton Infinity maps have dimensions of 32 x 24 characters with 32 possiblecharactersthatcanbeused.TheformatusedisMethodTwoasdescribedonpage7.

Transporter data is given as 2 16 bit numbers (in LSB/MSB form) for eachtransporter:sourceanddestination.Each16bitnumberisanaddress:X=addr MOD 32 Y=addr DIV 32

S.gamefileformatHeaderOffset Length Use0x000 0x0001 Colour00x001 0x0001 Colour10x002 0x0001 Colour20x003 0x0001 Colour30x004 0x0010 Nameofauthorterminatedwitha0x0D.0x014 0x0100 Mapspritechunk0x114 0x1800 SpritechunkMapspritechunksSizeofimageis4x8,andasperformatonpage8.SpritechunkEachentryis128bytesinsize,asperformatonpage8.Sizeofeachspriteis16x32pixels.

eS.gamefileformatThisisidenticaltotheS.*format,except:Offset LengthUse0x000 0x001 Colour00x001 0x001 Colour1

Page 29: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page29 22December2017

0x002 0x001 Colour20x003 0x001 Colour30x004 0x010 Nameofauthorterminatedwitha0x0D0x014 0x100 Mapspritechunk0x114 0x600 SpritechunkSpritechunkEachentryis32bytesinsize,asperformatonpage8.Sizeofeachspriteis8x16pixels.

O.gamefileformatOffset LengthUse0x00 0x10 AuthorName0xdterminated0x10 0x20 LowbyteoftheaddressoftheDEFINEACTIONroutine/sprite0x30 0x20 HighbyteoftheaddressoftheDEFINEACTIONroutine/sprite0x50 0x20 LowbyteoftheaddressoftheDEFINEHITSroutine/sprite0x70 0x20 HighbyteoftheaddressoftheDEFINEHITSroutine/sprite0x90 0x20 Systemflags(1)/sprite0xB0 0x20 Systemflags(2)/sprite0xD0 0x20 Userflags/sprite0xF0 ... 6502machinecodefortheDEFINEroutines,baseis0x5BB0

Addresses are absolute addresses for the routine which is place in memory at0x5BB0(soitstealsthefirstfewlinesofscreenmemory).Iftheaddressis0;thentheroutineisnotdefined.SystemFlags(1)are:0x01:unknown 0x02:unknown 0x04:One 0x08:Two0x10:unknown 0x20:unknown 0x40:unknown 0x80:Animate

If0x04and0x08and0,thenspeedisFour.Itisunknownwhathappensifbothare1.SystemFlags(2)are:0x01:Transport 0x02:Squash 0x04:Cycle 0x08:Under0x10:VPush 0x20:HPush 0x40:Deadly 0x80:Solid

CodeistranslatedfromtheReptoldirectlyto6502code.ThenoptimisedtoreplaceJSR xxxx:RTS with JMP xxxx. This isn't perfect if the code is followed by an END,whichwillstillstayasRTS.Codeequivalents:

(Note all JSRs can be turned into JMPs by the optimising if they are the laststatementinthelogicalflow.)

CHANCE(x):(75%usedhere)LDA #&FF:STA &33:LDA #&5F:STA &34:JSR &1D43:BCS xxxx (IF)

0x5FFF=75?Someformoffloatingpoint.Rangeis0-99.99

CHANGE(x,y):LDX #x:LDY #y:JSR &1982

Wherexandyarethespritenumberstochangefrom(x)to(y)

CONTENTSx:CMP #x

Wherexisthespritenumber(thisisreturnedfromtheroutineforLOOK(x).

CREATE(x,d):

Page 30: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page30 22December2017

LDY #d:LDA #x:JSR &19EB

or,ifintheHITSsection:LDY #d:LDA #x:JSR &1A54

Wherexisthespritenumber

disthedirection,listedbelow.Ifthisisnotincludeddis0x42

disthelocationtocreate.0x42isthecurrentlocationonagridof32characters.SoWis-1;Eis+1;Nis-0x20;Sis+0x20;NWis-0x21;NEis+0x19;SWis+0x19;NEis+0x21.(Why0x42?)

DEFINE:Isremoved-reproducethesefromtheheader

EASTOF:JSR &18A5:BCC xxxx (IF)

EFFECT(x):LDA #x:JSR &1C13

ELSE:DealtwithbyIF

END:RTS

NotremovedinOptimisation(!)evenifprecededbyaJSR;soyou'llseethestrangestatementofJMPxxxx:RTS

ENDIF:DealtwithbyIF

EVENT(x):LDA #&0e:AND #x:BNE xxxx (IF)

Theeventtimerbyte(0x000E)hasabitsetforeachtimerthathasgoneoff,sotheANDisforthecheckofthebit:6 0x7F5 0x3F

FLASH(x):LDA #x:STA &0069

Wherexisthenumericequivalentofthecolour,e.g.3=yellow

FLIP:LDA (&0058),Y:EOR #&40:STA (&0058),Y

0x0058containsthestatusbyteforthecurrentobject,bit0x40istheSTATE()bit.

GOTO(x):JMP x

x will be the absolute address for the label code; i.e. you'll only have a JMP to0x5BB0foraGOTO.

HITBY(x):LDA #&0049:BNE xxxx (IF)

IF:Usuallyjustimplementedasabranch-thisdoesdependonwhat'sbeentested.ELSEwillbeimplementedbyaJMPattheendofthefirstif,sosomethinglike:LDA (&0058),Y:AND #&40:BNE .else ... JMP .next .else JSR &1864

Page 31: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page31 22December2017

...

.next RTS

IfaJSRhasbeenturnedintoaJMPbytheoptimiser,assumethatthisistheendoftheIFbranch.

KEY:JSR &18CB

KILLREPTON:INC &0010

LABEL:

Notassembled,willhavetoreformitprogramatically

LOOK(x):JSR x

Theseareimplementedasseparateroutinesforeachdirection:F:0x17EA SW:0x1836 W:0x1844R:0x17EE SE:0x1834 E:0x1850B:0x17F2 NW:? S:0x185AL:0x17F6 NE:? N:0x1864

MOVE(x):LDA #x:JSR &19AE

Wherexisthenumericequivalentofthedirection:0:E 1:S 2:W 3:N4:F 5:R 6:B 7:L

MOVING:LDA (&0058),Y:BPL xxxx

Bit7oftheobjectstatusisthemovingflag.

NAME:Notassembled,withhavetoreformitprogrammatically.

NORTHOF:JSR &18B3:BCC xxxx (IF)

NOT:SwapsthelogicoverintheIF,e.g.BMIinsteadofBPL.

SCORE(x):LDA #x:JSR &1B37

SOUND(x):LDA #x:JSR &1C1D

SOUTHOF:JSR &188D:BCC xxxx (IF)

STATE(x):LDA (&0058),Y:AND #&40:BNE xxxx (IF)

WESTOF:JSR &189B:BCC xxxx (IF)

Userflagsarestoredin0x64

T.gamefileformatOffset LengthUse0 16 Nameofauthorterminatedwitha0x0D

Page 32: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page32 22December2017

Languagechunksx48Each language chunk is the tokenised source code of the sprite, using the belowtokens:80:NAME 81:HITBY 82:LOOK( 83:DEFINE 84:CREATE(85:IF 86:MOVING 87:ELSE 88:ENDIF 89:GOTO8A:NOT 8B:KILLREPTON 8C:CHANGE( 8D:END8E:SCORE( 8F:SOUND( 90:FLIP 91:EFFECT( 92:FLASH(93:CHANCE( 94:KEY 95:One 96:Two 97:Four98:TYPE 99:ACTION 9A:HITS 9B:MOVE( 9C:STATE(9D:LABEL 9E:EVENT( 9F:CONTENTSA0:Animate A1:REDA2:GREEN A3:YELLOW A4:BLUE A5:MAGENTAA6:CYANA7:WHITE A8:WESTOF A9:SOUTHOF AA:EASTOF AB:NORTHOF

An0x0Discountedasalinefeed.

Indentsareperformedbyabytegreaterthan0xC8,theindentisbyte-0xC8spaces.So0xCFwillindent6spaces.

Each spriteentry is terminatedwitha0xFEbyte.Anempty spritewill just contain0x0D and the 0xFE terminator. All sprites will have a definition, including theanimationsprites(eventhoughtheycannothavesourcecodeassignedtothem).

Theremaybejunkafterthe48entries,thismustbeignored.

PasswordsPasswordsareencodedusingthemapdata,sothefollowingBBCBASICprogramwillunencodethemforyou:DIM map &810,bytes 8 m%=map+&10 : PRINT"Repton Infinity Password Printer" INPUT'"Filename M."n$' OSCLI"LOAD M."+n$+" "+STR$~(map) FOR level=0 TO 2 PRINT CHR$(level+50)") "FNcalcpass(level) NEXT level END : DEFFNcalcpass(level) LOCAL A,X,Y,pword$ FOR Y=0 TO 8 bytes?Y=0 NEXT Y Y=0 REPEAT FOR X=7 TO 0 STEP-1 A=bytes?X A=A EOR ?((level*&200)+m%+Y) A=A EOR ?((level*&200)+m%+&E0+Y) bytes?X=A Y=(Y-1)AND255 NEXT X UNTIL Y=0 FOR X=7 TO 0 STEP-1 A=bytes?X A=A MOD 26 A=A+65 bytes?X=A NEXT X pword$="" FOR Y=6 TO 0 STEP-1 pword$=pword$+CHR$(bytes?Y) NEXT Y =pword$+CHR$(bytes?7)

Page 33: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page33 22December2017

SinclairZXSpectrumReptonManiaThisisbasedontheDSKfileofanoriginal+3disccopyofReptonMania.TheBINfileis theDSK filewith the 'Track-Info' strippedout (Iwroteasmall routine todo thisand produce the BIN file). The beginnings of tracks are identified by the string"Track-Info", which indicates a 0x100 area of track description that can safely beremoved for thepurposes of data extraction. The initial 0x1300bytes can also beremoved,butasthisdoesnot"getintheway"ofanydata,itisirrelevantwhetheritstaysornot.ThememoryoffsetcolumniswherethedataresideswithintheactualZXSpectrumwhen loaded.Fromthis, the respectivepositionscanbe locatedwithinasnapshotfile (e.g. z80). Remember that 0x4000-0x57FF and 0x5800-0x5AFF are the screenmemory locations for pixel data and then colourdata respectively - see thenotesbelowthebreakdown.

DSKandMemoryUsage.bin MemoryOffset Offset Description0x00000 Discdescriptoranddiscprotectionloadingcode0x01100 Data-loadingcodeandgameselector?0x01300 ReptonManiaLoadingscreen(0x1800size)0x02B00 ReptonManiaLoadingscreencolourdata(0x300size)REPTON10x02E00 ReptonLoadingscreen(0x1800size)0x04600 ReptonLoadingscreencolourdata(0x300size)0x04900 0x5B00 ReptonMaps(12offat0x400sizeeach)0x07900 0x8B00 Charactersetgraphics(eachcharacteris5bytes=8x5px)0x07A40 0x8C40 "Repton"displayattopofopeningscreen0x08240 0x9440 unknown0x08442 0x9642 Lookuptableintothescreenmemory0x08772 0x9972 Repton1mapcharacters(eachcharacteris8bytes=8x8px:32off)0x08872 0x9A72 Repton1characterarea(eachcharacteris0x80=32x32px:54off)0x0A372 0xB572 Charactercolourdata(0x10percharacter) 0xB8D2 Endofcolourdata+blankedoffworkarea0x0A6F2 unknown0x0A7B6 Lookuptableintothescreenmemory0x0A826 0xD60A Passwords-10characters,paddedwithspaces(ASCII32)0x0A89E 0xD682 unknown0x0A8AA 0xD68E Levelpalettecolours(5bytesperlevel)0x0A8E6 0xD6CA unknown0x0AB82 0xD967 Textlabels0x0AFCF 0xDDB2Nulldata0x0B0C4 unknown-code?0x0B70C Nulldata0x0B894 unknown-code?0x0C34D Nulldata0x0C44C unknown-patch?

Page 34: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page34 22December2017

0x0CCB6 NulldataREPTON20x0CD00 Repton2loadingscreen(0x1800size)0x0E500 Repton2loadingscreencolourdata(0x300size)0x0E800 0x5B00 Repton2maps,eachcharacterispackedinto5bits0x10920 0x7C20 Transporterdata:7bytes(screenfrom,X,Y,screento,X,Y,0x00)0x10AE0 0x7DE0 PuzzlePiecedata:6bytes(screen,X,Y,ScreenAX,ScreenAY,0x00)0x10BDC 0x7EDC SpiritData:4bytes(Screen,X,Y,direction)0x10D08 0x8008 "Messagetofill36sparebytesGJS"0x10D2C 0x802C Charactersetgraphics(eachcharacteris5bytes=8x5px)0x10E6C 0x816C "Repton2"displayattopofopeningscreen0x1166C 0x896C Lookuptableintothescreenmemory0x1199C 0x8C9C Musicdata0x11A9E 0x8D9E Repton2puzzlepieces(8x8px,eachpieceis0x08)0x11BEE 0x8EFE Repton2characterarea(32x32px,eachcharacteris0x80)0x1396E 0xAC6E Repton2charactercolourdata(0x10percharacter) 0xB068 Workarea0x13E00 0xD0FC Levelcolourpalette(5bytesperlevel)0x13E5A 0xD156 Levelsizeinrows(1byteperlevel)0x13E6C 0xD168 Leveloffsets(2bytesperlevel,add0xE800togetoffsetintofile)0x13E90 0xD18C Levelsurrounds(3bytesperlevel:top,sides,bottom)0x13EC6 0xD1C2 Topoflevel(01-Meteors,00-nometeors)0x13ED8 0xD1D4 SequenceofcolourstoanimateRepton2banner0x13F19 0xD215 Keyboardmapping0x13F68 0xD264 unknown0x143DF 0xD6DBTextlabels0x147BC 0xDAB8 unknown0x150B3 Nulldata0x15188 unknown0x15E51 Nulldata0x15F34 unknown0x168D2 Nulldata0x168F2 unknown0x16904 Nulldata0x169FF endofdata(restoffileisjunk)

MapsThemaps forReptonarenotcompressed,soeachbytewill representacharacter.However,Repton2mapsarestoredasperMethodTwoonpage7.

Transporters,PuzzlePiecesandSpiritsTheco-ordinatesfortheTransporters,PuzzlePiecesandSpiritsareworkedoutthus,togiveanumberbetween0and31.Thescreenswillbebetween1and18:x=(X-12)div 4 y=(Y-24)div 4

WhereXandYarethevaluesstored,withxandybeingtheactualco-ordinates.

Page 35: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page35 22December2017

Z80formatTheZXSpectrumemulatorscanstoreasnapshotofthememory,inmanydifferentformats. One of the most common is the .z80 format, which is described here(abridgedsothatonlytheinformationneededtoextractReptondataislisted).offset Description0x0000 Header0x0006 If0x0006and0x0007arezero,fileisversion2or3,otherwise10x000C Ifbit5issetonversion1,dataiscompressed0x001E V1-Data(aslaidoutinmemory);V2/3-Secondheader0x0022 V2/3-machinetype(0x0:48K,0x4:128K,0x7:+3,0xC:+2)0x0056 V2/3,notmachine0x7–Compresseddata,indatablocks0x0057 V2/3,machine0x7–Compresseddata,indatablocksVersion2/3Datablockheadersoffset Length Description0x0000 2bytes Length0x0002 1byte Page0x0003 xbytes DataVersion2/3pagesPage Memoryoffset 128K/+2/+3 48K3 0xC000to0xFFFF4 0x8000to0xBFFF5 0x8000to0xBFFF 0xC000to0xFFFF8 0x4000to0x7FFFCompressionThecompressionmethodisverysimple:itreplacesrepetitionsofatleastfiveequalbytesbyafour-bytecodeEDEDxxyy,whichstandsfor"byteyyrepeatedxxtimes".Onlysequencesoflengthatleast5arecoded.Theexceptionissequencesconsistingof ED's; if they are encountered, even two ED's are encoded into ED ED 02 ED.Finally,everybytedirectlyfollowingasingleEDisnottakenintoablock,forexampleED000000000000isnotencodedintoEDEDED0600butintoED00EDED0500.Theblockisterminatedbyanendmarker,00EDED00.Fulldetailsofboththez80andDSKformatcanbefoundontheWorldOfSpectrumwebsite(www.worldofspectrum.org).

Page 36: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page36 22December2017

EGO:Repton4PasswordsThe passwords for EGO can be found in themain program file, !Repton.ObjCode,fromoffset0x168AC to0x169A3. Therearea total of 31passwords, including thecheat (the last one). There is no terminating character as each password is 8characterslong(31*8=248).EachbyteneedstobeXOR-edwith0xFFtogettheASCIIcode.

LeveldataAlltheEGORepton4levelsarestoredinthe!Repton4.Resources.Allmapsfile.

Eachmap ismadeupof19x19 tiles.Theseare represented in the fileunencoded,andasit is laidoutasonthescreen.However,eachtile isrepresentedasa4-byteword,andthescreensarenotinscreenorder.Character position = ((level-1)*361*4)+((y-1)*19*4)+((x-1)*4) where 1<=level<=30;1<=x<=19;1<=y<=19

Togettotheappropriatedataforthescreen,thereare30bytesintheObjCodewhichareoffsets,multipliedbythedatasize,intotheAllmapsfile.Thistablecanbefoundatoffset0x165D0,andeachscreenis0x5A4insize.Therefore,theformulayouneedis:Offset into Allmaps = (byte-1)*0x5A4

Eachtileislaidoutasa4-byteword.Bytes0,1and2areusedtostoreextrainformation.Wherethisinformationisnotused,itisgenerally0x00buttreatitasundefined.Byte3referstothecharacters:0x00:Repton0x01:Puzzleplacement0x02:Upconveyor0x03:Downconveyor0x04:Leftconveyor0x05:Rightconveyor0x06:Android

Byte1isunknown.Byte2isthedirectionandspeedwith0x01,0x02&0x03representingLeft/Rightand0x04,0x05&0x06representingUp/Down.Thehigherthenumberthefasteritmoves.

0x07:GemByte1ishowmanytimestopickup,orhowmanygemsareonthespace,dependingonhowyoulookatit.

0x08:Tower/GemByte1isthesameasaGem

0x09:Tower/Potion0x0A:Tree0x0B:Tower0x0C:Disappearingtree(i.e.walkintoitanditdisappears)0x0D:Blank(orgrass,again,dependingonhowyoulookatit)0x0E:Mushroom0x0F:Blackhole

Byte1canbe0x01foralwaysthere,orothervaluesindicatingthelengthoftimeuntilitappears.0x10:Transporter

Byte1isthetransporternumber,andbyte2iseither0x00foradestinationor0x01forasource.0x11:Puzzlepiece

Byte1isthepiecenumber.Thesearenumbered,onacompletedpuzzle,1to5across,then6to10onthesecondrow,etc.to25.

0x12:Transporter/BlackHoleBytes1and2asfortheTransporter

0x13,0x14and0x15:Unused0x16:Disappearingtreewithbonus

Byte1-extrabonusscorex6000.You’llalsogetanextralifeforthistile.

Page 37: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page37 22December2017

PCRepton3GraphicsThegraphicsfiles,*.r3g,usedbyPCRepton3containall216charactersinWindowsBitmap format.Eachgraphicdoesnothave thebitmapheader,as theyareall thesame,andarestored ‘back-to-back’.Detailsof theorderof the216charactersaregiveninthePCRepton3EditorunderHelp.Normally,youwouldn’tneedtoworryabouttheformat,astheeditortakesthebitmapsandcreatesthefile.However, ifyouwantedtoeditexistinggraphics,youwouldneedtosplitthisfilebackintothebitmaps,whichtheeditordoesnotdo.

WindowsBitmapLayoutThis is an abridged version of the format, with only the information required forthese files listed. Addresses/offsets use little endian. The numbers in brackets aretheactualvaluesusedforeachbitmap.Offset Description0x0000 FileHeader0x000E DIBHeader0x0036 Palette0x???? Rawbitmapdata(seeheadersforoffset)Offset Size DescriptionFileHeader0x0000 2 'BM'IdentifiesitasaBMP(0x4D42)0x0002 4 Sizeofthefileinbytes(0x00001438)0x0006 4 Reserved(0x00000000)0x000A 4 Offsettopixeldata(0x00000436)DIBHeader0x000E 4 SizeofDIBheader(0x00000028)0x0012 4 Bitmapwidth(0x00000040)0x0016 4 Bitmapheight(0x00000040)0x001A 2 Colourplanes(0x0001)0x001C 2 Colourdepth/bitsperpixel(0x0008)0x001E 4 Compressionmethod(0x00000000)0x0022 4 Sizeoftherawbitmapdata,i.e.[0x02]-[0x0A](0x00001002)0x0026 4 Horizontalresolution(0x00000B12)0x002A 4 Verticalresolution(0x00000B12)0x002E 4 Numberofcoloursinthepalette(0x00000000)0x0032 4 Numberofimportantcolours-generallyignored(0x00000000)Restofdata0x0036 0x400 Colourpalette-BB,GG,RR,0x00foreachofthe256colours[0xA] [0x22] Bitmaprawdata.Rowsarepaddedtomultiplesof4bytes. Eachbyterepresentsacolournumberintothepalette,perpixel. Row0isthebottomoftheimage.

Therefore,inordertoreconstituteabitmap,youwillneedtosupplythefirst0x0436bytes of data, for each bitmap. You can easily see that the format expected is64x64pxat8bpp.

Page 38: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page38 22December2017

ReptonTheLostRealmsFileLayoutBBC Electron Usage0x000000 0x000000 ScreenAData0x00029D 0x00029D ScreenBData0x00053A 0x00053A ScreenCData0x0007D7 0x0007D7 ScreenDData0x000A74 0x000A74 ScreenEData0x000D11 0x000D11 ScreenFData0x000FAE 0x000FAE CharacterData0x002CAE 0x001FFE EOF

EncodingFourcharactersarepackedinto3bytesbyonlyusingbits0to5andspreadingthemacrossthe3bytes:

Byte0 Byte1 Byte27 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0

5 4 3 2 1 0 5 4 3 2 1 0 5 4 3 2 1 0 5 4 3 2 1 0Character1 Character2 Character3 Character4

ScreenData0x000to0x275 MapData(630bytes)30x28–packedasabove0x276to0x27B Password(8characterspackedinto6bytes,asabove)0x27Cto0x293 TransporterDatafor8transporters,6byteseachpackedas

above.StoredassourceX,Y,destinationX,Y.ThesourceXofalltransportersisstoredinthefirst6bytes(unpackedto8co-ordinates),thenthesourceY,etc.

0x294to0x295 ColourData,4bitspercolour(1111000033332222)0x296to0x297 EditCode(LSB/MSB)0x298to0x299 BombTime(LSB/MSB)0x29Ato0x29B Freezetime(LSB/MSB)0x29Cbit7 MapVisibility0x29Cbits4to6 FungiRate0x29Cbits0to3 AbsorbencyRate

CharacterDataTheBBCMicrouses7424bytesfor58characters,whichequatesto128byteseachat16x32pixelsinsize.TheAcornElectronuses4176bytesfor58characters,whichequatesto72byteseachat12x24pixelsinsize.BothplatformsarestoredasMODE5screendata.

Characters00Boulder 01Diamond 02Earth1

Page 39: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page39 22December2017

03Earth2 04TimeCapsule 05Skull06Blank 07Wall 08WallL09WallR 0AWallT 0BWallB0CWallTL 0DWallTR 0EWallBL0FWallBR 10Wall2 11Wall2TL12Wall2TR 13Wall2BL 14Wall2BR15Barrier 16Safe 17Cage118Cage2 19Door 1AFreezePill1BBalloon 1CAbsorbencyPill 1DEgg1EKey 1FFungus 20Timebomb21Transporter 22Crown 23Repton24Spirit1 25Spirit2 26Spirit1frame227Spirit2frame2 28ReptonDie1 29ReptonDie22AMonster 2BMonsterframe2 2CMonsterframe32DReptonlookingleft 2EReptonlookingright 2FReptonWalkingR130ReptonWalkingR2 31ReptonWalkingR3 32ReptonWalkingR433ReptonWalkingL1 34ReptonWalkingL2 35ReptonWalkingL336ReptonWalkingL4 37ReptonUp1 38Reptonup239Eggcracking

Page 40: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page40 22December2017

ClonesandSimilarGames:RiptonRipton,whichwasacloneofRepton,waswrittenbyKentonPriceandsubmittedtoA&BComputingmagazine.However,theydidnotdarepublishit.ThesedaysitcanbefoundonA&Bcompilationdiscimages,freelyavailableontheweb.

CharactersFullsize(16x32px)characters(128byteseach)LikeBBCRepton3, the full sizecharactersarestoredcomplete, inMODE5 format(seepage8).File Offset Length DescriptonRIPTON 0x3600 0x100 Riptondiecharacters(2)RIPTON 0x3E00 0x700 Monster/Ripton/BrokenEggs(14)RIPTONB 0x0000 0x900 Others(18)Mapsize(8x4)characters(8byteseach)Again,storedcompleteinMODE5format.RIPTON1 0x0F00 0x2F0 94Textcharacters 0x11F0 0x010 2blanks 0x1200 0x080 16mapcharacters

MapsThese are not encrypted in any way in Ripton, and only having 16 characters, itmeansthateachhalfbytecanbeusedforeachcharacterposition.File Offset Length DescriptonRIPTON 0x1E00 0x1400 32x32charactersperlevel, 4bitsperchar,512bytespermap

PaletteThereisnostoredpaletteinRipton.Instead,itiscalculateddependingonthelevelnumber.File Offset Length DescriptonRIPTON 0x1BF8 0x1C Codetochangepalette. Col=(level AND 3)+3; If Col=3 then Col=1

PasswordsFile Offset Length DescriptonRIPTON 0x3D00 0xB0 Passwords.16byteseach,inscreenorder–11 passwords(inconeforscreeneditor). 1stbyteXOR2ndbyte=1stchr ResultXORnextbyte=nextchr 0x0Dterminatespassword

TimelimitsAsRepton,thetimelimitsarealways6000(0x1770)

Page 41: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page41 22December2017

ClonesandSimilarGames:HWRepton3There aremany clones of the various Repton games, written by others for otherplatformsheretoSuperiorhasnotwrittenfor.Between1998and2002,HarryWoodwrote and released such a cloneof Repton3 for thePC. It has not beenupdatedsince,asSuperiorwroteandreleasedtheofficialPCversionsofthegames.YoucanstillfindHarry’sversionatwww.harrywood.co.uk/repton3.

FileStatusThereare twostatesof thedata files–one that isbeingedited,andone thathasbeenlocked.Thefirstfourbytesofthefilewillindicatewhichstatethefileisin:Offset Length Description0x0000 0x04 EDITorLOCKThefileformatwillthendiffer.

EDITFormatEach screen is held sequentially, and are 0x3DC bytes in length. The data startsimmediatelyafterthefilestatusstring.Forallbytesread,subtract0x21togetanymeaningfuldata.Offset Length Description0x0004 7 Password0x000B 1 Mapvisible:1=yes0x000C 3 TimeLimit–storedasthreecharacters:100s,10s,1s0x000F 0x3C1 Map-31x31,bottomrowfirst0x03D0 16 Transporterdetails,4byteseach(sx,sy,dx,dy)x4Totalfilesizewillbe7908(0x1EE4)bytes.

LOCKformatA locked file is somewhat more complex, as it has been encoded with a lockpassword,andcounter.Offset Length Description0x0004 15 LockPassword0x0013 1 Counterstart(byte-0x21)0x0014 Startofmapdata

LockPasswordThe lock password is held in 15 bytes, but only 8 of them are used. Bytes1,3,5,7,9,11,13 contain the password characterswhere the character ASCII code =(byte-(chr_pos-1))+1.Theotherbytes(0,2,4,6,8,10,12,14)arerandom,andcanbesafelydisposedof.

LOCKedMapsEach screen map is interlaced with each other, and the passwords, transporters,time limitsandvisible flagare interlacedwith themapdata.Also, thecolumnandrow order is interlaced. In addition, it is encoded with the lock password and acounter.Foreachbyte,theunencodedbyte=byte-0x21-p_encode-counter.

Page 42: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page42 22December2017

• p_encode iseachsuccessivepasswordcharacterASCII (to the lengthof thepassword,thenresettothebeginning),where60istakenawayuntilitis60orunder;

• counteris0to9inclusive,countingthenumberofbytesprocessed(resetto0when10isreached),andstartswithvalueat0x0013minus0x21.

Inaddition, iftheundecodedbyte is '5' (ASCII0x35),beforesubtracting0x21,thenfollowingbyteisskipped.Thedataisstoredinthisorder:row1,col31,scr1row1,col31,scr2torow1,col31,scr8row1,col30,scr1row1,col30,scr2andthentorow1,col1,scr8Following the first row of each screen, the password, interlaced with transporterdetailsandtimelimitarestored:Forthefirst4charactersofthepassword:pword_chrtrans_sxtrans_sytrans_dxtrans_dy(remember,asthemapis‘bottom-up’,thattheyco-ordinateswillreflectthis)Then,forcharacters5,6and7ofthepassword:pword_chrtime_limit_chrAndthenfinallyvisibleflag.Thedatathencontinues,inasimilarfashiontoabove:row2,col31,scr1torow31,col1,scr8withoutpassword/transporter/timelimit/visibledetails.

FinalNotesPasswords are padded with ASCII 32 to either 7 (screen password) or 8 (lockpassword).However,thesespacesareskippedontheencoding/decoding,soitwilldepend on the length of the password up to the first SPACE. Transporter y co-ordinatesareasmapislaidout(i.e.y=31-byte,asitis'bottom-up').

GraphicsThegamegraphicsareheld,asBitmaps,within theWindowsexecutable file itself.Therefore,youcaneithercreateyourown,orwriteautilitytoextractthem.

Page 43: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page43 22December2017

ClonesandSimilarGames:BonecruncherThis was produced using information published by David Boddie, and theninvestigated further by Gerald Holdsworth. So far, this document only covers theBBCMicroandAcornElectronversions,whicharefairlysimilar.

BONE2/BONE_2ThefollowingreferstothefilesBONE2ontheBBCMicrodiscversion(alsoMasterCompactandPlayItAgainSamdiscversion),andBONE_2(AcornElectronversion).Offset Length Usage0x0000 0x1400 Sprites-40off,0x80byteseach,16x32px,MODE5format0x1400 Code0x14C9 Unknown0x15F7 0x0016 Maptiletospritelookuptable-BBCMicro0x164E 0x0016 Maptiletospritelookuptable-AcornElectron0x1??? Code,including:0x1727 Numberoflives(storedat&0A)-BBCMicro0x173F Soapsrequiredtocompletelevel(storedat&05)-BBCMicro0x1774 Numberoflives(storedat&0A)-AcornElectron0x178C Soapsrequiredtocompletelevel(storedat&05)-Electron0x17C3 Invulnerability(codereducesvalueat&0Eby1)-BBCMicro0x1809 Invulnerability(codereducesvalueat&0Eby1)-Electron0x1853 InfiniteLives(codereducesvalueat&0Aby1)-BBCMicro0x189A InfiniteLives(codereducesvalueat&0Aby1)-AcornElectron0x1CD0 FozzyInfiniteenergy(codereducesvalueat&08by1)-BBC0x1CF7 FozzyInfiniteenergy(codereducesvalueat&08by1)-Electron0x1E31 0x0010 Animationsequences-4byteseachforGlook,Monster,Spider andFozzy-BBCMicro0x1E58 0x0010 Animationsequences-4byteseachforGlook,Monster,Spider andFozzy-AcornElectron0x1FAD 0x0004 Bonowalkingrightanimationsequence-BBCMicro0x1FB1 0x0004 Bonowalkingleftanimationsequence-BBCMicro0x1FB5 0x0002 Bonowalkingup/downanimationsequence-BBCMicro0x1FD3 0x0004 Bonowalkingrightanimationsequence-AcornElectron0x1FD7 0x0004 Bonowalkingleftanimationsequence-AcornElectron0x1FDB 0x0002 Bonowalkingup/downanimationsequence-AcornElectron0x206F Code0x20D2 LOAD":0.$.SCREEN1"3300[0x0D]-BBCMicro0x20E9 DISK[0x0D]-BBCMicro0x20EE Data0x2110 Code0x22B8 Unknown0x22?? Code0x22FB Unknown0x2408 0x00F8 Passwords,inreverselevelorder,eachterminatedwith0xFF. Add0x55torevealASCII,or0x40=SPC0x2500 0x0C00 Mapsstorageareafor6levels(SCREEN1,2,3and4areloaded

Page 44: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page44 22December2017

here).0x200bytesperlevel0x3100 0x1F40 Playingscreen0x5040 Code0x50D8 0x0370 Monsterwithsoapscreen–BBCMicro0x5290 LOAD:0.$.Screen13300[0x0D]-AcornElectron0x52A7 DISC[0x0D]-AcornElectron0x5448 Unknown0x587C Code0x5900 0x0040 Data-getsmovedto&600x5940 0x0020 Data-getsmovedto&1800x5960 0x0100 Data-getsmovedto&3000x5980 0x0100 Data-getsmovedto&8800x5A80 Unknown0x5AE0 Code0x5B8D Data

SCREENxWherexis1=levels1to6,2=levels7to12,3=levels13to18,4=levels19to24.

Eachrowisatleast20bytesinlength,witheachfourbitsrepresentingatileinthemap,thelowerfourbitsappearingontheleftandtheupperfourbitsontheright.Eachspecialtilerequiresanadditionalhalfbyte,sorowswithspecialtilesarelongerthan20bytesinlength.

Mapsizeis40x25tiles,buteachmapispaddedoutwithzerosto0x200bytes,withthefinalbytebeingtheactualcolournumber(3bits-BGR)ofthemap.

Tiledefinitions:0x0: Space 0x1: Horizontalwall0x2: Verticalwall 0x3: Cornerwall0x4: Cauldron 0x5: Door/gate0x6: Key 0x7: Earth0x8: Trapdoor 0x9: Sea0xA: Glook 0xB: Skeleton0xC: Monster 0xD: Spider0xE: Space(unknown/unused)0xF: Specialtile-thesearealwaysfollowedbyanothervaluewhichdetermines

whichspecialtileisused: 0x0: Fozzy 0x1: Rightwardstairs 0x2: Leftwardstairs 0x3: Upwardstairs 0x4: Downwardstairs 0x5: Bono 0x6: Volcano 0x7: Unused

SpriteorderThis is the order the sprites appear at the beginning of BONE2 (BBC) or BONE_2(Electron):0x01 HorizontalWall 0x02 VerticalWall 0x03 CornerWall0x04 Sea 0x05 Cauldron 0x06 RightwardStairs0x07 LeftwardStairs 0x08 UpwardStairs 0x09 DownwardStairs

Page 45: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page45 22December2017

0x0A Gate 0x0B Key 0x0C Trapdoor0x0D Earth 0x0E Skeleton1 0x0F Skeleton20x10 Glook1 0x11 Glook2 0x12 Glook30x13 Monsterstanding 0x14 Monster1 0x15 Monster20x16 Spider1 0x17 Spider2 0x18 Fozzystanding0x19 Fozzy1 0x1A Fozzy2 0x1B Bonodead0x1C Bonowalkingright1 0x1D Bonowalkingright2 0x1E Bonowalkingr30x1F Bonowalkingleft1 0x20 Bonowalkingleft2 0x21 Bonowalkingl30x22 BonoUp/Down1 0x23 BonoUp/Down2 0x24 BonoYawn0x25 BonoSleepy 0x26 BonoWinking 0x27 Bonohandup0x28 BonoStanding

MaptiletospriteLookupTableThis isa lookup table to find thecorrect sprite fromthemap tilebyte, i.e.a tablethattranslatesonetableabovetotheother.Thiscanbefoundat0x15F7inBONE2(BBC)or0x164EinBONE_2(AcornElectron).

For the special tiles (type 0xF, followed by a second half byte), just add the twotogether(e.g.Fozzyis0xF+0x0=0x0F,Bonois0xF+0x5=0x14,etc.).Bits5-7(0x80to0xB0)refertoananimatedsprite.Theanimationsequencescanbefoundatoffset0x1E31inBONE2(BBCMicro)or0x1E58inBONE_2(AcornElectron)andare4byteseach(eachbyteisaframe,andreferencesthesprites).

NOTE:ThelookuptabletranslatesBono’scharacter(0x14)toaSkeleton(0x0F),andavolcano(0x15)toEarth(0x0D).

Page 46: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page46 22December2017

UsefulProgramsInthissectionIpresentsomeBBCBASICprogramsthatyoumayfinduseful.

ArchimedesandDesktopRepton3DecoderThis will iterate through the specified directory structure looking for ArchimedesRepton 3 or High Res Desktop Repton 3 files. Once found, it will open them andoutputthepasswordsandeditcodesintoatextfile.REM>Editcodes REM REM Archimedes Repton 3 and Desktop Repton 3 file decoder REM written by Gerald Holdsworth REM (c)2013 GJH Software REM REM V1.10 16th December 2013 REM REM This will open all AR3 and DR3 files found in the specified REM directory and sub directories, open them and display the passwords REM and edit codes for all the levels. REM ONERRORREPORT:PRINT" at line ";ERL:CLOSE#0:END CLOSE#0 DIM data 130000,data% 512,typebuf% 10 typebuf%?8=13 VDU26,12 PRINT "Archimedes Repton 3 and Desktop Repton 3 password and edit code decoder" PRINT "written by Gerald J Holdsworth (c)2013 GJH Software" PRINT "V1.10 17th December 2013" PRINT SYS"OS_GBPB",6,,data% curdir$=FNgetname(data%+2) REPEAT PRINT"Base directory: ";:X=POS:Y=VPOS PRINTTAB(X,Y)curdir$ INPUTTAB(X,Y)""dir$ IF dir$="" dir$=curdir$ SYS"XOS_File",5,dir$ TO type% IF type%=0 PRINT"Error: "dir$" cannot be found" IF type%=1 PRINT"Error: "dir$" is a file" IF type%=3 PRINT"Error: "dir$" is an image" IF type%>3 PRINT"Error: "dir$" is not a valid path" UNTIL type%=2 REPEAT PRINT"Output directory: ";:X=POS:Y=VPOS PRINTTAB(X,Y)dir$ INPUTTAB(X,Y)""output$ IF output$="" output$=dir$ SYS"XOS_File",5,output$ TO type% IF type%=0 PRINT"Error: "output$" cannot be found" IF type%=1 PRINT"Error: "output$" is a file" IF type%=3 PRINT"Error: "output$" is an image" IF type%>3 PRINT"Error: "output$" is not a valid path" UNTIL type%=2 output%=OPENOUT(output$+".R3editcode") PROCexamine(dir$) CLOSE#output% OSCLI"SETTYPE "+output$+".R3editcode Text" END : DEF PROCwriteln(file%,line$) LOCAL i line$=line$+CHR$10 FOR i=1 TO LEN(line$) BPUT#file%,ASC(MID$(line$,i,1)) NEXT ENDPROC : DEF PROCexamine(dir$) LOCAL next%,number%,F$,screen,code,password$,x,ptr,m%,chr,P%,Q% next%=0 WHILE next%<>-1

Page 47: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page47 22December2017

SYS "OS_GBPB",10,dir$,data%,1,next%,63,"*" TO,,,number%,next% IF number%>0 THEN F$=FNgetname(data%+&14) IF data%!16=2 THEN PROCexamine(dir$+"."+F$) ELSE IF (!data% >>> 20)=&FFF AND (data%!8=28832 OR data%!8=102560) THEN X=POS:Y=VPOS PRINTTAB(X,Y)dir$"."F$" ";TAB(X,Y); IF data%!8=28832 PROCwriteln(output%,dir$+"."+F$+" (Archimedes Repton 3/Desktop Repton 3 Low Res)") IF data%!8=102560 PROCwriteln(output%,dir$+"."+F$+" (Desktop Repton 3 High Res)") SYS"OS_File",12,dir$+"."+F$,data FOR screen=0 TO 7 code=0 password$="" FOR x=0 TO 419 ptr=&380+(screen*420)+x IF (data?ptr AND 4) THEN code=code+(data?ptr*2) ELSE code=code+data?ptr NEXT P%=&380+(screen*420) IF data%!8=28832 THEN Q%=47:P%+=47 ELSE Q%=46:P%+=44 ptr=screen*8 m%=0 REPEAT chr=(data?(ptr+m%) EOR data?P%) AND &1F OR 64 P%+=Q% IF chr>13 THEN chr=chr AND &DF IF chr>64 AND chr<128 THEN password$+=CHR$chr m%+=1 UNTIL m%=7 OR chr<65 PROCwriteln(output%,"Screen "+CHR$(65+screen)+": "+STR$code+" "+password$) NEXT ENDIF ENDIF ENDIF ENDWHILE ENDPROC : DEF FNgetname(addr%) LOCAL b$ WHILE ?addr%>31 b$+=CHR$(?addr%) addr%+=1 ENDWHILE =b$

HWRepton3DecoderThisisaprogram,forRISCOS,toreadinanddecodethedatafilesfromHWRepton3,presentedheretoassistwithdealingwiththesefiles.REM>Decode REM REM Harry Wood Repton 3 file decoder REM written by Gerald Holdsworth REM (c)2016 GJH Software REM REM V1.00 18th March 2016 REM REM This will open the specified file, in the specified directory REM and display all the details about the file, including the raw REM map data for all the levels. REM ONERRORREPORT:PRINT" at line ";ERL:END REM Change this to point this towards your directory dir$="HostFS:$.Data.ReptonFile.Repton3." REM Change this for the file within that directory file$="Main/rls" SYS"OS_File",13,file$,,,dir$ TO ,,,,length% DIM data% length% SYS"OS_File",12,file$,data%,0,dir$ VDU26,12 PRINT" File: "file$ s$=CHR$(data%?0)+CHR$(data%?1)+CHR$(data%?2)+CHR$(data%?3) PRINT" File status: "s$

Page 48: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page48 22December2017

p$="" ctr%=0 pe%=0 b%=32 DIM pword$(8),time%(8),t_sx%(8,4),t_sy%(8,4),t_dx%(8,4),t_dy%(8,4),map%(8,32,32),vis%(8) IFs$="EDIT"THEN ptr%=&4 FORm%=1TO8 pword$(m%)="" FORc%=1TO7 ue%=FNgetbyte IFue%<>32pword$(m%)+=FNc(ue%) NEXT vis%(m%)=FNgetbyte=1 time%(m%)=(100*FNgetbyte)+(10*FNgetbyte)+FNgetbyte FORy%=1TO31 FORx%=1TO31 map%(m%,x%,32-y%)=FNgetbyte NEXT NEXT FORc%=1TO4 PROCtrans(m%,c%) NEXT NEXT ENDIF IFs$="LOCK"THEN FORi%=0 TO 7 b%=?(data%+5+(i%*2)) b%=(b%-i%)+1 IFb%<>32p$+=FNc(b%) NEXT PRINT"Lock Password: "p$ ptr%=&13 ctr%=(data%?ptr%)-&21 ptr%+=1 FORx%=1TO31 FORy%=1TO31 FORm%=1TO8 map%(m%,x%,32-y%)=FNgetbyte NEXT NEXT m%=x% IFm%<9THEN pword$(m%)="" time%(m%)=0 FORc%=1TO7 ue%=FNgetbyte IFue%<>32pword$(m%)+=FNc(ue%) IFc%<5PROCtrans(m%,c%) IFc%=5time%(m%)+=100*FNgetbyte IFc%=6time%(m%)+=10*FNgetbyte IFc%=7time%(m%)+=FNgetbyte NEXT vis%(m%)=FNgetbyte=1 ENDIF NEXT ENDIF FORm%=1TO8 PRINTSTRING$(93,"-") PRINT" Screen: ";m% PRINT"Screen password: "pword$(m%) PRINT" Screen time: ";time%(m%) PRINT" Transporters: "; FORc%=1 TO 4 IFFNvaltrans(m%,c%)PRINT;t_sx%(m%,c%)+1;",";t_sy%(m%,c%)+1;" to ";t_dx%(m%,c%)+1;",";t_dy%(m%,c%)+1'STRING$(17," "); NEXT PRINTSTRING$(17,CHR$127);" Is map visible: "; IFvis%(m%)PRINT"Yes"ELSEPRINT"No" PRINT" Map:" FOR r%=1 TO 31 FOR c%=1 TO 31 PRINTFNzero(map%(m%,c%,r%))" "; NEXT PRINT NEXT

Page 49: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page49 22December2017

IFm%<8THEN PRINT"Press SPACE for next map..."; REPEATUNTILINKEY-99:REPEATUNTILNOTINKEY-99 PRINTSTRING$(27,CHR$127); ENDIF NEXT : END : DEFFNc(c%) IFc%<32ORc%>126c%=32 =CHR$c% : DEFFNgetbyte LOCALue%,p_encode% ue%=?(data%+ptr%) ptr%+=1 p_encode=0 IFp$<>""THEN IFue%=&35ptr%+=1 pe%+=1:IFpe%>LENp$pe%=1 p_encode%=ASCMID$(p$,pe%,1) WHILEp_encode%>60:p_encode%-=60:ENDWHILE ctr%=(ctr%+1)MOD10 ENDIF =ue%-&21-p_encode%-ctr% : DEFFNzero(x%)=RIGHT$("0"+STR$~(x%),2) : DEFFNvaltrans(m%,c%) LOCALv% v%=TRUE IFt_sx%(m%,c%)<0ORt_sx%(m%,c%)>30v%=FALSE IFt_sy%(m%,c%)<0ORt_sy%(m%,c%)>30v%=FALSE IFt_dx%(m%,c%)<0ORt_dx%(m%,c%)>30v%=FALSE IFt_dy%(m%,c%)<0ORt_dy%(m%,c%)>30v%=FALSE IFv%IFmap%(m%,t_sx%(m%,c%)+1,t_sy%(m%,c%)+1)<>&0Av%=FALSE =v% : DEFPROCtrans(m%,c%) t_sx%(m%,c%)=FNgetbyte t_sy%(m%,c%)=30-FNgetbyte t_dx%(m%,c%)=FNgetbyte t_dy%(m%,c%)=30-FNgetbyte ENDPROC

Page 50: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page50 22December2017

AcknowledgementsThe information in this document was gathered from various sources, and thefollowingpeoplearedirectlycreditedfortheirwork:BBC/ElectronReptonandRepton2:JasperRenow-ClarkeBBC/ElectronRepton3:NeilCrutchlowandJonathanMartenSinclairReptonandRepton2:GeraldHoldsworthandGilJaysmithCommodoreRepton3:GeraldHoldsworthDesktopRepton(all):JasperRenow-Clarke,GeraldHoldsworthandDarrenSaltArchimedesReptonandRepton2:JasperRenow-ClarkeandGeraldHoldsworthBBC/ElectronReptonInfinity:DavidLodgeEGO:Repton4:GeraldHoldsworthandKrisAdcockHarryWood’sRepton3:GeraldHoldsworthBBC/ElectronBonecruncher:DavidBoddieandGeraldHoldsworthBBCRipton:GeraldHoldsworthPCRepton3(graphics):GeraldHoldsworthAlso,many thanks go to RichardHanson (Superior Interactive) and Tim Ellert (ESZConsulting) forallof their, continuing,helpandalso toDavidBoddie forhis tipofloadingfilesintothescreenmemoryonaBBCtofindthelocationofthegraphics.

Page 51: Decoding Repton

DecodingRepton

CompiledbyGeraldJHoldsworth Page51 22December2017

DecodingReptoncompiledbyand©2017GeraldJHoldsworth

HelpwiththeReptonformatsfromNeilCrutchlow,JonathanMarten,JasperRenow-Clarke,DarrenSalt,DavidBoddie,GilJaysmith,TimEllert,KrisAdcockandDavidLodge

Reptonremains©SuperiorSoftwareLtd/SuperiorInteractivewww.superiorinteractive.com

www.reptonresourcepage.co.uk