YouTube2Text

Why Do Arcade Games Boot Up Like This? — Transcript

by Retro Game Mechanics Explained · 6,802 words · 738 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Warning!
  2. 0:00This video will have
  3. 0:01a higher than average amount of flashing colors and graphics.
  4. 0:05If you're sensitive to this sort of thing,
  5. 0:07you might want to skip forward to the second half of the video.
  6. 0:10I'll be putting this warning sign in the corner for a few seconds
  7. 0:14before each video clip, so you can brace yourself.
  8. 0:17Let's look at some arcade game self-tests!
  9. 0:20♪ [intro jingle] ♪
  10. 0:23Retro Game Mechanics Explained is brought to you
  11. 0:26by its YouTube members, Patreon supporters, and viewers like you.
  12. 0:31Thank you!
  13. 0:34In a couple of my previous videos about Pac-Man, I've
  14. 0:36shown this short clip of the game starting up for the first time,
  15. 0:40and there have been
  16. 0:41a handful of comments asking me what the heck is going on here.
  17. 0:45This isn't the game glitching out or anything.
  18. 0:47It's intended to look like this.
  19. 0:49In fact, it's intended
  20. 0:50to look exactly like this, and if it doesn't, there's a problem.
  21. 0:54This is one of many self-tests that we'll look at today.
  22. 0:58Essentially, this is the machine testing every single bit of memory
  23. 1:02that is included on board by writing ones and zeros everywhere,
  24. 1:06and then reading them back to make sure they all work properly.
  25. 1:09If even a single bit doesn't stay a one when set or zero
  26. 1:13when reset, it will be detected and reported as an error.
  27. 1:18This way, the manager of the arcade machine
  28. 1:20can quickly fix it and get it back in working order.
  29. 1:23These game machines are moneymakers, after all,
  30. 1:26and if they're just giving away free games when they aren't supposed to,
  31. 1:29or if they're just flat out broken, they aren't bringing in the quarters.
  32. 1:33The reason for all of the glitchy looking graphics is because video
  33. 1:37memory itself is included in the memory tests,
  34. 1:40and the jumble of tiles on the screen is just a side effect of writing
  35. 1:44a bunch of different numbers to all of the memory locations.
  36. 1:48All of these tests are only done when the machine is booted
  37. 1:51up, which is presumably done
  38. 1:53when no players would be around to see anyway.
  39. 1:57The most common self-tests at boot are memory tests,
  40. 2:00but a lot of games will also perform ROM checksums as well,
  41. 2:03which is just another form of memory test if you think about it.
  42. 2:07While these are a quick
  43. 2:08and easy way to check for crude modifications of game code,
  44. 2:12they're also good to ensure the integrity of the ROM chips,
  45. 2:15as well as if they're even present
  46. 2:17and seated correctly on the motherboard.
  47. 2:19Other tests can include a sound test,
  48. 2:22which is usually just a sound or two that lets you confirm
  49. 2:25that the audio is present and in working order,
  50. 2:27as well as a big grid pattern like this, which helps
  51. 2:30with checking the alignment and brightness of the CRT monitor.
  52. 2:35A lot of arcade machines have some sort of switch,
  53. 2:37either in the cabinet or on the motherboard itself,
  54. 2:40that allow the manager to put the game into service mode.
  55. 2:44This mode can allow access to more tests, and provides results
  56. 2:48of the tests that can stay on screen for longer than half a second.
  57. 2:53Usually, everything you see at boot is present
  58. 2:55here as well, such as the checksums and memory tests.
  59. 2:59Full fledged sound tests are more common here,
  60. 3:01allowing for every sound effect and music track to be played back.
  61. 3:05More full screen grids are common, as well as color bars
  62. 3:08for more involved testing and color correction.
  63. 3:12Service mode is also where the game’s DIP switch states are shown.
  64. 3:16This small set of switches, usually located on the motherboard,
  65. 3:19control game properties such as the number of lives
  66. 3:22you start with, number of points
  67. 3:24to get an extra life, game difficulty, and so on.
  68. 3:27Being a physical switch you have to flip,
  69. 3:30you wouldn't need an extra battery to save these settings.
  70. 3:33The switches were usually unlabeled though, so this was a way
  71. 3:37you could change the settings without having
  72. 3:39to find the owner's manual to tell you which switch did what.
  73. 3:44I want to analyze some of these self-tests
  74. 3:46and figure out exactly what is happening at each step.
  75. 3:49But first, it would be a good idea to be familiar
  76. 3:52with the different types of memory, at least with video memory,
  77. 3:55as it's easy to tell apart visually during all of the tests.
  78. 3:59First, we can split memory into two main categories:
  79. 4:02read only memory and read/write memory.
  80. 4:06Read only memory, or ROM, is self-explanatory.
  81. 4:09This memory cannot be written to.
  82. 4:12These memory chips are burned once,
  83. 4:14and so the data they have on them generally can't be changed.
  84. 4:18Yes, technically some types of ROM can be rewritten,
  85. 4:20but for our purposes now, we'll just ignore that.
  86. 4:24There are two main types of ROM found in arcade machines.
  87. 4:27The first is the program ROM.
  88. 4:30These ROM chips contain the game code and they determine exactly
  89. 4:33how the game runs.
  90. 4:35The other type of ROM is graphics
  91. 4:37ROM, also known as character ROM or sprite ROM.
  92. 4:41These chips hold all of the graphics data used
  93. 4:43in the game from the backgrounds, text, and sprites.
  94. 4:47Program ROM and graphics ROM are generally stored separately
  95. 4:50because while the main processor utilizes the program ROM
  96. 4:54in order to execute the game code, it's the graphics processor
  97. 4:58or video unit that requires access to the graphics ROM.
  98. 5:02These two processes are usually happening simultaneously,
  99. 5:05and having them on separate chips helps with that functionality.
  100. 5:09Also in this read only category would be BIOS
  101. 5:12data--basic input/output systems.
  102. 5:14While the main processor in arcade machines might not have a BIOS,
  103. 5:18there are often more dedicated chips and microprocessors
  104. 5:21that might have embedded BIOS programs.
  105. 5:25The other kinds of memory can be written to
  106. 5:27to well, store information, the first of which is a technicality:
  107. 5:31processor registers--accumulators, index
  108. 5:34registers, stack pointers, etc.
  109. 5:37These memory locations aren't found on a memory chip,
  110. 5:40but rather inside the processor itself.
  111. 5:42Generally, there are a small number of these values when compared to
  112. 5:45how much data can be stored inside a dedicated memory chip.
  113. 5:49The rest of the writeable
  114. 5:50memory here are all random access memory or RAM.
  115. 5:54Random access, meaning that there isn't much, if any, variance
  116. 5:58in access time between two locations in that memory.
  117. 6:02Here we can have audio RAM, which is memory that is dedicated
  118. 6:05to the sound system for playing sound effects and music.
  119. 6:08This can hold music data, but often that is kept in the program ROM.
  120. 6:12While audio RAM
  121. 6:13holds stuff like the length and pitch of currently playing notes.
  122. 6:17There's also video RAM,
  123. 6:19which is memory that is dedicated to the graphics system.
  124. 6:22We'll come back to that.
  125. 6:23And then there's general purpose RAM, which can be used
  126. 6:26for any other purpose, sometimes referred to as work RAM.
  127. 6:30This is where you would find all of the game variables
  128. 6:32such as timers, level numbers, entity positions, velocities,
  129. 6:36and a whole bunch of other properties.
  130. 6:39We're going to split up the video RAM even further,
  131. 6:42just because
  132. 6:42it's pretty visually distinct when it comes to all of these self-tests.
  133. 6:46There's the tile RAM, also known as tilemap RAM, or background
  134. 6:50layer RAM, or sometimes just plain video RAM.
  135. 6:54This memory just holds the tile ID
  136. 6:56of every tile that should be visible on screen.
  137. 7:00This is usually partnered with the tile palette RAM or tile
  138. 7:03color RAM, which defines which colors each of these tiles uses.
  139. 7:08Those palettes are derived
  140. 7:10from the values that are found in color RAM, which holds
  141. 7:13definitions for each of the colors the tiles and sprites can use.
  142. 7:17Sometimes this is stored as red green blue color values,
  143. 7:20but it can also be in other formats depending on the hardware.
  144. 7:24Color data is also sometimes just stored in ROM instead
  145. 7:27if the color palette of the game isn't dynamic.
  146. 7:31And finally, there's the sprite RAM or object RAM,
  147. 7:34which holds data on every moving sprite on the screen.
  148. 7:38Unlike the tiles, which are restricted to a grid,
  149. 7:41these sprites can move anywhere on the screen,
  150. 7:43so this data usually contains X and Y position pairs as well as a sprite
  151. 7:48tile ID and palette number, not unlike the tiles themselves.
  152. 7:52Not every arcade
  153. 7:53machine system will have all of these types of memories,
  154. 7:56and the amount of each memory can vary as well.
  155. 7:59A game that only has a single background
  156. 8:01tile layer will only need
  157. 8:02enough memory to list out all the tiles that fit on screen,
  158. 8:06but a game that has multiple layers will need extra tile RAM for example.
  159. 8:11And any vector based game won't have any of these types of video RAM,
  160. 8:15but rather a different kind of video RAM meant for storing instructions
  161. 8:18for drawing all of the vectors on the screen.
  162. 8:23Let's look at a bunch of examples now.
  163. 8:26First, here is Galaxian’s bootup sequence.
  164. 8:29Blink and you miss it--this one's pretty quick.
  165. 8:32The first thing that happens is actually a solid black screen,
  166. 8:35which is a memory test on the generic work RAM.
  167. 8:38There's nothing drawn to the screen yet
  168. 8:40at this point, which is why it's completely dark.
  169. 8:43Second is the memory test on the tile RAM.
  170. 8:46The most common kind of test is to write a bunch of numbers
  171. 8:49in a sequence to the entirety of memory,
  172. 8:52and then read back everything
  173. 8:53to make sure that they match what was written.
  174. 8:55In this case, the game starts with a certain tile ID 64
  175. 9:00and then adds 47 to the ID to find the next tile’s ID,
  176. 9:04wrapping around at 256 if needed.
  177. 9:07Then it reads all of them back, making sure
  178. 9:09all of the IDs are 47 away from each other.
  179. 9:13It does this test 32 times, starting with a different initial tile ID
  180. 9:17each time.
  181. 9:19The next test is incredibly quick
  182. 9:21and you can't even see it after the tile RAM test.
  183. 9:24The game calculates the ROM checksums.
  184. 9:27While Galaxian has character ROM chips and program
  185. 9:30ROM chips, only the program ROM chips are checked.
  186. 9:34This is done by adding up every single byte from
  187. 9:37each of the ROM chips into one value, wrapping around at 256.
  188. 9:42If the ROM is genuine, it will always add up to the same number.
  189. 9:46The fourth test here is on the sprite RAM.
  190. 9:49A similar test to the tile RAM is done on the sprite RAM,
  191. 9:52which is what causes these graphics to flicker all over the place.
  192. 9:56Due to the pattern of numbers used for the test,
  193. 9:59the sprites always show up on this screen in this diamond shape.
  194. 10:03Then very briefly, if all of the tests pass, the letters
  195. 10:07“OK” are shown on the screen along with the DIP switch settings.
  196. 10:11One coin in the coin box will give one credit,
  197. 10:14the player gets an extra life at 7000 points,
  198. 10:17and starts with three lives.
  199. 10:20Then the screen fills with this grid pattern
  200. 10:22for a moment just so you can quickly check the screen alignment.
  201. 10:26Then the game jumps into normal gameplay with attract mode.
  202. 10:30If any of the tests fail, the whole process starts over.
  203. 10:34This way, if there was just a fluke, it will start normally on a retry.
  204. 10:38But if there's a real problem,
  205. 10:39the tests will keep going over and over and over again.
  206. 10:43In the case of Galaxian, the manager of the machine
  207. 10:46would need to switch the game into service mode.
  208. 10:48When in service mode, the tests do not start over
  209. 10:52and instead the game will report which chip went bad.
  210. 10:55If a ROM chip failed its checksum test, it will report bad ROM,
  211. 10:59and if any of the RAM chips
  212. 11:01failed their bit test, it will report bad RAM.
  213. 11:05You would have to defer to the owner's manual to decode
  214. 11:07the number here, which narrows it down to which chip went bad.
  215. 11:12Here's another one.
  216. 11:13Teddy Boy Blues has a relatively long self-test on boot.
  217. 11:17Its memory tests are pretty extensive.
  218. 11:20The game seems to hang on this screen that shows “IC CHECK” for a while.
  219. 11:25That's because instead of just checking if each
  220. 11:28bit in each byte in memory works correctly,
  221. 11:31requiring eight passes, (one for each bit),
  222. 11:34it checks if every byte in memory can properly hold every eight-bit
  223. 11:38value from 0 to 255, essentially
  224. 11:41requiring 256 passes.
  225. 11:44Eventually, the words on screen start to flash along with the background.
  226. 11:48This is the color RAM being checked for all possible values.
  227. 11:52Next, video RAM is checked very thoroughly by making sure
  228. 11:55every tile in the tilemap can possibly be every tile ID,
  229. 12:00and this game has two background layers,
  230. 12:03so the second one is checked after the first one is done.
  231. 12:06Lastly, the scrolling
  232. 12:07behavior of the background is tested with a bit of movement.
  233. 12:10Then the game starts up normally 47 seconds after powering on.
  234. 12:16If any of the tests fail, the screen immediately
  235. 12:19shows the ID of the bad chip on the motherboard.
  236. 12:22This game’s service mode doesn't have much, it
  237. 12:25just features the state of the DIP switches, buttons,
  238. 12:28and a very simple music and sound test, along
  239. 12:31with a second screen with some color bars.
  240. 12:35The last game I want to show off here is Joust
  241. 12:372, only because it has the coolest service mode in a game I've seen.
  242. 12:41When this game starts up, the first thing that happens
  243. 12:44is a few memory tests, along with a short sound test.
  244. 12:48Unlike most games that use sprite
  245. 12:50objects in conjunction with a grid-based background layer,
  246. 12:53Williams Electronics games like Joust use a gridded out background
  247. 12:57along with a single bitmap pixel-based layer for moving objects.
  248. 13:02That's why this memory test looks a lot more like TV static
  249. 13:05than any of the other ones we've seen so far,
  250. 13:07because this is the bitmap layer being tested.
  251. 13:11This next screen is a fun
  252. 13:12visual representation of the ROM checksums being tested.
  253. 13:16The big rectangle is the motherboard, and each little rectangle
  254. 13:19is the location of a particular ROM chip on the board.
  255. 13:23Each chip will light up green when the checksum passes
  256. 13:26and will turn red if it fails.
  257. 13:29If everything goes smoothly, the game reports
  258. 13:31“all systems go,” which is fun.
  259. 13:35The real fun here though, is the service mode.
  260. 13:38There are so many in-depth tests and options here.
  261. 13:41Upon entering service mode, the ROM checksums are performed again.
  262. 13:45Then next up is the RAM tests again.
  263. 13:48However, these tests will just keep going on forever
  264. 13:51until you press the button to advance to the next screen.
  265. 13:54So if you really wanted to stress test
  266. 13:56that memory, you could leave this going for a long while.
  267. 13:59The next test is a test of the CMOS RAM.
  268. 14:02Remember everything about DIP switches?
  269. 14:05This game doesn't have any, and instead
  270. 14:07saves all of its options in a special memory location here.
  271. 14:10It also stores a bunch of other stuff,
  272. 14:12including the high scores, so those can persist over a machine reset.
  273. 14:17The next screen is a simple sound test
  274. 14:19that plays each of the game’s sound effects and music tracks.
  275. 14:22[Joust 2 sounds]
  276. 14:23[Be careful, warrior!]
  277. 14:25[vulture screaming]
  278. 14:26Then there's the switch test, which lets you test
  279. 14:29each of the cabinet’s input buttons and coin boxes.
  280. 14:33The next screen cycles through a bunch of solid colors,
  281. 14:37and the next screen shows a fancy grid pattern.
  282. 14:42Then another solid screen
  283. 14:43of red, green, blue, and then some color bars are useful
  284. 14:47for diagnosing issues with the video system.
  285. 14:51And the next screen is the bookkeeping totals.
  286. 14:54The game keeps track of a bunch of statistics
  287. 14:56about how much it's played,
  288. 14:58how many coins have been fed, total number of credits,
  289. 15:01and how many minutes of gameplay have occurred.
  290. 15:04The final screen
  291. 15:05is all of the settings that take place of any DIP switches.
  292. 15:09The advantage of using special battery-backed RAM for these settings
  293. 15:13is that you can be a lot more granular with the options.
  294. 15:16For example, you can start with anywhere from 1 to 99 lives.
  295. 15:21There's also a difficulty setting and an option
  296. 15:23to extend the number of letters a player can input
  297. 15:26when they achieve the highest score on the leaderboard.
  298. 15:29But my favorite parts are here at the bottom.
  299. 15:32There's an option specifically to overwrite the high score’s
  300. 15:35name with custom text without removing the score itself.
  301. 15:39Just in case someone enters something inappropriate,
  302. 15:43there's also an option to set
  303. 15:45a custom message text that appears on the title screen.
  304. 15:48You can input a full two lines of text and reposition it on the screen,
  305. 15:53which just seems silly, but also really cool that the option
  306. 15:57is even there.
  307. 15:57[Who will challenge me?]
  308. 16:01The last thing I want to do in this
  309. 16:02video is analyze the code for a couple of these self-tests.
  310. 16:05I'm going to go over Pac-Man and Super Pac-Man's
  311. 16:08testing functions, breaking down the assembly code.
  312. 16:11Despite being the sequel, Super Pac-Man’s self-test is entirely
  313. 16:15different and much more complicated for reasons we'll see shortly.
  314. 16:19Oh, and there's not going to be any more flashing colors and graphics
  315. 16:22for the remainder of the video, so you're safe there.
  316. 16:25Let's go ahead and look at Pac-Man's code.
  317. 16:29Pac-Man uses a Zilog Z-80 processor,
  318. 16:32and here's the assembly code for all of the self-tests.
  319. 16:36Z-80 assembly is pretty sparse, and it takes a lot of instructions
  320. 16:40to do simple things, which is why this seems like a lot of code.
  321. 16:44It can be split up into three main sections: the ROM checksum tests,
  322. 16:49the RAM memory tests,
  323. 16:50which can be split into the writing phase and the reading phase,
  324. 16:55and then the clearing of all memory.
  325. 16:57Let's look at the checksum calculations first.
  326. 17:01Pac-Man uses four ROM chips, and each
  327. 17:03chip's checksum is calculated independently.
  328. 17:07If a chip's checksum is incorrect, the game will report
  329. 17:10which chip failed so it can be replaced.
  330. 17:13And each chip actually has two checksums.
  331. 17:16The even and odd bytes are summed together separately.
  332. 17:20So this code first calculates the four chips’
  333. 17:23even-byte checksums, then their odd-byte checksums.
  334. 17:27Here's some equivalent pseudocode for this big nest of loops.
  335. 17:31Being an 8-bit CPU, this innermost loop
  336. 17:35sums together each 256-byte page of ROM.
  337. 17:39Or rather, the 128 even or odd bytes in each page.
  338. 17:44The next inner loop
  339. 17:45advances through the 16 pages per ROM chip.
  340. 17:49This line of code here is doing what's referred to as “kicking
  341. 17:53the watchdog,” which is essentially just resetting an internal timer.
  342. 17:57The watchdog is a hardware mechanism that is responsible
  343. 18:00for restarting the entire system if left idle for too long,
  344. 18:04so that if the game were to ever lock up somehow,
  345. 18:07it would restart all on its own without needing someone to physically
  346. 18:10come out to turn the machine off and on again.
  347. 18:13In order for this not to happen, this particular register
  348. 18:17needs to be written to regularly,
  349. 18:19and it's done several times during all of these tests.
  350. 18:23Here's the actual comparison to confirm the checksums.
  351. 18:26The running sum total is an 8-bit value that wraps around at zero,
  352. 18:31and it should equal exactly zero after each calculation.
  353. 18:36Generally, the
  354. 18:37last byte in each ROM chip (or the last two bytes, one even
  355. 18:41and one odd) is reserved to be the checksum complement,
  356. 18:44which is pre-calculated at the time the ROM is burned onto the chip.
  357. 18:48The value is chosen to be the exact value
  358. 18:51needed to make the entire sum equal zero.
  359. 18:54If any of the checksums are found not to equal zero, then execution
  360. 18:59jumps down to this small block to flag the ROM as faulty.
  361. 19:03This small block of code is responsible
  362. 19:05for advancing to the next ROM chip after each checksum.
  363. 19:10This line of code resets the coin counter state.
  364. 19:13I'm not exactly sure what it's doing here, but sure.
  365. 19:16And then this small block of code flips from checking
  366. 19:19the even bytes to the odd bytes.
  367. 19:22If all of the
  368. 19:22tests pass, then execution jumps forward to the next section.
  369. 19:26If not, then the bad chip is identified by referring
  370. 19:29to the current memory address that the test was working on.
  371. 19:33The tests are marked
  372. 19:34as failed, and at this point the RAM tests are completely skipped.
  373. 19:38There's one small caveat here that's worth pointing out.
  374. 19:41See this comparison instruction?
  375. 19:44The ROM data gets memory mapped to $0000 through $3FFF,
  376. 19:49and this instruction is in charge of detecting
  377. 19:51when the calculation has hit the end of the ROM range.
  378. 19:54This $30 is referring to the upper eight bits of the ROM address,
  379. 19:59but because this is $30 instead of $40,
  380. 20:03the fourth ROM chip is actually never checked at all.
  381. 20:06The fourth ROM chip is the one that includes
  382. 20:08this self-test routine, but I'm not sure if this was on purpose or not.
  383. 20:13The fourth ROM chip does have a checksum complement
  384. 20:16at the end of the data, but both the even and odd bytes are incorrect.
  385. 20:20So if this instruction gets changed to “CP $40”
  386. 20:25like it should be without recalculating the proper checksum
  387. 20:28(but still taking into account the change to this instruction),
  388. 20:31the game will erroneously report that the fourth ROM chip is bad.
  389. 20:35The equivalent fix in the pseudocode would be to change this
  390. 20:38less than comparison to a less than or equal comparison.
  391. 20:44Next are the RAM tests.
  392. 20:46There are six tests performed, two on the work
  393. 20:49RAM, two on the video RAM, and two on the color RAM.
  394. 20:53This small table lists the six tests.
  395. 20:57The first parameter in each entry is the starting address for the test:
  396. 21:00$4C00 being work RAM, $4000 is video
  397. 21:05RAM, and $4400 being color RAM.
  398. 21:09The second parameter is the bitmask for each test.
  399. 21:12These three memory regions all used 4-bit RAM chips,
  400. 21:16so each of them needed two chips for a bytes worth of information.
  401. 21:20The lower four bits of each
  402. 21:22byte are stored on one chip, and the upper four bits on the other.
  403. 21:26That's why there are six tests here.
  404. 21:28There are six chips in total, and each test is dedicated to one chip.
  405. 21:34The last parameter in each entry is just how many pages of memory
  406. 21:37to test, and in our case, each chip has four pages worth of data
  407. 21:41or 1024 four-bit nybbles.
  408. 21:45Before looking at the code for this one,
  409. 21:47let me explain exactly how this test works.
  410. 21:51The test is split into two phases: writing to the memory
  411. 21:54and filling it up with a certain pattern of values,
  412. 21:57and then reading the memory back and checking to make sure
  413. 21:59all of the values are equal to what you wrote in the first place.
  414. 22:03There's an entire philosophy around what values are the best values
  415. 22:07to write to RAM to test it for errors best,
  416. 22:10but here they went with completely random values.
  417. 22:13The problem with filling memory with random values is remembering
  418. 22:17what you wrote in the first place, so that you can check it again later.
  419. 22:21And we're testing the integrity of the memory itself,
  420. 22:24so we can't store copies of all these values anywhere.
  421. 22:28So we'll use the next best thing,
  422. 22:29which is a sequence of pseudorandom values.
  423. 22:33This way, instead of having to remember
  424. 22:35which value we wrote to each location,
  425. 22:37we can just calculate what it should be on the fly.
  426. 22:41The way this was done in
  427. 22:42Pac-Man was starting the sequence with a known seed value,
  428. 22:46and then multiplying and adding to that value to get the next number,
  429. 22:49essentially just like a random number generator.
  430. 22:53The starting seed can be anything.
  431. 22:55Let's just start with 200 for this example.
  432. 22:59The first number in the sequence is just the seed
  433. 23:02bitwise ANDed with the particular bitmask used in this test.
  434. 23:07For this example, I'm going to be using the bitmask of %00001111.
  435. 23:11ANDing with this value of decimal 15 is equivalent
  436. 23:16to modulo 16, or dividing by 16 and taking the remainder.
  437. 23:21This gives us the first number in our sequence of 8.
  438. 23:25Each subsequent number is just the previous number
  439. 23:28plus 51, then bitwise ANDed with the bitmask again.
  440. 23:32So the next few numbers in our sequence are 11, 14, and 1.
  441. 23:38Now, every
  442. 23:3916 numbers in the sequence, there's an additional step.
  443. 23:43After adding 51, but before applying the mask,
  444. 23:47the number is multiplied by 5 and 49 is added to it.
  445. 23:52So the 17th number in the sequence after 5 isn't 8, but rather 9.
  446. 23:58This happens again on the 33rd and 49th number, and so on.
  447. 24:03The sequence ends up being 1024 numbers long for each of the tests.
  448. 24:09Now, this isn't a very random sequence of numbers, but
  449. 24:12it doesn't have to be that random, just good enough for the memory test.
  450. 24:16And remember, this sequence is dependent
  451. 24:18only on the very first number we chose.
  452. 24:21Just by changing the seed value from 200 to, say, 201,
  453. 24:26we can end up with a different sequence of numbers,
  454. 24:29and of course with a different bitmask
  455. 24:31we get an entirely different set of numbers.
  456. 24:34These bitmasks ensure only one RAM chip is being tested
  457. 24:37at a time, and lets the game report which one is faulty.
  458. 24:42Okay, let's take a look at the code now.
  459. 24:44This seems like a lot, but it's really not that bad.
  460. 24:47It's just a lot of math.
  461. 24:49Here's the equivalent pseudocode.
  462. 24:51The two big chunks here
  463. 24:53are the write phase and the read phase of the test.
  464. 24:57The innermost loop of each
  465. 24:58is calculating the next value in the sequence.
  466. 25:02Here's the AND instruction that applies the tests’ bitmask.
  467. 25:06And here's the read or write to RAM.
  468. 25:09Here's the adding 51, the multiplying by 5,
  469. 25:13and adding 49.
  470. 25:16The seed value for the first test
  471. 25:18here is $FF or 255.
  472. 25:22After one write phase and one read phase.
  473. 25:25The seed is reduced by $11 or decimal 17.
  474. 25:31This SUB instruction subtracts 16
  475. 25:33and then the DJNZ branch instruction decrements it by one more.
  476. 25:3815 total passes are done
  477. 25:40as the loop here breaks out when the seed value becomes zero.
  478. 25:45This is actually kind of frustrating to see, because this convoluted
  479. 25:48sequence of numbers was actually chosen
  480. 25:51so that every four-bit memory location gets every possible
  481. 25:55four-bit combination written to it while still feeling random.
  482. 25:59There are 16 possible values for a four-bit
  483. 26:02nybble to have, but only 15 of them are tested.
  484. 26:06The missing values are exactly the values that would be present
  485. 26:10had the test been run one more time with a seed value of zero.
  486. 26:15Oh well.
  487. 26:17The biggest loop here is over the six entries in the test table,
  488. 26:21which in the assembly
  489. 26:22has a very crude way of checking for the last entry by comparing
  490. 26:26against the memory address high byte and the mask together.
  491. 26:30Finally, if there ever
  492. 26:31is a mismatch in any of the memory comparisons,
  493. 26:34the code jumps down to this small block.
  494. 26:37The chip number is derived from the bitmask itself,
  495. 26:40and the RAM is flagged as faulty.
  496. 26:43Lastly, all of memory is cleared to set up
  497. 26:46for the screen that displays the result of the tests.
  498. 26:49First, the work RAM is cleared out to all zeros.
  499. 26:53Then the video RAM is cleared out to all $40,
  500. 26:57which is just a completely blank tile.
  501. 27:00Then the color RAM is cleared out to all 15,
  502. 27:04which is the default blue and white color palette.
  503. 27:07I'll skip over how the test result screen is displayed,
  504. 27:10because we'll look at that in the next example.
  505. 27:15Super Pac-Man's memory
  506. 27:16tests are significantly simpler, but not as robust.
  507. 27:21Additionally, the hardware in this machine is completely different.
  508. 27:24Pac-Man had its Z-80 CPU,
  509. 27:27six ROM chips, six RAM chips,
  510. 27:30and an interface for all of the I/O, such as the buttons and coin boxes.
  511. 27:35On the
  512. 27:36other hand, Super Pac-Man has a pair of co-processors.
  513. 27:39The main CPU can access video RAM, as well as three work RAM chips.
  514. 27:45It can also access two larger program ROM chips.
  515. 27:49The sub CPU only has access to a smaller program ROM,
  516. 27:53as well as a shared RAM chip dedicated for audio.
  517. 27:57There are also two character ROM chips on board,
  518. 27:59one for all of the graphics for the tiles, and one
  519. 28:02for all of the graphics for the moving sprites.
  520. 28:06And finally, there are two I/O microcontrollers
  521. 28:09that interface together with the main CPU through a smaller RAM chip.
  522. 28:14Due to the limited accessibility, both CPUs
  523. 28:17have to do their own self checks on what they can reach.
  524. 28:20Let's look at the code now.
  525. 28:23We'll start with the
  526. 28:24main CPU, since the sub CPU initially starts
  527. 28:27dormant and needs to be initialized by the main CPU anyway.
  528. 28:31Both co-CPUs are Motorola MC6809Es,
  529. 28:36so the assembly code here looks quite a bit different.
  530. 28:40The first thing on its checklist
  531. 28:41is to do a memory test on the four main RAM chips.
  532. 28:45That's done here,
  533. 28:46and here's what the pseudocode would look like for this block.
  534. 28:50Instead of using a pseudorandom sequence of numbers like Pac-Man did,
  535. 28:54Super Pac-Man sources its number sequence
  536. 28:57by just using the ROM itself.
  537. 28:59It just grabs the first 8000 bytes of one of the ROM chips
  538. 29:03and dumps it all into RAM,
  539. 29:05and then reads it back to make sure it matches.
  540. 29:08This is done 16 times, each time a different number
  541. 29:12is added to the value from ROM before writing or reading it.
  542. 29:16This way, each byte in memory gets at least 16 different
  543. 29:20values written to it.
  544. 29:22Any address that fails
  545. 29:24one of these checks gets kept track of right here.
  546. 29:27The code path here is a little weird,
  547. 29:29because even if all of the tests pass, this code still runs.
  548. 29:33It's just that the chip that gets marked as the failed chip
  549. 29:36is the fifth one, which hasn't even been checked yet.
  550. 29:39It takes care of that later, though.
  551. 29:42Also, Super Pac-Man stores the chip
  552. 29:44number in terms of its graphics tile indices,
  553. 29:47where the tile that displays a one is tile $31, a tile
  554. 29:52with two is tile $32, and so on, which is where that comes from.
  555. 29:57In my pseudocode, I just keep track of the chip number
  556. 29:59itself from 0, 1, and so on.
  557. 30:03The next thing in the checklist is to wipe out all the memory
  558. 30:06that just got filled, and it does this similar to Pac-Man.
  559. 30:10Video RAM gets all $20, color
  560. 30:13RAM gets all 2s, and work RAM gets zeroed out.
  561. 30:18Once that
  562. 30:18is done, the game quickly writes a few strings to the screen,
  563. 30:21which serve as the template to the self-test screen.
  564. 30:25This table here has each of the strings.
  565. 30:27They start with the video RAM address to start drawing the string,
  566. 30:31followed by each character to draw in order.
  567. 30:34The strings are null terminated and the table is as well.
  568. 30:39Here's where it checks for which RAM chip failed.
  569. 30:42If none of the chips failed, this will be reporting the fifth chip
  570. 30:45as bad, which we know can't be the case yet.
  571. 30:48So that's the cue to keep going forward...
  572. 30:50which is the exact chip that gets tested next.
  573. 30:54This test is very similar to the first, in that ROM
  574. 30:57is dumped into the RAM to fill all $3C0 bytes.
  575. 31:01However, these two chips are smaller, and just like in Pac-Man,
  576. 31:05one holds the upper four bits
  577. 31:06of each memory location and one holds the lower four bits.
  578. 31:10So the main difference in the test is that when a failure is detected,
  579. 31:14the game XORs the original ROM value
  580. 31:18with the value it read back from the faulty RAM address.
  581. 31:21This results in the bits only being set where they differ.
  582. 31:26It can then determine which chip is the bad one based on
  583. 31:29which bits are flipped.
  584. 31:32Next on the checklist is the small amount of RAM
  585. 31:35in the buffer chip between the main CPU and I/O chips.
  586. 31:39This is done not unlike before, just making sure
  587. 31:42to ignore the upper four bits of data, since the I/O
  588. 31:45buffer chip only outputs four bits at each location.
  589. 31:50Up next is the ROM checksums.
  590. 31:52The main CPU can only see the two big ROM chips,
  591. 31:56so those are checked for here.
  592. 31:58This is pretty standard as before, just summing up
  593. 32:01all of the bytes on each chip into a single 8-bit value.
  594. 32:05Super Pac-Man stores a more proper checksum
  595. 32:08and checksum complement together in the second ROM chip.
  596. 32:11(All of this code seen here is in the second ROM chip.)
  597. 32:15If you add up all of the bytes in the ROM, you'll get the checksum.
  598. 32:19But if you store the checksum in the ROM itself, then
  599. 32:23now you have to account for the extra byte, which increases the checksum.
  600. 32:27To prevent this self-reference, the checksum’s complement
  601. 32:30is stored next to the checksum.
  602. 32:32The complement is usually just whatever value
  603. 32:35when added to the checksum equals zero.
  604. 32:38Though Super Pac-Man uses a checksum of $66
  605. 32:42and a complement of $28 for some reason.
  606. 32:45It still solves the self-reference problems though.
  607. 32:49A complement wasn't included for the first ROM chip
  608. 32:52because its checksum was stored on the second chip,
  609. 32:55so there's no self-reference in the first place.
  610. 32:58If either of the checksums don't add up, then a bad
  611. 33:01ROM is reported.
  612. 33:05Okay, next on the list is to start up the sub CPU.
  613. 33:08This is done by writing to the address $500B here.
  614. 33:13The two processors run in parallel,
  615. 33:16which would normally make our exploration here
  616. 33:18a little more difficult,
  617. 33:19but thankfully the two processors basically
  618. 33:22wait for each other to finish here because the game wants to make sure
  619. 33:25everything is good to go before starting everything up for good.
  620. 33:30Once the main CPU fires up the sub CPU,
  621. 33:33it essentially sticks itself in a really long loop.
  622. 33:36Right before starting the sub CPU, it wrote the value $00
  623. 33:40to the shared memory address $4040 here, which is a 16-bit write.
  624. 33:46So address $4041 also gets set to $00.
  625. 33:51This is the byte that the main CPU will be listening
  626. 33:54to for the sub CPU to report its results.
  627. 33:58As long as that byte remains zero, it will hang in this loop for a while.
  628. 34:03It isn't forever though, and if time runs out,
  629. 34:05the main CPU
  630. 34:06will assume that something went wrong with the sub CPU’s program
  631. 34:10and report that the third, smaller ROM chip went bad.
  632. 34:15Let's look at the sub CPU's tests real quick.
  633. 34:18The first thing it does is test the two smaller RAM chips again.
  634. 34:23While these chips were already tested by the main CPU,
  635. 34:26these are this processor's main memory since
  636. 34:29it can't access the larger RAM chips, so it's worth trying it again.
  637. 34:34It's also using a different ROM chip to dump
  638. 34:36data into, so it's a bit more robust too.
  639. 34:40It does make sure to skip testing the two bytes that the main
  640. 34:42CPU is listening for, as to not ruin everything.
  641. 34:46If there is a failure, then the bad chip is determined
  642. 34:49just as before, and the result is placed into address $4040,
  643. 34:54which is the one that the main CPU isn't watching yet.
  644. 34:57This will hold the RAM result, but the sub CPU will go ahead
  645. 35:01and test the ROM while it's at it.
  646. 35:04This is done just like
  647. 35:05before with a checksum, complement, and everything.
  648. 35:08This code is structured like a loop since there's actually available
  649. 35:12hardware for the sub CPU to have access to another ROM chip,
  650. 35:16but it wasn't necessary for Super Pac-Man, and it was easier
  651. 35:19just to reduce the loop count by one than to restructure the code here.
  652. 35:24If all of the tests passed, then the special number
  653. 35:27$4F is used as a success value.
  654. 35:30The result of this test is then written to address $4041,
  655. 35:35which will trigger the main CPU to continue onward with its tests.
  656. 35:39After that, the sub CPU then goes into its own waiting loop,
  657. 35:43waiting for the main CPU to erase the result that it just wrote.
  658. 35:48Once that happens, the sub CPU will then clear out the RAM
  659. 35:51it has access to, and finally, it will wait again for the main
  660. 35:55CPU to tell it what to do next by monitoring the value at
  661. 35:58memory address $40FB here.
  662. 36:04That's it for the sub
  663. 36:05CPU, so let's jump back to the main CPU's code.
  664. 36:09After hearing the response from the sub CPU,
  665. 36:12it will check for failures and report them if necessary.
  666. 36:15Otherwise, if both values are $4F,
  667. 36:18then the game continues onward with more code.
  668. 36:21These lines here write the letters “OK” next to the words
  669. 36:25“ROM” and “RAM,”
  670. 36:26and if there were any failures at this point,
  671. 36:28the game reports it by writing the number of the chip next to either
  672. 36:32the word “ROM” or “RAM” as necessary.
  673. 36:35The bigger RAM chips are numbered 1 through 4,
  674. 36:38the smaller shared RAM are 5 and 6, and the I/O RAM is number 7.
  675. 36:43The big ROM chips are numbered 1 and 2, and the smaller one is number 3.
  676. 36:49Now there's actually one more test that happens,
  677. 36:52but it's a little bit later after the game sets up
  678. 36:55a lot more of the code structure for the entire game.
  679. 36:58Just like how the main CPU started up the sub CPU,
  680. 37:02it has to start up the special I/O chips as well.
  681. 37:06It was able to test the I/O buffer RAM without any problems,
  682. 37:09because those I/O chips hadn't been initialized yet.
  683. 37:12In the process of starting up the game, those chips eventually
  684. 37:15get started and start utilizing that buffer.
  685. 37:18Each one uses 16 4-bit nybbles of the buffer.
  686. 37:23They utilize it in different ways depending on what mode they're in.
  687. 37:27For example, they can monitor the player's input, listen
  688. 37:31for newly inserted coins, or output the state of the DIP switches.
  689. 37:35However, when they first start up, they go into a startup mode.
  690. 37:39In this mode, the I/O chips will add up the last seven nybbles
  691. 37:43it has access to and then put the result in the first two nybbles.
  692. 37:48The upper four bits in the first spot and the lower four
  693. 37:51bits in the next spot.
  694. 37:53In Super Pac-Man,
  695. 37:54the chips will also first initialize the last seven nybbles
  696. 37:59to all be 15.
  697. 38:02This means that the first two nybbles will end up being 6 and 9.
  698. 38:0615 times 7 is 105, which in hex is $69.
  699. 38:11The main CPU can ensure the integrity of the I/O
  700. 38:14chips themselves by verifying that this sum is correct.
  701. 38:19Here's the code that does that.
  702. 38:22This is tied in with more general code,
  703. 38:24since these I/O processes are run every frame during gameplay.
  704. 38:28It's just that this startup mode is only run at the very beginning
  705. 38:31of course.
  706. 38:33The location of the I/O buffer
  707. 38:35memory to the main CPU is at $4800 for the first I/O chip,
  708. 38:39and $4810 for the second.
  709. 38:42So this routine is run once for each chip.
  710. 38:46This bit of code just figures out
  711. 38:48which mode the I/O chip is in and runs the appropriate routine.
  712. 38:52The startup mode is mode eight.
  713. 38:55This is some more convoluted assembly math, but it's essentially
  714. 38:58taking the negative of the calculated sum in the first two nybbles,
  715. 39:03and then adding that back together with the final seven nybbles.
  716. 39:06Together, it should all equal zero.
  717. 39:09If it does, there's no problem.
  718. 39:11But if it doesn't add up, then the game immediately
  719. 39:14reports the chip number on the self-test screen.
  720. 39:17I like this code because theoretically it can run at any time.
  721. 39:21So if the I/O chip found itself in the startup mode again somehow
  722. 39:26and was also faulty, a random number 1 or 2
  723. 39:29would show up on screen and the game would lock up like this.
  724. 39:36Thank you so much for watching.
  725. 39:38I want to make another huge shout out to all of my YouTube
  726. 39:41members and Patreon supporters for all of the help.
  727. 39:45Everyone scrolling by your screen right now plays a big part
  728. 39:48into making this channel possible,
  729. 39:49and allows me to keep doing what I like doing.
  730. 39:52And if you're just a viewer, making it all the way to the end here
  731. 39:55also helps out a lot just due to the algorithm and everything.
  732. 39:58So special shout out to you as well!.
  733. 40:01Members and patrons can also get early access
  734. 40:04to videos, as well as some behind the scenes content.
  735. 40:07Supporting either on Patreon or YouTube gets you the same stuff,
  736. 40:11so you can pick whichever one is more convenient for you
  737. 40:13if you'd like to chip in a bit.
  738. 40:15Thank you so much and see you next time!

About this transcript

This page contains the full transcript of Why Do Arcade Games Boot Up Like This? by Retro Game Mechanics Explained, generated from the public captions YouTube serves with the video. The transcript has 6,802 words across 738 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.