-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stefan Schramm
committed
Dec 19, 2023
1 parent
3b2f12b
commit 3df2eb4
Showing
10 changed files
with
104 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import {type ConverterDefinition} from './converter/ConverterDefinition.js'; | ||
import AtariCasConverter from './converter/AtariCasConverter.js'; | ||
import KcTapConverter from './converter/KcTapConverter.js'; | ||
|
||
export const converters: ConverterDefinition[] = [ | ||
AtariCasConverter, | ||
KcTapConverter, | ||
]; |
71 changes: 71 additions & 0 deletions
71
retroload-lib/src/conversion/converter/AtariCasConverter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import {BufferAccess} from '../../common/BufferAccess.js'; | ||
import {calculateChecksum8WithCarry} from '../../common/Utils.js'; | ||
import {type OptionContainer} from '../../encoding/Options.js'; | ||
import {type ConverterDefinition} from './ConverterDefinition.js'; | ||
|
||
const definition: ConverterDefinition = { | ||
name: 'Atari .CAS-File', | ||
identifier: 'ataricas', | ||
options: [], | ||
convert, | ||
}; | ||
export default definition; | ||
|
||
const markerByte = 0x55; | ||
const blockTypeFull = 0xfc; | ||
const blockTypePartial = 0xfa; | ||
const blockTypeEndOfFile = 0xfe; | ||
const dataBytesPerBlock = 128; | ||
|
||
const pilotIrgLength = 20000; | ||
const defaultIrgLength = 250; // TODO: longer for 'ENTER'-loading | ||
|
||
function convert(data: BufferAccess, _options: OptionContainer): BufferAccess { | ||
const chunks = data.chunks(dataBytesPerBlock); | ||
|
||
// FUJI-Header, baud-block, data blocks, end of file block | ||
const outBa = BufferAccess.create(8 + 8 + (chunks.length + 1) * (8 + 132)); | ||
|
||
outBa.writeAsciiString('FUJI'); | ||
outBa.writeUint16Le(0x0000); | ||
outBa.writeUint16Le(0x0000); | ||
|
||
outBa.writeAsciiString('baud'); | ||
outBa.writeUint16Le(0x0000); | ||
outBa.writeUint16Le(600); // default baud rate | ||
|
||
for (let i = 0; i < chunks.length; i++) { | ||
const chunk = chunks[i]; | ||
|
||
outBa.writeAsciiString('data'); | ||
outBa.writeUint16Le(132); | ||
outBa.writeUint16Le(i === 0 ? pilotIrgLength : defaultIrgLength); | ||
|
||
const blockBa = BufferAccess.create(132); | ||
blockBa.writeUint8(markerByte); | ||
blockBa.writeUint8(markerByte); | ||
const partialBlock = chunk.length() !== dataBytesPerBlock; | ||
const blockType = partialBlock ? blockTypePartial : blockTypeFull; | ||
blockBa.writeUint8(blockType); | ||
blockBa.writeBa(partialBlock ? chunk.chunksPadded(dataBytesPerBlock, 0x00)[0] : chunk); | ||
if (partialBlock) { | ||
blockBa.setUint8(130, chunk.length()); | ||
} | ||
blockBa.setUint8(131, calculateChecksum8WithCarry(blockBa)); | ||
|
||
outBa.writeBa(blockBa); | ||
} | ||
|
||
// end of file block | ||
outBa.writeAsciiString('data'); | ||
outBa.writeUint16Le(132); | ||
outBa.writeUint16Le(defaultIrgLength); | ||
const endBlock = BufferAccess.create(132); | ||
endBlock.writeUint8(markerByte); | ||
endBlock.writeUint8(markerByte); | ||
endBlock.writeUint8(blockTypeEndOfFile); | ||
endBlock.setUint8(131, calculateChecksum8WithCarry(endBlock)); | ||
outBa.writeBa(endBlock); | ||
|
||
return outBa; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters