aboutsummaryrefslogtreecommitdiff
path: root/comptitle.s.in
blob: 4980c391c1cedd7c1f6cbce82dc6c56b9fe3e609 (plain)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
;;; see titlecompression.txt to understand how this works!

; cl65 -o comptitle.xex -t none comptitle.s

; comptitle.s.in is used by titlecomp.pl, to generate comptitle.s.
; __VARIABLE__ stuff is filled in by titlecomp.pl, q.v.
; DON'T bother to edit comptitle.s (edit the .in file instead)!

 .include "atari.inc"

 ; size of uncompressed image, in bytes (but, needs to be
 ; a multiple of $100).
;imgsize = __SIZE__
imgsize = $1700

 ; these both need to be page-aligned. destination also needs
 ; to be aligned on a 4K boundary.
start = $9000
;destination = $2400

srcptr = FR0
dstptr = FR0+2
pagecount = FR0+4
tmp = FR0+5

 .word $ffff
 .word start
 .word end-1

 .org start

compdata:
 .incbin "comptitle.dat"

; table runs __FIRSTCODE__ to __LASTCODE__
table:
 __TABLE__

 ; decompression code starts here
init:
 lda #0
 sta SDMCTL ; turn off the screen. newtitle.s turns it back on.

 ;;; for benchmarking only, remove!
 ;sta RTCLOK
 ;sta RTCLOK+1
 ;sta RTCLOK+2

 lda #>imgsize
 sta pagecount
 lda #>compdata
 sta srcptr+1
 lda #>destination
 sta dstptr+1
 lda #0
 sta srcptr
 sta dstptr
 tay

copyloop:
 lda (srcptr),y
 bpl storebyte  ; 0-127 always represent themselves
 cmp #__LASTCODE__+1
 bcs storebyte  ; anything above the last code represents itself
 sta tmp
 sec
 sbc #__FIRSTCODE__
 bcc notcode    ; anything below the 1st code represents itself
 tax
 lda table,x
 beq notcode

 ; got a zero-run code. A = number of bytes of zeroes to store.
storezerorun:
 sty tmp
 tay
 dey
 lda #0
 tax
szloop:
 sta (dstptr,x)
 jsr incdest
 beq done
nohi2:
 dey
 bpl szloop

 ldy tmp
 clc
 bcc storedone

notcode:
 lda tmp

storebyte:
 sty tmp
 ldy #0
 sta (dstptr),y
 jsr incdest
 beq done
nohi:
 ldy tmp

storedone:
 iny
 bne copyloop
 inc srcptr+1
 bne copyloop ; always branch (since srcptr never wraps around to 0)

done:
 ;;; for benchmarking only, remove!
 ;.byte $02 ; CIM, drops us to atari800 monitor
 rts

incdest:
 inc dstptr
 bne iddone
 inc dstptr+1
 dec pagecount
iddone:
 rts

end:
 .word INITAD
 .word INITAD+1
 .word init