This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's z80 & ez80 Assembly subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Z80 & 68k Assembly => z80 & ez80 Assembly
Author Message
jammasterz


Advanced Newbie


Joined: 28 Nov 2011
Posts: 72

Posted: 05 Apr 2012 10:45:31 am    Post subject:

Hi. I have a problem with this little piece of code:

Code:

MoveLeft:
    LD H, (pos)
    LD L, 1
    LD A, 2
    CALL Disp2A ;Displays DataLbl + A at HL (this time deletes the character)
    DEC H
    LD (pos), H ;trying to upload new position
    LD A, 0
    CALL Disp2A ; and here it displays "-"
    RET
MoveRight:
    LD H, (pos)
    LD L, 1
    LD A, 2
    CALL Disp2A
    INC H
    LD A, H
    LD (pos), A
   
    LD A, 0
    CALL Disp2A
    RET
]
I dont know exactly which line because my notepad doesnt show lines, but i think its line 7 and 17. What does this error mean?, I've tried everything to fix it but nothing worked.
Back to top
Xeda112358


Active Member


Joined: 19 May 2009
Posts: 520

Posted: 05 Apr 2012 11:53:19 am    Post subject:

The two offending lines are:
LD (pos), H
LD H, (pos)
Those are invalid commands :/ You can only load HL and A directly to a memory address, unfortunately. So what you could do is "LD A, H \ LD (pos),A" and "LD A,(pos) \ LD H,A" respectively. I hope that helps!

Also, a trick I learned with notepad is the doing Ctrl+G well let me go to a line. This helps a lot in debugging Smile
Back to top
jammasterz


Advanced Newbie


Joined: 28 Nov 2011
Posts: 72

Posted: 05 Apr 2012 01:01:38 pm    Post subject:

Eh, that feels bad, really really bad.
Feel free to test it out and tell me what you think Smile

Code:

.nolist
#include "ti83plus.inc"
#define    ProgStart    $9D95
lA_    .equ    $9876
pos    .equ    $9872
count    .equ    $9873
wait    .equ    $9874
.list
.org    ProgStart - 2
    .db    t2ByteTok, tAsmCmp
    bcall(_ClrScrnFull)
    RES IndicRun, (IY+IndicFlags)
    LD A, 3
    LD (pos), A
    XOR A
    LD (count), A
    LD HL, $0003
    LD (CurRow), HL
    LD A, '>'
    bcall(_PutMap)
InfiniteLoop:
    bcall(_GetCSC)
    CP SkMode
    JP Z, Quit
CheckLeft:
    CP sk8
    JR NZ, CheckRight
    LD H, A
    LD A, (pos)
    CP 0
    LD A, H
    CALL NZ,MoveLeft   
CheckRight:
    CP sk2
    JR NZ, CheckShoot
    LD A, (pos)
    CP 7
    CALL NZ, MoveRight
CheckShoot:
    CP sk6
    CALL Z, AddBullet
   
    LD HL, count
    LD A, (HL)
    CP 0
    JR Z, InfiniteLoop
    PUSH AF

    LD HL, wait
    LD A, (HL)
    INC A
    LD (HL), A
    CP 0
    JP NZ, Infiniteloop

    POP AF
    LD DE, $FFFF
    LD B, A
Checkif15:
    INC DE
    LD A, 15
    LD HL, lA_
    SCF
    ADC HL, DE
    PUSH BC
    CPI
    POP BC
    PUSH AF
    CALL NZ, Isnt15
    POP AF
    CALL Z, Is15
    DJNZ Checkif15
    JP InfiniteLoop
Is15:
    CALL GetBulletDisp
    LD A, ' '
    bcall(_PutMap)

    LD HL, count
    LD A, (HL)
    PUSH BC
    SUB E
    DEC A
    ADD A, A
    LD B, 0
    LD C, A
   
    LD HL, lA_
    ADD HL, DE
    PUSH DE
    LD D, H
    LD E, L
    INC HL
    INC HL
    LDIR
    POP DE
   
    LD HL, count
    LD A, (HL)
    DEC A
    LD (HL), A

    POP BC
