Thursday, December 18, 2014

Understanding 6502 assembly on the Commodore 64 - (25) Address modes

We've steered of course long enough.  Its time to get back to grass roots.  One of these days I will get all of these chapters in order because addressing modes should definitely be in the first 10.

Click here for Chapter 25

Sunday, December 14, 2014

Understanding 6502 assembly on the Commodore 64 - (24) A better way with NMI

     So far, we've found a less than ideal way to implement our interrupt. So much so that I wanted to simply remove the chapter, but decided to keep it so we can make a comparison.  Lets look at a better way to do this.

Click here for Chapter 24  

Thursday, December 4, 2014

Understanding 6502 assembly on the Commodore 64 - (23) The Ubiquitous Interrupt Request

     Conceptually, the interrupt at its core is easy to understand, yet rarely understood.   Before discussing an interrupt on the computer we must understand being interrupted in general.  To make this apparent we should assume that we are being interrupted from something we're doing or not doing.  We could consider not doing, the act of doing something, which is doing nothing.   Either way,  the interrupt comes as a distraction to what we were doing before we were interrupted.

Click here for Chapter 23

Understanding 6502 assembly on the Commodore 64 - (22) Output Display alternative

     Before we go any further in our program,  lets have a bit more fun.  Though we're still hanging off of our housekeeping interrupt, we're using the screen output addresses to display our code.  It's been effective, but a bit boring.   We can use what we learned in creating sprites to spruce things up a bit.

Click here for Chapter 22

Wednesday, December 3, 2014

Understanding 6502 assembly on the Commodore 64 - (21) Optimizing our interrupt code

     In the last chapter, we modified our code to run our binary converter 60 times per second using the system interrupt, bypassing the address of the usual housekeeping code with our own.  We then Jumped back to the housekeeping code so it could proceed.  We didn't cause an interrupt, we just added our code in as part of the normal system interrupt  But In doing so we ran into a bit of a problem.  

Click here for Chapter 21

Tuesday, December 2, 2014

Understanding 6502 assembly on the Commodore 64 - (20) May I Interrupt?

     In the last few chapters we've had to get through a lot of dry, but necessary stuff.  I figured since this is chapter 20, well do something fun.  Just about every 60th of a second, everything we do it put on hold for the computer to run its own housekeeping chores.  Cursor blink, keyboard input check, screen refresh, that sort of stuff.  To the user it is transparent, as if the 6502 is multitasking and running code in the background.  Arguably it is, but it isn't.  But it is the stuff of genius how this is accomplished.

Click here for Chapter 20

Monday, December 1, 2014

Understanding 6502 assembly on the Commodore 64 - (19) The Truth of the matter

If you haven't done much programming in the past, you will probably still remember Learning Truth tables in mathematics, wondering why you would ever need to know such a thing.  Well,   question answered.   Logical operations are a fundamental part of digital electronics.  The 6502 is no exception.  Before breaking into Mathematics,  we will first learn logical operations.

Sunday, November 30, 2014

Understanding 6502 assembly on the Commodore 64 - (18) Status flags NV-BDIZC

     The execution of Instructions in the 6502 is only half of the story.  The 6502 and its machine code is a running example of cause and effect.  We think of machine code as being at such low level that nothing is done without explicitly instructing it, however, the processor is much more dynamic than is initially apparent on the surface.

Click here for Chapter 18

Saturday, November 29, 2014

Understanding 6502 assembly on the Commodore 64 - (17) Stack and CPU Register in depth

     We need to stop for a minute with our programming, and discuss the registers that the 6502 uses.  We could then continue where we left off, perhaps, EXACTLY where we left off, having personally gained new information about the processor functionality, and continue on our merry way.  In fact, we could state that we are INTERRUPTING our normally scheduled programming to bring you this important information, and then upon completion return you to where you were.

Click here for Chapter 17

Wednesday, November 26, 2014

Disk ][ drive - Clean and Adjustment

     With the Commodore 1541 drives done, it was time to test out the Apple II disk drives.  The drive S6D2 was hardly every used and was at perfect speed and almost perfect alignment.  S6D1 was a different story, that was the workhorse.


See how to do it here!

Tuesday, November 25, 2014

Understanding 6502 assembly on the Commodore 64 - (16) Input and Data Manipulation

     If you haven't guessed by now,  Assembly is the ultimate strategy game.  With endless possibilities to achieve the desired result, we have enjoyed the fact that up until now, we have required very little data manipulation or error checking.  Our last program used a hardcoded value in a specific memory location to execute a task.  It was in fact, part of the program itself.  Sure you could put in whatever you wanted, but garbage in, garbage out. In fact, the only user interaction was running the program itself.

Click here for Chapter 16

Understanding 6502 assembly on the Commodore 64 - (15) The Zero Page

Many people learning 6502 will often hear about the mystical and revered Zero Page area of memory, and all of the magical things it can do.  Well, there is no trickery behind it. The concept is actually quite easy to understand. We can get through this in a single post.

Click here for Chapter 15

Monday, November 24, 2014

Understanding 6502 assembly on the Commodore 64 - (14) Space and cycle optimization

With the C64 and other 8 bit computers, limited in speed and storage space, it important to optimize code to be a small and as fast as possible.  While our simple binary conversion requires neither, its good to see how much we can reduce the size of the code and reduce the amount of cycles required to execute it.  I did not include every single possible optimization the world has to offer, so do not contact me with your idea.  This is primarily about optimizing there flow of the program, and not about   optimization through ways which beginning 6502 programmers might be confused.  

Click here for Chapter 14

Saturday, November 22, 2014

Understanding 6502 assembly on the Commodore 64 - (13) Watching the 6502 Think

I wrote a small program today, It takes a HEX value and returns the binary value onto the screen, or any other contiguous memory location.  I kept it simple, and while simple, still highly effective and adaptable.  What is more interesting though, is stepping through each process as the processor works towards the end of the program.  Thats what were going to do.  This is very hardware neutral code, Changing OURHEXNUM,TESTBYTE, and BIT7 to your preferred memory area will allow this to run on any 6502 based computer.

Click here for Chapter 13

Friday, November 21, 2014

Understanding 6502 assembly on the Commodore 64 - (12) Recap and Beginning Registers

Throughout our program, we have used relatively easy math to allow us to achieve our goals, this has primarily been accomplished with four operations. INX, INY, DEX, DEY.  This is the simplest form of addition and subtraction on the 6502, and its easy to understand.  You might have noticed as well that so far we have not only avoided writing code to NMI's or IRQ's, we have shown complete disregard for our status registers, a most important part of our processor.

Click here for Chapter 12

Thursday, November 20, 2014

Understanding 6502 assembly on the Commodore 64 - (11) Sprite Movement and Collision

By now you've realized this series is not a quick and dirty instruction for cutting and pasting code allowing for instant gratification for displaying cool demos and raster effects on your screen.  There are a great many pages which demonstrate this.  This is about 6502 assembly, and the computers memory mapped archetecture.

Click here for Chapter 11

Understanding 6502 assembly on the Commodore 64 - (10) Disappearing, Reappearing BASIC

Every time we test our program, we are in fact using BASIC to facilitate the initialization.  By calling SYS 49152, BASIC is handing over control to the machine language program, which we have loaded into memory at 49152 (HEX $C000).  At this point BASIC is no longer useful to us.

Click here for Chapter 10

Wednesday, November 19, 2014

Understanding 6502 assembly on the Commodore 64 - (9) The Hexadecimal Conundrum

Its time, now to take a step back and look at some very important things in out last program.  It would seem that the simplicity of this particular program allowed us to overlook what is an inevitable coding issue.  This of course, was done intentionally, as I've stated, to make the easiest to read program, whist sacrificing other things in return.

Click here for Chapter 9

Understanding 6502 assembly on the Commodore 64 - (8) Inputs in Assembly

Lets continue with our wonderful Commodore logo, we will use the code from the last chapters but we will stop after the creation of the sprite.  Ill include the code below to plug into Relaunch64.  By taking advantage of some more kernel functions, we can make the program a bit more interactive.

Click here for Chapter 8

Tuesday, November 18, 2014

Understanding 6502 assembly on the Commodore 64 - (7) The Assembler and Machine code Compiling

So what happened when the compiler ran??  It took our assembly code and converted it into machine code and stored it in a prg File that the commodore could read.  The commodore loaded the file, where it was instructed to, starting at C000.

Lets see what the code looks like, waiting to be executed

Click here for Chapter 7

Understanding 6502 assembly on the Commodore 64 - (6) Our instructions to assembly

In chapter 3 we listed all of the instructions we had done with regard to memory modification to achieve or goal.  Today we will convert those instructions into assembly and then onward to machine code where the C64 can understand it and execute the tasks.

Click here for Chapter 6

Understanding 6502 assembly on the Commodore 64 - (5) DEVTOOLS

In is post we briefly move away from the code work to set up our development tools.

Click here for Chapter 5

Understanding 6502 assembly on the Commodore 64 - (4) RECAP AND DEVTOOLS INTRO

There is no greater method, to study the inner workings of the the C64 than that which was demonstrated in the previous posts.  The ability to modify memory addresses in real time simply cannot be matched.

We watched how, not a computer program, but a human being executed a series of instructions on a computer, achieved a desired output.  Lets look at our instructions in order.

Click here for Chapter 4

Monday, November 17, 2014

Understanding 6502 assembly on the Commodore 64 - (3) Messing with Memory

Memory areas $0400 $07E7 are mapped to the screen memory, starting at the top left of the screen to the bottom right.  To keep the demonstration out of the way of the working area, we'll work down at memory address $0708 which is in the middle towards the bottom.

Click here for Chapter 3

Friday, November 14, 2014

Understanding 6502 assembly on the Commodore 64 - (2) Memory Mapped Hardware

     Theres a million different different resources for learning 6502 Assembly, but what does it do? Any why?  There is a logical order for learning this, Its not like learning C++ or Perl or PHP.

     A 6502 in a Commodore is the same as in an Apple II is the same as in an Atari 800, etc etc.   Assuming that these units did not have some sort of upgrade, such as the enhancement kit of the apple //e.


Click here for Chapter 2

Thursday, November 13, 2014

Understanding 6502 assembly on the Commodore 64 - (1) Intro

      With all computers,  there are only two catagories that a user falls into at any given time.  Writing software and using software.  Really, not much has changed with regard to that even today.

    Having only 4000+ transistors means programming the 6502 with regard to speed and available memory means Assembly is an obvious choice to develop software. The Commodore is a great computer to learn 6502 machine code.  Between all of my 6502 computers, my choice is the C64

Click here for Chapter 1


Apple ][GS Battery Swap

I got lucky on this one,   the computer spent about 20 years in an attic in Georgia, it had the old style battery soldered on the board that thankfully didn't rupture.

Dont purchase expensive replacement kits on Ebay.   This should cost you less than 10$

This was all available at Radio Shack.  3.6v Lithium battery and a AA holder

Here the old battery is still installed, luckily it didn't leak (date code August 1988)

Soldered new wires in and mounted the holder off to the side under the power supply

Back in business

SD2IEC What you need to know BEFORE you buy!

     I was so excited when after two years a new software update for the SD2IEC came out.   Most importantly because it purportedly included multitask support without having the write the swap list file for each one.   As of Oct 28 SD2IEC.DE now lists the current binary as 1.0.0alpha0.84.

But you won't find me upgrading........

     Why do you ask? Because I had the misfortune of buying my SD2IEC for a less than reputable dealer on eBay.  As a value added convenience he decided not to burden me with a boot loader.  

So Instead of simply putting the new BIN onto the SD card and upgrading, I will now have to purchase hardware to write to the chip.

But wait, theres more.    His design left no connector to write to the chip , I imagine he just programmes them and shoves them in the box.

So now Ill have to get this going on a breadboard and buy parts off eBay to do a software upgrade

when I raised the issue with despegatop about not upgrading, he wrote


Put the new file on the root directory of the sd card.

In any case, if you have any issue you can send back the device for reprogramming.

Best regards

Then I pressed him on the lack of a boot loader

I checked with other people in the commodore forums. You know this will not upgrade becuase you have not been adding the bootloader. Will you be paying the round trip shipping for me to send my device back to spain because you for got to do something correctly?

 and he responded with

I currently make non-upgradeable units via sd card because it is much more reliable from full accidental erasure.

I can only pay the return postage (from Spain to USA)

Best regards

So, If you feel like ordering from despegatop you had better be sure he includes it before buying

This is an example currently for sale with NO boot loader

Easy Tape to Disk conversion using Vice, AKA T64 to D64

You do not need any other software beyond Vice and its included application,  c1541, to convert tape to disk. Actually, you don't even need Vice.   All of this can be done with C1541 which is included with Vice

Step 1:   Create a blank disk in Vice

The Save As is the file you will be creating, the Name is what the commodore would see as the disk name.  The linux version and some other versions may ask for a value for index, make it 00 (zero zero).   See Step 9 for creating images in c1541 WITHOUT vice

Step 2: Load C1541

Step 3: Mount the new d64 file in C1541 with attach filename.d64, then type list to view it

Step 4: Dump a tape to the d64 image with tape filename.t64, then list to view it

Step 5: Dump another (space permitting), then list

Step 6: It would seem moon patrols image shows the file name to be file.prg which won't be very useful.  So lets change it using rename oldfilename newfilename

Step 7: Maybe you added a file and didn't wish to have it in your d64 image.... you can delete it with delete filename

Step 8: Maybe you don't want the disk called TAPETODISK on the C64 and want to rename the disk itself to favetapes.    use name newname,00

Step 9: Truth be told, you do not even need vice to create disks, you can just use C1541 to to this.  Lets create a disk image called sampledisk with an index of 00 using a real file name called sample.d64 , format it and mount it in drive 8 under c1541. Then run list

sample.d64 will be created in the current directory that c1541 was executed

type quit, and you are finished, attach the d64 to your emulator or image it to disk or sd2iec or whatever

Tuesday, November 11, 2014

1541 testing , heat sink vs, no heat sink

I conducted 1541 heat testing today, heatsink vs no heatsink. No heatsink measured at the middle of each IC, and with heatsink the avg of both sides where the heatsink meets the IC, the difference is staggering. Naturally there will be people who will say that somehow this was measured wrong, thats fine. Ive found that each chip between the middle point and 25% offset to be no more than 1 degree off. Measured off the same points over the same intervals, its clear the heat must be going somewhere. If I were wrong, then the heatsink would be asking like an insulator, increasing the temperature of the chip

With heatsinks. IC#5 would probably benefit if the 2 heatsinks were offset about 4mm to the left from what is shown in the photo