• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 729
  • Last Modified:

TASM to NASM???

I need to convert www.multicode.net/graphics.asm to NASM code..How?! Help please.
0
Morph007x2b
Asked:
Morph007x2b
  • 9
  • 8
1 Solution
 
dimitryCommented:
First, take a look at: http://home.attbi.com/~fbkotler/nasmdoc0.html
I used it to convert graphics.asm.
It passes compilation, but I can't promise you that it will work... :)
-----------------------------------------------------------
%xdefine ? 0
segment sseg stack
       resb 0x100
;.model small
;.stack 100h
segment dseg
;_DATA segment word public 'DATA'
filename  db   'A:\logo.bmp',0  ; insert the name and location
GLEN      db   'Copyright MultiCode Software 2003...' ; of the bitmap here
          db   '$'

handle    dw   ?           ; handle is used to store the file pointer
X         dw   ?           ; X and Y is used to fill the screen with pixels
Y         dw   ?
col       resb 640         ; col is used as a buffer to do a screen line
                           ; at a time
buff      dw   0
          dw   0
          dw   0
          dw   0
multi     dw   6
          dw   4
          dw   0
          dw   0
num       dw   0
y2        dw   409         ; y is used to store where the banks break up
          dw   408
          dw   307
          dw   306
          dw   204
          dw   203
          dw   102
          dw   101

struc BMPHEAD           ; This is the bitmap structure
   .id:          resb   2
   .filesize:    resw   2
   .reserved:    resw   2
   .headersize:  resw   2
   .infosize:    resw   2
   .width2:      resw   2
   .depth:       resw   2
   .biplanes:    resw   1
   .bits:        resw   1
   .bicomp:      resw   2
   .bisizeim:    resw   2
   .bixpels:     resw   2
   .biypels:     resw   2
   .biclrused:   resw   2
   .biclrimp:    resw   2
endstruc

struc RGBQUAD            ; This is how the bitmap stores its colours
   .blue:        resb   1
   .green:       resb   1
   .red:         resb   1
   .fill:        resb   1
endstruc

params:
  istruc BMPHEAD ; assigning the structures to these values
  iend
param:
  istruc RGBQUAD
;    at mt_blue,  db   0
;    at mt_green, db   0
;    at mt_red,   db   0
;    at mt_fill,  db   0
  iend
;_DATA ends
;.code
segment cseg
..start:
   mov  ax, SEG filename; moving all data into required memory position
   mov  ds, ax

   call loadbmp  ; calls a procedure called loadbmp

   mov  ah,00h   ; waits for a key to be pressed
   int  16h

   mov  ah,00h   ; changes the video mode to the normal setting
   mov  al,02h
   int  10h

   mov  ah, 09h  ; Prints out a message on the screen
   mov  dx, GLEN
   int  21h

   mov  ah,4ch   ; ends the program
   mov  al,0
   int  21h

putpixel:     ; this procedure is for putting a single pixel any
                                                        ; where on the display plane
; The linear address of the display plane is=y*640+x
   mov  ax,[Y] ; calculating linear=y2*640 in 16-bit
   mul  word [multi]
   mov  [buff],ax   ; first 16-bit calculation
   mov  ax,100
   mul  word [buff]
   mov  [buff],ax
   mov  [buff+2],dx

   mov  ax,[Y]    ; secound 16-bit calculation
   mul  word [multi+2]
   mov  [buff+4],ax
   mov  ax,10
   mul  word [buff+4]
   mov  [buff+4],ax
   mov  [buff+6],dx

   mov  ax,[buff] ; now adding the two 16-bit values
   add  ax,[buff+4]
   mov  [buff],ax
   mov  ax,[buff+2]
   adc  ax,[buff+6]
   mov  [buff+2],ax

   mov  ax,[X]  ; now adding x to the expression
   add  [buff],ax
   adc  word [buff+2],0   ; expression is now lin=y2*640+x

   mov  ax,[buff]
   mov  dx,[buff+2]

   mov  cx,16       ; calculating bank number
F1:
   sar     dx,1
   rcr     ax,1
   loop      F1
   mov     [num],ax

   mov   ax,[y2]    ; testing each of the bank boundaries
   cmp   ax,[Y]
   je    pass

   mov   ax,[y2+2]
   cmp       ax,[Y]
   je                pass

   mov   ax,[y2+4]
   cmp       ax,[Y]
   je                pass

   mov   ax,[y2+6]
   cmp       ax,[Y]
   je                pass

   mov   ax,[y2+8]
   cmp       ax,[Y]
   je                pass

   mov   ax,[y2+10]
   cmp       ax,[Y]
   je                pass

   mov   ax,[y2+12]
   cmp       ax,[Y]
   je                pass

   mov   ax,[y2+14]
   cmp       ax,[Y]

   jne       bypass
pass:
   mov ah,4fh   ; adjusting the bank
   mov al,05h
   mov bh,00h
   mov bl,00h
   mov dx,num
   int 10h

bypass:

        mov ax,0A000h      ;writing a single pixel to the display
        mov es,ax
        mov ax,buff
        mov di,ax
        mov al,[si]
        stosb  ; writing pixel ends
        inc si
        ret
        endp

loadbmp:      ;this procedure is for loading in the bitmap
   mov ah,4fh ; set mode to SVGA (101h i.e 640X480 in 256 colours
   mov al,02h
   mov bx,101h
   int 10h

   mov ah,4fh
   mov al,05h
   mov bh,00h
   mov bl,00h
   mov dx,4
   int 10h

   mov  ah,3dh   ; file open
   mov  al,00
   mov  dx, filename
   int  21h       ; file open end

   mov  [handle],ax

   mov  ah,3fh   ; file read
   mov  bx,handle
   mov  cx,54
   mov  dx, params
   int  21h      ; file read end

   mov  byte [col],0  ; reading in the palette
G1:
   mov  ah,3fh
   mov  bx,[handle]
   mov  cx,4
   mov  dx, param
   int  21h
   mov  al,[col]
   mov  dx,3c8h
   out  dx,al
   mov  al,[param+RGBQUAD.red]
   shr  al,2
   mov  dx,3c9h
   out  dx,al
   mov  al,[param+RGBQUAD.green]
   shr  al,2
   out  dx,al
   mov  al,[param+RGBQUAD.blue]
   shr  al,2
   out  dx,al
   cmp  byte [col],255
   inc  byte [col]
   jne  G1        ; palette read ends

   mov  word [Y],479
   mov  word [X],0
A1:
   mov  ah,3fh   ; file read
   mov  bx,[handle]
   mov  cx,640
   mov  dx, [col]
   int  21h      ; file read end

   ; writing a single pixel to the display in SVGA
mov     si, [col]
A2:
   call  putpixel
   inc  word [X]
   cmp  word [X],640
   jne  A2
   mov  word [X],0
   dec  word [Y]
   cmp  word [Y],-1
   jne  A1

   mov  ah,3eh
   mov  bx,[handle]
   int  21h
   ret
0
 
Morph007x2bAuthor Commented:
Graphics.asm:1: unknown preprocessor directive `%xdefine'
Graphics.asm:1: label or instruction expected at start of line
Graphics.asm:2: segment name `sseg' not recognised
Graphics.asm:6: segment name `dseg' not recognised
Graphics.asm:51: segment name `dseg' not recognised
Graphics.asm:58: segment name `dseg' not recognised
Graphics.asm:72: segment name `cseg' not recognised
Graphics.asm:73: unrecognised special symbol `..start'



Fixable? Those are the errors I got.
0
 
dimitryCommented:
Try next command:
NASM.EXE -fobj graphics.asm
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Morph007x2bAuthor Commented:
graphics.asm:1: unknown preprocessor directive `%xdefine'
graphics.asm:1: label or instruction expected at start of line



Shouldn't it be %DEFINE instead of %xdefine??
0
 
Morph007x2bAuthor Commented:
Yep thats it. Thankx a bunch :)!
0
 
Morph007x2bAuthor Commented:
Very helpful, thankx alot :).
0
 
dimitryCommented:
Strange, my NASM ate %xdefine...
Anyway, first, you are welcome. Second, please be aware that the code may no do what you want.
0
 
Morph007x2bAuthor Commented:
Yeah, I relize that now..It gives me a green screen of death, and then the prompt shows strange characters afterwords. Oh well..hmm..any ideas?
0
 
dimitryCommented:
1. What it supposes to do ?
2. Did TASM variant work properly ?
3. There are 4 major issues that I needed to change:
  1) Structure stuff
  2) Offset: mov dx, offset GLEN  <==> mov dx, GLEN
  3) Addressing: mov ax, Y        <==> mov ax, [Y]
  4) "col" processing
0
 
Morph007x2bAuthor Commented:
1. Load and display a bitmap file from A:\logo.bmp
2. Yes - the TASM did actually..
3...What? LOL. Please change..
0
 
Morph007x2bAuthor Commented:
Sorry, for 3 i ment can you change #4? the "col" processing?
0
 
dimitryCommented:
I found several problems, so try the code below.
Can you also descrive Bitmap file, so I'll be able to check it ?
----------------------------------------------------------
%xdefine ? 0
segment sseg stack
       resb 0x100
;.model small
;.stack 100h
segment dseg
;_DATA segment word public 'DATA'
filename  db   'A:\logo.bmp',0  ; insert the name and location
GLEN      db   'Copyright MultiCode Software 2003...' ; of the bitmap here
          db   '$'

handle    dw   ?           ; handle is used to store the file pointer
X         dw   ?           ; X and Y is used to fill the screen with pixels
Y         dw   ?
col       resb 640         ; col is used as a buffer to do a screen line
                           ; at a time
buff      dw   0
          dw   0
          dw   0
          dw   0
multi     dw   6
          dw   4
          dw   0
          dw   0
num       dw   0
y2        dw   409         ; y is used to store where the banks break up
          dw   408
          dw   307
          dw   306
          dw   204
          dw   203
          dw   102
          dw   101

struc BMPHEAD           ; This is the bitmap structure
   .id:          resb   2
   .filesize:    resw   2
   .reserved:    resw   2
   .headersize:  resw   2
   .infosize:    resw   2
   .width2:      resw   2
   .depth:       resw   2
   .biplanes:    resw   1
   .bits:        resw   1
   .bicomp:      resw   2
   .bisizeim:    resw   2
   .bixpels:     resw   2
   .biypels:     resw   2
   .biclrused:   resw   2
   .biclrimp:    resw   2
endstruc

struc RGBQUAD            ; This is how the bitmap stores its colours
   .blue:        resb   1
   .green:       resb   1
   .red:         resb   1
   .fill:        resb   1
endstruc

params:
  istruc BMPHEAD ; assigning the structures to these values
  iend
param:
  istruc RGBQUAD
;    at mt_blue,  db   0
;    at mt_green, db   0
;    at mt_red,   db   0
;    at mt_fill,  db   0
  iend
;_DATA ends
;.code
segment cseg
..start:
   mov  ax, SEG filename; moving all data into required memory position
   mov  ds, ax

   call      loadbmp  ; calls a procedure called loadbmp

   mov      ah,00h   ; waits for a key to be pressed
   int      16h

   mov      ah,00h   ; changes the video mode to the normal setting
   mov      al,02h
   int      10h

   mov  ah, 09h  ; Prints out a message on the screen
   mov  dx, GLEN
   int      21h

   mov      ah,4ch   ; ends the program
   mov      al,0
   int      21h

putpixel:     ; this procedure is for putting a single pixel any
                                          ; where on the display plane
; The linear address of the display plane is=y*640+x
   mov  ax,[Y] ; calculating linear=y2*640 in 16-bit
   mul  word [multi]
   mov  [buff],ax   ; first 16-bit calculation
   mov      ax,100
   mul  word [buff]
   mov  [buff],ax
   mov  [buff+2],dx

   mov  ax,[Y]    ; secound 16-bit calculation
   mul  word [multi+2]
   mov  [buff+4],ax
   mov      ax,10
   mul  word [buff+4]
   mov  [buff+4],ax
   mov  [buff+6],dx

   mov  ax,[buff] ; now adding the two 16-bit values
   add  ax,[buff+4]
   mov  [buff],ax
   mov  ax,[buff+2]
   adc  ax,[buff+6]
   mov  [buff+2],ax

   mov  ax,[X]  ; now adding x to the expression
   add  [buff],ax
   adc  word [buff+2],0   ; expression is now lin=y2*640+x

   mov  ax,[buff]
   mov  dx,[buff+2]

   mov      cx,16       ; calculating bank number
