feat: revision des fichiers, ajouts commentaires, ménage & indentation

This commit is contained in:
Nicolas Hordé 2018-08-17 16:46:56 +02:00
parent 3aa3adb92c
commit 56da8273e8
35 changed files with 2825 additions and 3072 deletions

View File

@ -59,9 +59,11 @@ Boot:
sti sti
mov si,Boot_Message mov si,Boot_Message
call ShowString call ShowString
; Initialisation du lecteur de disquette
xor ax,ax xor ax,ax
int 0x13 int 0x13
jc Boot_Error jc Boot_Error
; Calcul de la position de la FAT12
mov cx,[Reserved_Sectors] mov cx,[Reserved_Sectors]
add cx,[Sectors_Hidden] add cx,[Sectors_Hidden]
adc cx,[Sectors_Hidden+2] adc cx,[Sectors_Hidden+2]
@ -69,6 +71,7 @@ Boot:
mov di,Fat_Buffer mov di,Fat_Buffer
push bx push bx
push cx push cx
; Lecture de la FAT en mémoire
readfat: readfat:
call ReadSector call ReadSector
jc Boot_Error jc Boot_Error
@ -92,6 +95,7 @@ readfat:
call Boot_Ok call Boot_Ok
mov si,Loading_Message mov si,Loading_Message
call ShowString call ShowString
; Recherche du système dans les entrèes de répertoire
Find_System: Find_System:
mov di,Buffer mov di,Buffer
call ReadSector call ReadSector
@ -118,6 +122,7 @@ Next_Root_Entrie:
inc cx inc cx
jmp Find_System jmp Find_System
System_Found: System_Found:
; Système trouvé
call Boot_Ok call Boot_Ok
mov si,Entre_Message mov si,Entre_Message
call ShowString call ShowString
@ -129,6 +134,7 @@ System_Found:
push di push di
mov si,The_Dot mov si,The_Dot
Resume_Loading: Resume_Loading:
; Chargement des secteur en mémoire à l'adresse 0080:0000
cmp cx,0x0FF0 cmp cx,0x0FF0
jae Finish_Loading jae Finish_Loading
push cx push cx
@ -143,6 +149,7 @@ Resume_Loading:
jmp Resume_Loading jmp Resume_Loading
Finish_Loading: Finish_Loading:
call Boot_Ok call Boot_Ok
; Exécution du chargeur ELF
retf retf
;====================READSECTOR======================= ;====================READSECTOR=======================

View File

@ -1,270 +0,0 @@
[BITS 16]
[ORG 0x7C00]
section .text
start:
jmp near Boot
Disk_ID db "COS2000A" ;Fabricant + n° de série Formatage
Sectors_Size dw 512 ;Nombre d'octets/secteur
Sectors_Per_Cluster db 4 ;Nombre de secteurs/cluster
Reserved_Sectors dw 1 ;Nombre de secteurs réservé
Fats_Number db 2 ;Nombre de copies de la FAT
Fits_Number dw 512 ;Taille du répertoire racine
Sectors_Per_Disk dw 2880 ;Nombre secteurs du volume si < 32 Mo
Media_Descriptor db 0xF8 ;Descripteur de média
Sectors_Per_Fat dw 207 ;Nombre secteurs/FAT
Sectors_Per_Track dw 18 ;Nombre secteurs/piste
Heads_Number dw 38 ;Nombre de tete de lecture/écriture
Sectors_Hidden dd 16 ;Nombre de secteurs cachés
Sectors_Per_Disk2 dd 39 ;Nombre secteurs du volume si > 32 Mo
Boot_Drive db 0x80 ;Lecteur de démarrage
Reserved db 0 ;NA (pour NT seulement)
Extended_Boot_ID db 0x29 ;Signature Boot étendu 29h
Serial_Number dd 0x01020304 ;N° de série
Disk_Name db "COS2000 " ;Nom de volume
Fat_Type db "FAT16 " ;Type de système de fichiers
;Cpu_Message db "CPU test",0
;Boot_Message db "Booting ",0
;Finding_Message db "System ",0
;Loading_Message db "Loading ",0
System_File db "SYSTEM SYS"
Is_Ok db "[ OK ]",0x0A,0x0D,0
Is_Failed db "[Failed]",0x0A,0x0D,"Press a key",0x0A,0x0D,0
The_Dot db '.',0
Boot_Error:
mov si,Is_Failed
call ShowString
mov ah,0
int 0x16
int 0x19
Boot_Ok:
; mov al,[Stage]
; cmp al,0
; jz No_Ok
mov si,Is_Ok
call ShowString
;No_Ok:
; xor ah,ah
; mov si,ax
; add si,Boot_Message ;Cpu_Message
; call ShowString
; add byte [Stage],0x09
ret
;
;Stage db 0
Boot:
push cs
push cs
pop es
pop ds
mov [Boot_Drive],dl
cli
mov ax,0x9000
mov ss,ax
mov sp,0xFFFF
sti
; call Detect_Cpu
; jc Boot_Error
; call Boot_Ok
xor ax,ax
int 0x13
; jc Boot_Error
xor eax,eax
add ax,[Reserved_Sectors]
add ecx,eax
mov di,Fat_Buffer
call ReadSector
jc Boot_Error
xor eax,eax
mov al,[Fats_Number]
mov bx,[Sectors_Per_Fat]
mul bx
add ecx,eax
mov ax,32
mul word [Fits_Number]
div word [Sectors_Size]
add eax,ecx
mov dword [Serial_Number],eax
xor dx,dx
; call Boot_Ok
Find_System:
mov di,Buffer
call ReadSector
jc near Boot_Error
xor bx,bx
Next_Root_Entrie:
cmp byte [di],0
je near Boot_Error
push di
push cx
mov si,System_File
mov cx,11
rep cmpsb
pop cx
pop di
je System_Found
add di,32
add bx,32
inc dx
cmp dx,[Fits_Number]
ja near Boot_Error
cmp bx,[Sectors_Size]
jb Next_Root_Entrie
inc ecx
jmp Find_System
System_Found:
xor ecx,ecx
mov cx,[di+26]
mov ax,0x0071
mov es,ax
push es
mov di,0x100
push di
; call Boot_Ok
mov si,The_Dot
Resume_Loading:
cmp cx,0x0FFF0
jae Finish_Loading
call ReadGroup
jc near Boot_Error
call ShowString
mov bx,cx
shl bx,1
mov cx,[bx+Fat_Buffer]
jmp Resume_Loading
Finish_Loading:
call Boot_Ok
retf
;====================READSECTOR=======================
;Lit le secteur logique LBA ECX et le met en es:di
;-> ECX (limité à 2^32 secteurs, soit 2 To avec secteur 512 octets)
;<- Flag Carry si erreur
;=====================================================
ReadSector:
pushad
mov ax, cx
ror ecx,16
mov dx,cx
rol ecx,16
cmp ecx,4128705
ja Extended_CHS
div word [Sectors_Per_Track]
inc dl
mov bl, dl
xor dx,dx
div word [Heads_Number]
mov dh, [Boot_Drive]
xchg dl, dh
mov cx, ax
xchg cl, ch
shl cl, 6
or cl, bl
mov bx, di
mov si, 4
mov al, 1
Read_Again:
mov ah, 2
int 0x13
jnc Read_Done
dec si
jnz Read_Again
Read_Done:
popad
ret
Extended_CHS:
mov si,ECHS_Block
mov byte [si+Sizes],0x10
mov byte [si+Reserve],0x01
mov byte [si+NumSectors],0x01
mov [si+Adressseg],es
mov [si+Adressoff],di
mov [si+SectorLow],ax
mov [si+SectorHigh],dx
mov di,4
mov dl,[Boot_Drive]
Read_AgainX:
mov ah, 42h
int 13h
jnc Read_Done
dec di
jnz Read_AgainX
;======================READGROUP======================
;lit le groupe cx en es:di et incrmente DI
;-> cx, es:di
;<- di, Flag Carry si erreur
;=====================================================
ReadGroup:
push ax
push cx
push dx
mov al,[Sectors_Per_Cluster]
sub cx,2
xor ah,ah
mul cx
mov cx,dx
shl ecx,16
mov cx,ax
add ecx,dword [Serial_Number]
mov al,[Sectors_Per_Cluster]
read:
call ReadSector
jc errors
inc ecx
add di,[Sectors_Size]
dec al
jnz read
clc
errors:
pop dx
pop cx
pop ax
ret
;======================SHOWSTR========================
;Affiche la chaine de caractère pointé par ds:si à l'écran
;-> DS, SI
;<- Flag Carry si erreur
;=====================================================
ShowString:
;push ax
;push bx
;push si
pusha
Next_Char:
lodsb
or al,al
jz End_Show
mov ah,0x0E
mov bx,0x07
int 0x10
jmp Next_Char
End_Show:
;pop si
;pop bx
;pop ax
popa
ret
times 510-($-$$) db ' '
dw 0xAA55
ECHS_Block equ $
Buffer equ $+26
Fat_Buffer equ $+26+512
section .bss
%include "echs.h"
;ECHS_Block resb 24
;Buffer resb 512
;Fat_Buffer resb 10000

View File

@ -1,30 +1,30 @@
[BITS 16] [BITS 16]
[ORG 0x0] [ORG 0x0]
SECTION .text SECTION .text
push cs push cs
push cs push cs
pop ds pop ds
pop es pop es
mov si,msg0 mov si,msg0
call showstr call showstr
;Projection de la FAT12 en mémoire
mov si,msg1 mov si,msg1
call showstr call showstr
call initfat call initfat
call ok call ok
;Recherche du système
mov si,msg2 mov si,msg2
call showstr call showstr
mov si,System_File mov si,System_File
call search call search
call ok call ok
;Activation du BUS A20
mov si,msg3 mov si,msg3
call showstr call showstr
call EnableA20 call EnableA20
call ok call ok
;Chargement d'une GDT pour le mode FLAT REAL
mov si,msg4 mov si,msg4
call showstr call showstr
mov eax,cs mov eax,cs
@ -39,8 +39,8 @@
add eax,gdt0 add eax,gdt0
mov [GDTR.Address],eax mov [GDTR.Address],eax
lgdt [GDTR] lgdt [GDTR]
call ok call ok
;Passage en mode FLAT REAL
mov si,msg5 mov si,msg5
call showstr call showstr
cli cli
@ -62,31 +62,32 @@ call ok
mov es,bx mov es,bx
mov gs,bx mov gs,bx
sti sti
call ok call ok
;Chargement du noyau en 0x30000
mov si,msg6 mov si,msg6
call showstr call showstr
mov ebx,0x300000 mov ebx,0x300000
call load call load
call ok call ok
;Chargement du fichier PE
mov si,msg7 mov si,msg7
call showstr call showstr
call initpe call initpe
call ok call ok
suite:
;suite:
;mov cx,suite ;mov cx,suite
;call debug ;call debug
mov si,msg8 mov si,msg8
call showstr call showstr
cli cli
;Passage en mode protégé
mov al,0x80 mov al,0x80
out 0x70,al out 0x70,al
mov eax,cr0 mov eax,cr0
or al,1 or al,1
mov cr0,eax mov cr0,eax
;Exécution du code 32 bits
jmp SYS_CODE_SEL:GoPMode32 jmp SYS_CODE_SEL:GoPMode32
@ -203,14 +204,14 @@ sections:
itsok: itsok:
mov esi,info10 mov esi,info10
call showstr call showstr
call copy2mem call copy2mem
cmp dword [es:edi+Sections.Type],ST_NOBITS cmp dword [es:edi+Sections.Type],ST_NOBITS
jne itsok2 jne itsok2
mov esi,info9 mov esi,info9
call showstr call showstr
mov esi,info10 mov esi,info10
call showstr call showstr
call zero2mem call zero2mem
itsok2: itsok2:
push cx push cx
xor cx,cx xor cx,cx
@ -258,7 +259,7 @@ errorelf:
;CX adresse ;CX adresse
;->CX ;->CX
;<- ;<-
;=========================================== ;==========================
debug: debug:
mov esi,info11 mov esi,info11
call showstr call showstr
@ -271,23 +272,22 @@ debug:
infini: infini:
jmp infini jmp infini
;==========COPY2MEM=========== ;==========COPY2MEM===========
;Copie de es:esi vers es:edi ;Copie de es:esi vers es:edi
;->ES:ESI ES:EDI CX ;->ES:ESI ES:EDI CX
;<- Flag ;<- Flag
;=========================================== ;=============================
copy2mem: copy2mem:
push eax push eax
push esi push esi
push edi push edi
push ecx push ecx
mov esi,[es:edi+Sections.Offset] mov esi,[es:edi+Sections.Offset]
add esi,[cs:begin] add esi,[cs:begin]
mov ecx,[es:edi+Sections.Size] mov ecx,[es:edi+Sections.Size]
shr ecx,2 shr ecx,2
inc ecx inc ecx
mov edi,[es:edi+Sections.Vadress] mov edi,[es:edi+Sections.Vadress]
copietomem: copietomem:
mov eax,[es:esi] mov eax,[es:esi]
mov [es:edi],eax mov [es:edi],eax
@ -295,39 +295,39 @@ copietomem:
add esi,4 add esi,4
dec ecx dec ecx
jnz copietomem jnz copietomem
pop ecx pop ecx
pop edi pop edi
pop esi pop esi
pop eax pop eax
ret ret
;==========ZERO2MEM=========== ;==========ZERO2MEM===========
;Remise à zero de es:edi ;Remise à zero de es:edi
;->ES:EDI CX ;->ES:EDI CX
;<- Flag ;<- Flag
;=========================================== ;=============================
zero2mem: zero2mem:
push eax push eax
push esi push esi
push edi push edi
push ecx push ecx
mov esi,[es:edi+Sections.Offset] mov esi,[es:edi+Sections.Offset]
add esi,[cs:begin] add esi,[cs:begin]
mov ecx,[es:edi+Sections.Size] mov ecx,[es:edi+Sections.Size]
shr ecx,2 shr ecx,2
inc ecx inc ecx
mov edi,[es:edi+Sections.Vadress] mov edi,[es:edi+Sections.Vadress]
mov eax,0 mov eax,0
zerotomem: zerotomem:
mov [es:edi],eax mov [es:edi],eax
add edi,4 add edi,4
dec ecx dec ecx
jnz zerotomem jnz zerotomem
pop ecx pop ecx
pop edi pop edi
pop esi pop esi
pop eax pop eax
ret ret
begin dd 0 begin dd 0
entriepoint dd 0 entriepoint dd 0
@ -341,7 +341,7 @@ symbol dd 0
;Affiche un nombre hexadécimal EDX de taille CX aprés le curseur ;Affiche un nombre hexadécimal EDX de taille CX aprés le curseur
;-> EDX un entier, CX la taille ;-> EDX un entier, CX la taille
;<- ;<-
;=========================================== ;============================
ShowHex: ShowHex:
push ax push ax
push bx push bx
@ -378,11 +378,11 @@ Hexaize:
ret ret
Tab db '0123456789ABCDEF' Tab db '0123456789ABCDEF'
;======================EOL======================== ;============EOL=============
;Va en colonne CX ;Va en colonne CX
;-> ;->
;<- Flag Carry si erreur ;<- Flag Carry si erreur
;===================================================== ;============================
eol: eol:
pusha pusha
mov bp,cx mov bp,cx
@ -396,12 +396,11 @@ eol:
popa popa
ret ret
;============LOAD==============
;======================LOAD======================== ;Charge le groupe en mémoire en EBX pour le groupe CX
;Charge le groupe en mémoire en ebx ;-> CX
;->
;<- Flag Carry si erreur ;<- Flag Carry si erreur
;===================================================== ;==============================
load: load:
push ax push ax
push ebx push ebx
@ -455,11 +454,11 @@ Finish_Loading:
pop ax pop ax
ret ret
;======================INITFAT======================== ;===========INITFAT=============
;Initialise les variables de la fat ;Initialise les variables de la fat
;-> ;->
;<- Flag Carry si erreur ;<- Flag Carry si erreur
;===================================================== ;===============================
initfat: initfat:
pusha pusha
push ds push ds
@ -500,11 +499,11 @@ readfat:
popa popa
ret ret
;======================SEARCH======================== ;===========SEARCH============
;Recherche le groupe d'un fichier ;Recherche le groupe d'un fichier
;-> si nom du fichier ;-> si nom du fichier
;<- Flag Carry si erreur CX ;<- Flag Carry si erreur CX
;===================================================== ;=============================
search: search:
push bx push bx
push dx push dx
@ -541,11 +540,11 @@ Found:
pop bx pop bx
ret ret
;======================SHOWRTN======================== ;============SHOWRTN============
;Affiche la chaine de caractère return ;Affiche la chaine de caractère return
;-> ;->
;<- Flag Carry si erreur ;<- Flag Carry si erreur
;===================================================== ;===============================
showrtn: showrtn:
push ds push ds
push ax push ax
@ -559,11 +558,11 @@ showrtn:
pop ds pop ds
ret ret
;======================SHOWSTR======================== ;==============SHOWSTR=============
;Affiche la chaine de caractère pointé par ds:esi à l'écran ;Affiche la chaine de caractère pointé par ds:esi à l'écran
;-> DS, SI ;-> DS, ESI
;<- Flag Carry si erreur ;<- Flag Carry si erreur
;===================================================== ;==================================
showstr: showstr:
pushad pushad
xor bh,bh xor bh,bh
@ -619,12 +618,11 @@ endshow:
popad popad
ret ret
;==========READSECTOR============
;====================READSECTOR=======================
;Lit le secteur logique LBA CX et le met en es:di ;Lit le secteur logique LBA CX et le met en es:di
;-> CX (limité à 65536 secteurs, soit 32 Mo avec secteur 512 octets) ;-> CX (limité à 65536 secteurs, soit 32 Mo avec secteur 512 octets)
;<- Flag Carry si erreur ;<- Flag Carry si erreur
;===================================================== ;================================
ReadSector: ReadSector:
pusha pusha
mov ax,cx mov ax,cx
@ -653,11 +651,11 @@ Read_Done:
popa popa
ret ret
;===================NEXTFATGROUP====================== ;============NEXTFATGROUP===========
;Renvoie en CX le groupe qui succède dans la FAT le groupe CX ;Renvoie en CX le groupe qui succède dans la FAT le groupe CX
;-> CX ;-> CX
;<- ;<- CX
;===================================================== ;===================================
NextFatGroup: NextFatGroup:
push bx push bx
push dx push dx
@ -688,11 +686,11 @@ Next_Group_Found:
pop bx pop bx
ret ret
;***********************EnableA20******************************* ;============EnableA20============
;-> ;->
;<- ;<-
;Ouvre l'autoroute A20 ;Ouvre l'autoroute A20
;*************************************************************** ;=================================
EnableA20: EnableA20:
cli cli
call ClearKeybBuffer call ClearKeybBuffer
@ -722,8 +720,12 @@ A20Enabled:
ret ret
;=================================
;CODE 32 bits mode protégé
;=================================
GoPMode32: GoPMode32:
[BITS 32] [BITS 32]
;Initialisation des selecteurs
mov ax,ALL_DATA_SEL mov ax,ALL_DATA_SEL
mov es,ax mov es,ax
mov gs,ax mov gs,ax
@ -733,6 +735,7 @@ GoPMode32:
mov esp,0x3fffff mov esp,0x3fffff
push KERNEL_SEL push KERNEL_SEL
push dword [cs:entriepoint] push dword [cs:entriepoint]
;Execution du système
retf retf
section .data section .data

View File

@ -2,14 +2,11 @@ CC=nasm -f bin -o
all: makall all: makall
makall: boot12.bin boot16.bin loader.sys makall: boot12.bin loader.sys
boot12.bin: boot12.asm boot12.bin: boot12.asm
$(CC) $@ $^ $(CC) $@ $^
boot16.bin: boot16.asm
$(CC) $@ $^
loader.sys: loader.asm loader.sys: loader.asm
$(CC) $@ $^ $(CC) $@ $^

View File

@ -3,6 +3,7 @@ all: cos2000.img
cos2000.img: cos2000.img:
(dd if=/dev/zero of=cos2000.img count=2880 bs=512) (dd if=/dev/zero of=cos2000.img count=2880 bs=512)
(mkfs.msdos -F 12 -n "COS2000" cos2000.img) (mkfs.msdos -F 12 -n "COS2000" cos2000.img)
(mkdir ./mnt)
(fusefat cos2000.img ./mnt -o rw+) (fusefat cos2000.img ./mnt -o rw+)
(cp ../boot/loader.sys ./mnt/) (cp ../boot/loader.sys ./mnt/)
(cp ../system/system.sys ./mnt/;sync) (cp ../system/system.sys ./mnt/;sync)

View File

@ -1 +1,3 @@
#include "types.h"
void line(u32 x1, u32 y1, u32 x2, u32 y2, u8 color); void line(u32 x1, u32 y1, u32 x2, u32 y2, u8 color);

View File

@ -0,0 +1 @@
#include "types.h"

View File

@ -1,6 +0,0 @@
#include "types.h"
void outreg(u16 port,u8 *src,u16 num);
void outregsame(u16 port,u8 *src,u16 num);
void inreg(u16 port,u8 *src,u16 num);
void inregsame(u16 port,u8 *src,u16 num);

View File

@ -35,3 +35,7 @@ void enableblink();
void disableblink(); void disableblink();
u8 (*getchar)(u16 coordx,u16 coordy); u8 (*getchar)(u16 coordx,u16 coordy);
u8 (*getattrib)(u16 coordx,u16 coordy); u8 (*getattrib)(u16 coordx,u16 coordy);
void outreg(u16 port,u8 *src,u16 num);
void outregsame(u16 port,u8 *src,u16 num);
void inreg(u16 port,u8 *src,u16 num);
void inregsame(u16 port,u8 *src,u16 num);

51
lib/2d.c Executable file
View File

@ -0,0 +1,51 @@
#include "types.h"
#include "vga.h"
#include "video.h"
#include "2d.h"
#include "math.h"
/******************************************************************************/
/* Affiche une ligne entre les points spécifiés */
void line(u32 x1, u32 y1, u32 x2, u32 y2, u8 color)
{
s32 dx, dy, sdx, sdy;
u32 i, dxabs, dyabs, x, y, px, py;
dx = x2 - x1; /* distance horizontale de la line */
dy = y2 - y1; /* distance verticale de la line * */
dxabs = abs(dx);
dyabs = abs(dy);
sdx = sgn(dx);
sdy = sgn(dy);
x = dyabs >> 1;
y = dxabs >> 1;
px = x1;
py = y1;
writepxl(px, py, color);
if (dxabs >= dyabs) { /* la ligne est plus horizontale que verticale */
for (i = 0; i < dxabs; i++) {
y += dyabs;
if (y >= dxabs) {
y -= dxabs;
py += sdy;
}
px += sdx;
writepxl(px, py, color);
}
} else { /* la ligne est plus verticale que horizontale */
for (i = 0; i < dyabs; i++) {
x += dxabs;
if (x >= dyabs) {
x -= dyabs;
px += sdx;
}
py += sdy;
writepxl(px, py, color);
}
}
}

View File

@ -1,5 +1,6 @@
#include "3d.h" #include "3d.h"
#include "2d.h"
#include "vga.h" #include "vga.h"
#include "types.h" #include "types.h"
#include "video.h" #include "video.h"
#include "graph.h"

219
lib/VGA/modes.c Executable file
View File

@ -0,0 +1,219 @@
/* definition des registres de la carte VGA pour differents modes */
#define maxgraphmode 11
#define maxtextmode 5
static mode_def textmodes[maxtextmode] = {
/*40*25 16 couleurs mode 0x00 */
{
0x67,
0x03, 0x08, 0x03, 0x00, 0x02,
0x2D, 0x27, 0x28, 0x90, 0x2B, 0xA0, 0xBF, 0x1F, 0x00,
0x4F, 0x0D, 0x0E, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x8E, 0x8F, 0x14, 0x1F, 0x96, 0xB9, 0xA3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B,
0x3C, 0x3D, 0x3E, 0x3F,
0x0C, 0x00, 0x0F, 0x08, 0x00,
45, 25, 4},
/*80*25 16 couleurs mode 0x01 */
{
0x67,
0x03, 0x00, 0x03, 0x00, 0x02,
0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F, 0x00,
0x4F, 0x0D, 0x0E, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x0E, 0x8F, 0x28, 0x1F, 0x96, 0xB9, 0xA3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B,
0x3C, 0x3D, 0x3E, 0x3F,
0x0C, 0x00, 0x0F, 0x08, 0x00,
80, 25, 4},
/*80*50 16 couleurs mode 0x02 */
{
0x63,
0x03, 0x01, 0x03, 0x05, 0x02,
0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F, 0x00,
0x47, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x8E, 0x8F, 0x28, 0x1F, 0x96, 0xB9, 0xA3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B,
0x3C, 0x3D, 0x3E, 0x3F,
0x0C, 0x00, 0x0F, 0x00, 0x00,
80, 50, 4},
/*100*50 16 couleurs mode 0x03 */
{
0x67,
0x03, 0x01, 0x03, 0x05, 0x02,
0x70, 0x63, 0x64, 0x85, 0x68, 0x84, 0xBF, 0x1F, 0x00,
0x47, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x8E, 0x8F, 0x32, 0x1F, 0x96, 0xB9, 0xA3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B,
0x3C, 0x3D, 0x3E, 0x3F,
0x0C, 0x00, 0x0F, 0x00, 0x00,
100, 50, 4},
/*100*60 16 couleurs mode 0x04 */
{
0xA7,
0x03, 0x01, 0x03, 0x05, 0x02,
0x70, 0x63, 0x64, 0x85, 0x68, 0x84, 0xFF, 0x1F, 0x00,
0x47, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
0xE7, 0x8E, 0xDF, 0x32, 0x1F, 0xDF, 0xE5, 0xA3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B,
0x3C, 0x3D, 0x3E, 0x3F,
0x0C, 0x00, 0x0F, 0x00, 0x00,
100, 60, 4}
};
static mode_def graphmodes[maxgraphmode] = {
/*640*480 n&b mode 0x80 */
{
0xE3,
0x03, 0x01, 0x0F, 0x00, 0x06,
0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xEA, 0x0C, 0xDF, 0x28, 0x00, 0xE7, 0x04, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B,
0x3C, 0x3D, 0x3E, 0x3F,
0x01, 0x00, 0x0F, 0x00, 0x00,
80, 60, 1},
/*320*200 4 couleurs mode 0x81 */
{
0x63,
0x03, 0x09, 0x03, 0x00, 0x02,
0x2D, 0x27, 0x28, 0x90, 0x2B, 0x80, 0xBF, 0x1F, 0x00,
0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x0E, 0x8F, 0x14, 0x00, 0x96, 0xB9, 0xA3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x02, 0x00, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B,
0x3C, 0x3D, 0x3E, 0x3F,
0x01, 0x00, 0x03, 0x00, 0x00,
40, 25,
},
/*640*480 16 couleurs mode 0x82 */
{
0xE3,
0x03, 0x01, 0x0F, 0x00, 0x06,
0x5F, 0x4F, 0x50, 0x82, 0x53, 0x9F, 0x0B, 0x3E, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xE9, 0x8B, 0xDF, 0x28, 0x00, 0xE7, 0x04, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B,
0x3C, 0x3D, 0x3E, 0x3F,
0x01, 0x00, 0x0F, 0x00, 0x00,
80, 60, 4},
/*720*480 16 couleurs mode 0x83 */
{
0xE7,
0x03, 0x01, 0x08, 0x00, 0x06,
0x6B, 0x59, 0x5A, 0x82, 0x60, 0x8D, 0x0B, 0x3E, 0x00,
0x40, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
0xEA, 0x0C, 0xDF, 0x2D, 0x08, 0xE8, 0x05, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B,
0x3C, 0x3D, 0x3E, 0x3F,
0x01, 0x00, 0x0F, 0x00, 0x00,
90, 60, 4},
/*800*600 16 couleurs mode 0x84 */
{
0xE7,
0x03, 0x01, 0x0F, 0x00, 0x06,
0x70, 0x63, 0x64, 0x92, 0x65, 0x82, 0x70, 0xF0, 0x00,
0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x5B, 0x8C, 0x57, 0x32, 0x00, 0x58, 0x70, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B,
0x3C, 0x3D, 0x3E, 0x3F,
0x01, 0x00, 0x0F, 0x00, 0x00,
100, 75, 4},
/*320*200 256 couleurs RAPIDE mode 0x85 */
{
0x63,
0x03, 0x01, 0x0F, 0x00, 0x0E,
0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F, 0x00,
0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x0E, 0x8F, 0x28, 0x40, 0x96, 0xB9, 0xA3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
0x0C, 0x0D, 0x0E, 0x0F,
0x41, 0x00, 0x0F, 0x00, 0x00,
40, 25, 8},
/*320*200 256 couleurs mode 0x86 */
{
0x63,
0x03, 0x01, 0x0F, 0x00, 0x06,
0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F, 0x00,
0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x0E, 0x8F, 0x28, 0x00, 0x96, 0xB9, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
0x0C, 0x0D, 0x0E, 0x0F,
0x41, 0x00, 0x0F, 0x00, 0x00,
40, 25, 8},
/*320*400 256 couleurs mode 0x87 */
{
0x63,
0x03, 0x01, 0x0F, 0x00, 0x06,
0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x8E, 0x8F, 0x28, 0x00, 0x96, 0xB9, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
0x0C, 0x0D, 0x0E, 0x0F,
0x41, 0x00, 0x0F, 0x00, 0x00,
40, 50, 8},
/*320*480 256 couleurs mode 0x88 */
{
0xE3,
0x03, 0x01, 0x0F, 0x00, 0x06,
0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xEA, 0xAC, 0xDF, 0x28, 0x00, 0xE7, 0x06, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
0x0C, 0x0D, 0x0E, 0x0F,
0x41, 0x00, 0x0F, 0x00, 0x00,
40, 60, 8},
/*360*480 256 couleurs mode 0x89 */
{
0xE7,
0x03, 0x01, 0x0F, 0x00, 0x06,
0x6B, 0x59, 0x5A, 0x8E, 0x5E, 0x8A, 0x0D, 0x3E, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xEA, 0xAC, 0xDF, 0x2D, 0x00, 0xE7, 0x06, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
0x0C, 0x0D, 0x0E, 0x0F,
0x41, 0x00, 0x0F, 0x00, 0x00,
45, 60, 8},
/*400*600 256 couleurs mode 0x8A */
{
0xE7,
0x03, 0x01, 0x0F, 0x00, 0x06,
0x74, 0x63, 0x64, 0x97, 0x68, 0x95, 0x86, 0xF0, 0x00,
0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x5B, 0x8D, 0x57, 0x32, 0x00, 0x60, 0x80, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
0x0C, 0x0D, 0x0E, 0x0F,
0x41, 0x00, 0x0F, 0x00, 0x00,
50, 75, 8}
};

205
lib/cpu.c
View File

@ -4,10 +4,9 @@
#include "memory.h" #include "memory.h"
#include "string.h" #include "string.h"
/* Technologies supportées */
static u8 *msg[] = {
static u8 *msg[] =
{
"mmx", "mmx",
"mmx2", "mmx2",
"sse", "sse",
@ -20,113 +19,112 @@ static u8 *msg[] =
"apic", "apic",
}; };
static u8 space[]=" "; static u8 space[] = " ";
bool cansetflag (u32 flag) /******************************************************************************/
/* Annule les FLAGs CPU */
bool cansetflag(u32 flag)
{ {
u32 r1, r2; u32 r1, r2;
asm("pushfl\n" asm("pushfl\n" "popl %0\n" "movl %0, %1\n" "xorl %2, %0\n" "pushl %0\n" "popfl\n" "pushfl\n" "popl %0\n" "pushl %1\n" "popfl\n": "=&r"(r1), "=&r"(r2):"ir"(flag));
"popl %0\n" return ((r1 ^ r2) & flag) != 0;
"movl %0, %1\n"
"xorl %2, %0\n"
"pushl %0\n"
"popfl\n"
"pushfl\n"
"popl %0\n"
"pushl %1\n"
"popfl\n"
: "=&r" (r1), "=&r" (r2)
: "ir" (flag)
);
return ((r1 ^ r2) & flag) != 0;
} }
void cpuid(u32 op, u32 *eax, u32 *ebx,u32 *ecx, u32 *edx) /******************************************************************************/
/* Lance l'instruction CPUID */
void cpuid(u32 op, u32 * eax, u32 * ebx, u32 * ecx, u32 * edx)
{ {
asm("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "a" (op) : "cc"); asm("cpuid": "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx): "a"(op):"cc");
} }
u8 getcpuinfos(cpuinfo *proc) /******************************************************************************/
{
u32 i,maxfunction,maxextended,unused,regeax,regebx,regecx,regedx;
bool *boolean;
if (!cansetflag (0x00040000)) return 1; /*386 processor - no cpuid*/ /* Retourne les informations sur le CPU dans une structure cpuinfo */
if (!cansetflag (0x00200000)) return 2; /*486 processor with no cpuid*/
u8 getcpuinfos(cpuinfo * proc)
{
u32 i, maxfunction, maxextended, unused, regeax, regebx, regecx, regedx;
bool *boolean;
if (!cansetflag(0x00040000))
return 1; /*386 processor - no cpuid */
if (!cansetflag(0x00200000))
return 2; /*486 processor with no cpuid */
cpuid(0, &maxfunction, &unused, &unused, &unused); cpuid(0, &maxfunction, &unused, &unused, &unused);
maxfunction &= 0xffff; maxfunction &= 0xffff;
cpuid(0x80000000, &maxextended, &unused, &unused, &unused); cpuid(0x80000000, &maxextended, &unused, &unused, &unused);
maxextended &= 0xffff; maxextended &= 0xffff;
if (maxfunction >= 1) if (maxfunction >= 1) {
{
cpuid(1, &regeax, &regebx, &regecx, &regedx); cpuid(1, &regeax, &regebx, &regecx, &regedx);
proc->stepping = (regeax & 0x0000000F); proc->stepping = (regeax & 0x0000000F);
proc->models = ((regeax>>4) & 0x0000000F); proc->models = ((regeax >> 4) & 0x0000000F);
proc->family = ((regeax>>8) & 0x0000000F); proc->family = ((regeax >> 8) & 0x0000000F);
proc->types = ((regeax>>12) & 0x00000003); proc->types = ((regeax >> 12) & 0x00000003);
proc->emodels = ((regeax>>16) & 0x0000000F); proc->emodels = ((regeax >> 16) & 0x0000000F);
proc->efamily = ((regeax>>20) & 0x000000FF); proc->efamily = ((regeax >> 20) & 0x000000FF);
proc->brandid = (regeax & 0xF); proc->brandid = (regeax & 0xF);
proc->linesize = ((regeax>>8) & 0xF); proc->linesize = ((regeax >> 8) & 0xF);
proc->count = ((regeax>>16) & 0xF); proc->count = ((regeax >> 16) & 0xF);
proc->apicid = ((regeax>>24) & 0xF); proc->apicid = ((regeax >> 24) & 0xF);
proc->mmx=((regedx>>23) & 0x00000001); proc->mmx = ((regedx >> 23) & 0x00000001);
proc->sse=((regedx>>25) & 0x00000001); proc->sse = ((regedx >> 25) & 0x00000001);
proc->sse2=((regedx>>26) & 0x00000001); proc->sse2 = ((regedx >> 26) & 0x00000001);
proc->sse3=(regecx & 0x00000001); proc->sse3 = (regecx & 0x00000001);
proc->fpu=(regedx & 0x00000001); proc->fpu = (regedx & 0x00000001);
proc->htt=((regedx>>28) & 0x00000001); proc->htt = ((regedx >> 28) & 0x00000001);
} }
if (maxextended >= 1) if (maxextended >= 1) {
{
cpuid(0x80000001, &regeax, &regebx, &regecx, &regedx); cpuid(0x80000001, &regeax, &regebx, &regecx, &regedx);
proc->mmx2=((regedx>>22) & 0x00000001); proc->mmx2 = ((regedx >> 22) & 0x00000001);
proc->apic=((regedx>>9) & 0x00000001); proc->apic = ((regedx >> 9) & 0x00000001);
proc->now3d=((regedx>>30) & 0x00000001); proc->now3d = ((regedx >> 30) & 0x00000001);
proc->now3d2=((regedx>>31) & 0x00000001); proc->now3d2 = ((regedx >> 31) & 0x00000001);
} }
if (maxextended >= 4) if (maxextended >= 4) {
{
int i; int i;
for(i=0;i<3;i++) for (i = 0; i < 3; i++) {
{ cpuid(0x80000002 + i, &regeax, &regebx, &regecx,
cpuid(0x80000002+i, &regeax, &regebx, &regecx, &regedx); &regedx);
memcpy(&regeax,&proc->detectedname[0+i*16],4,1); memcpy(&regeax, &proc->detectedname[0 + i * 16], 4, 1);
memcpy(&regebx,&proc->detectedname[4+i*16],4,1); memcpy(&regebx, &proc->detectedname[4 + i * 16], 4, 1);
memcpy(&regecx,&proc->detectedname[8+i*16],4,1); memcpy(&regecx, &proc->detectedname[8 + i * 16], 4, 1);
memcpy(&regedx,&proc->detectedname[12+i*16],4,1); memcpy(&regedx, &proc->detectedname[12 + i * 16], 4, 1);
} }
} }
boolean=&proc->mmx; boolean = &proc->mmx;
i=0; i = 0;
for(i=0;i<10;i++) for (i = 0; i < 10; i++)
if (*(boolean++)==1) if (*(boolean++) == 1) {
{ strcat(msg[i], &proc->techs);
strcat(msg[i],&proc->techs); strcat(space, &proc->techs);
strcat(space,&proc->techs);
} }
return 0; return 0;
} }
/******************************************************************************/
/* Retourne un élément de la pile */
u32 viewstack(u32 number) u32 viewstack(u32 number)
{ {
u32 stack = 0; u32 stack = 0;
asm ( asm("movl %[a1],%%esi;" "addl %%esp,%%esi;" "movl (%%esi), %[a1] ;": [result] "=r"(stack): [a1] "r"(number):"%esi");
"movl %[a1],%%esi;"
"addl %%esp,%%esi;"
"movl (%%esi), %[a1] ;"
:[result] "=r" (stack)
:[a1] "r" (number)
:"%esi"
);
return stack; return stack;
} }
/******************************************************************************/
/* Affiche les registres CPU */
void dump_regs() void dump_regs()
{ {
u32 eax = 0; u32 eax = 0;
@ -144,74 +142,55 @@ void dump_regs()
u16 gs = 0; u16 gs = 0;
u16 ss = 0; u16 ss = 0;
u32 flags = 0; u32 flags = 0;
asm ( asm("movl %%eax, %[a1] ;" "movl %%ebx, %[b1] ;" "movl %%ecx, %[c1] ;" "movl %%edx, %[d1] ;" "movl %%esi, %[e1] ;" "movl %%edi, %[f1] ;" "movl %%esp, %[g1] ;" "movl %%ebp, %[h1] ;" "movw %%cs, %[i1] ;" "movw %%ds, %[j1] ;" "movw %%es, %[k1] ;" "movw %%fs, %[l1] ;" "movw %%gs, %[m1] ;" "movw %%ss, %[n1] ;":
"movl %%eax, %[a1] ;" [a1] "=m"(eax),[b1] "=m"(ebx),[c1] "=m"(ecx),[d1] "=m"(edx),[e1] "=m"(esi),
"movl %%ebx, %[b1] ;" [f1] "=m"(edi),[g1] "=m"(ebp),[h1] "=m"(esp),[i1] "=m"(cs),[j1] "=m"(ds),
"movl %%ecx, %[c1] ;" [k1] "=m"(es),[l1] "=m"(fs),[m1] "=m"(gs),[n1] "=m"(ss));
"movl %%edx, %[d1] ;"
"movl %%esi, %[e1] ;"
"movl %%edi, %[f1] ;"
"movl %%esp, %[g1] ;"
"movl %%ebp, %[h1] ;"
"movw %%cs, %[i1] ;"
"movw %%ds, %[j1] ;"
"movw %%es, %[k1] ;"
"movw %%fs, %[l1] ;"
"movw %%gs, %[m1] ;"
"movw %%ss, %[n1] ;"
:
[a1] "=m" (eax), [b1] "=m" (ebx), [c1] "=m" (ecx), [d1] "=m" (edx), [e1] "=m" (esi), [f1] "=m" (edi),
[g1] "=m" (ebp), [h1] "=m" (esp), [i1] "=m" (cs), [j1] "=m" (ds), [k1] "=m" (es), [l1] "=m" (fs), [m1] "=m" (gs), [n1] "=m" (ss)
);
printf("eax=%x ebx=%x ecx=%x eax=%x\r\n", eax,ebx,ecx,edx); printf("eax=%x ebx=%x ecx=%x eax=%x\r\n", eax, ebx,
printf("esi=%x edi=%x\r\n", esi,edi); ecx, edx);
printf("cs=%x ds=%x es=%x fs=%x gs=%x\r\n", cs,ds,es,fs,gs); printf("esi=%x edi=%x\r\n", esi, edi);
printf("ss=%x esp=%x ebp=%x\r\n",ss,esp,ebp); printf("cs=%x ds=%x es=%x fs=%x gs=%x\r\n",
cs, ds, es, fs, gs);
printf("ss=%x esp=%x ebp=%x\r\n", ss, esp, ebp);
asm ( asm("pushf ;" "pop %[f1] ;":
"pushf ;" [f1] "=m"(flags));
"pop %[f1] ;"
:
[f1] "=m" (flags)
);
printf("FLAGS"); printf("FLAGS");
if(flags & (1 << 0)) // Carry if (flags & (1 << 0)) // Carry
printf(" (C1"); printf(" (C1");
else else
printf(" (C0"); printf(" (C0");
if(flags & (1 << 2)) // Parity if (flags & (1 << 2)) // Parity
printf(" P1"); printf(" P1");
else else
printf(" P0"); printf(" P0");
if(flags & (1 << 4)) // Adjust if (flags & (1 << 4)) // Adjust
printf(" A1"); printf(" A1");
else else
printf(" A0"); printf(" A0");
if(flags & (1 << 6)) // Zero if (flags & (1 << 6)) // Zero
printf(" Z1"); printf(" Z1");
else else
printf(" Z0"); printf(" Z0");
if(flags & (1 << 7)) // Sign if (flags & (1 << 7)) // Sign
printf(" S1"); printf(" S1");
else else
printf(" S0"); printf(" S0");
if(flags & (1 << 11)) // Overflow if (flags & (1 << 11)) // Overflow
printf(" O1)\n"); printf(" O1)\n");
else else
printf(" O0)\n"); printf(" O0)\n");
printf("STACK\r\n"); printf("STACK\r\n");
for(u8 i=0;i<25;i++) for (u8 i = 0; i < 25; i++)
printf("+%d\t\t%x\r\n",i,viewstack(i*4)); printf("+%d\t\t%x\r\n", i, viewstack(i * 4));
} }

