'l•

OHIO SCIENTIFIC

ASSEMBLER EDITOR and

,· ,-. . • EXTENDED MONITOR

REFERENCE MANUAL

}-- ■

CHAPTER .· . ~ . .

·1. INT-ROD.UCtfCiN~ ...... ('!1.ll.••·~·-· •••••;:~ ...... ~ .• ~•~•.i!l·•.1!1•~-:.■~---··.:•••• ~~ •••••• ".~· ...... :..~~-- . . . - . . . . ·. ·_ . .. ~. '. . . 2. BUILDING: Bl.OCKS OF ASSEMBLY LANGUAGE...... u...... -~...... '" .. ~~...... ,. •...... , . : ,. ::. .· .· .- .·. . ) - . '. .· / _. ~,_-,:·· .. . -:

OPERATION .·SYMSOt.'S ...... - ...... ~.--~---~-~···.;...... ,. .•••••• q ••·"·•·!1 ...... --••• ~ ...... :;.._ • .;.:.~~~;, •• ;~~-....'ll:.~li :. < -·. • : •• ,··. • • • .- ' • ••• .:_,_ ·.·, •',,, •••

·CONSTANTS~;...... ~~•:a•-•····~······· .. ···~ ...... ~.•.,.~•···· 111 ...... ~•· ...... i.~···"········~··~-~~-•-:~~-"'~.-., .. :..~-~~~~-·•·~··· .,·. ' ·.. ·. c.. µBELs.·. ANO- EXPRE$$i~• ., •. ~---•--·~ ...· • .,-...... ~ •• ~.,----····~~-~: •• ~ •... ..:~ ...... ~:~-...... ~•. • .. ~tt~•····•·"·•·~~~,;~ .•...~.~~..:..~~········--::+:·

, - ' ...... ' .·· - .. -.. ' . •. :- ;···. -, . ·,, - . ··A:. ·. REMARKS ...... ~...... ~:...... ~...... c...... ~ ...... ; ...... ~.~~~ ...... ~ •..-~ ...... ~. . . '•. . , ...... - '_- . : .. . ·. ·:·· ·. : . •' .•·

a. INSmUCTIVE&~--~---~···········~~~---··~----" - ...... · . ~~----•·~---.·. ••• _.-...... ~~ •••..•. ~ ...... - . :,l.~~-~~-:•·~:~.~----·. -- , .. .. ••··._.·'...... ~3-5 (1) ·Direct ·.Addtessing·.~ ...... ,, •• ;...... ~~· ...... ;~ .... :;~ ••• ~ ...... 3,4· (2l lM~lat~. Address~ng ...... ~·-~--··•~··~~~~-• ..•··.,~---~·•·~··••ff••···•··~-····"'!·•· .. ···••4!•• ..······--~•·,~·~,.~.~·•··•.,·~~· ..• ...... 4 (~) 1.ndexed •·· Addressmg...... ;•• :········ ...... H.: ... ~~...... ~ ...... :...... ,..; ...• ~..• ~...... 4,5

(4) ... tndlF~ct ••~~~--~~~-- -~•~-~., •• ~-:--~~I!••~~ ...... ".-:.~ • .;~...... ~,•.••~~~~I!•~.•·~•·~ .. 5' ~ 'Add~tnu.••·~~- ■ -'!•··•·• ·. . .· ·,. ~--~- ■ ••.•·ra~•'!·.- ·~••.■--~•-···• ~■-•~•• .. . ",. - (5) ·_Implied Acicl~sl-rig~ ... ~--•-···~.,-~.-~.•--··~,•.--•·~~---H ...... ~.~··----~·~··••.•·•~ ...... _:•·~•.••,•-:~---·••~.•~~.•··,•· ...... _•.-.... _..~-.!••·••.•--•----· 5 . .

c. DlRECTIVES-~.~--••·•··--•····••4!~••·--~• .. .,. .... ~•!I••··•;. -~ •••• :....~;.. •• ·•••••• .. ~~ •••. .-,. •.••. ·: ....· ~ ...... ~~-····. •.- •••• ·-. ••••.•.••• ~ ...... ·- ~ ...... 11t~•~•il••········•···· S-7. :(1,) Th9 ·LQC:ation .. Coun•r-...... ~..... •·••·•~l!••ir-••··· ... •...... ~- ..... ~-•• : ...... ~~-• ... ~ ... "' ...·...... ~ ...... ~~.. ~ •••°i~~-~·•·•.~•···•••.••·•····~s~S (2) Defining·· Labels...... ~ •• ~ .•••••••• ;...... ; ...... ~ ...... ~~.... ~ ...... ~ ...... ;•.••••.• ·6 •.

(3) ~. Lo~i0f1-s...... ~. .a:••?••~··~•·~~; •• Q ...... ; ...... ;.., ••.•••.•:..-..~ ...~ •••• ~ ••••11 ...~ ...... ~- .. ~111••·-.. ~··~· ...... ~~· :6~7

(a) Byte...... '!" ...... ~.•· .. ·····,····.. ;.··.... ~~ ...-■~ ...... :~---~.•~··•~.-·~~•-- ■•--·•·:■~• ..·····• ..... ~~~·••.••.•11!•••- ■:•~~.'!•l!l•~.'!"!i••· .. ~·~•~-~~·~···"•••,•·.. •••...... ~--·~

(b) .Qbyte •• ,.•·•••il'!" ■...... ~ ...... ••••••• .... :■-aa.,i, ..~ ...... , ••~.;~~-~·••••~•~•.••••~l!l•••~ .. '!'~•.••·•«~•••-il.••• ...... ~•~•,lli:.~~-iu,w-■■••~~~-~~~·•·•~.•.... • ...... ~••~• .... •••n .. ·6~·7_ (c) Word...... H••···~ ..········••.•······ .. ··• .. ~ ...... ~ ...... ·.~ •••••••••••••u ...... 7·· , . ; .. BUILDING ANO EDITING AN. ASSEMBLY LANGUAGE ·souRCE. s .4. • •• ••• .- ' • : • .- Fll.E: ',· •..... • I' "°~ ...... • • • ~ •

. ·. :. ' .. ~ :·

5:. .ASS,EMBlY COMMANDS~ ...... ~·-·~ ...... ~ ...... ~ .. ·•••·•·• ...... ~ ...·.l!l~•-.•·· ...... 1!1-• ...... ~··.... ~ ...... -...~~.l!J••••:•~-·~ ...... 9 ,

6 •.·AN EXTENDED .EXAMPLE.(llfERE' ARE MANY SHORT EXAMPLES.IN TH£ PRECEDltro .SECTIONS) ...... ~...... ~.~-•·•·,;•~•••··•--·-- 10.13 . . . 7. RUNNING A. MACHINE tAN(lUAGE PROGRAM...... •• ...... ••~.;~ •• •• :...... 14 .· . . ~ . ~ .. ~:. ,. .· ~ . . .. : . .

.A. USJHG.·THE•.PROMMONITOR-CASSETTE BASED SYSTEMS ...... _ ..,~ ..~ ...... :~ .... m ...... 14·

B •. USING nte.' DQS. KERt4J:LJ>tSK·. BASED SYSTEMS•••••••••••• ~...... ~ ...... m ••••••••• 14 -· . . . ' . . - C•. USING· .THE• PROM·MONtTOR-OISK .. BASED S.VSTEMS •• ~ ...... ~~...... ,(.. ~•••9!•:~•···•·:.~.~.~~;~...... "!t ••••••••••••• ~ 14

' . . . . 8. TH.E '.EXTENE>E·o.·.MONITOft;·, ••~~•- .., ...... ~··•~lli··~· .. •·~ ...... ~ .... ~ ••. ~ ....._:.- ... ~•• ~-•···;;. .. ~~~.;~ •.. ~-•:-••·• .... ·~•-• .. •· t•5.-,t9: A~, THE EM .. _c·bMMANDs~·~.~ ...... -.~~·--~-:a-~ ...... ~[:-11••··~····••:a••··-··· .. •••• .. ···~~~ ...... -...... ~~~--~···•··~~ ...... :...... 1~ 1.7 B•. ·.THE. R ANb M.· COMMANDS IN DETAJt; WlfH EXAMPLES ...... : ••• ,.L.•••·•••m~••••• ..~••~••• ....•:11 • C •. BREAKPOINTS ANO.QJB~GING .• WIT" EXAMPLE$;...... m••'.···· .. ·•· ..•·•.:· ...... ~i ...... 17 • 19 PAGE

.9 •

, .. · . . . , .. ·, _. A.:. USR: FUNCTION·...... ~ ...... ~ ...... 20 · .• 8. DISK:! ·~Q.O:...... -:~-~!I~•-·· l!IJl•···"·'.-~~ ••••••.•.•~---~~- •• ~-...... ·.ll!,_.~ ••• ~.~· .... ··~ ... ········~-~...... ~··· ... ·~ ...... ~ •• ;..~~---: ••• ~ •• 20 · • ~ ~ ~'l'"'!••·~~---~-~~ ...... ~...... ______...... -...... 1!1_•••-···•·······• ...... ~···· 20,21 c. ·01sK.f ''XOT~ ...... ~_ ...... ~.:...... APPEN.DICES

.·. ', . .· .A. ASSEMB·LY ·iRRQRS...... ~~--~.•-···~·~···•-····~·•··•1!1~••· ...... ;._...... ,...... ~ ...... 4;"•~·--·•·!'• ...... ~••····~~ ...... 22. •• 6502 INSTRUCTION· .ADDRESSING .. MOOES, •..•••.•· ••. .:.: ...... H ...... ; ...... 23

o. os~· .·VtRStON· ·.,oF ASSEMBLERIEDiroR~---~"--·•-~ ...... -.- ...... ~····· ..··---·· .. ••••·•••• ..•••·· .. ··•~······:········2s E~· CASSETTE' VER$1O~. ·OF ·"SSEMBLE~IEDIT:OR~ •• -~:••-~·-•·~·•·• ...... "•••••••••• ~····--~~ ...... _...... ~a&~21' ·f. EM· COMMAND·· SUMMARY ...... ~ ...... 28' ' . / G. :·0$-650· V·EASION OF EM~··············~···•:a.ii••·· ..·····•·~--"··~···•··· ..... ,...... ~.•······· .... ~ ...... ~ ...... :...... _•••• ~:•••• - ••. 29. H~- ·cAS.SETTE:·veRSION-·OF. EM...... ·-··~·······;·····••.•······ .. ·••.•·····.:...... ~ ...... ~ ...... ~30: ·•~ ROM .MONITOR, COMMANDS...... _ ...... H...... · ...... 31 ·.

,~ ASCII. TAEiLE...... _...... lll ...... ~ ...l! ...... ~ ...... 'a ...... ~.-..132 'K.. CHECKSUM.·· ;'FORM'At ...... ~ ...... _...... ~~ ...... ~ ...... - ...... 33 . . . . ; . . . . -L o&-eso- ·coMuANoS- A"o eRaoRS. ... -...... ,l!.ll•-··...... '!~ ...... ~ ...... -...... ~ ...... -:-.. ~· ...... :a4~3s . . M; FLO~TING. POINT STORAGE FORMAt...... ~ ....~ ...... ~ ...... 37.

Na !~-.. DIS4SSE-BlV· TABLE ...... - ...... --.~ ...... _...... ~ .. ~ ...... ;...... ~•~· ...... "' ...... : ...... 1.r.= ...... -.3$ • .o .. 6502 .REFERENCE LIST ...... - ...... ;;39,40•

IN:D1:X· ...... ~ ...... ~ ...... ~ ...... 41,42

ii CHAPTER 1 INTRODUCTION •

This manual is intended to be an introductory and ASSEMBLER-The program which translates an as­ reference manual for entering, editing, debugging and sembly language program into machine language. The running assembly language programs using the OSI OSI Assembler/Editor also contains features which Assembler/Editor and Extended Monitor. This manual allow the editing of assembly language programs. While is not intended to be an introduction to assembly programmers sometimes say they are writing programs language programming. See Appendix O for a list of in "Assembler," it is technically more correct to say introductory texts. We shall assume that the reader is assembly language. An assembler is a large program, familiar with binary and hexadecimal numbers, the which functions somewhat like a compiler. two's complement system for storing negative numbers, ADDRESS-The memory of a 6502 computer is the architecture of the 6502 microprocessor (registers, organized into bytes. Each of these bytes has a unique flags, the stack, memory organization) and the rudi­ number associated with it called its address. Addresses ments of 6502 assembly language. In this manual we will are usually written as 4-digit hexadecimal numbers. The use the following conventions. first address is $0000. ($ denotes a hexadecimal The carriage return key on the number.) keyboard PAGE-Memory is organized into large units called The line feed key on the keyboard pages. Each page is 256 bytes. Page 0 consists of those The break key on the keyboard bytes with addresses $0000 through $00FF, page 1 is An up-arrow. May be A, or t t, those bytes with addresses $0100 through $01FF, and so shift-N on some keyboards on. Page 0 is important on the 6502, in that instructions • @ The commercial-at. May be shift-P which refer to page 0 are shorter and execute faster than on some keyboards instructions that refer to other parts of memory. We will use the following terms: EFFECTIVE ADDRESS-Most 6502 instructions make BYTE-The standard eight bit unit of storage. reference to some byte of memory. The address of that byte is called the effective address for that instruction. MACIIlNE LANGUAGE-The.language the micropro­ cessor understands. For the 6502, each machine OBJECT CODE-Machine language. Generally this language instruction occupies one to three bytes of refers to the result of assembly of an assembly language · memory. Hence, a machine language instructor is one 8 program. bit number, two 8 bit numbers or three 8 bit numbers. SOURCE CODE-The assembly language program to When the microprocessor is running, it is always a be assembled. The assembler translates source into machine language program that is running. object. ASSEMBLY LANGUAGE-A symbolic language in FILE-A program or group of data. Thus a file may be which every line of a program translates into one an assembly language file, a machine language file or a machine language instruction. This is in contrast to high source file. level languages like BASIC or PASCAL in which each line corresponds to many machine language instruc­ LOCATION COUNTER-When the assembler is as­ tions. While a machine language program consists sembling a source file; it keeps track of wherein memory entirely of groups of 8 bit numbers, in an assembly (the location) the object code is being put. The location language program, the programmer may use symbolic counter is where that location is kept. Hence, the loca­ names {mnemonics) for the machine instructions. tion counter is a place in memory that contains an address . • 1 CHAPTER 2

• BUILDING BLOCKS OF ASSEMBLY LANGUAGE

Each 6502 assembly language statement is composed consists of one to six characters from the set of one or more parts. Each part is built from the following: A-Z 0-9

A. OPERATION SYMBOLS $

These are three-character codes which the assembler The first character in a label must be a letter. The translates directly into a machine language operation characters must be contiguous, that is, there must be no code. For example, TICA (Transfer register X to register A) blanks between the characters. The single letters A, X, is the operation symbol for the 6502 operation code Y, S and P cannot be used as labels, since they refer to (opcode) $8A. the 6502 registers, and no operation symbols (like JMP, SEC, BNE) can be used as labels. Examples:

LEGAL ILLEGAL B.CONSTANTS LOOP POINTER END.2 $PR A constant is a number. On the 6502, a constant is TABL$ A/B lly an 8 bit (one byte) or 16 bit ( two bytes) number. • START: LOO P programmer may use numbers in decimal, binary, XY A octal or hex (hexadecimal) and may also use character LDAX LDA string constants, which are stored in memory in the 8 bit ASCII code. These codes are listed in Appendix J. The programmer may also use arithmetic expressions in 1) A decimal constant has no prefix. a program. An expression may be like an arithmetic 2) A binary constant is prefixed by a per cent sign expression in BASIC with no parentheses and no (%). exponentiation allowed. Evaluation of an expression is 3) An octal constant is prefixed by a "commercial always done left to right without regard to precedence of at" (@) sign. operators. Expressions are always evaluated to an 4) A hex constant is prefixed by a dollar sign($). answer of 16 bits or less, with any overflow ignored. Thus, for example: Division is integer division with any remainder ignored. 26 = % 11010 = @32 = $1A An expression cannot begin with a minus sign, however, 5) A character string constant is a string of an expression like 0-1 is allowed, with the answer characters enclosed in single quotes ( apostro­ appearing in two's complement form if it is negative. For phes). (If an apostrophe is to be included in the example, if Q = $50AF and D = 64 then the string then two consecutive apostrophes must be used.) Each character in the string is stored EXPRESSION EVALUATES TO in one byte in memory in the ASCII code. For Q/$100 $0050 example, 'A/3' is stored as $412F 33 and 'P"R' Q*256 $AF00 is stored as $50 22 32. Q/256*256 $5000 D+$0A/%1010 $0007

The assembler also recognizes one predefined label, an C. LABELS AND EXPRESSIONS asterisk(*), which denotes the current contents of the location assignment counter. The assembler can tell • label or symbol is a group of characters which looks from context if an asterisk means this or multiplica­ like a variable name in BASIC or FORTRAN. A label tion.

2 ·CflAfTER. 3: . ASSEMBLY LANGUAGE STATEMENTS

. . . There ate three kinds of statement$ that can be : exampleswewiU next descril)e two directive s.tatements. .entered into an assembly languagesomce program: .(a)· These willl,e describedin:greaterdetail inthe following remarks, ·. (b) ·· instructive statements. and (c) · directive section...... statements. Each line must begin with a line number. The form :of the .BYTE statement is.· ·. label .. BYTE operand remafks Thelabei and remarks ·fields are opu'onal. The operand,: .A. Rl;MARKS· may be' any expression. This directive causes the, assemblerto generate aone byt¢o,-,nstant at the current' A line that beginswith i semicolon (;)is a comnien:t. location in the program. Remarks are printed in any listing,but theydonotaffect ·.. ·. Tiie equals(= ).ditective causes a.label to take a value the object code producedduring.assembly; In addition, which is used throughout assembly: The form is. any line in. a sotJree.progJ'.am can contain con;iments,.as described below. label = expressio~ remarks or· * = expression remarks The second form sets the location counter to ·the value of B ... INSTRUCTIVES . the expression, and thus tells the assemb~r whereto put . . the machine .l ..nm•age code . w.h.·.en .· the ·p.rogram ·.is These· are .the. act~al assembly language instructi.Q~ •· assembled. ~.. .• •.. .. i thattranslate directly into machine language code. An Now back to assembly language instructive state-. assembly language statement has up to four parts called, ments ..The 6502 assembly language has five different fields. The general form. is · · . . addre~i11g forms: · · · label. operation symbof'. ·· aperand .· remarks The label arid remarks fields are always optionaL Some stat.e111entS requiretha:ttheoperand· fieldbe.blank.The· .. . 1~ DIRECT ADDRESSING . · fields may begin in any column and theyare sepat.ated by · blanks; It is, however;goodpractice to tabulate the four· The form is· fields in :~lumns,. See Appendix ff for tab characters. label op symbol For the statements that require an opetand, the .·. operand is.either(i) thedatafw the instruction, pr(ii)···•· The label.and remarks fields·are optional. The value of the·Effective Address,. or(iil) theinformatiort;need~dto: the operand is the Effective M4fess. TheJnstructions calculate. ·tb~.··Effective. Address. To·•·facilitite.some···· · ·thaLClln be used in the direct addressing mode are

.ARITIIME11C . DA.TAMOVE BOOLE~ · COMPARING ADC mA· ,i\No: ·cMP ., .;Bee· DEC LUX' BIT CPX: BCS INC, LDY· EOR CPY BEQ SBC·· Sl'A QRA BMI STX BNE ~TY BPL BVC . uvs JMP JSR

Example 50K1 .BYTE $FA 100 *=$100E 55K2 .BYTE$FB 120UNO .BYTE 5 60K3 .BYTE $FC 130OUO .BYTE 7 65K4 .BYTE $FD 140TRES .BYTE 9 70 LOX #2 150START LOX #1 75 LOY #2 160 LOA 80 LOA ADDA1 • ouo,x 170 LOX #2 85 LOA ADOA1,X 180 LOA UNO,X 90 LOA AOOR1,Y 190 LOY #1 95 LOA (ADOR1,X) 200 LOA START-2,Y 100 LOA (AOOR1),Y For each LDA instruction {lines .160, 180 and 200) the The effect .of each LDA instruction is as follows: effective address is $1010, so each. puts a 9 into the accumulator. LINE E FF. AD. ACCUM (After Skecutlon) 80 $80 $C1 4. INDIRECT ADDRESSING 85 $82 $C0 The form is 90 $82 $C0 95 $12C0 $FA label op·symbol (operand) remarks 100 $12C3 $FD or label op symbol (operand,X) f.emarks or label op symbol (operand),Y remarks 5. ·IMPLIED ADDRESSING Only the JMP instruction canbe used in the first form. The second form is called indexed indirect and the third The form.is is indirect indexed. label op symbol rema. In the first form Eff. Ad. = C(operand) In the second form Eff. Ad. = C(operand + C(X)) Theseinstructions ·have no operand. They generally In the third form Eff. Ad. = C(operand) + C(Y) refer to an operation on a flag, a register or a register In each the operand must be less than $100, Le., the pair. Some instructions of this type are SEC(SEt the operand must be on page 0. For these instrUctions, the Carry flag), INX (/Ncrement the X register) or TXS operand is taken to be the address of a .WORD, that is, (Transfer register X to the Stack pointer). Each a two byte number with the firstbyte containing the instrUction in this addressing mode produces one byte of eight low order bits and the second byte containing the machine language. eight high ·order bits of the Effective ·Address , below. Hence the two bytes of the 16-bit number are in reverse order. For example, if C($001B)=$FF and C($001C) = $2A,. then the Effective Address for the C. DIRECTIVES instrUction JMP ($001B) These assembly language statements d

5 For example: 3. DATA LOCATIONS Hi> * = $4408 The assembler recognizes three directives which may 20 LOA #%101 be used to set up memory locations with data. The 30DATA1 .BYTE $1A .BYTE directive is used to define one byte of data and 40 *=*+2 .DBYTEand .WORD set up two bytes, with .WORD • 50DATA2 .BYTE $F0 producing data with the bytes in reverse order, as required for indirect addressing. The op code for an LDA instruction in the immediate mode is $A9, hence the LD A instruction is assembled to $A905. When the program is assembled, the machine code produced is: a ..BYTE ADORESS (Hex) CONTENTS (Hex) The form is $440B $A9 $440C $05 DATA 1 = $440D $1A label .BYTE operand remarks $440E ? $440F ? DATA2= $4410 $F0 The operand may be one part or several parts separated The directive on line 40 causes the assembler to skip the by commas. There must be no blanks ( except in quotes) two bytes with addresses $440E and $440F, so the anywhere in the operand because a blank is used to contents of these bytes are not changed at assembly separate the operand and remarks fields. Each part of time.. The statement the operand is either an expression or a string of characters enclosed in single quotes. Each expression or * = * + 2 character in quotes produces one byte of data in allows the programmer to refer to DATAl as an array of memory. If the value of an expression is more than 8 bits three elements with an index register (X or Y) acting as then only the rightmost 8 bits ·are used. subscript . Example: 10 *=$0F0E 20 C=15 30 01 .BYTE 10,$10,@10,%10 •2. DEFINING· LABELS 40 02 .BYTE C-3,01/$10 The form is 50 03 .BYTE 'OSl',0 60 04 .BYTE C/2-8,01/$4 label = expression The result, in memory, when this code is assembled, Example: would be 10 *=$1BF8 ADDRESS CONTENTS 20 W=$12 01=$0F0E $0A 30 E=2*W+3 $0F0F $10 40 START LDA #E-W/3 $0F10 $08 50 J=*-1 $0F11 $02 The labels in this example have the following values: 02=$0F12 $0C $0F13 $F0 LABEL VALUE (Hex) $4F W $12 03=$0F14 $0F15 $53 E $27 $0F16 $49 START $1BF8 $0F17 $00 J $1BF9 04=$0F18 $FF When this example is assembled, the location counter $0F19 $C3 has the value $1BF8 before line 40 is assembled and the value $1BFA after line 40 is assembled. Hence, when 50 is processed, * = $1BFA. Since E is defined in f:s of W, an assembly error would result if lines 20 b ..DBYTE 30 were interchanged. The·form is

6 label .DBYTE operand remarks label .WORD operand remarks

This directive causes the assemblerto place a two byte The syntax is the same as for .OBYTE. This directive .•. constant into memory. The operand may be a single also· produces a· two byte constant, but the bytes are expression or several expressions separated by commas. stored in reverse order. Character strings in quotes are not allowed. Example: Example: 10 *=$1E00 20 T=$11D 30 1<1 .WORDT,T -122 10 *=$1E00 40 K2 .WORD K1,*-1 20 T=$011D 30 K1 .DBYTE T,T -,-$122 Notice the operands are the same as the last example. 40 K2 .DBYTE K1,*-1 Assembly would produce ADDRESS CONTENTS K1 =$fE00 $1D Assembly of this code would produce the .following: $1E01 $01 $1E02 $FB $1E03 $FF ADDRESS CONTENTS K2=$1E04 $00 K1 =$1E00 $01 $1E05 $1E $1E01 $1D $1E06 $05 $1E02 $FF $1E07 $1E $1E03 $FB In 6502 machine·language, addresses must be stored in K2=$1E04 $1E this "backwards'' fashion. For example the three byte $1E05 $00 instruction $1E06 $1E $1E07 $05 CMP $17FA is stored in memory as $CD operation code c.. WORD $FA.}•· address • The form is $17

7 • CHAPTER 4

.BUILDING AND EDITING AN ASSEMBL V LANGUAGE

SOURCE FILE

The Assembler is loaded by typing ASSEMBLER ( or automatically inserted into the source file at the place ASM) in response to the A* prompt in the OS-65D DOS specified by the line number. If a line is entered with the mode. (This mode is reached by typing EXIT when in same number as a line which is already in the source file, BASIC.) There are several commands that are accepted then the new line replaces the existing line~ Line by the Assembler/Editor. The Assembler/Editor is numbers must be no larger than 65535. Besides entering waiting for a command when a period (.) is printed. a line into the current source file, the user may also use The user may enter a line into the current source file one of the following editing commands. Each command by typing a line beginning with a line number. The line is may be abbreviated to its initial letter.

RESEQ Resequences all line numbers in the source file. The first line is assigned line number 10 and the line numbers increment by 10. After the resequence is finished, the next sequential line number is printed .

•PRINT Lists all or part of the current source file. PRINT may be used in the following forms: PRINT lists the entire file PRINT line lists one line PRINT first line - last line lists the specified lines PRINT first line - lists from the specified line to the end of the file PRINT - last line lists from the beginning of the file to the specified line. Any number of the above line specifications, separated by commas, can be used with one PRINT command. To direct the output to a printer refer to the DOS IO command the the IO flag bit settings (Appendix L).

DELETE Deletes a line or lines from the file using the same line specifications as PRINT.

INIZ Deletes all lines from the source file. To prevent inadvertently clearing the workspace, the question "INIZ? (YIN)" is printed after a line beginning with an "I" is entered. The user must enter "YES" ( or "Y") to complete initialization. When entering commands or source text lines, correc­ single characters. An up-arrow (or Shift N) can be used tions can be made to a line anytime before the carriage to delete the entire line from the file. return. A back-arrow (or Shift 0) can be used to delete

• NOTE: CTRL-P toggles device #4 on and off

8 CHAPTER 5 ASSEMBL V COMMANDS •

The Assembler recognizes four assembly commands. On disk systems, the M command may be used to change Three of the commands give object code listings, and the the place in memory where the object code is placed by fourth assembles the source to object code in memory, the A3 command. This command does not affect the ready (hopefully) for execution. The commands are: object code itself, only where it is put. For example, suppose the programmer wants to write a program A0 (or A) Gives a full assembly listing. Each line which will be assembled to memory starting at address printed contains: $3290. Thus the source program would have a line (1) the line number declaring *=$3290. However, an A3 command could (2) the address in memory of the object code not be executed, because the machine code produced (3) the object code (1-3 bytes) would overwrite the source code arid assembly would (4) the source code not be completed. This can be remedied by use of the M If errors are detected in the source, a pointer to the error command to offset the address for the machine code. and the appropriate error number are printed below the For example, if the programmer types line with the error. The machine code generated in case of an error depends on the type of error, but, generally, M1000 is either the appropriate op code byte with a zero operand or is three NOP bytes. In many cases, this will and then result in correct addresses for the rest of the listing. The A3 next section contains an example of an A0 listing. then the object code produced will be the same as • A1 Gives an errors-only listing. This command without the M command, but it will be placed in memory produces the same output as the full assembly listing but - starting at address $4290. The programmer can then use for only those lines that contain errors. the disk command !SAVE TT,5=4290/N A2 Gives an object tape listing in the standard checksum format. See Appendix K for a description of to save the machine language code, where TI is the checksum format. The user may save this output on tape track, S is the sector and N is the number of pages to be by typing copied to the disk. The code may then ( or later) be recalled to memory at the correct place for execution by then Save and the command A2. !CALL 3290=TT,S (Note: "SAVE" is used only on cassette versions of assembler. See Appendix L for· cassette 1/0 for disk from the Assembler/Editor orthe ExtendedMonitor or machines.) by DISK!"CA 3290 TT,S" A3 Puts the object code into memory ready for = execution. This command produces no listing, unless from BASIC. there are errors. • 9 CHAPTER 6 • AN EXAMPLE

Suppose the programmer enters the following pro­ clearing program using indirect addressing. gram through the keyboard. The program is a screen p 10 *=$4000 20 ADDA=$A 30STAAT LDA ADDA ; save the page 0 locations 40 PHA ; in case this routine is 50 LDA ADOA+1 ; called from BASIC 60 PHA 70 LOA #$00 ; set up page 0 locations 80 STA ADDA+1 ; for indirect addressing 90 LDA #0 100 STA ADDA 110 LOX #7 ; counter 120 LOY #0 ; register for ind. addressing 130 LOA #32 ; blank character in ASCII code 140LOOP STA (ADDA),Y 150 INY 160 BNE LOOP 170 INC ADDA+1 ; after 256 locations incr. page 180 DEX • 190 BPL LOOP 200 PLA ; recover the page 0 info 210 STA AODA+1 ; & put it back 220 PLA 230 STA ADDA 240 ATS 250 .ENO Note: On a ClP computer change: line 90 to LOA #83 line 110 to LDX #3 If the user then enters the A command, the ouput will be: A 10 4000 *=$4000 20 000A ADDA=$A 30 4000 A50A START LOA ADDA ; save the page 0 locations 40 4002 48 PHA ; in case this routine is 50 4003 A508 LOA ADDR+1 ; called from BASIC 60 4005 48 PHA 70 4006 A9D0 LOA #$00 ; set up page 0 locations 80 4008 8508 STA ADDR+1 ; for indirect addressing 90 400A A900 LOA #0 100 400C 850A STA ADDA • 110 400E A207 LOX #7 ; counter 10 120 4010 A000 LDY#0 ; register for ind. addressing 130 4012 A920 LOA#32 ; blank character in ASCII code 140 4014 910A LOOP STA (ADOR},Y 150 4016 cs lNY 160 4017 D0FB BNE LOOP 170 4019 E60B INCADOR+1 ; after 256 locations .incr .. page 180 401B CA DEX • 190 401C• 10F6 BPL LOOP 20040tE 68 PLA ; recover the page 0 info 210 401F 850B STA ADDR+1 ; & put it back 220 4021 68 PLA 230 4022 850A STAADOR 2404024 60 ATS 250 .ENO

For example, the third line is 30 4000 A50A START LOA ADDA ; save the page 0 locations Iremarks !operand operation symbol label machine languageJor this Une address of the first byte. occupied by· this instruction line number There are no· errors in the above assembly. will be put at addresses $4800 through $4824. If, at this point, the A3command is entered, no output If the user enters the A2 command,the output will be will result. The assembler will, however, put the the following, in checksum formatfortape storage. See machine code into memory at addresses $4000 through Appendix K. for a description of checksum format. $4024. If the user ( on a disk) system enters ; .184000A50A48A50B48A9D0850BA900850AA207 • M0800 A000A920910AC8D009D4 ; 0D4018FBE60BCA10F668850B68850A600670 and·then Assume next that the program is entered as. below. Lines A3 70, 80, 140 and 190 have been changed so that they the resulting machine code will be exactly the same but contain errors. p 10 *=$4000 20 ADDR=$A 30 START LOA ADDA ; save the page 0 locations 40 PHA ; in case this routine is 50 LDAADDR+1 ; called from 6AS.IC 60 PHA 70 LDA #D0 ; set up page 0 locations 80 STAADR+1 ; for indirect addressing 90 LOA #0 100 STA AOOH 110 LDX#7 ; counter 120 LDY#f/J ; register for ind. addressing 130 LOA #32 ; blank character in ASCII code 140 LOOP STA (ADDA, Y) 150 INY 160 BNE LOOP 170 INC ADOR+1 ; after 256 locations incr, page 180 DEX 11 • 190 BPK LOOP 200 PLA ; recover the page 0 infor 210 STA ADDR+ 1 ; & put it back 220 PLA 230 STA ADDA 240 ATS • 250 .END

