Query - Example code with graph_put_char working?

JustinBaldock

New Member
Jan 2, 2020
12
7
3
Hi, I seem to be having problems getting graph_put_char to work for me. I switch modes to 320x200x256c, set the graph_set_window. Set my stroke, fill, background colours okay. I can draw lines/boxes/etc all ok. I set my graph_set_font. When I try graph_put_char I get nothing on the display. I've tried stepping into it and following the asm but once it leaves my code and disappears in to the kernal/rom I get lost.
Does anyone have any working examples? Any pointers would be welcome.
 

Jestin

New Member
Jan 25, 2020
15
12
3
I've had no trouble getting it to work, so long as I have all the correct virtual register values set. For example, here's `draw_string` function that I've been using:

Code:
;==================================================
; draw_string
; Draws a string to the screen at the specified xy
; void draw_string(word x: u0, word y: u1, word addr: u2)
;==================================================
draw_string:
    +MoveW u0, r0        ; transfer x and y to the correct
    +MoveW u1, r1       ; virtual registers for GRAPH_put_char

    lda #0                ; load 0 into loop counter variable
    sta u3

-    ldy u3                ; load our loop counter variable into y
    lda (u2),y            ; use zero page indirect with y addressing mode to load the accumulator with the character
    beq +                ; branch to end when a 0 is found
    jsr GRAPH_put_char
    inc u3                ; increment our loop counter
    jmp -                ; loop back to loading y
+    rts
This is complied with the acme compiler. The `MoveW` macro is my "move word" macro, and the `u*` labels are my own set of user-safe virtual registers that won't conflict with virtual registers that the kernal uses. I'm generally doing a black on white screen, so I set the colors like:

Code:
    lda #0
    ldx #0
    ldy #1
    jsr GRAPH_set_colors
You may want to double check that the character(s) you are loading into the accumulator are in PETSCII. In acme, I'm defining my strings like:

Code:
.str_hello_world !pet "hello, world!",0
In terms of things to check, first I'd start with your call to `GRAPH_set_window`. I've learned that the x,y of characters is defined by their base, not the top left corner of the tile, so if you don't keep this in mind you'll end up clipping most of your characters. By default the window is the entire screen, so you should probably start off by not setting a window at all until you get your characters to show up. Next, I'd remove your call to GRAPH_set_font. I haven't played with that yet, but my guess is that if you mess up that call, none of your characters will show up. Again, the font should be set to the system font by default, so I recommend removing your call to set it until you can see characters.