log in | register | forums
Show:
Go:
Forums
Username:

Password:

User accounts
Register new account
Forgot password
Forum stats
List of members
Search the forums

Advanced search
Recent discussions
- Archive Edition 27:2 reviewed (News:)
- WROCC May 2024 meeting - Gerph talks games (News:)
- Drag'n'Drop 13i3 edition reviewed (News:1)
- Wakefield Show 2024 in Pictures (News:5)
- April 2024 News Summary (News:2)
- RISC OS 5.30 arrives (News:2)
- Upgrading your RISC OS system to 5.30 (News:2)
- WROCC May 2024 meeting on wednesday - Gerph talks games (News:)
- uniprint upgraded to 4.50 (News:)
- PhotoDesk 3.23 released (News:)
Latest postings RSS Feeds
RSS 2.0 | 1.0 | 0.9
Atom 0.3
Misc RDF | CDF
 
View on Mastodon
@www.iconbar.com@rss-parrot.net
Site Search
 
Article archives
Acorn Arcade forums: Programming: OS_ScreenMode problem
 
  OS_ScreenMode problem
  ksattic (07:35 28/5/2008)
  VincceH (09:36 28/5/2008)
    ksattic (18:14 28/5/2008)
      Phlamethrower (18:46 28/5/2008)
      VincceH (19:16 28/5/2008)
  jmb (10:28 28/5/2008)
  monkeyson2 (12:00 28/5/2008)
 
Simon Wilson Message #107516, posted by ksattic at 07:35, 28/5/2008
ksattic
Finally, an avatar!

Posts: 1291
OK, what am I doing wrong?

The following works:

int *mode_block;
r.r[0] = 1;
_kernel_swi(OS_ScreenMode, &r, &r);
mode_block = (int *)r.r[1];

The following does not:

int *mode_block;
e = _swix(OS_ScreenMode, _IN(0) | _OUT(1), 1, (int)mode_block);

I am on cold medication and think I may just be missing the obvious...

Using gcc 4.1.1 prerelease 1 with UnixLib.
  ^[ Log in to reply ]
 
VinceH Message #107517, posted by VincceH at 09:36, 28/5/2008, in reply to message #107516
VincceH
Lowering the tone since the dawn of time

Posts: 1600
OK, what am I doing wrong?
Don't know, because I use _kernel_swi (as per your first example) rather than _swix, with which I am totally unfamiliar - but I can have a guess:

The following works:

int *mode_block;
r.r[0] = 1;
_kernel_swi(OS_ScreenMode, &r, &r);
mode_block = (int *)r.r[1];
And in that you are performing the cast of r.r[1] to how you typed mode_block.

The following does not:

int *mode_block;
e = _swix(OS_ScreenMode, _IN(0) | _OUT(1), 1, (int)mode_block);
In this, although you've typed mode_block in the same way as above, in the _swix call, you're casting mode_block to match the register (ie the exact opposite of what you did in the first example).

But given that you want r.r[1] put into int *mode_block (and here my unfamiliarity with _swix comes in) I doubt you can do it that way.

Would that not be similar to saying:

int *foo;
int bar;
(int *)bar=foo;

Which, AFAIK, will not work.

However, as I said, completely unfamiliar with how _swix works, so this is just a guess.
  ^[ Log in to reply ]
 
JMB Message #107518, posted by jmb at 10:28, 28/5/2008, in reply to message #107516
Member
Posts: 467
int *mode_block;
e = _swix(OS_ScreenMode, _IN(0) | _OUT(1), 1, (int)mode_block);
e = _swix(OS_ScreenMode, _IN(0) | _OUT(1), 1, &mode_block);
  ^[ Log in to reply ]
 
Phil Mellor Message #107519, posted by monkeyson2 at 12:00, 28/5/2008, in reply to message #107516
monkeyson2Please don't let them make me be a monkey butler

Posts: 12380
Shouldn't you use OSLib for this sort of thing?
  ^[ Log in to reply ]
 
Simon Wilson Message #107525, posted by ksattic at 18:14, 28/5/2008, in reply to message #107517
ksattic
Finally, an avatar!

Posts: 1291
Would that not be similar to saying:

int *foo;
int bar;
(int *)bar=foo;
It's similar to doing:

bar = (int)foo;

...which is legal. I was merely casting a pointer to an int, since _swix takes ints for its register values. The address still points at a value, but it is stored in an int instead of in an int *.

The reason why my second method doesn't work is because OS_ScreenMode wants to give me a pointer to a block that it has allocated, but all I am letting it do is change the value of the int that mode_block points at, but it is not pointing at a valid address. Using a double pointer or taking the address of mode_block allows the pointer to be changed.

e = _swix(OS_ScreenMode, _IN(0) | _OUT(1), 1, &mode_block);
Ah, that makes sense. It is giving me a pointer to a block.

Shouldn't you use OSLib for this sort of thing?
That would be sensible!

I haven't tried linking OSLib into IyonixMesa yet, and I only need to do a very small amount of windowing stuff to support multitasking 3D apps. I'll give it a go.

[Edited by ksattic at 18:19, 28/5/2008]

[Edited by ksattic at 18:20, 28/5/2008]
  ^[ Log in to reply ]
 
Jeffrey Lee Message #107526, posted by Phlamethrower at 18:46, 28/5/2008, in reply to message #107525
PhlamethrowerHot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot stuff

Posts: 15100
Have you tried doing whatever magic is necessary to link IyonixMesa into SDL? A version of SDL for RISC OS which has OpenGL support could be a convenient way of getting a whole load of free 3D games ported (Including the inevitable SDL-OpenGL version of DeathDawn)
  ^[ Log in to reply ]
 
VinceH Message #107527, posted by VincceH at 19:16, 28/5/2008, in reply to message #107525
VincceH
Lowering the tone since the dawn of time

Posts: 1600
Would that not be similar to saying:

int *foo;
int bar;
(int *)bar=foo;
It's similar to doing:

bar = (int)foo;
Is it, though?

As I said, I don't use that method of calling swis so I'm not familiar with how it works - but I was under the impression that (to use your example) in:

e = _swix(OS_ScreenMode, _IN(0) | _OUT(1), 1, (int)mode_block);

You were telling it to put whatever is in r1 into mode_block - but you were casting that variable. Surely, that's equivalent to putting the cast on the LHS of the equals in a bog standard assignment - ie like (int) mode_block=r.r[1]; - which is just plain wrong.

Of course, sorted now - but if you're insisting that what you were doing was legal, and equivalent to bar = (int)foo; then I would just like to point one little thing to you.

And that thing is this:

bar=(int) foo; works

Your call to _swix in its original form didn't. tongue
  ^[ Log in to reply ]
 

Acorn Arcade forums: Programming: OS_ScreenMode problem