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