Welcome, Guest. Please login or register.


Author Topic: Help with memory layout (Read 4709 times)

Offline teopl

  • Newbie
  • Posts: 14
  • Country: cs
Help with memory layout
« on: 2022.September.06. 14:41:36 »
Hello Z80 friends :)

I made something like this: (with help from Geco and loader.asm he provided)

PROGRAM.COM
PROGRAM.BIN

When .COM is executed, we set the screen memory to be [ 0000 - 3FFF ] and .BIN is loaded in memory like this:

# [0x4000 - 0x40FF] =>   256 bytes for NOTHING! :) can be used if needed
# [0x4100 - 0x4200] =>   257 bytes of value 0x46 so any address in range [0x4100 - 0x41FF] will point to 0x4646
# [0x4201 - 0x4645] =>  1157 bytes of free space (use for stack)
# [0x4646 - 0x4648] =>     3 bytes for "JMP ABCD" instruction where ABCD is address of interrupt handler function to be set
# [0x4649 - 0x7FFF] => 14775 bytes for program

Then, jump to 0x4649 will happen and the program will do this:

- setup interrupt mode 2 and SP to align with the memory layout provided
- load EP1.BIN of size 16384 to memory [0x8000 - 0xBFFF]
- load EP2.BIN of size 4954 to memory [0xC000 - 0x....]

So basically, loader "PROGRAM.COM" loaded loader "PROGRAM.BIN" which loaded program "EP" which is split to "EP1.BIN" + "EP2.BIN"

After this, relevant memory would be:

# [0x8000 - 0x80FF] =>   256 bytes for video mask table
# [0x8100 - 0x8200] =>   257 bytes of value 0x86 so any address in range [0x8100 - 0x81FF] will point to 0x8686
# [0x8201 - 0x8685] =>  1157 bytes of free space (use for stack)
# [0x8686 - 0x8688] =>     3 bytes for "JMP ABCD" instruction where ABCD is address of interrupt handler function to be set
# [0x8689 - 0xFFFF] => 31095 bytes for program

When finally this is done, we jump to program "EP" start (0x8689) and all is executed correctly.

PROBLEM: If I add *one more byte* to "EP2.BIN" the "EP" program does not work! As if I have overwritten some part of memory which is used. (that would be ~54106 or ~0xD35A)

QUESTION: Do you have idea what might be wrong? Maybe I did not moved screen memory correctly or something with the disabling OS or something with interrupts? I really am out of my options, so anyone can help it would be great! :)

QUESTION: Do you have better idea? Do I need to use interrupt mode 2? I wanted to have at least 32K of main program in one continuous segment [0x8000 - 0xFFFF], 16K of screen memory [0x0000 - 0x3FFF] and 16K of swappable memory in the second block [0x4000 - 0x7FFF] => this is most important as I want to have the same logic for CPC and bankswitching on CPC is much simpler if you want to switch this block.

I could send source but it would be my last option as it involves too much and build process is just too complex (a lot of tools, scripting, cpctelera patches, ...) and it also requires external hardware to test (SF3 or RSF3), as I am actually loading EP1.BIN and EP2.BIN with SF3 from the internet...


Offline geco

  • EP addict
  • *
  • Posts: 7082
  • Country: hu
    • Támogató Támogató
Re: Help with memory layout
« Reply #1 on: 2022.September.06. 16:32:21 »
Please attach the "bad" version, because by the description seems nothing is overwritten in page3.

Offline teopl

  • Newbie
  • Posts: 14
  • Country: cs
Re: Help with memory layout
« Reply #2 on: 2022.September.06. 17:32:01 »
I uploaded 2 files: ("bad" version)

[8000-BFFF] <= EP.00
[C000-....] <= EP.01

If you jump to 0x8689 it should switch the background colors (in interrupt handler) and move box from left to right (in main loop).

Offline teopl

  • Newbie
  • Posts: 14
  • Country: cs
Re: Help with memory layout
« Reply #3 on: 2022.September.06. 17:55:58 »
I also uploaded "good" variant. (this works ok)

Offline teopl

  • Newbie
  • Posts: 14
  • Country: cs
Re: Help with memory layout
« Reply #4 on: 2022.September.06. 21:25:39 »
After some debugging, Geco solved the mistery - thanks again!

Turns out that:

- I used some cpctelera functions which needed some updates for EP (setBorder)
- and also some functions which use LPT (like setBorder and setPalette or change active screen) which should have be located in [8000-bfff] range

After these fixes which I would probably spend rest of my life to find alone, it worked :D

Offline geco

  • EP addict
  • *
  • Posts: 7082
  • Country: hu
    • Támogató Támogató
Re: Help with memory layout
« Reply #5 on: 2022.September.07. 18:10:29 »
small correction :-)
Set border can be anywhere, but it is in the same code with set ink, so if set ink part is called, and the routine is above 0c000h, it hangs, all LPT modifying routines should be below 0c000h.