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

Твердыня модульных языков
Текущее время: 29 мар 2024, 15:04

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




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

Сообщения: 104
how does someone go through each character of a string?

and split strings into smaller strings.

Also how do you turn a number into a string.

This doesnt work
Str="hi this is a string";
C.WriteStr(LEN(Str));

because string literals are not arrays


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

Сообщения: 1019
Откуда: Днепропетровская обл.
Hi Slenkar! :-)
slenkar писал(а):
how does someone go through each character of a string?
Actually if a string is array of characters, so:
Код: "OBERON"
  1. VAR str: ARRAY 256 OF CHAR; i: INTEGER;
  2. BEGIN
  3. FOR i := 0 TO 255 DO C.WriteCh( str[i] ) END;
But if a string is just literal, no way to do it.

slenkar писал(а):
and split strings into smaller strings.
For this, you can use your own procedure, like this (see Extract). Also there are Delete, Insert, Replace, Append, Concat, etc.

slenkar писал(а):
Also how do you turn a number into a string.
Код: "OBERON"
  1. PROCEDURE IntToString* (x: LONGINT; VAR s: ARRAY OF CHAR);
  2. VAR j, k: INTEGER; ch: CHAR; a: ARRAY 32 OF CHAR;
  3. CONST
  4. minLongIntRev = "8085774586302733229"; (* reversed string of -MIN(LONGINT) *)
  5. BEGIN
  6. IF x # MIN(LONGINT) THEN
  7. IF x < 0 THEN s[0] := "-"; k := 1; x := -x ELSE k := 0 END;
  8. j := 0; REPEAT a[j] := CHR(x MOD 10 + ORD("0")); x := x DIV 10; INC(j) UNTIL x = 0
  9. ELSE
  10. a := minLongIntRev; s[0] := "-"; k := 1;
  11. j := 0; WHILE a[j] # 0X DO INC(j) END
  12. END;
  13. ASSERT(k + j < LEN(s), 23);
  14. REPEAT DEC(j); ch := a[j]; s[k] := ch; INC(k) UNTIL j = 0;
  15. s[k] := 0X
  16. END IntToString;
(taken from BlackBox Component Builder)

slenkar писал(а):
This doesnt work
Str="hi this is a string";
Do you mean CONST Str="hi this is a string" here?
slenkar писал(а):
C.WriteStr(LEN(Str));
As I know, LEN doesn't work for string literals.

You can't have direct access to a string literal. Use COPY or := to initial an array, like:
Код: "OBERON"
  1. VAR str: ARRAY 256 OF CHAR;
  2. BEGIN
  3. str := "This is my string literal";
  4. COPY("This is my string literal", str);

You can also use non-standard extension of XDev - constant arrays:
Код: "OBERON"
  1. TYPE
  2. MsgStr = ARRAY 3, 7 OF CHAR;
  3. CONST
  4. Way = MsgStr("Hello","Error","Try");
  5. TYPE
  6. Labirint = ARRAY 3, 16 OF CHAR;
  7. CONST
  8. Map = Labirint(
  9. "...o..##...oo12",
  10. "...o..##...oo35",
  11. "...o..##...oo78"
  12. );

I hope I understood your questions correctly.

P.S. Do you write a game for ZX Dev Conversions party? ;-) I know that you can't announce. Well, you at least hint. ;-)


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

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

Thanks you answered my questions very well.

I am making a text game for someone, he is giving me all the text.

The text he is giving me is quite large and I can't just print it to the screen as it is.

I have to do a wordwrap function to make sure words are not split in half on the right side of the screen.
So I cant use string literals.

It seems like I have to count all the characters in each string?
(in order to create a char array, so it can be examined for word wrap)

Just think of a text adventure game but with very long descriptions for each room.


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

Сообщения: 1019
Откуда: Днепропетровская обл.
Then I suggest such an algorithm.

You read from a binary resource a byte-string that can be represented internally as constant arrays at the C-level (or at Oberon-level based on the XDev extension). You read the word for a word. As a separator, you accept a space, a comma or a dot. Then you check to see if the word will fit into the remaining space of the line, and whether it will not be splitted. If placed, you type the word. If not, go to a new line.

The algorithm is more complicated if you also want to align the text with extra spaces. Or, for example, you have a font not fixed in width. In the first case, you should not print a line on the screen at once, but form it in a small array. And complement the string with spaces for alignment. In the second case it is required to consider the line width in pixels, based on the width of each letter. In general, there is nothing complicated.

I understand that you are developing a game for the Spectrum. Therefore, you need to develop all the string functions in assembler. This is the most correct way.

For example, very good implementation of Conversion 16-bit Integer to ASCII (decimal).


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

Сообщения: 104
if oberon could get the memory address of the start of a string literal and then read bytes in order
it could do word wrap.
I think PEEK is in the Basic library. Just need the memory address of the string literal.
Are pointers implemented in OberonXDev?


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

Сообщения: 1019
Откуда: Днепропетровская обл.
Yeap, pointers are in any Oberon implementation.

But you just use INTEGER numbers to specify a memory address, and Basic.PEEK/POKE or SYSTEM.GET/PUT to access data.

Oberon is such a simple language that it does not provide a mechanism for including constant data to a module, for example, resources. Except reading from a file, etc. Therefore, to provide a more compact and economical way, Oleg Komlev (Saferoll) made a non-standard extension - constant arrays, implemented in Ofront+ for XDev. We plan to add this feature to the command-line Ofront+ translator for Windows and Linux, but so far this has not been implemented.

Here are two ways that you can use right now through the C-level.

1. Substitution of string implementation. In Oberon you describe a string as a large array. You are not even interested in its length, if only it was sufficient. You translate this definition to get a sym-file. In this case, the *.c and *.h files generated by Ofront do not interest you, and you delete them. Instead, you create your own *.c and *.h files (in ../C folder) with the implementation of the string, where you define it as a constant array in C filled with the necessary data.

2. Approximately the same method of substitution, but the work occurs byte by byte through abstractions (thin layer) of access to a resource. See the attached example.


Вложения:
Project.zip [8.52 КБ]
Скачиваний: 410
Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: strings
СообщениеДобавлено: 02 авг 2017, 20:54 
Не в сети

Сообщения: 104
Thanks :)

Why are the resources being read after they are printed to the screen?


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

Сообщения: 104
ohh there are 4 strings :D
I think I get it now thanks

does the resource Mod make it possible to use a compressor for strings?

(e.g. megalz)

When I change the strings in the .c file how do I compile them?


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

Сообщения: 104
BTW is the ofront 4 linux code still being kept up to date?


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

Сообщения: 1019
Откуда: Днепропетровская обл.
slenkar писал(а):
does the resource Mod make it possible to use a compressor for strings?
Yes.
You can use any depacker written for Z80 CPU in assembly language.

I implemented work with the packer ZX7 by Einar Saukas, which shows an excellent compression ratio. Under a host-OS, you use the utility to prepare compressed resources, as well as one of the three implementations of the unpacker, differing in size and speed of operation. The smallest occupies the whole 69 bytes only. You can see an example of using this packer in the clip.

slenkar писал(а):
(e.g. megalz)
Yes. Also I implemented MegaLZ unpacker. See in ZXDev/Lib/Mod/MegaLZ.Def

But I do not remember where we can get a packer for it, and I did not test it. You can, of course, write in assembler any other method for depacking text, and attach it to your Oberon-program.

slenkar писал(а):
When I change the strings in the .c file how do I compile them?
Write a building script to compile the modules that are generated by Ofront from the folder /Obj, and the written manually - from the folder /C. So you'll never get confused.

slenkar писал(а):
BTW is the ofront 4 linux code still being kept up to date?
Do you mean the Ofront 1.4 for Linux-386 Kernel 3.2 ? This is yes.


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

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


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

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


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

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