USBhost-64 code example

I thought to share a code snippet from the Koala Painter picture loader tool I wrote for USBhost-64. Bear in mind there are a number of ways to load hires pictures in a faster way, especially if the data in the file is arranged in a different way than in the Koala Painter format.

Anyway, this should give you an idea of how a generic USBhost-64 access routine looks like 🙂

        ; --------------------------
        ; Read data after PRG header
        ; --------------------------

_read   lda #$00        ; Load Bitmap at $2000
        sta $ae
        lda #$20
        sta $af

        lda #$40        ; 8000 bytes to read
        sta $ac
        lda #$1f
        sta $ad

        jsr fread       ; Read them from file
        bcc _vdmtrx     ; Carry is clear if no error occurred

_errdat jsr fclose      ; Close file on error

        lda #<errreadd  ; Print error message
        ldy #>errreadd
        jmp $ab1e       ; Error reading data

_vdmtrx lda #$00        ; Load Video Matrix data at $0400
        sta $ae
        lda #$04
        sta $af

        lda #$e8        ; 1000 bytes to read
        sta $ac
        lda #$03
        sta $ad

        jsr fread       ; Read them from file
        bcs _errdat

        lda #$00        ; Load Color Matrix data at $D800
        sta $ae
        lda #$D8
        sta $af

        lda #$e8        ; 1000 bytes to read
        sta $ac
        lda #$03
        sta $ad

        jsr fread       ; Read them from file
        bcs _errdat

        lda #$21        ; Load Background color
        sta $ae
        lda #$d0
        sta $af

        lda #$01        ; Single byte
        sta $ac
        lda #$00
        sta $ad

        jsr fread       ; Read it from file
        bcs _errdat

        jsr fclose      ; Close file

        ; ------------
        ; Init display
        ; ------------

        lda $d011
        ora #$20        ; Enable Bitmap graphics
        sta $d011

        lda #$18        ; Upper 8k for Bitmap, 2nd block for Video Matrix
        sta $d018

        lda $d016
        ora #$10        ; Enable multicolor Bitmap
        sta $d016

The fread and fclose class of functions belong to a C-runtime-like wrapper I wrote around the USB kernel for USBhost-64. Of course these constitute a commodity but come at a price in performance so programmers seeking maximum speed should use the USB kernel API directly 🙂

This entry was posted in Retrocomputing, Technical and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s