flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Projects and Ideas > Some help request with FreshLib

Author
Thread Post new topic Reply to topic
JohnFound



Joined: 16 Jun 2003
Posts: 3434
Location: Bulgaria
Some help request with FreshLib
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: A48DEF727DF44C3B5C2E576B65021F1A45D8FA52E2F8E257F1CAE148BBADB162FDF7820BD1F9


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.wos.hos.bpp,\
 screen.xscreen.yscreen.wscreen.h,\
 screen.nscreen.bppscreen.size,\
 screen.pwscreen.pitch

void palette.p

BOX g.box

function set.screenwhbpp
  alias n=r0pw=r1
  . screen.w=wscreen.h=h   ; size
  . r0=os.wr0/2r1=w
  . r1/2r0-r1screen.x=r0
  . r0=os.hr0/2r1=h
  . r1/2r0-r1screen.x=r0
  . n=wn*hscreen.n=n     ; # pixels
  . pw=bpppw/8             ; pixel width
  . screen.pw=pwn*pw       ; screen size
  . screen.size=n            ; in bytes
  . n=wn*pw                ; screen pitch
  . screen.pitch=n           ; w in bytes
  . screen.bpp=bpp           ; bits per pixel
endf

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

; erase screen with color

function clear.screenc
  alias p=r0n=r1z=r2
  . p=vga.pn=screen.nz=c
  loop n, (u32) *p++=zendl
endf

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

macro get.xy xy
  { . r0=yr0*screen.wr0+xr0*4 }

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

function vga.xyxy
  get.xy xy
  . r0+vga.p
endf

; draw pixel

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

; draw horizontal line

function draw.line.hxync
  alias p=r0z=r1w=r2
  . p=&xz=&yw=&n
  try clip.line 0pzw
  vga.xy xy
  . z=c
  loop n, (u32) *p++=zendl
endf 1

; draw vertical line

function draw.line.vxync
  locals swb
  alias p=r0z=r1h=r2
  . p=&xz=&yh=&n
  try clip.line 1pzh
  vga.xy xy
  . z=cswb=screen.pitch
  loop n, (u32) *p=zp+swbendl
endf 1

; draw solid rectangle

function draw.boxxywhc
  locals i
  try visible xywh
  . i=yi--
  loop hi++
    draw.line.h xiwc
  endl
endf 1

; draw rectangle outline

function draw.outlinexywhc
  try visible xywh
  draw.line.h xywc    ; top
  . r0=yr0+hr0--        ; bottom
  draw.line.h xr0wc
  . r0=yr0++, r1=hr1-2  ; left
  draw.line.v xr0r1c
  . r0=xr0+wr0--
  . r2=yr2++, r1=hr1-2  ; right
  draw.line.v r0r2r1c
endf 1

