Creating an Operating System for the NES

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
i built an operating system for the nintendo entertainment system why i think a better question might be how an operating system is a program that sits on top of the hardware of a computer and allows other programs to interact with a computer without having to worry about communicating directly with the physical components of it but the nintendo entertainment system otherwise known as the family computer in japan like many other home computers of that day did not come with an operating system rather games were written directly in instructions that the cpu executed on demand during the era of the nes other machines like the apple ii did have operating systems that you could put onto your computer like dos but it wouldn't be until apple took the idea of the graphical user interface from xerox that we would get operating systems that looks like something that runs on our computers today since dnas was a game machine and not a home computer it's no wonder no one ever created a dedicated operating system for it that is until today i'm going to create the nes os or as i like to call it nisos it's not going to be a command line based operating system like dos because one the system doesn't have any disk drives so i'd have to call it ross or something like that and two something like that would work great for being a basic writing machine but there's already a program called family basic that does that already no nissas will have an interactive gui with two core applications the word processor and the settings i want nissas to feel like an actual operating system that nintendo might have made back in the day for the nes what would it have looked and felt like i think it would be something like this an nes program is essentially a virtual game cartridge that is set up in the same way being mostly dedicated to the program rom where the game code is stored and the character realm where the graphics are stored so i'm bringing out my boilerplate file to get started i did wind up debugging it for a good hour so but eventually i got it to correctly compile and was able to write out this message here in sprites i had a little trouble at first trying to get the color palettes right but eventually i found the rogue command i was throwing everything off and here we are if you're wondering what this mini kirby is doing here that's the cursor for the os and yes he does like being in the files and no gui would be complete without an iconic background just like this no no no close yes this one here these are the kanji for nintendo and i made it look similar to the modern nintendo logo by putting this ring around it and i don't think it looks half bad after that i added the taskbar and this reset button this is the equivalent of hitting the physical reset button on your system just in digital form instead and the desktop is pretty much done at least in terms of layout so now i'm going to begin to write the first app for the system the word processor so how does this work as a quick review the character realm of my virtual game cartridge is broken into two sections of 256 sprites each one section for foreground sprites and one section for background sprites however the nes can only display 64 foreground sprites at a time these sprites are all only 8x8 pixels but can be moved together to represent larger entities like a mario or a file using foreground sprites would mean that i could have it max 64 characters in a text document a pitiful amount considering this sentence has 163 characters in it luckily the nes also has background sprites these background sprites must remain on a grid system and are represented by only a single byte in memory referencing one of 256 possible background characters but the whole background can be covered providing much more than 64 characters to write with and so not counting the taskbar area or the area that gets cut off and isn't visible the text file will be able to have 832 characters in it now let's remember that the nes controller only has eight buttons not the 101 keys found on a standard keyboard and not the 88 keys found on a standard piano so how is typing going to work well the nes does have a keyboard or at least the japanese version of the nes the famicom did don't forget that these two systems are actually one in the same with only a few minor differences one of which is that the famicom's controllers were plugged directly into the board and couldn't be unplugged by the user at will but it did have a 15-pin expansion port on the front of the console that it used for things like the zapper gun whereas in the nes the 8-pin controller ports acted as the expansion port for those sorts of things that means thanks to the magic of online wikis and extensive debugging nisos is compatible with a family basic keyboard and as you can see it works rather well i've decided to add 64 typeable characters to the word processor these letters here are the same font as found in super mario and these other characters here are building blocks the user can use to make fun shapes and designs given that the family basic keyboard has 72 keys on it that means there are eight extra keys that aren't assigned a certain background character these extra keys are all given unique functions in the word processor the arrow keys move the cursor around the screen freely the delete key of course deletes the last character the return key prints the last character printed the clear key clears the screen and the escape key closes the program and returns the user to the desktop nes users on the other hand will have to type these characters with the buttons on the controller like this a types the letter you want to print and b acts as the space bar holding a cycles through the letters that can be typed holding select with a or b reverses the process a cycles in reverse and b moves backwards honestly it sounds more complex than it actually is holding a controller it feels rather intuitive after a minute and of course i added buttons on the screen for clearing closing the program and saving the file to the system now where is my text data in memory right now to understand that we need to first understand that there are three processors in the nes the central processing unit the audio processing unit and the picture processing unit is the latter of which the ppu that deals with taking the bytes representing sprites and turning them into actual images in order to do this job effectively the ppu has been given its own dedicated ram to do its work in and the current background screen data ier text is in that ram that the ppu has exclusive access to specifically in a section called a name table and that's where i want it to stay i thought about creating a copy of this data in the cpus directly available memory that way i could easily access this data and i could even implement scrolling to make the document a little bigger even but even just one screen's worth of data is 832 bytes that's almost half of all the free memory in this 2k system and a significant chunk of what's left after i add in variables audio processing and sprites so i decided it best to limit file size to 832 bytes and make each file worth only one screen's worth of memory and this brings us to how exactly we save data on the nes early nes games didn't have any save features and the nes itself never had any memory on the system that games could write to and access save data this is why some games would give you a code you could input to get you to a certain checkpoint in the game but eventually later cartridges became more advanced and provided the ability for data to be preserved between play sessions it was stored on a special ram chip called nvram which was itself in the cartridge and was attached to a battery that kept the lights on in the chip so to speak luckily i don't have to worry about the particulars of physical cartridge design and computer chips because i'm creating a virtual game cartridge all i have to do to say that this game has battery-backed ram in it is to switch one value in my program header then to save data to that chip i just write data to the 8k of ram located between 6000 and 8000 and since we have 8k of memory available now that is enough for nine whole files of data with a little left over but i'm going to restrict the number of files to eight since it's just a nicer number than nine and you never know when you might need more space to store things remember that the text file is currently sitting inside the ppu's first name table this means that the cpu can't see it directly i have to politely ask the ppu to look at the address it's located at then read the data one byte at a time by looking at that same address whenever i save i have to go through this process of getting the background screen data bite by byte and then writing it to the designated save area of memory but once you do save your file it shows up on the desktop and then you can click on whichever file you want to load and see that your file really has been saved even if you reset the machine it's still all there it also has a message for when you already have eight files it says that the disk is full and it won't be able to save the current file you'll have to go clear a previously made file or delete it and entirely start over and that brings us to the settings app which also functions as the file manager i began with the icon of course and then when it's opened i want it to look like a window with the background of the desktop still visible this is easy to do once you understand how color on the nes works i just have to set the background characters of the window to a different palette and then they show up as this color here and then i can write out the text i want to show up in the settings first of all it needs to say what the app is then it needs to manage the cursor desktop color and also the files i'll leave a gap for where the files are going to be labeled then i want some system information down below like the processor ram nvram and of course the os version nisos 1.0 now i need some control buttons for the cursor and desktop and then check if each file exists or not if it does exist add it to the list here adding functionality for the cursor and background buttons isn't going to be hard either i just keep track of a single byte each in the 8k of nvram to remember which cursor and background the user chooses and then load up that variable when the system boots up and managing the files is easy as well i don't have to erase all 832 bytes of file data when one gets deleted instead i have it set up where there is another section of data in the nvram that keeps track of the file metadata one byte of which simply tracks if the file exists or not this is the byte that gets checked for whether or not to add the line for each file in the settings app it's also the byte the word processor uses to check if the file is available as new or not so when this button is pushed on the settings page and deletes this file it only has to flip that single byte to zero then the os will treat that section of data as empty and here you can see that really does work i can create a new file save some data to it go to settings delete it and it's gone and then i added a calculation for how much free memory is available since a file is a static 832 bytes it just subtracts how much of that is available from the 8k of nvram before moving on from the settings i added five more cursors which are callbacks to some of the most notable games on the nes from the beginning there is the normal cursor the mini kirby a mushroom from mario link's boomerang from the legend of zelda a shuriken from the mysterious murasame castle a tetramino block from tetris and the golf ball from golf and as for the background there are 53 possible colors that the user can choose from basically every color that the nes is capable of displaying then one last set to make it really feel like an operating system was to let the user move around the icons on the desktop if the user scrolls over a file or program and presses b then they can drag it around anywhere on the screen with them so feel free to arrange your files however you want and you can always place the app icons on the taskbar as well nisos 1.0 a 48 kilobyte operating system is still a little buggy but it's good enough for the public to experience just hit the reset button if it ever freezes up on you follow the links down below to download a copy of nisos and try it for yourself on your favorite emulator the nes or famcom itself if you want to see more projects like this then click subscribe and until next time thanks for watching [Music]
Info
Channel: Inkbox
Views: 587,827
Rating: undefined out of 5
Keywords: NESOS
Id: UTWK_bIJf1U
Channel Id: undefined
Length: 11min 11sec (671 seconds)
Published: Thu Sep 22 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.