Skip to content

Commit

Permalink
Refactored cartridgeType to cartridge
Browse files Browse the repository at this point in the history
  • Loading branch information
Flaflo committed Jan 3, 2021
1 parent 15bfd0b commit a727ae6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import xyz.flaflo.snes.rom.header.layout.SnesBankType
class SnesRomHeaderReader(bytes: ByteArray, offset: Int = SnesBankType.LoRom.headerOffset) {
val name = SnesRomHeaderValue(this, offset, 21, bytes)
val layout = SnesRomHeaderValue(this, name, 1, bytes)
val cartridgeType = SnesRomHeaderValue(this, layout, 1, bytes)
val romSize = SnesRomHeaderValue(this, cartridgeType, 1, bytes)
val cartridge = SnesRomHeaderValue(this, layout, 1, bytes)
val romSize = SnesRomHeaderValue(this, cartridge, 1, bytes)
val saveRamSize = SnesRomHeaderValue(this, romSize, 1, bytes)
val countryCode = SnesRomHeaderValue(this, saveRamSize, 1, bytes)
val licensorCode = SnesRomHeaderValue(this, countryCode, 1, bytes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,17 @@ class SnesRomHeaderValue(private val parent: SnesRomHeaderReader, var offset: In
}

/**
* Reads and converts this value into a SnesCartridgeType
* Reads and converts this value into a SnesCartridge
*
* @see SnesCartridge
* @return a SnesCartridgeType
* @return a SnesCartridge
*/
fun readCartridgeType(): SnesCartridge {
fun readCartridge(): SnesCartridge {
//Converting into a string and extracting the numbers out of it again is really ugly
//But I could think of another way to do it at the moment and I wanted this to work
//Improvements are welcome! :)

val typeByte = parent.cartridgeType.readByte().toUInt()
val typeByte = parent.cartridge.readByte().toUInt()
var type = typeByte.toString(16)

if (typeByte < 10U) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ class SnesRomParser(override var inputStream: InputStream) : ISnesRomParser {
val country = SnesRomCountry.fromId(header.countryCode.readByte().toInt())
val licensor = SnesRomLicensor.fromId(header.licensorCode.readByte().toInt())
val version = header.version.readByte().toInt()
val cartridgeType = header.cartridgeType.readCartridgeType()
val cartridge = header.cartridge.readCartridge()

return SnesRom(
name.trim(),
layout,
cartridgeType,
cartridge,
romSize,
saveRamSize,
country,
Expand Down

0 comments on commit a727ae6

Please sign in to comment.