Isnt15:
    CALL GetBulletDisp
    LD A, ' '
    bcall(_PutMap)
   
    LD HL, count
    LD A, (HL)
    CP 0
    RET Z
   
    LD HL, lA_
    ADD HL, DE
    INC HL
    LD A, (HL)
    INC A
    LD (HL), A
   
    CALL GetBulletDisp
    LD A, '-'
    bcall(_PutMap)
    RET
GetBulletDisp: ;destroys HL sets C
    PUSH DE
    LD H, D
    LD L, E
    ADD HL, HL
    EX DE, HL
    LD HL, lA_
    SCF
    ADC HL, DE
    LD A, (HL)
    LD (CurCol), A
    DEC HL
    LD A, (HL)
    LD (CurRow), A
    POP DE
    RET
DispA:   ;destroys HL
    LD HL, lA_
    PUSH DE
    ADD HL, DE
    LD E, (HL)
    INC HL
    LD D, (HL)
    EX DE, HL
    POP DE
Disp2A:
    LD (CurRow), HL
    bcall(_PutMap)
    RET
MoveLeft:
    LD A, (pos)
    LD H, 0
    LD L, A
    LD A, ' '
    CALL Disp2A
    DEC L
    LD A, L
    LD (pos), A
    LD A, '>'
    CALL Disp2A
    RET
MoveRight:
    LD A, (pos)
    LD H, 0
    LD L, A
    LD A, ' '
    CALL Disp2A
    INC L
    LD A, L
    LD (pos), A   
    LD A, '>'
    CALL Disp2A
    RET
AddBullet:
    LD A, (count)
    CP 0
    JR Z, AddTheBullet
    CP 5
    RET Z
    DEC A
    LD HL, lA_
    LD D, 0
    LD E, A
    EX DE, HL
    ADD HL, HL
    ADD HL, DE
    LD A, (pos)
    CPI
    JR NZ, AddTheBullet
    LD A, 1
    CPI
    JR NZ, AddTheBullet
    RET
AddTheBullet:
    LD HL, lA_
    LD A, (count)
    LD D, 0
    LD E, A
    EX DE, HL
    ADD HL, HL
    ADD HL, DE
    PUSH HL
    LD HL, pos
    LD A, (HL)
    POP HL
    LD (HL), A
    INC HL
    LD A, 1
    LD (HL), A
    LD A, (count)
    INC A
    LD (count), A
    RET
Quit:
    bcall(_ClrScrnFull)
    RET
.end
.end


Last edited by Guest on 10 Apr 2012 08:46:47 am; edited 1 time in total
Back to top
Xeda112358


Active Member


Joined: 19 May 2009
Posts: 520

Posted: 05 Apr 2012 01:32:00 pm    Post subject:

Hmm, I had a few issues. I changed these #define statements:

Code:

#define    ProgStart    $9D95
#define    lA    $9875
#define    pos    $9872
#define    count    $9873
#define    dc    $9874

To this (this is the proper syntax):

Code:

ProgStart  equ  $9D95
lA_        equ  $9875
pos        equ  $9872
count      equ  $9873
dc         equ  $9874

This is because you are assigning a constant to a variable as opposed to a function (macro). Also, you will notice that I had to change lA to lA_ and that is because that is already defined in the ti83plus include. I don't have time right now to debug (I have a project to go work on), but I could give it a go later Smile
Back to top
jammasterz


Advanced Newbie


Joined: 28 Nov 2011
Posts: 72

Posted: 06 Apr 2012 11:04:17 am    Post subject:

What?
Back to top
jammasterz


Advanced Newbie


Joined: 28 Nov 2011
Posts: 72

Posted: 06 Apr 2012 11:08:07 am    Post subject:

If you mean that im too lazy to debug it myself, youre wrong. I just posted it to show people what ive made so far and how terribly wrong it is, not to make them do my work for me. Right now im just too frustrated to look at the code again.
Back to top
Xeda112358


Active Member


Joined: 19 May 2009
Posts: 520

Posted: 06 Apr 2012 02:31:51 pm    Post subject:

