CoCoAssembler

所属分类:图形图像处理
开发工具:Python
文件大小:0KB
下载次数:0
上传日期:2023-07-04 23:04:45
上 传 者sh-1993
说明:  用Python编写的Tandy Color Computer 1、2和3汇编程序,
(A Tandy Color Computer 1, 2, and 3 assembler written in Python,)

文件列表:
CODE_OF_CONDUCT.md (3354, 2023-06-19)
CONTRIBUTING.md (7834, 2023-06-19)
LICENSE (1063, 2023-06-19)
PULL_REQUEST_TEMPLATE.md (789, 2023-06-19)
assembler.py (5254, 2023-06-19)
cocoasm/ (0, 2023-06-19)
cocoasm/__init__.py (2, 2023-06-19)
cocoasm/exceptions.py (1520, 2023-06-19)
cocoasm/instruction.py (16552, 2023-06-19)
cocoasm/operand_type.py (802, 2023-06-19)
cocoasm/operands.py (28828, 2023-06-19)
cocoasm/program.py (7378, 2023-06-19)
cocoasm/statement.py (12257, 2023-06-19)
cocoasm/values.py (21676, 2023-06-19)
cocoasm/virtualfiles/ (0, 2023-06-19)
cocoasm/virtualfiles/__init__.py (0, 2023-06-19)
cocoasm/virtualfiles/binary.py (1060, 2023-06-19)
cocoasm/virtualfiles/cassette.py (11914, 2023-06-19)
cocoasm/virtualfiles/coco_file.py (2067, 2023-06-19)
cocoasm/virtualfiles/disk.py (28610, 2023-06-19)
cocoasm/virtualfiles/source_file.py (1932, 2023-06-19)
cocoasm/virtualfiles/virtual_file.py (5192, 2023-06-19)
cocoasm/virtualfiles/virtual_file_container.py (2601, 2023-06-19)
cocoasm/virtualfiles/virtual_file_exceptions.py (489, 2023-06-19)
codecov.yml (306, 2023-06-19)
file_util.py (5002, 2023-06-19)
requirements.txt (20, 2023-06-19)
test/ (0, 2023-06-19)
test/.coverage (53248, 2023-06-19)
test/__init__.py (0, 2023-06-19)
test/test_exceptions.py (1369, 2023-06-19)
test/test_integration.py (39133, 2023-06-19)
... ...

# CoCo Assembler and File Utility [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/craigthomas/CoCoAssembler/python-app.yml?style=flat-square&branch=main)](https://github.com/craigthomas/CoCoAssembler/actions) [![Codecov](https://img.shields.io/codecov/c/gh/craigthomas/CoCoAssembler?style=flat-square)](https://codecov.io/gh/craigthomas/CoCoAssembler) [![Dependencies](https://img.shields.io/librariesio/github/craigthomas/CoCoAssembler?style=flat-square)](https://libraries.io/github/craigthomas/CoCoAssembler) [![Releases](https://img.shields.io/github/release/craigthomas/CoCoAssembler?style=flat-square)](https://github.com/craigthomas/CoCoAssembler/releases) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://opensource.org/licenses/MIT) # Table of Contents 1. [What is it?](#what-is-it) 2. [Requirements](#requirements) 3. [License](#license) 4. [Installing](#installing) 5. [The Assembler](#the-assembler) 1. [Assembler Usage](#assembler-usage) 1. [Input File Format](#input-file-format) 2. [Print Symbol Table](#print-symbol-table) 3. [Print Assembled Statements](#print-assembled-statements) 4. [Save to Binary File](#save-to-binary-file) 5. [Save to Cassette File](#save-to-cassette-file) 6. [Save to Disk File](#save-to-disk-file) 2. [Mnemonic Table](#mnemonic-table) 1. [Mnemonics](#mnemonics) 2. [Pseudo Operations](#pseudo-operations) 3. [Addressing Modes](#addressing-modes) 1. [Inherent](#inherent) 2. [Immediate](#immediate) 3. [Extended](#extended) 4. [Extended Indirect](#extended-indirect) 5. [Direct](#direct) 6. [Indexed](#indexed) 7. [Indexed Indirect](#indexed-indirect) 8. [Program Counter Relative](#program-counter-relative) 6. [File Utility](#file-utility) 1. [Listing Files](#listing-files) 2. [Extracting to Binary File](#extracting-to-binary-file) 3. [Extracting to Cassette File](#extracting-to-cassette-file) 7. [Common Examples](#common-examples) 1. [Appending to a Cassette](#appending-to-a-cassette) 2. [Listing Files in an Image](#listing-files-in-an-image) 3. [Extracting Binary Files from Cassette Images](#extracting-binary-files-from-cassette-images) 3. [Extracting Binary Files from Disk Images](#extracting-binary-files-from-disk-images) # What is it? This project is an assembler for the Tandy Color Computer 1, 2 and 3 written in Python 3.6+. More broadly speaking, it is an assembler that targets the Motorola 6809 processor, meaning it targets any computer that used the 6809 as it's main CPU (e.g. the [Dragon 32 and 64](https://en.wikipedia.org/wiki/Dragon_32/64), [Vectrex](https://en.wikipedia.org/wiki/Vectrex), [Thomson TO7](https://en.wikipedia.org/wiki/Thomson_TO7), etc). It is intended to be statement compatible with any code written for the EDTASM+ assembler. The assembler is capable of taking EDTASM+ assembly language code and translating it into 6809 machine code. Current support is for 6809 CPU instructions, but future enhancements will add 6309 instructions. This project also includes a general purpose file utility, used mainly for manipulating `CAS`, `DSK`, and `WAV` files. The file utility specifically targets the disk file formats and cassette formats used by the Color Computer line of personal computers. --- # License This project makes use of an MIT style license. Generally speaking, the license is extremely permissive, allowing you to copy, modify, distribute, sell, or distribute it for personal or commercial purposes. Please see the file called [LICENSE](https://github.com/craigthomas/CoCoAssembler/blob/master/LICENSE) for more information. --- # Requirements The assembler can be run on any OS platform, including but not limited to: - Windows (XP, Vista, 7, 8, 10, 11, etc) - Linux (Ubuntu, Debian, Arch, Raspbian, etc) - Mac (Mojave, Catalina, Big Sur, Monterey, Ventura, etc) The only requirement is Python 3.6 or greater will need to be installed and available on the search path, along with the Package Installer for Python (`pip`). To download Python, visit the [Downloads](https://www.python.org/downloads/) section on the Python website. See the Python installation documentation for more information on ensuring the Python interpreter is installed on the search path, and that `pip` is installed along with it. --- # Installing There is no specific installer that needs to be run in order to install the assembler. Simply copy the source files to a directory of your choice. A zipfile containing the latest release of the source files can be downloaded from the [Releases](https://github.com/craigthomas/CoCoAssembler/releases) section of the code repository. Unzip the contents to a directory of your choice. Next, you will need to install the required packages for the file: pip install -r requirements.txt --- # The Assembler The assembler is contained in a file called `assmbler.py` and can be invoked with: python3 assembler.py In general, the assembler recognizes EDTASM+ mnemonics, along with a few other somewhat standardized mnemonics to make program compilation easier. By default, the assembler assumes it is assembling statements in 6809 machine code. Future releases will include a 6309 extension. --- ## Assembler Usage To run the assembler: python3 assembler.py input_file This will assemble the instructions found in file `input_file` and will generate the associated Color Computer machine instructions in binary format. You will need to save the assembled contents to a file to be useful. There are several switches that are available: * `--print` - prints out the assembled statements * `--symbols` - prints out the symbol table * `--to_bin` - save assembled contents to a binary file * `--to_cas` - save assembled contents to a cassette file * `--to_dsk` - save assembled contents to a virtual disk file * `--name` - saves the program with the specified name on a cassette or virtual disk file --- ### Input File Format The input file needs to follow the format below: LABEL MNEMONIC OPERANDS COMMENT Where: * `LABEL` is a 10 character label for the statement * `MNEMONIC` is a 6809 operation mnemonic from the [Mnemonic Table](#mnemonic-table) below * `OPERANDS` are registers, values, expressions, or labels * `COMMENT` is a 40 character comment describing the statement (must have a `;` preceding it) An example file: ; Print HELLO WORLD on the screen NAM HELLO ; Name of the program CHROUT EQU $A30A ; Location of CHROUT routine POLCAT EQU $A000 ; Location of POLCAT routine ORG $0E00 ; Originate at $0E00 START JSR $A928 ; Clear the screen LDX #MESSAGE ; Load X index with start of message PRINT LDA ,X+ ; Load next character of message CMPA #0 ; Check for null terminator BEQ FINISH ; Done printing, wait for keypress JSR CHROUT ; Print out the character BRA PRINT ; Print next char MESSAGE FCC "HELLO WORLD" FDB $0 ; Null terminator FINISH JSR [POLCAT] ; Read keyboard BEQ FINISH ; No key pressed, wait for keypress JMP $A027 ; Restart BASIC END START --- ### Print Symbol Table To print the symbol table that is generated during assembly, use the `--symbols` switch: python3 assembler.py test.asm --symbols Which will have the following output: -- Symbol Table -- $A30A CHROUT $A000 POLCAT $0E00 START $0E06 PRINT $0E11 MESSAGE $0E1E FINISH The first column of output is the hex value of the symbol. This may be the address in memory where the symbol exits if it labels a mnemonic, or it may be the value that the symbol is defined as being if it references an `EQU` statement. The second columns is the symbol name itself. --- ### Print Assembled Statements To print out the assembled version of the program, use the `--print` switch: python3 assembler.py test.asm --print Which will have the following output: -- Assembled Statements -- $0000 NAM HELLO ; Name of the program $0000 CHROUT EQU $A30A ; Location of CHROUT routine $0000 POLCAT EQU $A000 ; Location of POLCAT routine $0E00 ORG $0E00 ; Originate at $0E00 $0E00 BDA928 START JSR $A928 ; Clear the screen $0E03 8E0E11 LDX #MESSAGE ; Load X index with start of message $0E06 A680 PRINT LDA ,X+ ; Load next character of message $0E08 8100 CMPA #0 ; Check for null terminator $0E0A 2712 BEQ FINISH ; Done printing, wait for keypress $0E0C BDA30A JSR CHROUT ; Print out the character $0E0F 20F5 BRA PRINT ; Print next char $0E11 48454C4C4F MESSAGE FCC "HELLO WORLD" ; $0E1C 0000 FDB $0 ; Null terminator $0E1E AD9FA000 FINISH JSR [POLCAT] ; Read keyboard $0E22 27FA BEQ FINISH ; No key pressed, wait for keypress $0E24 7EA027 JMP $A027 ; Restart BASIC $0E27 END START ; A single line of output is composed of 6 columns: Line: $0E00 BDA928 START JSR $A928 ; Clear the screen ----- ------ ----- --- ----- ------------------ Column: 1 2 3 4 5 6 The columns are as follows: 1. The offset in hex where the statement occurs (`$0E00`). 2. The machine code generated and truncated to 10 hex characters (`BDA928`). 3. The user-supplied label for the statement (`START`). 4. The instruction mnemonic (`JSR`). 5. Operands that the instruction processes (`$A928`). 6. The comment string (`Clear the screen`). --- ### Save to Binary File To save the assembled contents to a binary file, use the `--to_bin` switch: python3 assembler.py test.asm --to_bin test.bin The assembled program will be saved to the file `test.bin`. Note that this file may not be useful on its own, as it does not have any meta information about where the file should be loaded in memory (pseudo operations `ORG` and `NAM` will not have any effect on the assembled file). **NOTE**: If the file `test.bin` exists, it will be erased and overwritten. --- ### Save to Cassette File To save the assembled contents to a cassette file, use the `--to_cas` switch: python3 assembler.py test.asm --to_cas test.cas This will assemble the program and save it to a cassette file called `test.cas`. The source code must include the `NAM` mnemonic to name the program (e.g. `NAM myprog`), or the `--name` switch must be used on the command line (e.g. `--name myprog`). The program name on the cassette file will be `MYPROG`. **NOTE**: if the file `test.cas` exists, assembly will stop and the file will not be overwritten. If you wish to add the program to `test.cas`, you must specify the `--append` flag during assembly: python3 assembler.py test.asm --to_cas test.cas --append To load from the cassette file, you must use BASIC's `CLOADM` command as follows: CLOADM"MYPROG" --- ### Save to Disk File To save the assembled contents to a disk file, use the `--to_dsk` switch: python3 assembler.py test.asm --to_dsk test.dsk This will assemble the program and save it to a disk file called `test.dsk`. The source code must include the `NAM` mnemonic to name the program on disk (e.g. `NAM myprog`), or the `--name` switch must be used on the command line (e.g. `--name myprog`). The program name on the disk file will be `MYPROG.BIN`. **NOTE**: if the file `test.dsk` exists, assembly will stop and the file will not be updated. If you wish to add the program to `test.dsk`, you must specify the `--append` flag during assembly: python3 assembler.py test.asm --to_dsk test.dsk --append To load from the disk file, you must use Disk Basic's `LOADM` command as follows: LOADM"MYPROG.BIN" --- ## Mnemonic Table Below are the mnemonics that are accepted by the assembler (these mnemonics are compatible with EDTASM+ assembler mnemonics). For the mnemonics below, special symbols are: * `A` - 8-bit accumulator register. * `B` - 8-bit accumulator register. * `CC` - 8-bit condition code register. * `D` - 16-bit accumulator register comprised of A and B, with A being high byte, and B being low byte. * `M` - a memory location with a value between 0 and 65535. * `S` - 16-bit system stack register. * `U` - 16-bit user stack register. * `X` - 16-bit index register. * `Y` - 16-bit index register. Note that the operations described below may use different addressing modes for operands (e.g. `LDA` may use immediate, direct, indexed or extended addressing to load values). See the section below on addressing modes, and consult the MC6809 datasheet for more information on what addressing modes are applicable, as well as the number of cycles used to execute each operation. --- ### Mnemonics | Mnemonic | Description | Example | |----------|----------------------------------------------------------------------------------|----------------| | `ABX` | Adds contents of `B` to value in register `X` and stores in `X`. | `ABX` | | `ADCA` | Adds contents of `A`, memory value `M`, and carry bit and stores in `A`. | `ADCA $FFEE` | | `ADCB` | Adds contents of `B`, memory value `M`, and carry bit and stores in `B`. | `ADCB $FFEF` | | `ADDA` | Adds contents of `A` with memory value `M` and stores in `A`. | `ADDA #$03` | | `ADDB` | Adds contents of `B` with memory value `M` and stores in `B`. | `ADDB #$90` | | `ADDD` | Adds contents of `D` (`A:B`) with memory value `M:M+1` and stores in `D`. | `ADDD #$2000` | | `ANDA` | Performs a logical AND on `A` with memory value `M` and stores in `A`. | `ANDA #$05` | | `ANDB` | Performs a logical AND on `B` with memory value `M` and stores in `B`. | `ANDB $FFEE` | | `ANDCC` | Performs a logical AND on `CC` with immediate value `M` and stores in `CC`. | `ANDCC #$01` | | `ASLA` | Shifts bits in `A` left (0 placed in bit 0, bit 7 goes to carry in `CC`). | `ASLA` | | `ASLB` | Shifts bits in `B` left (0 placed in bit 0, bit 7 goes to carry in `CC`). | `ASLB` | | `ASL` | Shifts bits in `M` left (0 placed in bit 0, bit 7 goes to carry in `CC`). | `ASL $0E00` | | `ASRA` | Shifts bits in `A` right (bit 0 goes to carry in `CC`, bit 7 remains same). | `ASRA` | | `ASRB` | Shifts bits in `B` right (bit 0 goes to carry in `CC`, bit 7 remains same). | `ASRB` | | `ASR` | Shifts bits in `M` right (bit 0 goes to carry in `CC`, bit 7 remains same). | `ASR $0E00` | | `BCC` | Branches if carry bit in `CC` is 0. | `BCC CLS` | | `BCS` | Branches if carry bit in `CC` is 1. | `BCS CLS` | | `BEQ` | Branches if zero bit in `CC` is 1. | `BEQ CLS` | | `BGE` | Branches if negative and overflow bits in `CC` are equal. | `BGE CLS` | | `BGT` | Branches if negative and overflow bits are equal, and zero bit is zero in `CC`. | `BGT CLS` | | `BHI` | Branches if carry and zero bit in `CC` are 0. | `BHI CLS` | | `BHS` | Same as `BCC`. | `BHS CLS` | | `BITA` | Logically ANDs `A` with memory contents `M` and sets bits in `CC`. | `BITA #$1E` | | `BITB` | Logically ANDs `B` with memory contents `M` and sets bits in `CC`. | `BITB #$1E` | | `BLE` | Branches if negative and overflow bits are not equal, or zero bit is 1 in `CC`. | `BLE CLS` | | `BLO` | Same as `BCS`. | `BLO CLS` | | `BLS` | Branches if zero bit is 1, or carry bit is 1 in `CC`. | `BLS CLS` | | `BLT` | Branches if negative bit is not equal overflow bit in `CC`. | `BLT CLS` | | `BMI` | Branches if negative bit is 1 in `CC`. | `BMI CLS` | | `BNE` | Branches if zero bit is 0 in `CC`. | `BNE CLS` | | `BGE` | Branches if negative bit is 0 in `CC`. | `BGE CLS` | | `BRA` | Branch always. | `BRA CLS` | | `BRN` | Branch never - essentially 2-byte `NOP`. | `BRN CLS` | | `BSR` | Saves the value of `PC` on the `S` stack and branches to subroutine. | `BSR PRINT` | | `BVC` | Branches if overflow bit is 0 in `CC`. | `BVC CLS` | | `BVS` | Branches if overflow bit is 1 in `CC`. | `BVS CLS` | | `CLRA` | Zeroes out the `A` register, and clears `CC`. | `CLRA` | | `CLRB` | Zeroes out the `B` register, and clears `CC`. | `CLRB` | | `CLR` | Zeroes out the memory contents `M` and clears `CC`. | `CLR $01E0` | | `CMPA` | Subtract value from `A` register, and sets bits in `CC`. | `CMPA #$1E` | | `CMPB` | Subtract value from `B` register, and sets bits in `CC`. | `CMPB #$1E` | | `CMPD` | Subtract value from `D` register, and sets bits in `CC`. | `CMPD #$1E1F` | | `CMPS` | Subtract value from `S` register, and sets bits in `CC`. | `CMPS #$1E1F` | | `CMPU` | Subtract value from `U` register, and sets bits in `CC`. | `CMPU #$1E1F` | | `CMPX` | Subtract value from `X` register, and sets bits in `CC`. | `CMPX #$1E1F` | | `CMPY` | Subtract value from `Y` register, and sets bits in `CC`. | `CMPY #$1E1F` | | `COMA` | Perform logical complement of value in `A` and store in `A`. | `COMA` | | `COMB` | Perform logical complement of value in `B` and store in `B`. | `COMA` | | `COM` | Perform logical complement of value in memory location `M` and store in `M`. | `COM $FFEE` | | `CWAI` | Clear `CC` register, push state onto stack, and wait for interrupt. | `CWAI` | | `DAA` | Perform decimal addition adjust in `A`. Converts to Binary Coded Decimal. | `DAA` | | `DECA` | Decrement the value in `A` b ... ...

近期下载者

相关文件


收藏者