Advertisement
MichaelPetch

GDOS.ASM

Jun 30th, 2019
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.48 KB | None | 0 0
  1. PARA_SIZE equ 16
  2.  
  3. format MZ
  4. stack 4096 ; This code works only if stack < 65536
  5. ; Stack should always be an even number
  6.  
  7. entry GDOS_MAINSEG:GDOS_KERNEL_START
  8.  
  9. ERR_SUCCESS equ 0
  10. ERR_RESIZE_PRG equ 1
  11. ERR_OPEN_DRVR equ 2
  12. ERR_READ_DRVR_HDR equ 3
  13. ERR_SEEK_DRVR_BEG equ 4
  14. ERR_ALLOC_DRVR_MEM equ 5
  15. ERR_READ_DRVR equ 6
  16.  
  17. segment GDOS_MAINSEG
  18. GDOS_KERNEL_START: ; Punkt startowy jĄdra / Kernel start point
  19. ; At entry DS and ES point to PSP that starts program block
  20. mov cx, ds ; CX = segment of PSP and beginning of program
  21. ; memory block
  22. push cs
  23. pop ds
  24.  
  25. ; Determine segment just beyond stack. Resize down to that point
  26. mov ax, sp ; Get current stack pointer
  27. add ax, PARA_SIZE-1 ; Add 15 to round up to nearest paragraph
  28. shr ax, 4 ; Divide offset by 16 to get paragraphs
  29. push ss
  30. pop bx ; BX = segment at start of stack
  31. add bx, ax ; BX = segment just past end of stack
  32. sub bx, cx ; BX = number of paragraphs from
  33. ; start of program memory
  34. ; ES already points at PSP block
  35. init: ;Inicjujemy GDOS
  36. mov ah,0x4a
  37. int 0x21 ; Resize program memory
  38. mov byte [ErrorCode], ERR_RESIZE_PRG
  39. jc exit_error
  40.  
  41. mov dx,DrvString0
  42. call far GDOS_MAINSEG:gdosLoadDriverDOS
  43. cmp byte [ErrorCode], 0
  44. jnz exit_error ; If there was an error don't make calls to driver & exit
  45. call far GDOS_MAINSEG:gdosSetModeByID
  46. jmp exit ; Exit without error
  47.  
  48. exit_error:
  49. ; Print error string based on ErrorCode
  50. mov ah, 9
  51. mov dx, ErrorStr
  52. int 0x21 ; Print "error: "
  53. mov bh, 0
  54. mov bl, [ErrorCode]
  55. dec bl
  56. shl bx, 1 ; Convert ErrorCode to Error table index
  57. mov dx, [ErrorTable+bx]
  58. int 0x21 ; Print error string for ErrorCode
  59.  
  60. exit:
  61. mov ah, 0x4c ; Exit program with error or 0=success
  62. mov al, [ErrorCode]
  63. int 0x21
  64.  
  65. GDOS_KERNEL_DATA:
  66. DrvString0 : db 'VGA.BIN',0 ;Nazwa pliku dla sterownika VGA / Filename for VGA driver
  67. FileOpened : db 0
  68. ErrorCode : db 0
  69. ErrorStr : db "Error: $"
  70. ErrorResize : db "can't resize program$"
  71. ErrorOpen : db "can't open driver$"
  72. ErrorRdHdr : db "can't read driver header$"
  73. ErrorSeekBeg : db "can't seek to beginning of driver$"
  74. ErrorAllocDrv: db "can't allocate memory for driver$"
  75. ErrorRdDrvr : db "can't read driver$"
  76. ErrorTable : dw ErrorResize, ErrorOpen, ErrorRdHdr, ErrorSeekBeg
  77. dw ErrorAllocDrv, ErrorRdDrvr
  78.  
  79. GraphicsDriver: dw 0x0
  80.  
  81. g3:
  82. dw 0,0
  83. dw 0,0
  84.  
  85. DriverDeletionBuffer: TIMES 16 db 0
  86. ; Buffer to hold the driver header
  87. DriverHeaderBuffer: TIMES 16 db 0
  88. RecommendedDriverPosition: db 0
  89.  
  90. GDOS_KERNEL_FUNC:
  91. gdosLoadDriverDOS: ;Funkcja adujĄca sterownik za pomocĄ DOS-a / Function loading driver with DOS
  92. push ds
  93. push es
  94.  
  95. ; Open VGA driver file
  96. mov ax,0x3d00
  97. mov cl,0x0
  98. int 0x21
  99. mov byte [ErrorCode], ERR_OPEN_DRVR
  100. jc end_gdosLoadDriverDOS
  101.  
  102. ; Read the Drive header buffer
  103. mov si,ax ;Zapisz uchwyt / Save handle
  104. mov byte [FileOpened], 1
  105. mov ah,0x3f
  106. mov cx,16
  107. mov bx,si
  108. mov dx, DriverHeaderBuffer
  109. int 0x21
  110. mov byte [ErrorCode], ERR_READ_DRVR_HDR
  111. jc end_gdosLoadDriverDOS
  112.  
  113. ; Seek back to beginning of file
  114. mov ah,0x42
  115. mov al,0x00
  116. mov cx,0
  117. mov dx,0
  118. int 0x21
  119. mov byte [ErrorCode], ERR_SEEK_DRVR_BEG
  120. jc end_gdosLoadDriverDOS
  121.  
  122. ; Allocate memory to hold complete driver
  123. ; The size of the driver is second word in header
  124. mov ah,0x48
  125. mov bx,[DriverHeaderBuffer+0x2]
  126. mov cx,bx
  127. add bx, PARA_SIZE-1
  128. ; Add 15 to round up to nearest paragraph
  129. shr bx,4
  130. int 0x21
  131. mov byte [ErrorCode], ERR_ALLOC_DRVR_MEM
  132. jc end_gdosLoadDriverDOS
  133.  
  134. ; DS=ES=segment of driver
  135. mov es,ax
  136. mov ds,ax
  137. ; Read the driver into memory
  138. mov bx,si
  139. mov dx,0
  140. mov ah,0x3f
  141. int 0x21
  142. mov byte [ErrorCode], ERR_READ_DRVR
  143. jc end_gdosLoadDriverDOS
  144.  
  145. ; Update the FAR pointer in driver header
  146. mov [0x2],es
  147. mov bx,0x0
  148. ; Call the driver entry point
  149. call far [bx]
  150. push cs
  151. pop ds
  152. mov bx,g3
  153. mov [bx+2],es
  154. mov byte [ErrorCode], ERR_SUCCESS
  155.  
  156. end_gdosLoadDriverDOS:
  157. ; Close the file if it was opened
  158. cmp byte [FileOpened], 1
  159. jne end_gdos_NoClose
  160. mov bx, si
  161. int 0x3e
  162.  
  163. end_gdos_NoClose:
  164. pop es
  165. pop ds
  166. retf
  167.  
  168. gdosSetModeByID:
  169. push es
  170. push ds
  171.  
  172. push cs
  173. pop ds
  174.  
  175. mov bx,g3
  176. mov ax,[GraphicsDriver]
  177. shl ax,2
  178. add bx,ax
  179.  
  180. mov di,[bx+2]
  181. mov es,di
  182.  
  183. mov di,[es:11]
  184.  
  185. sub sp,4
  186. mov bp,sp
  187. mov [ss:bp],di
  188. mov [ss:bp+2],es
  189. call far [ss:bp]
  190.  
  191. add sp,4
  192. pop ds
  193. pop es
  194. retf
  195.  
  196. GDOS_KERNEL_END:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement