]> 4ch.mooo.com Git - 16.git/blobdiff - 16/xlib/xmain.asm
wwww
[16.git] / 16 / xlib / xmain.asm
index a8fd41842af94371f7bab962c121641ec57000f3..cdb174fdd42ca48111ad00c4305d7834d618fef1 100755 (executable)
 ;                      and tripple buffering - Tore Jahn Bastiansen\r
 ;                      (toreba@ifi.uio.no) for the\r
 ;-----------------------------------------------------------------------\r
-\r
-\r
 include xlib.inc\r
 include xmain.inc\r
 \r
 \r
-       .data\r
+       _DATA           SEGMENT WORD PUBLIC USE16 'DATA'\r
+;.data\r
 \r
 \r
 ; Mode X CRTC register tweaks for various resolutions\r
 \r
 \r
-LABEL X256Y200 word\r
+X256Y200 LABEL word\r
                db      0e3h    ; dot clock\r
                db      8       ; Number of CRTC Registers to update\r
        dw      05f00h  ; horz total\r
@@ -49,7 +48,7 @@ LABEL X256Y200 word
        dw      200\r
 \r
 \r
-LABEL X256Y240 word\r
+X256Y240 label word\r
        db      0e3h    ; dot clock\r
        db      16      ; Number of CRTC Registers to update\r
        dw      05f00h  ; horz total\r
@@ -157,7 +156,7 @@ X376Y282 label word
        dw      376\r
        dw      282\r
 \r
-LABEL X256Y400 word\r
+X256Y400 label word\r
        db      0e3h    ; dot clock\r
        db      8       ; Number of CRTC Registers to update\r
        dw      05f00h  ; horz total\r
@@ -173,7 +172,7 @@ LABEL X256Y400 word
        dw      400\r
 \r
 \r
-LABEL X256Y480 word\r
+X256Y480 label word\r
        db      0e3h    ; dot clock\r
        db      16      ; Number of CRTC Registers to update\r
                dw      05f00h  ; horz total\r
@@ -439,6 +438,9 @@ PARAM_COUNT equ ($-PARAMS)
 \r
 DoubleScanFlag db ?     ; Flag to indicate double scanned mode\r
 \r
+_DATA          ENDS\r
+\r
+\r
        .code\r
 \r
 ;-------------------------------------------------------------------------\r
@@ -459,7 +461,9 @@ SetLogicalScrWidth proc
        mov   ax,bx                        ; no - set logical width = physical\r
 \r
 @@ValidLogicalWidth:\r
-       shr   ax,3\r
+       shr   ax,1\r
+       shr   ax,1\r
+       shr   ax,1\r
        out   dx,al\r
 \r
        ; The EXACT logical pixel width may not have been possible since\r
@@ -472,10 +476,12 @@ SetLogicalScrWidth proc
        mov   [_RightClip],ax             ; Set default Right clip column\r
                                          ; screen\r
        sub   ax,[_ScrnPhysicalByteWidth] ; Calculate and store Max X position\r
-       shl   ax,2                        ; of physical screen in virtual\r
+       shl   ax,1                        ; of physical screen in virtual\r
+       shl   ax,1                        ; of physical screen in virtual\r
        mov   [_MaxScrollX],ax            ; screen in pixels\r
        mov   ax,bx                       ; set ax to byte width of virt scrn\r
-       shl   ax,2                        ; convert to pixels\r
+       shl   ax,1                        ; convert to pixels\r
+       shl   ax,1                        ; convert to pixels\r
        mov   [_ScrnLogicalPixelWidth],ax ; store virt scrn pixel width\r
        mov   cx,ax                       ; save ax (return value)\r
 \r
@@ -550,7 +556,7 @@ clear_vram endp
 ; parts adapted from M. Abrash code.\r
 ;------------------------------------------------------------------------\r
 _x_set_mode proc\r
-       ARG   mode:word,logicalscrwidth:word\r
+       ;;arg   mode:word,logicalscrwidth:word\r
        push  bp      ;preserve caller's stack frame\r
        mov   bp,sp\r
 \r
@@ -565,7 +571,7 @@ _x_set_mode proc
        mov   cx,PARAM_COUNT\r
        rep   stosb\r
 \r
-       mov   cx,[mode]\r
+       mov   cx,[BP+4]\r
        cmp   cx,LAST_X_MODE        ; have we selected a valid mode\r
        jle   @@ValidMode           ; Yes !\r
 \r
@@ -657,7 +663,8 @@ _x_set_mode proc
        mov   [_SplitScrnScanLine],ax       ; No splitscrn ==\r
                                            ; splitscrn=PhysicalscrnHeight\r
        mov   bx,ax                         ; Copy width for later use\r
-       shr   ax,2                          ; Convert to byte width\r
+       shr   ax,1                          ; Convert to byte width\r
+       shr   ax,1                          ; Convert to byte width\r
        mov   [_ScrnPhysicalByteWidth],ax   ; Store for later use\r
        lodsw                               ; Load Screen Phys. Height\r
        mov   [_ScrnPhysicalHeight],ax      ; Store for later use\r
@@ -665,7 +672,7 @@ _x_set_mode proc
 \r
        ;  Mode X is set, now set the required logical page width.\r
 \r
-       mov     cx,[logicalscrwidth]\r
+       mov     cx,[BP+6]\r
 \r
        call    SetLogicalScrWidth\r
 \r
@@ -687,10 +694,10 @@ _x_set_mode endp
 ; Written by Themie Gouthas\r
 ;----------------------------------------------------------------------\r
 _x_select_default_plane proc\r
-ARG Plane:byte\r
+       ;arg Plane:byte\r
        push bp\r
        mov  bp,sp       ; set up stack frame\r
-       mov  cl,byte ptr [Plane]\r
+       mov  cl,byte ptr [bp+4]\r
 \r
        ; SELECT WRITE PLANE\r
        and  cl,011b              ;CL = plane\r
@@ -727,7 +734,7 @@ _x_select_default_plane endp
 ;----------------------------------------------------------------------\r
 \r
 _x_set_splitscreen proc\r
-       ARG Line:word\r
+       ;arg Line:word\r
        push bp\r
        mov  bp,sp       ; set up stack frame\r
        push si\r
@@ -769,7 +776,7 @@ _x_set_splitscreen proc
        mov  [_PhysicalStartPixelX],ax  ; offset within virtual screen\r
        mov  [_PhysicalStartY],ax\r
        mov  [_SplitScrnActive],TRUE\r
-       mov  ax,[Line]\r
+       mov  ax,[bp+4]\r
        jns  @@NotNeg    ; Check that Split Scrn start scan line is +ve\r
 \r
        mov  ax,0        ; Since -ve set to 0\r
@@ -804,7 +811,10 @@ _x_set_splitscreen proc
 \r
        mov  ah,bh\r
        and  ah,1\r
-       shl  ah,4\r
+       shl  ah,1\r
+       shl  ah,1\r
+       shl  ah,1\r
+       shl  ah,1\r
        mov  al,OVERFLOW     ; Bit 4 of overflow register = Bit 8 of split\r
        out  dx,al           ; screen scan line,\r
        inc  dx              ; So using readability of VGA registers\r
@@ -816,7 +826,9 @@ _x_set_splitscreen proc
        dec  dx\r
        mov  ah,bh\r
        and  ah,2\r
-       ror  ah,3\r
+       ror  ah,1\r
+       ror  ah,1\r
+       ror  ah,1\r
        mov  al,MAX_SCAN_LINE  ; Bit 6 of max scan line register =\r
        out  dx,al             ; Bit 9 of split screen scan line\r
        inc  dx                ; As we did before, update the apropriate\r
@@ -846,9 +858,9 @@ _x_set_splitscreen proc
 \r
        mov  [_ScrnLogicalHeight],ax     ; Save Screen Logical Height\r
        cmp   ax,[_BottomClip]\r
-       jle   @@BottomClipOK             ; Adjust Clip Rectangle if necessary\r
+       jle   @@BottomClipOK2             ; Adjust Clip Rectangle if necessary\r
        mov   [_BottomClip],ax\r
-@@BottomClipOK:\r
+@@BottomClipOK2:\r
        sub  ax,[_SplitScrnScanLine]     ; Update the maximum Y position of\r
        mov  [_MaxScrollY],ax            ; Physical screen in logical screen\r
 \r
@@ -875,14 +887,14 @@ _x_set_splitscreen      endp
 ;------------------------------------------------------------------------\r
 \r
 _x_page_flip proc\r
-       ARG x:word,y:word\r
+       ;arg x:word,y:word\r
        push  bp                  ;preserve caller's stack frame\r
        mov   bp,sp               ;point to local stack frame\r
        push  si\r
 \r
-       mov  si,[x]\r
+       mov  si,[bp+4]\r
        mov  ax,[_ScrnLogicalByteWidth]     ; Calculate Offset increment\r
-       mov  cx,[y]\r
+       mov  cx,[bp+6]\r
        mul  cx                             ; for Y\r
        cmp  [_DoubleBufferActive],TRUE     ; Do we have double buffering ?\r
        je   @@DoubleBuffer\r
@@ -931,14 +943,14 @@ _x_page_flip endp
 ; Parts addapted from M. Abrash code published in DDJ Mag.\r
 ;------------------------------------------------------------------------\r
 _x_set_start_addr proc\r
-       ARG x:word,y:word\r
+       ;arg x:word,y:word\r
        push bp\r
        mov  bp,sp\r
        push si\r
 \r
-       mov  si,[x]\r
+       mov  si,[bp+4]\r
        mov  ax,[_ScrnLogicalByteWidth]     ; Calculate Offset increment\r
-       mov  cx,[y]                         ; for Y\r
+       mov  cx,[bp+6]                         ; for Y\r
        mul  cx\r
        cmp  [_DoubleBufferActive],TRUE     ; Do we have double buffering ?\r
        je   @@PageResolution\r
@@ -958,7 +970,8 @@ PageFlipEntry2:
 \r
 @@AddColumn:\r
        mov  cx,si\r
-       shr  cx,2\r
+       shr  cx,1\r
+       shr  cx,1\r
        mov  [_PhysicalStartByteX],cx\r
        add  ax,cx                          ; add the column offset for X\r
        mov  bh,al                          ; setup CRTC start addr regs and\r
@@ -1052,14 +1065,14 @@ _x_hide_splitscreen proc
        cmp  [_SplitScrnActive],TRUE\r
        je   @@SplitScreenEnabled\r
 \r
-@@error:\r
+@@error0:\r
        mov  [_ErrorValue],ERROR\r
        pop  bp\r
        ret\r
 \r
 @@SplitScreenEnabled:\r
        cmp  [_CurrXMode],4          ; Do nothing for Modes > 2\r
-       jg   @@error\r
+       jg   @@error0\r
        mov  bx,[_ScrnPhysicalHeight]\r
 \r
        mov  ax,[_ScrnLogicalHeight]\r
@@ -1069,10 +1082,10 @@ _x_hide_splitscreen proc
        mov  [_SplitScrnVisibleHeight],ax\r
 \r
        or    [DoubleScanFlag],0\r
-       jz    @@NotDoubleScanned\r
+       jz    @@NotDoubleScanned0\r
        shl   bx,1\r
        dec   bx\r
-@@NotDoubleScanned:\r
+@@NotDoubleScanned0:\r
        ;mov  cl,[DoubleScanFlag]  ; Compensate for double scanned modes\r
        ;shl  bx,cl\r
 \r
@@ -1086,7 +1099,10 @@ _x_hide_splitscreen proc
 \r
        mov  ah,bh\r
        and  ah,1\r
