flat assembler
Message board for the users of flat assembler.

flat assembler > Projects and Ideas > Some help request with FreshLib

Author
Thread Post new topic Reply to topic
JohnFound



Joined: 16 Jun 2003
Posts: 3475
Location: Bulgaria
I am really busy these days and don't have time to implement some features. They are not vital for FreshLib, but will be good if implemented.

So, graphics programmers volunteers needed. Smile

The function is image scaling. Here is the desired interface. Notice that the operation scales the image from random rectangle to other random rectangle:

Code:
proc ScaleBlendImage, .ImgSrc, .xSrc, .ySrc, .wSrc, .hSrc, .ImgDst, .xDst, .yDst, .wDst, .hDst    


The procedure scales a rectangle (.xSrc, .ySrc, .wSrc, .hSrc) from the image [.ImgSrc] to the size of destination rectangle (.xDst, .yDst, .wDst, .hDst) and draws the scaled rectangle over the image [.ImgDst].

Arguments:
.ImgSrc - the source image with format described below.
.xSrc. .ySrc - the upper left corner XY coordinates of the source rectangle.
.wSrc, .hSrc - the width and height of the source rectangle.
.ImgDst - destination image.
.xDst, .yDst - the upper left corner XY coordinates of the destination rectangle.
.wDst, .hDst - the width and height of the destination rectangle.


The image structure is simple:

Code:
struct TImage
  .width   dd ?  ; width in pixels.
  .height  dd ?  ; height in pixels.
  .pPixels dd ?  ; pointer to the pixel memory buffer.
ends    


The pixel format is always dword ARGB, not pre multiplied alpha. The scan lines are aligned on dword.

The code must be OS independent. So, calling OS graphics functions is not allowed. 32bit code is needed. MMX is OK, but other extensions are questionable (at least I don't use them in the remaining part of the library).

I can provide some help on the integration in the library and testing, but not too time consuming.

_________________
Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9


Last edited by JohnFound on 12 Oct 2015, 20:24; edited 2 times in total
Post 27 Sep 2015, 09:48
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
codestar



Joined: 25 Dec 2014
Posts: 254
John: Please check out my Kolibri games or Abakis > Kolibri > SYSTEM.INC/DRAW.INC. It features manual drawing (ARGB) and partially portable input. Preview:
Code:
; $$$$$$$$$$$$$$$$$$$ ABAKIS $$$$$$$$$$$$$$$$$$$$$
; *************** STAR^2 SOFTWARE ****************
; ?????????????????? DRAW.INC ????????????????????

; fast portable graphics

include 'color.inc'
include 'box.inc'

;;;;;;;;;;;;;;;;;;;;; SCREEN ;;;;;;;;;;;;;;;;;;;;;

align

void vga.p

integer os.w, os.h, os.bpp,\
 screen.x, screen.y, screen.w, screen.h,\
 screen.n, screen.bpp, screen.size,\
 screen.pw, screen.pitch

void palette.p

BOX g.box

function set.screen, w, h, bpp
  alias n=r0, pw=r1
  . screen.w=w, screen.h=h   ; size
  . r0=os.w, r0/2, r1=w
  . r1/2, r0-r1, screen.x=r0
  . r0=os.h, r0/2, r1=h
  . r1/2, r0-r1, screen.x=r0
  . n=w, n*h, screen.n=n     ; # pixels
  . pw=bpp, pw/8             ; pixel width
  . screen.pw=pw, n*pw       ; screen size
  . screen.size=n            ; in bytes
  . n=w, n*pw                ; screen pitch
  . screen.pitch=n           ; w in bytes
  . screen.bpp=bpp           ; bits per pixel
endf

;;;;;;;;;;;;;;;;;;;; DRAWING ;;;;;;;;;;;;;;;;;;;;;

; erase screen with color

function clear.screen, c
  alias p=r0, n=r1, z=r2
  . p=vga.p, n=screen.n, z=c
  loop n, (u32) *p++=z, endl
endf

; calculate x/y offset: (y*screen.w+x)*4

macro get.xy x, y
  { . r0=y, r0*screen.w, r0+x, r0*4 }

; address &vga[(y*screen.w+x)*4]

function vga.xy, x, y
  get.xy x, y
  . r0+vga.p
endf

; draw pixel

function draw.pixel, x, y, c
  alias p=r0, z=r1
  try clip.pixel x, y
  vga.xy x, y
  . z=c, (u32) *p=z
endf 1

; draw horizontal line

function draw.line.h, x, y, n, c
  alias p=r0, z=r1, w=r2
  . p=&x, z=&y, w=&n
  try clip.line 0, p, z, w
  vga.xy x, y
  . z=c
  loop n, (u32) *p++=z, endl
endf 1

; draw vertical line

function draw.line.v, x, y, n, c
  locals swb
  alias p=r0, z=r1, h=r2
  . p=&x, z=&y, h=&n
  try clip.line 1, p, z, h
  vga.xy x, y
  . z=c, swb=screen.pitch
  loop n, (u32) *p=z, p+swb, endl
endf 1

; draw solid rectangle

function draw.box, x, y, w, h, c
  locals i
  try visible x, y, w, h
  . i=y, i--
  loop h, i++
    draw.line.h x, i, w, c
  endl
endf 1

; draw rectangle outline

function draw.outline, x, y, w, h, c
  try visible x, y, w, h
  draw.line.h x, y, w, c    ; top
  . r0=y, r0+h, r0--        ; bottom
  draw.line.h x, r0, w, c
  . r0=y, r0++, r1=h, r1-2  ; left
  draw.line.v x, r0, r1, c
  . r0=x, r0+w, r0--
  . r2=y, r2++, r1=h, r1-2  ; right
  draw.line.v r0, r2, r1, c
endf 1

macro draw.box.s b, c
 { draw.box b#.x, b#.y, b#.w, b#.h, c }
macro draw.box.o b, c
 { draw.outline b#.x, b#.y, b#.w, b#.h, c }

macro draw.box a, b, c, d, e {
  IF ~e eq
    draw.box a, b, c, d, e
  ELSE IF ~d eq
    'Unsupported'
  ELSE IF ~c eq
    draw.box.s a, b
    draw.box.o a, c
  ELSE IF ~b eq
    draw.box.s a, b
  END IF
}

; draw scanline

function draw.scanline, pixels, x, y, w
  locals i
  alias p=r0, s=r1
  . r0=&i, r1=&x, r2=&y, r3=&w
  try clip.scanline r0, r1, r2, r3
  vga.xy x, y
  . s=pixels, s+i
  loop w, (u32) *p++=*s++, endl
endf 1

; draw scanline with transparent key

function draw.scanline.t, pixels, x, y, w, key
  locals i
  alias p=r0, s=r1, c=r2
  . r0=&i, r1=&x, r2=&y, r3=&w
  try clip.scanline r0, r1, r2, r3
  vga.xy x, y
  . s=pixels, s+i
  loop w, (u32) c=*s++
    if c<>key, (u32) *p=c, end, p+4
  endl
endf 1

; draw scanline with inverted x

function draw.scanline.ix, pixels, x, y, w
  locals i
  alias p=r0, s=r1
  . r0=x, r0+w
  vga.xy r0, y
  . p-4, s=pixels
  loop w, (u32) *p--=*s++, endl
endf 1

; draw variant scanline. pixels are
; grayscale, alpha intensity of co=color.
; for brushes and special effects

function draw.scanline.v, pixels, x, y, w, co
  locals a, i
  alias p=r0, s=r1, c=r2, c2=r3
  . r0=&i, r1=&x, r2=&y, r3=&w
  try clip.scanline r0, r1, r2, r3
  vga.xy x, y
  . s=pixels, s+i
  loop w, (u32) c=*s++
    . a=c, a&0FFh
    if a=0, go .next, end
    if a=0FFh, c=co, go .draw, end
    . (u32) c2=*p
    push p s
    get c=mix co, c2, a
    pop s p
    .draw: . (u32) *p=c
    .next: . p+4
  endl
endf 1

; draw bitmap

function draw.bitmap, pixels, x, y, w, h
  locals i, p
  try visible x, y, w, h
  . i=y, p=pixels
  loop h
    draw.scanline p, x, i, w
    . r0=w, r0*4, p+r0, i++
  endl
endf 1

; draw bitmap with transparency by
; upper left pixel color (X=0, Y=0)

function draw.bitmap.t, pixels, x, y, w, h
  locals i, p, key
  try visible x, y, w, h
  . i=y, r0=pixels, p=r0
  . (u32) r0=*r0, key=r0
  loop h
    draw.scanline.t p, x, i, w, key
    . r0=w, r0*4, p+r0, i++
  endl
endf 1

; draw bitmap with inverted x

function draw.bitmap.ix, pixels, x, y, w, h
  locals i, p
  try visible x, y, w, h
  . p=pixels
  loop h
    draw.scanline.ix p, x, y, w
    . r0=w, r0*4, p+r0, y++
  endl
endf 1

; draw bitmap with inverted y

function draw.bitmap.iy, pixels, x, y, w, h
  locals i, p
  try visible x, y, w, h
  . r0=h, r0--, y+r0, p=pixels
  loop h
    draw.scanline p, x, y, w
    . r0=w, r0*4, p+r0, y--
  endl
endf 1

; draw bitmap with both inverted

function draw.bitmap.ixy, pixels, x, y, w, h
  locals i, p, n
  try visible x, y, w, h
  . p=pixels
  loop h
    draw.scanline.ix p, x, y, w
    . r0=w, r0*4, p+r0, y--
  endl
endf 1

; draw variant bitmap

function draw.bitmap.v, pixels, x, y, w, h, c
  locals i, p
  try visible x, y, w, h
  . i=y, r0=pixels, p=r0
  loop h
    draw.scanline.v p, x, i, w, c
    . r0=w, r0*4, p+r0, i++
  endl
endf 1

; draw gradual vertical fade from
; color a to b. o/rient:
; 'h'=horizontal, 'v'=vertical

function draw.fade, bo, c1, c2
  locals x, y, w, h, i, n, c,\
   r, g, b, red, green, blue,\
   nr, ng, nb, first, last
  . r0=bo,\
   x=[?box.x+r0], y=[?box.y+r0],\
   w=[?box.w+r0], h=[?box.h+r0]

  . r0=y, first=r0, r1=h
  . n=r1, r0+r1, last=r0

  . r0=&r, r1=&g, r2=&b
  get.rgb c1, r0, r1, r2
  . r0=&red, r1=&green, r2=&blue
  get.rgb c2, r0, r1, r2

  . r<<8, g<<8, b<<8, r1=n
  if r1=0, r1++, end
  . r0=red, r0<<8, r0-r, r0/r1, nr=r0
  . r0=green, r0<<8, r0-g, r0/r1, ng=r0
  . r0=blue, r0<<8, r0-b, r0/r1, nb=r0

  . i=first
  forever
    . r0=r, r0>>8, r1=g, r1>>8, r2=b, r2>>8
    get c=rgb r0, r1, r2
    draw.line.h x, i, w, c
    . r0=nr, r+r0, r1=ng, g+r1, r2=nb, b+r2
    . i++, r0=last
    if i>r0, go .out, end
  endfv
  .out:
endf

; draw with vertical center fade:
; a to b then b to a

function draw.shade, bo, a, b
  memory.copy g.box, bo, 16
  . g.box.h>>>1
  draw.fade g.box, a, b
  . r0=g.box.h, g.box.y+r0
  draw.fade g.box, b, a
endf

;;;;;;;;;;;;;;;;; PALETTE PIXELS ;;;;;;;;;;;;;;;;;

; 8BPP versions with pa/lette. no clipping

function draw.scanline.8, pixels, x, y, w
  alias p=r0, s=r1, c=r2, q=r3
  vga.xy x, y
  . s=pixels
  loop w, q=*s++, q*4, q+palette.p
    . (u32) c=*q, (u32) *p++=c
  endl
endf 1

function draw.bitmap.8, pixels, x, y, w, h
  locals i, p
  try visible x, y, w, h
  . i=y, i--, p=pixels
  loop h, i++
    draw.scanline.8 p, x, i, w
    . r0=w, p+r0
  endl
endf 1

;;;;;;;;;;;;;;;;;;;;; SPECIAL ;;;;;;;;;;;;;;;;;;;;

; special variant 8BPP with alpha bias for
; fonts and sketching effects (example:
; chalkboard)

A.LIGHTEST=128
A.LIGHTER=96
A.LIGHT=64
A.DARK=-32
A.DARKER=-64
A.DARKEST=-96

align
integer alpha.bias=0 ; A.DARKEST

function draw.scanline.v.8, pixels, x, y, w, co
  locals a, i
  alias p=r0, s=r1, c=r2, c2=r3, q=r3
  vga.xy x, y
  . s=pixels
  loop w, q=*s++, q*4, q+palette.p
    . (u32) c=*q, a=c, a&0FFh
    if a=0, go .next, end
    . (u32) c2=*p
    push p s
    . r0=a
    if alpha.bias, r0+alpha.bias
      if r0<0, r0=0
      else.if r0>255, r0=255, end
    end
    get c=mix co, c2, r0
    pop s p
    .draw: . (u32) *p=c
    .next: . p+4
  endl
endf 1

function draw.bitmap.v.8, pixels, x, y, w, h, c
  locals i, p
  try visible x, y, w, h
  . i=y, i--, p=pixels
  loop h, i++
    draw.scanline.v.8 p, x, i, w, c
    . r0=w, p+r0
  endl
endf 1    
Code:
;;;;;;;;;;;;;;;;;;;;; SYSTEM ;;;;;;;;;;;;;;;;;;;;;

; menuet interrupt: eax, ebx, ecx, edx

macro mint a, b, c, d {
 IF ~a eq
  . r0=a
 END IF
 IF ~b eq
  . r3=b
 END IF
 IF ~c eq
  . r1=c
 END IF
 IF ~d eq
  . r2=d
 END IF
 db 0CDh, 40h
}

; events

EVENT.REDRAW=1
EVENT.KEY=2
EVENT.BUTTON=3

align
integer timer.speed=-1,\
 timer.counter, event.delay=1

macro set.timer n {
  . r0=n, r1=10, r0/r1
  . timer.speed=r0, timer.counter=r0
}

macro get.timer { mint 26, 9 }

macro delay x {
  . r0=x, r0/100, r3=r0
  mint 5
}

macro wait.event { mint 23, event.delay }

;;;;;;;;;;;;;;;;;;;;; MEMORY ;;;;;;;;;;;;;;;;;;;;;

macro create.heap        { mint 68, 11 }
macro os.allocate n      { mint 68, 12, n }
macro os.reallocate p, n { mint 68, 20, p, n }
macro os.destroy p       { mint 68, 13, p }

;;;;;;;;;;;;;;; ALLOCATE, DESTROY ;;;;;;;;;;;;;;;;

; allocate n
; allocate.p &p, n
; destroy &p

; example: try p=allocate 4*KB

function allocate, n
  os.allocate n
endf

function allocate.p, p, n
  if p=0
    allocate n
    return
  end
  os.reallocate p, n
endf

function destroy, p
  if p
    os.destroy p
  end
endf

macro destroy [p] { forward destroy p }

;;;;;;;;;;;;;;;;;;;;; INPUT ;;;;;;;;;;;;;;;;;;;;;;

align integer event.type

; keyboard

integer key, old.key, key.event
text keys.t(128)

numeric KEY.ESCAPE=27, KEY.SPACE=' ',\
 KEY.UP=0B2h, KEY.RIGHT=0B3h, KEY.DOWN=0B1h,\
 KEY.LEFT=0B0h, KEY.A='a', KEY.S='s',\
 KEY.D='d', KEY.W='w'

macro get.key.buffer { mint 26, 2, 1, keys.t }

; mouse

integer mouse.event,\
 mouse.1, mouse.2, mouse.x, mouse.y,\
 mouse.drag, mouse.drag.x, mouse.drag.y,\
 mouse.drop, mouse.drop.x, mouse.drop.y,\
 old.mouse.1, old.mouse.2,\
 old.mouse.x, old.mouse.y

macro get.mouse.xy      { mint 37, 0 }
macro get.mouse.buttons { mint 37, 2 }
macro get.mouse.wheel   { mint 37, 3 }

function update.mouse
  . mouse.event=0
  . old.mouse.1=mouse.1, old.mouse.2=mouse.2
  . old.mouse.x=mouse.x, old.mouse.y=mouse.y

  get.mouse.xy
  . r1=r0, r1&0FFFFh, r0>>>16, r0&0FFFFh
  . mouse.x=r0, mouse.y=r1
  get.mouse.buttons
  . r1=r0, r1&1, mouse.1=r1
  . r1=r0, r1&2, mouse.2=r1

  if mouse.1
    if not old.mouse.1, mouse.event='c'
      . mouse.drop=NO
      callf on.mouse
      return 1
    end
  else.if old.mouse.1, mouse.event='r'
    callf on.mouse
    if mouse.drag
      . mouse.drop=YES,\
      mouse.drop.x=mouse.x,\
      mouse.drop.y=mouse.y,\
      mouse.drag=NO
      . mouse.event='d'
      callf on.mouse
    end
    return 1
  end
  . r0=mouse.x, r1=old.mouse.x
  if r0<>r1
    .mouse.move:
    . mouse.event='m'
    callf on.mouse
    if mouse.1
      if not mouse.drag
        . mouse.drag=YES,\
        mouse.drag.x=mouse.x,\
        mouse.drag.y=mouse.y
      end
    else
      . mouse.drop=NO
    end
    return 1
  else
    . r0=mouse.y, r1=old.mouse.y
    if r0<>r1
      go .mouse.move
    end
  end
endf 0

align

integer window.x, window.y

function select.box, box
  . r0=mouse.x, r1=mouse.y
  . r0-window.x, r1-window.y
  callf point.inside, box, r0, r1
endf

macro if.select box { !if select.box, box }
macro else.if.select box
 { !else.if select.box, box }

;;;;;;;;;;;;;;;;;;;;; RANDOM ;;;;;;;;;;;;;;;;;;;;;

align integer @seed

; generate unique random number: 0-n

function random, n
  . r0=@seed
  if false
    rdtsc
    . @seed=r0
  end
  . r0*343FDh, r0+269EC3h,\
  @seed=r0, r0>>16, r0&7FFFh,\
  r1=n, r1+1, r0/r1, r0=r2
endf

; random(from-to-2)+from

function random.x, from, to
  . r0=from, r0-to, r0-2
  random r0
  . r0+from
endf

;;;;;;;;;;;;;;;;;;;;; IMAGE ;;;;;;;;;;;;;;;;;;;;;;

function os.draw.image, pixels, x, y, w, h
  pusha
  . r1=w, r1<<16, r1|h
  . r2=x, r2<<16, r2|y
  . r3=pixels, r6=32, r7=0, ebp=w, ebp*4, ebp-ebp
  mint 65
  popa
endf

;;;;;;;;;;;;;;;;;;;;; SCREEN ;;;;;;;;;;;;;;;;;;;;;;

; align void vga.p

function get.screen.w
  mint 14
  . r0>>16, os.w=r0
endf

function get.screen.h
  mint 14
  . r0&0FFFFh, os.h=r0
endf

function show.vga
  os.draw.image vga.p, 0, 0, WINDOW.W, WINDOW.H
endf

function create.vga, w, h, c
  if vga.p=0, r0=w, r0*h, r0*4
    try vga.p=allocate r0
  end
  call !clear.screen, c
endf 1


function set.vga, w, h
  ; ...
endf

function end.vga
  destroy vga.p
endf

;;;;;;;;;;;;;;;;;;;;; WINDOW ;;;;;;;;;;;;;;;;;;;;;

function os.draw.window
  . r2=0, r6=0, r7=0FFFFFFh
  . r3=window.x, r3<<16, r3|screen.w
  . r1=window.y, r1<<16, r1|screen.h
  mint 0
endf

macro draw.begin { mint 12, 1 }
macro draw.end   { mint 12, 2 }
macro render     { call !on.draw }
macro retrace    { mint 18, 14 }

;;;;;;;;;;;;;;;;;;;;;; MAIN ;;;;;;;;;;;;;;;;;;;;;;

; main entry. detect current input states,
; translate and redirect to on.event handlers.

!main!:
  create.heap
  get.screen.w
  get.screen.h
  callf set.screen,\
   SCREEN.W, SCREEN.H, SCREEN.BPP
  create.vga WINDOW.W, WINDOW.H, 0
  callf on.create

  . r0=os.w, r0/2, r1=screen.w
  . r1/2, r0-r1, window.x=r0
  . r0=os.h, r0/2, r1=screen.h
  . r1/2, r0-r1, window.y=r0


  get.event:
  wait.event
  . event.type=r0

  update.mouse

  if timer.speed<>-1
    . timer.counter--
    if timer.counter<=0
      . timer.counter=timer.speed
      callf on.timer
    end
  end

  if event.type=EVENT.REDRAW
    draw.begin
    callf os.draw.window
    callf on.draw
    draw.end

  else.if event.type=EVENT.KEY
    mint 2
    if r0<>1, r0>>8, r0&0FFh, key=r0
      . key.event='k'
      callf on.key
      . key.event='c'
      callf on.key
      if key=KEY.ESCAPE
        callf exit
      end
    end

  else.if event.type=EVENT.BUTTON
    callf exit
  end
go get.event

function exit
  callf end.vga
  callf on.exit
  mint -1
endf    
Example game: Binary Master:
Code:
; BINARY MASTER

WINDOW.W=360
WINDOW.H=492

include 'kolibri.inc'

text t(256), title.t='Binary Master: %hh'

text help.t=+\
 'Fun Game for Programmers.' RET\
 'Click BITs. Count in binary.' RET\
 'Match the decimal number' RET\
 'in the red box to make rows' RET\
 'disappear. Press any key.' RET\
 'r=Reset. p=Pause. Esc=exit'

text pause.t=+\
 'Paused. Press p to continue' RET\
 'or r=Reset. Esc=exit'

text game.over.t=+\
 'Game over. Score: %hh.' RET\
 'Press any key'

align

integer scene, score
numeric SCENE.*, TITLE, PLAY,\
 PAUSE, GAME.OVER
numeric EASY=5000, NORMAL=4000, HARD=2000

BOX board, my.box
integer my.n, red.n, magic.n=10101101b
integer cbit.x, cbit.y, bits.h
numeric BIT.*, W=32, H=48

text my.numbers(8+4), red.numbers(8+4)

FONT main.font='font'

IMAGE bits.i='bits', bit1.i='1',\
 bit0.i='0', close.i='x'

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

function random.byte
  locals n
  .r:
  random 3
  if r0<2
    random 16
  else.if r0=2
    random 128
  else.if r0=3
    random 255
  end
  . n=r0
  text.find red.numbers, n
  if true, go .r, end
  . r0=n
  if false, r0++, end
endf

function reset.game
  locals n, p
  . score=0, bits.h=1
  memory.zero my.numbers, 12
  memory.zero red.numbers, 12
  . n=8, p=red.numbers
  loop n
    random.byte
    . r1=p, *r1++=r0, p=r1
  endl
  set.box board, 4, 70, BIT.W*8, BIT.H*8
  . scene=SCENE.TITLE
endf

function on.create
  set.font main.font
  set.timer NORMAL
  reset.game
endf

function remove.byte, t, i
  locals n
  alias p=r0, q=r1, x=r2
  if i=7, go .new, end
  . p=t, p+i, q=p, q++, x=7, x-i, n=x
  loop n, *p++=*q++, endl
  .new:
  . p=my.numbers, *(p+7)=0
  random.byte
  . q=red.numbers, *(q+7)=r0
endf

function remove.row, i
  remove.byte my.numbers, i
  remove.byte red.numbers, i
  . bits.h--
  if bits.h<1, bits.h=1, end
endf

function check.numbers
  locals i
  . i=0
  while i<8, r0=my.numbers, r0+i
    . r1=*r0, r0=red.numbers
    . r0+i, r2=*r0
    if r1=r2, score+r1
      remove.row i
      return 1
    end
    . i++
  endw
endf 0

function draw.board
  locals i, n, x, y, w, h
  draw.image bits.i, 4, 35
  draw.image bits.i, 4, 457
   . x=0, y=0, w=32, h=48
  while y<8, x=0
    while x<8
      . r0=x, r0*w, r0+board.x
      . r1=y, r1*h, r1+board.y
      set.box my.box, r0, r1, w, h
      draw.box my.box, WHITE, GRAY
      . x++
    endw
    . r0=x, r0*w, r0+board.x
    . r1=y, r1*h, r1+board.y
    set.box my.box, r0, r1, 48, h
    draw.box.o my.box, WHITE
    . my.box.x+48
    draw.box.o my.box, RED
    . r0=y, r1=8, r1-bits.h
    if r0>=r1
      . r0=my.numbers, r1=y, r2=8
      . r2-bits.h, r1-r2, r0+r1
      . r1=*r0, my.n=r1
      . r0=red.numbers, r1=y, r2=8
      . r2-bits.h, r1-r2, r0+r1
      . r1=*r0, red.n=r1
      u2t my.n, t
      . my.box.x-40, my.box.y+11
      draw.text t, my.box.x, my.box.y
      . my.box.x+44
      u2t red.n, t
      draw.text t, my.box.x, my.box.y
    end
    . y++
  endw
endf

function draw.bit, n, x, y
  if n
    draw.image bit1.i, x, y
  else
    draw.image bit0.i, x, y
  end
endf

function draw.byte, n, x, y
  locals i
  . i=8
  loop i, r0=n, r1=i, r1--, r0>>cl, r0&1
    draw.bit r0, x, y
    . x+BIT.W
  endl
endf

function draw.my.numbers
  locals i, n, y
  . i=bits.h, y=404
  loop i, r0=my.numbers, r0+i, r0--
    . r0=*r0, n=r0
    draw.byte n, 4, y
    . y-BIT.H
  endl
endf

function draw.title.scene
  draw.text help.t, 16, 130
  draw.byte magic.n, 50, 300
endf

function draw.play.scene
  draw.board
  draw.my.numbers
endf

function draw.pause.scene
  draw.text pause.t, 16, 130
  draw.byte magic.n, 50, 300
endf

function draw.game.over
  print t, game.over.t, score
  draw.text t, 44, 170
  draw.byte magic.n, 50, 300
endf

function on.draw
  locals x, y, w, h
  clear.screen BLACK
  print t, title.t, score
  draw.text t, 4, 4
  draw.image close.i, 324, 4
  . r0=screen.w, r0--
  . r1=screen.h, r1--
  draw.outline 0, 0, r0, r1, GRAY
  if scene=SCENE.TITLE
    draw.title.scene
  else.if scene=SCENE.PLAY
    draw.play.scene
  else.if scene=SCENE.PAUSE
    draw.pause.scene
  else.if scene=SCENE.GAME.OVER
    draw.game.over
  end
  show.vga
endf

function on.key
  if key.event='c'
    if scene=SCENE.TITLE
      . scene=SCENE.PLAY
      go .draw
    end
    if scene=SCENE.GAME.OVER
      go .reset
    end
    if key='r'
      .reset:
      reset.game
      go .draw
    end
    if key='p'
      .pause:
      if scene=SCENE.PLAY
        . scene=SCENE.PAUSE
      else.if scene=SCENE.PAUSE
        . scene=SCENE.PLAY
      end
      go .draw
    end
    .draw:
    render
  end
endf

function on.mouse
  if.select board
    . r0=mouse.x, r0-window.x, r0-board.x
    . r1=BIT.W, r0/r1, cbit.x=r0
    . r0=mouse.y, r0-window.y, r0-board.y
    . r1=BIT.H, r0/r1, cbit.y=r0
    if mouse.event='c'
      . r0=cbit.y, r1=8, r1-bits.h
      if r0>=r1, r0=my.numbers, r1=cbit.y
        . r2=8, r2-bits.h, r1-r2, r0+r1
        . r3=*r0, r2=1, r1=7, r1-cbit.x
        . r2<<cl, r3><r2, *r0=r3
      end
    end
  end
  if mouse.event='r'
    check.numbers
    go .draw
  end
  if mouse.event='c'
    . r0=&close.i.x
    if.select r0
      exit
    end
    if scene<>SCENE.PLAY
      reset.game
      . scene=SCENE.PLAY
    end
    .draw:
    render
  end
endf

function on.timer
  if scene<>SCENE.PLAY
    return
  end
  if mouse.1, return, end
  if bits.h<8, bits.h++
  else
    . scene=SCENE.GAME.OVER
  end
  render
endf

function on.exit
  ; ...
endf    
Post 12 Oct 2015, 18:07
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3475
Location: Bulgaria
codestar, I am not searching for reference sources or some help to implement the above task. I simply don't have time to deal with this procedure that is good to have, but not vital or even important.

So, if someone (you?) want to contribute the code for FreshLib - the interface is in my first post.

The implementation should follow, at least loosely, the coding style of FreshLib and to not use macros more than really needed. (And they must obey the assembly style: label: COP operand, operand, operand, ...)
Post 12 Oct 2015, 20:14
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
borbonhause



Joined: 18 Oct 2015
Posts: 23
You need to resize images? I use this golang library for that, it may come in handy as a reference: https://github.com/nfnt/resize

m := resize.Resize(x, y, img, resize.NearestNeighbor) gives good enough result if you need to shrink image to something 6 times smaller, but you may need to try different algorithms if you have to shrink only a little, or to make new image larger.

I'm afraid I'm not going to recode it into assembler by hand, I'm not skilled in that at all.
Post 09 Nov 2015, 17:13
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3475
Location: Bulgaria
@borbonhause, there are many libraries, but we need pure FASM solution, because FreshLib is targeted to systems where the external libraries are not available.
Post 09 Nov 2015, 18:32
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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-2018, Tomasz Grysztar.

Powered by rwasa.