I’m creating a simple black jack game using the Easy 68K simulator and need to use a random number to assign the cards. My cards must be in the range 2 to 11. I seem to be getting the same number every time, and it isn’t within the range I expect. My card value needs to end up in D3, so I have the following random number code:
CLR.L D0
CLR.L D3
MOVE.B #8, D0 ;Access time
TRAP #15
AND.L #$5FFFFF,D1 ;prevent overflow in divu
DIVU #10, D1
SWAP D1
ADDQ.W #1, D1
MOVE D1, D3
which I came to by modifying the code on this site: https://notendur.hi.is/voe1/3.%20onn/Tolvuhogun/EASy68K/Examples/tutorial3.X68
I am hoping to find help generating a number 2 through 11. I have been searching the internet for several hours. I know I need to access the time by using Move.B #8, D0, but beyond that, I haven’t made much progress. Any help would be very much appreciated!
The mask being used in the
AND.L(“prevent overflow in divu”) was only good for a division by 100 — you’ll need to mask with0x7FFFFfor a division by 10.Why:
Additionally, the code you have will give you a number from 1 to 10 (0-9 + 1). If you want 2 to 11, you’ll have to add 2, not 1.
Here’s a more advanced random number generator, borrowed from the Mac OS QuickDraw source code. Note that you may need to translate the syntax somewhat (it was written over 25 years ago!) and/or modify the way it loads and stores its seed.