Usually if it says an interest of 143040, it is a spam bot x.x Also, you said "tell me what you think," so I thought you wanted people to test it and see if they could help remove errors :[ Sorry if I sounded like I was saying you cannot :(

EDIT: And apparently the part of my post that said "Also, the program seemed frozen and wasn't doing anything" was cut out :/ That is what I meant when I said I didn't have time to debug and I was in a hurry to get to my group on time so we could plan a presentation :[ I just wanted to see if I could step through your code to see what was going on.


Last edited by Guest on 06 Apr 2012 02:35:05 pm; edited 1 time in total
Back to top
jammasterz


Advanced Newbie


Joined: 28 Nov 2011
Posts: 72

Posted: 07 Apr 2012 02:17:38 pm    Post subject:

I absolutely didnt find it offending Smile.

And actually i did something Very Happy. The main loop was working because i could quit and everything was normal. Also when i pressed 8 or 2 something strange was displayed.

Now i have a little question. If i want the program to display ' ', '-' and '>' do i just do like this?

Code:

Data:
    .DB '>', 0
    .DB ' ', 0
    .DB '-', 0

or do i have to save them as some kind of special tokens or ascii codes?
Back to top
Xeda112358


Active Member


Joined: 19 May 2009
Posts: 520

Posted: 07 Apr 2012 03:43:46 pm    Post subject:

The .db statements should be good for most common chars, but the TI-83+ ASCII has a few differences from normal ASCII, so you might need to watch out for that. Also, since you are only displaying 1 char, it might be more beneficial to display them as chars instead of strings Smile For example:

Code:

     ld a,'G'
     bcall(_PutC)    ;displays the char based on the value of a, so it will display G

If you don't want the cursor to advance, you can use _PutMap instead Smile
Back to top
jammasterz


Advanced Newbie


Joined: 28 Nov 2011
Posts: 72

Posted: 07 Apr 2012 04:41:13 pm    Post subject:

Thanks! Didnt think about it Very Happy. Now as i can see something on the screen i can also see how many newbie mistakes i made Surprised I allways wondered, why make it little endian? It just confuzes people.
Back to top
Xeda112358


Active Member


Joined: 19 May 2009
Posts: 520

Posted: 07 Apr 2012 06:28:09 pm    Post subject:

I know I came across something that made sense to me about the little-endian thing, but I have forgotten. I think it was when I was working on some multiprecision math things. However, I think it is more to do with the actual processor design (it probably made it faster/smaller).
Back to top
jammasterz


Advanced Newbie


Joined: 28 Nov 2011
Posts: 72

Posted: 08 Apr 2012 09:54:18 am    Post subject:

I play quite a lot with processor design and layout, and i donw think its a problem. Think about it, there is no speed nor compacity loss when getting a wire to a diffrent place( those places should be right next to eachother). Ill google it Smile.

I've got one more problem. I have edited the bulletmovement routine and it says that there is no such instruction as:

Code:

    PUSH BC
    SUB A, E  ;this one
    ADD A, A
    LD C, A

Im certain because i checked it in documenatation, and its says, SUB A, reg8 where reg can be E.

EDIT:
Wow so this is why!
http://www.noveltheory.com/TechPapers/endian.asp

I didnt think about it this way, espetially that we dont look at raw memory, but process it and load to some adresses. It would only be usefull if there was a way to load 2 bytes of memry to a 16 bit register that does NOT cosist of 2 smaller ones, which would make that the number would still be correct. On z80 however, there are no such registers, which means little endian just makes our life much more difficult Smile


Last edited by Guest on 08 Apr 2012 10:02:22 am; edited 1 time in total
Back to top
Xeda112358


Active Member


Joined: 19 May 2009
Posts: 520

Posted: 08 Apr 2012 10:35:05 am    Post subject:

Haha, this one is always one that causes issues. With ADD, we can do either 8-bit or 16-bit, so you need to specify ADD A,reg8 or ADD HL,reg16. Many assembler carry the same syntax to SUB, even though it is only 8-bit. However, most omit the "A," part to save some memory and speed as it isn't needed (there is no SUB HL,reg16 though many would love it).

Pretty much, just do SUB E. I wish assemblers would be consistent, but you won't know which syntax a z80 assembler will use until you try it and either get an error or get an OK x.x
Back to top
jammasterz


Advanced Newbie


Joined: 28 Nov 2011
Posts: 72

Posted: 08 Apr 2012 12:00:48 pm    Post subject:

Okay, the code has been updated. Now im begging for help because its beyond me. The GetBulletDisp routine is in my understanding incorrect( should switch CurRow and CurCol), but its fine for the calculator. The rest is an exact translation of my ti-basic code, but of course it doesnt work. If there is only one bullet everything is almost ok, but when the bullet reaches Y=15 the ship disappears if its located above the bullet. I said almost allright because the bullets should move by themselves, not by any keypress. Then where there are more than one bullet it starts freaking out. Whats interesting is that when you 2nd quit, and try to do something the the operating system is broken without any reason. Could you please tell me where i made a mistake? If you want to see the working ti-basic code look at topic names starwars.
Back to top
Xeda112358


Active Member


Joined: 19 May 2009
Posts: 520

Posted: 08 Apr 2012 01:32:52 pm    Post subject:

Okay, I'll check it out. I used to have routines like this fail in the past and it would take me forever to figure out why x.x

EDIT: One thing that will make it not work is using bcall(_GetKey) instead of bcall(_GetCSC). _GetKey waits until you press a key, whereas _GetCSC does not. Also, the keycodes are different for the two, unfortunately, so you will have to change those around.

EDIT2: Hmm, I wrote up some code and it is working, now, but some parts are crazy. It currently looks like what it does below. Also, in doing this, I found a mistake in a well known/used .inc file x.x bcall(4744h) is one of the getkey bcalls that I like to use often.

Code:

#include    "ti83plus.inc"
#define     progStart   $9D95
.org        progStart-2
.db         $BB,$6D
     bcall(_RunIndicOff)
     bcall(_ClrScrnFull)
     ld a,127
     ld (textShadow-1),a    ;I do this so that updating the homescreen is easy
     ld hl,4
     ld (CurRow),hl        ;since hl is 0400 in little endian, (CurRow) is 4 and (CurCol) is 0
Loop:
     xor a
     ld (CurCol),a
     ld a,'>'
     bcall(_PutC)       ;This advances the cursor which I will use when shooting
     ld hl,(CurRow)
     push hl
     ld hl,0
     ld (CurRow),hl     ;since hl is 0, it resets the cursor
     ld hl,textShadow-1 ;HL points to the homescreen data minus 1 (where I put 127 before)
     bcall(_PutPS)      ;draws a string with size as a leading byte
     ld a,(textShadow+127)
     bcall(_PutMap)
     pop hl
     ld (CurRow),hl     ;Restores the coordinates

;I am going to manually remove the > on the screen
;I could optimise this more, but then it would be more confusing
     ld hl,textShadow
     ld a,(CurRow)
     add a,a            ;doubles a. There won't be an overflow.
     rlca               ;doubles a. There won't be an overflow.
     rla                ;doubles a. There won't be an overflow.
     adc a,a            ;doubles a. There won't be an overflow.
;At this point, A was the row, but since there are 16 chars to a row,
;I had to multiply it by 16. Now it is the proper offset into textShadow
     add a,l            ;we don't need to worry about it overflowing in this case. A is at most 70h and L is 08h
     ld l,a
     ld (hl),20h        ;This is in fact possible. 20h is a space

;Now we check for the key
     bcall(4744h)       ;cannot remember what it is called, but it is a getkey routine
     cp 19              ;This is 6
     jr nz,CheckClear
       push af
       ld a,'-'
       bcall(_PutC)
       pop af
CheckClear:
     cp 15              ;This is clear
     ret z
     ld hl,CurRow
     cp 26               ;This is 2
     jr nz,Check8
       inc (hl)
Check8:
     cp 28               ;This is 8
     jr nz,MaskY
       dec (hl)
MaskY:
     ld a,7             ;this a mask (it is 00000111b)
     and (hl)           ;Now if it went off screen, 8 contains the coordinates looped back around
     ld (hl),a          ;Load coordinate back in
Counter     equ  $+1    ;This is SMC
     ld a,0             ;the 12 will change
     dec a
     ld (Counter),a     ;So set it back to 12
     jr nz,Loop         ;If the counter doesn't hit zero, go back, else...
CounterIs0:
     ld a,0
     ld (Counter),a     ;So set it back to 12
ShiftHomeScreen:
;Feel free to ask why this works
;I am just going to shift the contents of textShadow by one byte and then clear the first row
;This isn't the fastest way to do this, but it is small
     ld de,textShadow+127     ;last byte of textShadow
     ld hl,textShadow+126
     ld bc,127          ;number of bytes we will coppy
     lddr               ;copies (HL) to (DE), then dec HL, dec DE, dec BC until BC=0
ClearFirstRow:
;DE now points to textShadow, let's uses it
;BC is 0, but I want it to be 16... hehe set bit 4 of C is 8 cycles, 2 bytes
;...Nevermind, if I use B for a counter later, it will save more cycles
     ex de,hl
     ld de,16
     ld b,8
     ld a,20h

;now HL=textShadow
;    DE=16            ;so D=0, E=16
;     B=8
;     A=20h           ;so A is a space
ClearColumn:
     ld (hl),a
     add hl,de        ;HL now points to the next row
     djnz ClearColumn
     jr Loop

I may or may not have broken it, too :/


Last edited by Guest on 08 Apr 2012 03:18:08 pm; edited 1 time in total
Back to top
jammasterz


Advanced Newbie


Joined: 28 Nov 2011
Posts: 72

Posted: 10 Apr 2012 01:04:49 am    Post subject:

I really love the small things and hacks that you do that make the code super fast. But unfortunately i can not accept this code. Please don't get me wrong, im not trying to be rude or something, but i want to write the code myself. It's my fault that i didn't say what i really want. What i ment is if someone could show the parts of code that are wrong or suspicious. I hope you understand.
Back to top
Xeda112358


Active Member


Joined: 19 May 2009
Posts: 520

Posted: 10 Apr 2012 06:57:13 am    Post subject:

Yeah, it's no problem Smile I just had fun working on it myself, so I shared Very Happy Anyays, if you use bcall(_GetCSC) instead of bcall(_GetKey), you will need to use these values:
55 instead of kQuit
28 instead of k8
26 instead of k2
19 instead of k6

Then it will shoot very fast (I thought it wasn't working until I watched very closely and saw it shoot out), so you might need some delay. Also, I think your routine for adding bullets/removing bullets might be broken :/ I hope that helps!
Back to top
jammasterz


Advanced Newbie


Joined: 28 Nov 2011
Posts: 72

Posted: 10 Apr 2012 08:45:06 am    Post subject:

Yeah, i solved it. I dont need to remember the codes, the are included in the inc file, for example 6 = Sk6. I also implemented a counter that counts to 255 before it jumps in the loop that moves the bullets(i think it will be slower on a calculator, but its not a problem to change the value). The problem is that if you shoot 4 times(not at the same time), it crashes. Somehow it manages to jump ot of the program and just go foward until meeting some invalid instruction. Also i noticed that after the 4th shot everything from adress FFFF to the code of program(not exactly, just go back and you will see it) is overwritten with the bullet coords. There is a problem with the Is15 routine, but i cant find it. I updated the code.

Last edited by Guest on 10 Apr 2012 08:49:31 am; edited 1 time in total
Back to top
jammasterz


Advanced Newbie


Joined: 28 Nov 2011
Posts: 72

Posted: 12 Apr 2012 02:30:34 am    Post subject:

Okay, there must be something wrong with the debugger, because i've spent the last 2 days trying to find that bug and it just doesn't exist. There is no way that a value of any register gets over 987F, but still it somehow manages to overwrite.
Back to top
Xeda112358


Active Member


Joined: 19 May 2009
Posts: 520

Posted: 12 Apr 2012 05:18:40 am    Post subject:

Hmm, just took a more detailed look:

Code:

CheckShoot:
    CP sk6
    CALL Z, AddBullet
   
    LD HL, count
    LD A, (HL)
    CP 0
    JR Z, InfiniteLoop
    PUSH AF                   ;you push... okey dokey

    LD HL, wait
    LD A, (HL)
    INC A
    LD (HL), A
    CP 0
    JP NZ, Infiniteloop     ;If your wait loop isn't zero, you never pop D:

Also, instead of INC A \ LD (HL),A, you can do INC (HL) and you don't even need the CP 0. When you do INC or DEC on an 8-bit register, if it reaches zero, the z flag is set, otherwise it is nz.
Back to top
Display posts from previous:   
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
    » Goto page 1, 2  Next
» View previous topic :: View next topic  
Page 1 of 2 » All times are UTC - 5 Hours

 

Advertisement