News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Dont Thread The BOX!

Started by StatusQuo, December 07, 2011, 05:45:04 PM

Previous topic - Next topic

anunitu

This does sound VERY old school DOS stuff..Working in dos you learn about screen memory where your text or graphic is simply sent to screen memory and using Int to set the coordinates for where it should appear. I am supprised that your "Teacher" would set this type of task in a modern assembler system like windows. As you mentioned he seems prejudiced. It might actully be your race he dosen't have a problem with,but your ability. I have run across this long ago while taking classes. If you seem smarter than the teacher,you threaten their position or something. One teacher hated when I asked questions he couldn't answer.

A really GOOD teacher would not be bothered by a student that exceeded his or the other students,he would encourge the extra effort.

StatusQuo

Great alternative but one problem, he is a GOOD F'en teacher, you would be surpised to see how many students come out of his class, and he has been around for years. Still stuck on those Black Screen/Green Text DOS days back in the mid-80's. The way I see it, I will just do his work as I have been doing, and then in the VERY end, have a talk with him and the dean of displines. Yet the thing is I DONT want to to bite more than I can chew. For now my grade is in his hands, and unfortuntely, one day of a lesson about his time and how Aseembly came to be, is truly intellectually entertaintaining. I guess thats why the school kept him there all these years, despite his belief, the man can tell you bit by bit how a simple "Hello World" program works, but refuses to tel you how you can write Hello World in a blink of an eye, and tells you to stick the old age of programming. :(
Then God sad, "In the beginning....There was SCOPE!", Then I asked, "What is Scope?", and God said...."A Stack Frame, geeze I forgot to include you with common sense, BUT a prototype you are, too wierd to live, to rare to die...", and it was written....

baltoro

Well,...I suppose the suffering will eventually make you a great programmer.
Baltoro

StatusQuo

That is another way i looked at it actually. I find it humorous when a professor gives me two extra credit assignments that have to be done in Java, when the college doesnt teach Java, they have C++, but i came in knowing java, and just to see his facial expressions seems brightful vengence to me. Then an assignment that is of Assembly level 230, which he thought I would look past it, have done and see that slight grin....brightful Vengence.  :U
Then God sad, "In the beginning....There was SCOPE!", Then I asked, "What is Scope?", and God said...."A Stack Frame, geeze I forgot to include you with common sense, BUT a prototype you are, too wierd to live, to rare to die...", and it was written....

dedndave

well - it is good to know how things work underneath the hood
for example - macros are very handy time savers, but isolate you from the underlying code
it's great to use them, but it's better to understand what they do and how they do it

anunitu

Dave, being a hardware guy can tell you about doing things right down to the bare metal..I tend to be very informed about hardware as well,and like to tinker with my box. In assembler it does help to know your chip level stuff. In fact a lot of assembler classes are discribed as knowing your hardware it seems.

dedndave

i know what you mean
i have read so many IC data sheets, i feel like a walking library - lol
i used to have many of the pinouts memorized
probably forgotten most of them, now

anunitu

Somewhere on my drive I have a really good CHM that lists most all connector and other data with a graffic pic of the pinouts. It is a free file. If I can find it I will upload it. its a great referance.

dedndave

i used to keep those kinds of things under a piece of glass on my desk - lol
i quit doing that - not sure why, really
i could put instructions, timings, and API functions (etc) there   :P

baltoro

Baltoro

StatusQuo

Okay guys i actually went into the old IRVINE Book, and worked on this program using the masm32 at my house, I forgot that the computers at my school are still on Irvine32.inc, so I have written this program through scratch using what I have seen in the old "Assembly Language For Intel Based Computers, Fourth Edition" color cream book. The horror, I know. So this what I have so far, and I need to seriously down grade this program, into a more basic routine for "he doesnt agree with Masm32" and  he gives me this last minute change to my program, now I have to give him this one and another one where I have to have the cursor, within the box, being able to type as processor, another pain but I will do it, luckly for Dave's and etc's advice i have now a more broaden idea. I honestly dont know how low i have to go with his program, because my brain cant downgrade this anymore than it is, I got this info STRAIT from his stupid Assembly Book, and I really am starting to hate the old Irvine32.Inc rule he gives me. Please correct me if any of the comments I made are wrong, for the Irvine book has many mistakes. Here is my code, excuse the small comments, for they are to him.


TITLE      TESTDRIVE3

include\masm32\include\masm32rt.inc

FORMAT            PROTO   :DWORD
MAKEWIN            PROTO   :DWORD, :DWORD

Rows            EQU 25
Colums            EQU 80
XLength            EQU Rows*Colums*4 ;**string length charachter** Incase someone asks because you wont remember it.

.DATA
BTitle            DB   "[]This Is A Little Blue Box, Filled With Yellow Lies[]",0
InputB            DWORD 1

;Positioning, directly
UpperRow         DB 218
RightCol         DB 191
LowerRow         DB 192
LeftCol            DB 217
Horizontal         DB 196
Vertical         DB 179

.Data? ; Declare my unitialized Data (Irivine pg568)
ConsoleScreen      CHAR_INFO 2000 DUP (<>) ; Declaring a structured variable, my default field, pg 335
Curs            CONSOLE_CURSOR_INFO <> ;pg 402 the information of the cursor's size and visibility.
Handler1         HANDLE ? ;pg 339, toogles Screen Buffer, could be wrong.
Handler2          HANDLE ?

WinSize            SMALL_RECT<>   ;pg390
BufSize            COORD <>
Starter            COORD <> ; Finding X, Y in the DOS field.   

Manyof            DD ?
Buffer            INPUT_RECORD <> ;pg 346, console input functions.


.CODE
speedracer:
WINSIZE            PROC
               INVOKE   SetConsoleTitle, ADDR BTitle ;pg386. Setting the title bar string.
               CALL   HideTheCursor ;****
               INVOKE   SetConsoleWindowInfo, Handler1, TRUE, ADDR WinSize
               INVOKE   SetConsoleScreenBufferSize, Handler1, DWORD PTR BufSize
               RET
WINSIZE            ENDP

PUTCHAR            PROC
               CALL   SetBufferColor
               INVOKE   MAKEWIN, 1, 3
               INVOKE   MAKEWIN, 4, 25
               RET
PUTCHAR            ENDP

; Fill the buffer with a box of 80 characters
; till the number of line passed as II parameter.
;My 3:45AM Buzz Kill.

MAKEWIN            PROC Row1:DWORD, Row2:DWORD
               MOV      EAX, Row1
               SUB      EAX, 1
               IMUL   EAX, 320 ;pg627 perform a signed integer multiplication.
               MOV      EDX, EAX
               LEA      EAX, ConsoleScreen ;pg631 calculate and load the memory address. 
               ADD      EAX, EDX
               
               MOVZX   EBX, BYTE PTR[UpperRow]
               MOV      BYTE PTR [EAX], BL
               ADD      EAX, 4
               MOV      ECX, 78
               
               MOVZX   EBX, BYTE PTR [Horizontal]
               MOV      BL, Horizontal
Filler1:
               MOV      BYTE PTR[EAX], BL
               ADD      EAX, 4
               DEC      ECX
               JNZ      Filler1
               
               MOVZX   EBX, BYTE PTR [RightCol}
               MOV      BYTE PTR [EAX], BL
               ADD      EAX, 4
               
               MOV      ECX, Row2
               SUB      ECX, ROW1
               DEC    ECX
               MOVZX   EBX, BYTE PTR [Vertical]
BordFill:
               MOV      BYTE PTR [EAX], BL
               ADD      EAX, 4
               MOV      EDX, 4
               IMUL   EDX, 78
               ADD      EAX, EDX
               MOV      BYTE PTR[EAX], BL
               ADD      EAX, 4
               DEC      ECX
               JNZ      BorderFill
               
               MOVZX   EBX, BYTE PTR [LowerRow]
               MOV      BYTE PTR [EAX], BL
               ADD      EAX, 4
               MOV      ECX, 78
               MOVZX   EBX, BYTE PTR [Horizontal]
               
Filler2:
               MOV      BYTE PTR [EAX], BL
               ADD      EAX, 4
               DEC      ECX
               JNZ      Filler2
               
               MOVZX   EBX, BYTE PTR [LeftCol]
               MOV      BYTE PTR [EAX], BL
               RET
MAKEWIN            ENDP

;Coloring Time XD
SetBufferColor      PROC
               PUSH   EDI
               MOV      EDI, OFFSET ConsoleScreen
               MOV      EAX, 201E2020H
               MOV      ECX, 2000
               REP      STOSD ; repeats what is stored in EAX.
               POP      EDI
               RET
SetBufferColor      ENDP

CURPOS            PROC
               INVOKE   GetConsoleCursorInfo, Handler1, ADDR Curs
               MOV      Curs.bVisible, TRUE
               INVOKE   SetConsoleCursorInfo, Handle1, ADDR Curs
               RET
CURPOS            ENDP

;*****
HideTheCursor      PROC
               INVOKE   GetConsoleCursorInfo, Handler1, ADDR curs
               MOV      curs.bVisible, FALSE
               INVOKE   SetConsoleCursorInfo, Handler1, ADDR curs
               RET
HidTheCursor      ENDP

InitProc         PROC
               INVOKE   GetStdHandle, STD_INPUT_HANDLE; pg383 return my handle back into EAX, the safekeeper.
               MOV      Handler2, EAX
               INVOKE   GetStdHandle, STD_OUTPUT_HANDLE
               MOV      Handler1, EAX
               
               MOV      windowSize.Left, 0
               MOV      windowSize.Right, 79
               MOV      windowSize.Top, 0
               MOV      windowSize.Bottom, 24
               
               MOV      BufSize.X, 80
               MOV      BufSize.Y, 25
               
               MOV      Starter.X, 0
               MOV      Starter.Y, 0
               RET
InitProc         ENDP

FORMAT            PROC    szFmtName:DWORD
               INVOKE   WriteConsoleOutput, Handler1, szFmtName, DWORD PTR BufSize,
                     DWORD PTR Starter, OFFSET WINSIZE
               RET
FORMAT            ENDP

;Returning the key code in buffer.KeyEvent.wVirtualKeyCode WORD size
AnyKey            PROC
Looper:
               INVOKE   ReadConsoleInput, Handler2, OFFSET Buffer, 1, OFFSET Manyof
               CMP      Buffer.EventType, KEY_EVENT
               JNZ      Looper
               
               CMP      Buffer.KeyEvent.bKeyDown, 0
               JZ      Looper
               RET
AnyKey            ENDP

MAIN            PROC
               CALL   InitProc
               CALL   WINSIZE
               CALL   WINDESC
               INVOKE   FORMAT, offset ConsoleScreen
               CALL   AnyKey
               CALL   CURPOS
RacerX:
               INVOKE ExitProcess, 0 ;MS terminates program pg159
               RET
MAIN            ENDP               
END               speedracer
Then God sad, "In the beginning....There was SCOPE!", Then I asked, "What is Scope?", and God said...."A Stack Frame, geeze I forgot to include you with common sense, BUT a prototype you are, too wierd to live, to rare to die...", and it was written....

dedndave

first of all, you can keep your posted text formatted by using code tags
highlight all the code text, then click on the # icon above the Reply window
this will add code tags and keep things lined up

we need to see the entire program - i think there are some routines missing

however, you do not have to post it all in the Reply window
you can attach ZIP files to the Reply by clicking on the Advanced Options link under the Reply window
zip the complete project and attach it   :U

EDIT - my mistake - it looks complete   :P

dedndave

one thing that should not work....
END               speedracer

the END directive should reference the entry point for EXE source files
        END     MAIN

dedndave

here is what i would suggest as far as "breaking the code down to a more basic level"
the instructor wants to see that you understand the concept of passing function parameters on the stack

so - every place you have an INVOKE, simply replace the line with the appopriate PUSH/CALL sequence

for example, replace....
        INVOKE  WriteConsoleOutput, Handler1, szFmtName, DWORD PTR BufSize,
                DWORD PTR Starter, OFFSET WINSIZE


with this....
;may be written as: INVOKE  WriteConsoleOutput, Handler1, szFmtName, DWORD PTR BufSize,
;                           DWORD PTR Starter, OFFSET WINSIZE

        push    OFFSET WINSIZE
        push    DWORD PTR Starter
        push    DWORD PTR BufSize
        push    szFmtName
        push    Handler1
        CALL    WriteConsoleOutput

by adding the comment, the instructor sees that you understand the concept of PUSH/CALL
and he sees that you know what INVOKE does   :U

StatusQuo

Thanks for the info dave, i mean th code at the bottom.

MAIN            ENDP               
END               speedracer

Works well, i have written and tested it out throughly, and i made an EXE and it works the same. I am still trying to figure out how to attack a file into these forums. I ddi press that # key and just pasted my WHOLE code into it, so there is no other subroutines missing. This basically it, and it works on a MASM32 Computer. I am breaking it down like dave suggested, and thanks dave, i feel more stupid for not thinking of just Push/Call.  :U
Then God sad, "In the beginning....There was SCOPE!", Then I asked, "What is Scope?", and God said...."A Stack Frame, geeze I forgot to include you with common sense, BUT a prototype you are, too wierd to live, to rare to die...", and it was written....