home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / PCACHSRC.ZIP / PCX2SCRN.ASM < prev    next >
Assembly Source File  |  1991-04-14  |  5KB  |  255 lines

  1. ;PCX2SCRN.COM
  2. ;invoke by--  PCX2SCRN <enter>
  3. ;version 20/3 has filespec DEMO.PCX inside this program.
  4. ;displays the pcx file on an ega or vga (mode-16) screen.
  5. ;
  6. comseg segment
  7.  org 100h
  8.  assume DS:comseg, CS:comseg
  9. main proc far
  10.      jmp     start
  11.  
  12. handle        dw     2        ;file handle.
  13. screenaddr    dw    0,0A000h    ;starting addr video-RAM, current line.
  14. screenend        dw    350*80,0A000h    ;ending addr video-RAM.
  15. header        db     128 dup(0)    ;pcx header read into here.
  16. buffer        db    200 dup(0)    ;pcx file read into here.
  17. bufferptr        dw    0            ;pointer into buffer.
  18. cnt16        dw    0        ;palette register
  19. cnt3            dw    0
  20. cnt            dw    0
  21. colour        dw    0
  22. bitplane        dw    0
  23. count        dw    0
  24. content        dw    0
  25. lineoffset    dw    0        ;offset in video-RAM, current line.
  26. filespec      db    "temp.pcx",0    ;*****temporarily added.
  27.  
  28. MSG1        DB    "Cannot open PCX file $"    ;****$ inserted
  29. MSG2        DB    "Cannot read header $" 
  30. closemsg    db    "Cannot close PCX file $"
  31.  
  32. colourmasks    DW    00H
  33.     DW    08H
  34.     DW    01H
  35.     DW    09H
  36.  
  37. start:
  38.     mov ah,3Dh        ;open the file.
  39.     mov dx,offset filespec
  40.     mov al,0
  41.     int 21h
  42.     jc  openerror
  43.     mov handle,ax        ;handle 
  44.     jmp short noerror
  45. openerror:
  46.     mov dx,offset MSG1
  47.     mov ah,9
  48.     int 21h
  49.     jmp exitprog
  50. noerror:
  51.  
  52. ;***read & check the header...
  53.  mov bx,handle        ;filehandle
  54.  mov cx,128
  55.  mov dx,offset header
  56.  mov ah,3Fh
  57.  int 21h            ;read file
  58.  jc  readerror
  59.     cmp    BYTE PTR header,10
  60.     je    place1
  61.  
  62. readerror:
  63.  mov dx,offset MSG2
  64.  mov ah,9
  65.  int 21h
  66.  jmp exitprog
  67.  
  68. place1:
  69. ;******should put checking if mode 16 supported.
  70.  mov ah,0
  71.  mov al,16
  72.  int 10h        ;mode 16
  73.     mov    WORD PTR cnt16,0
  74.     jmp    SHORT place4
  75.  
  76. place2:                    ;set ega palette....
  77.     mov    si,WORD PTR cnt16
  78.     mov    ax,si
  79.     shl    si,1
  80.     add    si,ax
  81.     mov    bx,WORD PTR cnt3
  82.     mov    al,BYTE PTR header[bx+16][si]
  83.     mov    cl,6
  84.     sar    al,cl
  85.     and    ax,3
  86.     mov    si,ax
  87.     mov    WORD PTR cnt,si
  88.     shl    si,1
  89.     mov    ax,WORD PTR colourmasks[si]
  90.     mov    cl,2
  91.     sub    cl,bl
  92.     shl    ax,cl
  93.     or    WORD PTR colour,ax
  94.     inc    WORD PTR cnt3
  95. place3:
  96.     cmp    WORD PTR cnt3,3
  97.     jl    place2
  98.  
  99.  mov ah,16        ;set palette registers...
  100.  mov al,0            ;set individual palette register.
  101.  mov bh,BYTE PTR colour    ;value.
  102.  mov    bl,BYTE PTR cnt16    ;which register.
  103.  int 10h
  104.  
  105.     inc    WORD PTR cnt16
  106. place4:
  107.     cmp    WORD PTR cnt16,16
  108.     jge    place5        ;to end of outer for-loop...
  109.  
  110.     sub    ax,ax
  111.     mov    WORD PTR colour,ax
  112.     mov    WORD PTR cnt3,ax
  113.     jmp    SHORT place3
  114. place5:            ;end of outer loop.
  115.  
  116. ;***select initial colour plane...
  117.     mov    ax,2
  118.     mov    dx,03C4h        ;port 03C4h
  119.     out    dx, al
  120.  
  121.     mov    ax,1
  122.     mov    dx,03C5h        ;port 03C5h
  123.     out    dx, al
  124.  
  125.     mov    ax,0
  126.     mov    WORD PTR screenaddr,ax
  127.     mov    dx,0A000h        ;top left byte of scrn mem
  128.     mov    WORD PTR screenaddr+2,dx
  129.     mov    ax,350*80
  130.     mov    WORD PTR screenend,ax
  131.     mov    dx,0A000h        ;end of scrn.
  132.     mov    WORD PTR screenend+2,dx
  133.     sub    ax,ax
  134.     mov    WORD PTR lineoffset,ax
  135.     mov    WORD PTR content,ax
  136.     mov    WORD PTR count,ax
  137.     mov    WORD PTR bitplane,1
  138.     mov    WORD PTR bufferptr,200
  139.  
  140. ;***graphics data loop...
  141. place6:
  142.     mov    ax,WORD PTR screenaddr
  143.     mov    dx,WORD PTR screenaddr+2
  144.     cmp    WORD PTR screenend,ax
  145.     jne    place7
  146.     cmp    WORD PTR screenend+2,dx
  147.     jne    place7
  148.     jmp    place15
  149.  
  150. place7:            ;start of the large not-end-mem loop
  151.     cmp    WORD PTR bufferptr,200
  152.     jne    place8
  153.     mov    WORD PTR bufferptr,0
  154.  
  155.  mov bx, handle
  156.  mov cx,200
  157.  mov dx,offset buffer
  158.  mov ah,3Fh
  159.  int 21h                    ;read file
  160.  
  161. place8:            ;***loop counter or data byte?
  162.     mov    bx,WORD PTR bufferptr
  163.     mov    al,BYTE PTR buffer[bx]
  164.     cbw    
  165.     mov    WORD PTR count,ax
  166.     inc    WORD PTR bufferptr
  167.     mov    al,BYTE PTR count
  168.     and    ax,192
  169.     cmp    ax,192
  170.     jne    place10
  171.  
  172.     cmp    WORD PTR bufferptr,200    ;third inner IF....
  173.     jne    place9
  174.     mov    WORD PTR bufferptr,0
  175.  mov bx, handle        ;file read...
  176.  mov cx,200
  177.  mov dx,offset buffer
  178.  mov ah,3Fh
  179.  int 21h                    ;read file
  180.  
  181. place9:                    ;
  182.     mov    bx,WORD PTR bufferptr
  183.     mov    al,BYTE PTR buffer[bx]
  184.     cbw    
  185.     mov    WORD PTR content,ax
  186.     inc    WORD PTR bufferptr
  187.     and    WORD PTR count,63
  188.     jmp    SHORT place11        ;jump around the else-condition...
  189.     nop    
  190.  
  191. place10:
  192.     mov    ax,WORD PTR count
  193.     mov    WORD PTR content,ax
  194.     mov    WORD PTR count,1
  195.  
  196. place11:
  197.     mov    ax,WORD PTR count
  198.     dec    WORD PTR count
  199.     or    ax,ax
  200.     jne    place12
  201.     jmp    place6
  202. place12:
  203.     mov    al,BYTE PTR content
  204.     les    bx,DWORD PTR screenaddr
  205.     mov    si,WORD PTR lineoffset
  206.     mov    BYTE PTR es:[bx][si],al
  207.  
  208.     inc    WORD PTR lineoffset
  209.     cmp    WORD PTR lineoffset,80
  210.     jne    place11
  211.     mov    WORD PTR lineoffset,0
  212.  
  213.     cmp    WORD PTR bitplane,8
  214.     jne    place13
  215.     add    WORD PTR screenaddr,80
  216.     mov    WORD PTR bitplane,1
  217.     jmp    SHORT place14
  218.     nop    
  219. place13:                ;***else condition...
  220.     shl    WORD PTR bitplane,1
  221. place14:
  222.     mov    ax,WORD PTR bitplane
  223.     mov    dx,03C5h        ;port 03C5h
  224.     out    dx, al
  225.  
  226.     jmp    SHORT place11    ;three loops close here.
  227.     nop    
  228.  
  229. place15:                ;***finished
  230.  mov bx, handle
  231.  mov ah,3Eh
  232.  int 21h                ;close file
  233.  jnc  nocloseerror
  234.  mov dx,offset closemsg
  235.  mov ah,9
  236.  int 21h
  237.  jmp short exitprog
  238. nocloseerror:
  239.  mov ah,2                ;beep and wait for keypress....
  240.  mov dl,07
  241.  int 21h
  242.  mov ah,0
  243.  int 16h
  244.  
  245.  mov ah,0
  246.  mov al,3
  247.  int 10h                    ;back to text mode 3
  248.  
  249. exitprog:
  250.  mov ax,4C00h
  251.  int 21h        ;exit
  252. main    ENDP
  253. comseg ends
  254.  END main
  255.