Advertisement
Mysoft

Untitled

Jun 22nd, 2016
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cpu 286
  2. org 100h
  3.  
  4. RowSz  equ 80
  5. BankSz equ 8192
  6.  
  7. %define _FontSeg 0xCCCC
  8. %define _FontPtr 0x9090
  9.  
  10. %define _DrawRow bp+(6+18+0)
  11. %define _DrawCol bp+(6+18+2)
  12. %define _TextSeg bp+(6+18+4)
  13. %define _TextPtr bp+(6+18+6)
  14. %define _TextLen bp+(6+18+8)
  15.  
  16. section .text
  17. DrawString:    
  18.     pusha
  19.     push ds
  20.     push es
  21.    
  22. ;-----------------------------------------------------------------------------------------
  23.     call SelfPtr             ;\
  24. SelfPtr:                     ;<PIPE>
  25.     pop bx                   ;<PIPE>
  26.     sub bx, SelfPtr          ;<PIPE> auto fix-up pointers...
  27.     add [cs:bx+SelfW1-2],bx  ;<PIPE>        
  28.     add [cs:bx+SelfW2-2],bx  ;<PIPE>
  29.     add [cs:bx+SelfW3-3],bx  ;<PIPE>
  30.     add [cs:bx+SelfW4-3],bx  ;/
  31.     mov word [cs:bx+SelfPtr-3],(((Start-SelfPtr)*256)+0E9h) ; Call SelfPtr -> Jmp Start
  32. ;-----------------------------------------------------------------------------------------
  33.  
  34. Start: 
  35.     mov ax,[_DrawRow] ; Get Start ROW
  36.     mov bx, ax        ; \
  37.     shl ax, 8         ; <PIPE> BX = ROWS*RowSz*4
  38.     shl bx, 6         ; <PIPE> ( 320 = 2^8 + 2^6 )
  39.     add bx, ax        ; /
  40.     mov ax,[_DrawCol] ; Get Start COLUMN
  41.     mov cl, al        ; copy Of COL
  42.     and cl, 3         ; which mode it starts?
  43.     add cl, cl        ; start of shift2
  44.     mov ch, 8         ; start of shift1 is..
  45.     sub ch, cl        ; 8-shift2...
  46.     mov byte [CS:SelfModB1-1], ch ;self-mod "shr bh, #"
  47. SelfW1:
  48.     mov si, ax        ; another copy for start offset
  49.     add si, si        ; 2 bytes per char
  50.     shr ax, 2         ; minus 1 byte
  51.     add si, ax        ; for each 4 characters...
  52.        
  53.     mov es,[_TextSeg] ;ES = text source segment
  54.     mov di,[_TextPtr] ;ES:DI = text source (could be CS/ES for multisegment)
  55.     mov ch,[_TextLen] ;CH = text length
  56. ; ## NO MORE LOCAL VARIABLES AFTER THIS POINT ###########################################
  57.     lea bp,[si+bx]    ;SS:BP screen target (for BP relative)   
  58.     mov dx,BankSz     ;Switch Between Banks or between liens (alternates)  
  59.     push SS           ;Save current stack segment on stack
  60.     pop word [CS:SelfModW1-2] ;And pop it on self-modified var for restoration
  61. SelfW2:
  62.     mov ax,_FontSeg   ; font segment (Modified on ARRAY)
  63. ModW1: 
  64.     mov ds,ax         ; DS = Font Segment
  65.     mov ax,0xB800     ; SS = screen target
  66.     cli               ; Disabling interrupts because SS will be modified
  67.     mov ss,ax         ; and screen becomes SS (for bp+ usage)  
  68.  
  69. NextChar:
  70.     dec ch            ; Any chars remaining?
  71.     js DoneDraw       ; No? then it's done...
  72.     xor bx,bx         ; clear BX (for byte->word cast)
  73.     mov bl,[es:di]    ; BL = next char
  74.     inc di            ; point to next source char :)
  75.     shl bx, 4         ; 16 bits * 8 rows = 16bytes
  76.     lea si,[bx+_FontPtr] ; DS:SI font (for lodsw) (Modified on ARRAY)
  77. ModW2:
  78.    
  79.     mov bl,8          ; 8 rows
  80. DrawChar:
  81.     lodsw             ; read a char line (16 bits)
  82.     mov bh,ah         ; need part of it for a byte
  83.     shr bh,7          ; shr by 8,6,4,2 (self-modified...)
  84. SelfModB1:
  85.     jz SkipByte       ; the result is 0? so no pixels to set
  86.     or [bp-1],bh      ; merge with screen
  87. SkipByte:
  88.     shl ax,cl         ; shl by 0,2,4,6 (0 ignores flags)
  89.     test ax,ax
  90.     jz SkipWord       ; the result is 0? so no pixels to set    
  91.     xchg ah,al        ; must change endian...
  92.     or [bp],ax        ; and merge with screen
  93. SkipWord:
  94.     add bp, dx        ; change to next line
  95.     xor dx, ((-BankSz)^BankSz)+RowSz   ; line/block swap
  96.     dec bl            ; one line done, there's more?
  97.     jnz DrawChar      ; yes, go draw them
  98. AfterChar: 
  99.     sub bp,RowSz*4-2  ; adjust to next char
  100.     add cl, 2         ; \ 0 -> 2 -> 4 -> 6 -> 0 ...
  101.     and cl, 7         ; /
  102.     sub byte [CS:SelfModB1-1], 2 ; 8 -> 6 -> 4 -> 2 -> 8 ...
  103. SelfW3:
  104.     jnz NextChar      ; process next char if not wrapped
  105.     mov byte [CS:SelfModB1-1], 8 ; ^ wrap back to 8
  106. SelfW4:
  107.     dec bp            ; when register wrap adjust offset 2,2,2,1
  108.     jmp NextChar      ; process next char
  109.  
  110. DoneDraw:
  111.     mov ax, 0000h     ; Self-modified (old SS)
  112. SelfModW1:
  113.     mov ss,ax         ; Restore SS
  114.     sti               ; Can enable interrupts now
  115.  
  116.     pop es
  117.     pop ds
  118.     popa
  119.     retf
  120.    
  121.     ;%assign Fixup1 ((SelfW1-2)-$$)
  122.     ;%assign Fixup2 ((SelfW2-2)-$$)
  123.     ;%assign Fixup3 ((SelfW3-3)-$$)
  124.     ;%assign Fixup4 ((SelfW4-3)-$$)
  125.     ;%warning word in offset Fixup1 need fixup on QB
  126.     ;%warning word in offset Fixup2 need fixup on QB
  127.     ;%warning word in offset Fixup3 need fixup on QB
  128.     ;%warning word in offset Fixup4 need fixup on QB
  129.     %assign SegSet1 ((ModW1-2)-$$)
  130.     %assign SegPtr1 ((ModW2-2)-$$)
  131.     %warning word in offset SegSet1 must be set to FONT varseg on QB
  132.     %warning word in offset SegPtr1 must be set to FONT varptr on QB
  133.    
  134. section .data
  135. msg     db "Hello World! ",1,32,3,4,5,6,13,14
  136. font    incbin  "DUNGEOLB.FNT",7
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement