Hi,
inflater wrote:The problem is:
When trying to write text on console, it works fine, but when i try to read from keyboard (all BIOS ints), it freezes.
Your code has a few problems....
First, can't do this in the mouse interrupt handler:
Code: Select all
data[0] := inportb($60);
data[1] := inportb($60);
data[2] := inportb($60);
You need to get one byte for each IRQ, not more, not less.
Also, you shouldn't access other "things" from within an IRQ handler (like the video BIOS functions).
At the end of every IRQ handler you need to send an EOI to the PIC chip. Because IRQ 12 is connected to both PIC chips you actually need to send an EOI to both of them. To do this, add something like this to the end of your IRQ handler:
Code: Select all
Port[$20] := $20;
Port[$A0] := $20;
If you don't send the EOI, then the PIC chips wont send other (equal or lower priority) IRQs to the CPU.
Lastly, the PIC chips are being used by the BIOS for the timer IRQ, keyboard IRQ, disk drive IRQs, etc. You can't remap the PIC chips without completely breaking the BIOS, unless you do something to trick the BIOS into thinking the IRQs are still the same.
For now, just delete the "{Init8259;}" line in the "mouse_install" procedure so that the PIC chips stays in it's default state. The PS/2 mouse uses IRQ 12, which the BIOS maps to interrupt $74. To install the interrupt handler you'd need to use:
I'm not sure what other problems you've got there, but that's a start....
BTW, to remap the PIC chips (your "Init8259" procedure), I'd recommend using IRQ0 = $68 and IRQ8 = $70. This means that for IRQs 8 to 15 it's the same as the BIOS expects, and you don't need to do anything for them. Then for IRQs 0 to 7 you need to have dummy interrupt handlers that jump to the BIOS's IRQ handlers. For these you need a little assembly:
Code: Select all
dummy_IRQ0:
push ax
push ds
xor ax,ax
mov ds,ax
push word [ (8 + 0) * 4 + 2]
push word [ (8 + 0) * 4]
pop ds
pop ax
retf
dummy_IRQ1:
push ax
push ds
xor ax,ax
mov ds,ax
push word [ (8 + 1) * 4 + 2]
push word [ (8 + 1) * 4]
pop ds
pop ax
retf
dummy_IRQ2:
push ax
push ds
xor ax,ax
mov ds,ax
push word [ (8 + 2) * 4 + 2]
push word [ (8 + 2) * 4]
pop ds
pop ax
retf
Of course I've only shown the dummy handlers for 3 of the IRQs - you should be able to figure out the other 5 of them....
This is a little tricky, and if you can guarantee that any variables you store (in Pascal) can be accessed via. the code segment register (CS) there's an easier way.
First, create an array of 8 pointers and copy the BIOS's IDT entries for IRQs 0 to 7 into this array. Then you can use dumy handlers like this:
Code: Select all
dummy_IRQ0:
jmp far [ cs: <offset_for_array> + 0 * 4 ]
dummy_IRQ1:
jmp far [ cs: <offset_for_array> + 1 * 4 ]
dummy_IRQ2:
jmp far [ cs: <offset_for_array> + 2 * 4 ]
I'm not too sure if CS can be used to access your Pascal code's data though. If your compiler supports different "memory models" (like tiny, small, large, etc) then it might work if you're using the "tiny" memory model (i.e. if your code and data is limited to a single 64 KB segment). Otherwise the easy method will crash the computer and you need the messier method above.
Cheers,
Brendan