feat: ajout de fonction permettant de communiquer avec le port LPT (imprimante) et fonction timer.

This commit is contained in:
Nicolas Hordé 2001-04-27 22:48:09 +02:00
parent 4c3f72e0ce
commit 163064bbb7
11 changed files with 1203 additions and 1005 deletions

View File

@ -9,6 +9,10 @@ util\tlink %1.obj /x/t
if errorlevel 1 goto end
echo Copying file %1...
if "%1"=="video" goto video
if "%1"=="lpt" goto system
if "%1"=="keyboard" goto system
if "%1"=="timer" goto system
if "%1"=="drive" goto system
if "%1"=="system" goto system
if "%1"=="setup" goto setup
copy %1.com ..\data\%1.exe>nul

View File

@ -24,7 +24,8 @@ Adres:
pop es
mov cx,sect
mov bx,offset buffer
call readsector
mov ax,0001h
int 48h
jnc noerror
errtr:
mov ah,25
@ -153,7 +154,8 @@ doaline2:
jne suit6
mov cx,sect
mov bx,offset buffer
call writesector
mov ah,1
int 48h
jnc waitkey
jmp errtr
suit6:
@ -189,7 +191,8 @@ waitst:
pop es
mov cx,sect
mov bx,offset buffer
call writesector
mov ah,1
int 48h
jnc adres
jmp errtr
tre:
@ -356,88 +359,9 @@ pope db 'VIEW ',0
spaces db ' ³ ',0
showbuffer db 35 dup (0FFh)
Lastread dw 0FFFFh
ReadSector:
push ax cx dx si
cmp cx,cs:lastread
je done
mov cs:LastRead,cx
mov AX, CX
xor DX, DX
div cs:DiskSectorsPerTrack
mov CL, DL ;{ Set the sector }
and CL, 63 ;{ Top two bits are bits 8&9 of the cylinder }
xor DX, DX
div cs:DiskTracksPerHead
mov CH, DL ;{ Set the track bits 0-7 }
mov AL, DH
ror AL, 1
ror AL, 1
and AL, 11000000b
or CL, AL ;{ Set bits 8&9 of track }
xor dX, DX
div cs:DiskHeads
mov DH, DL ;{ Set the head }
inc CL
mov SI, 4
TryAgain:
mov AL, 1
mov DL, 0
mov AH, 2
int 13h
jnc Done
dec SI
jnz TryAgain
mov word ptr cs:lastread,0ffffh
Done:
pop si dx cx ax
ret
WriteSector:
push ax cx dx si
cmp cs:Lastread,cx
jne nodestruct
mov cs:Lastread,0ffffh
nodestruct:
mov AX, CX
xor DX, DX
div cs:DiskSectorsPerTrack
mov CL, DL ;{ Set the sector }
and CL, 63 ;{ Top two bits are bits 8&9 of the cylinder }
xor DX, DX
div cs:DiskTracksPerHead
mov CH, DL ;{ Set the track bits 0-7 }
mov AL, DH
ror AL, 1
ror AL, 1
and AL, 11000000b
or CL, AL ;{ Set bits 8&9 of track }
xor DX, DX
div cs:DiskHeads
mov DH, DL ;{ Set the head }
inc CL
mov SI, 4
TryAgain2:
mov AL, 1
mov DL, 0
mov AH, 3
int 13h
jnc Done2
dec SI
jnz TryAgain2
Done2:
pop si dx cx ax
ret
oldmode db 0
DiskSectorsPerTrack dw 18
DiskTracksPerHead dw 80
DiskHeads dw 2
infos db 10 dup (0)
buffer equ $+4000
buffer equ $
end start

398
drive.asm Executable file
View File

