]> 4ch.mooo.com Git - 16.git/blob - 16/tweak16/MISC/SETMODEX.ASM
cleaned up the repo from debugging watcom2 ^^
[16.git] / 16 / tweak16 / MISC / SETMODEX.ASM
1 ; This file was taken from Michael Abrash' XSHARP package, a library\r
2 ; for programming mode X (320x240x256).\r
3 \r
4 ; Mode X (320x240, 256 colors) mode set routine. Works on all VGAs.\r
5 ; C near-callable as:\r
6 ;       void Set320x240Mode(void);\r
7 ; Tested with TASM 2.0.\r
8 ; Modified from public-domain mode set code by John Bridges.\r
9 \r
10 SC_INDEX equ    03c4h   ;Sequence Controller Index\r
11 CRTC_INDEX equ  03d4h   ;CRT Controller Index\r
12 MISC_OUTPUT equ 03c2h   ;Miscellaneous Output register\r
13 SCREEN_SEG equ  0a000h  ;segment of display memory in mode X\r
14 \r
15         .model  small\r
16         .data\r
17 ; Index/data pairs for CRT Controller registers that differ between\r
18 ; mode 13h and mode X.\r
19 CRTParms label  word\r
20         dw      00d06h  ;vertical total\r
21         dw      03e07h  ;overflow (bit 8 of vertical counts)\r
22         dw      04109h  ;cell height (2 to double-scan)\r
23         dw      0ea10h  ;v sync start\r
24         dw      0ac11h  ;v sync end and protect cr0-cr7\r
25         dw      0df12h  ;vertical displayed\r
26         dw      00014h  ;turn off dword mode\r
27         dw      0e715h  ;v blank start\r
28         dw      00616h  ;v blank end\r
29         dw      0e317h  ;turn on byte mode\r
30 CRT_PARM_LENGTH equ     (($-CRTParms)/2)\r
31 \r
32         .code\r
33         public  _Set320x240Mode\r
34 _Set320x240Mode proc    near\r
35         push    bp      ;preserve caller's stack frame\r
36         push    si      ;preserve C register vars\r
37         push    di      ; (don't count on BIOS preserving anything)\r
38 \r
39         mov     ax,13h  ;let the BIOS set standard 256-color\r
40         int     10h     ; mode (320x200 linear)\r
41 \r
42         mov     dx,SC_INDEX\r
43         mov     ax,0604h\r
44         out     dx,ax   ;disable chain4 mode\r
45         mov     ax,0100h\r
46         out     dx,ax   ;synchronous reset while switching clocks\r
47 \r
48         mov     dx,MISC_OUTPUT\r
49         mov     al,0e7h\r
50         out     dx,al   ;select 28 MHz dot clock & 60 Hz scanning rate\r
51 \r
52         mov     dx,SC_INDEX\r
53         mov     ax,0300h\r
54         out     dx,ax   ;undo reset (restart sequencer)\r
55 \r
56         mov     dx,CRTC_INDEX ;reprogram the CRT Controller\r
57         mov     al,11h  ;VSync End reg contains register write\r
58         out     dx,al   ; protect bit\r
59         inc     dx      ;CRT Controller Data register\r
60         in      al,dx   ;get current VSync End register setting\r
61         and     al,7fh  ;remove write protect on various\r
62         out     dx,al   ; CRTC registers\r
63         dec     dx      ;CRT Controller Index\r
64         cld\r
65         mov     si,offset CRTParms ;point to CRT parameter table\r
66         mov     cx,CRT_PARM_LENGTH ;# of table entries\r
67 SetCRTParmsLoop:\r
68         lodsw           ;get the next CRT Index/Data pair\r
69         out     dx,ax   ;set the next CRT Index/Data pair\r
70         loop    SetCRTParmsLoop\r
71 \r
72         mov     dx,SC_INDEX\r
73         mov     ax,0f02h\r
74         out     dx,ax   ;enable writes to all four planes\r
75         mov     ax,SCREEN_SEG ;now clear all display memory, 8 pixels\r
76         mov     es,ax         ; at a time\r
77         sub     di,di   ;point ES:DI to display memory\r
78         sub     ax,ax   ;clear to zero-value pixels\r
79         mov     cx,8000h ;# of words in display memory\r
80         rep     stosw   ;clear all of display memory\r
81 \r
82         pop     di      ;restore C register vars\r
83         pop     si\r
84         pop     bp      ;restore caller's stack frame\r
85         ret\r
86 _Set320x240Mode endp\r
87         end\r