Ultimate Amiga

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2   Go Down

Author Topic: How to write a code that make a new text file and store text into it?  (Read 11184 times)

0 Members and 1 Guest are viewing this topic.

xboxisfinished

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 205
  • Generic Amiga User
    • gamemakermagazine.com

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

Logged

Hungry Horace

  • Amorphous Blue-Blob Man
  • Site Admin
  • A4000T
  • ******
  • Karma: 307
  • Offline Offline
  • Gender: Male
  • Posts: 3,364
  • Don't forget... Ameboid's need love too!
    • AUW

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

Lonewolf10

  • AMOS Extensions Developer
  • AMOS Dev
  • A2000
  • *****
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 618
    • http://www.aliensrcooluk.com

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

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo

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

Volvo_0ne

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 71
  • A1200 lover

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

Hungry Horace

  • Amorphous Blue-Blob Man
  • Site Admin
  • A4000T
  • ******
  • Karma: 307
  • Offline Offline
  • Gender: Male
  • Posts: 3,364
  • Don't forget... Ameboid's need love too!
    • AUW

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

Hungry Horace

  • Amorphous Blue-Blob Man
  • Site Admin
  • A4000T
  • ******
  • Karma: 307
  • Offline Offline
  • Gender: Male
  • Posts: 3,364
  • Don't forget... Ameboid's need love too!
    • AUW

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

Lonewolf10

  • AMOS Extensions Developer
  • AMOS Dev
  • A2000
  • *****
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 618
    • http://www.aliensrcooluk.com

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 ;)
Logged

Hungry Horace

  • Amorphous Blue-Blob Man
  • Site Admin
  • A4000T
  • ******
  • Karma: 307
  • Offline Offline
  • Gender: Male
  • Posts: 3,364
  • Don't forget... Ameboid's need love too!
    • AUW

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

Lonewolf10

  • AMOS Extensions Developer
  • AMOS Dev
  • A2000
  • *****
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 618
    • http://www.aliensrcooluk.com
Re: How to write a code that make a new text file and store text into it?
« Reply #9 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!  ;)
Logged

xboxisfinished

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 205
  • Generic Amiga User
    • gamemakermagazine.com
Re: How to write a code that make a new text file and store text into it?
« Reply #10 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?
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: How to write a code that make a new text file and store text into it?
« Reply #11 on: August 21, 2019, 12:02:37 AM »

If you're going to peek and poke it anyway, just use a bank.
Logged

xboxisfinished

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 205
  • Generic Amiga User
    • gamemakermagazine.com
Re: How to write a code that make a new text file and store text into it?
« Reply #12 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?
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: How to write a code that make a new text file and store text into it?
« Reply #13 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
« Last Edit: August 21, 2019, 06:10:40 PM by SamuraiCrow »
Logged

xboxisfinished

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 205
  • Generic Amiga User
    • gamemakermagazine.com
Re: How to write a code that make a new text file and store text into it?
« Reply #14 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!
Logged
Pages: [1] 2   Go Up
 

TinyPortal 2.2.2 © 2005-2022