[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: self-replicating Apple ][ (6502) code on ApplePC



Tomoyuki Tanaka writes ...
> 
> when i had a real (clone) Apple ][ , i remember playing with a
> self-replicating 6502 code.
> 
> could someone post this code (6502 or Basic) if you have it?
> 

     This 6502 routine is not in my collection; but, a CALL-able
self-replicating routine should be pretty easy to do.

     If the routine knows only that it is not located in the stack page
and that the usual 'scratch' bytes are available in Page 0, it could
write an RTS ($60) instruction to a scratch byte location and execute a
JSR to the RTS. It would be able to locate itself via the return address
pushed onto the stack. This would be enough information to enable
copying itself x bytes ahead, where x is the length of the routine.

     The above routine could also decide when to skip certain areas
(like stack or I/O space), when (if desired) to wrap-around at the end
of memory, and when to exit.


> does this run on ApplePC?

     A routine like the above should run okay on a good emulator. Of
course, were it to fill up all available "Apple II" memory (except stack
and its own scratch area) with itself, the chances are you would not be
able to do much except exit to the monitor (whereupon part of your stuff 
would be over-written by the monitor display).


Rubywand