Advertisement
Ham62

GetGFX.asm

Feb 1st, 2017
476
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.  
  8. %define _StartX   BP+_ParamOffset+14
  9. %define _StartY   BP+_ParamOffset+12
  10. %define _Width    BP+_ParamOffset+10
  11. %define _Height   BP+_ParamOffset+8
  12. %define _GFXPtr   BP+_ParamOffset+6
  13. %define _GFXSeg   BP+_ParamOffset+4
  14. %define _BuffSeg  BP+_ParamOffset+2
  15. %define _BuffAddr BP+_ParamOffset+0
  16.  
  17. Start:
  18.     PUSHA    ;16 bytes
  19.     PUSH ES  ;2 bytes
  20.     PUSH DS  ;2 bytes
  21.     MOV BP, SP
  22.  
  23.                               ;Start pos on buffer is (X + (Y*ScreenWidth)) << 1
  24.     MOV BX, WORD [_StartY]    ;Get Y
  25.     IMUL AX, BX, _ScreenWidth ;Multiply by ScreenWidth and store result in AX
  26.     ADD AX, WORD [_StartX]    ;Add X
  27.     SHL AX, 1                 ;2 bytes per character block
  28.     MOV SI, WORD [_BuffAddr]  ;Set SI to start of buffer
  29.     ADD SI, AX                ;SI is now start of where to read image
  30.  
  31.     MOV ES, WORD [_GFXSeg]    ;Image segment
  32.     MOV DI, WORD [_GFXPtr]    ;Image offset
  33.                               ;Image is now ES:DI
  34.  
  35.     MOV BX, WORD [_Width]     ;How long are the rows
  36.     MOV DX, WORD [_Height]    ;How many rows to draw
  37.  
  38.     MOV AX, _ScreenWidth      ;How much to advance to get to next row
  39.     SUB AX, BX                ;AX = ScreenWidth - ImageWidth   
  40.  
  41.     MOV DS, WORD [_BuffSeg]   ;Get buffer segment
  42.                               ;Buffer is now DS:SI
  43.  
  44. NextRow:
  45.     MOV CX, BX                ;How much to draw to complete a row
  46.     REP MOVSW                 ;Draw a row
  47.  
  48.     ADD SI, AX                ;Adjust pointer to start of next row
  49.     DEC DX                    ;Done a row, still more?
  50.     JNZ NextRow               ;Yes? Draw the next line
  51.  
  52. End:
  53.     POP DS
  54.     POP ES
  55.     POPA
  56.     RETF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement