Ultimate Amiga

Network Boards => AMOS Programming Environment => AMOS Factory => AMOS BASIC => Topic started by: xboxisfinished on June 06, 2019, 06:11:36 AM

Title: How to write a code that make a new text file and store text into it?
Post by: xboxisfinished on June 06, 2019, 06:11:36 AM
   I am writing a game in AMOS but there is a bug that is persistence and I want to write a debug code that stores the result in a text file in RAM and store the result as text in the file. But I do not know if there is away to write a code in AMOS that make new file and store contents in the file. Can someone help in this matter? :)

Title: Re: How to write a code that make a new text file and store text into it?
Post by: Hungry Horace on June 08, 2019, 10:25:19 AM
I tend to write to a text string and then when i need to (e.g. program close, or specific events) have a procedure that sends the entire string to a text file.

I think there is a 'proper' way of doing it, but i am lazy and just POKE all the string into a file.

Code: [Select]
' keep adding to this as you need
DBUG$="my error msg."+Chr$(10)+"fish"

Gosub _SAVE_CODE :

End

_SAVE_CODE:
   Reserve As Work 1,Len(DBUG$)

   For N=1 To Len(DBUG$)
      Poke Start(1)+N-1,Asc(Mid$(DBUG$,N,1))
   Next

   Bsave "ram:debug.txt",Start(1) To Start(1)+Length(1)
   Erase 1
Return
Title: Re: How to write a code that make a new text file and store text into it?
Post by: Lonewolf10 on June 09, 2019, 01:49:01 PM
I tend to write to a text string and then when i need to (e.g. program close, or specific events) have a procedure that sends the entire string to a text file.

I think there is a 'proper' way of doing it, but i am lazy and just POKE all the string into a file.

Code: [Select]
' keep adding to this as you need
DBUG$="my error msg."+Chr$(10)+"fish"

Gosub _SAVE_CODE :

End

_SAVE_CODE:
   Reserve As Work 1,Len(DBUG$)

   For N=1 To Len(DBUG$)
      Poke Start(1)+N-1,Asc(Mid$(DBUG$,N,1))
   Next

   Bsave "ram:debug.txt",Start(1) To Start(1)+Length(1)
   Erase 1
Return


That is the way I would do it too.
Title: Re: How to write a code that make a new text file and store text into it?
Post by: SamuraiCrow on June 09, 2019, 09:07:10 PM
Isn't there a Poke$ command that will replace the loop in your save routine?
Title: Re: How to write a code that make a new text file and store text into it?
Post by: Volvo_0ne on June 10, 2019, 07:23:23 PM
_SAVE_CODE:
   Reserve As Work 1,Len(DBUG$)

   For N=1 To Len(DBUG$)
      Poke Start(1)+N-1,Asc(Mid$(DBUG$,N,1))
   Next

   Bsave "ram:debug.txt",Start(1) To Start(1)+Length(1)
   Erase 1
Return

Surely the above will keep overwriting the sprite bank ???

An unused bank above 5 would probably be better?
Title: Re: How to write a code that make a new text file and store text into it?
Post by: Hungry Horace on June 27, 2019, 09:36:02 PM
_SAVE_CODE:
   Reserve As Work 1,Len(DBUG$)

   For N=1 To Len(DBUG$)
      Poke Start(1)+N-1,Asc(Mid$(DBUG$,N,1))
   Next

   Bsave "ram:debug.txt",Start(1) To Start(1)+Length(1)
   Erase 1
Return

Surely the above will keep overwriting the sprite bank ???

An unused bank above 5 would probably be better?


this is what i would call "back of a cigarette packet" code - yes, another choice of bank would be better, but in my example i am not storing any sprites ;)

@SamuraiCrow

You know - you may be right - I am so used to applying the above method i probably never even considered there might be a special command for to do the same ;D
Title: Re: How to write a code that make a new text file and store text into it?
Post by: Hungry Horace on July 01, 2019, 09:31:24 PM
just a quick anecdote, that i tried using POKE$ today and it immediately crashed my system... grr...
Title: Re: How to write a code that make a new text file and store text into it?
Post by: Lonewolf10 on July 21, 2019, 02:10:36 PM
just a quick anecdote, that i tried using POKE$ today and it immediately crashed my system... grr...

Hmmm... the only time Poke$ has crashed my system is when I am putting the data in the wrong place. I forget whether the string data comes first or the address so I tend to do Poke$ TEXT$, ADDRESS and if I have them the wrong way round the editor will let me know ;)
Title: Re: How to write a code that make a new text file and store text into it?
Post by: Hungry Horace on July 21, 2019, 08:47:43 PM
well i found out that for some reason i managed to use $A instead of Chr$($A) in the third parameter and it still passed tokenisation, so i think that may have been the cause!
Title: Re: How to write a code that make a new text file and store text into it?
Post by: Lonewolf10 on August 10, 2019, 03:35:24 PM
well i found out that for some reason i managed to use $A instead of Chr$($A) in the third parameter and it still passed tokenisation, so i think that may have been the cause!

Yeah, that just might!  ;)
Title: Re: How to write a code that make a new text file and store text into it?
Post by: xboxisfinished on August 20, 2019, 06:58:33 AM
Thank you guys for the help! I have a question to add into this?

What if instead of storing text file...I wanted to store whatever values stored in a two dimensional array?

Say the array is this:

Dim MapArray(256, 256)

Assume in MapArray(3,3)=12
Assume in MapArray(3,0)=1
Assume in MapArray(3,2)=1
...
etc

I want to store the values in a file.bin (encrypted) and then reverse it by reading it using poke, peek method. How do I go about doing that?
Title: Re: How to write a code that make a new text file and store text into it?
Post by: SamuraiCrow on August 21, 2019, 12:02:37 AM
If you're going to peek and poke it anyway, just use a bank.
Title: Re: How to write a code that make a new text file and store text into it?
Post by: xboxisfinished on August 21, 2019, 01:38:31 AM
If you're going to peek and poke it anyway, just use a bank.

Would saving it in bank guarantee encryption and only read through the internal program itself?
Title: Re: How to write a code that make a new text file and store text into it?
Post by: SamuraiCrow on August 21, 2019, 02:22:30 AM
If you're using a map it's rare to need long integer precision for each entry in a map.  Using Deek and Doke will cut both the size and access time in half on a 16-bit Amiga.  I don't know of an encryption extension for banks or arrays but I can't imagine it being much more complex than an unpacker

Edit:  AMCAF extension has both unpacker and simple bank encryption and decryption.
https://www.ultimateamiga.co.uk/HostedProjects/AMOSFactory/AMCAFguide/manual/bank.html#bankencode
Title: Re: How to write a code that make a new text file and store text into it?
Post by: xboxisfinished on August 22, 2019, 03:19:09 AM
If you're using a map it's rare to need long integer precision for each entry in a map.  Using Deek and Doke will cut both the size and access time in half on a 16-bit Amiga.  I don't know of an encryption extension for banks or arrays but I can't imagine it being much more complex than an unpacker

Edit:  AMCAF extension has both unpacker and simple bank encryption and decryption.
https://www.ultimateamiga.co.uk/HostedProjects/AMOSFactory/AMCAFguide/manual/bank.html#bankencode

Thank you so much!!! I will take this extension and add it into my pac man and it's construction set!!

Right now I am spending drawing all the necessary graphics I need for the game!  I also need to focus on the AMAL side..when I got all the AMAL programming finished I can start on the engine!
Title: Re: How to write a code that make a new text file and store text into it?
Post by: SamuraiCrow on August 22, 2019, 06:04:04 AM
You're welcome!  AMCAF is easily the most useful extension for AmosPro.