8 Replies - 5257 Views - Last Post: 09 December 2012 - 04:09 PM

ASM x86, using Irvine32.inc, loading a file into a 2D array

Posted 09 December 2012 - 08:03 AM

I am building a maze game. I have been having trouble understanding how to get just two bytes out of a file and storing it into an array space, and loop the whole file, until the whole file is loaded. I have the array Maze initialized with values that do work. The idea is to be able to load different values, rather then leaving them hard coded. This will allow me to create more then one file and load new levels into the game.

I would need to be able to get two number from the file. Right now I am only get 1 number instead of the intend two that I am trying to get to from the file.
For example starting at the top of the file 35,35,35
Instead I am getting only 3,5,3,5

Replies To: ASM x86, using Irvine32.inc, loading a file into a 2D array

Re: ASM x86, using Irvine32.inc, loading a file into a 2D array

Posted 09 December 2012 - 09:52 AM

As you haven't posted the complete code, it is missing somethings for me to test. A few observations will have to do:

1. There is a big difference between call and jmp-call pushes the address of the next instruction onto the stack then jumps to the label and when the code at label is done, flow returns to the instruction after the call.jmp is just a goto, no return or anything, it just tells the cpu to execute the code at label and continue.

Re: ASM x86, using Irvine32.inc, loading a file into a 2D array

Posted 09 December 2012 - 11:35 AM

I had this working this way with the call WriteString
But I want to insert the alpha numeric value for the character
which should then put the this number in the array and work the same way I already had it setup in theory.

Re: ASM x86, using Irvine32.inc, loading a file into a 2D array

You need two copies of the data you load from your maze file. The first copy is to check for wall hits, valid moves, end of maze etc. The second copy is what you will update and write to screen.

You don't even need that Maze array in your data section, the file loads just fine with a few things commented out.

;TRYING TO LOAD THE VALUES FROM THE FILE INTO THE ARRAY HERE
;LoadFile:
; mov al, byte ptr [edi] ;get byte at current pointer
; mov byte ptr [edi], al ;move that decrypted byte back to our buffer at current pointer
; inc edi ;point to the next byte
;
; mov esi, OFFSET Maze
; mov eax, [esi] ;move the first spot in the array
; movzx eax, al ;Convert the byte to a 32 bit value
; add esi, 4 ;mov to the next byte in the array
; mov [esi], eax ;mov the value in the array
;loop LoadFile ;loop

Without this code, the maze seems to load from the file and display properly.

I don't have your code for key presses, but this is 2 ways of doing it.
You have a starting pos, and when a up/down key is pressed, you add/subtract the amount of chars in a row, inc/dec the counter for a left/right move... take this index and lookup that character in your first buffer.. if it is not a valid move, just loop back to get another key press, if it is a valid move, take that index, and write a mouse marker in your second buffer, and write that buffer to screen.

Do we really want to keep writing the whole buffer to the console each key press? This is fine for a small maze (it is even fast enough for a large maze) so the second way is to check for key press as above, keeping track of where th "mouse" is and use GotoXY and print a character to screen.