SwiZzoR

Error: Group DGROUP exceeds 64K x8086

Apr 5th, 2016
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %Title "Load and show file *.PCX 320x200x256"
  2.  
  3.         IDEAL
  4.  
  5.         MODEL large
  6. P386
  7.  
  8. MACRO SHOWPCX StartX, StartY, fName
  9.         mov ax, [StartX]
  10.         mov [Point_X], ax
  11.         mov ax, [StartY]
  12.         mov [Point_Y], ax
  13.  
  14.         mov dx, offset fName
  15.  
  16.         call ShowPCXFile
  17. ENDM SHOWPCX
  18.    
  19.     STACK 256
  20.  
  21.     DATASEG
  22.        
  23.     ErrorReadingFile DB 'Can not open file$'
  24.  
  25.         FileName1       DB 'mouse.pcx',0
  26.         FileName2       DB 'car2.pcx',0
  27.         FileName        DW ?    ; offset file name for current file
  28.  
  29.         FileHandle      DW ?
  30.    
  31.         FileSize        DW ?
  32.  
  33.         ImageSizeInFile DW ?
  34.  
  35.         ImageLength     DW ?
  36.         ImageHeigth     DW ?
  37.  
  38.         PaletteOffset   DW ?
  39.  
  40.         Point_X         DW ?
  41.         Point_Y         DW ?
  42.         Color           DB ?
  43.        
  44.         StartPictX      DW ?
  45.         StartPictY      DW ?
  46.        
  47. SEGMENT FILEBUF para public  'DATA'  
  48.         DB 65200 DUP(?)
  49. ENDS
  50.  
  51.         CODESEG  
  52.  
  53. Start:
  54.         mov ax, @data
  55.         mov ds, ax
  56.  
  57.         mov ax, 0013h
  58.         int 10h
  59. ; -----------------= Show Pic1 =----------------
  60.         mov [StartPictX], 0d
  61.         mov [StartPictY], 0d
  62.  
  63.         SHOWPCX StartPictX, StartPictY, FileName1
  64.        
  65.         mov ah,00h
  66.         int 16h
  67.  
  68. ; -----------------= Show Pic2 =----------------
  69.         ; mov ah,00h
  70.         ; int 16h
  71.    
  72.         mov ah,00h
  73.         mov al,03h
  74.         int 10h
  75. Exit:
  76.         mov ax,04c00h
  77.         int 21h
  78.  
  79. ;-------------------------------------------
  80. ; ReadPCXFile - read PCX file into FILEBUF
  81. ;-------------------------------------------
  82. ; Input:
  83. ;   File name
  84. ; Output:
  85. ;   File into FILEBUF
  86. ; Registers
  87. ;       AX, BX, CX, DX, DS
  88. ;-------------------------------------------
  89. PROC ReadPCXFile Near
  90.         pusha
  91.  
  92. ;-----  Initialize variables
  93.         mov     [FileHandle],0
  94.         mov     [FileSize],0
  95.  
  96. ;-----  Open file for reading
  97.         mov     ah, 3Dh
  98.         mov     al, 0
  99.         ; mov DX,offset FileName  
  100.         int     21h
  101.         jc      @@Err
  102.         mov     [FileHandle],AX   ; save Handle
  103.  
  104. ;-----  Get the length of a file by setting a pointer to its end
  105.         mov     ah, 42h
  106.         mov     al ,2
  107.         mov     bx, [FileHandle]
  108.         xor     cx, cx
  109.         xor     dx, dx
  110.         int     21h
  111.         jc      @@Err
  112.         cmp     dx,0
  113.         jne     @@Err  ;file size exceeds 64K
  114.  
  115. ;-----  Save size of file
  116.         mov     [FileSize], ax
  117.  
  118. ;----- Return a pointer to the beginning of the file
  119.         mov     ah, 42h
  120.         mov     al, 0
  121.         mov     bx, [FileHandle]
  122.         xor     cx, cx
  123.         xor dx, dx
  124.         int 21h
  125.         jc  @@Err
  126.  
  127. ;-----  Read file into FILEBUF
  128.         mov     bx, [FileHandle]
  129.         pusha    
  130.         push    ds
  131.         mov     ax,FILEBUF
  132.         mov     ds, ax
  133.         xor     dx, dx
  134.         mov     cx, 65200
  135.         mov     ah, 3Fh
  136.         int     21H
  137.         pop     ds
  138.         popa
  139.         jc      @@Err
  140.  
  141. ;-----  Close the file
  142.         mov     ah, 3Eh
  143.         mov     bx,[FileHandle]
  144.         int     21H
  145.         jc      @@Err
  146.         popa
  147.         ret
  148.        
  149. ;-----  Exit - error reading file
  150. @@Err:  ; Set text mode
  151.         mov     ax, 3
  152.         int     10h
  153.        
  154.         mov     dx, offset ErrorReadingFile
  155.         mov     ah, 09h
  156.         int     21h
  157.         jmp     Exit
  158. ENDP ReadPCXFile
  159.  
  160. ;-------------------------------------------
  161. ; ShowPCXFile - show PCX file
  162. ;-------------------------------------------
  163. ; Input:
  164. ;   File name
  165. ; Output:
  166. ;   The file
  167. ; Registers
  168. ;    AX, BX, CX, DX, DS
  169. ;-------------------------------------------
  170. PROC ShowPCXFile Near  
  171.         pusha
  172.  
  173.         call    ReadPCXFile
  174.        
  175.     mov ax, FILEBUF
  176.         mov     es, ax
  177.  
  178. ;-----  Set ES:SI on the image
  179.         mov     si, 128
  180.  
  181. ;-----  Calculate the width and height of the image
  182.         mov     ax, [es:42h]
  183.         mov     [ImageLength], ax
  184.         dec     [ImageLength]
  185.        
  186.         mov     ax, [es:0Ah]
  187.         sub     ax, [es:6]
  188.         inc     ax
  189.         mov     [ImageHeigth], ax
  190.  
  191. ;-----  Calculate the offset from the beginning of the palette file
  192.         mov     ax, [FileSize]
  193.         sub     ax, 768
  194.         mov     [PaletteOffset], ax
  195.         call    SetPalette
  196.         mov     ax, [FileSize]
  197.         sub     ax, 128+768
  198.         mov     [ImageSizeInFile], ax
  199.        
  200.         xor     ch, ch          ; Clear high part of CX for string copies
  201.         ;mov     [Point_x],0    ; Set start position
  202.         ;mov     [Point_y],0
  203. NextByte:
  204.         mov     cl, [es:si]     ; Get next byte
  205.     cmp     cl, 0C0h        ; Is it a length byte?
  206.         jb      normal          ;  No, just copy it
  207.         and     cl, 3Fh         ; Strip upper two bits from length byte
  208.         inc     si              ; Advance to next byte - color byte
  209.  
  210.         mov     al, [es:si]
  211.     mov     [Color], al
  212. NextPixel:
  213.         call    PutPixel
  214.         cmp     cx, 1
  215.         je  CheckEndOfLine
  216.    
  217.         inc     [Point_X]
  218.  
  219.         loop    NextPixel      
  220.         jmp     CheckEndOfLine
  221. Normal:
  222.         mov     [Color], cl
  223.         call    PutPixel
  224.  
  225. CheckEndOfLine:
  226.         mov     ax, [Point_X]
  227.         add     ax, [StartPictX]
  228.         cmp     ax, [ImageLength]
  229. ;-----  [point_x] >= [StartPictX]+[WidthPict]
  230.         jae     LineFeed
  231.         inc     [Point_x]
  232.         jmp     cont
  233. LineFeed:
  234.         push    [StartPictX]
  235.         pop     [Point_x]
  236.     ;    mov    [Point_X],0
  237.         inc     [Point_y]
  238. cont:
  239.         inc     si
  240.         cmp     si, [ImageSizeInFile]     ; End of file? (written 320x200 bytes)
  241.         jb      nextbyte
  242.         popa
  243.         ret
  244. ENDP ShowPCXFile
  245.  
  246. ;-------------------------------------------
  247. ; PutPixel - draw pixel
  248. ;-------------------------------------------
  249. ; Input:
  250. ;   x - Point_x, y - Point_y, Color - color
  251. ; Output:
  252. ;   The pixel
  253. ; Registers
  254. ;    AX, BH, CX, DX
  255. ;-------------------------------------------
  256. PROC PutPixel near
  257.         pusha
  258.         mov     bh, 0h
  259.         mov     cx, [Point_x]
  260.         mov     dx, [Point_Y]
  261.         mov     al, [color]
  262.         mov     ah, 0ch
  263.         int     10h
  264.         popa
  265.         ret
  266. ENDP PutPixel      
  267.        
  268. ;-------------------------------------------
  269. ; SetPalette - change palette from 0-255 to from 0-63
  270. ;-------------------------------------------
  271. ; Input:
  272. ;   PaletteOffset
  273. ; Output:
  274. ;   New palette
  275. ; Registers
  276. ;    AX, BX, CX, DX, SI, ES
  277. ;-------------------------------------------
  278. SetPalette:
  279.         pusha
  280.         mov cx, 256*3
  281.         mov si, [PaletteOffset]    
  282. NextColor:
  283.         shr [byte es:si], 2
  284.         inc si
  285.         loop NextColor
  286.  
  287.         mov dx, [PaletteOffset]
  288.         mov ax, 1012h
  289.         mov bx, 00h
  290.         mov cx, 256d  
  291.         int 10h
  292.         popa
  293. ret
  294.         End Start
Advertisement
Add Comment
Please, Sign In to add comment