?_{lz36502SDK Help fileBrowseButtons()Zmain mainE56502SDK Help5   }Q6"QEm##R+h52Zsecondaryglossary6502SDK Help5   }Q6"QEg##R+h52/&;)z4sw9Fw  |CONTEXTs|CTXOMAPb|FONTc`|KWBTREEqc|KWDATAb|KWMAP`c|SYSTEM|TOPICG|TTLBTREEkF뙐vv+F;vu;Fu&FG&vv{+F^_]UWVFFv v F^ &@2F%1F&@2F%1Ff& A2%1FF&A2%1FF&A2%1FF&B2%1FF&B2%1FF&B2% 1FF& B2%@1FFFF&"B2%1Ff&'A2%1Ff&o 2% 1Ff&w*2%1F&|.&?r%^ |?@s-^&F$^ W- ^&&WFFV^F&&WFtV^ |,r#|@sG-^F&!GW- ^F&&WFt5^ |@}G,^F&G- ^F&Ft6^ |@}G,^F&G- ^F&Ft6^ |@}G,^F&G- ^F&Ft6^ |@}G,^F&G- ^F&F t6^ |@}G,^F&G- ^F&F@t6^  | @}G ,[[ 6B19BEIndexpI ' 6502 Software Development Kitv. 1.0 BETA - 1996 by Valerio GioncoBp- (#6502SDK is an integrated development environment for writing and testing machine language code for 65xx based machines. The kit includes:W$3 4IPu-multi-file text editor;-assembler with macro capabilities;-project manager;-software emulator for the processor, that allows you to run and trace your code, set breakpoints, watch variables and memory, ...-a disassembler for object code;- some other stuff I won't discuss here.pN j\I5ńa○Ή... and all that is FREE!. If you have a Commodore 64, a VIC-20, an old Apple, or any other machine and you still spend time programming them, you'll save a lot of time.The integrated assembler supports macros with parameters and local labels, file inclusion, N-level forward referencing, and all what I was able to imagine. (However, only 6502 documented opcodes are supported.Assembly languageEditorEmulatorObject disassembleriEt SXeN(@E8 Memory dumpRegister windowStackVariable watchLegal stuffAcknowledgmentsContacting the AuthorCommodore 64 and VIC-20 are trademarks of Commodore Electronics Ltd.Apple is a trademark of Apple Computers Ltd.B12Assembly language[E2P p U򈉂㠌r̉O]iysӉ6502 assembly language.SyntaxOpcodesOperandsDirectivesScope rules@r1 r> Assembly syntaxzK2/ . Assembly syntaxEach line of code must be a statement, in the form:J&r6$ L [label] opcode [operand] [comment]#Y c yy 3#8҉  or may consist in:-a processor directive-a pre-processor directive (always starting with '#' )-a macro call;-a comment, a label or a blank line.Labels are identifiers followed by ':'. Note that labels are symbols whose value is assigned at compile time: you are allowed to use them anywhere.Comments begin with ';' and terminate with the line.Example:;the following lines are validlda#$00;this is a valid line6m 8 > rts;this is another valid line; this is a comment;label1: jmp $ff00 ;this is a line with labellabel2:label3:inx ;note that 'label2' and 'label3' have the same value.inclabel1 ;WITHOUT ':' !!!!rtsY > ' UPNote:I'm sorry, but you MUST put a ':' before labels. I don't like this myself (in fact the first version of the assembler used the label alone) but there was a problem: I had no way do distinguish between a label and a wrong-typed opcode. For instance, if you write "RTZ" instead of "RTS", the effect is to eliminate the instruction (that might cause catastrofic effects) because the assembler thinks "RTZ" to be a label.Am  1 /@Assembly opcodes)> ? L  6502 Assembly opcodesCurrently, the assembler only supports 6502 documented opcodes. Opcodes may be either in capital letters or not (the assembler is always case-insensitive for opcodes).Note that you already are supposed to know 6502 assembly language.Valid opcodes are:ADC AND ASL BCC BCS BEQ BIT BMI BNE BPL BRK BVC BVS CLC CLD CLI CLV CMP CPX CPY DEC DEX DEY EOR INC INX INY JMP JSR LDA LDX LDY LSR NOP ORA PHA PHP PLA PLP ROL {T /@'  ROR RTI RTS SBC SEC SED SEI STA STX ST/@> YTAX TAY TSX TXA TXS TYA Bq@1Zq@EAssembly operandsU,/@@) "X Assembly operandsThe operand must be:&q@AV zP: 뫉  -the A register (as in ASL A )-a constant expression. (as in LDX $1000 )-a constant expression and the X or Y register, following the addressing rules for the 6502 (as in LDX $1000,X )@B' All expressions MUST resolve to a constant in compile time, and may be surrounded by parentheses to indicate indirect addressing.Allowed addressing modes vary from instruction to instruction. Here is a complete list of modes:a0A\C1 2`  nn :8-bit constantnnnn :16-bit constant-BC* $ USV\CE "S             modeexamplebytes usedimmediateLDA #nn2absoluteLDA nnnn3page zeroLDA nn2accumulatorASL A1impliedRTS1indexed indirectLDA (nn,X)2indexedLDA (nn),Y2page zero, XLDA nn,x2page zero, YSTX nn,y2absolute, XLDA nnnn,x3absolute, YLDA nnnn,y3indirectJMP (nnnn)3relativeBNE (nnnn)2ECE1EKAssembly expressions1EE#  Expressions*E)GH ^Expression must resolve to constants at compile time. You are not allowed to write expressions like n=3*A (where A is the accumulator register), because this makes no sense.Numeric constants are assumed to be:E@HB RP:   -Hexadecimal if beginning with '$' ;-Octal if beginning with '@'-Binary if beginning with '%'-Decimal otherwise.To assign an expression to a symbol, simply use the EQU directive or the '=' sign:4)GtH# " n EQU 3*$1007@HH# (is equivalent to:2tHH#  n = 3*$100(HI% P:HKo M   You can use expressions in every place you should put a constant operand. For example, you can write:addr_lequ$1000addr_hequaddr_l+1ncyclesequ 10valueequ%01001011label1:ldxncycles *2sta (addr_l),Xdexsta(addr_h),Xdexbnelabel1Note that label1 is a label (and is followed by ':' ), and addr_l, addr_h, ncycles, value are symbolic constants (NOT followed by '':' ).}BIK; F"'1)ՉfOperators8- and 16-bit operationsForward referencesCKK1KMAssembly operators_6K9L) "l Operators You can use the following operators: KEMv -9arithmetic operators:+-*/logical operators:|bitwise OR&bitwise AND!bitwise NOTothers:<low byte>high bytefB9LM$ You can also use parentheses to override operator precedences.IEMM1eM8- and 16-bit operationsMN0 .E 8- and 16-bit operationsThe constants you calculate can only be 8- and 16-bit wide. A numeric constant N is assumed to be 8-bit wide if (and only if! ):nM@Z )q N<256 and length(N)<=8for binary (%) numbers;N<256 and length(N)<=4for octal (@) numbers;N<256 and length(N)<=2for hex ($) numbers;N<256 for decimal numbers.So, if you want to write a lda to location N@M$0020 using 16-bit addressing mode, you must write/ No#  lda $00200 @# instead of- ò#  lda $20xND* $qCharacter constants are always 8-bit.The width of operation results is:̀ZL ffor arithmetic operators:always 16 bit;for bitwise AND (&) and OR (|)8 bit if both operands are 8-bit; 16 bit otherwise;for bitwise NOT (!)the same of the operand;for < and >8 bit.D0 .%qNote that all calculations are made with UNSIGNED numbers, and you must take care about overflows and underflows.Note also that if the size of a forward-referenced operand is unknown, the assembler forces it to be 16 bit because he needs to calculate instruction widths immediately. So, if you want to force an operand to be 8-bit wide, you must use the '<' operator to take only the low byte. CZ_1_Forward referencesg1 0 Forward referencesSymbolic constants may be forward-referenced. This means that you can build an expression making use of other constants that are yet undefined. For example, the following code is correct:9_M h9  label4:noplda#$00staconst2rtsconst2equconst3+1const3equH ^  assembles a word for each entry in the argument list, in high-low order;For example:ORG$1000DB$12, $34, $45, $67DW$1234, $5678DD$9876, $8877generates the following object code:$1000> 12 34 45 67 34 12 78 56 98 76 88 77The DB directive also allows to assemble ASCII strings, one byte for character. For example:4r$   DB "abcdefg"T>+ &writes in memory the string "abcdefg". You can also used mixed syntax, like:X5rI# j DB "String", 'c', h', 'a', 'r', $10, %0100100, @67< 1f EQU and '='MI5 : EQU and '='You can use EQU or '=' to define symbols. The syntaIx is=P# 4 symbol EQU expression(x#  or;P# 0 symbol = expressionx6 :  fwhere symbol must be a valid symbol ( A-Z, a-z, 0-9 , not beginning with a digit). The maximum length for a symbol is 32 characters.You can use forward-referenced expressions (see forward reference).C1 #include directive{Ry) " #include directiveYou can include another file inside your code by writing:9# , #include "filename"y& When the assembler finds this directive, it starts assembling the included file, then it gets back to the main file. File inclusion can be nested one inside another with a maximum depth of 10 levels. Be careful to avoid circular inclusions.A1Macro processingkyO l9   Macro processingThe assembler allows macro definitions. Note that a macro is NOT a procedure, and its code is copied in every point the macro is instanced. Macro is just a lexical operation that substitutes the macro call with his body.The syntax for defining a macro is:#macro [ [param1 [, param2, ..., paramN] ] ][body of the macro]#endmThe macro may have N parameters param1,...,paramN that you can use to pass a string to the macro. Not that parameters are strings: they are copied "as they are" inside the code.~< F The names defined inside a macro are local names, and cannot be used outside the macro itself. If a name in a macro is equal to an external name, the local name takes precedence over the external one.You are always allowed to call a macro inside a macro definition, but macros cannot call themselves. You also cannot call a macro that has not been defined yet.Example:;macro without parameters#macro blacklda #$00sta $d020sta $d021#endm/y> J ;macro with 3 parameters#macro addition[op1, op2, result]lda op1clcadc op2sta result#endm;now let's call the macros:org $c000blackaddition [$20, #$10, var]; var = $20 + #$10 rts;holds space for the resultvardb 0L~1s Scope rules for identifiersh?a) "~ Scope rules for identifiers.Remeber the following rules:f3 4P:An included file is part of the main file. Identifiers defined and/or used in the included files follow the same rules of those in the main file.Identifiers defined outside macros can be used anywhere in the file;Identifiers defined inside a macro can only be used inside the macro itself;Maybe in a future I will add external names declarations.&a # ; [1[The editors 7 < The editorFor editing a source file, you can use an external text editor or the internal editor. The internal editor has some limitations, but it allows to compile the source code directly, by pressing ALT+F9. The internal text editor cannot manage files larger than 32K (but you can use #include to join files) and allows standard cut-copy-paste operations.= [B1BThe emulatorH+ $; The emulator6502SDK includes a software emulator for 6502 processor. Emulating a processor via software is not a difficult job, but it's necessary a complete knowledge on how the whole thing works.There are still a lot of obscure points in 6502 (for me, at least). For example:B[3 4%PHow does decimal mode works exactly, especially when operands [are NOT valid BCD numbers?When the processor encounters an undocumented opcode, what it really happens? Somebody says that newer (CMOS) versions of 6502 ignore those opcodes and execute NOP instead. But do they fetch operands or not?I have a Commodore 64 with a 6510. Do 6502 instructions (and bugs...) are the same of the 6510?E- (1I didn't want to build a perfect emulator. So I didn't care about undocumented opcodes and I tried to emulate some 6510 bugs, hoping that 6502 would behave in the same way.The emulator includes a 64K memory, the registers and an object code interpreter. The stack doesn't need to be emulated because in real 6502 it is located in main memory (from $0100 to $ 01FF). Maybe one day I'll add the emulation code for 6510 I/O port located in $0000 - $0001.You are allowed to do everything you might need to test and debug your code:[0 .cPstep-by-step execution;breakpoints insertion;register value change (including ALL registers and flags);RESET, IRQ, NMI simulation;variables inspection, and so on...($ H1U The object disassembler7 <  The object disassembler/debugger.The disassembler allows to examine assembler code for programs resident in the emulator memory. You can also follow the program flow in step-by-step execution (F7) and place breakpoints (by double-clicking with the mouse on the line where you want the breakpoint to be set or eliminated).Note that disassembling an object code sometimes gives ambiguous results. For example, if you have the following source code:ADDRESS CODE OBJECT FU E X  $1000: LDA #$A2 A9 A2$1002: STA $60EA 8D EA 60and you disassemble it from $1001 instead of $1000, you will find the following code:$1001: LDX #$8D A2 8D$1003: NOP EA$1004: RTS 60The actual position of the Program Counter is marked with '>>', and breakpoints are evidenced in red. You can use the vertical scrollbar to move the disassembling window.When the disassembler finds a byte that does not represents a valid opcode, it marks it with '???'.@ 1  The memory dump`'U  9 @O Memory dumpYou can watch what happens to memory in the Memory window. This window allows you to examine memory (in hexadecimal and ASCII).Unprintable ASCII characters are represented with '.' .You can perform some operations (like Fill, Copy, Go To...) with the right mouse button.E : 1:  The registers window`  ) " Registers windowThis window allows you to read and modify the contents of 6502 registers.A:  15  The stack window  * " Stack windowIn this window you can see the contents of the stack area. The line at the top of the window is the one pointed to by SP.Note that, for 6502, stack area is always from $0100 to $01FF.A 9 1@9 8The watch window 8)  Watch window6502SDK allows you to observe the value of your variables. In the watch window you can see a list of your watch expressions, the corresponding memory location and the value stored in the location.< 9 t1ttCFLegal stuff18@8 > Legal stuffThe program is free software: you can copy it freely (you are welcome to do so!) but you CANNOT make money out of it. Be warned: if you'll ask money for this software I'll get VERY MAD! (ah, ah...).If you use the program, you are asked to send a postcard to my address (see "contacting the Author) just to track the spret@8ading of 6502SDK.You should have received a copy of the GNU General Public License along with this program: here you can find all the legal stuff I cannot write.*tB1 0Here are reported GNU warranty disclaimers: NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTYFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHENOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIESPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSEDOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OFMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK ASF@!E, &5TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THEPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITINGWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/ORREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISINGOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED"BCF( TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BYYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHERPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THEPOSSIBILITY OF SUCH DAMAGES.A!EF1FHAcknowledgementsk<CFH/ ,y AcknowledgementsThe integrated assembler of 6502SDK has been written using GNU programs FLEX and BISON, included in DJGPP compiler distribution. Thanks to Robert Corbett and Richard Stallman (for BISON) and to Vern Paxson (for FLEX).Some notes about 65xx decimal mode have been released on the Net by:- John West (john@ucc.gu.uwa.edu.au)- Marko Mkel (msmakela@kruuna.helsinki.fi)Thanks also to Ville Muikkula for C64CONNECT (the fastest utility to transfer data from/to a C64 I've ever tried) and to Wolfgang Lorentz and Miha Peternel for PC64 and C64S.FF5I15IJContacting the Author HAJ1 0 Contacting the AuthorYou can send E-mail to s74454@cclix1.polito.it but I think will be deleted in a future (perhaps before 1998).You can send postcards (but also letters, money, food, wine, everything...) to:wM5IJ* $Valerio Gionco26, viale Europa14022 Castelnuovo Don Bosco (Asti)ITALY*AJJ%  1J1 HelvTimes New RomanSymbolArialMS Serift wt~hcMS Sans SerifndContTimesndAppqchPathHelveticapicNohfsCourier NewcoBackgCourierrFranklin GothicCubase$    A8Qf fmmQQQQQQm QmQ_ QImIf  fWm m <   Qfm _QfQ<<f   /&;)i24#FFOb.C*C!#endm#include#macro $%&*+ -$/(<,=0>8@<|@8-bit and 16-bitDAcknowledgementsHAddressing modesLArithmetic operatorsPASCII stringsTAssemblyXAuthor\Comment`ConstantsdContacting the AuthorhDBlDDpDebuggertDirectivesxDisassemblerDumpDWEditorEmulatorEQUExpressionsForward referencesIdentifiersIncluding filesIndexLabelLabelsLanguageLegal stuffLicenseLogical operatorsMacrosMemoryMemory tablesNumeric constantsOpcodesOperandOperand widthsOperandsOperatorsORGParenthesesRAMregistersScope rulesStack Start address$Syntax(Variables,Warranty0Watch4PFVR-#+Pb.Eb.E[-#FW b._Ib.pEmE vEFRAcknowledgements% vv1D@Acknowledgements/-#vvy b.Jb.En֌E -#F& b.Jb.̍EnpEo4-# b.Jb.fEnEV u& vx؋N~N~~NQWvVPKFVRPvv욾ktF^&+G~&E++FRPvNQVQv!& ^&w&O&O^&o"&_$&O+^_]UWVvvv v fnV uj-#&|b.Gb.E\ET |9?Ì@@؋I Ҹ؋F Ft +^v&^_]UWVvvvvfn؏V u /& v /^F&NV V+^&9N^&&WF&9T|&9sVvvk FG뽉~&&WF&9TN|&9wG~ F t0ƌRPvvFV욾kǎRPvvF PW!~ ^&~F FtF^&+v&wF&G^&^_]UWVvvv v fnaV uuF&|&DFD@@ȉVv5/&;)LzFsF&IndexAssembly languageAssembly syntax Assembly opcodesAssembly operandsmAssembly expressionsQAssembly operators_8- and 16-bit operationsForward referencesDirectivesfORG directiveDB, DD and DW directives EQU and '=' #include directivefMacro processing<Scope rules for identifiersThe editorWThe emulatorThe object disassemblerThe memory dumpThe registers window<The stack window The watch window Legal stuff AcknowledgementsIContacting the Authorv;vڋȋFV | =v+Ҹ;|;vȋVvvvvbS" +)vN+ҋNй!V+ҋNй!ViFϋ؋FV"ӉFVF ؋FVƃӉFVF FuF+҉FV u FFF+҉FV u FFFV;V| ;FvVFN^ | v+۹;|;vP+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