Author Topic: ShowContents  (Read 3783 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
ShowContents
« on: March 30, 2011, 04:55:11 AM »
Deleted
« Last Edit: May 05, 2015, 12:40:29 PM by Peter »

Charles Pegge

  • Guest
Re: ShowContents
« Reply #1 on: March 30, 2011, 06:15:02 AM »

Hi Peter,

I think this is what you need:

Code: [Select]
  indexbase 0

  Dim byref somp as long
  Dim something(2) as long

  something(0)<=10,20,30


  & somp=& something 'hitches somp to something

  print somp(0)
  print somp(1)
  print somp(2)

You may also map onto any section of something like this:

& somp= & something(100)

Charles

Charles Pegge

  • Guest
Re: ShowContents
« Reply #2 on: March 30, 2011, 07:20:02 AM »
Peter,

I do not understand what you intend with Mytest(). What are your intentions? :)
What will somp() contain?

Charles
« Last Edit: March 30, 2011, 07:21:43 AM by Charles Pegge »

Charles Pegge

  • Guest
Re: ShowContents
« Reply #3 on: March 30, 2011, 08:37:54 AM »

Now I understand Peter.

Here is your example made operational:

Code: [Select]

  #indexbase 0

  dim adr(10) as long

  sub hold(byval iadr as long)
  '===========================
  '
  static z as long 
  z +=1
  adr(z) =iadr
  end sub

  'then, I will call this sub routine:
  '
  dim data1(100) as long
  dim data2(100) as long
  dim data3(100) as long
  dim data4(100) as long
  '
  hold(& data1) 
  hold(& data2)
  hold(& data3)
  hold(& data4)
  '
  'in the adr array are stored four addresses now.
  'in adr(1) is data1 and so on
  'now I will get one of the address:
  '
  dim AC as long
  AC = adr(2)
  '
  'AC has now the address of data2!
  'how write I an value now in this address, which is standing in AC ?
  '
  data2(3)=42
  dim byref dat as long
  & dat = AC

  print dat(3) 'answer 42 .. maps to data2(3)

Charles

Charles Pegge

  • Guest
Re: ShowContents
« Reply #4 on: March 30, 2011, 10:53:17 AM »
Peter.

I get your original code working by doing this:

dim byref adr as long
& adr = & pal


You may of course point adr to any address or variable containing an address. There are no restrictions.

Code: [Select]
/*
Sub Sprite(byval nr as long,byval x as long,byval y as long,byval v as long)
'===========================================================================
Long z, adr
adr = SprA(nr)
For b=0 To SprH(nr)-1
For a=0 To SprW(nr)-1
z = b*(SprW(nr)*v) + a
'iF adr(z) >0       <-- this is the original value
iF pal(z) >0     '<-- after watching, remove all pal(z)
SetPixel BackHdc,a+x,b+y,pal(z) 'adr(z) <-- this is the original value
End iF
Next: Next
End Sub
*/


Sub Sprite(byval nr as long,byval x as long,byval y as long,byval v as long)
'===========================================================================
Long z
dim byref adr as long
& adr = & pal
For b=0 To SprH(nr)-1
  For a=0 To SprW(nr)-1
    z = b*(SprW(nr)*v) + a
    iF adr(z) >0      '<-- this is the original value
    'iF pal(z) >0     '<-- after watching, remove all pal(z)
      SetPixel BackHdc,a+x,b+y,adr(z) '<-- this is the original value
      'SetPixel BackHdc,a+x,b+y,pal(z)
    End iF
  Next
Next
End Sub

Charles
« Last Edit: March 30, 2011, 11:26:41 AM by Charles Pegge »

Charles Pegge

  • Guest
Re: ShowContents
« Reply #5 on: March 30, 2011, 11:56:05 AM »
But adr has to be byref

However there there is an underlying problem: loss of sprA(nl). I will trace it through.

Charles
« Last Edit: March 30, 2011, 12:09:40 PM by Charles Pegge »

Charles Pegge

  • Guest
Re: ShowContents
« Reply #6 on: March 30, 2011, 12:08:25 PM »
Bingo!

The underlying problem was in LoadSprite:

SprA(nr) = & dest 'must be the address (byref as any)


Code: [Select]
indexbase 0
include "wFunc.h"

Dim SprA(512) As Long
Dim SprW(512) As Long
Dim SprH(512) As Long

Function LoadSprite(file as string, byref dest as any, byval w as long, byval h as long) as long
'===============================================================================================
Static nr as long
Long hnd,count
hnd = CreateFile(file, GENERIC_WRITE or GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, SYS_SEC, OPEN_ALWAYS, 0, 0)
count = GetFileSize hnd,sys_long
ReadFile hnd,dest,count,&dwcount, sys_no
CloseHandle hnd
nr +=1
SprW(nr) = w: SprH(nr) = h
SprA(nr) = & dest 'must be the address (byref as any)
Function = nr
End Function

Dim pal(64) as long
Long ix

/*
Sub Sprite(byval nr as long,byval x as long,byval y as long,byval v as long)
'===========================================================================
Long z, adr
adr = SprA(nr)
For b=0 To SprH(nr)-1
For a=0 To SprW(nr)-1
z = b*(SprW(nr)*v) + a
'iF adr(z) >0       <-- this is the original value
iF pal(z) >0     '<-- after watching, remove all pal(z)
SetPixel BackHdc,a+x,b+y,pal(z) 'adr(z) <-- this is the original value
End iF
Next: Next
End Sub
*/


Sub Sprite(byval nr as long,byval x as long,byval y as long,byval v as long)
'===========================================================================
Long a,z
dim byref adr as long
& adr = sprA(nr)
For b=0 To SprH(nr)-1
  For a=0 To SprW(nr)-1
    z = b*(SprW(nr)*v) + a
    iF adr(z) >0      '<-- this is the original value
      SetPixel BackHdc,a+x,b+y,adr(z) '<-- this is the original value
    End iF
  Next
Next
End Sub



OpenWindow "Test",640,480,ws_overlapped
SetFont 16,16,0,"times"
dim zahl as long
zahl=LoadSprite "logo/box.bin",pal,8,8
While WinExit=0
ClearBuffer RGB(0,0,200)
For ix=0 To 200
  Sprite zahl,Rand(0,640),Rand(0,480),1
Next
Text "Frames: " + Str(ShowFrames),0,0,RGB(255,255,255)
DoEvents
FlipBuffer
Wend
WinEnd

Charles