phat code If you're too open-minded, your brains will fall out.
Main

Projects

Downloads

Articles

Links

Forum

 

View Message

Back to Messages
rel Tue Mar 21 2006 at 10:12 am
yo plaz need help(asm)
 
 
can you tell me why this crashes?  It loads the BMP anbd sets the pal but stays as is.

[code]
;************************************* ****************************
; 8 bit bmp loader
; Assemble with TASM
; TASM loadbmp.ASM
; Tlink loadbmp.Obj
;
; Http://Rel.Betterwebber.com
;*********************************** ******************************
.Model medium
.Stack 200h ;512 bytes of stack
.386 ;don't tell you're still using a 286

BMPHeaderType struc
      ID              dw  ?                     ;BM
      FileSize        dd  ?                     ;Wid*Hei+Header
      Reserved1       dw  ?
      Reserved2       dw  ?
      OffBits         dd  ?                     ;1078
      HSize           dd  ?
      Wid             dd  ?
      Hei             dd  ?
      Planes          dw  ?                     ;1
      Bpp             dw  ?                     ;8
      Compression     dd  ?                     ;0
      SizeImage       dd  ?                     ;W*H
      Xres            dd  ?                     ;3790
      Yres            dd  ?                     ;ditto
      ClrUsed         dd  ?
      ClrImportant    dd  ?
BMPHeaderType ends
                            ;Pal'Order=Blue*4, Green*4, Red*4, 0 * 4
.data

BmpHeader           BmpHeaderType <>
Bytes               db  ?

filename            db "crystal.bmp"
pal                 db 769 dup(0)
x                   dw 10
y                   dw 10
SwitchPal           dw 1

.Code ;start code seg

;************************************* ****************************
PrintChar Macro aschar
    pusha
        mov al, aschar
        mov ah, 0ah
        mov bh, 00
        mov cx, 1
        int 10h
    popa
EndM PrintChar

;************************************* ****************************
;reads the keyboad buffer
Input Macro
;needs ax to be unused
;returns in AH the scancode
;returns in AL the asciicode
mov   ah, 10h                   ; check for input
    int   16h
EndM Input


ReadByte MACRO ByteToRead
    push ax
    push cx
    push dx

    mov dx, Offset ByteToRead
    mov ax, @data
    mov ds, ax
    mov cx,1
    mov ah, 3fh
    int 21h

    pop dx
    pop cx
    pop ax

EndM ReadByte


LoadBmp Proc

    Local Hite:     Word
    Local DSSave:   Word

    Mov ax,0a000h     ;Vga seg
    mov es, ax     ;for blitting
    Mov ax, Y               ;calc offset
    xchg al,ah              ;*256
    mov di,ax               ;save
    shr di,2                ;256/4=64
    add di,ax               ;64+256=320
    add di,x                ;offset=Y*320+X

    ;;
    ;; Int 21h
    ;; ah = 3dh
    ;; al = 0 for read only
    ;; DS:DX=Filename

    mov ax, @data
    mov ds, ax             ;for filename
    mov fs, ax             ;for pal
    mov dx, offset filename
    mov ah,3dh
    xor al,al
    int 21h
    jc @CheckError              ;carry flag set so error error in AX!!!
    ;;
    ;; Return: AX=FileHandle(should be moved to BX)

    ;;3fh=Read bytes
    ;;Bx=Handle
    ;;cx=Bytes to read
    ;;dx=Offset where to put 'em. Variable or Array

    mov bx,ax                   ;Int 21h needs BX instead of AX
    ;mov ax, seg BmpHeader
    ;mov ds, ax
    mov dx, offset BmpHeader    ;Offset
    mov cx, Size BmpHeader      ;ByteLength
    mov ah,3fh
    xor al,al
    Int 21h
    jc @CheckError                  ;carry flag set so error error in AX!!!
                                    ;offset now in Pal
    ;;;
    ;;;Check for validity of file
    cmp BmpHeader.Id, 19778         ;"BM"
    jne @BmpNotSupported
    cmp BmpHeader.Planes,1
    jne @BmpNotSupported
    cmp BmpHeader.Bpp, 8            ;Only screen 13
    jne @BmpNotSupported
    cmp BmpHeader.Compression,0     ;should be 0
    jne @BmpNotSupported
    ;;;;
    ;;;;Load Pal
    mov cx,256                      ;256 colors 8Bpp
    mov si, offset Pal
@BmpLoadPal:
    ReadByte Bytes
    jc  @CheckError

    ;;;;BLUE
    mov al, Bytes
    shr al,2                        ;div by 4
    mov fs:[si+2],al

    ;;;;GREEN
    ReadByte Bytes
    jc  @CheckError
    mov al, Bytes
    shr al,2                        ;div by 4
    mov fs:[si+1],al

    ;;;;RED
    ReadByte Bytes
    jc  @CheckError
    mov al, Bytes
    shr al,2                        ;div by 4
    mov fs:[si],al

    ReadByte Bytes                  ;Padding
    jc  @CheckError
    add si,3
    dec cx
    jnz @BmpLoadPal

    ;;;Switch Pal
    Cmp SwitchPal,0
    jne @BMPSwitchPal
