; Title - Flying Witch Demo
;         (General Video Assembler Sample Program 2)
; By    - General Video
; Typed in by - Adam Trionfo
; Rev   - 1.0 - February 16, 2006
; 
; About this Program
; ------------------ 
;
; From the General Video Assembler Documentation
; (Appendix G):
;
; Assemble for target address 24576.
;
; A more complicated graphics program illustrating how
; an image may be vectored around the screen during the
; screen interrupt provided by the hardware. After
; CALLing the routine, notice that it continues to
; execute in background while you regain control of the
; normal Basic facilities. That is, the little witch
; continues to fly around the screen. You can stop her by 
; negating the call to your interrupt routine with the
; following instruction:
;
;     %(20118)=8701
;
; You can easily write a Basic program that draws a
; haunted house and then CALLs 24576 to start the little
; witch flying. Your program continues to execute, and so
; does the background graphic until your Basic program
; issues the above command.
;
; 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 flywitch.bin -x flywitch.lst flywitch.asm

        ORG    $6000      ; First byte of extra RAM

; Demo - Flying Witch
; Set up Screen Interrupt and Draw 1st Image

        DI                ; Disable Interrupts
        EXX               ; Save Regs
        EX     AF,AF'
        LD     HL,IRTN    ; Address of Interrupt RTN
        LD     ($4E96),HL
        LD     A,130      ; Sync
        OUT    (15),A
        RST    $38        ; Call Write
        DB     7          ; Routine
        DW     WRITE
        EXX               ; Restore Regs
        EX     AF,AF'
        EI                ; Enable Interrupts
        RET               ; Go Back

; Interrupt Routine
IRTN    LD     ($6FFE),SP ; New
        LD     SP,$6FFE   ; Stack
        PUSH   AF         ; Save Regs
        PUSH   BC
        PUSH   DE
        PUSH   HL
        PUSH   IX
        LD     A,80         ; Speed in Ta-
        LD     (MOTION+2),A ; ble
        RST    $38
        DB     0          ; Mult Calls
        DB     7          ; Erase Image
        DW     WRITE
        DB     $3F        ; Vector Image
        DW     MOTION
        DW     WIDTH
        DB     7          ; Write Image
        DW     WRITE
        DB     2          ; End Calls
        POP    IX         ; Restore Regs
        POP    HL
        POP    DE
        POP    BC
        POP    AF
        LD     SP,($6FFE)
        JP     $21FD      ; To BASIC's Normal Interrupts
WRITE   DB     $1F        ; Write it
        DW     MOTION
        DW     RFRNCE
        DB     8          ; Return
WIDTH   DW     $9800
        DW     $4C00      ; Height
RFRNCE  DW     0          ; Image Definition
        DB     2          ; Bytes Wide
        DB     8          ; Pixels High
        DW     $0008      ; Witch's
        DW     $800A      ; Image
        DW     $022A
        DW     $8802
        DW     $A002
        DW     $A802
        DW     $A8A8
        DW     $A820
MOTION  DW     $8020
        DB     $05        ; Speed
        DW     $5         ; Change in X
        DW     0          ; X Position
        DW     3          ; Flag
        DW     1          ; Change in Y
        DW     0          ; Y Position
        DB     3          ; Flag

; End of Program
