;;;-*-Package:lambda; Base:8.;  Mode:Lisp-*- 
;;;
;;; (c) Copyright 1984 - Lisp Machine, Inc.
;;;


;;This file contains information on setting up and using the Video Memory card from
;; Western Digital.  The video memory card has two separate memories onboard -- A and
;; B. The A memory is the one normally written to, and B is the one displayed.
;; There is a diagnostic hack for directly writing B memory from the nu-bus, but I
;; don't remember if it is really supposed to work all that well.  There is a copy bit
;; in one of the mode registers that enables continued copying from A memory to B 
;; during retrace cycles.  The board also has an ALU function which can be used to
;; mask in pixels over existing displays.

;; The video memory board also has a scan-line table that is in RAM, and can be
;; reconfigured to change the display.  This scan-line table is currently not initially
;; set up by the SDU, so we have to do it ourselves...

;; There are two registers on the video memory card:
;; The Memory Control Register -- location F.<id>.000004
;;              Bits 1-0   :  Number of memory refresh cycles per horizontal line [1-4]
;;              Bit  2     :  Memory bank being written from the nu-bus (0=A, 1=B)
;;              Bit  3     :  Copy bit (0 = no copying of A to B, 1 = A copied into B)
;;              Bit  4     :  Inverse video (0 = white on black, 1 = black on white)
;;              Bit  5     :  Interrupt enable for vertical blank interrupts to cause
;;                             a write to a specific location
;;              Bit  6     :  Reserved (must be 0)
;;
;; The Function Register --  location F.<id>.000000
;;              Bit  0     :  Reset bit (resets the video memory board)
;;              Bit  1     :  Board enable (enables the video memory board to be a
;;                             nu-bus master
;;              Bit  2     :  LED bit (light)
;;              Bits 3-4   :  ALU function of nu-bus data and A memory put in A memory --
;;                                  00 = nu-bus contents XOR A memory contents
;;                                  01 = nu-bus contents OR  A memory contents
;;                                  10 = nu-bus contents AND A memory contents
;;                                  11 = nu-bus contents
;;              Bits 5-7   :  Test bits for dignostic purposes


;; The actual display is located at F.<id>.020000 - F.<id>.03FFFF (400000-777777 octal).
;; The scan line table (with the least significant 16 bits being the starting addresses
;; for the new line [perhaps left-shifted by 2 for word addresses in hardware]) is located
;; between F.<id>.006000 to F.<id>.007FFC (60000-77774 octal).

(defun video-memory-init (slot)
  (nd-slot-write slot 0 1)			;reset
  (nd-slot-write slot 0 36)			;straight thru, led, nu-bus enabled
  (nd-slot-write slot 4 10)			;regular video, copy bit, A bank, one refresh
  (write-standard-scan-line-table slot))	;setup scan-line table

(defun write-standard-scan-line-table (slot)
  (do ((memory-location 400000 (+ memory-location 800.))
       (address-of-line  60000 (+ address-of-line 4)))
      ((> address-of-line 67640))
    (nd-slot-write slot address-of-line memory-location))
  (do ((address 67644 (+ address 4)))
      ((> address 77774))
    (nd-slot-write slot address 0)))
