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

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