@ -0,0 +1,398 @@
.model tiny
.486
smart
.code
org 0100h
start:
jmp tsr
db 'DRIVE'
Tsr:
cli
cmp ax,1234h
jne nomore
mov ax,4321h
jmp itsok
nomore:
push bx
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:
sti
iret
current dw 0
tables dw readsector
dw writesector
dw verifysector2
dw loadfatway
dw loadfile
;cx entre -> fatway chemin
getfatway:
push bx cx es
mov bx,offset fatway
fatagain:
mov cs:[bx],cx
add bx,2
cmp cx,0FFF0h
jae finishload
call getfat
jnc fatagain
finishload:
pop es cx bx
ret
;Charge le fichier de chemin cx
loadfatway:
push ax bx cx di
call getfatway
jc endload
mov di,offset fatway
loadagain:
mov cx,cs:[di]
cmp cx,0FFF0h
jae endload
add di,2
xor al,al
call readsector
jc endload
add bx,cs:sizec
jmp loadagain
endload:
pop di cx bx ax
ret
sizec dw 512
reserv dw 1
;<-cx nøsecteur ->cx code FAT
getfat:
push es ax bx dx
mov ax,cx
xor dx,dx
div cs:sizec
mov cx,ax
add cx,cs:reserv
mov bx,offset buffer
push cs
pop es
call readsector
jc errorgetfat
shl dx,1
add bx,dx
mov cx,cs:[bx]
errorgetfat:
pop dx bx ax es
ret
ReadSector:
push ax cx dx si
cmp al,1
je pr
cmp cx,cs:lastread
je done
pr:
mov cs:LastRead,cx
mov AX, CX
xor DX, DX
div cs:DiskSectorsPerTrack
mov CL, DL ;{ Set the sector }
and CL, 63 ;{ Top two bits are bits 8&9 of the cylinder }
xor DX, DX
div cs:DiskTracksPerHead
mov CH, DL ;{ Set the track bits 0-7 }
mov AL, DH
ror AL, 1
ror AL, 1
and AL, 11000000b
or CL, AL ;{ Set bits 8&9 of track }
xor dX, DX
div cs:DiskHeads
mov DH, DL ;{ Set the head }
inc CL
mov SI, 4
TryAgain:
mov AL, 1
mov DL, 0
mov AH, 2
int 13h
jnc Done
dec SI
jnz TryAgain
mov word ptr cs:lastread,0ffffh
Done:
pop si dx cx ax
ret
WriteSector:
push ax cx dx si
cmp cs:Lastread,cx
jne nodestruct
mov cs:Lastread,0ffffh
nodestruct:
mov AX, CX
xor DX, DX
div cs:DiskSectorsPerTrack
mov CL, DL ;{ Set the sector }
and CL, 63 ;{ Top two bits are bits 8&9 of the cylinder }
xor DX, DX
div cs:DiskTracksPerHead
mov CH, DL ;{ Set the track bits 0-7 }
mov AL, DH
ror AL, 1
ror AL, 1
and AL, 11000000b
or CL, AL ;{ Set bits 8&9 of track }
xor DX, DX
div cs:DiskHeads
mov DH, DL ;{ Set the head }
inc CL
mov SI, 4
TryAgain2:
mov AL, 1
mov DL, 0
mov AH, 3
int 13h
jnc Done2
dec SI
jnz TryAgain2
Done2:
pop si dx cx ax
ret
Lastread dw 0FFFFh
Inverse:
mov si,512/4
invert:
shl si,2
not dword ptr [bx+si-4]
shr si,2
dec si
jnz invert
ret
VerifySector:
push bx cx si di ds es
push cs
pop es
push cs
pop ds
mov bx,offset buffer
call ReadSector
jc errorverify
call inverse
call WriteSector
jc errorverify
mov bx,offset buffer2
call ReadSector
call inverse
jc errorverify
mov bx,offset buffer
call inverse
call WriteSector
jc errorverify
mov cx,512/4
mov si,offset buffer
mov di,offset buffer2
cld
rep cmpsd
errorverify:
pop es ds di si cx bx
ret
VerifySector2:
call verifysector
jne nook
or byte ptr [bp+6],10b
nook:
ret
;Charge le fichier Ds:si en es:di
loadfile:
push bx cx
call searchfile
mov bx,di
call loadfatway
pop cx bx
ret
;Recherche le fichier et retourne sont path et en cx sont debut
Searchfile:
push bx dx si di ds es
push cs
pop es
mov di,offset temp
call asciiztofit
mov bx,offset buffer
push cs
pop ds
mov cx,13
check:
call readsector
jc errorboot
xor di,di
findnext:
cmp byte ptr [bx+di],0
je errorboot
push si di cx
mov si,di
add si,bx
mov di,offset temp
mov cx,12+4
rep cmpsb
pop cx di si
je oksystem
add di,32
inc dx
cmp dx,nbfit
ja errorboot
cmp di,sizec
jb findnext
inc cx
jmp Check
oksystem:
mov cx,[di+BX+26]
errorboot:
pop es ds di si dx bx
ret
;->name ds:si ->es:di
AsciiZtoFit:
push ax bx cx dx si di ds es
xor bx,bx
mov dx,di
noextens:
mov al,[si+bx]
cmp al,'.'
je extens
call Issystchar
jc errortranslate
mov es:[di],al
inc di
inc bx
cmp bx,namesize ;(.)
jne noextens
erro:
stc
jmp errortranslate
extens:
add si,bx
inc si
sub bx,namesize
neg bx
mov al,0
mov cx,bx
cld
rep stosb
xor bx,bx
wasextens:
mov al,[si+bx]
cmp al,0
je endextens
call Issystchar
jc errortranslate
mov es:[di],al
inc di
inc bx
cmp bx,extsize
jne wasextens
jmp erro
endextens:
sub bx,extsize
neg bx
mov al,0
mov cx,bx
cld
rep stosb
mov si,dx
mov di,dx
push es
pop ds
mov cx,extsize+namesize
call uppercaseMEM
clc
endtranslate:
pop es ds di si dx cx bx ax
ret
errortranslate:
stc
jmp endtranslate
;Carry si al = caractŠre systŠme
isSystchar:
push di
mov di,offset exeptchar
isexcept:
cmp al,[di]
je nogood
inc di
cmp byte ptr [di],0
jne isexcept
endanal:
pop di
ret
exeptchar db '/\<>:|.',01,0,0
nogood:
stc
jmp endanal
;Transforme les x caractŠres de la mem en ds:si en maj
uppercaseMEM:
push si di cx ax
mov di,si
uppercaser:
mov al,ds:[si]
inc si
cmp al,'A'
jb nonmaj
cmp al,'Z'
ja nonmaj
add al,'a'-'A'
nonmaj:
mov es:[di],al
inc di
dec cx
jnz uppercaser
enduppercase:
clc
pop ax cx di si
ret
nbfit equ 255
namesize equ 12
extsize equ 5
temp db 12+5+1 dup (0)
DiskSectorsPerTrack dw 18
DiskTracksPerHead dw 80
DiskHeads dw 2
fatway equ $
buffer equ $+3000
buffer2 equ $+512
end start

