Author Topic: Trying to load an Atari disk image into memory  (Read 3495 times)

0 Members and 1 Guest are viewing this topic.

Offline rcamp48

  • Newbie
  • Posts: 62
    • View Profile
Trying to load an Atari disk image into memory
« on: January 19, 2022, 08:04:45 am »
Code: Text: [Select]
  1.  

Hi: I am trying to load a headerless binary file into memory (92160 K) , then preattach a header to it, basically load inn an xfs file as binary then write it back out as binary as an atr file.
The code I am using in the above section does not work. All I get is spaces.

Russ
Russ Campbell
rcamp48@rogers.com
BBS Files Programmer

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Trying to load an Atari disk image into memory
« Reply #1 on: January 19, 2022, 09:06:09 am »
Open "KWEST01B.XFD" For Binary As #1
Get #1, , temp$ 'get the whole array

The problem is with the above -- temp$ is a blank 0 byte string of "" by default, so you're getting 0 bytes from your file.

Open "KWEST01B.XFD" For Binary As #1
temp$ = SPACE$(LOF(1)) 'set temp$ to be the size of the file, if you want to get the whole thing at once.
Get #1, , temp$ 'get the whole array
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Trying to load an Atari disk image into memory
« Reply #2 on: January 19, 2022, 10:54:48 am »
Just what do you have myarray() DIMed as anyhow?
why not just GET #1,, myarray()?
If you know the file size anyway?(and even if you don't you still could)

Code: QB64: [Select]
  1. DIM myarray(92176) AS STRING '(or myarray as string *92176, or myarray(lof(1)) as string [after the OPEN] or even myarray(lof(1)) as _UNSIGNED _BYTE)
  2. OPEN "KWEST01B.XFD" FOR BINARY AS #1
  3. GET #1, , myarray()
  4.  

PS, just out of curiosity, do you realize just how big "myarray(1 To 92176) As String * 92176" that array is? 8,496,414,976 bytes!!!
do you really need 8gigs+ to load it?
« Last Edit: January 19, 2022, 11:00:33 am by Cobalt »
Granted after becoming radioactive I only have a half-life!

Offline tomxp411

  • Newbie
  • Posts: 28
    • View Profile
Re: Trying to load an Atari disk image into memory
« Reply #3 on: January 22, 2022, 02:50:46 am »
Ok, let's start with: you don't need TEMP$ or the array. You definitely do not want an array of string*92126 objects. That gives you 92126*92126 characters, which is over 8GB.

You should be able to load data straight into a string*, like this:

Code: QB64: [Select]
  1. Dim DiskData As String * 92176
  2.  
  3. Open "KWEST01B.XFD" For Binary As #1
  4. Get #1, , DiskData 'get the whole array
  5.  
  6. dim Header as string * 32
  7. Header = "96028016800000000000000000000000"
  8.  
  9. Open "KWEST01B.ATR" For Binary As #1
  10. PUT #1, Header
  11. PUT #1, DiskData
  12.  
  13.  

Offline tomxp411

  • Newbie
  • Posts: 28
    • View Profile
Re: Trying to load an Atari disk image into memory
« Reply #4 on: January 22, 2022, 03:10:19 am »
Here is a complete example that loads the 92K image, adds the header, and writes back the ATR file with the header.

Code: QB64: [Select]
  1. DefLng A-Z
  2. Const IMG_LEN = 92176
  3.  
  4. ''Create test data
  5. 'Dim b As _Byte
  6. 'b = 0
  7. 'Open "KWEST01B.XFD" For Binary As #1
  8. 'For i = 1 To IMG_LEN
  9. '    Put #1, , b
  10. '    b = b + 1
  11. 'Next
  12. 'Close 1
  13. 'Print "File saved"
  14. 'End
  15.  
  16. Dim DiskData As String * IMG_LEN
  17.  
  18. Open "KWEST01B.XFD" For Binary As #1
  19. Get #1, , DiskData 'get the whole array
  20.  
  21. Dim Header As String * 32
  22. Header = "96028016800000000000000000000000"
  23.  
  24. Open "KWEST01B.ATR" For Binary As #1
  25. Put #1, , Header
  26. Put #1, , DiskData
  27.