         ORG  #100
	 RUN  $
;
;	 Zoom initiation.
;	 By Targhan/Arkos in 2000.
;	 Crappy code inside...
;
;	 Source code extracted from Dams to Maxam (Winape).
;	 Should run on Dams with minimal modifications.
;
GFX      EQU  #1000
WIDTH    EQU  50                        ;Width of the gfx IN BYTE
WIDT2    EQU  80                        ;Width IN BYTE of the Zoom
HEIGHT   EQU  15                        ;Height in line of the Zoom
;
         LD   A,1
         CALL #BC0E
;
         LD   HL,TEXT1
         CALL WRITTER
         LD   HL,TEXT2
         CALL WRITTER
         LD   HL,1*256 + 24
         CALL #BB75
         LD   HL,TEXT3
         CALL WRITTER
;
         DI   
         EXX  
         PUSH BC
         LD   HL,(#38)
         LD   (SAVE38),HL
         LD   HL,#C9FB
         LD   (#38),HL
;
         CALL TRANSF
;
INIT
	 XOR  A
         LD   (ZDECI),A
	 INC  A
         LD   (ZOOM),A
;
SYNC     LD   B,#F5
	 IN   A,(C)
         RRA  
         JR   NC,SYNC+2
;
         LD   HL,GFX
         LD   (SRC),HL
         LD   DE,#C0A0
         LD   (DEST),DE
         LD   IXH,HEIGHT
;
YLOOP    LD   HL,(SRC)
         LD   B,H
         LD   C,L
         LD   DE,(DEST)
         LD   IXL,WIDT2
         EXX  
         LD   HL,0
         LD   B,H
         LD   A,(ZOOM)
         LD   D,A
         LD   A,(ZDECI)
         LD   E,A
         EXX  
;
;
;
;
XLOOP
         LD   A,(HL)			;Read the current byte of the gfx.
         LD   (DE),A			;Display it on the screen.
         INC  DE			;Move to the next byte on the screen.
;
         EXX  
;
         ADD  HL,DE			;NEXT = NEXT (H,L) + ZOOM (D,E)
         LD   A,H
;
         EXX  
         LD   H,0
         LD   L,A
         ADD  HL,BC			;BC = address of the first byte of the current line of the gfx.
;					 HL + A = next byte of the current line to display.
;
         DEC  IXL			;Next byte in X !
         JR   NZ,XLOOP
;
;
;
YNEXT    LD   HL,(DEST)			;Next line of the gfx...
         LD   A,H
         ADD  A,8
         LD   H,A
         JR   NC,YNOTC
         LD   BC,#C050
         ADD  HL,BC
YNOTC    LD   (DEST),HL
;
         LD   HL,(SRC)
         LD   DE,WIDTH*4
         ADD  HL,DE
         LD   (SRC),HL
;
	 DEC  IXH
	 JR   NZ,YLOOP
;
;
;
;
;
;
KEY      LD   A,5+64
         CALL KEYCODE
         CP   %01111111
         JP   Z,EXIT
;
         LD   A,0+64
         CALL KEYCODE
         CP   %11111101
         JR   Z,RIGHT
;
         LD   A,1+64
         CALL KEYCODE
         CP   %11111110
         JR   Z,LEFT
;
         JP   SYNC
;
LEFT     LD   A,(ZOOM)
         LD   H,A
         LD   A,(ZDECI)
         LD   L,A
         LD   DE,10
         ADD  HL,DE
LEFT2
         LD   A,H
         LD   (ZOOM),A
         LD   A,L
         LD   (ZDECI),A
         JP   SYNC
;
RIGHT    LD   A,(ZOOM)
         LD   H,A
         LD   A,(ZDECI)
         LD   L,A
         LD   DE,10
         OR   A
         SBC  HL,DE
         JR   NC,LEFT2
         LD   HL,0*256 + 1
	 JR   LEFT2
;
KEYCODE
	 LD BC,#F782
	 OUT (C),C
	 LD BC,#F40E
	 OUT (C),C
	 LD BC,#F6C0
	 OUT (C),C
	 DEFB #ed,#71
	 LD BC,#F792
	 OUT (C),C
	 DEC B
	 OUT (C),A
	 LD B,#F4
	 IN A,(C)
	 LD BC,#F782
	 OUT (C),C
	 DEC B
	 DEFB #ed,#71
	 RET
;
WRITTER  LD   A,(HL)
	 OR   A
         JR   Z,WRIT2
         CALL #BB5A
         PUSH HL
WRIT0    LD   A,R
         AND  %00000011
         OR   A
         JR   NZ,WRIT1
         JR   WRIT0
WRIT1    CALL #BB90
         POP  HL
         INC  HL
         JR   WRITTER
WRIT2
         LD   A,#A
         CALL #BB5A
         LD   A,#D
         CALL #BB5A
         RET  
;
EXIT     LD   HL,(SAVE38)
         LD   (#38),HL
         POP  BC
         EXX  
         RET  
;
;Converts each pixel of a mode 1 gfx on the screen into bytes.
;The resulting gfx is four times bigger.
TRANSF   LD   HL,#C000
         LD   (SRC),HL
         LD   DE,GFX
         LD   A,HEIGHT
         LD   (TRCOUNT+1),A
;
TRLOOP
         CALL TRLIGN
;
         LD   HL,(SRC)
         LD   A,H
         ADD  A,8
         LD   H,A
         JR   NC,TRNOTC
         LD   BC,#C050
         ADD  HL,BC
TRNOTC   LD   (SRC),HL
;
TRCOUNT  LD   A,HEIGHT
         DEC  A
         RET  Z
         LD   (TRCOUNT+1),A
         JR   TRLOOP
;
TRLIGN   LD   HL,(SRC)
         LD   B,WIDTH
;
TRNEXT   LD   A,(HL)
         AND  %10001000
         RR   A
         RR   A
         RR   A
         CALL TRCODE
         INC  DE
;
         LD   A,(HL)
         AND  %01000100
         RR   A
         RR   A
         CALL TRCODE
         INC  DE
;
         LD   A,(HL)
         AND  %00100010
         RR   A
         CALL TRCODE
         INC  DE
;
         LD   A,(HL)
         AND  %00010001
         CALL TRCODE
         INC  DE
;
         INC  HL
         DJNZ TRNEXT
         RET  
;
TRCODE   OR   A
         JR   Z,T00
         CP   %00000001
         JR   Z,T01
         CP   %00010000
         JR   Z,T10
         JR   T11
;
T00
         LD   (DE),A
         RET  
T01      LD   A,%00001111
         LD   (DE),A
         RET  
T10      LD   A,%11110000
         LD   (DE),A
         RET  
T11      LD   A,255
         LD   (DE),A
         RET  
;
SAVE38   DEFW 0
SRC      DEFW 0
DEST     DEFW 0
ZOOM     DEFB 0
ZDECI    DEFB 0
TEXT1    DEFB "HELLO",0
TEXT2    DEFB "EVRY1",0
TEXT3    DEFB "USE THE LEFT AND RIGHT KEYS...",0
