Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of loading af 4bpp bitmap directly to VRAM by using the KERNAL API calls - R38
*=$0801
!byte $0C,$08,$0A,$00,$9E,' ','2','0','6','4',$00,$00,$00
*=$0810
VERA_BASE = $9F20
VERA_ADDR_L = VERA_BASE
VERA_ADDR_M = VERA_BASE+1
VERA_ADDR_H = VERA_BASE+2
VERA_DATA0 = VERA_BASE+3
VERA_DC = VERA_BASE+9
VERA_DC_VIDEO = VERA_DC ; DCSEL=0
VERA_L0 = VERA_DC+4
VERA_L0_CONFIG = VERA_L0
VERA_L0_TILEBASE = VERA_L0+2
VERA_L0_HSCROLL_H = VERA_L0+4
CHROUT = $FFD2
SETLFS = $FFBA
SETNAM = $FFBD
LOAD = $FFD5
COLORPORT = $0376
SCREEN_SET_MODE = $FF5F
main:
lda #0 ; Set screen mode to 40x30 (320x240)
jsr SCREEN_SET_MODE
lda #$01 ; Black background, white text
sta COLORPORT
lda #147 ; Clear screen, black background is transparent
jsr CHROUT ; which enables layer0 to be seen.
; Enable layer 0
lda VERA_DC_VIDEO
ora #%00010000 ; bit5 = Layer1 enable
sta VERA_DC_VIDEO
; Setup Layer0 for bitmap data
lda #%00000110 ; Bitmap mode, 4 bpp
sta VERA_L0_CONFIG
lda #%00100000 ; Address $4000, w=320
sta VERA_L0_TILEBASE
lda #$02 ; Palette offset = 32
sta VERA_L0_HSCROLL_H
lda #1 ; Logical file number
ldx #8 ; Device 8 = sd card
ldy #0 ; 0=ignore address in bin file (2 first bytes)
; 1=use address in bin file
jsr SETLFS
lda #(End_fname-Fname) ; Length of filename
ldx #<Fname ; Low byte of Fname address
ldy #>Fname ; High byte of Fname address
jsr SETNAM
ldy #$40 ; VERA HIGH address
ldx #$00 ; VERA LOW address
lda #$02 ; VERA BANK + 2
jsr LOAD ; Load binary file into VRAM, ignoring 2 first bytes
; Write new 16 color palette entry - $1FA40
lda #$11
sta VERA_ADDR_H
lda #$FA
sta VERA_ADDR_M
lda #$40
sta VERA_ADDR_L
lda #<Palette
sta $02
lda #>Palette
sta $03
ldy #$00
- lda ($02),Y
sta VERA_DATA0
iny
cpy #32
bne -
jmp *
rts
Palette !word $0223,$0445,$0842,$0845,$0664,$0667,$0789,$0888,$0897,$0B88,$0A97,$09AB,$0AA9,$0DCA,$0DBB,$0CCC
Fname !text "MYIMAGE.BIN"
End_fname
@JimmyDansbo
Copy link
Author

JimmyDansbo commented Jan 27, 2020

Note: the .bin file must have 2 bytes before the actual image data. Normally these two bytes would be used to let LOAD know where in memory the data should be stored, but in the case of LOAD'ing directly to VRAM, LOAD just ignores those two bytes, but still expect them to be there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment