diff --git a/noyau/8237.asm b/noyau/8237.asm new file mode 100644 index 0000000..c03dcb1 --- /dev/null +++ b/noyau/8237.asm @@ -0,0 +1,266 @@ +;**************************************************************** +; * +; Periph‚rique : DMA * +; Plages Entr‚es-Sorties : 0000-000F * +; 00C0-00DF * +; 0080-0090 * +; (0094-009F) * +; Plages M‚moires : AUCUNES * +; * +DmaRead equ 044h ;I/O to memory, no autoinit, increment, single mode +DmaWrite equ 048h ;Memory to I/O, no autoinit, increment, single mode + +;Lecture des bits du registre d'‚tat (08, D0 ) +STATUS_REQ3 = 80h ;Bit actif: le canal DMA concern‚ +STATUS_REQ2 = 40h ;re‡oit une requˆte DMA +STATUS_REQ1 = 20h ;Request +STATUS_REQ0 = 10h +STATUS_TC3 = 08h ;Bit actif: Un transfert DMA a ‚t‚ +STATUS_TC2 = 04h ;ex‚cut‚ depuis la derniŠre lecture +STATUS_TC1 = 02h ;du registre d'‚tat. +STATUS_TC0 = 01h ;Terminal Count + +;Ecriture des bits du registre de commande (08, D0) +COMMAND_DACKLEVEL = 80h ;Bit 7 actif: ligne DMA Acknowledge HIGH active +COMMAND_DREQLEVEL = 40h ;Bit 6 actif: ligne REQ Acknowledge LOW active +COMMAND_EXTWRITE = 20h ;Bit 5 actif: EXTENDED Write,sinon LATE Write +COMMAND_FIXEDPRI = 10h ;Bit 4 actif: priorit‚ constante +COMMAND_COMPRESS = 08h ;Bit 3 actif: compression +COMMAND_INACTIVE = 04h ;Bit 2 actif: contr“leur d‚sactiv‚ +COMMAND_ADH0 = 02h ;Bit 1 actif: Adress Hold pour canal 0/4 d‚sactiv‚ +COMMAND_MEM2MEM = 01h ;Bit 0 actif: m‚moire/m‚moire, sinon m‚moire/p‚riph‚rie + +;Ecriture des bits du registre de requˆte ( 09, D2 ) +REQUEST_RESERVED = 0F8h ;R‚glage des bits r‚serv‚s =0 +REQUEST_SET = 04h ;D‚finir requˆte DMA +REQUEST_CLR = 00h ;Supprimer requˆte DMA +REQUEST_MSK = 03h ;Indiquer le canal dans les deux bits du bas + +;Ecriture des bits du registre de masquage de canal ( 0A, D4 ) +CHANNEL_RESERVED = 0F8h ;R‚glage des bits r‚serv‚s =0 +CHANNEL_SET = 04h ;Masquer/verrouiller canal DMA +CHANNEL_CLR = 00h ;Lib‚rer canal DMA +CHANNEL_MSK = 03h ;Indiquer le canal dans les deux bits du bas + +;Ecriture des bits du registre de mode (0B,D6) +MODE_DEMAND = 00h ;Transf‚rer … la demande +MODE_SINGLE = 40h ;Transf‚rer valeurs uniques +MODE_BLOCK = 80h ;Transf‚rer en bloc +MODE_CASCADE = 0C0h ;Transf‚rer en cascade +MODE_DECREMENT = 20h ;D‚cr‚menter +MODE_AUTOINIT = 10h ;Autoinitialisation vers la fin +MODE_VERIFY = 00h ;V‚rifier +MODE_WRITE = 04h ;Ecrire dans la m‚moire +MODE_READ = 08h ;Lire depuis la m‚moire +MODE_INVALID = 0Ch ;Incorrect +MODE_CHANNELMSK = 03h ;Indiquer le canal dans les deux bits du bas + +;Ports du DMA esclave + +DmaStatusS dw 08h ;R SLAVE Registre d'‚tat +DmaCommandS dw 08h ;W SLAVE Registre de commande +DmaRequestS dw 09h ;W SLAVE Ex‚cuter requˆte DMA +DmachMaskS dw 0ah ;W SLAVE Masquer canaux +DmaModeS dw 0bh ;W SLAVE Mode de transfert +DmaFlipFlopS dw 0ch ;W SLAVE Flipflop adr/compteur +DmaTempS dw 0dh ;R SLAVE Reset du contr“leur +DmaClearS dw 0dh ;R SLAVE Registre temporaire +DmaMaskClrS dw 0eh ;R SLAVE Lib‚rer canaux +DmaMaskS dw 0fh ;R SLAVE Masquer canaux + +;Ports du DMA esclave + +DmaStatusM dw 0D0h ;R MASTER Registre d'‚tat +DmaCommandM dw 0D0h ;W MASTER Registre de commande +DmaRequestM dw 0D2h ;W MASTER Ex‚cuter requˆte DMA +DmaMaskM dw 0D4h ;W MASTER Masquer canaux +DmaModeM dw 0D6h ;W MASTER Mode de transfert +DmaFlipFlopM dw 0D8h ;W MASTER Flipflop adr/compteur +DmaTempM dw 0DAh ;R MASTER Reset du contr“leur +DmaClearM dw 0DAh ;R MASTER Registre temporaire +DmaMaskClrM dw 0DCh ;R MASTER Lib‚rer canaux +DmaMaskM2 dw 0DEh ;R MASTER Masquer canaux + +DmaAdress db 00h ;DMA address register 0 + db 002h ;DMA address register 1 + db 004h ;DMA address register 2 + db 006h ;DMA address register 3 + db 0c0h ;DMA address register 4 + db 0c4h ;DMA address register 5 + db 0c8h ;DMA address register 6 + db 0cch ;DMA address register 7 + +DmaCount db 001h ;DMA count registers 0 + db 003h ;DMA count registers 1 + db 005h ;DMA count registers 2 + db 007h ;DMA count registers 3 + db 0c2h ;DMA count registers 4 + db 0c6h ;DMA count registers 5 + db 0cah ;DMA count registers 6 + db 0ceh ;DMA count registers 7 + +DmaPage db 087h ;DMA page registers 0 + db 083h ;DMA page registers 1 + db 081h ;DMA page registers 2 + db 082h ;DMA page registers 3 + db 08fh ;DMA page registers 4 + db 08bh ;DMA page registers 5 + db 089h ;DMA page registers 6 + db 08ah ;DMA page registers 7 + +;verouille le canal AL +DisableDma: + push ax dx + cmp al, 4 + jae MasterDisableDma + mov dx, DmaMaskS + or al, 00000100b + out dx, al + jmp EndDisableDma +MasterDisableDma: + mov dx, DmaMaskS + and al, 00000011b + or al, 00000100b + out dx, al +EndDisableDma: + pop dx ax + ret + +;déverouille le canal AL +EnableDma: + push ax dx + cmp al, 4 + jae MasterDisableDma + mov dx, DmaMaskS + out dx, al + jmp EndEnableDma +MasterEnableDma: + mov dx, DmaMaskS + and al, 00000011b + out dx, al +EndEnableDma: + pop dx ax + ret + +;Efface le FlipFlop canal AL +ClrDmaFlipFlop: + push ax dx + cmp al, 4 + jae MasterClrFlipFlopDma + mov dx,DmaFlipFlopS + xor ax, ax + out dx, al + jmp EndClrFlipFlopDma +MasterClrFlipFlopDma: + mov dx,DmaFlipFlopM + xor ax, ax + out dx, al +EndClrFlipFlopDma: + pop dx ax + ret + +;Met le mode du canal al à ah +SetDmaMode: + push ax dx + cmp al, 4 + jae MasterSetDmaMode + mov dx,DmaModeS + or al, ah + out dx, al + jmp EndSetDmaMode +MasterSetDmaMode: + mov dx,DmaModeM + and al, 00000011b + or al, ah + out dx, al +EndSetDmaMode: + pop dx ax + ret + + +;Met le page du canal al a ah +SetDmaPage: + push ax bx dx si + cmp al, 4 + jae MasterSetDmaPage + mov si, offset DmaPage + xor dh, dh + xor bh, bh + mov bl, al + mov dl, cs:[si+bx] + xchg al, ah + out dx, al + jmp EndSetDmaPage +MasterSetDmaPage: +EndSetDmaPage: + pop si dx bx ax + ret + +;Met l'adresse du canal al a DS:BX +SetDmaAdress: + push ax bx cx dx si + push ax + mov ax, ds + and ax, 0000111111111111b + shl ax,4 + add bx, ax + mov ax, ds + and ax, 1111000000000000b + shr ax, 4 + mov cx,ax + pop ax + push ax + add ax,cx + call SetDmaPage + pop ax + call ClrDmaFlipFlop + mov si, offset DmaAdress + xor dh, dh + push bx + xor bh, bh + mov bl, al + mov dl, byte ptr cs:[si+bx] + pop bx + cmp al, 4 + jae MasterSetDmaAddress + mov al, bh + out dx, al + mov al, bl + out dx, al + jmp EndSetDmaAddress +MasterSetDmaAddress: + mov al, bh + out dx, al + call ClrDmaFlipFlop + mov al, bl + out dx, al +EndSetDmaAddress: + pop si dx cx bx ax + ret + +;Spécifie au controleur DMA le nombre d'octets à transférer dans CX +SetDmaCount: + push ax bx dx si + call ClrDmaFlipFlop + mov si, offset DmaCount + xor dh, dh + xor bh, bh + mov bl, al + mov dl, byte ptr cs:[si+bx] + cmp al, 4 + jae MasterSetDmaCount + mov al, ch + out dx, al + mov al, cl + out dx, al + jmp EndSetDmaCount +MasterSetDmaCount: + mov al, ch + out dx, al + call ClrDmaFlipFlop + mov al, cl + out dx, al +EndSetDmaCount: + pop si dx bx ax + ret + diff --git a/noyau/8259a.asm b/noyau/8259a.asm new file mode 100644 index 0000000..2349253 --- /dev/null +++ b/noyau/8259a.asm @@ -0,0 +1,415 @@ +;Adresses de port du contr“leur IRQ + MASTERPIC = 020h ;Adresse de base du PIC maŒtre + SLAVEPIC = 0A0h ;Adresse de base du PIC esclave + IRQMASK = 001h ;Offset sur port de masquage + +;Commandes IRQ OCW2 + DISABLEROTATION = 000h ;Desactiver la rotation de priorités en mode EOI automatique + EOI = 020h ;End of Interrupt non sp‚cifi‚ + COMMANDEOI = 060h ;Commande EOI particulière + ENABLEROTATION = 080h ;Activer la rotation de priorités en mode EOI automatique + ROTATIONNOSPEC = 0A0h ;Rotation des priorités en mode EOI automatique + SETPRIORITY = 0C0h ;Definir la priorité + ROTATIONSPEC = 0E0h ;Rotation des priorités en mode EOI spécifié + +;Position des vecteurs d'interruptions + MASTERFIRSTVECTOR = 008h ;Vecteurs logiciels des interruptions + SLAVEFIRSTVECTOR = 070h ;‚lectroniques + +;OCW3 codes registres + IRR = 002h ;Interrupt Request Register + ISR = 003h ;In Service Register +;OCW3 et modes + OCW3 = 008h ;OCW3 + POLLING = 004h ;Polling bit + + +ISR = 0Bh ; Pas d'op‚ration, pas de Poll, lire ISR OCW3 +IRR = 0Ah ; Pas d'op‚ration, pas de Poll, lire IRR + +;Autorise une interruption ‚lectronique +;Entr‚e : %1 - Num‚ro de l'interruption (0-15) … autoriser 0-7 = MASTERPIC , 8-15 = SLAVEPIC +PROC enableirq FAR + ARG @irq:word + USES ax,cx,dx + mov ax,[@irq] + mov dx,MASTERPIC+IRQMASK + cmp al,7 + jbe @@master + mov dx,SLAVEPIC+IRQMASK +@@master: + mov cl,al + and cl,7 + mov al,1 + shl al,cl + not al + mov ah,al + in al,dx + and al,ah + out dx,al + ret +endp enableirq + +;Desactive une interruption ‚lectronique +;Entr‚e : %0 - Num‚ro de l'interruption (0-15) … desactiver 0-7 = MASTERPIC , 8-15 = SLAVEPIC +PROC disableirq FAR + ARG @irq:word + USES ax,cx,dx + mov ax,[@irq] + mov dx,MASTERPIC+IRQMASK + cmp al,7 + jbe @@master + mov dx,SLAVEPIC+IRQMASK +@@master: + mov cl,al + and cl,7 + mov al,1 + shl al,cl + not al + mov ah,al + in al,dx + or al,ah + out dx,al + ret +endp disableirq + + +;Signale "End Of Interrupt" de l'interruption %0 +PROC seteoi FAR + ARG @irq:word + USES ax,dx + mov ax,[@irq] + cmp al,7 + jbe @@master + mov al,EOI + out SLAVEPIC,al +@@master: + mov al,EOI + out MASTERPIC,al + ret +endp seteoi + + +;Lit les masques d'un contr“leur IRQ dans ax, 0 master ou slave 1 ds %1 +PROC readimr FAR + ARG @controleur:word + USES bx,dx + mov bx,[@controleur] + mov dx,MASTERPIC+ IRQMASK + cmp bl,0 + jne @@master + mov dx,SLAVEPIC+ IRQMASK +@@master: + xor ah,ah + in al,dx + pop dx + ret +endp readimr + +;Lit le registre d'‚tat d'un contr“leur IRQ dans ax, 0 master ou slave 1 ds %1 +PROC readisr FAR + ARG @controleur:word + USES bx,dx + mov bx,[@controleur] + mov dx,MASTERPIC + cmp bh,0 + jne @@master + mov dx,SLAVEPIC +@@master: + mov al,ISR + out dx,al + xor ah,ah + in al,dx + ret +endp readisr + + +;Lit le registre d'‚tat d'un contr“leur IRQ dans al, 0 master ou slave 1 ds bh +PROC readirr FAR + ARG @controleur:word + USES bx,dx + mov bx,[@controleur] + mov dx,MASTERPIC + cmp bh,0 + jne @@master + mov dx,SLAVEPIC +@@master: + mov al,IRR + out dx,al + xor ah,ah + in al,dx + ret +endp readirr + +;carry si enable et pas carry si pas enable +PROC isenableirq FAR + ARG @irq:word + USES ax,cx,dx + mov ax,[@irq] + mov dx,MASTERPIC+IRQMASK + cmp al,7 + jbe @@master + mov dx,SLAVEPIC+IRQMASK +@@master: + mov cl,al + and cx,7 + in al,dx + neg al + bt ax,cx + ret +endp isenableirq + + +;carry si enable et pas carry si pas enable +PROC isinserviceirq FAR + ARG @irq:word + USES ax,cx,dx + mov ax,[@irq] + mov dx,MASTERPIC + cmp al,7 + jbe @@master + mov dx,SLAVEPIC +@@master: + mov cl,al + mov al,ISR + out dx,al + and cx,7 + in al,dx + neg al + bt ax,cx + ret +endp isinserviceirq + + +;carry si enable et pas carry si pas enable +PROC isrequestirq FAR + ARG @irq:word + USES ax,cx,dx + mov ax,[@irq] + mov dx,MASTERPIC + cmp al,7 + jbe @@master + mov dx,SLAVEPIC +@@master: + mov cl,al + mov al,IRR + out dx,al + and cx,7 + in al,dx + neg al + bt ax,cx + ret +endp isrequestirq + + +PROC installirqhandler FAR + USES eax,bx,cx,edx,si,di,ds,es + push fs + call mbcreate,offset interruptionbloc,256*size ints + mov es,ax + mov ax,0x0000 + mov ds,ax + xor si,si +@@searchdummypointer: + mov fs,[(vector si).data.seg] + mov bx,[(vector si).data.off] + cmp [byte ptr fs:bx],0xCF ;iret + je @@founded + add si,size vector + cmp si,256*4 + jb @@searchdummypointer + xor edx,edx + jmp @@suite +@@founded: + mov edx,[(vector si).content] +@@suite: + xor cx,cx + xor si,si + xor di,di + cli +@@copy: + mov [es:(ints di).number],cl + mov [es:(ints di).locked],0 + mov [es:(ints di).vector1.content],0 + mov [es:(ints di).vector3.content],0 + mov [es:(ints di).vector4.content],0 + mov [es:(ints di).vector5.content],0 + mov [es:(ints di).vector6.content],0 + mov [es:(ints di).vector7.content],0 + mov [es:(ints di).vector8.content],0 + mov [es:(ints di).launchedlow],0 + mov [es:(ints di).launchedhigh],0 + mov [es:(ints di).calledlow],0 + mov [es:(ints di).calledhigh],0 + mov eax,[(vector si).content] + cmp eax,edx + je @@notarealvector + mov [es:(ints di).vector1.content],eax + mov [es:(ints di).activated],1 + jmp @@copynext +@@notarealvector: + mov [es:(ints di).vector1.content],0 + mov [es:(ints di).activated],0 +@@copynext: + mov bx,cx + shl bx,3 + sub bx,cx + add bx,offset coupling + mov [(vector si).data.seg],cs + mov [(vector si).data.off],bx + add si,size vector + add di,size ints + inc cl + cmp cl,0 + jne @@copy +@@end: + pop fs + sti + ret +endp installirqhandler + + +interruptionbloc db '/interrupts',0 + + +PROC savecontext FAR +ARG @pointer:word +USES eax,si,ds +pushfd +push eax +push ebx +push ecx +push edx +push esi +push edi +push ds +push es +push fs +push gs +push ss +mov si,[@pointer] +mov ds,[ss:bp+4] +mov eax,ebp +mov ax,[word ptr ss:bp] +push eax +push [word ptr ss:bp+4] +xor eax,eax +mov ax,[word ptr ss:bp+2] +push eax +mov ax,bp +add ax,4 +push eax +pop [(regs si).sesp] +pop [(regs si).seip] +pop [(regs si).scs] +pop [(regs si).sebp] +pop [(regs si).sss] +pop [(regs si).sgs] +pop [(regs si).sfs] +pop [(regs si).ses] +pop [(regs si).sds] +pop [(regs si).sedi] +pop [(regs si).sesi] +pop [(regs si).sedx] +pop [(regs si).secx] +pop [(regs si).sebx] +pop [(regs si).seax] +pop [(regs si).seflags] +ret +endp savecontext + +PROC restorecontextg FAR +ARG @pointer:word +mov si,[@pointer] +pushd [cs:(regs si).sesi] +pushd [cs:(regs si).seflags] +mov eax,[cs:(regs si).seax] +mov ebx,[cs:(regs si).sebx] +mov ecx,[cs:(regs si).secx] +mov edx,[cs:(regs si).sedx] +mov edi,[cs:(regs si).sedi] +mov ebp,[cs:(regs si).sebp] +mov es,[cs:(regs si).ses] +mov fs,[cs:(regs si).sfs] +mov gs,[cs:(regs si).sgs] +mov ds,[cs:(regs si).sds] +popfd +pop esi +pop [cs:dummy] +db 0xCA,0x02,0x00 ;retf 2 +endp restorecontextg + + + +coupling: +counter = 0 +REPEAT 256 +push counter+256 +push offset irqhandlers +ret +counter = counter + 1 +ENDM + +interrupt dw 0 +dummy dw 0 +calling_reg regs <> +function_reg regs <> + +irqhandlers: +cli +pop [cs:interrupt] +call savecontext,offset calling_reg +call irqhandler,[cs:interrupt] +call restorecontextg,offset calling_reg +sti +iret + +PROC irqhandler NEAR +ARG @int:word +push cs +pop ds +call mbfindsb,offset interruptionbloc,cs +jc @@end +mov es,ax +mov ax,[@int] +sub ax,256 +mov cx,size ints +mul cx +mov si,ax +add [es:(ints si).calledlow],1 +adc [es:(ints si).calledhigh],0 +cmp [es:(ints si).activated],1 +jne @@end +add [es:(ints si).launchedlow],1 +adc [es:(ints si).launchedhigh],0 +lea si,[es:(ints si).vector1] +mov cl,8 +@@launchall: +cmp [es:(vector si).content],0 +je @@end +push [word ptr cs:calling_reg.seflags] +push cs +push offset @@back +push [es:(vector si).data.seg] +push [es:(vector si).data.off] +call savecontext,offset function_reg +call restorecontextg,offset calling_reg +db 0xCB +@@back: +cli +call savecontext,offset calling_reg +call restorecontextg,offset function_reg +@@next: +add si,size vector +dec cl +jnz @@launchall +@@end: +ret +endp irqhandler + + + + + + + diff --git a/noyau/MAKEFILE b/noyau/MAKEFILE new file mode 100644 index 0000000..d14bef5 --- /dev/null +++ b/noyau/MAKEFILE @@ -0,0 +1,38 @@ +asm= lzasm /z/t +lnk= elink + +all: systeme.sys boot.bin + +systeme.sys: video.obj disque.obj systeme.obj + $(lnk) systeme.obj systeme.sys + +systeme.obj: ..\lib\detect.lib ..\lib\video.lib video.sys disque.sys + $(asm) systeme.asm + +disque.sys: + $(lnk) disque.obj disque.sys + +video.sys: + $(lnk) video.obj video.sys + +boot.bin: boot.obj + $(lnk) boot.obj boot.bin /bs + +video.obj: + $(asm) video.asm + +disque.obj: + $(asm) disque.asm + +boot.obj: + $(asm) boot.asm + +clean: + del *.obj + del *.exe + del *.bak + del *.lib + del *.com + del *.bin + del *.sys + del *.err \ No newline at end of file diff --git a/noyau/boot.asm b/noyau/boot.asm new file mode 100644 index 0000000..05812e0 --- /dev/null +++ b/noyau/boot.asm @@ -0,0 +1,216 @@ +model tiny,stdcall +p486 +locals +jumps +codeseg +option procalign:byte + +include "..\include\mem.h" +include "..\include\fat.h" +include "..\include\divers.h" + +org 7C00h + +jmp boot + +bootsec bootinfo <"COS2000A",512,1,1,2,224,2880,0F0h,9,18,2,0,0,0,0,0,29h,01020304h,"COS2000 ","FAT12 "> + +errorloading db " [Erreur]",0dh,0ah,0 +okloading db "Recherche noyau ",0Dh,0ah," -" +sys db "SYSTEME SYS",0 +syst db " [ Ok ]",0dh,0ah,"Chargement ",0 +dot db ".",0 + + + +errorboot: + mov si,offset errorloading + call showstr + mov ah,0 + int 16h + int 19h + +boot: + mov [bootsec.bootdrive],dl + cli + mov ax,09000h + mov ss,ax + mov sp,0FFFFh + sti +boot2: + push cs + push cs + pop es + pop ds + xor ax,ax + mov dl,[bootsec.bootdrive] + int 13h + jc errorboot + mov si,offset okloading + call showstr + mov cx,[bootsec.reservedsectors] + add cx,[bootsec.hiddensectorsh] + adc cx,[bootsec.hiddensectorsl] + push cx + mov bx,[bootsec.sectorsperfat] + mov di,offset bufferfat +readfat: + call readsector + jc errorboot + inc cx + add di,[bootsec.sectorsize] + dec bx + jnz readfat + pop cx + xor ax,ax + mov al,[bootsec.fatsperdrive] + mov bx,[bootsec.sectorsperfat] + mul bx + add cx,ax + mov ax,32 + mul [bootsec.directorysize] + div [bootsec.sectorsize] + add ax,cx + sub ax,2 + mov [word ptr bootsec.reservedfornt],ax + xor dx,dx +checkroot: + mov di,offset buffer + call readsector + jc errorboot + xor bx,bx +findnext: + cmp [byte ptr di],0 + je errorboot + cmp [byte ptr di],0E5h + je no + cmp [byte ptr di],041h + je no + mov si,offset dot + call showstr + push di cx + mov si,offset sys + mov cx,11 + rep cmpsb + pop cx di + je oksystem +no: + add di,32 + add bx,32 + inc dx + cmp dx,[bootsec.directorysize] + ja errorboot + cmp bx,[bootsec.sectorsize] + jb findnext + inc cx + jmp checkroot +oksystem: + mov si,offset syst + call showstr + mov cx,[di+26] + mov ax,8000h + mov es,ax + push es + mov di,0000h + push 0010h + mov si,offset dot + xor ax,ax +fatagain: + cmp cx,0FF0h + jae finishload + push cx + add cx,[word ptr bootsec.reservedfornt] + call readsector + pop cx + jc errorboot + inc ax + call showstr + add di,[bootsec.sectorsize] + call getfat + jnc fatagain +finishload: + retf + +;=============READSECTOR (Fonction 01H)=============== +;Lit le secteur CX et le met en es:di +;-> AH=1 +;<- Flag Carry si erreur +;===================================================== +readsector: + push ax bx cx dx si + mov ax,cx + xor dx,dx + div [bootsec.sectorspertrack] + inc dl + mov bl,dl + xor dx,dx + div [bootsec.headsperdrive] + xchg dl,dh + mov cx,ax + xchg cl,ch + shl cl,6 + or cl, bl + mov bx,di + mov si, 4 + mov al, 1 +tryagain: + mov ah, 2 + mov dl,[bootsec.bootdrive] + int 13h + jnc done + dec si + jnz tryagain +done: + pop si dx cx bx ax + ret + + +getfat: + push ax bx dx di + mov di,offset bufferfat + mov ax,cx + mov bx,ax + and bx,0000000000000001b + shr ax,1 + mov cx,3 + mul cx + add di,ax + cmp bx,0h + jnz evenfat +oddfat: + mov dx,[di] + and dx,0FFFh + mov cx,dx + jmp endfat +evenfat: + mov dx,[di+1] + and dx,0FFF0h + shr dx,4 + mov cx,dx +endfat: + pop di dx bx ax + ret + + +showstr: + push ax bx si +again: + lodsb + or al,al + jz fin + mov ah,0Eh + mov bx,07h + int 10h + jmp again +fin: + pop si bx ax + ret + + +db 055h,0AAh + +endof: + +buffer equ offset endof+2048 +bufferfat equ offset endof+4096 + diff --git a/noyau/clavier.asm b/noyau/clavier.asm new file mode 100644 index 0000000..9fd3cdd --- /dev/null +++ b/noyau/clavier.asm @@ -0,0 +1,261 @@ +.model tiny +.486 +smart +.code + +org 0h + +include ..\include\mem.h + +start: + +jmp tsr +offsets dd 0 +db 'KEYBOARD' +tsr: + pushf + db 2eh,0ffh,1eh + dw offsets + cli + cmp cs:isstate,1 + je endofforce + mov cs:isstate,1 + mov cs:eaxr,eax + in al,60h + cmp al,68 + je F10 + cmp al,87 + je F11 + cmp al,88 + je F12 +endof: + mov cs:isstate,0 + mov eax,cs:eaxr +endofforce: + sti + iret + isstate db 0 + infos db 40 dup (0) + feax dd 0 + +F10: + push cs + pop ds + mov si,offset com + mov ah,5 + int 49h + pop ax + pop ax + pop ax + push gs + push gs + push gs + pop ds + pop es + pop fs + push gs + push size exe + sti + mov cs:[isstate],0 + retf + +com db 'COMMANDE.CE',0 + +F11: + push ax di es + push cs + pop es + mov di,offset infos + mov ah,34 + int 47h + mov al,cs:[di+7] + inc al + cmp al,9 + jbe notabove + mov al,0 +notabove: + mov ah,0 + int 47h + pop es di ax + jmp endof + + +f12: +pushad +pushf +push ds +mov cs:[eaxr],eax +mov cs:[ebxr],ebx +mov cs:[ecxr],ecx +mov cs:[edxr],edx +mov cs:[esir],esi +mov cs:[edir],edi +mov cs:[espr],esp +mov cs:[ebpr],ebp +mov cs:[csr],cs +mov cs:[dsr],ds +mov cs:[esr],es +mov cs:[fsr],fs +mov cs:[gsr],gs +mov cs:[ssr],ss +push cs +pop ds +mov si,offset sep +call Showstr +mov si,offset reg +mov di,offset regdata +mov bx,7 +showregs: +cmp byte ptr cs:[si+6],":" +jne endshowregs +call Showstr +cmp byte ptr cs:[si+4]," " +je segsss +mov edx,cs:[di] +mov cx,32 +call Showhex +add di,4 +jmp showmax +segsss: +mov dx,cs:[di] +mov cx,16 +call Showhex +add di,2 +showmax: +add si,9 +mov bp,dx +push si +mov si,offset beginds +call showstr +mov si,bp +mov cx,8 +mov al,0 +letshow: +mov dl,ds:[si] +inc si +call showhex +inc al +cmp al,10 +jb letshow +mov si,offset ende +call showstr +mov si,offset begines +call showstr +mov si,bp +mov cx,8 +mov al,0 +letshow2: +mov dl,es:[si] +inc si +call showhex +inc al +cmp al,10 +jb letshow2 +mov si,offset ende +call showstr +pop si +jmp showregs +endshowregs: +mov si,offset sep +call Showstr +xor ax,ax +int 16h +pop ds +popf +popad +jmp endof +begines db ' es[',0 +beginds db ' ds[',0 +ende db '] ',0 + + +;==============================Affiche le nombre nb hexa en EDX de taille CX et couleur BL============== +ShowHex: + push ax bx cx edx si di + mov di,cx + sub cx,32 + neg cx + shl edx,cl + shr di,2 + mov ah,09h + and bx,1111b +Hexaize: + rol edx,4 + mov si,dx + and si,1111b + mov al,[si+offset tab] + push cx + mov cx,1 + cmp al,32 + jb control2 + mov ah,09h + int 10h +control2: + mov ah,0Eh + int 10h + pop cx + dec di + jnz Hexaize + pop di si edx cx bx ax + ret +Tab db '0123456789ABCDEF' + +;==============================Affiche une chaine DS:SI de couleur BL============== +showstr: + push ax bx cx si + mov cx,1 +again: + lodsb + or al,al + jz fin + and bx,0111b + cmp al,32 + jb control + mov ah,09h + int 10h +control: + mov ah,0Eh + int 10h + jmp again + fin: + pop si cx bx ax + ret + + +;================================================ +;Routine de débogage +;================================================ +regdata: +eaxr dd 0 +ebxr dd 0 +ecxr dd 0 +edxr dd 0 +esir dd 0 +edir dd 0 +espr dd 0 +ebpr dd 0 +csr dw 0 +dsr dw 0 +esr dw 0 +fsr dw 0 +gsr dw 0 +ssr dw 0 + +reg db 0Dh,0Ah,"eax : ",0 + db 0Dh,0Ah,"ebx : ",0 + db 0Dh,0Ah,"ecx : ",0 + db 0Dh,0Ah,"edx : ",0 + db 0Dh,0Ah,"esi : ",0 + db 0Dh,0Ah,"edi : ",0 + db 0Dh,0Ah,"esp : ",0 + db 0Dh,0Ah,"ebp : ",0 + db 0Dh,0Ah,"cs : ",0 + db 0Dh,0Ah,"ds : ",0 + db 0Dh,0Ah,"es : ",0 + db 0Dh,0Ah,"fs : ",0 + db 0Dh,0Ah,"gs : ",0 + db 0Dh,0Ah,"ss : ",0 + +sep db 0Ah,0Dh,'********************',0Ah,0Dh,0 + +end start diff --git a/noyau/disque.asm b/noyau/disque.asm new file mode 100644 index 0000000..0c91749 --- /dev/null +++ b/noyau/disque.asm @@ -0,0 +1,1099 @@ +model tiny,stdcall +p486 +locals +jumps +codeseg +option procalign:byte + +include "..\include\mem.h" +include "..\include\fat.h" + +org 0h + +header exe <"CE",1,0,0,offset exports,offset imports,,> + + +exporting +declare readsector +declare writesector +declare verifysector +declare initdrive +declare loadfile +declare compressrle +declare decompressrle +declare findfirstfile +declare findnextfile +declare getfreespace +declare searchfile +declare getname +declare getserial +declare changedir +declare readcluster +declare writecluster +declare getdir +declare projfile +declare execfile +ende + +importing +use SYSTEME,biosprinth +use SYSTEME,mbfindsb +use SYSTEME,mbfree +use SYSTEME,mbcreate +use SYSTEME,mbresident +use SYSTEME,mbfind +use SYSTEME,mbchown +use SYSTEME,mbloadfuncs +use SYSTEME,mbloadsection +endi + + +;DPT disquette +mydpt dpt <> + +;Secteur de boot +myboot bootinfo <> + +;Parametres +support db 0 +nbbuffer db 0 + +;Données Calculée +clustersize dw 0 +tracksperhead dw 0 +drivesize dd 0 +adressboot dw 0 +adressfat dw 0 +adressparent dw 0 +adressdirectory dw 0 +adressdata dw 0 +addingvalue dw 0 +currentdir dw 0 ;En cluster +currentdirstr db 128 dup (0) + + +PROC getfat near + uses ax,bx,dx,si,ds,es + push cs + pop ds + + push cs + pop es + call [cs:mbfindsb],offset datafat,cs + mov es,ax + mov ax,cx + mov bx,ax + and bx,0000000000000001b + shr ax,1 + mov cx,3 + mul cx + ;mov si,offset fatter + xor si,si + add si,ax + cmp bx,0h + jnz evenfat +oddfat: + mov ax,[es:si] + and ax,0FFFh + mov cx,ax + jmp endfat +evenfat: + mov ax,[es:si+1] + and ax,0FFF0h + shr ax,4 + mov cx,ax +endfat: + cmp ax,0FF0h + jbe nocarry + stc + ret +nocarry: + clc + ret +endp getfat + +;============loadfile=============== +;Charge le fichier ds:%0 en ds:%1 ->ax taille +;-> AH=4 +;<- Flag Carry si erreur +;===================================================== +PROC loadfile FAR + ARG @name:word,@pointer:word + LOCAL @@temp:word:48 + USES cx,si,di,ds,es + push ss + pop es + lea di,[@@temp] + push ds di + mov si,[@name] + mov cx,48/4 + cld + rep movsd + push ss + pop ds + pop di es + call searchfile,di + jne errorload + jc errorload + mov cx,[(find di).result.filegroup] + mov eax,[(find di).result.filesize] + push es + pop ds + call loadway,cx,eax,[@pointer] + jc errorload + clc + ret +errorload: + stc + xor eax,eax + ret +endp loadfile + +;============execfile (Fonction 18)=============== +;Execute le fichier ds:si +;-> AH=18 +;<- Flag Carry si erreur +;===================================================== +PROC execfile FAR + ARG @file:word + pushad + push ds es fs gs + mov di,[@file] + call uppercase,di + call projfile,di + jc @@reallyerrornoblock + call [cs:mbfind],di + jc @@reallyerror + call [cs:mbchown],ax,[word ptr ss:bp+4] + jc @@reallyerror + push ax + pop ds + cmp [ds:0x0],'EC' + jne @@reallyerror + push ax + push cs + push offset @@arrive + push ds + push [word ptr (exe).starting] + push ds + push ds + push ds + pop es + pop fs + pop gs + push 7202h + xor eax,eax + xor ebx,ebx + xor ecx,ecx + xor edx,edx + xor esi,esi + xor edi,edi + xor ebp,ebp + popf + sti + db 0CBh +@@arrive: + ;cli + ;pop ax + ;call [cs:mbfree],ax + call [cs:mbfree] + pop gs fs es ds + popad + clc + ret +@@reallyerror: + call [cs:mbfree],ax +@@reallyerrornoblock: + pop gs fs es ds + popad + stc + ret +endp execfile + +;============projfile (Fonction 17)=============== +;Charge le fichier ds:%0 sur un bloc mémoire -> eax taille +;-> eax taille fichier +;<- Flag Carry si erreur +;===================================================== +PROC projfile FAR +ARG @pointer:word +LOCAL @@temp:word:64 +USES cx,si,di,ds,es + push ss + pop es + lea di,[@@temp] + push di + mov si,[@pointer] + mov cx,64/4 + cld + rep movsd + push ss + pop ds + pop di + call uppercase,di + call [cs:mbfind],di + jnc @@notace + call searchfile,di + jne @@errorload + jc @@errorload + mov eax,[es:(find di).result.filesize] + call [cs:mbcreate],di,ax + jc @@errorload + call [cs:mbchown],ax,[word ptr ss:bp+4] + jc @@errorload + mov ds,ax + mov cx,[es:(find di).result.filegroup] + mov eax,[es:(find di).result.filesize] + call loadway,cx,eax,0 + jc @@errorload + cmp [ds:0x0],'EC' + jne @@notace + call [cs:mbloadfuncs],ds + jc @@errorload + call [cs:mbloadsection],ds + jc @@errorload + @@notace: + clc + ret +@@errorload: + xor eax,eax + stc + ret +endp projfile + + +;=============SearchFile=============== +;Renvois dans ds:%0 et non equal si pas existant +;-> +;<- Flag Carry si erreur +;====================================== +PROC searchfile FAR +ARG @pointer:word + USES bx,cx,si,di,ds,es + mov si,[@pointer] + lea bx,[es:(find si).result] + call uppercase,si + call findfirstfile,si + jc @@errorsearch + jmp @@founded +@@nextsearch: + call findnextfile,si + jc @@errorsearch +@@founded: + cmp [byte ptr bx],0 + je @@notgood + cmp [byte ptr bx+entries.fileattr],0Fh + je @@nextsearch + call cmpnames,si,bx + jc @@nextsearch +@@okfound: + clc + ret +@@notgood: + cmp si,0FF5h + ret +@@errorsearch: + stc + ret +endp searchfile + +;Transforme la chaine ds:%0 en maj +PROC uppercase FAR + ARG @strs:word + USES si,ax + mov si,[@strs] +@@uppercaser: + mov al,[si] + cmp al,0 + je @@enduppercase + cmp al,'a' + jb @@nonmaj + cmp al,'z' + ja @@nonmaj + sub al,'a'-'A' + mov [si],al +@@nonmaj: + inc si + jmp @@uppercaser +@@enduppercase: + clc + ret +endp uppercase + +;Compare le nom ds:%0 '.' avec ds:%1 +PROC cmpnames FAR + ARG @off1:word,@off2:word + USES ax,cx,si,di,es + mov si,[@off1] + mov di,[@off2] + cmp [byte ptr si],"." + jne @@notaredir + cmp [word ptr si],".." + jne @@onlyonedir + cmp [word ptr di],".." + je @@itok + jmp @@notequal +@@onlyonedir: + cmp [word ptr di]," ." + je @@itok +@@notaredir: + push ds + pop es + mov cx,8 + repe cmpsb + jne @@nequal + inc si + jmp @@equal +@@nequal: + cmp [byte ptr es:di-1],' ' + jne @@notequal +@@equal: + cmp [byte ptr si-1],'.' + jne @@trynoext + mov al,' ' + rep scasb + mov cx,3 + rep cmpsb + jne @@nequal2 + inc si + jmp @@equal2 +@@nequal2: + cmp [byte ptr es:di-1],' ' + jne @@notequal +@@equal2: + cmp [byte ptr si-1],0 + jne @@notequal +@@itok: + clc + ret +@@notequal: + stc + ret +@@trynoext: + cmp [byte ptr si-1],0 + jne @@notequal + jmp @@itok +endp cmpnames + +;charge le fichier de de groupe %0 et de taille %1 +PROC loadway NEAR + ARG @sector:word,@size:dword,@offset:word + USES eax,bx,cx,dx,si,di,ds,es + push ds + pop es + mov eax,[@size] + cmp eax,0 + je @@zeroload + rol eax,16 + mov dx,ax + ror eax,16 + div [cs:clustersize] + mov bx,ax + mov cx,[@sector] + mov di,[@offset] + cmp bx,1 + jb @@adjustlast +@@loadfat: + call readcluster,cx,di + jc @@noway + add di,[cs:clustersize] + call getfat + dec bx + jnz @@loadfat +@@adjustlast: + cmp dx,0 + je @@zeroload + push cs + pop ds + mov si,offset bufferread + call readcluster,cx,si + jc @@noway + mov cx,dx + cld + rep movsb +@@zeroload: + clc + ret +@@noway: + stc + ret +endp loadway + +;=============INITDRIVE=============== +;Initialise le lecteur pour une utilisation ultérieure +;-> +;<- Flag Carry si erreur +;===================================== +PROC initdrive FAR + USES eax,bx,cx,edx,si,di,ds,es + push cs + pop ds + push cs + pop es + mov di,3 +@@againtry: + xor ax,ax + mov dl,[support] + xor dh,dh + int 13h + mov bx,offset bufferread + mov ax,0201h + mov cx,0001h + mov dl,[support] + xor dh,dh + int 13h + jnc @@oknoagaintry + dec di + jnz @@againtry +@@oknoagaintry: + mov si,offset bufferread+3 + mov di,offset myboot + mov cx,size myboot + cld + rep movsb + mov ax,[myboot.sectorsize] + mov bl,[myboot.sectorspercluster] + xor bh,bh + mul bx + mov [clustersize],ax + mov bx,[myboot.hiddensectorsl] + adc bx,[myboot.hiddensectorsh] + mov [adressboot],bx + add bx,[myboot.reservedsectors] + mov [adressfat],bx + xor ax,ax + mov al,[myboot.fatsperdrive] + mul [myboot.sectorsperfat] + add bx,ax + mov [adressparent],bx + mov [adressdirectory],bx + mov ax,32 + mul [myboot.directorysize] + div [myboot.sectorsize] + add bx,ax + mov [adressdata],bx + sub bx,2 + mov [addingvalue],bx + mov ax,[myboot.sectorsperdrive] + div [myboot.sectorspertrack] + xor dx,dx + div [myboot.headsperdrive] + mov [tracksperhead],ax + xor eax,eax + mov ax,[myboot.sectorsperdrive] + sub ax,[adressdata] + mul [myboot.sectorsize] + shl edx,16 + add edx,eax + mov [drivesize],edx + mov [currentdir],0 + mov [adressdirectory],0 + mov [currentdirstr],0 + xor eax,eax + mov ax,[myboot.sectorsperfat] + mul [myboot.sectorsize] + call [cs:mbfindsb],offset datafat,cs + jnc @@hadafatbloc + call [cs:mbcreate],offset datafat,ax + jc @@errorinit + call [cs:mbresident],ax + jc @@errorinit + call [cs:mbchown],ax,cs + jc @@errorinit +@@hadafatbloc: + mov dx,[myboot.sectorsperfat] + mov cx,[adressfat] + xor di,di + ;mov di,offset fatter + mov ds,ax +@@seefat: + call readsector,cx,di + jc @@errorinit + add di,[cs:myboot.sectorsize] + inc cx + dec dx + jnz @@seefat + clc + ret +@@errorinit: + stc + ret +endp initdrive + +datafat db '/fat',0 + +;=============FindFirstFile============== +;Renvois dans DS:%1 un bloc d'info +;-> +;<- Flag Carry si erreur +;======================================== +PROC findfirstfile FAR + ARG @pointer:word + USES cx,si + mov si,[@pointer] + mov cx,[cs:currentdir] + mov [(find si).adressdirectory],cx + xor cx,cx + mov [(find si).entryplace],cx + mov [(find si).firstsearch],1 + call findnextfile,[@pointer] + ret +endp findfirstfile + +;=============FindnextFile============== +;Renvois dans DS:%0 un bloc d'info +;-> +;<- Flag Carry si erreur +;======================================= +PROC findnextfile FAR + ARG @pointer:word + USES ax,bx,cx,di,si,ds,es + push cs + push ds + pop es + pop ds + mov si,[@pointer] + mov cx,[es:(find si).adressdirectory] + mov bx,[es:(find si).entryplace] +@@findnextfileagain: + cmp [es:(find si).firstsearch],1 + je @@first + add bx,size entries + cmp bx,[cs:clustersize] + jb @@nopop +@@first: + mov di,offset bufferentry + mov bx,0 + cmp [cs:currentdir],0 + jne @@notrootdir + cmp [es:(find si).firstsearch],1 + je @@noaddfirst1 + inc cx +@@noaddfirst1: + add cx,[cs:adressparent] + mov al,[cs:myboot.sectorspercluster] +@@readroot: + call readsector,cx,di + jc @@notwell + add di,[cs:myboot.sectorsize] + dec al + jnz @@readroot + sub cx,[cs:adressparent] + jmp @@nopop +@@notrootdir: + cmp [es:(find si).firstsearch],1 + je @@noaddfirst2 + call getfat +@@noaddfirst2: + jc @@notwell + call readcluster,cx,di + jc @@notwell +@@nopop: + mov [es:(find si).firstsearch],0 + mov di,offset bufferentry + add di,bx + cmp [byte ptr di],0 + je @@notwell + mov [es:(find si).entryplace],bx + mov [es:(find si).adressdirectory],cx + cmp [byte ptr di],0E5h + je @@findnextfileagain + cmp [byte ptr di+entries.fileattr],28h + je @@findnextfileagain + cmp [byte ptr di+entries.fileattr],0Fh + je @@findnextfileagain + mov si,di + mov di,[@pointer] + lea di,[es:(find di).result] + mov cx,size entries + cld + rep movsb + clc + ret +@@notwell: + stc + ret +endp findnextfile + +;=============GetFreeSpace=============== +;Renvoie en EDX l'espace disque libre du volume +;-> +;<- Flag Carry si erreur +;======================================== +PROC getfreespace FAR + USES eax,bx + xor eax,eax + call getsector + mul [cs:myboot.sectorsize] + shl edx,16 + add edx,eax + pop eax + ret +endp getfreespace + +;ax=défectueux bx=libre +getsector: + push cx dx + mov dx,[cs:myboot.sectorsperdrive] + sub dx,[cs:addingvalue] + xor ax,ax + xor bx,bx + mov cx,0 +goget: + push cx + call getfat + cmp cx,0FF7h + jne notdefect + inc bx +notdefect: + cmp cx,0 + jne notfree + inc ax +notfree: + pop cx + inc cx + dec dx + jnz goget + pop dx cx + ret +errorfree: + stc + pop dx cx + ret + + +;=============READCLUSTER=============== +;Lit le secteur %0 et le met en ds:%1 +;-> +;<- Flag Carry si erreur +;======================================= +PROC readcluster FAR + ARG @sector:word,@pointer:word + USES ax,bx,dx,si + mov al,[cs:myboot.sectorspercluster] + xor ah,ah + mov bx,ax + mul [@sector] + add ax,[cs:addingvalue] + mov si,[@pointer] +@@readsectors: + call readsector,ax,si + jc @@errorreadincluster + add si,[cs:myboot.sectorsize] + inc ax + dec bx + jnz @@readsectors + clc + ret +@@errorreadincluster: + stc + ret +endp readcluster + +;=============WRITECLUSTER=============== +;Ecrit le cluster %0 et le met en ds:%1 +;-> +;<- Flag Carry si erreur +;===================================================== +PROC writecluster FAR + ARG @sector:word,@pointer:word + USES ax,bx,dx,si + mov al,[cs:myboot.sectorspercluster] + xor ah,ah + mov bx,ax + mul [@sector] + add ax,[cs:addingvalue] + mov si,[@pointer] +@@writesectors: + call writesector,ax,si + jc @@errorwriteincluster + add si,[cs:myboot.sectorsize] + inc ax + dec bx + jnz @@writesectors + clc + ret +@@errorwriteincluster: + stc + ret +endp writecluster + +;=============READSECTOR=============== +;Lit le secteur %0 et le met en ds:%1 +;-> +;<- Flag Carry si erreur +;====================================== +PROC readsector FAR + ARG @sector:word,@pointer:word + USES ax,bx,cx,dx,si,es + push ds + pop es + mov ax,[@sector] + xor dx,dx + div [cs:myboot.sectorspertrack] + inc dl + mov bl,dl + xor dx,dx + div [cs:myboot.headsperdrive] + mov dh,[cs:support] + xchg dl,dh + mov cx,ax + xchg cl,ch + shl cl,6 + or cl,bl + mov bx,[@pointer] + mov si,5 +@@tryagain: + mov ax,0201h + int 13h + jnc @@done + dec si + jnz @@tryagain +@@done: + ret +endp readsector + +;=============WRITESECTOR============ +;Ecrit le secteur %0 pointé par ds:%0 +;-> +;<- Flag Carry si erreur +;==================================== +PROC writesector FAR + ARG @sector:word,@pointer:word + USES ax,bx,cx,dx,si,es + push ds + pop es + mov ax,[@sector] + xor dx,dx + div [cs:myboot.sectorspertrack] + inc dl + mov bl,dl + xor dx,dx + div [cs:myboot.headsperdrive] + mov dh,[cs:support] + xchg dl,dh + mov cx,ax + xchg cl,ch + shl cl,6 + or cl, bl + mov bx,[@pointer] + mov si,5 +@@tryagain: + mov ax,0301h + int 13h + jnc @@done + dec si + jnz @@tryagain +@@done: + ret +endp writesector + +;=============Getname============== +;Renvoie le nom en DS:%0 +;-> AH=11 +;<- Flag Carry si erreur +;================================== +PROC getname FAR + ARG @pointer:word + USES ax,cx,si,di,ds,es + push ds + pop es + push cs + pop ds + mov di,[@pointer] + mov si,offset myboot.drivename + mov cx,11 + rep movsb + mov al,' ' + mov di,[@pointer] + mov cx,11 + repne scasb + mov [byte ptr es:di],0 + ret +endp getname +;=============Getserial============== +;Renvoie le numéro de serie en EAX +;-> +;<- Flag Carry si erreur +;==================================== +PROC getserial FAR + mov eax,[cs:myboot.serialnumber] + ret +endp getserial + +;=============VERIFYSECTOR============== +;Vérifie le secteur %0 +;-> +;<- Flag Carry si erreur, Flag Equal si secteurs égaux +;======================================= +PROC verifysector FAR + ARG @sector:word + USES ecx,si,di,ds,es + push cs + pop es + push cs + pop ds + mov si,offset bufferread + call readsector,cx,si + call inverse + call writesector,cx,si + jc @@errorverify + + mov si,offset bufferwrite + call readsector,cx,si + call inverse + jc @@errorverify + + mov si,offset bufferread + call inverse + call writesector,cx,si + jc @@errorverify + + xor ecx,ecx + mov cx,[cs:myboot.sectorsize] + shr cx,2 + mov si,offset bufferread + mov di,offset bufferwrite + cld + rep cmpsd +@@errorverify: + ret + +endp verifysector + +inverse: + push si cx + xor cx,cx +invert: + not [dword ptr si] + add si,4 + add cx,4 + cmp cx,[cs:myboot.sectorsize] + jb invert + pop cx si + ret + +;=============DecompressRle (Fonction 05H)============== +;decompress ds:si en es:di taille bp d‚compress‚ cx compress‚ +;-> AH=5 +;<- Flag Carry si erreur, Flag Equal si secteurs égaux +;===================================================== +PROC decompressrle FAR + ARG @seg1:word,@off1:word,@seg2:word,@off2:word,@size:word + USES ecx,dx,si,di,ds,es + mov ds,[@seg1] + mov es,[@seg2] + mov si,[@off1] + mov di,[@off2] + mov dx,[@size] +@@decompression: + mov eax,[ds:si] + cmp al,'/' + jne @@nocomp + cmp si,07FFFh-6 + jae @@thenen + mov ecx,eax + ror ecx,16 + cmp cl,'*' + jne @@nocomp + cmp [byte ptr ds:si+4],'/' + jne @@nocomp + mov al,ch + mov cl,ah + xor ah,ah + xor ch,ch + cld + rep stosb + add si,5 + sub dx,5 + jnz @@decompression + jmp @@thenen +@@nocomp: + mov [es:di],al + inc si + inc di + dec dx + jnz @@decompression +@@thenen: + xor eax,eax + mov ax,di + sub ax,[@off2] + clc + ret +endp decompressrle + +;=============CompressRle (Fonction 06H)============== +;compress ds:si en es:di taille cx d‚compress‚ BP compress‚ +;-> AH=6 +;<- Flag Carry si erreur, Flag Equal si secteurs égaux +;===================================================== +PROC compressrle FAR + ARG @seg1:word,@off1:word,@seg2:word,@off2:word,@size:word + USES ax,bx,cx,dx,si,di,ds,es + mov es,[@seg1] + mov ds,[@seg2] + mov di,[@off1] + mov si,[@off2] + mov dx,[@size] +@@againcomp: + mov bx,di + mov al,[es:di] + mov cx,dx + cmp ch,0 + je @@poo + mov cl,0ffh + ;mov cx,bp + ;sub cx,di + ;mov ah,cl +@@poo: + mov ah,cl + inc di + xor ch,ch + repe scasb + sub cl,ah + neg cl + cmp cl,6 + jbe @@nocomp2 + mov [dword ptr si],' * /' + mov [byte ptr si+4],'/' + mov [si+1],cl + mov [si+3],al + add si,5 + dec di + xor ch,ch + sub dx,cx + jnz @@againcomp + jmp @@fini +@@nocomp2: + mov [si],al + inc si + inc bx + mov di,bx + dec dx + jnz @@againcomp +@@fini: + mov ax,si + sub ax,[@off2] + clc + ret +endp compressrle + +;=============Changedir (Fonction 13)============== +;Change le repertoire courant a DS:SI +;-> AH=13 +;<- Flag Carry si erreur, Flag Equal si secteurs égaux +;===================================================== +PROC changedir FAR +ARG @pointer:word +LOCAL @@temp:word:64 +USES cx,si,di,ds,es + push ss + pop es + lea di,[@@temp] + push di + mov si,[@pointer] + mov cx,64/4 + cld + rep movsd + push ss + pop ds + pop di + call searchfile,di + jne @@noch + jc @@noch + ;cmp [si],005Ch ;'/',0 (root dir) + mov cx,[es:(find di).result.filegroup] + mov [cs:currentdir],cx + mov [cs:adressdirectory],cx + cmp [dword ptr es:(find di).result.filename],' .' + je @@theend + cmp [dword ptr es:(find di).result.filename],' ..' + jne @@notback + push cs + push cs + pop ds + pop es + mov di,offset currentdirstr + mov cx,128 + mov al,0 + cld + repne scasb + mov al,'/' + std + repne scasb + inc di + mov [byte ptr es:di],0 + jmp @@theend +@@notback: + push cs + push cs + pop ds + pop es + mov di,offset currentdirstr + mov cx,128 + mov al,0 + cld + repne scasb + dec di + mov al,'/' + cld + stosb + mov dx,di + push ss + pop es + lea di,[@@temp] + mov si,di + mov cx,128 + mov al,0 + cld + repne scasb + sub cx,128 + neg cx + push ss + pop ds + push cs + pop es + mov di,dx + cld + rep movsb +@@theend: + clc + ret +@@noch: + stc + ret +endp changedir + +;=============getdir============== +;Recupere le repertoire courant a DS:%0 +;-> +;<- Flag Carry si erreur +;================================= +PROC getdir FAR + ARG @pointer:word + USES ax,cx,si,di,ds,es + push cs + pop es + mov di,offset currentdirstr + mov cx,128 + mov al,0 + cld + repne scasb + sub cx,128 + neg cx + push ds + pop es + push cs + pop ds + mov si,offset currentdirstr + mov di,[@pointer] + cld + rep movsb + clc + ret +endp getdir + +bufferread db 512 dup (0) +bufferwrite db 512 dup (0) +bufferentry db 512 dup (0) +;fatter db 9*512 dup (0) diff --git a/noyau/font/2_hebrew.fnt b/noyau/font/2_hebrew.fnt new file mode 100644 index 0000000..9e668d6 Binary files /dev/null and b/noyau/font/2_hebrew.fnt differ diff --git a/noyau/font/8x11snsf.fnt b/noyau/font/8x11snsf.fnt new file mode 100644 index 0000000..d409f71 Binary files /dev/null and b/noyau/font/8x11snsf.fnt differ diff --git a/noyau/font/ad&d.fnt b/noyau/font/ad&d.fnt new file mode 100644 index 0000000..c8008de Binary files /dev/null and b/noyau/font/ad&d.fnt differ diff --git a/noyau/font/antique.fnt b/noyau/font/antique.fnt new file mode 100644 index 0000000..fe1aa68 Binary files /dev/null and b/noyau/font/antique.fnt differ diff --git a/noyau/font/applicat.fnt b/noyau/font/applicat.fnt new file mode 100644 index 0000000..b77b2dd Binary files /dev/null and b/noyau/font/applicat.fnt differ diff --git a/noyau/font/backward.fnt b/noyau/font/backward.fnt new file mode 100644 index 0000000..2c971a7 Binary files /dev/null and b/noyau/font/backward.fnt differ diff --git a/noyau/font/bigserif.fnt b/noyau/font/bigserif.fnt new file mode 100644 index 0000000..55a358c Binary files /dev/null and b/noyau/font/bigserif.fnt differ diff --git a/noyau/font/blcksnsf.fnt b/noyau/font/blcksnsf.fnt new file mode 100644 index 0000000..1e4e53e Binary files /dev/null and b/noyau/font/blcksnsf.fnt differ diff --git a/noyau/font/block.fnt b/noyau/font/block.fnt new file mode 100644 index 0000000..0ba23fe Binary files /dev/null and b/noyau/font/block.fnt differ diff --git a/noyau/font/bold.fnt b/noyau/font/bold.fnt new file mode 100644 index 0000000..1ccfa59 Binary files /dev/null and b/noyau/font/bold.fnt differ diff --git a/noyau/font/breeze.fnt b/noyau/font/breeze.fnt new file mode 100644 index 0000000..96ecb0d Binary files /dev/null and b/noyau/font/breeze.fnt differ diff --git a/noyau/font/broadway.fnt b/noyau/font/broadway.fnt new file mode 100644 index 0000000..0c053eb Binary files /dev/null and b/noyau/font/broadway.fnt differ diff --git a/noyau/font/comp.fnt b/noyau/font/comp.fnt new file mode 100644 index 0000000..6862665 Binary files /dev/null and b/noyau/font/comp.fnt differ diff --git a/noyau/font/computer.fnt b/noyau/font/computer.fnt new file mode 100644 index 0000000..a763ae7 Binary files /dev/null and b/noyau/font/computer.fnt differ diff --git a/noyau/font/courier.fnt b/noyau/font/courier.fnt new file mode 100644 index 0000000..dacd3a7 Binary files /dev/null and b/noyau/font/courier.fnt differ diff --git a/noyau/font/cyrillic.fnt b/noyau/font/cyrillic.fnt new file mode 100644 index 0000000..421fc97 Binary files /dev/null and b/noyau/font/cyrillic.fnt differ diff --git a/noyau/font/dblmtx14.fnt b/noyau/font/dblmtx14.fnt new file mode 100644 index 0000000..6a3a99b Binary files /dev/null and b/noyau/font/dblmtx14.fnt differ diff --git a/noyau/font/dblmtx16.fnt b/noyau/font/dblmtx16.fnt new file mode 100644 index 0000000..112e6f9 Binary files /dev/null and b/noyau/font/dblmtx16.fnt differ diff --git a/noyau/font/finnish.fnt b/noyau/font/finnish.fnt new file mode 100644 index 0000000..8da1c96 Binary files /dev/null and b/noyau/font/finnish.fnt differ diff --git a/noyau/font/font1!!!.dat b/noyau/font/font1!!!.dat new file mode 100644 index 0000000..792f46e Binary files /dev/null and b/noyau/font/font1!!!.dat differ diff --git a/noyau/font/font2!!!.dat b/noyau/font/font2!!!.dat new file mode 100644 index 0000000..ea44254 Binary files /dev/null and b/noyau/font/font2!!!.dat differ diff --git a/noyau/font/font3!!!.dat b/noyau/font/font3!!!.dat new file mode 100644 index 0000000..c07df6d Binary files /dev/null and b/noyau/font/font3!!!.dat differ diff --git a/noyau/font/font4!!!.dat b/noyau/font/font4!!!.dat new file mode 100644 index 0000000..29d8980 Binary files /dev/null and b/noyau/font/font4!!!.dat differ diff --git a/noyau/font/frankfrt.fnt b/noyau/font/frankfrt.fnt new file mode 100644 index 0000000..6123f78 Binary files /dev/null and b/noyau/font/frankfrt.fnt differ diff --git a/noyau/font/fresno.fnt b/noyau/font/fresno.fnt new file mode 100644 index 0000000..842ab5c Binary files /dev/null and b/noyau/font/fresno.fnt differ diff --git a/noyau/font/future.fnt b/noyau/font/future.fnt new file mode 100644 index 0000000..1fb73cd Binary files /dev/null and b/noyau/font/future.fnt differ diff --git a/noyau/font/greek.fnt b/noyau/font/greek.fnt new file mode 100644 index 0000000..510a288 Binary files /dev/null and b/noyau/font/greek.fnt differ diff --git a/noyau/font/hebrew.fnt b/noyau/font/hebrew.fnt new file mode 100644 index 0000000..9e668d6 Binary files /dev/null and b/noyau/font/hebrew.fnt differ diff --git a/noyau/font/hollow.fnt b/noyau/font/hollow.fnt new file mode 100644 index 0000000..0a49678 Binary files /dev/null and b/noyau/font/hollow.fnt differ diff --git a/noyau/font/hylas.fnt b/noyau/font/hylas.fnt new file mode 100644 index 0000000..fdfd940 Binary files /dev/null and b/noyau/font/hylas.fnt differ diff --git a/noyau/font/inverted.fnt b/noyau/font/inverted.fnt new file mode 100644 index 0000000..1ff13cd Binary files /dev/null and b/noyau/font/inverted.fnt differ diff --git a/noyau/font/italic.fnt b/noyau/font/italic.fnt new file mode 100644 index 0000000..2ebc096 Binary files /dev/null and b/noyau/font/italic.fnt differ diff --git a/noyau/font/italics.fnt b/noyau/font/italics.fnt new file mode 100644 index 0000000..ddb95d8 Binary files /dev/null and b/noyau/font/italics.fnt differ diff --git a/noyau/font/itt.fnt b/noyau/font/itt.fnt new file mode 100644 index 0000000..2992c0c Binary files /dev/null and b/noyau/font/itt.fnt differ diff --git a/noyau/font/lcd.fnt b/noyau/font/lcd.fnt new file mode 100644 index 0000000..aefe346 Binary files /dev/null and b/noyau/font/lcd.fnt differ diff --git a/noyau/font/mechanix.fnt b/noyau/font/mechanix.fnt new file mode 100644 index 0000000..3207764 Binary files /dev/null and b/noyau/font/mechanix.fnt differ diff --git a/noyau/font/medieval.fnt b/noyau/font/medieval.fnt new file mode 100644 index 0000000..680613a Binary files /dev/null and b/noyau/font/medieval.fnt differ diff --git a/noyau/font/modern-1.fnt b/noyau/font/modern-1.fnt new file mode 100644 index 0000000..79f69dc Binary files /dev/null and b/noyau/font/modern-1.fnt differ diff --git a/noyau/font/norway.fnt b/noyau/font/norway.fnt new file mode 100644 index 0000000..103b729 Binary files /dev/null and b/noyau/font/norway.fnt differ diff --git a/noyau/font/norway2.fnt b/noyau/font/norway2.fnt new file mode 100644 index 0000000..7c17bf6 Binary files /dev/null and b/noyau/font/norway2.fnt differ diff --git a/noyau/font/old8x8.fnt b/noyau/font/old8x8.fnt new file mode 100644 index 0000000..6d72f9c Binary files /dev/null and b/noyau/font/old8x8.fnt differ diff --git a/noyau/font/oldeng.fnt b/noyau/font/oldeng.fnt new file mode 100644 index 0000000..14e12a6 Binary files /dev/null and b/noyau/font/oldeng.fnt differ diff --git a/noyau/font/roman.fnt b/noyau/font/roman.fnt new file mode 100644 index 0000000..f7266c1 Binary files /dev/null and b/noyau/font/roman.fnt differ diff --git a/noyau/font/sanserif.fnt b/noyau/font/sanserif.fnt new file mode 100644 index 0000000..8392323 Binary files /dev/null and b/noyau/font/sanserif.fnt differ diff --git a/noyau/font/script.fnt b/noyau/font/script.fnt new file mode 100644 index 0000000..65b073f Binary files /dev/null and b/noyau/font/script.fnt differ diff --git a/noyau/font/standard.fnt b/noyau/font/standard.fnt new file mode 100644 index 0000000..00e69f4 Binary files /dev/null and b/noyau/font/standard.fnt differ diff --git a/noyau/font/stretch.fnt b/noyau/font/stretch.fnt new file mode 100644 index 0000000..e619be7 Binary files /dev/null and b/noyau/font/stretch.fnt differ diff --git a/noyau/font/thai.fnt b/noyau/font/thai.fnt new file mode 100644 index 0000000..b275bd8 Binary files /dev/null and b/noyau/font/thai.fnt differ diff --git a/noyau/font/thin.fnt b/noyau/font/thin.fnt new file mode 100644 index 0000000..22061e5 Binary files /dev/null and b/noyau/font/thin.fnt differ diff --git a/noyau/heure.asm b/noyau/heure.asm new file mode 100644 index 0000000..918ab3f --- /dev/null +++ b/noyau/heure.asm @@ -0,0 +1,81 @@ +.model tiny +.486 +smart +.code + +org 0h + +start: + +jmp tsr +offsets dd 0 +db 'HOURS' +tsr: + pushf + db 2eh,0ffh,1eh + dw offsets + cli + pusha + push ds es + push cs + push cs + pop ds + pop es + mov ah,22h + mov di,offset infos + int 47h + mov bl,[infos+1] + xor bh,bh + sub bl,8 + mov di,bx + shl di,1 + mov dx,71h + xor eax,eax + mov cx,0B800h + mov es,cx + mov cl,4 + mov bp,8 +show: + dec dx + mov al,cl + out dx,al + inc dx + in al,dx + call showbcd + cmp cl,0 + je finic + mov byte ptr es:[di],':' + add di,2 + sub cl,2 + jmp show +finic: + pop es ds + popa + sti + iret + + +;==============================Affiche le nombre nb hexa en EDX============== +Showbcd: + push ax bx cx edx + mov edx,eax + mov cx,bp + sub cx,32 + neg cx + shl edx,cl + mov ax,bp + shr ax,2 +bcdaize: + rol edx,4 + mov bx,dx + and bx,0fh + add bl,'0' + mov es:[di],bl + add di,2 + dec al + jnz bcdaize + pop edx cx bx ax + ret +infos db 40 dup (0) + +end start diff --git a/noyau/horloge.asm b/noyau/horloge.asm new file mode 100644 index 0000000..41c7f0d --- /dev/null +++ b/noyau/horloge.asm @@ -0,0 +1,32 @@ +.model tiny +.486 +smart +.code + +org 0h + +start: + +jmp tsr +offsets dd 0 +db 'TIMER' +tsr: + pushf + db 2eh,0ffh,1eh + dw offsets + cli + push ax bx es + mov bx,cs:compteur + inc bx + and bx,11b + mov cs:compteur,bx + mov bx,cs:[offset fig+bx] + mov ax,0B800h + mov es,ax + mov es:[0],bl + pop es bx ax + sti + iret +compteur dw 0 +fig db 'Ä\³/' +end start diff --git a/noyau/manette.asm b/noyau/manette.asm new file mode 100644 index 0000000..d291dc2 --- /dev/null +++ b/noyau/manette.asm @@ -0,0 +1,298 @@ +.model tiny +.486 +smart +.code +org 0h +start: +jmp tsr +drv db 'JOYSTICK',0 +Tsr: +cli +cmp ax,1234h +jne nomore +mov ax,4321h +jmp itsok +nomore: +push bx +cmp byte ptr cs:isact,1 +je nottest +mov cs:isact,1 +jmp react +mov bl,ah +xor bh,bh +shl bx,1 +mov bx,cs:[bx].tables +mov cs:current,bx +pop bx +call cs:current +itsok: +jnc noerror +push bp +mov bp,sp +or byte ptr [bp+6],1b +pop bp +mov ax,cs +shl eax,16 +mov ax,cs:current +jmp endofint +noerror: +push bp +mov bp,sp +and byte ptr [bp+6],0FEh +pop bp +endofint: +mov cs:isact,0 +sti +iret +nottest: +pop bx +jmp endofint +current dw 0 +tables dw 0;detectjoystick + ;dw getjoystick + ;dw getjoystickscreen + ;dw configjoystick +isact db 0 + +;envoie en bx,cx les coordonn‚es et en dl les boutons +getjoystick: +push ax cx +mov bx,cs:rx +mov cx,cs:ry +mov al,cs:button +not al +mov cl,4 +shr al,cl +mov dl,al +pop cx ax +ret + +;envoie en di les coordonn‚es ecran et en dl les boutons +getjoystickscreen: +push ax cx +mov di,cs:xy +mov al,cs:button +not al +mov cl,4 +shr al,cl +mov dl,al +pop cx ax +ret +db 'button' +Button db 0 +db 'rx' +rx dw 0 +db 'ry' +ry dw 0 +db 'vx' +VX db 0 +db 'vy' +VY db 0 +db 'x' +X dw 7FFFh +db 'y' +Y dw 7FFFh +speed db 6 +spherex db 0 +spherey db 0 +db 'count' +count db 0 +db 'error' +error db 0 +xy dw 0 +old db 0 + +calibrate db 0 +db 'ticks' +ticks dw 0 +db 'state' +state db 0 +db 'connard' +connard db 1 +connard2 db 1 +;Gestionnaire de joystick +react: + push ax bx cx dx si di bp ds es + push cs + pop ds + mov dx,201h + cmp error, 1 + je gest1 + cmp count,1 + je gest1 + cmp count,2 + je gest2 +gest1: + mov error,0 + mov count,2 + call getticks + mov ticks,ax + out dx,al + in al,dx + and al,00000011b + mov state,al + jmp endgest +gest2: +not connard + call getticks + sub ax,ticks + cmp ax,1FF0h + jb nofinish + mov error,1 + jmp endgest +nofinish: + mov bx,ax + in al,dx + and al,00000011b + cmp state,al + je endgest + xchg state,al + xor al,state + mov cl,4 + or bx,bx + js noadj + shr bx,cl +noadj: + test al,1 + je isy + mov VX,bl + jmp wasx +isy: + test al,2 + je endgest + mov VY,bl +wasx: +mov connard2,0fh + mov count,1 +endgest: + in al,dx + not al + mov cl,4 + shr al,cl + mov button,al + push cs + pop es + mov di,offset infos + mov ah,34 + int 47h + mov cl,speed + movsx bx,VY + shl bx,cl + cmp spherey,0 + jne nolimity + xor ah,ah + mov al,[di] + cmp byte ptr [di+7],4 + jbe text4 + shl ax,3 +text4: + dec ax + cmp bx,0 + jg decy + cmp ry,ax + jae noaddy + jmp nolimity +decy: + cmp ry,0 + je noaddy +nolimity: + sub y,bx +noaddy: + movsx bx,VX + shl bx,cl + cmp spherex,0 + jne nolimitx + xor ah,ah + mov al,[di+1] + cmp byte ptr [di+7],4 + jbe text5 + shl ax,3 +text5: + dec ax + cmp bx,0 + jl decx + cmp rx,ax + jae noaddx + jmp nolimitx +decx: + cmp rx,0 + je noaddx +nolimitx: + add x,bx +noaddx: + mov ax,x + mov bx,0FFFFh + xor ch,ch + mov cl,[di+1] + cmp byte ptr [di+7],4 + jbe text1 + shl cx,3 +text1: + mul cx + div bx + mov rx,ax + mov ax,y + xor ch,ch + mov cl,[di] + cmp byte ptr [di+7],4 + jbe text2 + shl cx,3 +text2: + mul cx + div bx + mov ry,ax + xor ch,ch + mov cl,[di+1] + cmp byte ptr [di+7],4 + jbe text3 + shl cx,3 +text3: + mul cx + add ax,rx + cmp byte ptr [di+7],4 + mov di,ax + jbe textpoint + mov ax,0A000h + mov es,ax + jmp graphpoint +textpoint: + mov ax,0B800h + mov es,ax + shl di,1 + inc di +graphpoint: + mov bx,xy + cmp byte ptr es:[bx],070h + jne waschanged + mov al,old + mov byte ptr es:[bx],al +waschanged: + mov xy,di + mov al,es:[di] + mov old,al + mov byte ptr es:[di],070h + mov al, 20h + out 0a0h, al + out 20h, al +errormouse: + pop es ds bp di si dx cx bx ax + mov cs:isact,0 + pop bx + iret + infos db 40 dup (0) + + +getticks: +mov al,0 +out 43h,al +jmp wait1 +wait1: +in al,40h +mov ah,al +jmp wait2 +wait2: +in al,40h +xchg ah,al +ret + +end start diff --git a/noyau/mcb.asm b/noyau/mcb.asm new file mode 100644 index 0000000..7facccc --- /dev/null +++ b/noyau/mcb.asm @@ -0,0 +1,749 @@ + +;Affiche le nombre hexa dans %0[dword] +PROC biosprinth FAR + ARG @num:dword + USES ax,bx,cx,edx,si,di + mov edx,[@num] + mov ah,09h + mov di,8 +@@hexaize: + rol edx,4 + mov si,dx + and si,1111b + mov al,[cs:si+offset @@tab] + mov cx,1 + cmp al,32 + jb @@control + mov bx,7 + mov ah,09h + int 10h +@@control: + mov ah,0Eh + int 10h + dec di + jnz @@hexaize + ret +@@tab db '0123456789ABCDEF' +endp biosprinth + +;Affiche le texte ASCIIZ pointé par %0 +PROC biosprint FAR + ARG @pointer:word + USES ax,bx,cx,si + mov si,[@pointer] + mov cx,1 + mov bx,7 +@@again: + lodsb + or al,al + jz @@fin + cmp al,32 + jb @@control + mov ah,09h + int 10h +@@control: + mov ah,0Eh + int 10h + jmp @@again +@@fin: + ret +endp biosprint + +PROC enablea20 FAR + USES ax + mov al,0d1h + out 64h,al + call a20wait + mov al,0dfh + out 60h,al + call a20wait + ;mov al,0ffh + ;out 64h,al + ;call a20wait + ret +endp enablea20 + +PROC disablea20 FAR + USES ax + mov al,0d1h + out 64h,al + call a20wait + mov al,0DDh + out 60h,al + call a20wait + ;mov al,0ffh + ;out 64h,al + ;call a20wait + ret +endp disablea20 + +a20wait: + in al,64h + jmp @@suite +@@suite: + and al,2 + jnz a20wait + ret +;par le system control port A +;in al,92h +;or al,2 +;out 92h,al + +;par le system control port A +;in al,92h +;and al,not 2 +;out 92h,al + +PROC flatmode FAR + USES eax,bx,ds + push cs + pop ds + ; first, calculate the linear address of GDT + xor eax,eax + mov ax,ds + shl eax,4 + add [dword ptr offset @@gdt+2],eax ; store as GDT linear base addr + ; now load the GDT into the GDTR + lgdt [fword ptr offset @@gdt] ; load GDT base + mov bx,1 * size descriptor ; point to first descriptor + cli ; turn off interrupts + mov eax,cr0 ; prepare to enter protected mode + or al,1 ; flip the PE bit + mov cr0,eax ; we're now in protected mode + jmp @@suite +@@suite: + mov fs,bx ; load the FS segment register + and al,0FEh ; clear the PE bit again + mov cr0,eax ; back to real mode + jmp @@suite2 +@@suite2: + sti ; resume handling interrupts + ret ; + +@@gdt descriptor ; the GDT itself + descriptor <0ffffh, 0, 0, 091h, 0cfh, 0> ; 4G data segment +@@gdtend: +endp flatmode + +;Attend l'appuie sur une touche +PROC bioswaitkey FAR + USES ax + xor ax,ax + int 16h + ret +endp bioswaitkey + +firstmb dw 0 + + +;Charge les sections du block %0 +PROC mbloadsection FAR + ARG @blocks:word + USES ax,bx,cx,si,di,ds,es + LOCAL @@toresov:word:60 + mov ax,[@blocks] + mov es,ax + mov ds,ax + cmp [word ptr 0],"EC" + jne @@notace + lea si,[@@toresov] + mov [word ptr ss:si],0FFFFh + mov bx,[ds:exe.sections] + cmp bx,0 + je @@finishloading +@@loading: + cmp [dword ptr bx],0 + je @@finishloading + mov ax,bx + add ax,4 +pushad +call biosprint,ax +popad + call mbcreate,ax,[word ptr bx+2] + jc @@error + inc si + inc si + mov [ss:si],ax + push si + mov si,[bx] + xor di,di + mov es,ax + mov cx,[bx+2] + cld + rep movsb + pop si + add bx,4 +@@gonext: + inc bx + cmp [byte ptr bx],0 + jne @@gonext + inc bx + jmp @@loading +@@finishloading: + cmp [word ptr ss:si],0FFFFh + je @@finishdepands + call mbloadfuncs,[word ptr ss:si] + jc @@depandserror + dec si + dec si + jmp @@finishloading +@@finishdepands: + ret +@@notace: + stc + ret +@@error: + stc + ret +@@depandserror: + stc + ret +endp mbloadsection + + +;Initialise les blocs de mémoire en prenant memorystart pour segment de base +PROC mbinit FAR + USES ax,cx,si,di,ds,es + cmp [cs:firstmb],0 + jne @@alreadyok + push cs + pop ds + mov [cs:firstmb],memorystart + mov ax,memorystart-2 + mov es,ax + mov si,offset afree + xor di,di + mov cx,size mb + rep movsb + clc + ret +@@alreadyok: + stc + ret +endp mbinit + +afree mb <"HN",0,0,0,0A000h-memorystart,"Libre"> + db 0 + +;Creér un bloc de nom %0 de taille %1 (octets) -> n°segment dans AX +PROC mbcreate FAR + ARG @blocks:word,@size:word + USES bx,cx,dx,si,di,ds,es + push gs + mov ax,[ss:bp+4] + mov dx,ax + dec dx + dec dx + mov gs,dx + cmp [word ptr gs:0x0],'NH' + je @@oktoset + mov ax,memorystart +@@oktoset: + mov gs,ax + mov cx,[@size] + shr cx,4 + inc cx + mov bx,[cs:firstmb] + dec bx + dec bx + mov dl,true +@@searchfree: + cmp dl,false + je @@notenougtmem + mov es,bx + cmp [word ptr es:mb.check],"NH" + jne @@memoryerror + cmp [es:mb.isnotlast],true + sete dl + cmp [es:mb.reference],free + jne @@notsogood + mov ax,[es:mb.sizes] + cmp cx,ax + ja @@notsogood + mov [word ptr es:mb.check],"NH" + mov [es:mb.isnotlast],true + mov [es:mb.reference],gs + mov [es:mb.isresident],false + lea di,[es:mb.names] + push cx + mov cx,24/4 + mov si,[@blocks] + cld + rep movsd + pop cx + inc bx + inc bx + sub ax,cx + cmp ax,0 + je @@nofree + dec ax + dec ax + mov [es:mb.sizes],cx + add cx,bx + mov es,cx + mov si,offset afree + xor di,di + mov cx,size mb + push cs + pop ds + cld + rep movsb + mov [es:mb.isnotlast],dl + mov [es:mb.sizes],ax +@@nofree: + mov ax,bx + pop gs + clc + ret +@@notsogood: + inc bx + inc bx + add bx,[es:mb.sizes] + jmp @@searchfree +@@memoryerror: + pop gs + stc + ret +@@notenougtmem: + pop gs + stc + ret +endp mbcreate + +;Libère le bloc de mémoire %0 et ses sous blocs +PROC mbfree FAR + ARG @blocks:word + USES ax,bx,cx,si,di,ds,es + mov bx,[@blocks] + mov ax,bx + dec bx + dec bx + mov es,bx + cmp [word ptr es:mb.check],"NH" + jne @@memoryerror + cmp [es:mb.reference],free + je @@wasfree + cmp [es:mb.isresident],true + je @@wasresident + mov [es:mb.reference],free + push cs + pop ds + mov si,offset @@isfree + lea di,[es:mb.names] + mov cx,6 + cld + rep movsb + mov bx,[cs:firstmb] + dec bx + dec bx +@@searchtofree: + mov es,bx + cmp [word ptr es:mb.check],"NH" + jne @@memoryerror + inc bx + inc bx + add bx,[es:mb.sizes] + cmp [es:mb.sizes],0 + je @@nottofree + cmp ax,[es:mb.reference] + jne @@nottofree + mov [es:mb.isresident],false + mov [es:mb.reference],free + mov si,offset @@isfree + lea di,[es:mb.names] + mov cx,6 + cld + rep movsb +@@nottofree: + cmp [es:mb.isnotlast],true + je @@searchtofree + call mbclean + ret +@@memoryerror: + stc + ret +@@wasfree: + stc + ret +@@wasresident: + stc + ret + +@@isfree db "libre",0 +endp mbfree + +;Mise a nivo de la mémoire (jonction de blocs libre) +PROC mbclean FAR + USES ax,bx,dx,es,gs + mov bx,[cs:firstmb] + dec bx + dec bx + xor ax,ax + xor dx,dx +@@searchfree: + mov gs,bx + cmp [word ptr gs:mb.check],"NH" + jne @@memoryerror + inc bx + inc bx + add bx,[gs:mb.sizes] + cmp [word ptr gs:mb.sizes],0 + je @@notenougtmem + cmp [gs:mb.reference],free + jne @@notfree + cmp ax,0 + je @@notmeetfree + add dx,[gs:mb.sizes] + mov [word ptr gs:mb.check],0 + mov [dword ptr gs:mb.names],0 + inc dx + inc dx + jmp @@nottrigered +@@notmeetfree: + xor dx,dx + mov ax,gs + jmp @@nottrigered +@@notfree: + cmp ax,0 + je @@nottrigered + mov es,ax + add [es:mb.sizes],dx + xor ax,ax +@@nottrigered: + cmp [gs:mb.isnotlast],true + je @@searchfree + cmp ax,0 + je @@reallyfinish + mov es,ax + add [es:mb.sizes],dx + mov [es:mb.isnotlast],false +@@reallyfinish: + clc + ret +@@notenougtmem: + stc + ret +@@memoryerror: + stc + ret +endp mbclean + +;Rend le segment %0 résident +PROC mbresident FAR + ARG @blocks:word + USES bx,es + mov bx,[@blocks] + dec bx + dec bx + mov es,bx + cmp [word ptr es:mb.check],"NH" + jne @@memoryerror + mov [es:mb.isresident],true + ret +@@memoryerror: + stc + ret +endp mbresident + +;Rend le segment %0 non résident +PROC mbnonresident FAR + ARG @blocks:word + USES bx,es + mov bx,[@blocks] + dec bx + dec bx + mov es,bx + cmp [word ptr es:mb.check],"NH" + jne @@memoryerror + mov [es:mb.isresident],false + ret +@@memoryerror: + stc + ret +endp mbnonresident + + +;Change le proprietaire de %0 a %1 +PROC mbchown FAR + ARG @blocks:word,@owner:word + USES bx,dx,es + mov bx,[@blocks] + dec bx + dec bx + mov es,bx + cmp [word ptr es:mb.check],"NH" + jne @@memoryerror + cmp [es:mb.reference],free + je @@wasfree + mov dx,[@owner] + mov [es:mb.reference],dx + ret +@@memoryerror: + stc + ret +@@wasfree: + stc + ret +endp mbchown + +;Alloue un bloc /data de CX caractere pour le process appelant -> ax +PROC mballoc FAR + ARG @size:word + USES si,ds + push cs + pop ds + call mbcreate,offset @@data,[@size] + call mbchown,ax,[word ptr ss:bp+4] + ret + +@@data db '/data',0 +endp mballoc + +;Renvoie en AX le MB n° %0 carry quand terminé +PROC mbget FAR + ARG @num:word + USES bx,dx,es + mov bx,[cs:firstmb] + dec bx + dec bx + xor dx,dx +@@searchfree: + mov es,bx + cmp [word ptr es:mb.check],"NH" + jne @@memoryerror + inc bx + inc bx + add bx,[es:mb.sizes] + cmp [es:mb.sizes],0 + je @@memoryerror + cmp dx,[@num] + je @@foundmcb + ja @@notfound + inc dx + cmp [es:mb.isnotlast],true + je @@searchfree +@@memoryerror: + stc + ret +@@foundmcb: + mov ax,es + inc ax + inc ax + clc + ret +@@notfound: + stc + ret +endp mbget + +;Renvoie en AX le MCB qui correspond a ds:%0 +PROC mbfind FAR + ARG @blocks:word + USES bx,si,di,es + mov bx,[cs:firstmb] + dec bx + dec bx + mov si,[@blocks] +@@search: + mov es,bx + lea di,[es:mb.names] + cmp [word ptr es:mb.check],"NH" + jne @@memoryerror + inc bx + inc bx + add bx,[es:mb.sizes] + cmp [es:mb.sizes],0 + je @@memoryerror + push si di +@@cmpnames: + mov al,[es:di] + cmp al,[ds:si] + jne @@ok + cmp al,0 + je @@ok + inc si + inc di + jmp @@cmpnames +@@ok: + pop di si + je @@foundmcb + cmp [es:mb.isnotlast],true + je @@search +@@notfound: + stc + ret +@@memoryerror: + stc + ret +@@foundmcb: + mov ax,es + inc ax + inc ax + clc + ret +endp mbfind + + +;Renvoie en AX le sous mcb qui correspond a %0 et qui appartien a %1 +PROC mbfindsb FAR + ARG @blocks:word,@owner:word + USES bx,dx,si,di,es + mov bx,[cs:firstmb] + dec bx + dec bx + mov si,[@blocks] + lea di,[es:mb.names] + mov dx,[@owner] +@@search: + mov es,bx + cmp [word ptr es:mb.check],"NH" + jne @@memoryerror + inc bx + inc bx + add bx,[es:mb.sizes] + cmp [es:mb.sizes],0 + je @@memoryerror + push si di +@@cmpnames: + mov al,[es:di] + cmp al,[ds:si] + jne @@ok + cmp al,0 + je @@ok + inc si + inc di + jmp @@cmpnames +@@ok: + pop di si + jne @@notfoundmcb + cmp [es:mb.reference],dx + je @@foundmcb +@@notfoundmcb: + cmp [es:mb.isnotlast],true + je @@search +@@notfound: + stc + ret +@@foundmcb: + mov ax,es + inc ax + inc ax + clc + ret +@@memoryerror: + stc + ret +endp mbfindsb + +;Resouds les dépendances du bloc de mémoire %0 +PROC mbloadfuncs FAR + ARG @blocks:word + USES ax,bx,cx,dx,si,ds + mov ds,[@blocks] + cmp [word ptr 0],"EC" + jne @@notace + mov si,[ds:exe.imports] + cmp si,0 + je @@endofloading +@@loadfuncs: + cmp [word ptr si],0 + je @@endofloading + call mbsearchfunc,si + jnc @@toendoftext + mov bx,si +;pushad +;call biosprint,si +;popad +@@findend: + inc bx + cmp [byte ptr bx], ':' + jne @@findend + mov [byte ptr bx],0 + call [cs:projfile],si + jc @@erroronload + mov [byte ptr bx],':' +;pushad +;call biosprint,si +;popad + call mbsearchfunc,si + jc @@libnotexist +@@toendoftext: + mov cl,[si] + cmp cl,0 + je @@oktonext + inc si + jmp @@toendoftext +@@oktonext: + inc si + mov [si],ax + mov [si+2],dx + add si,4 + jmp @@loadfuncs +@@endofloading: + clc + ret +@@notace: + stc + ret +@@libnotexist: + stc + ret +@@erroronload: + stc + ret +endp mbloadfuncs + + +;Recherche une fonction pointé par DS:%0 en mémoire et renvoie son adresse en DX:AX +PROC mbsearchfunc FAR + ARG @func:word + USES bx,si,di,es + mov bx,[@func] + mov si,bx +@@findend: + inc bx + cmp [byte ptr bx], ':' + jne @@findend + mov [byte ptr bx],0 + call mbfind,si + mov [byte ptr bx],':' + jc @@notfoundattallthesb + mov es,ax + cmp [word ptr es:exe.checks],"EC" + jne @@notfoundattallthesb + mov di,[es:exe.exports] + inc bx + inc bx +@@functions: + cmp [word ptr es:di],0 + je @@notfoundattallthesb + mov si,bx +@@cmpnamesfunc: + mov al,[es:di] + cmp al,[ds:si] + jne @@notfoundthesb + cmp al,0 + je @@seemsok + inc si + inc di + jmp @@cmpnamesfunc +@@notfoundthesb: + mov al,[es:di] + cmp al,0 + je @@oktonext + inc di + jmp @@notfoundthesb +@@oktonext: + inc di + inc di + inc di + jmp @@functions +@@seemsok: + mov dx,es + mov ax,[es:di+1] + clc + ret +@@notfoundattallthesb: + stc + ret +endp mbsearchfunc diff --git a/noyau/port.asm b/noyau/port.asm new file mode 100644 index 0000000..c4a588d --- /dev/null +++ b/noyau/port.asm @@ -0,0 +1,699 @@ +.model tiny +.486 +smart +.code +org 0h +start: +jmp tsr +drv db 'LPT ',0 +Tsr: +cli +cmp ax,1234h +jne nomore +mov ax,4321h +jmp itsok +nomore: +push bx ax +mov ah,4 +mov bh,1 +int 50h +mov bl,al +pop ax +cmp byte ptr cs:isact,1 +je nottest +mov cs:isact,1 +cmp bl,80h +jae react +mov bl,ah +xor bh,bh +shl bx,1 +mov bx,cs:[bx].tables +mov cs:current,bx +pop bx +call cs:current +itsok: +jnc noerror +push bp +mov bp,sp +or byte ptr [bp+6],1b +pop bp +mov ax,cs +shl eax,16 +mov ax,cs:current +jmp endofint +noerror: +push bp +mov bp,sp +and byte ptr [bp+6],0FEh +pop bp +endofint: +mov cs:isact,0 +sti +iret +nottest: +pop bx +jmp endofint +current dw 0 +tables dw getlptin + dw getlptout + dw getlptinout + dw setlptin + dw setlptout + dw setlptinout + dw getlpt + dw getfirstlpt + dw setemettor + dw setreceptor + dw settimeout + dw gettimeout + dw receivelpt + dw sendlpt + dw receivelptblock + dw sendlptblock + dw receivecommand + dw sendcommand + +react: +push ds es +mov cs:isact,1 +pushad +push cs +pop ds +push cs +pop es +cmp byte ptr never,1 +je oknever +mov bl,[drv+3] +sub bl,'0' +xor bh,bh +call getlpt +dec bl +shl bl,1 +mov al,7 +sub al,bl +mov ah,40 +mov di,offset video +int 47h +push ax +mov ah,01h +int 50h +mov ah,21 +mov cl,4 +int 47h +sti +mov al,0111b +call setlptout +call setreceptor +call initlpt +jc errorie +mov cx,0 +mov ah,20 +mov bx,1012h +mov si,offset initok +int 47h +cmp byte ptr always,1 +je yes +mov ah,20 +mov bx,1010h +mov si,offset mdd +int 47h +mov ah,13 +mov si,offset drv +int 47h +mov ah,6 +int 47h +mov ah,20 +mov bx,1011h +mov si,offset msg +int 47h +waitkey: +mov ax,0 +int 16h +cmp al,'n' +je no +cmp al,'N' +je no +cmp al,'Y' +je yes +cmp al,'y' +je yes +cmp al,'e' +je nev +cmp al,'E' +je nev +cmp al,'a' +je alw +cmp al,'A' +je alw +jmp waitkey +yes: +call receivecommand +jc errortimeout +no: +mov al,0111b +call setlptout +cli +mov ah,41 +mov si,offset video +int 47h +pop ax +mov ah,00h +int 50h +mov ah,09h +int 50h +oknever: +popad +pop es ds +mov cs:isact,0 +pop bx +jmp endofint +errorie: +mov si,offset inits +jmp show +errortimeout: +mov si,offset timeouts +show: +mov ah,20 +mov bx,1012h +int 47h +mov ax,0 +int 16h +jmp no +nev: +mov byte ptr never,1 +jmp no +alw: +mov byte ptr always,1 +jmp yes +initok db 'Initialisation is realised !',0 +inits db 'Error on initialisation',0 +timeouts db 'Connection lost or timeout complete !!',0 +mdd db 'Connection demand on ',0 +msg db 'Accept connection ? (Y)es (N)o n(E)ver (A)lways',0 +isact db 0 +always db 0 +never db 0 + +;envois une commande al +sendcommand: +push ax bx cx di +mov bl,al +xor bh,bh +shl bx,1 +add bx,offset cmde +call cs:[bx] +pop di cx bx ax +ret +cmde dw nothing + dw getram + +;recupŠre la ram en ds:si de cx distant caractŠres en es:di local +getram: +push ax bx cx ds +mov bx,offset command +mov cs:[bx+2],ds +mov cs:[bx],si +mov cs:[bx+4],cx +push cs +pop ds +mov si,bx +mov cx,6 +call sendlptblock +jc endofget +call receivelptblock +endofget: +pop ds cx bx ax +ret + +;Re‡ois une commande et l'execute +Receivecommand: +push ax bx cx di ds es +push cs +pop es +push cs +pop ds +mov di,offset command +call receivelptblock +jc endofno +mov bl,al +xor bh,bh +shl bx,1 +add bx,offset cmd +call cs:[bx] +clc +endofno: +pop es ds di cx bx ax +ret + +command db 25 dup (0) +cmd dw nothings + dw sendram + dw receiveram + dw sendreg + dw receivereg + dw sendport + dw receiveport + dw letexecute +nothings: +ret + +letexecute: +push ds es fs gs +pushad +push cs +push offset suite +mov ax,es:[di+2] +mov ds,ax +mov es,ax +mov fs,ax +mov gs,ax +push ax +mov ax,es:[di] +push ax +DB 0CBh +suite: +popad +pop gs fs es ds +ret + +Sendram: +push ax cx si ds +mov si,es:[di] +mov ax,es:[di+2] +mov ds,ax +mov cx,es:[di+4] +call sendlptblock +pop ds si cx ax +ret + +receiveram: +sendreg: +receivereg: + +sendport: +push ax cx dx si +mov dx,es:[di] +in ax,dx +mov cx,2 +mov si,offset tempblock +mov ds:[si],ax +call sendlptblock +pop si dx cx ax +ret + +receiveport: +push ax dx +mov dx,es:[di] +mov ax,es:[di+2] +out dx,ax +pop dx ax +ret + +tempblock db 25 dup (0) + +;---------Segment Adress----------- +Bios equ 040h +;---------Offset Adress------------ +Lptadr equ 008h +Timer equ 06Ch +;---------Constant----------------- +onesec equ 18 +tensec equ 182 +Ack equ 00 +Nack equ 0FFh +maxtry equ 10 + +Initlpt: +push ax ecx +call StartTimer +cmp cs:emettor,0 +je receptinit +mov al,10000b +call SetLptOut +waitinit1: +call EndTimer +cmp cx,cs:timeout +ja errorinit +call getlptIn +cmp al,00000b +jnz waitinit1 +jmp endinit +receptinit: +call EndTimer +cmp cx,cs:timeout +ja errorinit +call getlptIn +cmp al,00000b +jnz receptinit +mov al,10000b +call SetLptOut +endinit: +clc +pop ecx ax +ret +errorinit: +stc +pop ecx ax +ret + + +;-Envoie DL (dh) JNE si problŠme JNC error timeout +Sendlpt: +push ax bx ecx +call StartTimer +mov dh,dl +mov al,dl +and al,0Fh +call SetLptOut +waitSend: +call EndTimer +cmp cx,cs:timeout +ja errorsend +call getlptIn +bt ax,4 +jnc waitsend +and al,0Fh +mov bl,al +call StartTimer ;///// +mov al,dh +shr al,4 +or al,10000b +call SetLptOut +waitSend2: +call EndTimer +cmp cx,cs:timeout +ja errorsend +call getlptIn +bt ax,4 +jc waitsend2 +and al,0Fh +shl al,4 +add bl,al +cmp dl,bl +pop ecx bx ax +clc +ret +errorsend: +pop ecx bx ax +stc +ret + + +;-Re‡ois DL (dh) +Receivelpt: +push ax bx ecx +call StartTimer +waitreceive: +call EndTimer +cmp cx,cs:timeout +ja errorreceive +call getlptIn +bt ax,4 +jnc waitreceive +and al,0Fh +mov dl,al +call SetLptOut +call StartTimer ;///// +waitreceive2: +call EndTimer +cmp cx,cs:timeout +ja errorreceive +call getlptIn +bt ax,4 +jc waitreceive2 +and al,0Fh +mov dh,al +shl dh,4 +add dl,dh +or al,10000b +call SetlptOut +clc +pop ecx bx ax +ret +errorreceive: +stc +pop ecx bx ax +ret + +;-AX +SetTimeout: +mov cs:Timeout,dx +ret + +timeout dw tensec + +getTimeout: +mov dx,cs:Timeout +ret + +SetEmettor: +mov cs:Emettor,1 +ret + +Emettor db 0 + +SetReceptor: +mov cs:Emettor,0 +ret + +;->bx Nøport->Adresse dx +GetLpt: +push ax bx ds +mov ax,bios +mov ds,ax +dec bx +shl bx,1 +mov dx,ds:[Lptadr+bx] +mov cs:lpt,dx +pop ds bx ax +ret +lpt dw 0 + +;->bx Nøport->Adresse dx +GetFirstLpt: +push ax ds +mov ax,bios +mov ds,ax +xor bx,bx +findlpt: +mov dx,ds:[Lptadr+bx] +cmp dx,0 +jne oklpt +add bx,2 +cmp bx,4 +jbe findlpt +oklpt: +mov cs:lpt,dx +pop ds ax +ret + +;-> +StartTimer: +push ax ecx ds +mov ax,Bios +mov ds,ax +mov ecx,ds:[timer] +mov cs:times,ecx +pop ds ecx ax +ret +times dd 0 + +;->Ecx time elapsed +EndTimer: +push ax ds +mov ax,Bios +mov ds,ax +mov ecx,ds:[timer] +sub ecx,cs:times +pop ds ax +ret + +;-> +GetLptOut: +push dx +mov dx,cs:lpt +in al,dx +pop dx +ret + +GetLptIn: +push dx +mov dx,cs:lpt +inc dx +in al,dx +shr al,3 +pop dx +ret + +GetLptInOut: +push dx +mov dx,cs:lpt +add dx,2 +in al,dx +and al,11111b +pop dx +ret + +SetLptOut: +push dx +mov dx,cs:lpt +out dx,al +pop dx +ret + +SetLptIn: +push dx +mov dx,cs:lpt +inc dx +out dx,al +pop dx +ret + +SetLptInOut: +push dx +mov dx,cs:lpt +add dx,2 +out dx,al +pop dx +ret + +;R‚alise un checksum 8 bits sur donn‚es DS:SI, nb CX r‚sultat dans dl +Checksum8: +push cx si +check: +add dl,[si] +inc si +dec cx +jnz check +pop si cx +ret + +;DS:SI pointeur sur donn‚es, CX nombres de donn‚es, AL token +SendLptBlock: +push ax bx cx edx si edi bp +mov dx,cx +shl edx,16 +mov dh,al +call checksum8 +mov edi,edx +xor dh,dh +mov bp,dx +mov ah,maxtry +retry: +mov bl,4 +xor al,al +header: +mov dx,di +call sendlpt +setne al +jc outt +rol edi,8 +dec bl +jnz header +cmp al,0 +jne notgood +mov dl,ACK +jmp allsend +notgood: +mov dl,NACK +allsend: +call sendlpt +setne al +jc outt +cmp al,0 +je okheader +dec ah +jnz retry +jmp outt +okheader: +cmp cx,0 +je endoftrans +mov di,maxtry +retry2: +mov bx,cx +xor ax,ax +body: +mov dl,[si+bx-1] +add ah,dl +call sendlpt +setne al +jc outt +dec bx +jnz body +cmp al,0 +jne notgood2 +mov dl,ACK +jmp allisend +notgood2: +mov dl,NACK +allisend: +call sendlpt +setne al +jc outt +cmp al,0 +je endoftrans +dec di +jnz retry2 +outt: +stc +endoftrans: +mov al,ah +xor ah,ah +cmp bp,ax +pop bp edi si edx cx bx ax +ret + +;Receptionne en es:di les donn‚es au nombres de CX token AL (AH) (ECX) +receiveLptBlock: +push bx dx si bp +mov ah,maxtry +retrye: +mov bl,4 +headere: +call receivelpt +jc outte +mov cl,dl +rol ecx,8 +dec bl +jnz headere +call receivelpt +jc outte +cmp dl,ACK +je okheadere +dec ah +jnz retrye +jmp outte +okheadere: +mov al,ch +xor ch,ch +mov bp,cx +rol ecx,16 +cmp cx,0 +je endoftranse +mov si,maxtry +retrye2: +mov bx,cx +xor ah,ah +bodye: +call receivelpt +jc outte +mov es:[di+bx-1],dl +add ah,dl +dec bx +jnz bodye +call receivelpt +jc outte +cmp dl,ACK +je endoftranse +dec si +jnz retrye2 +outte: +stc +endoftranse: +mov bl,ah +xor bh,bh +cmp bp,bx +pop bp si dx bx +ret +video db 0 +end start diff --git a/noyau/souris.asm b/noyau/souris.asm new file mode 100644 index 0000000..ab8b210 --- /dev/null +++ b/noyau/souris.asm @@ -0,0 +1,327 @@ +.model tiny +.486 +smart +.code +org 0h +start: +jmp tsr +drv db 'MOUSE',0 +Tsr: +cli +cmp ax,1234h +jne nomore +mov ax,4321h +jmp itsok +nomore: +push bx ax +mov ah,4 +mov bh,0 +int 50h +mov bl,al +pop ax +cmp byte ptr cs:isact,1 +je nottest +mov cs:isact,1 +and bl,10000b +cmp bl,16 +jae react +mov bl,ah +xor bh,bh +shl bx,1 +mov bx,cs:[bx].tables +mov cs:current,bx +pop bx +call cs:current +itsok: +jnc noerror +push bp +mov bp,sp +or byte ptr [bp+6],1b +pop bp +mov ax,cs +shl eax,16 +mov ax,cs:current +jmp endofint +noerror: +push bp +mov bp,sp +and byte ptr [bp+6],0FEh +pop bp +endofint: +mov cs:isact,0 +sti +iret +nottest: +pop bx +jmp endofint +current dw 0 +tables dw cmdmouse + dw cmdmouse2 + dw detectmouse + dw getmouse + dw getmousescreen + dw configmouse + +isact db 0 + +;Envoie une commande AL … la souris via controleur clavier +cmdmouse: + push ax +videbuff1: + in al, 64h + and al, 10b + jne videbuff1 + mov al, 00d4h + out 64h, al +videbuff2: + in al, 64h + and al, 10b + jne videbuff2 + pop ax + out 60h, al + in al, 60h + ret + +;Envoie une commande2 AL … la souris via controleur clavier carry=nomouse +cmdmouse2: + push ax +videbuff21: + in al, 64h + and al, 10b + jne videbuff21 + mov al, 0060h + out 64h, al +videbuff22: + in al, 64h + and al, 10b + jne videbuff22 + pop ax + out 60h, al + in al, 60h + ret + +Detectmouse: + push ax cx + mov al, 0a8h ;AUX enable + out 64h, al + mov al, 0f3h ;Set sample + call cmdmouse + mov al, 100 ;Set sample + call cmdmouse + mov al, 0e8h ;Set resolution + call cmdmouse + mov al, 01 ;Set resolution + call cmdmouse + mov al, 0e7h ;Set scale 2:1 + call cmdmouse + mov al, 0f4h ;Enable device + call cmdmouse + mov al, 47h ;Interruption ON + call cmdmouse2 + mov cx, 1024 +testmouse: + in al, 60h ;Lecture du port de donn‚es + cmp al, 250 ;Test si il y a une souris + je okmouse + dec cx + jnz testmouse + stc + jmp endoftest +okmouse: + clc +endoftest: + pop cx ax + ret + +;envoie en bx,cx les coordonn‚es et en dl les boutons +getmouse: +mov bx,cs:rx +mov cx,cs:ry +mov dl,cs:button +sub dl,8 +and dl,0Fh +clc +ret + +;envoie en di les coordonn‚es ecran et en dl les boutons +getmousescreen: +mov di,cs:xy +mov dl,cs:button +sub dl,8 +and dl,0Fh +clc +ret + + +;configure la rapidit‚ dans cl et dans ah,al sphŠre x et y +Configmouse: +mov cs:speed,cl +mov cs:spherex,ah +mov cs:spherey,al +ret + +Button db 0 +rx dw 0 +ry dw 0 +VX db 0 +VY db 0 +X dw 7FFFh +Y dw 7FFFh +speed db 6 +spherex db 0 +spherey db 0 +count db 0 +error db 0 +xy dw 0 +old db 0 +;Gestionnaire de souris PS/2 +react: + push ax bx cx dx di ds es + push cs + pop ds + in al, 60h + cmp error, 1 + je gest1 + cmp count, 1 + je gest1 + cmp count, 2 + je gest2 + cmp count, 3 + je gest3 + +gest1: + mov count, 2 + mov Button, al + and al, 00001000b + cmp al, 8 + je gest1end + mov error, 1 + jmp gest1end2 +gest1end: + mov error, 0 +gest1end2: + mov count, 2 + jmp endgest +gest2: + mov count, 3 + mov VX, al + jmp endgest +gest3: + mov count, 1 + mov VY, al + jmp endgest +endgest: + cmp error,1 + je errormouse + push cs + pop es + mov di,offset infos + mov ah,34 + int 47h + mov cl,speed + movsx bx,VY + shl bx,cl + cmp spherey,0 + jne nolimity + xor ah,ah + mov al,[di] + cmp byte ptr [di+7],4 + jbe text4 + shl ax,3 +text4: + dec ax + cmp bx,0 + jg decy + cmp ry,ax + jae noaddy + jmp nolimity +decy: + cmp ry,0 + je noaddy +nolimity: + sub y,bx +noaddy: + movsx bx,VX + shl bx,cl + cmp spherex,0 + jne nolimitx + xor ah,ah + mov al,[di+1] + cmp byte ptr [di+7],4 + jbe text5 + shl ax,3 +text5: + dec ax + cmp bx,0 + jl decx + cmp rx,ax + jae noaddx + jmp nolimitx +decx: + cmp rx,0 + je noaddx +nolimitx: + add x,bx +noaddx: + mov ax,x + mov bx,0FFFFh + xor ch,ch + mov cl,[di+1] + cmp byte ptr [di+7],4 + jbe text1 + shl cx,3 +text1: + mul cx + div bx + mov rx,ax + mov ax,y + xor ch,ch + mov cl,[di] + cmp byte ptr [di+7],4 + jbe text2 + shl cx,3 +text2: + mul cx + div bx + mov ry,ax + xor ch,ch + mov cl,[di+1] + cmp byte ptr [di+7],4 + jbe text3 + shl cx,3 +text3: + mul cx + add ax,rx + cmp byte ptr [di+7],4 + mov di,ax + jbe textpoint + mov ax,0A000h + mov es,ax + jmp graphpoint +textpoint: + mov ax,0B800h + mov es,ax + shl di,1 + inc di +graphpoint: + mov bx,xy + cmp byte ptr es:[bx],070h + jne waschanged + mov al,old + mov byte ptr es:[bx],al +waschanged: + mov xy,di + mov al,es:[di] + mov old,al + mov byte ptr es:[di],070h + mov al, 20h + out 0a0h, al + out 20h, al +errormouse: + pop es ds di dx cx bx ax + mov cs:isact,0 + pop bx + iret + infos db 40 dup (0) + +end start diff --git a/noyau/systeme.asm b/noyau/systeme.asm new file mode 100644 index 0000000..f40ce49 --- /dev/null +++ b/noyau/systeme.asm @@ -0,0 +1,297 @@ +model tiny,stdcall +p586N +locals +jumps +codeseg +option procalign:byte + +include "..\include\mem.h" +include "..\include\divers.h" +include "..\include\cpu.h" +include "..\include\pci.h" +include "..\include\fat.h" + +memorystart equ 0052h ;premier bloc de la mémoire + +org 0h + +mb0: +header exe <"CE",1,0,0,offset exports,offset imports,offset section,offset start> + +start: + push cs + push cs + push cs + push cs + pop ds + pop es + pop fs + pop gs + call biosprint,offset return + call biosprint,offset msg_memory + call biosprint,offset return + call biosprint,offset msg_memory_init + call mbinit + jc error + call biosprint,offset msg_ok + call biosprint,offset msg_memory_section + mov ax,cs + call mbloadsection,ax + jc error + call biosprint,offset msg_ok + call biosprint,offset msg_memory_jumps + jmp [dword ptr cs:pointer] +pointer: + dw suite + dw memorystart +suite: + push cs + push cs + push cs + push cs + pop ds + pop es + pop fs + pop gs + call biosprint,offset msg_ok + call biosprint,offset msg_video_init + call [cs:setvideomode],2 + jc error + call [cs:clearscreen] + call [cs:print],offset msg_memory + call [cs:print],offset msg_ok2 + call [cs:print],offset msg_memory_init + call [cs:print],offset msg_ok2 + call [cs:print],offset msg_memory_section + call [cs:print],offset msg_ok2 + call [cs:print],offset msg_memory_jumps + call [cs:print],offset msg_ok2 + call [cs:print],offset msg_video_init + call [cs:print],offset msg_ok2 + call [cs:print],offset msg_handler + ;call installirqhandler + call [cs:print],offset msg_ok2 + call [cs:print],offset msg_cpu_detect + call [cs:cpuinfo],offset thecpu + call [cs:setinfo],offset thecpu,offset temp + call [cs:print],offset msg_ok2 + push offset temp + xor eax,eax + mov al,[thecpu.family] + push eax + mov al,[thecpu.models] + push eax + mov al,[thecpu.stepping] + push eax + push offset thecpu.names + push offset thecpu.vendor + call [cs:print],offset msg_cpu_detect_inf + call [cs:print],offset msg_pci + call [cs:pciinfo],offset thepci + jc nopci + call [cs:print],offset msg_ok2 + xor eax,eax + mov al,[thepci.maxbus] + push eax + mov al,[thepci.version_minor] + push eax + mov al,[thepci.version_major] + push eax + call [cs:print],offset msg_pci_info + call [cs:print],offset msg_pci_enum + xor bx,bx + xor cx,cx + xor si,si +searchpci: + call [cs:getcardinfo],bx,cx,si,offset temp + jc stopthis + mov al,[(pcidata offset temp).subclass] + push ax + mov al,[(pcidata offset temp).class] + push ax + call [cs:getpcisubclass] + push dx + push ax + mov al,[(pcidata offset temp).class] + xor ah,ah + push ax + call [cs:getpciclass] + push dx + push ax + push 4 + push esi + push 4 + push ecx + push 4 + push ebx + mov ax,[(pcidata offset temp).device] + push eax + mov ax,[(pcidata offset temp).vendor] + push eax + call [cs:print],offset msg_pci_card + inc si + cmp si,7 + jbe searchpci +stopthis: + xor si,si + inc cx + cmp cx,31 + jbe searchpci + xor cx,cx + inc bx + cmp bx,16 + jbe searchpci + jmp next +nopci: + call [cs:print],offset msg_echec2 +next: + call [cs:detectvmware] + jne novirtual + call [cs:print],offset msg_vmware +novirtual: + call [cs:print],offset msg_flat + call enablea20 + call flatmode + xor ax,ax + mov fs,ax + mov esi,0100000h + mov [dword ptr fs:esi],"OKIN" + call [cs:print],offset msg_ok2 + call [cs:print],offset msg_disk_init + call [cs:initdrive] + jc error2 + call [cs:print],offset msg_ok2 + call [cs:execfile],offset shell + +error2: + call [cs:print],offset msg_error2 + call bioswaitkey + jmp far 0FFFFh:0000h + +error: + call biosprint,offset msg_error + call bioswaitkey + jmp far 0FFFFh:0000h + +shell find <"COMMANDE.CE",0,0,0,1,> +thepci pciinf <> +thecpu cpu <> +temp db 256 dup (0) +return db 0dh,0ah,0 +msg_memory db "Initialisation de la memoire",0 +msg_memory_init db " -Creation du bloc primordial",0 +msg_memory_section db " -Developpement des sections",0 +msg_memory_jumps db "Redirection du systeme",0 +msg_video_init db "Initialisation du pilote VIDEO",0 +msg_handler db "Initialisation du gestionnaire d'interruption",0 +msg_cpu_detect db "Dectection du processeur",0 +msg_cpu_detect_inf db " -Fondeur : %0\l -Modele : %0\l -Revision : %u\l -Version : %u\l -Famille : %u\l -Technologies: %0\l",0 +msg_pci db "Detection des systemes PCI",0 +msg_pci_info db " -Version : %yB.%yB\l -Numero bus max: %u\l",0 +msg_pci_enum db " -Enumeration des peripheriques PCI:\l" + db " |Vendeur|Modele|Bus |Dev.|Func|Classe.Sous-classe\l",0 +msg_pci_card db " | %hW | %hW |%w|%w|%w|%0P.%0P\l",0 +msg_vmware db "\c04 VMWare a ete detecte !!!\c07\l",0 +msg_flat db "Initialisation du Flat Real Mode\l",0 +msg_disk_init db "Initialisation du pilote DISQUE\l",0 + + +msg_error db " [Erreur]",0dh,0ah,"",0 +msg_ok db " [ Ok ]",0dh,0ah,0 +msg_error2 db "\h70 [\c04Erreur\c07]\g00,49",0 +msg_ok2 db "\h70 [\c02 Ok \c07]\l",0 +msg_echec2 db "\h70 [\c0CPasser\c07]\l",0 + + +exporting +declare biosprinth +declare biosprint +declare mbinit +declare mbcreate +declare mbfree +declare mbclean +declare mbresident +declare mbnonresident +declare mbchown +declare mballoc +declare mbfind +declare mbfindsb +declare mbget +declare mbloadfuncs +declare mbsearchfunc +declare bioswaitkey +declare mbloadsection +declare enableirq +declare enableirq +declare readimr +declare readirr +declare readisr +declare seteoi +declare enablea20 +declare disablea20 +declare flatmode +declare installirqhandler +declare irqhandler +declare isenableirq +declare isrequestirq +declare isinserviceirq +declare savecontext +declare restorecontextg +ende + + +importing +use VIDEO,setvideomode +use VIDEO,clearscreen +use VIDEO.LIB,print +use DETECT.LIB,cpuinfo +use DETECT.LIB,setinfo +use DETECT.LIB,pciinfo +use DETECT.LIB,getcardinfo +use DETECT.LIB,getpcisubclass +use DETECT.LIB,getpciclass +use DETECT.LIB,detectvmware +use DISQUE,initdrive +use DISQUE,projfile +use DISQUE,execfile +endi + +include "mcb.asm" +include "8259a.asm" + +section: +dw offset mb0 +dw offset mb1-offset mb0 +db "SYSTEME",0 + +dw offset mb1 +dw offset mb2-offset mb1 +db "VIDEO",0 + +dw offset mb2 +dw offset mb3-offset mb2 +db "VIDEO.LIB",0 + +dw offset mb3 +dw offset mb4-offset mb3 +db "DETECT.LIB",0 + +dw offset mb4 +dw offset mb5-offset mb4 +db "DISQUE",0 + +dd 0 + +mb1: +includebin "video.sys" +mb2: +includebin "..\lib\video.lib" +mb3: +includebin "..\lib\detect.lib" +mb4: +includebin "disque.sys" +mb5: + + + + diff --git a/noyau/systeme.ini b/noyau/systeme.ini new file mode 100644 index 0000000..fe574b7 --- /dev/null +++ b/noyau/systeme.ini @@ -0,0 +1,9 @@ +mcb.sys(49) +video.sys(47) +horloge.sys(8) +8259a.sys(50) +disque.sys(48) +souris.sys(74) +heure.sys(8) +clavier.sys(9) +port.sys(D) \ No newline at end of file diff --git a/noyau/video.asm b/noyau/video.asm new file mode 100644 index 0000000..e8b6f68 --- /dev/null +++ b/noyau/video.asm @@ -0,0 +1,1352 @@ +model tiny,stdcall +p486 +locals +jumps +codeseg +option procalign:byte + +include "..\include\mem.h" +include "..\include\graphic.h" + +org 0h + +header exe <"CE",1,0,0,offset exports,offset imports,,> + +exporting +declare setvideomode +declare getvideomode +declare clearscreen +declare setfont +declare loadfont +declare getfont +declare addline +declare showchars +declare showpixel +declare getpixel +declare setstyle +declare getstyle +declare enablecursor +declare disablecursor +declare setcolor +declare getcolor +declare scrolldown +declare getxy +declare setxy +declare savescreen +declare restorescreen +declare page2to1 +declare page1to2 +declare xchgpages +declare waithretrace +declare waitretrace +declare getvideoinfos +declare savedac +declare restoredac +declare savestate +declare restorestate +declare enablescroll +declare disablescroll +declare getchars +declare savescreen +declare savescreento +declare saveparamto +declare restoreparamfrom +declare restorescreen +declare restorescreenfrom +declare page2to1 +declare page1to2 +declare xchgpages +declare savestate +declare restorestate +declare savestate +declare restoredacfrom +declare restoredac +declare savedacto +ende + +importing +use SYSTEME,mbcreate +use SYSTEME,mbfindsb +use SYSTEME,mbfree +use SYSTEME,mbchown +endi + +;================================Table des modes videos (64 BYTES) ============================================ +;40*25 16 couleurs +mode0 DB 67H,00H, 03H,08H,03H,00H,02H + DB 2DH,27H,28H,90H,2BH,0A0H,0BFH,01FH,00H,4FH,0DH,0EH,00H,00H,00H,00H + DB 9CH,8EH,8FH,14H,1FH,96H,0B9H,0A3H,0FFH + DB 00H,00H,00H,00H,00H,10H,0EH,00H,0FFH + DB 00H,01H,02H,03H,04H,05H,14H,07H,38H,39H,3AH,3BH,3CH,3DH,3EH,3FH + DB 0CH,00H,0FH,08H,00H + DB 40,25 + +;80*25 16 couleurs +mode1 DB 67H,00H, 03H,00H,03H,00H,02H + DB 5FH,4FH,50H,82H,55H,81H,0BFH,1FH,00H,4FH,0DH,0EH,00H,00H,00H,00H + DB 9CH,0EH,8FH,28H,1FH,96H,0B9H,0A3h,0FFH + DB 00H,00H,00H,00H,00H,10H,0EH,00H,0FFH + DB 00H,01H,02H,03H,04H,05H,14H,07H,38H,39H,3AH,3BH,3CH,3DH,3EH,3FH + DB 0CH,00H,0FH,08H,00H + DB 80,25 + +;80*50 16 couleurs +mode2 DB 63H, 00H, 03H,01H,03H,01H,02H + DB 5FH,4FH,50H,82H,55H,81H,0BFH,1FH,00H,47H,06H,07H,00H,00H,00H + DB 00H,9CH,8EH,8FH,28H,1FH,96H,0B9H,0A3H,0FFH + DB 00H,00H,00H,00H,00H,10H,0EH,00H,0FFH + DB 00H,01H,02H,03H,04H,05H,14H,07H,10H,11H,3AH,3BH,3CH,3DH,3EH,3FH + DB 0CH,00H,0FH,00H,00H + DB 80,50 + +;100*50 16 couleurs +mode3 DB 067H,00H,03H,01H,03H,01H,02H + DB 70H,63H,64H,85H,68H,84H,0BFH,1FH,00H,47H,06H,07H,00H,00H,00H + DB 00H,9Ch,08EH,8FH,32H,1FH,96H,0B9H,0A3H,0FFH + DB 00H,00H,00H,00H,00H,10H,0EH,00H,0FFH + DB 00H,01H,02H,03H,04H,05H,14H,07H,10H,11H,3AH,3BH,3CH,3DH,3EH,3FH + DB 0CH,00H,0FH,00H,00H + DB 100,50 + +;100*60 16 couleurs +mode4 DB 0A7H,00H,03H,01H,03H,01H,02H + DB 70H,63H,64H,85H,68H,84H,0FFH,1FH,00H,47H,06H,07H,00H,00H,00H + DB 00H,0E7H,8EH,0DFH,32H,1FH,0DFH,0E5H,0A3H,0FFH + DB 00H,00H,00H,00H,00H,10H,0EH,00H,0FFH + DB 00H,01H,02H,03H,04H,05H,14H,07H,10H,11H,3AH,3BH,3CH,3DH,3EH,3FH + DB 0CH,00H,0FH,00H,00H + DB 100,60 + +;320*200 256 couleurs +mode5 DB 63H, 00H, 03H,01H,0FH,00H,06H + DB 5FH,4FH,50H,82H,54H,80H,0BFH,1FH,00H,41H,00H,00H,00H,00H,00H,00H + DB 9CH,0EH,8FH,28H,00H,96H,0B9H,0E3H,0FFH + DB 00H,00H,00H,00H,00H,40H,05H,0FH,0FFH + DB 00H,01H,02H,03H,04H,05H,06H,07H,08H,09H,0AH,0BH,0CH,0DH,0EH,0FH + DB 41H,00H,0FH,00H,00H + DB 40,25 + +;320*400 256 couleurs +mode6 DB 063H, 00H, 03H,01H,0FH,00H,06H + DB 5FH,4FH,50H,82H,54H,80H,0BFH,1FH,00H,40H,00H,00H,00H,00H,00H,00H + DB 9CH,8EH,8FH,28H,00H,96H,0B9H,0E3H,0FFH + DB 00H,00H,00H,00H,00H,40H,05H,0FH,0FFH + DB 00H,01H,02H,03H,04H,05H,06H,07H,08H,09H,0AH,0BH,0CH,0DH,0EH,0FH + DB 41H,00H,0FH,00H,00H + DB 40,50 + +;320*480 256 couleurs +mode7 DB 0E3H, 00H, 03H,01H,0FH,00H,06H + DB 5FH,4FH,50H,82H,54H,80H,0BH,3EH,00H,40H,00H,00H,00H,00H,00H,00H + DB 0EAH,0ACH,0DFH,28H,00H,0E7H,06H,0E3H,0FFH + DB 00H,00H,00H,00H,00H,40H,05H,0FH,0FFH + DB 00H,01H,02H,03H,04h,05H,06H,07H,08H,09H,0AH,0BH,0CH,0DH,0EH,0FH + DB 41H,00H,0FH,00H,00H + DB 40,60 + +;360*480 256 couleurs +mode8 DB 0E7H, 00H, 03H,01H,0FH,00H,06H + DB 6BH,59H,5AH,8EH,5EH,8AH,0DH,3EH,00H,40H,00H,00H,00H,00H,00H,00H + DB 0EAH,0ACH,0DFH,2DH,00H,0E7H,06H,0E3H,0FFH + DB 00H,00H,00H,00H,00H,40H,05H,0FH,0FFH + DB 00H,01H,02H,03H,04h,05H,06H,07H,08H,09H,0AH,0BH,0CH,0DH,0EH,0FH + DB 41H,00H,0FH,00H,00H + DB 45,60 + +;400*600 256 couleurs +mode9 DB 0E7H, 00H, 03H,01H,0FH,00H,06H + DB 74h,63h,64h,97h,68h,95h,86h,0F0h,00h,60h,00h,00h,00h,00h,00h,00h + DB 5Bh,8Dh,57h,32h,00h,60h,80h,0E3h,0FFh + DB 00H,00H,00H,00H,00H,40H,05H,0FH,0FFH + DB 00H,01H,02H,03H,04h,05H,06H,07H,08H,09H,0AH,0BH,0CH,0DH,0EH,0FH + DB 41H,00H,0FH,00H,00H + DB 50,75 + +;640*480 16 couleurs +mode10 DB 0E3H + DB 00H + DB 03H,01H,0FH,00H,06H + DB 5FH,4FH,50H,82H,53H,9FH,0BH,3EH,00H,40H,00H,00H,00H,00H,00H,00H,0E9H,8BH,0DFH,28H,00H,0E7H,04H,0E3H,0FFH + DB 00H,00H,00H,00H,00H,00H,05H,0FH,0FFH + DB 00H,01H,02H,03H,04H,05H,06H,07H,10H,11H,3AH,3BH,3CH,3DH,3EH,3FH,01H,00H,0FH,00H,00H + DB 80,60 + +;800*600 16 couleurs +mode11 DB 0E7H + DB 00H + DB 03H,01H,0FH,00H,06H + DB 70H,63H,64H,92H,65H,82H,70H,0F0H,00H,60H,00H,00H,00H,00H,00H,00H,5BH,8CH,57H,32H,00H,58H,70H,0E3H,0FFH + DB 00H,00H,00H,00H,00H,00H,05H,0FH,0FFH + DB 00H,01H,02H,03H,04H,05H,06H,07H,10H,11H,3AH,3BH,3CH,3DH,3EH,3FH,01H,00H,0FH,00H,00H + DB 100,75 + +;============================================DATABLOCK========================================================= +datablock vgainf <0,0,0,0,0,7,0FFh,0,0,0,0,0,0,0,0,0,0,0,1> + +;=======================================Equivalence pour la clarté du code======================================== +sequencer equ 03C4h +misc equ 03C2h +ccrt equ 03D4h +attribs equ 03C0h +graphics equ 03CEh +statut equ 03DAh + +maxmode equ 11 +planesize equ 65000 +;============================================Fonctions de l'int VIDEO=========================================== + + +;=============ENABLESCROLLING========= +;Autorise le défilement +;-> +;<- +;===================================== +PROC enablescroll FAR + mov [cs:datablock.scrolling],1 + ret +endp enablescroll + +;=============DISABLESCROLLING========= +;Désactive le d‚filement +;-> +;<- +;====================================== +PROC disablescroll FAR + mov [cs:datablock.scrolling],0 + ret +endp disablescroll + +;=============ENABLECURSOR============= +;Autorise le d‚filement +;-> +;<- +;====================================== +PROC enablecursor FAR + USES ax,dx + mov [cs:datablock.cursor],1 + mov dx,ccrt + mov al,0Ah + out dx,al + inc dx + in al,dx + and al,11011111b + mov ah,al + dec dx + mov al,0Ah + out dx,ax + mov al,[cs:datablock.x] + xor ah,ah + mov dl,[cs:datablock.y] + xor dh,dh + call setxy,ax,dx + ret +endp enablecursor + +;=============DISABLECURSOR============= +;D‚sactive le d‚filement +;-> +;<- +;======================================= +PROC disablecursor FAR + USES ax,dx + mov [cs:datablock.cursor],0 + mov dx,ccrt + mov al,0Ah + out dx,al + inc dx + in al,dx + or al,00100000b + mov ah,al + dec dx + mov al,0Ah + out dx,ax + ret +endp disablecursor + +;==========SETSTYLE========= +;Change le style du texte a %0 +;-> %0 style +;<- +;============================ +PROC setstyle FAR + ARG @style:word + USES cx + mov ax,[@style] + mov [cs:datablock.style],al + ret +endp setstyle + +;==========GETSTYLE========= +;Récupère le style du texte dans AX +;-> +;<- AX style +;=========================== +PROC getstyle FAR + mov al,[cs:datablock.style] + xor ah,ah + ret +endp getstyle + +;=============SetVideoMode========= +;Fixe le mode vidéo courant a %0 +;-> %0 mode d'écran +;<- Carry if error +;================================== +PROC setvideomode FAR + ARG @mode:word + USES ax,cx,dx,di + mov ax,[@mode] + xor ah,ah + cmp al,maxmode + ja @@errorsetvideomode + cmp [cs:datablock.mode],5h + jb @@nographic + cmp al,5h + jae @@nographic + call initfont +@@nographic: + cmp [cs:datablock.mode],0FFh + jne @@noinit + call initfont +@@noinit: + mov [cs:datablock.mode],al + xor ah,ah + mov di,ax + shl di,6 + add di,offset mode0 + mov dx,misc + mov al,[cs:di] + out dx,al + inc di + mov dx,statut + mov al,[cs:di] + out dx,al + inc di + mov dx,sequencer + xor ax,ax +@@initsequencer: + mov ah,[cs:di] + out dx,ax + inc al + inc di + cmp al,4 + jbe @@initsequencer + mov ax,0E11h + mov dx,ccrt + out dx,ax + xor ax,ax +@@initcrt: + mov ah,[cs:di] + out dx,ax + inc al + inc di + cmp al,24 + jbe @@initcrt + mov dx,graphics + xor ax,ax +@@initgraphic: + mov ah,[cs:di] + out dx,ax + inc al + inc di + cmp al,8 + jbe @@initgraphic + mov dx,statut + in al,dx + mov dx,attribs + xor ax,ax +@@initattribs: + mov ah,[cs:di] + push ax + in ax,dx + pop ax + out dx,al + xchg ah,al + out dx,al + xchg ah,al + inc al + inc di + cmp al,20 + jbe @@initattribs + mov al,20h + out dx,al + mov al,[cs:di] + mov [cs:datablock.columns],al + mov ah,[cs:di+1] + mov [cs:datablock.lines],ah + mul ah + mov cl,[cs:di-5] + and cl,01000000b + cmp cl,0 + je @@colors16 + mov [cs:datablock.color],8 + mov cl,4 + jmp @@colors256 +@@colors16: + mov [cs:datablock.color],4 + mov cl,3 +@@colors256: + cmp [cs:datablock.mode],5 + setae [cs:datablock.graphic] + jb @@istext + shl ax,cl + mov [cs:datablock.segments],0A000h + jmp @@wasgraph +@@istext: + mov [cs:datablock.segments],0B800h + shl ax,1 +@@wasgraph: + mov [cs:datablock.pagesize],ax + mov ax,planesize + xor dx,dx + div [cs:datablock.pagesize] + mov [cs:datablock.nbpage],al + mov al,[cs:di-36] + xor ah,ah + shl ax,2 + mov cl,[cs:datablock.graphic] + shr ax,cl + mov [cs:datablock.linesize],ax + mov ax,[cs:di-43] + mov [cs:datablock.adress],ax + mov [cs:datablock.base],ax + mov [cs:datablock.cursor],1 + mov [cs:datablock.style],0 + ret +@@errorsetvideomode: + ret +endp setvideomode + + +initfont: + push ds + call clearscreen + push cs + pop ds + call loadfont,offset font8x8,8,1 + call loadfont,offset font8x16,16,0 + pop ds + ret + +;=============GetVideoMode========= +;Renvoie le mode vidéo courant dans AX +;-> +;<- AX +;================================== +PROC getvideomode FAR + mov al,[cs:datablock.mode] + xor ah,ah + ret +endp getvideomode + +;=============CLEARSCREEN========= +;Efface l'ecran graphique ou texte +;-> +;<- +;================================= +PROC clearscreen FAR + USES eax,cx,dx,di,es + mov cx,planesize + mov di,[cs:datablock.adress] + shr cx,2 + cmp [cs:datablock.graphic],1 + jne @@erasetext + mov ax,0A000h + mov es,ax +@@erasegraph: + mov ax,0F02h + mov dx,sequencer + out dx,ax + mov ax,0205h + mov dx,graphics + out dx,ax + mov ax,0003h + out dx,ax + mov ax,0FF08h + out dx,ax + mov eax,00000000h + cld + rep stosd + mov ax,0005h + cmp [cs:datablock.color],4 + je @@not256 + mov ax,4005h +@@not256: + mov dx,graphics + out dx,ax + mov ax,0003h + out dx,ax + jmp @@endoferase +@@erasetext: + mov ax,0B800h + mov es,ax + mov eax,07200720h + cld + rep stosd +@@endoferase: + call setxy,0,0 + ret +endp clearscreen + + +;=============SetFont========= +;Active la font %0 parmi les 8 +;-> %0 n° font +;<- Carry if error +;============================= +PROC setfont FAR + ARG @font:word + USES ax,cx,dx + mov cx,[@font] + xor ch,ch + cmp cl,7 + ja @@errorsetfont + mov [cs:datablock.font],cl + mov ah,cl + and cl,11b + and ah,0100b + shl ah,2 + add ah,cl + mov dx,sequencer + mov al,3 + out dx,ax + ret +@@errorsetfont: + ret +endp setfont + +;=============GetFont========= +;Récupère le n° de la font active AX +;-> +;<- CL n° font, Carry if error +;============================= +PROC getfont FAR + mov al,[cs:datablock.font] + xor ah,ah +endp getfont + +;!!!!!!!!!!!!!!!!!!!! a remettre les anciens params de timing depuis origine +;=============LoadFont======== +;Charge une police pointée par %0 dans la carte vidéo sous n°font %1, taille police dans %2 +;-> %0 n°font, %1 pointeur vers Font, %2 taille police +;<- Carry if error +;============================= +PROC loadfont FAR + ARG @pointer:word,@size:word,@font:word + USES ax,bx,cx,dx,si,di,es + mov si,[@pointer] + mov cx,[@size] + mov bx,[@font] + cmp bl,7 + ja @@errorloadfont + xor di,di + cli + mov dx,sequencer +@@doseq: + mov ax,[cs:di+offset reg1] + out dx,ax + inc di + inc di + cmp di,6 + jbe @@doseq + mov dx,graphics +@@doseq2: + mov ax,[cs:di+offset reg1] + out dx,ax + inc di + inc di + cmp di,6+6 + jbe @@doseq2 + sti + mov ax,0A000h + mov es,ax + mov dx,256 + mov al,0 + xor bh,bh + cmp bl,4 + jb @@isless + sub bl,4 + shl bl,1 + inc bl + jmp @@okmake +@@isless: + shl bl,1 +@@okmake: + mov di,bx + shl di,13 + mov bh,cl + mov bl,cl + sub bl,32 + neg bl + xor cx,cx + cld +@@popz: + mov cl,bh + rep movsb + mov cl,bl + rep stosb + dec dx + jnz @@popz + xor di,di + mov dx,sequencer +@@doseqs: + mov ax,[cs:di+offset reg2] + out dx,ax + inc di + inc di + cmp di,6 + jbe @@doseqs + mov dx,graphics +@@doseqs2: + mov ax,[cs:di+offset reg2] + out dx,ax + inc di + inc di + cmp di,6+6 + jbe @@doseqs2 + ret +@@errorloadfont: + stc + ret + +reg2 dw 0100h, 0302h, 0304h, 0300h + dw 0004h, 1005h, 0E06h +reg1 dw 0100h, 0402h, 0704h, 0300h + dw 0204h, 0005h, 0406h +endp loadfont + +;==========SHOWLINE=============== +;remet le curseur text a la ligne avec un retour chariot +;-> +;<- +;================================= +PROC addline FAR + USES bx,cx + mov bl,[cs:datablock.y] + xor bh,bh + mov cl,[cs:datablock.lines] + sub cl,2 + cmp bl,cl + jne @@scro + dec bl + mov cx,1 + cmp [cs:datablock.graphic],0 + je @@okscro + mov cx,8 +@@okscro: + call scrolldown,cx +@@scro: + inc bl + call setxy,0,bx + ret +endp addline + +;==========SETCOLOR========= +;Change les attributs du texte a CL +;-> %0 couleur +;<- +;=========================== +PROC setcolor FAR + ARG @color:word + USES cx + mov cx,[@color] + mov [cs:datablock.colors],cl + ret +endp setcolor + +;==========GETCOLOR========= +;Récupère les attributs du texte dans AX +;-> +;<- AX couleur +;=========================== +PROC getcolor FAR + mov al,[cs:datablock.colors] + xor ah,ah + ret +endp getcolor + +;==========SCROLLDOWN========= +;defile de %0 lines vers le bas +;-> %0 lines à défiler vers le bas +;<- +;============================= +PROC scrolldown FAR + ARG @line:word + USES ax,cx,dx,si,di,ds,es + cmp [cs:datablock.scrolling],0 + je @@graphp + mov ax,[@line] + mul [cs:datablock.linesize] + mov si,ax + mov cx,[cs:datablock.pagesize] + sub cx,si + mov di,[cs:datablock.adress] + cld + cmp [cs:datablock.graphic],1 + jne @@textp + mov ax,0A000h + mov es,ax + mov ds,ax + mov ax,0F02h + mov dx,sequencer + out dx,ax + mov ax,0105h + mov dx,graphics + out dx,ax + cld + rep movsb + mov ax,0005h + cmp [cs:datablock.color],4 + je @@not256ok + mov ax,4005h +@@not256ok: + mov dx,graphics + out dx,ax + mov ax,0003h + out dx,ax + jmp @@graphp + +@@textp: + mov ax,0B800h + mov es,ax + mov ds,ax + rep movsb +@@graphp: + ret +endp scrolldown + +;==========GETXY========= +;Met les coordonnées du curseur dans ah,al au format point +;-> +;<- ah coordonnées x, al coordonnées y +;======================== +PROC getxy FAR + USES bx + mov ah,[cs:datablock.x] + mov al,[cs:datablock.y] + ret +endp getxy + +;==========SETXY========= +;Change les coordonnées du curseur a X:%0,Y:%1 +;-> %0 coordonnées x, %1 coordonnées y +;<- +;======================== +PROC setxy FAR + ARG @x:word,@y:word + USES ax,bx,dx,di + mov ax,[@y] + mov bx,[@x] + mov [cs:datablock.x],bl + mov [cs:datablock.y],al + mov di,[cs:datablock.adress] + add di,bx + mul [cs:datablock.columns] + add di,ax + shl di,1 + mov [cs:datablock.xy],di + call setcursor + ret +endp setxy + +;==========SHOWPIXEL========= +;Affiche un pixel de couleur AL en X:%0,Y:%1 +;-> %0 coordonnées x, %1 coordonnées y, %2 couleur +;<- +;============================ +PROC showpixel FAR + ARG @x:word,@y:word,@color:word + USES ax,bx,cx,dx,si,di,es + mov bx,[@x] + mov cx,[@y] + mov ax,[@color] + cmp [cs:datablock.color],4 + je @@showpixel4 + mov si,ax + mov ax,cx + mov cl,bl + mul [cs:datablock.linesize] + shr bx,2 + add ax,bx + mov di,ax + add di,[cs:datablock.adress] + and cl,3 + mov ah,1 + shl ah,cl + mov al,2 + mov dx,sequencer + out dx,ax + mov bx,0A000h + mov es,bx + mov ax,si + mov [es:di],al + jmp @@endofshow + +@@showpixel4: + mov dx,ax + mov ax,cx + mov ch,dl + mov cl,bl + mul [cs:datablock.linesize] + shr bx,3 + add ax,bx + mov di,ax + add di,[cs:datablock.adress] + and cl,111b + xor cl,111b + mov ah,1 + shl ah,cl + mov al,8 + mov dx,graphics ;masque + out dx,ax + mov ax,0205h + out dx,ax + mov ax,0003h + out dx,ax + mov bx,0A000h + mov es,bx + mov al,[es:di] + mov [es:di],ch +@@endofshow: + ret +endp showpixel + +;!!!!!!!!!!!!!! gerer le mode chain 4 +;==========GETPIXEL========= +;Récupère en ax la couleur du pixel de coordonnées X:%0,Y:%1 +;-> %0 coordonnées x, %1 coordonnées y +;<- AX couleur +;========================================= +PROC getpixel FAR + ARG @x:word,@y:word + USES ax,bx,cx,dx,di,es + mov bx,[@x] + mov cx,[@y] + mov ax,cx + mov cl,bl + mul [cs:datablock.linesize] + shr bx,2 + add ax,bx + mov di,ax + add di,[cs:datablock.adress] + and cl,3 + mov ah,cl + mov al,4 + mov dx,graphics + out dx,ax + mov bx,0A000h + mov es,bx + mov al,[es:di] + ret +endp getpixel + +;==========GETVGAINFO========= +;Renvoie un bloc de donnée en ES:DI sur l'état de la carte graphique +;<- ES:%0 pointeur +;-> +;============================================= +PROC getvideoinfos FAR + ARG @pointer:word + USES cx,si,di,ds + push cs + pop ds + mov cx,size datablock + mov si,offset datablock + mov di,[@pointer] + cld + rep movsb + ret +endp getvideoinfos + +;==========WAITRETRACE========= +;Synchronisation avec la retrace verticale +;<- +;-> +;============================== +PROC waitretrace FAR + USES ax,dx + mov dx,3DAh +@@waitr: + in al,dx + test al,8 + jz @@waitr + ret +endp waitretrace + +;==========WAITHRETRACE========= +;Synchronisation avec la retrace horizontale +;<- +;-> +;=============================== +PROC waithretrace FAR + USES ax,dx + mov dx,3DAh +@@waitr: + in al,dx + test al,1 + jz @@waitr + ret +endp waithretrace + +;==========GETCHAR========= +;Renvoie en AX le caractère sur le curseur +;<- +;-> +;========================== +PROC getchars FAR + USES di,es + mov ax,0B800h + mov es,ax + mov di,[cs:datablock.xy] + mov al,[es:di] + xor ah,ah + ret +endp getchars + +;==========SHOWCHAR========= +;Ecrit le caractère ASCII %0 attribut %1 aprés le curseur, en le mettant à jours +;<- +;-> +;=========================== +PROC showchars FAR + ARG @char:word,@attr:word + USES ax,bx,cx,dx,di,es + mov cl,[byte ptr @char] + mov ch,[byte ptr @attr] + cmp [@attr],0FFFFh + jne @@notlastattr + mov ch,[cs:datablock.colors] +@@notlastattr: + cmp [cs:datablock.graphic],1 + jne @@textaccess + call emulatechar + jmp @@adjusttext +@@textaccess: + mov ax,0B800h + mov es,ax + mov di,[cs:datablock.xy] + mov [es:di],cx + add [cs:datablock.xy],2 +@@adjusttext: + inc [cs:datablock.x] + mov cl,[cs:datablock.columns] + cmp [cs:datablock.x],cl + jb @@noadjusted + call addline +@@noadjusted: + call setcursor + ret +endp showchars + +setcursor: + push ax cx dx + cmp [cs:datablock.cursor],1 + jne notshow + mov dx,ccrt + mov al,0Eh + mov cx,[cs:datablock.xy] + shr cx,1 + mov ah,ch + out dx,ax + mov ah,cl + inc al + out dx,ax +notshow: + pop dx cx ax + ret + + +;Ecrit le caractère ASCII CL attribut CH aprés le curseur graphique, en le mettant à jours en mode graphique +emulatechar: + push ax bx cx dx di + mov al,ch + mov di,cx + and di,11111111b + shl di,3 + add di,offset font8x8 + mov bl,[cs:datablock.x] + mov cl,[cs:datablock.y] + xor bh,bh + xor ch,ch + shl bx,3 + shl cx,3 + mov ah,[cs:di] + xor dx,dx +bouclet: + rol ah,1 + push ax + jc colored + shr al,4 + cmp [cs:datablock.style],0 + jnz transparent +colored: + and ax,1111b + call showpixel,bx,cx,ax +transparent: + pop ax + inc bx + inc dl + cmp dl,8 + jb bouclet + inc di + mov ah,[cs:di] + xor dl,dl + sub bx,8 + inc cx + inc dh + cmp dh,8 + jb bouclet +ended: + pop di dx cx bx ax + ret + +;sauve l'ecran dans un bloc de mémoire +PROC savescreen FAR +USES ax,ds,bp +mov bp,sp +push cs +pop ds +call [cs:mbcreate],offset data3,[cs:datablock.pagesize] +jc @@error +call [cs:mbchown],ax,[word ptr ss:bp+8] +jc @@error +push ax +pop ds +call savescreento,0 +clc +ret +@@error: +stc +ret +endp savescreen +data3 db '/vgascreen',0 + + +;===================================sauve l'ecran rapidement en ds:%1================ +PROC savescreento FAR + ARG @offset:word + USES ecx,si,di,ds,es + push ds + pop es + mov cx,0B800h + mov ds,cx + xor ecx,ecx + mov cx,[cs:datablock.pagesize] + mov di,[@offset] + shr cx,2 + xor si,si + cld + rep movsd + ret +endp savescreento + +;===================================sauve les parametres en ds:%0================ +PROC saveparamto FAR + ARG @offset:word + USES ecx,si,di,ds,es + push ds + pop es + push cs + pop ds + xor ecx,ecx + mov cx,size datablock + mov di,[@offset] + mov si,offset datablock + cld + rep movsb + ret +endp saveparamto + +;===================================restore les parametres depuis en ds:%0================ +PROC restoreparamfrom FAR + ARG @offset:word + USES ecx,si,di,es + push cs + pop es + xor ecx,ecx + mov cx,size datablock + mov si,[@offset] + call setvideomode,[word ptr (vgainf si).mode] + mov di,offset datablock + cld + rep movsb + ret +endp restoreparamfrom + + + + + + + +;restaure l'ecran dans un bloc de mémoire +PROC restorescreen FAR +USES ax,ds,bp +mov bp,sp +push cs +pop ds +call [cs:mbfindsb],offset data3,[word ptr ss:bp+8] +jc @@error +push ax +pop ds +call restorescreenfrom,0 +clc +ret +@@error: +stc +ret +endp restorescreen + + +;===================================restaure l'ecran rapidement en %1================ +PROC restorescreenfrom FAR + ARG @offset:word + USES ecx,si,di,es + mov cx,0B800h + mov es,cx + xor ecx,ecx + mov cx,[cs:datablock.pagesize] + mov si,[@offset] + shr cx,2 + xor di,di + cld + rep movsd + ret +endp restorescreenfrom + + + + +;===============================Page2to1============================ + +PROC page2to1 FAR + USES ecx,si,di,ds,es + mov cx,0B800H + mov es,cx + mov ds,cx + xor ecx,ecx + mov cx,[cs:datablock.pagesize] + shr cx,2 + mov si,[cs:datablock.pagesize] + xor di,di + cld + rep movsd + ret +endp page2to1 + +;===============================Page1to2============================ +PROC page1to2 FAR + USES ecx,si,di,ds,es + mov cx,0B800H + mov es,cx + mov ds,cx + xor ecx,ecx + mov cx,[cs:datablock.pagesize] + shr cx,2 + mov di,[cs:datablock.pagesize] + xor si,si + cld + rep movsd + ret +endp page1to2 +;===============================xchgPages============================ +PROC xchgpages FAR + USES ax,ecx,si,di,ds,es,bp +mov bp,sp +push cs +pop ds +call [cs:mbcreate],offset data4,[cs:datablock.pagesize] +jc @@error +call [cs:mbchown],ax,[word ptr ss:bp+18] +jc @@error +push ax +pop ds +call savescreento,0 +call page2to1 +xor si,si +mov cx,0B800H +mov es,cx +mov di,[cs:datablock.pagesize] +xor ecx,ecx +mov cx,[cs:datablock.pagesize] +shr cx,2 +cld +rep movsd +call [cs:mbfree],ax +clc +ret +@@error: +stc +ret +endp xchgpages + +data4 db '/vgatemp',0 + + + + + +;Sauve l'‚tat de la carte dans un bloc mémoire +PROC savestate FAR +USES ax,cx,di,ds,bp +mov bp,sp +mov cx,size datablock +add cx,[cs:datablock.pagesize] +add cx,3*256 +push cs +pop ds +call [cs:mbcreate],offset data,cx +jc @@error +call [cs:mbchown],ax,[word ptr ss:bp+12] +jc @@error +push ax +pop ds +xor di,di +call saveparamto,di +add di,size datablock +call savescreento,di +add di,[cs:datablock.pagesize] +call savedacto,di +clc +ret +@@error: +stc +ret +endp savestate + +data db '/vga',0 + + + + +;R‚cupŠre l'‚tat de la carte depuis son bloc mémoire +PROC restorestate FAR +USES ax,cx,di,ds,bp +mov bp,sp +push cs +pop ds +call [cs:mbfindsb],offset data,[word ptr ss:bp+12] +jc @@error +push ax +pop ds +xor di,di +call restoreparamfrom,di +add di,size datablock +call restorescreenfrom,di +add di,[cs:datablock.pagesize] +call restoredacfrom,di +clc +ret +@@error: +stc +ret +endp restorestate + + +;sauve le DAC dans un bloc de mémoire +PROC savedac FAR +USES ax,ds,bp +mov bp,sp +push cs +pop ds +call [cs:mbcreate],offset data3,3*256 +jc @@error +call [cs:mbchown],ax,[word ptr ss:bp+8] +jc @@error +push ax +pop ds +call savedacto,0 +clc +ret +@@error: +stc +ret +endp savedac + +data2 db '/vgadac',0 + + + +;R‚cupŠre le dac depuis son bloc mémoire +PROC restoredac FAR +USES ax,ds,bp +mov bp,sp +call [cs:mbfindsb],offset data2,[word ptr ss:bp+8] +jc @@error +push ax +pop ds +call restoredacfrom,0 +clc +ret +@@error: +stc +ret +endp restoredac + + + +;sauve le DAC en ds:%0 +PROC savedacto FAR +ARG @offset:word +USES ax,cx,dx,di +mov di,[@offset] +mov dx,3C7h +mov cx,256 +@@save: +mov al,cl +dec al +out dx,al +inc dx +inc dx +in al,dx +mov [ds:di],al +inc di +in al,dx +mov [ds:di],al +inc di +in al,dx +mov [ds:di],al +inc di +dec dx +dec dx +dec cx +jne @@save +ret +endp savedacto + +;restore le DAC depuis ds:si +PROC restoredacfrom FAR +ARG @offset:word +USES ax,cx,dx,si +mov si,[@offset] +xor ax,ax +mov dx,3C8h +mov cx,256 +@@save2: +mov al,cl +dec al +out dx,al +inc dx +mov al,[ds:si] +inc si +out dx,al +mov al,[ds:si] +inc si +out dx,al +mov al,[ds:si] +inc si +out dx,al +dec dx +dec cx +jne @@save2 +ret +endp restoredacfrom + + + +font8x8: +include "..\include\pol8x8.inc" +font8x16: +include "..\include\pol8x16.inc" + +