![]() |
Forum Index : Microcontroller and PC projects : Cmm2 How do I read a binary file to get data?
Author | Message | ||||
berighteous Senior Member ![]() Joined: 18/07/2020 Location: United StatesPosts: 110 |
Hi! I just got my CMM2 a few days ago and I'm having fun playing with it. I'm starting with porting over a game I did for the pc vga 320x200x256 in 1996. I have all the artwork in binary data files, each byte a color value 0-ff from the clut for a pixel for a sprite. For example one of the files starts with 30 animation frames of a 29x27 pixel asteroid, followed by 24 frames of the ship rotating with and without thrusters, etc. couple hundred images worth of pixel color data. I figure I can load the pixel data one by one and pixel them in the correct order on a non visible screen and then cut them and blit them as I need them. How do I read in the bytes and convert them to color values to pixel? Converting the data files to text numbers with line feeds to INPUT #1,c say works and I can display the correct colors with pixel j,i,map(c) works, but makes the data file 2-3 x it's original size. And it's extra effort massaging all the data files. How can I read the hex data directly and use it? I saw someone mention str2bin but I don't understand how it works. I need to read the data a byte at a time. (unless there's a better way to do it) can someone explain the process? Thanks |
||||
berighteous Senior Member ![]() Joined: 18/07/2020 Location: United StatesPosts: 110 |
![]() here's what it looks like doing it the hard way. Here's the code. The colored line at the bottom is the 8 bit palette. mode 3,8 'load bmp "bkgr1.bmp" open "palette.dat" for input as #2 for i = 0 to 255 input #2,r,g,b map(i)=rgb(r,g,b) next i close #2 map set for i = 0 to 255 pixel i,150,map(i) next open "newstuff.dat" for input as #1 for k = 0 to 10 for i = 0 to 26 for j = 0 to 28 input #1,c pixel 30*k+j,i,map(c) next j:next i:pause 100 :next k Edited 2020-08-09 07:56 by berighteous |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
From the manual To get the binary values, start by reading the file one 'character' at a time and convert it to binary with c$ = INPUT$(1,#1) p = asc(c$) Jim VK7JH MMedit |
||||
berighteous Senior Member ![]() Joined: 18/07/2020 Location: United StatesPosts: 110 |
Thanks. I didn't understand why i couldn't just read in the data as numbers. Reading ascii and converting to numbers seems really weird to me. I knew there'd be a simple solution. I'm trying to go through the manuals but the old grey matter she ain't what she used to be! Here's a video of the PC game https://www.youtube.com/watch?v=hJMQlca0DxM Edited 2020-08-09 08:13 by berighteous |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |