Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(2 edits) (+1)

A bit late to the party, but this explains the general concepts well if you want to take the calculating road:


But I too think Internet Janitor's idea of storing each digit in its own byte is probably easier to do with less code. Especially if you're just keeping score in a game and you only need to increase your large (0-9999) value by one at a time.

Something like this:

: bump-score
  i := score
  load v3
  v3 += 1
  if v3 == 10 begin
    v3 := 0
    v2 += 1
    if v2 == 10 begin
      v2 := 0
      v1 += 1
      if v1 == 10 begin
        v1 := 0
        v0 += 1
      end
    end
  end
  i := score
  save v3
  return
 
: show-score
  v5 := 0 # Coordinates to draw to
  v6 := 0
  i := score
  load v3
  
  i := bcd-buffer
  bcd v0
  i := bcd-digit
  load v0
  i := hex v0
  sprite v5 v6 5
  v5 += 5
  
  i := bcd-buffer
  bcd v1
  i := bcd-digit
  load v0
  i := hex v0
  sprite v5 v6 5
  v5 += 5
  
  i := bcd-buffer
  bcd v2
  i := bcd-digit
  load v0
  i := hex v0
  sprite v5 v6 5
  v5 += 5
  
  i := bcd-buffer
  bcd v3
  i := bcd-digit
  load v0
  i := hex v0
  sprite v5 v6 5
  
  return
 
: score
  0 0 0 0
: bcd-buffer
  0 0
: bcd-digit
  0
(+2)

If each memory location contains the number 0..9 than we do not need bcd

: show-score
  v5 := 0 # Coordinates to draw to
  v6 := 0
  i := score
  load v3
  i := hex v0
  sprite v5 v6 5
  v5 += 5
  i := hex v1
  sprite v5 v6 5
  v5 += 5
  i := hex v2
  sprite v5 v6 5
  v5 += 5
  load v3
  i := hex v0
  sprite v5 v6 5
  return

Heh, you're absolutely right :) Silly me.