atomic_fungus (atomic_fungus) wrote,

#4488: There is no way for me to see if that's the error I made.

At least, I'm pretty sure there isn't.

See: back in the Stone Age, before Al Gore invented the Internet--1984-ish--I was trying to teach myself the intricacies of 6510 Assembler and (mostly) failing. To do really interesting and useful things on the C-64 you pretty much had to be able to code in assembly language (machine code) because the BASIC interpreter was very, very slow.

A friend of mine wanted to set up the function keys to change the screen and text colors, and I thought that would be a good use of the tutorial I'd just read on programming interrupt routines on the C-64. He wrote the bulk of the code (he was also learning machine code) and I worked on the "shoehorn this into the C-64's normal interrupt routine" part.

The basic process was this: you used a snippet of machine code to change the interrupt vector to point to your routine. You had to use machine code because you had to suspend the interrupt routine while changing the vector, and if the computer ran for more than a few clock cycles without interrupt services it would become unstable and crash; BASIC was right out.

Anyway, load registers with your pointer values, that pointed to the beginning of your code, turn off interrupts, reset the interrupt routine pointer, then turn interrupts back on. It took maybe five or six clock cycles (if that) to do the whole thing, and I basically copied the tutorial's methods for my program, so I know I was doing that part right.

The problem was, no matter what I did, the program simply would not work. Write the code, compile it, load the program (using the ,1 switch after the drive number to force it to load to the address we wanted it at) and then SYS 828 to run it.

Warm restart, blank screen, colors remained the same.

I wrote a machine code program which changed the screen colors as fast as possible, which worked; but when I added code to make it part of the interrupt routine, it bombed to a warm restart screen.

No matter what I did, neither version of the interrupt routine ever, ever worked, and after struggling with it over the course of several days I finally gave up and found something more entertaining to do.

That was thirty-one years ago.

This morning I was lazing around in bed, and started thinking about that program. It hit me then that if I had ended my program with the RTI--ReTurn from Interrupt--opcode, that would have led the computer to crash. Remember, it crashed if the interrupt routines were not run, and they wouldn't run if I'd used RTI instead of transferring interrupt processing to the routines in ROM. But I have trouble believing that I could have been stupid enough to have done that, particularly with the example I had in front of me of a properly-functioning routine.

The source code, handwritten on notebook paper, is long gone; of that I have absolutely no doubt whatsoever. The C-64 disks that once contained the digital files are probably coasters by now thanks to the tendency of magnetic domains to randomize with time.

My travails with machine code programming were what made me begin to suspect that computer programming might not be a good career choice for me. I could write code that did useful things, but every other program I wrote took as much time to debug as it did to write, and some programs did things that did not match my expectations and could not be fixed no matter what I tried. (One was a simple Apple ][ program which was supposed to move simple lines down a screen. It never worked, and I never figured out why.)

When I went to college and learned Pascal and C++, my programming improved considerably, but learning how to program in compiled languages just further convinced me that I'm not cut out for programming. My code worked, it did what was needed, but it was inelegant and bloaty.

Hardware is what I understand, and I understand it well enough that I was able to teach myself how to repair computers and printers, and do it as a professional on-site tech for years.

Still, there's no way for me to tell what mistake I made with that interrupt routine, 'way back in the Cretaceous, and since the C-64 is long obsolete I don't think it really matters. I guess that's how it goes.

  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.