Skip to content

Commit

Permalink
fix: mend the issues with ZX Spectrum 128 exported file loader (#753)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dotneteer committed Apr 13, 2024
1 parent 926547c commit e5540c7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
28 changes: 6 additions & 22 deletions src/renderer/appIde/commands/CompilerCommand.ts
Expand Up @@ -453,8 +453,8 @@ export class ExportCodeCommand extends IdeCommandBase {
const endAddr = startAddr + bankSegment.emittedCode.length - 1;

const codeSegment = new Uint8Array(endAddr - startAddr + 3);
for (let i = 0; i < segments.length; i++) {
codeSegment[i + 1] = bankSegment[i];
for (let i = 0; i < bankSegment.emittedCode.length; i++) {
codeSegment[i + 1] = bankSegment.emittedCode[i];
}

// --- The first byte of the code segment is 0xFF (Data block)
Expand Down Expand Up @@ -766,26 +766,10 @@ export class ExportCodeCommand extends IdeCommandBase {
}

// --- Add 'LOAD "" CODE' for each block
if (exporter.singleBlock) {
codeLine.push(LOAD_TKN);
codeLine.push(DQUOTE);
codeLine.push(DQUOTE);
codeLine.push(CODE_TKN);
} else {
for (
let i = 0;
i < output.segments.map(s => s.bank == undefined).length;
i++
) {
if (i > 0) {
codeLine.push(COLON);
}
codeLine.push(LOAD_TKN);
codeLine.push(DQUOTE);
codeLine.push(DQUOTE);
codeLine.push(CODE_TKN);
}
}
codeLine.push(LOAD_TKN);
codeLine.push(DQUOTE);
codeLine.push(DQUOTE);
codeLine.push(CODE_TKN);

codeLine.push(NEW_LINE);
lines.push(codeLine);
Expand Down
27 changes: 27 additions & 0 deletions test/assembler/pragma.test.ts
Expand Up @@ -155,6 +155,33 @@ describe("Assembler - pragmas", async () => {
expect(output.segments[1].displacement).toBeUndefined();
});

it("bank - existing segment #3", async () => {
const compiler = new Z80Assembler();
const source = `
.model Spectrum128
.org #6400
nop
.bank 1
.defb 0x01, 0x02, 0x03
`;

const output = await compiler.compile(source);

expect(output.errorCount).toBe(0);
expect(output.segments.length).toBe(2);
expect(output.segments[0].startAddress).toBe(0x6400);
expect(output.segments[0].bank).toBeUndefined();
expect(output.segments[0].displacement).toBeUndefined();
expect(output.segments[1].startAddress).toBe(0xc000);
expect(output.segments[1].bank).toBe(1);
expect(output.segments[1].displacement).toBeUndefined();
expect(output.segments[1].emittedCode.length).toBe(3);
expect(output.segments[1].emittedCode[0]).toBe(0x01);
expect(output.segments[1].emittedCode[1]).toBe(0x02);
expect(output.segments[1].emittedCode[2]).toBe(0x03);
});


it("bank - new segment #1", async () => {
const compiler = new Z80Assembler();
const source = `
Expand Down

0 comments on commit e5540c7

Please sign in to comment.