F1:
   sar     dx,1
   rcr     ax,1
   loop      F1
   mov     [num],ax

   mov   ax,[y2]    ; testing each of the bank boundaries
   cmp   ax,[Y]
   je    pass

   mov   ax,[y2+2]
   cmp       ax,[Y]
   je                pass

   mov   ax,[y2+4]
   cmp       ax,[Y]
   je                pass

   mov   ax,[y2+6]
   cmp       ax,[Y]
   je                pass

   mov   ax,[y2+8]
   cmp       ax,[Y]
   je                pass

   mov   ax,[y2+10]
   cmp       ax,[Y]
   je                pass

   mov   ax,[y2+12]
   cmp       ax,[Y]
   je                pass

   mov   ax,[y2+14]
   cmp       ax,[Y]

   jne       bypass
pass:
   mov ah,4fh   ; adjusting the bank
   mov al,05h
   mov bh,00h
   mov bl,00h
   mov dx,num
   int 10h

bypass:

      mov ax,0A000h      ;writing a single pixel to the display
      mov es,ax
        mov ax,[buff]
      mov di,ax
      mov al,[si]
      stosb  ; writing pixel ends
      inc si
      ret
      endp

loadbmp:      ;this procedure is for loading in the bitmap
   mov ah,4fh ; set mode to SVGA (101h i.e 640X480 in 256 colours
   mov al,02h
   mov bx,101h
   int 10h

   mov ah,4fh
   mov al,05h
   mov bh,00h
   mov bl,00h
   mov dx,4
   int 10h

   mov      ah,3dh   ; file open
   mov      al,00
   mov  dx, filename
   int      21h       ; file open end

   mov  [handle],ax

   mov      ah,3fh   ; file read
   mov      bx, [handle]
   mov      cx,54
   mov  dx, params
   int      21h      ; file read end

   mov  byte [col],0  ; reading in the palette
G1:
   mov      ah,3fh
   mov  bx,[handle]
   mov      cx,4
   mov  dx, param
   int      21h
   mov  al,[col]
   mov      dx,3c8h
   out      dx,al
   mov  al,[param+RGBQUAD.red]
   shr      al,2
   mov      dx,3c9h
   out      dx,al
   mov  al,[param+RGBQUAD.green]
   shr      al,2
   out      dx,al
   mov  al,[param+RGBQUAD.blue]
   shr      al,2
   out      dx,al
   cmp  byte [col],255
   inc  byte [col]
   jne      G1        ; palette read ends

   mov  word [Y],479
   mov  word [X],0
A1:
   mov      ah, 3fh   ; file read
   mov  bx, [handle]
   mov      cx, 640
   mov  dx, col
   int      21h      ; file read end

   ; writing a single pixel to the display in SVGA
   mov  si, col
A2:
   call  putpixel
   inc  word [X]
   cmp  word [X],640
   jne       A2
   mov  word [X],0
   dec  word [Y]
   cmp  word [Y],-1
   jne      A1

   mov      ah, 3eh
   mov  bx, [handle]
   int      21h
   ret
0
 
Morph007x2bAuthor Commented:
Before I check it, I'll upload the file.

http://www.multicode.net/logo.bmp
0
 
Morph007x2bAuthor Commented:
The code partially works - it only displays about 50 pixels of the bottom of that bitmap file. Odd..I can't find why it does that.
0
 
dimitryCommented:
I have a flight today, so I'll check this in a few days...Sorry.
0
 
dimitryCommented:
I found the problem, so update the code with chunk below:
pass:
   mov ah,4fh   ; adjusting the bank
   mov al,05h
   mov bh,00h
   mov bl,00h
   mov dx,[num]
   int 10h
0
 
dimitryCommented:
Just curious, is it Ok ? Your NASM program after last
change loads full bitmap.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now