home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / demos / baah / TinyDemos / ShadeDots / Shade_Src next >
Encoding:
Text File  |  1996-12-22  |  13.1 KB  |  288 lines

  1. ;                                     \|/
  2. ;                                     O O
  3. ; --------------------------------oOO--U--OOo--------------------------------
  4. ; |                                                                         |
  5. ; |                               Shade Dots.                               |
  6. ; |                      By Alain BROBECKER. (as Baah)                      |
  7. ; |                                                        25 december 1995 |
  8. ; ---------------------------------------------------------------------------
  9. ;   This source is an example of my latest dot shading and unshading routine.
  10. ; The demo consist in many "shadedots" and "unshadedots" moving randomly
  11. ; on the screen, thus giving a quite nice pattern.
  12. ;   The main features of the shading routines are their speed and also the
  13. ; "bounding", ie they leave all pixels with color between max_value+1 and 15
  14. ; unaltered. (This allows to have foreground images without redrawing them
  15. ; all the time) The rest of the code is optimised for size, not for speed.
  16. ; The resulting executable is 788 bytes longs, which is quite ok.
  17. ;   This was written on a 1Meg A3000, with 800kb floppy. The assembler used
  18. ; is ExtASM 0.50b. If you want to assemble with another prog, or a newer
  19. ; version of ExtASM, you' ll have to make changes. Good luck.
  20.  
  21. ;   If you liked this little demo, or the sourcecode, please send me a nice
  22. ; postcard. (Cheap and very valuable to me when I receive it) Also, in case
  23. ; you use my code in one of your demo, please send it to me. You can get in
  24. ; touch with me for any reasons...
  25. ;
  26. ;           Alain BROBECKER         Dracula / Positivity (STe)
  27. ;           rte de Dardagny         Baah / Arm's Tech (Archie)
  28. ;            01630 CHALLEX                           Baah (PC)
  29. ;               FRANCE
  30.  
  31. ; 14 may 96 -- random number generator has been improved, it' s now faster,
  32. ;           smaller and it uses only one register. Code is now 776 bytes.
  33.  
  34. #name       ShadeDots
  35.  
  36. ;------>  Constants  <-------------------------------------------------------
  37. #set        nb_points = 64          ; Nb of points to process each frame.
  38. #set        nb_iter = 16            ; Nb of iterations per point.
  39. #set        max_value = 13          ; Maximum value for shading effect.
  40.  
  41. ;------>  BSS Labels Offsets  <----------------------------------------------
  42. #set        old_pc = 0
  43. #set        points_coords = 4
  44.  
  45.  
  46. ;****************************************************************************
  47. ;****************************************************************************
  48. ;*****                                                                  *****
  49. ;*****                              MACROS                              *****
  50. ;*****                                                                  *****
  51. ;****************************************************************************
  52. ;****************************************************************************
  53.  
  54. ;------>  Shade_Mode9  <-----------------------------------------------------
  55. ; At first, we calculate the adress of the longword which contains the pixel
  56. ; and also the shift we must use to place the pixel in the upper quartet of
  57. ; a register. Once the long is loaded, we compare max_value<<28 and the
  58. ; register with the applied shift. (Note that the other quartets in the
  59. ; register are not always null, and we must take this in account) If pixel
  60. ; value is lower than the max, then we shade it in the original long and
  61. ; save the modified long back in video memory.
  62. ;           m0=videoram adress.
  63. ;           m1=%111<<2
  64. ;           m2=1<<28
  65. ;           m3=max_value<<28
  66. ;           m4=x
  67. ;           m5=y
  68. ;           m6-m8 are temporary registers. (We can choose m6=m4 and m7=m5)
  69. macro shade_mode9 m0,m1,m2,m3,m4,m5,m6,m7,m8
  70. { add       m7,m5,m5,lsl #2         ; Make m7 points on good line.
  71.   add       m7,m0,m7,lsl #5
  72.   mov       m8,m4,lsr #3            ; m8=int(x/8).
  73.   bic       m6,m1,m4,lsl #2         ; m6=4*(not(x) mod8)=shift.
  74.   ldr       m8,[m7,m8,lsl #2]!      ; m7=long adress | m8=long.
  75.   cmp       m3,m8,lsl m6            ; Flags=max_value<<28-pixie<<28.
  76.   addHI     m8,m8,m2,lsr m6         ; Shade if max_value higher than pixie,
  77.   strHI     m8,[m7]                 ;   and save the long back.
  78. }
  79.  
  80. ;------>  UnShade_Mode9  <---------------------------------------------------
  81. ; The basic idea is the same as for the shading, except that we don' t want
  82. ; to change color of pixel if it' s 0 or higher than max_value. In order to
  83. ; have both conditions tested at same time, I substract 1 to the pixel value
  84. ; with wrapping. (mod16) Then if (pixel-1 mod16) is lower than max_value,
  85. ; we unshade it and save the long back.
  86. ;           m0=videoram adress.
  87. ;           m1=%111<<2
  88. ;           m2=1<<28
  89. ;           m3=x
  90. ;           m4=y
  91. ;           m5-m8 are temporary registers. (We can choose m5=m3 and m6=m4)
  92. macro unshade_mode9 m0,m1,m2,m3,m4,m5,m6,m7,m8
  93. { add       m6,m4,m4,lsl #2         ; Make m6 points on good line.
  94.   add       m6,m0,m6,lsl #5
  95.   mov       m7,m3,lsr #3            ; m7=int(x/8).
  96.   bic       m5,m1,m3,lsl #2         ; m5=4*(not(x) mod8)=shift.
  97.   ldr       m7,[m6,m7,lsl #2]!      ; m6=long adress | m7=long.
  98.   rsb       m8,m2,m7,lsl m5         ; m8=(pixie-1 mod16)<<28.
  99.   cmp       m8,#max_value<<28       ; Flags=m8-max_value<<28.
  100.   subCC     m7,m7,m2,lsr m5         ; Shade if m8 lower than max_value<<28,
  101.   strCC     m7,[m6]                 ;   and save the long back.
  102. }
  103.  
  104. ;------>  Random32  <--------------------------------------------------------
  105. ; This macro takes one random number, and by using subtile (hum) operations
  106. ; changes it in a new one.
  107. macro random32 m0
  108. { eorS      m0,m0,m0,rrx
  109.   adc       m0,m0,m0,ror #7
  110. }
  111. ;Previous random generator was the following one. I give it as a reminder.
  112. ;macro random32 m0,m1
  113. ;{ add       m0,m1,m0,ror #3
  114. ;  mov       m0,m0,ror m1
  115. ;  eor       m1,m0,m1,ror #7
  116. ;}
  117.  
  118.  
  119.  
  120. ;****************************************************************************
  121. ;****************************************************************************
  122. ;*****                                                                  *****
  123. ;*****                               CODE                               *****
  124. ;*****                                                                  *****
  125. ;****************************************************************************
  126. ;****************************************************************************
  127.  
  128. ;------>  Start Of Proggy  <-------------------------------------------------
  129. .proggy_start
  130.   str       r14,bss+old_pc          ; Save return adress.
  131.   swi       256+22                  ; Set screen mode.
  132.   swi       256+9
  133.   swi       OS_RemoveCursors        ; They are so ugly!
  134.   adr       r0,videoram_adress      ; Get videoram adress.
  135.   mov       r1,r0
  136.   swi       OS_ReadVduVariables
  137.   adr       r0,colors               ; Change colors.
  138.   mov       r1,#16*6
  139.   swi       OS_WriteN
  140.  
  141.   adr       r0,bss+points_coords    ; Set all points to the same position.
  142.   mov       r1,#256                 ; Initial position.
  143.   mov       r2,#200
  144.   mov       r3,#2*nb_points         ; Copy it 2*nb_points times.
  145. ._init_one_point
  146.   stmia     r0!,{r1-r2}             ; Initialise one point.
  147.   subS      r3,r3,#1
  148.   bNE       _init_one_point
  149.  
  150.   ldr       r0,videoram_adress      ; Copy the 'baah.' logo.
  151.   add       r0,r0,#7+(11*160)       ; Recenter the first logo.
  152.   mov       r1,#8                   ; Copy 8 rows of logos.
  153. ._logos_one_row
  154.   mov       r2,#5                   ; Copy 5 columns of logos.
  155. ._logos_one_column
  156.   mov       r3,r0                   ; r3=destination adress.
  157.   adr       r4,logo                 ; r4=source adress.
  158.   mov       r5,#9                   ; 9 lines.
  159. ._logo_one_line
  160.   mov       r6,#18                  ; 18 bytes per line.
  161. ._logo_one_byte
  162.   ldrB      r7,[r4],#1              ; Copy one byte.
  163.   strB      r7,[r3],#1
  164.   subS      r6,r6,#1
  165.   bNE       _logo_one_byte
  166.   add       r3,r3,#160-18           ; Next logo line.
  167.   subS      r5,r5,#1
  168.   bNE       _logo_one_line
  169.   add       r0,r0,#32               ; Next logo. (Column)
  170.   subS      r2,r2,#1
  171.   bNE       _logos_one_column
  172.   add       r0,r0,#160*31           ; Next logo. (Row)
  173.   subS      r1,r1,#1
  174.   bNE       _logos_one_row
  175.  
  176.  
  177. ;------>  Random Walk  <-----------------------------------------------------
  178. ; We process nb_points points, and for each of them, we perform nb_iter
  179. ; random movements. At each of thoses, we shade the according pixel.
  180. ; Then we do the same for unshading.
  181. .random_walk
  182.   ldr       r0,videoram_adress      ; r0=videoram adress.
  183.   adr       r1,directions           ; r1=table of directions.
  184.   ldr       r2,[r1,#-4]             ; Load random germ.
  185.   adr       r3,bss+points_coords
  186.   mov       r4,#nb_points           ; Nb of points to shade.
  187.   mov       r5,#&7<<2               ; Used to calculate pixel shift.
  188.   mov       r6,#1<<28               ; Used to decrement pixel in lword.
  189.   mov       r7,#max_value<<28       ; Used in pixel shading.
  190. .shade_one_point
  191.   ldmia     r3,{r8-r9}              ; r8=x_pos | r9=y_pos.
  192.   mov       r14,#nb_iter
  193. .shade_one_iter
  194.   shade_mode9 r0,r5,r6,r7,r8,r9,r10,r11,r12 ; Shade the pixel.
  195.   and       r10,r2,#%111            ; r10=random_nb mod8.
  196.   add       r10,r1,r10,lsl #3       ; r10 points on good direction.
  197.   ldmia     r10,{r10-r11}           ; r10=incx | r11=incy.
  198.   addS      r8,r8,r10               ; pos_x+=incx.
  199.   addMI     r8,r8,#1                ; Clipping.
  200.   cmp       r8,#320
  201.   subPL     r8,r8,#1
  202.   addS      r9,r9,r11               ; pos_y+=incy.
  203.   addMI     r9,r9,#1                ; Clipping.
  204.   cmp       r9,#256
  205.   subPL     r9,r9,#1
  206.   random32  r2                      ; Next random number.
  207.   subS      r14,r14,#1              ; One iteration processed.
  208.   bNE       shade_one_iter
  209.   stmia     r3!,{r8-r9}             ; Save new coords.
  210.   subS      r4,r4,#1                ; One point processed.
  211.   bNE       shade_one_point
  212.  
  213.   mov       r4,#nb_points           ; Nb of points to unshade.
  214. .unshade_one_point
  215.   ldmia     r3,{r7-r8}              ; r7=x_pos | r8=y_pos.
  216.   mov       r14,#nb_iter
  217. .unshade_one_iter
  218.   unshade_mode9 r0,r5,r6,r7,r8,r9,r10,r11,r12 ; UnShade the pixel.
  219.   and       r9,r2,#%111             ; r9=random_nb mod8.
  220.   add       r9,r1,r9,lsl #3         ; r9 points on good direction.
  221.   ldmia     r9,{r9-r10}             ; r9=incx | r10=incy.
  222.   addS      r7,r7,r9                ; pos_x+=incx.
  223.   addMI     r7,r7,#1                ; Clipping.
  224.   cmp       r7,#320
  225.   subPL     r7,r7,#1
  226.   addS      r8,r8,r10               ; pos_y+=incy.
  227.   addMI     r8,r8,#1                ; Clipping.
  228.   cmp       r8,#256
  229.   subPL     r8,r8,#1
  230.   random32  r2                      ; Next random number.
  231.   subS      r14,r14,#1              ; One iteration processed.
  232.   bNE       unshade_one_iter
  233.   stmia     r3!,{r7-r8}             ; Save new coords.
  234.   subS      r4,r4,#1                ; One point processed.
  235.   bNE       unshade_one_point
  236.  
  237.   str       r2,[r1,#-4]             ; Save the random germ for next time.
  238.  
  239.   swi       OS_ReadEscapeState      ; Escape key pressed?
  240.   bCC       random_walk             ; No, then loop.
  241.   ldr       pc,bss+old_pc           ; Bye...
  242.  
  243.  
  244. ;****************************************************************************
  245. ;****************************************************************************
  246. ;*****                                                                  *****
  247. ;*****                            MAIN DATAS                            *****
  248. ;*****                                                                  *****
  249. ;****************************************************************************
  250. ;****************************************************************************
  251.  
  252. .videoram_adress        ; Will contain videoram adress.
  253.   dcd       148,-1
  254.  
  255. .colors
  256.   dcb       19,&0,16,&00,&00,&00, 19,&1,16,&22,&00,&00
  257.   dcb       19,&2,16,&44,&00,&00, 19,&3,16,&66,&00,&00
  258.   dcb       19,&4,16,&88,&00,&00, 19,&5,16,&aa,&22,&00
  259.   dcb       19,&6,16,&bb,&44,&00, 19,&7,16,&cc,&66,&00
  260.   dcb       19,&8,16,&dd,&88,&00, 19,&9,16,&ee,&aa,&00
  261.   dcb       19,&a,16,&ff,&bb,&22, 19,&b,16,&ff,&cc,&44
  262.   dcb       19,&c,16,&ff,&dd,&66, 19,&d,16,&ff,&ee,&88
  263.   dcb       19,&e,16,&66,&66,&dd, 19,&f,16,&00,&00,&00
  264.  
  265. ; The random germ must be just before the directions.
  266. ; The 8 directions are the increments for the 8 surrounding pixels.
  267. .random_germ
  268.   dcd       &eb1a2c37
  269. .directions
  270.   dcd       -1,-1,0,-1,1,-1,1,0,1,1,0,1,-1,1,-1,0
  271.  
  272. .logo                   ; Hard to trust, but here' s the logo.
  273.   dcb       &F0,&0F,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&F0,&0F,&00,&00
  274.   dcb       &00,&00,&EF,&FE,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&EF,&FE
  275.   dcb       &00,&00,&00,&00,&EF,&FE,&FF,&0F,&00,&FF,&FF,&FF,&00,&FF,&FF,&FF
  276.   dcb       &EF,&FE,&FF,&0F,&00,&00,&EF,&FE,&EE,&FE,&F0,&EE,&EE,&EE,&FF,&EE
  277.   dcb       &EE,&EE,&EF,&FE,&EE,&FE,&00,&00,&EF,&EE,&FF,&EE,&EF,&FE,&FF,&EE
  278.   dcb       &EF,&FE,&FF,&EE,&EF,&EE,&FF,&EE,&0F,&00,&EF,&FE,&F0,&EE,&EF,&FE
  279.   dcb       &F0,&EE,&EF,&FE,&F0,&EE,&EF,&FE,&F0,&EE,&FF,&0F,&EF,&FE,&FF,&EE
  280.   dcb       &EF,&FE,&EF,&EE,&EF,&FE,&EF,&EE,&EF,&FE,&EF,&FE,&EF,&FE,&F0,&EE
  281.   dcb       &EE,&FE,&F0,&EE,&FE,&EE,&FF,&EE,&FE,&EE,&EF,&FE,&EF,&EE,&EF,&FE
  282.   dcb       &00,&FF,&FF,&0F,&00,&FF,&0F,&FF,&00,&FF,&0F,&FF,&F0,&0F,&F0,&FF
  283.   dcb       &F0,&0F
  284. ALIGN
  285.  
  286. ;----------------------->  THIS MUST BE AT VERY END  <-----------------------
  287. .bss
  288.