Check-in [eda2bb56cb]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add WritableMemoryOutputStream.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:eda2bb56cb588000e79b0c57ce9b98046032d5e6
User & Date: stephanie.gawroriski 2019-06-14 14:36:19
Context
2019-06-14
14:37
Remove deprecated class. check-in: 0ba25e5877 user: stephanie.gawroriski tags: trunk
14:36
Add WritableMemoryOutputStream. check-in: eda2bb56cb user: stephanie.gawroriski tags: trunk
14:25
Remove all the extra arguments to the bootstrap and just have a RAM, ROM, and Config memory areas. check-in: b48990fcdb user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to runt/libs/summercoat-vm/cc/squirreljme/vm/summercoat/ReadableMemoryInputStream.java.

34
35
36
37
38
39
40

41
42
43
44
45
46
47
	/**
	 * Initializes the stream.
	 *
	 * @param __mem The memory.
	 * @param __ad The start address.
	 * @param __ln The length.
	 * @throws NullPointerException On null arguments.

	 */
	public ReadableMemoryInputStream(ReadableMemory __mem, int __ad, int __ln)
		throws NullPointerException
	{
		if (__mem == null)
			throw new NullPointerException("NARG");
		







>







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	/**
	 * Initializes the stream.
	 *
	 * @param __mem The memory.
	 * @param __ad The start address.
	 * @param __ln The length.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/04/21
	 */
	public ReadableMemoryInputStream(ReadableMemory __mem, int __ad, int __ln)
		throws NullPointerException
	{
		if (__mem == null)
			throw new NullPointerException("NARG");
		

Added runt/libs/summercoat-vm/cc/squirreljme/vm/summercoat/WritableMemoryOutputStream.java.





















































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
//     Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package cc.squirreljme.vm.summercoat;

import java.io.EOFException;
import java.io.IOException;
import java.io.OutputStream;

/**
 * This is an output stream which can directly write to memory areas.
 *
 * @since 2019/06/14
 */
public final class WritableMemoryOutputStream
	extends OutputStream
{
	/** The output memory. */
	protected final WritableMemory memory;
	
	/** The base write address. */
	protected final int address;
	
	/** The number of bytes that can be written. */
	protected final int length;
	
	/** The current write offset. */
	private int _at;
	
	/**
	 * Initializes the stream.
	 *
	 * @param __mem The memory.
	 * @param __ad The start address.
	 * @param __ln The length.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/06/14
	 */
	public WritableMemoryOutputStream(WritableMemory __mem, int __ad, int __ln)
		throws NullPointerException
	{
		if (__mem == null)
			throw new NullPointerException("NARG");
		
		this.memory = __mem;
		this.address = __ad;
		this.length = __ln;
	}
	
	/**
	 * {@inheritDoc)
	 * @since 2019/06/14
	 */
	@Override
	public final void close()
	{
		// Does nothing
	}
	
	/**
	 * {@inheritDoc)
	 * @since 2019/06/14
	 */
	@Override
	public final void flush()
	{
		// Does nothing
	}
	
	/**
	 * {@inheritDoc)
	 * @since 2019/06/14
	 */
	@Override
	public final void write(int __b)
		throws IOException
	{
		// {@squirreljme.error AE0b Reached end of memory.}
		int at = this._at;
		if (at >= this.length)
			throw new EOFException("AE0b");
		
		// Write
		this.memory.memWriteByte(this.address + at, __b);
		this._at = at + 1;
	}
	
	/**
	 * {@inheritDoc)
	 * @since 2019/06/14
	 */
	@Override
	public final void write(byte[] __b)
		throws IOException, NullPointerException
	{
		this.write(__b, 0, __b.length);
	}
	
	/**
	 * {@inheritDoc)
	 * @since 2019/06/14
	 */
	@Override
	public final void write(byte[] __b, int __o, int __l)
		throws IOException, NullPointerException
	{
		if (__b == null)
			throw new NullPointerException("NARG");
		if (__o < 0 || __l < 0 || (__o + __l) > __b.length)
			throw new IndexOutOfBoundsException("IOOB");
		
		// Needed to check bounds.
		int memlen = this.length,
			at = this._at,
			left = memlen - at;
		
		// {@squirreljme.error AE0c Reached end of memory.}
		if (left <= 0)
			throw new EOFException("AE0c");
		
		// Do not write past the bounds
		if (__l > left)
			__l = left;
		
		// Write to memory
		this.memory.memWriteBytes(address + at, __b, __o, __l);
		
		// Increase pointer
		this._at = at + __l;
	}
}