;==============================================================================
;       Test Department's WINDOWS 32 BIT x86 ASSEMBLY EXAMPLE's     510
;==============================================================================

;==============================================================================
; ==> Part 510 :
;------------------------------------------------------------------------------
;Matrix, an experience of a tolerance database memory ... and crazyness ...
;This is my poor and very dilettante try to program a synthetic intelligence.
;And isn't that bad enough; it's a ported program from my ATARI 8 Bit computer.
;Believe me, it's highly enhanced.
;Well, for a proper work you MUST (!) respect the rules.
;I know it's hard for Anarchist's like us.
;
;LEARNING :
;-----------
; 1. Only standard letters are allowed, no space, no other signs.
; 2. One question - One answer (!), minimum 3 letters, maximum 10 letters.
; 3. No problem to enter the same Question / Answer pair again.
; 4. You can not (!) delete a previous entry, because memory organization.
; 5. Input Example:
;                   tree    - plant      ; first entry
;                   tree    - plant      ; reEnter is OK
;                   grass   - plant      ; OK
;                   plant   - tree       ; Ok
;                   tree    - wood       ; this is wrong, tree - plant before
;                   highway - traffic    ; OK
;                   high    - mountain   ; Bad entry
;                   mercedes- automobile ; OK
;
; 6. Silly inputs like abcd - abfrt etc. will destroy the memory matrix !
;    highway-traffic / high-mountain (high in both questions, same location)
;    do not work proper and could destroy parts of the memory matrix.
;    Best results are avaible if your question words are maximum different !
;    The summary of 0 Bits in the matrix most used quadrant must be greater
;    than the 1 Bits.
; 7. You see it's a poor program, take a look into the file theory.txt.
; 8. Memory increase as long as you insert more Question / Answer pairs.
;    The drawback is that memory becomes more foggy for every pair you insert.
; 9. Please do not forget: One Question - One Answer !!!
;
;INQUIRY :
;----------
;You can ask every question, if the answer was learned before.
;Because this memory is tolerance, also tolerance results are avaible.
;Tolerance means that you can ask for "gkass" and the answer will be
;also "plant" or something simular !
;
;MENU :
;-------
;Clicking Matrix in the menu bar you can load and save the memory matrix.
;You can also RESET your baby, any memory is lost ...
;
;Ideas:
;-------
;Read the file theory.txt.
;Thinking about a 3D memory matrix which will be much more exact ...
;Perhaps it's possible to use more vectors and create a 3D memory matrix.
;Hm, yes with more (32) matrix layer's, bah forget it...
;
;Ou, I must go, my PC is talking to me ...

;==============================================================================
; Assembler directives
;------------------------------------------------------------------------------
.386                    ; specifies the processor our program want run on
.Model Flat ,StdCall    ; Flat for Win9x (32 Bit), Calling Convention
option casemap:none     ; case sensitive !

;==============================================================================
; Include all files where API functins resist you want use, set correct path
;------------------------------------------------------------------------------
include \masm32\include\windows.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\comdlg32.lib

;==============================================================================
; Declaration of used API functions,take a look into WIN32.HLP and *.inc files
;------------------------------------------------------------------------------
GetModuleHandleA        PROTO :DWORD
LoadIconA               PROTO :DWORD,:DWORD
LoadCursorA             PROTO :DWORD,:DWORD
CreateSolidBrush        PROTO :DWORD
RegisterClassExA        PROTO :DWORD
CreateWindowExA         PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,
                              :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
ShowWindow              PROTO :DWORD,:DWORD
UpdateWindow            PROTO :DWORD
GetMessageA             PROTO :DWORD,:DWORD,:DWORD,:DWORD
TranslateMessage        PROTO :DWORD
DispatchMessageA        PROTO :DWORD
PostQuitMessage         PROTO :DWORD
DefWindowProcA          PROTO :DWORD,:DWORD,:DWORD,:DWORD
ExitProcess             PROTO :DWORD
SetFocus                PROTO :DWORD
DrawEdge                PROTO :DWORD,:DWORD,:DWORD,:DWORD
FillRect                PROTO :DWORD,:DWORD,:DWORD
LoadBitmapA             PROTO :DWORD,:DWORD
SendMessageA            PROTO :DWORD,:DWORD,:DWORD,:DWORD
BeginPaint              PROTO :DWORD,:DWORD
CreateFontA             PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,
                              :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
SelectObject            PROTO :DWORD,:DWORD
SetBkColor              PROTO :DWORD,:DWORD
SetTextColor            PROTO :DWORD,:DWORD
TextOutA                PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
EndPaint                PROTO :DWORD,:DWORD
GetWindowTextA          PROTO :DWORD,:DWORD,:DWORD
SetWindowTextA          PROTO :DWORD,:DWORD
MessageBoxA             PROTO :DWORD,:DWORD,:DWORD,:DWORD

GetOpenFileNameA        PROTO :DWORD
GetSaveFileNameA        PROTO :DWORD
CreateFileA             PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
GetFileSize             PROTO :DWORD,:DWORD
ReadFile                PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
WriteFile               PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
CloseHandle             PROTO :DWORD

;==============================================================================
; .const    = the constants area starts here,constants are defined & fixed
;------------------------------------------------------------------------------
.const

;==============================================================================
; .Data     = the data area starts here, datas are defined but not fixed
;------------------------------------------------------------------------------
.Data
IconName                db "TDIcon",0           ;icon name in rc file
MenuName                db "TDMenu",0           ;menu name in rc file
Class                   db "TDWinClass",0       ;name of window class
Titel                   db "TDTitel",0          ;static titel bitmap in rc
WindowName              db "Test Department - http://surf.to/TestD",0       ;
BUTTON_Class            db "BUTTON",0           ;name of window class
STATIC_Class            db "STATIC",0           ;name of window class
EDIT_Class              db "EDIT",0             ;name of window class
FontName                db "Fixedsys",0         ;font name
MB1Titel                db ".......... INPUT ERROR ..........",0            ;
MB1Text                 db "1. only standard letters are allowed.",13,10    ;
                        db "2. no space, no other signs.",13,10             ;
                        db "3. input must contain 3-10 letters.",0          ;
MB2Titel                db ".......... RESET MATRIX ..........",0           ;
MB2Text                 db "Sure to reset the matrix, any memory is lost ?",0;
MB3Titel                db "........... I/O  ERROR ...........",0           ;
MB3Text                 db "Error while loading / saving the matrix.",0     ;
HelpTitel               db "Quick Help",0                                   ;
HelpText                db " Matrix, example of tolerance database memory. ";
                        db "-----------------------------------------------";
                        db "Learning:                                      ";
                        db " - Only standard letters are allowed.          ";
                        db " - Minimum 3 letters, maximum 10 letters.      ";
                        db " - One question - One answer !!!               ";
                        db " - It is no problem to enter the same          ";
                        db "   Question / Answer pair again.               ";
                        db " - Silly inputs like abcdv - abfrtj etc. will  ";
                        db "   destroy memory. Also:                       ";
                        db "   highway-traffic / high-mountain don't work. ";
                        db "   'high' in both pairs at the same location.  ";
                        db " - The best results are avaible if your        ";
                        db "   question words are maximum different.       ";
                        db " - Example:                                    ";
                        db "           tree     - plant      ;OK           ";
                        db "           tree     - plant      ;OK, reEnter  ";                        
                        db "           grass    - plant      ;OK           ";
                        db "           tree     - wood       ;ERROR        ";
                        db "           highway  - traffic    ;OK           ";
                        db "           high     - mountain   ;BAD entry    ";
                        db "           mercedes - automobile ;OK           ";
                        db " - Memory grows inserting Question / Answer    ";
                        db "   pairs. The drawback is that memory becomes  ";
                        db "   more foggy for every pair you insert.       ";
                        db "Inquiry:                                       ";
                        db " - You can ask any question if the answer was  ";
                        db "   learned before. Because memory is tolerance ";
                        db "   also tolerance results are avaible.         ";
                        db " - Tolerance means that you can ask for        ";
                        db "   'gkass' and the answer will be also         ";
                        db "   'plant' or something simular.               ";
                        db "Matrix:                                        ";
                        db " - Load, Save or Reset the Memory Matrix       ";
                                                
LearnTitel              db "Learning",0             ;
InquiryTitel            db "Inquiry",0              ;
Question                db "Question",0             ;
Answer                  db "Answer",0               ;
QMark                   db 2Eh                      ;
QuestionBuffer          db "0123456789",0           ;
AnswerBuffer            db "0123456789",0           ;
Intelligence            db "          ",0           ;answer we are waiting for
FileFilt                db "Matrix Files",0,"*.mat",0,0 ;file filter
FileDefExt              db "mat",0                      ;default file extension
LoadFileT               db "LOAD File, choose a file",0 ;titel
SaveFileT               db "SAVE File, choose a file",0 ;titel

; - ASCII Sign ( INDEX, hex values of ascii characters ) -
Sign_Index              db 61h,62h,63h,64h,65h,66h,67h,68h,69h,6Ah,6Bh,6Ch,6Dh
                        db 6Eh,6Fh,70h,71h,72h,73h,74h,75h,76h,77h,78h,79h,7Ah

; - ASCII Sign ( TABLE, coded ) -
Sign_A                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,31h  ;
Sign_B                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,31h,20h  ;
Sign_C                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,31h,20h,20h  ;
Sign_D                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,31h,20h,20h,20h  ;
Sign_E                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,31h,20h,20h,20h,20h  ;
Sign_F                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,31h,20h,20h,20h,20h,20h  ;
Sign_G                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,31h,20h,20h,20h,20h,20h,20h  ;
Sign_H                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 31h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_I                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,31h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_J                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,31h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_K                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,31h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_L                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,31h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_M                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,31h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_N                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,31h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_O                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,31h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_P                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 31h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_Q                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,31h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_R                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,31h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_S                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,31h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_T                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,31h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_U                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,31h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_V                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,31h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_W                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,31h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_X                  db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 31h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_Y                  db 20h,20h,20h,20h,20h,20h,20h,31h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
Sign_Z                  db 20h,20h,20h,20h,20h,20h,31h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;
                        db 20h,20h,20h,20h,20h,20h,20h,20h  ;

; - RECT Structure ( API=DrawEdge ) - Learning area
rcLearn_left            dd 160h         ;RECT,x-coordinate upper-left corner
rcLearn_top             dd 044h         ;RECT,y-coordinate upper-left corner
rcLearn_right           dd 272h         ;RECT,x-coordinate lower-right corner
rcLearn_bottom          dd 0A2h         ;RECT,y-coordinate lower-right corner

; - RECT Structure ( API=DrawEdge ) - Inquiry area
rcInquiry_left          dd 160h         ;RECT,x-coordinate upper-left corner
rcInquiry_top           dd 0ACh         ;RECT,y-coordinate upper-left corner
rcInquiry_right         dd 272h         ;RECT,x-coordinate lower-right corner
rcInquiry_bottom        dd 20Ah         ;RECT,y-coordinate lower-right corner

;==============================================================================
; .Data?    = the data? area starts here, not defined and not fixed
;------------------------------------------------------------------------------
.data?
blackbrush              dd ?            ;background color (black)
counter0                dd ?            ;
QALength                dd ?            ;
Level                   dd ?            ;level
temp                    dd ?            ;
temp_ycoordinate        dd ?            ;
temp_Result             dd ?            ;
tolerance               dd ?            ;tolerance level
Matrix_RAM              db 19000h dup(?);matrix ram, 320*320
Load_Buffer             db 19000h dup(?);temp load buffer
temp_Question           db 140h dup(?)  ;question mask, 320
temp_Answer             db 140h dup(?)  ;answer mask
temp_Column             db 280h dup(?)  ;column buffer
LoadFileN               db 104h dup(?)  ;buffer load filename
SaveFileN               db 104h dup(?)  ;buffer save filename

STATIC_HelphWnd         dd ?            ;handle, quick help window
STATIC_TitelhWnd        dd ?            ;handle, title graphic window
EDIT1_WorkhWnd          dd ?            ;learning question
EDIT2_WorkhWnd          dd ?            ;learning answer
BUTTON_LearnhWnd        dd ?            ;handle, learn button window
EDIT3_WorkhWnd          dd ?            ;inquiry question
BUTTON_InquiryhWnd      dd ?            ;handle, inquiry button window
STATIC_Inquiry0hWnd     dd ?            ;inquiry answerą0 window
STATIC_Inquiry1hWnd     dd ?            ;inquiry answer-1 window
STATIC_Inquiry2hWnd     dd ?            ;inquiry answer-2 window
STATIC_Inquiry3hWnd     dd ?            ;inquiry answer-3 window
STATIC_Inquiry4hWnd     dd ?            ;inquiry answer-4 window
STATIC_Inquiry5hWnd     dd ?            ;inquiry answer-5 window
STATIC_Inquiry6hWnd     dd ?            ;inquiry answer-6 window
STATIC_Inquiry7hWnd     dd ?            ;inquiry answer-7 window
BUTTON_LearnhObject     dd ?            ;handle, learn bitmap
BUTTON_InquiryhObject   dd ?            ;handle, inquiry bitmap
hFont                   dd ?            ;handle saved original font
FileHandle              dd ?            ;file handle for read/write file
FileReturn              dd ?            ;needed for read/write file
ErrorFlag               dd ?            ;

; - WndClassEx Structure ( API=RegisterClassExA ) -
cbSize                  dd ?            ;size in bytes of this structure
style                   dd ?            ;window style
lpfnWndProc             dd ?            ;address of user proc function
cbclsExtra              dd ?            ;extra bytes to allocate set to 0
cbWndExtra              dd ?            ;extra bytes class directive, rc file
hInstance               dd ?            ;program handle(API=GetModuleHandleA)
hIcon                   dd ?            ;handle of icon (API=LoadIconA)
hcursor                 dd ?            ;handle of cursor (API=LoadCursor)
hbrBackground           dd ?            ;background color, 0=transparent
lpszMenuName            dd ?            ;name of menu class in resource file
lpszClassName           dd ?            ;name of windows this window class
hIconSm                 dd ?            ;iconhandle 0=search in resource file
hdcDest                 dd ?            ;handle of dest. device context

; - Msg Structure ( API=GetMessageA ) - member POINT = POINT structure
hWnd                    dd ?            ;handle of window who receives message
message                 dd ?            ;the message number
wParam                  dd ?            ;extra info about the message
lParam                  dd ?            ;extra info about the message
time                    dd ?            ;time the message was posted
xpt                     dd ?            ;cursor x-position, POINT struc
ypt                     dd ?            ;cursor x-position, POINT struc

; - Push Parameter MAIN WINDOW CallBack procedure ( API=RegisterClassExA ) -
WP1_CallBack            dd ?            ;return address of calling routine
WP1_hWnd                dd ?            ;handle of window who receives message
WP1_uMsg                dd ?            ;the message number
WP1_wParam              dd ?            ;extra info about the message
WP1_lParam              dd ?            ;extra info about the message

; - Paint Structure ( API=BeginPaint ) - member rcPaint = RECT structure
hdc                     dd ?            ;id, display DC used for painting 
fErase                  dd ?            ;must background must be erased
rcPaint_left            dd ?            ;RECT,x-coordinate upper-left corner
rcPaint_top             dd ?            ;RECT,y-coordinate upper-left corner
rcPaint_right           dd ?            ;RECT,x-coordinate lower-right corner
rcPaint_bottom          dd ?            ;RECT,y-coordinate lower-right corner
fRestore                dd ?            ;reserved, used by Windows 
fIncUpdate              dd ?            ;reserved, used by Windows 
rgbReserved             db 20h dup (?)  ;reserved, used by Windows

; - OPENFILENAME Structure ( API=GetOpenFileNameA / GetOpenSaveFileNameA ) -
lStructSize             dd ?            ;the length in bytes of structure 
hWndOwner               dd ?            ;Id window that owns dialog box 
hInstance1              dd ?            ;handle, our program id
lpstrFilter             dd ?            ;pointer to string + filter
lpstrCustomFilter       dd ?            ;pointer to user defined filter
nMaxCustFilter          dd ?            ;size bytes/characters of above
nFilterIndex            dd ?            ;filter index of lpstrFilter 
lpstrFile               dd ?            ;pointer initialize filename, 0=no
nMaxFile                dd ?            ;size bytes/characters of above
lpstrFileTitle          dd ?            ;pointer title of the selected file
nMaxFileTitle           dd ?            ;size of the lpstrFileTitle buffer 
lpstrInitialDir         dd ?            ;pointer string init file dir,0=default
lpstrTitle              dd ?            ;pointer title of the box 
Flags                   dd ?            ;the dialog box creation flags 
nFileOffset             dw ?            ;offset filename in string lpstrFile 
nFileExtension          dw ?            ;offset extension in string lpstrFile 
lpstrDefExt             dd ?            ;pointer default extension of file 
lCustData               dd ?            ;? 
lpfnHook                dd ?            ;? used if flag is OFN_ENABLETEMPLATE
lpTemplateName          dd ?            ;? used if flag is OFN_ENABLETEMPLATE

;==============================================================================
; .CODE     = our code area starts here     Main = label of our program code
;------------------------------------------------------------------------------
.Code
Main:

;==============================================================================
; Always get your program ID first (API=GetModuleHandleA)
;------------------------------------------------------------------------------
push    0h                          ;lpModuleHandle, 0=get program handle
call    GetModuleHandleA            ;- API Function -
mov     hInstance,eax               ;return value in eax=handle of program

;==============================================================================
; Init the program variables.
;------------------------------------------------------------------------------
call    My_InitPrg                  ;- Subroutine -

;==============================================================================
; The API function "RegisterClassExA" registers a window class.
; This API needs a "WNDCLASSEX" structure so we fill it with correct values.
;------------------------------------------------------------------------------
mov     cbSize,30h                  ;size in bytes of WNDCLASSEX structure
mov     style,3h                    ;window style
mov     lpfnWndProc,OFFSET WP1      ;address of user lpfnWndProc function
mov     cbclsExtra,0h               ;extra bytes to allocate set to 0
mov     cbWndExtra,0h               ;class directive in rc file
;------------------------------------------------------------------------------
; API "CreateSolidBrush" creates a logical brush with the specified solid color
;------------------------------------------------------------------------------
push    00000000h                   ;crColor, brush color value
call    CreateSolidBrush            ;- API Function -
mov     hbrBackground,eax           ;background color
mov     blackbrush,eax              ;store brush for future use
mov     lpszMenuName,OFFSET MenuName;menu name in resource file,0=no menu
mov     lpszClassName,OFFSET Class  ;name of windows class
mov     hIconSm,0h                  ;iconhandle 0=search in rc file
;------------------------------------------------------------------------------
; API "LoadIconA" loads an icon defined in the resource file and stores the
; handle in the "WNDCLASSEX" structure
;------------------------------------------------------------------------------
push    OFFSET IconName             ;icon-string or icon resource id
push    hInstance                   ;our program handle
call    LoadIconA                   ;- API Function -
mov     hIcon,eax                   ;store handle of newly loaded icon
;------------------------------------------------------------------------------
; API "LoadCursorA" loads a default system cursor, in this case we must set
; hInstance to 0 and lpCursorName to a default system cursor value, here 32512
; Then we store the cursor handle in the "WNDCLASSEX" structure
;------------------------------------------------------------------------------
push    32512                       ;lpCursorName, default value in dezimal
push    0h                          ;hInstance, 0=default system cursor
call    LoadCursorA                 ;- API Function -
mov     hcursor,eax                 ;store handle of the cursor
;------------------------------------------------------------------------------
; Now, after filled the "WNDCLASSEX" structure we call API "RegisterClassEx"
;------------------------------------------------------------------------------
push    OFFSET cbSize               ;pointer to WNDCLASSEX structure
call    RegisterClassExA            ;- API Function -

;==============================================================================
; API "CreateWindowExA" creates an overlapped, pop-up, or child window with an
; extended style. The return value in EAX is the handle of the new window.
; This API sends a WM_CREATE message to the window procedure (WP1).
;------------------------------------------------------------------------------
push    0h                          ;lpParam, extra pointer data 0=no data
push    hInstance                   ;hInstance, handle of our program
push    0h                          ;hMenu, handle window menu 0=class menu
push    0h                          ;hWndParent, handle parent window 0=no
push    00000240h                   ;intnHeight, window height pixel
push    00000280h                   ;intnWidth, window width pixel
push    00000000h                   ;inty, vertical position window
push    00000040h                   ;intx, horizontal position window
push    04CA0000h                   ;dwStyle, look into WIN32.HLP
push    OFFSET WindowName           ;lpWindowName, pointer to window name
push    OFFSET Class                ;lpClassName, pointer to class name
push    300h                        ;dwExStyle, extra window style 0=no
call    CreateWindowExA             ;- API Function -
mov     hWnd,eax                    ;hwnd,return value=handle of window

