]> 4ch.mooo.com Git - 16.git/blob - 16/PCGPE10/ASM2.TXT
modified: 16/DOS_GFX.OBJ
[16.git] / 16 / PCGPE10 / ASM2.TXT
1 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\r
2     ASM2.TXT - intro to keyboard and flow control\r
3 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\r
4     \r
5     Alright.  This bit of code introduces control flow, keyboard input, and \r
6     a way to easily print out one character.\r
7 \r
8 ÄÄÄÄÄÄÄÄ\r
9     First off, lets examine the easiest one: printing a character.\r
10 \r
11     It's like this: you put the character to print in DL, put 2 in AH and\r
12     call interrupt 21h.  Damn easy.\r
13 \r
14 ÄÄÄÄÄÄÄÄ\r
15     Ok, lets look at the next easiest one: keyboard input.\r
16 \r
17     There are quite a few functions related to INT 16h (the keyboard\r
18     interrupt.)  They are:\r
19 \r
20 FUNCTION#\r
21 ---------\r
22 \r
23     0h  -Gets a key from the keyboard buffer.  If there isn't one, it waits\r
24             until there is.\r
25             Returns the SCAN code in ah, and the ASCII translation in AL\r
26 \r
27     1h  -Checks to see if a key is ready to grab.  Sets the zero flag if a\r
28             key is ready to grab.  Grab it with Fn# 0\r
29             This also returns the same info about the key as Fn#0, but does\r
30             not remove it from the buffer.\r
31 \r
32     2h  -Returns the shift flags in al.  They are:\r
33             bit 7 - Insert active\r
34             bit 6 - Caps lock active\r
35             bit 5 - Num Lock active\r
36             bit 4 - Scroll lock active\r
37             bit 3 - Alt pressed\r
38             bit 2 - Ctrl pressed\r
39             bit 1 - Left shift pressed\r
40             bit 0 - right shift pressed\r
41 \r
42     3h  -You can set the Typematic Rate and delay with this function\r
43             registers must be set as follows\r
44             AL = 5\r
45             BH = Delay value (0-3: 250,500,750,1000 millisec)\r
46             BL = Typematic rate (0-1fh) 1fh = slowest (2 chars per sec)\r
47                 0 =fastest (30 chars per second)\r
48 \r
49     4h  -Key Click control - not important\r
50 \r
51     5h  -STUFF the keyboard\r
52         input:\r
53             CH = scan code\r
54             CL = ascii code\r
55 \r
56         output:\r
57             al = 0 no error\r
58             al = 1 keyboard buffer is full\r
59 \r
60    10h  -Same as #0, but its for the extended keyboard.  Checks all the keys.\r
61 \r
62    11h  -Same as #1, but for the extended keyboard.\r
63 \r
64    12h  -Same as #2, but AH contains additional shift flags:\r
65             bit 7 - Sys req pressed\r
66             bit 6 - Caps lock active\r
67             bit 5 - Num Lock active\r
68             bit 4 - Scroll lock active\r
69             bit 3 - Right Alt active\r
70             bit 2 - Right Ctrl active\r
71             bit 1 - Left Alt active\r
72             bit 0 - Right Alt active\r
73         Al is EXACTLY the same as in Fn#2\r
74 \r
75 \r
76 WHERE AH= the function number when you call INT 16h\r
77 \r
78 ÄÄÄÄÄÄÄÄ\r
79     That's neat-o, eh?  Now on to flow controll via CMP and Jcc...\r
80 \r
81 CMP:\r
82 ÄÄÄ\r
83     CMP is the same as SUB, but it does NOT alter any registers, only the\r
84     flags.  This is used in conjunction with Jcc.\r
85 \r
86 Jcc:\r
87 ÄÄÄ\r
88     Ok, Jcc is not a real instruction, it means 'jump if conditionis met.'\r
89 \r
90     I'll break this into 3 sections, comparing signed numbers, comparing \r
91     unsigned numbers, and misc.\r
92 \r
93     Note that a number being 'unsigned' or 'signed' only depends on how you\r
94     treat it.  That's why there are different Jcc for each...\r
95 \r
96     If you treat it as a signed number, the highest bit denotes whether it's\r
97     negative or not.  \r
98     \r
99     Prove to yourself that 0FFFFh is actually -1 by adding 1 to 0FFFFh.  You \r
100     should get a big zero: 00000h.  (Remember that the number is ONLY 16 bits\r
101     and the carry dissapears..)\r
102 \r
103 UNSIGNED:\r
104 ÄÄÄÄÄÄÄÄ\r
105     JA  -jumps if the first number was above the second number\r
106     JAE -same as above, but will also jump if they are equal\r
107 \r
108     JB  -jumps if the first number was below the second\r
109     JBE -duh...\r
110 \r
111     JNA -jumps if the first number was NOT above... (same as JBE)\r
112     JNAE-jumps if the first number was NOT above or the same as..\r
113             (same as JB)\r
114     JNB -jumps if the first number was NOT below... (same as JAE)\r
115     JNBE-jumps if the first number was NOT below or the same as..\r
116             (same as JA)\r
117     JZ  -jumps if the two numbers were equal (zero flag = 1)\r
118     JE  -same as JZ, just a different name\r
119 \r
120     JNZ -pretty obvious, I hope...\r
121     JNE -same as above...\r
122 \r
123 SIGNED:\r
124 ÄÄÄÄÄÄ\r
125     JG  -jumps if the first number was > the second number\r
126     JGE -same as above, but will also jump if they are equal\r
127 \r
128     JL  -jumps if the first number was < the second\r
129     JLE -duh...\r
130 \r
131     JNG -jumps if the first number was NOT >... (same as JLE)\r
132     JNGE-jumps if the first number was NOT >=.. (same as JL)\r
133 \r
134     JNL -jumps if the first number was NOT <... (same as JGE)\r
135     JNLE-jumps if the first number was NOT <=... (same as JG)\r
136 \r
137     JZ, JE, JNZ, JNE - Same as for Unsigned\r
138 \r
139 MISC:\r
140 ÄÄÄÄ\r
141     JC  -jumps if the carry flag is set\r
142     JNC -Go figgure...\r
143 \r
144     Here's the rest of them... I've never had to use these, though...\r
145 \r
146     JO  -jump if overflow flag is set\r
147     JNO -...\r
148 \r
149     JP  -jump is parity flag is set\r
150     JNP -...\r
151     JPE -jump if parity even (same as JP)\r
152     JPO -jump if parity odd (same as JNP)\r
153 \r
154     JS  -jumps if sign flag is set\r
155     JNS -...\r
156 \r
157 \r
158 Here's the flags really quickly:\r
159 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\r
160 bit#    8 7 6 5 4 3 2 1 0\r
161         ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\r
162 symbol: O D I T S Z A P C\r
163 \r
164     O = OverFlow flag\r
165     D = Direction flag  *\r
166     I = Interrupt flag\r
167     T = Trap flag\r
168     S = Sign flag\r
169     Z = Zero flag       *\r
170     A = Auxiliary flag\r
171     C = Carry flag      *\r
172 \r
173 The * denotes the ones that you should know.\r
174 \r
175 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\r
176 \r
177 That's it for now...  Until next time...\r
178 \r
179 Draeden\VLA\r
180 \r
181 \r
182 ÚÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\r
183 ³ ASM2.ASM ³\r
184 ÀÄÄÄÄÄÄÄÄÄÄÙ\r
185 \r
186 ;   ASM2.ASM\r
187 ; Prints messages get keyboard input and has control flow\r
188 \r
189     DOSSEG\r
190     .MODEL SMALL\r
191     .STACK 200h\r
192     .DATA\r
193 \r
194 Prompt      db  13,10,"Do you want to be prompted again? (Y/N) $"\r
195 NoMessage   db  13,10,"Ok, then I won't prompt you anymore.$"\r
196 YesMessage  db  13,10,"Here comes another prompt!$"\r
197 UnKnownKey  db  13,10,"Please hit either Y or N.$"\r
198 \r
199     .CODE\r
200 \r
201 START:\r
202     mov     ax,@DATA    ;moves the segment of data into ax\r
203     mov     ds,ax\r
204 \r
205 MainLoop:\r
206     mov     ah,9\r
207     mov     dx,offset Prompt\r
208     int     21h         ;print a message\r
209 \r
210     mov     ah,0\r
211     int     16h         ;get a key, returned in AX\r
212                         ;AL is the ASCII part\r
213                         ;AH is the SCAN CODE\r
214     push    ax\r
215     mov     dl,al\r
216     mov     ah,2\r
217     int     21h         ;print character in dl\r
218     pop     ax\r
219 \r
220     cmp     al,"Y"      ;was the character a 'Y'?\r
221     jne     NotYes      ;nope it was Not Equal\r
222 \r
223     mov     ah,9\r
224     mov     dx,offset YesMessage\r
225     int     21h\r
226     jmp     MainLoop\r
227 \r
228 NotYes:\r
229     cmp     al,"N"      ;was the character a 'N'\r
230     je      ByeBye      ;Yes, it was Equal\r
231 \r
232     mov     dx,offset UnknownKey\r
233     mov     ah,9\r
234     int     21h\r
235     jmp     MainLoop\r
236 \r
237 ByeBye:\r
238     mov     dx,offset NoMessage\r
239     mov     ah,9\r
240     int     21h\r
241 \r
242     mov     ax,4c00h    ;Returns control to DOS\r
243     int     21h         ;MUST be here! Program will crash without it!\r
244 \r
245 END START\r