Tuesday, March 8, 2011

Pulling out my hair

So last night I ambitiously decided to take my AVR program to the next level and instead of just logging elapsed time between pulses from the Apple 5.25" drive, I would actually try to convert these time intervals into actual bits so that the emulation community can enjoy copy-protected disk images someday (I find the concept interesting). So I started writing my AVR program, using C. I carefully stepped through each instruction in AVR Studio's simulator and counted the cycles and I felt like I had come up with a pretty awesome solution if I do say so myself. Then I flashed the code to the real AVR and powered up my Apple //gs.

At first, nothing happened and I found and fixed a bug in one of my loops. Then I tried again.

For the next hour, my supposed-to-be-awesome program sat there insolently spitting out 1's at me, no 0's at all. And since I was expecting a healthy mix of 1's and 0's, I was not getting the correct data here that I wanted! I pulled out my hair for probably an hour, then sighed in defeat and decided to go to sleep.

Once I got upstairs, I realized that maybe the problem was that my C program was simply too slow. Also, it didn't help that I was trying to take the easy way out and not use any interrupt handling.

So now I am resigned to the fact that I will probably have to rewrite the program in assembly language and use one or more interrupt handlers to ensure that my timing is rock solid. I had wanted to avoid this because coding in C is so much faster, but I can't seem to tell the C compiler that I want every variable stored in a register instead of in memory. I came close... :)

Hopefully I will have some good news soon.

1 comment:

  1. I love the idea of being able to use unaltered copy-protected images! Go-Go-Matt_O!