The IY register and the Spectrum ROM

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
MonkZy
Manic Miner
Posts: 279
Joined: Thu Feb 08, 2018 1:01 pm

The IY register and the Spectrum ROM

Post by MonkZy »

I have been looking at the ROM disassembly and noticed the routines reference system variables using the IY register. IY is set to 23610 and system vars are read using an offset to IY. This is useful for loading a system variable into registers other than A, as LD r,(IY+N) can be used on all the registers, at a cost of 3 extra T-cycles to LD a,(NN). It also means you can relocate the system variables and change the IY register to point to the new location.

Why did the designers use this method?
User avatar
ketmar
Manic Miner
Posts: 699
Joined: Tue Jun 16, 2020 5:25 pm
Location: Ukraine

Re: The IY register and the Spectrum ROM

Post by ketmar »

why not? ;-) it is common practice to use IX/IY to access some array of variables. array of system variables looks like a perfect fit.

p.s.: they stole my register! i can't use it even if i'm not calling ROM, because ISR at #38 expects it to point at sysvars. HAET.
AndyC
Dynamite Dan
Posts: 1406
Joined: Mon Nov 13, 2017 5:12 am

Re: The IY register and the Spectrum ROM

Post by AndyC »

It's a very space efficient way of accessing the system variables. The Speccy ROM code is optimised to fit as much in to as small a space as possible, even at the expense of performance. And probably have them more flexibility during the design about where the system variables would ultimately be placed.
Post Reply