Debian Codegraph @

examples/loading_a_kla_file.asm

raw
1 ;
2 ; Splitting a binary koala file into its components is easy and
3 ; just a matter using .binary a few times:
4 ;
5 ; bitmap .binary "picture.kla", 2, 8000
6 ; screen .binary "picture.kla", 8002, 1000
7 ; color .binary "picture.kla", 9002, 1000
8 ; background = binary("picture.kla", 10002, 1)
9 ;
10 ; Of course a constant could be used for the file name to not repeat
11 ; it all the time.
12 ;
13 ; But once we have that why not use that constant to hold the various
14 ; components instead of the file's name? That'd be lot more useful.
15 ;
16 ; So the following function does that. It loads the koala file and splits
17 ; it into it's components. Later these are used where ever needed.
18
19 loadkla .function _data : binary; use binary() on parameter
20 BITMAP = _data[2:8002] ; 8000 bytes bitmap
21 SCREEN = _data[8002:9002] ; 1000 bytes screen
22 COLOR = _data[9002:10002] ; 1000 bytes colour
23 BACKGROUND = _data[10002] ; 1 byte background
24 .endf namespace(*) ; return the namespace
25
26 ; calculate constant for VIC-II font/bitmap and screen location in video RAM
27 vicmem .sfunction _bmp, _scr, ((_bmp >> 10) & $0f) | ((_scr >> 6) & $f0)
28
29 ; Simple koala displayer follows:
30
31 ; PICTURE will hold the components of the koala picture
32 PICTURE = loadkla("picture.kla"); load this file
33
34 * = $0801 ; C64 BASIC header
35 .word (+), 2021
36 .null $9e, format("%4d", start)
37 + .word 0
38
39 start lda #$3b
40 sta $d011 ; select bitmap mode
41 lda #$18
42 sta $d016 ; select multi colour mode
43 lda #vicmem(bitmap, screen)
44 sta $d018 ; screen and bitmap locations
45 lda #PICTURE.BACKGROUND
46 sta $d021 ; background colour
47
48 ldx #0 ; copy 1K of colours
49 - .for i in range(0, 1024, 256)
50 lda color+i,x
51 sta $d800+i,x
52 .next
53 inx
54 bne -
55 stx $d015 ; disable sprites (just in case)
56 jmp * ; done
57
58 ; dump screen to $0c00 to avoid copying it.
59 * = $0c00
60 screen .text PICTURE.SCREEN ; dump screen data
61 color .text PICTURE.COLOR ; dump color data
62
63 ; dump bitmap to $2000 to avoid copying it
64 * = $2000
65 bitmap .text PICTURE.BITMAP ; dump bitmap data