View File

@ -2,83 +2,178 @@
.486
smart
.code
org 0100h
start:
mov al,0D0h
call keybcmd
in al,60h
ret
;============= PPI port A (Programmable Peripheral interface) ================
;8048 (old XT) 8042 (old AT) 8741 8742 (with PS2 mouse)
; R/W
;Port 60h : Scancode & keyboarddata
overrun equ 000h ;Error too many keys pressed
BATend equ 0AAh ;End of the test BAT (basic test assurance)
MF2code equ 0ABh ;Code send by MF2 keyboard
MF2code2 equ 041h ;Code send by MF2 keyboard
echo equ 0EEh ;Send by echo command
Ack equ 0FAh ;Send by every comman exept EEh et FEh (Aknoledge)
BATerror equ 0FCh ;BAT failed
Resend equ 0FEh ;Resend data please
Error equ 0FFh ;Error of keyboard
;Port 60h : command data
led equ 0EDh ;set the led like you want
echo equ 0EEh ;Echo byte for diagnostic
Set equ 0F0h ;Choose the Set of scancode
Id equ 0F2h ;Identify the keyboard
rate equ 0F3h ;Set the specified typematic rate
enable equ 0F4h ;clear buffer and scan
reset equ 0F5h ;Reset and no scan
reset2 equ 0F6h ;Reset and scan
;============= PPI port A (Programmable Peripheral interface) ================
;8048 (old XT) 8042 (old AT) 8741 8742 (with PS2 mouse)
; R/W
;Port 61h
;==================== Data and control keyboard registers ===================
;8042 (old AT) 8741 8742 (with PS2 mouse)
; R/W
;Port 64h
;Envoie la commande AL aux clavier et si besoin est la donne DL
Keybcmd:
push ax
xchg al,ah
xor cx,cx
clearbuffer:
in al,64h
test al,02h
loopnz clearbuffer
jnz errorkb
xchg al,ah
out 64h,al
clearbuffer2:
in al,64h
test al,02h
loopnz clearbuffer2
jnz errorkb
cmp dl,0
je endkeyb
mov al,dl
out 60h,al
endkeyb:
clc
pop ax
ret
errorkb:
stc
pop ax
ret
jmp tsr
offsets dd 0
db 'KEYBOARD'
tsr:
pushf
db 2eh,0ffh,1eh
dw offsets
cli
pusha
in al,60h
cmp cs:isstate,1
jne nostate
cmp al,57
jne nof12
mov cs:isstate,0
jmp noF12
nostate:
cmp al,87
jne NoF11
push es
push cs
pop es
mov di,offset infos
mov ah,34
int 47h
mov al,cs:infos+7
inc al
and ax,111b
int 47h
pop es
nof11:
cmp al,88
jne NoF12
mov ah,26
int 47h
call showstate
mov cs:isstate,1
sti
waitt:
cmp cs:isstate,0
jne waitt
mov ah,27
int 47h
noF12:
popa
sti
iret
isstate db 0
infos db 10 dup (0)
showstate:
push ds es
push ss
push gs
push fs
push es
push ds
push cs
pushad
pushfd
push cs
push cs
pop es
pop ds
mov ah,2
int 47h
mov ah,21
mov cl,4
int 47h
mov ah,13
mov si,offset reg
int 47h
mov ah,6
int 47h
mov ah,21
mov cl,7
int 47h
mov ah,13
mov si,offset fla
int 47h
pop edx
mov cx,32
mov ah,11
int 47h
mov ah,5
int 47h
mov ah,10
int 47h
mov si,offset regs
mov bx,8+6
mov ah,21
mov cl,6
int 47h
showallREG:
mov ah,6
int 47h
cmp bx,7
jb nodr
pop edx
jmp popo
nodr:
mov ah,21
mov cl,1
int 47h
xor edx,edx
pop dx
popo:
mov ah,13
int 47h
mov ah,10
mov cx,32
int 47h
mov ah,5
int 47h
push si
mov si,offset gr
mov ah,13
int 47h
mov ah,8
int 47h
mov si,offset dr
mov ah,13
int 47h
pop si
add si,5
dec bx
jnz showallreg
mov ah,34
mov di,offset infos
int 47h
mov ah,25
mov bl,cs:infos
xor bh,bh
dec bl
int 47h
mov si,offset app
mov ah,13
int 47h
mov ah,32
mov bl,cs:infos
xor bh,bh
mov di,ax
dec di
mov cl,116
int 47h
pop es ds
ret
reg db 'State of registers',0
fla db 'Flags:',0
regs db 'EDI:',0
db 'ESI:',0
db 'EBP:',0
db 'ESP:',0
db 'EBX:',0
db 'EDX:',0
db 'ECX:',0
db 'EAX:',0
db ' CS:',0
db ' DS:',0
db ' ES:',0
db ' FS:',0
db ' GS:',0
db ' SS:',0
gr db '(',0
dr db ')',0
app db 'Press space to quit...',0
end start

