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.

     With this logic, one would think you could write code for one computer and run it on all 6502's, but you can't.

The common denominator between all 6502 based computers is the processor, and that where it ends.

Sure, the machine language is the same, how it works with the computers hardware is different.  Commonalities, such as Zero page ($0000 - $00FF) and Processor stack ($0100 - 01FF) are mapped out in the memory because of the processor design, things are quite similar , but not the same.


     It seems like a good name, for a topic, but we won't be working in basic, to get a good understanding how the hardware is mapped to the memory we'll have a good look around at the Commodore memory map, looking at some obvious items that has immediate effect.  This will not be an instruction of assembly language, but an exploration of the memory mapped architecture.  Changes to the memory areas mapped to hardware have an immediate effect on the computer 

AREA [0286]  - Current color mode

With the monitor running, a command of M 0286 will bring up the values of memory area 0286 through 028D

Directly after .:0286 we see a HEX value of 01, it is because of this 01 that the color of everything written to the screen is White

With a simple move of the up arrow to the 1 in 01 you can change it to a 2, leaving you with 02, if you press RETURN, the memory area is updated and the immediate effect is seen.  Page 292 of the book breaks down color codes.   As you can see 01 is white, 02 is red

Note that once the value is changed, it stays that way, until it is changed again.  In this example we went to 07 (yellow) to 09 (brown) to 0A (lt red) and then exited with X.   the Basic ready prompt is still light red and will stay that way until someone or something changes that memory value again

So modifying 0286 is how text color is changed on the C64.  It just so happens to be the same for the VIC20. Mess with that value on a Commodore PET, and you won't be effecting text color, you will find yourself modifying a value in the #1Tape input buffer.  Modifying the same area on an Apple II will effect the GETLN Line input buffer.

Heres a good link for the Mapping of the C64  the section from today included below

From The Project 64 etext of the ~Mapping The Commodore 64 book~, typed
by David Holz , formatted to 71 columns and
somewhat proofed by Cris Berneburg.

646           $286           COLOR
Current Foreground Color for Text

The process of PRINTing a character to the screen consists of both
placing the screen code value for the character in screen memory and
placing a foreground color value in the corresponding location in
color RAM.  Whenever a character is PRINTed, the Operating System
fetches the value to be put in color RAM from this location.

The foreground color may be changed in a number of ways.  Pressing the
CTRL or Commodore logo key and numbers 1-8 at the same time will
change the value stored here, and thus the color being printed.
PRINTing the PETASCII equivalent character with the CHR$ command will
have the same effect.  But probably the easiest method is to POKE the
color value directly to this location.  The table below lists the
possible colors that may be produced, and shows how to produce them
using all three methods.

 0        Black     144    CTRL-1
 1        White       5    CTRL-2
 2        Red        28    CTRL-3
 3        Cyan      159    CTRL-4
 4        Purple    156    CTRL-5
 5        Green      30    CTRL-6
 6        Blue       31    CTRL-7
 7        Yellow    158    CTRL-8
 8        Orange    129    Logo-1
 9        Brown     149    Logo-2
10        Lt Red    150    Logo-3
11        Dark Gray 151    Logo-4
12        Med Gray  152    Logo-5
13        Lt Green  153    Logo-6
14        Lt Blue   154    Logo-7
15        Lt Gray   155    Logo-8



No comments:

Post a Comment