Re: [fpc-devel] FPC and Z80

2020-04-27 Thread Marco van de Voort

Op 2020-04-27 om 21:24 schreef Florian Klämpfl:
Well, for 6502 working 16-bit ptr indirect via volatile zp memory 
locations needs to be implemented anyway :-)


Does that CPU have no hardware stack at all, or only limited (128/256 
bytes or so?)


It has a full stack but too little registers to use it efficiently for 
local variables: it has 3 8 bit registers pair plus accumulator (so 7 
8 bit registers), 


Then you need a parallel software stack for parameters and local vars, 
and keep the hw stack for return addresses only.


But like with the c=64 without 16-bit regs you probably need some form 
of indirect addressing via zeropage base pointers to access that stack( 
if>8bit).  IIRC the 6502 had very little free ZPs, but a lot more if you 
can reuse the locations used by the interpreter (e.g. backup/restore if 
you want to be able to return to basic)


two of them can be used as pairs for indirect addressing, so this 
makes life very hard


That is already more than the 6502 has.  Afaik the instruction pointer 
is the only 16-bit one. But if an basic interpreter can do it, so can a 
compiled program?



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] FPC and Z80

2020-04-27 Thread Florian Klämpfl

Am 27.04.20 um 21:12 schrieb Marco van de Voort:


Op 2020-04-27 om 18:28 schreef Florian Klaempfl:



I have no idea, but quickly read through some docs, and it seems the
GameBoy CPU doesn't have IX/IY registers, which seems to be very 
useful to
implement some of the more complex references handling, according to 
what
Nikolay wrote earlier. 


Yes. IX and IY are the key for the FPC Z80 port. Without them it's 
getting really difficult. And I suspect we need to work without a 
normal stack but allocate local variables globally, so basically no 
recursion will be possible.


Well, for 6502 working 16-bit ptr indirect via volatile zp memory 
locations needs to be implemented anyway :-)


Does that CPU have no hardware stack at all, or only limited (128/256 
bytes or so?)


It has a full stack but too little registers to use it efficiently for 
local variables: it has 3 8 bit registers pair plus accumulator (so 7 8 
bit registers), two of them can be used as pairs for indirect 
addressing, so this makes life very hard, but maybe, when I think about 
it, doable ;) 8085 assembler was the first assembler I learned, at a 
certain time I knew the hex. codes for most instructions.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] FPC and Z80

2020-04-27 Thread Marco van de Voort


Op 2020-04-27 om 18:28 schreef Florian Klaempfl:



I have no idea, but quickly read through some docs, and it seems the
GameBoy CPU doesn't have IX/IY registers, which seems to be very 
useful to
implement some of the more complex references handling, according to 
what
Nikolay wrote earlier. 


Yes. IX and IY are the key for the FPC Z80 port. Without them it's 
getting really difficult. And I suspect we need to work without a 
normal stack but allocate local variables globally, so basically no 
recursion will be possible.


Well, for 6502 working 16-bit ptr indirect via volatile zp memory 
locations needs to be implemented anyway :-)


Does that CPU have no hardware stack at all, or only limited (128/256 
bytes or so?)



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] FPC and Z80

2020-04-27 Thread Sven Barth via fpc-devel
Florian Klaempfl  schrieb am Mo., 27. Apr. 2020,
18:28:

> Am 27.04.2020 um 17:52 schrieb Karoly Balogh (Charlie/SGR):
> > Hi,
> >
> > On Mon, 27 Apr 2020, Sven Barth via fpc-devel wrote:
> >
> >>> Well, I'm surprised and impressed you got it to work at all...
> >>> Quite an achievement.
> >>
> >> Considering that we already support AVR as well I was rather confident
> >> here. :D Maybe in the future we can also add GameBoy support which uses
> >> some Z80/8080 hybrid? ^^'
> >
> > I have no idea, but quickly read through some docs, and it seems the
> > GameBoy CPU doesn't have IX/IY registers, which seems to be very useful
> to
> > implement some of the more complex references handling, according to what
> > Nikolay wrote earlier.
>
> Yes. IX and IY are the key for the FPC Z80 port. Without them it's
> getting really difficult. And I suspect we need to work without a normal
> stack but allocate local variables globally, so basically no recursion
> will be possible.
>

Pity... Oh, well, a topic for another time then :)

Regards,
Sven

>
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] New feature announcement: constant parameters for generics

2020-04-27 Thread Sven Barth via fpc-devel
Ryan Joseph via fpc-devel  schrieb am Mo.,
27. Apr. 2020, 18:28:

