Skip to content

Commit

Permalink
#29 Support for CTM v6, v7
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejmaleckicg authored Jun 18, 2021
1 parent 06794de commit d32e053
Show file tree
Hide file tree
Showing 77 changed files with 275 additions and 90 deletions.
3 changes: 3 additions & 0 deletions CHANGES.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
= Change log

1.2.0::
* Charpad support for CTM v.6, 7 file format.

1.1.1::
* Bugfix: #26 charpad: fixed map generation in CTM files without Tileset.

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License

Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,6 +23,8 @@ SOFTWARE.
*/
package com.github.c64lib.retroassembler.charpad_processor

import com.github.c64lib.retroassembler.charpad_processor.ctm5.CTM5Processor
import com.github.c64lib.retroassembler.charpad_processor.ctm6.CTM6Processor
import com.github.c64lib.retroassembler.domain.processor.InputByteStream
import com.github.c64lib.retroassembler.domain.processor.OutputProducer
import com.github.c64lib.retroassembler.domain.processor.Processor
Expand All @@ -31,24 +33,32 @@ internal interface CTMProcessor : Processor

class CharpadProcessor(outputProducers: Collection<OutputProducer<*>>) {

internal val charsetProducers: Collection<CharsetProducer> =
private val charsetProducers: Collection<CharsetProducer> =
outputProducers.filterIsInstance<CharsetProducer>()

internal val charAttributesProducers: Collection<CharAttributesProducer> =
private val charAttributesProducers: Collection<CharAttributesProducer> =
outputProducers.filterIsInstance<CharAttributesProducer>()

internal val tileProducers: Collection<TileProducer> =
private val tileProducers: Collection<TileProducer> =
outputProducers.filterIsInstance<TileProducer>()

internal val tileColoursProducers: Collection<TileColoursProducer> =
private val tileColoursProducers: Collection<TileColoursProducer> =
outputProducers.filterIsInstance<TileColoursProducer>()

internal val mapProducers: Collection<MapProducer> =
private val mapProducers: Collection<MapProducer> =
outputProducers.filterIsInstance<MapProducer>()

fun process(inputByteStream: InputByteStream) =
getProcessor(inputByteStream).process(inputByteStream)

internal fun processCharset(action: (CharsetProducer) -> Unit) = charsetProducers.forEach(action)
internal fun processCharAttributes(action: (CharAttributesProducer) -> Unit) =
charAttributesProducers.forEach(action)
internal fun processTiles(action: (TileProducer) -> Unit) = tileProducers.forEach(action)
internal fun processTileColours(action: (TileColoursProducer) -> Unit) =
tileColoursProducers.forEach(action)
internal fun processMap(action: (MapProducer) -> Unit) = mapProducers.forEach(action)

private fun getProcessor(inputByteStream: InputByteStream): CTMProcessor {
val id = inputByteStream.read(3).map { it.toChar() }.joinToString(separator = "")
if (id != "CTM") {
Expand All @@ -57,6 +67,7 @@ class CharpadProcessor(outputProducers: Collection<OutputProducer<*>>) {
return when (val version = inputByteStream.readByte().toInt()
) {
5 -> CTM5Processor(this@CharpadProcessor)
6, 7 -> CTM6Processor(this@CharpadProcessor, version)
else -> throw InvalidCTMFormatException("Unsupported version: $version")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018 c64lib: The Ultimate Commodore 64 Library
Copyright (c) 2018-2021 c64lib: The Ultimate Commodore 64 Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -21,9 +21,13 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package com.github.c64lib.retroassembler.charpad_processor
package com.github.c64lib.retroassembler.charpad_processor.ctm5

import com.github.c64lib.retroassembler.binutils.toWord
import com.github.c64lib.retroassembler.charpad_processor.CTMProcessor
import com.github.c64lib.retroassembler.charpad_processor.CharpadProcessor
import com.github.c64lib.retroassembler.charpad_processor.ColouringMethod
import com.github.c64lib.retroassembler.charpad_processor.Flags
import com.github.c64lib.retroassembler.domain.processor.InputByteStream
import java.util.*
import kotlin.experimental.and
Expand All @@ -35,29 +39,29 @@ internal class CTM5Processor(private val charpadProcessor: CharpadProcessor) : C

if (header.numChars > 0) {
val charData = inputByteStream.read(header.numChars * 8)
charpadProcessor.charsetProducers.forEach { it.write(charData) }
charpadProcessor.processCharset { it.write(charData) }

val charAttributeData = inputByteStream.read(header.numChars)
charpadProcessor.charAttributesProducers.forEach { it.write(charAttributeData) }
charpadProcessor.processCharAttributes { it.write(charAttributeData) }
}

if (header.flags and CTM5Flags.TileSys.bit != 0.toByte()) {
if (header.flags and CTM5Flags.CharEx.bit == 0.toByte()) {
val tileData =
inputByteStream.read(
header.numTiles * header.tileWidth.toInt() * header.tileHeight.toInt() * 2)
charpadProcessor.tileProducers.forEach { it.write(tileData) }
charpadProcessor.processTiles { it.write(tileData) }
}

if (header.colouringMethod == ColouringMethod.PerTile.value) {
val tileColoursData = inputByteStream.read(header.numTiles)
charpadProcessor.tileColoursProducers.forEach { it.write(tileColoursData) }
charpadProcessor.processTileColours { it.write(tileColoursData) }
}
}

if (header.mapHeight > 0 && header.mapWidth > 0) {
val mapData = inputByteStream.read(header.mapWidth * header.mapHeight * 2)
charpadProcessor.mapProducers.forEach { it.write(header.mapWidth, header.mapHeight, mapData) }
charpadProcessor.processMap { it.write(header.mapWidth, header.mapHeight, mapData) }
}
}

Expand Down
Loading

0 comments on commit d32e053

Please sign in to comment.