Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6959563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:17:17+00:00 2026-05-27T15:17:17+00:00

I’m creating a simple black jack game using the Easy 68K simulator and need

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:17:18+00:00Added an answer on May 27, 2026 at 3:17 pm

    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 with 0x7FFFF for a division by 10.

    Why:

    0xFFFFFFFF / #100 = 0x28f5c28 - too big for a single word!
    0x5FFFFF   / #100 = 0xF5C2    - that fits
    
    0x5FFFFF / #10  = 0x99999 - too big for a single word!
    0x7FFFF  / #10  = 0xCCCC  - that fits
    

    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.

    ;--------------------------------------------------------------
    ;
    ;  FUNCTION Random: INTEGER;
    ;
    ;  returns a signed 16 bit number, and updates unsigned 32 bit randSeed.
    ;
    ;  recursion is randSeed := (randSeed * 16807) MOD 2147483647.
    ;
    ;  See paper by Linus Schrage, A More Portable Fortran Random Number Generator
    ;  ACM Trans Math Software Vol 5, No. 2, June 1979, Pages 132-138.
    ;
    ;  Clobbers D0-D2, A0
    ;
    ;
    ;  GET LO 16 BITS OF SEED AND FORM LO PRODUCT
    ;  xalo := A * LoWord(seed)
    ;
            MOVE.L  GRAFGLOBALS(A5),A0      ;POINT TO QuickDraw GLOBALS
            MOVE    #16807,D0               ;GET A = 7^5
            MOVE    D0,D2                   ;GET A = 7^5
            MULU    RANDSEED+2(A0),D0       ;CALC LO PRODUCT = XALO
    ;
    ;  FORM 31 HIGHEST BITS OF LO PRODUCT
    ;  fhi:=HiWord(seed) * ORD4(a) + HiWord(xalo);
    ;
            MOVE.L  D0,D1                   ;COPY xalo
            CLR.W   D1
            SWAP    D1                      ;GET HiWord(xalo) as a long
            MULU    RANDSEED(A0),D2         ;MULT BY HiWord(seed)
            ADD.L   D1,D2                   ;ADD LEFTLO = FHI
    ;
    ;  GET OVERFLOW PAST 31ST BIT OF FULL PRODUCT
    ;  k:=fhi DIV 32768;
    ;
            MOVE.L  D2,D1                   ;COPY FHI
            ADD.L   D1,D1                   ;CALC 2 TIMES FHI
            CLR.W   D1
            SWAP    D1                      ;CALC FHI SHIFTED RIGHT 15 FOR K
    ;
    ;  ASSEMBLE ALL THE PARTS AND PRE-SUBTRACT P
    ;  seed:=((BitAnd(XALO,$0000FFFF) - P) + BitAnd(fhi,$00007FFF) * b16) + K;
    ;
            AND.L   #$0000FFFF,D0           ;GET LO WORD XALO
            SUB.L   #$7FFFFFFF,D0           ;SUBTRACT P = 2^31-1
            AND.L   #$00007FFF,D2           ;BitAnd(fhi,$00007FFF)
            SWAP    D2                      ;TIMES 64K
            ADD.L   D1,D2                   ;PLUS K
            ADD.L   D2,D0                   ;CALC TOTAL
    ;
    ;  IF seed < 0 THEN seed:=seed+p;
    ;
            BPL.S   UPDATE
            ADD.L   #$7FFFFFFF,D0
    UPDATE  MOVE.L  D0,RANDSEED(A0)         ;UPDATE SEED
            CMP.W   #$8000,D0               ;IS NUMBER -32768 ?
            BNE.S   NUMOK                   ;NO, CONTINUE
            CLR     D0                      ;YES, RETURN ZERO INSTEAD
    NUMOK   MOVE.W  D0,4(SP)                ;RETURN LO WORD AS RESULT
            RTS
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.