flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Calling real mode interrupts from protected mode |
Author |
|
Gomer73 04 May 2004, 20:35
Heres a litte program I made up to call real mode interrupts from protected mode.
Was pretty tough to debug, but it is the basis for my new OS. Didn't see any examples anywhere of how to do it. I guess I could have made the IDT a 16 bit segment which would have saved some code(oh well). Compile it as an .exe and run it from dos. Basically the first digit on the screen toggles whenever an interrupt is being serviced. The second digit is toggled by my protected mode program. Press caps lock to see that the real mode still works(or any other TSR's you might have loaded). Press left shift key to exit to dos.
|
|||||||||||
04 May 2004, 20:35 |
|
ASHLEY4 05 May 2004, 17:49
Nice bit of code Gomer73, Just what i'v been looking for, Can i use some of this code in my OS .
I can exchange it for my atapi driver ASHLEY4. |
|||
05 May 2004, 17:49 |
|
Gomer73 05 May 2004, 19:21
Thanks, go for it, use the code for whatever you like.
I guess the code would be classified as public domain, which would mean no credit required and can be used under any kind of license. I would love to have a look at your ATAPI code. What are some of the specifications of the OS you are building? One thing to not with the interrupt routine. The DS has to be initialized to a base 0 in order for it to work. The push DWORD [0] uses the ds, so no big deal since my DS in protected mode is set to base 0. However if the DS in protected mode is set to something else, you need to initialize the DS to 0 before the push. Here is a modified source code to kind of do a work around for interrupts that require the DS to be set to something. It basically prints a message, waits for a key to be pressed, loads a file and then displays another message. ...Gomer73
|
|||||||||||
05 May 2004, 19:21 |
|
ASHLEY4 06 May 2004, 04:11
Thank Gomer73 , My os is just some test code for a Os i'm making ,this is the spek.
It is loaded from the disk by a boot loader that loads a exe from the floppy, It does these things, Gets the address(as in port) of the first HD and the first CD/DVD, check for vesa, does the a20, remap pic sets GDT,IDT,IT AS A CD/DVD driver with built in cdplayer,a simple keyboard,bmp viwer,time/date, it run's in ring0,it has functions for printing,hex,vesa fonts , put pixel. Alot of the code is not the best,but at least it works. Its made with fasm and is my first bit of code with fasm, You get the whole os called "TestOs.zp" from my temp web site. http://www.falconrybells.co.uk/ Theres also a game in asm (tasm) i made on there. Thanks again ASHLEY4. |
|||
06 May 2004, 04:11 |
|
ASHLEY4 08 May 2004, 02:34
Thank's Gomer73,
You can use any part of the code as you like, But if you could just acknowledge the name's that are in the kernel32.asm file, Then the license is up to you. I tryed to make it so most of the important bit's are in include file's, So people can understand a bit at a time like "A20.inc" etc. My aim is to make a simple 32bit os, with no protection (runs in ring0) ,nopaging (If we keep things small,no need for virtual memory) and calls in stead of int's (should be much faster), Like a 32bit pmode dos with a flat memory model. It will be cli or menu ,rather than a windows type gui. If you want ,We could help one another with our OS's, as you seem to know fasm much better than me. PS: The code was just put in a zip file as it was,So it could be better commented. I have also made a iso, That you can burn on a cd,This is good as no floppy is needed,I can put it on my site if you are interested,or you need to no how it's done Let me know. ASHLEY4. |
|||
08 May 2004, 02:34 |
|
Gomer73 09 May 2004, 20:35
Would be glad to help out.
Time is the big thing for me. Tough to work on an OS, work, and have another additional hobby. I am currently working on a pretty robust keyboard driver. I think it should fulfill all the needs. Supports unicode as well as getting the ascii value and key pressed. Currently right now I think too many OS's get stumped once the the key codes get to be more than one byte. It took some thinking, but I got away around that. Completely programmable by the user so that each key pressed will do 1 of several actions. The actions are as follows: 1. Send and 16 bit ascii code. 2. Toggle a mode(caps lock, num lock) 3. Set/release a mode(shift key, control key) 4. Run a program When a key code is pressed that the keyboard table doesn't recognize, it prompts the user as to what key was pressed and what action to take. It would be nice to build the two OS's together. Mine would include a GUI. Mainly because it is easier to multi-task(run calc and notepad for example). But I also like to be able to easily switch between GUI and Text mode. Got it working without the ISO, so no need, but thanks. |
|||
09 May 2004, 20:35 |
|
ASHLEY4 10 May 2004, 15:06
The keyboard drive sounds great,The keyboard in the zip file is only temp, But in the keyboard driver is a var that switch's the keyboard into a GAMES keyboard, So that up to 128 keys can be pressed at the same time and be registered as a press or as a release on releasing .
This is a good feature, For people who want to make game for your OS . ASHLEY4. |
|||
10 May 2004, 15:06 |
|
Gomer73 10 May 2004, 15:34
That is a good idea, knowing whether a key is currently down or not is a good idea.
Too bad keyboard design doesn't allow multiple keys at the same time. I think certain key combinations won't register. |
|||
10 May 2004, 15:34 |
|
ASHLEY4 10 May 2004, 17:09
THEY DO ,That's what the game keyboard does, upto 128 of them.
I can give you demo code for you to test if you like. ASHLEY4. |
|||
10 May 2004, 17:09 |
|
Tomasz Grysztar 10 May 2004, 17:25
Many (perhaps the most of) keyboards won't send you codes for any more key presses when there are already six or more keys pressed at the same time.
|
|||
10 May 2004, 17:25 |
|
ASHLEY4 10 May 2004, 18:01
Hi Privalov
This is some code useing it in a game, I,v not try it with 128 just assumed,So i will take your word . Code: MOV AL,09h ; Get INT 09h address MOV AH,35h INT 21h MOV [oldint9],BX ; Save it for later MOV [oldint9+2],ES MOV AL,09h ; Set new INT 09h MOV DX,OFFSET Newint9 ; DS:DX = new interrupt MOV AH,25h INT 21h ***************************************************************** maingameloop: call KeyPressed """"""""""""" """""""""""""" jmp maingameloopif not the end call ReStoreInt9 end! ****************************************************************** ;------------------------------------------------------------------------------------------------ ; Installs New Int9 ;------------------------------------------------------------------------------------------------ Newint9 PROC PUSH AX ; Push registers PUSH BX PUSH DS ; CLI MOV AX,CS MOV DS,AX IN AL,60h MOV BX,AX AND BX,007Fh ; switch high bit of BX to zero AND AL,80h ; check high bit of port value JZ Press Release: ; high bit = 1: "release" code MOV KeyDown[bx],00h ; write 00 to "down" array element JMP Done Press: ; high bit = 0: "press" code MOV KeyDown[bx],01h ; write 01 to "down" array element Done: IN AL,61h ; read port 61h, system ctrl port MOV AH,AL ; save value to AH OR AL,80h ; set top bit to "1" - reset kbd OUT 61h,AL ; write out value to port XCHG AH,AL ; put original value back into AL OUT 61h,AL ; rewrite original value in AL MOV AL,20h ; generate End of Interrupt OUT 20h,AL ;STI POP DS ; pop registers POP BX POP AX IRET Newint9 ENDP ;------------------------------------------------------------------------------------------------ ; Check to see if keypressed ;------------------------------------------------------------------------------------------------ KeyPressed PROC TEST [KeyDown+EscKey],1 ; Is ESC held down? JNZ Exit ; Yes, exit TEST [KeyDown+Q],1 ; Is Q down? JZ Next1 ; No, continue CMP PadLY,2 JBE Next1 sub PADLY,2 ; Yes, move left pad up; dec Next1: TEST [KeyDown+A],1 ; Is A down? JZ Next2 ; No, continue CMP PadLY,182 JAE Next2 add PADLY,2 ; Yes, move left pad down;inc Next2: TEST [KeyDown+Down],1 ; Is down arrow down? JZ Next3 ; No, continue CMP PadRY,182 JAE Next3 add PADRY,2 ; Yes, move right pad down;inc Next3: TEST [KeyDown+Up],1 ; Is up arrow down? JZ Next4 ; No, exit CMP PadRY,2 JBE Next4 sub PADRY,2 ; Yes, move right pad up;dec Next4: TEST [KeyDown+W],1 JZ Next5 CMP Ballx,30 JA Next5 CMP BallXstate,2 JE Next5 MOV Bstart,0 Next5: TEST [KeyDown+Left],1 JZ Last1 CMP Ballx,290 JB Last1 CMP BallXstate,1 JE Last1 MOV Bstart,0 Last1: RET KeyPressed ENDP ;------------------------------------------------------------------------------------------------ ; Restores Int9 ;------------------------------------------------------------------------------------------------ ReStoreInt9 PROC MOV AL,09h ; Restore original INT 09h MOV DX,[oldint9] MOV DS,[oldint9+2] ; Move old INT 09H pointer to DS:DX MOV AH,25h INT 21h RET ReStoreInt9 ENDP :=============================data=================================== KeyDown DB 128 dup(0) EscKey EQU 1 ; Escape key scancode Up EQU 48h ; Up arrow Down EQU 50h ; Down arrow Left EQU 4Bh Q EQU 10H A EQU 1EH W EQU 11h oldint9 DW 0,0 ASHLEY4. |
|||
10 May 2004, 18:01 |
|
Gomer73 11 May 2004, 06:00
The limitation has more to do with the way the keyboard is wired rather than the communication protocol to the PC.
For example on my Fujitsu keyboard, if I hold down the a and z keys and try to press the x key it won't work. On my laptop this key combo does work but if I hold down the d and c keys and try pressing the v key, the v key won't display. Just something to keep in mind when programming keyboard games. |
|||
11 May 2004, 06:00 |
|
DennisCGc 11 May 2004, 13:54
Gomer73 wrote: The limitation has more to do with the way the keyboard is wired rather than the communication protocol to the PC. Indeed, this is totally the keyboard its fault. You also have some keyboards, that the key combo SPACE and LEFT ARROW don't support. |
|||
11 May 2004, 13:54 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.