ld ix, 0 add ix, bc inc hl ; hl = *segment ld b, (hl) ld c, 0 ld iy, 0 add iy, bc
Just a note, you can directly load into ixl/h and iyl/h:
ld ixl,c ld ixh,b inc hl ld b,(hl) ld iyh,b
If the assembler doesn’t support the undocumented instruction you can write it like this:
db 0DDH ; next instruction uses ix instead of hl ld l,c db 0DDH ; next instruction uses ix instead of hl ld h,b inc hl ld b,(hl) db 0FDH ; next instruction uses iy instead of hl ld h,b
It’s a bit faster.
Good to know, but usually only use documented to avoid problems. It is an habit. It could be the rare case that CPUs backwards compatible with Z80A would not implement that as is not documented officially, who knows. Using this manual (I think is the official one) not mentioning IXL or IXH but for PUSH/POP.
http://z80.info/zip/z80cpu_um.pdf
All working now. Changing segments, inter-segment read/write and even inter-segment calls.
Having access to the whole memory :D
R800 implements it officially, and all Z80s support it as well. Anyway, just worth a mention.
Well I noticed something weird. When inter-segment calling to page 0, that code cannot use DOS system calls (like PRINTF, FOPEN, FREAD, PUTS, etc.), because it hangs. I copy the 1st 256-byte of the base memory page 0 to the segment (if not it would hang because the ISR 0038h). Functions not usings DOS system calls work fine.
When placing the code in another page, it works fine even when using DOS system calls.
Why could be this? I think is rare because looking at DOS environment:
http://map.grauw.nl/resources/dos2_environment.php
At address 0005h is a jump instruction to the start of the resident part of MSX-DOS which is used for making MSX-DOS calls. In addition the address of this jump defines the top of the TPA which the program may use. The size of the TPA depends on what cartridges are used on the MSX machine and the number of them, but is typically 53K. The low byte of the destination of this jump will always be 06h for CP/M compatibility, and the six bytes immediately preceding it will contain the CP/M version number and a serial number.
The 0005h is also copied so it should jump to the correct address.
The code is a full self-contained C compiled source with its own CRUN and etc. functions. As said, placing it in any other page it works fine. So it is not a symbol failure.
Edit: OK was copying wrong the page 0 system header.
Wow, now can load code in runtime on demand and execute it.
Infinite power :D
