On-screen clock for DOS

A clock that runs in the background in a DOS system and display the system time while it's operational.

As I remember I used either Microsoft Assembler or Turbo Assembler to compile this code. Program make use of a technology called ”Terminate and Stay Resident” (TSR) which was used by many applications those days to emulate multi-tasking in DOS.

clock.asm
  1. ;Clock,  Version 2.00
  2. ;Created 05/20/1999
  3. include mac_main.lib
  4. assume	cs:code,ds:code,es:code,ss:code
  5.  
  6. code	segment
  7.         org	100h
  8.  
  9. start	proc
  10.  
  11. do:	initialize
  12. 	mov	si,81h
  13. 	mov	al,[si]
  14. 	cmp	al,'/'
  15. 	jnz	nopa
  16. 	inc	si
  17. 	mov	al,[si]
  18. 	cmp	al,'?'
  19. 	jz	hl
  20. 	cmp	al,'U'
  21. 	jz	ul
  22. 	cmp	al,'u'
  23. 	jz	ul
  24. 	print	ivmsg
  25. 	jmp	finish
  26.  
  27. hl:	print	hlmsg
  28. 	jmp	finish
  29.  
  30. ul:	call	lodchk
  31. 	cmp	ax,0h
  32. 	jnz	nolod
  33. 	call	unload
  34. 	print	ulmsg
  35. 	jmp	finish
  36.  
  37. nopa:	call	lodchk
  38. 	cmp	ax,0h
  39. 	jz	loded
  40. 	xor	ax,ax
  41. 	mov	ds,ax
  42. 	mov	si,70h
  43. 	mov	di,offset	oldisr
  44. 	mov	ax,[si]
  45. 	mov	cs:[di],ax
  46. 	mov	ax,[si+2]
  47. 	mov	cs:[di+2],ax
  48. 	mov	si,413h
  49. 	mov	ax,[si]
  50. 	sub	ax,1h
  51. 	mov	[si],ax
  52. 	mov	cl,6h
  53. 	shl	ax,cl
  54. 	mov	es,ax
  55. 	push	cs
  56. 	pop	ds
  57. 	mov	si,offset	clockproc
  58. 	xor	di,di
  59. 	mov	cx,((offset	idvmsg)-(offset	clockproc))/2
  60. 	cld
  61. 	rep	movsw
  62. 	xor	ax,ax
  63. 	mov	ds,ax
  64. 	mov	si,70h
  65. 	mov	[si],ax
  66. 	mov	[si+2],es
  67. 	jmp	finish
  68.  
  69. nolod:	print	nlmsg
  70. 	jmp	finish
  71.  
  72. loded:	print	almsg
  73.  
  74. finish:	close
  75. start   endp
  76.  
  77. unload	proc
  78. 	push	ax
  79. 	push	ds
  80. 	push	si
  81. 	push	cx
  82. 	push	es
  83. 	push	di
  84. 	xor	ax,ax
  85. 	mov	ds,ax
  86. 	mov	si,413h
  87. 	mov	ax,[si]
  88. 	push	ax
  89. 	mov	cl,6h
  90. 	shl	ax,cl
  91. 	mov	es,ax
  92. 	pop	ax
  93. 	inc	ax
  94. 	mov	[si],ax
  95. 	mov	si,70h
  96. 	mov	di,(offset	oldisr)-(offset	clockproc)
  97. 	mov	ax,es:[di]
  98. 	mov	[si],ax
  99. 	mov	ax,es:[di+2]
  100. 	mov	[si+2],ax
  101. 	xor	ax,ax
  102. 	xor	di,di
  103. 	mov	cx,((offset	idvmsg)-(offset	clockproc))/2
  104. 	cld
  105. 	rep	stosw
  106. 	push	cs
  107. 	pop	ds
  108.         mov     ax,0b800h
  109.         mov     es,ax
  110.         mov     si,offset   msg2
  111.         mov     di,8ch
  112.         mov     cx,0ah
  113. 	cld
  114. 	rep	movsw
  115. 	pop	di
  116. 	pop	es
  117. 	pop	cx
  118. 	pop	si
  119. 	pop	ds
  120. 	pop	ax
  121. 	ret
  122. unload	endp
  123.  
  124. lodchk	proc
  125. 	push	cx
  126. 	push	di
  127. 	push	si
  128. 	push	ds
  129. 	push	es
  130. 	xor	ax,ax
  131. 	mov	ds,ax
  132. 	mov	si,413h
  133. 	mov	ax,[si]
  134. 	mov	cl,6h
  135. 	shl	ax,cl
  136. 	mov	es,ax
  137. 	push	cs
  138. 	pop	ds
  139. 	xor	di,di
  140. 	mov	si,offset	clockproc
  141. 	mov	cx,(offset	msg)-(offset	clockproc)
  142. 	cld
  143. 	rep	cmpsb
  144. 	mov	ax,cx
  145. 	pop	es
  146. 	pop	ds
  147. 	pop	si
  148. 	pop	di
  149. 	pop	cx
  150. 	ret
  151. lodchk	endp
  152.  
  153. clockproc   proc    far
  154. 	push    ax
  155.         push    es
  156.         push    si
  157.         push    di
  158.         push    cx
  159. 	push	cs
  160. 	pop	ds
  161.         mov     ax,0b800h
  162.         mov     es,ax
  163.         mov     si,(offset   msg)-(offset	clockproc)
  164.         mov     di,8ch
  165.         mov     cx,0ah
  166.         mov    al,0h
  167.         out    70h,al
  168.         in     al,71h
  169.         byte2asc       al,tstr
  170.         mov    ah,tstr[0]
  171.         mov    [si+14],ah
  172.         mov    ah,tstr[1]
  173.         mov    [si+16],ah
  174.         mov    al,2h
  175.         out    70h,al
  176.         in     al,71h
  177.         byte2asc       al,tstr
  178.         mov    ah,tstr[0]
  179.         mov    [si+8],ah
  180.         mov    ah,tstr[1]
  181.         mov    [si+10],ah
  182.         mov    al,4h
  183.         out    70h,al
  184.         in     al,71h
  185.         byte2asc       al,tstr
  186.         mov    ah,tstr[0]
  187.         mov    [si+2],ah
  188.         mov    ah,tstr[1]
  189.         mov    [si+4],ah
  190.         cld
  191.         rep     movsw
  192.         pop     cx
  193.         pop     di
  194.         pop     si
  195.         pop     es
  196.         pop     ax
  197.         iret
  198. clockproc   endp
  199.  
  200. attr	equ	3eh
  201. msg	db  ' ',attr,'X',attr,'X',attr,':',attr,'X',attr,'X',attr
  202. 	db  ':',attr,'X',attr,'X',attr,' ',attr
  203. tstr	db  'XX'
  204. oldisr	dw	?
  205. 	dw	?
  206. crnote	db	'Clock,  Version 2.00',0ah,0dh
  207.         db  	'Copyright (c) Sudaraka Wijesinghe 1999.',0ah,0dh,24h
  208. idvmsg  db  	'This program requiers DOS version 5.00 or later.',0ah,0dh,24h
  209. ulmsg	db	0ah,0dh,'Clock Unloaded.',0ah,0dh,24h
  210. hlmsg	db	0ah,0dh,'USAGE: SC2[/?][/U]',0ah,0dh,0ah,0dh
  211. 	db	'Without any parameter loads the clock,',0ah,0dh
  212. 	db	'	/? - Display this help screen.',0ah,0dh
  213. 	db	'	/U - Unload the clock.',0ah,0dh,0ah,0dh
  214. 	db	'	   Clock is a program that display the system time in DOS mode.',0ah,0dh
  215. 	db	'After the clock is loaded successfully you''ll see a digital clock on the top',0ah,0dh
  216. 	db	'right hand corner of your computers screen.',0ah,0dh,24h
  217. ivmsg	db	0ah,0dh,'Invalid parameter.',0ah,0dh,24h
  218. almsg	db	0ah,0dh,'Clock is already loaded.',0ah,0dh,24h
  219. nlmsg	db	0ah,0dh,'Clock is not loaded.',0ah,0dh,24h
  220. msg2	db	' ',1fh,' ',1fh,' ',1fh,'D',1fh,'i',1fh,'n',1fh,'o',1fh,' ',1fh
  221. 	db	' ',1fh,' ',1fh
  222.  
  223. code	ends
  224.         end	start