; -------------------------------------------------------------------------------------------------------------- ;
; VIC II screen modes
; -------------------------------------------------------------------------------------------------------------- ;
; 1   General
; -------------------------------------------------------------------------------------------------------------- ;
      Address bus:
        - 14 bits (A0-A13)  - 16K to address memory
                  (A14-A15) - in CI2PRA ($DD00) to access all 4 memory banks
                  
          c-access:c-adr 
            - VM13-VM10 = bits 7-4 in VMCSB ($D018)
            - VC9-VC0   = (Video Counter) 10bit internal register
          +------+------+------+------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
          |  13  |  12  |  11  |  10  |  9  |  8  |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |
          +------+------+------+------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
          | VM13 | VM12 | VM11 | VM10 | VC9 | VC8 | VC7 | VC6 | VC5 | VC4 | VC3 | VC2 | VC1 | VC0 |
          +------+------+------+------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
          
          g-access:g-adr 
            - CB13-CB11 = bits 3-1 in VMCSB ($D018)
            - D7-D0     = data
            - RC2-RC0   = (Row Counter) 3bit internal register
          +------+------+------+------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
          |  13  |  12  |  11  |  10  |  9  |  8  |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |
          +------+------+------+------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
          | CB13 | CB12 | CB11 |  D7  |  D6 |  D5 |  D4 |  D3 |  D2 |  D1 |  D0 | RC2 | RC1 | RC0 |
          +------+------+------+------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
          
      Data bus:
        - 12 bits (D0-D11) - 1K  to access  memory
            bit 0- 7 connected to memory and processor bus
            bit 8-11 connected to COLORAM (fix connection)
            Access types:
              - c-data: to video matrix        with 12 bits (D0-D11)
              - g-data: to bitmap/char gen     with  8 bits (D0-D7)
              - p-data: to sprite data pointer with  8 bits (D0-D7)
              - s-data: to sprite data         with  8 bits (D0-D7)
              
                c-access:c-data
                        +------+------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
                        |  11  |  10  |  9  |  8  |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |
                        +------+------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
                        |  color from "1"-pixels  |  D7 |  D6 |  D5 |  D4 |  D3 |  D2 |  D1 |  D0 |
                        +-------------------------+-----+-----+-----+-----+-----+-----+-----+-----+
                g-access:g-data
                                                  +-----+-----+-----+-----+-----+-----+-----+-----+
                                                  |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |
                                                  +-----+-----+-----+-----+-----+-----+-----+-----+
                                                  |  8 Pixel (1 Bit/Pixel)                        |
                                                  |                                               |
                                                  | "0": Background color 0 ($d021)               |
                                                  | "1": Color from bits 8-11 of c-data           |
                                                  +-----------------------------------------------+
      Display resolution:
        - 320200 pixels
      Basic display modes: 
        - Tiled  mode (text-mode)
        - Bitmap mode
      
        Both modes break up the display logically into 88-pixel "Tiles"
        but differ in how these are handled and how graphics are drawn
        
        - Tiled mode (2 data buffers)
          Data Buffers:
            Tile-Address-Buffer ("Video Matrix")
              1000-bytes of memory
              Organized as a matrix of 25 rows by 40 columns
              Each byte in here refers to an 88 block on the screen
              Each byte in here is used as a pointer into the:
            Tile-Data-Buffer ("Character Generator")
              2048-byte of memory
          Color Buffers:
            Foreground: 
              1000-bytes of fix memory in COLORAM ($d800)
            Background: 
              Globally set in BGCOL0 ($D021)
        - Bitmap mode (1 data buffer)- the tile-addressing step is skipped
          Data Buffers:
            Tile-Data-Buffer ("Bitmap Memory")
              8192-bytes of memory
              Blocks of 8x8 still addressed as a "tile"
          Color Buffers:
            Foreground: 
              1000-bytes of fix memory in COLORAM ($d800)
              1000-bytes in "Screen Memory" with 2 colors in each left/right nybble
            Background: 
              Globally set in BGCOL0 ($D021)
  
          Video matrix and character generator can be moved in memory bank with:
            VMCSB ($D018) bits 4-7 - Video matrix = 2k blocks (bitmap: bit 7 only = 8k blocks)
            VMCSB ($D018) bits 0-3 - Character generator
; -------------------------------------------------------------------------------------------------------------- ;
; 2   Valid Modes
; --------------------------+-----+-----+-----+----------------------------------------------------------------- ;
; 2.1 Standard Text Mode    | ECM | BMM | MCM |
;                           +-----+-----+-----+
;                           |  0  |  0  |  0  |
; --------------------------+-----+-----+-----+----------------------------------------------------------------- ;
    All text modes use 8 bit character pointers from the video matrix to address
    the dot matrix of the character in the character generator
    Each of the 256 possible characters consists of 88 pixels and is stored in 8
    successive bytes in the character generator
    
    In standard text mode, every bit in the character generator directly corresponds
    to one pixel on the screen. 
     +----------------------------------------+
     |                COLORING                |
     +----------------------------------------+
     | "0": Background color 0 ($d021)        |
     | "1": Color from bits 8-11 of c-data    |
; ---+----------------------+-----+-----+-----+----------------------------------------------------------------- ;
; 2.2 MultiColor Text Mode  | ECM | BMM | MCM |
;                           +-----+-----+-----+
;                           |  0  |  0  |  1  |
; --------------------------+-----+-----+-----+----------------------------------------------------------------- ;
    Display four-colored characters at the cost of horizontal resolution
      COLORAM ($d800) bit3=0
        character is displayed as in standard text mode
        but only with colors 0-7 available for the foreground
      COLORAM ($d800) bit3=1
        Each 2 adjacent bits of the dot matrix form one pixel
        Thus the resolution of a character is reduced to 48
        (the pixels are twice as wide - the total width of a characters is same
    
    Sprite priority and collision detection:
      Both bit combinations "00" and "01" are regarded as "background"
     +----------------------------------------+
     |                COLORING                |
     +----------------------------------------+
     |         (1 bit/pixel)                  |
     |                                        | MCM ($d016) = 0
     | "0": Background color 0  ($d021)       |
     | "1": Color from bits 8-11 of c-data    |
     +----------------------------------------+
     |         (2 bits/pixel)                 |
     |                                        |
     | "00": Background color 0 ($d021)       | MCM ($d016) = 1
     | "01": Background color 1 ($d022)       |
     | "10": Background color 2 ($d023)       |
     | "11": Color from bits 8-11 of c-data   |
; ---+----------------------+-----+-----+-----+----------------------------------------------------------------- ;
; 2.3 Standard BitMap Mode  | ECM | BMM | MCM |
;                           +-----+-----+-----+
;                           |  0  |  1  |  0  |
; --------------------------+-----+-----+-----+----------------------------------------------------------------- ;
    All bitmap mode uses the graphics data from a 320200 bitmap
    Every bit directly corresponds to one pixel on the screen
    An 88 pixel block on the screen is built from 8 successive bytes of the bitmap
    The screen memory data is used for color information
      The screen memory is still a 4025 matrix
      Foreground and background color can be individually set for every 88 block
     +----------------------------------------+
     |                COLORING                |
     +----------------------------------------+
     |         8 pixels (1 bit/pixel)         |
     |                                        |
     | "0": Color from bits 0-3 of c-data     |
     | "1": Color from bits 4-7 of c-data     |
; ---+----------------------+-----+-----+-----+----------------------------------------------------------------- ;
; 2.4 Multicolor BitMap Mode| ECM | BMM | MCM |
;                           +-----+-----+-----+
;                           |  0  |  1  |  1  |
; --------------------------+-----+-----+-----+----------------------------------------------------------------- ;
    Display four-colored bitmaps at the cost of horizontal resolution
      Each 2 adjacent bits of the bitmap form one pixel
      The resolution of a character is reduced to 160200 pixels

    Sprite priority and collision detection:
      The bit combination "01" are regarded as "background"
     +----------------------------------------+
     |                COLORING                |
     +----------------------------------------+
     |         (2 bits/pixel)                 |
     |                                        |
     | "00": Background color 0 ($d021)       |
     | "10": Color from bits 0- 3 of c-data   |
     | "01": Color from bits 4- 7 of c-data   |
     | "11": Color from bits 8-11 of c-data   |
; ---+----------------------+-----+-----+-----+----------------------------------------------------------------- ;
; 2.5 ECM Text Mode         | ECM | BMM | MCM |
;                           +-----+-----+-----+
;                           |  1  |  0  |  0  |
; --------------------------+-----+-----+-----+----------------------------------------------------------------- ;
    Aka 'Extended Background Colors'
    Same as the standard text mode but:
      - allows the selection of one of four background colors for every single character
      - The selection is done with the upper two bits of the character pointer
      - The character set is reduced from 256 to 64 characters
     +----------------------------------------+
     |                COLORING                |
     +----------------------------------------+
     |        (1 bit/pixel)                   |
     |                                        |
     | "0": Depending on bits 6-7 of char ptr |
     |      "00": Background color 0 ($d021)  |
     |      "01": Background color 1 ($d022)  |
     |      "10": Background color 2 ($d023)  |
     |      "11": Background color 3 ($d024)  |
     | "1": Color from bits 8-11 of c-data    |
; ---+----------------------------------------+----------------------------------------------------------------- ;
; 3   Invalid Modes
; --------------------------+-----+-----+-----+----------------------------------------------------------------- ;
; 3.1 Invalid Text Mode     | ECM | BMM | MCM |
;                           +-----+-----+-----+
;                           |  1  |  1  |  0  |
; --------------------------+-----+-----+-----+----------------------------------------------------------------- ;
    - Creates only black pixels on the screen
    - The graphics data sequencer internally generates valid graphics data
      - can trigger a sprite collisions
      - can only distinguish foreground and background pixels as sprite collisions do not get color info
    - The generated graphics is similar to that of the multicolor text mode
    - The character set is limited to 64 characters as in ECM mode
; --------------------------+-----+-----+-----+----------------------------------------------------------------- ;
; 3.2 Invalid bitmap mode 1 | ECM | BMM | MCM |
;                           +-----+-----+-----+
;                           |  1  |  1  |  0  |
; --------------------------+-----+-----+-----+----------------------------------------------------------------- ;
    - Creates only black pixels on the screen
    - The graphics data sequencer internally generates valid graphics data
      - can trigger a sprite collisions
      - can only distinguish foreground and background pixels as sprite collisions do not get color info
    
    The structure of the graphics is basically as in standard bitmap mode, but the bits 9 and 10 of the
    g-addresses are always zero due to the set ECM bit and so the graphics is - roughly said - made up of
    four "sections" that are each repeated four times.
; --------------------------+-----+-----+-----+----------------------------------------------------------------- ;
; 3.3 Invalid bitmap mode 2 | ECM | BMM | MCM |
;                           +-----+-----+-----+
;                           |  1  |  1  |  1  |
; --------------------------+-----+-----+-----+----------------------------------------------------------------- ;
    - Creates only black pixels on the screen
    - The graphics data sequencer internally generates valid graphics data
      - can trigger a sprite collisions
      - can only distinguish foreground and background pixels as sprite collisions do not get color info

    The structure of the graphics is basically as in multicolor bitmap mode, but the bits 9 and 10 of the
    g-addresses are always zero due to the set ECM bit, with the same results as in the first invalid bitmap
    mode. As usual, the bit combination 01 is part of the background.
; -------------------------------------------------------------------------------------------------------------- ;
; 4   Idle state
; -------------------------------------------------------------------------------------------------------------- ;
    In idle state, the VIC reads the graphics data from address $3fff (resp. $39ff if the ECM bit is set)
    and displays it in the selected graphics mode, but with the video matrix data (normally read in the
    c-accesses) being all "0" bits. So the byte at address $3fff/$39ff is output repeatedly.
; -------------------------------------------------------------------------------------------------------------- ;
