DSA errors, tips and tricks - discuss

Discuss Chaos Strikes Back for Windows and Linux, an unofficial port of Chaos Strikes Back to PC by Paul Stevens, as well as CSBuild, an associated dungeon editor.

Moderator: Zyx

Forum rules
Please read the Forum rules and policies before posting.
Roquen
Artisan
Posts: 179
Joined: Fri Jul 11, 2008 11:34 am
Location: Biarritz, France

Post by Roquen »

Read through it and have a BAGILLION questions...I'll get to them at some point.

BUT! I wrote my first DSA. It my classic "Goodbye World?" which is a play on the classic "Hello World!" The code is as follows:

Code: Select all

L1 L0 &\
Which answers yes or in other words:

CSBWin has stopped working

:twisted:
User avatar
beowuuf
Archmastiff
Posts: 20687
Joined: Sat Sep 16, 2000 2:00 pm
Location: Basingstoke, UK

Post by beowuuf »

Well, if you will go and divide by zero, then it is your own fault

I think with all the new features that keep being included in the engine, Paul S had enough to cope with and there will be some holes in the system that a dungeon designer should plug themselves or not cause. I know I created a check routine for a DSA that made sure I wasn't doing anything in a negative space of the dungeon to avoid errors - an error I think since guarded against

If you do a filter trace of the dsa, I would assume you would get a reading as far as a division by zero before everything went pair shaped. If a dungeon designer can't figure out from that where the wheels came off, they should probably stick to non DSA stuff! :D

That said, if it's a quick fix Paul may well do something about that one!
Roquen
Artisan
Posts: 179
Joined: Fri Jul 11, 2008 11:34 am
Location: Biarritz, France

Post by Roquen »

I have no strong opinion about changing the behavior, I'm just goofing around trying to understand how everything works and looking for got-yas.

I brought this up because in my experience the toughest to track down problems are those that are in pieces of code that you "know" to be correct. My example was trivial, but take another where the divisor is coming from a global that was calculated with say "&-", instead of "&1-" and the offending code is triggered by a monster stepping on a pressure plate and the person seeing the problem is a player...it might take awhile for the designer to figure out what's causing the seemingly random crash. Additionally many programmers don't seem to know (or think about) the fact that integer division and mods by zero generate hardware exceptions, so that is an additional barrier to designers with limited programming experience.

The trace might or might not (almost always not) be helpful since the engine routine PrintTrace doesn't explicitly flush the stream (which is a good thing IMHO) at each call. The runtime does not flush open streams on unhandled exceptions, so up to a buffer's worth of data (4K by default in VC) is lost (not written to the file) on unhandled exceptions, so the info in the trace virtually insured to be missing a fair amount of data if the program crashes. For my example above, no DSA tracing makes it's way into the file.

A possible patch for division is (and likewise for &%):

Code: Select all

  // current version
  i32 v = pdsaDbank->stack.pop();
  i32 w = pdsaDbank->stack.pop();
  pdsaDbank->stack.push(w/v);

Code: Select all

  // patched version
  i32 v = pdsaDbank->stack.pop();
  i32 w = pdsaDbank->stack.pop();
  
  if (v != 0)
     pdsaDbank->stack.push(w/v);
  else
     die(someNumber, "divide-by-zero");
While I'm babbling, another minor potential got-ya relates to the bit-shift instructions. The various CPU vendors implement shifts by more than 31 bits in two ways:

x >> (y & 31) or x >> (min(y,31))

Which could cause dungeons behave differently on desktop Windows vs. CE builds. (Intel uses the first BTW).

So, I'd suggest the following patch (and likewise for &RSHIFT):

Code: Select all

  i32 v = pdsaDbank->stack.pop();
  i32 w = pdsaDbank->stack.pop();
  pdsaDbank->stack.push( (v>=0)?(w<<(v&31)):(w>>((-v)&31)));
This would make all versions behave exactly the same (the current desktop behavior) and the compiler will remove the unneeded mask on CPUs that use the first convention.

Again, I have no strong feeling about either of these potential issues, but removing barriers for people with little programming experience is never a bad thing.
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Post by Paul Stevens »

I suppose there is no harm in complaining
about these things publicly. I will implement
something similar to your suggestions. But
Zyx and I communicate such things in private
and it saves a LOT of space in the forum,
believe me.

The best option is the 'bugs and requests'
section of the wiki:

http://dmwiki.atomas.com/wiki/CSBwin/Bugs_and_Requests

Putting them in the wiki also will help
keep them from being forgotten. If there
gets to be a large number we can make
additional pages to organize them.
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Post by Paul Stevens »

CSBwin version 10.098 in:
http://dianneandpaul.net/CSBwin/ConstructTorch.zip

closes the trace on any exception. Enable
DSA trace and go to level 2 and cause a
divide fault to see this work.

I also incorporated your code for left and
right shift.
Post Reply

Return to “Chaos Strikes Back for Windows & Linux (CSBWin) / CSBuild”