This time the result of an A command will be: A 10 4000 *=$4000 20 000A= ADDR=$A 30 4000 A50A START LOA ADDA ; save the page 0 locations 40 4002 48 PHA·· ; in case this routine is 50 4003 A50B LOA ADDR+1 ; called from BASIC 60 4005 48 PHA 70 4006 A900 LOA #D0 ; set up page 0 locations _..,_l" ______------A E# 18 80 4008 800100 STA ADR+1 ; for indirect addressing ------A E# 19 ------A E# 18 90 400B A900 LOA #0 100 4000 850A STA ADDA 110 400F A207 LOX #7 ; counter 120 4011 A000 LOY #0 ; register for ind. addressing 130 4013 A920 LOA #32 ; blank character in ASCII code 140 4015 EAEAEA LOOP STA (ADDR,Y) • __ A E# 7 150 4018 ca INY 160 4019 00Fa BNE LOOP 170 401B E60B INC ADDR+1 ; after 256 locations incr. page 180 4010 CA DEX 190 401E EAEAEA BPK LOOP ------A E# 6 200 4021 68 PLA ; recover the page 0 info 210 4022 850B STAADDR+1 ; & put it back 220 4024 68 PLA 230 4025 850A STA ADDA 240 4027 60 ATS 250 .END

• 12 An Al command will give the following: A1 70 4006 A900 LOA 00 ; set up page -0 locations ------______/\ E# 18 80 4008 800100 STA ADA+ 1 ; for indirect addressing • ------•• P•----" E# 19

E# 18 140 4015 EAEAEA LOOP STA (AODR,Y) ...... I\ E# 7 190 401E EAEAEA BPKLOOP

...... i ...... /\ E# 6

13 • CHAPTER 7

• RUNNING A MACHINE LANGUAGE PROGRAM

After an assembly language source program has been are discussed more completely in Appendix I. assembled to memory by theA3 command or a machine language program has been called into memory from disk or tape, there are several options for running and testing. The most powerful debugging tool is the B. DOS KERNEL-DISK BASED Extended Monitor, which is described in the next SYSTEMS section. The procedure for interfacing a machine language program with a. BASIC program is also On a disk based system, the user may type discussed in Chapter 9. EXIT (or E) to enter the DOS kernel and then type GO XXXX A. PROM MONITOR-CASSETTE where XXXX is the entry address of the machine BASED SYSTEMS language program in hex. If the user's program ends with ah RTS then control will revert to the DOS kernel. On a cassette based system, the user may exit from the (When in the DOS, the A* prompt appears.) Assembler/Editor and enter the machine language Monitor in ROM by typing and then .M C. PROM MONITOR-DISK BASED A machine language program in memory may then be SYSTEMS run by typing the entry address and then G Also a disk system, the user may exit to the Monitor in ROM by typing The user may return from the Monitor in ROM by typing EXIT and then .1300 G REM provided memory from addresses $0240 through $1390 The user may return from the Monitor in ROM to the has not been altered. The Monitor in ROM commands DOS kernel by typing .2547 G .

• 14 THE EXTENDED MONITOR •

The 6502 Extended Monitor is an extensive machine subcommands which can be entered only after the code debugging aid. It includes the following commands primary command has been entered. If an invalid for command is .entered, a ''?" will be printed. - memory display and modification In the command descriptions below, all addresses and memory display and change data values.are hexadecimal and. the following abbre­ memory dump viations or special characters are used: memoryfill memory move MEANING memory relocate the line feed key on the. keyboard the carriage return ( or return) key on - program debugging the keyboard disassembly i an up arrow character; May be a .j , /\ search for a byte string or a shift/N on some keyboards search for a character .string @ a commercial-at character. May be a breakpoint· installation· and control shift/P on some keyboards processor register display and change program execution

- audio cassette .input/output MEMORY DISPLAY AND MODIFICATION COM­ load MANDS save view @aaaa displays the address and contents of the location aaaa. New contents - hexadecimal arithmetic may or· may not· then be entered • calculate ( two hex digits) followed by one of display overflow/remainder the following:

displays the next location t displays the previous location LOADING THE EXTENDED MONITOR l displays the same location The method for loading the Extended Monitor " prints the contents of the location depends uport which version you are using. Refer to the as an ASCII or graphic character appendix appropriate .10· your system (Appendix Gor exits to the Extended Monitor H). command mode After the Extended Monitor has been loaded, its prompter, a colon(:), is displayed. This is the Extended Dfflf,tttt dumps the contents of memory Monitor's command mode. locations ffff through tttt-L

Fffff ,tttt = dd fills memory locations ffff through tttt-l with the value dd. A. THE EM COMMANDS Maaaa = ftlT,tttt moves the contents of memory Each of the Extended Monitor commands. is listed from locations. ffffthrough tttt~ 1 to below. Any of these commands may be entered the memory starting at location whenever you are in the command mode as indicated by aaaa. • the colon prompter. Many of the commands also have NOTE: The distance ofan upward ·. . .

15 move must be gieatet than the restored with the En,cominand. .If length of the move or data in•the breakpoint n had previously been ·original locations will be. overwrit-. assigned it is first restored. When a ten (aaaa> =tttt or aaaa< ffff) •. breakpoint is "hit" during program execution it. is. also .,automatically '8wia =fflf,tttt relocates (moves the contents of restored. (See Using Breakpoints • memory from locations ffff for Program Debugging) through tttt-1 to the memory start­ ing atlocation aaaa and appropria­ En eliminates. breakpoint n (il == t-8) . tely adjusts all three-byte 6562 and restores the original contents instruction operand addresses•that of the location where it was locat­ refer to locations within the range ed . . of the move. (Adds (aaaa•ffff) to each operand. address that is goes (transfers program control) to >=ffff and <==tttt-1)~ address aaaa. ·. Note: The Distance ofan upward move must be greater than the T prints . a table. of breakpoint ad" lellgth of the move or data in the dresses for each breakpoint 1 original locations will be overwrit­ through 8. An address of.· FFFF ten.(aaaa>=tttt or aaaa

C ·continues program execution from: PROGRAM' DEBl,JGGING ·cOMMANOS the locatiOn of the last breakpoint. Qfflf dis~ssembles . 6502. machine co<;le This command must oilly be used . into 6502 mnemonic code .from after. a breakpoint has been "hit.'' memory location ffff up. Disas- The byte that was replaced by the sembly continues for a total of 24 breakpoint ( and restored when the lines-a maximum of 72. bytes. At breakpoint was hit) is executed completion, it awaits, · first .. disassembles. the next 24 lines,·or I prints the address of the last exits to the Extended breakpoint "hit" and the• contents Monitor command .mode· of the A, X, Y, processor-status (P) and stackpointer (K) registers as · N'dd . .. .dd>fflf ,tttt searches the contents of· memory they existed at that breakpoint. · locations Jfff through tttt-1 for the stringofl to3data bytes dd; ..dd. A, X, Y, P, K these five commands print the If the string is found then the contents the as.sociated register. · affff ,tttt searches the contents of· memory ASCII or graphic character locations· ffff through tttt-1 for the · exits to the Extended l\4onitor string of 1. to 6 ASCII characters command mode c... c. If the string is found then the address of the first byte of the AUDIO CASSETTE COMMANDS first .occurrence of the string is displayed and the @ mode is Sffff,tttt saves· the contents of memory entered•. locations ffff thl'ough tttt-1 by writing them to the cassette port installs breakpoint. n (n. == 1.:8) at (as well as the terminal) in. check­ address aaaa. The contents of sum format. This function may be location aaaa is saved and niay be terminated by typing "L" and a

16 space. See Appendix K for a $806 JMP $1000 description of checksum format. $809 LDX $810 $80C STA $D740,X L loads .into memory the data read $80F RTS from the cassette port in checksum $810 .BYTE $A format. If a checksum ·error is detected, "ERR" is printed. To If the command • recover, stop the cassette machine, M0A00 = 0800,0811 rewind the tape a short distance and restart playing it. Type an "L'' is executed, then the machine code for these instructions to restart the loading. The LOAD is moved unchanged to memory address $0A00 through command can be exited at any time $0Al0. If the command by typing a space. R0A00=0800,0811

V view the data read from the cas­ is executed, then the code is moved to locations 0A00 sette port in checksum format. through 0A10 and· becomes Same as Load, above, but displays ADDRESS INSTRUCTION the data without modifying memo­ 0A00 LDA$2000 ry. 0A03 JSR $A09 0A06 JMP $1000 CALCULATOR COMMANDS 0A09 LDX $Al0 0A0C STA$D740,X Hxxxx,yyyy + calculates the sum of the hexadeci­ 0A0F RTS mal values xxxx and yyyy and 0A10 .BYTE $A prints the result. For the LDX and JSR instructions, the address part of Hxxxx,yyyy­ same as· above for difference. the instruction is changed, because the two addresses involved ($809 and$810) are in the range of the move (in Hxxxx,yyyy* same as above for product. this case between 0800 and 0811). For the remaining • three byte instructions, the address is not changed. If an Hxxxx,yyyy/ same as above for quotient. operand is changed, then it is changed by the amount of the move, that is, if 0 prints the overflow or remainder from the last multiplication or di­ Raaaa = ffff ,tttt vision. performed with the Hcom­ is executed then mand. New operand = old operand + (aaaa - ffff) NOTE: at most 17 characters per The use of the R command may cause problems if some command line are allowed. of the locations that are relocated do not contain machine language instructions, but contain data. For example,ifthe following three bytes appear as data in a program at addresses $SHI through $812: B. THE R AND M COMMANDS .BYTE $AD The M command moves the contentsof one area of .BYTE $7 memory to another area, without change. The R .BYTE $8 command moves memory and changes the contents of and the command those locations which can be interpreted to be the address portion of a three byte machine. ·language R0A08 = 0800,0820 instruction. This address portion is changed only if the is executed, then the contents .of these three bytes may address lies within the range ofthemove. For example, be interpreted to be the machine language for the consider the following sequence of instructions residing instruction LDA $807. Then the R command would at address $0800 through $0810: change these to ADDRESS INSTRUCTION .BYTE $AD $800 LDA $2000 .BYTE $F $803 JSR $809 .BYTE $A 17 • One way to prevent this is to use the R command to !RETURN EM (or !RE EM) relocate the entire program and then use the M The computer will respond command on the bytes that contain data, to correct any .stakes like the_ above. EM V2.0