260
logo.asm
View File

@ -6,11 +6,11 @@ org 0100h
start:
mov si,offset logo
call searchfile
mov ah,4
xor di,di
mov bx,6000h
mov es,bx
mov bx,0h
call loadfatway
int 48h
push es
pop ds
mov bx,5000h
@ -120,202 +120,6 @@ shl cx,2
add si,cx
jmp no
Searchfile:
push bx dx si di ds es
mov di,offset temp
mov bx,offset buffer
call asciiztofit
mov cx,13
check:
call readsector
jc errorboot
xor di,di
findnext:
cmp byte ptr [bx+di],0
je errorboot
push si di cx
mov si,di
add si,bx
mov di,offset temp
mov cx,12+4
rep cmpsb
pop cx di si
je oksystem
add di,32
inc dx
cmp dx,nbfit
ja errorboot
cmp di,sizec
jb findnext
inc cx
jmp Check
oksystem:
mov cx,[di+BX+26]
errorboot:
pop es ds di si dx bx
ret
;->name ds:si ->es:di
AsciiZtoFit:
push ax bx cx dx si di ds es
xor bx,bx
mov dx,di
noextens:
mov al,[si+bx]
cmp al,'.'
je extens
call Issystchar
jc errortranslate
mov es:[di],al
inc di
inc bx
cmp bx,namesize ;(.)
jne noextens
erro:
stc
jmp errortranslate
extens:
add si,bx
inc si
sub bx,namesize
neg bx
mov al,0
mov cx,bx
cld
rep stosb
xor bx,bx
wasextens:
mov al,[si+bx]
cmp al,0
je endextens
call Issystchar
jc errortranslate
mov es:[di],al
inc di
inc bx
cmp bx,extsize
jne wasextens
jmp erro
endextens:
sub bx,extsize
neg bx
mov al,0
mov cx,bx
cld
rep stosb
mov si,dx
mov di,dx
push es
pop ds
mov cx,extsize+namesize
call uppercaseMEM
clc
endtranslate:
pop es ds di si dx cx bx ax
ret
errortranslate:
stc
jmp endtranslate
;Carry si al = caractŠre systŠme
isSystchar:
push di
mov di,offset exeptchar
isexcept:
cmp al,cs:[di]
je nogood
inc di
cmp byte ptr cs:[di],0
jne isexcept
endanal:
pop di
ret
exeptchar db '/\<>:|.',01,0,0
nogood:
stc
jmp endanal
;Transforme les x caractŠres de la mem en ds:si en maj
uppercaseMEM:
push si di cx ax
mov di,si
uppercaser:
mov al,ds:[si]
inc si
cmp al,'A'
jb nonmaj
cmp al,'Z'
ja nonmaj
add al,'a'-'A'
nonmaj:
mov es:[di],al
inc di
dec cx
jnz uppercaser
enduppercase:
clc
pop ax cx di si
ret
nbfit equ 255
namesize equ 12
extsize equ 5
;cx entre -> fatway chemin
getfatway:
push bx cx es
mov bx,offset fatway
fatagain:
mov cs:[bx],cx
add bx,2
cmp cx,0FFF0h
jae finishload
call getfat
jnc fatagain
finishload:
pop es cx bx
ret
lastread dw 0FFFFh
ReadSector:
push ax cx dx si
cmp cx,cs:lastread
je done
mov cs:LastRead,cx
mov AX, CX
xor DX, DX
div cs:DiskSectorsPerTrack
mov CL, DL ;{ Set the sector }
and CL, 63 ;{ Top two bits are bits 8&9 of the cylinder }
xor DX, DX
div cs:DiskTracksPerHead
mov CH, DL ;{ Set the track bits 0-7 }
mov AL, DH
ror AL, 1
ror AL, 1
and AL, 11000000b
or CL, AL ;{ Set bits 8&9 of track }
xor dX, DX
div cs:DiskHeads
mov DH, DL ;{ Set the head }
inc CL
mov SI, 4
TryAgain:
mov AL, 1
mov DL, 0
mov AH, 2
int 13h
jnc Done
dec SI
jnz TryAgain
mov word ptr cs:lastread,0ffffh
Done:
pop si dx cx ax
ret
DecompressRle:
push cx dx si di
mov dx,cx
@ -354,63 +158,5 @@ neg bp
pop di si dx cx
ret
dot db '.',0
loadfatway:
push bx di
call getfatway
jc endload
mov di,offset fatway
mov si,offset dot
mov ah,13
loadagain:
mov cx,cs:[di]
cmp cx,0FFF0h
jae endload
add di,2
call readsector
jc endload
int 47h
add bx,cs:sizec
jmp loadagain
endload:
mov cx,bx
pop di bx
ret
sizec dw 512
reserv dw 1
;<-cx nøsecteur ->cx code FAT
getfat:
push es ax bx dx
mov ax,cx
xor dx,dx
div cs:sizec
mov cx,ax
add cx,cs:reserv
mov bx,offset buffer
push cs
pop es
call readsector
jc errorgetfat
shl dx,1
add bx,dx
mov cx,cs:[bx]
errorgetfat:
pop dx bx ax es
ret
logo db 'cos.rip',0
temp db 12+5+1 dup (0)
DiskSectorsPerTrack dw 18
DiskTracksPerHead dw 80
DiskHeads dw 2
fatway equ $
buffer equ $+5000
end start

514
lpt.asm Executable file
View File

@ -0,0 +1,514 @@
.model tiny
.486
smart
.code
org 0100h
start:
jmp tsr
db 'LPT'
Tsr:
cli
cmp ax,1234h
jne nomore
mov ax,4321h
jmp itsok
nomore:
push bx
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:
sti
iret
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
;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
call receivelptblock
pop ds cx bx ax
ret
;Re‡ois une commande et l'execute
Receivecommand:
push ax bx cx di es
push cs
pop es
mov di,offset command
call receivelptblock
mov bl,al
xor bh,bh
shl bx,1
add bx,offset cmd
call cs:[bx]
pop es di cx bx ax
ret
command db 25 dup (0)
cmd dw nothings
dw sendram
nothings:
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
;---------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
tokenstart equ 0
tokennext equ 1
tokenstop equ 2
tokenbad equ 3
tokenresend equ 4
Initlpt:
push ax ecx
call StartTimer
cmp 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
mov ecx,0
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
;Ralise un checksum 8 bits sur donnes DS:SI, nb CX rsultat dans dl
Checksum8:
push cx si
check:
add dl,[si]
inc si
dec cx
jnz check
pop si cx
ret
;DS:SI pointeur sur donnes, CX nombres de donnes, 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 donnes 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
end start

View File