-       shl  ah,4\r
+       shl  ah,1\r
+       shl  ah,1\r
+       shl  ah,1\r
+       shl  ah,1\r
        mov  al,OVERFLOW  ; Bit 4 of overflow register = Bit 8 of split\r
        out  dx,al        ; screen scan line,\r
        inc  dx           ; So using readability of VGA registers\r
@@ -1098,7 +1114,9 @@ _x_hide_splitscreen proc
        dec  dx\r
        mov  ah,bh\r
        and  ah,2\r
-       ror  ah,3\r
+       ror  ah,1\r
+       ror  ah,1\r
+       ror  ah,1\r
        mov  al,MAX_SCAN_LINE  ; Bit 6 of max scan line register =\r
        out  dx,al             ; Bit 9 of split screen scan line\r
        inc  dx                ; As we did before, update the apropriate\r
@@ -1108,7 +1126,7 @@ _x_hide_splitscreen proc
        out  dx,al\r
        sti                  ; Registers are set, so interrupts are safe\r
 \r
-@@done:\r
+@@done0:\r
 \r
        mov  [_ErrorValue],OK\r
        pop  bp\r
@@ -1140,16 +1158,16 @@ _x_show_splitscreen proc
        mov  bp,sp\r
 \r
        cmp  [_SplitScrnActive],TRUE\r
-       je   @@SplitScreenEnabled\r
+       je   @@SplitScreenEnabled0\r
 \r
-@@error:\r
+@@error1:\r
        mov  [_ErrorValue],ERROR\r
        pop  bp\r
        ret\r
 \r
-@@SplitScreenEnabled:\r
+@@SplitScreenEnabled0:\r
        cmp  [_CurrXMode],4          ; Do nothing for Modes > 2\r
-       jg   @@error\r
+       jg   @@error1\r
 \r
        mov  bx,[_SplitScrnScanLine]\r
        mov  ax,[_ScrnLogicalHeight] ; Update Max Scroll Y\r
@@ -1161,10 +1179,10 @@ _x_show_splitscreen proc
        mov  [_SplitScrnVisibleHeight],ax\r
 \r
        or    [DoubleScanFlag],0\r
-       jz    @@NotDoubleScanned\r
+       jz    @@NotDoubleScanned1\r
        shl   bx,1\r
        dec   bx\r
-@@NotDoubleScanned:\r
+@@NotDoubleScanned1:\r
        ;mov  cl,[DoubleScanFlag]  ; Compensate for double scanned modes\r
        ;shl  bx,cl\r
        WaitVsyncStart               ; wait for vertical retrace\r
@@ -1177,7 +1195,10 @@ _x_show_splitscreen proc
 \r
        mov  ah,bh\r
        and  ah,1\r
-       shl  ah,4\r
+       shl  ah,1\r
+       shl  ah,1\r
+       shl  ah,1\r
+       shl  ah,1\r
        mov  al,OVERFLOW  ; Bit 4 of overflow register = Bit 8 of split\r
        out  dx,al        ; screen scan line,\r
        inc  dx           ; So using readability of VGA registers\r
@@ -1189,7 +1210,9 @@ _x_show_splitscreen proc
        dec  dx\r
        mov  ah,bh\r
        and  ah,2\r
-       ror  ah,3\r
+       ror  ah,1\r
+       ror  ah,1\r
+       ror  ah,1\r
        mov  al,MAX_SCAN_LINE  ; Bit 6 of max scan line register =\r
        out  dx,al             ; Bit 9 of split screen scan line\r
        inc  dx                ; As we did before, update the apropriate\r
@@ -1199,7 +1222,7 @@ _x_show_splitscreen proc
        out  dx,al\r
        sti                  ; Registers are set, so interrupts are safe\r
 \r
-@@Done:\r
+@@Done1:\r
        mov  [_ErrorValue],0\r
        pop  bp\r
        ret\r
@@ -1229,24 +1252,24 @@ _x_show_splitscreen endp
 \r
 \r
 _x_adjust_splitscreen proc\r
-       ARG   ScanLine\r
+       ;arg   ScanLine\r
        push bp\r
        mov  bp,sp\r
 \r
        cmp  [_SplitScrnActive],TRUE\r
