Merge branch 'extra-Rom-path'
This commit is contained in:
commit
0eb0638b8b
8 changed files with 608 additions and 588 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -9,6 +9,5 @@ build.sh
|
|||
run.bat
|
||||
.gdbinit
|
||||
.gdb_history
|
||||
link.ld
|
||||
.gitignore
|
||||
|
||||
*.ld
|
||||
|
|
|
|||
82
src/bda.asm
82
src/bda.asm
|
|
@ -48,42 +48,70 @@
|
|||
; information relative à la souris
|
||||
;
|
||||
|
||||
%define BDA_MOUSE_SEG 0x0050
|
||||
%define BDA_DATA_SEG 0x0050
|
||||
%define BDA_MOUSE 0x0000
|
||||
|
||||
%define BDA_MOUSE_BUFFER 0x0000 ; dword; buffer (jusqu'à 4 octets)
|
||||
%define BDA_MOUSE_IDX 0x0004 ; byte 0..3
|
||||
%define DBA_MOUSE_PACKETLEN 0x0005
|
||||
%define DBA_CURSOR_MASK 0x0006 ; byte pixels mask (bit per pixel)
|
||||
%define BDA_MOUSE_STATUS 0x0007 ; byte
|
||||
%define BDA_MOUSE_X 0x0008 ; word
|
||||
%define BDA_MOUSE_Y 0x000A ; word
|
||||
%define BDA_MOUSE_WHEEL 0x000C ; word
|
||||
struc mouse
|
||||
.buffer resb 4 ; i8042 input buffer
|
||||
.idx resb 1 ; index in the buffer
|
||||
.packetlen resb 1 ; max buffer len (3 ou 4)
|
||||
|
||||
%define BDA_CURSOR_VISIBLE 0x000E ; byte (0/1)
|
||||
%define BDA_CURSOR_OLDX 0x000F ; word
|
||||
%define BDA_CURSOR_OLDY 0x0011 ; word
|
||||
%define BDA_CURSOR_NEWX 0x0013 ; word
|
||||
%define BDA_CURSOR_NEWY 0x0015 ; word
|
||||
%define BDA_CURSOR_BITOFF 0x0017 ; byte 0..7 bits d'offset (x&7)
|
||||
%define BDA_CURSOR_BYTES 0x0019 ; byte 2 ou 3 bytes as source for cursor image
|
||||
%define BDA_CURSOR_SAVED 0x001A ; flag if image saved
|
||||
%define BDA_CURSOR_PTR 0x001B ; pointeur vers l'image du curseur
|
||||
%define BDA_CURSOR_BG 0x0020 ; 48 bytes max (3*16)
|
||||
.status resb 1 ; mouse status (button etc)
|
||||
.wheel resb 1 ; if a packet size is 4; experimental
|
||||
.x resw 1 ;
|
||||
.y resw 1
|
||||
; cursor management
|
||||
.cur_oldx resw 1
|
||||
.cur_oldy resw 1
|
||||
.cur_newx resw 1
|
||||
.cur_newy resw 1
|
||||
.cur_visible resb 1
|
||||
.cur_seg resw 1 ; segment / offset of the pointer
|
||||
.cur_ofs resw 1
|
||||
.cur_mask resb 1 ; pixels mask (bit per pixel)
|
||||
.cur_bit_ofs resb 1 ; 0..7 bits d'offset (x&7)
|
||||
.cur_bytes resb 1 ; byte 2 ou 3 bytes as source for cursor image
|
||||
.bkg_saved resb 1 ; background saved
|
||||
.bkg_buffer resb 48 ; buffer for saved background
|
||||
endstruc
|
||||
|
||||
; -----------------------------------------------------------------------------------
|
||||
; PC components I/O ports
|
||||
; -----------------------------------------------------------------------------------
|
||||
|
||||
; controleur clavier/souris i8042 (AT-PS/2)
|
||||
%define PS2_PORT_BUFFER 0x60
|
||||
%define PS2_PORT_CTRL 0x64
|
||||
%define i8042_PS2_DATA 0x60
|
||||
%define i8042_PS2_CTRL 0x64
|
||||
|
||||
; PIC 8259 ports (Programmable Interrupt Controller)
|
||||
; PIC 1 : Master
|
||||
%define i8259_MASTER_CMD 0x20
|
||||
%define i8259_MASTER_DATA 0x21
|
||||
; PIC 2 : Slave
|
||||
%define i8259_SLAVE_CMD 0xA0
|
||||
%define i8259_SLAVE_DATA 0xA1
|
||||
|
||||
; i8259 Commands
|
||||
%define ICW1_ICW4 0x01 ; Indicates that ICW4 will be present
|
||||
%define ICW1_SINGLE 0x02 ; Single (cascade) mode
|
||||
%define ICW1_INTERVAL4 0x04 ; Call address interval 4 (8)
|
||||
%define ICW1_LEVEL 0x08 ; Level triggered (edge) mode
|
||||
%define ICW1_INIT 0x10 ; Initialization - required!
|
||||
|
||||
%define ICW4_8086 0x01 ; 8086/88 (MCS-80/85) mode
|
||||
%define ICW4_AUTO 0x02 ; Auto (normal) EOI
|
||||
%define ICW4_BUF_SLAVE 0x08 ; Buffered mode/slave
|
||||
%define ICW4_BUF_MASTER 0x0C ; Buffered mode/master
|
||||
%define ICW4_SFNM 0x10 ; Special fully nested (not)
|
||||
%define PIC_EOI 0x20
|
||||
|
||||
; Remap : IRQ0..7 -> 0x08..0x0F, IRQ8..15 -> 0x70..0x77
|
||||
%define i8259_MASTER_INT 0x08
|
||||
%define i8259_SLAVE_INT 0x70
|
||||
|
||||
%define IRQ_ENABLED 0x00
|
||||
%define IRQ_DISABLED 0x01
|
||||
|
||||
; -----------------------------------------------------------------------------------
|
||||
; bda_setup
|
||||
; Initialise la BDA à zéro
|
||||
|
|
@ -92,18 +120,10 @@ bda_setup:
|
|||
pusha
|
||||
push ds
|
||||
|
||||
mov ax, BDA_SEGMENT
|
||||
mov ax, BDA_DATA_SEG
|
||||
mov es, ax
|
||||
|
||||
mov ax, 0
|
||||
mov cx,0xFF
|
||||
xor di, di
|
||||
rep stosb ; clear BDA area
|
||||
|
||||
mov ax, BDA_MOUSE_SEG
|
||||
mov es, ax
|
||||
|
||||
mov ax, 0
|
||||
mov ax, 0x5F
|
||||
mov cx,0xFF
|
||||
xor di, di
|
||||
rep stosb ; clear BDA area
|
||||
|
|
|
|||
209
src/boot-test.asm
Normal file
209
src/boot-test.asm
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
; Compilation: nasm -f bin bios.asm -o bios.bin
|
||||
; Taille: 64 KB
|
||||
|
||||
BITS 16
|
||||
|
||||
section .text
|
||||
org 0x0000
|
||||
|
||||
%define BIOS_DATA_SEG 0x0050
|
||||
|
||||
; ------------------------------------------------------------------
|
||||
; POINT D'ENTRÉE DU BIOS (Cible du jump du reset vector)
|
||||
; ------------------------------------------------------------------
|
||||
start:
|
||||
cli
|
||||
cld
|
||||
xor ax, ax
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov ss, ax
|
||||
mov sp, 0x7000
|
||||
|
||||
; Créer une table "cohérente" de handler
|
||||
call setup_ivt
|
||||
|
||||
; Initialisation du PIC (Indispensable pour IRQ0/IRQ1)
|
||||
mov al, 0x11
|
||||
out 0x20, al
|
||||
out 0xA0, al
|
||||
mov al, 0x08 ; IRQ0-7 -> INT 08h-0Fh
|
||||
out 0x21, al
|
||||
mov al, 0x70 ; IRQ8-15 -> INT 70h-77h
|
||||
out 0xA1, al
|
||||
|
||||
mov al, 0x04
|
||||
out 0x21, al
|
||||
mov al, 0x02
|
||||
out 0xA1, al
|
||||
|
||||
mov al, 0x01
|
||||
out 0x21, al
|
||||
out 0xA1, al
|
||||
|
||||
; Scan et Initialisation des options ROMS (VGA BIOS, etc)
|
||||
call setup_load_rom
|
||||
|
||||
; initialise l'écran en mode texte
|
||||
mov ax,0x0003
|
||||
int 0x10
|
||||
|
||||
; Installation des ISR
|
||||
mov word [0x08*4], timer_isr
|
||||
mov word [0x08*4+2], 0xF000
|
||||
|
||||
mov word [0x09*4], keyboard_isr
|
||||
mov word [0x09*4+2], 0xF000
|
||||
|
||||
; Démasquer IRQ0 et IRQ1
|
||||
mov al, 0xFC
|
||||
out 0x21, al
|
||||
sti
|
||||
|
||||
mov ax, BIOS_DATA_SEG
|
||||
mov es, ax
|
||||
mov di, 0x0 ; Adresse physique de tes variables
|
||||
mov cx, 4
|
||||
xor ax,ax
|
||||
rep stosb ; Met 4 octets à zéro
|
||||
|
||||
main_loop:
|
||||
mov ax,BIOS_DATA_SEG
|
||||
mov fs,ax
|
||||
|
||||
mov al, [fs:0x00] ; Timer
|
||||
mov di, 0
|
||||
call draw_hex_byte
|
||||
|
||||
mov al, [fs:0x01] ; Clavier
|
||||
mov di, 6
|
||||
call draw_hex_byte
|
||||
|
||||
mov al, [fs:0x02] ; Clavier
|
||||
mov di, 12
|
||||
call draw_hex_byte
|
||||
|
||||
jmp main_loop
|
||||
|
||||
; ------------------------------------------------------------------
|
||||
; HANDLERS & HELPERS
|
||||
; ------------------------------------------------------------------
|
||||
default_isr:
|
||||
iret
|
||||
|
||||
|
||||
timer_isr:
|
||||
push ax
|
||||
push gs
|
||||
|
||||
mov ax, BIOS_DATA_SEG
|
||||
mov gs, ax
|
||||
|
||||
inc byte [gs:0x00]
|
||||
|
||||
mov al, 0x20
|
||||
out 0x20, al
|
||||
|
||||
pop gs
|
||||
pop ax
|
||||
iret
|
||||
|
||||
keyboard_isr:
|
||||
push ax
|
||||
push gs
|
||||
|
||||
mov ax, BIOS_DATA_SEG
|
||||
mov gs, ax
|
||||
|
||||
in al, 0x60 ; Ack clavier
|
||||
mov byte [gs:0x02],al
|
||||
|
||||
inc byte [gs:0x01]
|
||||
|
||||
mov al, 0x20
|
||||
out 0x20, al
|
||||
|
||||
pop gs
|
||||
pop ax
|
||||
iret
|
||||
|
||||
draw_hex_byte:
|
||||
push ax
|
||||
|
||||
mov bx, 0xb800
|
||||
mov es,bx
|
||||
|
||||
shr al, 4
|
||||
call .draw_nibble
|
||||
pop ax
|
||||
; add di, 2
|
||||
|
||||
.draw_nibble:
|
||||
and al, 0x0F
|
||||
add al, '0'
|
||||
cmp al, '9'
|
||||
jbe .print
|
||||
add al, 7
|
||||
.print:
|
||||
mov ah, 0x0F ; Blanc sur Noir
|
||||
stosw
|
||||
ret
|
||||
|
||||
; ----------------------------------------------------------------------------
|
||||
; construire une table "vide" de pointeur ISR
|
||||
; ----------------------------------------------------------------------------
|
||||
setup_ivt:
|
||||
; installation de la table d'interrupts
|
||||
xor ax, ax
|
||||
mov es, ax ; ES = 0000h -> base IVT
|
||||
xor di, di ; DI = 0000h -> offset IVT
|
||||
|
||||
mov ax, default_isr ; offset du handler
|
||||
mov dx, cs ; segment du handler (ROM)
|
||||
|
||||
mov cx, 256 ; 256 vecteurs
|
||||
.fill:
|
||||
stosw ; write offset (AX) -> [ES:DI], DI += 2
|
||||
xchg ax, dx ; AX = segment, DX = offset
|
||||
stosw ; write segment (AX) -> [ES:DI], DI += 2
|
||||
xchg ax, dx ; AX = offset, DX = segment
|
||||
loop .fill
|
||||
; fin de la table d'interrupt
|
||||
ret
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Détection les ROM supplementaires
|
||||
; Teste la RAM de 0xC000 jusqu’à 0xE000, par pas de 2KB.
|
||||
;
|
||||
; Si une ROM est détectée, le code de la ROM sera appelé.
|
||||
; ---------------------------------------------------------------------------
|
||||
setup_load_rom:
|
||||
mov bx, 0xC000
|
||||
.scanloop:
|
||||
mov gs, bx
|
||||
cmp word[gs:0x0000],0xAA55 ; ROM signature
|
||||
jne .nextblock
|
||||
|
||||
; appel le code (en 0x0003) de la ROM
|
||||
push cs
|
||||
push word .nextblock ; address de retour
|
||||
|
||||
push bx ; segment
|
||||
push 0x0003 ; offset entry rom
|
||||
retf ; call far ds:0x0003
|
||||
.nextblock:
|
||||
add bx, 0x80 ; add 2kb
|
||||
cmp bx, 0xE000
|
||||
jbe .scanloop
|
||||
ret
|
||||
|
||||
; ------------------------------------------------------------------
|
||||
; Padding jusqu'au reset vector
|
||||
; ------------------------------------------------------------------
|
||||
times 0xFFF0 - ($ - $$) db 0xFF
|
||||
|
||||
|
||||
reset_vector:
|
||||
jmp 0xF000:start
|
||||
db '06/01/2026'
|
||||
db 0 ; le stub tient dans 16 octets (ou moins)
|
||||
95
src/boot.asm
95
src/boot.asm
|
|
@ -29,22 +29,15 @@ bits 16
|
|||
%define DEBUG_PORT 0xe9 ; 0x402 ou 0xe9
|
||||
|
||||
; initial stack
|
||||
%define STACK_SEG 0x0030 ; compatible avec le BMM (Bios Memory Maps)
|
||||
%define STACK_TOP 0x0100 ; choix commun en RAM basse (pile descendante)
|
||||
|
||||
%define MEM_SEG_DEB 0x0800 ; 0x0800:0000 = 0x8000 (32KB) évite IVT/BDA + stack 7C00
|
||||
%define MEM_SEG_END 0xA000 ; 0xA000:0000 = 0xA0000 (début zone vidéo)
|
||||
%define MEM_SEG_STEP 0x0040 ; 1KB = 0x400 bytes = 0x40 paragraphs
|
||||
|
||||
%define STACK_SEG 0x1000 ; segment de base
|
||||
|
||||
section .text
|
||||
bits 16
|
||||
jmp reset ; ce jump n'est pas sensé être executer, il est présent uniquement pour le debug
|
||||
|
||||
; definition du BDA
|
||||
%include "./bda.asm"
|
||||
|
||||
%include "./services/macros.asm"
|
||||
; %include "./services/macros.asm"
|
||||
%include "./drivers/debug.asm"
|
||||
%include "./drivers/gfx_cgam.asm"
|
||||
%include "./drivers/mouse_ps2.asm"
|
||||
|
|
@ -56,28 +49,28 @@ err_vganok db 'VGA Not Initialized',0
|
|||
|
||||
reset:
|
||||
cli
|
||||
cld
|
||||
|
||||
; il n'existe aucun 'stack' par défaut
|
||||
mov ax, STACK_SEG
|
||||
mov ss, ax
|
||||
mov sp, STACK_TOP ; haut du segment, mot-aligné
|
||||
|
||||
; detection de la mémoire totale
|
||||
call ram_setup
|
||||
; modification du stack en "haut" de la RAM
|
||||
mov ax, dx
|
||||
sub ax, 0x0400 ; réserver les 16 dernier KB
|
||||
mov ss, ax
|
||||
mov sp, 0x1000 ; sommet de pile
|
||||
|
||||
; initialisation du BDA
|
||||
call bda_setup
|
||||
mov sp, 0xFFFE ; haut du segment (64ko de stack), mot-aligné
|
||||
|
||||
; installé une table d'interruption "dummy"
|
||||
call ivt_setup
|
||||
|
||||
call bda_setup
|
||||
|
||||
; test IRQ 0
|
||||
mov ax,cs
|
||||
mov dx,ax
|
||||
mov bx,test_isr
|
||||
mov ax,i8259_MASTER_INT
|
||||
|
||||
call ivt_setvector
|
||||
|
||||
; initialisation des PIC 8259A
|
||||
call pic_init
|
||||
sti
|
||||
|
||||
; load Roms
|
||||
call setup_load_rom
|
||||
|
|
@ -85,31 +78,40 @@ reset:
|
|||
; on vérifie que le BIOS VGA a installé une INT 10h
|
||||
call setup_check_vga
|
||||
|
||||
; on active le mode graphique
|
||||
; call gfx_init
|
||||
; on initialise le mode texte 80x25 par défaut DEBUG
|
||||
;mov ax, 0x0003
|
||||
;int 10h
|
||||
|
||||
; enable IRQ 0
|
||||
mov ah,IRQ_ENABLED
|
||||
mov al,0
|
||||
call pic_set_irq_mask
|
||||
|
||||
call kbd_init
|
||||
sti
|
||||
|
||||
call mouse_reset
|
||||
; on active le mode graphique
|
||||
call gfx_init
|
||||
|
||||
;call mouse_reset
|
||||
call mouse_init
|
||||
|
||||
|
||||
|
||||
; on initialise le mode texte 80x25 par défaut DEBUG
|
||||
mov ax, 0x0003
|
||||
int 10h
|
||||
|
||||
endless:
|
||||
mov ax,BDA_DATA_SEG
|
||||
mov ds,ax
|
||||
|
||||
mov dx,0
|
||||
call scr_gotoxy
|
||||
|
||||
mov ax,BDA_MOUSE_SEG
|
||||
mov ds,ax
|
||||
|
||||
mov ax,0 ; adresse début dump
|
||||
mov si,ax
|
||||
mov cx, 0x10
|
||||
mov cx, 0x20
|
||||
.dump:
|
||||
test cx,0x000F
|
||||
jnz .sameline
|
||||
inc dh
|
||||
xor dl,dl
|
||||
call scr_gotoxy
|
||||
.sameline:
|
||||
mov al,[ds:si]
|
||||
inc si
|
||||
|
||||
|
|
@ -127,6 +129,25 @@ endless:
|
|||
|
||||
jmp endless
|
||||
|
||||
|
||||
; -----------------------------------------------------------
|
||||
; Keyboard ISR (IRQ -> INT)
|
||||
; -----------------------------------------------------------
|
||||
test_isr:
|
||||
push ax
|
||||
|
||||
; push fs
|
||||
;mov ax,BDA_DATA_SEG
|
||||
;mov fs,ax
|
||||
;inc byte [fs:0x0005]
|
||||
|
||||
mov al, PIC_EOI ; EOI master
|
||||
out i8259_MASTER_CMD, al
|
||||
; pop fs
|
||||
|
||||
pop ax
|
||||
iret
|
||||
|
||||
; ------------------------------------------------------------------
|
||||
; Padding jusqu'au reset vector
|
||||
; ------------------------------------------------------------------
|
||||
|
|
@ -143,6 +164,6 @@ reset_vector:
|
|||
; code minimal au reset
|
||||
jmp 0xF000:reset
|
||||
builddate db '06/01/2026'
|
||||
times 16-($-$$) db 0 ; le stub tient dans 16 octets (ou moins)
|
||||
times 16-($-$$) db 0 ; le stub tient dans 16 octets (ou moins)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ gfx_init:
|
|||
mov al, GFX_MODE
|
||||
int 0x10
|
||||
|
||||
mov byte [BDA_CURSOR_SAVED],0 ; flag image saved
|
||||
mov byte [BDA_MOUSE + mouse.bkg_saved],0 ; flag image saved
|
||||
|
||||
; dessine un background "check-board"
|
||||
call gfx_background
|
||||
|
|
@ -91,7 +91,7 @@ gfx_calc_addr:
|
|||
; BL = color (0=black, !=0=white)
|
||||
; ------------------------------------------------------------
|
||||
gfx_putpixel:
|
||||
PUSH_ABCD
|
||||
pusha
|
||||
push di
|
||||
push es
|
||||
|
||||
|
|
@ -113,7 +113,7 @@ gfx_putpixel:
|
|||
.done:
|
||||
pop es
|
||||
pop di
|
||||
POP_ABCD
|
||||
popa
|
||||
ret
|
||||
|
||||
; ------------------------------------------------------------
|
||||
|
|
@ -159,13 +159,13 @@ gfx_background:
|
|||
gfx_cursor_calc_align:
|
||||
mov al, cl
|
||||
and al, 7 ; offset = x&7
|
||||
mov byte [BDA_CURSOR_BITOFF], al
|
||||
mov byte [BDA_MOUSE + mouse.cur_bit_ofs], al
|
||||
cmp al, 0
|
||||
jne .unaligned
|
||||
mov byte [BDA_CURSOR_BYTES], 2
|
||||
mov byte [BDA_MOUSE + mouse.cur_bytes], 2
|
||||
ret
|
||||
.unaligned:
|
||||
mov byte [BDA_CURSOR_BYTES], 3
|
||||
mov byte [BDA_MOUSE + mouse.cur_bytes], 3
|
||||
ret
|
||||
|
||||
; ------------------------------------------------------------
|
||||
|
|
@ -206,20 +206,20 @@ gfx_getpixel_fast:
|
|||
gfx_cursor_draw:
|
||||
pusha
|
||||
|
||||
mov ax, BDA_MOUSE_SEG
|
||||
mov ax, BDA_DATA_SEG
|
||||
mov ds, ax
|
||||
mov ax, VIDEO_SEG
|
||||
mov es, ax
|
||||
|
||||
mov ax, word [BDA_CURSOR_PTR]
|
||||
mov ax, word [BDA_MOUSE + mouse.cur_ofs]
|
||||
mov si, ax
|
||||
|
||||
mov cx, word [BDA_CURSOR_NEWX]
|
||||
mov dx, word [BDA_CURSOR_NEWY]
|
||||
mov cx, word [BDA_MOUSE + mouse.cur_newx]
|
||||
mov dx, word [BDA_MOUSE + mouse.cur_newy]
|
||||
|
||||
; calcule offset et bytes/ligne (2 ou 3)
|
||||
call gfx_cursor_calc_align
|
||||
mov bl, byte [BDA_CURSOR_BITOFF]; 0..7
|
||||
mov bl, byte [BDA_MOUSE + mouse.cur_bit_ofs]; 0..7
|
||||
|
||||
; calcule DI de départ (attention: gfx_calc_addr modifie CL)
|
||||
push cx
|
||||
|
|
@ -411,22 +411,22 @@ gfx_cursor_draw:
|
|||
gfx_cursor_savebg:
|
||||
pusha ; sauvegarde registres
|
||||
|
||||
mov ax, BDA_MOUSE_SEG
|
||||
mov ax, BDA_DATA_SEG
|
||||
mov ds, ax
|
||||
|
||||
mov ax, VIDEO_SEG
|
||||
mov es, ax
|
||||
|
||||
cmp byte [BDA_CURSOR_SAVED], 0
|
||||
cmp byte [BDA_MOUSE + mouse.bkg_saved], 0
|
||||
jne .done ; déjà sauvé
|
||||
|
||||
mov cx, [BDA_MOUSE_X]
|
||||
mov dx, [BDA_MOUSE_Y]
|
||||
mov cx, [BDA_MOUSE + mouse.x]
|
||||
mov dx, [BDA_MOUSE + mouse.y]
|
||||
|
||||
mov byte [BDA_CURSOR_SAVED], 1 ; flag image saved
|
||||
mov byte [BDA_MOUSE + mouse.bkg_saved], 1 ; flag image saved
|
||||
|
||||
mov word [BDA_CURSOR_NEWX], cx ; sauvegarde la nouvelle position
|
||||
mov word [BDA_CURSOR_NEWY], dx
|
||||
mov word [BDA_MOUSE + mouse.cur_newx], cx ; sauvegarde la nouvelle position
|
||||
mov word [BDA_MOUSE + mouse.cur_newy], dx
|
||||
|
||||
call gfx_calc_addr ; ES:DI = byteaddr pour (X,Y)
|
||||
mov dx,0x2000 ; offset pour lignes impaire
|
||||
|
|
@ -434,15 +434,15 @@ gfx_cursor_savebg:
|
|||
jl .no_odd_bank
|
||||
neg dx ; Y est déja une ligne impaire, on retire l'offset
|
||||
.no_odd_bank:
|
||||
|
||||
mov si, BDA_CURSOR_BG ; DS:SI = buffer de sauvegarde
|
||||
mov ax, BDA_MOUSE + mouse.bkg_buffer
|
||||
mov si, ax ; DS:SI = buffer de sauvegarde
|
||||
mov bx, 8
|
||||
|
||||
and cx,0x0007 ; alignement X
|
||||
jnz .row3
|
||||
|
||||
.row3: ; sauve 3 bytes/ligne
|
||||
mov byte [BDA_CURSOR_BYTES], 3 ; 3 bytes/ligne
|
||||
mov byte [BDA_MOUSE + mouse.cur_bytes], 3 ; 3 bytes/ligne
|
||||
; ligne 'y', peut etre paire ou impaire
|
||||
mov ax, word [es:di] ; charge first word
|
||||
mov word [ds:si], ax ; sauvegarde
|
||||
|
|
@ -464,7 +464,7 @@ gfx_cursor_savebg:
|
|||
jmp .done
|
||||
|
||||
.row2: ; sauve 2 bytes/ligne
|
||||
mov byte [BDA_CURSOR_BYTES], 2 ; par défaut
|
||||
mov byte [BDA_MOUSE + mouse.cur_bytes], 2 ; par défaut
|
||||
; ligne 'y', peut etre paire ou impaire
|
||||
mov ax, word [es:di] ; charge first word
|
||||
mov word [ds:si], ax ; sauvegarde
|
||||
|
|
@ -491,18 +491,18 @@ gfx_cursor_savebg:
|
|||
gfx_cursor_restorebg:
|
||||
pusha ; sauvegarde registres
|
||||
|
||||
mov ax, BDA_MOUSE_SEG
|
||||
mov ax, BDA_DATA_SEG
|
||||
mov ds, ax
|
||||
|
||||
mov ax, VIDEO_SEG
|
||||
mov es, ax
|
||||
|
||||
cmp byte [BDA_CURSOR_SAVED], 0 ; pas de background sauvé
|
||||
cmp byte [BDA_MOUSE + mouse.bkg_saved], 0 ; pas de background sauvé
|
||||
je .done
|
||||
|
||||
mov cx,word [BDA_CURSOR_OLDX] ; restore de la position
|
||||
mov dx,word [BDA_CURSOR_OLDY]
|
||||
mov byte [BDA_CURSOR_SAVED], 0 ; le background a été restauré
|
||||
mov cx,word [BDA_MOUSE + mouse.cur_oldx] ; restore de la position
|
||||
mov dx,word [BDA_MOUSE + mouse.cur_oldy]
|
||||
mov byte [BDA_MOUSE + mouse.bkg_saved], 0 ; le background a été restauré
|
||||
|
||||
call gfx_calc_addr ; ES:DI = byteaddr pour (X,Y)
|
||||
mov dx,0x2000 ; offset pour lignes impaire
|
||||
|
|
@ -510,10 +510,12 @@ gfx_cursor_restorebg:
|
|||
jl .no_odd_bank
|
||||
neg dx ; Y est déja une ligne impaire, on retire l'offset
|
||||
.no_odd_bank:
|
||||
mov si, BDA_CURSOR_BG ; DS:SI = buffer de sauvegarde
|
||||
|
||||
mov ax, BDA_MOUSE + mouse.bkg_buffer
|
||||
mov si, ax ; DS:SI = buffer de sauvegarde
|
||||
mov bx, 8
|
||||
|
||||
cmp byte [BDA_CURSOR_BYTES], 2 ; si la sauvegarde est en 2 bytes/ligne
|
||||
cmp byte [BDA_MOUSE + mouse.cur_bytes], 2 ; si la sauvegarde est en 2 bytes/ligne
|
||||
je .row2
|
||||
|
||||
.row3: ; restore en 3 bytes/ligne
|
||||
|
|
|
|||
|
|
@ -21,335 +21,62 @@
|
|||
;
|
||||
; =============================================================================
|
||||
|
||||
; -------------------------------
|
||||
; scancode set 1 -> ASCII
|
||||
; index = scancode (0..0x7F)
|
||||
; 0 = non imprimable
|
||||
; -------------------------------
|
||||
kbd_map_nomod:
|
||||
db 0,
|
||||
db 27 ; 01 ESC
|
||||
db '1','2','3','4','5','6','7','8','9','0','-','='
|
||||
db 8 ; 0E Backspace
|
||||
db 9 ; 0F Tab
|
||||
db 'q','w','e','r','t','y','u','i','o','p','[',']'
|
||||
db 13 ; 1C Enter
|
||||
db 0 ; 1D Ctrl
|
||||
db 'a','s','d','f','g','h','j','k','l',';',0x27, 0x60
|
||||
db 0 ; 2A LShift
|
||||
db 0x5c,'z','x','c','v','b','n','m',',','.','/'
|
||||
db 0 ; 36 RShift
|
||||
db '*' ; 37 keypad *
|
||||
db 0 ; 38 Alt
|
||||
db ' ' ; 39 Space
|
||||
times (0x80-($-kbd_map_nomod)) db 0
|
||||
|
||||
kbd_map_shift:
|
||||
db 0
|
||||
db 27
|
||||
db '!','@','#','$','%','^','&','*','(',')','_','+'
|
||||
db 8
|
||||
db 9
|
||||
db 'Q','W','E','R','T','Y','U','I','O','P','{','}'
|
||||
db 13
|
||||
db 0
|
||||
db 'A','S','D','F','G','H','J','K','L',':','"','~'
|
||||
db 0
|
||||
db '|','Z','X','C','V','B','N','M','<','>','?'
|
||||
db 0
|
||||
db '*'
|
||||
db 0
|
||||
db ' '
|
||||
times (0x80-($-kbd_map_shift)) db 0
|
||||
|
||||
; -----------------------------------------------------------
|
||||
; Vérifie si une touche est disponible dans le buffer clavier
|
||||
; Retour: CF=0 si une touche est dispo, CF=1 sinon
|
||||
; -----------------------------------------------------------
|
||||
kbd_kbhit:
|
||||
push ds
|
||||
mov ax, BDA_SEGMENT
|
||||
mov ds, ax
|
||||
mov al, [BDA_KBD_HEAD]
|
||||
cmp al, [BDA_KBD_TAIL]
|
||||
pop ds
|
||||
je .empty
|
||||
clc
|
||||
ret
|
||||
.empty:
|
||||
stc
|
||||
kbd_flush:
|
||||
in al, 0x64 ; Lire le Status Register
|
||||
test al, 1 ; Est-ce qu'il y a une donnée (Output Buffer Full) ?
|
||||
jz .done
|
||||
in al, 0x60 ; Lire et ignorer la donnée
|
||||
jmp kbd_flush
|
||||
.done:
|
||||
ret
|
||||
|
||||
; -----------------------------------------------------------
|
||||
; Lit un caractère du buffer clavier (make+ascii)
|
||||
; Retour: CF=0 si une touche est dispo, AX=word (scancode<<8 | ascii)
|
||||
; CF=1 si aucune touche disponible
|
||||
; -----------------------------------------------------------
|
||||
kbd_poll:
|
||||
push ds
|
||||
mov ax, BDA_SEGMENT
|
||||
mov ds, ax
|
||||
call kbd_buf_pop
|
||||
pop ds
|
||||
ret
|
||||
|
||||
; -----------------------------------------------------------
|
||||
; Lit un caractère du buffer clavier (make+ascii)
|
||||
; Bloque jusqu'à ce qu'une touche soit disponible
|
||||
; Retour: AX=word (scancode<<8 | ascii)
|
||||
; -----------------------------------------------------------
|
||||
kbd_getch:
|
||||
.wait:
|
||||
call kbd_poll
|
||||
jc .wait
|
||||
ret
|
||||
|
||||
; -----------------------------------------------------------
|
||||
; Met à jour les modifiers sur make code
|
||||
; -----------------------------------------------------------
|
||||
kbd_init:
|
||||
push ds
|
||||
push ax
|
||||
|
||||
call kbd_flush
|
||||
|
||||
; gestion du buffer clavier
|
||||
mov ax, BDA_SEGMENT
|
||||
mov ds, ax
|
||||
mov byte [BDA_KBD_HEAD], 0
|
||||
mov byte [BDA_KBD_TAIL], 0
|
||||
mov byte [BDA_KBD_FLAGS], 0
|
||||
|
||||
; installer INT 09h = IRQ1
|
||||
cli
|
||||
xor ax, ax
|
||||
mov ds, ax
|
||||
mov si, 0x09*4
|
||||
mov word [ds:si], kbd_isr
|
||||
mov ax, cs
|
||||
mov word [ds:si+2], ax
|
||||
sti
|
||||
mov ax,cs
|
||||
mov dx,ax
|
||||
mov bx,kbd_isr
|
||||
|
||||
; unmask IRQ1 (master bit1 = 0)
|
||||
in al, i8259_MASTER_DATA
|
||||
and al, 0xFD
|
||||
out i8259_MASTER_DATA, al
|
||||
mov ax, i8259_MASTER_INT ; base offset IRQ0
|
||||
inc ax ; IRQ 1
|
||||
|
||||
call ivt_setvector
|
||||
|
||||
; enable IRQ 1
|
||||
mov ah,IRQ_ENABLED
|
||||
mov al,1
|
||||
call pic_set_irq_mask
|
||||
|
||||
pop ax
|
||||
pop ds
|
||||
ret
|
||||
|
||||
; -----------------------------------------------------------
|
||||
; Met à jour les modifiers sur make code
|
||||
; Entrée: AL = scancode (sans bit7)
|
||||
; -----------------------------------------------------------
|
||||
kbd_buf_push:
|
||||
; In: AX = word à pousser
|
||||
; DS = 0x40
|
||||
push bx
|
||||
push di
|
||||
|
||||
mov bl, [BDA_KBD_HEAD]
|
||||
mov bh, [BDA_KBD_TAIL]
|
||||
|
||||
; next_head = (head+1) & MASK
|
||||
mov dl, bl
|
||||
inc dl
|
||||
and dl, KBD_BUF_MASK
|
||||
|
||||
; si next_head == tail => buffer plein => drop
|
||||
cmp dl, bh
|
||||
je .full
|
||||
|
||||
; écrire à BUF[head]
|
||||
; offset = BDA_KBD_BUF + head*2
|
||||
xor bh, bh
|
||||
mov di, bx
|
||||
shl di, 1
|
||||
add di, BDA_KBD_BUF
|
||||
mov [di], ax
|
||||
|
||||
; head = next_head
|
||||
mov [BDA_KBD_HEAD], dl
|
||||
.full:
|
||||
pop di
|
||||
pop bx
|
||||
ret
|
||||
|
||||
; -----------------------------------------------------------
|
||||
; pop un word du buffer clavier (circulaire)
|
||||
; -----------------------------------------------------------
|
||||
kbd_buf_pop:
|
||||
; Out: CF=1 si vide, sinon AX=word, CF=0
|
||||
; DS=0x40
|
||||
push bx
|
||||
push di
|
||||
|
||||
mov bl, [BDA_KBD_HEAD]
|
||||
mov bh, [BDA_KBD_TAIL]
|
||||
cmp bl, bh
|
||||
je .empty
|
||||
|
||||
; lire BUF[tail]
|
||||
xor bh, bh
|
||||
mov di, bx
|
||||
shl di, 1
|
||||
add di, BDA_KBD_BUF
|
||||
mov ax, [di]
|
||||
|
||||
; tail = (tail+1) & MASK
|
||||
inc bh
|
||||
and bh, KBD_BUF_MASK
|
||||
mov [BDA_KBD_TAIL], bh
|
||||
|
||||
clc
|
||||
pop di
|
||||
pop bx
|
||||
ret
|
||||
.empty:
|
||||
stc
|
||||
pop di
|
||||
pop bx
|
||||
ret
|
||||
|
||||
; -----------------------------------------------------------
|
||||
; Keyboard ISR (INT 09h)
|
||||
; Keyboard ISR (IRQ -> INT)
|
||||
; -----------------------------------------------------------
|
||||
kbd_isr:
|
||||
pusha
|
||||
|
||||
in al, 0x60 ; consomme scancode (obligatoire)
|
||||
|
||||
mov dx, 0x00E9 ; debugcon
|
||||
mov al, '*'
|
||||
out dx, al
|
||||
|
||||
mov al, 0x20 ; EOI master
|
||||
out 0x20, al
|
||||
|
||||
popa
|
||||
iret
|
||||
|
||||
|
||||
; kbd_isr:
|
||||
push ds
|
||||
pusha
|
||||
push ds
|
||||
|
||||
mov ax, BDA_SEGMENT
|
||||
mov ds, ax
|
||||
in al, 0x60 ; consomme scancode (obligatoire)
|
||||
|
||||
in al, PS2_PORT_BUFFER
|
||||
cmp al, 0xE0
|
||||
jne .sc
|
||||
or byte [BDA_KBD_FLAGS], 0x10
|
||||
jmp .eoi
|
||||
mov ax,BDA_DATA_SEG
|
||||
mov ds,ax
|
||||
inc byte [0x0000]
|
||||
|
||||
.sc:
|
||||
mov bl, al
|
||||
mov al, PIC_EOI ; EOI master
|
||||
out i8259_MASTER_CMD, al
|
||||
|
||||
test bl, 0x80
|
||||
jz .make
|
||||
and bl, 0x7F
|
||||
mov al, bl
|
||||
call kbd_update_modifiers_break
|
||||
jmp .clear_eoi
|
||||
|
||||
.make:
|
||||
mov al, bl
|
||||
call kbd_update_modifiers_make
|
||||
|
||||
; filtrer modifiers (ne push pas)
|
||||
cmp bl, 0x2A
|
||||
je .clear_eoi
|
||||
cmp bl, 0x36
|
||||
je .clear_eoi
|
||||
cmp bl, 0x1D
|
||||
je .clear_eoi
|
||||
cmp bl, 0x38
|
||||
je .clear_eoi
|
||||
cmp bl, 0x3A
|
||||
je .clear_eoi
|
||||
|
||||
; scancode -> ASCII
|
||||
mov al, bl
|
||||
xor bh, bh
|
||||
test byte [BDA_KBD_FLAGS], 0x01
|
||||
jz .nomod
|
||||
mov si, kbd_map_shift
|
||||
jmp .doxlat
|
||||
.nomod:
|
||||
mov si, kbd_map_nomod
|
||||
.doxlat:
|
||||
; XLAT uses DS:BX, so set BX = scancode and DS points to table.
|
||||
; On ne veut pas changer DS=0x40. Donc on ne peut pas XLAT directement ici.
|
||||
; => on fait un accès indexé.
|
||||
; AL = [CS:SI + scancode]
|
||||
push ds
|
||||
mov ax, cs
|
||||
mov ds, ax
|
||||
xor ah, ah
|
||||
mov di, si
|
||||
add di, bx
|
||||
mov al, [di]
|
||||
pop ds
|
||||
|
||||
; AX = (scancode<<8) | ascii
|
||||
mov ah, bl
|
||||
call kbd_buf_push
|
||||
|
||||
.clear_eoi:
|
||||
and byte [BDA_KBD_FLAGS], 0xEF ; clear ext
|
||||
.eoi:
|
||||
mov al, i8259_MASTER_CMD
|
||||
out i8259_MASTER_CMD, al
|
||||
pop ds
|
||||
popa
|
||||
pop ds
|
||||
iret
|
||||
|
||||
; -----------------------------------------------------------
|
||||
; Met à jour les modifiers sur make code
|
||||
; Entrée: AL = scancode (sans bit7)
|
||||
; -----------------------------------------------------------
|
||||
kbd_update_modifiers_make:
|
||||
; AL = scancode (make)
|
||||
cmp al, 0x2A
|
||||
je .shift_on
|
||||
cmp al, 0x36
|
||||
je .shift_on
|
||||
cmp al, 0x1D
|
||||
je .ctrl_on
|
||||
cmp al, 0x38
|
||||
je .alt_on
|
||||
cmp al, 0x3A
|
||||
je .caps_toggle
|
||||
ret
|
||||
.shift_on:
|
||||
or byte [BDA_KBD_FLAGS], 0x01
|
||||
ret
|
||||
.ctrl_on:
|
||||
or byte [BDA_KBD_FLAGS], 0x02
|
||||
ret
|
||||
.alt_on:
|
||||
or byte [BDA_KBD_FLAGS], 0x04
|
||||
ret
|
||||
.caps_toggle:
|
||||
xor byte [BDA_KBD_FLAGS], 0x08
|
||||
ret
|
||||
|
||||
kbd_update_modifiers_break:
|
||||
; AL = scancode (break)
|
||||
cmp al, 0x2A
|
||||
je .shift_off
|
||||
cmp al, 0x36
|
||||
je .shift_off
|
||||
cmp al, 0x1D
|
||||
je .ctrl_off
|
||||
cmp al, 0x38
|
||||
je .alt_off
|
||||
ret
|
||||
.shift_off:
|
||||
and byte [BDA_KBD_FLAGS], 0xFE
|
||||
ret
|
||||
.ctrl_off:
|
||||
and byte [BDA_KBD_FLAGS], 0xFD
|
||||
ret
|
||||
.alt_off:
|
||||
and byte [BDA_KBD_FLAGS], 0xFB
|
||||
ret
|
||||
iret
|
||||
|
|
@ -34,8 +34,11 @@
|
|||
%define I8042_CMD_EN_AUX 0xA8
|
||||
%define I8042_CMD_RD_CBYTE 0x20
|
||||
%define I8042_CMD_WR_CBYTE 0x60
|
||||
%define I8042_CMD_DIS_KBD 0xAD
|
||||
%define I8042_CMD_DIS_MOUSE 0xA7
|
||||
%define I8042_CMD_WRITE_AUX 0xD4
|
||||
|
||||
|
||||
%define CURSOR_W 16
|
||||
%define CURSOR_H 16
|
||||
|
||||
|
|
@ -78,26 +81,28 @@ mouse_arrow:
|
|||
;
|
||||
; ------------------------------------------------------------
|
||||
mouse_reset:
|
||||
mov ax, BDA_MOUSE_SEG
|
||||
mov ds,ax
|
||||
mov ax, BDA_DATA_SEG
|
||||
mov fs,ax
|
||||
|
||||
; effacer les variables du drivers
|
||||
mov byte [BDA_MOUSE_IDX],0
|
||||
mov dword [BDA_MOUSE_BUFFER],0
|
||||
mov byte [DBA_MOUSE_PACKETLEN],3
|
||||
mov byte [fs:BDA_MOUSE + mouse.idx],0
|
||||
mov dword [fs:BDA_MOUSE + mouse.buffer],0
|
||||
mov byte [fs:BDA_MOUSE + mouse.packetlen],3
|
||||
|
||||
mov byte [BDA_MOUSE_STATUS],0
|
||||
mov word [BDA_MOUSE_X],320 ; vous pouvez aussi préciser le centre
|
||||
mov word [BDA_MOUSE_Y],100 ; vous pouvez aussi préciser le centre
|
||||
mov byte [fs:BDA_MOUSE + mouse.status],0
|
||||
mov word [fs:BDA_MOUSE + mouse.x],320 ; vous pouvez aussi préciser le centre
|
||||
mov word [fs:BDA_MOUSE + mouse.y],100 ; vous pouvez aussi préciser le centre
|
||||
|
||||
; experiemntal
|
||||
mov word [BDA_MOUSE_WHEEL],0
|
||||
mov word [fs:BDA_MOUSE + mouse.wheel],0
|
||||
|
||||
mov byte [BDA_CURSOR_VISIBLE], 1
|
||||
mov word [BDA_CURSOR_OLDX], 0
|
||||
mov word [BDA_CURSOR_OLDY], 0
|
||||
mov byte [fs:BDA_MOUSE + mouse.cur_visible], 1
|
||||
mov word [fs:BDA_MOUSE + mouse.cur_oldx], 0
|
||||
mov word [fs:BDA_MOUSE + mouse.cur_oldy], 0
|
||||
|
||||
mov word [BDA_CURSOR_PTR], mouse_arrow
|
||||
mov ax, cs
|
||||
mov word [fs:BDA_MOUSE + mouse.cur_seg], ax
|
||||
mov word [fs:BDA_MOUSE + mouse.cur_ofs], mouse_arrow
|
||||
ret
|
||||
|
||||
; ------------------------------------------------------------
|
||||
|
|
@ -112,18 +117,29 @@ mouse_init:
|
|||
; reset des valeurs internes
|
||||
call mouse_reset
|
||||
|
||||
; Activer le port souris
|
||||
call ps2_flush_output
|
||||
cli
|
||||
|
||||
call ps2_wait_ready_write
|
||||
mov al, I8042_CMD_DIS_KBD ; Disable Keyboard
|
||||
out i8042_PS2_CTRL, al
|
||||
|
||||
call ps2_wait_ready_write
|
||||
mov al, I8042_CMD_DIS_MOUSE ; Disable Mouse
|
||||
out i8042_PS2_CTRL, al
|
||||
|
||||
; Vider tout ce qui traîne
|
||||
call ps2_flush_output
|
||||
|
||||
; Activer le port souris (AUX)
|
||||
call ps2_wait_ready_write
|
||||
mov al, I8042_CMD_EN_AUX
|
||||
out PS2_PORT_CTRL, al
|
||||
out i8042_PS2_CTRL, al
|
||||
|
||||
; Lire command byte
|
||||
call ps2_wait_ready_write
|
||||
mov al, I8042_CMD_RD_CBYTE
|
||||
out PS2_PORT_CTRL, al
|
||||
out i8042_PS2_CTRL, al
|
||||
|
||||
call ps2_read ; AL = command byte
|
||||
|
||||
; Activer IRQ12 (bit 1)
|
||||
|
|
@ -133,10 +149,10 @@ mouse_init:
|
|||
; Réécrire command byte (commande 0x60 envoyée à 0x64)
|
||||
call ps2_wait_ready_write
|
||||
mov al, I8042_CMD_WR_CBYTE
|
||||
out PS2_PORT_CTRL, al
|
||||
out i8042_PS2_CTRL, al
|
||||
call ps2_wait_ready_write
|
||||
mov al, ah
|
||||
out PS2_PORT_BUFFER, al
|
||||
out i8042_PS2_DATA, al
|
||||
|
||||
call ps2_flush_output
|
||||
|
||||
|
|
@ -159,24 +175,22 @@ mouse_init:
|
|||
call mouse_detect_packet_len
|
||||
|
||||
; installer ISR IRQ12 (INT 74h)
|
||||
cli
|
||||
|
||||
mov si, 0x74 * 4
|
||||
xor ax, ax
|
||||
mov ds, ax
|
||||
mov ax,cs
|
||||
mov dx,ax
|
||||
mov bx, isr_mouse_handler
|
||||
|
||||
mov word [ds:si], mouse_handler
|
||||
add si, 2
|
||||
mov ax, cs
|
||||
mov word [ds:si], cs
|
||||
mov ax, i8259_SLAVE_INT ; base offset IRQ8
|
||||
add ax,4 ; IRQ 12
|
||||
|
||||
call ivt_setvector
|
||||
|
||||
; enable IRQ 1
|
||||
mov ah,IRQ_ENABLED
|
||||
mov al, 12
|
||||
call pic_set_irq_mask
|
||||
|
||||
sti
|
||||
|
||||
mov dx, 0x00E9
|
||||
mov al, '!'
|
||||
out dx, al
|
||||
|
||||
|
||||
pop ax
|
||||
pop ds
|
||||
ret
|
||||
|
|
@ -188,7 +202,10 @@ out dx, al
|
|||
;
|
||||
; ------------------------------------------------------------
|
||||
mouse_detect_packet_len:
|
||||
mov byte [DBA_MOUSE_PACKETLEN], 3
|
||||
mov ax, BDA_DATA_SEG
|
||||
mov fs,ax
|
||||
|
||||
mov byte [fs:BDA_MOUSE + mouse.packetlen], 3
|
||||
|
||||
; SET_RATE + 200
|
||||
mov bl, MOUSE_SET_RATE
|
||||
|
|
@ -219,7 +236,7 @@ mouse_detect_packet_len:
|
|||
je .is4
|
||||
ret
|
||||
.is4:
|
||||
mov byte [DBA_MOUSE_PACKETLEN], 4
|
||||
mov byte [fs:BDA_MOUSE + mouse.packetlen], 4
|
||||
ret
|
||||
|
||||
; ------------------------------------------------------------
|
||||
|
|
@ -229,16 +246,21 @@ mouse_detect_packet_len:
|
|||
|
||||
; attendre que le 8042 soit pret a recevoir de l'information
|
||||
ps2_wait_ready_write:
|
||||
push cx
|
||||
mov cx, 1000
|
||||
.wait:
|
||||
in al, PS2_PORT_CTRL
|
||||
in al, i8042_PS2_CTRL
|
||||
test al, 02h ; IBF
|
||||
jnz .wait
|
||||
jz .ok
|
||||
loop .wait
|
||||
.ok:
|
||||
pop cx
|
||||
ret
|
||||
|
||||
; attendre que le 8042 soit pret a lire de l'information
|
||||
ps2_wait_ready_read:
|
||||
.wait:
|
||||
in al, PS2_PORT_CTRL
|
||||
in al, i8042_PS2_CTRL
|
||||
test al, 01h ; OBF
|
||||
jz .wait
|
||||
ret
|
||||
|
|
@ -246,16 +268,16 @@ ps2_wait_ready_read:
|
|||
; lire de l'information depuis le 8042
|
||||
ps2_read:
|
||||
call ps2_wait_ready_read
|
||||
in al, PS2_PORT_BUFFER
|
||||
in al, i8042_PS2_DATA
|
||||
ret
|
||||
|
||||
; vide le buffer interne du 8042 (information(s) ignorée(s))
|
||||
ps2_flush_output:
|
||||
.flush:
|
||||
in al, PS2_PORT_CTRL
|
||||
in al, i8042_PS2_CTRL
|
||||
test al, 01h
|
||||
jz .done
|
||||
in al, PS2_PORT_BUFFER
|
||||
in al, i8042_PS2_DATA
|
||||
jmp .flush
|
||||
.done:
|
||||
ret
|
||||
|
|
@ -271,11 +293,11 @@ mouse_sendcmd:
|
|||
call ps2_wait_ready_write
|
||||
|
||||
mov al, I8042_CMD_WRITE_AUX
|
||||
out PS2_PORT_CTRL, al
|
||||
out i8042_PS2_CTRL, al
|
||||
|
||||
call ps2_wait_ready_write
|
||||
mov al, bl
|
||||
out PS2_PORT_BUFFER, al
|
||||
out i8042_PS2_DATA, al
|
||||
|
||||
call ps2_read ; AL = réponse
|
||||
cmp al, MOUSE_ACK
|
||||
|
|
@ -304,102 +326,75 @@ mouse_sendcmd:
|
|||
; bit 6 = X overflow
|
||||
; bit 7 = Y overflow
|
||||
; ------------------------------------------------------------
|
||||
mouse_handler:
|
||||
pusha
|
||||
push ds
|
||||
|
||||
; vider le byte qui a déclenché IRQ12
|
||||
in al, PS2_PORT_BUFFER
|
||||
|
||||
mov dx, 0xE9 ; debugcon
|
||||
mov al, '*'
|
||||
out dx, al ; imprime directement
|
||||
|
||||
; EOI PIC (slave puis master)
|
||||
mov al, 0x20
|
||||
out 0xA0, al
|
||||
out 0x20, al
|
||||
|
||||
pop ds
|
||||
popa
|
||||
iret
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
isr_mouse_handler:
|
||||
; sauvegarder tout les registres
|
||||
pusha
|
||||
push ds
|
||||
|
||||
; use BDA segment
|
||||
mov ax,BDA_MOUSE_SEG
|
||||
mov ax,BDA_DATA_SEG
|
||||
mov ds,ax
|
||||
|
||||
; lire un octet depuis le contrôleur
|
||||
; et le stocker dans le buffer
|
||||
in al, PS2_PORT_BUFFER ; lire octet souris
|
||||
mov byte [BDA_MOUSE_BUFFER + BDA_MOUSE_IDX], al
|
||||
inc byte [BDA_MOUSE_IDX]
|
||||
; lire un octet depuis le contrôleur et le stocker dans le buffer
|
||||
in al, i8042_PS2_DATA ; lire octet souris
|
||||
movzx bx, byte [BDA_MOUSE + mouse.idx]
|
||||
mov byte [BDA_MOUSE + mouse.buffer + bx], al
|
||||
inc byte [BDA_MOUSE + mouse.idx]
|
||||
|
||||
; vérifier si le packet est complet
|
||||
mov al, [DBA_MOUSE_PACKETLEN]
|
||||
cmp byte [BDA_MOUSE_IDX], al
|
||||
mov al, [BDA_MOUSE + mouse.packetlen]
|
||||
cmp byte [BDA_MOUSE + mouse.idx], al
|
||||
jne .done
|
||||
|
||||
; packet complet, on decode les données
|
||||
mov byte [BDA_MOUSE_IDX], 0
|
||||
mov al,'*' ; pour debug
|
||||
call debug_putc
|
||||
mov byte [BDA_MOUSE + mouse.idx], 0
|
||||
mov al, [BDA_MOUSE + mouse.buffer] ; status
|
||||
mov [BDA_MOUSE + mouse.status], al
|
||||
|
||||
|
||||
mov al, [BDA_MOUSE_BUFFER] ; status
|
||||
mov [BDA_MOUSE_STATUS], al
|
||||
|
||||
mov al, [BDA_MOUSE_BUFFER+1] ; delta X
|
||||
mov al, [BDA_MOUSE + mouse.buffer+1] ; delta X
|
||||
cbw
|
||||
add [BDA_MOUSE_X], ax
|
||||
add [BDA_MOUSE + mouse.x], ax
|
||||
|
||||
mov al, [BDA_MOUSE_BUFFER+2] ; delta Y
|
||||
mov al, [BDA_MOUSE + mouse.buffer+2] ; delta Y
|
||||
cbw
|
||||
sub [BDA_MOUSE_Y], ax
|
||||
sub [BDA_MOUSE + mouse.y], ax
|
||||
|
||||
; si packetlen = 4, gérer la molette; experimental
|
||||
mov al, [BDA_MOUSE_BUFFER+3] ; delta Wheel
|
||||
mov al, [BDA_MOUSE + mouse.buffer+3] ; delta Wheel
|
||||
cbw
|
||||
add word [BDA_MOUSE_WHEEL], ax
|
||||
add word [BDA_MOUSE + mouse.wheel], ax
|
||||
|
||||
; clamp X
|
||||
cmp word [BDA_MOUSE_X], 0
|
||||
cmp word [BDA_MOUSE + mouse.x], 0
|
||||
jge .x_ok_low
|
||||
mov word [BDA_MOUSE_X], 0
|
||||
mov word [BDA_MOUSE + mouse.x], 0
|
||||
.x_ok_low:
|
||||
cmp word [BDA_MOUSE_X], 639
|
||||
cmp word [BDA_MOUSE + mouse.x], 639
|
||||
jle .x_ok_high
|
||||
mov word [BDA_MOUSE_X], 639
|
||||
mov word [BDA_MOUSE + mouse.x], 639
|
||||
.x_ok_high:
|
||||
|
||||
; clamp Y
|
||||
cmp word [BDA_MOUSE_Y], 0
|
||||
cmp word [BDA_MOUSE + mouse.y], 0
|
||||
jge .y_ok_low
|
||||
mov word [BDA_MOUSE_Y], 0
|
||||
mov word [BDA_MOUSE + mouse.y], 0
|
||||
.y_ok_low:
|
||||
cmp word [BDA_MOUSE_Y], 199
|
||||
cmp word [BDA_MOUSE + mouse.y], 199
|
||||
jle .y_ok_high
|
||||
mov word [BDA_MOUSE_Y], 199
|
||||
mov word [BDA_MOUSE + mouse.y], 199
|
||||
.y_ok_high:
|
||||
; restaurer l'ancien arrière plan du curseur
|
||||
call gfx_cursor_restorebg
|
||||
;call gfx_cursor_restorebg
|
||||
|
||||
; sauvegarder le nouvel arrière plan du curseur
|
||||
call gfx_cursor_savebg
|
||||
;call gfx_cursor_savebg
|
||||
|
||||
call gfx_cursor_draw
|
||||
;call gfx_cursor_draw
|
||||
|
||||
.done:
|
||||
mov al, 0x20
|
||||
out 0xA0, al ; EOI PIC esclave
|
||||
out 0x20, al ; EOI PIC maître
|
||||
out i8259_SLAVE_CMD, al ; EOI PIC esclave
|
||||
out i8259_MASTER_CMD, al ; EOI PIC maître
|
||||
|
||||
; restaurer tous les registres
|
||||
pop ds
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@
|
|||
;
|
||||
; =============================================================================
|
||||
|
||||
|
||||
%define MEM_SEG_DEB 0x0800 ; 0x0800:0000 = 0x8000 (32KB) évite IVT/BDA + stack 7C00
|
||||
%define MEM_SEG_END 0xA000 ; 0xA000:0000 = 0xA0000 (début zone vidéo)
|
||||
%define MEM_SEG_STEP 0x0040 ; 1KB = 0x400 bytes = 0x40 paragraphs
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Détection RAM conventionnelle
|
||||
|
|
@ -70,7 +72,7 @@ ram_setup:
|
|||
|
||||
.fail_restore:
|
||||
; restaurer avant de sortir
|
||||
mov [es:di], bx
|
||||
mov [es:di], bx
|
||||
|
||||
.done:
|
||||
; AX contient le nb de KB valides *à partir de MEM_SEG_DEB*.
|
||||
|
|
@ -87,7 +89,7 @@ ram_setup:
|
|||
mov bx, BDA_SEGMENT
|
||||
mov ds, bx
|
||||
mov [BDA_INFO_MEM_SIZE], ax
|
||||
mov [BDA_INFO_MEM_SEG],dx
|
||||
mov [BDA_INFO_MEM_SEG], dx
|
||||
|
||||
ret
|
||||
|
||||
|
|
@ -98,27 +100,23 @@ ram_setup:
|
|||
; Si une ROM est détectée, le code de la ROM sera appelé.
|
||||
; ---------------------------------------------------------------------------
|
||||
setup_load_rom:
|
||||
mov bx, 0xC000
|
||||
mov bx, 0xC000
|
||||
.scanloop:
|
||||
mov ds, bx
|
||||
cmp word[0x0000],0xAA55 ; ROM signature
|
||||
jne .norom
|
||||
|
||||
; Debug
|
||||
mov al,'.'
|
||||
call debug_putc
|
||||
mov ds, bx
|
||||
cmp word[0x0000],0xAA55 ; ROM signature
|
||||
jne .norom
|
||||
|
||||
; appel le code (en 0x0003) de la ROM
|
||||
push cs
|
||||
push word .norom ; address de retour
|
||||
push cs
|
||||
push word .norom ; address de retour
|
||||
|
||||
push ds
|
||||
push 0x0003
|
||||
push ds
|
||||
push 0x0003
|
||||
retf ; call far ds:0x0003
|
||||
.norom:
|
||||
add bx, 0x80 ; add 2kb
|
||||
cmp bx, 0xE000
|
||||
jbe .scanloop
|
||||
add bx, 0x80 ; add 2kb
|
||||
cmp bx, 0xE000
|
||||
jbe .scanloop
|
||||
.end:
|
||||
ret
|
||||
|
||||
|
|
@ -130,25 +128,22 @@ setup_load_rom:
|
|||
; ---------------------------------------------------------------------------
|
||||
setup_check_vga:
|
||||
; vérification de l'offset 0x0000:0x0040 qui DOIT etre différent de @default_isr
|
||||
xor ax,ax
|
||||
mov es,ax
|
||||
xor ax,ax
|
||||
mov es,ax
|
||||
; Lire INT10: offset+segment depuis 0000:0040
|
||||
mov bx, [es:0x0040] ; BX = offset INT10
|
||||
mov cx, [es:0x0042] ; CX = segment INT10
|
||||
mov ax, cs
|
||||
mov bx, [es:0x0040] ; BX = offset INT10
|
||||
mov cx, [es:0x0042] ; CX = segment INT10
|
||||
mov ax, cs
|
||||
|
||||
; Comparer avec default_isr (offset) et CS (segment)
|
||||
mov dx, default_isr ; DX = offset default_isr (dans notre CS)
|
||||
cmp bx, dx
|
||||
jne .init_ok ; vecteur different, bios initialisé
|
||||
cmp cx, ax
|
||||
jne .init_ok
|
||||
mov dx, default_isr ; DX = offset default_isr (dans notre CS)
|
||||
cmp bx, dx
|
||||
jne .init_ok ; vecteur different, bios initialisé
|
||||
cmp cx, ax
|
||||
jne .init_ok
|
||||
|
||||
mov ax,cs ; vecteur identique, sans doute pas d'initialisation
|
||||
mov ds,ax
|
||||
|
||||
mov si, err_vganok
|
||||
call debug_puts
|
||||
mov ax,cs ; vecteur identique, sans doute pas d'initialisation
|
||||
mov ds,ax
|
||||
.init_ok:
|
||||
ret
|
||||
|
||||
|
|
@ -158,20 +153,20 @@ setup_check_vga:
|
|||
; ---------------------------------------------------------------------------
|
||||
ivt_setup:
|
||||
; installation de la table d'interrupts
|
||||
xor ax, ax
|
||||
mov es, ax ; ES = 0000h -> base IVT
|
||||
xor di, di ; DI = 0000h -> offset IVT
|
||||
xor ax, ax
|
||||
mov es, ax ; ES = 0000h -> base IVT
|
||||
xor di, di ; DI = 0000h -> offset IVT
|
||||
|
||||
mov ax, default_isr ; offset du handler
|
||||
mov dx, cs ; segment du handler (ROM)
|
||||
mov ax, default_isr ; offset du handler
|
||||
mov dx, cs ; segment du handler (ROM)
|
||||
|
||||
mov cx, 256 ; 256 vecteurs
|
||||
mov cx, 256 ; 256 vecteurs
|
||||
.fill:
|
||||
stosw ; write offset (AX) -> [ES:DI], DI += 2
|
||||
xchg ax, dx ; AX = segment, DX = offset
|
||||
xchg ax, dx ; AX = segment, DX = offset
|
||||
stosw ; write segment (AX) -> [ES:DI], DI += 2
|
||||
xchg ax, dx ; AX = offset, DX = segment
|
||||
loop .fill
|
||||
xchg ax, dx ; AX = offset, DX = segment
|
||||
loop .fill
|
||||
; fin de la table d'interrupt
|
||||
ret
|
||||
|
||||
|
|
@ -183,75 +178,127 @@ ivt_setup:
|
|||
; bx = offset handler
|
||||
; ---------------------------------------------------------------------------
|
||||
ivt_setvector:
|
||||
push es
|
||||
push di
|
||||
push es
|
||||
push di
|
||||
|
||||
shl ax,2 ; ax=id *4
|
||||
mov di,ax
|
||||
shl ax,2 ; ax=id *4
|
||||
mov di,ax
|
||||
|
||||
xor ax,ax
|
||||
mov es, ax ; ES = 0000h -> base IVT
|
||||
xor ax,ax
|
||||
mov es, ax ; ES = 0000h -> base IVT
|
||||
|
||||
mov ax, bx ; offset du handler
|
||||
mov ax, bx ; offset du handler
|
||||
cli
|
||||
stosw ; write offset (AX) -> [ES:DI], DI += 2
|
||||
xchg ax, dx ; AX = segment, DX = offset
|
||||
xchg ax, dx ; AX = segment, DX = offset
|
||||
stosw ; write segment (AX) -> [ES:DI], DI += 2
|
||||
sti
|
||||
|
||||
pop di
|
||||
pop es
|
||||
pop di
|
||||
pop es
|
||||
ret
|
||||
|
||||
; ------------------------------------------------------------
|
||||
io_wait:
|
||||
xor al,al
|
||||
out 0x80,al
|
||||
ret
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Initialise les PIC 8259 (PC/AT):
|
||||
; - Master offset 0x08
|
||||
; - Slave offset 0x70
|
||||
; - Cascade: IRQ2
|
||||
; https://wiki.nox-rhea.org/back2root/ibm-pc-ms-dos/hardware/8259
|
||||
; ------------------------------------------------------------
|
||||
; ---------------------------------------------------------------------------
|
||||
pic_init:
|
||||
push ax
|
||||
cli
|
||||
push ax
|
||||
|
||||
; ICW1: init + ICW4
|
||||
mov al, 0x11 ; 000010001b
|
||||
out i8259_MASTER_CMD, al
|
||||
out i8259_SLAVE_CMD, al
|
||||
; force un End Of Interrupt sur les 2 PIC
|
||||
mov al, 0x20
|
||||
out i8259_SLAVE_CMD, al ; EOI PIC esclave
|
||||
out i8259_MASTER_CMD, al ; EOI PIC maître
|
||||
|
||||
; ICW2: vector offsets
|
||||
mov al, 0x08
|
||||
out i8259_MASTER_DATA, al
|
||||
mov al, 0x70
|
||||
out i8259_SLAVE_DATA, al
|
||||
; starts the initialization sequence (in cascade mode)
|
||||
mov al, ICW1_INIT | ICW1_ICW4
|
||||
out i8259_MASTER_CMD, al
|
||||
out i8259_SLAVE_CMD, al
|
||||
|
||||
; ICW3: wiring
|
||||
mov al, 0x04 ; master: slave on IRQ2: 0100b
|
||||
out i8259_MASTER_DATA, al
|
||||
mov al, 0x02 ; slave: cascade identity 2
|
||||
out i8259_SLAVE_DATA, al
|
||||
mov al, i8259_MASTER_INT
|
||||
out i8259_MASTER_DATA, al ; ICW2: Master PIC vector offset
|
||||
mov al, i8259_SLAVE_INT
|
||||
out i8259_SLAVE_DATA, al ; ICW2: Slave PIC vector offset
|
||||
|
||||
; Master: cascade (IRQ2 => 1 << IRQ2 = 0x04)
|
||||
mov al, 0x04 ; master: slave on IRQ2: 0100b
|
||||
out i8259_MASTER_DATA, al ; ICW3: tell Master PIC that there is a slave PIC at IRQ2
|
||||
|
||||
; Slave: numéro de ligne sur master (2)
|
||||
mov al, 0x02 ; slave: cascade identity 2
|
||||
out i8259_SLAVE_DATA, al ; ICW3: tell Slave PIC its cascade identity (0000 0010)
|
||||
|
||||
; ICW4: 8086 mode
|
||||
mov al, 0x01
|
||||
out i8259_MASTER_DATA, al
|
||||
out i8259_SLAVE_DATA, al
|
||||
mov al, ICW4_8086
|
||||
out i8259_MASTER_DATA, al
|
||||
out i8259_SLAVE_DATA, al
|
||||
|
||||
; Masques: unmask IRQ2 (master) et IRQ12 (slave)
|
||||
in al, i8259_MASTER_DATA
|
||||
and al, 0xFB ; clear bit2
|
||||
out i8259_MASTER_DATA, al
|
||||
|
||||
in al, i8259_SLAVE_DATA
|
||||
and al, 0xEF ; clear bit4
|
||||
out i8259_SLAVE_DATA, al
|
||||
|
||||
pop ax
|
||||
pop ax
|
||||
ret
|
||||
|
||||
; ------------------------------------------------------------------
|
||||
; set_irq_mask
|
||||
; AH = 0 (Enable/Unmask) ou 1 (Disable/Mask)
|
||||
; AL = Numéro de l'IRQ (0 à 15)
|
||||
; ------------------------------------------------------------------
|
||||
pic_set_irq_mask:
|
||||
push bx
|
||||
push cx
|
||||
push dx
|
||||
push ax ; Sauvegarde AX pour récupérer AH plus tard
|
||||
|
||||
mov cl, al ; CL = numéro d'IRQ
|
||||
; Par défaut, PIC Maître (Data port)
|
||||
mov dx, i8259_MASTER_DATA
|
||||
|
||||
cmp cl, 8
|
||||
jl .is_master
|
||||
|
||||
; Si IRQ >= 8, on passe sur le PIC Esclave
|
||||
sub cl, 8 ; Ajuste l'index du bit (8-15 -> 0-7)
|
||||
; Port Data du PIC Esclave
|
||||
mov dx, i8259_SLAVE_DATA
|
||||
|
||||
.is_master:
|
||||
; Préparation du masque de bit
|
||||
mov bl, 1
|
||||
shl bl, cl ; BL contient maintenant le bit correspondant (ex: IRQ 3 -> 00001000)
|
||||
|
||||
in al, dx ; Lire l'IMR actuel depuis le port (0x21 ou 0xA1)
|
||||
|
||||
test ah, ah ; AH est-il à 1 (Disable) ?
|
||||
jnz .do_disable
|
||||
|
||||
.do_enable:
|
||||
not bl ; Inverser le masque (ex: 11110111)
|
||||
and al, bl ; Mettre le bit à 0 (Unmask)
|
||||
jmp .write_back
|
||||
|
||||
.do_disable:
|
||||
or al, bl ; Mettre le bit à 1 (Mask)
|
||||
|
||||
.write_back:
|
||||
out dx, al ; Écrire le nouveau masque dans l'IMR
|
||||
|
||||
pop ax ; Restaurer AX
|
||||
pop dx
|
||||
pop cx
|
||||
pop bx
|
||||
ret
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Handler par défaut: fait juste IRET
|
||||
; IMPORTANT: doit être FAR (appelé par le CPU via IVT), et terminer par IRET
|
||||
; ---------------------------------------------------------------------------
|
||||
default_isr:
|
||||
iret
|
||||
iret
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue