kopia lustrzana https://github.com/maccasoft/z80-tools
Implemented binary builder
rodzic
9392b02e16
commit
c920f607a8
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Marco Maccaferri and others.
|
||||
* Copyright (c) 2018-19 Marco Maccaferri and others.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
|
@ -1958,7 +1958,7 @@ public class Application {
|
|||
|
||||
if (preferences.isGenerateBinary()) {
|
||||
OutputStream output = new FileOutputStream(new File(file.getParentFile(), baseName + ".BIN"));
|
||||
source.generateObjectCode(output);
|
||||
output.write(new BinaryBuilder(source).build());
|
||||
output.close();
|
||||
}
|
||||
|
||||
|
@ -2161,7 +2161,7 @@ public class Application {
|
|||
});
|
||||
|
||||
serialPort = terminal.getSerialPort();
|
||||
byte[] data = source.generateObjectCode();
|
||||
byte[] data = new BinaryBuilder(source).build();
|
||||
|
||||
monitor.beginTask("Upload", (data.length + 127) / 128);
|
||||
out.println("Sending to serial port " + serialPort.getPortName() + " ...");
|
||||
|
@ -2227,7 +2227,7 @@ public class Application {
|
|||
});
|
||||
|
||||
serialPort = terminal.getSerialPort();
|
||||
byte[] data = source.generateObjectCode();
|
||||
byte[] data = new BinaryBuilder(source).build();
|
||||
|
||||
monitor.beginTask("Upload", (data.length + 127) / 128);
|
||||
out.println("Sending to serial port " + serialPort.getPortName() + " ...");
|
||||
|
@ -2707,7 +2707,7 @@ public class Application {
|
|||
sb.append(":");
|
||||
|
||||
int checksum = 0;
|
||||
byte[] data = source.generateObjectCode();
|
||||
byte[] data = new BinaryBuilder(source).build();
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
sb.append(String.format("%02X", data[i] & 0xFF));
|
||||
checksum += data[i] & 0xFF;
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Copyright (c) 2018-19 Marco Maccaferri and others.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under
|
||||
* the terms of the Eclipse Public License v1.0 which accompanies this
|
||||
* distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
|
||||
package com.maccasoft.tools;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import nl.grauw.glass.AssemblyException;
|
||||
import nl.grauw.glass.Line;
|
||||
import nl.grauw.glass.Scope;
|
||||
import nl.grauw.glass.Source;
|
||||
import nl.grauw.glass.directives.If;
|
||||
|
||||
public class BinaryBuilder {
|
||||
|
||||
Source source;
|
||||
|
||||
int addr;
|
||||
byte[] code;
|
||||
|
||||
int filler;
|
||||
ByteArrayOutputStream os;
|
||||
|
||||
public BinaryBuilder(Source source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public void setFiller(int filler) {
|
||||
this.filler = filler;
|
||||
}
|
||||
|
||||
public byte[] build() {
|
||||
addr = -1;
|
||||
filler = 0x00;
|
||||
os = new ByteArrayOutputStream();
|
||||
|
||||
build(source);
|
||||
|
||||
return os.toByteArray();
|
||||
}
|
||||
|
||||
void build(Source source) {
|
||||
for (Line line : source.getLines()) {
|
||||
try {
|
||||
Scope scope = line.getScope();
|
||||
if (line.getDirective() instanceof If) {
|
||||
code = new byte[0];
|
||||
}
|
||||
else if (scope.isAddressSet()) {
|
||||
code = line.getBytes();
|
||||
}
|
||||
else {
|
||||
code = new byte[0];
|
||||
}
|
||||
|
||||
if (code.length != 0) {
|
||||
int lineAddr = line.getScope().getAddress();
|
||||
|
||||
if (addr != -1) {
|
||||
while (addr < lineAddr) {
|
||||
os.write(filler);
|
||||
addr++;
|
||||
}
|
||||
}
|
||||
|
||||
os.write(code);
|
||||
addr = lineAddr + code.length;
|
||||
}
|
||||
|
||||
if (line.getDirective() instanceof If) {
|
||||
if (line.getInstructionObject() != null) {
|
||||
nl.grauw.glass.instructions.If ins = (nl.grauw.glass.instructions.If) line.getInstruction();
|
||||
build(ins.getThenSource());
|
||||
if (ins.getElseSource() != null) {
|
||||
build(ins.getElseSource());
|
||||
}
|
||||
}
|
||||
else {
|
||||
If ins = (If) line.getDirective();
|
||||
build(ins.getThenSource());
|
||||
if (ins.getElseSource() != null) {
|
||||
build(ins.getElseSource());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (AssemblyException e) {
|
||||
e.addContext(line);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Ładowanie…
Reference in New Issue