If the user now enters C. BREAKPOINTS AND DEBUGGING B1, 4007 B2, 4008 As the name implies, a breakpoint is a point where 83, 400D the execution of a running program may be "broken" or interrupted. Using the Extended Monitor, up to eight then three breakpoints will be installed in the program. breakpoints may.be placedinto a program. When the The T command will produce the following listing: program is run ( executed) and a breakpoint is encoun­ B1,4007 tered, the Extended Monitor is re-entered and prints the 82,4008 l following to document the breakpoint: B3,400D Bn@aaaa B4,FFFF A/aa X/xx Y/yy P/pp K/kk B5,FFFF B6,FFFF where: n is the breakpoint number 1-8 B7,FFFF aaaa is the location where the breakpoint was B8,FFFF encountered aa is the contents of the accumulator Note: When you exit and re-enter EM, all breakpoints xx is the contents of the X index register are initialized. · yy is the contents of the Y index register If pp is the contents of the processor status word the command kk is the contents of the stackpointer G4000 To illustrate the use of a breakpoint, consider the following program: is entered, one "e" will be printed on the screen and the Extended Monitor will print • 100 *=$4000 120 START LOA #101 81@4007 140 LOX #2 A/65 X/02 Y/FF P/70 K/FF 160 STA $0290,X indicating that breakpoint #1 has been hit and also the 180 DEX status of the five registers when the breakpoint .was 200. BNE *-4 encountered. The breakpoint Bl has now been removed 220 STA $D29C and the DEX instruction has been put back into the 240 ATS program. If the C command is now entered, the program When this program is executed, it will print two lower will continue execution of just one instruction, the case e's atthe left margin of the screen and another near DEX, the next breakpoint will be hit and the Extended the center. An assembly listing ( assembler A command) Monitor will print yields: 82@4008 .A A/65 X/01 Y/FF P/70 K/FF 100 · 4000 $ = $4000 If the C command is entered again, then two more e's 120 4000 A965 START LDA #101 will appear and .the· Extended Monitor will print 140 4002 A202 LOX #2 160 4004· 9D90D2 STA $D290,X B3@400D 1804007 CA DEX A/65 X/00 Y/FF P/7F K/FF 200 4008 D0FA BNE *-4 220 400A 8D9CD2 STA $D29C All breakpoints have now been eliminated. If the user 240 4000 60 ATS now enters Assuming the Oser is working with the Assembler/Edi-· B1,400D r, the program may now be.. assembled to memory by • e A3 command. The· Extended Monitor may now be and then entered ( on disk systems) by the command X

18 the Extended Monitor wil[respond with p

/00 then the Extended Monitor will respond which is the contents of register X at the time the last /7D breakpoint was hit. If. the user now types which is the contents of the Processor Status Word atthe 0A time the breakpoint was hit .. If the user now types then that will be· the contents of the X register when 7F execution is resumed. If the user now types this will be the contents of the Processor Status Word G4004 when execution resumes. Specifically, the Z flag will be set so that no branch takes place. Hence, if the C then eleven ''e's" will appear on the screen andthe command is entered, one. more e will appear. on· the Extended Monitor will print: screen, and the Extended Monitor will print B1@400D B2@400D A/65 X/00 Y/FF P/7F K/FF A/65 X/01 Y/FF P/7F K/FF The· programmer can also change the flow of execution of the program. For example, if the user now enters B1,4008 USING THE EM AND THE ASSEMBLER/EDITOR B2,4000 SIMULTANEOUSLY G4000 On disk based systems, the Exten(ied Monitor and the Extended Monitor will respond the Assembler/Editor are.always loaded.into memory simultaneously. The user may go from one to the other B1@4008 by typing A/65 X/0JY/FF P/7D K/FF !RE AS or !RE EM If the user now enters the C command, execution of the program will resume and the branch back to The Extended Monitor and Assembler/Editor (on disk STAD290,X systems) occupy memory from. $0200 through $16FF. The Extended Monitor uses page 0 locations $C0 will be executed. If instead the programmer types through $FF. •

• 19 • INTER·FAClNG WITH BASIC

. There ate several. methods that can be used to call a routine whose address is· stored at addresses ;$0006 and machine .language routine from a· BASIC program. If a $0007. This can be done, for example, by routine is stored on disk at ttack IT and sector S, then a LOA 6 BASIC program. may contain .the· statement STACALL+1 OlSKt'CA. XXXX= TT,S" LOA 7 STA CALL+2 to bring. the machine .code into memory to hexadecimal . CALL JSR $FFFF addresses X}Q{X. The user should take precautions to ,void having a running BASIC program change memory This routine will put its answer at $AE and $AF with the locations occupied by his macliine language subroutine, high order byte of the answer at $AE. If the user wants · and riot to· bring in machine code onto your BASIC to store an answer at Y (assuming Y =USR(X) is in the program. Beginning at $327E, in the workspace, the · BASIC program) then this 16 bit value should be put in BASIC• program and numeric variables are stored, the Y register (low byte) and the A register (high byte) .. ·.. however, string· variables· are stored· at the end of and then the routine whose address is stored at $0008 memory sothat the emiof memorymay not be a "safe" and $0009. can be called. place for a machine language subroutine. The user can create a safe place by running the BASIC utility CHANG:E .. B. DlSKl"GO XXXX"

• • .. . . . On. disk based systems, a BASIC program xnay call a ·• A.THEUSR FUNCTION machine language subroutine by this statement, :where XXXX is the entry address, in hex, ofthe machine • The user can: cause a BASIC program to branch to language routine. The routine must end with an RTS_. any location in memory inexactly the. same fashion that· Parameters can be passed to such a routine (or a routine BASIC's builHn fu11ctiorts (like ABS, RND, SIN) are accessed by the USR function) using POKEs. called. ·The appropriate form is Y=U$R(X) where. Y can be an1- arithmeticf variable· and X can be C. DISKl"XQT NNNNNN" replaced by any arithmetic expression. The address of the entry point into the user's routine must be POKEd This command loads the disk file named NNNNNN to into memory locations 574 {= 23E hex) and 575 (= 23F address $3279·up and then executes·a-JMP to $327E. hex). The low order byte of the address goes to 574 and Thus the program should be assembled to start at $327E: · the high order byte to 575. (This is the standard 6502 Header and track length information are stored at D,1ethod of storing addresses backwards.) . $3279-$327D, NNNNNN can be the name of a disk file When Y=USR(X}is executed, control passes to the or a track number. Since $327E is the beginning of POKEd address via a JSR and the value of){ (or workspace for assembly language progtams, the pros whatever the argument) is loaded into the Floating gi-ammer must offset the assembly to avoid destroying . Accumulator, which is on page 0 at addresses -• $AE the source code during assembly. In addition, to allow · through $B3: See appendix M for the format ofoumbers the program to be stored· on disk,. the user must put, at in the Floating Accumulator. This is all that is done by address $327D, the number of tracks required to hold . BASIC and nothing is~ stored at Y unless the user's. the·machinelanguage program. (Onetrackholds2040 routine does it; The value in the.floating Accumulator, bytes.) For purposes of example, let us assume the . floating poi11t format, can be converted to a 16 bit assembled program will use $200 (:.:: 512 decimal)bytes • .... teger(in two's complementif negative)bycalling the.. of• memory and that the Assembler/Editor command

20 Ml000·• wm ·cause the assembler. to assemble ·the· code EMV2.0 without running into the source program in the :M 327E=427E,447E workspace. The following sequence of commands will :@3270 set up the disk file ready for a DISK!"XQT NNNNNN" 327O/dd01 ·. :!PUT NNNNNN command in a BASIC program. The user's input is underlined. We assume the program is in the workspace. .M1000 *Note: This discussion assumes that the workspace starts at $327E, which is correct for minifloppies. For .A3 eight inch floppies substitute $317Eand subtract $100 .!RE EM from the above locations.

21 • APPENDIX A • ASSEMBLV ERRORS

The following descriptions of assembly errors and had a different value on pass one than on pass two. their possible causes are provided to facilitate elimina­ The latter error may be caused by previous errors in tion of these errors in an assembly. the assembly. 1) A, X, Y, Sand Pare Reserved Names 13) Out Of Bounds On Indirect Addressing One ofthese reserved names was found in the label An indirect-indexed or indexed-indirect address field. No code is generated for a statement with a does not fall into page zero as required. reserved name as a label. Use of a reserved name in 14) There isn't any. an expression will give an "undefined label" error, 15) Ran Off End Of Line error 18. An operand is required and wasn't found before the 2) There isn't any. end of the line. 3) Address Not Valid 16) Relative Branch Out Of Range An address greater than 65535 (hex FFFF) was The target address of a branch instruction is farther encountered. away than the minus 128 to plus 127 byte range of 4) Forward Reference In Equate, Origin or Reserve the instruction permits. Directive 17) There isn't any. An expression used in one of these directives 18) Undefined Label includes a label that hasn't been previously defined The identified label is not defined anywhere within in the assembly source file. the assembler source file. 5) Illegal Operand Type For This Instruction 19) Forward Reference To Page Zero Memory An operand was found which is not defined for the This warning message is generated when an specified instruction opcode. Refer to Appendix B instruction that has both page zero and absolute for the defined instruction addressing modes. addressing modes has an operand that is defined • 6) Illegal or Missing Opcode later in the assembly source file to be a page zero A defined opcode was not found. Refer to address. During pass one of the assembly, two bytes Appendix B for the defined opcodes. are allocated for the operand since its value is not 7) Invalid Expression yet known. Then during pass two, the operand is An expression was found that is not a valid found to require only a single byte so one byte is sequence of numerical constants and/or labels wasted. This is usually not a serious error because separated by valid operators or is not a valid the generated code will generally execute as instruction operand form. expected. 8) Invalid Index-Must Be X Or Y 20) Immediate Operand Greater Than 255 An indexable instruction was found with an invalid An ·immediate operand expression evaluated to index. Refer to Appendix B. greater than 255, the maximum value that can be 9) Label Doesn't Begin With Alphabetic Character represented in a single byte immediate operand. A non-alphabetic character was encountered where 21) There isn't any. a label was expected. 22) There isn't any. 10) Label Greater Than Six Characters 23) There isn't any. A string of more than six valid label characters 24) There isn't any. (A-Z, 0-9, $, ., :) was found before anon-valid label 25) Label (Symbol) Table Overflow character. This is a warning message. Assembly The size of the workspace is insufficient to hold the continues using the first six characters of the label. current source file and a table for all of the labels 11) There isn't any. encountered in the program. To assemble will 12) Label Previously Defined require a reduction in either the size of the program The identified label has previously occurred in the source file or the number of symbols or an increase assembler source file or this occurrence of the label in the size of the workspace.

22 6502· INSTRUCTION>ADDRESSING MODES

SEMBLER ·DDRE~SlNG: ODES

.· ACHINE LAN .. : .UAGE. · A··. I .z A R z A DDR.ESSING ODES . C p .b e •. p b P b n n• · n s 1 s s X X y y X y

X X X X ASL LSR ROL ROR X X X X

BIT ·. X X

CPXCPY X

. DECINC X X • JMP X X .JSR X LOAD LDX · INDEX· LDY TORE. S1'X INDEX STY

RANCH sec BCS BEQ BMl . BNE BPL BVC BVS BRK NOP RTI RT · Implied

CLC CL'D CLI CLV . (No Operand). . · DE . YINX INY PH · •.. ··PLA PLP' SE D·SEI·· . T YTSX A TICS AC-:-,Accumulator Abs-.Abs9I:ute · . IM-Immedi;!lte Rel••-Relative .·. zp...:...... zerac Page In..;,..lndirect•·.· • APPENDIX C • ASSEMBLER/EDITOR STATISTICS

