; Title - 4 Colors
; By    - Adam Trionfo
;         1.2 - March 31, 2016
;             - Fixed to work with recent versions of MESS/MAME Emulator
;               and on real machines.  Changed Interrupt Mode
;               from $18 to $08 (screen interrupts only).
;             - Changed source name from "Screen Display" to "4 Colors"
;             - Menu now displays "4 COLORS" instead of "TEST"
; Rev.  - 1.3 - December 3, 2010
;               * Added David Turner's June 14, 2010 comments
;         1.2 - November 30, 2003
;               * Made compatible with HVGLIB.H
; Rev   - 1.1 - March 22, 2002
; 
; This program could not have been written without using
; Mike White's "Astro BASIC 4x2 Multicart Loader" and
; and the "Nutting Manual" as a reference.
;
;  
; About this Program
; ------------------ 
;
; Displays four pixels (repeated four times) at $4000
; (the top-left of the screen).
; The byte value displayed is $B1, which should display
; color registers 0-3, but the order displayed is
; reverse from what I expect (3-0).  Why?
;
; Explanation of Why Color Order is Backward:
; By David Turner 
; -----------------------------------------------------
; If you look on page 88 of the DNA manual, you will see the color
; mapping ports described. There are two ways to set the ports, 
; individually and all at once.
;
; Individually, you write each color register starting with 0 to
; port 0, register 1 to port 1 and go up until you reach
; register 7 to port 7.
;
; Writing them all at once, you use the OTIR instruction to
; port $0B (c=$0B), and register b=8 (number of entries in table).
; HL points to the color table. This loads the registers in the
; table at one time, but the trick is that it loads register 7 first
; and register 0 last. So if you use the OTIR method, you would put
; your color table backwards than what you expect.
;
; The COLSET system routine uses the OTIR method, so your table should
; start with register 7 first (color 3 left) and go down to
; register 0 (color 0 right).
;
;
; Assembling this Program
; -----------------------
;    This file will assemble with ZMAC 1.3 (a little
; known, freely distributable Z-80 assembler (with C
; source), that has a 25-year history.  ZMAC can be
; compiled under just about any O.S. in existence, so
; try it out. 
;  
; To assemble Z-80 source code using ZMAC:
;  
; zmac -i -m -o <outfile> -x <listfile> <filename>
; 
; For example, to assemble this Astrocade Z-80 program:
;    
; zmac -i -m -o fourcolr.bin -x fourcolr.lst fourcolr.asm

INCLUDE "HVGLIB.H"      ; Home Video Game Library Header

        ORG    FIRSTC    ; First Byte of Cartridge
        DB     "U"       ; User Cartridge Sentinel

; Menu Selection Choice #1
        DW     MENUST   ; Next Menu Link
        DW     PRGNAM   ; Address of Program Name text
        DW     PRGST    ; Jump here if selected
 
; Program Start
PRGST:  DI                ; Disable interrupts

        SYSTEM (INTPC)    ; Start System Interpreter 

        DO     (SETOUT)   ; Set Display Ports
        DB     176D       ; Vertical Blanking Line 
        DB     44D        ; Left/Right Color Boundary 
        DB     00001000B  ; Set Bit 3 of INterrupt MODe (Screen Interrupts Only) 

        DO     (COLSET)   ; Set Color Registers
        DW     COLTAB     ; Color Table

        DO     (FILL)     ; Screen Fill
        DW     $4000      ; Destination
        DW     4000D      ; Bytes to move
        DB     $00        ; Fill with zeros

        DO     (MOVE)     ; Move Bytes
        DW     $4000      ; Destination
        DW     4D         ; Bytes to move (four)
        DW     TOMOVE     ; Source Address

        EXIT              ; Exit System Interpreter

        EI                ; Enable interrupts 

LOOP:   NOP               ; Endless loop
        JP     LOOP       ; End of program

; Program Data

; Color Table #1
COLTAB: DB     $00        ; Color 0 Right - Black
        DB     $5A        ; Color 1 Right - Red
        DB     $86        ; Color 2 Right - Yellow
        DB     $F9        ; Color 3 Right - Blue
        DB     $00        ; Color 0 Left  - Black
        DB     $5A        ; Color 1 Left  - Red
        DB     $86        ; Color 2 Left  - Yellow
        DB     $F9        ; Color 3 Left  - Blue

; Program Name
PRGNAM: DB     "4 COLORS",$00

; Bytes to move
TOMOVE: DB     00011011B  ; Four pixels (0,1,2,3)
        DB     00011011B  ; Four pixels (0,1,2,3)
        DB     00011011B  ; Four pixels (0,1,2,3)
        DB     00011011B  ; Four pixels (0,1,2,3)

; End of Program
