2021-06-19 20:11:26 +00:00
|
|
|
/// @file
|
2021-06-19 19:26:05 +00:00
|
|
|
/// A lightweight library for printing on the C64.
|
2021-06-19 20:28:44 +00:00
|
|
|
///
|
2021-06-19 19:26:05 +00:00
|
|
|
/// Printing with this library is done by calling print_ function for each element
|
2020-12-21 07:57:41 +00:00
|
|
|
// 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
|
2017-12-26 16:38:51 +00:00
|
|
|
:BasicUpstart(main)
|
2020-06-27 18:32:09 +00:00
|
|
|
.label print_screen = $400
|
2020-06-27 21:26:57 +00:00
|
|
|
.label print_char_cursor = 2
|
2021-09-23 06:24:56 +00:00
|
|
|
.label print_line_cursor = 6
|
2020-12-21 07:57:41 +00:00
|
|
|
.segment Code
|
2017-12-26 16:38:51 +00:00
|
|
|
main: {
|
2020-02-23 08:44:36 +00:00
|
|
|
// print_cls()
|
2017-12-26 16:38:51 +00:00
|
|
|
jsr print_cls
|
|
|
|
ldx #0
|
2020-06-27 18:32:09 +00:00
|
|
|
lda #<print_screen
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z print_line_cursor
|
2020-06-27 18:32:09 +00:00
|
|
|
lda #>print_screen
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z print_line_cursor+1
|
2020-06-27 18:32:09 +00:00
|
|
|
lda #<print_screen
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z print_char_cursor
|
2020-06-27 18:32:09 +00:00
|
|
|
lda #>print_screen
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z print_char_cursor+1
|
2019-09-29 21:13:37 +00:00
|
|
|
__b1:
|
2020-02-23 08:44:36 +00:00
|
|
|
// print_str(txt)
|
2017-12-26 16:38:51 +00:00
|
|
|
jsr print_str
|
2020-02-23 08:44:36 +00:00
|
|
|
// print_ln()
|
2017-12-26 16:38:51 +00:00
|
|
|
jsr print_ln
|
2020-02-23 08:44:36 +00:00
|
|
|
// txt[1]++;
|
2020-04-28 19:21:32 +00:00
|
|
|
inc txt+1
|
2020-02-23 08:44:36 +00:00
|
|
|
// for ( byte i: 0..10)
|
2017-12-26 16:38:51 +00:00
|
|
|
inx
|
|
|
|
cpx #$b
|
2019-09-29 21:13:37 +00:00
|
|
|
bne __b4
|
2020-02-23 08:44:36 +00:00
|
|
|
// }
|
2017-12-26 16:38:51 +00:00
|
|
|
rts
|
2019-09-29 21:13:37 +00:00
|
|
|
__b4:
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z print_line_cursor
|
|
|
|
sta.z print_char_cursor
|
|
|
|
lda.z print_line_cursor+1
|
|
|
|
sta.z print_char_cursor+1
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b1
|
2017-12-26 16:38:51 +00:00
|
|
|
}
|
2020-06-27 21:26:57 +00:00
|
|
|
// Clear the screen. Also resets current line/char cursor.
|
|
|
|
print_cls: {
|
|
|
|
// memset(print_screen, ' ', 1000)
|
|
|
|
jsr memset
|
2020-02-23 08:44:36 +00:00
|
|
|
// }
|
2017-12-26 16:38:51 +00:00
|
|
|
rts
|
|
|
|
}
|
2019-02-17 23:12:29 +00:00
|
|
|
// Print a zero-terminated string
|
2021-09-23 06:24:56 +00:00
|
|
|
// void print_str(__zp(4) char *str)
|
2017-12-26 16:38:51 +00:00
|
|
|
print_str: {
|
2021-09-23 06:24:56 +00:00
|
|
|
.label str = 4
|
2017-12-26 16:38:51 +00:00
|
|
|
lda #<txt
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z str
|
2017-12-26 16:38:51 +00:00
|
|
|
lda #>txt
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z str+1
|
2019-09-29 21:13:37 +00:00
|
|
|
__b1:
|
2020-02-23 08:44:36 +00:00
|
|
|
// while(*str)
|
2017-12-26 16:38:51 +00:00
|
|
|
ldy #0
|
|
|
|
lda (str),y
|
2019-08-07 17:48:56 +00:00
|
|
|
cmp #0
|
2019-09-29 21:13:37 +00:00
|
|
|
bne __b2
|
2020-02-23 08:44:36 +00:00
|
|
|
// }
|
2017-12-26 16:38:51 +00:00
|
|
|
rts
|
2019-09-29 21:13:37 +00:00
|
|
|
__b2:
|
2020-04-18 18:54:39 +00:00
|
|
|
// print_char(*(str++))
|
2017-12-26 16:38:51 +00:00
|
|
|
ldy #0
|
|
|
|
lda (str),y
|
2020-04-18 18:54:39 +00:00
|
|
|
jsr print_char
|
|
|
|
// print_char(*(str++));
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z str
|
2017-12-26 16:38:51 +00:00
|
|
|
bne !+
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z str+1
|
2017-12-26 16:38:51 +00:00
|
|
|
!:
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b1
|
2017-12-26 16:38:51 +00:00
|
|
|
}
|
2020-06-27 21:26:57 +00:00
|
|
|
// Print a newline
|
|
|
|
print_ln: {
|
|
|
|
__b1:
|
2024-01-02 18:45:16 +00:00
|
|
|
// print_line_cursor + 0x28
|
2020-06-27 21:26:57 +00:00
|
|
|
lda #$28
|
|
|
|
clc
|
|
|
|
adc.z print_line_cursor
|
|
|
|
sta.z print_line_cursor
|
|
|
|
bcc !+
|
|
|
|
inc.z print_line_cursor+1
|
|
|
|
!:
|
|
|
|
// while (print_line_cursor<print_char_cursor)
|
|
|
|
lda.z print_line_cursor+1
|
|
|
|
cmp.z print_char_cursor+1
|
|
|
|
bcc __b1
|
2020-04-18 18:54:39 +00:00
|
|
|
bne !+
|
2020-06-27 21:26:57 +00:00
|
|
|
lda.z print_line_cursor
|
|
|
|
cmp.z print_char_cursor
|
|
|
|
bcc __b1
|
2020-04-18 18:54:39 +00:00
|
|
|
!:
|
|
|
|
// }
|
|
|
|
rts
|
|
|
|
}
|
2019-07-17 23:54:16 +00:00
|
|
|
// Copies the character c (an unsigned char) to the first num characters of the object pointed to by the argument str.
|
2021-08-10 15:48:55 +00:00
|
|
|
// void * memset(void *str, char c, unsigned int num)
|
2019-07-17 23:54:16 +00:00
|
|
|
memset: {
|
|
|
|
.const c = ' '
|
|
|
|
.const num = $3e8
|
2020-06-27 18:32:09 +00:00
|
|
|
.label str = print_screen
|
2019-07-17 23:54:16 +00:00
|
|
|
.label end = str+num
|
2021-09-23 06:24:56 +00:00
|
|
|
.label dst = 4
|
2019-07-17 23:54:16 +00:00
|
|
|
lda #<str
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z dst
|
2019-07-17 23:54:16 +00:00
|
|
|
lda #>str
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z dst+1
|
2019-09-29 21:13:37 +00:00
|
|
|
__b1:
|
2020-02-23 08:44:36 +00:00
|
|
|
// for(char* dst = str; dst!=end; dst++)
|
2019-08-25 20:21:56 +00:00
|
|
|
lda.z dst+1
|
|
|
|
cmp #>end
|
2019-09-29 21:13:37 +00:00
|
|
|
bne __b2
|
2019-08-25 20:21:56 +00:00
|
|
|
lda.z dst
|
|
|
|
cmp #<end
|
2019-09-29 21:13:37 +00:00
|
|
|
bne __b2
|
2020-02-23 08:44:36 +00:00
|
|
|
// }
|
2019-08-25 20:21:56 +00:00
|
|
|
rts
|
2019-09-29 21:13:37 +00:00
|
|
|
__b2:
|
2020-02-23 08:44:36 +00:00
|
|
|
// *dst = c
|
2019-07-17 23:54:16 +00:00
|
|
|
lda #c
|
2017-12-30 20:59:23 +00:00
|
|
|
ldy #0
|
2019-07-17 23:54:16 +00:00
|
|
|
sta (dst),y
|
2020-02-23 08:44:36 +00:00
|
|
|
// for(char* dst = str; dst!=end; dst++)
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z dst
|
2017-12-26 16:38:51 +00:00
|
|
|
bne !+
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z dst+1
|
2017-12-26 16:38:51 +00:00
|
|
|
!:
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b1
|
2020-06-27 21:26:57 +00:00
|
|
|
}
|
|
|
|
// Print a single char
|
2021-08-10 15:48:55 +00:00
|
|
|
// void print_char(__register(A) char ch)
|
2020-06-27 21:26:57 +00:00
|
|
|
print_char: {
|
|
|
|
// *(print_char_cursor++) = ch
|
|
|
|
ldy #0
|
|
|
|
sta (print_char_cursor),y
|
|
|
|
// *(print_char_cursor++) = ch;
|
|
|
|
inc.z print_char_cursor
|
|
|
|
bne !+
|
|
|
|
inc.z print_char_cursor+1
|
|
|
|
!:
|
|
|
|
// }
|
|
|
|
rts
|
2017-12-26 16:38:51 +00:00
|
|
|
}
|
2020-12-21 07:57:41 +00:00
|
|
|
.segment Data
|
2019-08-07 17:36:19 +00:00
|
|
|
txt: .text "camelot"
|
|
|
|
.byte 0
|