********* Welcome to Project 64! The goal of Project 64 is to preserve Commodore 64 related documents in electronic text format that might otherwise cease to exist with the rapid advancement of computer technology and declining interest in 8- bit computers on the part of the general population. If you would like to help by converting C64 related hardcopy documents to electronic texts please contact the manager of Project 64, Cris Berneburg, at 74171.2136@compuserve.com. Extensive efforts were made to preserve the contents of the original document. However, certain portions, such as diagrams, program listings, and indexes may have been either altered or sacrificed due to the limitations of plain vanilla text. Diagrams may have been eliminated where ASCII-art was not feasible. Program listings may be missing display codes where substitutions were not possible. Tables of contents and indexes may have been changed from page number references to section number references. Please accept our apologies for these limitations, alterations, and possible omissions. Document names are limited to the 8.3 file convention of DOS. The first characters of the file name are an abbreviation of the original document name. The version number of the etext follows next. After that a letter may appear to indicate the particular source of the document. Finally, the document is given a .TXT extension. The author(s) of the original document and members of Project 64 make no representations about the accuracy or suitability of this material for any purpose. This etext is provided "as-is". Please refer to the warantee of the original document, if any, that may included in this etext. No other warantees, express or implied, are made to you as to the etext or any medium it may be on. Neither the author(s) nor the members of Project 64 will assume liability for damages either from the direct or indirect use of this etext or from the distribution of or modification to this etext. ********* The Project 64 etext for ML Programming articles #1, converted by anonymous. This etext was created by concatenating several documents into one. All of the included documents were retrieved from the Headgap BBS, sysop Bob Nunn, telnet://bbs.headgap.com:1474 login: guest, password: guest. Wildy's Corner! (71 - ML Beginner). Beginning ML Programming Continued! (71 - ML Beginner 2). ML110.TXT, July 1996, etext #64. ********* The Project 64 etext of Wildy's Corner! (71 - ML Beginner). ********* Wildy's Corner! In the following issues I am going to use this as a ML For Beginners course. By the time you finish it, you will have enough knowledge to do almost anything you want in ML. Including some rudimentary special effects as used in software pirate's demos. For this month we are going to go over the most basic commands in ML, and I will show you how to use these to write your first ML routine. Although most people view ML as the 'complex' language, it is really much simpler than BASIC. It is just that you need a number of simple commands to equal one command from a high-level language such as BASIC. First we will learn about the most important register in ML-the Accumulator. Different ML instructions allow you to copy the accumulator to a memory location and vice versa, modify its contents, and other useful tasks. This may not seem like much but this is where 50% of a program is accomplished. In addition, the accumulator is the only register that has math instructions. Now we will learn our first ML instruction. LDA. You may have guessed it stands for LoaD the Accumulator and is arguably the most used of all commands. Putting a '#' after LDA tells the computer that you want to LoaD the Accumulator with the value after it. A '$' following the LDA simply tells the computer that the number following is in hexadecimal form. (For more info on HEX see the preceding file.) With this knowledge you should know that: LDA #$05 tells the computer to LoaD the Accumulator with $05. Make sense? Good. This is very simple to grasp but is required to perform many things. Our next command is STA. It stands for STore the Accumulator. This command takes the value in the accumulator and transfers it to to any memory location you wish. Before we can write our first routine we need to know one more command. BRK. It is the BReaK command and is needed because in ML, if there is no BRK at the end-it will just lock up. Now we can write our first routine. It is very simple and changes the screen color to Cyan. To type it in a ML monitor you need to follow this format. .A 1400 LDA #$03 The .A tells it that this is an accumulator instruction. Afterwords, the monitor will automatically number and place the correct beginning on the lines. .A 1402 STA $D020 $D020 is the equivelant to 53280 in decimal. Last but not least... .A 1404 BRK Now press return until you are on a clean line and type G 1400. Bingo! If you did everything right it will change your screen to Cyan. Congratulations. You have now created you first program. Play around with those commands and see how much else you can accomplish with that little bit of info. Unfortunately I was in a bind for time this issue so it is semi small, but next issue I will have a immense column to help you further into the world of ML. As always, if you have questions or comments on this or any other articles-contact me through Digital Fantasia. 301+553+0001! Later! TWO! ********* End of Wildy's Corner! (71 - ML Beginner). ********* The Project 64 etext of Beginning ML Programming Continued! (71 - ML Beginner 2). ********* 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.. POKE 780,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.. POKE 780,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 ********* End of Beginning ML Programming Continued! (71 - ML Beginner 2). ********* The end of the Project 64 etext for ML Programming #1. *********