Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Title "Load and show file *.PCX 320x200x256"
- IDEAL
- MODEL large
- P386
- MACRO SHOWPCX StartX, StartY, fName
- mov ax, [StartX]
- mov [Point_X], ax
- mov ax, [StartY]
- mov [Point_Y], ax
- mov dx, offset fName
- call ShowPCXFile
- ENDM SHOWPCX
- STACK 256
- DATASEG
- ErrorReadingFile DB 'Can not open file$'
- FileName1 DB 'mouse.pcx',0
- FileName2 DB 'car2.pcx',0
- FileName DW ? ; offset file name for current file
- FileHandle DW ?
- FileSize DW ?
- ImageSizeInFile DW ?
- ImageLength DW ?
- ImageHeigth DW ?
- PaletteOffset DW ?
- Point_X DW ?
- Point_Y DW ?
- Color DB ?
- StartPictX DW ?
- StartPictY DW ?
- SEGMENT FILEBUF para public 'DATA'
- DB 65200 DUP(?)
- ENDS
- CODESEG
- Start:
- mov ax, @data
- mov ds, ax
- mov ax, 0013h
- int 10h
- ; -----------------= Show Pic1 =----------------
- mov [StartPictX], 0d
- mov [StartPictY], 0d
- SHOWPCX StartPictX, StartPictY, FileName1
- mov ah,00h
- int 16h
- ; -----------------= Show Pic2 =----------------
- ; mov ah,00h
- ; int 16h
- mov ah,00h
- mov al,03h
- int 10h
- Exit:
- mov ax,04c00h
- int 21h
- ;-------------------------------------------
- ; ReadPCXFile - read PCX file into FILEBUF
- ;-------------------------------------------
- ; Input:
- ; File name
- ; Output:
- ; File into FILEBUF
- ; Registers
- ; AX, BX, CX, DX, DS
- ;-------------------------------------------
- PROC ReadPCXFile Near
- pusha
- ;----- Initialize variables
- mov [FileHandle],0
- mov [FileSize],0
- ;----- Open file for reading
- mov ah, 3Dh
- mov al, 0
- ; mov DX,offset FileName
- int 21h
- jc @@Err
- mov [FileHandle],AX ; save Handle
- ;----- Get the length of a file by setting a pointer to its end
- mov ah, 42h
- mov al ,2
- mov bx, [FileHandle]
- xor cx, cx
- xor dx, dx
- int 21h
- jc @@Err
- cmp dx,0
- jne @@Err ;file size exceeds 64K
- ;----- Save size of file
- mov [FileSize], ax
- ;----- Return a pointer to the beginning of the file
- mov ah, 42h
- mov al, 0
- mov bx, [FileHandle]
- xor cx, cx
- xor dx, dx
- int 21h
- jc @@Err
- ;----- Read file into FILEBUF
- mov bx, [FileHandle]
- pusha
- push ds
- mov ax,FILEBUF
- mov ds, ax
- xor dx, dx
- mov cx, 65200
- mov ah, 3Fh
- int 21H
- pop ds
- popa
- jc @@Err
- ;----- Close the file
- mov ah, 3Eh
- mov bx,[FileHandle]
- int 21H
- jc @@Err
- popa
- ret
- ;----- Exit - error reading file
- @@Err: ; Set text mode
- mov ax, 3
- int 10h
- mov dx, offset ErrorReadingFile
- mov ah, 09h
- int 21h
- jmp Exit
- ENDP ReadPCXFile
- ;-------------------------------------------
- ; ShowPCXFile - show PCX file
- ;-------------------------------------------
- ; Input:
- ; File name
- ; Output:
- ; The file
- ; Registers
- ; AX, BX, CX, DX, DS
- ;-------------------------------------------
- PROC ShowPCXFile Near
- pusha
- call ReadPCXFile
- mov ax, FILEBUF
- mov es, ax
- ;----- Set ES:SI on the image
- mov si, 128
- ;----- Calculate the width and height of the image
- mov ax, [es:42h]
- mov [ImageLength], ax
- dec [ImageLength]
- mov ax, [es:0Ah]
- sub ax, [es:6]
- inc ax
- mov [ImageHeigth], ax
- ;----- Calculate the offset from the beginning of the palette file
- mov ax, [FileSize]
- sub ax, 768
- mov [PaletteOffset], ax
- call SetPalette
- mov ax, [FileSize]
- sub ax, 128+768
- mov [ImageSizeInFile], ax
- xor ch, ch ; Clear high part of CX for string copies
- ;mov [Point_x],0 ; Set start position
- ;mov [Point_y],0
- NextByte:
- mov cl, [es:si] ; Get next byte
- cmp cl, 0C0h ; Is it a length byte?
- jb normal ; No, just copy it
- and cl, 3Fh ; Strip upper two bits from length byte
- inc si ; Advance to next byte - color byte
- mov al, [es:si]
- mov [Color], al
- NextPixel:
- call PutPixel
- cmp cx, 1
- je CheckEndOfLine
- inc [Point_X]
- loop NextPixel
- jmp CheckEndOfLine
- Normal:
- mov [Color], cl
- call PutPixel
- CheckEndOfLine:
- mov ax, [Point_X]
- add ax, [StartPictX]
- cmp ax, [ImageLength]
- ;----- [point_x] >= [StartPictX]+[WidthPict]
- jae LineFeed
- inc [Point_x]
- jmp cont
- LineFeed:
- push [StartPictX]
- pop [Point_x]
- ; mov [Point_X],0
- inc [Point_y]
- cont:
- inc si
- cmp si, [ImageSizeInFile] ; End of file? (written 320x200 bytes)
- jb nextbyte
- popa
- ret
- ENDP ShowPCXFile
- ;-------------------------------------------
- ; PutPixel - draw pixel
- ;-------------------------------------------
- ; Input:
- ; x - Point_x, y - Point_y, Color - color
- ; Output:
- ; The pixel
- ; Registers
- ; AX, BH, CX, DX
- ;-------------------------------------------
- PROC PutPixel near
- pusha
- mov bh, 0h
- mov cx, [Point_x]
- mov dx, [Point_Y]
- mov al, [color]
- mov ah, 0ch
- int 10h
- popa
- ret
- ENDP PutPixel
- ;-------------------------------------------
- ; SetPalette - change palette from 0-255 to from 0-63
- ;-------------------------------------------
- ; Input:
- ; PaletteOffset
- ; Output:
- ; New palette
- ; Registers
- ; AX, BX, CX, DX, SI, ES
- ;-------------------------------------------
- SetPalette:
- pusha
- mov cx, 256*3
- mov si, [PaletteOffset]
- NextColor:
- shr [byte es:si], 2
- inc si
- loop NextColor
- mov dx, [PaletteOffset]
- mov ax, 1012h
- mov bx, 00h
- mov cx, 256d
- int 10h
- popa
- ret
- End Start
Advertisement
Add Comment
Please, Sign In to add comment