Thissimplificationthat I'veillustratedis a littleunrealistic.
Itsurfacedfrom.
Onebigproblemonthatisswappingtheentireaddressspaceinonegois, well, a badidea.
Andthisisbecauseastheprogramisrunning, there's a greatdealofriskinjustswappingthememoryoutastheprogramcounterwillstartintheexactsamelocationinthenewbankofmemory.
Now, unlessyoucarefullycoordinatedthattobelegitimate, that's reallyjustgoingtomakeyourlifeis a developerquitecomplicated?
Themapmayhavebeenconfiguredthatalloftheaddressesinthisrangearemappedinto a specificbankintheprogrammemory, butalsothattheaddressesinthisrangearemappedtosomeotherbank.
Ifthecottageonlyprovided a 16 kilobyterum, thenwemirrortheaddress, effectivelysplittingthe 32 kilobyterangeintotwoidentical 16 kilobyteprogrammemories.
If, however, wehadtwobanksofprogrammemory, remember, eachoneis 16 kilobytes.
So a totalof 32 kilobytesofprogrammemoryWell, thenthatmapsdirectlyintotheCPUaddressablerange, whereitexpectstheprogramstoresideForthepeopIeYoureadingright?
Well, there's nothingtodoitall.
Wejustdirectlypasttheaddressthroughthesefunctions, takeinaninputaddressontherespectivebossofthedevicethat's callingthem, andtheyreturn a mapaddress.
SowhenCpReediscalledthemapperturnsthataddressontheCPUbossinto a physicaladdressintotheroomonthecartridgeonthisphysicaladdressisthenusedtolocatetherequireddataintheprogramMemoryvector.
Mapper 66 is a verysimplemapper, too, and I wasinterestedinitbecauseit's theSuperMarioBrothersandDuckHuntcombinationcartridge, andthisis a simplebruteforcemapper.
Oneis, onthesurfacequite a complexmapjustbylookingattheamountofdataontheWikipediaarticlecouldputyouoff, butinternally, it's actuallyquite a simplemapper.
Itjusthas a ratherobscureintoface, which I thinkmakesituniqueamongstthemappers.
However, it's importanttoget M.
M C oneworkingcorrectlybecauseitcoversoverhalfofthereleaseNintendoGames.
Also, thisisthefirstmapwe'veencounteredwherethemirroringisflexible, a necessaryfeatureforgamesthatcanscrollinmultipledirectionsdependingonthecontextofthegame.
Whatmakesthismap a ratherunusualisyoucommunicatewithitsserially, I justonebitat a time.
I imaginethiswastoreducethecomplexityofthechipandthereforereducethecostbackinthedayswhenproducingthesesortofmaterialswasveryexpensiveatthetoplevel, Macrooneconsistsoftworegisterson, aswiththeothermappers.
Er, beresponsiblefordataThat's notabovethemidwaypointoftheaddressablerangeoftheCPUbus, anditsimplytakestheaddressoffsetintothatrangeonmapsitdirectlyintothestaticGrahamprovidedonthecartridge.
Now I'vehackedinsomethingheretomakesurethat I don't thengoontoeffectdataelsewhereinthesystem.
If I return a maptodressspecificallyofallonesinthecartridgeclassthathascalledthisfunctiononourmap.
Eritissensitivetothatoneparticularcondition.
Thismakestherathernaiveassumptionthatwe'renevergoingtohave a nezrahmwith, well, fourbillionbytesofinformation.
Readformomentwilllookathowweconfigurethemapin a shortwhile, butwhatwecanseeistheimplementationisquitetrivial.
We'relookingacrossthewholeaddressablerangefortheprogramwrongnow, dependingon a particularbitofthecontrolregister, wereeitheroperatinginthispairof 16 kilobytebanksor a single 32 kilobytebank.
Thereisnoramtoeworryaboutthistime, butagain, a bitinthecontrolregisterisusedtodeterminewhetherwe'reoperatinginthislargechunkmodeor a smallerchunkmodeontheoffsets.
A calculatedaccordingly, asyou'llfindformanyofthemapas, peopIerightdoesn't doverymuch.
Memoryisthiefflexible, onethatcanbemovedaroundsowechoosewhichspecificbankthatisfromourloadregisterprogrammemodethreebehavesin a verysimilarway, butalsooppositethat.
I don't knowifthateverhappensinreality, butit's a nicelittlesafetychecktoputin.
Sowhatweseefromthismap, er, isit's actuallyquiteflexibleinhowyougoaboutmappingthevariousroomstotheaddressablespacesoftheCPUandthepeopie.
You?
Yeah, ittakes a littlebitofthinkingaboutit, andperhapstheyhadautomatedtools, whichhelpedthem.
Thisleavesuswithtworemainingfunctionsofthe M M C threemapper, andthatishandlingthisnewfeatureintoitrequestson.
I'lladdthatthisisn't aninterruptrequesttothemap, er, togoanddosomething.
ThisisthemapforgeneratinganinterruptrequestfortheCPU, andsofarinthisseries, we'venotreallyhandledanyinterruptrequestsotherthanthenonmaskherbalinterruptissuedbythe P.
P U.
Thatparticularinterrupt, whichusedtoinformtheCPUthatithadfinishedrendering a frameandthereforethegameLukecouldgoaheadandgettheinputs, dosomecalculationsandproducedtheoutputforthenextframeinmanygamesisusefultosplityourscreenintodifferentregions, particularlyifyou'vegotstatusparts.
So, forexample, inthisregion, appearyoucouldhavescoreinformationonperhapsdownhere, youhaveinventorystuff I don't know, leavingthisregioninthemiddletohavesomesortofgainenvironmenton.
Welookedinthepastthatthepeopieyou, howithandlessplitscreenscrollingandingameslikeMarioone, asthescanlineiszippingacrossthescreen, itwaitsfor a specificpixeltobehit.
Andbykeepingtrackofthisaddress, itcandetectwhenthere's been a memoryaddresschangeinsuch a waythatwouldtypicallyreflecttheendof a scanline.
Now, ifyou'rereallyhardcoreaboutmakingyouremulators, youcouldgoaheadandimplementthislogicandtryandgetit a cycleaccurateaspossible.
I'venotdonethatwithmyemulator, soit's notstrictlyanoptionforme, butbecause I havewrittenthisemulator, I cancheat.
Therefore, I willaddspecificallytomymapperintoface a functionthatiscalledwhen a scanlinehasbeencompletedandthemap a canaccumulatethescallsonissue, and I arecutewhenrequired.
Nowlet's have a lookatmymapoffourimplementation I'venow.
I didsomeadditionalfunctionstotheinterfacetoehandle.
Theai R Q.
Onthisisthatscanlinefunction I'vejustmentionedinternally, I'vegotthoseeightregisters, and I'vealsocreatedtointernalarraystostorethebankoffsetsforthecharacterandprogramROM's.
Er, isthisscanlinefunctioneverytimeit's calleditjustdeckremainsthecounteronwhenthecounterreacheszeroreloadsitwiththevaluethatwe'vesetsowecangetittofireeveryfivescanlines.
Every 20 scanlines, every 39 scanlines, whatever.
Intheeventthatthe I R Q Counterhasequalzeroon, we'reactuallyinterestedinreceiving. 00:4