Ultimate Amiga

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

Title: How to write a code that make a new text file and store text into it?
Post by: xboxisfinished on 06 Jun, 2019, 07:11 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 08 Jun, 2019, 11:25 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.

' 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 09 Jun, 2019, 02:49 PM
Quote from: Hungry Horace on 08 Jun, 2019, 11:25 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.

' 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 09 Jun, 2019, 10:07 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 10 Jun, 2019, 08: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 27 Jun, 2019, 10:36 PM
Quote from: Volvo_0ne on 10 Jun, 2019, 08: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?


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 01 Jul, 2019, 10:31 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 21 Jul, 2019, 03:10 PM
Quote from: Hungry Horace on 01 Jul, 2019, 10:31 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 21 Jul, 2019, 09:47 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 10 Aug, 2019, 04:35 PM
Quote from: Hungry Horace on 21 Jul, 2019, 09:47 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 20 Aug, 2019, 07:58 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 21 Aug, 2019, 01:02 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 21 Aug, 2019, 02:38 AM
Quote from: SamuraiCrow on 21 Aug, 2019, 01:02 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 21 Aug, 2019, 03:22 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 22 Aug, 2019, 04:19 AM
Quote from: SamuraiCrow on 21 Aug, 2019, 03:22 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 22 Aug, 2019, 07:04 AM
You're welcome!  AMCAF is easily the most useful extension for AmosPro.