/// @file /// A lightweight library for printing on the C64. /// /// Printing with this library is done by calling print_ function for each element // Commodore 64 PRG executable file .file [name="incrementinarray.prg", type="prg", segments="Program"] .segmentdef Program [segments="Basic, Code, Data"] .segmentdef Basic [start=$0801] .segmentdef Code [start=$80d] .segmentdef Data [startAfter="Code"] .segment Basic :BasicUpstart(main) .label print_screen = $400 .label print_char_cursor = 2 .label print_line_cursor = 6 .segment Code main: { // print_cls() jsr print_cls ldx #0 lda #print_screen sta.z print_line_cursor+1 lda #print_screen sta.z print_char_cursor+1 __b1: // print_str(txt) jsr print_str // print_ln() jsr print_ln // txt[1]++; inc txt+1 // for ( byte i: 0..10) inx cpx #$b bne __b4 // } rts __b4: lda.z print_line_cursor sta.z print_char_cursor lda.z print_line_cursor+1 sta.z print_char_cursor+1 jmp __b1 } // Clear the screen. Also resets current line/char cursor. print_cls: { // memset(print_screen, ' ', 1000) jsr memset // } rts } // Print a zero-terminated string // void print_str(__zp(4) char *str) print_str: { .label str = 4 lda #txt sta.z str+1 __b1: // while(*str) ldy #0 lda (str),y cmp #0 bne __b2 // } rts __b2: // print_char(*(str++)) ldy #0 lda (str),y jsr print_char // print_char(*(str++)); inc.z str bne !+ inc.z str+1 !: jmp __b1 } // Print a newline print_ln: { __b1: // print_line_cursor + 0x28 lda #$28 clc adc.z print_line_cursor sta.z print_line_cursor bcc !+ inc.z print_line_cursor+1 !: // while (print_line_cursorstr sta.z dst+1 __b1: // for(char* dst = str; dst!=end; dst++) lda.z dst+1 cmp #>end bne __b2 lda.z dst cmp #