flat assembler
Message board for the users of flat assembler.

Index > Heap > m3ntal's Diary: Code, Macros, Previews

Goto page 1, 2, 3, 4  Next
Author
Thread Post new topic Reply to topic
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal


Last edited by m3ntal on 09 Feb 2014, 06:30; edited 1 time in total
Post 04 Feb 2014, 18:08
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
VARIABLES

Supports standard declarations: char, short, integer, float, double:
Code:
macro verify e {
 if ?s eq 0
  display `e
  'Error: ' e
 end if
}

; define variable of type, name, value

macro !DV type, name, value {
 local l
 l=$
 name type value ; example: msg db 'Hello'
 name#.$=$-l     ; size
}

; define b/w/d/q variable

macro !D1 a, b { !DV db, a, b }
macro !D2 a, b { !DV dw, a, b }
macro !D4 a, b { !DV dd, a, b }
macro !D8 a, b { !DV dq, a, b }

;;;;;;;;;;;;;; DEFINE HL VARIABLE ;;;;;;;;;;;;;;;;

; define X. syntax: type then any a/a=b
; sequence/s separated with ,s. example:
; integer x, y, w=320, h=240
; variables=0 if there is no initial value

macro !D type, [p] {
 common
  if p eq
   'Name expected'
  end if
 forward
  define ?s 0
  match =0 a==b, ?s p \{ ; a=b
   type a, b
   define ?s 1
  \}
  match =0 a=,, ?s p \{  ; a, (next)
   type a, 0
   define ?s 1
  \}
  match =0 a, ?s p \{    ; a (end)
   type a, 0
   define ?s 1
  \}
  verify variable
}

; HL variable names

macro char [a]    { !D !D1, a }
macro short [a]   { !D !D2, a }
macro integer [a] { !D !D4, a }
macro float [a]   { !D !D4, a }
macro double [a]  { !D !D8, a }    
Post 04 Feb 2014, 18:08
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
[ Post removed by author. ]


Last edited by m3ntal on 09 Feb 2014, 06:28; edited 1 time in total
Post 05 Feb 2014, 05:16
View user's profile Send private message Reply with quote
sid123



Joined: 30 Jul 2013
Posts: 340
Location: Asia, Singapore
sid123
Um.... Isn't that a bit insulting?
Nice art btw. Did you use photoshop/paint/etc.? By the art I mean the artwork,
NOT the message it conveys!
I can understand that you and Dex have fights; but why JohnFound and AsmGuru?
uart777;m3ntal;Dex;AsMGuru;Tomasz;revolution;vid;DOS386 are the heart of this community.
You people should stay united which will benefit asm coders.
Post 05 Feb 2014, 12:43
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 18:18; edited 1 time in total
Post 05 Feb 2014, 12:53
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
Update: Deleted "offensive" image.


Last edited by m3ntal on 09 Feb 2014, 06:29; edited 1 time in total
Post 05 Feb 2014, 16:24
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
New design:


Description:
Filesize: 269.49 KB
Viewed: 8535 Time(s)

create.jpg


Post 07 Feb 2014, 21:43
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
New Main Dialog. No setup required. Runs anywhere (Micro SD).

Image

Updated "Create Project". Select system. Displays available languages+library and system information. Example: For NES, there's only the assembler with minimal language and library.

Image

Wizard "Templates" Dialog. Portable custom controls.

Image
Post 09 Feb 2014, 06:28
View user's profile Send private message Reply with quote
sid123



Joined: 30 Jul 2013
Posts: 340
Location: Asia, Singapore
sid123
Wow, is it for x86 also? Need one of them to make life easier.
Post 09 Feb 2014, 13:07
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
Yes. Just ideas and designs for now. What if there was one development package that supports multiple CPUs/OSs?

Microsoft compilers+IDEs have serious problems: Only for Windows, slow startup and compilation, insane size (gigabytes). Time consuming setup, must download required packages, .NET, "upgrades" (always a downgrade) redundant features ("bells and whistles"). After all this, good luck trying to compile a minimal printf("Hello");
Post 09 Feb 2014, 17:30
View user's profile Send private message Reply with quote
sid123



Joined: 30 Jul 2013
Posts: 340
Location: Asia, Singapore
sid123
I couldn't agree more than that. It takes at LEAST two hours of your precious life to set up Visual Studio. .NET Dependencies, All sorts of bloated stuff, And the program that is created in those languages are neither portable nor efficient. Linux IDEs aren't good either, Mono is literally worse that Visual C#. The only IDEs that satisfied me was the FASM IDE, and the NetBeans IDE, the latter being a little bloated.
Post 10 Feb 2014, 11:42
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 671
system error
uart, your work here is excellent. It is only that your language (tokens) isn't easy to remember. Too many dots and '!'.

@sid123, let them fight. When experts argue, noobs benefit. That's what experts are for Very Happy
Post 10 Feb 2014, 12:06
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
Thanks. I design interfaces like this all the time and never show anyone. I'm not satisfied with any of these sketches. I'll think about it for a while. To write code without a design is like trying to build a house without blueprints. You can, but it may not be your best work.

sid123: Recently, I downloaded the free Embedded VC++ to examine the ARM output and I couldn't get it setup. I followed the instructions on M$'s website, downloaded NET, packages, etc. After wasting hours of time waiting for downloads and setups, can't select ARM CPU and Start causes instant crash Sad So, I only use free compilers+assemblers. You mentioned that you were looking for a C compiler. Try TinyCC or CC386 (+IDE).

PS: Writing a 6502 assembler Smile One at a time.
Code:
textai i.names,\
 I.ADC='adc', I.AND='and', I.ASL='asl', I.BCC='bcc',\
 I.BCS='bcs', I.BEQ='beq', I.BIT='bit', I.BMI='bmi',\
 I.BNE='bne', I.BPL='bpl', I.BRK='brk', I.BVC='bvc',\
 I.BVS='bvs', I.CLC='clc', I.CLD='cld', I.CLI='cli',\
 I.CLV='clv', I.CMP='cmp', I.CPX='cpx', I.CPY='cpy',\
 I.DEC='dec', I.DEX='dex', I.DEY='dey', I.EOR='eor',\
 I.INC='inc', I.INX='inx', I.INY='iny', I.JMP='jmp',\
 I.JSR='jsr', I.LDA='lda', I.LDX='ldx', I.LDY='ldy',\
 I.LSR='lsr', I.NOP='nop', I.ORA='ora', I.PHA='pha',\
 I.PHP='php', I.PLA='pla', I.PLP='plp', I.ROL='rol',\
 I.ROR='ror', I.RTI='rti', I.RTS='rts', I.SBC='sbc',\
 I.SEC='sec', I.SED='sed', I.SEI='sei', I.STA='sta',\
 I.STX='stx', I.STY='sty', I.TAX='tax', I.TAY='tay',\
 I.TSX='tsx', I.TXA='txa', I.TXS='txs', I.TYA='tya'    
Post 10 Feb 2014, 15:36
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
90% satisfied with this one:

Image
Post 11 Feb 2014, 07:45
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
Sky, Water, Buddha Quotes

Basic Animation Example.

Image
Excerpts:
Quote:
* "All that we are is the result of all that we have thought"
* "I never see what has been done. I only see what remains to be done"
* "Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and common sense"
* "Doubt everything; find your own Light"
* "Holding onto anger is like grasping a hot coal with the intent of throwing it at someone else; you are the one getting burned"
* "There are only two mistakes one can make along the road to truth; not going all the way, and not starting"
Quote:
"If there is any religion that would cope with modern scientific needs it would be Buddhism". - Albert Einstein
Post 11 Feb 2014, 11:14
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
New I7 .IMAGE compression:
Code:
;;;;;;;;;;;;;;;;;;; COLOR RUN ;;;;;;;;;;;;;;;;;;;;

; get # of consecutive 32BIT values at p.
; return >1 or 1=no repeat. example:
; if p=RED,RED,RED,RED, it returns 4

function count.run.32, p, max
  locals n, c
  . n=0, r0=p, r1=[r0], c=r1
  while c=r1
    . r1=[r0], r0+4, r2=n
    if r2>=max
      break
    end
    . n++
  endw
  . n--
endf n

;;;;;;;;;;;;;;;;;;; LOAD .IMAGE ;;;;;;;;;;;;;;;;;;

; load .IMAGE

function load.i, image, file
  locals i, j, n, x, c, p, q,\
   nc, ps, pc, w, h, r,\
   source, pixels, palette, size
  catch .r
  . r=0

  ; load file, read header and allocate image...

  try file=load.file file
  memory.copy image.header, file, 16

  if [image.header.type]<>'I7'
   go .r
  end
  . r0=image
  . r1=[image.header.w], r2=[image.header.h]
  . [?image.w+r0]=r1, [?image.h+r0]=r2
  . w=r1, h=r2, r1*r2, size=r1
  . r1==>>[image.header.nc], nc=r1

  try create.image image, w, h
  . r0=image, pixels=[?image.p+r0]

  . r0=file, r2=&[r0+16]
  . r1=nc, r1*3, ps=r1, r2+r1, source=r2

  ; create palette, read and convert...

  try palette=allocate 512
  . r0=file, r0+16
  memory.copy palette, r0, ps

  convert.palette.24.32 palette, nc
  reverse.pixels palette, nc

  ; load/uncompress pixels...

  . q=source, p=pixels, r0=[file.n], r0-16
  . r0-ps, n=r0

  loop i to n
    . r0=q, r0==>[r0], c=r0 ; get byte

    ; 0.XXXXXXXb - 1 uncompressed 7BIT

    if c<<=80h
      . r2=palette, r1=c, r0=[r2+r1*4]
      . r1=p, [r1]=r0, p+4, q++, pc=c
      go .next
    end

    ; E0h/1110.XXXXb - repeat 3-15

    . r0=c, r0&11110000b
    if r0=11100000b
      . r0=c, r0&1111b, j=r0
      if j=0
        . j=255
        go .run
      end
      if j=1
        . j=1023
        go .run
      end
      if j>1
        if j<16
          .run:
          . r2=palette
          loop x to j
            . r0=pc, r1=[r2+r0*4]
            . r0=p, [r0]=r1, p+4
          endl
          . q++
          go .next
        end
      end
    end

    . r0=c, r0&11100000b ; 110.ABCDEb - 5 1BIT
    if r0=11000000b
      . r2=palette
      . r1=c, r1>>4, r1&1, r0=[r2+r1*4]
      . r1=p, [r1]=r0, p+4
      . r1=c, r1>>3, r1&1, r0=[r2+r1*4]
      . r1=p, [r1]=r0, p+4
      . r1=c, r1>>2, r1&1, r0=[r2+r1*4]
      . r1=p, [r1]=r0, p+4
      . r1=c, r1>>1, r1&1, r0=[r2+r1*4]
      . r1=p, [r1]=r0, p+4
      . r1=c, r1&1, r0=[r2+r1*4]
      . r1=p, [r1]=r0, p+4
      . q++
      go .next
    end

    . r0=c, r0&11000000b ; 10.AABBCCb - 3 2BIT
    if r0=10000000b
      . r2=palette
      . r1=c, r1>>4, r1&11b, r0=[r2+r1*4]
      . r1=p, [r1]=r0, p+4
      . r1=c, r1>>2, r1&11b, r0=[r2+r1*4]
      . r1=p, [r1]=r0, p+4
      . r1=c, r1&11b, r0=[r2+r1*4]
      . r1=p, [r1]=r0, p+4
      . q++
      go .next
    end

    go .r ; error
    .next:
  endl

  . r=YES
  .r:
  destroy file, palette
endf r

;;;;;;;;;;;;;;;;;;; SAVE .IMAGE ;;;;;;;;;;;;;;;;;;

; save .IMAGE

function save.i, image, file
  locals \
   i, j, k, p, q, n, c, nc, ps, cc, r,\
   source, pixels, palette, size, max, remain,\
   c1, c2, c3, c4, c5, s1, s2, s3, s4, s5
  catch .r

  try create file

  ; setup header, create pixels and 32BPP
  ; palette from image...

  . r=0, r0=image, source=[?image.p+r0]
  . palette=0, [image.header.type]='I7'
  . r1=[?image.w+r0], [image.header.w]=r1
  . r2=[?image.h+r0], [image.header.h]=r2
  . r1*r2, n=r1, r1*4, size=r1

  try pixels=allocate size
  try palette=create.palette image, 127

  . nc=r1, [image.header.nc]=cx, r1*3, ps=r1
  reverse.pixels palette, nc
  convert.palette.32.24 palette, nc

  ; write header and palette...

  try write image.header, 16
  try write palette, ps
  convert.palette.24.32 palette, nc
  reverse.pixels palette, nc

  ; compress pixels

  . q=source, p=pixels
  loop i to n
    . r0=q, r1=[r0], c=r1     ; c=color
    . r2=n, r2-i, max=r2

    get j=count.run.32 q, max ; # appearances

    get k=find.color \        ; get color index
     palette, c, nc

    ; 1110.0001 - repeat 1023
    ; 1110.0000 - repeat 255
    ; 1110.XXXX - repeat 3-15

    if j>1023
      . j=1024
      . r0=k, r1=p, [r1]=al ; write 1st pixel
      . p++, q+4, r0=0E1h   ; repeat byte
      go .run.w
    end
    if j>255
      . j=256
      . r0=k, r1=p, [r1]=al ; write 1st pixel
      . p++, q+4, r0=0E0h   ; repeat byte
      go .run.w
    end
    if j>2                  ; repeat 3-15
      if j>15
        . j=16
      end
      .run:
      . r0=k, r1=p, [r1]=al ; write 1st pixel
      . p++, q+4, r0=0E0h   ; then write
      . r2=j, r2--, r0|r2   ; repeat value
      .run.w:
      . r1=p, [r1]=al, p++
      . r1=j, r1--, i+r1    ; advance loop
      . r1*4, q+r1          ; and source
      go .next
    end

    ; get next 3-5 image pixels if remaining,
    ; lookup palette indices then get sizes

    . remain=max
    if remain>=2
      . r0=q, c1=c, c2=[r0+4], c3=[r0+8]
      get c1=find.color palette, c1, nc
      get c2=find.color palette, c2, nc
      get c3=find.color palette, c3, nc
      get s1=get.bit.size c1
      get s2=get.bit.size c2
      get s3=get.bit.size c3

      if remain>=4
        . r0=q, c4=[r0+12], c5=[r0+16]
        get c4=find.color palette, c4, nc
        get c5=find.color palette, c5, nc
        get s4=get.bit.size c4
        get s5=get.bit.size c5

        ; 5 1BIT indices? 110.ABCDEb

        if s1=1
          if s2=1
            if s3=1
              if s4=1
                if s5=1
                  . r0=11000000b
                  . r1=c1, r1<<4, r0|r1 ; 110.ABCDEb
                  . r1=c2, r1<<3, r0|r1
                  . r1=c3, r1<<2, r0|r1
                  . r1=c4, r1<<1, r0|r1
                  . r1=c5, r0|r1
                  . r1=p, [r1]=al       ; write byte
                  . p++, i+4, q+20      ; advance
                  go .next
                end
              end
            end
          end
        end
      end                               ; remain>4

      ; 3 2BIT indices? 10.AABBCCb

      if s1<=2
        if s2<=2
          if s3<=2
            . r0=10000000b
            . r1=c1, r1<<4, r0|r1 ; 10.AABBCCb
            . r1=c2, r1<<2, r0|r1
            . r1=c3, r0|r1
            . r1=p, [r1]=al       ; write byte
            . p++, i+2, q+12      ; advance
            go .next
          end
        end
      end
    end

    if j=2                  ; write 2 pixels
      . r0=k, r1=p, [r1]=al
      . p++, q+4, i++
      go .one
    end
    if j=1                  ; write 1 pixel
      .one:
      . r0=k, r1=p, [r1]=al
      . p++, q+4
    end
    .next:
  endl

  ; save compressed p/ixels

  . r0=p, r0-pixels, ps=r0
  try write pixels, ps
  . r=YES
  .r:
  close
  destroy palette, pixels
endf r

; load .BMP, save as .IMAGE. .BMP must be
; reduced to 7BIT-1/127 palette and saved
; as 8BPP. no color quantization yet

function convert.bmp.i, image, file
  locale f(256), p
  . r0=&f, p=r0
  text.copy r0, file
  try load.image image, p
  change.ext p, i.ext
  save.i image, p
endf    
Testing:
Code:
; EXAMPLE: TEST.IMAGE. 4X4, 3 COLORS.
; FILE SIZE ONLY 31 BYTES. COMPARE TO 8BPP
; .BMP SIZE: 1094 BYTES, 35+ TIMES BIGGER.
; ENLARGED 8000%

; HEX VIEW (HXD):

; [I7]  [  WIDTH  ] [ HEIGHT  ] [#] [RESERVED]
; 49 37 04 00 00 00 04 00 00 00 03 00 00 00 00 00
; [PALETTE: GRAY, BLUE, BLACK]
; A8 A8 A8 10 20 FF 00 00 00
; [PIXEL DATA]
; CC 00 E3 A8 00 E3

; CC - 110.01100b - 5 1BIT: 0,1,1,0,0 (20)
; 00 - 0.0000000b - INDEX 0 (GRAY)
; E3 - 1110.0011b - REPEAT 3 (12)
; A8 - 10.101000b - 3 2BIT: 2,2,0 (12 BYTES)
; 00 - 0.0000000b - INDEX 0 (GRAY)
; E3 - 1110.0011b - REPEAT 3 (12)

; VERY EFFICIENT! EXAMPLE: 40h E1h E1h =
; INDEX 40h (0.1000000b) THEN REPEAT 1023 X2.
; ENCODES 2047 PIXELS IN 3 BYTES

; pixels begin = 16+(nc*3)
; pixels size = file.size-16-(nc*3)

; EXAMPLE 2: FACE.IMAGE. ONLY 50 BYTES

; 49 37 08 00 00 00 08 00 00 00 03 00 00 00 00 00
; [PALETTE: W/HITE, B/LACK, Y/ELLOW]
; FF FF FF 00 00 00 FF FF 00
; [PIXELS]
; C7 D1 02 E3 91 A6 A6 96 9A 99 9A 02 E3 96 01 E3
; A4 9A A9 00 E2 01 E3 00 00

; C7 - 110.00111b - 5 1BIT: W,W,B,B,B (20)
; D1 - 110.10001b - 5 1BIT: B,W,W,W,B (20)
; 02 - 0.0000010b - INDEX Y=2
; E3 - 1110.0011b - REPEAT 3 (12) (FOREHEAD)
; 91 - 10.010001b - 3 2BIT: B,W,B (12)
; A6 - 10.100110b - 3 2BIT: Y,B,Y (12)
; A6 - 10.100110b - 3 2BIT: Y,B,Y (12)
; 96 - 10.010110b - 3 2BIT: B,B,Y (12)
; 9A - 10.011010b - 3 2BIT: B,Y,Y (12)
; 99 - 10.011001b - 3 2BIT: B,Y,B (12)
; 9A - 10.011010b - 3 2BIT: B,Y,Y (12)
; 02 - 0.0000010b - INDEX Y=2
; E3 - 1110.0011b - REPEAT 3 (12) (MIDDLE)
; 96 - 10.010110b - 3 2BIT: B,B,Y (12)
; 01 - 0.0000001b - INDEX B=1
; E3 - 1110.0011b - REPEAT 3 (12) (MOUTH)
; A4 - 10.100100b - 3 2BIT: Y,B,W (12)
; 9A - 10.011010b - 3 2BIT: B,Y,Y (12)
; A9 - 10.101001b - 3 2BIT: Y,Y,B (12) (CHIN)
; 00 - 0.0000000b - INDEX W=0
; E2 - 1110.0010b - REPEAT 2 (8) (BOTTOM)
; 01 - 0.0000001b - INDEX B=1
; E3 - 1110.0011b - REPEAT 3 (12)
; 00 - 0.0000000b - INDEX W=0
; 00 - 0.0000000b - INDEX W=0    
Post 11 Feb 2014, 12:23
View user's profile Send private message Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 821
Location: Jakarta, Indonesia
TmX
Is the Linux support already working?
I don't have access to Linux system at the moment so couldn't test it.
Post 12 Feb 2014, 02:30
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 18:15; edited 1 time in total
Post 12 Feb 2014, 02:35
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
RLE compression is generally good for computer generated images (screen captures, non-AA ray tracing, etc.). For pictures of real scenes, or dithered computer generated content, things like GIF/PNG (non-lossy) and JPEG (lossy) are usually a better choice.

Actually a GIF/PNG en/decoder is easy to code. Who is up to the task?
Post 12 Feb 2014, 02:37
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 18:14; edited 3 times in total
Post 12 Feb 2014, 02:42
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3, 4  Next

< 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 can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.