flat assembler
Message board for the users of flat assembler.

Index > Main > Is it possible to change assembling point? / Patching macros

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 25 Jul 2008, 19:37
revolution wrote:
Org starts a new section, with a new base and offset.
Are you sure? AFAIK org just sets new base for following instructions, not section or offset [cf. MZ Exe]. When I was assembling bitmap fonts in .Fon, the problem was in absolute/relative offsets, so I extensively use $ and $$...
Post 25 Jul 2008, 19:37
View user's profile Send private message Reply with quote
Grom PE



Joined: 13 Mar 2008
Posts: 114
Location: i@grompe.org.ru
Grom PE 26 Jul 2008, 12:02
I wrote new patching macros!
Now they allow setting base for code between "patchat" macros.
Adding functionality is almost as easy as writing your own programs now =)

Code:
; Patching macros
; v0.60
; for flat assembler by Grom PE

; How it works:
; - File name and size are specified with "patchfile"
; - On every "patchat", part of file is loaded and added,
;   (or zeroes if file is ended) assembling point moves to
;   specified offset.
; - On "patchend", if there part of file left, it is added.
; - "patchsection x" makes every following "patchat" macro
;   act like "org x" was placed after it.

; Notes:
; - Don't use "org" directive between all patching macros!

;  For good example on how to use patching macros look:
;  http://board.flatassembler.net/topic.php?t=8876

p_savedorg = 0
p_sectionset = 0

macro pushorg value*
{
  p_wasorg = $
  org value
  p_inorg = $
  p_savedorg = 1
}

macro poporg
{
  local orgsize
  orgsize = $ - p_inorg
  org p_wasorg + orgsize
  p_savedorg = 0
}

macro patchsection value*
{
  p_sectionset = 1
  p_sectionorg = value
}

macro patchfile name*
{
  virtual
    @@:
    file name
    p_filesize = $ - @b
  end virtual
  p_start = $
  p_pointer = 0
  p_filename equ name
}

macro patchat address*
{
  if p_savedorg = 1
    poporg
  end if

  p_pointer = p_pointer - p_start + $
  p_toadd = address - $

  if address >= 0
    if p_toadd >= 0
      if p_pointer + p_toadd <= p_filesize
        file p_filename: p_pointer, p_toadd
      else
        p_addpart = 0
        if p_pointer < p_filesize
          p_addpart = p_filesize - p_pointer
          file p_filename: p_pointer, p_addpart
        end if
        rb p_toadd - p_addpart
      end if
    else
      "Error: can't move backwards."
    end if
  else
    "Error: invalid address, must be >= 0."
  end if

  p_start = $
  p_pointer = p_pointer + p_toadd

  if p_sectionset = 1
    pushorg p_sectionorg + address
  end if
}

macro patchend
{
  if p_savedorg
    poporg
  end if

  p_pointer = p_pointer - p_start + $
  p_toadd = p_filesize - $

  if p_toadd >= 0
    if p_pointer + p_toadd <= p_filesize
      file p_filename: p_pointer, p_toadd
    else
      p_addpart = 0
      if p_pointer < p_filesize
        p_addpart = p_filesize - p_pointer
        file p_filename: p_pointer, p_addpart
      end if
      db p_toadd - p_addpart dup 0
    end if
  end if
}    
Post 26 Jul 2008, 12:02
View user's profile Send private message Visit poster's website Reply with quote
Grom PE



Joined: 13 Mar 2008
Posts: 114
Location: i@grompe.org.ru
Grom PE 26 Jul 2008, 12:09
By the way, I'm still interested in modifying fasm source code to allow changing assembling point.
Post 26 Jul 2008, 12:09
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.