z80:Ports:Port00

From Learn @ Cemetech
Jump to navigationJump to search

Basic Info

Port Address: 00

This port controls the calculator's serial link port (the one labeled I/O on newer calculators, shaped like a circle).

Writing to Port

Bits 0 and 1: Setting a bit will pull the line low. Resetting a bit will stop holding the line low (allowing it to go high if the other calculator is not holding it low). A low line is read as a bit being reset, but when writing setting a bit brings the line low. 83+ only: Bit 2: Set this bit to enable the link receive assist. After setting this bit, poll port 0 until bit 3 is high, at which point read from port 5 to get the byte.

Reading from Port

Bits 0 and 1: These bits indicate the state of the link port's two lines. If a bit is set that indicates the line is high, and if it is reset that indicates the line is low. When idle (no transfer in progress, no cable plugged in, etc), both lines are usually high. When a cable is connected on both ends, a line reads high if and only if both ends have set the line high. The line will read low if either calculator sets it low. Bit 0 is the tip and bit 1 is the ring. 83+ only: Bit 2: Set means link receive assist is active. 83+ only: Bit 3: Set when link assist has received a complete byte. The only way to reset this bit is to read port 5. Bit 4 and 5: Bits 4 and 5 indicate which lines are pulled low by the calculator (unlike bits 0 and 1 they are not influenced by the other calculator). A 1 bit indicates your calculator is holding the line low. A 0 bit indicates your calculator is not holding the line low. (When both calculators have a 0 bit here, the corresponding line will read 1.) In other words, these bits reflect bits 0 and 1 from the most recent write to this port. 83+ only: Bit 6: Set if the link assist is currently receiving data.

Example Uses

Sending/Setting

   ld a,0     ; Set both lines high
     out (0),a
   
     ld a,2     ; Set tip high, ring low
     out (0),a
   
     ld a,1     ; Set tip low, ring high
     out (0),a
   
     ld a,3     ; Set both low
     out (0),a


Receiving/Reading

   in a,(0)        ; Get link port value
   
     bit 0,a         ; Check tip
     jr z,tip_low
     jr nz,tip_high
   
     bit 1,a         ; Check ring
     jr z,ring_low
     jr nz,ring_high