Goalatio 0 Junior Poster in Training

Hello everyone, I've spent most of today working on a 16-bit interactive interface, and thought it'd be nice to share it with you all. :)

Notes:
Assembled with NASM16
Has only been tested on Windows XP and Windows 7
There is A LOT of code that needs to be posted here . . .

----------------------------------------

What is it?
It's an interface framework -- Made to simplify the creation of 16-bit interfaces

----------------------------------------

FAQ from others I've shown it to:
How does this work? I mean, what am I supposed to do with this?
Answer: The files "Calls.asm" "Macros.asm" and "DS.asm" are to be used, however, DS.asm is not required.

Not much done, huh? It could use some work.
Answer: Well, I have only been working on it for a day. :)

----------------------------------------

Help:
Okay, before I begin posting all of my code and confusing you all, GUI.asm is the SAMPLE file (It shows what the framework is capable of), Compile.bat is the compiler that I wrote. The rest is the actual framework.

----------------------------------------

Some of this code is commented, some of it is not.. You may need some assembler experience to fully understand this. Sorry for not having it all commented, I hope to have this once I complete more.
----------------------------------------

To make this work correctly, place Compile.bat and GUI.asm in the same folder, also have your paths set correctly so that NASM16 can be called from the batch file.
Next, make a folder called "Data" in the same folder as Compile.bat, and place the following files into the "Data" folder.
Calls.asm
DS.asm
Macros.asm
----------------------------------------

Compile.bat:::::::

@echo off
color 0a

set filename=GUI
if exist "%filename%.com" (
	echo Deleting old files . . .
	del %filename%.com
)
if exist "%filename%.asm" (
	echo Compiling %filename%.asm
	nasm16 %filename%.asm -o %filename%.com -l info.txt
	echo OUTPUT: %filename%.com
	pause
	exit
) else (
	echo Compile error: File does not exist "%filename%"
	pause
	exit
)

GUI.asm:::::::

[org 0100h]

[section .text]
	%include "Data/Macros.asm"	;Include framework macros

main:
	call clear
					;Render buttons
	button 5,32,button1,29h
	button 10,32,button2,64h
	button 15,32,button3,64h

button1_select:
	call pause			;Wait for a keypress
	if al,13,check_selection	;If key is ENTER, check which button is selected
	ifnot ah,80,button1_select	;If key is not DOWN-ARROW, loop back to button1_select

	button 5,32,button1,64h		;Re-render button 1 with default button colors
	button 10,32,button2,29h	;Render button 2 with 'selected' colors
	mov byte[buffer],'1'		;Increase button selection by 1
	jmp button2_select

button2_select:
	call pause			;Wait for a keypress
	if al,13,check_selection	;If key is ENTER, check which button is selected
	ifnot ah,80,button2_select	;If key is not DOWN-ARROW, loop back to button2_select

	button 10,32,button2,64h	;Re-render button 2 with default colors
	button 15,32,button3,29h	;Render button 3 with 'selected' colors
	mov byte[buffer],'2'		;Increase button selection by 1
	jmp button3_select

button3_select:
	call pause			;Wait for a keypress
	if al,13,check_selection	;If key is ENTER, check which button is selected
	ifnot ah,80,button3_select	;If key is not DOWN-ARROW, loop back to button3_select

	button 15,32,button3,64h	;Re-render button 3 with default colors
	button 5,32,button1,29h		;Render button 1 with 'selected' colors
	mov byte[buffer],'0'		;Reset selection buffer
	jmp button1_select

check_selection:
	if byte[buffer],'0',button1_selected
	if byte[buffer],'1',button2_selected
	if byte[buffer],'2',button3_selected
	exit 1				;If there was an error, exit with ERRORLEVEL 1

button1_selected:
	call clear			;Clear the screen
	xor dx,dx
	call cursor

	mov dx,button1_select_text
	call output			;Display "You selected button 1."
	call pause			;Create a pause
	call clear
	call render_buttons
	button 5,32,button1,29h
	jmp button1_select		;It remembers which button was selected

button2_selected:
	call clear			;Clear the screen
	xor dx,dx
	call cursor
	mov dx,button2_select_text
	call output			;Display "You selected button 2."
	call pause			;Create a pause
	call clear
	call render_buttons
	button 10,32,button2,29h
	jmp button2_select		;It remembers which button was selected

button3_selected:
	call clear			;Clear the screen
	xor dx,dx
	call cursor
	mov dx,button3_select_text
	call output			;Display "You selected button 3."
	call pause			;Create a pause
	call clear
	call render_buttons
	button 15,32,button3,29h
	jmp button3_select		;It remembers which button was selected



;---------------------------------------------------------------------------------
	%include "Data/Calls.asm"	;Include framework calls

[section .data]
	%include "Data/DS.asm"

Macros.asm::::::::

%macro exit 1
	mov ah,4ch	;Function 4Cx21 - Exit with errorlevel
	mov al,%1	;Errorlevel passed to macro
	int 21h		;Interrupt v21

%endmacro




%macro if 3
	cmp %1,%2
	je near %3

%endmacro


%macro ifnot 3
	cmp %1,%2
	jne near %3

%endmacro




%macro button 4
	mov dh,%1		;Start first column
	mov dl,%2
	call cursor

	mov al,0
	mov bl,%4
	mov cx,buttonlength
	call color

	mov dx,button		;The top\bottoms of the button
	call output

	mov dh,%1		;Start second column pt1
	mov dl,%2
	inc dh
	call cursor

	mov al,0		;Character to display, 0 is NUL
	mov bl,%4		;Color attribute
	mov cx,buttonlength	;The length of the button
	call color

	mov dx,buttonbyte	;Display a single brick
	call output

	mov dh,%1		;Display another one, but position it farther to the right
	mov dl,%2
	inc dl
	inc dl
	inc dl
	inc dl
	inc dl
	inc dl
	inc dl
	inc dl
	inc dl
	inc dl
	inc dl
	inc dl
	inc dl
	inc dl
	inc dh
	call cursor
	mov dx,buttonbyte
	call output


	mov dh,%1		;Start third column
	mov dl,%2
	inc dh
	inc dh
	call cursor

	mov al,0
	mov bl,%4
	mov cx,buttonlength
	call color

	mov dx,button
	call output

	mov dh,%1		;Display text
	mov dl,%2
	inc dl
	inc dl
	inc dh
	call cursor
	mov dx,%3
	call output

%endmacro

Calls.asm::::::::

output:
	mov ah,9	;Function 9x21 - Display string
	int 21h		;Interrupt v21
	ret		;Return

pause:
	mov ah,0	;Function 0x16 - Pause and pass keyscan code into AX
	int 16h		;Interrupt v10
	ret		;Return

clearbuffer:
	mov di,buffer	;Destination - Button buffer
	mov cx,3	;Store 3 bytes
	xor al,al	;Clear AL to store a nul byte
	cld		;Clear direction flag
	rep stosb	;REPeat STOre-String-Byte sequence
	ret		;Return

cursor:
	mov ah,2	;Function 2x10 - Position hardware cursor
	int 10h		;Interrupt v10 :::: DH = X:DL = Y
	ret		;Return

color:
	mov ah,9	;Function 9x10 - Write color attribute into memory
	int 10h		;Interrupt v10 :::: CX = #to print : BL = Hex attribute : AL = Character to print
	ret		;Return

clear:
	xor dx,dx	;Set DH and DL to 0
	call cursor	;Position the cursor
	mov al,0	;Nul character
	mov bl,07h	;White on black color
	mov cx,5000	;5000 characters
	call color	;Display 5000 characters
	ret		;Return

render_buttons:
	button 5,32,button1,64h
	button 10,32,button2,64h
	button 15,32,button3,64h
	ret

DS.asm (Data segment for GUI.asm)::::::

;This is the data segment


	button db 0177, 0177, 0177, 0177, 0177, 0177, 0177, 0177, 0177, 0177, 0177, 0177, 0177, 0177, 0177, "$"
	buttonbyte db 0177, "$"
		buttonlength EQU $-button-3
	selection db 0175, "$"
	buffer db '0'

	button1 db "Option 1", "$"
	button2 db "Option 2", "$"
	button3 db "Option 3", "$"

	button1_select_text db "You selected button 1.", "$"
	button2_select_text db "You selected button 2.", "$"
	button3_select_text db "You selected button 3.", "$"

Enjoy, I hope someone out there learns something from this.