2021-02-04 08:18:27 +00:00
|
|
|
// A lightweight library for printing on the C64.
|
|
|
|
// 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="test-comparisons.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
|
2018-01-01 14:59:15 +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_line_cursor = 6
|
|
|
|
.label print_char_cursor = $a
|
2020-12-21 07:57:41 +00:00
|
|
|
.segment Code
|
2018-01-01 14:59:15 +00:00
|
|
|
main: {
|
2019-07-31 11:47:21 +00:00
|
|
|
.label b = $c
|
2018-01-01 14:59:15 +00:00
|
|
|
.label a = 2
|
2018-01-01 21:59:06 +00:00
|
|
|
.label i = 3
|
2020-03-22 21:26:39 +00:00
|
|
|
.label r = 4
|
2020-02-23 08:44:36 +00:00
|
|
|
// print_cls()
|
2018-01-01 14:59:15 +00:00
|
|
|
jsr print_cls
|
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
|
2018-01-01 21:59:06 +00:00
|
|
|
lda #0
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z i
|
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
|
2018-01-01 21:59:06 +00:00
|
|
|
lda #7
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z a
|
2019-09-29 21:13:37 +00:00
|
|
|
__b1:
|
2021-05-02 12:28:03 +00:00
|
|
|
// byte b = $ce-a
|
2018-01-02 09:17:59 +00:00
|
|
|
lda #$ce
|
2018-01-01 14:59:15 +00:00
|
|
|
sec
|
2019-08-07 19:00:19 +00:00
|
|
|
sbc.z a
|
|
|
|
sta.z b
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a<b)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z a
|
|
|
|
cmp.z b
|
2020-03-30 18:33:26 +00:00
|
|
|
bcs __b22
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'+'
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b2
|
2020-03-30 18:33:26 +00:00
|
|
|
__b22:
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'-'
|
2019-09-29 21:13:37 +00:00
|
|
|
__b2:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "< ", b, r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z b
|
|
|
|
sta.z printu.b
|
2020-03-22 21:26:39 +00:00
|
|
|
sty.z printu.res
|
2018-01-02 09:17:59 +00:00
|
|
|
lda #<op
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2018-01-02 09:17:59 +00:00
|
|
|
lda #>op
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-01 14:59:15 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a<$37)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z a
|
2018-01-02 09:17:59 +00:00
|
|
|
cmp #$37
|
2020-03-30 18:33:26 +00:00
|
|
|
bcs __b23
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'+'
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b3
|
2020-03-30 18:33:26 +00:00
|
|
|
__b23:
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'-'
|
2019-09-29 21:13:37 +00:00
|
|
|
__b3:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "< ", $37, r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
|
|
|
sta.z printu.res
|
2018-01-02 09:17:59 +00:00
|
|
|
lda #$37
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.b
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #<op
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #>op
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-01 14:59:15 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a<cs[i])
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z a
|
|
|
|
ldy.z i
|
2018-01-01 14:59:15 +00:00
|
|
|
cmp cs,y
|
2020-03-30 18:33:26 +00:00
|
|
|
bcs __b24
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'+'
|
|
|
|
sta.z r
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b4
|
2020-03-30 18:33:26 +00:00
|
|
|
__b24:
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'-'
|
|
|
|
sta.z r
|
2019-09-29 21:13:37 +00:00
|
|
|
__b4:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "< ", cs[i], r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
2019-08-07 19:00:19 +00:00
|
|
|
ldy.z i
|
2018-01-01 14:59:15 +00:00
|
|
|
lda cs,y
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.b
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #<op
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #>op
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-01 14:59:15 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a<a)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z a
|
|
|
|
cmp.z a
|
2020-03-30 18:33:26 +00:00
|
|
|
bcs __b25
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'+'
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b5
|
2020-03-30 18:33:26 +00:00
|
|
|
__b25:
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'-'
|
2019-09-29 21:13:37 +00:00
|
|
|
__b5:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "< ", a, r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
|
|
|
txa
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.b
|
2020-03-22 21:26:39 +00:00
|
|
|
sty.z printu.res
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #<op
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #>op
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// print_ln()
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr print_ln
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a>b)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z b
|
|
|
|
cmp.z a
|
2020-03-30 18:33:26 +00:00
|
|
|
bcs __b26
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'+'
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b6
|
2020-03-30 18:33:26 +00:00
|
|
|
__b26:
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'-'
|
2019-09-29 21:13:37 +00:00
|
|
|
__b6:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "> ", b, r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z b
|
|
|
|
sta.z printu.b
|
2020-03-22 21:26:39 +00:00
|
|
|
sty.z printu.res
|
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
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "> ", b, r)
|
2018-01-02 09:17:59 +00:00
|
|
|
lda #<op4
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2018-01-02 09:17:59 +00:00
|
|
|
lda #>op4
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a>$37)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z a
|
2019-04-10 14:06:03 +00:00
|
|
|
cmp #$37+1
|
2020-03-30 18:33:26 +00:00
|
|
|
bcc __b27
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'+'
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b7
|
2020-03-30 18:33:26 +00:00
|
|
|
__b27:
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'-'
|
2019-09-29 21:13:37 +00:00
|
|
|
__b7:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "> ", $37, r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
|
|
|
sta.z printu.res
|
2018-01-02 09:17:59 +00:00
|
|
|
lda #$37
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.b
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #<op4
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #>op4
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a>cs[i])
|
2019-08-07 19:00:19 +00:00
|
|
|
ldy.z i
|
2018-01-05 21:29:21 +00:00
|
|
|
lda cs,y
|
2019-08-07 19:00:19 +00:00
|
|
|
cmp.z a
|
2020-03-30 18:33:26 +00:00
|
|
|
bcs __b28
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'+'
|
|
|
|
sta.z r
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b8
|
2020-03-30 18:33:26 +00:00
|
|
|
__b28:
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'-'
|
|
|
|
sta.z r
|
2019-09-29 21:13:37 +00:00
|
|
|
__b8:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "> ", cs[i], r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
2019-08-07 19:00:19 +00:00
|
|
|
ldy.z i
|
2018-01-02 09:17:59 +00:00
|
|
|
lda cs,y
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.b
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #<op4
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #>op4
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a>a)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z a
|
|
|
|
cmp.z a
|
2020-03-30 18:33:26 +00:00
|
|
|
bcs __b29
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'+'
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b9
|
2020-03-30 18:33:26 +00:00
|
|
|
__b29:
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'-'
|
2019-09-29 21:13:37 +00:00
|
|
|
__b9:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "> ", a, r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
|
|
|
txa
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.b
|
2020-03-22 21:26:39 +00:00
|
|
|
sty.z printu.res
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #<op4
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #>op4
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// print_ln()
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr print_ln
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a<=b)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z b
|
|
|
|
cmp.z a
|
2020-03-30 18:33:26 +00:00
|
|
|
bcc __b30
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'+'
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b10
|
2020-03-30 18:33:26 +00:00
|
|
|
__b30:
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'-'
|
2019-09-29 21:13:37 +00:00
|
|
|
__b10:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "<=", b, r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z b
|
|
|
|
sta.z printu.b
|
2020-03-22 21:26:39 +00:00
|
|
|
sty.z printu.res
|
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
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "<=", b, r)
|
2018-01-02 09:17:59 +00:00
|
|
|
lda #<op8
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2018-01-02 09:17:59 +00:00
|
|
|
lda #>op8
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a<=$37)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z a
|
2019-04-10 14:06:03 +00:00
|
|
|
cmp #$37+1
|
2020-03-30 18:33:26 +00:00
|
|
|
bcs __b31
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'+'
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b11
|
2020-03-30 18:33:26 +00:00
|
|
|
__b31:
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'-'
|
2019-09-29 21:13:37 +00:00
|
|
|
__b11:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "<=", $37, r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
|
|
|
sta.z printu.res
|
2018-01-02 09:17:59 +00:00
|
|
|
lda #$37
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.b
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #<op8
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #>op8
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a<=cs[i])
|
2019-08-07 19:00:19 +00:00
|
|
|
ldy.z i
|
2018-01-05 21:29:21 +00:00
|
|
|
lda cs,y
|
2019-08-07 19:00:19 +00:00
|
|
|
cmp.z a
|
2020-03-30 18:33:26 +00:00
|
|
|
bcc __b32
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'+'
|
|
|
|
sta.z r
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b12
|
2020-03-30 18:33:26 +00:00
|
|
|
__b32:
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'-'
|
|
|
|
sta.z r
|
2019-09-29 21:13:37 +00:00
|
|
|
__b12:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "<=", cs[i], r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
2019-08-07 19:00:19 +00:00
|
|
|
ldy.z i
|
2018-01-02 09:17:59 +00:00
|
|
|
lda cs,y
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.b
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #<op8
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #>op8
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a<=a)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z a
|
|
|
|
cmp.z a
|
2020-03-30 18:33:26 +00:00
|
|
|
bcc __b33
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'+'
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b13
|
2020-03-30 18:33:26 +00:00
|
|
|
__b33:
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'-'
|
2019-09-29 21:13:37 +00:00
|
|
|
__b13:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "<=", a, r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
|
|
|
txa
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.b
|
2020-03-22 21:26:39 +00:00
|
|
|
sty.z printu.res
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #<op8
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #>op8
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// print_ln()
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr print_ln
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a>=b)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z a
|
|
|
|
cmp.z b
|
2020-03-30 18:33:26 +00:00
|
|
|
bcc __b34
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'+'
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b14
|
2020-03-30 18:33:26 +00:00
|
|
|
__b34:
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'-'
|
2019-09-29 21:13:37 +00:00
|
|
|
__b14:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, ">=", b, r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z b
|
|
|
|
sta.z printu.b
|
2020-03-22 21:26:39 +00:00
|
|
|
sty.z printu.res
|
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
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, ">=", b, r)
|
2018-01-02 09:17:59 +00:00
|
|
|
lda #<op12
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2018-01-02 09:17:59 +00:00
|
|
|
lda #>op12
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a>=$37)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z a
|
2018-01-02 09:17:59 +00:00
|
|
|
cmp #$37
|
2020-03-30 18:33:26 +00:00
|
|
|
bcc __b35
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'+'
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b15
|
2020-03-30 18:33:26 +00:00
|
|
|
__b35:
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'-'
|
2019-09-29 21:13:37 +00:00
|
|
|
__b15:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, ">=", $37, r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
|
|
|
sta.z printu.res
|
2018-01-02 09:17:59 +00:00
|
|
|
lda #$37
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.b
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #<op12
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #>op12
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a>=cs[i])
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z a
|
|
|
|
ldy.z i
|
2018-01-02 09:17:59 +00:00
|
|
|
cmp cs,y
|
2020-03-30 18:33:26 +00:00
|
|
|
bcc __b36
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'+'
|
|
|
|
sta.z r
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b16
|
2020-03-30 18:33:26 +00:00
|
|
|
__b36:
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'-'
|
|
|
|
sta.z r
|
2019-09-29 21:13:37 +00:00
|
|
|
__b16:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, ">=", cs[i], r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
2019-08-07 19:00:19 +00:00
|
|
|
ldy.z i
|
2018-01-02 09:17:59 +00:00
|
|
|
lda cs,y
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.b
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #<op12
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #>op12
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a>=a)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z a
|
|
|
|
cmp.z a
|
2020-03-30 18:33:26 +00:00
|
|
|
bcc __b37
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'+'
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b17
|
2020-03-30 18:33:26 +00:00
|
|
|
__b37:
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'-'
|
2019-09-29 21:13:37 +00:00
|
|
|
__b17:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, ">=", a, r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
|
|
|
txa
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.b
|
2020-03-22 21:26:39 +00:00
|
|
|
sty.z printu.res
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #<op12
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #>op12
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// print_ln()
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr print_ln
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a==b)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z a
|
|
|
|
cmp.z b
|
2020-03-30 18:33:26 +00:00
|
|
|
bne __b38
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'+'
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b18
|
2020-03-30 18:33:26 +00:00
|
|
|
__b38:
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'-'
|
2019-09-29 21:13:37 +00:00
|
|
|
__b18:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "==", b, r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z b
|
|
|
|
sta.z printu.b
|
2020-03-22 21:26:39 +00:00
|
|
|
sty.z printu.res
|
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
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "==", b, r)
|
2018-01-02 09:17:59 +00:00
|
|
|
lda #<op16
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2018-01-02 09:17:59 +00:00
|
|
|
lda #>op16
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a==$37)
|
2019-03-26 22:49:44 +00:00
|
|
|
lda #$37
|
2019-08-07 19:00:19 +00:00
|
|
|
cmp.z a
|
2020-03-30 18:33:26 +00:00
|
|
|
bne __b39
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'+'
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b19
|
2020-03-30 18:33:26 +00:00
|
|
|
__b39:
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'-'
|
2019-09-29 21:13:37 +00:00
|
|
|
__b19:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "==", $37, r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
|
|
|
sta.z printu.res
|
2018-01-02 09:17:59 +00:00
|
|
|
lda #$37
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.b
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #<op16
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #>op16
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a==cs[i])
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z a
|
|
|
|
ldy.z i
|
2018-01-02 09:17:59 +00:00
|
|
|
cmp cs,y
|
2020-03-30 18:33:26 +00:00
|
|
|
bne __b40
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'+'
|
|
|
|
sta.z r
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b20
|
2020-03-30 18:33:26 +00:00
|
|
|
__b40:
|
2020-03-22 21:26:39 +00:00
|
|
|
lda #'-'
|
|
|
|
sta.z r
|
2019-09-29 21:13:37 +00:00
|
|
|
__b20:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "==", cs[i], r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
2019-08-07 19:00:19 +00:00
|
|
|
ldy.z i
|
2018-01-02 09:17:59 +00:00
|
|
|
lda cs,y
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.b
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #<op16
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #>op16
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-02 09:17:59 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(a==a)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z a
|
|
|
|
cmp.z a
|
2020-03-30 18:33:26 +00:00
|
|
|
bne __b41
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'+'
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b21
|
2020-03-30 18:33:26 +00:00
|
|
|
__b41:
|
2020-03-22 21:26:39 +00:00
|
|
|
ldy #'-'
|
2019-09-29 21:13:37 +00:00
|
|
|
__b21:
|
2020-02-23 08:44:36 +00:00
|
|
|
// printu(a, "==", a, r)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z a
|
|
|
|
txa
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.b
|
2020-03-22 21:26:39 +00:00
|
|
|
sty.z printu.res
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #<op16
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op
|
2019-02-24 22:23:57 +00:00
|
|
|
lda #>op16
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z printu.op+1
|
2018-01-01 21:59:06 +00:00
|
|
|
jsr printu
|
2020-02-23 08:44:36 +00:00
|
|
|
// print_ln()
|
2018-01-01 14:59:15 +00:00
|
|
|
jsr print_ln
|
2020-02-23 08:44:36 +00:00
|
|
|
// a=a+$30
|
2019-08-07 19:00:19 +00:00
|
|
|
lax.z a
|
2019-03-27 06:47:31 +00:00
|
|
|
axs #-[$30]
|
2019-08-07 19:00:19 +00:00
|
|
|
stx.z a
|
2020-02-23 08:44:36 +00:00
|
|
|
// for( byte i : 0..4 )
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z i
|
2019-03-26 22:49:44 +00:00
|
|
|
lda #5
|
2019-08-07 19:00:19 +00:00
|
|
|
cmp.z i
|
2019-09-29 21:13:37 +00:00
|
|
|
bne __b68
|
|
|
|
__b42:
|
|
|
|
jmp __b42
|
|
|
|
__b68:
|
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
|
2020-12-21 07:57:41 +00:00
|
|
|
.segment Data
|
2019-11-03 20:27:11 +00:00
|
|
|
cs: .byte 7, $c7, $37, $97, $67
|
2019-08-07 17:36:19 +00:00
|
|
|
op: .text "< "
|
|
|
|
.byte 0
|
|
|
|
op4: .text "> "
|
|
|
|
.byte 0
|
|
|
|
op8: .text "<="
|
|
|
|
.byte 0
|
|
|
|
op12: .text ">="
|
|
|
|
.byte 0
|
|
|
|
op16: .text "=="
|
|
|
|
.byte 0
|
2018-01-01 14:59:15 +00:00
|
|
|
}
|
2020-12-21 07:57:41 +00:00
|
|
|
.segment Code
|
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
|
|
|
|
// }
|
|
|
|
rts
|
|
|
|
}
|
|
|
|
// printu(byte register(X) a, byte* zp(8) op, byte zp(5) b, byte zp(4) res)
|
|
|
|
printu: {
|
|
|
|
.label b = 5
|
|
|
|
.label res = 4
|
|
|
|
.label op = 8
|
|
|
|
// print_char(' ')
|
|
|
|
lda #' '
|
|
|
|
jsr print_char
|
|
|
|
// print_uchar(a)
|
|
|
|
jsr print_uchar
|
|
|
|
// print_str(op)
|
|
|
|
jsr print_str
|
|
|
|
// print_uchar(b)
|
|
|
|
ldx.z b
|
|
|
|
jsr print_uchar
|
|
|
|
// print_char(' ')
|
|
|
|
lda #' '
|
|
|
|
jsr print_char
|
|
|
|
// print_char(res)
|
|
|
|
lda.z res
|
|
|
|
jsr print_char
|
|
|
|
// }
|
|
|
|
rts
|
|
|
|
}
|
2019-02-17 23:12:29 +00:00
|
|
|
// Print a newline
|
2018-01-01 14:59:15 +00:00
|
|
|
print_ln: {
|
2019-09-29 21:13:37 +00:00
|
|
|
__b1:
|
2020-02-23 08:44:36 +00:00
|
|
|
// print_line_cursor + $28
|
2019-03-18 01:23:29 +00:00
|
|
|
lda #$28
|
2018-01-01 14:59:15 +00:00
|
|
|
clc
|
2019-08-07 19:00:19 +00:00
|
|
|
adc.z print_line_cursor
|
|
|
|
sta.z print_line_cursor
|
2018-01-01 14:59:15 +00:00
|
|
|
bcc !+
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z print_line_cursor+1
|
2018-01-01 14:59:15 +00:00
|
|
|
!:
|
2020-02-23 08:44:36 +00:00
|
|
|
// while (print_line_cursor<print_char_cursor)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z print_line_cursor+1
|
|
|
|
cmp.z print_char_cursor+1
|
2019-09-29 21:13:37 +00:00
|
|
|
bcc __b1
|
2018-01-01 14:59:15 +00:00
|
|
|
bne !+
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z print_line_cursor
|
|
|
|
cmp.z print_char_cursor
|
2019-09-29 21:13:37 +00:00
|
|
|
bcc __b1
|
2018-01-01 14:59:15 +00:00
|
|
|
!:
|
2020-02-23 08:44:36 +00:00
|
|
|
// }
|
2018-01-01 14:59:15 +00:00
|
|
|
rts
|
|
|
|
}
|
2020-06-27 21:26:57 +00:00
|
|
|
// Copies the character c (an unsigned char) to the first num characters of the object pointed to by the argument str.
|
|
|
|
memset: {
|
|
|
|
.const c = ' '
|
|
|
|
.const num = $3e8
|
|
|
|
.label str = print_screen
|
|
|
|
.label end = str+num
|
|
|
|
.label dst = 8
|
|
|
|
lda #<str
|
|
|
|
sta.z dst
|
|
|
|
lda #>str
|
|
|
|
sta.z dst+1
|
|
|
|
__b1:
|
|
|
|
// for(char* dst = str; dst!=end; dst++)
|
|
|
|
lda.z dst+1
|
|
|
|
cmp #>end
|
|
|
|
bne __b2
|
|
|
|
lda.z dst
|
|
|
|
cmp #<end
|
|
|
|
bne __b2
|
2020-02-23 08:44:36 +00:00
|
|
|
// }
|
2018-01-01 14:59:15 +00:00
|
|
|
rts
|
2020-06-27 21:26:57 +00:00
|
|
|
__b2:
|
|
|
|
// *dst = c
|
|
|
|
lda #c
|
|
|
|
ldy #0
|
|
|
|
sta (dst),y
|
|
|
|
// for(char* dst = str; dst!=end; dst++)
|
|
|
|
inc.z dst
|
|
|
|
bne !+
|
|
|
|
inc.z dst+1
|
|
|
|
!:
|
|
|
|
jmp __b1
|
2018-01-01 14:59:15 +00:00
|
|
|
}
|
2019-02-17 23:12:29 +00:00
|
|
|
// Print a single char
|
2019-02-19 19:51:48 +00:00
|
|
|
// print_char(byte register(A) ch)
|
2018-01-01 14:59:15 +00:00
|
|
|
print_char: {
|
2020-02-23 08:44:36 +00:00
|
|
|
// *(print_char_cursor++) = ch
|
2018-01-01 14:59:15 +00:00
|
|
|
ldy #0
|
2018-03-25 21:40:38 +00:00
|
|
|
sta (print_char_cursor),y
|
2020-02-23 08:44:36 +00:00
|
|
|
// *(print_char_cursor++) = ch;
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z print_char_cursor
|
2018-01-01 14:59:15 +00:00
|
|
|
bne !+
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z print_char_cursor+1
|
2018-01-01 14:59:15 +00:00
|
|
|
!:
|
2020-02-23 08:44:36 +00:00
|
|
|
// }
|
2018-01-01 14:59:15 +00:00
|
|
|
rts
|
|
|
|
}
|
2020-04-13 18:00:13 +00:00
|
|
|
// Print a char as HEX
|
2020-04-13 18:06:30 +00:00
|
|
|
// print_uchar(byte register(X) b)
|
|
|
|
print_uchar: {
|
2020-02-23 08:44:36 +00:00
|
|
|
// b>>4
|
2020-03-22 23:10:07 +00:00
|
|
|
txa
|
2018-01-01 14:59:15 +00:00
|
|
|
lsr
|
|
|
|
lsr
|
|
|
|
lsr
|
|
|
|
lsr
|
2020-02-23 08:44:36 +00:00
|
|
|
// print_char(print_hextab[b>>4])
|
2018-01-01 14:59:15 +00:00
|
|
|
tay
|
2018-04-02 22:02:25 +00:00
|
|
|
lda print_hextab,y
|
2020-03-07 21:38:40 +00:00
|
|
|
// Table of hexadecimal digits
|
2018-01-01 14:59:15 +00:00
|
|
|
jsr print_char
|
2020-02-23 08:44:36 +00:00
|
|
|
// b&$f
|
2020-03-22 23:10:07 +00:00
|
|
|
txa
|
|
|
|
and #$f
|
2020-02-23 08:44:36 +00:00
|
|
|
// print_char(print_hextab[b&$f])
|
2018-01-01 14:59:15 +00:00
|
|
|
tay
|
2018-04-02 22:02:25 +00:00
|
|
|
lda print_hextab,y
|
2018-01-01 14:59:15 +00:00
|
|
|
jsr print_char
|
2020-02-23 08:44:36 +00:00
|
|
|
// }
|
2018-01-01 14:59:15 +00:00
|
|
|
rts
|
|
|
|
}
|
2019-02-17 23:12:29 +00:00
|
|
|
// Print a zero-terminated string
|
2020-06-27 21:26:57 +00:00
|
|
|
// print_str(byte* zp(8) str)
|
2018-01-02 09:17:59 +00:00
|
|
|
print_str: {
|
2020-06-27 21:26:57 +00:00
|
|
|
.label str = 8
|
2019-09-29 21:13:37 +00:00
|
|
|
__b1:
|
2020-02-23 08:44:36 +00:00
|
|
|
// while(*str)
|
2018-01-02 09:17:59 +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
|
|
|
// }
|
2018-01-02 09:17:59 +00:00
|
|
|
rts
|
2019-09-29 21:13:37 +00:00
|
|
|
__b2:
|
2020-04-18 18:54:39 +00:00
|
|
|
// print_char(*(str++))
|
2018-01-02 09:17:59 +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
|
2018-01-02 09:17:59 +00:00
|
|
|
bne !+
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z str+1
|
2018-01-02 09:17:59 +00:00
|
|
|
!:
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b1
|
2018-01-01 14:59:15 +00:00
|
|
|
}
|
2020-12-21 07:57:41 +00:00
|
|
|
.segment Data
|
2018-04-02 22:02:25 +00:00
|
|
|
print_hextab: .text "0123456789abcdef"
|