1 /*
2  * sys-emu - A system emulator for tutorials
3  * Copyright (C) 2018 - 2019 osdevelopment-info
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  */
18 package info.osdevelopment.sysemu.memory
19 
20 import scala.util.Try
21 
22 /**
23   * A read-only memory backed by an array.
24  *
25   * @param data the data for the read-only memory.
26   */
27 class ArrayReadOnlyMemory (val data: Array[Byte]) extends ReadOnlyMemory {
28 
29   /**
30     * Returns the size of the memory.
31     * @return the size of the memory
32     */
33   override def size: Long = data.length
34 
35   /**
36     * The implementation of the read.
37     * @param address the address that should be read
38     * @return a `Success` with the byte read at the given address or a `Failure`
39     */
40   override protected def doRead(address: Long): Try[Byte] = {
41     Try(data(address.asInstanceOf[Int]))
42   }
43 
44 }
Line Stmt Id Pos Tree Symbol Code
33 9 1134 - 1145 Select scala.Int.toLong ArrayReadOnlyMemory.this.data.length.toLong
41 11 1402 - 1433 Apply scala.Array.apply ArrayReadOnlyMemory.this.data.apply(address.asInstanceOf[Int])
41 10 1407 - 1432 TypeApply scala.Any.asInstanceOf address.asInstanceOf[Int]
41 12 1398 - 1434 Apply scala.util.Try.apply scala.util.Try.apply[Byte](ArrayReadOnlyMemory.this.data.apply(address.asInstanceOf[Int]))