flat assembler
Message board for the users of flat assembler.
Index
> Main > Where to start? Goto page Previous 1, 2, 3, 4, 5, 6, 7 Next |
Author |
|
ProphetOfDoom 10 Apr 2012, 20:10
Hi there,
If I'm understanding you right, you're asking if you can fill an array (some consecutive values) with data, based on a pointer to the start of the array. If that's what you want, it would be something like this: Code: array rd 8 ; reserve 8 32-bit integers ... mov ebx, array ; ebx is address of first item (you could also use lea ebx, [array]) mov ecx, 8 ; ecx is number of items loop_start: push ecx call some_function ; some value is placed in eax pop ecx mov [ebx], eax ; mov eax into "what ebx points to" add ebx, 4 ; increase ebx by size of dword (so it points to next element) dec ecx ; decrease counter by 1 cmp ecx, 0 ; compare counter to 0 jnz loop_start ; if it's still non-zero, repeat I wrote that from memory, I don't have access to a 32-bit windows. Hopefully it'll work. |
|||
10 Apr 2012, 20:10 |
|
AsmGuru62 10 Apr 2012, 20:25
The question is why call it 20 times and put all the return values into array?
It will return the same value all 20 times, because you always pass -11. The better way to put these values is to use EDI register and STOSD instruction, because this instruction stores EAX at EDI and adds 4 to EDI at the same time. |
|||
10 Apr 2012, 20:25 |
|
Inagawa 10 Apr 2012, 20:28
Guru: You must've misunderstood the code. I get a new StdHandle each time I call it. -11 is a code for STD_OUTPUT_DEVICE.
I acquire an array of StdHandles and then set different colors for each of them. When I do it this way, I can actually have multiple colors in a console window. Yes, I see where you're coming from, but I barely got my feet wet and I can't really use stosd yet. Prophet: Actually, that's exactly it! It just got me confused for a little while. Thanks a lot |
|||
10 Apr 2012, 20:28 |
|
revolution 10 Apr 2012, 21:16
Inagawa wrote:
|
|||
10 Apr 2012, 21:16 |
|
Inagawa 10 Apr 2012, 21:23
You've caught me with my pants down I'll go fix it
Code: ;=== ACQUIRE THE WINDOW HANDLES ================ mov ecx, 20 ; Init the counter with 20 mov ebx, _textModeBuffer .GetHandles: ; Get all the handles push ecx invoke GetStdHandle, -11 ; -11 for STD_OUTPUT_DEVICE mov [ebx], eax ; Store the handle into [EBX] add ebx, 4 ; Add 4 bytes pop ecx loop .GetHandles This should be okay, right? |
|||
10 Apr 2012, 21:23 |
|
AsmGuru62 10 Apr 2012, 22:17
It is good -- ECX is OK now.
You should use debugger to check your code. It is easy - try the following code: Code: invoke GetStdHandle, -11 mov edi, eax invoke GetStdHandle, -11 mov esi, eax invoke GetStdHandle, -11 mov edx, eax int3 ; ; At this point look in debugger at the registers: ESI, EDI, EDX, EAX. ; They all should contain the same value. ; Run this code. When debugger will stop at INT3 instruction -- look at the registers. |
|||
10 Apr 2012, 22:17 |
|
AsmGuru62 10 Apr 2012, 22:18
del
|
|||
10 Apr 2012, 22:18 |
|
Inagawa 11 Apr 2012, 07:39
Well, my reasoning was that I simply get a handle. I never really thought about what happens.
Code: ;=== ACQUIRE THE WINDOW HANDLES ================ mov edx, _textModeBuffer invoke GetStdHandle, -11 ; -11 for STD_OUTPUT_DEVICE mov ecx, 20 ; Init the counter with 20 .GetHandles: ; Get all the handles mov [edx], eax ; Store the handle into [EDX] add edx, 4 ; Add 4 bytes loop .GetHandles You are probably pointing out that it's totally useless to call GetStdHandle 20 times if I can simply copy eax into the buffer 20 times instead. Am I right? You are completely right, I just never thought of it that way. I'll go fix it now. By the way, am I doing the color stuff right? I experimented and this is the only way that I know of to have multiple colors. Is there by any chance a better way? |
|||
11 Apr 2012, 07:39 |
|
AsmGuru62 11 Apr 2012, 10:31
Well, you need only one handle to write to console.
Put it into a global variable and use it in all calls to API. I am not sure why do you need 20 handles. 1. invoke SetConsoleCursorPosition and set the X,Y for the text to be printed. 2. invoke SetConsoleTextAttribute and set the color for the text to be printed. 3. invoke WriteConsole and this will print the text on screen at the X,Y specified in step #1 and with color specified in step #2. For all these calls you just need one global variable holding the handle returned by GetStdHandle API. Make some more small functions to do all that. For example, if you need to write part of text with one color and then another part with different color - you do not need to set X,Y - you want to continue writing text at the same location where the previous text ended. I would written functions like: GotoXY - to set the coordinates PutText - to print text SetColor - to set the color Now, can you tell me what kind of a game you're planning? Is that a full screen game? Cool stuff btw. How do you plan to take input from the user? Do you type the text into some command panel? Do you use mouse to input the game controlling commands? |
|||
11 Apr 2012, 10:31 |
|
Picnic 11 Apr 2012, 10:47
Inagawa wrote: By the way, am I doing the color stuff right? I experimented and this is the only way that I know of to have multiple colors. Is there by any chance a better way? Hi Inagawa, You need only one global handle like AsmGuru62 wrote. One method is the following. Code: format PE CONSOLE 4.0 include "win32axp.inc" .data macro enum [arg] { common count = 0 forward arg = count count = count+1 } enum BLACK, BLUE, GREEN, CYAN, RED, PURPLE, YELLOW,\ SYSTEM, GRAY, BRIGHTBLUE, BRIGHTGREEN, BRIGHTCYAN,\ BRIGHTRED, BRIGHTPURPLE, BRIGHTYELLOW, WHITE hOut dd ? dwTemp dd ? .code main: invoke GetStdHandle, STD_OUTPUT_HANDLE mov [hOut], eax stdcall setColor, BLUE, BRIGHTYELLOW ; print text stdcall setColor, RED, WHITE ; print text stdcall setColor, BLACK, SYSTEM ; print text invoke ExitProcess, 0 proc setColor uses ecx edx, BGColor, FGColor mov eax, [BGColor] shl eax, 4 or eax, [FGColor] invoke SetConsoleTextAttribute, [hOut], eax ret endp .end main There is a simple and clean example of a Win32 console application skeleton inside fresh. File->New application->Win32 console |
|||
11 Apr 2012, 10:47 |
|
AsmGuru62 11 Apr 2012, 14:35
Great stuff, Picnic!
I think macro is better to combine colors: Code: macro SetColor bkColor, txColor { pusha invoke SetConsoleTextAttribute, [glb_HOutput], (bkColor shl 4) or txColor popa } |
|||
11 Apr 2012, 14:35 |
|
Inagawa 11 Apr 2012, 16:01
I have incorporated all of the code you have posted here into my program (which I am completely rewriting for the third time, since until Picnic posted the code, I had no idea how useful procedures are!), except the macro, because I absolutely don't understand macros, so I didn't want to complicate the code.
But guys, I am so thankful for the help, with these snippets of code you've helped me tremendously, I've learned lots of things from them. I am now able to print colors with one handle, just as you've shown me - excellent. To Guru Quote: Now, can you tell me what kind of a game you're planning? I have no idea what kind of a game. I need to be able to print actual graphics instead of the ASCII characters into the console. Also, the console seems to be limited in width, that is very bad and limiting. Maybe the graphics mode doesn't have that? I tried to use it, but the only way I found is via interrupts and that crashed the program. Quote: Is that a full screen game? Cool stuff btw. Depends.. I have no idea how console behaves in fullscreen and how does it cope with the width limit of 79. And thanks Quote: How do you plan to take input from the user? Same as before. If I have the graphics mode, I'll make it mouse and shortcuts controlled. Quote: Do you type the text into some command panel? What do you mean? If the player inputs his decisions into a "terminal"? Well that was the original thought. I beg you to help me with the graphics mode, guys.. If you could check on youtube the game "Dwarf Fortress" (Link), is it made with console and graphics mode? Or rather, could I make a game like that in console's graphics mode? I've never seen how it looks, so I have no idea what to expect. (Or maybe it would be easier to just use OpenGL?) |
|||
11 Apr 2012, 16:01 |
|
AsmGuru62 11 Apr 2012, 18:31
Ah... I see... the console is for text characters only.
To do what you want (???-CRAFT type of game) -- you'll need to create a full blown Windows GUI application and that will allow for some sprites and graphics to be painted. Wow, that is like 25 times more to learn than in console mode. I'll advise to read some Windows API tutorials first - if you never coded for Windows (I presume you never did). You know, if I have some time -- I could write you a small sample of what I think you're trying to do. |
|||
11 Apr 2012, 18:31 |
|
Inagawa 11 Apr 2012, 19:05
Ouch, 25 times more painful than so far doesn't sound good. If you could write me a sample I'd be
glad, but I don't think I will be able to really use it to create anything at my current skill level. So if you think I won't be able to use it, please don't bother with it. It's just that coding for console is really just to learn something and the fact that you can't really make a game is kinda demotivating. Well a game sure, but certainly not a game that I'd like to work on for the next couple of years as I learn assembly. |
|||
11 Apr 2012, 19:05 |
|
AsmGuru62 11 Apr 2012, 20:38
I have a good coding style.
|
|||
11 Apr 2012, 20:38 |
|
mindcooler 12 Apr 2012, 14:56
Here is an example of how to get console input if still interested in doing console:
http://files.sys5.se/huvaligen.zip _________________ This is a block of text that can be added to posts you make. |
|||
12 Apr 2012, 14:56 |
|
Inagawa 12 Apr 2012, 16:41
Of course I am still interested, only a little discouraged. Thanks a lot, I will look into it ASAP.
|
|||
12 Apr 2012, 16:41 |
|
AsmGuru62 12 Apr 2012, 17:47
So, how exactly you can add graphics elements into a console?
|
|||
12 Apr 2012, 17:47 |
|
Inagawa 12 Apr 2012, 18:31
If you are asking me, this is the Thread that even gave me the idea that it can be done. I am not able to make it work, though.
|
|||
12 Apr 2012, 18:31 |
|
Goto page Previous 1, 2, 3, 4, 5, 6, 7 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.