2019-04-20 20:12:56 +00:00
|
|
|
// Tests of strip() function from https://news.ycombinator.com/item?id=12080871
|
|
|
|
.pc = $801 "Basic"
|
|
|
|
:BasicUpstart(main)
|
|
|
|
.pc = $80d "Program"
|
2020-06-27 21:26:57 +00:00
|
|
|
.label screen = 6
|
2019-04-20 20:12:56 +00:00
|
|
|
main: {
|
2020-02-23 08:44:36 +00:00
|
|
|
// strip(msg1, ' ')
|
2019-04-20 20:12:56 +00:00
|
|
|
ldx #' '
|
|
|
|
lda #<msg1
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z strip.dest
|
2019-04-20 20:12:56 +00:00
|
|
|
lda #>msg1
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z strip.dest+1
|
2019-04-20 20:12:56 +00:00
|
|
|
jsr strip
|
2020-02-23 08:44:36 +00:00
|
|
|
// print(msg1)
|
2019-04-20 20:12:56 +00:00
|
|
|
lda #<$400
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z screen
|
2019-04-20 20:12:56 +00:00
|
|
|
lda #>$400
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z screen+1
|
2019-04-20 20:12:56 +00:00
|
|
|
lda #<msg1
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z print.msg
|
2019-04-20 20:12:56 +00:00
|
|
|
lda #>msg1
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z print.msg+1
|
2019-04-20 20:12:56 +00:00
|
|
|
jsr print
|
2020-02-23 08:44:36 +00:00
|
|
|
// strip(msg2, 'y')
|
2019-04-20 20:12:56 +00:00
|
|
|
ldx #'y'
|
|
|
|
lda #<msg2
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z strip.dest
|
2019-04-20 20:12:56 +00:00
|
|
|
lda #>msg2
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z strip.dest+1
|
2019-04-20 20:12:56 +00:00
|
|
|
jsr strip
|
2020-02-23 08:44:36 +00:00
|
|
|
// print(msg2)
|
2019-04-20 20:12:56 +00:00
|
|
|
lda #<msg2
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z print.msg
|
2019-04-20 20:12:56 +00:00
|
|
|
lda #>msg2
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z print.msg+1
|
2019-04-20 20:12:56 +00:00
|
|
|
jsr print
|
2020-02-23 08:44:36 +00:00
|
|
|
// }
|
2019-04-20 20:12:56 +00:00
|
|
|
rts
|
|
|
|
}
|
2019-12-26 08:51:41 +00:00
|
|
|
// strip(byte* zp(8) p, byte register(X) c)
|
2019-04-20 20:12:56 +00:00
|
|
|
strip: {
|
2020-06-27 21:26:57 +00:00
|
|
|
.label dest = 2
|
2019-07-31 11:47:21 +00:00
|
|
|
.label p = 8
|
2019-10-19 23:43:51 +00:00
|
|
|
.label p_1 = 4
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z dest
|
2019-10-19 23:43:51 +00:00
|
|
|
sta.z p_1
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z dest+1
|
2019-10-19 23:43:51 +00:00
|
|
|
sta.z p_1+1
|
2019-09-29 21:13:37 +00:00
|
|
|
__b1:
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(*p!=c)
|
2019-04-20 20:12:56 +00:00
|
|
|
txa
|
|
|
|
ldy #0
|
2019-10-19 23:43:51 +00:00
|
|
|
cmp (p_1),y
|
2019-09-29 21:13:37 +00:00
|
|
|
beq __b2
|
2020-02-23 08:44:36 +00:00
|
|
|
// *dest++=*p
|
2019-10-19 23:43:51 +00:00
|
|
|
lda (p_1),y
|
2019-04-20 20:12:56 +00:00
|
|
|
sta (dest),y
|
2020-02-23 08:44:36 +00:00
|
|
|
// *dest++=*p;
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z dest
|
2019-04-20 20:12:56 +00:00
|
|
|
bne !+
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z dest+1
|
2019-04-20 20:12:56 +00:00
|
|
|
!:
|
2019-09-29 21:13:37 +00:00
|
|
|
__b2:
|
2020-02-23 08:44:36 +00:00
|
|
|
// while(*p++!=0)
|
2019-04-20 20:12:56 +00:00
|
|
|
clc
|
2020-10-12 18:28:00 +00:00
|
|
|
lda.z p_1
|
2019-04-20 20:12:56 +00:00
|
|
|
adc #1
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z p
|
2019-10-19 23:43:51 +00:00
|
|
|
lda.z p_1+1
|
2019-04-20 20:12:56 +00:00
|
|
|
adc #0
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z p+1
|
2019-04-20 20:12:56 +00:00
|
|
|
ldy #0
|
2019-10-19 23:43:51 +00:00
|
|
|
lda (p_1),y
|
2019-04-20 20:12:56 +00:00
|
|
|
cmp #0
|
2019-09-29 21:13:37 +00:00
|
|
|
bne __b4
|
2020-02-23 08:44:36 +00:00
|
|
|
// }
|
2019-04-20 20:12:56 +00:00
|
|
|
rts
|
2019-09-29 21:13:37 +00:00
|
|
|
__b4:
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z p
|
2019-10-19 23:43:51 +00:00
|
|
|
sta.z p_1
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z p+1
|
2019-10-19 23:43:51 +00:00
|
|
|
sta.z p_1+1
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b1
|
2020-06-27 21:26:57 +00:00
|
|
|
}
|
|
|
|
// print(byte* zp(4) msg)
|
|
|
|
print: {
|
|
|
|
.label msg = 4
|
|
|
|
__b1:
|
|
|
|
// *screen++ = *msg++
|
|
|
|
ldy #0
|
|
|
|
lda (msg),y
|
|
|
|
sta (screen),y
|
|
|
|
// *screen++ = *msg++;
|
|
|
|
inc.z screen
|
|
|
|
bne !+
|
|
|
|
inc.z screen+1
|
|
|
|
!:
|
|
|
|
inc.z msg
|
|
|
|
bne !+
|
|
|
|
inc.z msg+1
|
|
|
|
!:
|
|
|
|
// while(*msg!=0)
|
|
|
|
ldy #0
|
|
|
|
lda (msg),y
|
|
|
|
cmp #0
|
|
|
|
bne __b1
|
|
|
|
// }
|
|
|
|
rts
|
2019-04-20 20:12:56 +00:00
|
|
|
}
|
2019-08-07 17:36:19 +00:00
|
|
|
msg1: .text "hello world!"
|
|
|
|
.byte 0
|
|
|
|
msg2: .text "goodbye blue sky!"
|
|
|
|
.byte 0
|