skilldrick / 6502js

A JavaScript 6502 assembler and simulator
GNU General Public License v3.0
484 stars 143 forks source link

an example that simulates a z80 ldir is very needed #6

Open ghost opened 7 years ago

ghost commented 7 years ago

i often ask people with 6502 assembly coding experience how can we do a ldir (like that one from z80) - when some people runs away, others tries to ask with totally useless suggestions - would be great if there would be an example explaining how can we have a routine that shows us how can we have ldir on 6502

BigEd commented 7 years ago

That's a very complex instruction! For reference:

It takes a source address in HL, a target address in DE, and a 16-bit count in BC. When executed, LDIR will load a byte from the address pointed to by HL, and store it at the address pointed to by DE. It will then increment HL and DE, decrement BC and repeat the whole load/store/increment/decrement dance until BC is 0. An entire memory block could be copied in a single instruction! Copying one byte this way cost 21 cycles though so it wasn’t exactly fast, for a few dozen kilobytes LDIR would take multiple seconds to complete.

Perhaps the best place for this would be codebase64 (original here) or a discussion on the forum at 6502.org?