;; TRIVIAL PURSUITS

0300 cdfebb    call    $bbfe

;; set display mode 2
0303 3e02      ld      a,$02
0305 cd0ebc    call    $bc0e				; firmware function: scr set mode

;; set pen 0 colour
0308 3adf03    ld      a,($03df)
030b 47        ld      b,a
030c 48        ld      c,b
030d af        xor     a
030e cd32bc    call    $bc32				; firmware function: scr set pen

;; set pen 1 colour
0311 3ae003    ld      a,($03e0)
0314 47        ld      b,a
0315 48        ld      c,b
0316 3e01      ld      a,$01
0318 cd32bc    call    $bc32				; firmware function: scr set pen

;; set border colour
031b 3adf03    ld      a,($03df)
031e 47        ld      b,a
031f 48        ld      c,b
0320 cd38bc    call    $bc38				; firmware function: scr set border

0323 cd19bd    call    $bd19				; firmware function: mc wait flyback
0326 cd19bd    call    $bd19				; firmware function: mc wait flyback

0329 f3        di      
032a 310000    ld      sp,$0000
032d dd21ffff  ld      ix,$ffff			; end address (data is loaded backwards)

;; start cassette motor
0331 0110f6    ld      bc,$f610
0334 ed49      out     (c),c

;; mask for colours
0336 af        xor     a
0337 32d803    ld      ($03d8),a

033a cdc203    call    $03c2
033d 30fb      jr      nc,$033a         ; (-$05)
033f 2600      ld      h,$00
0341 cdc203    call    $03c2
0344 30f4      jr      nc,$033a         ; (-$0c)
0346 7c        ld      a,h
0347 fe0d      cp      $0d
0349 38f4      jr      c,$033f          ; (-$0c)
034b cdc203    call    $03c2
034e 30ea      jr      nc,$033a         ; (-$16)
0350 2e05      ld      l,$05
0352 cdbd03    call    $03bd
0355 2d        dec     l
0356 20fa      jr      nz,$0352         ; (-$06)

;; skip 16 characters?? (filename??)
0358 0610      ld      b,$10
035a c5        push    bc
035b cda503    call    $03a5
035e 79        ld      a,c
035f fe20      cp      $20
0361 c1        pop     bc
0362 20db      jr      nz,$033f         ; (-$25)
0364 10f4      djnz    $035a            ; (-$0c)

0366 cda503    call    $03a5		
0369 30cf      jr      nc,$033a         

;; space?
036b 79        ld      a,c
036c fe20      cp      $20
036e 28f6      jr      z,$0366          ; (-$0a)

;; end of filename marker?? 
0370 fef0      cp      $f0
0372 20f2      jr      nz,$0366         ; (-$0e)
;; just read f0 byte

;; load low byte of length
0374 cda503    call    $03a5
0377 59        ld      e,c

;; load high byte of length
0378 cda503    call    $03a5
037b 51        ld      d,c

;; mask for colours
037c 3e1f      ld      a,$1f
037e 32d803    ld      ($03d8),a

;; initialise checksum
0381 2e00      ld      l,$00

;; load data byte
0383 cda503    call    $03a5
0386 d20003    jp      nc,$0300
0389 dd7100    ld      (ix+$00),c		; write data byte to memory

;; update checksum
038c 79        ld      a,c
038d ad        xor     l
038e 6f        ld      l,a

038f dd2b      dec     ix			; decrease memory pointer
0391 1b        dec     de			; decrease byte count
0392 7a        ld      a,d
0393 b3        or      e
0394 20ed      jr      nz,$0383        

;; load checksum byte
0396 cda503    call    $03a5
;; compare against calculate checksum
0399 79        ld      a,c
039a ad        xor     l
039b c20003    jp      nz,$0300
;; load successful

;; turn off cassette motor
039e 0100f6    ld      bc,$f600
03a1 ed49      out     (c),c

03a3 183c      jr      $03e1            ; (+$3c)

;;---------------------------------------------------------------------------------


03a5 2604      ld      h,$04
03a7 cdbf03    call    $03bf
03aa 0e01      ld      c,$01
03ac 1805      jr      $03b3            ; (+$05)

;;---------------------------------------------------------------------------------

03ae c5        push    bc
03af cdbd03    call    $03bd
03b2 c1        pop     bc
03b3 d0        ret     nc
03b4 3e1a      ld      a,$1a
03b6 bc        cp      h
03b7 cb11      rl      c
03b9 d2ae03    jp      nc,$03ae
03bc c9        ret     

;;---------------------------------------------------------------------------------


03bd 2600      ld      h,$00
03bf cdc203    call    $03c2
03c2 06f5      ld      b,$f5
03c4 ed48      in      c,(c)
03c6 24        inc     h
03c7 c8        ret     z
03c8 ed78      in      a,(c)
03ca a9        xor     c
03cb e680      and     $80
03cd cac603    jp      z,$03c6
03d0 01107f    ld      bc,$7f10
03d3 ed49      out     (c),c
03d5 ed5f      ld      a,r
03d7 e600      and     $00
03d9 ee44      xor     $44
03db ed79      out     (c),a
03dd 37        scf     
03de c9        ret     

;;---------------------------------------------------------------------------------


03df 011801    ld      bc,$0118
03e2 107f      djnz    $0463            ; (+$7f)
03e4 3e44      ld      a,$44
03e6 ed49      out     (c),c
03e8 ed79      out     (c),a
03ea c7        rst     $00

;;---------------------------------------------------------------------------------


03eb 05        dec     b
03ec 7b        ld      a,e
03ed 03        inc     bc
03ee 00        nop     
