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