Re: gtBASIC
Posted: 08 Sep 2021, 10:44
ok, thank you. In the meantime I think I can progress by just keeping an eye out for that fault. If I can get it to be on 2 unused variables that would work.
Code: Select all
888a889,890
> uint16_t offset = 15;
>
893a896,897
> if(savedLD._opcode.find("LDWI") != std::string::npos) offset += 1;
>
897c901
< savedLD._address += 15; // LD<X> is moved 15 bytes
---
> savedLD._address += offset; // LD<X> is moved 15bytes, LDWI is moved 16 bytes
906,908c910,925
< itVasm = Compiler::getCodeLines()[i]._vasm.insert(itVasm, savedLD);
< adjustLabelAddresses(i, firstLine - 1, -4);
< adjustVasmAddresses(i, firstLine - 1, -4);
---
> if(offset == 15)
> {
> itVasm = Compiler::getCodeLines()[i]._vasm.insert(itVasm, savedLD);
> adjustLabelAddresses(i, firstLine - 1, -4);
> adjustVasmAddresses(i, firstLine - 1, -4);
> }
> // LDW is replaced with LDWI so push everything forward starting at the last LDW by 1 more byte
> else
> {
> itVasm = Compiler::getCodeLines()[i]._vasm.insert(itVasm, savedLD);
> adjustLabelAddresses(i, firstLine - 1, -5);
> adjustVasmAddresses(i, firstLine - 1, -5);
> adjustLabelAddresses(i, firstLine + 5, 1);
> adjustVasmAddresses(i, firstLine + 5, 1);
> }
>
936a954,955
> uint16_t offset = 17;
>
942c961,963
< // Migrate LD<X>'s label to LDWI
---
> if(savedLD._opcode.find("LDWI") != std::string::npos) offset += 1;
>
> // Discard it's label, (it's no longer needed), and adjust it's address
945c966
< savedLD._address += 17; // LD<X> is moved 17 bytes
---
> savedLD._address += offset; // LD<X> is moved 17bytes, LDWI is moved 18 bytes
954,956c975,990
< itVasm = Compiler::getCodeLines()[i]._vasm.insert(itVasm, savedLD);
< adjustLabelAddresses(i, firstLine - 1, -4);
< adjustVasmAddresses(i, firstLine - 1, -4);
---
> if(offset == 17)
> {
> itVasm = Compiler::getCodeLines()[i]._vasm.insert(itVasm, savedLD);
> adjustLabelAddresses(i, firstLine - 1, -4);
> adjustVasmAddresses(i, firstLine - 1, -4);
> }
> // LDW is replaced with LDWI so push everything forward starting at the last LDW by 1 more byte
> else
> {
> itVasm = Compiler::getCodeLines()[i]._vasm.insert(itVasm, savedLD);
> adjustLabelAddresses(i, firstLine - 1, -5);
> adjustVasmAddresses(i, firstLine - 1, -5);
> adjustLabelAddresses(i, firstLine + 6, 1);
> adjustVasmAddresses(i, firstLine + 6, 1);
> }
>
You'll have to send me the code again, just a quick note, the optimiser relocation problem was not causing the overlapping of variables, it was causing code to be relocating incorrectly and then causing the memory manager to try and allocate code RAM that was already allocated. This kind of problem can cause anything to happen, (i.e. undefined behaviour), as some portion of code that was meant to be emitted could not be emitted from the RAM allocation collision. (i.e. When you app tries to execute code that it thinks will be at a certain place in memory, it won't be there and it will try and execute what is there, e.g. random bytes, other code, program data etc).
Code: Select all
'ROM1, ROM2, ROM3, ROM4
(0x80 - 0x30)/2 = 40 zero page vars
'ROM5a or higher without VBlank Interrupt
(0x80 - 0x30)/2 + (0xC0 - 0xD4)/2 = 50 zero page vars
'ROM5a/DEVROM with VBlank Interrupt
(0x80 - 0x36)/2 + (0xC0 - 0xD4)/2 = 47 zero page vars
'ROMvX0 with VBlank Interrupt
(0x80 - 0x38)/2 + (0xC0 - 0xD4)/2 = 46 zero page vars
Code: Select all
'misc byte array, i.e. uint8
dim misc_u8%(4) = 0, 1, 2, 3, 4
print misc_u8(0)
'misc int16 array
dim misc_i16(4) = 1000, 1001, 1002, 1003, 1004
print misc_i16(0)
'for bonus points use constants
const level = 0
const lives = 1
const score = 2
dim m(2) = 1, 3, 0
print m(level)
print m(lives)
print m(score)