;==============================================================================
; API "ShowWindow" function sets the specified window's show state. 
;------------------------------------------------------------------------------
push    1h                          ;nCmdShow, show state 1=SW_SHOWNORMAL
push    hWnd                        ;hwnd, handle of window
call    ShowWindow                  ;- API Function -

;==============================================================================
; API "UpdateWindow" updates the area of the specified window by sending a
; WM_PAINT message to the window if the window's update region is not empty.
;------------------------------------------------------------------------------
push    hWnd                        ;hwnd, handle of window
call    UpdateWindow                ;- API Function -

LoopGetMessage:
;==============================================================================
; API "GetMessageA" retrieves a message + places it in the specified structure.
;------------------------------------------------------------------------------
push    0h                          ;wMsgFilterMax, highest message value
push    0h                          ;wMsgFilterMin, lowest message value
push    0h                          ;hWnd, handle of window who gets msg.
push    OFFSET hWnd                 ;lpMsg, pointer to MSG structure
call    GetMessageA                 ;- API Function -
cmp     eax,0h                      ;check if return value=0 (exit)
je      ExitPrg                     ;if return value is 0 goto LABEL

;==============================================================================
; API "TranslateMessage" translates virtual-key messages in character messages
;------------------------------------------------------------------------------
push    OFFSET hWnd                 ;lpMSG, pointer to msg structure
call    TranslateMessage            ;- API Function - keyboard code

;==============================================================================
; API "DispatchMessageA" function dispatches a message to a window procedure.
;------------------------------------------------------------------------------
push    OFFSET hWnd                 ;lpMSG, pointer to msg structure
call    DispatchMessageA            ;- API Function -
jmp     LoopGetMessage              ;check for message again, goto LABEL

ExitPrg:
;==============================================================================
; Next we terminate our program (API=ExitProcess)
;------------------------------------------------------------------------------
push    hInstance                   ;push our programm handle to exit
call    ExitProcess                 ;- API Function -

;##############################################################################
; This is the Window Procedure lpfnWndProc (API=RegisterClassExA) for this
; registered window.
; The WindowProc function is an application-defined callback function that
; processes messages sent to a window. 
; Here our code for checking the receiving messages resist.
; First we POP all parameter given by Windows from the stack and store them in
; variables for future use.
; !!!!! Next we PUSH the WP1_CallBack return address back to the stack !!!!!
; !!! WP1_CallBack must be avaible on the stack in this window procedure !!!
; It is also a good idea to PUSHAD all register, because than we are free to
; use all register in this window procedure.
; Before we leave this subroutine we must POPAD them back. 
;------------------------------------------------------------------------------
WP1:
pop     WP1_CallBack                ;POP return address lpfnWndProc
pop     WP1_hWnd                    ;handle of window who receives message
pop     WP1_uMsg                    ;the message number
pop     WP1_wParam                  ;extra info about the message
pop     WP1_lParam                  ;extra info about the message
push    WP1_CallBack                ;PUSH return address lpfnWndProc !!!!!
pushad                              ;push all register to the stack

mov     eax,WP1_uMsg                ;move the message number to eax
;==============================================================================
; WM_CREATE (value=01h) message received ?
;------------------------------------------------------------------------------
WP1_uMsg_01h:
cmp     eax,1h                      ;check if WM_CREATE message recieved
jne     WP1_uMsg_02h                ;if not goto LABEL
call    My_WM_CREATE                ;- Subroutine - init all windows
call    My_SetFocus                 ;- Subroutine -
jmp     WP1_return                  ;

;==============================================================================
; WM_DESTROY (value=02h) message received ?
;------------------------------------------------------------------------------
WP1_uMsg_02h:
cmp     eax,2h                      ;check if value=2h (WM_DESTROY)
jne     WP1_uMsg_0Fh                ;if not 2h go to LABEL
;------------------------------------------------------------------------------
; API "PostQuitMessage" indicates to Windows a request to terminate
;------------------------------------------------------------------------------
popad                               ;pop all register back from stack
push    0h                          ;nExitCode, exit code=wParam
call    PostQuitMessage             ;- API Function -
xor     eax,eax                     ;set eax to 0 to exit our program
ret                                 ;return to lpfnWndProc

;==============================================================================
; WM_PAINT (value=0Fh) message, used to repaint the window area.
;------------------------------------------------------------------------------
WP1_uMsg_0Fh:
cmp     eax,0Fh                     ;check if WM_PAINT message recieved
jne     WP1_uMsg_111h               ;if not goto label
call    My_PaintHelpArea            ;- Subroutine - paint Quick Help area
call    My_PaintWorkArea            ;- Subroutine - paint working area
jmp     WP1_return                  ;

;==============================================================================
; WM_COMMAND (value=111h) message recieved ?
;------------------------------------------------------------------------------
WP1_uMsg_111h:
cmp     eax,111h                    ;check if WM_COMMAND message recieved
jne     WP1_return                  ;if not goto label
WP1_wParam_20h:
;------------------------------------------------------------------------------
; "Reset Matrix" in the menu bar clicked ?
;------------------------------------------------------------------------------
mov     eax,WP1_wParam              ;extra info about the message in ax
cmp     ax,20h                      ;check if "Reset Matrix" in menu clicked
jne     WP1_wParam_21h              ;if not goto LABEL
;------------------------------------------------------------------------------
; API "MessageBoxA" creates a message box, are you sure to reset the matrix ?
;------------------------------------------------------------------------------
push    4h                          ;uType, style, 4=MB_YESNO Button
push    OFFSET MB2Titel             ;lpCaption,pointer to title text
push    OFFSET MB2Text              ;lpText,pointer to text message box
push    WP1_hWnd                    ;handle of owner window 0=no owner
call    MessageBoxA                 ;- API Function -
cmp     eax,6h                      ;if return value=6h (IDYES) reset matrix
jne     WP1_return			;if return value=7h (IDNO) goto LABEL
call    My_ClearQA                  ;- Subroutine -
call    My_ResetMatrix              ;- Subroutine -
jmp     WP1_return                  ;

WP1_wParam_21h:
;------------------------------------------------------------------------------
; "Load Matrix" in the menu bar clicked ?
;------------------------------------------------------------------------------
mov     eax,WP1_wParam              ;extra info about the message in ax
cmp     ax,21h                      ;check if "Load Matrix" in menu clicked
jne     WP1_wParam_22h              ;if not goto LABEL
call    My_LoadMatrix               ;- Subroutine -
cmp     ErrorFlag,1h                ;
je      IO_Error                    ;
;------------------------------------------------------------------------------
; This is my small test if the loaded file is a correct *.mat file.
;------------------------------------------------------------------------------
mov     ecx,0h                      ;test data's in the load buffer
mov     ebx,OFFSET Load_Buffer      ;
TestData:
mov     eax,3120h                   ;
cmp     [ebx],al                    ;
je      TestNext                    ;
cmp     [ebx],ah                    ;
jne     IO_Error                    ;
TestNext:
inc     ebx                         ;
inc     ecx                         ;
cmp     ecx,19000h                  ;
jne     TestData                    ;
mov     ecx,0h                      ;copy datas from load buffer into matrix
mov     ebx,OFFSET Load_Buffer      ;
mov     edx,OFFSET Matrix_RAM       ;
CopyNext:
mov     al,[ebx]                    ;
mov     [edx],al                    ;
inc     ebx                         ;
inc     edx                         ;
inc     ecx                         ;
cmp     ecx,19000h                  ;
jne     CopyNext                    ;
call    My_ClearQA                  ;- Subroutine -
jmp     WP1_return                  ;
IO_Error:
;------------------------------------------------------------------------------
; API "MessageBoxA" creates a message box, we can only click OK
;------------------------------------------------------------------------------
push    0h                          ;uType, style, 0=MB_OK Button
push    OFFSET MB3Titel             ;lpCaption,pointer to title text
push    OFFSET MB3Text              ;lpText,pointer to text message box
push    WP1_hWnd                    ;handle of owner window 0=no owner
call    MessageBoxA                 ;- API Function -
jmp     WP1_return                  ;

WP1_wParam_22h:
;------------------------------------------------------------------------------
; "Save Matrix" in the menu bar clicked ?
;------------------------------------------------------------------------------
cmp     ax,22h                      ;check if "Save Matrix" in menu clicked
jne     WP1_wParam_500h             ;if not goto LABEL
call    My_SaveMatrix               ;- Subroutine -
cmp     ErrorFlag,1h                ;
je      IO_Error                    ;
jmp     WP1_return                  ;

WP1_wParam_500h:
;------------------------------------------------------------------------------
; Learning button clicked ?
;------------------------------------------------------------------------------
cmp     ax,500h                     ;check if button ID=0500h clicked
jne     WP1_wParam_501h             ;if not 1h goto LABEL
call    My_ClearQA                  ;- Subroutine -
;------------------------------------------------------------------------------
; API "GetWindowTextA" copies the text of the specified window's title bar.
;------------------------------------------------------------------------------
push    0Bh                         ;nMaxCount, max number of chars to copy
push    OFFSET QuestionBuffer       ;lpString, address of buffer for text
push    EDIT1_WorkhWnd              ;hWnd, handle of window or control
call    GetWindowTextA              ;- API Function -
mov     QALength,eax                ;
cmp     eax,3h                      ;
jae     LQLength_OK                 ;
call    My_MessageBoxA              ;- Subroutine -
jmp     WP1_return                  ;
LQLength_OK:
mov     esi,OFFSET QuestionBuffer   ;
mov     edi,OFFSET temp_Question    ;
call    My_GetQA                    ;- Subroutine -
cmp     eax,0h                      ;check flag, correct input ?
je      LQ_OK                       ;
call    My_MessageBoxA              ;- Subroutine -
jmp     WP1_return                  ;
LQ_OK:
;------------------------------------------------------------------------------
; API "GetWindowTextA" copies the text of the specified window's title bar.
;------------------------------------------------------------------------------
push    0Bh                         ;nMaxCount, max number of chars to copy
push    OFFSET AnswerBuffer         ;lpString, address of buffer for text
push    EDIT2_WorkhWnd              ;hWnd, handle of window or control
call    GetWindowTextA              ;- API Function -
mov     QALength,eax                ;
cmp     eax,3h                      ;check string length, correct input ?
jae     LALength_OK                 ;
call    My_MessageBoxA              ;- Subroutine -
jmp     WP1_return                  ;
LALength_OK:
mov     esi,OFFSET AnswerBuffer     ;
mov     edi,OFFSET temp_Answer      ;
call    My_GetQA                    ;- Subroutine -
cmp     eax,0h                      ;check flag, correct input ?
je      LA_OK                       ;
call    My_MessageBoxA              ;- Subroutine -
jmp     WP1_return                  ;
LA_OK:
call    My_PutAnswer                ;- Subroutine -
jmp     WP1_return                  ;

