Оберон-клуб «ВЄДАsoft»

Твердыня модульных языков
Текущее время: 28 мар 2024, 13:52

Часовой пояс: UTC + 2 часа




Начать новую тему Ответить на тему  [ Сообщений: 28 ]  На страницу Пред.  1, 2, 3
Автор Сообщение
 Заголовок сообщения: Re: strings
СообщениеДобавлено: 07 авг 2017, 07:38 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
Basic__init__init must be just Basic__init. It looks like you're using SYSTEM.h incompatible with the used Ofront version. Note that the older Ofront uses this definition:
Код: "C"
#define __IMPORT(name)	SYSTEM_INCREF(name##__init())
While Ofront + uses:
Код: "C"
#define __IMPORT(name__init)	SYSTEM_INCREF(name__init())
You can, of course, fix this line and repeat the compilation. But for using with Ofront+, it's better to get SYSTEM.h from XDev repository.

The reason why I got rid of ## is the desire to use Ofront+ with Borland Turbo C which does not support ##.


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: strings
СообщениеДобавлено: 07 авг 2017, 20:45 
Не в сети

Сообщения: 104
Success!

here is the makefile

Цитата:
all: $(targetname).tap


#OBJECTS = ""


$(targetname).tap: $(targetname).bin
bin2tap -b -a 25000 -c 24999 -r 25000 -o $(targetname).tap $(targetname).bin

fuse $(targetname).tap
$(targetname).bin: $(targetname).ihx
hex2bin $(targetname).ihx

$(targetname).ihx: $(targetname).c
sdcc $(targetname).c -mz80 --code-loc 25000 --data-loc 53000 --no-std-crt0 --opt-code-size --funsigned-char --disable-warning 126 -I $(XDEV)/ZXDev/Lib/C -I $(XDEV)/ZXDev/Lib $(XDEV)/ZXDev/Lib/Basic.lib $(XDEV)/ZXDev/Lib/XDev.lib

$(targetname).c :$(OBJECTS) $(targetname).mod
ofront+ $(targetname).mod -m

%.lib: %.rel
sdcclib $@ $<

%.rel:%.c
sdcc -mz80 -c $< -I Lib

%.c %.sym:%.mod
ofront+ $< -e -s
clean:
rm *.lib *.rel *.c *.h *.ihx *.bin



it works on windows and linux
windows needs MinGW installed,

the xdev environment variable is used to import libraries, so that has to be set

then you have to add a lot of stuff to your PATH
c:/mingw/msys/1.0/bin - for windows users only
xdev/zxdev/bin
fuse emulator location
sdcc location
ofront+ location

then you just run "make targetname=hello" if you main file is called hello.mod

the makefile
turns your mod files into c and sym
then compiles c to hex
then converts hex to bin
then converts bin to tap
and runs fuse

if one of these steps fails it stops and gives the error message
I run the makefile from a text editor called geany.


If I want to create a library in c and use it in oberon do I just need a def file along with the C?
if you also need .sym files how are those created?

I looked through the ofront manual and couldnt find any info on that


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: strings
СообщениеДобавлено: 08 авг 2017, 22:37 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
Perfectly! Glad your success! :-) Please keep us informed on the progress of writing the game. Can I hope that you will help contribute to the growth of the popularity of the environment ZXDev by opening the source of the game (after the compo) or by helping with examples (similar to those that come with ZXDev)?

slenkar писал(а):
then you just run "make targetname=hello" if you main file is called hello.mod

the makefile
turns your mod files into c and sym
Please note that .h and .sym files are not created for a main module.

slenkar писал(а):
If I want to create a library in c and use it in oberon do I just need a def file along with the C?
There are at least two ways to do it (and their variations).

    1. You use a C library that has not been modified for Ofront. You'll need Module.h, Module.c, Module.lib and the hand-written Module.Def which you are translating through Ofront to get the file Module.Sym.

    We're keeping in mind that Ofront uses a special underscore mangling for names to prevent a conflict of names (placed in different headers). From this side, a pure C library is not ready to be used with Ofront.

    So you need to use a small layer, which you'll include from an Oberon module:
    Код: "C"
    #define Module_Name1 Name1
    #define Module_Name2 Name2
    ...
    #define Module_NameN NameN
    An example of using a library in this way you can see at ZXDev/Lib/TrDos.Def. It uses the layer Lib/C/TrDos.h which internally includes the original unmodified Lib/C/TrDos/trdos.h where all the names are defined in Ofront style.


    2. Ofront has a command line option -i that is well documented. If you use -i, Ofront attaches to the generated C files the contents of two files - Module.h0 and Module.c0. There are the parts of your Oberon-module written in C language.
    Код: "C"
    // SDL2.h0
    extern int SDL_HasEvent(int);
    extern int SDL_HasEvents(int, int);
    extern int SDL_PeepEvents(void *, int, int, int, int);
    Код: "OBERON"
    1. IMPORT SYSTEM;
    2.  
    3. (* If -i option used, you don't need this line: *)
    4. PROCEDURE -AAIncludeSDL2h0 '#include "SDL2.h0"';
    5.  
    6. PROCEDURE -HasEvent*(type: INTEGER): INTEGER "SDL_HasEvent(type)";
    7. PROCEDURE -HasEvents*(minType, maxType: INTEGER): INTEGER
    8. "SDL_HasEvents(minType, maxType)";
    9. PROCEDURE -PeepEvents*(events: ARRAY OF Event; numevents, action,
    10. minType, maxType: INTEGER): INTEGER
    11. "SDL_PeepEvents(events, numevents, action, minType, maxType)";

slenkar писал(а):
if you also need .sym files how are those created?
By compiling the hand-written .Def file where all the constants and prototypes of functions are defined for binding to a module written in Oberon.

slenkar писал(а):
I looked through the ofront manual and couldnt find any info on that
I advise you to see how arranged the modules Platform.Unix.Mod and Platform.Windows.Mod from Ofront+ itself. Also you can read my article «Details of Oberon Programming in ZXDev». There is a chapter on this topic.


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: strings
СообщениеДобавлено: 08 авг 2017, 23:10 
Не в сети

Сообщения: 104
thanks,

I have a pathfinding routine, from that last game, I will have to see if I posted it already. If not I will make that available.

If I have any other useful functions I will post those also.


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: strings
СообщениеДобавлено: 10 авг 2017, 09:38 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
Thank you.

See also this code, which shows how to work with strings in the C-style. Oberon has a length field for a string, and strings in C are just null-terminated strings of characters. To work with strings like in C, I declare the type CString:
Код: "OBERON"
  1. TYPE
  2. CString = SYSTEM.PTR; (* C-like null-terminated string. *)
Note that the type SYSTEM.PTR is managed (garbage collected) in Ofront, but for Z80 there aren't any memory management implemented. So in this case we can use SYSTEM.PTR as unmanaged memory pointer.

Код: "OBERON"
  1. PROCEDURE -AAincludeStdlib "#include <stdlib.h>";
  2. PROCEDURE -AAincludeString "#include <string.h>";
  3. PROCEDURE -Length (str: CString): INTEGER "strlen((char*)str)";
  4. PROCEDURE -CopyStr (dest, src: CString) "strcpy((char*)dest, (char*)src)";
  5. PROCEDURE -IntToStr (n: INTEGER; str: CString) "_itoa(n, (char*)str, 10)";
  6. PROCEDURE -UIntToStr (u: INTEGER; str: CString)
  7. "_uitoa((unsigned int)u, (char*)str, 10)";
  8. PROCEDURE -Concat (dest, src: CString) "strcat((char*)dest, (char*)src)";
Example:
Код: "OBERON"
  1. PROCEDURE GuessHappy; (** Try to guess a happy by one of three way. *)
  2. CONST
  3. MaxIntSize = 7; (* -12345 + 0X. *)
  4. VAR
  5. num: (* UNSIGNED *) SHORTINT;
  6. strBuf: ARRAY MaxIntSize OF CHAR; (* For conversions integer to string. *)
  7. BEGIN
  8. num := SHORT( b.RND(1, 4) );
  9. UIntToStr(num, SYSTEM.VAL(CString, SYSTEM.ADR(strBuf)));
  10. Concat(SYSTEM.VAL(CString, SYSTEM.ADR(strBuf)),
  11. SYSTEM.VAL(CString, SYSTEM.ADR(" "))
  12. );

Of course, such style of working with strings should be called dangerous. This is not Oberon-way. But for Z80, it is more or less acceptable. I use it in a puzzle game for ZX Spectrum.


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: strings
СообщениеДобавлено: 12 авг 2017, 05:36 
Не в сети

Сообщения: 104
I tried that code
Код: "OBERON"
  1.  
  2. MODULE Stringy;
  3. IMPORT SYSTEM, B := Basic;
  4. TYPE
  5. CString = SYSTEM.PTR; (* C-like null-terminated string. *)
  6. CONST
  7. MaxIntSize = 7; (* "-12345" + 0X. *)
  8. VAR
  9. num: SHORTINT;
  10. strBuf: ARRAY MaxIntSize OF CHAR; (* Convert integer to string. *)
  11. PROCEDURE -includestdlib "#include <stdlib.h>";
  12. PROCEDURE -includestring "#include <string.h>";
  13. PROCEDURE -Length (str: CString): INTEGER "strlen((char*)str)";
  14. PROCEDURE -CopyStr (dest, src: CString) "strcpy((char*)dest, (char*)src)";
  15. PROCEDURE -IntToStr (n: INTEGER; str: CString) "_itoa(n, (char*)str, 10)";
  16. PROCEDURE -UIntToStr (u: INTEGER; str: CString)"_uitoa((unsigned int)u, (char*)str, 10)";
  17. PROCEDURE -Concat (dest, src: CString) "strcat((char*)dest, (char*)src)";
  18.  
  19.  
  20.  
  21.  
  22.  
  23. BEGIN
  24. num :=4;
  25. UIntToStr(num, SYSTEM.VAL(CString, SYSTEM.ADR(strBuf)));
  26. Concat(SYSTEM.VAL(CString, SYSTEM.ADR(strBuf)),SYSTEM.VAL(CString, SYSTEM.ADR(" is my number")) );
  27. END Stringy.
  28.  

the SDCC compiler says the functions like utoa are missing


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: strings
СообщениеДобавлено: 13 авг 2017, 14:58 
Не в сети
Аватара пользователя

Сообщения: 1019
Откуда: Днепропетровская обл.
These functions are from stdlib.h/z80.lib, so make sure that when you call SDCC, you specify the paths where the files are present.

sdcc -L %ZXDev%\Lib ( here is path to z80.lib )
sdcc -I %ZXDev%\Lib\C\include ( here is path to stdlib.h )


Вложения:
stdlib.png
stdlib.png [ 17.32 КБ | Просмотров: 13915 ]
Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: strings
СообщениеДобавлено: 14 авг 2017, 17:10 
Не в сети

Сообщения: 104
thanks it works now


Вернуться к началу
 Профиль  
Ответить с цитатой  
Показать сообщения за:  Поле сортировки  
Начать новую тему Ответить на тему  [ Сообщений: 28 ]  На страницу Пред.  1, 2, 3

Часовой пояс: UTC + 2 часа


Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 2


Вы не можете начинать темы
Вы не можете отвечать на сообщения
Вы не можете редактировать свои сообщения
Вы не можете удалять свои сообщения
Вы не можете добавлять вложения

Найти:
Перейти:  
cron
Создано на основе phpBB® Forum Software © phpBB Group
© VEDAsoft Oberon Club