PROGRAMMING: MEMOTECH Recovery by A F Wilson Extracted from pages 22-23 of Popular Computing Weekly, 29 May-4 June 1987 Recovery is a utility for the Memotech MTX series of micros. which mimics the BBC micro command OLD. Recovery as its name suggests recovers programs which have been accidently erased. The utility is interrupt driven,thus the program is available at all times. Function key 'F1' is used to save the systen variables and 'F2' to restore the saved system variables. As you will soon see the recovery listing is for the disc based system,but by removing the USER command from line 120 of listing, allows the program to work on a tape based MTX micro. Note MTX 500 owners should change all #4000 references to the equivalent #8000 addresses. The program when loaded,auto runs itself in high memory ,then sets the interrupt vector and NEW's itself. The program won't affect any BASIC programs and is available at all times,just press F1 and F2. To save the program type GOTO 120. This will save the program. When you come back to reload the program,the BASIC OS is ready to execute line 140. The RUN command sets the BASIC OS to line 10,which goes to line 100. The code at line 100 then moves the relocatable code in line 20,to the top of free space,sets the interrupt vector to point to the relocated code. Once this is done the program NEWs itself as we don't need the basic listing just the code at #BF34. To use the program,load it using: USER LOAD "RECOVERY.BAS" for disc users,or LOAD "" for tape users. Type in the following example: 10 PRINT "TEST" 20 REM Now press 'F1' to save the cuurent program. Type in PANEL ,D BF97 ,. The hex dump at the bottom of the screen displays the contents of FIRST8B,SYSVARS. These should be: 0C 00 0A 00 90 22 54 45 12 40 00 40 12 40 12 00 00 40 12 40 00 Type NEW ,the press 'F2' to recover. However,if you press the RESET keys then you lose the interrupt code. This means you cannot use the function keys. At this stage you can either save the program you are working on and reload the RECOVER program or use the following two commands to save and restore: to save :RAND USR(48960) to recover:RAND USR(49012) 10 GOTO 100 20 CODE 4010 LD A,(#FD7D) ;LET A=THE LAST ASCII KEY PRESSED. 4013 CP #80 ;IS IT 'F1' 4015 JR Z,SAVEPRG ;IF SO GOTO SAVE VARIABLES 4017 CP #81 ;IS IT 'F2' 4019 JR Z,RESTPRG ;IF SO GOTO RESTORE VARIABLES 401B RET ;RETURN TO CALL ROUTINE 401C SAVEPRG:LD HL,#4000 ;POINT HL TO START OF BASIC 401F LD DE,#BF97 ;SAVE AT FIRST8B 4022 LD BC,8 ;8 BYTES TO SAVE 4025 LDIR ;SAVE THE 8 BYTE BLOCK 4027 SARLOOP:LD DE,#BF9F ;POINT DE TO SYSVARS 402A LD IX,#BF90 ;POINT IX TO LSB OF SYSTEM VARS. 402E LD B,7 ;SEVEN WORDS TO SAVE. 4030 SYSVLOP:LD A,(#BFAD) ;LET A=SAVE OR RESTORE FLAG. 4033 LD H,#FA ;H=MSB OF SYSTEM VARIABLE 4035 LD L,(IX+0) ;L=LSB OF SYSTEM VARIABLE 4038 PUSH DE ;SAVE DE AS AFFECTED ON RESTORE 4039 CP 0 ;IS FLAG=0? 403B JR Z,SAVE ;IF SO SAVE SYSTEM VARIABLES 403D CALL #BF87 ;RESTORE SYSTEM VARIABLES 4040 JR LOADED ;ONCE RESTORED WORD BYPASS SAVE. 4042 SAVE: CALL #BF88 ;SAVES SYSTEM VARIABLES 4045 LOADED: POP DE ;RESTORE CORRUPTED REGISTER PAIR 4046 INC DE ;MOVE DE ONTO 2 PLACES 4047 INC DE ; 4048 INC IX ;MOVE IX TO NEXT WORD IN VARDISP 404A DJNZ SYSVLOP ;IS ALL FINISHED 404C LD (#BFAD),A ;RESET FLAG 404F RET ;RETURN TO CALLING ROUTINE 4050 RESTPRG:LD HL,#BF97 ;RESTORE FIRST8B AT #4000 ON A MTX 4053 LD DE,#4000 ;512 COMPUTER,#8000 ON A MTX 500. 4056 LD BC,8 ;8 BYTES TO BE RECOVERED 4059 LDIR ;MOVE THEM BACK. 405B LD A,1 ;SET FLAG FOR RESTORE 405D LD (#BFAD),A ;SAVE IT IN FLAG 4060 JP #BF4B ;GOTO SARLOOP 4063 RESSYSV:EX DE,HL ;LET DE=HL & HL=DE ,FOR RESTORING. 4064 SAVSYSV:LD A,(HL) ;SWAP CONTENTS OF DE AND HL. 4065 LD (DE),A ; 4066 INC HL ;REMEMBER SWAPPING TWO BYTES 4067 INC DE ; 4068 LD A,(HL) ; 4069 LD (DE),A ; 406A XOR A ;CLEAR REGISTER A AND FLAGS 406B RET ;RETURN TO MAIN PART 406C VARDISP:DB #A4,#A7,#AA,#AC,#CC,#CF,#D6 4073 FIRST8B:DS 8 407B SYSVAR: DS 14 4089 FLAG: DB 0 408A RET 100 CODE 420C LD HL,#4010 ;MOVE THE CODE IN LINE 20 TO 420F LD DE,#BF34 ;TOP OF FREE SPACE. 4212 LD BC,123 ;JUST BELOW THE BASIC VARIABLE 4215 LDIR ;RAM AT #C000 TO #D6FF. 4217 LD A,#C3 ;LET INTERRUPT VECTOR TO JP #BF34 4219 LD (#FA98),A ;THE JP #BF34 IS STORED IN A 421C LD HL,#BF34 ;RESERVED 3 BYTE SPACE AT #FA98. 421F LD (#FA99),HL ;THIS IS CALLED EVERY 64TH OF A 4222 LD A,(#FD5E) ;SECOND WHEN INTFFF,ADDRESS IS 4225 OR #9F ;SET BY SETTING BITS 4 AND 7,SEE 4227 LD (#FD5E),A ;BASIC REFERENCE MANUAL. 422A RET ;RETURN TO BASIC 110 NEW 120 USER SAVE "RECOVERY.BAS" :REM FOR DISC USERS 130 REM USE SAVE "RECOVERY" FOR TAPE USERS. 140 RUN Notes: If you press the RESET keys then you lose the interrupt code. This means you cannot use the function keys. To recover the previous program RAND USR(49012),this will restore it. Remember the code at #BF34,is still intact as is the system variables already saved. When you reset the computer it wipes out the Operating System system variables,which includes our interrupt driven code.