WP1_wParam_501h:
;------------------------------------------------------------------------------
; Inquiry button clicked ?
;------------------------------------------------------------------------------
cmp     ax,501h                     ;check if button ID=0501h clicked
jne     WP1_return                  ;if not 1h goto LABEL
call    My_ClearQA                  ;- Subroutine -
;------------------------------------------------------------------------------
; API "GetWindowTextA" copies the text of the specified window's title bar.
;------------------------------------------------------------------------------
push    0Bh                         ;nMaxCount, max number of chars to copy
push    OFFSET QuestionBuffer       ;lpString, address of buffer for text
push    EDIT3_WorkhWnd              ;hWnd, handle of window or control
call    GetWindowTextA              ;- API Function -
mov     QALength,eax                ;
cmp     eax,3h                      ;check string length, correct input ?
jae     IQLength_OK                 ;
call    My_MessageBoxA              ;- Subroutine -
jmp     WP1_return                  ;
IQLength_OK:
mov     esi,OFFSET QuestionBuffer   ;
mov     edi,OFFSET temp_Question    ;
call    My_GetQA                    ;- Subroutine -
cmp     eax,0h                      ;check flag, correct input ?
je      IQ_OK                       ;
call    My_MessageBoxA              ;- Subroutine -
jmp     WP1_return                  ;
IQ_OK:
mov     tolerance,0h                ;
call    My_FindAnswer               ;- Subroutine -
;------------------------------------------------------------------------------
; API "SetWindowTextA" set's the text of the specified window's title bar.
;------------------------------------------------------------------------------
push    OFFSET Intelligence         ;lpsz, address of string
push    STATIC_Inquiry0hWnd         ;hwnd, handle of window or control
call    SetWindowTextA              ;- API Function -
mov     tolerance,1h                ;
call    My_FindAnswer               ;- Subroutine -
;------------------------------------------------------------------------------
; API "SetWindowTextA" set's the text of the specified window's title bar.
;------------------------------------------------------------------------------
push    OFFSET Intelligence         ;lpsz, address of string
push    STATIC_Inquiry1hWnd         ;hwnd, handle of window or control
call    SetWindowTextA              ;- API Function -
mov     tolerance,2h                ;
call    My_FindAnswer               ;- Subroutine -
;------------------------------------------------------------------------------
; API "SetWindowTextA" set's the text of the specified window's title bar.
;------------------------------------------------------------------------------
push    OFFSET Intelligence         ;lpsz, address of string
push    STATIC_Inquiry2hWnd         ;hwnd, handle of window or control
call    SetWindowTextA              ;- API Function -
mov     tolerance,3h                ;
call    My_FindAnswer               ;- Subroutine -
;------------------------------------------------------------------------------
; API "SetWindowTextA" set's the text of the specified window's title bar.
;------------------------------------------------------------------------------
push    OFFSET Intelligence         ;lpsz, address of string
push    STATIC_Inquiry3hWnd         ;hwnd, handle of window or control
call    SetWindowTextA              ;- API Function -
mov     tolerance,4h                ;
call    My_FindAnswer               ;- Subroutine -
;------------------------------------------------------------------------------
; API "SetWindowTextA" set's the text of the specified window's title bar.
;------------------------------------------------------------------------------
push    OFFSET Intelligence         ;lpsz, address of string
push    STATIC_Inquiry4hWnd         ;hwnd, handle of window or control
call    SetWindowTextA              ;- API Function -
mov     tolerance,5h                ;
call    My_FindAnswer               ;- Subroutine -
;------------------------------------------------------------------------------
; API "SetWindowTextA" set's the text of the specified window's title bar.
;------------------------------------------------------------------------------
push    OFFSET Intelligence         ;lpsz, address of string
push    STATIC_Inquiry5hWnd         ;hwnd, handle of window or control
call    SetWindowTextA              ;- API Function -
mov     tolerance,6h                ;
call    My_FindAnswer               ;- Subroutine -
;------------------------------------------------------------------------------
; API "SetWindowTextA" set's the text of the specified window's title bar.
;------------------------------------------------------------------------------
push    OFFSET Intelligence         ;lpsz, address of string
push    STATIC_Inquiry6hWnd         ;hwnd, handle of window or control
call    SetWindowTextA              ;- API Function -
mov     tolerance,7h                ;
call    My_FindAnswer               ;- Subroutine -
;------------------------------------------------------------------------------
; API "SetWindowTextA" set's the text of the specified window's title bar.
;------------------------------------------------------------------------------
push    OFFSET Intelligence         ;lpsz, address of string
push    STATIC_Inquiry7hWnd         ;hwnd, handle of window or control
call    SetWindowTextA              ;- API Function -
jmp     WP1_return                  ;

;==============================================================================
; API "DefWindowProcA" calls the window procedure to provide default processing
; for any window messages that an application does not process.
; This function ensures that every message is processed.
; It is called with the same parameters received by the window procedure.
;------------------------------------------------------------------------------
WP1_return:
popad                               ;pop all register from stack
push    WP1_lParam                  ;extra info about the message
push    WP1_wParam                  ;extra info about the message
push    WP1_uMsg                    ;the message number
push    WP1_hWnd                    ;handle of window who receives message
call    DefWindowProcA              ;- API Function -
ret                                 ;return to lpfnWndProc (multitask os)
;##############################################################################

;******************************************************************************
; My own subroutine(s) for a compacter code resist here ...
;------------------------------------------------------------------------------
My_InitPrg:
;==============================================================================
; Here I init the program.
;------------------------------------------------------------------------------
mov     esi,0h                      ;init Matrix_RAM
mov     al,20h                      ;
mov     ebx,OFFSET Matrix_RAM       ;
Init1:
mov     [ebx],al                    ;
inc     ebx                         ;
inc     esi                         ;
cmp     esi,19000h                  ;
jne     Init1                       ;
mov     esi,0h                      ;init buffer's
mov     ax,0020h                    ;
mov     ebx,OFFSET temp_Question    ;
mov     ecx,OFFSET temp_Answer      ;
mov     edx,OFFSET temp_Column      ;
Init2:
mov     [ebx],al                    ;
mov     [ecx],al                    ;
mov     [edx],ah                    ;
mov     [edx+1],ah                  ;
inc     ebx                         ;
inc     ecx                         ;
inc     edx                         ;
inc     edx                         ;
inc     esi                         ;
cmp     esi,140h                    ;
jne     Init2                       ;
ret                                 ;

My_MessageBoxA:
;==============================================================================
; API "MessageBoxA" creates a message box, we can only click OK
;------------------------------------------------------------------------------
push	0h                            ;uType, style, 0=MB_OK Button
push	OFFSET MB1Titel               ;lpCaption,pointer to title text
push	OFFSET MB1Text                ;lpText,pointer to text message box
push	WP1_hWnd                      ;handle of owner window 0=no owner
call	MessageBoxA                   ;- API Function -
ret                                 ;

My_ClearQA:
;==============================================================================
; My routine to clear my temp Question / Answer buffer.
;------------------------------------------------------------------------------
mov     edx,0h                      ;
mov     ah,20h                      ;
Clear_QA:
mov     ebx,OFFSET temp_Question    ;
add     ebx,edx                     ;
mov     ecx,OFFSET temp_Answer      ;
add     ecx,edx                     ;
mov     [ebx],ah                    ;
mov     [ecx],ah                    ;
inc     edx                         ;
cmp     edx,140h                    ;
jne     Clear_QA                    ;
ret                                 ;

My_GetQA:
;==============================================================================
; My routine to get a Question / Answer and code it into a proper format.
;------------------------------------------------------------------------------
mov     counter0,0h                 ;
NextChar:
mov     edx,0h                      ;
mov     ebx,esi                     ;ESI = OFFSET Question / Answer buffer
add     ebx,counter0                ;
mov     ecx,OFFSET Sign_Index       ;hex values of character
dec     ecx                         ;
dec     edx                         ;
MaxSign:
inc     edx                         ;
cmp     edx,1Ah                     ;
jae     Input_Error                 ;ERROR
add     ecx,1h                      ;
mov     al,[ebx]                    ;
mov     ah,[ecx]                    ;
or      al,20h                      ;convert all character's to small letters
cmp     al,ah                       ;
jne     MaxSign                     ;
mov     ebx,OFFSET Sign_A           ;coded character table
cmp     edx,0h                      ;
je      CheckTempQA                 ;
PointCharBits:
add     ebx,20h                     ;
dec     edx                         ;
jne     PointCharBits               ;
CheckTempQA:
mov     ecx,edi                     ;EDI = OFFSET temp_Question / temp_Answer
mov     eax,counter0                ;
cmp     eax,0h                      ;
je      FillTempQA                  ;
PointTempQA:
add     ecx,20h                     ;
dec     eax                         ;
jne     PointTempQA                 ;
FillTempQA:
mov     al,20h                      ;
LoopFillTempQA:                     ;
mov     ah,[ebx]                    ;
mov     [ecx],ah                    ;
inc     ebx                         ;
inc     ecx                         ;
dec     al                          ;
jne     LoopFillTempQA              ;
inc     counter0                    ;
mov     eax,counter0                ;
cmp     eax,QALength                ;
jne     NextChar                    ;
mov     eax,0h                      ;no error encountered, reset flag
ret                                 ;
Input_Error:
mov     eax,1h                      ;ERROR, set flag
ret                                 ;

My_FindAnswer:
;==============================================================================
; Reset temp_Answer buffer.
;------------------------------------------------------------------------------
mov     edx,0h                      ;
mov     ah,20h                      ;
Clear_A:
mov     ecx,OFFSET temp_Answer      ;
add     ecx,edx                     ;
mov     [ecx],ah                    ;
inc     edx                         ;
cmp     edx,140h                    ;
jne     Clear_A                     ;
;------------------------------------------------------------------------------
; Calculate Level ( summary of 1 in the question ).
;------------------------------------------------------------------------------
mov     edx,0h                      ;count the number of 1 in the question
mov     Level,0h                    ;
mov     ebx,OFFSET temp_Question    ;
mov     ecx,OFFSET temp_Column      ;
CheckLevel:
mov     al,[ebx]                    ;
cmp     al,31h                      ;
jne     NextValue                   ;
inc     Level                       ;store the summary in variable "Level"
mov     [ecx],dh                    ;store the founded column's
mov     [ecx+1],dl                  ;
inc     ecx                         ;
inc     ecx                         ;
NextValue:
inc     ebx                         ;
inc     edx                         ;
cmp     edx,140h                    ;
jne     CheckLevel                  ;
;------------------------------------------------------------------------------
; Search for the answer in the matrix and store it in temp_Answer.
;------------------------------------------------------------------------------
mov     esi,0h                      ;
mov     edi,OFFSET temp_Answer      ;
L00:
mov     temp_Result,0h              ;
mov     ebx,OFFSET temp_Column      ;
mov     ecx,OFFSET Matrix_RAM       ;
add     ecx,esi                     ;
mov     eax,0h                      ;
L01:
mov     edx,0h                      ;
mov     dh,[ebx]                    ;
mov     dl,[ebx+1]                  ;
add     ecx,edx                     ;
push    eax                         ;save EAX
mov     al,[ecx]                    ;
sub     ecx,edx                     ;
cmp     al,31h                      ;
jne     L02                         ;
inc     temp_Result                 ;
L02:
pop     eax                         ;restore EAX
inc     ebx                         ;
inc     ebx                         ;
inc     eax                         ;
cmp     eax,Level                   ;
jne     L01                         ;
mov     bl,20h                      ;
mov     [edi],bl                    ;
mov     eax,Level                   ;
sub     eax,tolerance               ;
jc      L03                         ;
cmp     temp_Result,eax             ;
jb      L03                         ;
mov     bl,31h                      ;
mov     [edi],bl                    ;
L03:
inc     edi                         ;
add     esi,140h                    ;
cmp     esi,19000h                  ;
jne     L00                         ;
;------------------------------------------------------------------------------
; Reset output buffer
;------------------------------------------------------------------------------
mov     ax,0h                       ;clear output buffer
mov     ebx,OFFSET Intelligence     ;
Clear_Intelligence:
mov     [ebx],ah                    ;
inc     al                          ;
inc     ebx                         ;
cmp     al,0Ah                      ;
jne     Clear_Intelligence          ;
;------------------------------------------------------------------------------
; Decode back into hex value of ascii character; if avaible.
;------------------------------------------------------------------------------
mov     edx,0h                      ;
mov     edi,0h                      ;
LX0:
mov     counter0,0h                 ;
mov     esi,0h                      ;
LX10:
mov     ebx,OFFSET temp_Answer      ;
add     ebx,edx                     ;
mov     ecx,OFFSET Sign_A           ;
add     ecx,esi                     ;
mov     ah,0h                       ;
LX1:
mov     al,[ebx]                    ;
cmp     [ecx],al                    ;
je      LX2                         ;
inc     counter0                    ;
add     esi,20h                     ;
cmp     esi,340h                    ;
jne     LX10                        ;
mov     ebx,OFFSET QMark            ;
jmp     LX3                         ;
LX2:
inc     ebx                         ;
inc     ecx                         ;
inc     ah                          ;
cmp     ah,20h                      ;
jne     LX1                         ;
mov     ebx,OFFSET Sign_Index       ;
add     ebx,counter0                ;
LX3:
mov     ecx,OFFSET Intelligence     ;
add     ecx,edi                     ;
mov     al,[ebx]                    ;
mov     [ecx],al                    ;
add     edx,20h                     ;
inc     edi                         ;
cmp     edi,0Ah                     ;
jne     LX0                         ;
ret                                 ;

My_PaintHelpArea:
;==============================================================================
; API "BeginPaint" prepares the specified window for painting and fills a
; PAINTSTRUCT structure with information about the painting.
;------------------------------------------------------------------------------
push    OFFSET hdc                  ;lpPaint, pointer to PAINTSTRUCT
push    STATIC_HelphWnd             ;hwnd, handle of the window
call    BeginPaint                  ;- API Function -
mov     hdcDest,eax                 ;handle, display device (DC)=dest.
;------------------------------------------------------------------------------
; API "FillRect" fills a rectangle by using the specified brush or color.
; Includes the left and top borders, but excludes the right and bottom borders.
;------------------------------------------------------------------------------
push    blackbrush                  ;hbr, handle of brush or default color
push    OFFSET rcPaint_left         ;lprc, address structure with rectangle
push    hdcDest                     ;hDC, handle of device context
call    FillRect                    ;- API Function -
;------------------------------------------------------------------------------
; API "SetBkColor" sets the current background color to the specified color
; value, or to the nearest physical color if the device cannot represent the
; specified color value. Parameter crColor = Null Blue Green Red (BGR).
;------------------------------------------------------------------------------
push    0h                          ;crColor, background color value
push    hdcDest                     ;hdc, handle of device context
call    SetBkColor                  ;- API Function -
;------------------------------------------------------------------------------
; API "SetTextColor" sets the text color for the specified device context to
; the specified color. Parameter crColor = Null Blue Green Red (BGR).
;------------------------------------------------------------------------------
push    0000D6FFh                   ;crColor, text color
push    hdcDest                     ;hdc, handle of device context
call    SetTextColor                ;- API Function -
;------------------------------------------------------------------------------
; API "TextOutA" writes a character string at the specified location, using
; the currently selected font.
;------------------------------------------------------------------------------
push    0Ah                         ;cbString, number characters in string
push    OFFSET HelpTitel            ;lpString, address of string
push    6h                          ;nYStart, y-coord. of starting position
push    80h                         ;nXStart, x-coord. of starting position
push    hdcDest                     ;hdc, handle of device context
call    TextOutA                    ;- API Function -
;------------------------------------------------------------------------------
; API "CreateFont" creates a logical font that has specific characteristics.
; The logical font can subsequently be selected as the font for any device.
;------------------------------------------------------------------------------
push    OFFSET FontName             ;lpszFace, address typeface name string
push    30h                         ;fdwPitchAndFamily, pitch and family
                                    ;FF_MODERN          =48
                                    ;DEFAULT_PITCH      = 0
push    2h                          ;fdwQuality, output quality
                                    ;PROOF_QUALITY      = 2
push    0h                          ;fdwClipPrecision, clipping precision
                                    ;CLIP_DEFAULT_PRECIS= 0
push    0h                          ;fdwOutputPrecision, output precision
                                    ;OUT_DEFAULT_PRECIS = 0
push    0FFh                        ;fdwCharSet, character set identifier
                                    ;OEM_CHARSET        = 255
push    0h                          ;fdwStrikeOut, strikeout attribute flag
push    0h                          ;fdwUnderline, underline attribute flag
push    0h                          ;fdwItalic, italic attribute flag
push    400                         ;fnWeight, font weight
                                    ;FW_NORMAL          = 400
push    0h                          ;nOrientation, base orientation angle
push    0h                          ;nEscapement, angle of escapement
push    7h                          ;nWidth,logical average character width
push    0Eh                         ;nHeight, logical height of font
call    CreateFontA                 ;- API Function -
;------------------------------------------------------------------------------
; API "SelectObject" selects an object into the specified device context.
; The new object replaces the previous object of the same type.
;------------------------------------------------------------------------------
push    eax                         ;hgdiobj, handle of object
push    hdcDest                     ;hdc, handle of device context
call    SelectObject                ;- API Function -
mov     hFont,eax                   ;handle of previous (!) font
;------------------------------------------------------------------------------
; API "SetBkColor" sets the current background color to the specified color
; value, or to the nearest physical color if the device cannot represent the
; specified color value. Parameter crColor = Null Blue Green Red (BGR).
;------------------------------------------------------------------------------
push    00FFFFFFh                   ;crColor, background color value
push    hdcDest                     ;hdc, handle of device context
call    SetBkColor                  ;- API Function -
;------------------------------------------------------------------------------
; API "SetTextColor" sets the text color for the specified device context to
; the specified color. Parameter crColor = Null Blue Green Red (BGR).
;------------------------------------------------------------------------------
push    0h                          ;crColor, text color
push    hdcDest                     ;hdc, handle of device context
call    SetTextColor                ;- API Function -
;------------------------------------------------------------------------------
; API "TextOutA" writes a character string at the specified location, using
; the currently selected font.
;------------------------------------------------------------------------------
mov     temp_ycoordinate,1Ch        ;set default ycoordinate
mov     ebx,OFFSET HelpText         ;move pointer to matrix into EBX
mov     temp,ebx                    ;mov EBX into temporary variable
mov     counter0,0h                 ;reset counter
LoopHelp_TextOutA:
push    2Fh                         ;cbString, number characters in string
push    temp                        ;lpString, address of string
push    temp_ycoordinate            ;nYStart, y-coord. of starting position
push    2h                          ;nXStart, x-coord. of starting position
push    hdcDest                     ;hdc, handle of device context
call    TextOutA                    ;- API Function -
add     temp,2Fh                    ;increase matrix pointer
add     temp_ycoordinate,0Eh        ;increase ycoordinate for the next line
inc     counter0                    ;increase counter
cmp     counter0,22h                ;check if line counter reached 22h
jne     LoopHelp_TextOutA           ;if not loop again
;------------------------------------------------------------------------------
; API "SelectObject" selects an object into the specified device context.
; The new object replaces the previous object of the same type.
;------------------------------------------------------------------------------
push    hFont                       ;hgdiobj, handle of object
push    hdcDest                     ;hdc, handle of device context
call    SelectObject                ;- API Function -
;------------------------------------------------------------------------------
; API "EndPaint" marks the end of painting in the given window.
; This function is required for each call to the BeginPaint function, but only
; after painting is complete.  
;------------------------------------------------------------------------------
push    OFFSET hdc                  ;lpPaint, pointer PAINTSTRUCT
push    STATIC_HelphWnd             ;hwnd, handle of the window
call    EndPaint                    ;- API Function -
ret                                 ;

My_PaintWorkArea:
;==============================================================================
; API "BeginPaint" prepares the specified window for painting and fills a
; PAINTSTRUCT structure with information about the painting
;------------------------------------------------------------------------------
push    OFFSET hdc                  ;lpPaint, pointer to PAINTSTRUCT
push    WP1_hWnd                    ;hwnd, handle of the window
call    BeginPaint                  ;- API Function -
mov     hdcDest,eax                 ;handle, display device (DC)=dest.
;------------------------------------------------------------------------------
; API "DrawEdge" draws one or more edges of rectangle.
;------------------------------------------------------------------------------
push    400Fh                       ;grfFlags, type of border
push    5h                          ;edge, type inner + outer edge to draw
                                    ;BDR_RAISEDOUTER    = 0001h
                                    ;BDR_RAISEDINNER    = 0004h
push    OFFSET rcLearn_left         ;qrc, address of rectangle coordinates
push    hdcDest                     ;hdc, handle of device context
call    DrawEdge                    ;- API Function -
;------------------------------------------------------------------------------
; API "SetBkColor" sets the current background color to the specified color
; value, or to the nearest physical color if the device cannot represent the
; specified color value. Parameter crColor = Null Blue Green Red (BGR).
;------------------------------------------------------------------------------
push    0h                          ;crColor, background color value
push    hdcDest                     ;hdc, handle of device context
call    SetBkColor                  ;- API Function -
;------------------------------------------------------------------------------
; API "SetTextColor" sets the text color for the specified device context to
; the specified color. Parameter crColor = Null Blue Green Red (BGR).
;------------------------------------------------------------------------------
push    0000D6FFh                   ;crColor, text color
push    hdcDest                     ;hdc, handle of device context
call    SetTextColor                ;- API Function -
;------------------------------------------------------------------------------
; API "TextOutA" writes a character string at the specified location, using
; the currently selected font.
;------------------------------------------------------------------------------
push    08h                         ;cbString, number characters in string
push    OFFSET LearnTitel           ;lpString, address of string
push    48h                         ;nYStart, y-coord. of starting position
push    1C0h                        ;nXStart, x-coord. of starting position
push    hdcDest                     ;hdc, handle of device context
call    TextOutA                    ;- API Function -
;------------------------------------------------------------------------------
; API "SetTextColor" sets the text color for the specified device context to
; the specified color. Parameter crColor = Null Blue Green Red (BGR).
;------------------------------------------------------------------------------
push    00FFFFFFh                   ;crColor, text color
push    hdcDest                     ;hdc, handle of device context
call    SetTextColor                ;- API Function -
;------------------------------------------------------------------------------
; API "TextOutA" writes a character string at the specified location, using
; the currently selected font.
;------------------------------------------------------------------------------
push    08h                         ;cbString, number characters in string
push    OFFSET Question             ;lpString, address of string
push    64h                         ;nYStart, y-coord. of starting position
push    170h                        ;nXStart, x-coord. of starting position
push    hdcDest                     ;hdc, handle of device context
call    TextOutA                    ;- API Function -
;------------------------------------------------------------------------------
; API "TextOutA" writes a character string at the specified location, using
; the currently selected font.
;------------------------------------------------------------------------------
push    06h                         ;cbString, number characters in string
push    OFFSET Answer               ;lpString, address of string
push    84h                         ;nYStart, y-coord. of starting position
push    170h                        ;nXStart, x-coord. of starting position
push    hdcDest                     ;hdc, handle of device context
call    TextOutA                    ;- API Function -
;------------------------------------------------------------------------------
; API "DrawEdge" draws one or more edges of rectangle.
;------------------------------------------------------------------------------
push    400Fh                       ;grfFlags, type of border
push    5h                          ;edge, type inner + outer edge to draw
                                    ;BDR_RAISEDOUTER    = 0001h
                                    ;BDR_RAISEDINNER    = 0004h
push    OFFSET rcInquiry_left       ;qrc, address of rectangle coordinates
push    hdcDest                     ;hdc, handle of device context
call    DrawEdge                    ;- API Function -
;------------------------------------------------------------------------------
; API "SetBkColor" sets the current background color to the specified color
; value, or to the nearest physical color if the device cannot represent the
; specified color value. Parameter crColor = Null Blue Green Red (BGR).
;------------------------------------------------------------------------------
push    0h                          ;crColor, background color value
push    hdcDest                     ;hdc, handle of device context
call    SetBkColor                  ;- API Function -
;------------------------------------------------------------------------------
; API "SetTextColor" sets the text color for the specified device context to
; the specified color. Parameter crColor = Null Blue Green Red (BGR).
;------------------------------------------------------------------------------
push    0000D6FFh                   ;crColor, text color
push    hdcDest                     ;hdc, handle of device context
call    SetTextColor                ;- API Function -
;------------------------------------------------------------------------------
; API "TextOutA" writes a character string at the specified location, using
; the currently selected font.
;------------------------------------------------------------------------------
push    07h                         ;cbString, number characters in string
push    OFFSET InquiryTitel         ;lpString, address of string
push    0B0h                        ;nYStart, y-coord. of starting position
push    1C0h                        ;nXStart, x-coord. of starting position
push    hdcDest                     ;hdc, handle of device context
call    TextOutA                    ;- API Function -
;------------------------------------------------------------------------------
; API "SetTextColor" sets the text color for the specified device context to
; the specified color. Parameter crColor = Null Blue Green Red (BGR).
;------------------------------------------------------------------------------
push    00FFFFFFh                   ;crColor, text color
push    hdcDest                     ;hdc, handle of device context
call    SetTextColor                ;- API Function -
;------------------------------------------------------------------------------
; API "TextOutA" writes a character string at the specified location, using
; the currently selected font.
;------------------------------------------------------------------------------
push    08h                         ;cbString, number characters in string
push    OFFSET Question             ;lpString, address of string
push    0CCh                        ;nYStart, y-coord. of starting position
push    170h                        ;nXStart, x-coord. of starting position
push    hdcDest                     ;hdc, handle of device context
call    TextOutA                    ;- API Function -
;------------------------------------------------------------------------------
; API "TextOutA" writes a character string at the specified location, using
; the currently selected font.
;------------------------------------------------------------------------------
push    06h                         ;cbString, number characters in string
push    OFFSET Answer               ;lpString, address of string
push    104h                        ;nYStart, y-coord. of starting position
push    170h                        ;nXStart, x-coord. of starting position
push    hdcDest                     ;hdc, handle of device context
call    TextOutA                    ;- API Function -
;------------------------------------------------------------------------------
; API "EndPaint" marks the end of painting in the given window.
; This function is required for each call to the BeginPaint function, but only
; after painting is complete.  
;------------------------------------------------------------------------------
push    OFFSET hdc                  ;lpPaint, pointer PAINTSTRUCT
push    WP1_hWnd                    ;hwnd, handle of the window
call    EndPaint                    ;- API Function -
ret                                 ;

My_WM_CREATE:
;==============================================================================
; API "CreateWindowExA" creates a window with a predefined class name (STATIC).
; The return value in EAX is the handle of the new window (Quick Help).
;------------------------------------------------------------------------------
push    0h                          ;lpParam, extra pointer data 0=no data
push    hInstance                   ;hInstance, handle of our program
push    900h                        ;hMenu, the child-window ID
push    WP1_hWnd                    ;hWndParent, handle parent window 0=no
push    200h                        ;intnHeight, window height pixel
push    153h                        ;intnWidth, window width pixel
push    0Ch                         ;inty, vertical position window
push    04h                         ;intx, horizontal position window
push    54000001h                   ;dwStyle, static window style
                                    ;WS_CHILD           = 40000000h
                                    ;WS_VISIBLE         = 10000000h
                                    ;WS_CLIBSIBLINGS    =  4000000h
                                    ;SS_CENTER          =        1h
push    0h                          ;lpWindowName, pointer to window name
push    OFFSET STATIC_Class         ;lpClassName, pointer to class name
push    1h                          ;dwExStyle,look WIN32.HLP + windows.inc
call    CreateWindowExA             ;- API Function -
mov     STATIC_HelphWnd,eax         ;hwnd,return value=handle of window
;------------------------------------------------------------------------------
; API "CreateWindowExA" creates a window with a predefined class name (STATIC).
; The return value in EAX is the handle of the new window (Titel).
;------------------------------------------------------------------------------
push    0h                          ;lpParam, extra pointer data 0=no data
push    hInstance                   ;hInstance, handle of our program
push    700h                        ;hMenu, the child-window ID
push    WP1_hWnd                    ;hWndParent, handle parent window 0=no
push    30h                         ;intnHeight, window height pixel
push    112h                        ;intnWidth, window width pixel
push    0Ch                         ;inty, vertical position window
push    160h                        ;intx, horizontal position window
push    5400000Eh                   ;dwStyle, static window style
                                    ;WS_CHILD           = 40000000h
                                    ;WS_VISIBLE         = 10000000h
                                    ;WS_CLIBSIBLINGS    =  4000000h
                                    ;SS_BITMAP          =       0Eh
push    OFFSET Titel                ;lpWindowName, pointer to window name
push    OFFSET STATIC_Class         ;lpClassName, pointer to class name
push    0h                          ;dwExStyle,look WIN32.HLP + windows.inc
call    CreateWindowExA             ;- API Function -
mov     STATIC_TitelhWnd,eax        ;hwnd,return value=handle of window
;------------------------------------------------------------------------------
; API "CreateWindowExA" creates a window with a predefined class name (EDIT).
; The return value in EAX is the handle of the new window (Learning Question).
;------------------------------------------------------------------------------
push    0h                          ;lpParam, extra pointer data 0=no data
push    hInstance                   ;hInstance, handle of our program
push    910h                        ;hMenu, the child-window ID
push    WP1_hWnd                    ;hWndParent, handle parent window 0=no
push    18h                         ;intnHeight, window height pixel
push    80h                         ;intnWidth, window width pixel
push    60h                         ;inty, vertical position window
push    1B0h                        ;intx, horizontal position window
push    54010000h                   ;dwStyle, static window style
                                    ;WS_CHILD           = 40000000h
                                    ;WS_VISIBLE         = 10000000h
                                    ;WS_CLIBSIBLINGS    =  4000000h
                                    ;WS_TABSTOP         =    10000h
push    0h                          ;lpWindowName, pointer to window name
push    OFFSET EDIT_Class           ;lpClassName, pointer to class name
push    1h                          ;dwExStyle,look WIN32.HLP + windows.inc
call    CreateWindowExA             ;- API Function -
mov     EDIT1_WorkhWnd,eax          ;hwnd,return value=handle of window
;------------------------------------------------------------------------------
; API "CreateWindowExA" creates a window with a predefined class name (EDIT).
; The return value in EAX is the handle of the new window (Learning Answer).
;------------------------------------------------------------------------------
push    0h                          ;lpParam, extra pointer data 0=no data
push    hInstance                   ;hInstance, handle of our program
push    920h                        ;hMenu, the child-window ID
push    WP1_hWnd                    ;hWndParent, handle parent window 0=no
push    18h                         ;intnHeight, window height pixel
push    80h                         ;intnWidth, window width pixel
push    80h                         ;inty, vertical position window
push    1B0h                        ;intx, horizontal position window
push    54010000h                   ;dwStyle, static window style
                                    ;WS_CHILD           = 40000000h
                                    ;WS_VISIBLE         = 10000000h
                                    ;WS_CLIBSIBLINGS    =  4000000h
                                    ;WS_TABSTOP         =    10000h
push    0h                          ;lpWindowName, pointer to window name
push    OFFSET EDIT_Class           ;lpClassName, pointer to class name
push    1h                          ;dwExStyle,look WIN32.HLP + windows.inc
call    CreateWindowExA             ;- API Function -
mov     EDIT2_WorkhWnd,eax          ;hwnd,return value=handle of window
;------------------------------------------------------------------------------
; API "CreateWindowExA" creates a window with a predefined class name (BUTTON).
; The return value in EAX is the handle of the new child window (Go Learning).
;------------------------------------------------------------------------------
push    0h                          ;lpParam, extra pointer data 0=no data
push    hInstance                   ;hInstance, handle of our program
push    500h                        ;hMenu, the child-window ID
push    WP1_hWnd                    ;hWndParent, handle parent window 0=no
push    20h                         ;intnHeight, window height pixel
push    20h                         ;intnWidth, window width pixel
push    6Ch                         ;inty, vertical position window
push    244h                        ;intx, horizontal position window
push    54000080h                   ;dwStyle, button style
                                    ;WS_CHILD           = 40000000h
                                    ;WS_VISIBLE         = 10000000h
                                    ;WS_CLIBSIBLINGS    =  4000000h
                                    ;WS_TABSTOP         =    10000h
                                    ;BS_BITMAP          =       80h
                                    ;BS_PUSHBUTTON      =        0h
push    0h                          ;lpWindowName, pointer to window name
push    OFFSET BUTTON_Class         ;lpClassName, pointer to class name
push    0h                          ;dwExStyle,
call    CreateWindowExA             ;- API Function -
mov     BUTTON_LearnhWnd,eax        ;return value=handle of window
;------------------------------------------------------------------------------
; API "LoadBitmapA" loads a bitmap from the resource file
;------------------------------------------------------------------------------
push    80h                         ;lpBitmapName, bitmap resource ID
push    hInstance                   ;hInstance, handle of modul instance
call    LoadBitmapA                 ;- API Function -
mov     BUTTON_LearnhObject,eax     ;hObject, handle of graphic object
;------------------------------------------------------------------------------
; API "SendMessageA" sends a message to the Window Procedure lpfnWndProc
;------------------------------------------------------------------------------
push    eax                         ;lParam, handle of bitmap
push    0h                          ;wParam, first message ( IMAGE_BITMAP )
push    0F7h                        ;uMsg, message to send ( BM_SETIMAGE )
push    BUTTON_LearnhWnd            ;hWnd, handle of destination window
call    SendMessageA                ;- API Function -
;------------------------------------------------------------------------------
; API "CreateWindowExA" creates a window with a predefined class name (EDIT).
; The return value in EAX is the handle of the new window (Inquiry Question).
;------------------------------------------------------------------------------
push    0h                          ;lpParam, extra pointer data 0=no data
push    hInstance                   ;hInstance, handle of our program
push    930h                        ;hMenu, the child-window ID
push    WP1_hWnd                    ;hWndParent, handle parent window 0=no
push    18h                         ;intnHeight, window height pixel
push    80h                         ;intnWidth, window width pixel
push    0C8h                        ;inty, vertical position window
push    1B0h                        ;intx, horizontal position window
push    54010000h                   ;dwStyle, static window style
                                    ;WS_CHILD           = 40000000h
                                    ;WS_VISIBLE         = 10000000h
                                    ;WS_CLIBSIBLINGS    =  4000000h
                                    ;WS_TABSTOP         =    10000h
push    0h                          ;lpWindowName, pointer to window name
push    OFFSET EDIT_Class           ;lpClassName, pointer to class name
push    1h                          ;dwExStyle,look WIN32.HLP + windows.inc
call    CreateWindowExA             ;- API Function -
mov     EDIT3_WorkhWnd,eax          ;hwnd,return value=handle of window
;------------------------------------------------------------------------------
; API "CreateWindowExA" creates a window with a predefined class name (STATIC).
; The return value in EAX is the handle of the new window (Answer0-6).
; Here we create the seven answer windows !
;------------------------------------------------------------------------------
push    0h                          ;lpParam, extra pointer data 0=no data
push    hInstance                   ;hInstance, handle of our program
push    600h                        ;hMenu, the child-window ID
push    WP1_hWnd                    ;hWndParent, handle parent window 0=no
push    18h                         ;intnHeight, window height pixel
push    80h                         ;intnWidth, window width pixel
push    100h                        ;inty, vertical position window
push    1B0h                        ;intx, horizontal position window
push    54000000h                   ;dwStyle, static window style
                                    ;WS_CHILD           = 40000000h
                                    ;WS_VISIBLE         = 10000000h
                                    ;WS_CLIBSIBLINGS    =  4000000h
                                    ;SS_LEFT            =        0h
push    0h                          ;lpWindowName, pointer to window name
push    OFFSET STATIC_Class         ;lpClassName, pointer to class name
push    1h                          ;dwExStyle,look WIN32.HLP + windows.inc
call    CreateWindowExA             ;- API Function -
mov     STATIC_Inquiry0hWnd,eax     ;hwnd, return value=handle of window
push    0h
push    hInstance
push    601h
push    WP1_hWnd
push    18h
push    80h
push    120h
push    1B0h
push    54000000h
push    0h
push    OFFSET STATIC_Class
push    1h
call    CreateWindowExA
mov     STATIC_Inquiry1hWnd,eax
push    0h
push    hInstance
push    602h
push    WP1_hWnd
push    18h
push    80h
push    140h
push    1B0h
push    54000000h
push    0h
push    OFFSET STATIC_Class
push    1h
call    CreateWindowExA
mov     STATIC_Inquiry2hWnd,eax
push    0h
push    hInstance
push    603h
push    WP1_hWnd
push    18h
push    80h
push    160h
push    1B0h
push    54000000h
push    0h
push    OFFSET STATIC_Class
push    1h
call    CreateWindowExA
mov     STATIC_Inquiry3hWnd,eax
push    0h
push    hInstance
push    604h
push    WP1_hWnd
push    18h
push    80h
push    180h
push    1B0h
push    54000000h
push    0h
push    OFFSET STATIC_Class
push    1h
call    CreateWindowExA
mov     STATIC_Inquiry4hWnd,eax
push    0h
push    hInstance
push    605h
push    WP1_hWnd
push    18h
push    80h
push    1A0h
push    1B0h
push    54000000h
push    0h
push    OFFSET STATIC_Class
push    1h
call    CreateWindowExA
mov     STATIC_Inquiry5hWnd,eax
push    0h
push    hInstance
push    606h
push    WP1_hWnd
push    18h
push    80h
push    1C0h
push    1B0h
push    54000000h
push    0h
push    OFFSET STATIC_Class
push    1h
call    CreateWindowExA
mov     STATIC_Inquiry6hWnd,eax
push    0h
push    hInstance
push    607h
push    WP1_hWnd
push    18h
push    80h
push    1E0h
push    1B0h
push    54000000h
push    0h
push    OFFSET STATIC_Class
push    1h
call    CreateWindowExA
mov     STATIC_Inquiry7hWnd,eax
;------------------------------------------------------------------------------
; API "CreateWindowExA" creates a window with a predefined class name (BUTTON).
; The return value in EAX is the handle of the new child window (Go Inquiry).
;------------------------------------------------------------------------------
push    0h                          ;lpParam, extra pointer data 0=no data
push    hInstance                   ;hInstance, handle of our program
push    0501h                       ;hMenu, the child-window ID
push    WP1_hWnd                    ;hWndParent, handle parent window 0=no
push    20h                         ;intnHeight, window height pixel
push    20h                         ;intnWidth, window width pixel
push    0C4h                        ;inty, vertical position window
push    244h                        ;intx, horizontal position window
push    54000080h                   ;dwStyle, button style
                                    ;WS_CHILD           = 40000000h
                                    ;WS_VISIBLE         = 10000000h
                                    ;WS_CLIBSIBLINGS    =  4000000h
                                    ;WS_TABSTOP         =    10000h
                                    ;BS_BITMAP          =       80h
                                    ;BS_PUSHBUTTON      =        0h
push    0h                          ;lpWindowName, pointer to window name
push    OFFSET BUTTON_Class         ;lpClassName, pointer to class name
push    0h                          ;dwExStyle,
call    CreateWindowExA             ;- API Function -
mov     BUTTON_InquiryhWnd,eax      ;return value=handle of window
;------------------------------------------------------------------------------
; API "LoadBitmapA" loads a bitmap from the resource file
;------------------------------------------------------------------------------
push    81h                         ;lpBitmapName, bitmap resource ID
push    hInstance                   ;hInstance, handle of modul instance
call    LoadBitmapA                 ;- API Function -
mov     BUTTON_InquiryhObject,eax   ;hObject, handle of graphic object
;------------------------------------------------------------------------------
; API "SendMessageA" sends a message to the Window Procedure lpfnWndProc
;------------------------------------------------------------------------------
push    eax                         ;lParam, handle of bitmap
push    0h                          ;wParam, first message ( IMAGE_BITMAP )
push    0F7h                        ;uMsg, message to send ( BM_SETIMAGE )
push    BUTTON_InquiryhWnd          ;hWnd, handle of destination window
call    SendMessageA                ;- API Function -
ret                                 ;

My_SetFocus:
;==============================================================================
; API "SetFocus" sets the keyboard focus to the specified window.
;------------------------------------------------------------------------------
push    EDIT1_WorkhWnd              ;hwnd, handle of window to receive focus
call    SetFocus                    ;- API Function -
ret                                 ;   

My_ResetMatrix:
;==============================================================================
; Reset matrix, clear memory, everything learned before is lost forever ...
;------------------------------------------------------------------------------
mov     ecx,0h                      ;
mov     ebx,OFFSET Matrix_RAM       ;
Loop_ResetMatrix:
mov     al,20h                      ;
mov     [ebx],al                    ;
inc     ebx                         ;
inc     ecx                         ;
cmp     ecx,19000h                  ;
jne     Loop_ResetMatrix            ;
ret                                 ;

My_LoadMatrix:
mov     ErrorFlag,0h                ;reset error flag
;==============================================================================
; API "GetOpenFileName" creates a system-defined dialog box that enables the
; user to select a file to open. 
;------------------------------------------------------------------------------
mov     lStructSize,4Ch             ;length in bytes of structure
mov     eax,WP1_hWnd                ; 
mov     hWndOwner,eax               ;id window that owns dialog box
mov     eax,hInstance               ; 
mov     hInstance1,eax              ;handle, our program id
mov     lpstrFilter,OFFSET FileFilt ;pointer to string + filter, 0= no
mov     lpstrCustomFilter,0h		;pointer to user defined filter
mov     nMaxCustFilter,0h           ;size bytes/characters of above
mov     nFilterIndex,0h             ;filter index of lpstrFilter 
mov     lpstrFile,OFFSET LoadFileN  ;pointer initialize filename, 0=no
mov     nMaxFile,104h               ;max size bytes/characters of above
mov     lpstrFileTitle,0h           ;pointer title of the selected file
mov     nMaxFileTitle,0h            ;size of the lpstrFileTitle buffer 
mov     lpstrInitialDir,0h          ;pointer init file dir,0=default
mov     lpstrTitle,OFFSET LoadFileT ;pointer title of the box 
mov     Flags,00281804h             ;the dialog box creation flags 
mov     nFileOffset,0h              ;offset filename in string lpstrFile 
mov     nFileExtension,0h           ;offset extension in string lpstrFile 
mov     lCustData,0h                ;? 
mov     lpfnHook,0h                 ;? used if flag is OFN_ENABLETEMPLATE
mov     lpTemplateName,0h           ;? used if flag is OFN_ENABLETEMPLATE
mov     eax,OFFSET FileDefExt       ;
mov     lpstrDefExt,eax             ;pointer default extension file, 0=no
push    OFFSET lStructSize          ;pointer to OPENFILENAME Structure
call    GetOpenFileNameA            ;- API Function -
cmp     eax,1h                      ;check for error
je      GoOpenLoad                  ;
mov     ErrorFlag,1h                ;
ret                                 ;
GoOpenLoad:
;------------------------------------------------------------------------------
; API "CreateFileA" creates or opens a file.
; It returns a handle that can be used to access the object.
;------------------------------------------------------------------------------
push    0h                          ;hTemplateFile,
push    80h                         ;dwFlagsAndAttributes, 80h=normal
push    3h                          ;dwCreationDistribution, OPEN_EXISTING
push    0h                          ;lpSecurityAttributes,
push    0h                          ;dwShareMode,
push    80000000h                   ;dwDesiredAccess, GENERIC_READ
push    OFFSET LoadFileN            ;lpFileName, pointer to filename
call    CreateFileA                 ;- API Function -
cmp     eax,-1                      ;error ? INVALID_HANDLE_VALUE = -1
jne     GoGetLoad                   ;
mov     ErrorFlag,1h                ;
ret                                 ;
GoGetLoad:
mov     FileHandle,eax              ;store handle in variable
;------------------------------------------------------------------------------
; API "GetFileSize" retrieves the size, in bytes, of the specified file.
;------------------------------------------------------------------------------
push    0h                          ;lpFileSizeHigh, address file size highword 
push    FileHandle                  ;hFile, handle of file to get size of
call    GetFileSize                 ;- API Function -
cmp     eax,0FFFFFFFFh              ;check for error
jne     GoCheck                     ;
mov     ErrorFlag,1h                ;
jmp     GoCloseL                    ;
GoCheck:
cmp     eax,19000h                  ;
je      GoLoad                      ;
mov     ErrorFlag,1h                ;
jmp     GoCloseL                    ;
GoLoad:
;------------------------------------------------------------------------------
; API "ReadFile" reads data from a file, starting at the position file pointer
;------------------------------------------------------------------------------
push    0h                          ;lpOverlapped, address data structure 
push    OFFSET FileReturn           ;lpNumberOfBytesRead, readed bytes 
push    19000h                      ;nNumberOfBytesToRead, bytes to read 
push    OFFSET Load_Buffer          ;lpBuffer, address buffer receives data
push    FileHandle                  ;hFile, handle of file to read 
call    ReadFile                    ;- API Function -
cmp     eax,0h                      ;check for error
jne     GoCloseL                    ;
mov     ErrorFlag,1h                ;
GoCloseL:
;------------------------------------------------------------------------------
; API "CloseHandle" closes an open object handle. 
;------------------------------------------------------------------------------
push    FileHandle                  ;hObject, handle of object to close  
call    CloseHandle                 ;- API Function -
cmp     eax,0h                      ;check for error
jne     GoLoadReturn                ;
mov     ErrorFlag,1h                ;
GoLoadReturn:
ret                                 ;

My_SaveMatrix:
mov     ErrorFlag,0h                ;reset error flag
;==============================================================================
; API "GetSaveFileName" creates a system-defined dialog box that enables the
; user to select a file to save. 
;------------------------------------------------------------------------------
mov     lStructSize,4Ch             ;length in bytes of structure
mov     eax,WP1_hWnd                ; 
mov     hWndOwner,eax               ;id window that owns dialog box
mov     eax,hInstance               ; 
mov     hInstance1,eax              ;handle, our program id
mov     lpstrFilter,OFFSET FileFilt ;pointer to string + filter, 0= no
mov     lpstrCustomFilter,0h        ;pointer to user defined filter
mov     nMaxCustFilter,0h           ;size bytes/characters of above
mov     nFilterIndex,0h             ;filter index of lpstrFilter 
mov     lpstrFile,OFFSET SaveFileN  ;pointer initialize filename, 0=no
mov     nMaxFile,104h               ;max size bytes/characters of above
mov     lpstrFileTitle,0h           ;pointer title of the selected file
mov     nMaxFileTitle,0h            ;size of the lpstrFileTitle buffer 
mov     lpstrInitialDir,0h          ;pointer init file dir,0=default
mov     lpstrTitle,OFFSET SaveFileT ;pointer title of the box 
mov     Flags,00281804h             ;the dialog box creation flags 
mov     nFileOffset,0h              ;offset filename in string lpstrFile 
mov     nFileExtension,0h           ;offset extension in string lpstrFile 
mov     lCustData,0h                ;? 
mov     lpfnHook,0h                 ;? used if flag is OFN_ENABLETEMPLATE
mov     lpTemplateName,0h           ;? used if flag is OFN_ENABLETEMPLATE
mov     eax,OFFSET FileDefExt       ;
mov     lpstrDefExt,eax             ;pointer default extension file, 0=no 
push    OFFSET lStructSize          ;pointer to OPENFILENAME Structure
call    GetSaveFileNameA            ;- API Function -
cmp     eax,1h                      ;check for error
je      GoOpenSave                  ;
mov     ErrorFlag,1h                ;
ret                                 ;
GoOpenSave:
;------------------------------------------------------------------------------
; API "CreateFileA" creates or opens a file.
; It returns a handle that can be used to access the object.
;------------------------------------------------------------------------------
push    0h                          ;hTemplateFile,
push    80h                         ;dwFlagsAndAttributes, 80h=normal
push    2h                          ;dwCreationDistribution, CREATE_ALWAYS
push    0h                          ;lpSecurityAttributes,
push    0h                          ;dwShareMode,
push    40000000h                   ;dwDesiredAccess,GENERIC_WRITE
push    OFFSET SaveFileN            ;lpFileName,pointer to filename
call    CreateFileA                 ;- API Function -
cmp     eax,-1                      ;error ? INVALID_HANDLE_VALUE = -1
jne     GoGetSave                   ;
mov     ErrorFlag,1h                ;
ret                                 ;
GoGetSave:
mov     FileHandle,eax              ;store handle in variable
;------------------------------------------------------------------------------
; API "WriteFile" writes data to a file
;------------------------------------------------------------------------------
push    0h                          ;lpOverlapped, structure overlapped I/O
push    OFFSET FileReturn           ;lpNumberOfBytesWritten,
push    19000h                      ;nNumberOfBytesToWrite, bytes to write 
push    OFFSET Matrix_RAM           ;lpBuffer, address data write to file 
push    FileHandle                  ;hFile, handle of file to write to 
call    WriteFile                   ;- API Function -
cmp     eax,0h                      ;check for error
jne     GoCloseS                    ;
mov     ErrorFlag,1h                ;
GoCloseS:
;------------------------------------------------------------------------------
; API "CloseHandle" closes an open object handle. 
;------------------------------------------------------------------------------
push    FileHandle                  ;hObject, handle of object to close  
call    CloseHandle                 ;- API Function -
cmp     eax,0h                      ;check for error
jne     GoSaveReturn                ;
mov     ErrorFlag,1h                ;
GoSaveReturn:
ret                                 ;

My_PutAnswer:
;==============================================================================
; This is my routine to insert the answer into the Matrix.
;------------------------------------------------------------------------------
mov     esi,0h                      ;
NextEntry:
mov     ebx,OFFSET temp_Question    ;
add     ebx,esi                     ;
mov     al,[ebx]                    ;
cmp     al,31h                      ;
jne     QBitNotSet                  ;
mov     ecx,OFFSET Matrix_RAM       ;
add     ecx,esi                     ;
mov     edx,0h                      ;
mov     ebx,OFFSET temp_Answer      ;
NextLine:
mov     al,[ebx]                    ;
cmp     al,31h                      ;
jne     ABitNotSet                  ;
mov     [ecx],al                    ;
ABitNotSet:
add     ecx,140h                    ;
inc     ebx                         ;
inc     edx                         ;
cmp     edx,140h                    ;
jne     NextLine                    ;
QBitNotSet:
inc     esi                         ;
cmp     esi,140h                    ;
jne     NextEntry                   ;
ret                                 ;
;******************************************************************************

;==============================================================================
; end Main	= end of our program code
;------------------------------------------------------------------------------
end Main                            ;end of our program code, entry point

;==============================================================================
; To create the exe file use this commands with your Microsoft Assembler/Linker
;------------------------------------------------------------------------------
; ml.exe /c /coff td__510.asm                           ;asm command
; rc.exe /v rsrc.rc                                     ;rc command
; cvtres.exe /machine:ix86 rsrc.res
; link.exe /subsystem:windows td__510.obj rsrc.obj      ;link command
;==============================================================================