@PostBMPSwitchPal:

    ;;
    Mov ecx,BmpHeader.Wid
    mov eax,ecx
    and eax,3
    jz @MulOfFour
    sub ecx,eax                     ;make it a multiple of four
    add ecx,4                       ;make up for lost pixels

@MulOfFour:

    mov BmpHeader.Wid,ecx
    ;;
    ;;;
    ;; calc start offset
    ;; BMP's are stored backwards (nasty developers)
    mov eax,BmpHeader.Hei
    dec ax
    xchg ah,al                      ;H*256
    mov cx,ax                       ;save
    shr cx,2                        ;256/4=64
    add cx,ax                       ;64+256=320
    add di,cx                       ;Ylayer offset+ BmpHeight

    mov ecx,BmpHeader.Hei           ;loop counter
    Mov Hite,cx

@BmpYloop:
    Mov DSSave, Ds
    ;;
    ;; Ds:si=Layer for direct from file write
    ;; ECX=Wid of one scanline
    Mov ecx, BmpHeader.Wid
    Mov ax,es                       ;layer
    mov ds,ax                       ;fileseg
    mov dx,di                       ;layer offset
    mov ah, 3fh                     ;read
    int 21h
    jc @CheckError
    mov ds,DsSave
    sub di,320                      ;next scanline
    dec Hite
    Jnz @BmpYLoop
    mov ah, 3eh                   ;Close file
    int 21h
    xor ax, ax                    ;No error
    jmp @exitLoadBmp
@BmpNotSupported:
    mov ah, 3eh
    int 21h
    mov ax, 1                     ;Unknown ver
@ExitLoadBmp:

    ret

;/=======Subs======
@BMPSwitchPal:
    ;;;
    ;;;Fs:si PalSeg:PalOff
    ;;;Out =Dx:Port Addy, al color
    ;;; 3c8h=port WriteMode
    ;;; 3c9h=Dac
    mov ax, @data
    mov fs,ax
    mov si, offset pal
    xor cx,cx               ;start from zero
@BmpColorLoop:
    mov dx, 3c8h
    mov ax, cx
    xor ah, ah
    out dx, al              ;color index

    ;;;;
    ;;;;RED
    mov dx, 3c9h
    mov al, fs:[si]
    out dx, al
    ;;;;
    ;;;;GREEN
    mov dx, 3c9h
    mov al, fs:[si+1]
    out dx, al
    ;;;;
    ;;;;BLUE
    mov dx, 3c9h
    mov al, fs:[si+2]
    out dx, al

    add si,3                ;next 3 colors
    inc cx
    cmp cx,256
    jne @BmpColorLoop
Jmp @PostBmpSwitchPal

@CheckError:
    mov ah, 3eh         ;Close File
    int 21h
    or ax,ax
    jnz @ExitLoadBmp
    Mov ax,255          ;unknown error
Jmp @ExitLoadBmp


LoadBmp  Endp


;************************************* ****************************
;Initializes the screen to VGA 320x200x256

init13h   proc
   mov   ax, 0a000h    ;load VGA segment(can't load
       ;directly to segment registers
   mov   es, ax                        ; es now points to the vga

   mov   ah, 00h                       ; set video mode
   mov   al, 13h                       ; mode 13h
   int   10h                           ; we are now in 320x200x256
   ret
init13h   endp

;************************************* ****************************

textmode         proc
   mov   ah, 00h                        ;set video mode
   mov   al, 03h                        ;mode 03h
   int   10h                            ;enter 80x25x16 mode
   ret
textmode         endp


;************************************* ****************************
;this waits for screen retrace/refresh or our demo being in ASM
;would as fast as an x-wing on steroids. :*)

waitretrace proc
        mov dx,03dah            ;0x3da9 vertical retrace port

wret:
        in al,dx
        and al,08h ; is vga in retrace?
jnz wret
wref:
        in al,dx
        and al,08h ;is retrace finished?
jz wref


ret
waitretrace endp


;************************************* ****************************
;************************************* ****************************
;************************************* ****************************

zzzzzzztart: ;too much pocket books

    call init13h ;set to 320*200*256

    Mov ax,0a000h ;Vga seg
    mov es, ax ;for blitting
    Mov ax,@data
    mov ds, ax                  ;data seg
    mov fs, ax

    call loadbmp


   input

    mov   ah, 4ch
    mov   al, 00h
    int   21h               ; return to dos

END zzzzzzztart



[/code]
 
 
 
 

Reply to this Message

Name
Subject
Message

No HTML is allowed, except for <code> <b> <i> <u> in the message only.
All URLs and email addresses will automatically be converted to hyperlinks.