<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.softalkapple.com"  xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>The Softalk Apple Project - Roger Wagner</title>
 <link>http://www.softalkapple.com/tags/roger-wagner</link>
 <description></description>
 <language>en</language>
<item>
 <title>Assembly Lines: The Complete Book</title>
 <link>http://www.softalkapple.com/blogs/assembly-lines-complete-book</link>
 <description>&lt;div class=&quot;field field-name-field-image field-type-image field-label-hidden view-mode-rss&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;figure class=&quot;clearfix field-item even&quot;&gt;&lt;a href=&quot;http://www.softalkapple.com/sites/default/files/ALCover%20small.jpg&quot;&gt;&lt;img typeof=&quot;foaf:Image&quot; class=&quot;image-style-large&quot; src=&quot;http://www.softalkapple.com/sites/default/files/styles/large/public/ALCover%20small.jpg?itok=6MUi3A9n&quot; width=&quot;265&quot; height=&quot;400&quot; alt=&quot;Assembly Lines: The Complete Book cover&quot; title=&quot;Assembly Lines: The Complete Book&quot; /&gt;&lt;/a&gt;&lt;/figure&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-field-tags field-type-taxonomy-term-reference field-label-hidden view-mode-rss&quot;&gt;&lt;ul class=&quot;field-items&quot;&gt;&lt;li class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/tags/reprint&quot; typeof=&quot;skos:Concept&quot; property=&quot;rdfs:label skos:prefLabel&quot; datatype=&quot;&quot;&gt;Reprint&lt;/a&gt;&lt;/li&gt;&lt;li class=&quot;field-item odd&quot;&gt;&lt;a href=&quot;/tags/programming&quot; typeof=&quot;skos:Concept&quot; property=&quot;rdfs:label skos:prefLabel&quot; datatype=&quot;&quot;&gt;Programming&lt;/a&gt;&lt;/li&gt;&lt;li class=&quot;field-item even&quot;&gt;&lt;a href=&quot;/tags/roger-wagner&quot; typeof=&quot;skos:Concept&quot; property=&quot;rdfs:label skos:prefLabel&quot; datatype=&quot;&quot;&gt;Roger Wagner&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-body field-type-text-with-summary field-label-hidden view-mode-rss&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot; property=&quot;content:encoded&quot;&gt;&lt;p&gt;I am very excited to announce that Assembly Lines: The Complete Book is now available as a &lt;a href=&quot;http://www.lulu.com/shop/roger-wagner/assembly-lines-the-complete-book/hardcover/product-21959093.html&quot;&gt;hardcover from Lulu press&lt;/a&gt;. Roger Wagner’s Assembly Lines articles originally appeared in Softalk magazine from October 1980 to June 1983. The first fifteen articles were reprinted in 1982 in &lt;a href=&quot;https://openlibrary.org/books/OL8356855M/Assembly_Lines&quot;&gt;Assembly Lines: The Book&lt;/a&gt;. Now, for the first time, all thirty-three articles are available in one complete volume. This edition also contains all of the appendices from the original book as well as new appendices on the 65C02, zero-page memory usage, and a beginner’s guide to using the Merlin Assembler. The book is designed for students of all ages: the nostalgic programmer enjoying the retro revolution, the newcomer interested in learning low-level assembly coding, or the embedded systems developer using the latest 65C02 chips from Western Design Center.&lt;/p&gt;
