home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / DISKMAGS / IMPHOB_9.ZIP / IMP9_EX!.ZIP / LBM256.ZIP / LBM256.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-01-02  |  6.9 KB  |  292 lines

  1. comment ;-)
  2.  
  3. Smiley comment, eh?
  4.  
  5.     This program is devoted to show LBMs. There was need for a viewer for
  6.     standard VGAs which can handle 256 pixel tall Amiga pictures.
  7.     Here it is.
  8.     The 320*255½ video mode was experimentally worked out with Robert
  9.     Schmidt's Tweak Ten.
  10.     As I noticed, it's impossible to make a full 320*256 resolution
  11.     on a standard VGA. Possible for Tseng cards (of course), but for
  12.     example, the Trident boards didn't like it at all. However,
  13.     the 320*255+0.5 mode worked everywhere. (It's refreshing frequency
  14.     is about 57 Hz.)
  15.     Summa summarum, at 256 pixel tall pictures the last row is half-height.
  16.  
  17.     If this proggy doesn't show a valid LBM picture, it's probably because:
  18.  
  19.         -LBM is 'ILBM'-type, not 'PBM '
  20.         -LBM isn't 320 pixel wide
  21.         -LBM isn't packed with method 1
  22.         -LBM is masked
  23.         -You don't own a VGA or 386 ;-)
  24.  
  25.  
  26.  
  27. o    equ    offset                ;Useful abbrevations to
  28. b    equ    byte ptr            ;optimize coding time
  29. w    equ    word ptr
  30. d    equ    dword ptr
  31.  
  32. a    segment
  33. assume    cs:a,ds:a
  34. org    100h
  35. ;-----------------------------------------------
  36. go:
  37.         push    sp            ;Test 286
  38.         pop    ax
  39.         xor    ax,sp            ;AL will be 0
  40.         jne    error            ;No 286
  41. .286
  42.         mov    ah,1ah            ;Test VGA (AL=0)
  43.         int    10h
  44.         cmp    al,1ah
  45.         jne    error            ;No VGA
  46.         cmp    bl,7
  47.         jb    error            ;No VGA
  48.  
  49.         push    3000h            ;Test 386
  50.         popf                ;(This does for us the CLD too)
  51.         pushf
  52.         pop    ax
  53.         test    ax,3000h
  54.         je    error            ;No 386
  55. .386
  56. ;-----------------------------------------------
  57.         mov    di,81h            ;Prepare for command line check
  58.         movzx    ecx,b ds:[di-1]        ;Fetch parameter string length
  59.         mov    al,' '
  60.     rep    scasb                ;Skip spaces
  61.         jcxz    error            ;Exit if wasn't any parameter
  62.         mov    dx,di            ;Save parameter's address
  63.         dec    dx            ;(file's name)
  64.     repne    scasb                ;Seek to filename's end
  65.  
  66.         mov    ax,3d00h        ;Prepare AX for file opening
  67.         stosb                ;Put 0 after file's name
  68.         int    21h            ;Open file
  69.         jb    error            ;Exit on bad filename
  70.  
  71.         lea    sp,$            ;Make safe stack
  72.                         ;(Prevent picture from being
  73.                         ;overwritten by the stack)
  74.  
  75.         mov    bx,o freemem
  76.         push    bx            ;Save freemem's offset
  77.         call    adjustds        ;Align DS to freemem
  78.  
  79.         xchg    bx,ax            ;Put file's handle to bx
  80.         cwd                ;Offset for data (DX will be 0)
  81.         mov    cx,08000h        ;Read 8000h bytes in one step
  82. loadloop:
  83.         mov    ah,3fh            ;Prepare for file reading
  84.         int    21h            ;Read file
  85.         or    ax,ax            ;AX=0: file read over
  86.         je    loadready
  87.         mov    ax,ds            ;Adjust DS
  88.         add    ax,0800h
  89.         mov    ds,ax
  90.         jmp    loadloop
  91. loadready:
  92.         mov    ah,3eh            ;Close file
  93.         int    21h
  94.  
  95. ;-----------------------------------------------
  96.         push    cs
  97.         pop    ds bx            ;Get picture address (freemem)
  98.  
  99.         cmp    d [bx],'MROF'        ;Check IFF signature (FORM)
  100.         jne    error
  101.         cmp    d [bx+8],' MBP'        ;Check picture type (PBM)
  102.         jne    error
  103.         cmp    w [bx+20],4001h        ;Check: width=320?
  104.         je    noerror
  105.  
  106. ;-----------------------------------------------
  107. error:
  108.         mov    dx,o msg        ;Fetch error message's address
  109.         mov    ah,9
  110.         int    21h            ;Write error message
  111.         int    20h            ;Exit COM program
  112.  
  113. ;-----------------------------------------------
  114. noerror:
  115.         movzx    eax,w [bx+22]        ;Get picture's height
  116.         xchg    ah,al            ;Big->little endian conversion
  117.         imul    ax,40            ;Put number of pixels to EBP
  118.         imul    ebp,eax,8        ;(height*320)
  119.         neg    ax            ;Calculate starting screen
  120.         add    ah,40            ;offset: (128-height/2)*80
  121.         push    ax            ;Save screen offset
  122.                         ;(Pictures which are not 256
  123.                         ;tall, will be dispalyed on
  124.                         ;the middle of the screen)
  125.  
  126.         cmp    b [bx+1eh],1        ;Check: packing=1? (CmpByteRun)
  127.         jne    error
  128.  
  129.         call    blank            ;Avoid filckering (Carry=0)
  130.         mov    ax,0013h        ;Init 320*200*256 mode
  131.         int    10h
  132.         call    blank            ;Avoid flickering (again)
  133.  
  134.         mov    si,o regset        ;Init 320*256 tweaked mode
  135.         mov    dl,0c2h
  136.         outsb
  137.         mov    dl,0c4h
  138.         outsw
  139.         mov    cx,feed_3d4_length
  140.         mov    dl,0d4h
  141.     rep    outsw
  142.  
  143. ;-----------------------------------------------
  144.         mov    eax,'PAMC'        ;Seek to CMAP
  145.         call    searchchunk
  146.  
  147.         mov    al,0            ;Prepare palette
  148.         mov    ch,3
  149.         mov    dl,0c8h
  150.         out    dx,al
  151.         inc    dx
  152. loadpal:
  153.         lodsb
  154.         shr    al,2
  155.         out    dx,al            ;Load palette
  156.         loop    loadpal
  157.  
  158. ;-----------------------------------------------
  159.         mov    eax,'YDOB'        ;Seek to BODY
  160.         call    searchchunk
  161.  
  162.         push    0a000h            ;Prepare for video operations
  163.         pop    es
  164.  
  165.         xor    ax,ax            ;Clear lower 256k video memory
  166.         mov    ch,80h            ;CL=0...
  167.     rep    stosw                ;(DI is even)
  168.  
  169.         mov    dl,0c4h            ;Prepare plane enable register
  170.         mov    al,2            ;DH=3...
  171.         out    dx,al
  172.         inc    dx
  173.         mov    al,11h            ;Prepare plane enable mask
  174.  
  175.         pop    di            ;Retrieve screen offset
  176. unpack:
  177.         mov    bx,si            ;Adjust DS:SI
  178.         and    si,0fh            ;to maintain 'huge' pointer
  179.         call    adjustds        ;(SI<10h always)
  180.  
  181.         movzx    cx,b [si]        ;Get control byte
  182.         inc    si
  183.         or    cl,cl            ;Test control byte
  184.         js    replicated        ;Jump if 'Replicated' ( <0 ),
  185.                         ;stay if 'Stored'
  186.         inc    cx
  187.         sub    ebp,ecx            ;Adjust pixel counter
  188.         jb    memok            ;Exit if all the pixels are out
  189. storeloop:
  190.         out    dx,al            ;Send mask
  191.         movsb                ;Send pixel
  192.         rol    al,1            ;Adjust mask
  193.         adc    di,0ffffh        ;Adjust video offset
  194.         loop    storeloop
  195.         jmp    unpack
  196.  
  197. replicated:
  198.         neg    cl
  199.         inc    cx
  200.         sub    ebp,ecx            ;Adjust pixel counter
  201.         jb    memok            ;Exit if all the pixels are out
  202.         mov    ah,[si]            ;Get pixel
  203.         inc    si
  204. replicloop:
  205.         out    dx,al            ;Send mask
  206.         mov    es:[di],ah        ;Send pixel
  207.         rol    al,1            ;Adjust mask
  208.         adc    di,0            ;Adjust video offset
  209.         loop    replicloop
  210.         jmp    unpack
  211.  
  212. ;-----------------------------------------------
  213. memok:
  214.         call    blank            ;Turn the sceen on (Carry=1)
  215.         cbw                ;AH will be 0
  216.         int    16h            ;Wait for a key
  217.  
  218.         call    blank            ;Avoid youknowhat... (Carry=0)
  219.         mov    ax,3            ;Init 80*25 textmode
  220.         int    10h
  221.         int    20h            ;Exit COM program
  222.  
  223.  
  224.  
  225. ;-----------------------------------------------
  226. adjustds:
  227.         shr    bx,4            ;Adjust DS to point DS:BX
  228.         mov    cx,ds
  229.         add    cx,bx
  230.         mov    ds,cx
  231.         ret
  232.  
  233.  
  234.  
  235. ;-----------------------------------------------
  236. blank:
  237.         mov    ax,2101h        ;Turn on/off the screen,
  238.         jnb    turn_off        ;depending on Carry Flag
  239.  
  240.         mov    dl,0dah
  241. retrace:
  242.         in    al,dx
  243.         test    al,8
  244.         je    retrace
  245.         mov    ax,0101h
  246. turn_off:
  247.         mov    dx,03c4h
  248.         out    dx,ax
  249.         ret
  250.  
  251.  
  252.  
  253. ;-----------------------------------------------
  254. searchchunk:
  255.         mov    di,o freemem+28h    ;The chunk's address after BMHD
  256. seekchunk:
  257.         scasd                ;Check type
  258.         je    chunkfound
  259.  
  260.         mov    bx,[di+2]        ;Get length
  261.         xchg    bh,bl            ;Big->little endian conversion
  262.         lea    di,[bx+di+4]        ;Next chunk's address to DI
  263.         and    bx,1            ;Chunks are word-aligned!
  264.         add    di,bx
  265.         jmp    seekchunk
  266. chunkfound:
  267.         lea    si,[di+4]        ;Chunk's data address to SI
  268.         ret
  269.  
  270.  
  271.  
  272.                         ;This register set kicks the
  273.                         ;card to 320*255½ tweaked mode
  274.                         ;(256 isn't suitable for some
  275.                         ;non-Tseng cards)
  276. regset    db    0e3h,4,6
  277. feed3d4    db    11h,0,6,20h,7,3eh,10h,0ffh,12h,0feh,15h,0ffh,16h,10h
  278.     db    14h,0,17h,0e3h
  279. feed_3d4_length    equ    ($-feed3d4)/2
  280.  
  281. msg    db    13,10
  282.     db    'Viewer by Ervin / AbaddoN',13,10
  283.     db    'Use: lbm256 file.ext',13,10
  284.     db    'Minimal config: 386+VGA',13,10
  285.     db    'The file must be 320 pixel wide ''PBM ''-type IFF',13,10,'$'
  286.  
  287. align    16
  288. freemem    label    byte
  289.  
  290. a    ends
  291. end    go
  292.