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 >
Text File  |  2023-02-26  |  5KB  |  152 lines

  1.   Beginning ML Programming Continued!
  2.  
  3. Continuing from the last article by The
  4. Wild One, we will now go into the use 
  5. of the three different registers in 
  6. which he covered.. There are several 
  7. more in your computer but the A, X, and
  8. Y are by far the most often used and 
  9. easier to understand for beginning ML 
  10. programmers.. Throughout this article, 
  11. you will learn the use of some ML 
  12. instructions known as mnemonics..
  13. These allow us humans to easier relate 
  14. to ML programming than the way the 
  15. microprocessor would.. One of the most 
  16. common instructions you will be using 
  17. is LDA.. This simply means LoaD 
  18. Accumulator.. Here is an example..
  19.  
  20. LDA #$00
  21.  
  22. This command simply placed the vallue 0
  23. in the A register.. The # preceding the
  24. value tells the computer that you wish 
  25. to use the immediate mode of LDA.. This
  26. means that the actual value ($00) was 
  27. loaded into the Accumulator.. The same 
  28. thing can be accomplished from BASIC 
  29. like this..
  30.  
  31. POKE780,0
  32.  
  33. Location 780 is the storage area for 
  34. the A register.. The immediate mode 
  35. uses two bytes of computer memory.. One
  36. for the opcode and one for the 
  37. operand.. There is another addressing 
  38. mode which you may use LDA with.. That 
  39. is the absolute mode.. In this, you 
  40. instead load the Accumulator with the 
  41. contents of a memory location.. This 
  42. mode is specified by not including a # 
  43. in front of the operand..
  44.  
  45. LDA $FB
  46.  
  47. The contents of $FB (251 decimal) are
  48. loaded into A with this instruction.. 
  49. So, if $FB contained $80, A would then
  50. contain $80 as well after this command
  51. was executed.. Accomplishing this task 
  52. in BASIC would be as easy as this..
  53.  
  54. POKE780,PEEK(251)
  55.  
  56. The absolute mode uses up three bytes 
  57. of memory.. One for the opcode, and one
  58. each for the low and high bytes of the 
  59. address (if it was not in zero page as 
  60. in the example which would use only two
  61. bytes..) Now that you know how to load 
  62. A, let's put what you loaded into there
  63. to work.. We all know that location 
  64. 53280 holds the current color code of 
  65. the border and 53281 holds the color
  66. for the background, right? Using the 
  67. STA (STash Accumulator in) command, you
  68. place the contents of A wherever in 
  69. memory you wish.. See if you can see 
  70. what this short ML routine does..
  71.  
  72. LDA #$00
  73. STA $D020
  74. STA $D021
  75.  
  76. It may seem a little tricky at first 
  77. seeing as how I used hexadecimal 
  78. numbers (symbolized by the $ sign) for 
  79. the memory locations.. But all it does 
  80. is put a 0 in both location 53280 and 
  81. 53281.. Effectively changing the screen
  82. black.. If you wished to do the same in
  83. BASIC you would only need to POKE both 
  84. locations with a 0.. Is this easy or 
  85. what? You should probably be getting a 
  86. VERY basic idea of how ML works by 
  87. these few examples.. Now, to cut this
  88. already overly long article short, 
  89. here's a few new ones you should be 
  90. able to figure out which I will quickly
  91. define for you..
  92.  
  93. LDA #$01
  94. STA $FC
  95. LDX #$80
  96. LDY $FC
  97. STX $28A
  98. STY $286
  99.  
  100. The first two you already know.. It 
  101. puts $01 into A and then into location 
  102. 252.. Then you come across a new 
  103. command.. LDX means LoaD X.. The 
  104. example puts the value $80 (in decimal 
  105. that's 128) into X.. You should 
  106. (hopefully) be able to figure out what 
  107. LDY means.. That command puts the 
  108. contents of location $FC (252) into Y..
  109. Which was $01 from the above STA 
  110. command.. After that, STX (STash X in) 
  111. puts the contents of X into location 
  112. $28A.. Then finally, we use STY to 
  113. store what we had in Y ($01) into 
  114. location $286 (646).. Now, if you 
  115. examine all these closely you'll 
  116. realize you actually modified your 
  117. computer in several ways by using these
  118. commands.. Let's assume our screen is 
  119. still black from the example of the STA
  120. commands above.. So, after storing Y 
  121. with $01 by stashing it into $FC with
  122. the STA command, you change the color 
  123. of the screen character.. Remember, 
  124. POKEing location 646 will do that in 
  125. BASIC.. You also loaded X with $80 and 
  126. then stashed it into $28A (650).. This
  127. location determines whether or not all 
  128. the keys you press repeat or not.. A 
  129. $80 or 128 here will make it so that 
  130. that happens.. Now after all this, you 
  131. have a black screen with a white cursor
  132. that repeatedly prints everything you 
  133. press.. Neat, huh? This is just a VERY 
  134. small sample of what you can do with 
  135. machine language! The applications are 
  136. endless and it is much more efficient 
  137. and faster than BASIC which could have 
  138. accomplished the same thing if you so 
  139. chose.. Hopefully, ML is not as 
  140. mysterious to you who thought it was 
  141. some foreign language before this quick
  142. tutorial.. It is difficult at first, 
  143. but it becomes as easy as BASIC and 
  144. better with practice.. So, until the 
  145. next newsletter, see what other things 
  146. you can do with these kinds of 
  147. instructions.. You'll learn even more 
  148. next time, though, there's a LOT to 
  149. cover still..
  150.  
  151.                    Alister Fiend
  152.