Author Topic: APP -- Sprites and text all messed up... why!?  (Read 7332 times)

0 Members and 1 Guest are viewing this topic.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
APP -- Sprites and text all messed up... why!?
« on: May 24, 2010, 10:52:38 am »
I've finally created an App, but when I run it, all sprites/text in the screen is messed up.
Everything does work, it reacts correctly to buttons pressed, but whenever I use a sprite or do something like :
Code: [Select]
    LD     HL, $0006
    LD     (CurRow), HL
    LD    HL, Sometext
    b_call _PutS
the screen fills with random stuff.
The program doesn't crash, I can still switch between menus by pressing the correct buttons (I made the priogram, so I can navigate blind in it), but like said, text shown as above and sprites dont work.

The programm worked fine before being turned into an App, and most sprites seem to show in the upper left corner of the screen, instead of twhere they're supposed to be.

I've used AppDev to compile the .z80 into an app.
Has anyone encountered the same problem?
How to fix this?
As said befire, when I normally compile it, it works perfectly fine.
I'm exeeding the 8kB limit though, so that's why I'm turining it into an App.
If I need to include more info, just ask and I'll post it.

Some random info that might/might not be related to the problem:
My header:
Code: [Select]
#INCLUDE "DWEDIT.INC"
#IFDEF APP
.org $4000

#IFNDEF NOAPPHEADER
;This is the application header definition area required for all apps.
 .db 080h,0Fh    ;Field: Program length
 .db   00h,00h,00h,00h ;Length=0 (N/A for unsigned apps)
 .db 080h,012h    ;Field: Program type
 #ifdef TI73
  .db 01h, 02h  ;type=Shareware, TI-73
 #else
  .db   01h,04h  ;Type= Shareware, TI-83Plus
 #endif
 .db 080h,021h    ;Field: App ID
 .db   01h       ;Id = 1
 .db 080h,031h    ;Field: App Build
 .db   01h       ;Build = 1
 .db 080h,048h    ;Field: App Name
 .db "CalcHero"
 .db 080h,081h    ;Field: App Pages
 .db 1
 .db 080h,090h    ;No default splash screen
 .db 03h,026h ,09h,04h, 04h,06fh,01bh,80h     ;Field: Date stamp- 5/12/1999
 .db 02h,0dh,040h                             ;Dummy encrypted TI date stamp signature
 .db 0a1h ,06bh ,099h ,0f6h ,059h ,0bch ,067h
 .db 0f5h ,085h ,09ch ,09h ,06ch ,0fh ,0b4h ,03h ,09bh ,0c9h
 .db 03h ,032h ,02ch ,0e0h ,03h ,020h ,0e3h ,02ch ,0f4h ,02dh
 .db 073h ,0b4h ,027h ,0c4h ,0a0h ,072h ,054h ,0b9h ,0eah ,07ch
 .db 03bh ,0aah ,016h ,0f6h ,077h ,083h ,07ah ,0eeh ,01ah ,0d4h
 .db 042h ,04ch ,06bh ,08bh ,013h ,01fh ,0bbh ,093h ,08bh ,0fch
 .db 019h ,01ch ,03ch ,0ech ,04dh ,0e5h ,075h
 .db 80h,7Fh      ;Field: Program Image length
 .db   0,0,0,0    ;Length=0, N/A
 .db   0,0,0,0    ;Reserved
 .db   0,0,0,0    ;Reserved
 .db   0,0,0,0    ;Reserved
 .db   0,0,0,0    ;Reserved
#ENDIF
#ENDIF

Oh, and I use this to put a sprite on the screen:
Code: [Select]
    LD A, 46 ; Random number
    LD (ypos), A
    LD A, 27 ; another Random number
    LD (xpos), A
    LD B, 18 ; Length of sprite in Y direction
    LD      DE, (ypos)
    LD      IX, Sprite ; Label of the sprite
    CALL Showsprite

