# Sword of Surtr [FINAL](formerly Sword of Iffrit)

Sword of Surtr Sword of Iffrit

169 replies to this topic

### #151 bogaxOFFLINE

bogax

Dragonstomper

• 761 posts

Posted Tue Mar 27, 2018 8:19 PM

Here I've done some code with tables

First is 22 of your if statements (put in to a more tabular form)
then the same thing with tables.

Each if statement takes a minimum of 7 cycles so if you fall through
all 22 that by it self takes 154 cycles.
If the if statements represent 1/3 of the possible rooms and the
rooms come up at random (they probably don't) 2/3 of the time you'll
spend 154 cycles just to decide you don't want to do anything.
If you do take the if statement then on average you'll do half of them
or about 77 cycles (again if the rooms are random which they probably aren't)
plus the 50 cycles or so that it takes for the rest it.

In the case of the tables it does a look up to decide if it needs to do
anything, that takes about nine cycles (versus 154).
The rest of the table code takes 180 cycles or so (versus the 77 + 50)

But that's all sort of worst case.  It might be faster it might not.
I don't think it would be much worse.

It takes about 1/3 the ROM

Of course, it's not tested but it does compile.

```
set romsize 32k
set optimization noinlinedata

dim _Room = r
dim _Bit5_Frozen = f

bank 2

dispatch2

bank 3

dispatch3
DS7

mk1

if _Room =  2 && player1x >  72 && player1x <  85 &&                  player1y < 55 then _Room = 46 :                  player1y = 85 : _Bit5_Frozen{5} = 0 : goto DS46 bank5  ; 01  1
if _Room =  4 && player1x >  66 && player1x <  86 && player1y > 45 && player1y < 55 then _Room = 42 : player1x = 117 : player1y = 85 : _Bit5_Frozen{5} = 0 : goto DS42 bank5  ; 02  0
if _Room =  5 && player1x > 108 && player1x < 118 &&                  player1y < 65 then _Room = 39 :                  player1y = 84 : _Bit5_Frozen{5} = 0 : goto DS39 bank4  ; 03 10
if _Room =  6 && player1x >  44 && player1x <  56 &&                  player1y < 71 then _Room = 27 : player1x =  78 : player1y = 85 : _Bit5_Frozen{5} = 0 : goto DS27 bank4  ; 04  3
if _Room =  7 && player1x > 114 && player1x < 134 &&                  player1y < 25 then _Room = 37 :                  player1y = 18 : _Bit5_Frozen{5} = 0 : goto DS37 bank4  ; 05  8
if _Room =  8 && player1x >  62 && player1x <  77 && player1y > 52 && player1y < 62 then _Room = 40 : player1x =  21 : player1y = 85 : _Bit5_Frozen{5} = 0 : goto DS40 bank4  ; 06 11
if _Room =  9 && player1x >  49 && player1x <  70 &&                  player1y < 24 then _Room = 66 :                  player1y = 84 : _Bit5_Frozen{5} = 0 : goto DS66 bank5  ; 07  7
if _Room = 10 && player1x >  80 && player1x <  91 && player1y > 55 && player1y < 63 then _Room = 31 : player1x =  77 : player1y = 77 : _Bit5_Frozen{5} = 0 : goto DS31 bank4  ; 08  4
if _Room = 13 && player1x >  46 && player1x <  66 && player1y > 40 && player1y < 46 then _Room = 37 :                  player1y = 84 : _Bit5_Frozen{5} = 0 : goto DS37 bank4  ; 09  8
if _Room = 15 && player1x >  87 && player1x <  96 && player1y > 60 && player1y < 77 then _Room = 25 : player1x =  78 :                 _Bit5_Frozen{5} = 0 : goto DS25 bank4  ; 10  1
if _Room = 18 && player1x >  99 && player1x < 113 && player1y > 40 && player1y < 47 then _Room = 38 :                  player1y = 84 : _Bit5_Frozen{5} = 0 : goto DS38 bank4  ; 11  9
if _Room = 19 && player1x >  51 && player1x <  64 &&                  player1y < 63 then _Room = 26 : player1x =  78 : player1y = 85 : _Bit5_Frozen{5} = 0 : goto DS26 bank4  ; 12  2
if _Room = 24 && player1x >  58 && player1x <  78 &&                  player1y < 62 then _Room = 32 : player1x =  46 : player1y = 85 : _Bit5_Frozen{5} = 0 : goto DS32 bank4  ; 13  5
if _Room = 32 && player1x >  88 && player1x < 104 &&                  player1y < 31 then _Room = 34 :                  player1y = 85 : _Bit5_Frozen{5} = 0 : goto DS34 bank4  ; 14  6
if _Room = 35 && player1x >  96 && player1x < 106 &&                  player1y < 62 then _Room = 36 :                  player1y = 85 : _Bit5_Frozen{5} = 0 : goto DS36 bank4  ; 15  7
if _Room = 37 && player1x > 124 && player1x < 134 && player1y > 28                  then _Room =  7 :                  player1y = 34 : _Bit5_Frozen{5} = 0 : goto  DS7 bank3  ; 16
if _Room = 41 &&                                                      player1y < 55 then _Room = 56 : player1x =  25 : player1y = 84 : _Bit5_Frozen{5} = 0 : goto DS56 bank5  ; 17  5
if _Room = 47 && player1x >  32 && player1x <  52 &&                  player1y < 47 then _Room = 48 :                  player1y = 75 : _Bit5_Frozen{5} = 0 : goto DS48 bank5  ; 18  2
if _Room = 51 && player1x > 114 && player1x < 134 &&                  player1y < 47 then _Room = 50 :                  player1y = 75 : _Bit5_Frozen{5} = 0 : goto DS50 bank5  ; 19  3
if _Room = 52 && player1x >  71 && player1x <  90 &&                  player1y < 47 then _Room = 51 :                  player1y = 84 : _Bit5_Frozen{5} = 0 : goto DS51 bank5  ; 20  4
if _Room = 54 && player1x >  77 && player1x <  90 &&                  player1y < 40 then _Room = 64 :                  player1y = 84 : _Bit5_Frozen{5} = 0 : goto DS64 bank5  ; 21  6
if _Room = 59 && player1x >  84 && player1x < 101 && player1y > 59 && player1y < 76 then _Room = 23 :                  player1y = 84 : _Bit5_Frozen{5} = 0 : goto DS23 bank4  ; 22  0

mk2

dim  room_index = temp1
dim target_bank = temp2
dim   DS_target = temp3

if !ridat[_Room] then skip
room_index = ridat[_Room]-1

if player1x < P1xlo[room_index]  || player1x > P1xhi[room_index] then skip
if player1y < P1ylo[room_index]  || player1y > P1yhi[room_index] then skip

_Bit5_Frozen{5} = 0
if newxdat[room_index] then player1x = newxdat[room_index]
if newydat[room_index] then player1y = newydat[room_index]
_Room  = new_room[room_index]
DS_target = DStdat[room_index]
target_bank = tbnkdat[room_index]

on target_bank goto bnk3 bnk4 bnk5 bnk6

skip

bnk3 goto dispatch3
bnk4 goto dispatch4 bank4
bnk5 goto dispatch5 bank5
bnk6 goto dispatch6 bank6

; 00   01   02   03   04   05   06   07   08   09   10   11   12   13   14   15   16   17   18   19   20   21

data newydat
85,  85,  84,  85,  18,  85,  84,  77,  84,   0,  84,  85,  85,  85,  85,  34, 84,  75,  75,  84,  84,  84
end

data newxdat
0, 117,   0,  78,   0,  21,   0,  77,   0,  78,   0,  78,  46,   0,   0,   0,  25,   0,   0,   0,   0,   0
end

data P1xlo
73,  67, 109,  45, 115,  63,  50,  81,  47,  88, 100,  52,  59,  89,  97, 125,   0,  33, 115,  72,  78,  85
end

data P1xhi
84,  85, 117,  55, 133,  76,  69,  90,  65,  95, 112,  63,  77, 103, 105, 133, 255, 51, 133,  89,  89, 100
end

data P1ylo
255,  46, 255, 255, 255,  53, 255,  56,  41,  61,  41, 255, 255, 255, 255,  29, 255, 255, 255, 255, 255,  60
end

data P1yhi
54,  54,  64,  70,  24,  61,  23,  62,  45,  76,  46,  62,  61,  30,  61,   0,  54,  46,  46,  46,  39,  75
end

data new_room
46,  42,  39,  27,  37,  40,  66,  31,  37,  25,  38,  26,  32,  34,  36,   7,  56,  48,  50,  51,  64,  23
end

data DStdat
1,   0,  10,   3,   8,  11,   7,   4,   8,   1,   9,   2,   5,   6,   7,   0,   5,   2,   3,   4,   6,   0
end

data tbnkdat
3,   3,   2,   2,   2,   2,   3,   2,   2,   2,   2,   2,   2,   2,   2,   1,   3,   3,   3,   3,   3,   2
end

data ridat
0,   0,   1,   0,   2,   3,   4,   5,   6,   7,   8,   0,   0,   9,   0,  10
0,   0,  11,  12,   0,   0,   0,   0,  13,   0,   0,   0,   0,   0,   0,   0
14,   0,   0,  15,   0,  16,   0,   0,   0,  17,   0,   0,   0,   0,   0,  18
0,   0,   0,  19,  20,   0,  21,   0,   0,   0,   0,  22,   0,   0,   0,   0
end

mk3

bank 4

dispatch4 on DS_target goto DS23 DS25 DS26 DS27 DS31 DS32 DS34 DS36 DS37 DS38 DS39 DS40 DS37

DS23
DS25
DS26
DS27
DS31
DS32
DS34
DS36
DS37
DS38
DS39
DS40

bank 5

dispatch5  on DS_target goto DS42 DS46 DS48 DS50 DS51 DS56 DS64 DS66

DS42
DS46
DS48
DS50
DS51
DS56
DS64
DS66

bank 6

dispatch6

asm
echo (.mk2 - .mk1)d
echo (.mk3 - .mk2)d
end

```

### #152 LillapojkenpćönOFFLINE

Lillapojkenpćön

Star Raider

• 81 posts

Posted Wed Mar 28, 2018 3:10 PM

ie they produce the same code

Oh, I saw that in the saving cycles thread a long time ago and assumed that was how it worked

### #153 bogaxOFFLINE

bogax

Dragonstomper

• 761 posts

Posted Wed Mar 28, 2018 5:08 PM

A couple more things.

First I didn't really mention it 'cause it doesn't really pertain
to tables
If eg you take the room 2 branch and fall through you go on and
spend another 150 cycles or so testing a bunch of rooms you already
know you're not in.

Second the 180 cycles v 77 + 50 is worst case and only if you change rooms
If you ran through that code every frame and changed rooms three times
a second that would still only be 5% of the time
If you fall through after, say, the two x position tests then break even
is at about 5 room tests.

The table code always (potentially) does four tests (not counting the room test)
Only a few of the string of if tests do that many.

### #154 ultimaOFFLINE

ultima

Chopper Commander

• Topic Starter
• 174 posts
• Location:Yakima, WA USA

Posted Sat May 12, 2018 4:48 PM

I'm wasting my time trying to fix this so I'm just going to kill it here. Maybe I'll start a new project. Maybe I won't.

### #155 StanJrOFFLINE

StanJr

Web-slinger

• 15,351 posts
• fun or bust
• Location:Louisville KY

Posted Sat May 12, 2018 6:24 PM

I blame myself.  I asked too much.  This is very distressing news to hear.  Honestly, if you released the last version you uploaded I would buy that on a cart.  This is an incredibly well done game.

### #156 Karl GONLINE

Karl G

Moonsweeper

• 374 posts

Posted Sat May 12, 2018 8:23 PM

I worry that I may have inadvertently been discouraging as well. Overcycling was a bit noticeable in spots when I tried it on real hardware, but nothing that makes it unplayable. You have created a pretty awesome game. Put me down for a cart, too, if you choose to publish it.

### #157 MrBeefyONLINE

MrBeefy

Stargunner

• 1,027 posts
• Location:Missouri USA

Posted Sat May 12, 2018 8:35 PM

I'm wasting my time trying to fix this so I'm just going to kill it here. Maybe I'll start a new project. Maybe I won't.

Dude this was looking great! Don't kill it! Maybe someone can help you with whatever is causing the problem?

### #158 ultimaOFFLINE

ultima

Chopper Commander

• Topic Starter
• 174 posts
• Location:Yakima, WA USA

Posted Mon May 28, 2018 9:00 PM

I finished the atari version rewrote and reorganized all the code hope it works on a real system. update is in first post.

-changed a couple playfields

### #159 Karl GONLINE

Karl G

Moonsweeper

• 374 posts

Posted Sun Jun 3, 2018 12:20 PM

It is jitter free on my Atari Jr, and I can't detect any overcycling via Stella (tested in the debugger with breakif {_scan>#262}).

### #160 MrBeefyONLINE

MrBeefy

Stargunner

• 1,027 posts
• Location:Missouri USA

Posted Mon Jun 4, 2018 9:04 AM

So does that mean that he found a way to fix it?

### #161 ultimaOFFLINE

ultima

Chopper Commander

• Topic Starter
• 174 posts
• Location:Yakima, WA USA

Posted Mon Jun 4, 2018 2:32 PM

So does that mean that he found a way to fix it?

Yes I figured out some branch controls to run it without nearly as many cycles. The problem did not really matter on the flashback portable but on real Atari hardware it was making the screen jitter.

### #162 ultimaOFFLINE

ultima

Chopper Commander

• Topic Starter
• 174 posts
• Location:Yakima, WA USA

Posted Sat Aug 4, 2018 10:48 AM

Added the Atari Flashback Portable version with Karl G's score fix to the first post.  After playing for a few I see the playfield bar on the right hand side of the score no longer bleeds into the right most score digits. Nice Job Karl!

### #163 cimmerianOFFLINE

cimmerian

Chopper Commander

• 189 posts

Posted Sat Aug 11, 2018 5:33 PM

Heya ultima! We played Sword of Surtr live on Twitch on our show ZeroPage Homebrew yesterday! Super fun adventure game and I think we made it about half way through or more collecting all the pieces.

You can check out the YouTube archive of the show here:

### #164 ultimaOFFLINE

ultima

Chopper Commander

• Topic Starter
• 174 posts
• Location:Yakima, WA USA

Posted Wed Aug 15, 2018 10:20 PM

Thanks for pointing out the bug in the fire demon cave I'll update it shortly.

### #165 TheFallenWarriorOFFLINE

TheFallenWarrior

Combat Commando

• 2 posts
• Jammed
• Location:Brazil

Posted Thu Aug 16, 2018 11:45 AM

Great game. It has a quite enjoyable experience. Have you considered selling it in cartridges?

### #166 ultimaOFFLINE

ultima

Chopper Commander

• Topic Starter
• 174 posts
• Location:Yakima, WA USA

Posted Fri Aug 17, 2018 5:54 PM

Great game. It has a quite enjoyable experience. Have you considered selling it in cartridges?

Thanks for playing glad you enjoyed it. I guess I've thought about putting it on a cartridge but I'm not sure it's up to par with the amazing work of the people who program in .asm programming.

### #167 ultimaOFFLINE

ultima

Chopper Commander

• Topic Starter
• 174 posts
• Location:Yakima, WA USA

Posted Fri Aug 17, 2018 5:59 PM

Bugfix

- fixed Fire Demon bug where leaving the fight left a fireball (ball pixel) on screen that would kill the player

- adjusted the color of water illumination down a couple notches

- fixed a inventory graphic

- wrote up some general instructions that explain gameplay and a color map of the overworld

new version in first post

### #168 SIO2OFFLINE

SIO2

Stargunner

• 1,110 posts

Posted Fri Aug 17, 2018 7:06 PM

Thanks for playing glad you enjoyed it. I guess I've thought about putting it on a cartridge but I'm not sure it's up to par with the amazing work of the people who program in .asm programming.

This is an awesome game.  Congratulations to you.

Edited by SIO2, Fri Aug 17, 2018 7:18 PM.

### #169 Karl GONLINE

Karl G

Moonsweeper

• 374 posts

Posted Fri Aug 17, 2018 7:10 PM

It's about the quality of the game, not just about the tools that are used. It's a great game with a huge world. I'd love to have it on cart.

### #170 TheFallenWarriorOFFLINE

TheFallenWarrior

Combat Commando

• 2 posts
• Jammed
• Location:Brazil

Posted Yesterday, 7:29 AM

Thanks for playing glad you enjoyed it. I guess I've thought about putting it on a cartridge but I'm not sure it's up to par with the amazing work of the people who program in .asm programming.

I think this game has a great potential and the tool you use isn't what makes a game good or bad.

#### 0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users