
; X-SPECS 3D-glasses (goggles) driver, developed in fall 1988
; E-mail addresses:
;  hawkins@phast.umass.edu, UMASS Dept. of Physics and Astronomy
;  kirkstar@npvm.newpaltz.edu, SUNY New Paltz - Kirk Planetarium

;Constants
#CIAAPRA=$BFE001
#CIAADDRA=$BFE201

.xspecsinit:
;Set Joyport button-0 direction to output in cia-a direction register
; for state-control of 3D-glasses
  MOVE.L  D7,-(A7)    ;PRESERVE REGISTERS
  CLR.L   D7           ;clear to avoid artifacts
  MOVE.B  CIAADDRA,D7  ;get state of CIA-A data-direction-register-A
  ORI.B   #$80,D7      ;set bit 7, for enabling button-0 as OUTPUT
  MOVE.B  D7,CIAADDRA  ;set CIA-A DDRA register, enable the output
  MOVE.B  CIAAPRA,D7  ;get output state
  ANDI.B  #$7F,D7     ;initialize the bit to OFF
  MOVE.B  D7,CIAAPRA  ;set output state
  MOVE.L  (A7)+,D7  ;restore registers
  Return            ;routine program end

.xspecstog:
;Toggle the STATE of the 3D-glasses
  MOVE.L  D7,-(A7)   ;PRESERVE REGISTER
  MOVE.B  CIAAPRA,D7  ;get output state
  EOR.B   #$80,D7     ;toggle the bit, toggle the glasses
  MOVE.B  D7,CIAAPRA  ;set output state
  MOVE.L  (A7)+,D7  ;restore registers
  Return            ;routine end

.xspecsexit:
;Clear Joyport button-0 direction to input (as is usual)
  MOVE.L  D7,-(A7)    ;PRESERVE REGISTERS
  CLR.L   D7           ;clear to avoid artifacts
  MOVE.B  CIAADDRA,D7  ;get CIA-A data-direction-register-A
  ANDI.B  #$7F,D7      ;CLEAR bit 7, to RE-enable button-0 as INPUT
  MOVE.B  D7,CIAADDRA  ;set CIA-A DDRA register
  MOVE.B  CIAAPRA,D7  ;get output state
  ANDI.B  #$7F,D7     ;initialize the bit to OFF
  MOVE.B  D7,CIAAPRA  ;set output state
  MOVE.L  (A7)+,D7  ;restore registers
  Return            ;routine end

