Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PARA_SIZE equ 16
- format MZ
- stack 4096 ; This code works only if stack < 65536
- ; Stack should always be an even number
- entry GDOS_MAINSEG:GDOS_KERNEL_START
- ERR_SUCCESS equ 0
- ERR_RESIZE_PRG equ 1
- ERR_OPEN_DRVR equ 2
- ERR_READ_DRVR_HDR equ 3
- ERR_SEEK_DRVR_BEG equ 4
- ERR_ALLOC_DRVR_MEM equ 5
- ERR_READ_DRVR equ 6
- segment GDOS_MAINSEG
- GDOS_KERNEL_START: ; Punkt startowy jĄdra / Kernel start point
- ; At entry DS and ES point to PSP that starts program block
- mov cx, ds ; CX = segment of PSP and beginning of program
- ; memory block
- push cs
- pop ds
- ; Determine segment just beyond stack. Resize down to that point
- mov ax, sp ; Get current stack pointer
- add ax, PARA_SIZE-1 ; Add 15 to round up to nearest paragraph
- shr ax, 4 ; Divide offset by 16 to get paragraphs
- push ss
- pop bx ; BX = segment at start of stack
- add bx, ax ; BX = segment just past end of stack
- sub bx, cx ; BX = number of paragraphs from
- ; start of program memory
- ; ES already points at PSP block
- init: ;Inicjujemy GDOS
- mov ah,0x4a
- int 0x21 ; Resize program memory
- mov byte [ErrorCode], ERR_RESIZE_PRG
- jc exit_error
- mov dx,DrvString0
- call far GDOS_MAINSEG:gdosLoadDriverDOS
- cmp byte [ErrorCode], 0
- jnz exit_error ; If there was an error don't make calls to driver & exit
- call far GDOS_MAINSEG:gdosSetModeByID
- jmp exit ; Exit without error
- exit_error:
- ; Print error string based on ErrorCode
- mov ah, 9
- mov dx, ErrorStr
- int 0x21 ; Print "error: "
- mov bh, 0
- mov bl, [ErrorCode]
- dec bl
- shl bx, 1 ; Convert ErrorCode to Error table index
- mov dx, [ErrorTable+bx]
- int 0x21 ; Print error string for ErrorCode
- exit:
- mov ah, 0x4c ; Exit program with error or 0=success
- mov al, [ErrorCode]
- int 0x21
- GDOS_KERNEL_DATA:
- DrvString0 : db 'VGA.BIN',0 ;Nazwa pliku dla sterownika VGA / Filename for VGA driver
- FileOpened : db 0
- ErrorCode : db 0
- ErrorStr : db "Error: $"
- ErrorResize : db "can't resize program$"
- ErrorOpen : db "can't open driver$"
- ErrorRdHdr : db "can't read driver header$"
- ErrorSeekBeg : db "can't seek to beginning of driver$"
- ErrorAllocDrv: db "can't allocate memory for driver$"
- ErrorRdDrvr : db "can't read driver$"
- ErrorTable : dw ErrorResize, ErrorOpen, ErrorRdHdr, ErrorSeekBeg
- dw ErrorAllocDrv, ErrorRdDrvr
- GraphicsDriver: dw 0x0
- g3:
- dw 0,0
- dw 0,0
- DriverDeletionBuffer: TIMES 16 db 0
- ; Buffer to hold the driver header
- DriverHeaderBuffer: TIMES 16 db 0
- RecommendedDriverPosition: db 0
- GDOS_KERNEL_FUNC:
- gdosLoadDriverDOS: ;Funkcja adujĄca sterownik za pomocĄ DOS-a / Function loading driver with DOS
- push ds
- push es
- ; Open VGA driver file
- mov ax,0x3d00
- mov cl,0x0
- int 0x21
- mov byte [ErrorCode], ERR_OPEN_DRVR
- jc end_gdosLoadDriverDOS
- ; Read the Drive header buffer
- mov si,ax ;Zapisz uchwyt / Save handle
- mov byte [FileOpened], 1
- mov ah,0x3f
- mov cx,16
- mov bx,si
- mov dx, DriverHeaderBuffer
- int 0x21
- mov byte [ErrorCode], ERR_READ_DRVR_HDR
- jc end_gdosLoadDriverDOS
- ; Seek back to beginning of file
- mov ah,0x42
- mov al,0x00
- mov cx,0
- mov dx,0
- int 0x21
- mov byte [ErrorCode], ERR_SEEK_DRVR_BEG
- jc end_gdosLoadDriverDOS
- ; Allocate memory to hold complete driver
- ; The size of the driver is second word in header
- mov ah,0x48
- mov bx,[DriverHeaderBuffer+0x2]
- mov cx,bx
- add bx, PARA_SIZE-1
- ; Add 15 to round up to nearest paragraph
- shr bx,4
- int 0x21
- mov byte [ErrorCode], ERR_ALLOC_DRVR_MEM
- jc end_gdosLoadDriverDOS
- ; DS=ES=segment of driver
- mov es,ax
- mov ds,ax
- ; Read the driver into memory
- mov bx,si
- mov dx,0
- mov ah,0x3f
- int 0x21
- mov byte [ErrorCode], ERR_READ_DRVR
- jc end_gdosLoadDriverDOS
- ; Update the FAR pointer in driver header
- mov [0x2],es
- mov bx,0x0
- ; Call the driver entry point
- call far [bx]
- push cs
- pop ds
- mov bx,g3
- mov [bx+2],es
- mov byte [ErrorCode], ERR_SUCCESS
- end_gdosLoadDriverDOS:
- ; Close the file if it was opened
- cmp byte [FileOpened], 1
- jne end_gdos_NoClose
- mov bx, si
- int 0x3e
- end_gdos_NoClose:
- pop es
- pop ds
- retf
- gdosSetModeByID:
- push es
- push ds
- push cs
- pop ds
- mov bx,g3
- mov ax,[GraphicsDriver]
- shl ax,2
- add bx,ax
- mov di,[bx+2]
- mov es,di
- mov di,[es:11]
- sub sp,4
- mov bp,sp
- mov [ss:bp],di
- mov [ss:bp+2],es
- call far [ss:bp]
- add sp,4
- pop ds
- pop es
- retf
- GDOS_KERNEL_END:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement