Below you will find pages that utilize the taxonomy term “6502”
Machine Language: Count Faster on 6502
I’ve done a lot of silly math, ciphers and asked a lot of my vintage hardware on this site over the years. But I’ve not talked a ton about optimizing code for faster results.
Today, we will count from 0 to 2^24-1
(16,777,215). Nothing else. Count, time it, and see how fast we can get it to go.
Rust
In Rust on my 2020 MacBook Pro:
use std::time::{Instant};
fn main() {
// Start timing
let start = Instant::now();
// Loop from 0 to 16777215
for _i in 0..=16777215 {
// The loop body is empty, just like in the BASIC code
}
// Calculate elapsed time
let duration = start.elapsed();
// Convert elapsed time to seconds
let elapsed_seconds = duration.as_secs() as f64
+ (duration.subsec_nanos() as f64 / 1_000_000_000.0);
println!("Counting to 16777215 took {} seconds", elapsed_seconds);
println!("That's {} additions per second", 16777216.0 / elapsed_seconds);
println!("On 2 GHz Quad-Core Intel Core i5")
}
A gentle introduction to two's complement
I was recently on a video call with a friend, throwing around some ideas for a new product. I mentioned adding large signed numbers in assembly and using two’s complement. He asked me what two’s complement was. I was a little surprised that he didn’t know. He’s been a Java programmer for more than 30 years. Java and Python programmers (and others like gasp Commodore / MicroSoft BASIC) don’t have a native unsigned integer type. The language takes care of the details for you.
Rail Fence Cipher on Commoodore 64 and TI 99/4A
I have a BUNCH of nieces and nephews. Over the years, doing some secret message passing with them around birthdays and holidays has been fun.
The “secret” location of hidden Christmas presents is a favorite.
Traditionally, we’ve used a transposition cipher like the Shift or Ceasar Cipher
For something different, we’re going to use another transposition cipher called the Rail Fence Cipher. It is easy to implement and understand. Plus easy to break, so it’s a good teaching tool.
Building a software serial bridge
Modern and retro mix
One of my favorite peices of retro clone hardware is Bob Corsham’s KIM-1 Clone. I’ve featured it many places like the 6502 speed series.
I have the latest model of this board, and he made an interesting design choice. It actually has an FTDI chip on board and you use that via USB to connect via a modern computer with an FTDI driver. This is very convenient for working with a modern computer, but then eliminates the ability to use a real serial port.