Showsprite: ; Show Sprite (XOR)
        CALL    ClipSprXOR
        b_call _GrBufCpy
ret
ClipSprXOR: ; Show Sprite XOR
    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
« Last Edit: May 24, 2010, 11:00:54 am by Jerros »


79% of all statistics are made up randomly.

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: APP -- Sprites and text all messed up... why!?
« Reply #1 on: May 24, 2010, 11:12:44 am »
When you do a Bcall, the address you are giving on your app page will be pointing to random OS data instead. What most APP developers do is write their own _PutS routine like this:
Code: [Select]
app_PutS:
    ld a,(hl)
    inc hl
    or a
    ret z
    b_call _PutC
    jr app_PutS
Hope this helps!
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: APP -- Sprites and text all messed up... why!?
« Reply #2 on: May 24, 2010, 11:17:55 am »
When you do a Bcall, the address you are giving on your app page will be pointing to random OS data instead. What most APP developers do is write their own _PutS routine like this:

LĂ­ttle more info please, what it all does? :O
I'm a very newby programmer, so some more concrete info would be appreciated.
I do understany WHY the lot is messed up, thanx, though I still dont understand how to fix it.

And wha tyou said about the B_calls, does that count for ALL B_calls?
Because most, like b_call _RunIndicOff and b_call _GrBufClr seem to work fine...

Thanks anyway.


79% of all statistics are made up randomly.

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: APP -- Sprites and text all messed up... why!?
« Reply #3 on: May 24, 2010, 11:25:04 am »
Well, your app page is mapped in at addresses $4000-$7fff. When you do a Bcall, the OS page with the routine is temporarily put there, so the data pointed to by HL will no longer be your text. That's why it works if you read your text data and display each character manually, since the OS will not be trying to read data from your APP.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: APP -- Sprites and text all messed up... why!?
« Reply #4 on: May 24, 2010, 11:38:29 am »
Well, your app page is mapped in at addresses $4000-$7fff. When you do a Bcall, the OS page with the routine is temporarily put there, so the data pointed to by HL will no longer be your text. That's why it works if you read your text data and display each character manually, since the OS will not be trying to read data from your APP.

I start to get it...
Though I still don't understand how your posted code can help.
What do I do in order to show sprited/text the right way?
I don't know what to do with the code you gave me, sorry :C


79% of all statistics are made up randomly.

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: APP -- Sprites and text all messed up... why!?
« Reply #5 on: May 24, 2010, 02:53:28 pm »
I start to get it...
Though I still don't understand how your posted code can help.
What do I do in order to show sprited/text the right way?
I don't know what to do with the code you gave me, sorry :C
Instead of using:
 bcall _PutS
use:
 call app_PutS
and include the calcmaniac84 routine in the source code, of course.
Hobbing in calculator projects.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: APP -- Sprites and text all messed up... why!?
« Reply #6 on: May 25, 2010, 02:58:48 am »
Instead of using:
 bcall _PutS
use:
 call app_PutS
and include the calcmaniac84 routine in the source code, of course.

I'll try, thanks alot.
Oh, where can I find that source code of calcmaniac?
Been googling without result so far...
Meh, I'll keep searching.
« Last Edit: May 25, 2010, 11:56:55 am by Jerros »


79% of all statistics are made up randomly.

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: APP -- Sprites and text all messed up... why!?
« Reply #7 on: May 25, 2010, 03:17:11 pm »
Instead of using:
 bcall _PutS
use:
 call app_PutS
and include the calcmaniac84 routine in the source code, of course.

I'll try, thanks alot.
Oh, where can I find that source code of calcmaniac?
Been googling without result so far...
Meh, I'll keep searching.
Some name it safePutS.

This is the routine that calcmaniac found in this topic:
Code: [Select]
app_PutS:
    ld a,(hl)
    inc hl
    or a
    ret z
    b_call _PutC
    jr app_PutS
Hobbing in calculator projects.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: APP -- Sprites and text all messed up... why!?
« Reply #8 on: May 26, 2010, 04:01:15 am »
Replaced all the "b_call_PutS" with "call app_PutS" and included the small routine, but it's still messed up.
It does show the text now, though its in large font, and no where near where I want it.
Also, I can't applie it to sprites :/
I'm probably doing something wrong, but what's the normal way to display sprites/small text in an app where I want when I want?
Works when I use TASM to assemble and run it, but in an app its all still random junk on the screen, QQ.
« Last Edit: May 26, 2010, 04:02:47 am by Jerros »


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: APP -- Sprites and text all messed up... why!?
« Reply #9 on: May 26, 2010, 04:15:27 am »
I think you're thinking of "VPutS" instead of "PutS".  You also change "PutC" to "VPutMap" and instead of using CurCol and CurRow you use PenCol and PenRow.  I'm surprised this worked in small font before as a non-app, that's strange...

The sprites not working now but working before sounds like you might still have some self modifying code.  Either that, or you're using some other bcall that can't be executed in the $4000 address.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: APP -- Sprites and text all messed up... why!?
« Reply #10 on: May 26, 2010, 04:18:58 am »
Replaced all the "b_call_PutS" with "call app_PutS" and included the small routine, but it's still messed up.
It does show the text now, though its in large font, and no where near where I want it.
Also, I can't applie it to sprites :/
I'm probably doing something wrong, but what's the normal way to display sprites/small text in an app where I want when I want?
Works when I use TASM to assemble and run it, but in an app its all still random junk on the screen, QQ.
For using small font there is a flag you need to change. (see asmin28days tutorial in the part about text display, I think)
There is other flag to write only to the buffer and not to the screen, so you copy the buffer to screen whenever you want.

For sprites a normal routine works, are you giving the right inputs for it?
If you have some bugs on the APPS, it can happen to show strange symbols in all the screen upon exit.
Hobbing in calculator projects.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: APP -- Sprites and text all messed up... why!?
« Reply #11 on: May 27, 2010, 06:39:33 am »
Hmm...
It's annoying that my programm is nearly completed, but that things aren't workigng now because it's an App...
I shall try your suggestions, but otherwise I might need to PM my whole program (its VERY easy, since I'm a newby programmer) to someone, I bet you can see whats wrong in a quick glance.
I'm not asking anyone to fully "scan" my programm, but if someone wants to take quick peek to see wahts worng, tell me and I PM you the script.
For now I'll just try then things you've suggested.

Thanks ALOt for your help people!


79% of all statistics are made up randomly.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: APP -- Sprites and text all messed up... why!?
« Reply #12 on: May 27, 2010, 01:43:10 pm »
I don't know how to fix the sprite problem, but try this for your string:

    LD     HL, $0006
    LD     (CurRow), HL
    LD    HL, Sometext
    LD    DE, OP1
    LD    BC, ______     ; _____ is the length of your string in characters, INCLUDING the zero at the end
    LDIR
    LD HL, OP1
    b_call _PutS

I really have no idea what this will do for your app, but it fixed all my string problems for my app

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: APP -- Sprites and text all messed up... why!?
« Reply #13 on: May 28, 2010, 04:00:58 am »
    LD    BC, ______     ; _____ is the length of your string in characters, INCLUDING the zero at the end

I'll try, but you mean I load the number in BC that contains the number of characters +1?
So "Hello World!" would be
     LD     BC, 13
?

I'll try and see, as for the sprites it might be a self-modifieing code, like Quigibo said.
Unfortunately I can't touch the PC with the programming tools right now, but I'll try all suggestions later.
Thanks.


79% of all statistics are made up randomly.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: APP -- Sprites and text all messed up... why!?
« Reply #14 on: May 28, 2010, 04:29:37 am »
    LD    BC, ______     ; _____ is the length of your string in characters, INCLUDING the zero at the end

I'll try, but you mean I load the number in BC that contains the number of characters +1?
So "Hello World!" would be
     LD     BC, 13
?

Yes, that's correct.