home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Commodore 64 Scene Diskmags Assortment
/
DMBBS_Bi-Monthly_Magazine_5_1990-06-01_Sledge.d64
/
8.3
< prev
next >
Wrap
Text File
|
2023-02-26
|
5KB
|
152 lines
Beginning ML Programming Continued!
Continuing from the last article by The
Wild One, we will now go into the use
of the three different registers in
which he covered.. There are several
more in your computer but the A, X, and
Y are by far the most often used and
easier to understand for beginning ML
programmers.. Throughout this article,
you will learn the use of some ML
instructions known as mnemonics..
These allow us humans to easier relate
to ML programming than the way the
microprocessor would.. One of the most
common instructions you will be using
is LDA.. This simply means LoaD
Accumulator.. Here is an example..
LDA #$00
This command simply placed the vallue 0
in the A register.. The # preceding the
value tells the computer that you wish
to use the immediate mode of LDA.. This
means that the actual value ($00) was
loaded into the Accumulator.. The same
thing can be accomplished from BASIC
like this..
POKE780,0
Location 780 is the storage area for
the A register.. The immediate mode
uses two bytes of computer memory.. One
for the opcode and one for the
operand.. There is another addressing
mode which you may use LDA with.. That
is the absolute mode.. In this, you
instead load the Accumulator with the
contents of a memory location.. This
mode is specified by not including a #
in front of the operand..
LDA $FB
The contents of $FB (251 decimal) are
loaded into A with this instruction..
So, if $FB contained $80, A would then
contain $80 as well after this command
was executed.. Accomplishing this task
in BASIC would be as easy as this..
POKE780,PEEK(251)
The absolute mode uses up three bytes
of memory.. One for the opcode, and one
each for the low and high bytes of the
address (if it was not in zero page as
in the example which would use only two
bytes..) Now that you know how to load
A, let's put what you loaded into there
to work.. We all know that location
53280 holds the current color code of
the border and 53281 holds the color
for the background, right? Using the
STA (STash Accumulator in) command, you
place the contents of A wherever in
memory you wish.. See if you can see
what this short ML routine does..
LDA #$00
STA $D020
STA $D021
It may seem a little tricky at first
seeing as how I used hexadecimal
numbers (symbolized by the $ sign) for
the memory locations.. But all it does
is put a 0 in both location 53280 and
53281.. Effectively changing the screen
black.. If you wished to do the same in
BASIC you would only need to POKE both
locations with a 0.. Is this easy or
what? You should probably be getting a
VERY basic idea of how ML works by
these few examples.. Now, to cut this
already overly long article short,
here's a few new ones you should be
able to figure out which I will quickly
define for you..
LDA #$01
STA $FC
LDX #$80
LDY $FC
STX $28A
STY $286
The first two you already know.. It
puts $01 into A and then into location
252.. Then you come across a new
command.. LDX means LoaD X.. The
example puts the value $80 (in decimal
that's 128) into X.. You should
(hopefully) be able to figure out what
LDY means.. That command puts the
contents of location $FC (252) into Y..
Which was $01 from the above STA
command.. After that, STX (STash X in)
puts the contents of X into location
$28A.. Then finally, we use STY to
store what we had in Y ($01) into
location $286 (646).. Now, if you
examine all these closely you'll
realize you actually modified your
computer in several ways by using these
commands.. Let's assume our screen is
still black from the example of the STA
commands above.. So, after storing Y
with $01 by stashing it into $FC with
the STA command, you change the color
of the screen character.. Remember,
POKEing location 646 will do that in
BASIC.. You also loaded X with $80 and
then stashed it into $28A (650).. This
location determines whether or not all
the keys you press repeat or not.. A
$80 or 128 here will make it so that
that happens.. Now after all this, you
have a black screen with a white cursor
that repeatedly prints everything you
press.. Neat, huh? This is just a VERY
small sample of what you can do with
machine language! The applications are
endless and it is much more efficient
and faster than BASIC which could have
accomplished the same thing if you so
chose.. Hopefully, ML is not as
mysterious to you who thought it was
some foreign language before this quick
tutorial.. It is difficult at first,
but it becomes as easy as BASIC and
better with practice.. So, until the
next newsletter, see what other things
you can do with these kinds of
instructions.. You'll learn even more
next time, though, there's a LOT to
cover still..
Alister Fiend