1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
; text decompressor for taipan.
; text is packed 6 bits per character. see textcomp.c
; for details.
.include "atari.inc"
.export _print_msg
.import _cputc
srcptr = FR1
outbyte = FR0 ; decoded 6-bit byte
bitcount = FR0+1 ; counts 8..1, current bit in inbyte
inbyte = FR0+2
ysave = FR0+3
.rodata
table: ; outbyte values 53..63
.byte ' ', '!', '%', ',', '.', '?', ':', 39, 40, 41, $9b
tablesize = * - table
.ifdef CART_TARGET
.segment "HIGHCODE"
.else
.code
.endif
; extern void __fastcall__ print_msg(char *msg);
_print_msg:
sta srcptr
stx srcptr+1
lda #0
sta outbyte
ldy #$ff ; since we increment it first thing...
ldx #6 ; counts 6..1, current bit in outbyte
@nextbyte:
iny
lda #8
sta bitcount
lda (srcptr),y
sta inbyte
@bitloop:
asl inbyte
rol outbyte
dex
beq @decode ; got 6 bits
dec bitcount
bne @bitloop
beq @nextbyte
@decode:
lda outbyte
bne @notend
rts ; 0 = end of message
@notend:
cmp #27
bcs @notlower
adc #'a'-1 ; 1-26 are a-z
bne @printit
@notlower:
cmp #52
bcs @notupper
adc #38 ; 27-52 are A-Z
bne @printit
@notupper:
sbc #53 ; 53-63 are table lookups
tax
lda table,x
@printit:
sty ysave ; _cputc trashes Y
cmp #$9b ; always print a \r after a \n
bne @nocr
lda #$0d ; \r
jsr _cputc
lda #$9b
@nocr:
jsr _cputc
ldy ysave
lda #0
sta outbyte
ldx #6
dec bitcount
beq @nextbyte
bne @bitloop
decodersize = * - _print_msg
.out .sprintf("print_msg() is %d bytes", decodersize + tablesize)
|