random.asm 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ; $Id$
  2. ; MegaZeux
  3. ;
  4. ; Copyright (C) 1996 Greg Janson
  5. ; Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
  6. ;
  7. ; This program is free software; you can redistribute it and/or
  8. ; modify it under the terms of the GNU General Public License as
  9. ; published by the Free Software Foundation; either version 2 of
  10. ; the License, or (at your option) any later version.
  11. ;
  12. ; This program is distributed in the hope that it will be useful,
  13. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. ; General Public License for more details.
  16. ;
  17. ; You should have received a copy of the GNU General Public License
  18. ; along with this program; if not, write to the Free Software
  19. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. ;
  21. ; RANDOM.ASM- Random number generator.
  22. ;
  23. Ideal
  24. include "random.inc"
  25. p186
  26. JUMPS
  27. include "model.inc"
  28. Codeseg
  29. rand_num dw 0
  30. ;
  31. ; Seed the random number generator with the timer
  32. ;
  33. proc random_seed far
  34. push ax cx dx
  35. xor ah,ah
  36. int 1ah ; Call BIOS timer func
  37. flipflag cx,dx ; XOR high & low bytes together
  38. mov [cs:rand_num],cx ; Seed w/recieved value from timer func
  39. pop dx cx ax
  40. ret
  41. endp random_seed
  42. ;
  43. ; Returns a random number in AX
  44. ;
  45. proc random_num far
  46. mov ax,[cs:rand_num]
  47. inc ax
  48. flipflag ax,0deadh
  49. add ax,0b00bh
  50. rol ax,2
  51. mov [cs:rand_num],ax
  52. ret
  53. endp random_num
  54. ends
  55. end