home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / ASM / ASMLIB40.ZIP / ASM4DEMO.ZIP / RANDDOTS.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-08-28  |  1.6 KB  |  94 lines

  1. include    asm.inc
  2.  
  3. ; library functions
  4. extrn    random:proc, putdot:proc, getkey:proc, smalltext:proc
  5. extrn    gprint2x:proc, gcolor:proc, keywaiting:proc, clearkey:proc
  6. extrn    gprintdown2x:proc, gprint:proc
  7.  
  8. extrn    graphmode:proc
  9. extrn    textmode:proc
  10.  
  11. .data
  12. extrn    drawmode:byte
  13. extrn    maxx:word, maxy:word
  14. xfactor    dw 0            ; scale factor for x-dimension
  15. yfactor    dw 0            ; scale factor for y-dimension
  16. x    dw 0            ; x-coordinate
  17. y    dw 0            ; y-coordinate
  18. count    db 10            ; do 10*64k dots
  19. msg    db '640 k random dots',0
  20. escape    db 'press any key to stop',0
  21.  
  22. .code
  23. public    randomdots
  24. randomdots    proc
  25. ; save all registers used by the subroutine
  26.     push    ax
  27.     push    bx
  28.     push    cx
  29.     push    dx
  30.     push    si
  31.  
  32. ; kick it into graphics mode
  33.     call    graphmode
  34.  
  35.     mov    ax,7
  36.     call    gcolor
  37.     mov    x,0
  38.     mov    y,0
  39.     lea    dx,x
  40.     lea    si,msg
  41.     call    smalltext
  42.     call    gprint2x
  43.     add    x+2,16
  44.     lea    si,escape
  45.     call    gprint
  46.  
  47.     mov    count,10
  48.     xor    dx,dx
  49.     mov    ax,65535
  50.     mov    bx,maxx
  51.     div    bx
  52.     mov    xfactor,ax
  53.     mov    ax,65535
  54.     xor    dx,dx
  55.     mov    bx,maxy
  56.     div    bx
  57.     mov    yfactor,ax
  58.  
  59.     mov    drawmode,0
  60.     mov    cx,0
  61.  
  62. s1:    call    random            ; returns AX = random number
  63.     call    gcolor            ; so I get a random color
  64.     call    random            ; for a random x
  65.     mov    bx,xfactor
  66.     xor    dx,dx
  67.     div    bx
  68.     mov    x,ax
  69.     call    random            ; for a random y
  70.     mov    bx,yfactor
  71.     xor    dx,dx
  72.     div    bx
  73.     mov    y,ax
  74.     lea    bx,x
  75.     call    putdot            ; update the pixel
  76.     call    keywaiting        ; exit loop if a key has been pressed
  77.     or    ax,ax
  78.     jnz    s3
  79.     loop    s1
  80.     dec    count
  81.     jnz    s1
  82.  
  83. s3:    mov    drawmode,1
  84.     call    clearkey
  85.     call    getkey
  86.     pop    si
  87.     pop    dx
  88.     pop    cx
  89.     pop    bx
  90.     pop    ax
  91.     jmp    textmode
  92. randomdots    endp
  93.     end
  94.