@ -5,27 +5,27 @@ smart
org 0100h
start:
mov si,offset video
call searchfile
mov bx,8400h
mov es,bx
mov bx,100h
call loadfatway
mov di,bx
mov bx,47h
call setint
ret
mov bx,9
call getint
mov cs:int9seg,ds
mov cs:int9off,si
push cs
pop es
mov di,offset int9
call setint
mov ax,47h
call installhandler
mov si,offset lpt
mov bx,7400h
mov ax,49h
call installhandler
mov si,offset keyboard
mov bx,7000h
mov ax,9h
call replacehandler
mov si,offset timer
mov bx,7800h
mov ax,8h
call replacehandler
mov si,offset drive
mov bx,9000h
mov ax,48h
call installhandler
start2:
push cs
push cs
@ -53,9 +53,10 @@ int 47h
mov ah,6
int 47h
xor di,di
mov ax,0001h
mov bx,offset buffer
mov cx,13
call readsector
int 48h
xor bp,bp
showall:
cmp byte ptr [bx+di],0
@ -189,7 +190,7 @@ pop es cx bx
ret
loadfatway:
push bx cx di
push ax bx cx di
call getfatway
jc endload
mov di,offset fatway
@ -206,7 +207,7 @@ int 47h
add bx,cs:sizec
jmp loadagain
endload:
pop di cx bx
pop di cx bx ax
ret
sizec dw 512
@ -253,9 +254,9 @@ ret
xx dw 1
xxold dw 0
menu db 'F1 Read disk F2 Read file F9 Quit F11 Change video F12 Debug ',0
msg1 db 'Cos 2000 menu loader release 1.0',0
msg1 db ' Cos 2000 menu loader release 1.0',0
msg2 db 'The program is loading',0
msg3 db 'Cos will restart your computer, eject the floppy disk and press a key',0
msg3 db ' Cos will restart your computer, eject the floppy disk and press a key',0
prompt db '>',0
spaces db ' ',0
dot db '.',0
@ -297,6 +298,7 @@ Done:
pop si dx cx ax
ret
WriteSector:
push ax cx dx si
cmp cs:Lastread,cx
jne nodestruct
@ -333,8 +335,41 @@ Done2:
ret
Lastread dw 0FFFFh
WriteSector:
;remplace le handler pointer par ds:si en bx:100h interruption ax
replacehandler:
push ax bx si di ds es
mov es,bx
mov di,0100h
call loadfile
mov bx,ax
call getint
mov es:[102h],si
mov es:[104h],ds
call setint
pop es ds di si bx ax
ret
;install le handler pointer par ds:si en bx:100h interruption ax
installhandler:
push bx di es
mov es,bx
mov di,100h
call loadfile
mov bx,ax
call setint
pop es di bx
ret
;Charge le fichier Ds:si en es:di
loadfile:
push bx cx
call searchfile
mov bx,di
call loadfatway
pop cx bx
ret
;met es:di le handle de l'int bx
setint:
@ -352,188 +387,19 @@ ret
;met ds:si le handle de l'int bx
getint:
push ax bx es
cli
shl bx,2
xor ax,ax
mov es,ax
mov si,es:[bx]
mov ds,es:[bx+2]
pop es bx ax
sti
ret
int9off dw 0
int9seg dw 0
int9:
pushf
db 2eh,0ffh,1eh
dw int9off
cli
pusha
in al,60h
cmp cs:isstate,1
jne nostate
cmp al,57
jne nof12
mov cs:isstate,0
jmp noF12
nostate:
cmp al,87
jne NoF11
push es
push cs
pop es
mov di,offset infos
mov ah,34
int 47h
mov al,cs:infos+7
inc al
and ax,111b
int 47h
pop es
nof11:
cmp al,88
jne NoF12
mov ah,26
int 47h
call showstate
mov cs:isstate,1
sti
waitt:
cmp cs:isstate,0
jne waitt
mov ah,27
int 47h
noF12:
popa
sti
iret
isstate db 0
infos db 10 dup (0)
showstate:
push ds es
push ss
push gs
push fs
push es
push ds
push cs
pushad
pushfd
push cs
push cs
pop es
pop ds
mov ah,2
int 47h
mov ah,21
mov cl,4
int 47h
mov ah,13
mov si,offset reg
int 47h
mov ah,6
int 47h
mov ah,21
mov cl,7
int 47h
mov ah,13
mov si,offset fla
int 47h
pop edx
mov cx,32
mov ah,11
int 47h
mov ah,5
int 47h
mov ah,10
int 47h
mov si,offset regs
mov bx,8+6
mov ah,21
mov cl,6
int 47h
showallREG:
mov ah,6
int 47h
cmp bx,7
jb nodr
pop edx
jmp popo
nodr:
mov ah,21
mov cl,1
int 47h
xor edx,edx
pop dx
popo:
mov ah,13
int 47h
mov ah,10
mov cx,32
int 47h
mov ah,5
int 47h
push si
mov si,offset gr
mov ah,13
int 47h
mov ah,8
int 47h
mov si,offset dr
mov ah,13
int 47h
pop si
add si,5
dec bx
jnz showallreg
mov ah,34
mov di,offset infos
int 47h
mov ah,25
mov bl,cs:infos
xor bh,bh
dec bl
int 47h
mov si,offset app
mov ah,13
int 47h
mov ah,32
mov bl,cs:infos
xor bh,bh
mov di,ax
dec di
mov cl,116
int 47h
pop es ds
ret
reg db 'State of registers',0
fla db 'Flags:',0
regs db 'EDI:',0
db 'ESI:',0
db 'EBP:',0
db 'ESP:',0
db 'EBX:',0
db 'EDX:',0
db 'ECX:',0
db 'EAX:',0
db ' CS:',0
db ' DS:',0
db ' ES:',0
db ' FS:',0
db ' GS:',0
db ' SS:',0
gr db '(',0
dr db ')',0
app db 'Press space to quit...',0
;Recherchele fichier et retourne sont path et en cx sont debut
Searchfile:
push bx dx si di ds es
push cs
pop es
mov di,offset temp
mov bx,offset buffer
call asciiztofit
@ -674,7 +540,11 @@ extsize equ 5
nbfit equ 255
drive db 'drive.sys',0
timer db 'timer.sys',0
lpt db 'lpt.sys',0
video db 'video.sys',0
keyboard db 'keyboard.sys',0
temp db 12+5+1 dup (0)
DiskSectorsPerTrack dw 18