View File

@ -1,58 +0,0 @@
#include "types.h"
#include "vga.h"
#include "video.h"
#include "graph.h"
#include "math.h"
/******************************************************************************/
/* Affiche une ligne entre les points spécifiés */
void line(u32 x1, u32 y1, u32 x2, u32 y2, u8 color)
{
s32 dx,dy,sdx,sdy;
u32 i,dxabs,dyabs,x,y,px,py;
dx=x2-x1; /* distance horizontale de la line */
dy=y2-y1; /* distance verticale de la line **/
dxabs=abs(dx);
dyabs=abs(dy);
sdx=sgn(dx);
sdy=sgn(dy);
x=dyabs>>1;
y=dxabs>>1;
px=x1;
py=y1;
writepxl(px,py,color);
if (dxabs>=dyabs) /* la ligne est plus horizontale que verticale */
{
for(i=0;i<dxabs;i++)
{
y+=dyabs;
if (y>=dxabs)
{
y-=dxabs;
py+=sdy;
}
px+=sdx;
writepxl(px,py,color);
}
}
else /* la ligne est plus verticale que horizontale */
{
for(i=0;i<dyabs;i++)
{
x+=dxabs;
if (x>=dyabs)
{
x-=dyabs;
px+=sdx;
}
py+=sdy;
writepxl(px,py,color);
}
}
}

511
lib/idt.c
View File

@ -1,511 +0,0 @@
#include "idt.h"
#include "types.h"
#include "asm.h"
#include "memory.h"
#include "video.h"
/* registre idt */
static struct dtr idtreg;
/* table de IDT */
static idtdes idt[256];
void initpic(void)
{
/* MASTER */
/* Initialisation de ICW1 */
outb(0x20,0x11);
nop();
/* Initialisation de ICW2 - vecteur de depart = 32 */
outb(0x21,0x20);
nop();
/* Initialisation de ICW3 */
outb(0x21,0x04);
nop();
/* Initialisation de ICW4 */
outb(0x21,0x01);
nop();
/* masquage des interruptions */
outb(0x21,0xFF);
nop();
/* SLAVE */
/* Initialisation de ICW1 */
outb(0xA0,0x11);
nop();
/* Initialisation de ICW2 - vecteur de depart = 96 */
outb(0xA1,0x60);
nop();
/* Initialisation de ICW3 */
outb(0xA1,0x02);
nop();
/* Initialisation de ICW4 */
outb(0xA1,0x01);
nop();
/* masquage des interruptions */
outb(0xA1,0xFF);
nop();
/* Demasquage des irqs sauf clavier
outb(0x21,0xFD);
nop();
*/
}
void enableirq(u8 irq)
{
u16 port;
cli();
port = (((irq & 0x08) << 4) + 0x21);
outb(port,inb(port) & ~(1 << (irq & 7)));
sti();
}
void disableirq(u8 irq)
{
u16 port;
cli();
port = (((irq & 0x08) << 4) + 0x21);
outb(port,inb(port) | (1 << (irq & 7)));
sti();
}
void makeidtdes(u32 offset, u16 select, u16 type, idtdes* desc)
{
desc->offset0_15 = (offset & 0xffff);
desc->select = select;
desc->type = type;
desc->offset16_31 = (offset & 0xffff0000) >> 16;
return;
}
void setidt(u32 offset, u16 select, u16 type,u16 index)
{
cli();
idtdes *desc;
desc=idtreg.base;
desc[index].offset0_15 = (offset & 0xffff);
desc[index].select = select;
desc[index].type = type;
desc[index].offset16_31 = (offset & 0xffff0000) >> 16;
sti();
}
void putidt(u32 offset, u16 select, u16 type,u16 index)
{
idtdes temp;
makeidtdes(offset,select,type,&temp);
idt[index]=temp;
}
void cpuerror(const u8 *src)
{
print("\033[31m***** ERREUR CPU ****\r\n -");
print(src);
dump_regs();
while(1)
{
nop();
}
}
void interruption()
{
cli();
pushf();
pushad();
print("Appel d'une interruption\r\n");
popad();
popf();
sti();
iret();
}
void exception0()
{
print("divide error\r\n");
}
void exception1()
{
cpuerror("debug exception\r\n");
}
void exception2()
{
cpuerror("non-maskable hardware interrupt\r\n");
}
void exception3()
{
cpuerror("INT3 instruction\r\n");
}
void exception4()
{
cpuerror("INTO instruction detected overflow\r\n");
}
void exception5()
{
print("BOUND instruction detected overrange\r\n");
}
void exception6()
{
cpuerror("invalid instruction opcode\r\n");
}
void exception7()
{
cpuerror("no coprocessor\r\n");
}
void exception8()
{
cpuerror("double fault\r\n");
}
void exception9()
{
cpuerror("coprocessor segment overrun\r\n");
}
void exception10()
{
cpuerror("invalid task state segment (TSS)\r\n");
}
void exception11()
{
cpuerror("segment not present\r\n");
}
void exception12()
{
cpuerror("stack fault");
}
void exception13()
{
cpuerror("general protection fault (GPF)\r\n");
}
void exception14()
{
cpuerror("page fault\r\n");
}
void exception15()
{
cpuerror("(reserved)\r\n");
}
void exception16()
{
cpuerror("coprocessor error\r\n");
}
void exception17()
{
cpuerror("alignment check\r\n");
}
void exception18()
{
cpuerror("machine check");
}
void irq0()
{
cli();
pushf();
pushad();
print("irq 0");
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq1()
{
cli();
pushf();
pushad();
print("irq 1");
while ((inb(0x64)&1)==0);
inb(0x60);
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq2()
{
cli();
pushf();
pushad();
print("irq 2");
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq3()
{
cli();
pushf();
pushad();
print("irq 3");
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq4()
{
cli();
pushf();
pushad();
print("irq 4");
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq5()
{
cli();
pushf();
pushad();
print("irq 5");
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq6()
{
cli();
pushf();
pushad();
print("irq 6");
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq7()
{
cli();
pushf();
pushad();
print("irq 7");
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq8()
{
cli();
pushf();
pushad();
print("irq 8");
irqendslave();
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq9()
{
cli();
pushf();
pushad();
print("irq 9");
irqendslave();
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq10()
{
cli();
pushf();
pushad();
print("irq 10");
irqendslave();
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq11()
{
cli();
pushf();
pushad();
print("irq 11");
irqendslave();
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq12()
{
cli();
pushf();
pushad();
print("irq 12");
while ((inb(0x64)&1)==0);
inb(0x60);
irqendslave();
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq13()
{
cli();
pushf();
pushad();
print("irq 13");
irqendslave();
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq14()
{
cli();
pushf();
pushad();
print("irq 14");
irqendslave();
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq15()
{
cli();
print("irq 15");
irqendslave();
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void initidt(void)
{
u16 i;
putidt((u32)exception0, 0x20, INTGATE, 0);
putidt((u32)exception1, 0x20, INTGATE, 1);
putidt((u32)exception2, 0x20, INTGATE, 2);
putidt((u32)exception3, 0x20, INTGATE, 3);
putidt((u32)exception4, 0x20, INTGATE, 4);
putidt((u32)exception5, 0x20, INTGATE, 5);
putidt((u32)exception6, 0x20, INTGATE, 6);
putidt((u32)exception7, 0x20, INTGATE, 7);
putidt((u32)exception8, 0x20, INTGATE, 8);
putidt((u32)exception9, 0x20, INTGATE, 9);
putidt((u32)exception10, 0x20, INTGATE, 10);
putidt((u32)exception11, 0x20, INTGATE, 11);
putidt((u32)exception12, 0x20, INTGATE, 12);
putidt((u32)exception13, 0x20, INTGATE, 13);
putidt((u32)exception14, 0x20, INTGATE, 14);
putidt((u32)exception15, 0x20, INTGATE, 15);
putidt((u32)exception16, 0x20, INTGATE, 16);
putidt((u32)exception17, 0x20, INTGATE, 17);
putidt((u32)exception18, 0x20, INTGATE, 18);
for(i=19;i<32;i++)
{
putidt((u32)interruption, 0x20, INTGATE, i);
}
putidt((u32)irq0, 0x20, INTGATE, 32);
putidt((u32)irq1, 0x20, INTGATE, 33);
putidt((u32)irq2, 0x20, INTGATE, 34);
putidt((u32)irq3, 0x20, INTGATE, 35);
putidt((u32)irq4, 0x20, INTGATE, 36);
putidt((u32)irq5, 0x20, INTGATE, 37);
putidt((u32)irq6, 0x20, INTGATE, 38);
putidt((u32)irq7, 0x20, INTGATE, 39);
for(i=40;i<96;i++)
{
putidt((u32)interruption, 0x20, INTGATE, i);
}
putidt((u32)irq8, 0x20, INTGATE, 96);
putidt((u32)irq9, 0x20, INTGATE, 97);
putidt((u32)irq10, 0x20, INTGATE, 98);
putidt((u32)irq11, 0x20, INTGATE, 99);
putidt((u32)irq12, 0x20, INTGATE, 100);
putidt((u32)irq13, 0x20, INTGATE, 101);
putidt((u32)irq14, 0x20, INTGATE, 102);
putidt((u32)irq15, 0x20, INTGATE, 103);
for(i=104;i<255;i++)
{
putidt((u32)interruption, 0x20, INTGATE, i);
}
/* initialise le registre idt */
idtreg.limite = 256*8;
idtreg.base = 0x0000000;
/* recopie de la IDT a son adresse */
memcpy(&idt, (u8*)idtreg.base, idtreg.limite,1);
/* chargement du registre IDTR */
lidt(&idtreg);
}

549
lib/interrupts.c Executable file
View File

@ -0,0 +1,549 @@
#include "interrupts.h"
#include "types.h"
#include "asm.h"
#include "memory.h"
#include "video.h"
/* registre idt */
static struct dtr idtreg;
/* table de IDT */
static idtdes idt[256];
/******************************************************************************/
/* Initialise le controleur d'interruption 8259A */
void initpic(void)
{
/* MASTER */
/* Initialisation de ICW1 */
outb(0x20, 0x11);
nop();
/* Initialisation de ICW2 - vecteur de depart = 32 */
outb(0x21, 0x20);
nop();
/* Initialisation de ICW3 */
outb(0x21, 0x04);
nop();
/* Initialisation de ICW4 */
outb(0x21, 0x01);
nop();
/* masquage des interruptions */
outb(0x21, 0xFF);
nop();
/* SLAVE */
/* Initialisation de ICW1 */
outb(0xA0, 0x11);
nop();
/* Initialisation de ICW2 - vecteur de depart = 96 */
outb(0xA1, 0x60);
nop();
/* Initialisation de ICW3 */
outb(0xA1, 0x02);
nop();
/* Initialisation de ICW4 */
outb(0xA1, 0x01);
nop();
/* masquage des interruptions */
outb(0xA1, 0xFF);
nop();
/* Demasquage des irqs sauf clavier
outb(0x21,0xFD);
nop();
*/
}
/******************************************************************************/
/* Active une IRQ */
void enableirq(u8 irq)
{
u16 port;
cli();
port = (((irq & 0x08) << 4) + 0x21);
outb(port, inb(port) & ~(1 << (irq & 7)));
sti();
}
/******************************************************************************/
/* Désactive une IRQ */
void disableirq(u8 irq)
{
u16 port;
cli();
port = (((irq & 0x08) << 4) + 0x21);
outb(port, inb(port) | (1 << (irq & 7)));
sti();
}
/******************************************************************************/
/* Créé un descripteur pour l'IDT */
void makeidtdes(u32 offset, u16 select, u16 type, idtdes * desc)
{
desc->offset0_15 = (offset & 0xffff);
desc->select = select;
desc->type = type;
desc->offset16_31 = (offset & 0xffff0000) >> 16;
return;
}
/******************************************************************************/
/* Change une entrée dans l'IDT */
void setidt(u32 offset, u16 select, u16 type, u16 index)
{
cli();
idtdes *desc;
desc = idtreg.base;
desc[index].offset0_15 = (offset & 0xffff);
desc[index].select = select;
desc[index].type = type;
desc[index].offset16_31 = (offset & 0xffff0000) >> 16;
sti();
}
/******************************************************************************/
/* Met une entrée dans l'IDT */
void putidt(u32 offset, u16 select, u16 type, u16 index)
{
idtdes temp;
makeidtdes(offset, select, type, &temp);
idt[index] = temp;
}
/******************************************************************************/
/* Affiche une erreur CPU et fige l'ordinateur */
void cpuerror(const u8 * src)
{
print("\033[31m***** ERREUR CPU ****\r\n -");
print(src);
dump_regs();
while (1) {
nop();
}
}
/******************************************************************************/
/* Déclenché lors de l'appel d'une interruption */
void interruption()
{
cli();
pushf();
pushad();
print("Appel d'une interruption\r\n");
popad();
popf();
sti();
iret();
}
/******************************************************************************/
/* Les expections */
void exception0()
{
print("divide error\r\n");
}
void exception1()
{
cpuerror("debug exception\r\n");
}
void exception2()
{
cpuerror("non-maskable hardware interrupt\r\n");
}
void exception3()
{
cpuerror("INT3 instruction\r\n");
}
void exception4()
{
cpuerror("INTO instruction detected overflow\r\n");
}
void exception5()
{
print("BOUND instruction detected overrange\r\n");
}
void exception6()
{
cpuerror("invalid instruction opcode\r\n");
}
void exception7()
{
cpuerror("no coprocessor\r\n");
}
void exception8()
{
cpuerror("double fault\r\n");
}
void exception9()
{
cpuerror("coprocessor segment overrun\r\n");
}
void exception10()
{
cpuerror("invalid task state segment (TSS)\r\n");
}
void exception11()
{
cpuerror("segment not present\r\n");
}
void exception12()
{
cpuerror("stack fault");
}
void exception13()
{
cpuerror("general protection fault (GPF)\r\n");
}
void exception14()
{
cpuerror("page fault\r\n");
}
void exception15()
{
cpuerror("(reserved)\r\n");
}
void exception16()
{
cpuerror("coprocessor error\r\n");
}
void exception17()
{
cpuerror("alignment check\r\n");
}
void exception18()
{
cpuerror("machine check");
}
/******************************************************************************/
/* Les IRQ par défaut */
void irq0()
{
cli();
pushf();
pushad();
print("irq 0");
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq1()
{
cli();
pushf();
pushad();
print("irq 1");
while ((inb(0x64) & 1) == 0) ;
inb(0x60);
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq2()
{
cli();
pushf();
pushad();
print("irq 2");
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq3()
{
cli();
pushf();
pushad();
print("irq 3");
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq4()
{
cli();
pushf();
pushad();
print("irq 4");
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq5()
{
cli();
pushf();
pushad();
print("irq 5");
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq6()
{
cli();
pushf();
pushad();
print("irq 6");
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq7()
{
cli();
pushf();
pushad();
print("irq 7");
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq8()
{
cli();
pushf();
pushad();
print("irq 8");
irqendslave();
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq9()
{
cli();
pushf();
pushad();
print("irq 9");
irqendslave();
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq10()
{
cli();
pushf();
pushad();
print("irq 10");
irqendslave();
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq11()
{
cli();
pushf();
pushad();
print("irq 11");
irqendslave();
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq12()
{
cli();
pushf();
pushad();
print("irq 12");
while ((inb(0x64) & 1) == 0) ;
inb(0x60);
irqendslave();
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq13()
{
cli();
pushf();
pushad();
print("irq 13");
irqendslave();
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq14()
{
cli();
pushf();
pushad();
print("irq 14");
irqendslave();
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
void irq15()
{
cli();
print("irq 15");
irqendslave();
irqendmaster();
popad();
popf();
sti();
asm("addl $0x01C, %esp;");
iret();
}
/******************************************************************************/
/* Initialise une IDT */
void initidt(void)
{
u16 i;
putidt((u32) exception0, 0x20, INTGATE, 0);
putidt((u32) exception1, 0x20, INTGATE, 1);
putidt((u32) exception2, 0x20, INTGATE, 2);
putidt((u32) exception3, 0x20, INTGATE, 3);
putidt((u32) exception4, 0x20, INTGATE, 4);
putidt((u32) exception5, 0x20, INTGATE, 5);
putidt((u32) exception6, 0x20, INTGATE, 6);
putidt((u32) exception7, 0x20, INTGATE, 7);
putidt((u32) exception8, 0x20, INTGATE, 8);
putidt((u32) exception9, 0x20, INTGATE, 9);
putidt((u32) exception10, 0x20, INTGATE, 10);
putidt((u32) exception11, 0x20, INTGATE, 11);
putidt((u32) exception12, 0x20, INTGATE, 12);
putidt((u32) exception13, 0x20, INTGATE, 13);
putidt((u32) exception14, 0x20, INTGATE, 14);
putidt((u32) exception15, 0x20, INTGATE, 15);
putidt((u32) exception16, 0x20, INTGATE, 16);
putidt((u32) exception17, 0x20, INTGATE, 17);
putidt((u32) exception18, 0x20, INTGATE, 18);
for (i = 19; i < 32; i++) {
putidt((u32) interruption, 0x20, INTGATE, i);
}
putidt((u32) irq0, 0x20, INTGATE, 32);
putidt((u32) irq1, 0x20, INTGATE, 33);
putidt((u32) irq2, 0x20, INTGATE, 34);
putidt((u32) irq3, 0x20, INTGATE, 35);
putidt((u32) irq4, 0x20, INTGATE, 36);
putidt((u32) irq5, 0x20, INTGATE, 37);
putidt((u32) irq6, 0x20, INTGATE, 38);
putidt((u32) irq7, 0x20, INTGATE, 39);
for (i = 40; i < 96; i++) {
putidt((u32) interruption, 0x20, INTGATE, i);
}
putidt((u32) irq8, 0x20, INTGATE, 96);
putidt((u32) irq9, 0x20, INTGATE, 97);
putidt((u32) irq10, 0x20, INTGATE, 98);
putidt((u32) irq11, 0x20, INTGATE, 99);
putidt((u32) irq12, 0x20, INTGATE, 100);
putidt((u32) irq13, 0x20, INTGATE, 101);
putidt((u32) irq14, 0x20, INTGATE, 102);
putidt((u32) irq15, 0x20, INTGATE, 103);
for (i = 104; i < 255; i++) {
putidt((u32) interruption, 0x20, INTGATE, i);
}
/* initialise le registre idt */
idtreg.limite = 256 * 8;
idtreg.base = 0x0000000;
/* recopie de la IDT a son adresse */
memcpy(&idt, (u8 *) idtreg.base, idtreg.limite, 1);
/* chargement du registre IDTR */
lidt(&idtreg);
}

View File

@ -1,4 +1,4 @@
#include "idt.h" #include "interrupts.h"
#include "types.h" #include "types.h"
#include "asm.h" #include "asm.h"
#include "memory.h" #include "memory.h"
@ -6,258 +6,273 @@
#include "video.h" #include "video.h"
static u8 bufferscan[256]={0}; static u8 bufferscan[256] = { 0 };
static u8 bufferascii[256]={0}; static u8 bufferascii[256] = { 0 };
static u8 ptrscan=0;
static u8 ptrascii=0;
static u16 kbdstatus,breakcode ;
static const u8 set1_normal[] = static u8 ptrscan = 0;
{ static u8 ptrascii = 0;
0, 0x1B, '&', 'é', '\"', '\'', '(', '-', static u16 kbdstatus, breakcode;
/******************************************************************************/
/* Tables clavier */
static const u8 set1_normal[] = {
0, 0x1B, '&', 'é', '\"', '\'', '(', '-',
'è', '_', 'ç', 'à', ')', '=', '\b', '\t', 'è', '_', 'ç', 'à', ')', '=', '\b', '\t',
'a', 'z', 'e', 'r', 't', 'y', 'u', 'i', 'a', 'z', 'e', 'r', 't', 'y', 'u', 'i',
'o', 'p', '^', '$', '\r', 0, 'q', 's', 'o', 'p', '^', '$', '\r', 0, 'q', 's',
'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm',
'ù', '²', 0, '*', 'w', 'x', 'c', 'v', 'ù', '²', 0, '*', 'w', 'x', 'c', 'v',
'b', 'n', ',', ';', ':', '!', 0, '*', 'b', 'n', ',', ';', ':', '!', 0, '*',
0, ' ', 0, 0, 0, 0, 0, 0, 0, ' ', 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, '7', 0, 0, 0, 0, 0, 0, 0, '7',
'8', '9','-', '4','5','6', '+', '1', '8', '9', '-', '4', '5', '6', '+', '1',
'2', '3','0','.',0, 0, '<', 0, '2', '3', '0', '.', 0, 0, '<', 0,
0 0
}; };
static const u8 set1_shift[] = static const u8 set1_shift[] = {
{ 0, 0x1B, '1', '2', '3', '4', '5', '6',
0, 0x1B, '1', '2', '3', '4', '5', '6',
'7', '8', '9', '0', '°', '+', '\b', '\t', '7', '8', '9', '0', '°', '+', '\b', '\t',
'A', 'Z', 'E', 'R', 'T', 'Y', 'U', 'I', 'A', 'Z', 'E', 'R', 'T', 'Y', 'U', 'I',
'O', 'P', '¨', '£', '\r', 0, 'Q', 'S', 'O', 'P', '¨', '£', '\r', 0, 'Q', 'S',
'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M',
'%', 0, 0, 'µ', 'W', 'X', 'C', 'V', '%', 0, 0, 'µ', 'W', 'X', 'C', 'V',
'B', 'N', '?', '.', '/', '§', 0, '*', 'B', 'N', '?', '.', '/', '§', 0, '*',
0, ' ', 0, 0, 0, 0, 0, 0, 0, ' ', 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,0, 0, '7', 0, 0, 0, 0, 0, 0, 0, '7',
'8', '9','-', '4','5','6', '+', '1', '8', '9', '-', '4', '5', '6', '+', '1',
'2', '3','0','.',0, 0, '>', 0, '2', '3', '0', '.', 0, 0, '>', 0,
0 0
}; };
static const u8 set1_alt[] = static const u8 set1_alt[] = {
{ 0, 0x1B, 0, 0, 0, 0, 0, 0,
0, 0x1B, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, '\r', 0, 0, 0, 0, 0, 0, 0, '\r', 0, 0, 0,
0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, '*', 0, 0, 0, 0, 0, 0, 0, '*',
0, ' ', 0, 0, 0, 0, 0, 0, 0, ' ', 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,0, 0, '7', 0, 0, 0, 0, 0, 0, 0, '7',
'8', '9','-', '4','5','6', '+', '1', '8', '9', '-', '4', '5', '6', '+', '1',
'2', '3','0','.',0, 0, 0, 0, '2', '3', '0', '.', 0, 0, 0, 0,
0 0
}; };
static const u8 set1_altgr[] = {
static const u8 set1_altgr[] = 0, 0x1B, 0, '~', '#', '{', '[', '|',
{
0, 0x1B, 0, '~', '#', '{', '[', '|',
'`', '\\', '^', '@', ']', '}', '\b', '\t', '`', '\\', '^', '@', ']', '}', '\b', '\t',
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, '¤', '\r', 0, 0, 0, 0, 0, 0, '¤', '\r', 0, 0, 0,
0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, '*', 0, 0, 0, 0, 0, 0, 0, '*',
0, ' ', 0, 0, 0, 0, 0, 0, 0, ' ', 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,0, 0, '7', 0, 0, 0, 0, 0, 0, 0, '7',
'8', '9','-', '4','5','6', '+', '1', '8', '9', '-', '4', '5', '6', '+', '1',
'2', '3','0','.',0, 0, 0, 0, '2', '3', '0', '.', 0, 0, 0, 0,
0 0
}; };
static const u8 set1_ctrl[] = static const u8 set1_ctrl[] = {
{ 0, 0x1B, 0, 0, 0, 0, 0x1B, 0,
0, 0x1B, 0, 0,0, 0, 0x1B, 0,
0, 0x1C, 0, 0, 0x1D, 0, 0, 0x1F, 0, 0x1C, 0, 0, 0x1D, 0, 0, 0x1F,
0x01, 0x1A, 0x05, 0x012, 0x14, 0x19, 0x15, 0x09, 0x01, 0x1A, 0x05, 0x012, 0x14, 0x19, 0x15, 0x09,
0x0F, 0x10, 0x1E, 0, 0, 0, 0x11, 0x13, 0x0F, 0x10, 0x1E, 0, 0, 0, 0x11, 0x13,
0x04, 0x06, 0x07,0x08, 0x0A, 0x0B, 0x0C, 0x0D, 0x04, 0x06, 0x07, 0x08, 0x0A, 0x0B, 0x0C, 0x0D,
0, 0, 0, 0, 0x17, 0x18, 0x03, 0x16, 0, 0, 0, 0, 0x17, 0x18, 0x03, 0x16,
0x02, 0x0E, 0, 0, 0, 0, 0, '*', 0x02, 0x0E, 0, 0, 0, 0, 0, '*',
0, ' ', 0, 0, 0, 0, 0, 0, 0, ' ', 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,0, 0, '7', 0, 0, 0, 0, 0, 0, 0, '7',
'8', '9','-', '4','5','6', '+', '1', '8', '9', '-', '4', '5', '6', '+', '1',
'2', '3','0','.',0, 0, 0, 0, '2', '3', '0', '.', 0, 0, 0, 0,
0 0
}; };
/******************************************************************************/ /******************************************************************************/
/* Fonction qui attend l'appuie d'une touche générant un code ASCII puis le retourne */
u8 waitascii() u8 waitascii()
{ {
u8 oldptrscan=ptrscan; u8 oldptrscan = ptrscan;
u8 oldptrascii=ptrascii; u8 oldptrascii = ptrascii;
while((oldptrascii==ptrascii));/*(oldptrscan==ptrscan)&&*/ while ((oldptrascii == ptrascii)) ;
return bufferascii[ptrascii]; return bufferascii[ptrascii];
} }
/******************************************************************************/ /******************************************************************************/
/* Envoi d'une commande vers le contrôleur de clavier */
void outkbd(u8 port, u8 data) void outkbd(u8 port, u8 data)
{ {
u32 timeout; u32 timeout;
u8 state; u8 state;
/* timeout */ /* timeout */
for(timeout = 500000L; timeout != 0; timeout--) for (timeout = 500000L; timeout != 0; timeout--) {
{
state = inb(0x64); state = inb(0x64);
/* vide le buffer du 8042 */ /* vide le buffer du 8042 */
if((state & 0x02) == 0) break; if ((state & 0x02) == 0)
break;
} }
if(timeout != 0) if (timeout != 0)
outb(port, data); outb(port, data);
} }
/******************************************************************************/ /******************************************************************************/
/* Redemarre l'ordinateur */
static void reboot(void) static void reboot(void)
{ {
u8 temp; u8 temp;
cli(); cli();
/* vide le 8042 */ /* vide le 8042 */
do do {
{
temp = inb(0x64); temp = inb(0x64);
if((temp & 0x01) != 0) if ((temp & 0x01) != 0) {
{
(void)inb(0x60); (void)inb(0x60);
continue; continue;
} }
} while((temp & 0x02) != 0); } while ((temp & 0x02) != 0);
/* active le reset CPU */ /* active le reset CPU */
outb(0x64, 0xFE); outb(0x64, 0xFE);
while(1) while (1)
/* boucle infinie */; /* boucle infinie */ ;
} }
/******************************************************************************/ /******************************************************************************/
/* Converti un scancode vers une code ASCII */
unsigned convert(u32 keypressed) unsigned convert(u32 keypressed)
{ {
u8 temp,key,lastscan; u8 temp, key, lastscan;
/* garde le dernier pointeur du buffer scan */ /* garde le dernier pointeur du buffer scan */
lastscan=ptrscan; lastscan = ptrscan;
/* incrémente le pointeur est assigne au buffer le dernier scancode */ /* incrémente le pointeur est assigne au buffer le dernier scancode */
ptrscan++; ptrscan++;
if (ptrscan==255) ptrscan==0; if (ptrscan == 255)
bufferscan[ptrscan]=keypressed; ptrscan == 0;
bufferscan[ptrscan] = keypressed;
/* break key (touche relaché) ? */ /* break key (touche relaché) ? */
if(keypressed >= 0x80) breakcode = 1; if (keypressed >= 0x80)
key = (keypressed&0x7F); breakcode = 1;
key = (keypressed & 0x7F);
/* Mise a jour des flags lors du relachement de touches de controle */ /* Mise a jour des flags lors du relachement de touches de controle */
if(breakcode) if (breakcode) {
{ if (key == SCAN_ALT) {
if(key == SCAN_ALT)
{
kbdstatus &= ~STATUS_ALT; kbdstatus &= ~STATUS_ALT;
/* si ALT GR (E01D) alors activer aussi control */ /* si ALT GR (E01D) alors activer aussi control */
if (bufferscan[lastscan]==0xE0) kbdstatus &= ~STATUS_CTRL; if (bufferscan[lastscan] == 0xE0)
}
else if(key == SCAN_CTRL)
kbdstatus &= ~STATUS_CTRL; kbdstatus &= ~STATUS_CTRL;
else if(key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) } else if (key == SCAN_CTRL)
kbdstatus &= ~STATUS_CTRL;
else if (key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT)
kbdstatus &= ~STATUS_SHIFT; kbdstatus &= ~STATUS_SHIFT;
breakcode = 0; breakcode = 0;
return 0; return 0;
} }
/* Mise a jour des flags lors de l'appuie de touches de controle */ /* Mise a jour des flags lors de l'appuie de touches de controle */
if(key == SCAN_ALT) if (key == SCAN_ALT) {
{
kbdstatus |= STATUS_ALT; kbdstatus |= STATUS_ALT;
/* si ALT GR (E01D) alors desactiver aussi control */ /* si ALT GR (E01D) alors desactiver aussi control */
if (bufferscan[lastscan]==0xE0) kbdstatus |= STATUS_CTRL; if (bufferscan[lastscan] == 0xE0)
return 0;
}
if(key == SCAN_CTRL)
{
kbdstatus |= STATUS_CTRL; kbdstatus |= STATUS_CTRL;
return 0; return 0;
} }
if(key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) if (key == SCAN_CTRL) {
{ kbdstatus |= STATUS_CTRL;
return 0;
}
if (key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) {
kbdstatus |= STATUS_SHIFT; kbdstatus |= STATUS_SHIFT;
return 0; return 0;
} }
if ((key >= SCAN_F1) && (key <= SCAN_F8)) if ((key >= SCAN_F1) && (key <= SCAN_F8)) {
{ changevc(key - SCAN_F1);
changevc(key-SCAN_F1);
} }
/* Scroll Lock, Num Lock, and Caps Lock mise a jour des leds */ /* Scroll Lock, Num Lock, and Caps Lock mise a jour des leds */
if(key == SCAN_SCROLLLOCK) if (key == SCAN_SCROLLLOCK) {
{
kbdstatus ^= STATUS_SCRL; kbdstatus ^= STATUS_SCRL;
goto LEDS; goto LEDS;
} }
if(key == SCAN_NUMLOCK) if (key == SCAN_NUMLOCK) {
{
kbdstatus ^= STATUS_NUM; kbdstatus ^= STATUS_NUM;
goto LEDS; goto LEDS;
} }
if(key == SCAN_CAPSLOCK) if (key == SCAN_CAPSLOCK) {
{
kbdstatus ^= STATUS_CAPS; kbdstatus ^= STATUS_CAPS;
LEDS: LEDS:
outkbd(0x60, 0xED); /* "mise a jour des LEDS */ outkbd(0x60, 0xED); /* "mise a jour des LEDS */
temp = 0; temp = 0;
if(kbdstatus & STATUS_SCRL) if (kbdstatus & STATUS_SCRL)
temp |= 1; temp |= 1;
if(kbdstatus & STATUS_NUM) if (kbdstatus & STATUS_NUM)
temp |= 2; temp |= 2;
if(kbdstatus & STATUS_CAPS) if (kbdstatus & STATUS_CAPS)
temp |= 4; temp |= 4;
outkbd(0x60, temp); /* 3 bits de poids faible pour les LEDs */ outkbd(0x60, temp); /* 3 bits de poids faible pour les LEDs */
return 0; return 0;
} }
/* est ce un code etendu */ /* est ce un code etendu */
if ((bufferscan[lastscan]==0xE0)||((kbdstatus & STATUS_NUM)&&(key>=0x47)&&(key<=0x53)&&(key!=0x4A)&&(key!=0x4e))) if ((bufferscan[lastscan] == 0xE0)
|| ((kbdstatus & STATUS_NUM) && (key >= 0x47) && (key <= 0x53)
&& (key != 0x4A) && (key != 0x4e)))
/* exceptions */ /* exceptions */
{ {
/* '/' (E035) */ /* '/' (E035) */
if (key==0x35) return '/'; if (key == 0x35)
/* '\r' (E01C) 2ème enter numérique*/ return '/';
if (key==0x1C) return '\r'; /* '\r' (E01C) 2ème enter numérique */
/* 0x11 (E048) device control 1)*/ if (key == 0x1C)
if (key==0x48) return 0x11; return '\r';
/* 0x12 (E050) device control 2)*/ /* 0x11 (E048) device control 1) */
if (key==0x50) return 0x12; if (key == 0x48)
/* 0x13 (E04b) device control 3)*/ return 0x11;
if (key==0x4b) return 0x13; /* 0x12 (E050) device control 2) */
/* 0x14 (E04d) device control 4)*/ if (key == 0x50)
if (key==0x4d) return 0x14; return 0x12;
/* 0x02 (E049) start of text)*/ /* 0x13 (E04b) device control 3) */
if (key==0x49) return 0x2; if (key == 0x4b)
/* 0x03 (E051) end of text)*/ return 0x13;
if (key==0x51) return 0x3; /* 0x14 (E04d) device control 4) */
/* 0x10 (E047) Line feed)*/ if (key == 0x4d)
if (key==0x47) return '\n'; return 0x14;
/* 0x1A (E052) Substitution)*/ /* 0x02 (E049) start of text) */
if (key==0x52) return 0x1A; if (key == 0x49)
/* 0x18 (E053) Cancel)*/ return 0x2;
if (key==0x53) return 0x18; /* 0x03 (E051) end of text) */
/* 0x19 (E04f) End of medium)*/ if (key == 0x51)
if (key==0x4f) return 0x19; return 0x3;
/* 0x10 (E047) Line feed) */
if (key == 0x47)
return '\n';
/* 0x1A (E052) Substitution) */
if (key == 0x52)
return 0x1A;
/* 0x18 (E053) Cancel) */
if (key == 0x53)
return 0x18;
/* 0x19 (E04f) End of medium) */
if (key == 0x4f)
return 0x19;
return 0x00; return 0x00;
} } else {
else
{
/* detecte les SCANCODES invalides */ /* detecte les SCANCODES invalides */
if(key >= sizeof(set1_normal) / sizeof(set1_normal[0])) return 0; if (key >= sizeof(set1_normal) / sizeof(set1_normal[0]))
return 0;
/* converti le scancode en code ASCII en fonction du statut*/ /* converti le scancode en code ASCII en fonction du statut*/
if (kbdstatus & STATUS_SHIFT||kbdstatus & STATUS_CAPS) if (kbdstatus & STATUS_SHIFT || kbdstatus & STATUS_CAPS)
temp = set1_shift[key]; temp = set1_shift[key];
else if ((kbdstatus & STATUS_ALT)&&(kbdstatus & STATUS_CTRL)) else if ((kbdstatus & STATUS_ALT) && (kbdstatus & STATUS_CTRL))
temp = set1_altgr[key]; temp = set1_altgr[key];
else if (kbdstatus & STATUS_CTRL) else if (kbdstatus & STATUS_CTRL)
temp = set1_ctrl[key]; temp = set1_ctrl[key];
@ -268,11 +283,11 @@ if ((bufferscan[lastscan]==0xE0)||((kbdstatus & STATUS_NUM)&&(key>=0x47)&&(key<=
} }
/* si scancode non reconnu fin de fonction */ /* si scancode non reconnu fin de fonction */
if(temp == 0) return temp; if (temp == 0)
return temp;
/* Appuie de CRTL + ALT + SUPR ? */ /* Appuie de CRTL + ALT + SUPR ? */
if((kbdstatus & STATUS_CTRL) && (kbdstatus & STATUS_ALT) && if ((kbdstatus & STATUS_CTRL) && (kbdstatus & STATUS_ALT) &&
(key == 76)) (key == 76)) {
{
print("redemarrage du systeme"); print("redemarrage du systeme");
reboot(); reboot();
} }
@ -280,26 +295,27 @@ if ((bufferscan[lastscan]==0xE0)||((kbdstatus & STATUS_NUM)&&(key>=0x47)&&(key<=
return temp; return temp;
} }
/******************************************************************************/ /******************************************************************************/
/* Handler d'interruption IRQ 1 pour le clavier */
void keyboard() void keyboard()
{ {
cli(); cli();
pushf(); pushf();
pushad(); pushad();
u8 scancode,ascii; u8 scancode, ascii;
cli(); cli();
while ((inb(0x64)&1)==0); while ((inb(0x64) & 1) == 0) ;
scancode=inb(0x60); scancode = inb(0x60);
ascii = convert(scancode); ascii = convert(scancode);
if(ascii != 0) if (ascii != 0) {
{ ptrascii++;
ptrascii++; if (ptrascii == 255)
if (ptrascii==255) ptrascii==0; ptrascii == 0;
bufferascii[ptrascii]=ascii; bufferascii[ptrascii] = ascii;
} }
irqendmaster(); irqendmaster();
popad(); popad();
popf(); popf();
sti(); sti();

View File

View File

@ -1,6 +1,6 @@
CC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -fomit-frame-pointer -Wall -w -m32 -F pe-i386 -I ../include CC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -fomit-frame-pointer -Wall -w -m32 -F pe-i386 -I ../include
LINK=ld -m elf_i386 -r -o LINK=ld -m elf_i386 -r -o
OBJS=memory.o vga.o port.o video.o mouse.o idt.o timer.o keyboard.o types.o string.o graph.o 3d.o math.o cpu.o OBJS=memory.o vga.o video.o mouse.o interrupts.o timer.o keyboard.o types.o string.o 2d.o 3d.o math.o cpu.o
all: makeall all: makeall

View File

@ -1,7 +1,12 @@
#include "types.h" #include "types.h"
u32 abs(int x) /******************************************************************************/
{
if (x<0) x=-x; /* Fonction qui retourne la valeur absolue */
return (u32)x;
u32 abs(int x) {
if (x < 0)
x = -x;
return (u32) x;
} }

View File

@ -3,12 +3,12 @@
/*******************************************************************************/ /*******************************************************************************/
/* Copie un octet une ou plusieurs fois en mémoire */ /* Copie un octet une ou plusieurs fois en mémoire */
void memset(void *dst, u8 val, u32 count,u32 size)
void memset(void *dst, u8 val, u32 count, u32 size)
{ {
u8 *temp; u8 * temp;
for(temp = (u8 *)dst; count != 0; count--) for (temp = (u8 *) dst; count != 0; count--) {
{ temp += size;
temp+=size;
*temp = val; *temp = val;
} }
} }
@ -16,30 +16,30 @@ void memset(void *dst, u8 val, u32 count,u32 size)
/*******************************************************************************/ /*******************************************************************************/
/* Copie une portion de mémoire vers une autre */ /* Copie une portion de mémoire vers une autre */
void memcpy(void *src, void *dst, u32 count, u32 size)
{ void memcpy(void *src, void *dst, u32 count, u32 size) {
char *s, *d; char *s, *d;
u32 i; u32 i;
s = (u8*) src; s = (u8 *) src;
d = (u8*) dst; d = (u8 *) dst;
for(i=0;i<count;i++){ for (i = 0; i < count; i++) {
*(d+i*size) = *(s+i); *(d + i * size) = *(s + i);
} }
} }
/*******************************************************************************/ /*******************************************************************************/
/* Compare 2 portions de mémoire */ /* Compare 2 portions de mémoire */
u32 memcmp(void *src, void *dst, u32 count, u32 size) u32 memcmp(void *src, void *dst, u32 count, u32 size)
{ {
const u8 *mem1 = (const u8 *)src; const u8 *mem1 = (const u8 *)src;
const u8 *mem2 = (const u8 *)dst; const u8 *mem2 = (const u8 *)dst;
for(; count != 0; count--) for (; count != 0; count--) {
{ if (*mem1 != *mem2)
if(*mem1 != *mem2)
return *mem1 - *mem2; return *mem1 - *mem2;
mem1+=size; mem1 += size;
mem2+=size; mem2 += size;
} }
} }

View File

@ -1,225 +0,0 @@
/* definition des registres de la carte VGA pour differents modes */
#define maxgraphmode 11
#define maxtextmode 5
static mode_def textmodes[maxtextmode] = {
/*40*25 16 couleurs mode 0x00*/
{
0x67,
0x03, 0x08, 0x03, 0x00, 0x02,
0x2D, 0x27, 0x28, 0x90, 0x2B, 0xA0, 0xBF, 0x1F, 0x00,
0x4F, 0x0D, 0x0E, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x8E, 0x8F, 0x14, 0x1F, 0x96, 0xB9, 0xA3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x0C, 0x00, 0x0F, 0x08, 0x00,
45, 25, 4
},
/*80*25 16 couleurs mode 0x01*/
{
0x67,
0x03, 0x00, 0x03, 0x00, 0x02,
0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F, 0x00,
0x4F, 0x0D, 0x0E, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x0E, 0x8F, 0x28, 0x1F, 0x96, 0xB9, 0xA3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x0C, 0x00, 0x0F, 0x08, 0x00,
80, 25, 4
},
/*80*50 16 couleurs mode 0x02*/
{
0x63,
0x03, 0x01, 0x03, 0x05, 0x02,
0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F, 0x00,
0x47, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x8E, 0x8F, 0x28, 0x1F, 0x96, 0xB9, 0xA3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x0C, 0x00, 0x0F, 0x00, 0x00,
80, 50, 4
},
/*100*50 16 couleurs mode 0x03*/
{
0x67,
0x03, 0x01, 0x03, 0x05, 0x02,
0x70, 0x63, 0x64, 0x85, 0x68, 0x84, 0xBF, 0x1F, 0x00,
0x47, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x8E, 0x8F, 0x32, 0x1F, 0x96, 0xB9, 0xA3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x0C, 0x00, 0x0F, 0x00, 0x00,
100, 50, 4
},
/*100*60 16 couleurs mode 0x04*/
{
0xA7,
0x03, 0x01, 0x03, 0x05, 0x02,
0x70, 0x63, 0x64, 0x85, 0x68, 0x84, 0xFF, 0x1F, 0x00,
0x47, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
0xE7, 0x8E, 0xDF, 0x32, 0x1F, 0xDF, 0xE5, 0xA3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x0C, 0x00, 0x0F, 0x00, 0x00,
100, 60, 4
}
};
static mode_def graphmodes[maxgraphmode] = {
/*640*480 n&b mode 0x80*/
{
0xE3,
0x03, 0x01, 0x0F, 0x00, 0x06,
0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xEA, 0x0C, 0xDF, 0x28, 0x00, 0xE7, 0x04, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x01, 0x00, 0x0F, 0x00, 0x00,
80, 60, 1
},
/*320*200 4 couleurs mode 0x81*/
{
0x63,
0x03, 0x09, 0x03, 0x00, 0x02,
0x2D, 0x27, 0x28, 0x90, 0x2B, 0x80, 0xBF, 0x1F, 0x00,
0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x0E, 0x8F, 0x14, 0x00, 0x96, 0xB9, 0xA3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x02, 0x00, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x01, 0x00, 0x03, 0x00, 0x00,
40, 25,
},
/*640*480 16 couleurs mode 0x82*/
{
0xE3,
0x03, 0x01, 0x0F, 0x00, 0x06,
0x5F, 0x4F, 0x50, 0x82, 0x53, 0x9F, 0x0B, 0x3E, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xE9, 0x8B, 0xDF, 0x28, 0x00, 0xE7, 0x04, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x01, 0x00, 0x0F, 0x00, 0x00,
80, 60, 4
},
/*720*480 16 couleurs mode 0x83*/
{
0xE7,
0x03, 0x01, 0x08, 0x00, 0x06,
0x6B, 0x59, 0x5A, 0x82, 0x60, 0x8D, 0x0B, 0x3E, 0x00,
0x40, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
0xEA, 0x0C, 0xDF, 0x2D, 0x08, 0xE8, 0x05, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x01, 0x00, 0x0F, 0x00, 0x00,
90, 60, 4
},
/*800*600 16 couleurs mode 0x84*/
{
0xE7,
0x03, 0x01, 0x0F, 0x00, 0x06,
0x70, 0x63, 0x64, 0x92, 0x65, 0x82, 0x70, 0xF0, 0x00,
0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x5B, 0x8C, 0x57, 0x32, 0x00, 0x58, 0x70, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x01, 0x00, 0x0F, 0x00, 0x00,
100, 75, 4
},
/*320*200 256 couleurs RAPIDE mode 0x85*/
{
0x63,
0x03, 0x01, 0x0F, 0x00, 0x0E,
0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F, 0x00,
0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x0E, 0x8F, 0x28, 0x40, 0x96, 0xB9, 0xA3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x41, 0x00, 0x0F, 0x00, 0x00,
40, 25, 8
},
/*320*200 256 couleurs mode 0x86*/
{
0x63,
0x03, 0x01, 0x0F, 0x00, 0x06,
0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F, 0x00,
0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x0E, 0x8F, 0x28, 0x00, 0x96, 0xB9, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x41, 0x00, 0x0F, 0x00, 0x00,
40, 25, 8
},
/*320*400 256 couleurs mode 0x87*/
{
0x63,
0x03, 0x01, 0x0F, 0x00, 0x06,
0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x8E, 0x8F, 0x28, 0x00, 0x96, 0xB9, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x41, 0x00, 0x0F, 0x00, 0x00,
40, 50, 8
},
/*320*480 256 couleurs mode 0x88*/
{
0xE3,
0x03, 0x01, 0x0F, 0x00, 0x06,
0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xEA, 0xAC, 0xDF, 0x28, 0x00, 0xE7, 0x06, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x41, 0x00, 0x0F, 0x00, 0x00,
40, 60, 8
},
/*360*480 256 couleurs mode 0x89*/
{
0xE7,
0x03, 0x01, 0x0F, 0x00, 0x06,
0x6B, 0x59, 0x5A, 0x8E, 0x5E, 0x8A, 0x0D, 0x3E, 0x00,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xEA, 0xAC, 0xDF, 0x2D, 0x00, 0xE7, 0x06, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x41, 0x00, 0x0F, 0x00, 0x00,
45, 60, 8
},
/*400*600 256 couleurs mode 0x8A*/
{
0xE7,
0x03, 0x01, 0x0F, 0x00, 0x06,
0x74, 0x63, 0x64, 0x97, 0x68, 0x95, 0x86, 0xF0, 0x00,
0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x5B, 0x8D, 0x57, 0x32, 0x00, 0x60, 0x80, 0xE3, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x41, 0x00, 0x0F, 0x00, 0x00,
50, 75, 8
}
};

View File

@ -5,134 +5,142 @@
#include "vga.h" #include "vga.h"
#include "video.h" #include "video.h"
/******************************************************************************/
/* initialise la souris */
bool initmouse() bool initmouse()
{ {
u16 i=1024; u16 i = 1024;
outkbd(0x64,0xA8); /* autorisé Aux */ outkbd(0x64, 0xA8); /* autorisé Aux */
outmseack(0xf3); /*sample*/ outmseack(0xf3); /*sample */
outmseack(100); /*sample donnée*/ outmseack(100); /*sample donnée */
outmseack(0xe8); /*resolution*/ outmseack(0xe8); /*resolution */
outmseack(3); /*resolution donnée*/ outmseack(3); /*resolution donnée */
outmseack(0xe7); /* echelle 2:1*/ outmseack(0xe7); /* echelle 2:1 */
outmseack(0xf4); /* Autorise peripherique */ outmseack(0xf4); /* Autorise peripherique */
outmsecmd(0x47); /* Autorise interruption */ outmsecmd(0x47); /* Autorise interruption */
while(i-->0) if (inb(0x60)==250) return 1; while (i-- > 0)
return 0; if (inb(0x60) == 250)
return 1;
return 0;
} }
static u8 bytepos=0,mousereplies=0; static u8 bytepos = 0, mousereplies = 0;
static u8 mpacket[3]; static u8 mpacket[3];
static s32 mousex=40, mousey=12; static s32 mousex = 40, mousey = 12;
static u16 oldx=0, oldy=0; static u16 oldx = 0, oldy = 0;
static u8 oldchar=0x00,oldattr=0x07; static u8 oldchar = 0x00, oldattr = 0x07;
static bool mousebut1=0,mousebut2=0,mousebut3=0; static bool mousebut1 = 0, mousebut2 = 0, mousebut3 = 0;
static u8 speed=6; static u8 speed = 6;
/******************************************************************************/
/* ecriture vers souris */
void outmseack(u8 value) void outmseack(u8 value)
{ {
outkbd(0x64,0xD4); /* ecriture vers souris */ outkbd(0x64, 0xD4);
outb(0x60,value); outb(0x60, value);
mousereplies++; mousereplies++;
} }
/* ecriture vers mode */
void outmsecmd(u8 command) void outmsecmd(u8 command)
{ {
outkbd(0x64,0x60); /* ecriture vers mode */ outkbd(0x64, 0x60);
outb(0x60,command); outb(0x60, command);
} }
/******************************************************************************/
/* Handler d'interruption de la souris IRQ 12 */
void mouse() void mouse()
{ {
u8 mbyte=inb(0x60); cli();
s8 changex,changey; pushf();
cli(); pushad();
u8 mbyte = inb(0x60);
s8 changex, changey;
if (mousereplies > 0) if (mousereplies > 0) {
{ if (mbyte == 0xFA) {
if (mbyte == 0xFA)
{
mousereplies--; mousereplies--;
goto endofint; goto endofint;
} }
mousereplies = 0; mousereplies = 0;
} }
mpacket[bytepos]=mbyte; mpacket[bytepos] = mbyte;
bytepos++; bytepos++;
if(bytepos==3) { if (bytepos == 3) {
bytepos=0; bytepos = 0;
if ( mpacket[1] == 0) if (mpacket[1] == 0) {
{
changex = 0; changex = 0;
} } else {
else
{
changex = (mpacket[0] & 0x10) ? changex = (mpacket[0] & 0x10) ?
mpacket[1] - 256 : mpacket[1] - 256 : mpacket[1];
mpacket[1];
} }
if (mpacket[2] == 0) if (mpacket[2] == 0) {
{
changey = 0; changey = 0;
} } else {
else
{
changey = -((mpacket[0] & 0x20) ? changey = -((mpacket[0] & 0x20) ?
mpacket[2] - 256 : mpacket[2] - 256 : mpacket[2]);
mpacket[2]);
} }
mousex+= (changex<<speed); mousex += (changex << speed);
mousey+= (changey<<speed); mousey += (changey << speed);
if(mousex<0) { mousex=0; } if (mousex < 0) {
if(mousex>=65535) { mousex=65535; } mousex = 0;
if(mousey<0) { mousey=0; } }
if(mousey>=65535) { mousey=65535; } if (mousex >= 65535) {
mousex = 65535;
}
if (mousey < 0) {
mousey = 0;
}
if (mousey >= 65535) {
mousey = 65535;
}
u16 newx=(u32)mousex*getxres()/65536; u16 newx = (u32) mousex * getxres() / 65536;
u16 newy=(u32)mousey*getyres()/65536; u16 newy = (u32) mousey * getyres() / 65536;
// Retrieve mouse button status from packet // Retrieve mouse button status from packet
mousebut1=mpacket[0] & 1; mousebut1 = mpacket[0] & 1;
mousebut2=mpacket[0] & 2; mousebut2 = mpacket[0] & 2;
mousebut3=mpacket[0] & 4; mousebut3 = mpacket[0] & 4;
// printf("RX:%d\tRY:%d\tX:%d\tY:%d\tB1:%d\tB2:%d\tB3:%d\t\r\n",changex,changey,mousex,mousey,mousebut1,mousebut2,mousebut3); // printf("RX:%d\tRY:%d\tX:%d\tY:%d\tB1:%d\tB2:%d\tB3:%d\t\r\n",changex,changey,mousex,mousey,mousebut1,mousebut2,mousebut3);
if ((newx!=oldx)||(newy!=oldy)) if ((newx != oldx) || (newy != oldy)) {
{ showchar(oldx, oldy, oldchar, oldattr);
showchar(oldx,oldy,oldchar,oldattr); oldx = newx;
oldx=newx; oldy = newy;
oldy=newy; oldchar = getchar(oldx, oldy);
oldchar=getchar(oldx,oldy); oldattr = getattrib(oldx, oldy);
oldattr=getattrib(oldx,oldy); showchar(newx, newy, 0xDB, 0x0F);
showchar(newx,newy,0xDB,0x0F); }
} }
} endofint:
endofint: irqendmaster();
irqendmaster(); irqendslave();
irqendslave(); popad();
sti(); popf();
//asm("movl 0x2C(%esp), %ebx;movl 0x30(%esp), %esi;movl 0x34(%esp), %edi;movl 0x38(%esp), %ebp;addl $0x3C, %esp;iret;"); sti();
asm( asm("addl $0x18,%esp;\
"addl $0x18,%esp;\
popl %bx;\ popl %bx;\
iret;"); iret;");
iret();
} }

View File

@ -1,68 +0,0 @@
#include "types.h"
#include "asm.h"
/*******************************************************************************/
/* Envoie une série d'octet a destination d'une portion de mémoire
vers le registre video spécifié */
void outreg(u16 port,u8 *src,u16 num)
{
int i;
for(i=0;i<num;i++)
{
outb(port,i);
outb(port+1,*src++);
}
}
/*******************************************************************************/
/* Envoie une série d'octet a destination d'une portion de mémoire
vers le registre video spécifié (accés data et index confondu) */
void outregsame(u16 port,u8 *src,u16 num)
{
int i;
for(i=0;i<num;i++)
{
inb(port);
outb(port,i);
outb(port,*src++);
}
}
/*******************************************************************************/
/* Récupère une série d'octet en provenance d'un registre video spécifié
vers portion de mémoire */
void inreg(u16 port,u8 *src,u16 num)
{
int i;
for(i=0;i<num;i++)
{
outb(port,i);
*src++=inb(port+1);
}
}
/*******************************************************************************/
/* Récupère une série d'octet en provenance d'un registre video spécifié
vers portion de mémoire (accés data et index confondu) */
void inregsame(u16 port,u8 *src,u16 num)
{
int i;
for(i=0;i<num;i++)
{
inb(port);
outb(port,i);
*src++=inb(port);
}
}
/*******************************************************************************/

View File

@ -1,65 +1,78 @@
#include <string.h> #include <string.h>
/******************************************************************************/
/* Compare 2 chaines de caractère et renvoie la premiere distance (diff) */ /* Compare 2 chaines de caractère et renvoie la premiere distance (diff) */
s8 strcmp(const u8 *src,const u8 *des)
s8 strcmp(const u8 * src, const u8 * des)
{ {
register s8 result; register s8 result;
do do {
{ if ((result = *src - *des++) != 0)
if ((result = *src - *des++) != 0) break; break;
} }
while (*src++!=0); while (*src++ != 0);
return result; return result;
} }
/******************************************************************************/
/* Trouve la premiere occurence d'un caractère dans une chaine */ /* Trouve la premiere occurence d'un caractère dans une chaine */
u8 * strchr(const u8 *src, u8 achar) u8 *strchr(const u8 * src, u8 achar)
{ {
for(; *src!= achar; ++src) for (; *src != achar; ++src)
if (*src == 0) return 0; if (*src == 0)
return (u8*)src; return 0;
return (u8 *) src;
} }
/******************************************************************************/
/* Renvoie la taille de la chaine */ /* Renvoie la taille de la chaine */
u32 strlen(const u8 *src) u32 strlen(const u8 * src)
{ {
u32 size; u32 size;
for (size = 0; *(src+size) != 0; size++); for (size = 0; *(src + size) != 0; size++) ;
return size; return size;
} }
/******************************************************************************/
/* copie une chaine dans une autre */ /* copie une chaine dans une autre */
u8* strcpy(const u8 *src, u8 *des) u8 *strcpy(const u8 * src, u8 * des)
{ {
u8 *temp = des; u8 *temp = des;
while ((*des++ = *src++) != 0); while ((*des++ = *src++) != 0) ;
return temp; return temp;
} }
/******************************************************************************/
/* copie une portion limité d'une chaine asciiZ*/ /* copie une portion limité d'une chaine asciiZ*/
u8 *strncpy(const u8 *src,u8 *des,u32 count) u8 *strncpy(const u8 * src, u8 * des, u32 count)
{ {
u8 *temp = des; u8 *temp = des;
while (count) { while (count) {
if ((*temp = *src) != 0) src++; if ((*temp = *src) != 0)
src++;
temp++; temp++;
count--; count--;
} }
return des; return des;
} }
/******************************************************************************/
/* concatene 2 chaines de caractère */ /* concatene 2 chaines de caractère */
u8 *strcat( const u8 *src,u8 *des) u8 *strcat(const u8 * src, u8 * des)
{ {
u8 *temp = des; u8 *temp = des;
while (*des!=0) des++; while (*des != 0)
while ((*des++ = *src++) != 0); des++;
while ((*des++ = *src++) != 0) ;
return temp; return temp;
} }

View File

@ -1,27 +1,29 @@
#include "idt.h" #include "interrupts.h"
#include "types.h" #include "types.h"
#include "asm.h" #include "asm.h"
#include "memory.h" #include "memory.h"
#include "timer.h" #include "timer.h"
#include "vga.h" #include "vga.h"
static u8 curs[4] = { "-\\|/" };
static u8 curs[4]={"-\\|/"}; static u8 curspos = 0;
static u8 curspos=0; /******************************************************************************/
/* Handler d'interruption de la souris IRQ 0 */
void timer() void timer()
{ {
cli(); cli();
pushf(); pushf();
pushad(); pushad();
showchar(0,0,curs[curspos],7); showchar(0, 0, curs[curspos], 7);
curspos=(curspos+1)&0x3; curspos = (curspos + 1) & 0x3;
irqendmaster(); irqendmaster();
popad(); popad();
popf(); popf();
sti(); sti();
asm("addl $0x0C, %esp;"); asm("addl $0x0C, %esp;");
iret(); iret();
} }

View File

@ -1,46 +1,45 @@
#include <types.h> #include <types.h>
char ctype[] = char ctype[] = {
{
0x00, 0x00,
/* 0 */ CT_CTL, CT_CTL, CT_CTL, CT_CTL, /* 0 */ CT_CTL, CT_CTL, CT_CTL, CT_CTL,
CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL,
/* 8 */ CT_CTL, CT_CTL | CT_WHT, CT_CTL | CT_WHT, CT_CTL | CT_WHT, /* 8 */ CT_CTL, CT_CTL | CT_WHT, CT_CTL | CT_WHT, CT_CTL | CT_WHT,
CT_CTL | CT_WHT, CT_CTL | CT_WHT, CT_CTL, CT_CTL, CT_CTL | CT_WHT, CT_CTL | CT_WHT, CT_CTL, CT_CTL,
/* 16 */CT_CTL, CT_CTL, CT_CTL, CT_CTL, /* 16 */ CT_CTL, CT_CTL, CT_CTL, CT_CTL,
CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL,
/* 24 */CT_CTL, CT_CTL, CT_CTL, CT_CTL, /* 24 */ CT_CTL, CT_CTL, CT_CTL, CT_CTL,
CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL, CT_CTL,
/* ' ' */CT_WHT | CT_SP, CT_PUN, CT_PUN, CT_PUN, /* ' ' */ CT_WHT | CT_SP, CT_PUN, CT_PUN, CT_PUN,
CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN,
/* '(' */CT_PUN, CT_PUN, CT_PUN, CT_PUN, /* '(' */ CT_PUN, CT_PUN, CT_PUN, CT_PUN,
CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN,
/* '0' */CT_DIG, CT_DIG, CT_DIG, CT_DIG, /* '0' */ CT_DIG, CT_DIG, CT_DIG, CT_DIG,
CT_DIG, CT_DIG, CT_DIG, CT_DIG, CT_DIG, CT_DIG, CT_DIG, CT_DIG,
/* '8' */CT_DIG, CT_DIG, CT_PUN, CT_PUN, /* '8' */ CT_DIG, CT_DIG, CT_PUN, CT_PUN,
CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN,
/* '@' */CT_PUN, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP | CT_HEX, /* '@' */ CT_PUN, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP | CT_HEX,
CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP | CT_HEX, CT_UP,
/* 'H' */CT_UP, CT_UP, CT_UP, CT_UP, /* 'H' */ CT_UP, CT_UP, CT_UP, CT_UP,
CT_UP, CT_UP, CT_UP, CT_UP, CT_UP, CT_UP, CT_UP, CT_UP,
/* 'P' */CT_UP, CT_UP, CT_UP, CT_UP, /* 'P' */ CT_UP, CT_UP, CT_UP, CT_UP,
CT_UP, CT_UP, CT_UP, CT_UP, CT_UP, CT_UP, CT_UP, CT_UP,
/* 'X' */CT_UP, CT_UP, CT_UP, CT_PUN, /* 'X' */ CT_UP, CT_UP, CT_UP, CT_PUN,
CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN, CT_PUN,
/* '`' */CT_PUN, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW | CT_HEX, /* '`' */ CT_PUN, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW | CT_HEX,
CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW | CT_HEX, CT_LOW,
/* h' */CT_LOW, CT_LOW, CT_LOW, CT_LOW, /* h' */ CT_LOW, CT_LOW, CT_LOW, CT_LOW,
CT_LOW, CT_LOW, CT_LOW, CT_LOW, CT_LOW, CT_LOW, CT_LOW, CT_LOW,
/* 'p' */CT_LOW, CT_LOW, CT_LOW, CT_LOW, /* 'p' */ CT_LOW, CT_LOW, CT_LOW, CT_LOW,
CT_LOW, CT_LOW, CT_LOW, CT_LOW, CT_LOW, CT_LOW, CT_LOW, CT_LOW,
/* 'x' */CT_LOW, CT_LOW, CT_LOW, CT_PUN, /* 'x' */ CT_LOW, CT_LOW, CT_LOW, CT_PUN,
CT_PUN, CT_PUN, CT_PUN, CT_CTL, CT_PUN, CT_PUN, CT_PUN, CT_CTL,
/* 128 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 128 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 144 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 144 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 160 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 160 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 176 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 176 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 192 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 192 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 208 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 208 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 224 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 224 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 240 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 240 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}; };

620
lib/vga.c
View File

@ -1,11 +1,10 @@
#include "vga.h" #include "vga.h"
#include "memory.h" #include "memory.h"
#include "asm.h" #include "asm.h"
#include "port.h"
#include "types.h" #include "types.h"
#include "modes.c" #include "VGA/modes.c"
#include "8x8fnt.c" #include "VGA/8x8fnt.c"
#include "8x16fnt.c" #include "VGA/8x16fnt.c"
/* Registres VGAs */ /* Registres VGAs */
@ -20,13 +19,13 @@
#define planesize 0x10000 #define planesize 0x10000
static u16 resX,resY,color,splitY; /* resolution x,y en caractères et profondeur */ static u16 resX, resY, color, splitY; /* resolution x,y en caractères et profondeur */
static u8 pages,activepage,showedpage; /* nombre de pages disponibles N° de la page active*/ static u8 pages, activepage, showedpage; /* nombre de pages disponibles N° de la page active */
static u32 linesize,pagesize;/* Taille d'une ligne et d'une page */ static u32 linesize, pagesize; /* Taille d'une ligne et d'une page */
static u8 vmode=0xFF; /* mode en cours d'utilisation */ static u8 vmode = 0xFF; /* mode en cours d'utilisation */
static u32 basemem; /* Adresse de la mémoire vidéo */ static u32 basemem; /* Adresse de la mémoire vidéo */
static bool scrolling,graphic,blink;/* Activation du défilement, Flag du mode graphique */ static bool scrolling, graphic, blink; /* Activation du défilement, Flag du mode graphique */
/*******************************************************************************/ /*******************************************************************************/
@ -34,7 +33,7 @@ static bool scrolling,graphic,blink;/* Activation du d
u16 getxres() u16 getxres()
{ {
return resX; return resX;
} }
/*******************************************************************************/ /*******************************************************************************/
@ -43,7 +42,7 @@ return resX;
u8 getdepth() u8 getdepth()
{ {
return color; return color;
} }
/*******************************************************************************/ /*******************************************************************************/
@ -52,7 +51,7 @@ return color;
u16 getyres() u16 getyres()
{ {
return resY-splitY; return resY - splitY;
} }
/*******************************************************************************/ /*******************************************************************************/
@ -61,7 +60,7 @@ return resY-splitY;
u16 getnbpages() u16 getnbpages()
{ {
return pages; return pages;
} }
/*******************************************************************************/ /*******************************************************************************/
@ -70,7 +69,8 @@ return pages;
void setpage(u8 page) void setpage(u8 page)
{ {
if (page<pages) activepage=page; if (page < pages)
activepage = page;
} }
/*******************************************************************************/ /*******************************************************************************/
@ -79,7 +79,7 @@ if (page<pages) activepage=page;
u8 getpage() u8 getpage()
{ {
return activepage; return activepage;
} }
/*******************************************************************************/ /*******************************************************************************/
@ -88,42 +88,43 @@ return activepage;
void showpage(u8 page) void showpage(u8 page)
{ {
if (page<pages) if (page < pages) {
{ u16 addr;
u16 addr; addr = page * pagesize / 2;
addr=page*pagesize/2;
outb(ccrt, 0x0C); outb(ccrt, 0x0C);
outb(ccrt+1,(addr>>8)); outb(ccrt + 1, (addr >> 8));
outb(ccrt, 0x0D); outb(ccrt, 0x0D);
outb(ccrt+1,(addr&0xFF)); outb(ccrt + 1, (addr & 0xFF));
showedpage=page; showedpage = page;
} }
} }
/*******************************************************************************/ /*******************************************************************************/
/* Sépare l'écran en 2 a partir de la ligne Y */ /* Sépare l'écran en 2 a partir de la ligne Y */
void split(u16 y) void split(u16 y)
{ {
u16 addr; u16 addr;
if (graphic==0) if (graphic == 0)
addr=(y<<3); addr = (y << 3);
else else
addr=y; addr = y;
/* line compare pour ligne atteinte */ /* line compare pour ligne atteinte */
outb(ccrt, 0x18); outb(ccrt, 0x18);
outb(ccrt+1,(addr&0xFF)); outb(ccrt + 1, (addr & 0xFF));
/* overflow pour le bit 8 */ /* overflow pour le bit 8 */
outb(ccrt, 0x07); outb(ccrt, 0x07);
outb(ccrt+1,(inb(ccrt+1) & ~16)|((addr>>4)&16)); outb(ccrt + 1, (inb(ccrt + 1) & ~16) | ((addr >> 4) & 16));
/* Maximum Scan Line pour le bit 9 */ /* Maximum Scan Line pour le bit 9 */
outb(ccrt, 0x09); outb(ccrt, 0x09);
outb(ccrt+1,(inb(ccrt+1) & ~64)|((addr>>3)&64)); outb(ccrt + 1, (inb(ccrt + 1) & ~64) | ((addr >> 3) & 64));
splitY=y; splitY = y;
} }
/*******************************************************************************/ /*******************************************************************************/
/* Sépare l'écran en 2 a partir de la ligne Y */ /* Sépare l'écran en 2 a partir de la ligne Y */
@ -132,80 +133,79 @@ void unsplit()
{ {
/* line compare pour ligne atteinte */ /* line compare pour ligne atteinte */
outb(ccrt, 0x18); outb(ccrt, 0x18);
outb(ccrt+1,0); outb(ccrt + 1, 0);
/* overflow pour le bit 8 */ /* overflow pour le bit 8 */
outb(ccrt, 0x07); outb(ccrt, 0x07);
outb(ccrt+1,inb(ccrt+1) & ~16); outb(ccrt + 1, inb(ccrt + 1) & ~16);
/* Maximum Scan Line pour le bit 9 */ /* Maximum Scan Line pour le bit 9 */
outb(ccrt, 0x09); outb(ccrt, 0x09);
outb(ccrt+1,inb(ccrt+1) & ~64); outb(ccrt + 1, inb(ccrt + 1) & ~64);
splitY=0; splitY = 0;
} }
/*******************************************************************************/ /*******************************************************************************/
/* Attend la retrace verticale */ /* Attend la retrace verticale */
void waitvretrace (void) void waitvretrace(void)
{ {
while ((inb(state)&8)==0); while ((inb(state) & 8) == 0) ;
} }
/*******************************************************************************/ /*******************************************************************************/
/* Attend la retrace horizontale */ /* Attend la retrace horizontale */
void waithretrace (void) void waithretrace(void)
{ {
while ((inb(state)&1)==0); while ((inb(state) & 1) == 0) ;
} }
/*******************************************************************************/ /*******************************************************************************/
/* Active l'affichage du curseur de texte */ /* Active l'affichage du curseur de texte */
void enablecursor (void) void enablecursor(void)
{ {
u8 curs; u8 curs;
/* active le curseur hardware */ /* active le curseur hardware */
outb(ccrt, 10); outb(ccrt, 10);
curs = inb(ccrt+1)&~32; curs = inb(ccrt + 1) & ~32;
outb(ccrt+1, curs); outb(ccrt + 1, curs);
} }
/*******************************************************************************/ /*******************************************************************************/
/* Desactive l'affichage du curseur de texte */ /* Desactive l'affichage du curseur de texte */
void disablecursor (void) void disablecursor(void)
{ {
u8 curs; u8 curs;
/* Desactive le curseur hardware */ /* Desactive le curseur hardware */
outb(ccrt, 10); outb(ccrt, 10);
curs = inb(ccrt+1)|32; curs = inb(ccrt + 1) | 32;
outb(ccrt+1, curs); outb(ccrt + 1, curs);
} }
/*******************************************************************************/ /*******************************************************************************/
/* Active le scrolling en cas de débordement d'écran */ /* Active le scrolling en cas de débordement d'écran */
void enablescroll (void) void enablescroll(void)
{ {
scrolling=true; scrolling = true;
} }
/*******************************************************************************/ /*******************************************************************************/
/* Desactive le scrolling en cas de débordement d'écran */ /* Desactive le scrolling en cas de débordement d'écran */
void disablescroll (void) void disablescroll(void)
{ {
scrolling=false; scrolling = false;
} }
/*******************************************************************************/ /*******************************************************************************/
@ -219,10 +219,10 @@ void useplane(u8 plan)
mask = 1 << plan; mask = 1 << plan;
/* choisi le plan de lecture */ /* choisi le plan de lecture */
outb(graphics, 4); outb(graphics, 4);
outb(graphics+1, plan); outb(graphics + 1, plan);
/* choisi le plan d'ecriture */ /* choisi le plan d'ecriture */
outb(sequencer, 2); outb(sequencer, 2);
outb(sequencer+1, mask); outb(sequencer + 1, mask);
} }
/*******************************************************************************/ /*******************************************************************************/
@ -233,11 +233,10 @@ u32 getbase(void)
{ {
u32 base; u32 base;
outb(graphics, 6); outb(graphics, 6);
base = inb(graphics+1); base = inb(graphics + 1);
base >>= 2; base >>= 2;
base &= 3; base &= 3;
switch(base) switch (base) {
{
case 0: case 0:
case 1: case 1:
base = 0xA0000; base = 0xA0000;
@ -256,27 +255,28 @@ u32 getbase(void)
/* efface l'écran */ /* efface l'écran */
void (*fill)(u8 attrib); void (*fill) (u8 attrib);
void fill_text(u8 attrib)
void fill_text (u8 attrib)
{ {
memset((u8 *)(basemem+activepage*pagesize),' ',pagesize/2,2); memset((u8 *) (basemem + activepage * pagesize), ' ', pagesize / 2, 2);
memset((u8 *)(basemem+activepage*pagesize+1),attrib,pagesize/2,2); memset((u8 *) (basemem + activepage * pagesize + 1), attrib,
pagesize / 2, 2);
} }
void fill_chain (u8 attrib) void fill_chain(u8 attrib)
{ {
memset((u8 *)(basemem+activepage*pagesize),attrib&0x0F,pagesize,1); memset((u8 *) (basemem + activepage * pagesize), attrib & 0x0F,
pagesize, 1);
} }
void fill_unchain (u8 attrib) void fill_unchain(u8 attrib)
{ {
int i; int i;
for(i=0;i<4;i++) for (i = 0; i < 4; i++) {
{
useplane(i); useplane(i);
memset((u8 *)(basemem+activepage*pagesize),attrib&0x0F,pagesize,1); memset((u8 *) (basemem + activepage * pagesize), attrib & 0x0F,
pagesize, 1);
} }
} }
@ -284,103 +284,114 @@ void fill_unchain (u8 attrib)
/* fixe la position du curseur texte */ /* fixe la position du curseur texte */
void gotoscr(u16 x,u16 y) void gotoscr(u16 x, u16 y)
{ {
u16 pos; u16 pos;
if (splitY==0) if (splitY == 0)
pos=(showedpage*pagesize/2+x+y*resX); pos = (showedpage * pagesize / 2 + x + y * resX);
else else
pos=(x+y*resX); pos = (x + y * resX);
outb(ccrt,0x0F); outb(ccrt, 0x0F);
outb(ccrt+1,(u8)(pos&0x00FF)); outb(ccrt + 1, (u8) (pos & 0x00FF));
outb(ccrt,0x0E); outb(ccrt, 0x0E);
outb(ccrt+1,(u8)((pos&0xFF00)>>8)); outb(ccrt + 1, (u8) ((pos & 0xFF00) >> 8));
} }
/*******************************************************************************/ /*******************************************************************************/
/* Fait defiler l'ecran de n lignes vers le haut */ /* Fait defiler l'ecran de n lignes vers le haut */
void (*scroll)(u8 lines,u8 attrib); void (*scroll) (u8 lines, u8 attrib);
void scroll_unchain(u8 lines,u8 attrib) void scroll_unchain(u8 lines, u8 attrib)
{
if (scrolling)
{ {
if (scrolling) {
u8 i; u8 i;
for(i=0;i<4;i++) for (i = 0; i < 4; i++) {
{
useplane(i); useplane(i);
memcpy((u8*)(basemem+activepage*pagesize+linesize*8*lines),(u8*)basemem,pagesize-linesize*8*lines,1); memcpy((u8 *) (basemem + activepage * pagesize +
memset((u8*)(basemem+activepage*pagesize+pagesize-linesize*8*lines),attrib&0x0F,linesize*8*lines,1); linesize * 8 * lines), (u8 *) basemem,
pagesize - linesize * 8 * lines, 1);
memset((u8 *) (basemem + activepage * pagesize +
pagesize - linesize * 8 * lines),
attrib & 0x0F, linesize * 8 * lines, 1);
} }
} }
} }
void scroll_chain(u8 lines,u8 attrib) void scroll_chain(u8 lines, u8 attrib)
{ {
if (scrolling) if (scrolling) {
{ memcpy((u8 *) basemem + activepage * pagesize +
memcpy((u8*)basemem+activepage*pagesize+linesize*8*lines,(u8*)basemem+activepage*pagesize,pagesize-linesize*8*lines,1); linesize * 8 * lines,
memset((u8*)(basemem+activepage*pagesize+pagesize-linesize*8*lines),attrib&0x0F,linesize*8*lines,1); (u8 *) basemem + activepage * pagesize,
} pagesize - linesize * 8 * lines, 1);
memset((u8 *) (basemem + activepage * pagesize + pagesize -
linesize * 8 * lines), attrib & 0x0F,
linesize * 8 * lines, 1);
}
} }
void scroll_text(u8 lines,u8 attrib) void scroll_text(u8 lines, u8 attrib)
{ {
if (scrolling) if (scrolling) {
{ memcpy((u8 *) basemem + activepage * pagesize +
memcpy((u8*)basemem+activepage*pagesize+linesize*lines,(u8*)basemem+activepage*pagesize,pagesize-linesize*lines,1); linesize * lines, (u8 *) basemem + activepage * pagesize,
memset((u8*)(basemem+activepage*pagesize+pagesize-linesize*lines-2),' ',(linesize*lines)/2,2); pagesize - linesize * lines, 1);
memset((u8*)(basemem+activepage*pagesize+pagesize-linesize*lines-1),attrib,(linesize*lines)/2,2); memset((u8 *) (basemem + activepage * pagesize + pagesize -
} linesize * lines - 2), ' ',
(linesize * lines) / 2, 2);
memset((u8 *) (basemem + activepage * pagesize + pagesize -
linesize * lines - 1), attrib,
(linesize * lines) / 2, 2);
}
} }
/*******************************************************************************/ /*******************************************************************************/
/* Affiche le caractère a l'écran */ /* Affiche le caractère a l'écran */
void (*showchar)(u16 coordx,u16 coordy,u8 thechar,u8 attrib); void (*showchar) (u16 coordx, u16 coordy, u8 thechar, u8 attrib);
void showchar_graphic(u16 coordx,u16 coordy,u8 thechar,u8 attrib) void showchar_graphic(u16 coordx, u16 coordy, u8 thechar, u8 attrib)
{ {
u8 x,y,pattern,set; u8 x, y, pattern, set;
for(y=0;y<8;y++) for (y = 0; y < 8; y++) {
{ pattern = font8x8[thechar * 8 + y];
pattern=font8x8[thechar*8+y]; for (x = 0; x < 8; x++) {
for(x=0;x<8;x++) set = ((pattern >> (7 - x)) & 0x1); /* mettre un ROL importé depuis asm */
{ if (set == 0)
set=((pattern>>(7-x))&0x1); /* mettre un ROL importé depuis asm */ writepxl(coordx * 8 + x, coordy * 8 + y,
if (set==0) ((attrib & 0xF0) >> 8) * set);
writepxl(coordx*8+x,coordy*8+y,((attrib&0xF0)>>8)*set);
else else
writepxl(coordx*8+x,coordy*8+y,(attrib&0x0F)*set); writepxl(coordx * 8 + x, coordy * 8 + y,
(attrib & 0x0F) * set);
} }
} }
} }
void showchar_text(u16 coordx, u16 coordy, u8 thechar, u8 attrib)
void showchar_text(u16 coordx,u16 coordy,u8 thechar,u8 attrib)
{ {
u8 *screen; u8 *screen;
screen = (u8 *)basemem+activepage*pagesize+2*(coordx+coordy*resX); screen =
(u8 *) basemem + activepage * pagesize + 2 * (coordx +
coordy * resX);
*screen = thechar; *screen = thechar;
*(++screen) =attrib; *(++screen) = attrib;
} }
/*******************************************************************************/ /*******************************************************************************/
/* Recupere le caractère a l'écran */ /* Recupere le caractère a l'écran */
u8 (*getchar)(u16 coordx,u16 coordy); u8(*getchar) (u16 coordx, u16 coordy);
u8 getchar_text(u16 coordx,u16 coordy)
u8 getchar_text(u16 coordx, u16 coordy)
{ {
u8 *screen; u8 *screen;
screen = (u8 *)basemem+activepage*pagesize+2*(coordx+coordy*resX); screen =
(u8 *) basemem + activepage * pagesize + 2 * (coordx +
coordy * resX);
return *screen; return *screen;
} }
@ -388,32 +399,32 @@ u8 getchar_text(u16 coordx,u16 coordy)
/* Recupere les attributs a l'écran */ /* Recupere les attributs a l'écran */
u8 (*getattrib)(u16 coordx,u16 coordy); u8(*getattrib) (u16 coordx, u16 coordy);
u8 getattrib_text(u16 coordx,u16 coordy)
u8 getattrib_text(u16 coordx, u16 coordy)
{ {
u8 *screen; u8 *screen;
screen = (u8 *)basemem+activepage*pagesize+2*(coordx+coordy*resX)+1; screen =
(u8 *) basemem + activepage * pagesize + 2 * (coordx +
coordy * resX) + 1;
return *screen; return *screen;
} }
/*******************************************************************************/ /*******************************************************************************/
/* Ecrit un pixel a l'écran */ /* Ecrit un pixel a l'écran */
void (*writepxl)(u16 x, u16 y, u32 c); void (*writepxl) (u16 x, u16 y, u32 c);
void writepxl_1bit(u16 x, u16 y, u32 c) void writepxl_1bit(u16 x, u16 y, u32 c)
{ {
u8* off; u8 *off;
u8 mask; u8 mask;
c = (c & 1) * 0xFF; c = (c & 1) * 0xFF;
off = (u8*)(basemem+activepage*pagesize+linesize * y + x / 8); off = (u8 *) (basemem + activepage * pagesize + linesize * y + x / 8);
x = (x & 7) * 1; x = (x & 7) * 1;
mask = 0x80 >> x; mask = 0x80 >> x;
*off= ((*off) & ~mask) | (c & mask); *off = ((*off) & ~mask) | (c & mask);
} }
void writepxl_2bits(u16 x, u16 y, u32 c) void writepxl_2bits(u16 x, u16 y, u32 c)
@ -421,44 +432,43 @@ void writepxl_2bits(u16 x, u16 y, u32 c)
u8 *off; u8 *off;
u8 mask; u8 mask;
c = (c & 3) * 0x55; c = (c & 3) * 0x55;
off = (u8*)(basemem+activepage*pagesize+linesize * y + x / 4); off = (u8 *) (basemem + activepage * pagesize + linesize * y + x / 4);
x = (x & 3) * 2; x = (x & 3) * 2;
mask = 0xC0 >> x; mask = 0xC0 >> x;
*off= ((*off) & ~mask) | (c & mask); *off = ((*off) & ~mask) | (c & mask);
} }
void writepxl_4bits(u16 x, u16 y, u32 c) void writepxl_4bits(u16 x, u16 y, u32 c)
{ {
u8* off; u8 *off;
u8 mask, p, pmask; u8 mask, p, pmask;
off = (u8*)(basemem+activepage*pagesize+linesize * y + x / 8); off = (u8 *) (basemem + activepage * pagesize + linesize * y + x / 8);
x = (x & 7) * 1; x = (x & 7) * 1;
mask = 0x80 >> x; mask = 0x80 >> x;
pmask = 1; pmask = 1;
for(p = 0; p < 4; p++) for (p = 0; p < 4; p++) {
{
useplane(p); useplane(p);
if(pmask & c) if (pmask & c)
*off= ((*off) | mask); *off = ((*off) | mask);
else else
*off= ((*off) & ~mask); *off = ((*off) & ~mask);
pmask <<= 1; pmask <<= 1;
} }
} }
void writepxl_8bits(u16 x, u16 y, u32 c) void writepxl_8bits(u16 x, u16 y, u32 c)
{ {
u8* off; u8 *off;
off = (u8*)(basemem+activepage*pagesize+linesize * y + x); off = (u8 *) (basemem + activepage * pagesize + linesize * y + x);
*off=c; *off = c;
} }
void writepxl_8bitsunchain(u16 x, u16 y, u32 c) void writepxl_8bitsunchain(u16 x, u16 y, u32 c)
{ {
u8* off; u8 *off;
off = (u8*)(basemem+activepage*pagesize+linesize * y + x / 4); off = (u8 *) (basemem + activepage * pagesize + linesize * y + x / 4);
useplane(x & 3); useplane(x & 3);
*off=c; *off = c;
} }
/*******************************************************************************/ /*******************************************************************************/
@ -467,121 +477,113 @@ void writepxl_8bitsunchain(u16 x, u16 y, u32 c)
u32 setvmode(u8 mode) u32 setvmode(u8 mode)
{ {
u8 *def,gmode; u8 *def, gmode;
/* Récupere la definition des registres VGA en fonction du mode /* Récupere la definition des registres VGA en fonction du mode
graphique : >0x80 graphique : >0x80
text : 0x00 - 0x7F text : 0x00 - 0x7F
*/ */
if (mode>=0x80) if (mode >= 0x80) {
{ gmode = mode - 0x80;
gmode=mode-0x80; if (gmode > maxgraphmode)
if (gmode>maxgraphmode) return 1; /* mode inexistant */ return 1; /* mode inexistant */
def=graphmodes[gmode]; def = graphmodes[gmode];
graphic=true; graphic = true;
} } else {
else if (mode > maxtextmode)
{ return 1; /* mode inexistant */
if (mode>maxtextmode) return 1; /* mode inexistant */ def = textmodes[mode];
def=textmodes[mode]; graphic = false;
graphic=false; loadfont(font8x8, 8, 1);
loadfont(font8x8,8,1); loadfont(font8x16, 16, 0);
loadfont(font8x16,16,0);
} }
/* Initialise les registre "divers" */ /* Initialise les registre "divers" */
outb(misc,def[0]); outb(misc, def[0]);
/* Initialise les registre d'etat */ /* Initialise les registre d'etat */
outb(state,0x00); outb(state, 0x00);
/* Initialise le séquenceur */ /* Initialise le séquenceur */
outreg(sequencer,&def[1],5); outreg(sequencer, &def[1], 5);
/* Debloque le verouillage des registres controleur CRT */ /* Debloque le verouillage des registres controleur CRT */
outb(ccrt,0x11); outb(ccrt, 0x11);
outb(ccrt+1,0x0E); outb(ccrt + 1, 0x0E);
/* Initialise le controleur CRT */ /* Initialise le controleur CRT */
outreg(ccrt,&def[6],25); outreg(ccrt, &def[6], 25);
/* Initialise le controleur graphique */ /* Initialise le controleur graphique */
outreg(graphics,&def[31],9); outreg(graphics, &def[31], 9);
inb(state); inb(state);
/* Initialise le controleur d'attributs */ /* Initialise le controleur d'attributs */
outregsame(attribs,&def[40],21); outregsame(attribs, &def[40], 21);
inb(state); inb(state);
outb(attribs,0x20); outb(attribs, 0x20);
/* Récupere depuis la table de définition des mode la résolution et la /* Récupere depuis la table de définition des mode la résolution et la
profondeur (en bits) */ profondeur (en bits) */
resX=def[61]; resX = def[61];
resY=def[62]; resY = def[62];
color=def[63]; color = def[63];
/* Initialise l'adresse des procedures de gestion graphique et les differentes /* Initialise l'adresse des procedures de gestion graphique et les differentes
variables en fonction de la profondeur et du mode*/ variables en fonction de la profondeur et du mode */
if (!graphic) if (!graphic) {
{
/* mode texte */ /* mode texte */
linesize=resX*2; linesize = resX * 2;
writepxl=NULL; /* pas d'affichage de pixels */ writepxl = NULL; /* pas d'affichage de pixels */
showchar=showchar_text; showchar = showchar_text;
scroll=scroll_text; scroll = scroll_text;
fill=fill_text; fill = fill_text;
pagesize=resY*linesize; pagesize = resY * linesize;
getchar=getchar_text; getchar = getchar_text;
getattrib=getattrib_text; getattrib = getattrib_text;
} } else {
else switch (color) {
{
switch(color)
{
case 1: case 1:
/* mode N&B */ /* mode N&B */
linesize=resX; linesize = resX;
writepxl=writepxl_1bit; writepxl = writepxl_1bit;
fill=fill_chain; fill = fill_chain;
scroll=scroll_chain; scroll = scroll_chain;
break; break;
case 2: case 2:
/* mode 4 couleurs */ /* mode 4 couleurs */
linesize=(resX<<1); linesize = (resX << 1);
writepxl=writepxl_2bits; writepxl = writepxl_2bits;
fill=fill_chain; fill = fill_chain;
scroll=scroll_chain; scroll = scroll_chain;
break; break;
case 4: case 4:
/* mode 16 couleurs */ /* mode 16 couleurs */
linesize=resX; linesize = resX;
writepxl=writepxl_4bits; writepxl = writepxl_4bits;
fill=fill_unchain; fill = fill_unchain;
scroll=scroll_unchain; scroll = scroll_unchain;
break; break;
case 8: case 8:
/* mode 256 couleurs */ /* mode 256 couleurs */
if (def[5]==0x0E) if (def[5] == 0x0E) {
{
/* mode chainé (plus rapide mais limité en mémoire) */ /* mode chainé (plus rapide mais limité en mémoire) */
linesize=(resX<<3); linesize = (resX << 3);
writepxl=writepxl_8bits; writepxl = writepxl_8bits;
scroll=scroll_chain; scroll = scroll_chain;
fill=fill_chain; fill = fill_chain;
} } else {
else
{
/* mode non chainé */ /* mode non chainé */
linesize=(resX<<1); linesize = (resX << 1);
writepxl=writepxl_8bitsunchain; writepxl = writepxl_8bitsunchain;
scroll=scroll_unchain; scroll = scroll_unchain;
fill=fill_unchain; fill = fill_unchain;
} }
break; break;
default: default:
break; break;
} }
showchar=showchar_graphic; showchar = showchar_graphic;
pagesize=((resY*linesize)<<3); pagesize = ((resY * linesize) << 3);
} }
/* calcul des variables d'état video */ /* calcul des variables d'état video */
activepage=0; activepage = 0;
showedpage=0; showedpage = 0;
splitY=0; splitY = 0;
vmode=mode; vmode = mode;
scrolling=1; scrolling = 1;
pages=(planesize/pagesize); pages = (planesize / pagesize);
basemem=(def[20]<<8)+def[21]+getbase(); basemem = (def[20] << 8) + def[21] + getbase();
return 0; return 0;
} }
@ -598,52 +600,52 @@ u8 getvmode(void)
/* Charge une nouvelle police de caractère */ /* Charge une nouvelle police de caractère */
u32 loadfont(u8* def,u8 size,u8 font) u32 loadfont(u8 * def, u8 size, u8 font)
{ {
if (graphics==1) return 1; if (graphics == 1)
u8 oldregs[5]={0,0,0,0,0}; return 1;
u8* base; u8 oldregs[5] = { 0, 0, 0, 0, 0 };
u8 *base;
u16 i; u16 i;
if (font>7) return 1; if (font > 7)
if (font<4) return 1;
base = (u8 *)(getbase()+(font<<14)); if (font < 4)
base = (u8 *) (getbase() + (font << 14));
else else
base = (u8 *)(getbase()+((((font-4)<<1)+1)<<13)); base = (u8 *) (getbase() + ((((font - 4) << 1) + 1) << 13));
/* sauve les anciens registres */ /* sauve les anciens registres */
outb(sequencer,2); outb(sequencer, 2);
oldregs[0]=inb(sequencer+1); oldregs[0] = inb(sequencer + 1);
outb(sequencer,4); outb(sequencer, 4);
oldregs[1]=inb(sequencer+1); oldregs[1] = inb(sequencer + 1);
/* Adressage paire/impair desactivé (lineaire) */ /* Adressage paire/impair desactivé (lineaire) */
outb(sequencer+1, oldregs[1]|0x04); outb(sequencer + 1, oldregs[1] | 0x04);
outb(graphics,4); outb(graphics, 4);
oldregs[2]=inb(graphics+1); oldregs[2] = inb(graphics + 1);
outb(graphics,5); outb(graphics, 5);
oldregs[3]=inb(graphics+1); oldregs[3] = inb(graphics + 1);
/* Adressage paire/impair desactivé (lineaire) */ /* Adressage paire/impair desactivé (lineaire) */
outb(graphics+1, oldregs[3]&~0x10); outb(graphics + 1, oldregs[3] & ~0x10);
outb(graphics,6); outb(graphics, 6);
oldregs[4]=inb(graphics+1); oldregs[4] = inb(graphics + 1);
/* Adressage paire/impair desactivé (lineaire) */ /* Adressage paire/impair desactivé (lineaire) */
outb(graphics+1, oldregs[4] & ~0x02); outb(graphics + 1, oldregs[4] & ~0x02);
/* utilisation du plan N°2 */ /* utilisation du plan N°2 */
useplane(2); useplane(2);
for(i=0; i < 256; i++) for (i = 0; i < 256; i++) {
{ memcpy(def, base + i * 32, size, 1);
memcpy(def,base+i*32,size,1);
def += size; def += size;
} }
outb(sequencer,2); outb(sequencer, 2);
outb(sequencer+1,oldregs[0]); outb(sequencer + 1, oldregs[0]);
outb(sequencer,4); outb(sequencer, 4);
outb(sequencer+1,oldregs[1]); outb(sequencer + 1, oldregs[1]);
outb(graphics,4); outb(graphics, 4);
outb(graphics+1,oldregs[2]); outb(graphics + 1, oldregs[2]);
outb(graphics,5); outb(graphics, 5);
outb(graphics+1,oldregs[3]); outb(graphics + 1, oldregs[3]);
outb(graphics,6); outb(graphics, 6);
outb(graphics+1,oldregs[4]); outb(graphics + 1, oldregs[4]);
return 0; return 0;
} }
@ -653,10 +655,10 @@ u32 loadfont(u8* def,u8 size,u8 font)
u8 getfont() u8 getfont()
{ {
u8 num,tmp; u8 num, tmp;
outb(sequencer,3); outb(sequencer, 3);
tmp=inb(sequencer+1); tmp = inb(sequencer + 1);
num=(tmp&0x03)|((tmp&0x10)>>2); num = (tmp & 0x03) | ((tmp & 0x10) >> 2);
return num; return num;
} }
@ -666,23 +668,24 @@ u8 getfont()
u8 getfont2() u8 getfont2()
{ {
u8 num,tmp; u8 num, tmp;
outb(sequencer,3); outb(sequencer, 3);
tmp=inb(sequencer+1); tmp = inb(sequencer + 1);
num=((tmp&0x0C)>>2)|((tmp&0x20)>>3); num = ((tmp & 0x0C) >> 2) | ((tmp & 0x20) >> 3);
return num; return num;
} }
/*******************************************************************************/ /*******************************************************************************/
/* Fixe le N° de la police de caractère a utiliser */ /* Fixe le N° de la police de caractère a utiliser */
void setfont(u8 num) void setfont(u8 num)
{ {
num&=0x07; num &= 0x07;
outb(sequencer,3); outb(sequencer, 3);
outb(sequencer+1,(inb(sequencer+1)&0xEC)|((num&0x03)+((num&0x04)<<2))); outb(sequencer + 1,
(inb(sequencer + 1) & 0xEC) | ((num & 0x03) +
((num & 0x04) << 2)));
} }
/*******************************************************************************/ /*******************************************************************************/
@ -691,30 +694,89 @@ void setfont(u8 num)
void setfont2(u8 num) void setfont2(u8 num)
{ {
num&=0x07; num &= 0x07;
outb(sequencer,3); outb(sequencer, 3);
outb(sequencer+1,(inb(sequencer+1)&0xD3)|(((num&0x03)<<2)+((num&0x04)<<3))); outb(sequencer + 1,
(inb(sequencer + 1) & 0xD3) | (((num & 0x03) << 2) +
((num & 0x04) << 3)));
} }
/*******************************************************************************/ /*******************************************************************************/
/* Fixe le N° de la police de caractère a utiliser */ /* Autorise le clignotement */
void enableblink() void enableblink()
{ {
outb(ccrt,0x10); outb(ccrt, 0x10);
outb(ccrt+1,(inb(sequencer+1)|0x04)); outb(ccrt + 1, (inb(sequencer + 1) | 0x04));
} }
/*******************************************************************************/ /*******************************************************************************/
/* Fixe le N° de la police de caractère a utiliser */ /* Annule le clignotement */
void disableblink() void disableblink()
{ {
outb(ccrt,0x10); outb(ccrt, 0x10);
outb(ccrt+1,(inb(sequencer+1)&~0x04)); outb(ccrt + 1, (inb(sequencer + 1) & ~0x04));
} }
/*******************************************************************************/ /*******************************************************************************/
/* Envoie une série d'octet a destination d'une portion de mémoire
vers le registre spécifié */
void outreg(u16 port, u8 * src, u16 num)
{
int i;
for (i = 0; i < num; i++) {
outb(port, i);
outb(port + 1, *src++);
}
}
/*******************************************************************************/
/* Envoie une série d'octet a destination d'une portion de mémoire
vers le registre spécifié (accés data et index confondu) */
void outregsame(u16 port, u8 * src, u16 num)
{
int i;
for (i = 0; i < num; i++) {
inb(port);
outb(port, i);
outb(port, *src++);
}
}
/*******************************************************************************/
/* Récupère une série d'octet en provenance d'un registre spécifié
vers portion de mémoire */
void inreg(u16 port, u8 * src, u16 num)
{
int i;
for (i = 0; i < num; i++) {
outb(port, i);
*src++ = inb(port + 1);
}
}
/*******************************************************************************/
/* Récupère une série d'octet en provenance d'un registre spécifié
vers portion de mémoire (accés data et index confondu) */
void inregsame(u16 port, u8 * src, u16 num)
{
int i;
for (i = 0; i < num; i++) {
inb(port);
outb(port, i);
*src++ = inb(port);
}
}
/*******************************************************************************/

View File

@ -2,19 +2,25 @@
#include "video.h" #include "video.h"
#include "stdarg.h" #include "stdarg.h"
console vc[8] = {
{0x07, 0, 0, 0, 0, 0, 0, 0}
,
{0x07, 0, 0, 0, 0, 0, 0, 0}
,
{0x07, 0, 0, 0, 0, 0, 0, 0}
,
{0x07, 0, 0, 0, 0, 0, 0, 0}
,
{0x07, 0, 0, 0, 0, 0, 0, 0}
,
{0x07, 0, 0, 0, 0, 0, 0, 0}
,
{0x07, 0, 0, 0, 0, 0, 0, 0}
,
{0x07, 0, 0, 0, 0, 0, 0, 0}
};
console vc[8]={ u8 usedvc = 0;
{0x07,0,0,0,0,0,0,0},
{0x07,0,0,0,0,0,0,0},
{0x07,0,0,0,0,0,0,0},
{0x07,0,0,0,0,0,0,0},
{0x07,0,0,0,0,0,0,0},
{0x07,0,0,0,0,0,0,0},
{0x07,0,0,0,0,0,0,0},
{0x07,0,0,0,0,0,0,0}};
u8 usedvc=0;
/*******************************************************************************/ /*******************************************************************************/
@ -22,32 +28,28 @@ u8 usedvc=0;
void setattrib(u8 att) void setattrib(u8 att)
{ {
static const u8 ansitovga[] = static const u8 ansitovga[] = {
{
0, 4, 2, 6, 1, 5, 3, 7 0, 4, 2, 6, 1, 5, 3, 7
}; };
u8 tempattr; u8 tempattr;
tempattr = vc[usedvc].attrib; tempattr = vc[usedvc].attrib;
if(att == 0) if (att == 0)
tempattr = 0x07; /* Couleur Grise sur fond noir */ tempattr = 0x07; /* Couleur Grise sur fond noir */
else if (att == 5) else if (att == 5)
tempattr |= 0x80; tempattr |= 0x80;
else if (att == 7) else if (att == 7)
tempattr = ((tempattr&0x0F)<<4)+((tempattr&0xF0)>>4); tempattr = ((tempattr & 0x0F) << 4) + ((tempattr & 0xF0) >> 4);
else if (att == 8) else if (att == 8)
tempattr = 0; tempattr = 0;
else if (att == 1) else if (att == 1)
tempattr |= 0x08; /* Forte intensité */ tempattr |= 0x08; /* Forte intensité */
else if(att >= 30 && att <= 37) else if (att >= 30 && att <= 37) {
{
att = ansitovga[att - 30]; att = ansitovga[att - 30];
tempattr = (tempattr & ~0x07) | att;/* couleur de premier plan */ tempattr = (tempattr & ~0x07) | att; /* couleur de premier plan */
} } else if (att >= 40 && att <= 47) {
else if(att >= 40 && att <= 47)
{
att = ansitovga[att - 40] << 4; att = ansitovga[att - 40] << 4;
tempattr = (tempattr & ~0x70) | att;/* couleur de fond */ tempattr = (tempattr & ~0x70) | att; /* couleur de fond */
} }
vc[usedvc].attrib = tempattr; vc[usedvc].attrib = tempattr;
} }
@ -59,20 +61,17 @@ void setattrib(u8 att)
bool makeansi(u8 c) bool makeansi(u8 c)
{ {
/* state machine to handle the escape sequences */ /* state machine to handle the escape sequences */
switch(vc[usedvc].ansi) switch (vc[usedvc].ansi) {
{
case 0: case 0:
/* ESC -- next state */ /* ESC -- next state */
if(c == 0x1B) if (c == 0x1B) {
{
vc[usedvc].ansi++; vc[usedvc].ansi++;
return 1; /* "I handled it" */ return 1; /* "I handled it" */
} }
break; break;
/* ESC */ /* ESC */
case 1: case 1:
if(c == '[') if (c == '[') {
{
vc[usedvc].ansi++; vc[usedvc].ansi++;
vc[usedvc].param1 = 0; vc[usedvc].param1 = 0;
return 1; return 1;
@ -80,101 +79,90 @@ bool makeansi(u8 c)
break; break;
/* ESC[ */ /* ESC[ */
case 2: case 2:
if(isdigit(c)) if (isdigit(c)) {
{
vc[usedvc].param1 = vc[usedvc].param1 * 10 + c - '0'; vc[usedvc].param1 = vc[usedvc].param1 * 10 + c - '0';
return 1; return 1;
} } else if (c == ';') {
else if(c == ';')
{
vc[usedvc].ansi++; vc[usedvc].ansi++;
vc[usedvc].param2 = 0; vc[usedvc].param2 = 0;
return 1; return 1;
} }
/* ESC[2J -- efface l'ecran */ /* ESC[2J -- efface l'ecran */
else if(c == 'J') else if (c == 'J') {
{ if (vc[usedvc].param1 == 2) {
if(vc[usedvc].param1 == 2)
{
fill(vc[usedvc].attrib); fill(vc[usedvc].attrib);
vc[usedvc].cursX=0; vc[usedvc].cursX = 0;
vc[usedvc].cursY=0; vc[usedvc].cursY = 0;
gotoscr(0,0); gotoscr(0, 0);
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
return 1; return 1;
} }
} }
/* ESC[num1m -- met l'attribut num1 */ /* ESC[num1m -- met l'attribut num1 */
else if(c == 'm') else if (c == 'm') {
{
setattrib(vc[usedvc].param1); setattrib(vc[usedvc].param1);
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
return 1; return 1;
} }
/* ESC[num1A -- bouge le curseur de num1 vers le haut */ /* ESC[num1A -- bouge le curseur de num1 vers le haut */
else if(c == 'A') else if (c == 'A') {
{ vc[usedvc].cursY -= vc[usedvc].param1;
vc[usedvc].cursY-=vc[usedvc].param1; if (vc[usedvc].cursY < 0)
if (vc[usedvc].cursY<0) vc[usedvc].cursY=0; vc[usedvc].cursY = 0;
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
return 1; return 1;
} }
/* ESC[num1B -- bouge le curseur de num1 vers le bas */ /* ESC[num1B -- bouge le curseur de num1 vers le bas */
else if(c == 'B') else if (c == 'B') {
{ vc[usedvc].cursY += vc[usedvc].param1;
vc[usedvc].cursY+=vc[usedvc].param1; if (vc[usedvc].cursY >= getyres() - 1)
if (vc[usedvc].cursY>=getyres()-1) vc[usedvc].cursY=getyres(); vc[usedvc].cursY = getyres();
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
return 1; return 1;
} }
/* ESC[num1D -- bouge le curseur de num1 vers la gauche */ /* ESC[num1D -- bouge le curseur de num1 vers la gauche */
else if(c == 'D') else if (c == 'D') {
{ vc[usedvc].cursX -= vc[usedvc].param1;
vc[usedvc].cursX-=vc[usedvc].param1; if (vc[usedvc].cursX < 0)
if (vc[usedvc].cursX<0) vc[usedvc].cursX=0; vc[usedvc].cursX = 0;
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
return 1; return 1;
} }
/* ESC[num1C -- bouge le curseur de num1 vers la droite */ /* ESC[num1C -- bouge le curseur de num1 vers la droite */
else if(c == 'C') else if (c == 'C') {
{ vc[usedvc].cursX += vc[usedvc].param1;
vc[usedvc].cursX+=vc[usedvc].param1; if (vc[usedvc].cursX >= getxres() - 1)
if (vc[usedvc].cursX>=getxres()-1) vc[usedvc].cursX=getxres(); vc[usedvc].cursX = getxres();
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
return 1; return 1;
} }
break; break;
/* ESC[num1; */ /* ESC[num1; */
case 3: case 3:
if(isdigit(c)) if (isdigit(c)) {
{
vc[usedvc].param2 = vc[usedvc].param2 * 10 + c - '0'; vc[usedvc].param2 = vc[usedvc].param2 * 10 + c - '0';
return 1; return 1;
} } else if (c == ';') {
else if(c == ';')
{
vc[usedvc].ansi++; vc[usedvc].ansi++;
vc[usedvc].param3 = 0; vc[usedvc].param3 = 0;
return 1; return 1;
} }
/* ESC[num1;num2H ou ESC[num1;num2f-- bouge le curseur en num1,num2 */ /* ESC[num1;num2H ou ESC[num1;num2f-- bouge le curseur en num1,num2 */
else if((c == 'H')||(c == 'f')) else if ((c == 'H') || (c == 'f')) {
{
/* Remet la position du curseur matériel a num1,num2 */ /* Remet la position du curseur matériel a num1,num2 */
gotoscr(vc[usedvc].param2,vc[usedvc].param1); gotoscr(vc[usedvc].param2, vc[usedvc].param1);
/* Remet la position du curseur logiciel a num1,num2 */ /* Remet la position du curseur logiciel a num1,num2 */
vc[usedvc].cursX=vc[usedvc].param2; vc[usedvc].cursX = vc[usedvc].param2;
vc[usedvc].cursY=vc[usedvc].param1; vc[usedvc].cursY = vc[usedvc].param1;
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
return 1; return 1;
} }
/* ESC[num1;num2m -- met les attributs num1,num2 */ /* ESC[num1;num2m -- met les attributs num1,num2 */
else if(c == 'm') else if (c == 'm') {
{
setattrib(vc[usedvc].param1); setattrib(vc[usedvc].param1);
setattrib(vc[usedvc].param2); setattrib(vc[usedvc].param2);
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
@ -183,14 +171,12 @@ bool makeansi(u8 c)
break; break;
/* ESC[num1;num2;num3 */ /* ESC[num1;num2;num3 */
case 4: case 4:
if(isdigit(c)) if (isdigit(c)) {
{
vc[usedvc].param3 = vc[usedvc].param3 * 10 + c - '0'; vc[usedvc].param3 = vc[usedvc].param3 * 10 + c - '0';
return 1; return 1;
} }
/* ESC[num1;num2;num3m -- met les attributs num1,num2,num3 */ /* ESC[num1;num2;num3m -- met les attributs num1,num2,num3 */
else if(c == 'm') else if (c == 'm') {
{
setattrib(vc[usedvc].param1); setattrib(vc[usedvc].param1);
setattrib(vc[usedvc].param2); setattrib(vc[usedvc].param2);
setattrib(vc[usedvc].param3); setattrib(vc[usedvc].param3);
@ -204,7 +190,7 @@ bool makeansi(u8 c)
break; break;
} }
vc[usedvc].ansi = 0; vc[usedvc].ansi = 0;
return 0; /* Ansi fini ;)*/ return 0; /* Ansi fini ;) */
} }
/*******************************************************************************/ /*******************************************************************************/
@ -213,10 +199,10 @@ bool makeansi(u8 c)
void changevc(u8 avc) void changevc(u8 avc)
{ {
usedvc=avc; usedvc = avc;
showpage(usedvc); showpage(usedvc);
setpage(usedvc); setpage(usedvc);
gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
} }
/*******************************************************************************/ /*******************************************************************************/
@ -225,90 +211,88 @@ gotoscr(vc[usedvc].cursX,vc[usedvc].cursY);
void putchar(u8 thechar) void putchar(u8 thechar)
{ {
showpage(usedvc); showpage(usedvc);
setpage(usedvc); setpage(usedvc);
if(makeansi(thechar)) return; if (makeansi(thechar))
switch (thechar) return;
{ switch (thechar) {
case 0x11: case 0x11:
if (vc[usedvc].cursY>0) vc[usedvc].cursY--; if (vc[usedvc].cursY > 0)
break; vc[usedvc].cursY--;
case 0x12: break;
if (vc[usedvc].cursY<getyres()-1) vc[usedvc].cursY++; case 0x12:
break; if (vc[usedvc].cursY < getyres() - 1)
case 0x13: vc[usedvc].cursY++;
if (vc[usedvc].cursX>0) vc[usedvc].cursX--; break;
break; case 0x13:
case 0x14: if (vc[usedvc].cursX > 0)
if (vc[usedvc].cursX<getxres()-1) vc[usedvc].cursX++; vc[usedvc].cursX--;
break; break;
case 0x2: case 0x14:
vc[usedvc].cursX=0; if (vc[usedvc].cursX < getxres() - 1)
vc[usedvc].cursY=0; vc[usedvc].cursX++;
break; break;
case 0x3: case 0x2:
vc[usedvc].cursX=0; vc[usedvc].cursX = 0;
vc[usedvc].cursY=getyres()-1; vc[usedvc].cursY = 0;
break; break;
case 0x19: case 0x3:
vc[usedvc].cursX=getxres()-1; vc[usedvc].cursX = 0;
break; vc[usedvc].cursY = getyres() - 1;
case '\b': break;
if (vc[usedvc].cursX==0) case 0x19:
{ vc[usedvc].cursX = getxres() - 1;
if (vc[usedvc].cursY>0) break;
{ case '\b':
vc[usedvc].cursX=getxres()-1; if (vc[usedvc].cursX == 0) {
vc[usedvc].cursY--; if (vc[usedvc].cursY > 0) {
} vc[usedvc].cursX = getxres() - 1;
} vc[usedvc].cursY--;
else }
{ } else {
vc[usedvc].cursX--; vc[usedvc].cursX--;
} }
showchar(vc[usedvc].cursX,vc[usedvc].cursY,' ',vc[usedvc].attrib); showchar(vc[usedvc].cursX, vc[usedvc].cursY, ' ',
break; vc[usedvc].attrib);
case '\t': break;
vc[usedvc].cursX=(vc[usedvc].cursX + 8) & ~(8 - 1); case '\t':
break; vc[usedvc].cursX = (vc[usedvc].cursX + 8) & ~(8 - 1);
case '\n': break;
vc[usedvc].cursX=0; case '\n':
break; vc[usedvc].cursX = 0;
case '\r': break;
vc[usedvc].cursX=0; case '\r':
vc[usedvc].cursY++; vc[usedvc].cursX = 0;
break; vc[usedvc].cursY++;
default: break;
if (thechar>=' ') default:
{ if (thechar >= ' ') {
showchar(vc[usedvc].cursX,vc[usedvc].cursY,thechar,vc[usedvc].attrib); showchar(vc[usedvc].cursX, vc[usedvc].cursY, thechar,
vc[usedvc].cursX++; vc[usedvc].attrib);
} vc[usedvc].cursX++;
break; }
} break;
if (vc[usedvc].cursX>=getxres()) }
{ if (vc[usedvc].cursX >= getxres()) {
vc[usedvc].cursX=0; vc[usedvc].cursX = 0;
vc[usedvc].cursY++; vc[usedvc].cursY++;
} }
if (vc[usedvc].cursY>=getyres()) if (vc[usedvc].cursY >= getyres()) {
{ scroll(1, vc[usedvc].attrib);
scroll(1,vc[usedvc].attrib); vc[usedvc].cursY = getyres() - 1;
vc[usedvc].cursY=getyres()-1;
} }
gotoscr(vc[usedvc].cursX,vc[usedvc].cursY); gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
} }
/*******************************************************************************/ /*******************************************************************************/
/* affiche une chaine de caractère a l'écran */ /* affiche une chaine de caractère a l'écran */
void print(u8* string) void print(u8 * string)
{ {
u8 *source; u8 *source;
source = string; source = string;
while(*source!=0) while (*source != 0) {
{
putchar(*source++); putchar(*source++);
} }
} }
@ -317,7 +301,7 @@ void print(u8* string)
/* affiche une chaine de caractère formaté a l'ecran */ /* affiche une chaine de caractère formaté a l'ecran */
void printf (const u8 *string, ...) void printf(const u8 * string, ...)
{ {
va_list ap; va_list ap;
u8 buffer[50]; u8 buffer[50];
@ -327,69 +311,67 @@ void printf (const u8 *string, ...)
bool signe; bool signe;
long num; long num;
va_start(ap, string); va_start(ap, string);
while(*string!= 0) while (*string != 0) {
{
if (*string != '%') if (*string != '%')
putchar (*string); putchar(*string);
else else {
{ switch (*++string) {
switch (*++string)
{
case 'c': case 'c':
putchar (va_arg(ap, int)); putchar(va_arg(ap, int));
break; break;
case 'u': case 'u':
radix=10; radix = 10;
signe=0; signe = 0;
showstring: showstring:
num=va_arg(ap, int); num = va_arg(ap, int);
pointer = buffer + 50 - 1; pointer = buffer + 50 - 1;
*pointer = '\0'; *pointer = '\0';
if ((signe==1)&&(num<0)) if ((signe == 1) && (num < 0)) {
{
num = -num; num = -num;
signe++; signe++;
} }
do do {
{
unsigned long temp; unsigned long temp;
temp = (unsigned long)num % radix; temp = (unsigned long)num % radix;
pointer--; pointer--;
if(temp < 10) if (temp < 10)
*pointer = temp + '0'; *pointer = temp + '0';
else else
*pointer = temp - 10 + 'a'; *pointer = temp - 10 + 'a';
num = (unsigned long)num / radix; num = (unsigned long)num / radix;
} }
while(num != 0); while (num != 0);
if (signe>1) *(--pointer)='-'; if (signe > 1)
while (*pointer!=0) putchar(*pointer++); *(--pointer) = '-';
while (*pointer != 0)
putchar(*pointer++);
break; break;
case 'o': case 'o':
radix = 8; radix = 8;
signe=0; signe = 0;
goto showstring; goto showstring;
case 'd': case 'd':
case 'i': case 'i':
radix=10; radix = 10;
signe=1; signe = 1;
goto showstring; goto showstring;
case 'x': case 'x':
radix=16; radix = 16;
signe=0; signe = 0;
goto showstring; goto showstring;
case 's': case 's':
pointer=va_arg(ap, u8*); pointer = va_arg(ap, u8 *);
if (!pointer) pointer="(null)"; if (!pointer)
while (*pointer!=0) putchar(*pointer++); pointer = "(null)";
while (*pointer != 0)
putchar(*pointer++);
break; break;
case '%': case '%':
putchar ('%'); putchar('%');
break; break;
default: default:
putchar (va_arg(ap, int)); putchar(va_arg(ap, int));
break; break;
} }
} }
@ -399,4 +381,3 @@ showstring:
} }
/*******************************************************************************/ /*******************************************************************************/

View File

@ -1,4 +1,3 @@
FINALCC=gcc -O4 -nostdinc -ffreestanding -fno-builtin -fomit-frame-pointer -Wall -w -I ../include -m32 -c -o
GCC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -fomit-frame-pointer -Wall -w -I ../include -m32 -c -o GCC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -fomit-frame-pointer -Wall -w -I ../include -m32 -c -o
LINK=ld -m elf_i386 -T linker.lds -e main -o LINK=ld -m elf_i386 -T linker.lds -e main -o
@ -7,9 +6,8 @@ all: system.sys
sync sync
system.sys: system.sys:
nasm -f elf -o system.o system.asm $(GCC) system.o system.c
$(GCC) systemc.o system.c $(LINK) system.sys system.o ../lib/libs.o
$(LINK) system.sys systemc.o system.o ../lib/libs.o
clean: clean:
rm -f *.o rm -f *.o

View File

@ -1,5 +0,0 @@
[BITS 32]
SECTION .text

View File

@ -1,6 +1,6 @@
#include "vga.h" #include "vga.h"
#include "video.h" #include "video.h"
#include "idt.h" #include "interrupts.h"
#include "timer.h" #include "timer.h"
#include "keyboard.h" #include "keyboard.h"
#include "mouse.h" #include "mouse.h"
@ -11,9 +11,14 @@
#include "ansi.c" #include "ansi.c"
static cpuinfo cpu; static cpuinfo cpu;
static u8 noproc[]="\033[31mInconnu\033[0m\000"; static u8 noproc[] = "\033[31mInconnu\033[0m\000";
static u8 okmsg[]="\033[99C\033[8D\033[37m\033[1m[ \033[32mOK\033[37m ]\033[0m\000"; static u8 warnmsg[] =
static u8 key=0; "\033[99C\033[8D\033[37m\033[1m[ \033[36mNON\033[37m ]\033[0m\000";
static u8 okmsg[] =
"\033[99C\033[8D\033[37m\033[1m[ \033[32mOK\033[37m ]\033[0m\000";
static u8 errormsg[] =
"\033[99C\033[8D\033[37m\033[1m[\033[31mERREUR\033[37m]\033[0m\000";
static u8 key = 0;
void ok() void ok()
{ {
@ -21,70 +26,63 @@ void ok()
return; return;
} }
int main(void) { void warning()
{
print(warnmsg);
return;
}
void error()
{
print(errormsg);
return;
}
int main(void)
{
cli(); cli();
setvmode(0x02); setvmode(0x02);
/* Efface l'ecran */ /* Efface l'ecran */
print("\033[2J\000"); print("\033[2J\000");
printf(ansilogo); printf(ansilogo);
print("\033[0mNoyau charge en memoire\000");
ok();
print("Initilisation de la table d'interruption\000"); print("\033[37m\033[0m -Initilisation des interruptions\000");
initidt(); initidt();
ok();
print("Initialisation du controleur d'interruption\000");
initpic(); initpic();
sti(); sti();
ok(); ok();
print("Installation du handler timer\000"); print(" -Installation du handler timer (IRQ 0)\000");
setidt((u32)timer, 0x20, INTGATE, 32); setidt((u32) timer, 0x20, INTGATE, 32);
ok();
print("Activation de l'IRQ 0\000");
enableirq(0); enableirq(0);
ok(); ok();
print("Installation du handler clavier\000"); print(" -Installation du handler clavier (IRQ 1)\000");
setidt((u32)keyboard, 0x20, INTGATE, 33); setidt((u32) keyboard, 0x20, INTGATE, 33);
ok();
print("Activation de l'IRQ 1\000");
enableirq(1); enableirq(1);
ok(); ok();
print("Installation du handler souris\000"); print(" -Installation du handler souris (IRQ12+Cascade IRQ2)\000");
setidt((u32)mouse, 0x20, INTGATE, 100); setidt((u32) mouse, 0x20, INTGATE, 100);
ok();
print("Initialisation du controleur souris :\000");
if (initmouse()==1)
print(" \033[1m\033[32mSouris Presente\033[0m\000");
else
print(" \033[1m\033[31mSouris non detecte\033[0m\000");
ok();
print("Activation de l'IRQ 2 (Controleur esclave)\000");
enableirq(2); enableirq(2);
ok();
print("Activation de l'IRQ 12\000");
enableirq(12); enableirq(12);
if (initmouse() != 1)
warning();
else
ok(); ok();
strcpy(&noproc,&cpu.detectedname); strcpy(&noproc, &cpu.detectedname);
getcpuinfos(&cpu); getcpuinfos(&cpu);
printf("Processeur detecte\r Revision \t:%d\r Modele \t:%d\r Famille \t:%d\r Nom cpuid\t:%s\rJeux\t:%s\000",cpu.stepping,cpu.models,cpu.family,&cpu.detectedname,&cpu.techs); printf
(" -Detection du processeur\r\033[1m Revision \t:%d\r Modele \t:%d\r Famille \t:%d\r Nom cpuid\t:%s\rJeux d'instruction\t:%s\033[0m\000",
cpu.stepping, cpu.models, cpu.family, &cpu.detectedname,
&cpu.techs);
ok(); ok();
while(1) while (1) {
{ key = waitascii();
key=waitascii();
putchar(key); putchar(key);
} }
} }