Skip to content

Commit ec3b9bb

Browse files
add COMPRESS and DECOMPRESS
1 parent 2c6ee2b commit ec3b9bb

297 files changed

Lines changed: 2124 additions & 1307 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docpages/basic-language-reference/functions/integer/02_INDEX.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ The following functions operate on or return **integer values** in Retro Rocket
1616
* \subpage BITSHL
1717
* \subpage BITSHR
1818
* \subpage BITXNOR
19+
* \subpage COMPRESS
1920
* \subpage CPUID
2021
* \subpage CURRENTX
2122
* \subpage CURRENTY
2223
* \subpage DATAREAD
2324
* \subpage DAY
2425
* \subpage DECIBELS
26+
* \subpage DECOMPRESS
2527
* \subpage EOF
2628
* \subpage EXISTSVARI
2729
* \subpage FILESIZE
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
\page COMPRESS COMPRESS Function
2+
3+
```basic
4+
COMPRESS(input, input_len, output, output_max_len, level)
5+
```
6+
7+
Compresses a memory buffer using gzip compression.
8+
9+
Compressed data is written to the output buffer and the function returns the compressed size in bytes.
10+
11+
Returns zero on error.
12+
13+
---
14+
15+
### Examples
16+
17+
```basic
18+
REM Compress a memory buffer
19+
20+
INPUT_BUFFER = MEMALLOC(1024)
21+
OUTPUT_BUFFER = MEMALLOC(2048)
22+
23+
REM Fill input buffer here
24+
25+
SIZE = COMPRESS(INPUT_BUFFER, 1024, OUTPUT_BUFFER, 2048, 6)
26+
27+
PRINT "Compressed size: "; SIZE
28+
```
29+
30+
```basic
31+
REM Compress a file loaded into memory
32+
33+
F = OPENIN("data.bin")
34+
35+
SIZE = FILESIZE("data.bin")
36+
37+
INPUT = MEMALLOC(SIZE)
38+
OUTPUT = MEMALLOC(SIZE * 2)
39+
40+
BINREAD F, INPUT, SIZE
41+
CLOSE F
42+
43+
COMPRESSED = COMPRESS(INPUT, SIZE, OUTPUT, SIZE * 2, 9)
44+
45+
PRINT "Compressed "; SIZE; " bytes into "; COMPRESSED
46+
```
47+
48+
---
49+
50+
### Notes
51+
52+
* `input` is the source memory buffer.
53+
* `input_len` is the size of the source data in bytes.
54+
* `output` is the destination memory buffer.
55+
* `output_max_len` is the maximum writable size of the output buffer.
56+
* `level` is the gzip compression level from 0 to 9.
57+
* Higher compression levels are slower but may produce smaller output.
58+
* The output buffer must be large enough to hold the compressed data.
59+
* Returns the compressed size in bytes.
60+
* Returns zero if compression fails.
61+
62+
---
63+
64+
### Errors
65+
66+
* Compression failed
67+
* Output buffer too small
68+
69+
---
70+
71+
**See also:**
72+
\ref DECOMPRESS "DECOMPRESS" · \ref MEMALLOC "MEMALLOC" · \ref MEMRELEASE "MEMRELEASE" · \ref BINREAD "BINREAD" · \ref BINWRITE "BINWRITE"
73+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
\page DECOMPRESS DECOMPRESS Function
2+
3+
```basic id="w4kp6f"
4+
DECOMPRESS(input, input_len, output, output_max_len)
5+
```
6+
7+
Decompresses a gzip-compressed memory buffer.
8+
9+
Decompressed data is written to the output buffer and the function returns the decompressed size in bytes.
10+
11+
Returns zero on error.
12+
13+
---
14+
15+
### Examples
16+
17+
```basic id="m7qz6a"
18+
REM Decompress a gzip-compressed memory buffer
19+
20+
INPUT_BUFFER = MEMALLOC(1024)
21+
OUTPUT_BUFFER = MEMALLOC(8192)
22+
23+
REM Fill compressed input buffer here
24+
25+
SIZE = DECOMPRESS(INPUT_BUFFER, 1024, OUTPUT_BUFFER, 8192)
26+
27+
PRINT "Decompressed size: "; SIZE
28+
```
29+
30+
```basic id="j0x2vq"
31+
REM Load and decompress a gzip file
32+
33+
F = OPENIN("archive.gz")
34+
35+
COMPRESSED_SIZE = FILESIZE("archive.gz")
36+
37+
COMPRESSED = MEMALLOC(COMPRESSED_SIZE)
38+
OUTPUT = MEMALLOC(65536)
39+
40+
BINREAD F, COMPRESSED, COMPRESSED_SIZE
41+
CLOSE F
42+
43+
SIZE = DECOMPRESS(COMPRESSED, COMPRESSED_SIZE, OUTPUT, 65536)
44+
45+
PRINT "Decompressed "; COMPRESSED_SIZE; " bytes into "; SIZE
46+
```
47+
48+
---
49+
50+
### Notes
51+
52+
* `input` is the compressed source memory buffer.
53+
* `input_len` is the compressed input size in bytes.
54+
* `output` is the destination memory buffer.
55+
* `output_max_len` is the maximum writable size of the output buffer.
56+
* The output buffer must be large enough to hold the decompressed data.
57+
* Returns the decompressed size in bytes.
58+
* Returns zero if decompression fails.
59+
60+
---
61+
62+
### Errors
63+
64+
* Decompression failed
65+
* Output buffer too small
66+
67+
---
68+
69+
**See also:**
70+
\ref COMPRESS "COMPRESS" · \ref MEMALLOC "MEMALLOC" · \ref MEMRELEASE "MEMRELEASE" · \ref BINREAD "BINREAD" · \ref BINWRITE "BINWRITE"
71+

docs/ACS.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
<div class="textblock"><div class="fragment"><div class="line">ACS(real-expression)</div>
127127
</div><!-- fragment --><p>Returns the <b>arc cosine</b> (inverse cosine) of the given expression, in <b>radians</b>. The input must be between <span class="tt">-1</span> and <span class="tt">1</span>.</p>
128128
<hr />
129-
<h3 class="doxsection"><a class="anchor" id="examples-92"></a>
129+
<h3 class="doxsection"><a class="anchor" id="examples-94"></a>
130130
Examples</h3>
131131
<div class="fragment"><div class="line">PRINT ACS(1)</div>
132132
</div><!-- fragment --><p>Produces <span class="tt">0</span>.</p>
@@ -139,7 +139,7 @@ <h3 class="doxsection"><a class="anchor" id="examples-92"></a>
139139
<div class="line">PRINT ACS(COS(angle#))</div>
140140
</div><!-- fragment --><p>Produces the original angle (within floating point accuracy).</p>
141141
<hr />
142-
<h3 class="doxsection"><a class="anchor" id="notes-88"></a>
142+
<h3 class="doxsection"><a class="anchor" id="notes-90"></a>
143143
Notes</h3>
144144
<ul>
145145
<li>Argument range: <span class="tt">-1 ≤ x ≤ 1</span>. Values outside this range cause an error.</li>

docs/ADFSIMAGE.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@
126126
<div class="textblock"><div class="fragment"><div class="line">ADFSIMAGE$(path$)</div>
127127
</div><!-- fragment --><p>Creates a <b>RAM-backed block device from an ADFS disk image</b>. The parameter is the path to an ADFS S/M/L image file. Returns the device name on success.</p>
128128
<hr />
129-
<h3 class="doxsection"><a class="anchor" id="examples-113"></a>
129+
<h3 class="doxsection"><a class="anchor" id="examples-115"></a>
130130
Examples</h3>
131131
<div class="fragment"><div class="line">REM Load an ADFS disk image into RAM</div>
132132
<div class="line">RD$ = ADFSIMAGE$(&quot;chukie-egg.adl&quot;)</div>
133133
<div class="line">MOUNT &quot;/games&quot;, RD$, &quot;adfs&quot;</div>
134134
<div class="line">PRINT &quot;ADFS image mounted&quot;</div>
135135
</div><!-- fragment --><hr />
136-
<h3 class="doxsection"><a class="anchor" id="notes-109"></a>
136+
<h3 class="doxsection"><a class="anchor" id="notes-111"></a>
137137
Notes</h3>
138138
<ul>
139139
<li>The image must be a valid ADFS S/M/L disk image</li>

docs/ANIMATE.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ <h3 class="doxsection"><a class="anchor" id="example-7"></a>
159159
<div class="line">CLS</div>
160160
<div class="line">END</div>
161161
</div><!-- fragment --><hr />
162-
<h3 class="doxsection"><a class="anchor" id="notes-157"></a>
162+
<h3 class="doxsection"><a class="anchor" id="notes-159"></a>
163163
Notes</h3>
164164
<ul>
165165
<li>If the sprite is not animated (single-frame image), <span class="tt">ANIMATE</span> statements are silent no-ops.</li>

docs/ARRAYFIND.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
</li>
138138
</ul>
139139
<hr />
140-
<h5 class="doxsection"><a class="anchor" id="examples-159"></a>
140+
<h5 class="doxsection"><a class="anchor" id="examples-161"></a>
141141
Examples</h5>
142142
<p><b>Integer array</b></p>
143143
<div class="fragment"><div class="line">DIM N,5</div>
@@ -180,7 +180,7 @@ <h5 class="doxsection"><a class="anchor" id="examples-159"></a>
180180
<div class="fragment"><div class="line">0</div>
181181
<div class="line">-1</div>
182182
</div><!-- fragment --><hr />
183-
<h5 class="doxsection"><a class="anchor" id="notes-158"></a>
183+
<h5 class="doxsection"><a class="anchor" id="notes-160"></a>
184184
Notes</h5>
185185
<ul>
186186
<li><span class="tt">dest-array</span> is <b>automatically created or resized</b>:<ul>

docs/ARRSORT.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
</li>
137137
</ul>
138138
<hr />
139-
<h5 class="doxsection"><a class="anchor" id="examples-160"></a>
139+
<h5 class="doxsection"><a class="anchor" id="examples-162"></a>
140140
Examples</h5>
141141
<p><b>Integer array (ascending)</b></p>
142142
<div class="fragment"><div class="line">DIM N,5</div>
@@ -189,7 +189,7 @@ <h5 class="doxsection"><a class="anchor" id="examples-160"></a>
189189
<div class="line"> </div>
190190
<div class="line">ARRSORT D#</div>
191191
</div><!-- fragment --><hr />
192-
<h5 class="doxsection"><a class="anchor" id="notes-159"></a>
192+
<h5 class="doxsection"><a class="anchor" id="notes-161"></a>
193193
Notes</h5>
194194
<ul>
195195
<li>Sorting is <b>in place</b>; the original order is replaced</li>

docs/ARRSORTBY.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
</ul>
139139
<p>The values in <span class="tt">key-array</span> are <b>not modified</b>.</p>
140140
<hr />
141-
<h5 class="doxsection"><a class="anchor" id="examples-161"></a>
141+
<h5 class="doxsection"><a class="anchor" id="examples-163"></a>
142142
Examples</h5>
143143
<p><b>Sort indices by real key (depth sort)</b></p>
144144
<div class="fragment"><div class="line">DIM DEPTH#,6</div>
@@ -194,7 +194,7 @@ <h5 class="doxsection"><a class="anchor" id="examples-161"></a>
194194
<div class="line"> PRINT IDX(I), NAMES$(IDX(I))</div>
195195
<div class="line">NEXT</div>
196196
</div><!-- fragment --><hr />
197-
<h5 class="doxsection"><a class="anchor" id="notes-160"></a>
197+
<h5 class="doxsection"><a class="anchor" id="notes-162"></a>
198198
Notes</h5>
199199
<ul>
200200
<li>Only <span class="tt">index-array</span> is reordered; <span class="tt">key-array</span> remains unchanged</li>

docs/ASN.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
<div class="textblock"><div class="fragment"><div class="line">ASN(real-expression)</div>
127127
</div><!-- fragment --><p>Returns the <b>arc sine</b> (inverse sine) of the given expression, in <b>radians</b>. The input must be between <span class="tt">-1</span> and <span class="tt">1</span>.</p>
128128
<hr />
129-
<h3 class="doxsection"><a class="anchor" id="examples-93"></a>
129+
<h3 class="doxsection"><a class="anchor" id="examples-95"></a>
130130
Examples</h3>
131131
<div class="fragment"><div class="line">PRINT ASN(0)</div>
132132
</div><!-- fragment --><p>Produces <span class="tt">0</span>.</p>
@@ -139,7 +139,7 @@ <h3 class="doxsection"><a class="anchor" id="examples-93"></a>
139139
<div class="line">PRINT ASN(SIN(angle#))</div>
140140
</div><!-- fragment --><p>Produces the original angle (within floating point accuracy).</p>
141141
<hr />
142-
<h3 class="doxsection"><a class="anchor" id="notes-89"></a>
142+
<h3 class="doxsection"><a class="anchor" id="notes-91"></a>
143143
Notes</h3>
144144
<ul>
145145
<li>Argument range: <span class="tt">-1 ≤ x ≤ 1</span>. Values outside this range cause an error.</li>

0 commit comments

Comments
 (0)