agssim: add support for string literals, rewrite memory model
commit956aea1649f724bccbfc6411f822abda8b3bd75d
authorrofl0r <rofl0r@users.noreply.github.com>
Wed, 11 Dec 2019 01:32:25 +0000 (11 01:32 +0000)
committerrofl0r <rofl0r@users.noreply.github.com>
Wed, 11 Dec 2019 01:32:25 +0000 (11 01:32 +0000)
tree11ddd7416356fd97bfa363af9cf618cb888e0887
parentfed1411300f0d5914d20b564a3cd41b1066152f5
agssim: add support for string literals, rewrite memory model

the reason string literal support was postponed is that it wasn't
quite clear where to put them.
ags itself saves a lot of metadata together with each value
passed around (and therefore knows that if it's a string it's
stored in some specific "segment"), while we want to do it low-level.

the following solution was implemented:
- flat memory model, starting with text segment, rounded up to
  multiples of 4096 bytes, followed by stack (currently fixed at
  16KB), and then a heap that's not yet in use.
  this allows to access all 3 memory regions with a single
  index/pointer from the script.
- text segment, which was previously an array of int which is
  simpler to deal with in some regards, and IP which was an
  array index into the text segment, have been changed to work
  with a character array, with full single-byte addressing.
  here we differ now from how ags does it, but it doesn't really
  matter.
- strings are added to the text segment as they appear in the
  assembly, and simply jumped over. this adds some overhead:
  8 bytes for the jump instruction and padding to the next 4byte
  boundary. in the future, this may be changed to use the heap
  memory instead.
- since we need to know how big the text segment is when we
  initialize the stack pointer, the growth of text becomes
  "locked" as soon as execution starts, i.e. the first step
  or run command executed. it's still possible to add instructions
  to fill up the entire last text page, though.
agssim.c