&lt;p&gt;The book will be available in a few weeks from Amazon and other online retailers. I am currently working on an eBook version, which I hope to have finished in early 2015.&lt;/p&gt;
&lt;p&gt;You can download disk images of all of the assembly-language programs from the &lt;a href=&quot;ftp://ftp.apple.asimov.net//pub/apple_II/images/programming/assembler/&quot;&gt;Asimov ftp site&lt;/a&gt; in the pub/apple_II/images/programming/assembler directory:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;AssemblyLinesWagnerDOS1.DSK contains DOS versions for chapters 1-17&lt;/li&gt;
&lt;li&gt;AssemblyLinesWagnerDOS2.DSK contains DOS versions for chapters 18-30&lt;/li&gt;
&lt;li&gt;AssemblyLinesWagnerProDOS1.DSK contains ProDOS versions for chapters 1-17&lt;/li&gt;
&lt;li&gt;AssemblyLinesWagnerProDOS2.DSK contains ProDOS versions for chapters 18-30&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;Note that a few of the programs (in the DOS chapter) will only work in DOS, not ProDOS. &lt;/p&gt;
&lt;p&gt;To create your own programs, you can download a copy of the Merlin assembler from the same directory: &lt;/p&gt;
&lt;ul&gt;&lt;li&gt;merlin/Merlin-8 v2.48 (DOS 3.3).dsk &lt;/li&gt;
&lt;li&gt;merlin/Merlin-8 v2.58 (ProDOS) Disk 1-2.dsk&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;These disk images can be opened in any of the Apple II emulators, such as &lt;a href=&quot;http://www.virtualii.com&quot;&gt;Virtual ][&lt;/a&gt; for the Mac or &lt;a href=&quot;https://github.com/AppleWin/AppleWin&quot;&gt;AppleWin&lt;/a&gt; for Windows. You could also use &lt;a href=&quot;http://adtpro.sourceforge.net&quot;&gt;ADTPro&lt;/a&gt; to transfer the disk images to an actual Apple II.&lt;/p&gt;
&lt;p&gt;I would love to get your feedback on the new book. If you have any questions or comments on the new book or the original articles, please post them below.&lt;/p&gt;
&lt;p&gt;Here&#039;s a video &lt;a href=&quot;https://www.youtube.com/watch?v=pgJuilzsAmQ&quot;&gt;explaining more about how the book was created&lt;/a&gt;...&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
 <pubDate>Mon, 22 Dec 2014 17:45:30 +0000</pubDate>
 <dc:creator>Chris Torrence</dc:creator>
 <guid isPermaLink="false">171 at http://www.softalkapple.com</guid>
 <comments>http://www.softalkapple.com/blogs/assembly-lines-complete-book#comments</comments>
</item>
<item>
 <title>Assembly Lines by Roger Wagner - Part 16</title>
 <link>http://www.softalkapple.com/content/assembly-lines-roger-wagner-part-16</link>
 <description>&lt;div class=&quot;field field-name-field-image field-type-image field-label-hidden view-mode-rss&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;figure class=&quot;clearfix field-item even&quot; rel=&quot;og:image rdfs:seeAlso&quot; resource=&quot;http://www.softalkapple.com/sites/default/files/styles/large/public/images/AssemblyLines_masthead.png?itok=00-q9QGP&quot;&gt;&lt;a href=&quot;http://www.softalkapple.com/sites/default/files/images/AssemblyLines_masthead.png&quot;&gt;&lt;img typeof=&quot;foaf:Image&quot; class=&quot;image-style-large&quot; src=&quot;http://www.softalkapple.com/sites/default/files/styles/large/public/images/AssemblyLines_masthead.png?itok=00-q9QGP&quot; width=&quot;420&quot; height=&quot;114&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;/figure&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-field-tags field-type-taxonomy-term-reference field-label-hidden view-mode-rss&quot;&gt;&lt;ul class=&quot;field-items&quot;&gt;&lt;li class=&quot;field-item even&quot; rel=&quot;dc:subject&quot;&gt;&lt;a href=&quot;/tags/reprint&quot; typeof=&quot;skos:Concept&quot; property=&quot;rdfs:label skos:prefLabel&quot; datatype=&quot;&quot;&gt;Reprint&lt;/a&gt;&lt;/li&gt;&lt;li class=&quot;field-item odd&quot; rel=&quot;dc:subject&quot;&gt;&lt;a href=&quot;/tags/programming&quot; typeof=&quot;skos:Concept&quot; property=&quot;rdfs:label skos:prefLabel&quot; datatype=&quot;&quot;&gt;Programming&lt;/a&gt;&lt;/li&gt;&lt;li class=&quot;field-item even&quot; rel=&quot;dc:subject&quot;&gt;&lt;a href=&quot;/tags/roger-wagner&quot; typeof=&quot;skos:Concept&quot; property=&quot;rdfs:label skos:prefLabel&quot; datatype=&quot;&quot;&gt;Roger Wagner&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class=&quot;field field-name-body field-type-text-with-summary field-label-hidden view-mode-rss&quot;&gt;&lt;div class=&quot;field-items&quot;&gt;&lt;div class=&quot;field-item even&quot; property=&quot;content:encoded&quot;&gt;&lt;p&gt;&lt;em&gt;Assembly Lines, Part 16 was first published in Softalk in January 1982. This was the first article in what was supposed to be &quot;Volume 2&quot; of &quot;Assembly Lines: The Book&quot;. Unfortunately, Volume 2 remained unpublished when Softalk went bankrupt in August 1984. Part 16 is actually the first of three parts where Roger Wagner explains how to interface assembly language with Applesoft Basic.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;Everyone&#039;s Machine Language Guide, Part 16&lt;/h2&gt;
&lt;p&gt;One useful application of machine language programming is in the enhancement of your existing Applesoft programs. Some people are inclined to write all their programs in machine language, but it may be more efficient on occasion to write “hybrids”—programs that are a combination of Applesoft and machine language. In this way, particular functions can be done by the operating system best suited to the particular task.&lt;/p&gt;
&lt;p&gt;If you had to write a short program to store ten names, it would be best to do it in Applesoft:&lt;/p&gt;
&lt;p&gt;10 FOR I = 1 TO 10&lt;br /&gt;
20 INPUT N$(l)&lt;br /&gt;
30 NEXT I&lt;/p&gt;
&lt;p&gt;This is much simpler than the equivalent program in machine language. In cases where neither speed nor program size is a concern, Applesoft is a completely acceptable solution.&lt;/p&gt;
&lt;p&gt;However, if you had to sort a thousand names, speed would become a concern, and it would be worth considering whether the job could best be done in machine language.&lt;/p&gt;
&lt;p&gt;If you have ever done a call in one of your Basic programs, then you have already combined Applesoft with machine code. For example:&lt;/p&gt;
&lt;p&gt;10 HOME&lt;br /&gt;
20 PRINT &quot;THIS IS A TEST&quot;&lt;br /&gt;
30 PRINT &quot;THIS IS STILL A TEST&quot;&lt;br /&gt;
40 GET A$&lt;br /&gt;
50 VTAB 1: HTAB 5: CALL-958&lt;/p&gt;
&lt;p&gt;In this program, a line of text is printed on the screen. After you press a key, all text on the screen after the first word “THIS” is cleared.&lt;/p&gt;
&lt;p&gt;Now although it might be possible to accomplish the same effect in Applesoft by printing many blank lines, it would not be as fast or as efficient in terms of code as the call -958.&lt;/p&gt;
&lt;p&gt;In executing the above program, the Applesoft interpreter goes along carrying out your instructions until it reaches the call statement. At that point a JSR is done to the address indicated by the call. When the final RTS is encountered, control returns to the Basic program. In between, however, you can do anything you’d like!&lt;/p&gt;
&lt;p&gt;Calling routines is hardly complicated enough to warrant an entire article on the subject. The real questions are, how do you pass data back and forth between the two programs, and how can the problem of handling that data be made easier for the machine language program?&lt;/p&gt;
&lt;p&gt;Simple Interfacing. The easiest way to pass data to a machine language routine is simply to poke the appropriate values into unused memory locations, and then retrieve them when you get to your machine language routine. To illustrate this, let’s resurrect the tone routine from the May 1981 issue of Softalk.&lt;/p&gt;
&lt;p&gt;To use this, assemble the code and place the final object code at $300. Then enter the accompanying Applesoft program.&lt;/p&gt;
&lt;p&gt;1 **********************&lt;br /&gt;
2 * SOUND ROUTINE #3A *&lt;br /&gt;
3 **********************&lt;br /&gt;
4	*&lt;br /&gt;
5	*&lt;br /&gt;
6	OBJ $300&lt;br /&gt;
7	ORG $300&lt;br /&gt;
8	*&lt;br /&gt;
9 PITCH EQU $06&lt;br /&gt;
10	DURATION EQU $07&lt;br /&gt;
11	SPKR EQU $C030&lt;br /&gt;
12	*&lt;br /&gt;
13	BEGIN LDX DURATION&lt;br /&gt;
14	LOOP LDY PITCH&lt;br /&gt;
15	LDA	SPKR&lt;br /&gt;
16	DELAY	DEY&lt;br /&gt;
17	BNE	DELAY&lt;br /&gt;
18	DRTN DEX&lt;br /&gt;
19	BNE	LOOP&lt;br /&gt;
20	EXIT RTS&lt;/p&gt;
&lt;p&gt;From the Monitor, this will appear as:&lt;/p&gt;
&lt;p&gt;*300L&lt;br /&gt;
0300-	A6	07	LDX	$07&lt;br /&gt;
0302-	A4	06	LDY	$06&lt;br /&gt;
0304-	AD	30 CO LDA	$C030&lt;br /&gt;
0307-	88	DEY&lt;br /&gt;
0308-	DO	FD	BNE	$0307&lt;br /&gt;
030A-	CA	DEX&lt;br /&gt;
030B-	DO	F5	BNE	$0302&lt;br /&gt;
030D-	60	RTS&lt;/p&gt;
&lt;p&gt;This Applesoft program is used to call it:&lt;/p&gt;
&lt;p&gt;10 INPUT &quot;PITCH, DURATION? &quot;;P,D 20 POKE 6,P: POKE 7,D 30 CALL 768 40 PRINT 50 GOTO 10&lt;/p&gt;
&lt;p&gt;The Applesoft program works by first requesting values for the pitch and duration of the tone from the user. These values are then poked into locations 6 and 7 and the tone routine called. The tone routine uses these values to produce the desired sound, and then returns to the calling program for another round.&lt;/p&gt;
&lt;p&gt;This technique works fine for limited applications. Having to poke all the desired parameters into various comers of memory is not flexible, and strings are nearly impossible. There must be an alternative.&lt;/p&gt;
&lt;p&gt;The Internal Structure of Applesoft. If you’ve been following this series for long, you’ve no doubt figured out by now that I’m a great believer in using routines already present in the Apple where possible, to accomplish a particular task. Since routines already exist in Applesoft for processing variables directly, why not use them?&lt;/p&gt;
&lt;p&gt;To answer this, we must take a brief detour to outline how Applesoft actually “runs” a program.&lt;/p&gt;
&lt;p&gt;Consider this simple program:&lt;/p&gt;
&lt;p&gt;10 HOME: PRINT &quot;HELLO&quot;&lt;br /&gt;
20 END&lt;/p&gt;
&lt;p&gt;After you’ve entered this into the computer, typing list should reproduce the listing given here. An interesting question arises: “How does the computer actually store, and then later execute, this program?”&lt;/p&gt;
&lt;p&gt;To answer that, we’ll have to go to the Monitor and examine the program data directly.&lt;/p&gt;
&lt;p&gt;The first question to answer is, exactly where in the computer is the program stored? This can be found by entering the Monitor and typing in: 67 68 AF B0 and pressing return.&lt;/p&gt;
&lt;p&gt;The computer should respond with:&lt;/p&gt;
&lt;p&gt;67-	01&lt;br /&gt;
68-	08&lt;br /&gt;
AF-	18&lt;br /&gt;
B0-	08&lt;/p&gt;
&lt;p&gt;The first pair of numbers is the pointer for the program beginning, bytes reversed of course. They indicate that the program starts at $801. The second pair is the program end pointer, and they show it ends at $818. Using this information let’s examine the program data by typing in:&lt;/p&gt;
&lt;p&gt;801L&lt;/p&gt;
&lt;p&gt;You should get:&lt;/p&gt;
&lt;p&gt;*801L&lt;br /&gt;
0801-	10	08	BPL	$080B&lt;br /&gt;
0803-	0A	ASL&lt;br /&gt;
0804-	00	BRK&lt;br /&gt;
0805-	97	???&lt;br /&gt;
0806-	3A	???&lt;br /&gt;
0807-	BA	TSX&lt;br /&gt;
0808-	22	???&lt;br /&gt;
0809-	48	PHA&lt;br /&gt;
080A-	45	4C	EOR	#$4C&lt;br /&gt;
080C-	4C	4F 22 JMP	$224F&lt;br /&gt;
080F-	00	BRK&lt;br /&gt;
0810-	16	08	ASL	$08,X&lt;br /&gt;
0812-	14	???&lt;br /&gt;
0813-	00	BRK&lt;br /&gt;
0814-	80	???&lt;br /&gt;
0815-	00	BRK&lt;br /&gt;
0816-	00	BRK&lt;br /&gt;
0817-	00	BRK&lt;br /&gt;
0818-	F9 A2 00 SBC $00A2,Y&lt;br /&gt;
08IB-	86	FE	STX	$FE&lt;/p&gt;
&lt;p&gt;This is obviously not directly executable code. Now type in: 801.818&lt;/p&gt;
&lt;p&gt;This will give:&lt;/p&gt;
&lt;p&gt;0801-	10	08	0A	00	97	3A	BA&lt;br /&gt;
0808-	22	48	45	4C	4C	4F	22	00&lt;br /&gt;
0810-	16	08	14	00	80	00	00	00&lt;br /&gt;
0818- 8C&lt;/p&gt;
&lt;p&gt;To understand this, let’s break it down one section at a time. When the Apple stores a line of Basic, it encodes each keyword as a single byte token. Thus the world print is stored as a $BA. This does wonders for conserving space. In addition, there is some basic overhead associated with packaging the line, namely a byte to signify the end of the line, and a few bytes at the beginning of each line to hold information related to the length of the line, and also the line number itself.&lt;/p&gt;
&lt;p&gt;To be more specific:&lt;/p&gt;
&lt;p&gt;0801- 10 08 0A 00 97 3A BA&lt;br /&gt;
0808- 22 48 45 4C 4C 4F 22 00&lt;br /&gt;
0810- 16 08 14 00 80 00 00 000&lt;br /&gt;
818- 8C&lt;/p&gt;
&lt;p&gt;The first two bytes of every line of an Applesoft program are an index to the address of the beginning of the next line. At $801,802 we find the address $810 (bytes reversed). This is where line 20 starts. At $810 we find the address $816. This is where the next line would start if there were one. The double 00 at $816 tells Applesoft that this is the end of the Basic listing. It is important to realize that the 00 00 end of the Applesoft program usually, but not always, corresponds to the contents of $AF,B0. It is possible to hide machine language code between the end of the line data and the actual end as indicated by $AF,B0—but more on that later.&lt;/p&gt;
&lt;p&gt;The next information within a line is the line number itself:&lt;/p&gt;
&lt;p&gt;0801-	10	08 0A	00 97	3A	BA&lt;br /&gt;
0808-	22	48 45	4C 4C	4F	22	00&lt;br /&gt;
0810-	16 	 08  14  00	80	00	00	00&lt;br /&gt;
0818- 8C&lt;/p&gt;
&lt;p&gt;The 0A 00 is the two-byte form of the number ten, the line number of the first line of the Applesoft program. Likewise, the 14 00 is the data for the line number twenty. The bytes are again reversed. After these four bytes, we see the actual tokens for each line.&lt;/p&gt;
&lt;p&gt;0801-	10	08 0A	00	 97 	 3A 	 BA&lt;br /&gt;
0808-	22	48 45	4C 4C	4F	22	00&lt;br /&gt;
0810-	16	08 14	00 80	00	00	00&lt;br /&gt;
0818- 8C&lt;/p&gt;
&lt;p&gt;All bytes with a value of $80 or greater are Applesoft keywords in token form. Bytes less than $80 represent normal ASCII data (letters of the alphabet, for example). Examining the data here we see a $97 followed by $3A. $97 is the token for home, and $3A the colon. Next, $BA is the token for print. This is followed by the quote ($22) and the text for HELLO (48 45 4C 4C 4F) and the closing quote ($22). Last of all, the 00 indicates the end of the line.&lt;/p&gt;
&lt;p&gt;In line number twenty, the $80 is the token for end. As before, the line is terminated with a 00.&lt;/p&gt;
&lt;p&gt;When a program is executed, the interpreter scans through the data. Each time it encounters a token, such as the print token, it looks up the value in a table to see what action should be taken. In the case of print, this would be to output the characters following the token, namely “HELLO”.&lt;/p&gt;
&lt;p&gt;This constant translation is the reason for the use of the term interpreter for Applesoft Basic.&lt;/p&gt;
&lt;p&gt;Machine code on the other hand is directly executable by the 6502 microprocessor and hence is much faster, since no table lookups are required.&lt;/p&gt;
&lt;p&gt;In Applesoft, a syntax error is generated whenever a series of tokens is encountered that is not consistent with what the interpreter expects to find.&lt;/p&gt;
&lt;p&gt;Passing Variables. So, back to the point of all this. The key to passing variables to your own machine language routines is to work with Applesoft in terms of routines already present in the machine. One of the simplest methods was described in the October 1981 issue of Softalk, wherein a given variable is the very first one defined in your program (see the input routine). This is okay, but rather restrictive. A better way is to name the variable you’re dealing with right in the call statement.&lt;/p&gt;
&lt;p&gt;The important points here are two components of the Applesoft interpreter: TXTPTR and CHRGET (and related routines).&lt;/p&gt;
&lt;p&gt;TXTPTR is the two-byte pointer ($B8, B9) that points to the next token to be analyzed. CHRGET ($B1) is a very short routine that actually resides on the zero page and that reads a given token into the accumulator. In addition to occasionally being called directly, many other routines used CHRGET to process a string of data in an Applesoft program line.&lt;/p&gt;
&lt;p&gt;Here then is the revised tone routine :&lt;/p&gt;
&lt;p&gt;1	**********************&lt;br /&gt;
2	* SOUND ROUTINE #3B *&lt;br /&gt;
3	**********************&lt;br /&gt;
4	*&lt;br /&gt;
5	*&lt;br /&gt;
6	OBJ $300&lt;br /&gt;
7	ORG $300&lt;br /&gt;
8	*&lt;br /&gt;
9 PITCH EQU $06&lt;br /&gt;
10	DURATION EQU $07&lt;br /&gt;
11	SPKR EQU $C030&lt;br /&gt;
12	*&lt;br /&gt;
13	COMBYTE EQU $E74C&lt;br /&gt;
14	*&lt;br /&gt;
15	ENTRY JSR COMBYTE&lt;br /&gt;
16	STX PITCH&lt;br /&gt;
17	JSR COMBYTE&lt;br /&gt;
18	STX DURATION&lt;br /&gt;
19	*&lt;br /&gt;
20	BEGIN LDX DURATION&lt;br /&gt;
21	LOOP LDY PITCH&lt;br /&gt;
22	LDA SPKR&lt;br /&gt;
23	DELAY DEY&lt;br /&gt;
24	BNE DELAY&lt;br /&gt;
25	DRTN DEX&lt;br /&gt;
26	BNE LOOP&lt;br /&gt;
27	EXIT RTS&lt;/p&gt;
&lt;p&gt;This would list from the Monitor as:&lt;/p&gt;
&lt;p&gt;*300L&lt;/p&gt;
&lt;p&gt;0300-	20	4C	E7	JSR	$E74C&lt;br /&gt;
0303-	86	06	STX	$06&lt;br /&gt;
0305-	20	4C	E7	JSR	$E74C&lt;br /&gt;
0308-	86	07	STX	$07&lt;br /&gt;
030A-	A6	07	LDX	$07&lt;br /&gt;
030C-	A4	06	LDY	$06&lt;br /&gt;
030E-	AD	30	CO	LDA	$C030&lt;br /&gt;
0311-	88	DEY&lt;br /&gt;
0312-	DO	FD	BNE	$0311&lt;br /&gt;
0314-	CA	DEX&lt;br /&gt;
0315-	DO	F5	BNE	$030C&lt;br /&gt;
0317-	60	RTS&lt;/p&gt;
&lt;p&gt;The Applesoft calling program would then be revised to read:&lt;/p&gt;
&lt;p&gt;10 INPUT &quot;PITCH DURATION? &quot;,P,D&lt;br /&gt;
20 CALL 768,P,D&lt;br /&gt;
30 PRINT&lt;br /&gt;
40 GOTO 10&lt;/p&gt;
&lt;p&gt;This is a much more elegant way of passing the values and also requires no miscellaneous memory locations as such (although for purposes of simplicity the tone routine itself still uses the same zero page locations.)&lt;/p&gt;
&lt;p&gt;The secret to the new technique is the use of the routine COMBYTE ($E74C). This is an Applesoft routine which checks for a comma and then returns a value between $00 and $FF (0-255) in the X register.&lt;/p&gt;
&lt;p&gt;It is normally used for evaluating pokes, hcolor=t and so forth, but does the job very nicely here. It also leaves TXTPTR pointing to the end of the line (or a colon if there was one) by using CHRGET to advance TXTPR appropriate to the number of characters following each comma. Note also that any legal expression--such as (X-5)/2--can be used to pass the data.&lt;/p&gt;
&lt;p&gt;To verify the importance of managing TXTPTR, try putting a simple RTS ($60) at $300. Calling this you will get a SYNTAX ERROR, since upon return, Applesoft’s TXTPTR will be on the first comma, and the phrase “,P,D” is not a legal Applesoft expression.&lt;/p&gt;
&lt;p&gt;Now what about two-byte quantities? To do this, a number of other routines are used. For example, this routine will do the equivalent of a two-byte pointer poke. Suppose for instance you wanted to store the bytes for the address $9600 at locations $1000, 1001. Normally in Applesoft you would do it like this:&lt;/p&gt;
&lt;p&gt;50 POKE 4096,0: POKE 4097,150&lt;/p&gt;
&lt;p&gt;Where 4096 and 4097 are the decimal equivalents of $1000 and $1001 and 0 and 150 are the low-order and high-order bytes for the address $9600 ($96 = 150, $00 = 0).&lt;/p&gt;
&lt;p&gt;A more convenient approach might be like this:&lt;/p&gt;
&lt;p&gt;50 CALL 768, 4096, 38400&lt;/p&gt;
&lt;p&gt;or perhaps:&lt;/p&gt;
&lt;p&gt;50 CALL 768, A, V&lt;/p&gt;
&lt;p&gt;The routine for this would be:&lt;/p&gt;
&lt;p&gt;1 **************************&lt;br /&gt;
2	* POINTER SET UP ROUTINE *&lt;br /&gt;
3 **************************&lt;br /&gt;
4	*&lt;br /&gt;
5	*&lt;br /&gt;
6	OBJ $300&lt;br /&gt;
7	ORG $300&lt;br /&gt;
8	*&lt;br /&gt;
9	CHKCOM EQU $DEBE&lt;br /&gt;
10	FRMNUM EQU $DD67&lt;br /&gt;
11	GETADR EQU $E752&lt;br /&gt;
12	LINNUM EQU $50 ; ($50,51)&lt;br /&gt;
13	*&lt;br /&gt;
14	PTR EQU $3C&lt;br /&gt;
15	*&lt;br /&gt;
16	ENTRY JSR CHKCOM&lt;br /&gt;
17	JSR FRMNUM;	EVAL	FORMULA&lt;br /&gt;
18	JSR GETADR ;	PUT	FAC	INTO LINNUM&lt;br /&gt;
19	LDA LINNUM&lt;br /&gt;
20	STA PTR&lt;br /&gt;
21	LDA LINNUM+1&lt;br /&gt;
22	STA PTRH-1&lt;br /&gt;
23	*&lt;br /&gt;
24	JSR CHKCOM&lt;br /&gt;
25	JSR FRMNUM&lt;br /&gt;
26	JSR GETADR&lt;br /&gt;
27	*&lt;br /&gt;
28	LDY #$00&lt;br /&gt;
29	LDA LINNUM&lt;br /&gt;
30	STA (PTR),Y&lt;br /&gt;
31	INY&lt;br /&gt;
32	LDA LINNUM+1&lt;br /&gt;
33	STA (PTR),Y&lt;br /&gt;
34	*&lt;br /&gt;
35	DONE RTS&lt;/p&gt;
&lt;p&gt;which will list from the Monitor as:&lt;/p&gt;
&lt;p&gt;*300L&lt;/p&gt;
&lt;p&gt;0300-	20	BE	DE	JSR	$DEBE&lt;br /&gt;
0303-	20	67	DD	JSR	$DD67&lt;br /&gt;
0306-	20	52	E7	JSR	$E752&lt;br /&gt;
0309-	A5	50	LDA	$50&lt;br /&gt;
030B-	85	3C	STA	$3C&lt;br /&gt;
030D-	A5	51	LDA	$51&lt;br /&gt;
030F-	85	3D	STA	$3D&lt;br /&gt;
0311-	20	BE	DE	JSR	$DEBE&lt;br /&gt;
0314-	20	67	DD	JSR	$DD67&lt;br /&gt;
0317-	20	52	E7	JSR	$E752&lt;br /&gt;
031 A-	AO	00	LDY	#$00&lt;br /&gt;
031C-	A5	50	LDA	$50&lt;br /&gt;
031E-	91	3C	STA	($3C),Y&lt;br /&gt;
0320-	C8	INY&lt;br /&gt;
0321-	A5	51	LDA	$51&lt;br /&gt;
0323-	91	3C	STA	($3C),Y&lt;br /&gt;
0325-	60	RTS&lt;/p&gt;
&lt;p&gt;The special items in this routine include CHKCOM, a syntax-checking routine that serves two purposes. First it verifies that a command follows the call address, and secondly it advances TXTPTR to point to the first byte of the expression immediately following the comma. If a comma is not found, a syntax error is generated.&lt;/p&gt;
&lt;p&gt;FRMNUM is a routine that evaluates any expression and puts the real floating-point number result into Applesoft’s floating-point accumulator, usually called FAC. This is a six-byte pseudo register ($97-9C) used to hold the floating-point representation of a number. It includes such nifties as the exponential magnitude of the number and the equivalent of the digits of the logarithm of the number stored.&lt;/p&gt;
&lt;p&gt;At this stage you’d have to be something of a masochist to want to deal with the number in its current form, so the next step is used to convert it into a two-byte integer.&lt;/p&gt;
&lt;p&gt;GETADR does this by putting the two-byte result into LINNUM, LINNUM+1 ($50,51).&lt;/p&gt;
&lt;p&gt;Even if this is not exactly an in-depth explanation of all the most precise details of the operation, the bottom line is that the three JSRs (CHKCOM, FRMNUM, and GETADR) will always end up with the low-order and high-order bytes of whatever expression follows a comma in LINNUM and LINNUM+1.&lt;/p&gt;
&lt;p&gt;These simple subroutines should be quite adequate for many applications. Next month, however, we’ll look at string passing, some of the various other routines available, and how to pass data back to the calling Applesoft program.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description>
 <pubDate>Wed, 14 May 2014 00:54:01 +0000</pubDate>
 <dc:creator>Chris Torrence</dc:creator>
 <guid isPermaLink="false">122 at http://www.softalkapple.com</guid>
 <comments>http://www.softalkapple.com/content/assembly-lines-roger-wagner-part-16#comments</comments>
</item>
</channel>
</rss>
