Video Poker

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
delpozzo
Posts: 31
Joined: 03 Jun 2020, 18:47

Video Poker

Post by delpozzo »

Good news everyone! The Gigatron is now ready for installation at your local casino as a video poker machine :lol:

Image

I've been working on this project for awhile now in my spare time and had an absolute blast developing it! I'd like to make a huge shout-out to at67, I can't thank you enough for gtBASIC and your emulator. My software development background is primarily in C and other higher level languages; while I do have some basic assembly skills my experience is quite limited. The gtBASIC compiler made this project achievable for me, and being able to just click on my .gbas file in the emulator for an automatic compile and test run was an essential part of my development and debugging process.

The latest release is availble on my GitHub repo here: https://github.com/delpozzo/gigatron

Direct download links are as follows:
VideoPoker.gt1 - https://github.com/delpozzo/gigatron/ra ... oPoker.gt1
VideoPoker.gbas - https://github.com/delpozzo/gigatron/ra ... Poker.gbas
VideoPoker.gasm - https://github.com/delpozzo/gigatron/ra ... Poker.gasm

Gamepad Controls
Left, Right - Card selection
Up, Down - Increase / Decrease bet
A Button - Hold / Unhold card
B Button - Deal / Draw

Keyboard Controls
Left, Right - Card selection
Up, Down - Increase / Decrease bet
Backspace, Delete, End - Hold / Unhold card
Home, PrtScn/Insert/SysReq - Deal / Draw

Gameplay
During the bet round, use Up or Down to increase or decrease your bet. The minimum bet is 1 credit and the maximum is 5 credits. Press B to deal the cards. Select cards using Left or Right. Press A to toggle Hold on the selected card. Press B to exchange unheld cards for new ones from the deck. If a winning hand results, you will be awarded the amount of credits corresponding to the illuminated win on the payout board at the top of the screen. The bet can now be increased or decreased again before the next round of cards is dealt.

Winning hands and rewards are as follows:

Royal Flush: 250 x Bet
Straight Flush: 50 x Bet
Four of a Kind: 25 x Bet
Full House: 9 x Bet
Flush: 6 x Bet
Straight: 4 x Bet
Three of a Kind: 3 x Bet
Two Pair: 2 x Bet
Pair of Jacks or Better: 1 x Bet

Feedback is always appreciated, especially if anyone encounters any bugs! On my Gigatron GitHub repo, at67 also pointed out some optimizations that I could make which is what I plan on working on next. In the meantime, the game should be completely playable on ROMv3 or higher in its current state.
at67
Posts: 332
Joined: 14 May 2018, 08:29

Re: Video Poker

Post by at67 »

This is awesome, it's fun, addictive and super interactive; you can rip through hands, (and your balance), once you build up a head of steam.

Many moons ago, one of my first jobs straight out of university was working for an electronic reels/slots/cards gaming company, (they produced the hardware, software, mechanics and packaging for complete units, which sold for about 15k AUS $ each), containing stripped down and modified Amiga 500 motherboards with coin/note acceptors/dispensors, touch screens, security, etc, and a plethora of individual games. This brings back a lot of memories :)

