Keyboard input/Obtain a Y or N response: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) No edit summary |
|||
Line 52: | Line 52: | ||
no: db 'No$'</lang> |
no: db 'No$'</lang> |
||
=={{header|8086 Assembly}}== |
|||
<lang asm> .model small |
|||
.stack 1024 |
|||
.data |
|||
include \SrcAll\8086_Macros.asm |
|||
include \SrcDOS\lib\macros\DOS_Macros.asm |
|||
include \SrcDOS\lib\macros\debug_macros.asm |
|||
include \SrcDOS\lib\macros\video_macros.asm |
|||
include \SrcDOS\lib\macros\mouse_macros.asm |
|||
include \SrcDOS\lib\macros\keyboard_macros.asm |
|||
include \SrcDOS\lib\macros\ascii_defs.asm |
|||
.code |
|||
start: |
|||
mov ax,@code |
|||
mov ds,ax |
|||
call PRIMM |
|||
BYTE "Exit program and return to MS-DOS? (Y/N)",0 |
|||
mov ax,0C00h |
|||
int 21h ;flush keyboard buffer |
|||
forever: |
|||
call waitKey |
|||
;returns ASCII code in AL |
|||
and AL,11011111b ;ignore case |
|||
cmp al,"Y" |
|||
jz ReturnToMSDOS |
|||
cmp al,"N" |
|||
jz forever |
|||
;normally this would jump somewhere else but for simplicity it will wait |
|||
;for a yes response. |
|||
jnz forever |
|||
ReturnToMSDOS: |
|||
mov ax,0C00h |
|||
int 21h ;flush keyboard buffer |
|||
mov ax,4C00h |
|||
int 21h ;end program |
|||
;------------------------------------------------------------------- |
|||
; SUBROUTINES |
|||
;------------------------------------------------------------------- |
|||
waitKey: |
|||
mov ah,01h |
|||
int 16h |
|||
jz waitKey |
|||
ret |
|||
;waits until a key is pressed. |
|||
;return: |
|||
; AL = ASCII CODE |
|||
; AH = SCAN CODE (???) |
|||
;------------------------------------------------------------------- |
|||
PrintString: ;Print null-terminated strings |
|||
;input: string address = ds:si |
|||
lodsb ;Load a letter |
|||
cmp al,0 ;Was that letter the terminator? |
|||
jz PrintString_Done ;Yes? then RET |
|||
call PrintChar ;Print to screen |
|||
jmp PrintString ;Repeat |
|||
PrintString_Done: |
|||
ret |
|||
;------------------------------------------------------------------- |
|||
PrintChar: |
|||
push ax |
|||
mov ah,0Eh |
|||
int 10h ;print AL to the screen. |
|||
pop ax |
|||
ret |
|||
;------------------------------------------------------------------- |
|||
PrintSpace: |
|||
mov al,' ' |
|||
jmp PrintChar ;JMP avoids a tail call. |
|||
;ret ;"PrintChar"'s ret will do this for us. |
|||
;------------------------------------------------------------------- |
|||
NewLine: |
|||
push dx |
|||
push ax |
|||
mov ah, 02h |
|||
mov dl, 13 ;CR |
|||
int 21h |
|||
mov dl, 10 ;LF |
|||
int 21h |
|||
pop ax |
|||
pop dx |
|||
ret |
|||
;------------------------------------------------------------------- |
|||
PRIMM: |
|||
pop si |
|||
push ax |
|||
;get return address in si, this is the source offset for |
|||
;the string that will be printed. |
|||
;String must be null terminated. |
|||
push ds |
|||
LoadSegment ds,ax,@code |
|||
call PrintString |
|||
pop ds |
|||
pop ax |
|||
push si |
|||
;PrintString adjusts the return address for us, it is now |
|||
;just after the null terminator. So put it back on the stack. |
|||
ret |
|||
;------------------------------------------------------------------- |
|||
end start</lang> |
|||
=={{header|8th}}== |
=={{header|8th}}== |
||
<lang forth> |
<lang forth> |
||
Line 65: | Line 183: | ||
cr bye |
cr bye |
||
</lang> |
</lang> |
||
=={{header|Ada}}== |
=={{header|Ada}}== |