Source File Storage Requirements (per line): Symbol Table Storage Requirements:

Two bytes for the line number plus, Six bytes/symbol. one byte for each text character plus, 6502 opcodes and reserved names occupy no one byte for the line terminator character (0D). symbol table space.

All repeated characters such as a sequence of spaces Assembly Speed: occupy only two bytes; one for the character and one for Approximately 600 lines per minute. a repeat count .

• 24 APPENDIX D

OS-65O V3.N VERSION OF THE 6502 ASSEMBLER/EDITOR •

In OS-65D V3.N, the Assembler/Editor is loaded This version of the Assembler/Editor occupies memory from disk and initiated by typing ASM after the A* from 0200 through 16FF. Its workspfe stal}s at 3179 prompter in the DOS kernel command mode. When­ (3279 in mini-floppy versions) and is utilized as shown ever exiting to the DOS, you can return to the below: Assembler/Editor as long as it is loaded by typing RETURN ASM ( or RE ASM). This version of the 6502 Assembler/Editor contains 3179,317A address of start of source (low, the following commands in addition to those described high )-normally 317E elsewhere in this manual. 317B,317C address of end of source + 1 (low, high) Exit exits the Assembler/Editor and 317D number of tracks required for source transfers control to the OS-65D 317E normal start of source kernel which then displays the A* prompter.

Hnnnn sets the high memory limit to hexadecimal address nnnn. Note: It is possible to carry the Assembler's symbol table forward from one assembly to another. To do so, Mnnnn sets the memory offset for A3 exit the Assembler after the first assembly and enter the assemblies to hexadecimal nnnn. machine language monitor by typing "RE M". Change • location 0855 from 0A to 18 and read out the contents of Control-I tabs 8 spaces from the current print locations 2F83 and 2F84. Enter the values from these position. Also: locations into locations 12FA and 12FB, respectively. CONTROL-U 7 spaces Then re-enter the Assembler by re-entering the DOS CONTROL-Y 6 spaces kernel at 2547 and typing "RE AS." Now the symbols CONTROL-T 5 spaces from the first assembly will remain in the symbol table for CONTROL-R 4 spaces reference during the next assembly. Likewise, the CONTROL-E 3 spaces symbols from the first and second assemblies will remain for the third assembly, etc. ff you want to eliminate all but Control-C aborts the current operation. the symbols from the first assembly, exit the Assembler and immediately re-enter it by tying "RE AS." To restore !Command Line sends the command line to OS-65D normal operation of the Assembler, change location 0855 to be executed, then returns to the back to 0A. This will cause the symbol table to be cleared Assembler. at the beginning of each assembly.

• 25 I i

• ·cASSETTE VERSION OF ASSEMBLER/EDITOR

Thi$ ve.rsion of the Assembler/Editor is supplied on TO SAVE SOURCE CODE an auto-load cassette tape. The following procedure Type "SAVE" (carriage return), type may be used to loiid the Assembler from tape: "PRINT" , turn on the cassette machine in record mode· and hit ·. As in ROM. LOADING THE ASSEMBLERIEOITOH · BASIC, the SAVE mode is disabled by fyping ..LOAD" followed·by a space; · 1) Apply power to your personal computer then reset it by depressing the key. Load the cassette, label up, into the cassette TO LOAD .PREVIOUSL V RECORDED niachine and turn the cassette machine on with · SOURCE CODE . ·the volume· at about mid-range. Turn on· cassette. machine in play'., type "LQAD", 2) Type ''ML"~ wait for leader to pass, then hit . The LOAD The M initiates the 65VP monitor and the L mode is disabled by hitting a space. starts the auto-load. In a few seconds the four This version of the Assembler/Editor also provides . zeros in the upper left portion of the video the following commands: monitor should change to· an incrementing address .•value· with .a rapidly changing data EXlT---causes the computer to·execut.e its reset vector field. The value of the addressis dependent on and display "C/W/M?". Great care mustbe taken never which auto-load cassette is being read. At this to type "C", as this will destroy the Assembler/Editor. r · time, a checksum loader is beirig read into The Assembler/Editor may.then be re-entered by typing. "M 1300 G". . . memory in 65VP form.at. Upon completion (no l,.j more than 30 seconds}, th.e checksllm loader · wiU load the rest of the cassette. The Assembler CONTROL-I-tabs 8 spaces from the. current· cursor r comes up with the message INIZ? (YIN). location. Should achecksum.error qccur, the following ·the above commands; as .all other ·Assembler/Editor. message is printed: commands, may be executed by typing the first letter OBJECT LOAD. CHECKSUM ERR only. .· This version of the ·Assembler/Editor occupies REWIND PASi ERR-TYPE G TO memory from 0240 through 1390 (hexadecimal). and RESTART requires a minimal total of8K of memory to operate. Its source file workspace starts at 1391 and' ends at lFFF, as ·· Ifa checksum. error consistently happens at the · supplied. The entry location is hex 1300. While running, same location~ the cassette is probably. bad. all of page zero is used. However, youican exit. the Contact your· OSI dealer concerning replace,. Assembler/Editor-use page zero and re~enter it by ment. However, should checksum errots occur typing ''M 1300 G". . randomly, at vari<;>us locations, ffis most likely The following locations may be changed· in the that there is a problem with th_e cassette cassette version of· the ·Assembler/Editor to .suit· your .machine or the connection to the computer. requirements: Check for broken or frayed connections. Make· sure the playback head and pressure roll­ 12C9,12CA.:._the low, high memory address ofthe start er/capstan· assembly is clean. With a minimal . of the source .file .workspace. 1391 ·· hex, as• supplied. .am<>unt of care, no problems with auto-load cassettes should be encountered. llCB,12CC-the low, high memory address of the end . .· . The cassette version of the Assembler/Editor permits . ofthe source file wotkspace. lFFF, as supplied . • loading and saving source codes in a manner similar to ROM.BASIC .·. . 12FC,12FD-the low, high merttory o~t used to bias

26 . , '. •'. -. -- : ·:·_ , '·· - -,· ... -··. '· ._.... :· .,.- .. . - . . . . . :

~acement·Qfobject code during ..~· A3 asseniblf, i/8' ·.. . MA and:-:. Enter. the valu;;i<>m•those,locations supplied. .·· into locations 12FA a11d 12FB, •respe:ctively. Then . •te-enter the Assembler .by fypfu&•'~.1"3000'\ Now. the 12FE,UFF-tie low$ high ~ddressohhe next av~le, · ·. sylt,lbo~ .from.• the• first. assembly will rem~n in the source file storage location. These · locations are ~ymboLiable for. reference duting the next assembly. initializedtotheaddress.ofthestartoftheworkspaceby. Likewise, .. the symbols .from. the• fti:st •. and·. second the INIZ command and, thereafter, are automaticalJy · assemblies will remain for the third assembly, etc. If you updated by the EditOt; · · · want to eliminate all but the S}'Dlbols from the first. < assembly, exitthe Assembler ancfimmediately re-enter Itis possible to carry the Assembler's symbol table it bytyping "M1300Q". Torestorenorm,aloperation of forward fromoneassemblytoanother. Todoso, exit the the Assembler, change locati()n 0855 b•ck to 0A. This · Assembler after the first assembly and enter the · .. willcaase.the·symbol table to be cleared at the beginning machine language 1;t1onitorby "M''. .Change location·. of each assembly. · · · 0855frQm0AtQ18 and readout the eontents oUocatiol1$ APPENDIX F

EXTENDED MONITOR COMMAND SUMMARY

SUBCOMMANDS COMMAND FUNCTION ( ALWAYS RETURNS TO ":") @aaaa display contents of aaaa dd-<:hange aaaa {dd=two hex digits) "-display as character -display next location t -display previous location /-display same location A, X, Y, P or K display A, X, Y, P or K from last dd-<:hange register break "-display as character A, X, Y-processor register P-processor status K-stackpointer Bn,aaaa enter breakpoint n at aaaa (n = 1-8) C continue from last breakpoint Dffl'f,tttt dump ffff through tttt-1 En eliminate breakpoint n • Ffffl',tttt =dd fill ffff through tttt-1 with dd Gaaaa go to aaaa Hxxn,yyyy+ display xxxx + yyyy (also - , *, /) I display location of last breakpoint L load memory from cassette SPACE key returns to ":" Maaaa =fffl',tttt move ffff through tttt-1 to aaaa Ndd ..• dd>fffl',tttt search ffff through tttt-1 for (dd ... dd is 1-8 bytes) dd ... dd 0 display overflow/remainder from last H command Qaaaa disassemble from aaaa continue disassembly Raaaa = fffl',tttt relocate ffff through tttt-1 to aaaa Sfffl', tttt save ffff through tttt-1 to cassette T display breakpoint table V view from cassette SPACE key returns to ":" wc ... c>fftT,tttt search ffff through tttt-1 for (c ... c is 1-8 characters) • c ... c 28 '. " .. ·, _' ,, ·>·, •.' .·.· .. · ,.,_:. :.· . . , . . • _. . ·· EXTENDED' MONtfo~ COMMAND.SUMMARY

SUBCOMMANDS .. . ·...... COMMANI> Ft.JNcnoN ( ALWAYS RETURNS TO u:") •· @aaaa display contents of ·aaaa dd-change aaaa (dd = two hex digits}•· "~lay as ch~acter • · ·--display next·. location f--display· previous· location l--Oisplay same location.· . . . . . display A~ X, Y; P or· K from last dd-ch~ge register break. . "-display as character A, X, Y,;,rocessor repter P-processor status l<~tackP9in~r Bn,aaaa, enter breakpoint n at aaaa . (n = 1-8) C continue from last breakpoint · Dffff,tttt · dump ffff tht'ough ttmt · En eliminate breakpoint n :Ffflr,tttt= dd fill ffff tllrough tttt-f with dd • Gaaaa go to aaaa Huxx,yyyy+ displaiy xxxx + yyyy I display location of last breakpoint L load memory from cassette SPACE key returns to ~•: '' Maaaa = fflt,tut move ffff through tttt-1 to aaaa Ndd .•• dd>fflf,tttt · search ffff thtough tttt,;l. fot • . (dd... dd is l-8 bytes) dd .•. dd< . ,_ ' ' 0 display overfiow/re~der from · · la!it .. H command Qaaaa• .disassemble froiµ aaaa · continue disassembly Raaata= mr,tttt r~locate ffff through tttt'-1 ta: a~ . . Sfflf,tttt save ffff through tttt-lto cas~tte" T ·display breakpoint table V view from Cll!isettd. SPACE key returns to '':" wc•.. c>mr,tttt search ffff tllrough tttt-l £Qr (c ... c is 1-8;characters} c.,.c APPENDIX G

• 0S-65D V3.N VERSION OF THE EXTENDED MONITOR

In OS,65D V3.N, the Extended Monitor is loaded Monitor as long as it is loaded by typing RETURN EM. from disk and initiated by typing EM after the A* This version of the Extended Monitor occupies prompter in the DOS kernel command mode. When­ memory from 1700 through lFFF and uses page zero ever exiting to the DOS, you can return to the Extended locations C0 through FF.

• 29 APPENDIX H

CASSETTE VERSION OF EM

This version of the Extended Monitor is supplied on randomly, at various locations, it is most likely a.n auto-load cassette tape. The ·following procedure that there is a problem with the cassette may be used to load the Extended Monitor from tape: machine or the connection to the computer. Checkfor broken or frayed connections; Make LOADING THE EXTENDED MONITOR sure the playback head and pressure roll­ er/capstan assembly is clean .. With a. minimal 1) Apply power to your personal computer then amount of care, no problems with auto-load reset it by .depressing the key. cassettes should be encountered. Load the cassette, label up, into the cassette This version of the Exte'nded Monitor contains one machineandtumthe cassette machine on with additional ·instruction for dumping the contents of the volume at about mid-range. memory on the 24 character lP video screen:

2) Type "ML. COMMAND FUNCTION Zaaaa dumps 8 bytes from aaaa 3} The M initiates the 65VP monitor and the L starts the auto-load. In a few seconds the four zeros in the upper left portion of the video monitor should change to an incrementing SUBCOMMAND address value with a rapidly changing data dumps next 8 bytes field. The value of the address is dependent on which auto-load cassette is being reared. At this time, a checksum loader is being read into This version occupies memory from 0800 through memory in 65VP format. Upon completion (no 0FFF and uses page zero locations D0 through FF. The • more than 30 seconds), the checksum loader checksum loader used to load the Extended Monitor will load the rest of the cassette. The Extended occupies locations 0700 through 07EF. Monitor comes up with the prompter":''. This version of the Extended Monitor is normally Should a checksum error occur, the following entered at 0800. This causes the stackpointer tobe set to message is printed: £11FF and the breakpoint registers to be initialized. Under certain circumstances, it may be desirable to OBJECT LOAD CHECKSUM EAR re-enter the Extended Monitor without this initializa­ REWIND PAST ERR-TYPE G TO tion. This may be done by entering it at 081F. RESTART There are two free command letters-J and. U, ·that If a checksum error consistently happens atthe can be utilized. by inserting the address of a command same location, the cassette is probably bad. routine at 0974 ·for J or 098A for U. The machine Contact your OSI dealer concerning replace­ language command routine must end with an RTS ment, However, should checksum errors occur instruction.

30 APPENDIX I • ROM MONITOR COMMANDS

In the cassette version, the ROM Monitor is entered entered by typing/. When in this mode, a will by typing and then M. If BASIC, the increase the displayed address by one. Assembler/Editor, or the Extended Monitor is in memory when is hit, then the user may 3) Go Mode return to it by typing and then W. If the Monitor is in the Addressing Mode, then typing On disk systems, the user can also enter the ROM a G will cause the Monitor to execute a JMP to the Monitor by typing and then M, but, if this is address currently displayed. done, then re-entry to BASIC, the Assembler/Editor, or the Extended Monitor is usually impossible. However, the disk based usermay also enter the ROM Monitor by 4) Cassette Loader Mode typing ''EXIT" and then "REM". The DOS kernel may If in the Addressing Mode, typing L permits the then be re-entered by typing .2547G . The ROM loading of programs from cassette. Upon typing L, all Monitor begins at address $FE00. ASCII commands are accepted from the audio The ROM Monitor has four command modes: cassette input port rather than the keyboard.

1) Addressing· Mode Some addresses associated with the monitor ROM are When an address is typed, the address and the FE00-Start of Monitor (restart location) contents of that address are displayed. If the Monitor FE0C-Restart with clear screen and no .other is not in the Addressing Mode then it may be entered initialization by typing a period (.). · FE43-Entry to Addressing· mode FE77-Entry to Data mode • 2) Data Entry Mode Hexadecimal data may be put into the memory A complete listing of the monitor ROM may be found in location whose address is displayed. This mode is the Appendix of the OSI 65V Primer.

31 APPENDIX J ASCII CHARACTER CODES

CODE CHAR CODE CHAR CODE CHAR 00 NUL 28 + 56 V 01 SOH 2C 57 w 02 STX 20 58 X 03 ETX 2E 59 y 04 EOT 2F I SA z 05 ENO 30 0 58 [ 06 ACK 31 1 SC I 07 BEL 32 2 50 J 08 BS 33 3 SE I\ 09 HT 34 4 SF 0A LF 35 5 60 (Blank) 08 VT 36 6 61 a 0C FF 37 7 62 b 00 CR 38 8 63 C 0E so 39 9 64 d 0F SI 3A 65 e 10 OLE 3B 66 f 11 DC1 3C < 67 g 12 DC2 3D = 68 h 13 DC3 3E > 69

14 DC4 3F ? 6A j 15 NAK 40 @ 68 k 16 SYN 41 A 6C I 17 ETB 42 B 60 m 18 CAN 43 C 6E n

19 EM 44 D SF 0 1A SUB 45 E 70 p 18 ESC 46 F 71 q 1C FS 47 G 72 r 10 GS 48 H 73 s 1E RS 49 I 74 t 1F us 4A J 75 u 20 SP 48 K 76 V 21 4C L 77 w ,, 22 4D M 78 X

23 # 4E N 79 y 24 $ 4F 0 7A z 25 % 50 p 78 { 26 & 51 Q 7C } 27 52 R 7D 28 ( 53 s 7E 29 ) 54 T 7F DEL 2A * 55 u •I 32 APPENDIX K • CHECKSUM FORMAT

The checksum format is as follows for each "record" of data: ;l8aaaadd ...ddcccc

where:

is the start of record character

18 is the hexadecimal number of data bytes in the record (24 decimal)

aaaa is the address of the first data byte in the record

dd ...dd are the 24 data bytes

cccc is the checksum-a sum modulo 65536 of all bytes in the record after • 10 the start of· record character

• 33 COMMANDS . ' . . . ASM.. Load·the assemblerandextended monitor. Transfercontrol.to:the assembler.· BASIC Load BASIC and transfer control to it; CALL Load contents of track "Tr', NNNN=Tf,S .sector ~'S;'' to memory locatkln ·"NNNN;'; . 09 Disableerror9.TQisisreqlriredtoreadsomeearlierversiou:fi1:es(V1.5,V2;0). DIRNN.. ·· Print sector map directory of track "NN''. · . .. . . ·· · · · ·.. . EM Load the assembler and extended monitor. Transfereontrolto• the extended·· monitor. .. .··.··. ·.···· ..... ·.. . •. ·... ··•·.·.· .. ·•·.. ·.. ••····...... ·.. EXAM NNNN=TI Examinetrack'Ii. Load entire track contents, includingforntatting formation, ·. into location "NNNN''. · · GONNNN Transfer control to location "NNNN". HOME Reset· track countto .· zero and home. the current drive's head.to track· zero. · INIT .· Initialize the entire disk, i.e., erase the entire diskettec(ex'Cept track 0) and write new formatting information on each track. · · !NIT IT Same as "'!NIT'';. but only operates on track "TT''. •. ··· IONN,MM Chqesthe.inputI/0 distributorflagto "NN", and the outputflag to "MM'\ Se:e the table at the end of this app¢ndix for 110 flag. $t.ttings. ·· IO, MM Changes only the output flag; · •. IONN Changes only Jhe input flag~ ...... · . LOADFILNAM 1.,;oads named source file, "FILNAM'' .· into memory. LOADTI Loads source ·file iritomemory given $tarting tracknumber:"'rr ..; .MEM Sets the memoiy 110 device input · · · NNNN,MMMM· pointer .to. "NNNN;', ·and the output pointer to ''MMMM:': PUT FILNAM Si!ves s<>nrcefile.in memory onthe·named· diskfile·''...-ruNJ\M'\ PUT TT Saves SQutce file in memory on track "TT;', and follo:wibg traclcs, :RETASM Restart the. assembler .. ·. RETBAS · Restart ·BASIC•. RETEM Restart tne, Extehded•Monitor ..• RETMON Restart the Prom Mo~tor (via· RST ·vector). SAVE Save me~ froi:n location . . . . . tt,s = NNNN/P "NNNN" , ' SELECTX Select disk drive;"X" \Vhere''X"·can be, A, B, C,:or,D; ..Seleet ena.blesthe requested drive and homes the'11ea.d to track 0. . . . .·. XQTFILNAM Loadthefile, ''flLNAM" as if itwas,a.souree file,.and'transfercontrolto location$327E.· · . .

NOTE: . . . . --Only the first 2· characters are used in recognizing a command. The rest up to the blaqk are ignored. --The• line input buffer can. only hold 18 cbarac::ters including th~ return. -The DOS can be reentered ~t 9543 ($2547) ... · . ---File names must start with an ''A" to ''Z" and can be only 6 characters, long. . ~The. dictionary is always maintained on. disk. This. ·permits the •interchange of .disk~ttes:. ~The following control keys are valid: ...... · · •·· .CONTRQL-Q continue output from a CONTI{OL-S • ·· CONTROL---S stop output to the c~nso~e CONTROL-U delete entire line as input BACKARROW delete the last character typed. SHIFf-0 delete the last character (polled keyboards)

ERROR NUMBERS !---Can't read sector (parity error). 2-Can't write sector (reread error). 3-Track zero is write protected against that operation. 4--Diskette is write protected. 5-Seek error (track header doesn't match track). (5...... :-Drive not ready. 7-Syntax error in command line. ~Bad track number. 9-Can't find track header within one rev of diskette. A----Can't .find sector before one ·requested. B-Bad sector length value. C----Can't find that name in directory. D~Read/Write attempted past end of named file!

MEMORY ALLOCATION 5" Floppies . • • . • • • . • • • . • . • • • ..... • ...... , ...... 8'' Floppies 0000-22FF BASIC or Assembler/Extended Monitor • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • , • • • • • • • 0000-,.22FF 2W0-22FE Cold start initialization on boot • • • • · • • • • • • • ·. • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • 2200-22FE 2300-265B Input/Output handlers • • • • • • • • • • · · · · · · · · · · · · · · • · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 2300-265B 265C-2A4A drivers · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · • · · 265C-2A4A 2A4B-2E78 OS-65D V3.2 operating system kernel · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ' · · 2A4B-2E78 2E79-2F78 Directory buffer • • • · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·. · · · · · · · · · · · · · · · · · · · · · · · · · · 2E79-2F78 2F79-3178 Page 0/1 swap buffer .... •. • • • • • • • • • • • • • • • • • · • · · · · · • · • • • • • • • • • • • • • • • • • • • ..... 2F79-3178 3179-3278 DOS extensions • • • • • • • • • · · · · · · • · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · • • • - - - 3279-327D Source file header • • • • • • • • • • · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · • · • • • • •; • • • 3l79-317D •• 327E- Source file • • • • • • • · • · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · • 317E DISKETTE ALLOCATION 5" Floppies • • • • • • • • • • • • • • • • • • • · • · • • • · · • • · • • • • • • • • • • • • • · • • · · · · · · · · • · · · · · · · · · · · · · · · · · · · · · · · · 8" Floppies 0-1 OS-65D V3.2 (boot-strap-loads to $2200 for 8 pages) ...... , . 0-1 2-6 9½ Digit Microsoft BASIC · · · · · · · · · · · · · · · · · · · :i · · · · · · · ' · · · · · · · · · · · · · · · · · · · · · · 2-4 7-9 Assembler-Editor ( if present} · · · · · · · · · · · · · · · · · ·. · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 5-6 10-11 Extended Monitor (if present)································ · · · · · · · .. · · · · · · ·7-7 12 Sector !-Directory, page L · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 8 Sector 2-Directory, page 2. Sector 3-BASIC overlays. Sector 4-GET/PUT overlays 13 Track0/Copier utility. (loads to $0200 for 5 pages). • • • • • • • · · · · · · · · · · · · · · • • · · · · · · · · 1 Sector· 2 14-38 User programs and OS-65D utility BASIC programs. • • • • · · · · · · · · • · • · • · • · • • • • • · • · 9-75 39 Compare routine, on some disks only. • • · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 76

1/0 FLAG BIT SETTINGS INPUT: Bit 0-ACIA on CPU board (terminal). BIT !-Keyboard on 540 board. BIT 2.:._UART on 430/550 board. BIT 3-NULL. BIT 4-Memory input (auto incrementing) . BIT 5-'--Memory buffered disk input. • BIT (5...... :-Memory buffered disk input. 35 BIT· 7-550 board ACIA ·. input. As selected by index ·at location $2323 (8995 decimal). OUTPUT: BIT 0--ACIA on CPU board (terminal). BIT 1-Video output on 540 board. •.•·t BIT 2-UARTon430/550 board. BIT 3-Line printerinterface. BIT 4--Memory output (auto· incrementing). ·1

BIT 5-Memory buffered disk output. i.!_· l3IT.6-Memory··buffered· disk output. : BIT 7--550 board ACIA output. As selected by index. NOTE: In the ASM $12E0 contains the number of lines per page and is set to top of page after each RE ASM.

36 APPENDIX M • THE FLOATING POINT ACCUMULATOR

The floating accumulator .(F AC) on disk based contains e + $80. systems is located in six bytes on page zero at addresses 2) is the mantissa. The binary point is assumed to be on $AE-$B3. See Note 2 for BASIC-in--ROM. The FAC is the left ofm. mis always normalized, that is, mis left used during all operations involving numeric variables. shifted and e is.decremented until the leftmost bit of Of interest to end users is the fact that when a BASIC mis 1. Thus, for example, .125 is stored as .1 x 2·11 statement like (binary) instead of .001 x 28• The mantissa is a 32 bit Y =USR(formula) number and is put into the FAC at $AF, %B0, $81, $B2. is executed, the value of the formula is loaded into the FAC before BASIC branches to the user's routine. The 3) The sign of the floating point number is put into the floating point format is sign bit (leftmost bit) ·of the byte with address $B3. This bit is 0 for a positive number and l for a negative ± .m x 28 number. The remaining bits are indeterminate and 1) e is the exponent. The byte with address $AE have no meaning.

Examples: • Number ( decimal) floating point (binary) In FAC (hex) 26.5 .110101 X 2131 85D400000000 --'26.5 - .110101 X 2181 85D400000080 .25 .1 X 2-: 1 7F8000000000 .2 .1100 X 2-1• 7ECCCCCCCD00

Note 1: When .2 is converted from decimal to binary, it becomes an infinite repeating number. The bar over the mantissa indicates that those four bits repeat forever. Thus, the mantissa is .110011001100110011001100110011001100--- when this is rounded to 32 bits it becomes .11001100110011001100110011001101

Note 2: For BASIC-in~ROM, the FACis five bytes at addresses $AC-$B0. the exponent ( + $80) isin the first bytc;the • sign is the sign bit of the last byte and the mantissa is the middle three bytes. 37 OPCODE TABLE LSD 0 I 2 3 4 5 6 7 8 9 A B C D E F MSD 0 BRK ORA-IND,X ORA-2,Page ASL-Z,Page PHP ORA-IMM ASL-A ORA-ABS ASL-ABS I BPL ORA-IND,Y ORA-2,Page,X ASL-Z,Page,X CLC ORA-ABS,Y ORA-ABS,X ASL·ABS,X )> 2 JSR AND-IND,X BIT-Z,Page AND-Z,Page ROL-Z,Page PLP AND-IMM ROL-A BIT-ABS AND-ABS ROL-ABS 3 BMI AND-IND',Y AND-Z,Page,X ROL-Z,Page,X SEC AND-ABS,Y AND-ABS,X ROL-ABS,X -a 4 RTI EOR-IND,X EOR-Z,Page LSR-2,Page PHA EOR-IMM LSR-A JMP-ABS EOR-ABS LSR-ABS -a 5 BVC EOR-IND,Y EOR-2,Page,X LSR-Z,Page,X CLI EOR-ABS,Y EOR-ABS,X LSR-ABS,X m u) 6 RTS ADC-IND,X ADC-2,Page ROR-Z,Page PLA ADC-IMM ROR-A JMP-IND ADC-ABS ROR-ABS (X) 7 BYS ADC-IND,Y ADC-Z,Page,X ROR-Z,Page,X SE! ADC-ABS,Y ADC-ABS,X ROR-ABS,X z 8 STA-IND,X STY-2,Page STA-2,Page STX-2,Page DEY TXA STY-ABS STA-ABS STX-ABS C 9 BCC STA-IND,Y STY-Z,Page,X ST A-2,Page,X STX-2,Page, Y TYA STA-ABS,Y TXS STA-ABS,X A LDY-IMM LDA-IND,X LDX-IMM LDY-2,Page LDA-2,Page LDX-2,Page TAY LDA-IMM TAX LDY-ABS LDA-ABS LDX-ABS ->< B BCS LDA-IND,Y LDY-Z,Page,X LDA-2,Page,X LDX-2,Page,Y CLV LDA-ABS,Y TSX LDY-ABS,X LDA-ABS,X LDX-ABS,Y C CPY-IMM CMP-IND,X CPY-2,Page CMP-Z,Page DEC-2,Page INY CMP-IMM DEX CPY-ABS CMP-ABS DEC-ABS z D BNE CMP-IND,Y CMP-2,Page,X DEC-2,Page,X CLD CMP-ABS,Y CMP-ABS,X DEC-ABS,X E CPX-IMM SBC-IND,X CPX-2,Page SBC-2,Page INC-2,Page INX SBC-IMM NOP CPX-ABS SBC-ABS INC-ABS F BEQ SBC-IND,Y SBC-2,Page,X INC-Z,Page,X SED SBC-ABS,Y SBC-ABS,X INC-ABS,X LSD-Least Significant Digit MSD-Most Significant Digit

______.._,_• .. ,,,., ... ,.~·,--~ .. --~"-~""'"'-,...------'•·~~_..,• ---~ .. ·.,.., .. , ,.· --~ .. ~~• ... ---•,-.---- ..- ...... - .. ~~ APPENDIX 0 • 6502 REFERENCE LIST 1. * How to Program by William Barden Howard W. Sams & Company, Inc. Indianapolis, IN 46268

2. 6502 Software Gourmet Guide and Cookbook by Robert Findley SCELBI Publications 20 Hurlbut Street Elmwood, CT 06110

3. The First Book of KIM

4. Programming a : 6502 by Caxton C. Foster Addison Wesley Publishing Company, Inc. Reading, MA 01867

5. 6502 Assembly Language Programming by Lance Leventhal Osborne/ McGraw" Hill

6. MCS6500 Microcomputer Family Programming Manual MOS Technology, Inc. 950 Rittenhouse Road Norristown, PA 19401

7. MICRO: The 6502 Journal P.O. Box 6502 Chelmsford, MA 01824

8. SY6500/MCS6500 Microcomputer Family Hardware Manual Synertek 3050 Coronado Drive Santa Clara, CA 95051

9. Programming the 6502 (Second Edition) by Rodney Zaks Sybex 2344 Sixth Street Berkeley, CA 94710

10. 6502 Applications Book by Rodney Zaks Sybex 2344 Sixth Street • Berkeley, CA 94710 39 1 L 6502 Games by Rodney Zaks Sybex 2344 Sixth Street Berkeley, CA 94710 12. Programming & Interfacing The 6502,. With. Experiments •I by Marvin L. De Jong Howard W. Sams & Co., Inc. I 4300 West 62nd Street t f Indianapolis, IN. 46268

13. * 65V Primer: The Workbook of Programming· exercises in machine code, using your machine's builtsin 65V monitor in ROM. Ohio Scientific 1333 S. Chillicothe Rd. Aurora, .OH 44202

* Available from OSI

• 40 INDEX

A D

Address ...... •...... 1 Delete ...... 8 Addressing Direct Addressing...... 3 Direct ...... 3 Division ...... 2 Immediate ...... 4 Implied...... 5 Indexed ...... •...... 4 Indirect ...... •...... 5 E ASCII Codes...... 3 2 Assembler ...... 1 Extended Monitor, ...... •. 15 Example ...... 10, 11 Example...... 10 Assembly Commands ...... 9 Error Codes ...... , ...... •...... 22 Language., ...... 1 F At (@) ...... 2, 15 File ...... 1

B

Back-arrow ...... 8, 35 I Break ...... •.... 1 Immediate Addressing ...... 4 Breakpoint...... 17 Implied Addressing...... Byte ...... I Indexed Addressing ...... 4 .Byte ...... , ...... 3 Indirect Addressing ...... 5 • INIZ ...... 8

C

Carriage Return (CR) ...... , ...... 1, 15 L Code Object ...... : ...... I Labels ...... 2 Source ...... I Line Feed (LF) ...... 1, 15 Constant Binary.•....•...... •...... 2 Decimal...... 2 Hex ...... 2 M Octal...... 2 CTRL Machine Language ...... •...... ! P ...... 8 Running Program ...... 14 Q •...... , ...... 34 M Command ...... 9, 17 s ...... 34 Monitor (Extended) ...... 15 u ...... 25, 35 +-(Backarrow) •...... 35 I. ...•...... •...... ····· 25 Y ...... , ...... 25 0 T ...... 25 R ...... 25 Object Code ...... 1 • E ...... 25 Operation Symbols ...... , ...... 2 41 p So~ Code;; ...... o~ ...... ,J ... ,...... 1 .. :symbol& •.. ~··•··"·"···:····· ...... ~ •. ::: •... ~ .. , ...... • 2.. Page;:~ .. , ...:.·; .•. ··.u•. ,...... ~ ...; .... ;·, ...... ;, ... ;... ~ ...... ;·; 1: Print~ ....: .....•...•... ~··············"············•········••,:~ ...... 8

R

.R Command.:, •.•... H ..:: ...... 11: RESEQ ...... •. n.~•···•···••.. ••···•··············••..-.•···•······~••.•··•·>g u -· . - .. u~arrowi ...... ····················'.·'·•····;· l,,8~• 15 USR Function ...•...... ,_. .•...... :.; ..~.'.; •..... ; ..... 20 S:

:SHIFT·

N.~ ...... u ...... l, 8 w o ...... ~ ...... s, .35 P ...... ,:., ...... :••·•.' l

42