I noticed you used the embedded assembler within your source code to convert a musical note index into a Gigatron specific audio frequency, (which is awesome btw, I didn't expect anyone to be using the embedded assembler at all!)

Code: Select all

getRomNote:
    asm
        LDWI    0x0900
        ADDW    _index
        ADDW    _index
        STW     _notes
        LUP     0
        ST      _note
        LDW     _notes
        LUP     1
        ST      _note + 1
    endasm
return
There is an inbuilt GET symbol, "MUSIC_NOTE", that pretty much does the same thing, so that you could replace your embedded assembler subroutine with this:

Code: Select all

n = get("MUSIC_NOTE", index)
But I like seeing the use of assembly code within gtBASIC, so don't change it on my account :)

I've also added your GT1 file to the GT1 repository, which I will update as you update this thread with newer versions:
https://www.dropbox.com/sh/4bbys2afg9y6 ... tlBza?dl=0
walter
Site Admin
Posts: 117
Joined: 13 May 2018, 08:00

Re: Video Poker

Post by walter »

I played it as well. It's hard to stop but eventually I ran out of money :)

I've added Video Poker to the sticky posting about all projects.
delpozzo
Posts: 31
Joined: 03 Jun 2020, 18:47

Re: Video Poker

Post by delpozzo »

at67 wrote: 11 Nov 2020, 21:44 Many moons ago, one of my first jobs straight out of university was working for an electronic reels/slots/cards gaming company, (they produced the hardware, software, mechanics and packaging for complete units, which sold for about 15k AUS $ each), containing stripped down and modified Amiga 500 motherboards with coin/note acceptors/dispensors, touch screens, security, etc, and a plethora of individual games. This brings back a lot of memories :)
That is really cool, and quite remarkable that the units sold at such a high price tag! Out of curiousity I looked up what a standard video poker cabinet runs for nowadays and it seems they are around $3,000. When I was growing up, I remember playing the handheld versions that my parents had lying around the house (the ones produced by Radica come to mind). I also recall playing video poker in the local arcade for tickets/tokens, lots of nostalgia.
at67 wrote: 11 Nov 2020, 21:44
There is an inbuilt GET symbol, "MUSIC_NOTE", that pretty much does the same thing, so that you could replace your embedded assembler subroutine with this:

Code: Select all

n = get("MUSIC_NOTE", index)
Wow that is actually really good to know! For sound, I must admit that I copied the methodlogy used in your Notes.gbas example and modified it a bit for video poker :-P
walter wrote: 12 Nov 2020, 09:18 I played it as well. It's hard to stop but eventually I ran out of money :)

I've added Video Poker to the sticky posting about all projects.
Thank you Walter and at67 for the feedback, and also for posting this on the GT1 repository and sticky post. I really appreciate it!
delpozzo
Posts: 31
Joined: 03 Jun 2020, 18:47

Re: Video Poker

Post by delpozzo »

I implemented some optimization advice from at67 (cheers!) and commited the changes. The download links are still the same as the OP. Free RAM has more than doubled (from 678 to 1599) and the hand evaluations now happen almost instanenously.

Before optimization:

Code: Select all

****************************************************************************************************
* Assembling file '../../../delpozzo/VideoPoker/VideoPoker.gasm'
****************************************************************************************************

Output : ../../../delpozzo/VideoPoker/VideoPoker.gt1

**********************************************
*                   Loading                    
**********************************************
* ../../../delpozzo/VideoPoker/VideoPoker.gt1 : 0x0200  :  8430 bytes
**********************************************
* Free RAM after load  :    678
**********************************************
After:

Code: Select all

****************************************************************************************************
* Assembling file '../../../delpozzo/VideoPoker/VideoPoker.gasm'
****************************************************************************************************

Output : ../../../delpozzo/VideoPoker/VideoPoker.gt1

**********************************************
*                   Loading                    
**********************************************
* ../../../delpozzo/VideoPoker/VideoPoker.gt1 : 0x0200  :  8198 bytes
**********************************************
* Free RAM after load  :   1599
**********************************************
at67
Posts: 332
Joined: 14 May 2018, 08:29

Re: Video Poker

Post by at67 »

Well done, it's even snappier now. I updated the .gt1 repo with your new version.

Would you like to do a pull request and get your stuff under Contrib in the main repo as well? It would be great to see the Contrib area expand even more.
delpozzo
Posts: 31
Joined: 03 Jun 2020, 18:47

Re: Video Poker

Post by delpozzo »

Thank you!

I would feel honored to be included in Contrib. I created a pull request, hopefully I did it correctly :-P
at67
Posts: 332
Joined: 14 May 2018, 08:29

Re: Video Poker

Post by at67 »

Yup, all good and accepted, cheers :)
at67
Posts: 332
Joined: 14 May 2018, 08:29

Re: Video Poker

Post by at67 »

I downloaded your .gbas and .tga files to test with the new version of the compiler and observed some pretty interesting results :)

Firstly, it was crashing after I compiled and ran it, as it looked like the code relocator had run out of memory and was trying to reallocate 0x0200 over and over continuously. Looking at the size of your sprite data, (18x15 bytes), plus the size of your arrays, it became obvious that the compiler was using up all of the precious lower code RAM to store sprite data and the arrays, (which in theory is fine).

The issue with this, is that the compiler always expects 0x0200 to be free for the code entry point, (which is actually a bug, the code should be able to launch from any address), but 0x0200 had already been allocated to sprites and/or arrays.

The quick and easy fix was to use the _spriteStripeChunks_ pragma like this:

Code: Select all

_runtimeStart_ &h7FFF

'defines the amount of contiguous RAM needed for sprite stripes, (in this case 15*6 + 1), min address and search direction
_spriteStripeChunks_ 15, &h7000, descending 'allocates from _runtimeStart_ to &h7000
Which allocated the sprite stripes in 91 byte chunks or less, (i.e. 15*6 + 1), starting at &h7F00 and heading down to &h7000, this not only allowed the code to compile and run correctly, but also resulted in free RAM of 1785 bytes, (186 more bytes than your 1589).

I then altered your code one more time and changed the word arrays to byte arrays, like this, (the percentage signs):

Code: Select all

dim cardValue%(52)
dim cardSuit%(52)
dim cardState%(52)
dim hand%(5)
This allowed the arrays to also fit in off-screen memory, (as well as the sprite data), thus allowing all of the lower memory segments in the range of 0x0200 to 0x07FF to contain code. This also resulted in a final free RAM amount of 2187 bytes, so a total savings of 598 bytes over your original size. This is pretty much explainable by the fact that your code was banished to the nether regions of off-screen memory and thus required many many more thunks, (page jumps), to stitch all of the code together.

The real follicle twirling dilemma is how did it compile and run on your system without errors and crashing? As I said I couldn't get it to run until I added the extra pragma noted above. You should have had the same issue as myself, which was code trying to allocate at already allocated 0x2XX sprite and array memory.

Anyway, it was a good exercise, as it exposed a major flaw in the code entry point handling which I am now attempting to fix!

*Edit* I added a _userCodeStart_ <address> pragma option to the compiler so that the programmer can decide exactly where he/she wants the code to start. A bit of a cop-out, but flexible enough that it should cover most bases.
delpozzo
Posts: 31
Joined: 03 Jun 2020, 18:47

Re: Video Poker

Post by delpozzo »

First of all, thank you for fixing these issues (_spriteStripeChunks_ and byte arrays) with the new compiler version! This probably would have taken me forever to figure out :-P
The real follicle twirling dilemma is how did it compile and run on your system without errors and crashing? As I said I couldn't get it to run until I added the extra pragma noted above. You should have had the same issue as myself, which was code trying to allocate at already allocated 0x2XX sprite and array memory.
This is where it gets even more interesting. Today was the first time I used the new compiler for the current release of VideoPoker.gbas and I can't seem to get it to crash on my side at all. I can tell it compiled with the new compiler because the sprites are now upside down (no surprise, as we discussed previously via this GitHub issue). I tried ROMv3, v4, and 5a in your emulator and also on my Gigatron running the latest dev.rom, all without crashing...very strange. Regardless, I plan on making your recommended changes and flipping the sprites shortly.

Edit: Updates complete, pull request has been made. Changing those word arrays to byte arrays made a huge difference, I will certainly keep that in mind for future projects:

Code: Select all

****************************************************************************************************
* Assembling file '../../../delpozzo/VideoPoker/VideoPoker.gasm'
****************************************************************************************************

Output : ../../../delpozzo/VideoPoker/VideoPoker.gt1


**********************************************
*                   Loading                    
**********************************************
* ../../../delpozzo/VideoPoker/VideoPoker.gt1 : 0x0200  : 10383 bytes
**********************************************
* Free RAM after load  :   2187
**********************************************
Post Reply