vito-Z80

tr-dos headline

Jul 29th, 2019
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.99 KB | None | 0 0
  1. val zxBytes = z80File.readBytes()
  2.         val fileInfoLength = 16
  3.         var startDisk = 0
  4.         var basicStart = 0u
  5.         var basicLength = 0u
  6.         while (true) {
  7.             val headline = ByteArray(fileInfoLength)
  8.             System.arraycopy(zxBytes, startDisk, headline, 0, fileInfoLength)
  9. //            System.arraycopy(array,0,array1,9,10)
  10.             // копирование 10 элементов из массива array, начиная с позиции 0,
  11.             // в массив array1, начиная с позиции 9
  12.             startDisk += fileInfoLength
  13.             if (headline[0].toInt() == 0) return
  14.             val text = StringBuilder()
  15. //            headline.copyOfRange(0, 7).forEach { text.append(it.toChar()) }
  16.             val expansion = headline[8].toChar()
  17.             text.append("File name: ").apply {
  18.                 headline.copyOfRange(0, 7).forEach { text.append(it.toChar()) }
  19.             }.append(".").append(expansion)
  20.                     .append(" | Start: ")
  21.                     .append("track: ")
  22.                     .append(headline[15].toUByte())
  23.                     .append(", sector: ")
  24.                     .append(headline[14].toUByte())
  25.                     .append(" | Length: ")
  26.                     .append(headline[10].toUByte() * 256u + headline[11].toUByte())
  27.                     .append(" bytes. ")
  28.             println(text)
  29.             if (expansion == 'B') {
  30.                 basicStart = (headline[15] * 4096 + headline[14] * 256).toUInt()
  31.                 basicLength = headline[10].toUByte() * 256u + headline[11].toUByte()
  32. //                basicLength = 256u
  33.                 val basicCode = zxBytes
  34.                         .copyOfRange(basicStart.toInt(), (basicStart + basicLength).toInt())
  35.                 basicCode.forEachIndexed { id: Int, byte: Byte ->
  36.                     if (id % 16 == 0) println()
  37.                     print("${byte.toUByte()}, ")
  38.                 }
  39.                 println()
  40.             }
  41.         }
Advertisement
Add Comment
Please, Sign In to add comment