March 9th, 1993 A 6502 assembler Using the 6800 assembler source code of ASxxxx version 1.50 by Alan R. Baldwin, I have written a couple of files to make the assembler support 65C02. For those who are familiar with NMOS 6502s, i.e. the processors in the Commodore microcomputers, for instance, there are a couple of new instructions that work only in the CMOS 6502 family. I have used the Rockwell document 29651N52, a data booklet of R65C02, R65C102 and R65C112 as a source of opcode information. The instruction syntax of this assembler may be somewhat weird for the 6502 phreaks, for example you have to write `bbr0 memory,label'. In addition to that, I had to change the familiar indirection parentheses () with bracket parentheses [] in order to avoid heavy, error-prone modification of asexpr.c and other modules that participate in parsing the statements. Directory listing As I have only exploited Alan R. Baldwin's work, not all files in this directory are written by me. A complete commented directory listing of this archive file follows: Documentation READ.ME This file * ASMLNK.DOC Instructions for the ASxxxx cross assemblers R65C02.ASM Rockwell 65C02 instruction set Common ASxxxx files * ASM.H Header file for the ASxxxx cross assemblers + ASMAIN.C Main module of the cross assemblers A bug in parsing the command line is fixed by me * ALLOC.H Definitions for memory allocation functions referenced to by both ASxxxx and ASLINK You may have to copy this to your INCLUDE subdirectory in order to ensure that the compiler finds this. * ASLEX.C * ASSYM.C * ASSUBR.C Miscellanous ASxxxx modules * ASDATA.C * ASLIST.C * ASOUT.C * ASEXPR.C The module that parses most of the statements + ASEXPR1.C Improved version of ASEXPR.C (see below) Replace the old ASEXPR.C with this if you want to use this. 6502 specific ASxxxx files AS6502.MAK File for compiling the 6502 compiler with NMake and Microsoft C/C++ 7.0 AS6502.PRJ A corresponding file for Borland's Turbo C AS6502.BLD A makefile for DECUS C R6502.H Header file for the R65C02 specific C files R52EXT.C Contains some information of this R65C02 part R52PST.C Contains the R65C02 op-codes R52ADR.C Determines addressing modes of instruction parameters R52MCH.C Processes an instruction ASLINK files ASLINK.MAK Makefile for NMake and Microsoft C/C++ 7.0 * ASLINK.PRJ Makefile for Borland's Turbo C * ASLINK.BLD Makefile for DECUS C * ASLINK.H Header file for the ASLINK linker utility * LKMAIN.C * LKHEAD.C * LKAREA.C * LKDATA.C * LKEVAL.C * LKLEX.C Miscellanous ASLINK modules * LKSYM.C * LKRLOC.C * LKLIST.C * LKIHX.C * LKS19.C MS-DOS executables AS6502.EXE 6502 compiler. + ASLINK.EXE Linker program compiled with modified ASLINK.H (see below) Note: The files marked with `*' are written by Alan R. Baldwin. The files marked with `+' are cosmetically changed by me. Unmarked files are heavily changed or created by me. You can find the complete ASxxxx package on the anonymous FTP server shop-pdp.kent.edu. The files are in the subdirectories of the directory du3:/cug292. (The subdirectories have the extension dsk.) The package is in a single file on SIMTEL20 servers. For example at the main Finnish FTP server funic.funet.fi it is in the file /pub/msdos/SIMTEL20-mirror/crossasm/cug292wk.zip. Some improvements and improvement proposals to the original files ASMAIN.C The file ASMAIN.C had an error that occurs when you place an -l, -o or -s switch after a source file name. I added two lines to monitor the inpfil variable in the beginning of the switch processing block in order to remove this bug. I did not correct the handling of MS-DOS style file names. If you specify a directory path preceding the file name, correct behaviour of the program would be that the resulting files would be created in the default directory instead of the directory that contain the respective source file. A real bug occurs when the path specification contains dots. ASEXPR.C The compiler produces normally `r' errors with the following code that is a completely legal procedure to set file name attributes with Commodore PET/Vic20/C16/+4/C64/C128 Kernal: lda #nmend-name ldx #name ; instead of a relocatable label jsr setnam ... name: .ascii "FILENAME" nmend: If you want to get rid of those annoying messages, remove the last call to function abscheck from the 181st line of ASEXPR.C. The MS-DOS executable as6502.exe was compiled using a corrected ASEXPR.C. To compile, you have to copy all the relevant files to same directory. In addition to the old DECUS C and Turbo C format build files there is a file for NMAKE and Microsoft C v7.0, AS6502.MAK. Refer to ASMLNK.DOC for more information of building the files. Another thing that you probably like to repair is that the compiler allows wrong use of the immediate operator #. So if you want to get a syntax error message when you write i.e. `bne #label' instead of `bne label', add a qerr call right before the getnb call at the 152nd line. And if you find the radix specification system difficult, the asexpr.c needs some modifications. Otherwise you can't write hexadecimal numbers comfortably, even if you had ordered .radix x. The figures may not start with a letter, in which case you have to add an extra 0 before them. But the combination 0d specifies decimal numbers and 0b binary numbers, so if the hexadecimal number starts with those, you have to write 0xb... or 0xd... A better way would be that you would specify the radix with the convenient $, % and &. But the latter two are reserved for arithmetics, so let's just use plain $ and $ followed by %, & or #. Examples of valid numbers would be $FCE2, $%1001011, $&377 and $#65535, and of course 1001011, 377 and 65535, if the respective .radix directive is used. But hexadecimal figures may still not start with a letter, they must start with a number or $. To enable numbers like this, copy the file ASEXPR1.C to ASEXPR.C and recompile. The file ASEXPR1.C contains all three modifications described here. The AS6502.EXE was compiled using ASEXPR1.C. ASM.H ASLINK.H You may find the original FILSPC specification too small. I changed it to 128 characters while compiling AS6502.EXE and ASLINK.EXE so that I could compile and link files that are in outside the default subdirectory. Summary If you notice any strange behaviour of as6502, feel free to send me E-mail and describe the problem. You can reach me both at Internet (Marko.Makela@Helsinki.FI) and at Bitnet (msmakela@finuh). Marko Mäkelä