<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.wexosmk.xyz/index.php?action=history&amp;feed=atom&amp;title=Yay0_%28Compression%29</id>
	<title>Yay0 (Compression) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.wexosmk.xyz/index.php?action=history&amp;feed=atom&amp;title=Yay0_%28Compression%29"/>
	<link rel="alternate" type="text/html" href="https://wiki.wexosmk.xyz/index.php?title=Yay0_(Compression)&amp;action=history"/>
	<updated>2026-04-07T18:48:02Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://wiki.wexosmk.xyz/index.php?title=Yay0_(Compression)&amp;diff=344&amp;oldid=prev</id>
		<title>Wexos: Imported from avsys wiki</title>
		<link rel="alternate" type="text/html" href="https://wiki.wexosmk.xyz/index.php?title=Yay0_(Compression)&amp;diff=344&amp;oldid=prev"/>
		<updated>2024-05-01T18:10:19Z</updated>

		<summary type="html">&lt;p&gt;Imported from avsys wiki&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;Yay0&amp;#039;&amp;#039;&amp;#039; is a RLE compression (run-length encoding). It is used in many [[Nintendo 64]] games, and early [[Nintendo GameCube]] games as well. One example of a game which uses Yay0 is [[Luigi&amp;#039;s Mansion]] for the [[Nintendo GameCube]]. Note that Yay0-compressed files are not affected by the endianness of the CPU. All fields will always be stored as big endian.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
A Yay0-compressed file starts with the following header:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Offset !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x00 || String || &amp;#039;&amp;#039;&amp;#039;File magic&amp;#039;&amp;#039;&amp;#039;. Always &amp;#039;&amp;#039;Yay0&amp;#039;&amp;#039; in ASCII.&lt;br /&gt;
|-&lt;br /&gt;
| 0x04 || UInt32 || &amp;#039;&amp;#039;&amp;#039;Size of the decompressed data&amp;#039;&amp;#039;&amp;#039; in bytes.&lt;br /&gt;
|-&lt;br /&gt;
| 0x08 || UInt32 || &amp;#039;&amp;#039;&amp;#039;Link table offset&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
|-&lt;br /&gt;
| 0x0C || UInt32 || &amp;#039;&amp;#039;&amp;#039;Byte chunk offset&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Chunks ==&lt;br /&gt;
The data is stored into different chunks. There are three different data blocks, the &amp;#039;&amp;#039;command block&amp;#039;&amp;#039;, which is stored directly after the header, and then two are linked in the [[#Header|header]]. Each UInt32 in the command block contains 32 commands, one per bit, where MSB is the first command, and LSB corrusponds to the last command. Commands are read until the output data size matches the size of the uncompressed data, which is specified in the [[#Header|header]].&lt;br /&gt;
&lt;br /&gt;
; Direct Copy&lt;br /&gt;
If a command bit is 1, then one byte is copied directly from the input to the output data. The data is copied from the &amp;#039;&amp;#039;byte chunk&amp;#039;&amp;#039; block.&lt;br /&gt;
&lt;br /&gt;
; Run-length&lt;br /&gt;
If a command bit is 0, then the chunk contains run-length encoded data. One UInt16 (&amp;#039;&amp;#039;&amp;#039;A&amp;#039;&amp;#039;&amp;#039;) has to be read from the &amp;#039;&amp;#039;link table&amp;#039;&amp;#039; block. The data is copied from the output to the output. The output address, where the data is copied from, can be calculated using this formula:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CopyOffset = CurrentOffset - (A &amp;amp; 0xFFF) - 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the number of bytes to copy needs to be calculated. The run-length command supports two different size mode, and first the following calculation is performed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
B = (A &amp;gt;&amp;gt; 12) &amp;amp; 0b1111&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If &amp;#039;&amp;#039;&amp;#039;B&amp;#039;&amp;#039;&amp;#039; is zero, then another byte is read from the &amp;#039;&amp;#039;byte chunk&amp;#039;&amp;#039; block. The number of bytes to copy is then calculated by adding 0x12 to the read byte. If &amp;#039;&amp;#039;&amp;#039;B&amp;#039;&amp;#039;&amp;#039; is not zero, then the number of bytes to copy is by adding 2 to &amp;#039;&amp;#039;&amp;#039;B&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Compression]]&lt;/div&gt;</summary>
		<author><name>Wexos</name></author>
	</entry>
</feed>