-       je   @@SplitScreenEnabled\r
+       je   @@SplitScreenEnabled1\r
 \r
-@@error:\r
+@@error2:\r
        mov  [_ErrorValue],ERROR\r
        pop  bp\r
        ret\r
 \r
-@@SplitScreenEnabled:\r
+@@SplitScreenEnabled1:\r
        cmp  [_CurrXMode],4          ; Do nothing for Modes > 2\r
-       jg   @@error\r
-       mov  bx,[ScanLine]            ; Is the required starting scan line\r
+       jg   @@error2\r
+       mov  bx,[bp+4]            ; Is the required starting scan line\r
        cmp  bx,[_SplitScrnScanLine]  ; valid ?\r
-       js   @@Done                   ; No - Then do nothing\r
+       js   @@Done2                   ; No - Then do nothing\r
 \r
 @@ValidScanLine:\r
 \r
@@ -1259,10 +1282,10 @@ _x_adjust_splitscreen proc
        mov  [_SplitScrnVisibleHeight],ax\r
 \r
        or    [DoubleScanFlag],0\r
-       jz    @@NotDoubleScanned\r
+       jz    @@NotDoubleScanned2\r
        shl   bx,1\r
        dec   bx\r
-@@NotDoubleScanned:\r
+@@NotDoubleScanned2:\r
        ;mov  cl,[DoubleScanFlag]   ; Compensate for double scanned modes\r
        ;shl  bx,cl\r
 \r
@@ -1277,7 +1300,10 @@ _x_adjust_splitscreen proc
 \r
        mov  ah,bh\r
        and  ah,1\r
-       shl  ah,4\r
+       shl  ah,1\r
+       shl  ah,1\r
+       shl  ah,1\r
+       shl  ah,1\r
        mov  al,OVERFLOW  ; Bit 4 of overflow register = Bit 8 of split\r
        out  dx,al        ; screen scan line,\r
        inc  dx           ; So using readability of VGA registers\r
@@ -1289,7 +1315,9 @@ _x_adjust_splitscreen proc
        dec  dx\r
        mov  ah,bh\r
        and  ah,2\r
-       ror  ah,3\r
+       ror  ah,1\r
+       ror  ah,1\r
+       ror  ah,1\r
        mov  al,MAX_SCAN_LINE  ; Bit 6 of max scan line register =\r
        out  dx,al             ; Bit 9 of split screen scan line\r
        inc  dx                ; As we did before, update the apropriate\r
@@ -1298,7 +1326,7 @@ _x_adjust_splitscreen proc
        or   al,ah\r
        out  dx,al\r
        sti                    ; Registers are set, so interrupts are safe\r
-@@Done:\r
+@@Done2:\r
        mov  [_ErrorValue],OK\r
        pop   bp\r
        ret\r
@@ -1330,7 +1358,7 @@ _x_adjust_splitscreen endp
 \r
 \r
 _x_set_doublebuffer proc\r
-          ARG PageHeight:word\r
+          ;arg PageHeight:word\r
           push  bp\r
           mov   bp,sp\r
 \r
@@ -1346,7 +1374,7 @@ _x_set_doublebuffer proc
           mov   ax,[_ScrnLogicalHeight] ; Set Maximum D.B. Page height to\r
           shr   ax,1                    ;   _ScrnLogicalHeight / 2\r
 \r
-          mov   bx,[PageHeight]         ; Is the require D.B. Page Height\r
+          mov   bx,[bp+4]         ; Is the require D.B. Page Height\r
           cmp   ax,bx                   ;  > the Maximum  D.B. Page Height ?\r
 \r
           js    @@InvalidHeight         ; no  - jump\r
@@ -1357,9 +1385,9 @@ _x_set_doublebuffer proc
           mov   [_ScrnLogicalHeight],ax    ; Update logical screen height to\r
                                        ;  reflect the height of a D.B. page\r
           cmp   ax,[_BottomClip]\r
-          jle   @@BottomClipOK             ; Adjust Clip Rectangle if necessary\r
+          jle   @@BottomClipOK0             ; Adjust Clip Rectangle if necessary\r
           mov   [_BottomClip],ax\r
-@@BottomClipOK:\r
+@@BottomClipOK0:\r
           push  ax\r
           mul   [_ScrnLogicalByteWidth]    ; Calculate the offset of the second\r
           mov   cx,ax                      ;  D.B. Page in video ram\r
@@ -1410,40 +1438,40 @@ _x_set_doublebuffer endp
 ;------------------------------------------------------------------------\r
 \r
 _x_set_tripplebuffer proc\r
-          ARG PageHeight:word\r
+          ;arg PageHeight:word\r
           push  bp\r
           mov   bp,sp\r
 \r
           cmp   [_DoubleBufferActive],0\r
-          jne   @@Error\r
+          jne   @@Error3\r
           cmp   [_TrippleBufferActive],0\r
-          je    @@OkToContinue\r
-@@Error:\r
+          je    @@OkToContinue3\r
+@@Error3:\r
           mov   [_ErrorValue],ERROR\r
           pop   bp\r
           ret\r
 \r
-@@OkToContinue:\r
+@@OkToContinue3:\r
           mov   [_VisiblePageIdx],0     ; Set visible Page to 0\r
           mov   ax,[_ScrnLogicalHeight] ; Set Maximum T.B. Page height to\r
           mov   bx,3\r
           xor   dx,dx\r
           idiv  bx                      ;   _ScrnLogicalHeight / 3\r
 \r
-          mov   bx,[PageHeight]         ; Is the require T.B. Page Height\r
+          mov   bx,[bp+4]         ; Is the require T.B. Page Height\r
           cmp   ax,bx                   ;  > the Maximum  T.B. Page Height ?\r
 \r
-          js    @@InvalidHeight         ; no  - jump\r
+          js    @@InvalidHeight0         ; no  - jump\r
           mov   ax,bx                   ; yes - Set the T.B. Page height to\r
                                                                         ;       to the maximum allowed.\r
 \r
-@@InvalidHeight:\r
+@@InvalidHeight0:\r
           mov   [_ScrnLogicalHeight],ax    ; Update logical screen height to\r
                                                                                ;  reflect the height of a T.B. page\r
           cmp   ax,[_BottomClip]\r
-          jle   @@BottomClipOK             ; Adjust Clip Rectangle if necessary\r
+          jle   @@BottomClipOK1             ; Adjust Clip Rectangle if necessary\r
           mov   [_BottomClip],ax\r
-@@BottomClipOK:\r
+@@BottomClipOK1:\r
           push  ax\r
           mul   [_ScrnLogicalByteWidth]    ; Calculate the offset of the second\r
           mov   cx,ax                      ;  D.B. Page in video ram\r
@@ -1489,19 +1517,19 @@ _x_set_tripplebuffer endp
 ;------------------------------------------------------------------------\r
 \r
 _x_set_cliprect proc\r
-ARG left:word,top:word,right:word,bottom:word\r
+;arg left:word,top:word,right:word,bottom:word\r
        push  bp\r
        mov   bp,sp\r
-       mov   ax,[left]\r
-       mov   bx,[right]\r
+       mov   ax,[bp+4]\r
+       mov   bx,[bp+8]\r
        cmp   bx,ax\r
        jns   @@CorrectXOrder\r
        xchg  bx,ax\r
 @@CorrectXOrder:\r
        mov   [_LeftClip],ax\r
        mov   [_RightClip],bx\r
-          mov   ax,[top]\r
-       mov   bx,[bottom]\r
+          mov   ax,[bp+6]\r
+       mov   bx,[bp+10]\r
        cmp   bx,ax\r
           jns   @@CorrectYOrder\r
        xchg  bx,ax\r
@@ -1536,4 +1564,4 @@ _x_wait_vsync proc
 _x_wait_vsync endp\r
 \r
 \r
-       end\r
+end\r