Skip to content

Commit

Permalink
Add MSX generic binary adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanschramm committed Nov 19, 2023
1 parent f3c6829 commit 27bf54d
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 10 deletions.
10 changes: 9 additions & 1 deletion retroload-lib/src/Examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,21 @@ const examples: ExampleDefinition[] = [
tests: ['2022-11-29 OK (Philips VG-8020)'],
},
{
dir: 'msx_cas_binary',
dir: 'msx_binary',
file: 'rl.cas',
options: {shortpilot: true, msxfast: true},
hash: '1eaa89c87bad3f9a4a900a028db83c64',
instructions: 'bload"cas:",r',
tests: ['2022-11-29 OK (Philips VG-8020)'],
},
{
dir: 'msx_binary',
file: 'rl.bin',
options: {format: 'msxgeneric', shortpilot: true, msxfast: true, name: 'RL', load: '8000', entry: '8000'},
hash: '1eaa89c87bad3f9a4a900a028db83c64',
instructions: 'bload"cas:",r',
tests: ['2022-11-29 OK (Philips VG-8020)'],
},
// TA alphatronic PC
{
dir: 'ta_bas',
Expand Down
2 changes: 2 additions & 0 deletions retroload-lib/src/encoding/AdapterProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Lc80GenericAdapter from './adapter/Lc80GenericAdapter.js';
import Mo5GenericAdapter from './adapter/Mo5GenericAdapter.js';
import Mo5K7Adapter from './adapter/Mo5K7Adapter.js';
import MsxCasAdapter from './adapter/MsxCasAdapter.js';
import MsxGenericAdapter from './adapter/MsxGenericAdapter.js';
import TaGenericAdapter from './adapter/TaGenericAdapter.js';
import TiFiadAdapter from './adapter/TiFiadAdapter.js';
import TiGenericAdapter from './adapter/TiGenericAdapter.js';
Expand Down Expand Up @@ -55,6 +56,7 @@ export const adapters: AdapterDefinition[] = [
Mo5GenericAdapter,
Mo5K7Adapter,
MsxCasAdapter,
MsxGenericAdapter,
TaGenericAdapter,
TiFiadAdapter,
TiGenericAdapter,
Expand Down
11 changes: 2 additions & 9 deletions retroload-lib/src/encoding/adapter/MsxCasAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@ import {MsxEncoder} from '../encoder/MsxEncoder.js';
import {Logger} from '../../common/logging/Logger.js';
import {type RecorderInterface} from '../recorder/RecorderInterface.js';
import {type BufferAccess} from '../../common/BufferAccess.js';
import {shortpilotOption, type OptionContainer, type FlagOptionDefinition} from '../Options.js';
import {shortpilotOption, type OptionContainer} from '../Options.js';
import {type AdapterDefinition} from './AdapterDefinition.js';

const msxfastOption: FlagOptionDefinition = {
name: 'msxfast',
label: 'Fast baudrate',
description: 'MSX: Use 2400 baud instead of 1200 (faster loading, less reliable)',
type: 'bool',
common: false,
};
import {msxfastOption} from './options/MsxOptions.js';

const definition: AdapterDefinition = {
name: 'MSX .CAS-File',
Expand Down
69 changes: 69 additions & 0 deletions retroload-lib/src/encoding/adapter/MsxGenericAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {MsxEncoder} from '../encoder/MsxEncoder.js';
import {type RecorderInterface} from '../recorder/RecorderInterface.js';
import {BufferAccess} from '../../common/BufferAccess.js';
import {shortpilotOption, type OptionContainer, loadOption, nameOption, entryOption} from '../Options.js';
import {unidentifiable, type AdapterDefinition} from './AdapterDefinition.js';
import {msxfastOption} from './options/MsxOptions.js';
import {InvalidArgumentError} from '../../common/Exceptions.js';

const definition: AdapterDefinition = {
name: 'MSX (Generic binary)',
internalName: 'msxgeneric',
targetName: MsxEncoder.getTargetName(),
options: [
loadOption,
nameOption,
entryOption,
shortpilotOption,
msxfastOption,
],
identify,
encode,
};
export default definition;

const typeHeaderLength = 10;
const typeHeaderBinary = 0xd0;
// TODO implement other types (basic == 0xd3, ascii == 0xea)
const maxNameLength = 6;

function identify(_filename: string, _ba: BufferAccess) {
return unidentifiable;
}

function encode(recorder: RecorderInterface, ba: BufferAccess, options: OptionContainer) {
const loadAddress = options.getArgument(loadOption);
if (loadAddress === undefined) {
throw new InvalidArgumentError(loadOption.name, 'Option load must be set for this data type.');
}
const entryAddress = options.getArgument(loadOption) ?? 0;
const name = options.getArgument(nameOption);
if (name.length > maxNameLength) {
throw new InvalidArgumentError(nameOption.name, `Option name is expected to be a string of ${maxNameLength} characters maximum. Example: HELLO`);
}

const e = new MsxEncoder(
recorder,
options.isFlagSet(shortpilotOption),
options.isFlagSet(msxfastOption),
);

const headerBa = BufferAccess.create(typeHeaderLength + 6);
for (let i = 0; i < typeHeaderLength; i++) {
headerBa.writeUint8(typeHeaderBinary);
}
headerBa.writeAsciiString(name, maxNameLength, 0x20);

const dataHeaderBa = BufferAccess.create(6);
dataHeaderBa.writeUint16Le(loadAddress);
dataHeaderBa.writeUint16Le(loadAddress + ba.length() - 1);
dataHeaderBa.writeUint16Le(entryAddress);

e.begin();
e.recordHeader(true);
e.recordBytes(headerBa);
e.recordHeader(false);
e.recordBytes(dataHeaderBa);
e.recordBytes(ba);
e.end();
}
9 changes: 9 additions & 0 deletions retroload-lib/src/encoding/adapter/options/MsxOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {type FlagOptionDefinition} from '../../Options.js';

export const msxfastOption: FlagOptionDefinition = {
name: 'msxfast',
label: 'Fast baudrate',
description: 'MSX: Use 2400 baud instead of 1200 (faster loading, less reliable)',
type: 'bool',
common: true,
};

0 comments on commit 27bf54d

Please sign in to comment.