Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:29 25 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Inputting data from a file byte by byte

Author Message
mookster1
Regular Member

Joined: 10/06/2011
Location: New Zealand
Posts: 81
Posted: 08:47pm 19 Jan 2012
Copy link to clipboard 
Print this post

I was wishing to write a Z-machine interpreter for the Maximite so I can play text adventures written by Infocom (e.g. The Hitchhiker's Game, the game of the infamous Hitchhikers' Guide to the Galaxy.) However Z-code files frequently have lines of longer than 255 characters, and I was wondering if you can load a file into memory byte-by-byte, as opposed to using the likes of LINE INPUT #number, stuff$. Here's a link that has a bit of information about the Z-machine (it's basically a code interpreter and Infocom wrote their software to conform to this format so if you wanted to port the code to another platform you just had to write an interpreter for the platform): http://en.wikipedia.org/wiki/Z-machine

There's links on that page detailing the specifics of the format too.
Capacitance is futile - roll on 2012!
 
Olimex
Senior Member

Joined: 02/10/2011
Location: Bulgaria
Posts: 226
Posted: 08:57pm 19 Jan 2012
Copy link to clipboard 
Print this post

c$ = INPUT$(1,#number)
 
mookster1
Regular Member

Joined: 10/06/2011
Location: New Zealand
Posts: 81
Posted: 11:55pm 19 Jan 2012
Copy link to clipboard 
Print this post

Thanks Olimex I take it the 1 in the statement INPUT$(1,#number) is the byte position in the file? (sorry about the probably stupid question)
Capacitance is futile - roll on 2012!
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1425
Posted: 12:44am 20 Jan 2012
Copy link to clipboard 
Print this post

1 is one byte.

c$ = INPUT$( 10, #number )

would read 10 bytes.

Each read reads the next byte (or 10 bytes) in the file.Edited by CircuitGizmos 2012-01-21
Micromites and Maximites! - Beginning Maximite
 
mookster1
Regular Member

Joined: 10/06/2011
Location: New Zealand
Posts: 81
Posted: 12:48am 22 Jan 2012
Copy link to clipboard 
Print this post

Is there any way of specifying the location in the file to read from? A method I'm using at the moment is to have a loop with the INPUT$ statement in it, and that loops x times. When that loop ends the byte(s) are read, then the file is closed, ready for re-opening and INPUT$ing from byte 1 again.
Capacitance is futile - roll on 2012!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 02:24am 22 Jan 2012
Copy link to clipboard 
Print this post

MM Basic doesn't have a RANDOM file mode but you can get to a file position fairly quickly:

'read and discard the unwanted bytes (must be 255 or less each read)
for n = 1 to 5
c$ = INPUT$(200,#number)
next n
c$ = INPUT$(1,#number) ' this gets the 200 * 5 + 1 = 1001st byte


Jim
VK7JH
MMedit   MMBasic Help
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024