ACNews #68
30 августа 2017

Handling global variables in Evo SDK - we shall expand Evo SDK possibilities again

<b>Handling global variables in Evo SDK</b> - we shall expand Evo SDK possibilities again
              Handling global variables in Evo SDK
                         by Hippiman

So, guys, we shall expand Evo SDK possibilities again. Initially
SDK had very limited possibilities and was close by
functionality to popular ZX Spectrum native editors. There was
no disk access and high memory addressing, and the terrible code
limitation to 32KB.

I described means of overcoming that in my previous
publications. However, growing code by dividing it in modules
was uncomfortable because of no access to global variables from
modules. We needed monstrous manager functions to pass needed
parameters in module or write them in high memory. In fact, we
could live with that, but the need for extra effort slowed down
module calls and their uses. Here I'll tell how to make friends
with global (and static) variables of main program from a

                             * * *

First we go to_temp_ subdirectory in our project (if you don't
have it, read ACNews #59 ) and open Scroll to the
middle of the file, searching for lines like this:

Area  Addr     Size     Decimal Bytes (Attributes)
_DATA 00005322 000007C9 = 1993. bytes (REL,CON)

Where 00005322 is a beginning of data area. (Of course, it
varies for different projects.)
Let's, we don't need it any more. Open out.asm.
It starts with function list, skip it. Find the following:

; ram data
.area _DATA

After that, a list of global and static variables follows like

 .ds 2
 .ds 2
 .ds 2
 .ds 2
 .ds 1
 .ds 1

As we see, there are no addresses, and that's confusing.
Although we have this:.ds 2.
These are nothing but byte sizes of variables.
Using simple computations, we produce the addresses:

_curtime 0x00005322 (beginning of data area)
_nexttime 0x00005322+0x2 = 0x00005324
_nextid 0x00005324+0x2 = 0x00005326
_nextglobid 0x00005326+0x2 = 0x00005328
_bullet1 0x00005328+0x2 = 0x0000532A
_roadpos 0x0000532A+0x1 = 0x0000532B etc.

So we know all the addresses of global variables. We just need
adding then in a module.
For example, this way:

static u8 *maxhealth;

Make sure that addresses can change after every change and
recompilation of main module. So hand counting all links is bad
idea, we better write a script for this. Here is the listing of
perl script that processes main module sources and generates two

pointers.h - with function pointers;
variables.h - with variable pointers.

use strict;

my $flag;
my $str;
my @arr;
my $databegin;
my $tmp;
open FIL,"_temp_\";
open OUT,">pointers.h";
open VAR,">variables.h";
  chomp $str;
    @arr=split(/ /,$str);
    if(substr($arr[2],0,1) eq "_")
      print "#define " .$arr[2]." 0x". $arr[0]."n";
      print OUT "#define " .$arr[2]." 0x". $arr[0]."n";
    if($arr[0]eq"_DATA" && $databegin==0)
      $databegin= hex($arr[31]);#we obtained data area address
                                #and convert it in decimal.

close FIL;
open FIL,"_temp_\out.asm"; #open main source.
while($flag==0) #scroll to beginning of variable descriptions
  chomp $str;
  #print $str."n";
  if($str eq "; ram data")

while($flag==0)#process variable area
  chomp $str;
  if($str eq
#end of area, we don't need anything after it.
    $str=~s/t//g;#remove various trash
    $tmp="#define ".$str." ".sprintf ("0x%x",$databegin)."n";
    $str=<FIL>;#read one more line containing shift
    chomp $str;
    @arr=split(/ /,$str);
    $databegin+=$arr[1];#we obtained new shift
    print $tmp;
    print VAR $tmp; #output the result in header

That's all. Now we can call this script from .bat file that 
compiles the main module, and we shall always have fresh data 
about addresses of functions and variables. 

Другие статьи номера:

Новости - Изменения в пакете NedoLang, Hippiman сменил квартиру, после чего начал писать игровой движок на NedoLang, John Silver купил студийные колонки-мониторы, венгерские хакеры портировали Wolfenstein 2004 на компьютер Enterprise 128.

News - Hippiman changed his residence, then started to make a game, John Silver bought studio speakers, first ATM 8.00 board was finally

Работа с глобальными переменными в Evo SDK - сегодня мы снова будем расширять возможности Evo SDK

Handling global variables in Evo SDK - we shall expand Evo SDK possibilities again #mhm о демопатях - какието там ЦЦ-Дихальты, это чисто русские такие тусовки-бухаловки с чисто русским таким менталитетом #mhm about demoparties - about russian parties

О светодиодных лампах - Началось всё с покупки настенного светильника в магазине IKEA в октябре 2016 года...

Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Похожие статьи:
ZX in the world - С сегодняшнего номера в этой рубрике мы будем, по мере возможности, освешать все новости, а может и события, относительно новых коммуникационных возможностей Спектрума.
WANTED - Розыск программ.
Список BBS - Список работающий BBS.
Обзор - десять лучших игр на спектруме: UFO-2, Last Battle, Blood Wich, Laser Squad, Carrier Command, Lord of Chaos, Shadow of the Beast, Battle Command, Star Glider, Dizzy.
Аперативчик - От авторов.

В этот день...   29 сентября