10 REM 'CHANGE' 20 REM An experimental program for altering Machine Code programs to run at a different location. 30 MODE7 40 ON ERROR PROCerror:END 50 PRINT CHR$(141);" ALTCODE - Changes Program addresses" 60 PRINT CHR$(141);" ALTCODE - Changes Program addresses" 70 PRINT'" The addresses are changed but the machine code program is not moved. Program must be *SAVEd and reloaded at the new address before use." 80 VDU28,0,24,39,8,12 90 INPUT"Enter actual starting address &"B$ 100 INPUT'"Enter actual finishing address &"C$ 110 B=EVAL("&"+B$) 120 IF C$>B$ C=EVAL("&"+C$):D=C-B+1 ELSE VDU7:PRINT'"Finishing address must be higher than the starting address, please re-enter details":wait=TIME:REPEAT UNTIL(TIME-wait)>400:GOTO80 130 INPUT'"Enter starting address where code shouldnormally reside &"E$ 140 E=EVAL("&"+E$):F=E+D 150 INPUT'"Enter the new starting address &"G$ 160 G=EVAL("&"+G$) 170 IF G>E H=G-E:?&7A=0 ELSE H=E-G:?&7A=&FF 180 ?&70=B MOD &100:?&71=B DIV &100 190 ?&72=D MOD &100:?&73=D DIV &100 200 ?&74=E DIV &100:?&75=F DIV &100 210 ?&78=H MOD &100:?&79=H DIV &100 220 RESTORE 1340 :REM 6502 CPU 230 REM RESTORE 1400 :REM 6512 CPU 240 FOR word=&A00 TO &AFC STEP 4 250 READ number% 260 !word=number% 270 NEXT 280 : 290 PROCcode 300 CALL&900 310 result=?&77*256+?&76 320 PRINT'"There were ";result;" addresses changed." 330 VDU7 340 C=C+1:C$=STR$~(C) 350 PRINT'" *SAVE XXXX ";B$;" ";C$;" ";G$;" ";G$ 360 PRINT'"Code may be saved by copying the above line, using the up arrow and COPY keys." 370 END 380 : 390 DEF PROCcode 400 searchbase=&70:memtotal=&72 410 counter=&76 :REM number of alterations counter 420 FOR pass=0 TO 2 STEP 2 430 P%=&900 440 [OPT pass 450 INC &75 460 LDY #0 470 STY &76 480 STY &77 490 LDA memtotal+1 \checking machine code program 500 BEQ nohigh 510 .loop1 520 JSR compare 530 LDA memtotal+1 540 BNE loop1 550 .nohigh 560 LDA memtotal 570 BEQ done 580 .loop2 590 JSR compare 600 CPY memtotal 610 BCC loop2 620 .done 630 RTS 640 : 650 .compare 660 LDA (searchbase),Y 670 TAX 680 LDA &A00,X 690 TAX 700 CPX #3 710 BEQ change 720 .skip \1 & 2 byte Opcodes, no action taken 730 JSR update 740 DEX 750 BNE skip 760 RTS 770 : 780 .change \check to see whether address is within the program area 790 JSR update 800 JSR update 810 LDA (searchbase),Y \check address (hi byte) 820 CMP &74 830 BCC out 840 CMP &75 850 BCS out 860 INC counter \increment address change counter 870 BNE few 880 INC counter+1 890 .few 900 DEY 910 CPY #&FF 920 BNE jump 930 DEC searchbase+1 940 INC memtotal+1 950 .jump 960 LDA &7A \check to see if move should be up or down 970 BNE down 980 : 990 .up \alter address up or down as appropriate 1000 CLC 1010 LDA (searchbase),Y 1020 ADC &78 1030 STA (searchbase),Y 1040 JSR update 1050 LDA (searchbase),Y 1060 ADC &79 1070 STA (searchbase),Y 1080 JMP out 1090 : 1100 .down 1110 SEC 1120 LDA (searchbase),Y 1130 SBC &78 1140 STA (searchbase),Y 1150 JSR update 1160 LDA (searchbase),Y 1170 SBC &79 1180 STA (searchbase),Y 1190 .out 1200 JSR update 1210 RTS 1220 : 1230 .update \increment Y register counter 1240 INY 1250 BNE over 1260 INC searchbase+1 1270 DEC memtotal+1 1280 .over 1290 RTS 1300 ]:NEXT 1310 ENDPROC 1320 : 1330 REM 6502 CPU Opcode bytes 1340 DATA &01010201,&01020201,&01010201,&01030301,&01010202,&01020201,&01010301,&01030301,&01010203,&01020202,&01010201,&01030303,&01010202,&01020201,&01010301,&01030301 1350 DATA &01010201,&01020201,&01010201,&01030303,&01010202,&01020201,&01010301,&01030301,&01010201,&01020201,&01010201,&01030303,&01010202,&01020201,&01010301,&01030301 1360 DATA &01010201,&01020202,&01010101,&01030303,&01010202,&01020202,&01010301,&01010301,&01020202,&01020202,&01010201,&01030303,&01010202,&01020202,&01010301,&01030303 1370 DATA &01010202,&01020202,&01010201,&01030303,&01010202,&01020201,&01010301,&01030301,&01010202,&01020202,&01010201,&01030303,&01010202,&01020201,&01010301,&01030301 1380 : 1390 REM 6512 CPU Opcode bytes 1400 DATA &01010201,&01020202,&01010201,&01030303,&01020202,&01020202,&01010301,&01030303,&01010203,&01020202,&01010201,&01030303,&01020202,&01020202,&01010301,&01030303 1410 DATA &01010201,&01020201,&01010201,&01030303,&01020202,&01020201,&01010301,&01030301,&01010201,&01020202,&01010201,&01030303,&01020202,&01020202,&01010301,&01030302 1420 DATA &01010202,&01020202,&01010201,&01030303,&01020202,&01020202,&01010301,&01030303,&01020202,&01020202,&01010201,&01030303,&01020202,&01020202,&01010301,&01030303 1430 DATA &01010202,&01020202,&01010201,&01030303,&01020202,&01020201,&01010301,&01030301,&01010202,&01020202,&01010201,&01030303,&01020202,&01020201,&01010301,&01030301 1440 : 1450 DEF PROCerror 1460 REPORT:PRINT" at line ";ERL 1470 ENDPROC