home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / asm_programming / HSTARS.ZIP / HSTAR.ASM next >
Assembly Source File  |  1993-04-15  |  6KB  |  257 lines

  1. ─────────────────────────────────────────────────────────────────────────────
  2. ;
  3. ;     TITLE: Horizontal Star field
  4. ;WRITTEN BY: DRAEDEN
  5. ;      DATE: 04/16/93
  6. ;
  7. ;     NOTES: Need 286+ to execute.
  8. ;
  9. ;ASSOCIATED FILES:
  10. ;
  11. ;       HSTAR.ASM   =>  This file
  12. ;
  13. ;       HSTAR.BAS   =>  Basic program that generates a set of 'random' star
  14. ;                       locations.  Creates the file 'HSTARS.DW'
  15. ;
  16. ;       HSTAR.TXT   =>  The text file that explains Horizontal "starfields"
  17. ;
  18. ;       HSTARS.DW   =>  Holds the star location data (the structured info)
  19. ;
  20. ────────────────────────────────────────────────────────────────────────────
  21.  
  22.     DOSSEG
  23.     .MODEL SMALL
  24.     .STACK 200h
  25.     .CODE
  26.     .286
  27.     ASSUME CS:@CODE, DS:@CODE
  28.     LOCALS
  29.  
  30.     Ideal
  31.  
  32. ────────────────────────────────────────────────────────────────────────────
  33.  
  34. ScreenWidth  EQU 320
  35. ScreenHeight EQU 200
  36.  
  37. STRUC Star
  38.     XPos    dw  0
  39.     YPos    dw  0
  40.     OldDi   dw  0
  41. ENDS Star
  42.  
  43. Level1  EQU 40      ;40 level 1's
  44. Level2  EQU 70      ;30 level 2's
  45. Level3  EQU 90      ;20 level 3's
  46. Level4  EQU 100     ;10 level 4's -the index of the last of that level
  47.  
  48. VLevel1 dw  1       ;far ones go slow
  49. VLevel2 dw  2
  50. VLevel3 dw  3       
  51. VLevel4 dw  4       ;closest ones go fastest
  52.  
  53. CLevel1 db  4       ;darkest
  54. CLevel2 db  3
  55. CLevel3 db  2       
  56. CLevel4 db  1       ;nearest goes last- over writes others
  57.  
  58. Palette db  63,63,63    ;color for closest star
  59.         db  40,40,40
  60.         db  30,30,30
  61.         db  20,20,20
  62.  
  63. INCLUDE "Hstars.dw"
  64.  
  65. LABEL YposChart WORD    ;chart used to lookup Offset of a Y position
  66.     i=0
  67.     REPT ScreenHeight
  68.         dw i*ScreenWidth
  69.         i=i+1
  70.     ENDM
  71. ────
  72.  
  73. VgaSeg  dw  0A000h      ;VGA segment for mode 13h
  74.  
  75. ────────────────────────────────────────────────────────────────────────────
  76. PROC DisplayAndMoveStars
  77.     pusha
  78.     push    es ds
  79.  
  80.     mov     ax,cs
  81.     mov     ds,ax
  82.     mov     es,[VgaSeg]
  83.  
  84.     mov     si,0
  85.     mov     bp,[VLevel1]                        ;grab velocity
  86.     mov     al,[CLevel1]                        ;grab color
  87. Loop1:
  88.     mov     di,[si + TheStars.OldDi]            ;erase old star
  89.     mov     [byte es:di],0
  90.  
  91.     mov     di,[si + TheStars.Ypos]     
  92.     add     di,di
  93.     mov     di,[di + YposChart]                 ;calculate Y pos offset
  94.  
  95.     add     [si + TheStars.Xpos],bp             ;advance the star
  96.     cmp     [si + TheStars.Xpos],ScreenWidth    ;check range- upper
  97.     jl      NoWrap1
  98.     sub     [si + TheStars.Xpos],ScreenWidth
  99. NoWrap1:
  100.     cmp     [si + TheStars.Xpos],0              ;check range- lower
  101.     jge     NoWrap1b
  102.     add     [si + TheStars.Xpos],ScreenWidth
  103. NoWrap1b:
  104.     add     di,[si + TheStars.Xpos]             ;add in the Xpos
  105.  
  106.     mov     [es:di],al                          ;write dot to screen
  107.     mov     [si + TheStars.OldDi],di            ;save old di
  108.     
  109.     add     si,size Star                        ;see if we are done
  110.     cmp     si,(size Star)*Level1
  111.     jb      loop1
  112.  
  113.     mov     bp,[VLevel2]                        ;same as above, just repeated
  114.     mov     al,[CLevel2]
  115. Loop2:
  116.     mov     di,[si + TheStars.OldDi]
  117.     mov     [byte es:di],0
  118.  
  119.     mov     di,[si + TheStars.Ypos]
  120.     add     di,di
  121.     mov     di,[di + YposChart]
  122.  
  123.     add     [si + TheStars.Xpos],bp
  124.     cmp     [si + TheStars.Xpos],ScreenWidth
  125.     jl      NoWrap2
  126.     sub     [si + TheStars.Xpos],ScreenWidth
  127. NoWrap2:
  128.     cmp     [si + TheStars.Xpos],0
  129.     jge     NoWrap2b
  130.     add     [si + TheStars.Xpos],ScreenWidth
  131. NoWrap2b:
  132.  
  133.     add     di,[si + TheStars.Xpos]
  134.  
  135.     mov     [es:di],al
  136.     mov     [si + TheStars.OldDi],di
  137.     
  138.     add     si,size Star
  139.     cmp     si,(size Star)*Level2
  140.     jb      loop2
  141.  
  142.     mov     bp,[VLevel3]            ;same.. just a repeat for level 3
  143.     mov     al,[CLevel3]
  144. Loop3:
  145.     mov     di,[si + TheStars.OldDi]
  146.     mov     [byte es:di],0
  147.  
  148.     mov     di,[si + TheStars.Ypos]
  149.     add     di,di
  150.     mov     di,[di + YposChart]
  151.  
  152.     add     [si + TheStars.Xpos],bp
  153.     cmp     [si + TheStars.Xpos],ScreenWidth
  154.     jl      NoWrap3
  155.     sub     [si + TheStars.Xpos],ScreenWidth
  156. NoWrap3:
  157.     cmp     [si + TheStars.Xpos],0
  158.     jge     NoWrap3b
  159.     add     [si + TheStars.Xpos],ScreenWidth
  160. NoWrap3b:
  161.  
  162.     add     di,[si + TheStars.Xpos]
  163.  
  164.     mov     [es:di],al
  165.     mov     [si + TheStars.OldDi],di
  166.     
  167.     add     si,size Star
  168.     cmp     si,(size Star)*Level3
  169.     jb      loop3
  170.  
  171.     mov     bp,[VLevel4]            ;repeat for level 4
  172.     mov     al,[CLevel4]
  173. Loop4:
  174.     mov     di,[si + TheStars.OldDi]
  175.     mov     [byte es:di],0
  176.  
  177.     mov     di,[si + TheStars.Ypos]
  178.     add     di,di
  179.     mov     di,[di + YposChart]
  180.  
  181.     add     [si + TheStars.Xpos],bp
  182.     cmp     [si + TheStars.Xpos],ScreenWidth
  183.     jl      NoWrap4
  184.     sub     [si + TheStars.Xpos],ScreenWidth
  185. NoWrap4:
  186.     cmp     [si + TheStars.Xpos],0
  187.     jge     NoWrap4b
  188.     add     [si + TheStars.Xpos],ScreenWidth
  189. NoWrap4b:
  190.  
  191.     add     di,[si + TheStars.Xpos]
  192.  
  193.     mov     [es:di],al
  194.     mov     [si + TheStars.OldDi],di
  195.     
  196.     add     si,size Star
  197.     cmp     si,(size Star)*Level4
  198.     jb      loop4
  199.  
  200.     pop     ds es
  201.     popa
  202.     ret
  203. ENDP DisplayAndMoveStars
  204.  
  205. ────────────────────────────────────────────────────────────────────────────
  206.  
  207. START:
  208.     mov     ax,13h
  209.     int     10h
  210.  
  211.     mov     ax,cs
  212.     mov     es,ax
  213.     mov     ds,ax
  214.  
  215.     mov     dx,offset Palette       ;ES:DX points to palette data
  216.     mov     ax,1012h                ; WRITE palette 
  217.     mov     bx,1                    ;start at color 1
  218.     mov     cx,4                    ; and write 4 of 'em
  219.     int     10h
  220.  
  221. MainLoop:
  222.  
  223.     mov     dx,3dah
  224. @@VRT:
  225.     in      al,dx
  226.     test    al,8
  227.     jnz     @@VRT         ;wait until Verticle Retrace starts
  228. @@NoVRT:
  229.     in      al,dx
  230.     test    al,8
  231.     jz      @@NoVRT       ;wait until Verticle Retrace Ends
  232.  
  233.     call    DisplayAndMoveStars                        
  234.  
  235.     mov     ah,1
  236.     int     16h
  237.     jz      MainLoop
  238.  
  239.     xor     ah,ah
  240.     int     16h
  241.     cmp     al," "
  242.     jne     ByeBye
  243.  
  244.     neg     [VLevel1]
  245.     neg     [VLevel2]
  246.     neg     [VLevel3]
  247.     neg     [VLevel4]
  248.     jmp     MainLoop
  249.  
  250. ByeBye:
  251.     mov     ax,3
  252.     int     10h
  253.     mov     ax,4c00h
  254.     int     21h
  255.  
  256. END Start
  257.