t-edson / P65Pas

CPU 6502 Pascal Compiler/IDE/Debugger
GNU General Public License v3.0
120 stars 27 forks source link

Problem using word variable to access screen array #39

Closed odflor closed 2 years ago

odflor commented 2 years ago

The output of this program is not the spected.

Instead of fullfill the screen with petscii characters, only fills the first 256 screen positions.

If I see the assembler generated code is because uses only the low bytes to do the assigment.

;screen[i] := b; $0823 A5 F9 LDA b $0825 A6 F7 LDX i@0 <-----only use low byte $0827 9D 00 04 STA $0400,X

program Hello; //uses Commodore128; uses Commodore64; var i : word; b : byte; begin b := 0;

for i := 0 to 999 do screen[i] := b; <---- here is the problem inc(b);

if b > 254 then
  b := 0;
end; // if

end; // for

screen[999] := 0; <---- using constants works very well asm RTS end end.

t-edson commented 2 years ago

Hi. I've identified the problem. This is a feature lost when redesigned the Code generator. Currently this is a failure in the Optimizer. I remember I considered to implement this using a register in Zero page. I will be checking it in this days.

t-edson commented 2 years ago

Hi. The issue for assigning to arrays of bytes, is fixed now. There are still some issues to work with arrays but you can work OK with arrays of bytes.