Best way to init SP (ROM)?

Page 1/3
| 2 | 3

Par viejo_archivero

Paragon (1394)

Portrait de 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 ou Inscrivez-vous pour poster

Par zeilemaker54

Champion (281)

Portrait de zeilemaker54

23-07-2020, 12:23

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

Par viejo_archivero

Paragon (1394)

Portrait de 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

Par theNestruo

Master (200)

Portrait de 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.

Par Pencioner

Scribe (1182)

Portrait de 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?

Par Grauw

Ascended (9342)

Portrait de 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.

Par viejo_archivero

Paragon (1394)

Portrait de 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

Par theNestruo

Master (200)

Portrait de 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

Par viejo_archivero

Paragon (1394)

Portrait de 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.

Par SjaaQ

Master (149)

Portrait de SjaaQ

24-07-2020, 11:50

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

Par gdx

Prophet (3761)

Portrait de 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+.

Page 1/3
| 2 | 3