I'm learning ez80 assembly with EZStudio and want to add sprites and palette data to my code but it's difficult to add directly to the source on-calc.
I want to read the palette and sprite data that convimg outputs from an appvar, I have read the documentation and made a function for it but it doesn't seem to work right.
To get a pointer to an appvar, load HL with a pointer to an appvar header. Then, call Mov9ToOP1 and ChkFindSym. DE will now point to the appvar. Here is what that would look like:


Code:
GetAppvarPointer:
    ld    hl, AppvarHeader
    call  Mov9ToOP1
    call  ChkFindSym
    ret

AppvarHeader:
    db $15, "AppvarName", 0
It's a little more complex than that to get to the appvar's actual data if it may be archived. You have to account for the variable header in archive when that's the case. Here's some code to handle archived variables:


Code:
    ; Input: HL points to appvar name
    ; Returns pointer to appvar size bytes in DE, and pointer to VAT entry in HL
    ; Carry flag is set if appvar was not found, or zero flag is set if appvar is in RAM
GetAppvarDataPointer:
    call  Mov9ToOP1
    call  ChkFindSym
    ; Return with carry flag set if not found
    ret c
    call ChkInRam
    ld bc, 0
    ex de, hl
    jr z, AppvarInRam
    ; Skip to the name size in the archived copy of the VAT entry
    ld c, 9
    add hl, bc
    ; Get the size of the name and skip it
    ld c, (hl)
    inc hl
AppvarInRam:
    ; Clear carry flag but preserve Z flag
    add hl, bc
    ex de, hl
    ret

    ; Example appvar name
AppvarName:
    db $15, "AppvarName", 0


As for convimg details, it should have an option to output an asm include file along with the appvar (using source-format: asm), though I don't know enough about EZStudio to know if that's directly compatible or might need some formatting changes. This contains equates for the offsets in the appvar for each palette and converted image, as well as the size of the convimg appvar header (which I believe the palette/image offsets are relative to, but it may not include the appvar size bytes, so you might need to add an additional 2 bytes to the address returned from the previous routine).
Thanks for the help.
I tried almost the same code and added a check to see if the file was found and copied the first 24 bytes (palette data exported by convimg) to the palette ram area for the LCD but the colors aren't right.
As for the include file, ezstudio does support this, but I want to do as much as I can on-calc so I will be adding images with Design.
Here's my graphics code:
Code:
call ClrScrnFull
call RunIndicOff
ld a,mb
push af
push iy
;load appvar
ld hl,appvarName
call Mov9ToOP1
call ChkFindSym
jr c,Fail ;if appvar not found jr fail

ld (AppvarPtr),de

;call GetCurrentMB
;Set screen to 8bpp
     ;%WUUVPBBRFMTBMMME
ld de,%0000100100100111
ld (mpLcdCtrl),de

;Palette setup
ld de,mpLcdPalette
;ld hl,Palette ;palette defs
ld hl,(AppvarPtr) ;palette from appvar
ld bc,12*2 ;size of palette
ldir ;load palette

ld a,0 ;color
call FillScrn
ld bc,26 ;skip palette and xy size
ld hl,(AppvarPtr)
add hl,bc
ld b,h
ld c,l
call SpriteTest

Finish:
pop iy
pop af
ld mb,a
call GetKey
call ClrScrnFull
;set back to 16bpp
     ;%WUUVPBBRFMTBMMME
ld de,%0000100100101101
ld (mpLcdCtrl),de
res 5,(iy+0) ;doneprgm,doneflags
ret

Fail:
ld hl,failString
call PutS
jr Finish

SpriteTest:
 ld hl,AppvarPtr+258*2+24 ;skip palette
 ;and sprite xy
 ld b,h
 ld c,l
 ld de,vRam
 ld ixl,16 ;y lines
NextLine:
 push de
  ld bc,16;AppvarPtr+24 ;x bytes
  ldir ;copy 1 line
 pop de
 push hl
  ld hl,320 ;move down 1 line
  add hl,de
  ex de,hl
 pop hl
 dec ixl
 jr nz,NextLine
ret

FillScrn:
 ld hl,vRam
 ld (hl),a ;load color
 ld de,vRam+1
 ld bc,320*240-1 ;(320*240)-1
 ldir
ret
 
appvarName:
db $15
db "BUILDINE"
db $0
failString:
db "couldnt load. "
AppvarPtr:
dw 0

Unfortunately I don't have the yaml file I used but I was able to load the first 24 bytes as palette data into Design and the colors were right
I'm not sure how big the convimg appvar header is by default (the include file I mentioned would tell you) but you're currently copying the palette from the data pointer directly returned by ChkFindSym, which would include the 2-byte appvar size header and/or the archived variable header (if it's archived), plus whatever is in the convimg header.

This code is definitely a problem, meaning the sprite is not going to be drawn correctly:

Code:
 ld hl,AppvarPtr+258*2+24 ;skip palette and sprite xy


You forgot to load the pointer first before offsetting, it should actually be:

Code:
 ld hl,(AppvarPtr)
 ld bc,258*2+24 ;skip palette and sprite xy
 add hl,bc


Though if your palette is only 12 colors, I'm not sure where the 258 here is coming from.

Also, the parts where you're attempting to load HL into BC aren't working (which I feel like you noticed) because pointers are 24-bit on eZ80. You would actually need to do:

Code:
 push hl
 pop bc


Another problem related to the 24-bit pointers is that you need to use dl here instead of dw, otherwise you'd be corrupting whatever byte is after this line in the loaded program:

Code:
AppvarPtr:
dw 0
Thanks, its working now! 🙂
Edit: the problem was all of the above, but mostly the two byte header.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement