flat assembler
Message board for the users of flat assembler.

flat assembler > Examples and Tutorials > Newbie - code won't compile. Help.

Author
Thread Post new topic Reply to topic
bteddy1



Joined: 11 Mar 2019
Posts: 6
The code below is different from the one above. Neither will compile. I get errors on line 4 ("above code" struc card) and line 9 ("code below" numeric WIN.).

I am a newbie to FASM. As old as it is (FASM), I can not find a cheat sheet with Instruction syntax, directives, Data definitions, Constants and labels etc...

What Is "numeric"? Is it defined properly or do I have something wrong on my system?

What's going on with this?

Thank You

Code:
N.DECK=52
N.CARDS=5

STRUC CARD{
 NUMBER n, suite, held, up
 ?card ENDS;
};

numeric WIN.ROYAL.FLUSH,\
 WIN.STRAIGHT.FLUSH, WIN.FOUR.KIND,\
 WIN.FULL.HOUSE, WIN.FLUSH, WIN.STRAIGHT,\
 WIN.THREE.KIND, WIN.TWO.PAIR, WIN.JACKS.BETTER

TEXTS wins[]=\
 'Royal Flush', 'Straight Flush',\
 'Four of a Kind', 'Full House', 'Flush',\
 'Straight', 'Three of a Kind', 'Two Pair',\
 'Jacks or Better'

; create hand and deck. 2-10=0-8, J-A=9-12.
; suites: 0=clubs, 1=spades, 2=hearts, 3=diamonds

function create.cards
locals p, i, n, suite
array.size hand, N.CARDS
.erase hand
array.size deck, N.DECK
let [i]=0
.loop [suite]=0 to 4       ; suites
  .loop [n]=0 to 13        ; numbers
    get [p]=.index deck[i]
    let [?card.n+eax]=[n],\
     [?card.suite+eax]=[suite],\
     [?card.up+eax]=NO,\
    [?card.held+eax]=NO, [i]++
  .endl
.endl
endf

macro shuffle.cards { array.randomize deck }

; copy next card from top of deck[n-1]
; to hand[i] then remove from deck

function deal.card, i
.if not [deck.n]       ; no cards remaining?
  create.cards         ; reload deck
  shuffle.cards
.end
array.recent deck      ; top card
array.replace \
 hand, [i], eax
array.reduce deck
.index hand[i]
let [?card.up+eax]=YES,\
 [?card.held+eax]=NO
endf

; deal cards from deck to hand. replace all
; hand cards that are not held with next
; cards in deck

function deal.cards
locals i
.loop [i]=0 to N.CARDS
  .index hand[i]
  .if not [?card.held+eax]
    deal.card [i]
  .end
.endl
endf

; search hand for card #. return # occurances

function has.card, c
locals i, nc
let [nc]=0
.loop [i]=0 to N.CARDS
  .index hand[i]
  let ecx=[?card.n+eax]
  .if [c]=ecx
    let [nc]++
  .end
.endl
endf [nc]

; all cards of the same suite?

function all.same.suite
locals i, suite
let eax=[hand.p],\ ; get first card suite
 [suite]=[?card.suite+eax]

; remaining cards must be same suite...

.loop [i]=1 to N.CARDS
  .index hand[i]
  let ecx=[?card.suite+eax]
  .if [suite]<>ecx
    return 0
  .end
.endl
endf 1

; jacks or better? pair of high cards: A/K/Q/J

function has.jacks.or.better
locals i, j, p, card.n
.loop [i]=0 to N.CARDS
  get [p]=.index hand[i]
  let [card.n]=[?card.n+eax]

  ; if high card, search remaining indices
  ; for same card #/.n...

  .if [card.n]>=CARD.JACK
    let eax=[i], eax++

    .loop [j]=eax to N.CARDS
      get [p]=.index hand[j]
      let ecx=[?card.n+eax]
      .if [card.n]=ecx
        return 1
      .end
    .endl
  .end
.endl
endf 0

; is there another card n?

function has.pair, n
locals i, nc
let [nc]=0
.loop [i]=0 to N.CARDS
  .index hand[i]
  let ecx=[?card.n+eax]
  .if [n]=ecx
    let [nc]++
    .if [nc]>1
      return 1
    .end
  .end
.endl
endf 0

; 2 pairs?

function has.two.pair
locals i, n, cn, np
let [cn]=NOTHING, [np]=0
.loop [i]=0 to N.CARDS
  .index hand[i]
  let eax=[?card.n+eax], [n]=eax
  .if [cn]<>eax
    .if.has.pair [n]
      let [cn]=[n], [np]++
      .if [np]>1
        return 1
      .end
    .end
  .end
.endl
endf 0

; has x of kind?

function has.x.kind, x
locals i
.loop [i]=0 to N.CARDS
  .index hand[i]
  has.card [?card.n+eax]
  .if eax=[x]
    return 1
  .end
.endl
endf 0

; full house? 3 of one kind, 2 of another

function has.full.house
.if.has.3.kind
  .if.has.2.kind
    return 1
  .end
.end
endf 0

; any five consecutive cards of same suite

function has.straight.flush
.if.has.straight
  .if.has.flush
    return 1
  .end
.end
endf 0

; royal flush? A/K/Q/J/10 of same suite

function has.royal.flush
.if.has.flush
  .if.has.card CARD.ACE
    .if.has.card CARD.KING
      .if.has.card CARD.QUEEN
        .if.has.card CARD.JACK
          .if.has.card CARD.10
            return 1
          .end
        .end
      .end
    .end
  .end
.end
endf 0

; is current hand a winner?

function winner?
.if.has.royal.flush
  return WIN.ROYAL.FLUSH
.end
.if.has.straight.flush
  return WIN.STRAIGHT.FLUSH
.end
.if.has.4.kind
  return WIN.FOUR.KIND
.end
.if.has.full.house
  return WIN.FULL.HOUSE
.end
.if.has.flush
  return WIN.FLUSH
.end
.if.has.straight
  return WIN.STRAIGHT
.end
.if.has.3.kind
  return WIN.THREE.KIND
.end
.if.has.two.pair
  return WIN.TWO.PAIR
.end
.if.has.jacks.or.better
  return WIN.JACKS.BETTER
.end
endf NOTHING

; calculate winnings

function payout
let eax=[win], eax*(5*4), ecx=[bet], ecx--,\
 ecx<<2, eax+ecx, eax=[payouts+eax],\
[won]=eax, eax+[bet], [credits]+eax
endf                                                                                                  
Post 11 Mar 2019, 05:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16782
Location: In your JS exploiting you and your system
Is that MASM code?

There are a lot of differences between fasm and other assemblers.

This post gives some indication of the problems you will encounter
Quote:
MASM - depending from MASM version and coding style used, you will have to rewrite 50% ... 95% (MASM compatibility (partial) macros exist for Win32, also some unofficial "PROC16")
Start small and build your way up. Look through the examples for how things work in fasm. You can start with your first struc. "NUMBER" hasn't been defined so fasm doesn't know what to do with it.
Post 11 Mar 2019, 05:57
View user's profile Send private message Visit poster's website Reply with quote
bteddy1



Joined: 11 Mar 2019
Posts: 6
The code come from this site, this post, look at first post at top . It is supposed to be working fasm code. The code at the top is different from the code I was able to download from link. NOT MASM. The FASM Manual "Fasm Version 1.73_Programmer's_Manual.doc" does not show how to define a stucture, where in code to place it, how to reference it ...
Post 11 Mar 2019, 07:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16782
Location: In your JS exploiting you and your system
You are probably missing some included macro library then.

Which page is it from?
Post 11 Mar 2019, 07:05
View user's profile Send private message Visit poster's website Reply with quote
bteddy1



Joined: 11 Mar 2019
Posts: 6
Deluxe video poker
https://board.flatassembler.net/topic.php?t=15478

There are no includes or calls.
Post 11 Mar 2019, 07:08
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16782
Location: In your JS exploiting you and your system
Okay, Those files from uart777 do not use the standard fasm or Intel syntax. That is probably not a good way to learn how fasm works. They require a very complex set of macros to implement the code.
Post 11 Mar 2019, 07:11
View user's profile Send private message Visit poster's website Reply with quote
bteddy1



Joined: 11 Mar 2019
Posts: 6
Ok, sorry, I thought the site was all FASM code.
Post 11 Mar 2019, 07:16
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16782
Location: In your JS exploiting you and your system
In a way it shows the power of fasm macros, because it can be assembled with fasm if you have the correct macro set. I don't know where uart777 posted the macros he was using. But I do remember they were very long and complicated.
Post 11 Mar 2019, 07:22
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.