Skip to content

Instantly share code, notes, and snippets.

@pwillard
Last active October 8, 2024 17:59
Show Gist options
  • Save pwillard/a13f8cad05876c4d3c62ca7892ab7fe1 to your computer and use it in GitHub Desktop.
Save pwillard/a13f8cad05876c4d3c62ca7892ab7fe1 to your computer and use it in GitHub Desktop.
Fitten example

Prompt

--> Lets say I have an ACIA 6850 device at address $FF68 and the program will reside at $4000.

Overview

To write a simple 6809 assembly language program that interfaces with an ACIA 6850 device located at address $FF68, we will need to configure the register addresses for the ACIA and handle reading data from it. The ACIA 6850 has several registers, but we will primarily be concerned with the data register and the status register for reading incoming data.

Key ACIA 6850 Register Addresses

Data Register (DR): $FF68 (for receiving and transmitting data) Status Register (SR): $FF69 (provides status information) Receive Ready: Bit 0 (indicates if there is data to read)

6809 Assembly Program

Here’s the program to read from the ACIA 6850:


        ORG    $4000             ; Program origin

START:
        LDX    #BUFFER           ; Load the address of the buffer
        SWI                       ; Enable interrupt handling (if using)

MAIN_LOOP:
        JSR    READ_ACIA         ; Call the ACIA read subroutine
        STAA   ,X                 ; Store received byte to buffer
        INX                       ; Move to the next buffer location
        BRA    MAIN_LOOP          ; Repeat the process

READ_ACIA:
        PSHS   A                  ; Save A on the stack
WAIT_FOR_DATA:
        LDA    $FF69              ; Load status register
        BITA   #$01               ; Check if the Receive Ready bit is set
        BEQ    WAIT_FOR_DATA      ; If not ready, loop
        LDA    $FF68              ; Read data from the ACIA DR
        PULS   A                  ; Restore A from the stack
        RTS                        ; Return from subroutine

BUFFER:  .BLOCK  256              ; Allocate a buffer of 256 bytes for received data

        ORG    $FFFE              ; Reset vector
        DB     START              ; Go to START on reset

Program Overview:

Setting Up Program Origin: The program starts executing at address $4000.

Main Loop: The program enters the MAIN_LOOP, where it continuously reads data from the ACIA device.

Reading from the ACIA:

Status Check: The READ_ACIA subroutine checks the status register at $FF69 to see if there is data ready to be read by checking the Receive Ready bit (bit 0).

Data Read: Once data is ready, it reads the data from the data register at $FF68 and restores any previous value stored in the accumulator.

Storage: Each read byte is stored in a buffer that can hold up to 256 bytes.

Buffer Definition: The program reserves 256 bytes for incoming data with the label BUFFER.

Reset Vector: Finally, the reset vector at address $FFFE points to the START entry of the program.

Additional Considerations:

Flow Control: Depending on your application, you may want to implement additional logic for handling flow control characters or other protocols.

Buffer Overflow Handling: The program does not currently handle the situation where the buffer could overflow. You may want to track how many bytes are written and stop reading after a fixed limit.

Echo or Processing: You can modify the program to process or echo the received data as needed. For example, you can add functionality to send data back through the ACIA.

Testing and Debugging: Make sure to test your program in your environment, as the setup may require specific configurations based on hardware and connected devices.

This example should serve as a basic foundation for working with the ACIA 6850 on the 6809 microprocessor.

OK, so not perfect... but its a start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment