; Title - Rainbow
; For the Bally Astrocade
; Typed by Adam Trionfo
;
;         1.1 - December 6, 2016
;             - Fixed to work with recent versions of MESS/MAME Emulator.
;               Changed Interrupt Mode from $18 to $08 (screen
;               interrupts only).  Must press Reset to begin program properly.
;         1.0 - October 4, 2004
;
; For a NEAT effect, play around with the knob on controller 1
; after you run this program.
;
; 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 rainbow.bin -x rainbow.lst rainbow.asm

INCLUDE "HVGLIB.H"

        ORG  $2000        ; Starting address for ALL Bally carts

        DB     $55        ; Bally System Sentinel

        DW     MENUST   ; Next menu link
        DW     PRGNAM   ; Address of title for program
        DW     START    ; Jump here if prog is selected

; Program Start

START   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

        EXIT              ; Exit System Interpreter

        EI                ; Enable interrupts 

RAIN    INC  A
        OUT  (COL0L),A    ; Left Color Register
        JR   NZ,RAIN      ; Jump to Beginning if not zero

        IN   A,(POT0)     ; Get Pot 0 value (Player 1 knob)
        LD   B,A          ; Store Player 1 Knob in B

LOOP    IN   A,($15)      ; Get Horizontal Keypad Feedback
        DJNZ LOOP         ; Decrement B (Loop)
        
        CP   $01          ; Halt button pressed?
        JR   NZ,RAIN      ; Jump to beginning if Halt not pressed

        RET               ; End of Program - Halt pressed

PRGNAM: DB     'R','A','I','N','B','O','W'
        DB     $00        ; End String

; 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
