Jump to content
  • 0

Loading Data into VRAM (Kick Assembler)


paradoxnj
 Share

Question

After being semi-successful with C, I am trying my hand at assembler again. ūüôā¬† I am running into an issue loading data directly into VRAM.¬† Using the emulator's debugging feature, I see my load function is using the correct address. and I have the bank hard coded to "2" right now.¬† I am using Kick Assembler with Visual Studio Code.

My function is as follows:
 

Quote
//**********************************************
// Function:  load_vram
// Args:      A = VRAM Low Byte
//            X = VRAM High Byte
//            Y = filename (7:0)
// Brief:     Loads a file into VRAM
//**********************************************
load_file_into_vram: {
        clc
        stz ROM_BANK
 
        sta ZP_PTR_1                    // Store Low Byte
        stx ZP_PTR_1+1                  // Store High Byte
        sty ZP_PTR_2                    // Store file name low byte
 
        // SETLFS
        lda #1
        ldx #HOST_DEVICE
        ldy #0
        jsr SETLFS
 
        // SETNAM
        ldy #>filenames
        sty ZP_PTR_2+1
        ldy #0
!:      lda (ZP_PTR_2),y
        beq !+
        iny
        jmp !-
!:      tya                             // Filename size
        ldx ZP_PTR_2                    // Filename (Low Byte)
        ldy #>filenames
        jsr SETNAM
 
        // LOAD
        lda #2                          // Bank
        ldx ZP_PTR_1
        ldy ZP_PTR_1+1
        clc                             // Clear the carry
        jsr LOAD
        bcs err
        rts
err:    cmp #$05
        beq dev_error
        cmp #$04
        beq file_error
        cmp #$1D
        beq load_error
 
dev_error:
        lda #<dev_error_msg
        ldx #>dev_error_msg
        ldy #(end_dev_error_msg-dev_error_msg)
        jmp prt
 
file_error:
        lda #<file_error_msg
        ldx #>file_error_msg
        ldy #(end_file_error_msg-file_error_msg)
        jmp prt
 
load_error:
        lda #<load_error_msg
        ldx #>load_error_msg
        ldy #(end_load_error_msg-load_error_msg)
        jmp prt
 
prt:    jsr print_string
        rts
}


My function call, looks like this:
 

Quote
        lda #>(VRAM_palette & $FFFF)
        ldx #<(VRAM_palette & $FFFF)
        ldy #<pal_fn
        jsr load_file_into_vram

I keep getting a "FILE NOT FOUND" error ($04) and static on the screen.  Any help would be appreciated.

Edited by paradoxnj
Link to comment
Share on other sites

20 answers to this question

Recommended Posts

  • 0

Sort of like in Chasevault...just formatted for Kick Assembler.

Quote
filenames:
pal_fn: 
    .text "FF1TS1.PAL"
    .byte 0
tiles_fn: 
    .text "FF1TS1.X16"
    .byte 0
end_filenames:

 

Link to comment
Share on other sites

  • 0

I made some progress today.  I loaded the palette using the "Kick Assembler" way and copied it to VRAM.  Now the palette is red and I also found out that the image is actually being loaded even though it is giving me a "FILE NOT FOUND" error and the carry flag is being set.

The "Kick Assembler" way is as follows:

 

 
.var palette = LoadBinary("FF1TS1.PAL", BF_C64FILE)
bmp_palette: .fill palette.getSize(), palette.uget(i)

 

red_tileset.png.e75f3b7e28c9e0425f31dcd35ee6c84f.png

Link to comment
Share on other sites

  • 0

Finally got it!!!  I used a macro instead of a function for load_file_into_vram.  I was able to abstract the bank that way and keep it like a function call.  I know that is repetitive code in the end and I will still work to get that correct but for now it works.

.macro loadVRAM(filename, filenameLength, address) {
        lda #filenameLength
        ldx #<filename
        ldy #>filename
        jsr CX16.SETNAM
 
        lda #1
        ldx #CX16.HOST_DEVICE
        ldy #0
        jsr CX16.SETLFS
 
        ldx #<(address & $FFFF)
        ldy #>(address & $FFFF)
        lda #((address >> 16) & $F)
        clc
        adc #2
        clc
        jsr CX16.LOAD
}
 
bmp_pal:
    .text "FF1TS1-X16.PAL"
bmp_pal_end:
 
loadVRAM(bmp_pal, bmp_pal_end-bmp_pal, CX16.VRAM_palette)
loadVRAM(bmp_file, bmp_file_end-bmp_file, VRAM_TILES)

This is just a full screen render of a bitmap I had.  I am using it for learning as the tiles are 16x16.  Now to figure out tile mode using this bitmap.
image.png.e9ded41db26c84bb57653ead0fdf22dc.png

Link to comment
Share on other sites

  • 0

Refined the macro a bit more and got rid of the clc and adc instructions.

 

.macro loadVRAM(filename, filenameLength, address) {
        lda #filenameLength
        ldx #<filename
        ldy #>filename
        jsr CX16.SETNAM
 
        lda #1
        ldx #CX16.HOST_DEVICE
        ldy #0
        jsr CX16.SETLFS
 
        ldx #<(address & $FFFF)
        ldy #>(address & $FFFF)
        lda #(((address >> 16) & $F) + 2)
        clc
        jsr CX16.LOAD
}
Link to comment
Share on other sites

  • 0
Just now, StinkerB06 said:

It's possible to use the carry flag as a 1-bit argument.

But LOAD doesn't use the carry bit as an input argument. It is used as an output, but the state of the flag going in should not have any effect on the result of the call. At least, that's how the legacy LOAD function worked. It could have changed for the X16, but not to my knowledge.

Link to comment
Share on other sites

  • 0
Posted (edited)

I finally got the function working correctly.  I had to use the Zero Page for some of the function arguments, but the function is repeatable now.  The given example shows how I load a palette file into VRAM at the VERA palette location.  Again...this is using Kick Assembler.

 

/*********************************************************************
; Function:         loadIntoVRAM
; Uses:             A = filenameLength
;                   X = filename msb
;                   Y = filename lsb
;                   ZP_ARG1 = ADDR_LO
;                   ZP_ARG2 = ADDR_MID
;                   ZP_ARG3 = ADDR_HI
; Returns:          A = 0 on success
;                       1 on failure
; Description:      Loads a file into VRAM
**********************************************************************/
loadIntoVRAM: {
    jsr CX16.SETNAM

    lda #1
    ldx #CX16.HOST_DEVICE
    ldy #0
    jsr CX16.SETLFS

    lda CX16.ZP_ARG3
    ldx CX16.ZP_ARG1
    ldy CX16.ZP_ARG2
    clc
    jsr CX16.LOAD

    bcs errfile
    lda #0
    rts

errfile:
    lda #1
    rts
}

 

Used like this:

        lda #((CX16.VRAM_palette >> 16) & $F) + 2
        sta CX16.ZP_ARG3
        lda #<(CX16.VRAM_palette & $FF00) >> 8
        sta CX16.ZP_ARG2
        lda #>(CX16.VRAM_palette & $FF)
        sta CX16.ZP_ARG1

        ldx #<bmp_pal
        ldy #>bmp_pal
        lda #(bmp_pal_end-bmp_pal)

        jsr loadIntoVRAM

 

Edited by paradoxnj
Link to comment
Share on other sites

  • 0
35 minutes ago, paradoxnj said:

loadIntoVRAM: {
    jsr CX16.SETNAM

    lda #1
    ldx #CX16.HOST_DEVICE
    ldy #0
    jsr CX16.SETLFS

    lda CX16.ZP_ARG3
    ldx CX16.ZP_ARG1
    ldy CX16.ZP_ARG2
    clc
    jsr CX16.LOAD

    bcs success
    lda #1

success:
    lda #0
    rts
}

You should put an rts before the success label. As it is, if you detect a failure, you still lda #0 so the caller of this function will always see it as successful.

Link to comment
Share on other sites

  • 0
Posted (edited)

Yep...thanks.¬† I put it there after I posted this.¬† I realized it was missing.¬† Edited the post to reflect it.¬† Thanks again.¬† I also just realized that I have the check backwards.¬† It should be success if the carry is not set.¬† ūüôā

Edited by paradoxnj
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

√ó
√ó
  • Create New...

Important Information

Please review our Terms of Use