Best way to init SP (ROM)?

Página 1/3
| 2 | 3

Por viejo_archivero

Paragon (1394)

Imagen del viejo_archivero

23-07-2020, 12:15

Hi there! I Recently came up with a discussion on which is the best way to initialize the stack pointer (ROM enviroment).

What I usually do is:
ld sp, (HIMEM)

What I am being told is better to do is:
ld sp, f380h

I always thought the first way was the standard and the safest way to do it instead of hardcoding the sp adress... but various MSX developers are telling me that if a DOS2 interface or a Flashjacks with Nextor is present, the ROM won't work, and that I should hardcode sp adress. Am I doing things wrong? Question

Login sesión o register para postear comentarios

Por zeilemaker54

Champion (281)

Imagen del zeilemaker54

23-07-2020, 12:23

If it does not interact with basic, using himem should be ok

Por viejo_archivero

Paragon (1394)

Imagen del viejo_archivero

23-07-2020, 12:24

zeilemaker54 wrote:

If it does not interact with basic, using himem should be ok

It does not Wink

Por theNestruo

Master (199)

Imagen del theNestruo

23-07-2020, 12:48

I do it the HIMEM way... and also preserve the existing hook.

I prefer this "respectful" style for no technical reason; I just find it more "respectful" and feels "right"... But I agree that depending on the firmware/other cartridge, it can lead to some problems if the previous software moves the stack down a lot (may interfere with your variables) or if the previous hook tooks really long (may degrade the game performance).

As a game ROM is intented to be used stand-alone, I guess it is not really *that* important: you won't be returning to previous software, so whatever it had in stack / hook can be safely drop out.

Por Pencioner

Scribe (1181)

Imagen del Pencioner

23-07-2020, 14:36

Is there any problem of using the stack pointer 'AS IS' after ROM starts? What could be wrong with that?

Por Grauw

Ascended (9342)

Imagen del Grauw

23-07-2020, 15:57

I reckon the context is this recommendation from the MSX2 technical handbook. It seems mostly relevant when you want to use all of the upper memory up to F380H. So in that sense I reckon there is maybe not much point to setting the stack pointer to HIMEM, it will only save a few bytes.

I myself so far always used the stack pointer as-is. But I do usually have a check if there’s sufficient stack space between the end of my variable area and the stack. Ignoring HIMEM and manually setting the stack pointer to F380H seems a bit dirty. What if a hook has been set up that point to that area (e.g. interrupt handler?). But I guess it’s nice that the option is there if you really need a lot of RAM.

Por viejo_archivero

Paragon (1394)

Imagen del viejo_archivero

23-07-2020, 19:19

Thnx Grauw for the detailed info. So... it is not a good practice to initialize stack at the beginning of the program with ld sp,(HIMEM)? It would be better to just let the sp be wherever it is and just check it to see if it's located somewhere safe for your RAM usage? Just trying to learn here Smile

Por theNestruo

Master (199)

Imagen del theNestruo

23-07-2020, 20:06

You can always take a look at the disassembly of the first insturctions of some classics and modern games... but I'm afraid that will simply add more confusion oO

  • Alcazar: di / ld sp,$F032
  • Ali Baba: im 1 / ld sp,$F300
  • Butamaru Pants: nothing (no di, no im, no ld sp)
  • Crazy Train: (...) / ld sp,$E800
  • Eggerland Mystery: (...) / di / ld sp,$DE3F
  • Gommy Medieval Defender: di / im 1 / ld sp,(HIMEM)
  • Metal Gear: di / ld sp,Stack (Stack is a 1.130 bytes long space reserved in RAM)
  • Pyramid Warp: nothing (no di, no im, no ld sp)
  • Relevo's Snowboarding: di /im 1 / ld sp,(HIMEM) :-P
  • Stevedore: di / im 1 / ld sp,(HIMEM)
  • X-Spelunker: ld sp,$F380
  • Yazzie: ld sp,$F380

Por viejo_archivero

Paragon (1394)

Imagen del viejo_archivero

23-07-2020, 20:27

heh, I did a similar research when they told me on ld sp,(HIMEM) not being the correct way Wink, that's mostly the reason I came here looking for answers on the best practice for stack pointer initialization.

Por SjaaQ

Master (147)

Imagen del SjaaQ

24-07-2020, 11:50

In DotAttack, I use IM2 and do a LD SP,#FFFE. No byte to waste!

Por gdx

Prophet (3753)

Imagen del gdx

24-07-2020, 12:17

MSXs use IM1 only and LD SP,#FFFE is not advisable because in this way you overwrite system variables MSX2/2+.

Página 1/3
| 2 | 3