Stock Exchange Game in MSX-C

By ToriHino

Champion (385)

ToriHino's picture

12-05-2018, 12:27

In order to get more acquainted with developing using MSX-C, and also to try and setup my toolchain i re-implemented the 'Stock Exchange Game' published long time ago as a basic listing (named 'Beursspel') in the dutch Msx Computer Magazine.

Main goal was to practice in MSX-C so the game probably might have some bugs here or there. It even needs MSX-DOS2 since i used MSX-C v1.2.

My current toolchain:

  • I use Notepad++ on my PC to edit the sources files
  • Sources are located in a folder which is part of a local FTP server
  • On my TurboR i run a make script performing the following steps:
    • Fetch the sources (when updated) using GR8FTP on GR8NET
    • Compile, parametercheck, generate code, build and link to a .COM file

I had to split up the source code in a number of sources because the program got too big. Compilation on my TurboR in total now takes just under 3 minutes Tongue

The resulting exectuable can be played here: Stock Exchange Game

When you select 1 player, the MSX will play against you. Although a simple game, it sometimes can become quite challenging to beat the MSX :D

Ofcourse with the latest WebMSX you can now even play it with multiple players over the internet :)

Login or register to post comments

By ToriHino

Champion (385)

ToriHino's picture

12-05-2018, 15:12

One of the things i encountered was that the standard randomizer function rnd() of MSX-C is not that random at all. So i had to come up with an alternative for that, while trying not to make use of assembly Smile

I'm now using the following, srand() to seed the randomizer and rand() for the function itself:

#define GETTIME			0x2c
#define getTime(regs)	regs.bc = (NAT)GETTIME, callx((NAT)5, &regs)
 
unsigned int randA = 0;
unsigned int randB = 0;
unsigned int randC = 0;
unsigned int randX = 0;

VOID srand()
{
  REGS regs;
 
  getTime(regs);

  randA = (regs.hl / 256) * (regs.hl % 256) * (regs.de / 256);
  randB = (regs.de / 256);
  randC = (regs.hl % 256);
}
 
int rand(limit)
int limit;
{
  randX++;               
  randA = (randA^randC^randX);
  randB = (randB+randA);
  randC = (randC+(randB>>1)^randA);

  return(randC) % limit;
}

By Grauw

Ascended (8516)

Grauw's picture

12-05-2018, 16:40

Could try xorshift too:

http://www.arklyffe.com/main/2010/08/29/xorshift-pseudorando...

It’s fast and has good random characteristics. Used in a lot of modern software too, e.g. last year most browsers switched to using xorshift.

By ToriHino

Champion (385)

ToriHino's picture

13-05-2018, 08:57

Will try that as well, although current implementation already gives quite good results.

By Grauw

Ascended (8516)

Grauw's picture

13-05-2018, 12:29

What's the name of the algorithm you used btw?

By ToriHino

Champion (385)

ToriHino's picture

13-05-2018, 12:38