274
test.asm
View File

@ -1,274 +0,0 @@
.model tiny
.486
smart
.code
org 0100h
start:
go:
call calc
jmp go
ret
calc:
pusha
mov ah,2Ch
int 21h
mov bh,dh
xor ebp,ebp
wait2:
xor bl,bl
waits:
mov dx,3dah
in al,dx
and al,1000b
jz wait2
cmp bl,1
je waits
inc ebp
inc bl
cmp ebp,300
jne waits
mov ah,2Ch
int 21h
sub dh,bh
mov bl,dh
xor bh,bh
mov ax,bp
shr ebp,16
mov dx,bp
div bx
xor edx,edx
mov dx,ax
call showint
popa
ret
;===================================Afficher un int EDX a l'cran en ah,al================
ShowInt:
push eax bx cx edx esi di es ds
mov di,0
mov cx,0B800h
mov es,cx
xor cx,cx
mov eax,edx
mov esi,10
mov bx,offset showbuffer+27
decint3:
xor edx,edx
div esi
add dl,'0'
mov dh,cs:colors
sub bx,2
add cx,2
mov cs:[bx],dx
cmp ax,0
jne decint3
mov si,bx
push cs
pop ds
cld
rep movsb
pop ds es di esi edx cx bx eax
ret
showbuffer db 35 dup (0FFh)
colors equ 1
;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,01H,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,6H,7H,8H,9H,0AH,0BH,0CH,0DH,0EH,0FH
DB 0CH,00H,0FH,08H,00H
db 80,25
;80*50 16 couleurs
mode2 DB 67H, 00H, 03H,00H,03H,00H,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,00H,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
mode22 DB 067H , 00H, 03H,01H,03H,00H,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
Sequencer equ 03C4h
misc equ 03C2h
misc2 equ 03CCh
CCRT equ 03D4h
Attribs equ 03C0h
graphic equ 03CEh
statut equ 3DAh
;====Met les cl registres conscutif … ds:si du port dx
Setregs:
push ax
xor ax,ax
initreg:
mov ah,[si]
out dx,ax
inc al
inc si
cmp al,cl
jb initreg
pop ax
ret
;met une serie de registres Cl a partir du port dx
Setlowregs:
push ax bx
xor bx,bx
cmp cl,0
je only
initreg2:
mov al,bl
out dx,al
only:
mov al,[si]
out dx,al
inc bl
inc si
cmp bl,cl
jb initreg2
pop bx ax
ret
Setvideomode:
push ax cx dx si
xor ah,ah
mov si,ax
shl si,6
add si,offset mode0
xor cx,cx
mov dx,misc
call setlowregs
mov dx,statut
call setlowregs
mov dx,sequencer
mov cl,5
call setregs
mov ax,0E11h
mov dx,ccrt
out dx,ax
mov cl,25
call setregs
mov dx,graphic
mov cl,9
call setregs
mov dx,attribs
mov cl,20
call setlowregs
mov al,20h
out dx,al
pop dx cx ax si
ret
;====Met les cl registres conscutif … en es:DI du port dx TOUT REGISTRES
getregs:
push ax bx dx
xor bx,bx
cmp cl,0
je only2
initreg4:
mov al,bl
out dx,al
cmp dx,3C1h
je only2
inc dx
only2:
in al,dx
mov es:[di],al
dec dx
inc bl
inc di
cmp bl,cl
jb initreg4
pop dx bx ax
ret
;====Met le mode video present dans Es:di
getvideomode:
push ax cx dx di
xor cx,cx
mov dx,misc2
call getregs
mov dx,statut
call getregs
mov dx,sequencer
mov cl,5
call getregs
mov dx,ccrt
mov cl,25
call getregs
mov dx,graphic
mov cl,9
call getregs
mov dx,attribs
mov cl,20
call getregs
mov al,20h
out dx,al
pop di dx cx ax
ret
;mode scuris al
Safemode:
push cx si di ds es
call setvideomode
mov di,offset buffer
push cs
pop es
push cs
pop ds
call getvideomode
mov byte ptr es:[di+1],0
mov si,offset mode1
mov di,offset buffer
mov cx,62
rep cmpsb
jne errormode
clc
endsafe:
pop ds es di si cx
ret
errormode:
stc
jmp endsafe
buffer db 0
end start

