AUTOFADE from Your Sinclair #4 (Apr.1986) FADE AWAY Have you got a burning desire to be on the telly? Well, you're going the right way about it - unless you use this program. Andy Pennell's AutoFade provides the perfect protection policy for your TV. Have you ever wondered what happens to your telly if you decide to go walkabout while you're in the middle of a spot of programming. Sod's law says that something always crops up right in the middle of what you're doing - nature calls, the cat dies, the telegram arrives to tell you that your premium bond's just come up. Well, if you've just won a hundred grand you're not going to worry too much about your TV, but for the rest of us it's worth knowing what happens if the Speccy's left on too long untouched. Well, if you leave any image on the screen for a long time you may affect the phosphor in the TV tube and that can result in a faint image being burnt permanently into your screen. So, how do you avoid it happening? Well, what you need is a program that turns the screen off if you don't do anything for a while. And that's exactly what this program, AutoFade, does. If you don't touch a key for a certain period - you can choose any time lapse up to twenty minutes - the screen will go completely black. Well, all except for a single flashing white square that lets you know what's happened. The next time you press a key the screen will be restored to its previous state. The idea for the program was suggested to me by a YS reader who'd seen a similar routine for the Beeb - the ancient historians amongst you may remember the machine! As usual my filing system fell over and I lost the original letter, but thanks anyway whoever you may be. INTERRUPT US! You've probably guessed already that the program uses interrupts to do its stuff. And I use my interrupts so that they work regardless of what add-ons are connected, including Interface 1. That's what makes the program not only genuinely useful but also a good illustration of how to handle Interrupt Mode 2 neatly. The usual problems with IM2 type routines is that they don't work with non- Sinclair peripherals. That's because the byte that's read when the Z80 tries to get the vector address is not FF as normal but it can be any value. To take into account all the values from 0 to FF you have to construct a jump table that allows for all possibilities. And in spite of what you'll read in many Z80 manuals, bit 0 isn't zeroed when the vector is to be found. So, the interrupt routine has to lie at an address that has two bytes the same - I've used #FDFD. The I vector points to $FE00, which is a table of 257 bytes of $FD, allowing for all possibilities. Take a look at the Source Code and you'll see what I'm on about. The Source The easiest way of blanking the screen while saving its previous contents is not to save all 6K of screen data but just the attribute file of 768 bytes. You can then make the display file black by zeroing the attributes, leaving the display bit map well alone. The attributes are stored In the area SCRBUF. The INIT routine sets up the vector table and the Interrupt mode. It also sets TIMER to 1 - this normally increases by 1 every 50th of a second until it reaches its maximum value, when the screen is blanked, then it's set to 0 until a key is pressed. The DISFAD routine turns off the fader by going back to the usual Interrupt mode 1. INTROU is my version of the Interrupt routine which normally just scans the keyboard. It starts by calling the ROM interrupt routine in either the Basic ROM or Interface 1, then saves the registers before calling the extra routine MYINT. It then restores the registers and returns in a similar way to the ROM routine. The JP INTROU must always be at #FDFD and it must immediately be followed by the 257 byte vector table at #FE00. All these requirements do mean that relocating the program to another memory address isn't just a simple matter of changing the ORG directive. It's a job that should only be attempted by the brave - or foolhardy! MYINT is the special interrupt routine that controls the screen. It starts by testing for a TIMER value of 0, which means that the screen's been blanked. Now assuming that it hasn't, it sees if the count has reached the magic number - altering the LD DE instruction changes the period of the delay in 50th seconds. If it's not timed out, the timer is incremented unless a key's been pressed, when it's reset to 1. BLANK handles the job of clearing the screen which it does by copying the attributes to the buffer then setting them all to 0 (black). The border's set to black as well and you'll find the flashing cursor at the bottom right position on the screen. It returns with a zero value on HL for TIMER. TISBLA works when the screen's already blank and tests to see if you've pressed a key. If you have, the old screen attributes are restored, the correct border colour is set and the TIMER is set to 1. -- Another Fine Product transcribed by: Jim Grimwood (jimg@globalnet.co.uk), Weardale, England --