Jump to content
  • 0
paradoxnj

Loading Data into VRAM (Kick Assembler)

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

Share this post


Link to post
Share on other sites

16 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:

 

Share this post


Link to post
Share on other sites
  • 0

One drawback to this approach (which I should know!) Is that it depends on all the filenames being on the same RAM page. But since you are using the first filename, that should be ok.

The only real bug I see is you have the wrong bank set for LOAD. It should be 3 (1+2), not 2 (0+2).

  • Thanks 1

Share this post


Link to post
Share on other sites
  • 0

Ahh...thanks for the VRAM bank find.  I will look at the filename address a bit more.  I can use my print_string function to see what the file name is being set to.

Share this post


Link to post
Share on other sites
  • 0

I also recommend running the emulator with -debug and use the built-in debugger. You can step through the whole thing and examine all the RAM.

Share this post


Link to post
Share on other sites
  • 0

Two questions:

  1. Are you using the host file-system or an SD card image?
  2. Does Kick Assembler's .text directive translate ASCII into PetSCII, or does it assemble that text as ASCII?

Share this post


Link to post
Share on other sites
  • 0

1.  Host file system.  The files are in the same directory as the emulator executable.

2.  Kick Assembler does translate.  I see the names in the emulator memory correctly using the emulator debugger.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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
}

Share this post


Link to post
Share on other sites
  • 0
4 minutes ago, Greg King said:

Why do you put a "clc" above the "jsr CX16.LOAD"?

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

Share this post


Link to post
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.

Share this post


Link to post
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.


√ó
√ó
  • Create New...

Important Information

Please review our Terms of Use