string.asm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. .286
  2. .model small
  3. .code
  4. org 100h
  5. ;--------------------
  6. Black equ 0
  7. Blue equ 1
  8. Green equ 2
  9. Cyan equ 3
  10. Red equ 4
  11. Magenta equ 5
  12. Brown equ 6
  13. LightGray equ 7
  14. DarkGray equ 8
  15. LightBlue equ 9
  16. LightGreen equ 10
  17. LightCyan equ 11
  18. LightRed equ 12
  19. LightMagenta equ 13
  20. Yellow equ 14
  21. White equ 15
  22. ; Color Defenition
  23. FileColor equ 128
  24. FileBg equ 22
  25. ;--------------------
  26. start:
  27. mov ax, 1130h
  28. mov bh, 06h
  29. int 10h
  30. mov FontSeg, es
  31. mov FontOffs, bp
  32. mov ax, 13h
  33. int 10h
  34. mov ax, 3d00h
  35. mov dx, offset fname
  36. int 21h
  37. jc MainEnd
  38. mov bx, ax
  39. mov ah, 3fh
  40. mov cx, 1f8h
  41. mov dx, offset buf
  42. int 21h
  43. cmp ax, 0
  44. je FileEnd
  45. mov cx, ax
  46. mov di, dx
  47. ReadChar:
  48. mov ah, 0
  49. mov al, byte ptr [di]
  50. cmp al, 0dh
  51. jne writenorm
  52. inc di
  53. cmp byte ptr [di], 0ah
  54. jne NewLine
  55. inc di
  56. dec cx
  57. jmp NewLine
  58. writenorm:
  59. push charx
  60. push chary
  61. push ax
  62. push filecolor
  63. push filebg
  64. push fontoffs
  65. push fontseg
  66. Call OutCharXY
  67. inc di
  68. cmp charX, 39
  69. jne VeryGood
  70. cmp byte ptr [di], 0Dh
  71. loope ReadChar
  72. jmp FileEnd
  73. VeryGood:
  74. inc charX
  75. loop ReadChar
  76. jmp FileEnd
  77. NewLine:
  78. cmp charY, 11
  79. je FileEnd
  80. inc charY
  81. mov charX, 0
  82. loop ReadChar
  83. FileEnd:
  84. mov ah,3eh
  85. int 21h
  86. MainEnd:
  87. mov ah, 8h ; ReadKey
  88. int 21h ;
  89. mov ax, 3h ;
  90. int 10h ; Set Text mode
  91. int 20h ; Quit
  92. ;---------------------------------------------
  93. OutCharXY proc near ;OutCharXY(X,Y,Char,Color,bg,TableOffs,TableSeg)
  94. push bp
  95. mov bp, sp
  96. TableSeg equ word ptr [bp+4]
  97. TableOffs equ word ptr [bp+6]
  98. Color equ byte ptr [bp+10]
  99. Bg equ byte ptr [bp+8]
  100. Char equ byte ptr [bp+12]
  101. posY equ word ptr [bp+14]
  102. posX equ word ptr [bp+16]
  103. pusha
  104. push es
  105. ;----------------------------
  106. ; Character Creation
  107. mov di, TableOffs
  108. mov es, TableSeg
  109. mov ah, 0
  110. mov al, Char
  111. shl ax, 4
  112. add di, ax
  113. mov cx, 16
  114. mov si, offset face
  115. MainLoop:
  116. mov bh, es:di
  117. push cx
  118. mov cx, 8
  119. LineLoop:
  120. test bh, 80h
  121. jz BackGround
  122. mov ah, Color
  123. mov byte ptr ds:[si], ah
  124. jmp LoopEnd
  125. BackGround:
  126. mov ah, Bg
  127. mov byte ptr ds:[si], ah
  128. LoopEnd:
  129. shl bh, 1
  130. inc si
  131. loop LineLoop
  132. pop cx
  133. inc di
  134. loop MainLoop
  135. ; End of Character creation
  136. ;=======================================
  137. mov ax, posX
  138. shl ax, 3
  139. push ax ; X position
  140. mov ax, posY
  141. shl ax, 4
  142. push ax ; Y position
  143. push offset face ; Character bitmap
  144. push 8 ; SizeX
  145. push 16 ; SizeY
  146. call WriteSprite ; WriteChar
  147. pop es
  148. popa
  149. pop bp
  150. ret 14
  151. endp
  152. ;-------------------------------------------
  153. WriteSprite proc near ;writesprite(x,y,char *sprt,razmx,razmy)
  154. push bp
  155. mov bp,sp
  156. razmy equ word ptr [bp+4]
  157. razmx equ word ptr [bp+6]
  158. sprt equ word ptr [bp+8]
  159. posy equ word ptr [bp+10]
  160. posx equ word ptr [bp+12]
  161. pusha
  162. push es
  163. mov ax, 0A000h
  164. mov es, ax
  165. mov ax, posy
  166. mov bx, ax
  167. shl ax, 8
  168. shl bx, 6
  169. add ax, bx
  170. add ax, posx
  171. mov di, ax
  172. mov ax, sprt
  173. mov si, ax
  174. mov cx, razmy
  175. lup:
  176. push cx
  177. mov cx, razmx
  178. repe movsb
  179. add di, 320
  180. sub di,razmx
  181. pop cx
  182. loop lup
  183. pop es
  184. popa
  185. pop bp
  186. ret 10
  187. endp
  188. face db 128 dup (?)
  189. FontOffs dw ?
  190. FontSeg dw ?
  191. fname db 'colors.txt'
  192. charx dw 0
  193. chary dw 0
  194. buf db 1f8h dup (?)
  195. end start