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 ZealandPosts: 81 |
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: BulgariaPosts: 226 |
c$ = INPUT$(1,#number) |
||||
mookster1 Regular Member Joined: 10/06/2011 Location: New ZealandPosts: 81 |
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 StatesPosts: 1425 |
1 is one byte. c$ = INPUT$( 10, #number ) would read 10 bytes. Each read reads the next byte (or 10 bytes) in the file. Micromites and Maximites! - Beginning Maximite |
||||
mookster1 Regular Member Joined: 10/06/2011 Location: New ZealandPosts: 81 |
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: AustraliaPosts: 6098 |
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 |