source: xtideuniversalbios/trunk/Configurator/Src/Libraries/menu/prntvram.asm@ 533

Last change on this file since 533 was 293, checked in by krille_n_@…, 13 years ago

Commit 1/2 (Library, Configurators and Serial Server):

  • Changed Emulate.inc so that making 286 and 386 versions now works. Additionally, only one processor type define is needed in the makefile.
  • Minor optimizations.
  • Fixed spelling and did some cleaning.
File size: 5.2 KB
Line 
1; Project name : Print library
2; Description : ASM library for character and string
3; printing using direct access to VRAM.
4;
5; NOT WORKING!!!
6
7;--------------- Equates -----------------------------
8
9%include "BDA.inc" ; For BDA variables
10
11; Int 10h (BIOS) functions
12FN_BIOS_WR_CHAR_TEL EQU 0Eh ; Teletype Output
13
14; Color adapter or Mono adapter segments
15SEG_COLOR EQU 0B800h ; CGA+
16SEG_MONO EQU 0B000h ; MDA, Hercules
17
18
19;-------------- Public functions ---------------------
20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; Return pointer to VRAM for current cursor position.
25;
26; PrntVram_GetPtr
27; Parameters:
28; Nothing
29; Returns:
30; ES:DI: Pointer to cursor location
31; Corrupts registers:
32; AX
33;--------------------------------------------------------------------
34ALIGN JUMP_ALIGN
35PrntVram_GetPtr:
36 push dx
37 xor ax, ax ; Zero AX
38 mov es, ax ; Copy zero to ES (BDA segment)
39
40 ; Calculate offset to VRAM
41 eMOVZX di, [es:BDA.bVidPageIdx] ; Load page index
42 shl di, 1 ; Shift for word lookup
43 mov ax, [es:di+BDA.rgwVidCurPos] ; Load cursor position
44 shl ax, 1 ; Cursor offsets to WORD offsets
45 eMOVZX di, al ; Copy X offset to DI
46 mov al, ah ; Y offset to AL
47 xor ah, ah ; Y offset to AX
48 mul WORD [es:BDA.wVidColumns] ; DX:AX = Y offset * Column cnt
49 add di, [es:BDA.wVidPageOff] ; Add page offset to DI
50 add di, ax ; Add row offset to DI
51
52 ; Get segment to VRAM
53 mov ax, SEG_COLOR ; Assume CGA+
54 cmp BYTE [es:BDA.bVidMode], 7 ; MDA or Hercules?
55 jne .Return ; If not, return
56 mov ax, SEG_MONO
57ALIGN JUMP_ALIGN
58.Return:
59 mov es, ax
60 pop dx
61 ret
62
63
64;--------------------------------------------------------------------
65; Prints character. All character printing functions must
66; use this macro to print characters (so printing implementation
67; can be easily modified when needed).
68;
69; PRINT_CHAR
70; Parameters:
71; DL: Character to print
72; Returns:
73; Nothing
74; Corrupts registers:
75; AX
76;--------------------------------------------------------------------
77%macro PRINT_CHAR 0
78 call PrntVram_TeleChar
79%endmacro
80
81ALIGN JUMP_ALIGN
82PrntVram_TeleChar:
83 cmp dl, 20h ; Printable char?
84 jb .Bios ; If not, use BIOS functions
85 push es
86 push di
87 call PrntVram_GetPtr ; VRAM pointer to ES:DI
88 mov [es:di], dl ; Store character
89 call PtnrVram_IncCursor ; Increment cursor position
90 pop di
91 pop es
92 ret
93ALIGN JUMP_ALIGN
94.Bios:
95 push bp ; Save because of buggy BIOSes
96 push bx
97 mov ah, FN_BIOS_WR_CHAR_TEL
98 mov al, dl ; Copy char to write
99 xor bx, bx ; Page 0
100 int 10h
101 pop bx
102 pop bp
103 ret
104
105ALIGN JUMP_ALIGN
106PtnrVram_IncCursor:
107 push es
108 xor ax, ax ; Zero AX
109 mov es, ax ; Copy zero to ES (BDA segment)
110 mov al, [es:BDA.rgwVidCurPos]
111 inc ax
112 cmp al, [es:BDA.wVidColumns]
113 pop es
114 je .IncRow
115
116 ; Inc column only
117 push dx
118 push cx
119 push bx
120 mov cx, 1
121 call MenuCrsr_Move
122 pop bx
123 pop cx
124 pop dx
125 ret
126ALIGN JUMP_ALIGN
127.IncRow:
128 push dx
129 push cx
130 push bx
131 call MenuCrsr_GetCursor
132 xor dl, dl
133 inc dh
134 call MenuCrsr_SetCursor
135 pop bx
136 pop cx
137 pop dx
138 ret
139
140
141;--------------------------------------------------------------------
142; Prints string. All string printing functions must
143; use this macro to print strings (so printing implementation
144; can be easily modified when needed).
145;
146; PRINT_STR
147; Parameters:
148; DS:DX: Ptr to STOP terminated string
149; Returns:
150; Nothing
151; Corrupts registers:
152; AX
153;--------------------------------------------------------------------
154%macro PRINT_STR 0
155 push dx
156 call Print_VramTeleStr
157 pop dx
158%endmacro
159
160
161;--------------------------------------------------------------------
162; Prints string and returns number of characters printed.
163; All string printing functions must use this macro to print strings
164; (so printing implementation can be easily modified when needed).
165;
166; PRINT_STR_LEN
167; Parameters:
168; DS:DX: Ptr to STOP terminated string
169; Returns:
170; DX: Number of characters printed
171; Corrupts registers:
172; AX
173;--------------------------------------------------------------------
174%macro PRINT_STR_LEN 0
175 call Print_VramTeleStr
176%endmacro
177
178ALIGN JUMP_ALIGN
179Print_VramTeleStr:
180 push es
181 push di
182 push si
183 call PrntVram_GetPtr ; VRAM pointer to ES:DI
184 mov si, dx ; Copy offset to string
185 xor dx, dx ; Zero char counter
186 cld ; STOSB to increment SI and DI
187ALIGN JUMP_ALIGN
188.CharLoop:
189 lodsb ; Load char from [DS:SI] to AL
190 cmp al, 20h ; Printable character?
191 jb .Bios ; If not, use BIOS functions
192
193 push dx
194 mov al, dl
195 PRINT_CHAR
196 pop dx
197
198 ;stosb ; Store char to [ES:DI]
199 inc dx ; Increment chars printed
200 ;inc di ; Skip attribute
201 jmp .CharLoop ; Loop while chars left
202ALIGN JUMP_ALIGN
203.Return:
204 pop si
205 pop di
206 pop es
207 ret
208ALIGN JUMP_ALIGN
209.Bios:
210 cmp al, STOP ; End of string?
211 je .Return ; If so, return
212 push dx
213 mov dl, al
214 PRINT_CHAR
215 pop dx
216 times 2 inc di
217 inc dx ; Increment chars printed
218 jmp .CharLoop ; Loop while chars left
Note: See TracBrowser for help on using the repository browser.