Videopac / Odyssey2 forum
May 22, 2017, 11:26:39 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Order now: STRIKEFORCE by Revival Studios!
 
   Home   arcade Help Login Register links videopac.nl  
Pages: [1]   Go Down
  Print  
Author Topic: Need Snippets for Random Numbers  (Read 180 times)
sokoban
Trying to get the cartridge in...
*
Posts: 11



ghismart ghisloban ghisloban
WWW
« on: May 02, 2017, 09:52:59 PM »

Hello,

I found quite all I need to make some small and easy games on the forum and also with the Soeren examples Smiley
But there is only one thing that I absolutely don't understand: how to generate random numbers Cry
I have read that there is a Videopac routine that is not compatible with Videopac+ Sad
But I have also read it is possible to generate random numbers without this routine and this is why I post my message today Wink
Basically, how is it possible to generate a random number between 0 and X (where X is a 8 bits integer) Huh?

Help needed, Thanks for all,
Sokoban
Logged
LD
Played Munchkin once...
**
Posts: 91



« Reply #1 on: May 02, 2017, 11:25:51 PM »

This is a neat little random code I've adapted from 6502 assembly :
Code:
;--------------------------------------
RandomNumber                          ;subroutine
mov R0,#RandomVar
mov a,@R0
clr c
rrc a
jc Neor
xrl a,#0B4h
Neor
mov @R0,a
ret

Where RandomVar is an int. RAM. This generates 0-255 possible numbers and never repeats. Call this code once every frame.

To limit the result is more difficult, you can use ANL to limit the range of A ex.:

anl a,#003h ;limit A to 0-3
anl a,#007h ;limit A to 0-7
anl a,#00Fh ;limit A to 0-15
anl a,#01Fh ; limit A to 0-31
anl a,#03Fh ; limit A to 0-63
anl a,#07Fh ; limit A to 0-127

load the random var to A and use ANL.

 mov a,@R0 ;where R0 is the random var (int RAM)
 anl a,#00Fh

 now A could be 0 up to 15
« Last Edit: May 02, 2017, 11:36:52 PM by LD » Logged
sokoban
Trying to get the cartridge in...
*
Posts: 11



ghismart ghisloban ghisloban
WWW
« Reply #2 on: May 03, 2017, 08:32:55 PM »

Thank you very much LD!!
I will try this in a few days.
Logged
sokoban
Trying to get the cartridge in...
*
Posts: 11



ghismart ghisloban ghisloban
WWW
« Reply #3 on: May 05, 2017, 09:42:24 PM »

tested... and it works!!
thanks again!
now i have no more excuses not to make a game ^^
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!