Jump to content
IGNORED

Assembly code samples


GDMike

Recommended Posts

My super awesome random number generator!

 

First, you need to initialize the 9901 counter at the start of your application:

 

* Set up 9901 counter
       CLR  R12                        * CRU base of the TMS9901
       SBO  0                          * Enter timer mode
       LI   R1,>3FFF                   * Set counter
       INCT R12                        * Address of bit 1
       LDCR R1,14                      * Load value
       DECT R12
       SBZ  0                          * Exit clock mode, start decrementer 

Then, the following routines will generate either a 16-bit word size random value, or any value from 0 to max-1. I've set them up to have their own workspace but you don't need to do this if you don't want to.

* Random number generator (Range in R3, Result in R4)
* Returns 0 to R3-1
RNDNUM DATA VWS,RAND2
RAND2  BL   @RNDGEN
       MOV  @>0006(R13),R3
       CLR  R4
       DIV  R3,R4
       MOV  R5,@>0008(R13)
       RTWP
* Random number generator 16-bit (Result in R4)
* returns 0-65535
RANDOM DATA VWS,RAND1
RAND1  BL   @RNDGEN
       MOV  R4,@>0008(R13)
       RTWP
* Random number generation
RNDGEN LI   R4,23729                   * Load with 15-bit value
       MPY  @RSEED,R4                  * Multiply by the random seed
       AI   R5,31871                   * Add a 15-bit value to the lower word
       CLR  R12                        * CRU base of the TMS9901
       SBO  0                          * Enter timer mode
       STCR R0,15                      * Read current value (plus mode bit)
       SRL  R0,1                       * Get rid of mode bit
       SBZ  0                          * Exit clock mode, decrementer continues
       ANDI R0,>000F                   * Filter to 0-15
       JEQ  RNDGN1                     * If zero, skip
       SRC  R5,0                       * Rotate seed based on clock value
RNDGN1 MOV  R5,@RSEED                  * Copy back to RSEED
       RT

 

  • Thanks 1
Link to comment
Share on other sites

Here's the updated code test

I'm putting an "A" at pos 0 on the screen if it's a bad search. If it's a good search, then I'm placing an asterisk on the word. I'm having to convert the address in R6 to the screen location. But I didn't have any luck, I tried inct in my loop and just a Inc but I always seem to place an asterisk at the position it shows now.

And I'm always hitting a positive search no matter what my search word is.

 

IMG_20200714_230823247_HDR.jpg

IMG_20200714_230828368_HDR.jpg

IMG_20200714_230850972.jpg

IMG_20200714_230854748_HDR.jpg

IMG_20200714_230858211_HDR.jpg

IMG_20200714_230901894.jpg

IMG_20200714_230906982_HDR.jpg

IMG_20200714_230911037.jpg

Link to comment
Share on other sites

I changed my search word a couple times, first it was"SEARCH" and it was a positive hit, then changed to Mike, it too was a positive hit.

I wanted to make sure that I wasn't placing the search word into my copied screen page, as I thought that was happening. But I don't think it was.

Is it ok if I crash? At this moment im starting to screw with things and I'm messing it up. I'll read notes in a couple hours ??

Edited by GDMike
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...