Advertisement
Ham62

DrawRect.ASM

Jan 30th, 2017
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ORG 0h
  2.  
  3. %define _ScreenWidth 80
  4.  
  5. %define _ParamOffset (4+16+2+2) ;(CS/IP)+PUSHA+ES+DS
  6.  
  7. %define _RectX    BP+_ParamOffset+12
  8. %define _RectY    BP+_ParamOffset+10
  9. %define _RectWid  BP+_ParamOffset+8
  10. %define _RectHei  BP+_ParamOffset+6
  11. %define _TxtBlock BP+_ParamOffset+4
  12. %define _BuffSeg  BP+_ParamOffset+2
  13. %define _BuffAddr BP+_ParamOffset+0
  14.  
  15. Start:
  16.     PUSHA    ;16 bytes
  17.     PUSH ES  ;2 bytes
  18.     PUSH DS  ;2 bytes
  19.     MOV BP, SP
  20.  
  21.                               ;Start pos on buffer is [RectX + (RectY*ScreenWidth)] << 1
  22.     MOV BX, WORD [_RectY]     ;Get RectY
  23.     IMUL AX, BX, _ScreenWidth ;Multiply by ScreenWidth and store result in AX
  24.     ADD AX, WORD [_RectX]     ;Add RectX
  25.     SHL AX, 1                 ;2 bytes per character block
  26.     MOV DI, WORD [_BuffAddr]  ;Set DI to start of buffer
  27.     ADD DI, AX                ;DI is now top left corner of rectangle
  28.  
  29.     MOV CH, BYTE [_RectHei]   ;Counter for drawing rows
  30.     MOV CL, BYTE [_RectWid]   ;Counter for position in row
  31.  
  32.     MOV DX, _ScreenWidth      ;How much to add to get to next line
  33.     SUB DL, CL                ;DL = ScreenWidth - RectWid
  34.     SHL DX, 1                 ;2 bytes per character block
  35.  
  36.     MOV AX, WORD [_TxtBlock]  ;Character we'll draw the rectangle with
  37.  
  38.     MOV DS, WORD [_BuffSeg]   ;Load buffer segment
  39.                               ;Buffer is DS:DI
  40.  
  41.     MOV BL, CL                ;Backup X counter in BL
  42. NextY:
  43.     MOV CL, BL
  44.  
  45. NextX:
  46.     MOV [DI], AX              ;Write a character to the buffer
  47.     ADD DI, 2                 ;Update buffer pointer
  48.  
  49.     DEC CL                    ;One character, still more?
  50.     JNZ NextX                 ;Yes? draw the next one
  51.     ADD DI, DX                ;Adjust pointer to next row
  52.     DEC CH                    ;Done one line, still more?
  53.     JNZ NextY                 ;Yes? Go back until done
  54.  
  55. End:
  56.     POP DS
  57.     POP ES
  58.     POPA
  59.     RETF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement