Making NES Game #15: RLE compression and DPCM samples

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hey what's going on Gamers! It looks like it takes longer   and longer for me to put out a new video. For me it's always not enough new changes.   I keep thinking I need to put something more! This time I didn't want to delay the video   update and I'm going to show what's going on  right now! Even if there's not much to show.  But first I just wanted to remind you that  my game is available to download right now!  Because I got asked if there will be  possibility to buy the ROM for the ever drive.  Come on, the ROM is free and the link  to it is in this video's description.   Okay, so the last time I kind of exaggerated  the problem with the free space in the ROM a   little bit. Especially in the thumbnail. I still have plenty enough of free space   in the ROM, but the deal is, the space is just  not in the main bank, where I need it the most.  I was kind of reluctant to move code blocks from  the main bank to other banks just because this   would make my game to run a bit slower,  but looks like I have no other choice,   because recently I was constantly  battling for every bit in this bank.  I kept freeing up several bites  and then, boom: they are gone!  While doing that I still somehow managed to   add a completely new location  and a Granny's house in it.   Now you can visit granny and she will give  you a couple of basic quests. So far she's   not interconnected with other villagers  so really you can completely ignore her. Well I actually had a problem with this new  location after I exited the granny's house I   needed to scroll a little bit and with that I  needed to push my collision data as well. And   for some reason I could not do it correctly.  What's funny that it's not the first time that   something like that happened. It was always  painful to fix the collision data offset   after moving from one location to another.  Especially when some scrolling was involved.  I've talked about my overly complex  collision detection system in more   detail in my first NES game videos,  and I got more than one comment saying   that this type of system is a bit unnecessary. Now I can say you guys were completely correct   and I'm grateful that you pointed that problem  out I just needed to react faster and get rid   of that crappy code it might be cool to have a  separate Collision layer but it's not a modern   system where you have unlimited amounts of memory  and computing power so now I have decided to make   a much simpler Collision system I'm simply  checking the tiles the character is working   on I divided the background tille set in half the  first 128 tiles are passable and the rest of them   are obstacles after I rearranged the tiles and  fixed my existing Maps I tested them in my map   editor and as you see the Collision layer looks  quite fine even the crash s looks okay so it seems   it's not necessary to have a separate Collision  layer and edit it manually also as you see I   haven't abandoned my map editor I added a grid  which can be turned on and off this improves the   map editing experience quite significantly and  also you can no longer edit the Collision layer   of course with the new Collision system there are  some problems with the Hill houses but I guess I   can fix that by copying snow tiles to the obstacle  part of the tile set or probably a better solution   would be to create a lookup table in the ROM which  tells if the tile is passable or not but I think I   will make that later I was surprised that after  deleting the old Collision code I only freed up   just 1 kilobyte of memory in the main bank I was  expecting way much more unfortunately it appeared   that the new Collision is is much slower than the  old one because for each Collision check I needed   to calculate an address for a map Row in the Rong  so how can I possibly improve the speed well I've   have decided to create a huge lookup table in the  RAM and store all the map row addresses there so   every time I would enter a new location I would  fill this table with addresses from the the maps   of this location this helped me not only to speed  up the Collision checks but also to reduce the   code because I could reuse the same address table  to check if I can use a hammer or a fishing rod   on a tile and I would no longer need to perform  same calculations so I had more than one comment   suggesting that I should use the RL compression  algorithm so I thought why not to give it a try   for those who don't know it's a very simple  compression method which instead of storing   multiple bites with the same value in a row counts  the sequences of repeated bytes and stores the   bite value and the repetition count of that value  so this way you can save up a lot of space in the   ROM especially if you have large bit maps with  little or no detail or screens that have large   chunks of repeated tiles sure I could use this  to compress my background and Sprite tile sets   but as a first attempt I just wanted to compress  the static screens that I don't need to scroll or   check collisions in them there are probably many  ways how to implement this algorithm but I just   wanted to be able to display the screen scens that  are compressed with the screen tool application   as you see there's an option which enables the  rle compression and if you would try to save a   name Table after you enabled this option it will  be saved as compressed after reading the screen   tool source code I found out that the application  looks for an unused bite your name table and when   it finds that bite it uses it as a tag value Val  so the first bite in your compressed screen is   precisely that tag value after it goes a some kind  of tile value and right after that goes another   tag value but only if this style is repeated if  so the next thing will be the repetition count   but if the tile is not repeated there will be  some another tile value and so on the compressed   file simply ends with a tile that has a zero  repetition count but what happens if I would   use all the 256 Styles in my screen and there  would be no unused ones well in that case the   screen tool would say that the rle compression is  not possible also if by any chance you would have   a screen that is filled with the same tile the  screen tool would not simply save it as a tile   value and let's say two bytes of repetition  count no the maximum repetition count for a   tile in the screen tool is 256 so if a tile is  repeated more than 256 times in a row the screen   tool would simply write tile value 256 and then  repeat this sequence until the final repetition   count is reached as you see my explosion screen  wasn't compressed that perfectly but I guess the   data is still much smaller than it was before so  I've compressed not only my cuts scene screens   but also the title game over and even the menu  screen what I love about this is the fact that   the screens are loaded still fairly quickly I  guess now I simply can't complain anymore that   I don't have any free space left the next thing  I tried was a bit unnecessary but I really wanted   to do it and I'm talking about playing audio  samples particularly speech sure it's nothing   special by today's standards maybe it might be a  bit annoying where did you learn to fly but back   in the day I was really impressed when I heard  for the first time speech in ZX Spectrum games or when I played Blades of Steel on my fam  clone Blades of Steel I was like wow my my   console can't talk so from that moment I knew it  was possible to do speech on the NES and my game   simply must have this feature so I tried to record  a simple game over phrase and play it during the   game more screen the NES CPU has a channel for  the digitized sounds called dpcm since I'm using   the fam Studios sound engine I needed to import  my recorded samples into fam Studio first as you   can see there's a section for your samples where  you can load up some wave files what is weird that   we must put our sound samples into the fam Studios  music f file if we would put our samples and would   try to export them as a sound effects code the  samples simply would not get exported which is   odd to play the sample you have two options play  the sample itself or to play the music track that   uses your sample the single sample effect will  not be played if other music track is playing   at the time so you need to stop it unless of  course it's the same music track that contains   your samp so yeah it is necessary to create a new  music track and also to use a dpcm instrument in   it you need to click the rightmost icon on the  instrument like so and there you can attach your   sample to particular notes and adjust the pitch  if it's necessary after that you can simply use   those notes in your music music track and it will  play your samples when those notes are activated   a very annoying thing about fam Studios sound  engine is that you have to put your digitized   samples in the main bank you must assign a value  to P studios's dpcm offset from this interval if   it's something else your sample simply would  not be played and in the best case you would   hear some strange farts or some Godzilla noises  this is really bad because the samples can be   very very large and hog all the space in the main  bank which is crucial for your game's core logic   and the nmi for instance my first recorded sample  took about 4 kiloby game over sure it's not much   but you need to remember the whole main bank is  only 16 kiloby so I had to relocate bunch of Co   to the second bank and it was still not enough to  fit the sample luckily I found out you can simply   reduce the sample rate but with every decrement  you need to reduce the pitch on the notes in the   dpcm instrument as well sure the sample would  no longer sound as good at least it would be   much smaller in size I had to create a separate  segment in the main bank so the starting address   for the dpsm samples would remain the same even  if I would add more code or some other stuff I   don't know maybe there's some undocumented way or  maybe I need to edit the code of the sound engine   so I could place my samples in some other bank  because I really hate to use the main bank if   you know if it's possible then please share your  knowledge in the comments so yeah now I have this was it really worth it well at least I freed up a  large chunk of memory in my main bank guess what   that's all the changes I wanted to talk about I  hope it won't take that long for my next video   to appear and hopefully I will have more things  to show so if you're interested in my further NES   game Journey then please subscribe the channel so  thanks for watching and I will see you next time bye
Info
Channel: Memelvar
Views: 558
Rating: undefined out of 5
Keywords: Nes, famicom, gamedev, devlog, RLE, Run Length Encoding, DPCM, Speach, Audio samples, asm, assembly, programming
Id: ZKeCt7NSqak
Channel Id: undefined
Length: 14min 11sec (851 seconds)
Published: Sun Oct 22 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.