laeuchli
asked on
Another os question
Once again my wimpy os is having progamming problems. Could some help me debug the code? the last lines don't display right. This code was writen in nasm and will NOT compile under MASM or TASM. Just so you know. Here is the code:
[BITS 16]
[ORG 0]
jmp main
tester dw ''
getkey dw ''
a dw 0
message db ' This is the JesseOS in low RES' ,0
message2 db ' This is the JesseOS in high RES' ,0
message3 db ' Press any key to test getkeyboard' ,0
message4 db ' ',0
message5 db ' You typed' ,0
reboot:
db 0EAH
dw 0000h
dw 0FFFFh
RET
waittillkey:
mov ah,0
int 16h
RET
changeres:
mov ax,4F02h
mov bx,107h
int 0x10
RET
%macro mprintf 1
mov ax,%1
mov [tester] ,ax
call printf
%endmacro
printf:
mov si,[tester]
print@:
lodsb
or al,al
jz done@
mov ah,0eh
mov bx,0007
int 0x10
jmp print@
done@:
RET
%macro mgetkeyboard 1
mov ax,%1
mov [getkey] ,ax
call getkeyboard
%endmacro
getkeyboard:
get_001:
mov di,[getkey]
mov ah,0eh
int 10h
mov cx,15
mov ah,1
int 16h
jz get_002
mov ah,0
int 16h
jmp get_001
get_002:
mov ah,0
int 16h
cmp al,13
je get_003
cmp al,0
jl get_002
cmp al,20
jl get_002
cmp al,126
stosb
mov ah,0eh
int 10h
mov ah,02h
inc dl
dec cx
int 10
jz get_003
jmp get_002
get_003: xor al,al
stosb
RET
main:
mov ax,0x7c0
mov ds,ax
mov es,ax
cli
mov ax,0x9000
mov ss,ax
mov sp,0xffff
sti
mprintf message
call waittillkey
call changeres
mprintf message2
call waittillkey
mprintf message3
mgetkeyboard message4
mprintf message5
mprintf message4
call waittillkey
call reboot
times 510-($-$$) db 0
dw 0xAA55
[BITS 16]
[ORG 0]
jmp main
tester dw ''
getkey dw ''
a dw 0
message db ' This is the JesseOS in low RES' ,0
message2 db ' This is the JesseOS in high RES' ,0
message3 db ' Press any key to test getkeyboard' ,0
message4 db ' ',0
message5 db ' You typed' ,0
reboot:
db 0EAH
dw 0000h
dw 0FFFFh
RET
waittillkey:
mov ah,0
int 16h
RET
changeres:
mov ax,4F02h
mov bx,107h
int 0x10
RET
%macro mprintf 1
mov ax,%1
mov [tester] ,ax
call printf
%endmacro
printf:
mov si,[tester]
print@:
lodsb
or al,al
jz done@
mov ah,0eh
mov bx,0007
int 0x10
jmp print@
done@:
RET
%macro mgetkeyboard 1
mov ax,%1
mov [getkey] ,ax
call getkeyboard
%endmacro
getkeyboard:
get_001:
mov di,[getkey]
mov ah,0eh
int 10h
mov cx,15
mov ah,1
int 16h
jz get_002
mov ah,0
int 16h
jmp get_001
get_002:
mov ah,0
int 16h
cmp al,13
je get_003
cmp al,0
jl get_002
cmp al,20
jl get_002
cmp al,126
stosb
mov ah,0eh
int 10h
mov ah,02h
inc dl
dec cx
int 10
jz get_003
jmp get_002
get_003: xor al,al
stosb
RET
main:
mov ax,0x7c0
mov ds,ax
mov es,ax
cli
mov ax,0x9000
mov ss,ax
mov sp,0xffff
sti
mprintf message
call waittillkey
call changeres
mprintf message2
call waittillkey
mprintf message3
mgetkeyboard message4
mprintf message5
mprintf message4
call waittillkey
call reboot
times 510-($-$$) db 0
dw 0xAA55
ASKER
the problem is that the last to displays don't work right. I don't understand why.
i have some comments and questions about ur getkeyboard procedure.... but in any case, i think ur getkeyboard procedure is like a gets in c?? (as in u get a string until the user presses enter or u reach the limit correct?)
u only allocate space for 1 character in message4 (db ' ', 0 -- 1 character!)
so if u enter more than 1 character, say u enter
1234567890
it'll overwrite message5 and when u display u'll see something like
345678901234567890
i think... could u check that?
your getkeyboard proc; read comments:
get_001:
>> i think this loop is to clear the kb buffer...
mov di,[getkey]
mov ah,0eh
int 10h
>> how come you want to display the characters u clear from the kb buffer?
mov cx,15
>> is this the maximum number of characters u can enter? looks like it
mov ah,1
int 16h
jz get_002
mov ah,0
int 16h
jmp get_001
get_002:
mov ah,0
int 16h
cmp al,13
je get_003
cmp al,0
jl get_002
>> to get rid of ascii 128-255? u don't need this...
cmp al,20
jl get_002
>> cos this does it also...
cmp al,126
stosb
mov ah,0eh
int 10h
>> display the character? ok... is bx set properly?
mov ah,02h
inc dl
dec cx
int 10
>> do u want int 10 or int 10h? they're different... i assume u want int 10h.
in that case, u don't set dl beforehand so how'd u know that the value there is valid?
jz get_003
jmp get_002
get_003: xor al,al
stosb
RET
u only allocate space for 1 character in message4 (db ' ', 0 -- 1 character!)
so if u enter more than 1 character, say u enter
1234567890
it'll overwrite message5 and when u display u'll see something like
345678901234567890
i think... could u check that?
your getkeyboard proc; read comments:
get_001:
>> i think this loop is to clear the kb buffer...
mov di,[getkey]
mov ah,0eh
int 10h
>> how come you want to display the characters u clear from the kb buffer?
mov cx,15
>> is this the maximum number of characters u can enter? looks like it
mov ah,1
int 16h
jz get_002
mov ah,0
int 16h
jmp get_001
get_002:
mov ah,0
int 16h
cmp al,13
je get_003
cmp al,0
jl get_002
>> to get rid of ascii 128-255? u don't need this...
cmp al,20
jl get_002
>> cos this does it also...
cmp al,126
stosb
mov ah,0eh
int 10h
>> display the character? ok... is bx set properly?
mov ah,02h
inc dl
dec cx
int 10
>> do u want int 10 or int 10h? they're different... i assume u want int 10h.
in that case, u don't set dl beforehand so how'd u know that the value there is valid?
jz get_003
jmp get_002
get_003: xor al,al
stosb
RET
ASKER
_lychee_
I will fix the int 10 problem, but the real problem is as you said,the fact that I am overwriting message5. should I define message4 like this?:
message4 db ' ',0
Or do you have a better idea? Thanks for your help.
I will fix the int 10 problem, but the real problem is as you said,the fact that I am overwriting message5. should I define message4 like this?:
message4 db ' ',0
Or do you have a better idea? Thanks for your help.
message4 db ' ', 0 would work....
if u don't include a partition table u can put message4 at the bottom and nothing will go wrong (or is this for a diskette? then nothing will go wrong if u put it below)
if u don't include a partition table u can put message4 at the bottom and nothing will go wrong (or is this for a diskette? then nothing will go wrong if u put it below)
ASKER
ok last question, when I print message3, why does it print with a extra letter added on? Thanks,
Jesse
Jesse
hmmm... i think i need more details... since i can't immediately see the ?error?
the first thing that comes to mind is that it is added during the getkeyboard when it is emptying the buffer, but i'm not sure how this can be...
is the letter added on before or after message3?
if it's after, could u add a 13, 10 after message3 and see if the extra character comes b4 or after the line break? this will help in debugging...
thanx
the first thing that comes to mind is that it is added during the getkeyboard when it is emptying the buffer, but i'm not sure how this can be...
is the letter added on before or after message3?
if it's after, could u add a 13, 10 after message3 and see if the extra character comes b4 or after the line break? this will help in debugging...
thanx
>> cmp al,0
>> jl get_002
This is needed to eliminate extended
keystrokes like F1..Alt-F8..etc...
cmp al,20
jl get_002 is to eliminate keystorkes
from 1..19....
>> jl get_002
This is needed to eliminate extended
keystrokes like F1..Alt-F8..etc...
cmp al,20
jl get_002 is to eliminate keystorkes
from 1..19....
ASKER
the letter after message3 is i.
consistently?
during the printing of message3 or during getkeyboard? (get according to the suggestion mentioned in my prev comment)
try using different keys for the different pauses in ur boot code... and see if it is still i...
i still can't think of anything, esp. if u r not trying anything funny like pressing extended keys...
during the printing of message3 or during getkeyboard? (get according to the suggestion mentioned in my prev comment)
try using different keys for the different pauses in ur boot code... and see if it is still i...
i still can't think of anything, esp. if u r not trying anything funny like pressing extended keys...
ASKER
it is happening consistently, it is always the same key, and it happens before I type in any keys. Why don't you download nasm, and assemble the code. I will up the points.
argh!!!! i am so disgusted with my stupidity.... i noticed the problem when i wrote my first comment but neglected to write it down... (cos i thot the output in ur getkeyboard was a test output...)
notice when u first go into getkeyboard, u use that value of ax to write to the screen.... which happens to contain the address of message4! which is y it is consistent.... (i)
that's part of my first comment... "how come u want to display the characters u clear from the keyboard buffer?"
the solution is to erase off the first int 10h in ur getkeyboard procedure...
notice when u first go into getkeyboard, u use that value of ax to write to the screen.... which happens to contain the address of message4! which is y it is consistent.... (i)
that's part of my first comment... "how come u want to display the characters u clear from the keyboard buffer?"
the solution is to erase off the first int 10h in ur getkeyboard procedure...
ASKER
Thankyouthankyouthankyouth ankyou!!!I t finally works. Please answer the queston, so I can give you the points.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
how can I do that?
i think on each comment (the coloured bar that says Comment) there's a link on the right side saying "Accept comment as answer"
but that's from memory...
but that's from memory...
basically i dun understand ur getkey routine.... displaying?? but inside there, u call int 10 (without the h)... which is ?irq2? so i guess there's at least a problem there....
what do u mean by the last lines? do u mean after the getkey part or after u change resolution?
actually u can reverse the order of message4 and 5 and get rid of the null (0) at message4... then just display message 4....
u can save the ret after the ea 0000 ffff