;---------------------------------------------------------------------------
; screen.asm written by Jim Gage 3/5/96
; sample program for gasm that tests a small number of gasm features
; fills the screen with color
;---------------------------------------------------------------------------
; code
;---------------------------------------------------------------------------

@start:
  push  cs
  pop   ds
  mov   dx,offset words1 ;give a little response
  mov   ah,9
  int   021h

  call  @keypress  ;wait for keypress

  cld              ;clear decrement

  mov   ax,013h    ;set video mode to 13 h
  int   010h


  mov   bx,0a000h  ;setup to move data into a000:0000
  mov   es,bx
  xor   di,di

; palette change
  mov   cx,201     ;200 colors
@loop1:            ;set screen palette
  mov   al,0ffh
  mov   dx,03c7h
  out   dx,al
  mov   al,cl
  mov   dx,03c8h
  out   dx,al
  mov   dx,03c9h   ;green
  mov   ax,cx
  shr   ax
  shr   ax
  out   dx,al
  mov   al,0
  out   dx,al
  out   dx,al
  loop  @loop1

; fill the screen with lines
  mov   cx,200     ;screen height is 200
@loop:             ;place to loop back to

  push  cx         ;save this

  mov   al,cl      ;now just store what's in cl 320 times
  mov   cx,320
  rep   stosb
  pop   cx
  loop  @loop

  call @keypress

  mov   cx,201     ;200 colors
@loop2:            ;set screen palette
  mov   al,0ffh
  mov   dx,03c7h
  out   dx,al
  mov   al,cl
  mov   dx,03c8h
  out   dx,al
  mov   dx,03c9h   
  mov   ax,cx
  neg   ax
  add   ax,201
  shr   ax
  shr   ax
  out   dx,al
  mov   al,0       
  out   dx,al
  mov   ax,cx      ;blue
  shr   ax
  shr   ax
  out   dx,al
  loop  @loop2

  call @keypress

  mov   cx,201     ;200 colors
@loop3:            ;set screen palette
  mov   al,0ffh
  mov   dx,03c7h
  out   dx,al
  mov   al,cl
  mov   dx,03c8h
  out   dx,al
  mov   dx,03c9h   ;green
  mov   al,0
  out   dx,al
  mov   ax,cx
  shr   ax
  shr   ax
  out   dx,al
  mov   al,0
  out   dx,al
  loop  @loop3

  call @keypress

  mov   ax,03h     ;get text screen back
  int   010h

  push  cs
  pop   ds
  mov   dx,offset words2 ;give a little response
  mov   ah,9
  int   021h

  mov   ax,04c00h  ;go back to DOS
  int   021h

;---------------------------------------------------------------------------
; function keypress
;---------------------------------------------------------------------------

@keypress:
  mov   ah,0       ;wait for keypress
  int   016h
  ret

;---------------------------------------------------------------------------
; data
;---------------------------------------------------------------------------

words1 db "Short assembly program to fill color palette.",0dh,0ah
       db "Press any key.",0dh,0ah,"$"
words2 db "This sample program was compiled with gasm.$"
