\ Dual synchronous serial port (DSSP) dual optical encoder (DOE) interface HEX 46FE R-TOP ! 4700 DUP H ! H-FENCE ! 8080 CONSTANT DSSP_OUT_BUS_BITS 0101 CONSTANT DSSP_IN_BUS_BITS 0002 CONSTANT DSSP_WRITE_EN 0001 CONSTANT DSSP_SCLK_LOW \ 8080 CONSTANT DSSP_FRAME_START 0080 CONSTANT DSSP_FRAME_START \ Used for testing of one optical encoder. \ 4040 CONSTANT DSSP_DATA_VALID 0040 CONSTANT DSSP_DATA_VALID \ Used for testing of one optical encoder. : DSSP-WRITE-BITS ( n -- ) DSSP_OUT_BUS_BITS AND \ Isolate the MSB of both bytes. DSSP_WRITE_EN OR \ Maintain the SSP bus drivers on. DUP \ Make a copy of the data. DSSP_SCLK_LOW OR \ Bring the SSP clock line low. 1A G! \ Output the data. 0018 FOR NEXT \ Extend duration of clock level 1A G! \ Output the data, bring the SSP clock line high. 0018 FOR NEXT \ Extend duration of clock level ; : DSSP-WRITE-BYTES ( n -- ) 7 FOR \ Enter loop to write out eight bits for each byte. DUP \ Make a copy of the data. DSSP-WRITE-BITS \ Write out the MSB of both bytes. 2* \ Shift the data left by one bit. NEXT \ Continue the loop. DROP \ Discard the trash data. ; : DSSP-WRITE-REGISTERS ( data addr -- ) DSSP_WRITE_EN 1A G! \ Output data to turn on the SSP bus drivers. DSSP-WRITE-BYTES \ Output address bytes onto SSP busses. DSSP-WRITE-BYTES \ Output data bytes onto SSP busses. 0000 1A G! \ Output data to turn off the SSP bus drivers. ; : DSSP-READ-BITS ( -- n ) DSSP_SCLK_LOW 1A G! \ Output data to bring the SSP clock line low. 0018 FOR NEXT \ Extend duration of clock level DSSP_IN_BUS_BITS \ Set up mask to isolate the incomming bits. 0000 1A G! \ Output data to bring the SSP clock line high. 0018 FOR NEXT \ Extend duration of clock level 1A G@ \ Input the data. AND \ Isolate the LSB of both bytes. ; : DSSP-READ-BYTES ( -- n ) 0 \ Initially start with an empty bit field. 7 FOR \ Enter loop to read in eight bits for each byte. 2* \ Shift the data left by one bit DSSP-READ-BITS \ Read in bits into LSB bit of both bytes. OR \ Combine new bits with shifted bits. NEXT ; : DSSP-READ-REGISTERS ( addr -- data ) DSSP_WRITE_EN 1A G! \ Output data to turn on the SSP bus drivers. DSSP-WRITE-BYTES \ Output address bytes onto SSP busses. NOP \ Pause for last bit before bus driver shut-off. 0000 1A G! \ Output data to turn off the SSP bus drivers. 00C7 FOR NEXT \ Loop 200 times for delay between write and read. DSSP-READ-BYTES \ Input data bytes from the SSP busses. ; : DOE-RESET ( -- ) 8080 8080 DSSP-WRITE-REGISTERS ; : DOE-POWER-DOWN ( -- ) 4040 8080 DSSP-WRITE-REGISTERS ; : DOE-KEEP-AWAKE ( -- ) 0101 8080 DSSP-WRITE-REGISTERS ; : DOE-LET-SLEEP ( -- ) 0000 8080 DSSP-WRITE-REGISTERS ; : DOE-READ-CONFIG ( -- data ) 0000 DSSP-READ-REGISTERS ; : DOE-STATUS ( -- data ) 0101 DSSP-READ-REGISTERS ; : DOE-DELTA-Y ( -- data ) 0202 DSSP-READ-REGISTERS ; : DOE-DELTA-X ( -- data ) 0303 DSSP-READ-REGISTERS ; : DOE-SQUAL ( -- data ) 0404 DSSP-READ-REGISTERS ; : DOE-MAX-PIXEL ( -- data ) 0505 DSSP-READ-REGISTERS ; : DOE-MIN-PIXEL ( -- data ) 0606 DSSP-READ-REGISTERS ; : DOE-PIXEL-SUM ( -- data ) 0707 DSSP-READ-REGISTERS ; : DOE-RESET-PIXEL-DATA ( -- ) 0000 8888 DSSP-WRITE-REGISTERS ; : DOE-READ-PIXEL-DATA ( addr -- code) DOE-RESET-PIXEL-DATA \ Reset the pixel hardware. 0640 FOR NEXT \ Delay loop of 1600 loops. 0143 FOR \ Loop 324 times to read in pixels 0808 \ Address for pixel data. DSSP-READ-REGISTERS \ Read bytes. SWAP \ Bring address to TOS. !+2 \ Write out values and increment by two bytes. NEXT \ Loop if all status bits are true. DROP \ Discard the address. ; : DOE-SHUTTER-UPPER ( -- data ) 0909 DSSP-READ-REGISTERS ; : DOE-SHUTTER-LOWER ( -- data ) 0A0A DSSP-READ-REGISTERS ; : DOE-SHUTTER-RATES ( -- data1 data0 ) DOE-SHUTTER-UPPER \ Obtain the upper-byte shutter rate values DOE-SHUTTER-LOWER \ Obtain the lower-byte shutter rate values OVER \ Duplicate the upper-byte shutter rate data OVER \ Duplicate the lower-byte shutter rate data FF00 \ Mask for the lower byte of sensor #1 AND \ Isolate the lower byte of sensor #1 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ \ Shift the lower byte to it proper place SWAP \ Bring upper-byte shutter rate values to TOS FF00 \ Mask for the upper byte of sensor #1 AND \ Isolate the upper byte of sensor #1 AND \ Combine with lower byte for sensor #1 value -ROT \ Rotate sensor #1 data into the stack 00FF \ Mask for the lower byte of sensor #0 AND \ Isolate the lower byte of sensor #0 SWAP \ Bring upper-byte shutter rate values to TOS 00FF \ Mask for the lower byte of sensor #0 AND \ Isolate the upper byte of sensor #0 2* 2* 2* 2* 2* 2* 2* 2* \ Shift the upper byte to it proper place AND \ Combine with lower byte for sensor #0 value ; : DOE-INV-PRODUCT-ID ( -- data ) 1111 DSSP-READ-REGISTERS ; : CRUDE-FOCUS ( n -- ) 0 DO DOE-SQUAL 00FF AND 2 .H CR LOOP ; : PIXEL-DUMP ( addr -- ) ." {" CR \ Output initial open brace for data. 12 0 DO \ Eighteen rows in the image. ." {" \ Output open brace for row. 12 0 DO \ Eighteen pixels in each row. @+2 \ Read data value and increment pointer by two. SWAP \ Bring data value to TOS. 003F AND \ Mask to clear unused bits. 2* 2* \ Shift left by two to increase dynamic range. ." #" \ Output color triplet indicator DUP 2 .H \ Output first copy of byte for red color. DUP 2 .H \ Output second copy of byte for green color. 2 .H ." " \ Output third copy of byte for blue color. LOOP ." }" CR \ Output close brace for row and newline. LOOP ." }" CR \ Output close brace for data and newline. ; : GET-PIXELS R @ DOE-READ-PIXEL-DATA R @ PIXEL-DUMP ; : RAW-PIXEL-DUMP ( addr -- ) 12 0 DO \ Eighteen rows in the image. 12 0 DO \ Eighteen pixels in each row. @+2 \ Read data value and increment pointer by two. SWAP \ Bring data value to TOS. 00FF AND \ Mask to clear unused bits. 2 .H ." " \ Output byte. LOOP CR \ Output newline. LOOP CR \ Output newline. ; : GET-RAW-PIXELS R @ DOE-READ-PIXEL-DATA R @ RAW-PIXEL-DUMP ; : MOVE-TEST 0 DO DOE-DELTA-X 00FF AND DUP 0080 AND 0> IF FF00 OR THEN ." Delta X: " . DOE-DELTA-Y 00FF AND DUP 0080 AND 0> IF FF00 OR THEN ." Delta Y: " . CR LOOP ; : CALIBRATE-X-Y DOE-DELTA-X 00FF AND DUP 0080 AND 0> IF FF00 OR THEN DECIMAL ." Delta X: " . HEX DOE-DELTA-Y 00FF AND DUP 0080 AND 0> IF FF00 OR THEN DECIMAL ." Delta Y: " . CR HEX ;