Well, the 24.1 daily hours of schoolwork?

Code:
unsigned char RandInt ( unsigned char Range )
{
   Range;
   _asm
      push   de
      push   af
      push   bc
      push   hl
      ld   b, 4(ix)
      ld   hl,(#0x9d95)
      ld   a,r
      ld   d,a
      ld   e,(hl)
      add   hl,de
      add   a,l
      xor   h
      sbc   hl,hl
      ld   e,a
      ld   d,h
   iRandomLoop:
      add   hl,de
      djnz   iRandomLoop
      ld   a,h
      pop   hl
      ld   l,a
      pop   de
      pop   af
      pop   bc
   _endasm ;
}

unsigned char Rand8 ( void )
{
   return RandInt(255);
}

char Rand16 ( void )
{
   return (RandInt(255)*255)+RandInt(255);
}


unfortunately Rant16 doesn't work that great (can anyone see what i'm screwing up?), but oh well
Hehehe, that routine looks familiar... Smile
Glad to see this is getting underway.
Kerm, do you see why Rand16 isn't working right? It will either return < 160 or > 65000

Rand8 works just fine as far as i can tell (returning a fairly random looking number between 0-255), and RandInt also appears to be working just fine
Kllrnohj: yes. It's interpreting it as a signed 2-byte int, not an unsigned 1-byte int. Smile
KermMartian wrote:
Kllrnohj: yes. It's interpreting it as a signed 2-byte int, not an unsigned 1-byte int. Smile


whoops....the NEW Rand16() (which is tested and does return values between 0-65535 fairly well)


Code:
unsigned short Rand16 ( void )
{
   return (RandInt(255)*255)+RandInt(255);
}


Oh, and for anyone who wants to write a function, it goes like this:

for the paramaters, its (4+n)ix for the parameters (so for a 2 byte parameter (or two 1 byte parameters), it would be ld h, 4(ix) ld l, 5(ix)

To RETURN a value, its L for one byte, HL for two bytes, and something else that i forgot for 4 bytes, lol (look in the SDCC documentation under Z80 somwhere)
I'll probably write some DCS compatibility stuff.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement