Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

I have a very small mind and must live with it. -- E. Dijkstra


programming / alt.lang.asm / Re: Convert DrawImage to Pascal (for Mario Port) ?

SubjectAuthor
* Convert DrawImage to Pascal (for Mario Port) ?skybuck2000
+* Re: Convert DrawImage to Pascal (for Mario Port) ?skybuck2000
|`* Re: Convert DrawImage to Pascal (for Mario Port) ?skybuck2000
| `- Re: Convert DrawImage to Pascal (for Mario Port) ?skybuck2000
+- Re: Convert DrawImage to Pascal (for Mario Port) ?skybuck2000
+- Re: Convert DrawImage to Pascal (for Mario Port) ?skybuck2000
+- Re: Convert DrawImage to Pascal (for Mario Port) ?skybuck2000
`- Re: Convert DrawImage to Pascal (for Mario Port) ?skybuck2000

1
Subject: Convert DrawImage to Pascal (for Mario Port) ?
From: skybuck2...@hotmail.com
Newsgroups: alt.lang.asm
Date: Tue, 4 Feb 2020 04:39 UTC
X-Received: by 2002:a05:620a:13e7:: with SMTP id h7mr27576407qkl.235.1580791186013;
Mon, 03 Feb 2020 20:39:46 -0800 (PST)
X-Received: by 2002:a0d:ca89:: with SMTP id m131mr3438284ywd.509.1580791185805;
Mon, 03 Feb 2020 20:39:45 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder7.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: alt.lang.asm
Date: Mon, 3 Feb 2020 20:39:45 -0800 (PST)
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=84.25.116.141; posting-account=np6u_wkAAADxbE7UBGUIOm-csir6aX02
NNTP-Posting-Host: 84.25.116.141
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <603abff3-c1a8-4a6c-86df-490250e51d5f@googlegroups.com>
Subject: Convert DrawImage to Pascal (for Mario Port) ?
From: skybuck2...@hotmail.com
Injection-Date: Tue, 04 Feb 2020 04:39:46 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
View all headers
Hello,

Now that I have a turbo pascal IDE working in MS-DOS 6.22 in VMWare I can experiment with mario clone source code (mike wieringa) and can confirm that the following assembler routine is very important, it is responsible for drawing all the sprites/bitmaps, except background shades or so:

Now I already tried and convert it myself a little bit, but I think I missed to include some variables.

Anyway if any of you assembler experts could convert this to pascal then that would be awesome and help any conversion for sure:

(I will include my own down below so you could expand on that)

// Including all variables/constants used just in case:

  const
    VGA_SEGMENT           = $A000;

    WINDOWHEIGHT        = 13 * 14;
    WINDOWWIDTH         = 16 * 20;

    SCREEN_WIDTH        = 320;
    SCREEN_HEIGHT       = 200;

    VIR_SCREEN_WIDTH    = SCREEN_WIDTH + 2 * 20;
    VIR_SCREEN_HEIGHT   = 182;
    BYTES_PER_LINE      = VIR_SCREEN_WIDTH div 4;

    MISC_OUTPUT         = $03C2;
    SC_INDEX            = $03C4;
    GC_INDEX            = $03CE;
    CRTC_INDEX          = $03D4;
    VERT_RESCAN         = $03DA;

    MAP_MASK            = 2;
    MEMORY_MODE         = 4;

    VERT_RETRACE_MASK   = 8;

    MAX_SCAN_LINE       = 9;
    START_ADDRESS_HIGH  = $C;
    START_ADDRESS_LOW   = $D;
    UNDERLINE           = $14;
    MODE_CONTROL        = $17;

    READ_MAP            = 4;
    GRAPHICS_MODE       = 5;
    MISCELLANEOUS       = 6;

    MAX_SCREENS         = 24;
    MAX_PAGE            = 1;
    PAGE_SIZE           = (VIR_SCREEN_HEIGHT + MAX_SCREENS) * BYTES_PER_LINE;
    PAGE_0              = 0;
    PAGE_1              = $8000;

    YBASE               = 9;


  const
    InGraphicsMode: Boolean = FALSE;

// implementation

  var
    OldExitProc: Pointer;
    OldScreenMode: Byte;

  const
    XView: Integer = 0;
    YView: Integer = 0;

    Page: Integer = 0;
    PageOffset: Word = 0;

    YOffset: Integer = 0;

    SAFE = 34 * BYTES_PER_LINE;

    Stack: array[0..MAX_PAGE] of Word       (PAGE_0 + PAGE_SIZE + SAFE,
       PAGE_1 + PAGE_SIZE + SAFE);


  procedure DrawImage (XPos, YPos, Width, Height: Integer; var BitMap);
    { Draw an image on the screen (NULL-bytes are ignored) }
  begin
    asm
        push    ds

        mov     ax, VGA_SEGMENT
        mov     es, ax

        mov     ax, YPos
        cmp     ax, VIR_SCREEN_HEIGHT
        jb      @NotNeg
        jg      @End
        mov     bx, ax
        add     bx, Height
        jnc     @End
  @NotNeg:
        mov     bx, BYTES_PER_LINE
        mul     bx
        mov     di, XPos
        mov     bx, di
        shr     di, 1
        shr     di, 1
        add     di, ax                  { DI = (YPos * 80) + XPos / 4 }
        add     di, PageOffset

        lds     si, BitMap              { Point to bitmap }

        and     bl, 3
        mov     cl, bl
        mov     ah, 1
        shl     ah, cl
        sub     bl, 4
        mov     cx, 4                   { 4 planes }

  @Plane:
        push    bx
        push    cx                      { Planes to go }
        push    ax                      { Mask in AH }

        mov     al, MAP_MASK
        mov     dx, SC_INDEX
        out     dx, ax

        cld
        push    di
        mov     bx, Width
        shr     bx, 1
        shr     bx, 1
        mov     ax, BYTES_PER_LINE
        sub     ax, bx                  { Space before next line }
        mov     dx, Height
  @Line:
        mov     cx, bx
        shr     cx, 1

        push    ax
        pushf

  @Pixel:
        lodsw
        or      al, al
        jz      @Skip1
        seges
        mov     [di], al
  @Skip1:
        inc     di
        or      ah, ah
        jz      @Skip2
        seges
        mov     [di], ah
  @Skip2:
        inc     di
        loop    @Pixel

        popf
        rcl     cx, 1
        jcxz    @Skip3

        lodsb
        or      al, al
        jz      @Odd
        stosb
        jmp     @Skip3
  @Odd: inc     di
  @Skip3:
        pop     ax
        add     di, ax
        dec     dx
        jnz     @Line

        pop     di

        pop     ax
        mov     al, ah
        mov     cl, 4
        shl     al, cl
        or      ah, al                  { Mask for next byte }
        rol     ah, 1                   { Bit mask for next plane }
        pop     cx                      { Planes }
        pop     bx
        inc     bl                      { Still in the same byte? }
        adc     di, 0
        loop    @Plane

    @End:
        pop     ds
    end;
  end;


My conversion so far (probably so palette loading code missing, but gives some idea what this does):

type

TWindowsPixel = packed record
case integer of
0 : (Value : integer );
1 : (Blue,Green,Red,Alpha : byte);
end;

TWindowsPixelBuffer = packed record
case integer of
0 : (Lixel : array[0..64000-1] of TWindowsPixel);
1 : (Pixel : array[0..199,0..319] of TWindowsPixel);
end;

TVGAPixel = byte;

TVGAPixelBuffer = packed record

Click here to read the complete article
Subject: Re: Convert DrawImage to Pascal (for Mario Port) ?
From: skybuck2...@hotmail.com
Newsgroups: alt.lang.asm
Date: Thu, 6 Feb 2020 02:30 UTC
References: 1
X-Received: by 2002:a37:6590:: with SMTP id z138mr618646qkb.351.1580956205134;
Wed, 05 Feb 2020 18:30:05 -0800 (PST)
X-Received: by 2002:a5b:c52:: with SMTP id d18mr1061997ybr.59.1580956204965;
Wed, 05 Feb 2020 18:30:04 -0800 (PST)
Path: i2pn2.org!i2pn.org!aioe.org!peer03.am4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: alt.lang.asm
Date: Wed, 5 Feb 2020 18:30:04 -0800 (PST)
In-Reply-To: <603abff3-c1a8-4a6c-86df-490250e51d5f@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=84.25.116.141; posting-account=np6u_wkAAADxbE7UBGUIOm-csir6aX02
NNTP-Posting-Host: 84.25.116.141
References: <603abff3-c1a8-4a6c-86df-490250e51d5f@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e9868cca-3561-4344-ba1a-4d52fd3a99a9@googlegroups.com>
Subject: Re: Convert DrawImage to Pascal (for Mario Port) ?
From: skybuck2...@hotmail.com
Injection-Date: Thu, 06 Feb 2020 02:30:05 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 6302
X-Received-Body-CRC: 3512975864
View all headers
Here is a somewhat reduced example and also an example of the ASM bitmap:

Here is the code I need help with understanding:

const
  VGA_SEGMENT = $A000;

  VIR_SCREEN_WIDTH = SCREEN_WIDTH + 2 * 20;
  VIR_SCREEN_HEIGHT = 182;

  BYTES_PER_LINE = VIR_SCREEN_WIDTH div 4;

  MAP_MASK = 2;

  SC_INDEX = $03C4;

var
  PageOffset: Word = 0;

procedure DrawImage (XPos, YPos, Width, Height: Integer; var BitMap);
    { Draw an image on the screen (NULL-bytes are ignored) }
  begin
    asm
        push    ds

        mov     ax, VGA_SEGMENT
        mov     es, ax

        mov     ax, YPos
        cmp     ax, VIR_SCREEN_HEIGHT
        jb      @NotNeg
        jg      @End
        mov     bx, ax
        add     bx, Height
        jnc     @End
  @NotNeg:
        mov     bx, BYTES_PER_LINE
        mul     bx
        mov     di, XPos
        mov     bx, di
        shr     di, 1
        shr     di, 1
        add     di, ax                  { DI = (YPos * 80) + XPos / 4 }
        add     di, PageOffset

        lds     si, BitMap              { Point to bitmap }

        and     bl, 3
        mov     cl, bl
        mov     ah, 1
        shl     ah, cl
        sub     bl, 4
        mov     cx, 4                   { 4 planes }

  @Plane:
        push    bx
        push    cx                      { Planes to go }
        push    ax                      { Mask in AH }

        mov     al, MAP_MASK
        mov     dx, SC_INDEX
        out     dx, ax

        cld
        push    di
        mov     bx, Width
        shr     bx, 1
        shr     bx, 1
        mov     ax, BYTES_PER_LINE
        sub     ax, bx                  { Space before next line }
        mov     dx, Height
  @Line:
        mov     cx, bx
        shr     cx, 1

        push    ax
        pushf

  @Pixel:
        lodsw
        or      al, al
        jz      @Skip1
        seges
        mov     [di], al
  @Skip1:
        inc     di
        or      ah, ah
        jz      @Skip2
        seges
        mov     [di], ah
  @Skip2:
        inc     di
        loop    @Pixel

        popf
        rcl     cx, 1
        jcxz    @Skip3

        lodsb
        or      al, al
        jz      @Odd
        stosb
        jmp     @Skip3
  @Odd: inc     di
  @Skip3:
        pop     ax
        add     di, ax
        dec     dx
        jnz     @Line

        pop     di

        pop     ax
        mov     al, ah
        mov     cl, 4
        shl     al, cl
        or      ah, al                  { Mask for next byte }
        rol     ah, 1                   { Bit mask for next plane }
        pop     cx                      { Planes }
        pop     bx
        inc     bl                      { Still in the same byte? }
        adc     di, 0
        loop    @Plane

    @End:
        pop     ds
    end;
  end;

{ Example of ASM bitmap enemy }

procedure GRKOOPA000; assembler;
asm
  db   0,  0,  0,  0,  0,  0, 23,  0,  0,  0,  0, 31,  0,  0,  0
  db   0, 31, 16,  0,  0,  0, 31, 81,  0,  0,  0, 31, 77,  0,  0
  db   0, 31, 78,  0,  0,  0, 31, 78,  0,  0, 16,127, 53,  0,  0
  db  16, 78, 83, 17, 17, 16, 53, 74,113,112, 16, 73,104,116,115
  db  16, 16,104,115,114,  0, 16, 28,129,129,  0, 83, 30,115,114
  db   0, 76, 30,128,112,  0, 16, 30,114,113,  0, 16,111,114,113
  db   0,  0,135, 18, 96,  0,  0,130, 26, 26,  0,  0, 16,134,134
  db   0, 16, 76,120,120,  0, 29, 83,  0, 76,  0, 16, 16,  0, 16
  db   0,  0,  0,  0,  0,  0, 23,  0,  0,  0,  0, 31,  0,  0,  0
  db   0, 31,  0,  0,  0, 16, 31, 16,  0,  0, 16, 31, 76,  0,  0
  db  16, 31, 77,  0,  0, 18,127, 77,  0,  0, 84, 78, 75,  0,  0
  db  84, 78, 16,128,  0, 83, 74, 25,114,112, 76, 16, 31,116,113
  db  76, 81, 31,129,115, 18, 83, 20,118,112,  0, 77, 16,117,113
  db   0, 77, 16,115,112,  0, 83, 16,112,114,  0, 74, 23,114,114
  db   0,  0, 31, 16, 18,  0,  0,134, 26, 26,  0, 16,128,134,134
  db   0, 76, 76,120,120,  0, 77, 83, 17,132,  0, 16, 16,  0, 16
  db   0,  0,  0,  0,  0,  0, 19,  0,  0,  0, 16, 20,  0,  0,  0
  db  23, 20,  0,  0,  0, 18, 20,  0,  0,  0, 17, 20, 17,  0,  0
  db  17,125, 17,  0,  0, 25,133, 17,  0,  0, 78, 78, 17,  0,  0
  db  77, 78,  0,128,  0, 78, 76,104,118,  0, 78, 81,104,129, 16
  db  78, 76,104,117,113, 74, 74,113,119,114,  0, 73, 96,119, 96
  db   0, 73,114,116,114,  0, 73,114,113,114,  0, 18,113,112,112
  db   0, 16,104,112, 16,  0, 16, 27, 26, 26,  0, 74,134,134, 55
  db   0, 77,120,120, 19,  0, 77, 17, 76, 28,  0, 16,  0, 16, 16
  db   0,  0,  0,  0,  0, 20,  0,  0,  0,  0, 22, 19,  0,  0,  0
  db  28, 16,  0,  0,  0, 25,120,  0,  0,  0, 22, 73,  0,  0,  0
  db  23, 77,  0,  0,  0,135, 53,  0,  0,  0, 76, 78,  0,  0,  0
  db  74, 53,  0,112,  0, 78, 76,128,113,  0, 77, 81,114,130,  0
  db  83, 81,114,129, 16, 83, 23,112,118, 16, 17, 23,113,117, 16
  db  17, 23,128,114, 16,  0, 23,115,112, 16,  0, 23,113,112, 16
  db   0,122, 96, 16,  0,  0, 18, 26, 26, 16,  0, 74,134,134, 16
  db   0, 77,120,120,  0,104, 83,  0, 76, 16, 16, 16,  0, 16, 16
end;

Bye,
  Skybuck.


Subject: Re: Convert DrawImage to Pascal (for Mario Port) ?
From: skybuck2...@hotmail.com
Newsgroups: alt.lang.asm
Date: Thu, 6 Feb 2020 15:13 UTC
References: 1 2
X-Received: by 2002:aed:2510:: with SMTP id v16mr3084887qtc.306.1581001991371;
Thu, 06 Feb 2020 07:13:11 -0800 (PST)
X-Received: by 2002:a81:a903:: with SMTP id g3mr3495114ywh.427.1581001991175;
Thu, 06 Feb 2020 07:13:11 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder7.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: alt.lang.asm
Date: Thu, 6 Feb 2020 07:13:10 -0800 (PST)
In-Reply-To: <e9868cca-3561-4344-ba1a-4d52fd3a99a9@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=84.25.116.141; posting-account=np6u_wkAAADxbE7UBGUIOm-csir6aX02
NNTP-Posting-Host: 84.25.116.141
References: <603abff3-c1a8-4a6c-86df-490250e51d5f@googlegroups.com> <e9868cca-3561-4344-ba1a-4d52fd3a99a9@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3feaedb7-f960-4d87-9574-d7832982598e@googlegroups.com>
Subject: Re: Convert DrawImage to Pascal (for Mario Port) ?
From: skybuck2...@hotmail.com
Injection-Date: Thu, 06 Feb 2020 15:13:11 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
View all headers
Finally a better working example for Delphi VCL Application:

Add two buttons and two paintboxes to a form and paste this code:

(ScreenWidth and ScreenHeight constants added)

(This code also includes the mario palette used and shows how to attach it to a pointer, it also shows how to get a pointer to the bitmap and pass it to the drawimage. I am not sure if width/height is indeed 16 by 16 for this bitmap but I think so, could be wrong though, might also be 16/32 or something will try...)

// *** Code Start Here ***


unit UnitMain;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System..Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;

type
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    ButtonDrawPalette: TButton;
    ButtonDrawImage: TButton;
    PaintBox2: TPaintBox;
    procedure ButtonDrawPaletteClick(Sender: TObject);
    procedure ButtonDrawImageClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

const
  VGA_SEGMENT = $A000;

  SCREEN_WIDTH = 320;
  SCREEN_HEIGHT = 200;

  VIR_SCREEN_WIDTH = SCREEN_WIDTH + 2 * 20;
  VIR_SCREEN_HEIGHT = 182;

  BYTES_PER_LINE = VIR_SCREEN_WIDTH div 4;

  MAP_MASK = 2;

  SC_INDEX = $03C4;

var
  PageOffset: Word = 0;


type
Trgb = packed record
r,g,b : byte;
end;

type
PpalRGB = ^TpalRGB;
TpalRGB = array[0..255] of Trgb;

PROCEDURE pal256; ASSEMBLER;
ASM
  DB  0, 0, 0, 0,10,41,12,28,18, 2,43,22,35,19, 9,58, 0, 0,57,35
  DB 12,43,43,47,24,24,28,20,24,60,10,60,15,31,47,63,62,56,20,60
  DB 56,22,63,61,36,63,63,63
  DB  0, 0, 0, 5, 5, 5, 8, 8, 8,11,11,11,14,14,14,17,17,17,20,20
  DB 20,24,24,24,28,28,28,32,32,32,36,36,36,40,40,40,45,45,45,50
  DB 50,50,56,56,56,63,63,63
  DB 13,12,15,15,16,22,17,20,29,19,24,36,21,28,43,23,31,50,25,34
  DB 57,26,42,63, 0,15, 2, 1,22, 4, 2,29, 6, 3,36, 8, 4,43,10, 5
  DB 50,12, 6,57,14,20,63,40
  DB 18, 6, 7,25,12,11,33,17,14,40,23,18,48,28,21,55,34,25,62,39
  DB 27,63,48,36,15, 3, 2,22, 6, 4,29, 9, 6,36,12, 8,43,15,10,50
  DB 18,12,57,21,14,63,28,20
  DB 15, 0, 0,22, 7, 0,29,15, 0,36,23, 0,43,31, 0,50,39, 0,57,47
  DB  0,63,55, 0,15, 5, 3,22,11, 7,29,17,11,36,23,15,43,29,19,50
  DB 35,23,57,41,27,63,53,34
  DB 28,14,12,33,20,14,38,26,16,43,32,18,48,38,20,53,44,22,58,50
  DB 24,63,56,30, 5, 5, 6,10,10,13,15,15,20,20,20,27,25,25,34,30
  DB 30,41,35,35,48,44,44,63
  DB  3, 6, 5, 5,11, 9, 7,16,13, 9,21,17,11,26,21,13,31,25,15,36
  DB 29,20,48,38, 6, 6, 7,13,13,15,20,20,23,27,27,31,34,34,39,41
  DB 41,47,48,48,55,57,57,63
  DB  6,15, 4,12,22, 8,18,29,12,24,36,16,30,43,20,36,50,24,42,57
  DB 28,54,63,35,15,10,10,22,16,16,29,21,21,36,27,27,43,32,32,50
  DB 38,38,57,43,43,63,54,54
  DB 15,15, 6,22,22,12,29,29,18,36,36,24,43,43,30,50,50,36,57,57
  DB 42,63,63,54, 2, 4,14, 6,12,21,10,20,28,14,28,35,18,36,42,22
  DB 44,49,26,52,56,36,63,63
  DB 18, 4,14,24, 8,21,31,12,28,37,16,35,44,20,42,50,24,49,57,28
  DB 56,63,38,63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  DB  0, 0, 0, 0, 0,53,44,22
  DB  9, 8,12,16,14,16,22,21,20,29,27,24,35,34,28,42,40,32,48,47
  DB 36,57,56,43, 8,12,16,14,16,22,21,20,29,27,24,35,34,28,42,40
  DB 32,48,47,36,57,56,43,63
  DB 13, 9,11,21,16,15,27,22,18,36,29,22,42,35,25,51,42,29,57,48
  DB 32,63,56,39, 6,14, 9,12,21,14,18,27,22,24,33,28,30,39,36,36
  DB 46,42,42,52,47,50,59,53
  DB  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  DB  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  DB  0, 0, 0, 0, 0, 0, 0, 0
  DB  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  DB  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  DB  0, 0, 0, 0, 0, 0, 0, 0
  DB  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  DB  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  DB  0, 0, 0, 0, 0, 0, 0, 0
  DB  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  DB  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  DB  0, 0, 0, 0, 0, 0, 0, 0
END;

{ Example of ASM bitmap enemy }

procedure GRKOOPA000; assembler;
asm
  db   0,  0,  0,  0,  0,  0, 23,  0,  0,  0,  0, 31,  0,  0,  0
  db   0, 31, 16,  0,  0,  0, 31, 81,  0,  0,  0, 31, 77,  0,  0
  db   0, 31, 78,  0,  0,  0, 31, 78,  0,  0, 16,127, 53,  0,  0
  db  16, 78, 83, 17, 17, 16, 53, 74,113,112, 16, 73,104,116,115
  db  16, 16,104,115,114,  0, 16, 28,129,129,  0, 83, 30,115,114
  db   0, 76, 30,128,112,  0, 16, 30,114,113,  0, 16,111,114,113
  db   0,  0,135, 18, 96,  0,  0,130, 26, 26,  0,  0, 16,134,134
  db   0, 16, 76,120,120,  0, 29, 83,  0, 76,  0, 16, 16,  0, 16
  db   0,  0,  0,  0,  0,  0, 23,  0,  0,  0,  0, 31,  0,  0,  0
  db   0, 31,  0,  0,  0, 16, 31, 16,  0,  0, 16, 31, 76,  0,  0
  db  16, 31, 77,  0,  0, 18,127, 77,  0,  0, 84, 78, 75,  0,  0
  db  84, 78, 16,128,  0, 83, 74, 25,114,112, 76, 16, 31,116,113
  db  76, 81, 31,129,115, 18, 83, 20,118,112,  0, 77, 16,117,113
  db   0, 77, 16,115,112,  0, 83, 16,112,114,  0, 74, 23,114,114
  db   0,  0, 31, 16, 18,  0,  0,134, 26, 26,  0, 16,128,134,134
  db   0, 76, 76,120,120,  0, 77, 83, 17,132,  0, 16, 16,  0, 16
  db   0,  0,  0,  0,  0,  0, 19,  0,  0,  0, 16, 20,  0,  0,  0
  db  23, 20,  0,  0,  0, 18, 20,  0,  0,  0, 17, 20, 17,  0,  0
  db  17,125, 17,  0,  0, 25,133, 17,  0,  0, 78, 78, 17,  0,  0
  db  77, 78,  0,128,  0, 78, 76,104,118,  0, 78, 81,104,129, 16
  db  78, 76,104,117,113, 74, 74,113,119,114,  0, 73, 96,119, 96
  db   0, 73,114,116,114,  0, 73,114,113,114,  0, 18,113,112,112
  db   0, 16,104,112, 16,  0, 16, 27, 26, 26,  0, 74,134,134, 55
  db   0, 77,120,120, 19,  0, 77, 17, 76, 28,  0, 16,  0, 16, 16
  db   0,  0,  0,  0,  0, 20,  0,  0,  0,  0, 22, 19,  0,  0,  0
  db  28, 16,  0,  0,  0, 25,120,  0,  0,  0, 22, 73,  0,  0,  0
  db  23, 77,  0,  0,  0,135, 53,  0,  0,  0, 76, 78,  0,  0,  0
  db  74, 53,  0,112,  0, 78, 76,128,113,  0, 77, 81,114,130,  0
  db  83, 81,114,129, 16, 83, 23,112,118, 16, 17, 23,113,117, 16
  db  17, 23,128,114, 16,  0, 23,115,112, 16,  0, 23,113,112, 16
  db   0,122, 96, 16,  0,  0, 18, 26, 26, 16,  0, 74,134,134, 16
  db   0, 77,120,120,  0,104, 83,  0, 76, 16, 16, 16,  0, 16, 16
end;

procedure DrawImage (XPos, YPos, Width, Height: Integer; var BitMap);
    { Draw an image on the screen (NULL-bytes are ignored) }
  begin
(*
    asm
push    ds

mov     ax, VGA_SEGMENT
mov     es, ax

mov     ax, YPos
cmp     ax, VIR_SCREEN_HEIGHT
jb      @NotNeg
jg      @End
mov     bx, ax
        add     bx, Height
        jnc     @End
  @NotNeg:
mov     bx, BYTES_PER_LINE
        mul     bx
        mov     di, XPos
        mov     bx, di
        shr     di, 1
        shr     di, 1
add     di, ax                  { DI = (YPos * 80) + XPos / 4 }
        add     di, PageOffset

        lds     si, BitMap              { Point to bitmap }

        and     bl, 3
        mov     cl, bl
        mov     ah, 1
        shl     ah, cl
        sub     bl, 4
        mov     cx, 4                   { 4 planes }

Click here to read the complete article
Subject: Re: Convert DrawImage to Pascal (for Mario Port) ?
From: skybuck2...@hotmail.com
Newsgroups: alt.lang.asm
Date: Thu, 6 Feb 2020 15:18 UTC
References: 1 2 3
X-Received: by 2002:aed:2510:: with SMTP id v16mr3112338qtc.306.1581002307194;
Thu, 06 Feb 2020 07:18:27 -0800 (PST)
X-Received: by 2002:a05:6902:70e:: with SMTP id k14mr3574453ybt.304.1581002307049;
Thu, 06 Feb 2020 07:18:27 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder7.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: alt.lang.asm
Date: Thu, 6 Feb 2020 07:18:26 -0800 (PST)
In-Reply-To: <3feaedb7-f960-4d87-9574-d7832982598e@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=84.25.116.141; posting-account=np6u_wkAAADxbE7UBGUIOm-csir6aX02
NNTP-Posting-Host: 84.25.116.141
References: <603abff3-c1a8-4a6c-86df-490250e51d5f@googlegroups.com>
<e9868cca-3561-4344-ba1a-4d52fd3a99a9@googlegroups.com> <3feaedb7-f960-4d87-9574-d7832982598e@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <38b8d426-1f2c-4fdc-9dfe-defc7bb3bc4b@googlegroups.com>
Subject: Re: Convert DrawImage to Pascal (for Mario Port) ?
From: skybuck2...@hotmail.com
Injection-Date: Thu, 06 Feb 2020 15:18:27 +0000
Content-Type: text/plain; charset="UTF-8"
View all headers
I think bitmap width and height might actually be:

20x24

This was indicated in the mirror function.

Yes now I am sure:

W = 20;
H = 24;

So DrawImage should be called as follows:

        DrawImage( 0, 0, 20,24, (@GRKOOPA000)^ );

This should give best success of trying to decode it.

Bye for now,
  Skybuck.


Subject: Re: Convert DrawImage to Pascal (for Mario Port) ?
From: skybuck2...@hotmail.com
Newsgroups: alt.lang.asm
Date: Thu, 6 Feb 2020 17:56 UTC
References: 1
X-Received: by 2002:a0c:e1ce:: with SMTP id v14mr3354365qvl.39.1581011794146;
Thu, 06 Feb 2020 09:56:34 -0800 (PST)
X-Received: by 2002:a25:c54a:: with SMTP id v71mr4156010ybe.6.1581011793836;
Thu, 06 Feb 2020 09:56:33 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder7.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: alt.lang.asm
Date: Thu, 6 Feb 2020 09:56:33 -0800 (PST)
In-Reply-To: <603abff3-c1a8-4a6c-86df-490250e51d5f@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=84.25.116.141; posting-account=np6u_wkAAADxbE7UBGUIOm-csir6aX02
NNTP-Posting-Host: 84.25.116.141
References: <603abff3-c1a8-4a6c-86df-490250e51d5f@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f61f6dc1-47ad-4ed0-8d91-5631d06f3eaf@googlegroups.com>
Subject: Re: Convert DrawImage to Pascal (for Mario Port) ?
From: skybuck2...@hotmail.com
Injection-Date: Thu, 06 Feb 2020 17:56:34 +0000
Content-Type: text/plain; charset="UTF-8"
View all headers
Smart Mike ! ;) =D

HE provided everything needed to reverse engineer this !

Thank god it can be reversed engineer by running GRED.exe in VMWare.

It's the graphical editor used to create sprites/bitmaps.

TAB allows changing colors
Arrows can be used to draw or mouse.
X places a color

F4 seems to save *. and *.$

The $ extension contains the ASM/PAS source code.

So now with smart placement of pixels I can try and reverse engineer this format.

alt-h
and
alt-v

sets the width and height of the bitmap/sprite.

Bye for now,
  Skybuck.


Subject: Re: Convert DrawImage to Pascal (for Mario Port) ?
From: skybuck2...@hotmail.com
Newsgroups: alt.lang.asm
Date: Thu, 6 Feb 2020 22:39 UTC
References: 1
X-Received: by 2002:ac8:1206:: with SMTP id x6mr4949430qti.55.1581028800297;
Thu, 06 Feb 2020 14:40:00 -0800 (PST)
X-Received: by 2002:a81:a903:: with SMTP id g3mr5241164ywh.427.1581028800094;
Thu, 06 Feb 2020 14:40:00 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder7.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: alt.lang.asm
Date: Thu, 6 Feb 2020 14:39:59 -0800 (PST)
In-Reply-To: <603abff3-c1a8-4a6c-86df-490250e51d5f@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=84.25.116.141; posting-account=np6u_wkAAADxbE7UBGUIOm-csir6aX02
NNTP-Posting-Host: 84.25.116.141
References: <603abff3-c1a8-4a6c-86df-490250e51d5f@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0e7eb1bf-9f7f-4c80-ba35-284f5a23d2b6@googlegroups.com>
Subject: Re: Convert DrawImage to Pascal (for Mario Port) ?
From: skybuck2...@hotmail.com
Injection-Date: Thu, 06 Feb 2020 22:40:00 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
View all headers
This version is shorter/simpler it doesn't skip over zero bytes/colors but does extract colors from the bitmap and renders it onto the screen, so this one should be easier to convert to Delphi to try and understand how the bytes are extracted and maybe put onto the screen/xmode:

  procedure PutImage (XPos, YPos, Width, Height: Integer; var BitMap);
    { Draw an image on the screen (NULL-bytes are NOT ignored) }
  begin
    asm
        push    ds
        push    es
        mov     ax, VGA_SEGMENT
        mov     es, ax

        mov     ax, YPos
        mov     bx, BYTES_PER_LINE
        mul     bx
        mov     di, XPos
        mov     bx, di
        shr     di, 1
        shr     di, 1
        add     di, ax                  { DI = (YPos * 80) + XPos / 4 }
        add     di, PageOffset

        lds     si, BitMap              { Point to bitmap }

        and     bl, 3
        mov     cl, bl
        mov     ah, 1
        shl     ah, cl
        sub     bl, 4
        mov     cx, 4                   { 4 planes }

  @Plane:
        push    bx
        push    cx                      { Planes to go }
        push    ax                      { Mask in AH }

        mov     al, MAP_MASK
        mov     dx, SC_INDEX
        out     dx, ax

        cld
        push    di
        mov     bx, Width
        shr     bx, 1
        shr     bx, 1
        mov     ax, BYTES_PER_LINE
        sub     ax, bx                  { Space before next line }
        mov     dx, Height
  @Line:
        mov     cx, bx
        shr     cx, 1
        rep     movsw
        rcl     cx, 1
        rep     movsb
        add     di, ax
        dec     dx
        jnz     @Line

        pop     di

        pop     ax
        mov     al, ah
        mov     cl, 4
        shl     al, cl
        or      ah, al                  { Mask for next byte }
        rol     ah, 1                   { Bit mask for next plane }
        pop     cx                      { Planes }
        pop     bx
        inc     bl                      { Still in the same byte? }
        adc     di, 0
        loop    @Plane


        pop     es
        pop     ds
    end;
  end;

Bye,
  Skybuck.


Subject: Re: Convert DrawImage to Pascal (for Mario Port) ?
From: skybuck2...@hotmail.com
Newsgroups: alt.lang.asm
Date: Thu, 6 Feb 2020 22:50 UTC
References: 1
X-Received: by 2002:aed:2f45:: with SMTP id l63mr4996427qtd.221.1581029438873; Thu, 06 Feb 2020 14:50:38 -0800 (PST)
X-Received: by 2002:a25:c650:: with SMTP id k77mr5207949ybf.4.1581029438729; Thu, 06 Feb 2020 14:50:38 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder7.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: alt.lang.asm
Date: Thu, 6 Feb 2020 14:50:38 -0800 (PST)
In-Reply-To: <603abff3-c1a8-4a6c-86df-490250e51d5f@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=84.25.116.141; posting-account=np6u_wkAAADxbE7UBGUIOm-csir6aX02
NNTP-Posting-Host: 84.25.116.141
References: <603abff3-c1a8-4a6c-86df-490250e51d5f@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <77ac7b46-0edf-4a49-892f-3bc360faa8a3@googlegroups.com>
Subject: Re: Convert DrawImage to Pascal (for Mario Port) ?
From: skybuck2...@hotmail.com
Injection-Date: Thu, 06 Feb 2020 22:50:38 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 9
View all headers
This document about how VGA works might be of some use:

http://www.mcamafia.de/pdf/ibm_vgaxga_trm2.pdf

Still "draft" not sure if it contains grave-errors.

(I may upload this later to my web drive project)

Bye,
  Skybuck.


Subject: Re: Convert DrawImage to Pascal (for Mario Port) ?
From: skybuck2...@hotmail.com
Newsgroups: alt.lang.asm
Date: Fri, 7 Feb 2020 08:08 UTC
References: 1
X-Received: by 2002:a37:e20a:: with SMTP id g10mr6196031qki.423.1581062894785;
Fri, 07 Feb 2020 00:08:14 -0800 (PST)
X-Received: by 2002:a25:c650:: with SMTP id k77mr6935606ybf.4.1581062894586;
Fri, 07 Feb 2020 00:08:14 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder7.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: alt.lang.asm
Date: Fri, 7 Feb 2020 00:08:14 -0800 (PST)
In-Reply-To: <603abff3-c1a8-4a6c-86df-490250e51d5f@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=84.25.116.141; posting-account=np6u_wkAAADxbE7UBGUIOm-csir6aX02
NNTP-Posting-Host: 84.25.116.141
References: <603abff3-c1a8-4a6c-86df-490250e51d5f@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a12aceb1-d597-4aae-9344-9bca72528d2c@googlegroups.com>
Subject: Re: Convert DrawImage to Pascal (for Mario Port) ?
From: skybuck2...@hotmail.com
Injection-Date: Fri, 07 Feb 2020 08:08:14 +0000
Content-Type: text/plain; charset="UTF-8"
View all headers
This problem has mostly be solved in different ways/versions.

Visit this link to see all versions:

http://www.skybuck.org/Source/Pascal/Games/Mario/Tests/test%20drawing%20graphics%20from%20asm%20files/version%200.03%20(try%20again%20from%20scratch)/

<X> = version number.

Look for files called Main.pas.v<X>.<SomeComments>.txt

Latest version is:

// let's try and get rid of the annoying page for loop
// the divisions could be replaced with shr 2, but compiler might already optimize
// that as well.
// draw ok.
// page is calculated by vPixelIndex mod 4, which is same as "and 3".
procedure TForm1.Button1Click(Sender: TObject);
var
// vTransformIndex : TTransformIndex;
vBitmapWidth : integer;
vBitmapHeight : integer;
vPage : word;
vBitmapIndex : word;
vPixelIndex : word;
vPaletteIndex : TPaletteIndex;

vX, vY : integer;

begin
vBitmapWidth := 20;
vBitmapHeight := 24;

vPixelIndex := 0;
for vY := 0 to vBitmapHeight-1 do
begin
for vX := 0 to vBitmapWidth-1 do
begin
vPage := vPixelIndex and 3;

vBitmapIndex := vPage * 120 + (vY * (vBitmapWidth div 4)) + vX div 4;
vPaletteIndex := iTurtle[vBitmapIndex];

// palette r,g,b is only 0..63 so multiply by 4 to get 0..255 rgb values.
mPixelMap.Lixel[vPixelIndex].mRed := iPalette[vPaletteIndex].mRed * 4;
mPixelMap.Lixel[vPixelIndex].mGreen := iPalette[vPaletteIndex].mGreen * 4;
mPixelMap.Lixel[vPixelIndex].mBlue := iPalette[vPaletteIndex].mBlue * 4;

vPixelIndex := vPixelIndex + 1;
end;
end;

PixelMapControl1.Repaint;
end;

Special thanks to Colin for helping with formulas ! =D

Bye,
  Skybuck.


1

rocksolid light 0.8.3
clearneti2ptor