BrickHacks

8-bit robotics and the official home of the Lego Chevy 454 V-8

In memory of Dan Roganti

About, Notes, YouTube, Instagram



Back to the 8-Bit software page

Programming the 9750 interface in 6502 Assembly

Prerequisite: you should have a working knowledge of standard assembly programming for the Apple II. Note: I do not have this knowledge. I'm an absolute beginner at assembly programming. I just recently wrote my first “Hello World” in this language. I will revisit this page when I learn can speak about it with more experience.

The following is quoted directly from pages 4.16-4.17 of the Lego Lines manual.

Although the Lego interface can be programmed in BASIC, some of the Lego Lines program is written in 6502 machine code, to improve performance.

All hexadecimal values are denoted by the prefix $ (for example, $2A), while binary values are denoted with the prefix % (for example, %101100).

The address of the interface I/O port is given by the following:

LEGO EQU $C080+$10*S

where S is the slot number of the Lego interface. Normally, where the Lego interface is in slot 2, the address is given by:

LEGO EQU $C0A0

The correct initialization sequence for the interface is as follows:

LEGO EQU $C0A0
INIT LDA #1
STA $C0A3
STA #$3F
LDA $C0A2
STA #0
STA $C0A1
RTS $C0A0

All data is written to address $C0A0. The six data bits on the interface correspond exactly to the six data least significant bits written to the address. So, for example, to turn on bits 1 and 3 only (and the rest off), it is necessary to load the accumulator with binary %001010 ($0A).

Below is the routine to send the bits in the accumulator to the interface:

SEND AND #$3F :Mask with %0011111
STA $C0A0 :To filter out bits 7 and 6
RTS

Reading the data is more complex. First, the data must be read from the interface. Then the correct bits must be filtered out, if necessary. Finally, the appropriate bits must be examined.

To read the current status of the output bits (to read which bits are currently on):

STATUS LDA $C0A0
AND #$3F :Filter out bits 7 and 6
RTS

TEST JSR STATUS
STA TEMP
LDA #0
STA COUNT

T0 ROR :Rotate last bit into carry
BCC T1 :No bit
JSR ACT :Else act on it

T1 INC COUNT
LDA COUNT :Up to 6?
CMP#6
BNET0
RTS



Home - History - Universal Buggy - Computers - Interface A - Connections - Peripherals - Code - Analog - Beyond - Lego Chevy V8

Copyright: Evan Koblentz, 2018-2024