X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fmodex%2Fdemos%2Fc%2Fc_utils.asm;h=011820134d532a9d394870f84b4c4a2427ce1a11;hb=0f83b9814824e86433e9ded412db5a7b9cb1efb5;hp=8302561a7c73c7498b87b7c88147a108fa9c3ebe;hpb=19d97c4277378f20c6c756981f4123cdc6cbb32b;p=16.git diff --git a/src/lib/modex/demos/c/c_utils.asm b/src/lib/modex/demos/c/c_utils.asm index 8302561a..01182013 100755 --- a/src/lib/modex/demos/c/c_utils.asm +++ b/src/lib/modex/demos/c/c_utils.asm @@ -4,26 +4,26 @@ PAGE 255, 132 - .MODEL Medium - .286 + .MODEL Huge +; .286 ; ==== MACROS ==== ; macros to PUSH and POP multiple registers -PUSHx MACRO R1, R2, R3, R4, R5, R6, R7, R8 - IFNB - push R1 ; Save R1 - PUSHx R2, R3, R4, R5, R6, R7, R8 - ENDIF -ENDM - -POPx MACRO R1, R2, R3, R4, R5, R6, R7, R8 - IFNB - pop R1 ; Restore R1 - POPx R2, R3, R4, R5, R6, R7, R8 - ENDIF -ENDM +; PUSHx MACRO R1, R2, R3, R4;, R5, R6, R7, R8 +; IFNB +; push R1 ; Save R1 +; PUSHx R2, R3, R4;, R5, R6, R7, R8 +; ENDIF +; ENDM +; +; POPx MACRO R1, R2, R3, R4;, R5, R6, R7, R8 +; IFNB +; pop R1 ; Restore R1 +; POPx R2, R3, R4;, R5, R6, R7, R8 +; ENDIF +; ENDM ; Macro to Clear a Register to 0 @@ -58,6 +58,8 @@ ENDM s EQU SHORT ?x4 EQU ?x3 EQU + ?x2 EQU + ?x1 EQU .Data @@ -82,15 +84,22 @@ CR_LF DB 13, 10 ; the CRLF data PUBLIC DOS_PRINT DP_Stack STRUC - DW ?x4 ; DI, SI, DS, BP + DW ?x1 ; DI, SI, DS, BP + DW ?x1 ; DI, SI, DS, BP + DW ?x1 ; DI, SI, DS, BP + DW ?x1 ; DI, SI, DS, BP DD ? ; Caller DP_Text DD ? ; Far Address of Text to print DP_Stack ENDS DOS_PRINT PROC FAR - - PUSHx BP, DS, SI, DI ; Preserve Important Registers + + ;PUSHx BP, DS, SI, DI ; Preserve Important Registers + push bp + push ds + push si + push di mov BP, SP ; Set up Stack Frame lds DX, [BP].DP_Text ; Get Addr of Text$ descriptor @@ -101,7 +110,7 @@ DOS_PRINT PROC FAR mov SI, DX ; DS:SI = String data @@DP_Scan_it: - + cmp b [SI], 0 ; Null Byte found? je @@DP_Got_Len ; exit loop if so @@ -122,14 +131,18 @@ DOS_PRINT PROC FAR mov DS, AX mov DX, o CR_LF ; Get Addr of CR/LF pair - mov CX, 2 ; 2 Characters to Write + mov CX, 2 ; 2 Characters to Write mov BX, 1 ; 1= DOS Handle for Display mov AH, 40h ; Write Text Function int 21h ; Call DOS to do it - cld ; Reset Direction Flag - POPx DI, SI, DS, BP ; Restore Saved Registers + cld ; Reset Direction Flag + ;POPx DI, SI, DS, BP ; Restore Saved Registers + pop di + pop si + pop ds + pop bp ret 4 ; Exit & Clean Up Stack DOS_PRINT ENDP @@ -138,8 +151,8 @@ DOS_PRINT ENDP ;=========================================== ;void far pascal dos_prints (char far *Text) ;=========================================== -; -; Print Text Directly to DOS console +; +; Print Text Directly to DOS console ; without a trailing CR/LF ; @@ -147,7 +160,11 @@ DOS_PRINT ENDP DOS_PRINTS PROC FAR - PUSHx BP, DS, SI, DI ; Preserve Important Registers + ;PUSHx BP, DS, SI, DI ; Preserve Important Registers + push bp + push ds + push si + push di mov BP, SP ; Set up Stack Frame lds DX, [BP].DP_Text ; Get Addr of Text$ descriptor @@ -158,7 +175,7 @@ DOS_PRINTS PROC FAR mov SI, DX ; DS:SI = String data @@DPS_Scan_it: - + cmp b [SI], 0 ; Null Byte found? je @@DPS_Got_Len ; exit loop if so @@ -175,8 +192,12 @@ DOS_PRINTS PROC FAR int 21h ; Call DOS to do it @DPS_Exit: - cld ; Reset Direction Flag - POPx DI, SI, DS, BP ; Restore Saved Registers + cld ; Reset Direction Flag + ;POPx DI, SI, DS, BP ; Restore Saved Registers + pop di + pop si + pop ds + pop bp ret 2 ; Exit & Clean Up Stack DOS_PRINTS ENDP @@ -192,7 +213,10 @@ DOS_PRINTS ENDP PUBLIC SET_VIDEO_MODE SVM_Stack STRUC - DW ?x4 ; DI, SI, DS, BP + DW ?x1 ; DI, SI, DS, BP + DW ?x1 ; DI, SI, DS, BP + DW ?x1 ; DI, SI, DS, BP + DW ?x1 ; DI, SI, DS, BP DD ? ; Caller SVM_Mode DB ?,? ; Desired Video Mode SVM_Stack ENDS @@ -200,7 +224,11 @@ SVM_Stack ENDS SET_VIDEO_MODE PROC FAR - PUSHx BP, DS, SI, DI ; Preserve Important Registers + ;PUSHx BP, DS, SI, DI ; Preserve Important Registers + push bp + push ds + push si + push di mov BP, SP ; Set up Stack Frame CLR AH ; Function 0 @@ -209,7 +237,11 @@ SET_VIDEO_MODE PROC FAR int 10H ; Change Video Modes @SVM_Exit: - POPx DI, SI, DS, BP ; Restore Saved Registers + ;POPx DI, SI, DS, BP ; Restore Saved Registers + pop di + pop si + pop ds + pop bp ret 2 ; Exit & Clean Up Stack SET_VIDEO_MODE ENDP @@ -226,7 +258,11 @@ SET_VIDEO_MODE ENDP SCAN_KEYBOARD PROC FAR - PUSHx BP, DS, SI, DI ; Preserve Important Registers + ;PUSHx BP, DS, SI, DI ; Preserve Important Registers + push bp + push ds + push si + push di mov AH, 01H ; Function #1 INT 16H ; Call Keyboard Driver @@ -245,8 +281,12 @@ SCAN_KEYBOARD PROC FAR CLR AX ; Return Nil (no Keypress) @SK_Exit: - cld ; Reset Direction Flag - POPx DI, SI, DS, BP ; Restore Saved Registers + cld ; Reset Direction Flag + ;POPx DI, SI, DS, BP ; Restore Saved Registers + pop di + pop si + pop ds + pop bp ret ; Exit & Clean Up Stack SCAN_KEYBOARD ENDP @@ -327,10 +367,10 @@ INIT_RANDOM ENDP ;========================================= ; ; Returns the Integer Square Root of (X) -; Round allows the return value to be rounded to the +; Round allows the return value to be rounded to the ; nearest integer value by passing 0x80. Passing 0 ; return the Integer Portion only. The rounding amound is -; a number from 0 to 1 multiplied by 256, thus +; a number from 0 to 1 multiplied by 256, thus ; 0.5 * 0x100 = 0x80! ; @@ -345,7 +385,9 @@ ISQ_Stack ENDS INT_SQR PROC FAR - PUSHx BP, DI ; Save BP + ;PUSHx BP, DI ; Save BP + push bp + push di mov BP, SP ; Set up Stack Frame xor AX, AX ; {xor eax,eax} @@ -370,14 +412,23 @@ INT_SQR PROC FAR sub DX, BX ; {sub edx,ebx} inc AX ; {inc eax} -@ISQ_S: +@ISQ_S: loop @ISQ_L - add ax, [BP].ISQ_Round ; {add eax,$00008000} + add ax, [BP].ISQ_Round ; {add eax,$00008000} ; {*round* result in hi word: ie. +0.5} - shr ax, 8 ; {shr eax,16} {to ax (result)} - - POPx DI, BP ; Restore Registers + shr ax, 1 ; {shr eax,16} {to ax (result)} + shr ax, 1 ; {shr eax,16} {to ax (result)} + shr ax, 1 ; {shr eax,16} {to ax (result)} + shr ax, 1 ; {shr eax,16} {to ax (result)} + shr ax, 1 ; {shr eax,16} {to ax (result)} + shr ax, 1 ; {shr eax,16} {to ax (result)} + shr ax, 1 ; {shr eax,16} {to ax (result)} + shr ax, 1 ; {shr eax,16} {to ax (result)} + + ;POPx DI, BP ; Restore Registers + pop di + pop bp ret 4 ; Exit INT_SQR ENDP