32
timer.asm Executable file
View File

@ -0,0 +1,32 @@
.model tiny
.486
smart
.code
org 0100h
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

115
verif.asm
View File

@ -58,7 +58,8 @@ VerifAll:
mov si,offset Msg3
int 47h
call gauge
call verifysector
mov ah,2
int 48h
jc errors
je noprob
inc di
@ -147,116 +148,4 @@ max dw 2880
sizes dw 50
xy dw 0A12h
gaugetxt db 'ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ',0
Inverse:
mov si,512/4
invert:
shl si,2
not dword ptr [bx+si-4]
shr si,2
dec si
jnz invert
ret
VerifySector:
push bx cx si di ds es
push cs
pop es
push cs
pop ds
mov bx,offset buffer
call ReadSector
jc errorverify
call inverse
call WriteSector
jc errorverify
mov bx,offset buffer2
call ReadSector
call inverse
jc errorverify
mov bx,offset buffer
call inverse
call WriteSector
jc errorverify
mov cx,512/4
mov si,offset buffer
mov di,offset buffer2
cld
rep cmpsd
errorverify:
pop es ds di si cx bx
ret
ReadSector:
push ax cx dx si
mov AX, CX
xor DX, DX
div cs:DiskSectorsPerTrack
mov CL, DL ;{ Set the sector }
and CL, 63 ;{ Top two bits are bits 8&9 of the cylinder }
xor DX, DX
div cs:DiskTracksPerHead
mov CH, DL ;{ Set the track bits 0-7 }
mov AL, DH
ror AL, 1
ror AL, 1
and AL, 11000000b
or CL, AL ;{ Set bits 8&9 of track }
xor dX, DX
div cs:DiskHeads
mov DH, DL ;{ Set the head }
inc CL
mov SI, 4
TryAgain:
mov AL, 1
mov DL, 0
mov AH, 2
int 13h
jnc Done
dec SI
jnz TryAgain
Done:
pop si dx cx ax
ret
WriteSector:
push ax cx dx si
mov AX, CX
xor DX, DX
div cs:DiskSectorsPerTrack
mov CL, DL ;{ Set the sector }
and CL, 63 ;{ Top two bits are bits 8&9 of the cylinder }
xor DX, DX
div cs:DiskTracksPerHead
mov CH, DL ;{ Set the track bits 0-7 }
mov AL, DH
ror AL, 1
ror AL, 1
and AL, 11000000b
or CL, AL ;{ Set bits 8&9 of track }
xor DX, DX
div cs:DiskHeads
mov DH, DL ;{ Set the head }
inc CL
mov SI, 4
TryAgain2:
mov AL, 1
mov DL, 0
mov AH, 3
int 13h
jnc Done2
dec SI
jnz TryAgain2
Done2:
pop si dx cx ax
ret
DiskSectorsPerTrack dw 18
DiskTracksPerHead dw 80
DiskHeads dw 2
Buffer equ $
Buffer2 equ $+512
End Start

View File

@ -6,7 +6,8 @@ smart
org 0100h
start:
jmp tsr
db 'VIDEO'
Tsr:
cli
cmp ax,1234h
@ -185,7 +186,7 @@ mode1 DB 67H,00H, 03H,00H,03H,00H,02H
db 80,25
;80*50 16 couleurs
mode2 DB 67H, 00H, 03H,00H,03H,01H,02H
mode1b 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
@ -202,7 +203,6 @@ mode3 DB 067H,00H,03H,01H,03H,01H,02H
DB 0CH,00H,0FH,00H,00H
db 100,50
;100*60 16 couleurs
mode4b DB 067H,00H,03H,01H,03H,01H,02H
DB 70H,63H,64H,85H,68H,84H,0FFH,1FH,00H,47H,06H,07H,00H,00H,00H