macro draw.box.s bc
 { draw.box b#.xb#.yb#.wb#.hc }
macro draw.box.o bc
 { draw.outline b#.xb#.yb#.wb#.hc }

macro draw.box abcde {
  IF ~e eq
    draw.box abcde
  ELSE IF ~d eq
    'Unsupported'
  ELSE IF ~c eq
    draw.box.s ab
    draw.box.o ac
  ELSE IF ~b eq
    draw.box.s ab
  END IF
}

; draw scanline

function draw.scanlinepixelsxyw
  locals i
  alias p=r0s=r1
  . r0=&ir1=&xr2=&yr3=&w
  try clip.scanline r0r1r2r3
  vga.xy xy
  . s=pixelss+i
  loop w, (u32) *p++=*s++, endl
endf 1

; draw scanline with transparent key

function draw.scanline.tpixelsxywkey
  locals i
  alias p=r0s=r1c=r2
  . r0=&ir1=&xr2=&yr3=&w
  try clip.scanline r0r1r2r3
  vga.xy xy
  . s=pixelss+i
  loop w, (u32c=*s++
    if c<>key, (u32) *p=cendp+4
  endl
endf 1

; draw scanline with inverted x

function draw.scanline.ixpixelsxyw
  locals i
  alias p=r0s=r1
  . r0=xr0+w
  vga.xy r0y
  . p-4s=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.vpixelsxywco
  locals ai
  alias p=r0s=r1c=r2c2=r3
  . r0=&ir1=&xr2=&yr3=&w
  try clip.scanline r0r1r2r3
  vga.xy xy
  . s=pixelss+i
  loop w, (u32c=*s++
    . a=ca&0FFh
    if a=0go .nextend
    if a=0FFhc=cogo .drawend
    . (u32c2=*p
    push p s
    get c=mix coc2a
    pop s p
    .draw. (u32) *p=c
    .next. p+4
  endl
endf 1

; draw bitmap

function draw.bitmappixelsxywh
  locals ip
  try visible xywh
  . i=yp=pixels
  loop h
    draw.scanline pxiw
    . r0=wr0*4p+r0i++
  endl
endf 1

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

function draw.bitmap.tpixelsxywh
  locals ipkey
  try visible xywh
  . i=yr0=pixelsp=r0
  . (u32r0=*r0key=r0
  loop h
    draw.scanline.t pxiwkey
    . r0=wr0*4p+r0i++
  endl
endf 1

; draw bitmap with inverted x

function draw.bitmap.ixpixelsxywh
  locals ip
  try visible xywh
  . p=pixels
  loop h
    draw.scanline.ix pxyw
    . r0=wr0*4p+r0y++
  endl
endf 1

; draw bitmap with inverted y

function draw.bitmap.iypixelsxywh
  locals ip
  try visible xywh
  . r0=hr0--, y+r0p=pixels
  loop h
    draw.scanline pxyw
    . r0=wr0*4p+r0y--
  endl
endf 1

; draw bitmap with both inverted

function draw.bitmap.ixypixelsxywh
  locals ipn
  try visible xywh
  . p=pixels
  loop h
    draw.scanline.ix pxyw
    . r0=wr0*4p+r0y--
  endl
endf 1

; draw variant bitmap

function draw.bitmap.vpixelsxywhc
  locals ip
  try visible xywh
  . i=yr0=pixelsp=r0
  loop h
    draw.scanline.v pxiwc
    . r0=wr0*4p+r0i++
  endl
endf 1

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

function draw.fadeboc1c2
  locals xywhinc,\
   rgbredgreenblue,\
   nrngnbfirstlast
  . r0=bo,\
   x=[?box.x+r0], y=[?box.y+r0],\
   w=[?box.w+r0], h=[?box.h+r0]

  . r0=yfirst=r0r1=h
  . n=r1r0+r1last=r0

  . r0=&rr1=&gr2=&b
  get.rgb c1r0r1r2
  . r0=&redr1=&greenr2=&blue
  get.rgb c2r0r1r2

  . r<<8g<<8b<<8r1=n
  if r1=0r1++, end
  . r0=redr0<<8r0-rr0/r1nr=r0
  . r0=greenr0<<8r0-gr0/r1ng=r0
  . r0=bluer0<<8r0-br0/r1nb=r0

  . i=first
  forever
    . r0=rr0>>8r1=gr1>>8r2=br2>>8
    get c=rgb r0r1r2
    draw.line.h xiwc
    . r0=nrr+r0r1=ngg+r1r2=nbb+r2
    . i++, r0=last
    if i>r0go .outend
  endfv
  .out:
endf

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

function draw.shadeboab
  memory.copy g.boxbo16
  . g.box.h>>>1
  draw.fade g.boxab
  . r0=g.box.hg.box.y+r0
  draw.fade g.boxba
endf

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

; 8BPP versions with pa/lette. no clipping

function draw.scanline.8pixelsxyw
  alias p=r0s=r1c=r2q=r3
  vga.xy xy
  . s=pixels
  loop wq=*s++, q*4q+palette.p
    . (u32c=*q, (u32) *p++=c
  endl
endf 1

function draw.bitmap.8pixelsxywh
  locals ip
  try visible xywh
  . i=yi--, p=pixels
  loop hi++
    draw.scanline.8 pxiw
    . r0=wp+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.8pixelsxywco
  locals ai
  alias p=r0s=r1c=r2c2=r3q=r3
  vga.xy xy
  . s=pixels
  loop wq=*s++, q*4q+palette.p
    . (u32c=*qa=ca&0FFh
    if a=0go .nextend
    . (u32c2=*p
    push p s
    . r0=a
    if alpha.biasr0+alpha.bias
      if r0<0r0=0
      else.if r0>255r0=255end
    end
    get c=mix coc2r0
    pop s p
    .draw. (u32) *p=c
    .next. p+4
  endl
endf 1

function draw.bitmap.v.8pixelsxywhc
  locals ip
  try visible xywh
  . i=yi--, p=pixels
  loop hi++
    draw.scanline.v.8 pxiwc
    . r0=wp+r0
  endl
endf 1


Code:
;;;;;;;;;;;;;;;;;;;;; SYSTEM ;;;;;;;;;;;;;;;;;;;;;

; menuet interrupt: eax, ebx, ecx, edx

macro mint abcd {
 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 0CDh40h
}

; events

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

align
integer timer.speed=-1,\
 timer.counterevent.delay=1

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

macro get.timer { mint 269 }

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

macro wait.event { mint 23event.delay }

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

macro create.heap        { mint 6811 }
macro os.allocate n      { mint 6812n }
macro os.reallocate pn { mint 6820pn }
macro os.destroy p       { mint 6813p }

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

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

; example: try p=allocate 4*KB

function allocaten
  os.allocate n
endf

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

function destroyp
  if p
    os.destroy p
  end
endf

macro destroy [p] { forward destroy p }

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

align integer event.type

; keyboard

integer keyold.keykey.event
text keys.t(128)

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

macro get.key.buffer { mint 2621keys.t }

; mouse

integer mouse.event,\
 mouse.1mouse.2mouse.xmouse.y,\
 mouse.dragmouse.drag.xmouse.drag.y,\
 mouse.dropmouse.drop.xmouse.drop.y,\
 old.mouse.1old.mouse.2,\
 old.mouse.xold.mouse.y

macro get.mouse.xy      { mint 370 }
macro get.mouse.buttons { mint 372 }
macro get.mouse.wheel   { mint 373 }

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

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

  if mouse.1
    if not old.mouse.1mouse.event='c'
      . mouse.drop=NO
      callf on.mouse
      return 1
    end
  else.if old.mouse.1mouse.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.xr1=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.yr1=old.mouse.y
    if r0<>r1
      go .mouse.move
    end
  end
endf 0

align

integer window.xwindow.y

function select.boxbox
  . r0=mouse.xr1=mouse.y
  . r0-window.xr1-window.y
  callf point.insideboxr0r1
endf

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

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

align integer @seed

; generate unique random number: 0-n

function randomn
  . r0=@seed
  if false
    rdtsc
    . @seed=r0
  end
  . r0*343FDhr0+269EC3h,\
  @seed=r0r0>>16r0&7FFFh,\
  r1=nr1+1r0/r1r0=r2
endf

; random(from-to-2)+from

function random.xfromto
  . r0=fromr0-tor0-2
  random r0
  . r0+from
endf

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

function os.draw.imagepixelsxywh
  pusha
  . r1=wr1<<16r1|h
  . r2=xr2<<16r2|y
  . r3=pixelsr6=32r7=0ebp=webp*4ebp-ebp
  mint 65
  popa
endf

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

; align void vga.p

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

function get.screen.h
  mint 14
  . r0&0FFFFhos.h=r0
endf

function show.vga
  os.draw.image vga.p00WINDOW.WWINDOW.H
endf

function create.vgawhc
  if vga.p=0r0=wr0*hr0*4
    try vga.p=allocate r0
  end
  call !clear.screenc
endf 1


function set.vgawh
  ; ...
endf

function end.vga
  destroy vga.p
endf

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

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

macro draw.begin { mint 121 }
macro draw.end   { mint 122 }
macro render     { call !on.draw }
macro retrace    { mint 1814 }

;;;;;;;;;;;;;;;;;;;;;; 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.WSCREEN.HSCREEN.BPP
  create.vga WINDOW.WWINDOW.H0
  callf on.create

  . r0=os.wr0/2r1=screen.w
  . r1/2r0-r1window.x=r0
  . r0=os.hr0/2r1=screen.h
  . r1/2r0-r1window.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<>1r0>>8r0&0FFhkey=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 scenescore
numeric SCENE.*, TITLEPLAY,\
 PAUSEGAME.OVER
numeric EASY=5000NORMAL=4000HARD=2000

BOX boardmy.box
integer my.nred.nmagic.n=10101101b
integer cbit.xcbit.ybits.h
numeric BIT.*, W=32H=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.numbersn
  if truego .rend
  . r0=n
  if falser0++, end
endf

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

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

function remove.byteti
  locals n
  alias p=r0q=r1x=r2
  if i=7go .newend
  . p=tp+iq=pq++, x=7x-in=x
  loop n, *p++=*q++, endl
  .new:
  . p=my.numbers, *(p+7)=0
  random.byte
  . q=red.numbers, *(q+7)=r0
endf

function remove.rowi
  remove.byte my.numbersi
  remove.byte red.numbersi
  . bits.h--
  if bits.h<1bits.h=1end
endf

function check.numbers
  locals i
  . i=0
  while i<8r0=my.numbersr0+i
    . r1=*r0r0=red.numbers
    . r0+ir2=*r0
    if r1=r2score+r1
      remove.row i
      return 1
    end
    . i++
  endw
endf 0

function draw.board
  locals inxywh
  draw.image bits.i435
  draw.image bits.i4457
   . x=0y=0w=32h=48
  while y<8x=0
    while x<8
      . r0=xr0*wr0+board.x
      . r1=yr1*hr1+board.y
      set.box my.boxr0r1wh
      draw.box my.boxWHITEGRAY
      . x++
    endw
    . r0=xr0*wr0+board.x
    . r1=yr1*hr1+board.y
    set.box my.boxr0r148h
    draw.box.o my.boxWHITE
    . my.box.x+48
    draw.box.o my.boxRED
    . r0=yr1=8r1-bits.h
    if r0>=r1
      . r0=my.numbersr1=yr2=8
      . r2-bits.hr1-r2r0+r1
      . r1=*r0my.n=r1
      . r0=red.numbersr1=yr2=8
      . r2-bits.hr1-r2r0+r1
      . r1=*r0red.n=r1
      u2t my.nt
      . my.box.x-40my.box.y+11
      draw.text tmy.box.xmy.box.y
      . my.box.x+44
      u2t red.nt
      draw.text tmy.box.xmy.box.y
    end
    . y++
  endw
endf

function draw.bitnxy
  if n
    draw.image bit1.ixy
  else
    draw.image bit0.ixy
  end
endf

function draw.bytenxy
  locals i
  . i=8
  loop ir0=nr1=ir1--, r0>>clr0&1
    draw.bit r0xy
    . x+BIT.W
  endl
endf

function draw.my.numbers
  locals iny
  . i=bits.hy=404
  loop ir0=my.numbersr0+ir0--
    . r0=*r0n=r0
    draw.byte n4y
    . y-BIT.H
  endl
endf

function draw.title.scene
  draw.text help.t16130
  draw.byte magic.n50300
endf

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

function draw.pause.scene
  draw.text pause.t16130
  draw.byte magic.n50300
endf

function draw.game.over
  print tgame.over.tscore
  draw.text t44170
  draw.byte magic.n50300
endf

function on.draw
  locals xywh
  clear.screen BLACK
  print ttitle.tscore
  draw.text t44
  draw.image close.i3244
  . r0=screen.wr0--
  . r1=screen.hr1--
  draw.outline 00r0r1GRAY
  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.xr0-window.xr0-board.x
    . r1=BIT.Wr0/r1cbit.x=r0
    . r0=mouse.yr0-window.yr0-board.y
    . r1=BIT.Hr0/r1cbit.y=r0
    if mouse.event='c'
      . r0=cbit.yr1=8r1-bits.h
      if r0>=r1r0=my.numbersr1=cbit.y
        . r2=8r2-bits.hr1-r2r0+r1
        . r3=*r0r2=1r1=7r1-cbit.x
        . r2<<clr3><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.1returnend
  if bits.h<8bits.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: 3434
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: 3434
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.