• C

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




LVL 5
laeuchliAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_lychee_Commented:
well..

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
0
laeuchliAuthor Commented:
the problem is that the last to displays don't work right. I don't understand why.
0
_lychee_Commented:
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
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

laeuchliAuthor Commented:
_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.
0
_lychee_Commented:
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)
0
laeuchliAuthor Commented:
ok last question, when I print message3, why does it print with a extra letter added on? Thanks,
Jesse
0
_lychee_Commented:
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
0
sergelebelCommented:
>>  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....
0
laeuchliAuthor Commented:
the letter after message3 is i.
0
_lychee_Commented:
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...
0
laeuchliAuthor Commented:
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.
0
_lychee_Commented:
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...
0
laeuchliAuthor Commented:
Thankyouthankyouthankyouthankyou!!!It finally works. Please answer the queston, so I can give you the points.
0
_lychee_Commented:
ok... but u can actually select one of the comments as an answer :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
laeuchliAuthor Commented:
how can I do that?
0
_lychee_Commented:
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...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.