Author Topic: Text and sprites in an APP? Why is my scrip failing?  (Read 4698 times)

0 Members and 1 Guest are viewing this topic.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Text and sprites in an APP? Why is my scrip failing?
« on: June 29, 2010, 10:39:40 am »
I've recently converted my programm into an APP, and everything works fine, exept Sprites and Text.
For the text I've used numerious routines, but none seem to work, they all display random junk.
This is what I've tried so far:

Code: [Select]
LD HL, $1C04 ; Location of where to display Text
LD (CurRow), HL
LD HL, SomeText
LD DE, OP1
LD BC, 5 ; Lengt + the "0" in the end
LDIR
LD HL, OP1
b_call _PutS

SomeText:
    .DB    "Text", 0

;The above didn't work.
;Neither does this:

LD     HL, $1C04 ; Location again.
LD     (PenCol), HL
LD    HL, SomeText
b_call _VPutS

SomeText:
    .DB    "Text", 0

Both won't work in an App, when I just compile it with TASM, the secont script does work normally, and shows small text at the desired location.

I have a similar problem with showing sprites.
When compiling normally, there's nothing wrong, and everything shows as it's supposed to.
But as soon as it's an APP, the spriter appear in the upper left corner, and somewhat scrambled.
My sprite script:

Code: [Select]
    LD A, 38 ; X position to display
    LD (xpos), A
    LD A, 54 ; Y position do display
    LD (ypos), A
    LD B, 10 ; Length of sprite (in Y direction)
    LD      DE, (ypos)
    LD      IX, Sprite ; The sprite
    CALL ClipSprXOR

ClipSprXOR: ; The actual spriting (from the asm-in-28-days, workt perfectly, but not in APPs appearantly)
    LD     A, %11111111
    LD     (clip_mask), A
    LD     A, E
    OR     A
    JP     M, ClipTop
    SUB    64
    RET    NC
    NEG
    CP     B
    JR     NC, VertClipDone
    LD     B, A
    JR     VertClipDone
ClipTop:
    LD     A, B
    NEG
    SUB    E
    RET    NC
    PUSH   AF
    ADD    A, B
    LD     E, 0
    LD     B, E
    LD     C, A
    ADD    IX, BC
    POP    AF
    NEG
    LD     B, A
VertClipDone:
    LD     C, 0
    LD     A, D
    CP     -7
    JR     NC, ClipLeft
    CP     96
    RET    NC
    CP     89
    JR     C, HorizClipDone
ClipRight:
    AND    7
    LD     C, A
    LD     A, %11111111
FindRightMask:
    ADD    A, A
    DEC    C
    JR     NZ, FindRightMask
    LD     (clip_mask), A
    LD     A, D
    JR     HorizClipDone
ClipLeft:
    AND    7
    LD     C, A
    LD     A, %11111111
FindLeftMask:
    ADD    A, A
    DEC    C
    JR     NZ, FindLeftMask
    CPL
    LD     (clip_mask), A
    LD     A, D
    ADD    A, 96
    LD     C, 12
HorizClipDone:
    LD     H, 0
    LD     D, H
    LD     L, E
    ADD    HL, HL
    ADD    HL, DE
    ADD    HL, HL
    ADD    HL, HL
    LD     E, A
    SRL    E
    SRL    E
    SRL    E
    ADD    HL, DE
    LD     DE, PlotSScreen
    ADD    HL, DE
    LD     D, 0
    LD     E, C
    SBC    HL, DE
    AND    7
    JR     Z, _Aligned
    LD     C, A
    LD     DE, 11
_RowLoop:
    PUSH   BC
    LD     B, C
    LD     A, (clip_mask)
    AND    (IX)
    LD     C, 0
_ShiftLoop:
    SRL    A
    RR     C
    DJNZ   _ShiftLoop
    XOR    (HL)
    LD     (HL), A
    INC    HL
    LD     A, C
    XOR    (HL)
    LD     (HL), A
    ADD    HL, DE
    INC    IX
    POP    BC
    DJNZ   _RowLoop
    RET
_Aligned:
    LD     DE, 12
_PutLoop:
    LD     A, (IX)
    XOR    (HL)
    LD     (HL), A
    INC    IX
    ADD    HL, DE
    DJNZ   _PutLoop
    RET

Sprite: ; Some random Sprite
        .DB     %11111111
        .DB     %00011000
        .DB     %00001100
        .DB     %11111111
        .DB     %00010000
        .DB     %00010000
        .DB     %11110000
        .DB     %00111100
        .DB     %00001110
        .DB     %00000011

Nothing is working, which is frustrating because it did all work before it was turned into an APP, and the programm is nearly completed >.<
Thanks in advance for any help!


79% of all statistics are made up randomly.

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Text and sprites in an APP? Why is my scrip failing?
« Reply #1 on: June 29, 2010, 10:50:55 am »
The sprite routine does not seem to use self modifying code that is not possible in APPS.
But have you equated xpos, ypos and clip_mask to a location on safe ram?

In the first text routine:
   LD   HL, $1C04   ; Location of where to display Text
   LD   (CurRow), HL
$IC04 seems out of the screen and may overflow somewhere.

In the second you need to relocate the string in ram or code a app safe replacement for _VPutS


If you want to ease some coding it is easier to use:
appsafePutS:
   ld a,(hl)
   inc hl
   or a
   ret z
   b_call _PutC
   jr appPutS

 ld hl,string
 call appsafePutS

than relocating the string to ram every time.
Hobbing in calculator projects.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: Text and sprites in an APP? Why is my scrip failing?
« Reply #2 on: June 29, 2010, 12:51:50 pm »
Thanks for your reply!

But have you equated xpos, ypos and clip_mask to a location on safe ram?

Probably not...
How do I do this?
I'm actually quite a newby with ASM, so don't be afraid to explain "too much".

If you want to ease some coding it is easier to use:
appsafePutS:
   ld a,(hl)
   inc hl
   or a
   ret z
   b_call _PutC
   jr appPutS

 ld hl,string
 call appsafePutS

than relocating the string to ram every time.

Uhm...
Can you use this in an easy example for me please?
Like, lets say I want the "Hello World!" message displayed at a specific location.
How would I do that youre way?

Thanks for the help!
It's REALLY appreciated.


79% of all statistics are made up randomly.

Offline mapar007

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 550
  • Rating: +28/-5
  • The Great Mata Mata
    • View Profile
Re: Text and sprites in an APP? Why is my scrip failing?
« Reply #3 on: June 29, 2010, 03:22:55 pm »
You can't use bcalls for text/sprites in an app. You have to write your own routines, or store all text in RAM.

This is because, if you call cross-page, the pointer is messed up: it points to the same address, but on a different page. So basically, you can't access data in your app during a bcall. (or an external page call, in general)

EDIT: if you want all the technical details about why this is, you can read up on wikiti.brandonw.net
« Last Edit: June 29, 2010, 03:24:49 pm by mapar007 »

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: Text and sprites in an APP? Why is my scrip failing?
« Reply #4 on: June 30, 2010, 04:13:55 am »
You can't use bcalls for text/sprites in an app. You have to write your own routines, or store all text in RAM.

Ok... How?
Got an example for text or sprites?
Isn't there a piece of script someone has made before to easely display messages/sprites in APPs?
I'm not really experienced enough yet to fully know how to, so any help woult be apreciated.

If anyone has a helpfull pece of script, I don't per-se need to know HOW and WHY it works, as long as it works. ;P

Anyway, thanks.
I'll look into some documentation about how to show text/sprites in APPs.


79% of all statistics are made up randomly.

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Text and sprites in an APP? Why is my scrip failing?
« Reply #5 on: June 30, 2010, 05:04:27 am »
Actually, if you want to take the lazy way out which may or may not be easier in this case, just copy your data to ram first and then you can use your handy dandy bcalls with the ram location.  If you have enough room, you can just copy all that data there at the beginning and then you're all set.  If not, then you can dynamically copy the text/sprites to the ram only when you need them.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: Text and sprites in an APP? Why is my scrip failing?
« Reply #6 on: June 30, 2010, 05:31:13 am »
Actually, if you want to take the lazy way out which may or may not be easier in this case, just copy your data to ram first and then you can use your handy dandy bcalls with the ram location.  If you have enough room, you can just copy all that data there at the beginning and then you're all set.  If not, then you can dynamically copy the text/sprites to the ram only when you need them.

Smart :O
But I think copying the whole deal at the start would'nt work, since I turned it into an APP because of the 8kB limit, and the programm might get much larger even.
I guess the 8kB limit is still an issue when you just copy the lot at the start, so you're second solution sounds nice to me.

This might be asking for a bit too much, but can you provide me with an example scrip that, lets say, displays the "Hello World!" message in small font on a specific location?
That way things will get more concrete to me, or maybe you can tell me how to "dynamically copy the text/sprites to the ram only when you need them". (with a small script please!)

I'm sorry if I'm being very demanding here, after all I'm pretty much asking fr33 st00f here on a forum...
Thanks alot!
« Last Edit: June 30, 2010, 05:31:40 am by Jerros »


79% of all statistics are made up randomly.

Offline mapar007

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 550
  • Rating: +28/-5
  • The Great Mata Mata
    • View Profile
Re: Text and sprites in an APP? Why is my scrip failing?
« Reply #7 on: July 02, 2010, 06:51:46 am »
The best idea is to write your own routines, definitely. (or copy them from the internet, UTI has threads full of them and nobody will mind if you credit the right people)

As long as you keep those pieces of code on the same page as the data, no issues will arise.
« Last Edit: July 02, 2010, 06:52:00 am by mapar007 »

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: Text and sprites in an APP? Why is my scrip failing?
« Reply #8 on: July 03, 2010, 04:28:34 am »
Thanks, I'll look into that site.
The problem with writing my own would be my total lack of knowledge, I don't know WHY 90% of my script works, I just know what variables to change do what I want . : )


79% of all statistics are made up randomly.

Offline mapar007

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 550
  • Rating: +28/-5
  • The Great Mata Mata
    • View Profile
Re: Text and sprites in an APP? Why is my scrip failing?
« Reply #9 on: July 03, 2010, 04:30:22 am »
That's the beginning. Tinkering with programs is always good.