This repository has been archived by the owner on Dec 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathL27-3.ASM
192 lines (183 loc) · 3.84 KB
/
L27-3.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
; Program to illustrate flipping from bit-mapped graphics mode to
; text mode and back without losing any of the graphics bit-map.
;
; Assemble with MASM or TASM
;
; By Michael Abrash
;
Stack segment para stack 'STACK'
db 512 dup(0)
Stack ends
GRAPHICS_SEGMENT equ 0a000h ;mode 10 bit-map segment
TEXT_SEGMENT equ 0b800h ;mode 3 bit-map segment
SC_INDEX equ 3c4h ;Sequence Controller Index register
MAP_MASK equ 2 ;index of Map Mask register
GC_INDEX equ 3ceh ;Graphics Controller Index register
READ_MAP equ 4 ;index of Read Map register
Data segment para common 'DATA'
GStrikeAnyKeyMsg0 label byte
db 0dh, 0ah, 'Graphics mode', 0dh, 0ah
db 'Strike any key to continue...', 0dh, 0ah, '$'
GStrikeAnyKeyMsg1 label byte
db 0dh, 0ah, 'Graphics mode again', 0dh, 0ah
db 'Strike any key to continue...', 0dh, 0ah, '$'
TStrikeAnyKeyMsg label byte
db 0dh, 0ah, 'Text mode', 0dh, 0ah
db 'Strike any key to continue...', 0dh, 0ah, '$'
Plane2Save db 2000h dup (?) ;save area for plane 2 data
; where font gets loaded
CharAttSave db 4000 dup (?) ;save area for memory wiped
; out by character/attribute
; data in text mode
Data ends
Code segment para public 'CODE'
assume cs:Code, ds:Data
Start proc near
mov ax,10h
int 10h ;select video mode 10h (640x350)
;
; Fill the graphics bit-map with a colored pattern.
;
cld
mov ax,GRAPHICS_SEGMENT
mov es,ax
mov ah,3 ;initial fill pattern
mov cx,4 ;four planes to fill
mov dx,SC_INDEX
mov al,MAP_MASK
out dx,al ;leave the SC Index pointing to the
inc dx ; Map Mask register
FillBitMap:
mov al,10h
shr al,cl ;generate map mask for this plane
out dx,al ;set map mask for this plane
sub di,di ;start at offset 0
mov al,ah ;get the fill pattern
push cx ;preserve plane count
mov cx,8000h ;fill 32K words
rep stosw ;do fill for this plane
pop cx ;get back plane count
shl ah,1
shl ah,1
loop FillBitMap
;
; Put up "strike any key" message.
;
mov ax,Data
mov ds,ax
mov dx,offset GStrikeAnyKeyMsg0
mov ah,9
int 21h
;
; Wait for a key.
;
mov ah,01h
int 21h
;
; Save the 8K of plane 2 that will be used by the font.
;
mov dx,GC_INDEX
mov al,READ_MAP
out dx,al
inc dx
mov al,2
out dx,al ;set up to read from plane 2
mov ax,Data
mov es,ax
mov ax,GRAPHICS_SEGMENT
mov ds,ax
sub si,si
mov di,offset Plane2Save
mov cx,2000h/2 ;save 8K (length of default font)
rep movsw
;
; Go to text mode without clearing display memory.
;
mov ax,083h
int 10h
;
; Save the text mode bit-map.
;
mov ax,Data
mov es,ax
mov ax,TEXT_SEGMENT
mov ds,ax
sub si,si
mov di,offset CharAttSave
mov cx,4000/2 ;length of one text screen in words
rep movsw
;
; Fill the text mode screen with dots and put up "strike any key"
; message.
;
mov ax,TEXT_SEGMENT
mov es,ax
sub di,di
mov al,'.' ;fill character
mov ah,7 ;fill attribute
mov cx,4000/2 ;length of one text screen in words
rep stosw
mov ax,Data
mov ds,ax
mov dx,offset TStrikeAnyKeyMsg
mov ah,9
int 21h
;
; Wait for a key.
;
mov ah,01h
int 21h
;
; Restore the text mode screen to the state it was in on entering
; text mode.
;
mov ax,Data
mov ds,ax
mov ax,TEXT_SEGMENT
mov es,ax
mov si,offset CharAttSave
sub di,di
mov cx,4000/2 ;length of one text screen in words
rep movsw
;
; Return to mode 10h without clearing display memory.
;
mov ax,90h
int 10h
;
; Restore the portion of plane 2 that was wiped out by the font.
;
mov dx,SC_INDEX
mov al,MAP_MASK
out dx,al
inc dx
mov al,4
out dx,al ;set up to write to plane 2
mov ax,Data
mov ds,ax
mov ax,GRAPHICS_SEGMENT
mov es,ax
mov si,offset Plane2Save
sub di,di
mov cx,2000h/2 ;restore 8K (length of default font)
rep movsw
;
; Put up "strike any key" message.
;
mov ax,Data
mov ds,ax
mov dx,offset GStrikeAnyKeyMsg1
mov ah,9
int 21h
;
; Wait for a key before returning to text mode and ending.
;
mov ah,01h
int 21h
mov ax,03h
int 10h
mov ah,4ch
int 21h
Start endp
Code ends
end Start