TL;DR:
It's 64 KiB total in any combination imaginable.
Or more general:
The Z80 features
- 16 address lines (A15..A0),
- sufficient to address 64 KiB (via D7..D0),
which can be used to access one of two address spaces
- default memory (with next to all instructions, indicated by
/MREQ
) or
- I/O locations (with IN and OUT instructions, indicated by
/IORQ
).
Either address space can be filled at will with
- RAM,
- ROM,
- I/O or
- not at all.
Pick your choice.
(Not to mention swapping RAM/ROM/IO in and out by reconfiguration of address decoding - but that'll be design/machine specific and not due to CPU design)
In Detail:
Whenever I see how Memory a Z80 could address in many sites, Wikipedia and so it states 64KB, but type type of memory isn't specified ROM or RAM,
Because it's an address space of 64 Ki, independent of what is placed there.
I could understand that your confusion comes from modern SoC with separate channels for each use case. The Z80, like basically all classic CPUs offer only a single, generic bus for all types connected. All devices use the same interface. Selection is done by address decoding outside the CPU.
it is specified that RAM and ROM share the 64KB address so 32KB for RAM and 32KB for ROM,
Why does it have to be 32+32 KiB? Any split is possible. Some systems will have only a small 2-4 KiB Boot ROM, able to load some OS from an external media.
in other places I saw that maximum RAM space is 64KB, hence there should be extra space for ROM.
No, not necessary, as ROM may only be needed during boot and will be disabled after some OS is booted - the usual way for CP/M machines.
tried to open the Z80 datasheet directly [...] I found what's called a stack pointer which is holding 16bit address for external RAM
That's the software side. If you want to see how hardware is interfaced, you ned to look at the pins and their function. Like A15..A0 holding an address.
plus there is a pin called MREQ which supposedly becomes active when the Z80 is using RAM.
No, it's active when it accesses memory - independent of being RAM or ROM (or whatever). It distinguishes access to memory address space to I/O address space (marked by /IORQ
).
Now some evidence suggest that the Z80 could address a total 64KB total ROM and RAM, and some suggest that is could address 64KB ROM and 64KB RAM so 128KB total for both of the memory types.
Now that would be nice to see that evidence. Because all I ever found is reference to a 16-bit address space that can be populated with anything.