{ _GRAPH.PAS  - Ansgar Scherp, Joachim Gelhaus
  all rights reserved / vt'95 }

procedure get_ground_s1;
var z:byte;
    z1,z2,z3,z4:word;
begin
  z3:=bally+48;
  z4:=ballx div 4;
  asm
    push ax
    push dx
    mov ax,0004h
    mov dx,03ceh
    out dx, ax
    pop dx
    pop ax

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      mov z1,ax

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax

      mov es,[groundseg]
      mov ds,[vseg]
      mov si,z2
      mov di,z1
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16

      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  asm
    push ax
    push dx
    mov ax,0104h
    mov dx,03ceh
    out dx, ax
    pop dx
    pop ax

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,64
      mov z1,ax

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax

      mov es,[groundseg]
      mov ds,[vseg]
      mov si,z2
      mov di,z1
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16

      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  asm
    push ax
    push dx
    mov ax,0204h
    mov dx,03ceh
    out dx, ax
    pop dx
    pop ax

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,128
      mov z1,ax

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax

      mov es,[groundseg]
      mov ds,[vseg]
      mov si,z2
      mov di,z1
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16

      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  asm
    push ax
    push dx
    mov ax,0304h
    mov dx,03ceh
    out dx, ax
    pop dx
    pop ax

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,192
      mov z1,ax

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax

      mov es,[groundseg]
      mov ds,[vseg]
      mov si,z2
      mov di,z1
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16

      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
end;

procedure get_ground_s2;
var z:byte;
    z1,z2,z3,z4:word;
begin
  z3:=bally+48;
  z4:=ballx div 4;
  asm
    push ax
    push dx
    mov ax,0104h
    mov dx,03ceh
    out dx, ax
    pop dx
    pop ax

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      mov z1,ax

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax

      mov es,[groundseg]
      mov ds,[vseg]
      mov si,z2
      mov di,z1
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16

      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  asm
    push ax
    push dx
    mov ax,0204h
    mov dx,03ceh
    out dx, ax
    pop dx
    pop ax

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,64
      mov z1,ax

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax

      mov es,[groundseg]
      mov ds,[vseg]
      mov si,z2
      mov di,z1
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16

      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  asm
    push ax
    push dx
    mov ax,0304h
    mov dx,03ceh
    out dx, ax
    pop dx
    pop ax

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,128
      mov z1,ax

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax

      mov es,[groundseg]
      mov ds,[vseg]
      mov si,z2
      mov di,z1
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16

      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  asm
    push ax
    push dx
    mov ax,0004h
    mov dx,03ceh
    out dx, ax
    pop dx
    pop ax

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,192
      mov z1,ax

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax

      mov es,[groundseg]
      mov ds,[vseg]
      mov si,z2
      mov di,z1
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16

      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
end;

procedure get_ground_s3;
var z:byte;
    z1,z2,z3,z4:word;
begin
  z3:=bally+48;
  z4:=ballx div 4;
  asm
    push ax
    push dx
    mov ax,0204h
    mov dx,03ceh
    out dx, ax
    pop dx
    pop ax

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      mov z1,ax

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax

      mov es,[groundseg]
      mov ds,[vseg]
      mov si,z2
      mov di,z1
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16

      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  asm
    push ax
    push dx
    mov ax,0304h
    mov dx,03ceh
    out dx, ax
    pop dx
    pop ax

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,64
      mov z1,ax

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax

      mov es,[groundseg]
      mov ds,[vseg]
      mov si,z2
      mov di,z1
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16

      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
  asm
    push ax
    push dx
    mov ax,0004h
    mov dx,03ceh
    out dx, ax
    pop dx
    pop ax

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,128
      mov z1,ax

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax

      mov es,[groundseg]
      mov ds,[vseg]
      mov si,z2
      mov di,z1
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16

      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
  asm
    push ax
    push dx
    mov ax,0104h
    mov dx,03ceh
    out dx, ax
    pop dx
    pop ax

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,192
      mov z1,ax

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax

      mov es,[groundseg]
      mov ds,[vseg]
      mov si,z2
      mov di,z1
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16

      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
end;

procedure get_ground_s4;
var z:byte;
    z1,z2,z3,z4:word;
begin
  z3:=bally+48;
  z4:=ballx div 4;
  asm
    push ax
    push dx
    mov ax,0304h
    mov dx,03ceh
    out dx, ax
    pop dx
    pop ax

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      mov z1,ax

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax

      mov es,[groundseg]
      mov ds,[vseg]
      mov si,z2
      mov di,z1
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16

      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
  asm
    push ax
    push dx
    mov ax,0004h
    mov dx,03ceh
    out dx, ax
    pop dx
    pop ax

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,64
      mov z1,ax

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax

      mov es,[groundseg]
      mov ds,[vseg]
      mov si,z2
      mov di,z1
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16

      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
  asm
    push ax
    push dx
    mov ax,0104h
    mov dx,03ceh
    out dx, ax
    pop dx
    pop ax

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,128
      mov z1,ax

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax

      mov es,[groundseg]
      mov ds,[vseg]
      mov si,z2
      mov di,z1
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16

      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
  asm
    push ax
    push dx
    mov ax,0204h
    mov dx,03ceh
    out dx, ax
    pop dx
    pop ax

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,192
      mov z1,ax

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax

      mov es,[groundseg]
      mov ds,[vseg]
      mov si,z2
      mov di,z1
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16

      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

end;

procedure draw_ball_s1;
var z:byte;
    z1,z2,z3,z4:word;
begin

  {DRAW_BALL_s1 1}
  z3:=bally+48;
  z4:=ballx div 4;
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,258
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      mov z1,ax { z1:=z*4;}
      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[ballseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,4
      @l1:
        mov al,[ds:si]
        or al,al
        jz @l2
        mov ah,[es:di]
        cmp ah,farbe
        jz @l2
        mov [es:di],al
        @l2:
        inc si
        inc di
        dec cx
      jnz @l1
      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {DRAW_BALL_s1 2}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,514
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,64
      mov z1,ax { z1:=z*4;}
      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[ballseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,4
      @l1:
        mov al,[ds:si]
        or al,al
        jz @l2
        mov ah,[es:di]
        cmp ah,farbe
        jz @l2
        mov [es:di],al
        @l2:
        inc si
        inc di
        dec cx
      jnz @l1
      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {DRAW_BALL_s1 3}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,1026
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,128
      mov z1,ax { z1:=z*4;}
      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[ballseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,4
      @l1:
        mov al,[ds:si]
        or al,al
        jz @l2
        mov ah,[es:di]
        cmp ah,farbe
        jz @l2
        mov [es:di],al
        @l2:
        inc si
        inc di
        dec cx
      jnz @l1
      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {DRAW_BALL_s1 4}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,2050
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,192
      mov z1,ax { z1:=z*4;}
      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[ballseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,4
      @l1:
        mov al,[ds:si]
        or al,al
        jz @l2
        mov ah,[es:di]
        cmp ah,farbe
        jz @l2
        mov [es:di],al
        @l2:
        inc si
        inc di
        dec cx
      jnz @l1
      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
end;

procedure draw_ball_s2;
var z:byte;
    z1,z2,z3,z4:word;
begin

  z3:=bally+48;
  z4:=ballx div 4;
  {draw_ball_s2 1}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,514
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      mov z1,ax { z1:=z*4;}
      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[ballseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,4
      @l1:
        mov al,[ds:si]
        or al,al
        jz @l2
        mov ah,[es:di] {hole farbe}
        cmp ah,farbe
        jz @l2
        mov [es:di],al {setzt einen punkt}
        @l2:
        inc si
        inc di
        dec cx
      jnz @l1
      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {draw_ball_s2 2}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,1026
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,64
      mov z1,ax { z1:=z*4;}
      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[ballseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,4
      @l1:
        mov al,[ds:si]
        or al,al
        jz @l2
        mov ah,[es:di]
        cmp ah,farbe
        jz @l2
        mov [es:di],al
        @l2:
        inc si
        inc di
        dec cx
      jnz @l1
      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {draw_ball_s2 3}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,2050
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,128
      mov z1,ax { z1:=z*4;}
      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[ballseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,4
      @l1:
        mov al,[ds:si]
        or al,al
        jz @l2
        mov ah,[es:di]
        cmp ah,farbe
        jz @l2
        mov [es:di],al
        @l2:
        inc si
        inc di
        dec cx
      jnz @l1
      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {DRAW_BALL_S2 4}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,258
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,192
      mov z1,ax { z1:=z*4;}
      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[ballseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,4
      @l1:
        mov al,[ds:si]
        or al,al
        jz @l2
        mov ah,[es:di]
        cmp ah,farbe
        jz @l2
        mov [es:di],al
        @l2:
        inc si
        inc di
        dec cx
      jnz @l1
      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
end;

procedure draw_ball_s3;
var z:byte;
    z1,z2,z3,z4:word;
begin
  z3:=bally+48;
  z4:=ballx div 4;
  {draw_ball_s3 1}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,1026
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      mov z1,ax { z1:=z*4;}
      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[ballseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,4
      @l1:
        mov al,[ds:si]
        or al,al
        jz @l2
        mov ah,[es:di]
        cmp ah,farbe
        jz @l2
        mov [es:di],al
        @l2:
        inc si
        inc di
        dec cx
      jnz @l1
      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {draw_ball_s3 2}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,2050
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,64
      mov z1,ax { z1:=z*4;}
      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[ballseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,4
      @l1:
        mov al,[ds:si]
        or al,al
        jz @l2
        mov ah,[es:di]
        cmp ah,farbe
        jz @l2
        mov [es:di],al
        @l2:
        inc si
        inc di
        dec cx
      jnz @l1
      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {DRAW_BALL_S3 3}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,258
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,128
      mov z1,ax { z1:=z*4;}
      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[ballseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,4
      @l1:
        mov al,[ds:si]
        or al,al
        jz @l2
        mov ah,[es:di]
        cmp ah,farbe
        jz @l2
        mov [es:di],al
        @l2:
        inc si
        inc di
        dec cx
      jnz @l1
      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
  {draw_ball_s3 4}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,514
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,192
      mov z1,ax { z1:=z*4;}
      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[ballseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,4
      @l1:
        mov al,[ds:si]
        or al,al
        jz @l2
        mov ah,[es:di]
        cmp ah,farbe
        jz @l2
        mov [es:di],al
        @l2:
        inc si
        inc di
        dec cx
      jnz @l1
      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
end;

procedure draw_ball_s4;
var z:byte;
    z1,z2,z3,z4:word;
begin
  z3:=bally+48;
  z4:=ballx div 4;
  {draw_ball_s4 1}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,2050
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      mov z1,ax { z1:=z*4;}
      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[ballseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,4
      @l1:
        mov al,[ds:si]
        or al,al
        jz @l2
        mov ah,[es:di]
        cmp ah,farbe
        jz @l2
        mov [es:di],al
        @l2:
        inc si
        inc di
        dec cx
      jnz @l1
      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {draw_ball_s4 2}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,258
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,64
      mov z1,ax { z1:=z*4;}
      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[ballseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,4
      @l1:
        mov al,[ds:si]
        or al,al
        jz @l2
        mov ah,[es:di]
        cmp ah,farbe
        jz @l2
        mov [es:di],al
        @l2:
        inc si
        inc di
        dec cx
      jnz @l1
      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
  {draw_ball_s4 3}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,514
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,128
      mov z1,ax { z1:=z*4;}
      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[ballseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,4
      @l1:
        mov al,[ds:si]
        or al,al
        jz @l2
        mov ah,[es:di]
        cmp ah,farbe
        jz @l2
        mov [es:di],al
        @l2:
        inc si
        inc di
        dec cx
      jnz @l1
      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
  {draw_ball_s4 4}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,1026
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,192
      mov z1,ax { z1:=z*4;}
      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[ballseg] {DS:SI}
      mov si,z1
      mov di,z2
      mov cx,4
      @l1:
        mov al,[ds:si]
        or al,al
        jz @l2
        mov ah,[es:di]
        cmp ah,farbe
        jz @l2
        mov [es:di],al
        @l2:
        inc si
        inc di
        dec cx
      jnz @l1
      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;


end;


procedure draw_ground_s1;
var z:byte;
    z1,z2,z3,z4:word;
begin
  {Draw_Ground_s1 1}
  z3:=by_old+48;
  z4:=bx_old div 4;
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,258
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      mov z1,ax { z1:=z*4;}

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[groundseg]
      mov si,z1
      mov di,z2
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {Draw_Ground_S1 2}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,514
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,64
      mov z1,ax { z1:=z*4;}

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[groundseg]
      mov si,z1
      mov di,z2
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

 {Draw_Ground_S1 3}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,1026
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,128
      mov z1,ax { z1:=z*4;}

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[groundseg]
      mov si,z1
      mov di,z2
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {Draw_Ground_S1 4}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,2050
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,192
      mov z1,ax { z1:=z*4;}

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[groundseg]
      mov si,z1
      mov di,z2
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
end;

procedure draw_ground_s2;
var z:byte;
    z1,z2,z3,z4:word;
begin
  z3:=by_old+48;
  z4:=bx_old div 4;

  {Draw_Ground_S2 1}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,514
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      mov z1,ax { z1:=z*4;}

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[groundseg]
      mov si,z1
      mov di,z2
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

 {Draw_Ground_S2 2}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,1026
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,64
      mov z1,ax { z1:=z*4;}

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[groundseg]
      mov si,z1
      mov di,z2
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {Draw_Ground_S2 3}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,2050
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,128
      mov z1,ax { z1:=z*4;}

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[groundseg]
      mov si,z1
      mov di,z2
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {DRAW_GROUND_S2 4}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,258
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,192
      mov z1,ax { z1:=z*4;}

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[groundseg]
      mov si,z1
      mov di,z2
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
end;

procedure draw_ground_s3;
var z:byte;
    z1,z2,z3,z4:word;
begin
  z3:=by_old+48;
  z4:=bx_old div 4;

 {draw_ground_s3 1}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,1026
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      mov z1,ax { z1:=z*4;}

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[groundseg]
      mov si,z1
      mov di,z2
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {draw_ground_s3 2}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,2050
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,64
      mov z1,ax { z1:=z*4;}

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[groundseg]
      mov si,z1
      mov di,z2
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {draw_ground_s3 3}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,258
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,128
      mov z1,ax { z1:=z*4;}

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[groundseg]
      mov si,z1
      mov di,z2
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {draw_ground_s3 4}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,514
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,192
      mov z1,ax { z1:=z*4;}

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[groundseg]
      mov si,z1
      mov di,z2
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
end;

procedure draw_ground_s4;
var z:byte;
    z1,z2,z3,z4:word;
begin
  z3:=by_old+48;
  z4:=bx_old div 4;
  {draw_ground_s4 1}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,2050
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      mov z1,ax { z1:=z*4;}

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[groundseg]
      mov si,z1
      mov di,z2
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {draw_ground_s4 2}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,258
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,64
      mov z1,ax { z1:=z*4;}

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[groundseg]
      mov si,z1
      mov di,z2
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

  {draw_ground_s4 3}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,514
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,128
      mov z1,ax { z1:=z*4;}

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[groundseg]
      mov si,z1
      mov di,z2
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;

 {draw_ground_s4 4}
  asm
    push dx
    push ax
    mov dx,03c4h
    mov ax,1026
    out dx,ax
    pop ax
    pop dx

    push ax
    push si
    push di
    push cx
    push es

    mov z,1
    @loop:
      push ds
      xor ah,ah
      mov al,z
      mov cl,4
      mul cl
      add ax,192
      mov z1,ax { z1:=z*4;}

      xor ah,ah
      mov al,z
      add ax,z3
      mov cx,80
      mul cx
      add ax,z4
      inc ax
      mov z2,ax {z2:=(z+z3)*80+z4;}

      mov es,[vseg]   {ES:DI}
      mov ds,[groundseg]
      mov si,z1
      mov di,z2
      mov cx,2
      rep movsw

      mov al,z
      inc al
      mov z,al
      cmp al,16
      pop ds
    jnz @loop
    pop es
    pop cx
    pop di
    pop si
    pop ax
  end;
end;


