?
Solved

TASM to NASM???

Posted on 2003-03-15
17
Medium Priority
?
712 Views
Last Modified: 2007-12-19
I need to convert www.multicode.net/graphics.asm to NASM code..How?! Help please.
0
Comment
Question by:Morph007x2b
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 8
17 Comments
 
LVL 11

Accepted Solution

by:
dimitry earned 600 total points
ID: 8144652
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
 
LVL 1

Author Comment

by:Morph007x2b
ID: 8144803
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
 
LVL 11

Expert Comment

by:dimitry
ID: 8144824
Try next command:
NASM.EXE -fobj graphics.asm
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:Morph007x2b
ID: 8144886
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
 
LVL 1

Author Comment

by:Morph007x2b
ID: 8144890
Yep thats it. Thankx a bunch :)!
0
 
LVL 1

Author Comment

by:Morph007x2b
ID: 8144893
Very helpful, thankx alot :).
0
 
LVL 11

Expert Comment

by:dimitry
ID: 8144916
Strange, my NASM ate %xdefine...
Anyway, first, you are welcome. Second, please be aware that the code may no do what you want.
0
 
LVL 1

Author Comment

by:Morph007x2b
ID: 8144922
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
 
LVL 11

Expert Comment

by:dimitry
ID: 8144969
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
 
LVL 1

Author Comment

by:Morph007x2b
ID: 8144971
1. Load and display a bitmap file from A:\logo.bmp
2. Yes - the TASM did actually..
3...What? LOL. Please change..
0
 
LVL 1

Author Comment

by:Morph007x2b
ID: 8144979
Sorry, for 3 i ment can you change #4? the "col" processing?
0
 
LVL 11

Expert Comment

by:dimitry
ID: 8145765
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
 
LVL 1

Author Comment

by:Morph007x2b
ID: 8146488
Before I check it, I'll upload the file.

http://www.multicode.net/logo.bmp
0
 
LVL 1

Author Comment

by:Morph007x2b
ID: 8146497
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
 
LVL 11

Expert Comment

by:dimitry
ID: 8152199
I have a flight today, so I'll check this in a few days...Sorry.
0
 
LVL 11

Expert Comment

by:dimitry
ID: 8152925
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
 
LVL 11

Expert Comment

by:dimitry
ID: 8169358
Just curious, is it Ok ? Your NASM program after last
change loads full bitmap.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
"Any files you do not have backed up in at least two [other] places are files you do not care about."
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question