<?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=Yaz0_%28Compression%29</id>
	<title>Yaz0 (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=Yaz0_%28Compression%29"/>
	<link rel="alternate" type="text/html" href="https://wiki.wexosmk.xyz/index.php?title=Yaz0_(Compression)&amp;action=history"/>
	<updated>2026-04-07T20:36:13Z</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=Yaz0_(Compression)&amp;diff=346&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=Yaz0_(Compression)&amp;diff=346&amp;oldid=prev"/>
		<updated>2024-05-01T18:11:59Z</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;Yaz0&amp;#039;&amp;#039;&amp;#039; is a RLE compression (run-length encoding). It has been used in lots of games and platforms since its introduction on the [[Nintendo 64]] console. It has been used in games like [[Mario Kart Wii]], [[Super Mario Odyssey]] and many more. Note that Yaz0-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 Yaz0-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;Yaz0&amp;#039;&amp;#039; in ASCII.&lt;br /&gt;
|-&lt;br /&gt;
| 0x04 || UInt32 || &amp;#039;&amp;#039;&amp;#039;Size of the uncompressed data&amp;#039;&amp;#039;&amp;#039; in bytes.&lt;br /&gt;
|-&lt;br /&gt;
| 0x08 || UInt32 || &amp;#039;&amp;#039;&amp;#039;Reserved&amp;#039;&amp;#039;&amp;#039; for special use within a game. [[Super Mario Odyssey]] uses this field as the file alignment.&lt;br /&gt;
|-&lt;br /&gt;
| 0x0C || UInt32 || &amp;#039;&amp;#039;&amp;#039;Reserved&amp;#039;&amp;#039;&amp;#039; for special use within a game. Only seen as 0.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Chunks ==&lt;br /&gt;
The data is then stored into different chunks. Each chunk starts with a chunk header, which consist of a Byte. It obviously contains 8 bits, and each bit specifies the mode for one copy command, meaning there will be 8 copy commands per chunk. The MSB bit is the first command, and the LSB bit corresponds to the last command. Chunks are read until the size of the output is the same as specified in the header.&lt;br /&gt;
&lt;br /&gt;
; Direct Copy&lt;br /&gt;
If a bit is 1, then one byte is copied directly from the input to the output data.&lt;br /&gt;
&lt;br /&gt;
; Run-length&lt;br /&gt;
If a bit is 0, then this group will contain run-length encoded data. In order for this to work, a UInt16 (&amp;#039;&amp;#039;&amp;#039;B&amp;#039;&amp;#039;&amp;#039;) has to be read from the input. The data is copied from the output, at a specific address, to the output. To calculate the address to copy the data from, perform this calculation:&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;
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. 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>