> I think constants in generics may be the only way to create dynamically
> sized types at compile time (via static arrays). That seems like a really
> narrow usage but it opens a lot of doors most of us have probably never
> thought about. I suspect in time more good usages will be discovered.
>

That's what I think as well.

Regards,
Sven

>
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] FPC and Z80

2020-04-27 Thread Florian Klaempfl

Am 27.04.2020 um 17:52 schrieb Karoly Balogh (Charlie/SGR):

Hi,

On Mon, 27 Apr 2020, Sven Barth via fpc-devel wrote:


Well, I'm surprised and impressed you got it to work at all...
Quite an achievement.


Considering that we already support AVR as well I was rather confident
here. :D Maybe in the future we can also add GameBoy support which uses
some Z80/8080 hybrid? ^^'


I have no idea, but quickly read through some docs, and it seems the
GameBoy CPU doesn't have IX/IY registers, which seems to be very useful to
implement some of the more complex references handling, according to what
Nikolay wrote earlier. 


Yes. IX and IY are the key for the FPC Z80 port. Without them it's 
getting really difficult. And I suspect we need to work without a normal 
stack but allocate local variables globally, so basically no recursion 
will be possible.



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] FPC and Z80

2020-04-27 Thread nickysn--- via fpc-devel
On Mon, 2020-04-27 at 17:52 +0200, Karoly Balogh (Charlie/SGR) wrote:
> Hi,
> 
> On Mon, 27 Apr 2020, Sven Barth via fpc-devel wrote:
> 
> >> Well, I'm surprised and impressed you got it to work at all...
> >> Quite an achievement.
> >
> > Considering that we already support AVR as well I was rather
> confident
> > here. :D Maybe in the future we can also add GameBoy support which
> uses
> > some Z80/8080 hybrid? ^^'
> 
> I have no idea, but quickly read through some docs, and it seems the
> GameBoy CPU doesn't have IX/IY registers, which seems to be very
> useful to
> implement some of the more complex references handling, according to
> what
> Nikolay wrote earlier. Also, it seems to be quite a few stuff missing
> from
> it, as well as it has some extras. The question is, how far it
> diverges
> from Z80 of course, and how that might violate some basic assumptions
> the
> Z80 CG currently does about the ISA.

Ah, that sucks :( We currently use IX as the frame pointer (similar to
BP on i8086), and there's this very convenient (IX+d) addressing. SDCC
does the same. So, this would mean the GameBoy would probably be a
different architecture, as far as FPC is concerned, with possibly some
shared units, like maybe the instruction set info tables, etc. It think
SDCC also treats it as a different arch.

Nikolay

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] FPC and Z80

2020-04-27 Thread J. Gareth Moreton
I'm kind of impressed actually that you're going out of your way to 
support older consoles and workstations.  It's certainly good for 
hobbyist development.  It's a shame that so many modern consoles have 
NDAs and physical measures to prevent homebrew software.  I still feel 
sad that the OUYA flopped, even though I never owned one... I thought 
the concept of allowing homebrewing was a nice idea.


If you can't tell, I have a slight passion for games development, but am 
stuck on the PC for now.


Gareth aka. Kit

On 27/04/2020 16:52, Karoly Balogh (Charlie/SGR) wrote:

Hi,

On Mon, 27 Apr 2020, Sven Barth via fpc-devel wrote:


Well, I'm surprised and impressed you got it to work at all...
Quite an achievement.

Considering that we already support AVR as well I was rather confident
here. :D Maybe in the future we can also add GameBoy support which uses
some Z80/8080 hybrid? ^^'

I have no idea, but quickly read through some docs, and it seems the
GameBoy CPU doesn't have IX/IY registers, which seems to be very useful to
implement some of the more complex references handling, according to what
Nikolay wrote earlier. Also, it seems to be quite a few stuff missing from
it, as well as it has some extras. The question is, how far it diverges
from Z80 of course, and how that might violate some basic assumptions the
Z80 CG currently does about the ISA.


I suppose FPC is now probably the compiler working for the biggest
number of CPUs/OSes - if it wasn't already. (C excepted, probably)

After GCC I'd assume that, too :)

GCC doesn't have most of what it supports mainline, rather in an
independenly maintained fork, plus the C library is not included in its
tree. So as far as "out of box" solutions go, FPC is quite up there.

Charlie

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] FPC and Z80

2020-04-27 Thread Karoly Balogh (Charlie/SGR)
Hi,

On Mon, 27 Apr 2020, Sven Barth via fpc-devel wrote:

>> Well, I'm surprised and impressed you got it to work at all...
>> Quite an achievement.
>
> Considering that we already support AVR as well I was rather confident
> here. :D Maybe in the future we can also add GameBoy support which uses
> some Z80/8080 hybrid? ^^'

I have no idea, but quickly read through some docs, and it seems the
GameBoy CPU doesn't have IX/IY registers, which seems to be very useful to
implement some of the more complex references handling, according to what
Nikolay wrote earlier. Also, it seems to be quite a few stuff missing from
it, as well as it has some extras. The question is, how far it diverges
from Z80 of course, and how that might violate some basic assumptions the
Z80 CG currently does about the ISA.

>> I suppose FPC is now probably the compiler working for the biggest
>> number of CPUs/OSes - if it wasn't already. (C excepted, probably)
>
> After GCC I'd assume that, too :) 

GCC doesn't have most of what it supports mainline, rather in an
independenly maintained fork, plus the C library is not included in its
tree. So as far as "out of box" solutions go, FPC is quite up there.

Charlie___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] New feature announcement: constant parameters for generics

2020-04-27 Thread Ryan Joseph via fpc-devel
I think constants in generics may be the only way to create dynamically sized 
types at compile time (via static arrays). That seems like a really narrow 
usage but it opens a lot of doors most of us have probably never thought about. 
I suspect in time more good usages will be discovered.

Regards,
Ryan Joseph

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] FPC and Z80

2020-04-27 Thread Sven Barth via fpc-devel
Michael Van Canneyt  schrieb am Mo., 27. Apr. 2020,
15:40:

>
>
> On Mon, 27 Apr 2020, nickysn--- via fpc-devel wrote:
>
> > Last night, I got the full system unit to compile, including console
> > output, so now you can use standard write/writeln. Unfortunately if you
> > include both read/readln and write/writeln in your program, the program
> > becomes too big to fit in the memory of the 48k ZX Spectrum, so there's
> > lots of optimizations left to do... :) However, the fact that the
> > system unit compiles fully, means that the code generator is starting
> > to become stable and, therefore, you should have little trouble porting
> > FPC to other Z80 platforms, such as the MSX - it's a matter of writing
> > the platform-specific RTL functions, and implementing the specific
> > things (linking and postprocessing the binary), required to produce a
> > program, in a format, suitable to run on the MSX.
>
> Well, I'm surprised and impressed you got it to work at all...
> Quite an achievement.
>

Considering that we already support AVR as well I was rather confident
here. :D Maybe in the future we can also add GameBoy support which uses
some Z80/8080 hybrid? ^^'


> I suppose FPC is now probably the compiler working for the biggest number
> of
> CPUs/OSes - if it wasn't already. (C excepted, probably)
>

After GCC I'd assume that, too :)

Regards,
Sven

>
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] FPC and Z80

2020-04-27 Thread Florian Klaempfl

Am 27.04.2020 um 15:37 schrieb nickysn--- via fpc-devel:

On Mon, 2020-04-20 at 17:07 +0300, nick...@gmail.com wrote:

On Thu, 2020-04-16 at 11:04 +0200, Guillermo wrote:

Thanks Swen.

I see last commit was 2 days ago so it is active.  I would like to
know
who is responsible to speak to him. May be I can help with the MSX
target, but I need gidance about the internals of the compiler (I
tried
but it is beyond my comprehension right now).



The current state of the Z80 port is that it's partially working, but
it's not complete enough in order to be able to compile a full RTL.
However, simple stuff like this is working on the ZX Spectrum:

program hello;
var
   i: byte;
begin
   PrintChar('F');
   PrintChar('P');
   PrintChar('C');
   for b := 0 to 255 do
 PrintHexByte(b);
end.


Last night, I got the full system unit to compile, including console
output, so now you can use standard write/writeln. Unfortunately if you
include both read/readln and write/writeln in your program, the program
becomes too big to fit in the memory of the 48k ZX Spectrum, so there's
lots of optimizations left to do... :) 


Maybe you look in the rtl for the CPUAVR defines. Reducing e.g. the size 
of textrec helps a lot, also exception handling for io (not sure if it 
is activated) causes a big share of code being pulled in.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] FPC and Z80

2020-04-27 Thread nickysn--- via fpc-devel
On Mon, 2020-04-27 at 15:40 +0200, Michael Van Canneyt wrote:
> 
> On Mon, 27 Apr 2020, nickysn--- via fpc-devel wrote:
> 
> > Last night, I got the full system unit to compile, including
> > console
> > output, so now you can use standard write/writeln. Unfortunately if
> > you
> > include both read/readln and write/writeln in your program, the
> > program
> > becomes too big to fit in the memory of the 48k ZX Spectrum, so
> > there's
> > lots of optimizations left to do... :) However, the fact that the
> > system unit compiles fully, means that the code generator is
> > starting
> > to become stable and, therefore, you should have little trouble
> > porting
> > FPC to other Z80 platforms, such as the MSX - it's a matter of
> > writing
> > the platform-specific RTL functions, and implementing the specific
> > things (linking and postprocessing the binary), required to produce
> > a
> > program, in a format, suitable to run on the MSX.
> 
> Well, I'm surprised and impressed you got it to work at all... 
> Quite an achievement.

To be honest, I was also surprised how quickly I reached this point of
code generator stability. The i8086 port was much more painful and took
a lot of time to get it that stable. But now, things are different,
because:

1. I'm much more familiar with the compiler internals, so the learning
curve isn't that steep
2. The compiler already has been ported to 16-bit and 8-bit platforms,
so there's less work needed in the generic parts of the code generator.
3. There are no special pointer types (near, far) and memory models.
It's just 16-bit flat address space.

On the other hand, this time:

1. I knew nothing about Z80 assembly when I started.
2. I knew nothing about the ZX Spectrum.

So, this time, I had to learn about these things from scratch. I also
had to implement the asm backend entirely, almost from scratch
(actually Florian had already started it, but it wasn't as complete as
the x86 family, which just borrows everything from i386, since i8086 is
just a subset of the i386 instructions).

> 
> I suppose FPC is now probably the compiler working for the biggest
> number of
> CPUs/OSes - if it wasn't already. (C excepted, probably)

Yeah, after this port, I'm convinced that FPC can be ported to anything
:) I guess, now 6502 becomes the next challenge. :) Btw, I'm also
considering the PIC microcontroller family, because I use them in some
of my hardware projects - AVR is cool, but sometimes there's a PIC that
just has the right peripherals integrated for your project. :) But
first, the Z80 target still needs a lot of optimizations, because it
produces too many unnecessary moves and the code becomes quite bloated,
at least compared to SDCC.

Nikolay

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] FPC and Z80

2020-04-27 Thread Michael Van Canneyt



On Mon, 27 Apr 2020, nickysn--- via fpc-devel wrote:


Last night, I got the full system unit to compile, including console
output, so now you can use standard write/writeln. Unfortunately if you
include both read/readln and write/writeln in your program, the program
becomes too big to fit in the memory of the 48k ZX Spectrum, so there's
lots of optimizations left to do... :) However, the fact that the
system unit compiles fully, means that the code generator is starting
to become stable and, therefore, you should have little trouble porting
FPC to other Z80 platforms, such as the MSX - it's a matter of writing
the platform-specific RTL functions, and implementing the specific
things (linking and postprocessing the binary), required to produce a
program, in a format, suitable to run on the MSX.


Well, I'm surprised and impressed you got it to work at all... 
Quite an achievement.


I suppose FPC is now probably the compiler working for the biggest number of
CPUs/OSes - if it wasn't already. (C excepted, probably)

Michael.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] FPC and Z80

2020-04-27 Thread nickysn--- via fpc-devel
On Mon, 2020-04-20 at 17:07 +0300, nick...@gmail.com wrote:
> On Thu, 2020-04-16 at 11:04 +0200, Guillermo wrote:
> > Thanks Swen.
> > 
> > I see last commit was 2 days ago so it is active.  I would like to
> > know
> > who is responsible to speak to him. May be I can help with the MSX
> > target, but I need gidance about the internals of the compiler (I
> > tried
> > but it is beyond my comprehension right now).
> 
> 
> The current state of the Z80 port is that it's partially working, but
> it's not complete enough in order to be able to compile a full RTL.
> However, simple stuff like this is working on the ZX Spectrum:
> 
> program hello;
> var
>   i: byte;
> begin
>   PrintChar('F');
>   PrintChar('P');
>   PrintChar('C');
>   for b := 0 to 255 do
> PrintHexByte(b);
> end.

Last night, I got the full system unit to compile, including console
output, so now you can use standard write/writeln. Unfortunately if you
include both read/readln and write/writeln in your program, the program
becomes too big to fit in the memory of the 48k ZX Spectrum, so there's
lots of optimizations left to do... :) However, the fact that the
system unit compiles fully, means that the code generator is starting
to become stable and, therefore, you should have little trouble porting
FPC to other Z80 platforms, such as the MSX - it's a matter of writing
the platform-specific RTL functions, and implementing the specific
things (linking and postprocessing the binary), required to produce a
program, in a format, suitable to run on the MSX.

Nikolay

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel