;;; -*- Mode: Common-Lisp; Package: User; Base: 10.; Patch-File: T -*-

;;; Reason: Fixes to be able to boot a disk-saved MMON-p band on a different
;;; hardware configuration. Changed current-chassis-configuration &
;;; get-serial-number to work before error-handler enabled. Moved
;;; (tv:monitor-initialize) way up on si:system-initialization-list.

;;;                           RESTRICTED RIGHTS LEGEND
;;;
;;; Use, duplication, or disclosure by the Government is subject to
;;; restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
;;; Technical Data and Computer Software clause at 52.227-7013.
;;;
;;;   TEXAS INSTRUMENTS INCORPORATED      
;;;   P.O. BOX 2909, M/S 2151             
;;;   AUSTIN, TEXAS 78769                 
;;;
;;; Copyright (C) 1989 Texas Instruments Incorporated.
;;; All rights reserved.

;;; Patch file for MMON version 6.2
;;; Written 10/20/89 12:51:37 by marky,
;;; while running on LIBRA from band LODA
;;; With SYSTEM 6.20, VIRTUAL-MEMORY 6.2, EH 6.5, MAKE-SYSTEM 6.2, MICRONET 6.0, LOCAL-FILE 6.1,
;;;  BASIC-PATHNAME 6.2, NETWORK-SUPPORT-COLD 6.2, BASIC-NAMESPACE 6.4, NETWORK-NAMESPACE 6.0,
;;;  DISK-IO 6.1, DISK-LABEL 6.0, BASIC-FILE 6.4, MAC-PATHNAME 6.0, NETWORK-PATHNAME 6.0,
;;;  COMPILER 6.12, TV 6.15, DATALINK 6.0, CHAOSNET 6.1, GC 6.3, MEMORY-AUX 6.0, NVRAM 6.2,
;;;  SYSLOG 6.2, STREAMER-TAPE 6.4, UCL 6.0, INPUT-EDITOR 6.0, METER 6.1, ZWEI 6.7,
;;;  DEBUG-TOOLS 6.3, NETWORK-SUPPORT 6.0, NETWORK-SERVICE 6.1, DATALINK-DISPLAYS 6.0,
;;;  FONT-EDITOR 6.1, SERIAL 6.0, PRINTER 6.3, MAC-PRINTER-TYPES 6.1, PRINTER-TYPES 6.2,
;;;  IMAGEN 6.1, SUGGESTIONS 6.1, MAIL-DAEMON 6.3, MAIL-READER 6.5, TELNET 6.0, VT100 6.0,
;;;  NAMESPACE-EDITOR 6.3, PROFILE 6.2, VISIDOC 6.5, TI-CLOS 6.25, CLEH 6.5, IP 3.54,
;;;  Experimental CLX 6.5, CLUE 6.25, X11M 6.15, Experimental BUG 11.15, Inconsistent MMON 6.1,
;;;   microcode 429, Band Name: clogged

;;; SPR 10196 part of series of patches : window.6.17 ,system.6.22
;;; In order to be able to boot a disk-saved MMON-p band on a different
;;; hardware configuration, we must perform (tv:monitor-initialize) before
;;; anyone tries to do a sheet-load-registers which calls
;;; (:method tv:block-flavor :set-foreground-color-register) which requires
;;; that (tv:init-csib-registers) be done BEFORE - see system-patch.6.22 -
;;; (si:process-initialize) is invoked off si:system-initialization-list
;;; which results in the blinkers & who fields being updated.
;;;  Also changed get-serial-number & current-chassis-configuration
;;; to work before error-handler is enabled.

#!C
; From file MONITOR-INITIALIZE.LISP#> MMON; Hotel:
#10R TV#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "TV"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: MMON; MONITOR-INITIALIZE.#"


(DEFUN rebuild-previously-selected-screens
       ()
  ;; We should not be changing carelessly an array that the async kbd-process can modify.	;; may 10/20/89 
  (WITHOUT-INTERRUPTS ;; may 10/20/89
    (ARRAY-INITIALIZE *previously-selected-screens* nil))
  (LOOP FOR screen IN all-the-screens
	WHEN (AND (screen-exposable-p screen)
		  (SEND screen :operation-handled-p :make-default-screen)
		  (NOT (EQ screen default-screen)))
	DOING (add-to-previously-selected-screens screen)))
))

#!C
; From file MONITOR-INITIALIZE.LISP#> MMON; Hotel:
#10R TV#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "TV"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: MMON; MONITOR-INITIALIZE.#"


;; may 10/17/89 
;; use si:board-type so that it can be called before error-handler is enabled.
(DEFUN current-chassis-configuration ()
  (LET ((configuration-array
	  (MAKE-ARRAY (LIST tv:number-of-slots 2))))
    (LOOP FOR slot FROM 0 BELOW tv:number-of-slots
	  DOING
	  (SETF (AREF configuration-array slot 0) (OR (si:board-type (+ #xf0 slot)) "")	;; may 07/18/89 
		(AREF configuration-array slot 1) (OR (tv:get-serial-number slot) "")))
    configuration-array))
))

#!C
; From file UTILITIES.LISP#> MMON; Hotel:
#10R TV#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "TV"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: MMON; UTILITIES.#"


;; Replaced "(ignore-errors (si:%nubus-read-8b" with "(si:%nubus-read-8b-careful"
(Defun get-serial-number (slot)
  "Internal function not meant to get REAL serial number, only a psuedo serial number."	;; may 10/17/89 added
  (LET ((f-slot (+ #xf0 slot)))
    (WHEN (si:%nubus-read-8b-careful f-slot cromo-board-serial-number)	;; may 10/17/89 
      (LOOP with byte
	    FOR offset
	    FROM cromo-board-serial-number
	    BELOW (+ cromo-board-serial-number (* cromo-serial-number-length 4.))
	    BY 4.
	    COLLECTING (CHARACTER
			 (if (integerp (setq byte (si:%nubus-read-8b-careful f-slot offset)))	;; may 10/17/89 
				      byte
				      #\space))
	    INTO bytes-read
	    FINALLY (RETURN (FORMAT nil "~{~A~}" bytes-read))))))
))



;; we must not load this patch unless the other patches are
;; also loaded, ort least try to load them!
(MULTIPLE-VALUE-BIND (current-major-version current-patch-number)
    (sys:GET-SYSTEM-VERSION "system")
  (UNLESS (>= current-patch-number 22.) ;; system patch.6.22 loaded ?
    (LET* ((system (si:find-system-named "system" t t))
	   (patch-dir (AND system (CAR (si:system-patch-directory system))))
	   (patch-file (AND patch-dir
			    (send patch-dir :new-name-and-type
				  (format nil "patch-~d-~d.xld" current-major-version current-patch-number)))))
      (IF (AND patch-file (PROBE-FILE patch-file))
	  (LOAD patch-file :verbose t) ;; what is best to do with verbose option ... ?
	  (BEEP)(FORMAT t "~% ** WARNING ** You have not loaded SYSTEM patch 6.22 which is necessary!"))))

  (MULTIPLE-VALUE-SETQ (current-major-version current-patch-number)
    (sys:GET-SYSTEM-VERSION "tv"))
  (UNLESS (>= current-patch-number 17.) ;; tv patch.6.17 loaded ?
    (LET* ((system (si:find-system-named "tv" t t))
	   (patch-dir (AND system (CAR (si:system-patch-directory system))))
	   (patch-file (AND patch-dir
			    (send patch-dir :new-name-and-type
				  (format nil "patch-~d-~d.xld" current-major-version current-patch-number)))))
      (IF (AND patch-file (PROBE-FILE patch-file))
	  (LOAD patch-file :verbose t) ;; what is best to do with verbose option ... ?
	  (BEEP)(FORMAT t "~% ** WARNING ** You have not loaded TV patch 6.17 which is necessary!"))))

  (delete-initialization "Monitor Initialize" :system)
  (ADD-INITIALIZATION "Monitor Initialize"
		      '(tv:monitor-initialize)
		      '(:system))
  (tv:move-element-before "Monitor Initialize"
			  sys:system-initialization-list
			  "Process" ;;"Window-System"	;; may 10/20/89 Must move before (si:process-initialize)
			  :key #'CAR
			  :test #'STRING-EQUAL)
  )




