Skip to content

Commit

Permalink
Fixed pasm data alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
maccasoft committed Dec 13, 2023
1 parent db575ba commit 533e38f
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,43 @@ void testValueSizeOverride() throws Exception {
+ "", compile(text));
}

@Test
void testAlignment() throws Exception {
String text = ""
+ "PUB null\n"
+ "\n"
+ "DAT\n"
+ "\n"
+ " byte 1, 2, 3\n"
+ " long 4\n"
+ "\n"
+ " byte 5, 6\n"
+ " mov a, b\n"
+ " \n"
+ "a res 1\n"
+ "b res 1\n"
+ "";

Assertions.assertEquals(""
+ "' Object header (var size 0)\n"
+ "00000 00000 1C 00 Object size\n"
+ "00002 00002 02 Method count + 1\n"
+ "00003 00003 00 Object count\n"
+ "00004 00004 18 00 00 00 Function null @ $0018 (local size 0)\n"
+ "00008 00008 000 01 02 03 byte 1, 2, 3\n"
+ "0000B 0000B 00 (filler)\n"
+ "0000C 0000C 001 04 00 00 00 long 4\n"
+ "00010 00010 002 05 06 byte 5, 6\n"
+ "00012 00012 00 00 (filler)\n"
+ "00014 00014 003 05 08 BC A0 mov a, b\n"
+ "00018 00018 004 a res 1\n"
+ "00018 00018 005 b res 1\n"
+ "' PUB null\n"
+ "00018 00018 32 RETURN\n"
+ "00019 00019 00 00 00 Padding\n"
+ "", compile(text));
}

String compile(String text) throws Exception {
return compile(text, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,61 @@ void testValueSizeOverride() throws Exception {
+ "", compile(text));
}

@Test
void testAlignment() throws Exception {
String text = ""
+ "DAT\n"
+ "\n"
+ " byte 1, 2, 3\n"
+ " long 4\n"
+ "\n"
+ " byte 5, 6\n"
+ " mov a, b\n"
+ " \n"
+ "a long 1\n"
+ "b long 1\n"
+ "";

Assertions.assertEquals(""
+ "' Object header (var size 4)\n"
+ "00000 00000 00000 01 02 03 byte 1, 2, 3\n"
+ "00003 00003 00003 04 00 00 00 long 4\n"
+ "00007 00007 00007 05 06 byte 5, 6\n"
+ "00009 00009 00009 11 1A 00 F6 mov a, b\n"
+ "0000D 0000D 0000D 01 00 00 00 a long 1\n"
+ "00011 00011 00011 01 00 00 00 b long 1\n"
+ "", compile(text));
}

@Test
void testOrgAlignment() throws Exception {
String text = ""
+ "DAT\n"
+ " org $000\n"
+ "\n"
+ " byte 1, 2, 3\n"
+ " long 4\n"
+ "\n"
+ " byte 5, 6\n"
+ " mov a, b\n"
+ " \n"
+ "a long 1\n"
+ "b long 1\n"
+ "";

Assertions.assertEquals(""
+ "' Object header (var size 4)\n"
+ "00000 00000 000 org $000\n"
+ "00000 00000 000 01 02 03 byte 1, 2, 3\n"
+ "00003 00003 000 04 00 00 00 long 4\n"
+ "00007 00007 001 05 06 byte 5, 6\n"
+ "00009 00009 00 00 00 (filler)\n"
+ "0000C 0000C 003 05 08 00 F6 mov a, b\n"
+ "00010 00010 004 01 00 00 00 a long 1\n"
+ "00014 00014 005 01 00 00 00 b long 1\n"
+ "", compile(text));
}

String compile(String text) throws Exception {
return compile(text, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,20 @@ public Spin1Object generateObject(int memoryOffset) {
hubAddress = object.getSize();

for (Spin1PAsmLine line : source) {
if (line.getInstructionFactory() instanceof com.maccasoft.propeller.spin1.instructions.Long) {
if ((line.getInstructionFactory() instanceof com.maccasoft.propeller.spin1.instructions.Word)
|| (line.getInstructionFactory() instanceof com.maccasoft.propeller.spin1.instructions.Wordfit)) {
hubAddress = (hubAddress + 1) & ~1;
address = (address + 1) & ~1;
}
else if (line.getMnemonic() != null && !(line.getInstructionFactory() instanceof com.maccasoft.propeller.spin1.instructions.Byte)
&& !(line.getInstructionFactory() instanceof com.maccasoft.propeller.spin1.instructions.Bytefit)) {
hubAddress = (hubAddress + 3) & ~3;
address = (address + 3) & ~3;
}
line.getScope().setObjectAddress(hubAddress);
if ((line.getInstructionFactory() instanceof Org) || (line.getInstructionFactory() instanceof Res)) {
hubAddress = (hubAddress + 3) & ~3;
address = (address + 3) & ~3;
}
try {
address = line.resolve(address, memoryOffset + hubAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
import com.maccasoft.propeller.spin2.instructions.Org;
import com.maccasoft.propeller.spin2.instructions.Orgh;
import com.maccasoft.propeller.spin2.instructions.Res;
import com.maccasoft.propeller.spin2.instructions.Word;

public class Spin2ObjectCompiler extends Spin2BytecodeCompiler {

Expand Down Expand Up @@ -531,7 +530,8 @@ public Spin2Object generateObject(int memoryOffset) {
boolean spinMode = methods.size() != 0;

for (Spin2PAsmLine line : source) {
if (!hubMode && !(line.getInstructionFactory() instanceof com.maccasoft.propeller.spin2.instructions.Byte) && !(line.getInstructionFactory() instanceof Word)) {
if (!hubMode && isInstruction(line.getMnemonic())
&& !(line.getInstructionFactory() instanceof com.maccasoft.propeller.spin2.instructions.Long)) {
if (hubAddress != -1) {
hubAddress = (hubAddress + 3) & ~3;
}
Expand Down Expand Up @@ -674,6 +674,19 @@ else if (address > fitAddress) {
return object;
}

boolean isInstruction(String mnemonic) {
if (mnemonic == null) {
return false;
}
if ("long".equalsIgnoreCase(mnemonic) || "word".equalsIgnoreCase(mnemonic) || "byte".equalsIgnoreCase(mnemonic)) {
return false;
}
if ("longfit".equalsIgnoreCase(mnemonic) || "wordfit".equalsIgnoreCase(mnemonic) || "bytefit".equalsIgnoreCase(mnemonic)) {
return false;
}
return true;
}

Expression enumValue = new NumberLiteral(0);
Expression enumIncrement = new NumberLiteral(1);

Expand Down

0 comments on commit 533e38f

Please sign in to comment.