home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS - Coast to Coast
/
simteldosarchivecoasttocoast2.iso
/
asmutil
/
dos32v12.zip
/
STDIO.ASM
< prev
next >
Wrap
Assembly Source File
|
1993-10-12
|
11KB
|
422 lines
comment $
FOR 32 BIT PROTECDED MODE ONLY
Writen by Adam Seychell
▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐
▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐ VARIOUS PROCEDURES ▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐
▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐
▐ ▐
▐ THIS FILE CONTAINS USEFUL PROCEDURES ▐
▐ ▐
▐ THEY SHOULDN'T NEED TO BE CHANGED TO MUSH ▐
▐ ▐
▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐
▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐
▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐ VARIOUS PROCEDURES ▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐
▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐▐
╒═════════════╤═══════════════════════════
│ proc Name │ Discription
╞═════════════╪═══════════════════════════
│ ClrScr │ fills video memory (B8000h-B8FFFh) with AX
│ │
├─────────────┼───────────────────────────
│PRINT_CHAR │ prints a character AL with color AH at the cursor
│ │ AH = attribute byte ( COLOR )
│ │
├─────────────┼───────────────────────────
│ TEXT │ Prints a string at the cursor position.
│ │ expects : EDX = offset of string in data segment
│ │ AH = attribute byte ( COLOR )
│ │
├─────────────┼───────────────────────────
│HEX_DWORD │ Prints the value of EDX, DX or DL as hexidecimal
│HEX_WORD │ at the cursor position.
│HEX_BYTE │ expects : EDX = value to display
│ │ AH = attribute byte ( COLOR )
│ │
├─────────────┼───────────────────────────
│BINARY_DWORD │ Same as hex above except it prints in binary
│BINARY_WORD │
│BINARY_BYTE │
├─────────────┼───────────────────────────
│DEC_DWORD │ Same as hex above except it prints in decimal
│DEC_WORD │
│DEC_BYTE │
├─────────────┼───────────────────────────
│SCROLL_SCREEN│Scrolls the screen up a line.
│ │
├─────────────┼───────────────────────────
│SET_TIMER │Sets the timer 0 register of the 8242 PIC
│ │ to the value in AX
├─────────────┼───────────────────────────
│RANDOM │returns EAX = a random number CL bits in size
│ │
├─────────────┼───────────────────────────
│SQRT │Returns EAX with the square root of EAX.
│ │
└─────────────┴───────────────────────────
$
; Various varibles used by the procedures
random_init dd 1010111000110111101010011011b
clicker db 0
HexChar db '0123456789ABCDEF'
; Contains the current cursor cordinates used by the printing procs
Cursor_X db 0,0; Contain the current cursor cordinates
Cursor_Y db 0,0; used by the printing procs ( see file PROCS.INC )
dec_diver dd 1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000
DecVal23 dd 0
tmpdec_color07 db 0
public Click
public ClrScr
public Scroll_Screen
public Set_timer
public TEXT
public binary_Dword
public binary_Word
public binary_Byte
public Hex_Dword
public Hex_Word
public Hex_Byte
public DEC_Dword
public DEC_Word
public DEC_Byte
public PRINT_CHAR
public SQRT
public Random
;════════════════ Click speaker ═════════════════
Click proc near
xor clicker,010b
mov al,clicker
out 61h,al
ret
click endp
; ══════════════ CLEAR THE SCREEN ( FILL WITH ATTRIBUTES AH ) ════════════
ClrScr proc near
PUSH edi ecx eax es
push fs
pop es
mov edi,0b8000h
cld
xor al,al
mov ecx,2000
rep stosw
POP es eax ecx edi
ret
ClrScr endp
;═════════════════ SCROLL THE SCREEN UP A LINE ══════════════════════
Scroll_Screen proc near
PUSH esi edi ecx eax es
push fs
pop es
mov edi,0b8000h
mov esi,0B8000h+0a0h
cld
mov ecx,1000-40
rep movs dword ptr es:[edi],es:[esi]
; now screen is scrolled up, must clear bottom line
mov ecx,80
cxtln: mov byte ptr es:[0b8000h+(80*24*2)-2+ecx*2],0
loop cxtln
POP es eax ecx edi esi
ret
Scroll_Screen endp
Set_timer proc near
;═══════ SET THE PIT (8253) TIMER NUMBER 0 TO THE VALUE IN AX REGISTER ═════
shl eax,8
mov al,00110100b
out 43h,al
shr eax,8
out 40h,al
mov al,ah
out 40h,al
ret
Set_timer endp
;═════════════════════════PRINT TEXT═══════════════════════════════════
; PRINTS A STRING ON SCREEN ( TEXT MODE 3 )
; Expects edx > offset of string in the data segment
; Cursor_X,Cursor_Y > position (X,Y) on the screen
; ah > attribute byte ( colors )
;NOTE: string ends with a '$'
; Cursor_X is returned with the X position at the end of the string
TEXT proc near
push eax edx
textlop: mov al,[edx]
inc edx
cmp al,'$'
jz exit_text
call print_char
jmp textlop
exit_text: pop edx eax
ret
TEXT ENDP
;════════════════════ PRINT BINARY NUMBER OF THE REGISTER EDX═══════════════
; Similar to the TEXT proc near above
; Expects :
; ah = color
; Cursor_X,Cursor_Y position (X,Y) on the screen
;
binary_Dword proc near ; prints EDX
push ecx
mov ecx,32
jmp binSizeSet
binary_Word proc near ; prints DX
push ecx
mov ecx,16
rol edx,16
jmp binSizeSet
binary_Byte proc near ; prints DL
push ecx
mov ecx,8
rol edx,24
BinSizeSet: push eax
binary_digit:
mov al,'0'
rol edx,1
jnc bin_p_0
mov al,'1'
bin_p_0: call print_char ;prints a char al : color = ah
loop binary_digit
pop eax ecx
ret
Binary_Byte endp
Binary_Word endp
Binary_DWord endp
;═══════════════PRINT HEXIDECIMAL NUMBER OF THE REGISTER EDX═══════════════
; Expects :
; ah = color
; Cursor_X,Cursor_Y position (X,Y) on the screen
;
Hex_Dword proc near ; prints EDX
push ecx
mov ecx,8
jmp strt_hex
Hex_Word proc near ; prints DX
push ecx
mov ecx,4
rol edx,16
jmp strt_hex
Hex_Byte proc near ; prints DL
push ecx
rol edx,24
mov ecx,2
strt_hex:
push esi
HexPrnt: rol edx,4
mov esi,edx
and esi,0fh
mov al,HexChar+esi
call print_char
Loop HexPrnt
pop esi ecx
ret
endp
endp
endp
;═══════════════ PRINT DECIMAL NUMBER OF THE REGISTER EDX ═══════════════
; Expects :
; ah = color
; Cursor_X,Cursor_Y position (X,Y) on the screen
;
DEC_Dword proc near ; prints EDX
push ecx esi edx
mov ESI,9*4
jmp strt_dec
DEC_Word proc near ; prints DX
push ecx esi edx
mov ESI,4*4
and edx,0FFFFh
jmp strt_dec
DEC_Byte proc near ; prints DL
push ecx esi edx
mov ESI,2*4
and edx,0FFh
strt_dec:
push EAX
mov tmpdec_color07,ah ; save color
mov decVal23,EDX
dec83: mov ECX, Dec_diver + ESI
mov eax,decVal23
xor edx,edx
div ECX
mov DecVal23,EDX ; use remainder
; use quot as digit number
add al,'0' ; print digit
mov ah,tmpdec_color07
call print_char
sub ESI,4
jge dec83
pop EAX EDX ESI ECX
ret
endp
endp
endp
;════════════════════ PRINT A CHARACTER ═════════════════════════
; EXPECTS:
; al character to print
; ah attribute byte
; Cursor_X,Cursor_Y position (X,Y) on the screen
PRINT_CHAR proc near
;-- line feed ----------------------------------
cmp al,0Ah
jnz no_feed
inc Cursor_Y ; move curser down a line
jmp char_printed
no_feed: ;-- carage return ------------------------------------
cmp al,0Dh
jnz no_carg
mov Cursor_X,0 ; return curser to start
jmp char_printed
no_carg: ;-- print the character on the screen -----------------
push eax ecx
mov ecx,eax
xor eax,eax
mov eax,80
mul Cursor_Y
add ax,word ptr Cursor_X
mov fs:[0b8000h+2*eax],CX
inc Cursor_X
pop ecx eax
; ----- don't let the curser go off the screen -----------
char_printed: cmp Cursor_X,80
jb k23
mov Cursor_X,0
inc Cursor_Y
k23: cmp Cursor_Y,25
jb k24
call Scroll_Screen
mov Cursor_Y,24
k24: ret
endp
SQRT proc near
;═══════════════════════════════════════════════════════════════════════════
; returns EAX with the SQUARE ROOT of EAX.
;
; Uses newtons method: Xn+1 = Xn - f(Xn) / f'(Xn)
; f'(x) is the derivitive of f(x)
;
; For square routes: f(x) = x*x - ( Root value i.e EAX)
; and f'(x) = 2x
;
;═══════════════════════════════════════════════════════════════════════════
;
mov edi,eax
;----- Get Estimated Root Value ( ebp = rough value of the sqrt of EAX ) ---
bsr ecx,edi ; Get bit number of highest NZ bit
shr cl,1 ; Half this highest bit number
mov ebp,edi ; Rotate Root Value by
shr ebp,cl ; the bit number to get a estimate root.
;----- Main Loop that makes EBP converge to the square root of EDI ------
calc_sqrt_Loop:
push EBP ; save x so can check if x has converged
mov EBX,EBP
shl EBX,1 ; ebx = f'(x) = 2x
mov EAX,EBP
mul EBP
sub EAX,EDI ; eax = f(x) = X*X - Root_value
sbb EDX,0 ; use 64bit subtract
div EBX ; eax = f(Xn) / f'(Xn)
sub EBP,EAX ; ebp = Xn+1 = Xn - f(Xn) / f'(Xn)
pop EAX ; look at old value
cmp EBP,EAX ; loop only if new value is different
jnz calc_sqrt_Loop
;-------------------------- End of Loop --------------------------------
mov eax,ebp ; EBP contians the square root of EDI
ret
;────────────────────────────────────────────────────────────────────────────
endp
Random proc near
;═══════════════════════════════════════════════════════════════════════════
; EAX = a random number CL bits in size
;
;═══════════════════════════════════════════════════════════════════════════
xor eax,eax
mov bl,byte ptr random_init
and bl,1
Gen_bit: ; make n bit numbers
shl eax,1
mov edx,random_init
shr edx,9
xor bl,dl
shr edx,5
xor bl,dl
bt ebx,1
rcr random_init,1
setc bl
or al,bl
dec cl
jnz Gen_bit
ret
;────────────────────────────────────────────────────────────────────────────
endp