Jump to content
  • 0

Hello world asm question


Craig
 Share

Question

I've got the code below that works when I use the CHROUT function, but when I change it to console_put_char, I see no output.  I see similar problems with other new x16-specific new kernel functions.  So can we assume those functions are not fully implemented yet?

Thanks,

Craig

    ldx #0
again:
    lda hello, x
    cmp #0
    beq done
    stx SaveX
    ;jsr $FEDE   ; console_put_char
    jsr $FFD2    ; CHROUT
    ldx SaveX
    inx
    jmp again
done:
    rts
SaveX: .byte 0
hello:
    .byte   "hello world! ", $00
 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

You can't just substitute CHROUT for console_put_char.

Per the documentation, under "Console":

Quote

Console

$FEDB: console_init - initialize console mode $FEDE: console_put_char - print character to console $FED8: console_put_image - draw image as if it was a character $FEE1: console_get_char - get character from console $FED5: console_set_paging_message - set paging message or disable paging

The console is a screen mode that allows text output and input in proportional fonts that support the usual styles. It is useful for rich text-based interfaces.

Function Name: console_init

Signature: void console_init(word x: r0, word y: r1, word width: r2, word height: r3); Purpose: Initialize console mode. Call address: $FEDB

Description: This function initializes console mode. It sets up the window (text clipping area) passed into it, clears the window and positions the cursor at the top left. All 0 arguments create a full screen console. You have to switch to graphics mode using screen_set_mode beforehand.

Function Name: console_put_char

Signature: void console_put_char(byte char: .a, bool wrapping: .c); Purpose: Print a character to the console. Call address: $FEDE

Description: This function prints a character to the console. The .C flag specifies whether text should be wrapped at character (.C=0) or word (.C=1) boundaries. In the latter case, characters will be buffered until a SPACE, CR or LF character is sent, so make sure the text that is printed always ends in one of these characters.

Note: If the bottom of the screen is reached, this function will scroll its contents up to make extra room.

With this documentation in mind, consider the following modifications:

; screen_set_mode
    lda #$80
    jsr $FF5F ; SET 320x200@256C MODE

; console_init
    ; All zeroes in r0 through r3 result in a full-screen console
    ;r0
    stz $02
    stz $03
    ;r1
    stz $04
    stz $05
    ;r2
    stz $06
    stz $07
    ;r3
    stz $08
    stz $09

    jsr $FEDB

; rest of the code
   ldx #0
again:
    lda hello, x
    cmp #0
    beq done
    stx SaveX
    sec ; Adding carry to wrap at word boundaries
    jsr $FEDE   ; console_put_char
    ;jsr $FFD2    ; CHROUT
    ldx SaveX
    inx
    jmp again
done:
    rts
SaveX: .byte 0
hello:
    .byte   "hello world! ", $00

 

Edited by StephenHorn
Comparing the two code editors.
Link to comment
Share on other sites

  • 0
41 minutes ago, Craig said:

 I did not realize I needed to init the console.  I figured it was already initialized.

It's not the console that needs to be initialized, but the new kernal console library.

I have created a simple print macro for ca65 that uses the legacy kernal:

.macro PRINT_STRING str_arg
   .scope
         jmp end_string
      string_begin: .byte str_arg
      end_string:
         lda #<string_begin
         sta ZP_PTR_1
         lda #>string_begin
         sta ZP_PTR_1+1
         ldx #(end_string-string_begin)
         ldy #0
      loop:
         lda (ZP_PTR_1),y
         jsr CHROUT
         iny
         dex
         bne loop
   .endscope
.endmacro

Then you can pass whatever string you want, e.g.:

PRINT_SCREEN "hello, world!"

I created another macro to print a carriage return to get to the next line:

.macro PRINT_CR
   lda #$0D
   jsr CHROUT
.endmacro

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use