How to write a code that make a new text file and store text into it?

Started by xboxisfinished, June 06, 2019, 06:11:36 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

xboxisfinished

   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? :)


Hungry Horace

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
Quote from: KillerGorillabecause winuae is made of code and your amiga is made of stuff


Hungry Horace's Artwork Available
Buy my work

http://twitter.com/horaceandspider

Lonewolf10

Quote from: 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.

' 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.

SamuraiCrow

Isn't there a Poke$ command that will replace the loop in your save routine?

Volvo_0ne

_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?
Transuranic heavy elements may not be used where there is life.

Hungry Horace

Quote from: 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?



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
Quote from: KillerGorillabecause winuae is made of code and your amiga is made of stuff


Hungry Horace's Artwork Available
Buy my work

http://twitter.com/horaceandspider

Hungry Horace

just a quick anecdote, that i tried using POKE$ today and it immediately crashed my system... grr...
Quote from: KillerGorillabecause winuae is made of code and your amiga is made of stuff


Hungry Horace's Artwork Available
Buy my work

http://twitter.com/horaceandspider