logical>>   0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F

r0                X
r1                   X
r2                      X
r3          X
r4             X
r5                X
r6                   X
r7                      X

g0                               X
g1                                  X
g2                                     X
g3                         X
g4                            X
g5                               X
g6                                  X
g7                                     X

b0                                              X
b1                                                 X
b2                                                    X
b3                                        X
b4                                           X
b5                                              X
b6                                                 X
b7                                                    X



Hold a 32-word table of NVidia LUT entries, reserve space for a spare copy.

To handle an IOMD-style palette entry write in 16bpp modes:

  FOR NVidia_index = 0 TO 31
    OldNVidiaLUT!NVidia_index = NVidiaLUT!NVidia_index
  NEXT
  
  FOR IOMD_index = first_index TO last_index
    IF IOMD_index AND &E0 = 0 THEN
      ?(NVidiaLUT + (IOMD_index AND &1F)*4 + red_offset) = palette_entry >> 8
    ENDIF
    IF IOMD_entry AND &C1 = 0 THEN
      ?(NVidiaLUT + (IOMD_index AND &3E)*2 + green_offset) = palette_entry >> 16
    ENDIF
    IF IOMD_entry AND &83 = 0 THEN
      ?(NVidiaLUT + (IOMD_index AND &7C)*1 + blue_offset) = palette_entry >> 24
    ENDIF
  NEXT
  
  FOR NVidia_index = 0 TO 31
    IF NVidiaLUT!NVidia_index <> OldNVidiaLUT!NVidia_index THEN
      REM program register number ((NVidia_index << 3) + (NVidia_index >> 2))
    ENDIF
  NEXT


When only programming one IOMD palette entry, the middle loop is obviously
only executed once, and the other two loops only need worry about entries
(IOMD_index AND &1F), (IOMD_index AND &3E)/2 and (IOMD_index AND &7C)/4
since these are the only ones that could have been changed.


When a 16bpp mode is selected, the cached LUT needs to be initialised thus:

FOR index = 0 TO 31
  setting = (index << 3) + (index >> 2)
  setting *= &10101
  !(LUT + index * 4) = setting
NEXT
