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
- WROCC Newsletter Volume 41:11 reviewed (News:)
- WROCC March 2024 meeting o... Hughes and Peter Richmond (News:1)
- Rougol March 2024 meeting on monday with Bernard Boase (News:)
- Drag'n'Drop 13i2 edition reviewed (News:)
- South-West Show 2024 talks (News:4)
- February 2024 News Summary (News:1)
- Next developer fireside chat (News:)
- DDE31d released (News:)
- South-West Show 2024 Report (News:)
- South-West Show 2024 in pictures (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: Using OS_WriteN in C/C++
 
  Using OS_WriteN in C/C++
  Cauchy (21:00 24/10/2012)
  Phlamethrower (21:38 24/10/2012)
    nunfetishist (22:04 24/10/2012)
    Cauchy (22:29 24/10/2012)
      swirlythingy (00:10 25/10/2012)
        Cauchy (21:23 5/2/2013)
          swirlythingy (23:23 5/2/2013)
            Cauchy (00:55 6/2/2013)
              Stoppers (08:30 6/2/2013)
              swirlythingy (13:14 6/2/2013)
                jeff-doggett (14:38 6/2/2013)
                  Cauchy (16:06 6/2/2013)
 
John O'Meara Message #121313, posted by Cauchy at 21:00, 24/10/2012
Member
Posts: 43
Hi, I want to get the equivalent SWI in C/C++ to generate, for example: vdu 17,3. Which defines text colour. With OS_WriteN, R0 = pointer to string to write, and R1 = no., of bytes to write. 17 and 3 are the two bytes to write. So does the following code do the job of BASIC's VDU 17,3.
char *str = "17 3";
_kernel_swi_regs regs;
regs.r[0] = str;
regs.r[1] = 2;

_kernek_swi(OS_WriteN, &regs, &regs);

Will the SWI ignore the space between the 17 and the 3 and accept 17 as the first byte and 3 as the second byte. I don't want to try this piece of code on my iyonix as it might have a problem with it so I said to myself see what they say at the iconbar. Thanks for the help.
  ^[ Log in to reply ]
 
Jeffrey Lee Message #121316, posted by Phlamethrower at 21:38, 24/10/2012, in reply to message #121313
PhlamethrowerHot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot stuff

Posts: 15100
"17 3" will result in a 5 byte string containing the bytes 49 55 32 51 0, which isn't what you're after. Instead you have two options:

1. Initialise the string like you would an array or a struct, i.e.

char *str = {17,3};

2. Initialise the string as a string, but using control codes, i.e.

char *str = "\x11\x03";

(\xNN is used to denote a character in hex, the compiler will convert it to the appropriate byte value when it parses the string)

The control code approach is probably easier if you need to mix in text with the VDU codes.
  ^[ Log in to reply ]
 
Rob Kendrick Message #121318, posted by nunfetishist at 22:04, 24/10/2012, in reply to message #121316
nunfetishist
Today's phish is trout a la creme.

Posts: 522
Also, just spitting this out via printf() will still go via RISC OS's terminal emulation and do the right thing, won't it?
  ^[ Log in to reply ]
 
John O'Meara Message #121319, posted by Cauchy at 22:29, 24/10/2012, in reply to message #121316
Member
Posts: 43
Thanks for replying. So if I want to define a graphics window like:
VDU 24, left; bottom; right; top;. Where left;, etc., is a two byte number for graphics, sending the low order byte first, I could write the string as: char *str = { left%256,left/256,bottom%256,bottom/256,right%256,right/256,top%256,top/256};
regs.r[0] = str;
regs.r[1] = 8;
_kernel_swi(OS_WriteN, &regs, &regs);
With control code approach it might be more difficult in this case.
  ^[ Log in to reply ]
 
Martin Bazley Message #121320, posted by swirlythingy at 00:10, 25/10/2012, in reply to message #121319

Posts: 460
Yes, it's unpleasant. That's why BASIC hides it away from you with the ; operator. Sadly, C is not BASIC.
  ^[ Log in to reply ]
 
John O'Meara Message #121867, posted by Cauchy at 21:23, 5/2/2013, in reply to message #121320
Member
Posts: 43
I think I finally got around to doing this programming, but I have run into a problem using the SWI OS_WriteN. According to the PPM, OS_WriteN, writes a counted string to the VDU; on entry R0 = pointer to string to write; R1 = number of bytes to write. So if I write in my program: regs.r[0] = str; Where I have defined str as: char str[10]; The compiler gives an error saying '=': implicit cast of pointer to int. I am checking it out at the moment on Castle's C compiler ver 5.64. So I specifically don't know how to assign a pointer to R0. I am hoping someone will be able to help me. If you read through the othet posts in this thread you will see what I am trying to do. Thanks in advance.
  ^[ Log in to reply ]
 
Martin Bazley Message #121869, posted by swirlythingy at 23:23, 5/2/2013, in reply to message #121867

Posts: 460
May I ask what's wrong with putchar(17); putchar(3);?

(Or some other ANSI equivalent. I'm not sure how much of the POSIX stdio.h RISC OS implements.)
  ^[ Log in to reply ]
 
John O'Meara Message #121870, posted by Cauchy at 00:55, 6/2/2013, in reply to message #121869
Member
Posts: 43
Well, I'm not sure how putchar(17); or whatever etc, would work, say in the following context.

void defineGraphicsWindow(int lbx, int lby, int rtx, int rty) {
_kernel_swi_regs regs;
char str[10] = { 24, lbx%256, lbx/256, lby%256, lby/256, rtx%256, rtx/256, rty%256, rty/256 };

regs.r[0] = str; // which must be a wrong //assignment, (pointer to int)
regs.r[1] = 9;

_kernel_swi(OS_WriteN, &regs, &regs);
}
I cannot see as of yet an example for the use of the swi, OS_WriteN in the PRM. Thanks again.
  ^[ Log in to reply ]
 
Simon Willcocks Message #121872, posted by Stoppers at 08:30, 6/2/2013, in reply to message #121870
Member
Posts: 302

regs.r[0] = str; // which must be a wrong //assignment, (pointer to int)
You can explicitly cast the pointer to an integer, like this:

regs.r[0] = (int) str;
  ^[ Log in to reply ]
 
Martin Bazley Message #121877, posted by swirlythingy at 13:14, 6/2/2013, in reply to message #121870

Posts: 460
Well, I'm not sure how putchar(17); or whatever etc, would work, say in the following context.
Have you tried? It's always best to use the standard library functions where possible. Frankly, from within the C environment, I can't think of a single circumstance where calling OS_WriteN directly would be necessary.

All putchar(c) does (or should do) is the equivalent of SYS "OS_WriteC",c.
  ^[ Log in to reply ]
 
Jeff Doggett Message #121878, posted by jeff-doggett at 14:38, 6/2/2013, in reply to message #121877
Member
Posts: 21
All putchar(c) does (or should do) is the equivalent of SYS "OS_WriteC",c.
I seem to recall that it doesn't work that way. I think that control codes get output as "|c" (or something). In my Doom conversion I had to use _kernel_oswrch();
  ^[ Log in to reply ]
 
John O'Meara Message #121881, posted by Cauchy at 16:06, 6/2/2013, in reply to message #121878
Member
Posts: 43
Thank you all for your replies. I made a cast to int of str[10] as suggested, and it compiled fine in C, GCC, G++, but with C++ it gave a "not implemented:" error. I am ok with that as I intend to make a library of such functions like defineGraphicsWindow() for my use with g++, if I succeed.
No, I have not tried the putchar() function. I wasn't sure if it used OS_WriteC, and if it did, I would have to call it much more often than OS_WriteN would be called. Thanks again.
  ^[ Log in to reply ]
 

Acorn Arcade forums: Programming: Using OS_WriteN in C/C++