You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
In the first of a new<br />
series, Eric Doyle<br />
introduces you to the<br />
secret of your<br />
Commodore's<br />
memory.<br />
WE ALL TAKE THE CHIPS INside<br />
our computers for granted<br />
but a greater understanding of<br />
them can lead to better<br />
programs. Over the next few<br />
months I hope to clarify the Another difference is that<br />
function of each chip and to ROM is a permanent, nonreveal<br />
the inner workings and volatile store which cannot be<br />
hidden secrets of the Comma- erased by turning the power on<br />
dare range of computers: the and off but RAM is volatile and<br />
Vic 20, C64, C-16, Plus/4 and its contents disappear when<br />
C126. t h e computer is switched off.<br />
The heart of any computer ROM is where the Basic<br />
is the central processor and the operating system is stored and<br />
most common application of at power up it reserves certain<br />
the computer is to run Basic parts of RAM for storing the<br />
programs so this is where our transient values generated as its<br />
Odyssey will begin, r o u t i n e s are executed.<br />
The microprocessor in<br />
Commodore micros is a one of<br />
several derivatives of the<br />
Motorola 6500 series microchip.<br />
This processor is the<br />
number cruncher inside which<br />
are the registers that assist in all<br />
of the computer's mathematical<br />
operations. Diagram 1<br />
shows the basic architecture of<br />
all 6500 range microprocessors.<br />
As far as the processor is<br />
concerned the whole of the<br />
computer memory is an extension<br />
of itself from which<br />
numerical values can be loaded<br />
(read) or sent (written).<br />
A good way of imagining<br />
memory is as a large, pigeon<br />
hole internal mailing system.<br />
Each box represents a byte of<br />
memory and can contain a<br />
value from zero to 255. Don't<br />
worry if you don't know how<br />
computers deal with numbers<br />
larger than 255, all will become<br />
clear later.<br />
Memory comes in two<br />
varieties Read Only Memory<br />
(ROM) and Random Access<br />
Memory (RAM). As the name<br />
implies ROM can only be read<br />
from but RAM can either be<br />
read from or written to if it is<br />
necessary to change its value.<br />
For example variables defined<br />
by a Basic program must be<br />
stored in RAM for two reasons.<br />
Firstly, because it must have a<br />
value written to it to start with<br />
and, secondly, because that<br />
value may change later on in<br />
the program.<br />
Processing<br />
Load and run Listing 1 to see<br />
how the processor operates.<br />
The program counter tells<br />
the processor where the<br />
current instruction is located in<br />
RAM/ROM memory. When<br />
commanded to execute a piece<br />
of machine code, the current<br />
value of the program counter is<br />
stored in a special reserved<br />
PRO6RAM: LISTING 1<br />
0<br />
180 L=0-0/16;60SUB200<br />
10 0013:60SU8360<br />
190 RETURN<br />
20 LLsPEEX(S+1)4PEEK(S+2)125 200 IF 09 THEN VS=CHRS(550.<br />
6<br />
)+VS;6010220<br />
30 LC20<br />
210 VS.RIGHTS(STRICL1pLEN(ST<br />
40 LN2PEEK(S+3)+PEEK(S+4)125 RS(L))-1)0$<br />
61PRINT"(CLR)(WHT)LIMEN;LN:" 220 RETURN<br />
(VW'<br />
230 LL=PEEK(S+LC+1)+PEEK(S+L<br />
50 LO.LNIGOSUB280:1FLCO0T Cf2)$256<br />
HEN50<br />
240 FLINO:IFLL.OTHEN LC=0:PRI<br />
60 A:S400<br />
NTNICYN)00 1<br />
70 PRINT<br />
1:0010 250 PRINT:00110:001PEEK(S+LCi.<br />
6EASE<br />
WAIT'<br />
270 3)+PEEK(S+LC+4)$256:IFLN=40T<br />
(YEL) 80 PIA+1:1FPEEK(A)21ANDPEEK( HENLC80:60T0270<br />
(DOWN A4.1)1.143THEN100<br />
260 PRINTI(DOWN)(WHT)LINPO.<br />
1(DOW 90 SOT080<br />
N)PL 100 PRINT"(UP) PRESS °<br />
N;a(CYN)°<br />
270 RETURN<br />
280 WEEK(PLC):GOSUB170<br />
110 6ET AS:IF A$O" THEN11 290 IF 00.2 AND FL.0 THEN PR<br />
0<br />
INTs(YEL)';<br />
120 SA-4<br />
300 IF CO.4 AND FL.0 THEN PR<br />
130 LL.PEEK(S4.1).0PEEK(S4.2)12 INTICLDLUPpFL.1<br />
56<br />
310 IF CO.CN THEN PRINT:C0=0<br />
140 LN=PEEK(64.3)+PEEK(S+4)12 320 IF FL.1 AND D>127 AND D<<br />
56:PRINT*(CLR)(WHT)LINE";LN; 203 THEN PRINP(GRN)<br />
':00.0:FL:0<br />
1LU)';:60T0340<br />
150 LO:LC+1:60SUB280:IFL000 VSe 330 PRINT (LB Vs";<br />
THEN150<br />
340 CORC04.1:IF S.H.C2LL-1 THE<br />
160 PRINT<br />
N 60SUB230<br />
:END 1<br />
350 RETURN<br />
170 00(LBL YS.":L=D AND 15:60SUD20 360 PRINT<br />
U)':LI6T<br />
1<br />
440—<br />
(OLR)<br />
•IO (DOWN)<br />
(DOWN)<br />
(<br />
area of RAM memory (the<br />
processor stack area) and the<br />
internal stack pointer is adjusted<br />
to point to the next free<br />
location in the stack. The start<br />
address of the new machine<br />
code routine is then placed<br />
into the counter. This value is<br />
then loaded into the address<br />
buffer which directs the data<br />
bus to the correct location.<br />
The data bus copies the<br />
information found in the given<br />
location and carries this back to<br />
the processor which is expecting<br />
a machine code operator.<br />
When this is evaluated in the<br />
instruction decoder it determines<br />
whether an operand or<br />
two will follow. Depending on<br />
the type of operator, any<br />
operands are evaluated and<br />
stored in the X or Y register or<br />
in the accumulator,<br />
If the operator is a finite<br />
address the address buffer is<br />
given this value and the data<br />
bus reacts accordingly. If the<br />
value is an offset address, the<br />
finite address has the value of<br />
the X or Y register added to it<br />
and this value is passed to the<br />
address buffer.<br />
All mathematical work is<br />
performed in the ALL,' which<br />
can access all of the registers<br />
which merely act as passive<br />
stores for transient values.<br />
The instruction decoder<br />
determines whether the data<br />
bus is reading or writing its<br />
encoded information and<br />
which internal register<br />
provides or accepts the<br />
information.<br />
When an RTS command is<br />
detected the last value to be<br />
stored on the stack is read into<br />
the program counter and the<br />
processor continues from<br />
where it was before it was<br />
asked to execute the routine.<br />
I have said that the processor<br />
only responds to machine<br />
code routines so how does it<br />
respond to Basic?