t-edson / P65Pas

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

init array on var declaration #5

Closed mvdhoning closed 5 years ago

mvdhoning commented 5 years ago

It would be nice if we were able to init arrays with value. Also you mentioned an array could be assigned to a defined memory position.

So that would make it possible to define sprite or font data at $3000 for instance:

var
  bytearray: array [3] of byte = ($10,$10,$10) absolute $3000;

also a more pascal syntax way for declaring an array would be array [0..2] of byte for a size 3 array.

i know i can do

bytearray[0] := $10;
bytearray[1] := $10;
bytearray[2] := $10;

already, it just does not feel efficient.

t-edson commented 5 years ago

I think this won't be a problem. I will check if it can be easily implemented in this version.

t-edson commented 5 years ago

Initialize arrays is implemented now:

var 
  a: [3]byte = [%01010, $FF, 10];

But initialize ABSOLUTE arrays is not implemented. It's not an issue of the compiler but of the PRG file generator. Absolute variables can be far away of the code section, and the PRG would need to cover that spaces. Moreover the assembler viewer is not prepared to show differente segments of code now. I will review.

t-edson commented 5 years ago

You can now initialize absolute arrays setting to a value. Not in declarartion but like a assigment instruction:

uses Commodore64;
var 
  a:[5]BYTE absolute $400;
begin
  a := [1,2,3,4,5];
  asm rts end
end.
mvdhoning commented 5 years ago

with things possibe now i feel that

uses Commodore64;
var 
  adef1: [3]byte = [%01010, $FF, 10];
  adef2: [3]byte = [$EE, $FF, $10];
  aabs: [3]byte absolute $400;
begin
  //first assing array1
  aabs := adef1;
  //do something
  //next assing array2
  aabs := adef2;
end

think i wont use aabs := [1,2,3]; but others might

also with this useable i feel less need to init a array at a specified position.

t-edson commented 5 years ago

No problem. The problem with init absolute arrays, is in the output format the PRG work. It only can specify just one block of memory. If including several blocks, the intermediate RAM will be rewritten. Maybe it can be implemented using other output format.

Don't forget you can use types too:

type
  Tarray3 = [3]byte;
t-edson commented 5 years ago

And don't forget you can use constants too, to init arrays;

const A1 = [1,2,3];
var ar: [3]byte;
begin
  ar := A1;

end.