• Output to window with TextEdit

    From Tom Thumb@21:1/5 to All on Tue Feb 21 11:33:02 2023
    I admit freely I’m floundering around but… I’m trying to write a desktop application for the IIgs in C to set flagstones, borrowing heavily from Mike Westerfield’s “Toolbox Programming in C”. In the course of that endeavor I’ve gone a bit
    far afield trying to output printf statements to a desktop window that I can scroll through and copy and paste to save or whatever, basically a console window I guess. I’ve had some success starting up the tools with Orca’s startdesk(); , setting
    the grafport and calling printf() but I wanted to use TextEdit and so switched to StartUpTools and have had much less success.

    I’ve tried creating a buffer of CStrings:

    void initbfr(void)
    {

    int i;
    int numstrs, strlen;

    numstrs = 300;
    strlen = 80;

    outbfr.indx = 0;
    outbfr.outstrs = malloc(numstrs * sizeof(char*));

    for(i = 0; i < numstrs; i++)
    {
    outbfr.outstrs[i] = malloc((strlen) * sizeof(char));

    }


    and to open a window:

    void DoOut(void)
    {

    outwinptr = outwin();
    SetPort(outwinptr);

    setCtrl();

    }

    GrafPortPtr outwin(void)
    {

    return NewWindow2("\pOutput", 0, Output, NULL, 0x02, teControl, rWindParam1);


    }

    void Output(void)
    {

    DrawControls(GetPort());

    }


    And in setCtrl():

    void setCtrl(void)
    {

    LongWord length;
    LongWord *tPtr, *sPtr;

    FontID fID;
    TEStyle style;

    fID.fidRec.fontStyle = 0;
    style.styleFontID = fID;


    /* length = 42; /* hard-coded length outbfr.outstrs[0] */
    length = 300; /* hard-coded size of buffer */

    /* tPtr = (LongWord *) ((outbfr.outstrs[0])); */
    tPtr = (LongWord *) ((LongWord)(*(outbfr.outstrs)));

    tPtr = (LongWord *) (&outbfr);
    sPtr = (LongWord *) &style;


    TESetText(5, (Ref) tPtr, length, 0,(Ref) NULL, NULL);


    /* TESetText(1, (Ref) tPtr, length, 0,(Ref) NULL, NULL); */
    /* TESetText(5, (Ref) tPtr, length, 0,(Ref) sPtr, NULL); */

    }

    I don’t know if I need to create a style record and a TERecord. or what not. I know it’s a big ask but I put a SHK on github containing the files and a file “mk” to compile it if anyone might look and tell me what a banana I am and point me in
    the right direction.

    I don’t know of anyone programming Apple IIs around here to talk to. Anyway the repository is at:

    https://github.com/mswade0/Output.git

    if anyone is so inclined, again a big ask, I know.

    — Mark Wade

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tom Thumb@21:1/5 to Kelvin Sherlock on Wed Feb 22 07:22:53 2023
    On Tuesday, February 21, 2023 at 6:00:32 PM UTC-5, Kelvin Sherlock wrote:
    TESetText() replaces all the existing text. There is no TEAppendText()
    but you can

    TESetSelection((Pointer)-1, (Pointer)-1, teH);
    TEInsert(teDataIsTextBlock | teTextIsPtr, (Ref)buffer, length, 0, NULL, teH);

    You probably don't need to worry about style records for now but if you
    call TEStyleChange()
    after the control is created and there's no selection, it will be the default style (and for a console log, you probably only want a single style).

    Side note - if the TextEdit control is read-only, TESetText and
    TEInsert() don't do anything.
    You would need to fiddle with the textFlags to make it writable before trying to modify it.
    On 2023-02-21 19:33:02 +0000, Tom Thumb said:

    I admit freely I’m floundering around but… I’m trying to write a desktop application for the IIgs in C to set flagstones, borrowing
    heavily from Mike Westerfield’s “Toolbox Programming in C”. In the course of that endeavor I’ve gone a bit far afield trying to output printf statements to a desktop window that I can scroll through and
    copy and paste to save or whatever, basically a console window I guess. I’ve had some success starting up the tools with Orca’s startdesk(); , setting the grafport and calling printf() but I wanted to use TextEdit
    and so switched to StartUpTools and have had much less success.


    will give TESetSelection and TEInsert a try but I don’t understand why I’m not displaying the strings in the buffer my output window.
    I’ve populated the buffer in initbfr by calling:

    void xprintf(char *str)
    {
    int cnt;
    cnt = outbfr.indx;

    /*
    outbfr is declared globally: outputbfr outbfr; and is a structure:

    typedef struct outputbfr{

    int indx;
    char **outstrs;

    } outputbfr;
    */

    outbfr.outstrs[outbfr.indx++] = str;

    printf("%d: ",cnt);
    /* printf(outbfr.outstrs[cnt]); */
    printf(*((outbfr.outstrs) + cnt)); /* output to text screen */


    }

    So I thought given I have a pointer to my text buffer: tPtr = (LongWord *) (&outbfr); and I’ve called: TESetText(5, (Ref) tPtr, length, 0,(Ref) NULL, NULL); that whenever there is an update event since I declared the window as: NewWindow2("\pOutput", 0,
    Output, NULL, 0x02, teControl, rWindParam1); that Output() is called and so DrawControls is called and I thought my text would be displayed but I just get stuff like: -@˛™◊»D‘˛€ and ? marks I assume are non printing characters.

    So why can’t I display a cstring I’ve tried pointing to by:

    LongWord *tPtr;
    tPtr = (LongWord *) ((outbfr.outstrs[0]));
    tPtr = (LongWord *) ((LongWord)(*(outbfr.outstrs)));
    tPtr = (LongWord *) (&outbfr);

    TESetText(5, (Ref) tPtr, length, 0,(Ref) NULL, NULL);

    The strings are displayed on the text screen when I quit the app by the printf() calls in xprintf(). Did I mention I’m floundering around? <sigh>

    — Mark Wade

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Antoine Vignau@21:1/5 to All on Wed Feb 22 09:04:01 2023
    Hi,
    Here is some ASM code I wrote. You can insert different kinds of strings (C, Pascal, GS/OS)

    tePASCAL = $0000
    teC = $0001
    teC1 = $0002

    *---

    fcSPROCESS0 lda #teC1 ; volume name
    ldx #^volNAMEopen
    ldy #volNAMEopen
    jsr doLOG

    lda #tePASCAL ; comma
    ldx #^strCOMMA
    ldy #strCOMMA
    jsr doLOG

    *-----------

    ldx #^strSPROCESS ; start process
    ldy #strSPROCESS
    lda #tePASCAL
    jsr doLOG

    *---

    doLOG
    pha ; type of string on entry
    phx ; pointer to string
    phy

    PushLong #-1 ; move to the end of the buffer
    PushLong #-1
    PushLong #0
    _TESetSelection

    lda #0 ; insert the text
    pha ; l
    pha
    pha ; w
    pha ; l
    pha
    pha ; l
    pha
    _TEInsert
    rts

    Toolbox ref volume 3 @ https://drive.google.com/file/d/1WnyA6aTQSVX0IbIk2LbjX56K8MuO_92L/view?usp=share_link

    Antoine

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tom Thumb@21:1/5 to Antoine Vignau on Wed Feb 22 10:13:45 2023
    On Wednesday, February 22, 2023 at 12:04:03 PM UTC-5, Antoine Vignau wrote:
    Hi,
    Here is some ASM code I wrote. You can insert different kinds of strings (C, Pascal, GS/OS)

    tePASCAL = $0000
    teC = $0001
    teC1 = $0002

    *---

    fcSPROCESS0 lda #teC1 ; volume name
    ldx #^volNAMEopen
    ldy #volNAMEopen
    jsr doLOG

    lda #tePASCAL ; comma
    ldx #^strCOMMA
    ldy #strCOMMA
    jsr doLOG

    *-----------

    ldx #^strSPROCESS ; start process
    ldy #strSPROCESS
    lda #tePASCAL
    jsr doLOG

    *---

    doLOG
    pha ; type of string on entry
    phx ; pointer to string
    phy

    PushLong #-1 ; move to the end of the buffer
    PushLong #-1
    PushLong #0
    _TESetSelection

    lda #0 ; insert the text
    pha ; l
    pha
    pha ; w
    pha ; l
    pha
    pha ; l
    pha
    _TEInsert
    rts

    Toolbox ref volume 3 @ https://drive.google.com/file/d/1WnyA6aTQSVX0IbIk2LbjX56K8MuO_92L/view?usp=share_link

    Antoine

    Hmm, a lot to digest; assembly to C but I think I follow that. Thank you Antoine.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From D Finnigan@21:1/5 to Antoine Vignau on Wed Feb 22 18:12:12 2023
    Antoine Vignau wrote:
    Hi,
    Here is some ASM code I wrote. You can insert different kinds of strings
    (C, Pascal, GS/OS)


    La prochaine fois, il s'ecrira par ChatGPT! ;-)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tom Thumb@21:1/5 to Tom Thumb on Wed Feb 22 11:10:03 2023
    On Wednesday, February 22, 2023 at 1:18:01 PM UTC-5, Tom Thumb wrote:

    Perhaps. I just want to scroll though output from my running app

    Neither here nor there but, well…

    I’ve been wanting to write a program to set flagstones in a given area that shows placement and tallies stones used since my IIgs. The smallest stone is 12” x 12” and sizes are in increments of 6” up to 36” x 36”, though a stone of that size
    is uncommon.

    So the stones would be placed on a grid, the first x,y gridlines a mutiple of 12 from the edges, subsequent x,y gridlines multiples of 6 from the previous gridline. Given the IIgs aspect ratio, y gridlines are calculated multiples of 6 x 1, x gridlines
    multiples of 6 x 2, also real world stones are 1/2” smaller than their denominations to allow for a mortar joint, a 12 x 12 stone is actually 11 1/2" x 11 1/2" and that is accounted for with the stone size and gridlines.

    Stones would be placed on the grid according to several rules; the rules being: two stones of the same size may be placed next to each other but no more than two, three of the same stones in a row or column is off-putting. Edges of stones may form a
    continuous line but no more than perhaps 4’ after which the line would need to be broken by placing a stone across the line. Lines of stone edges may not form a cross, as in “+” but must be offset as in “—|__”. Orphaned spaces, ie. voids on
    the grid less than 12 x 12 must be avoided and occur easily.

    So, there are choices such as when creating the collection of stones should a 12 x 24 and a 24 x 12 be created or just a 12 x 24 created and turned as needed. So far I chosen the later, seems more real world, saves space and such though that’s kind of
    trivial.

    I’ve done some; I pseudo-randomly choose a stone from the collection and again randomly turn it if it isn’t square and draw them to the screen but I’ve a long way to go and now I’ve gone by the wayside trying to output printf and sprintf
    statements that don’t scroll off to oblivion.

    Seems like a simple thing and it is called random flagstone but when a human goes about it it is anything but random. Choices are consciously made and evaluated for pitfalls and esthetics. Maybe one day I'll finish it or get close with nothing to gain
    from it than the endeavor.

    -- Mark Wade

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tom Thumb@21:1/5 to D Finnigan on Wed Feb 22 10:17:59 2023
    On Wednesday, February 22, 2023 at 1:12:14 PM UTC-5, D Finnigan wrote:
    Antoine Vignau wrote:
    Hi,
    Here is some ASM code I wrote. You can insert different kinds of strings (C, Pascal, GS/OS)

    La prochaine fois, il s'ecrira par ChatGPT! ;-)

    Perhaps. I just want to scroll though output from my running app

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Antoine Vignau@21:1/5 to Tom Thumb on Wed Feb 22 23:02:33 2023
    On Wednesday, February 22, 2023 at 7:13:47 PM UTC+1, Tom Thumb wrote:
    Hmm, a lot to digest; assembly to C but I think I follow that. Thank you Antoine.

    The result can be seen on page 7 @ http://www.brutaldeluxe.fr/products/apple2gs/fishhead/fishhead_manual_v1.pdf

    av

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Antoine Vignau@21:1/5 to D Finnigan on Wed Feb 22 23:02:49 2023
    On Wednesday, February 22, 2023 at 7:12:14 PM UTC+1, D Finnigan wrote:
    La prochaine fois, il s'ecrira par ChatGPT! ;-)

    Beurk :-(

    Antoine

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From fadden@21:1/5 to Antoine Vignau on Thu Feb 23 15:31:49 2023
    On Wednesday, February 22, 2023 at 11:02:34 PM UTC-8, Antoine Vignau wrote:
    The result can be seen on page 7 @ http://www.brutaldeluxe.fr/products/apple2gs/fishhead/fishhead_manual_v1.pdf

    FWIW, you can put page numbers in URLs now: https://www.brutaldeluxe.fr/products/apple2gs/fishhead/fishhead_manual_v1.pdf#page=7

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Antoine Vignau@21:1/5 to All on Sat Mar 4 12:01:59 2023
    Thank you, Andy!
    av

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)