4. I understand, it's good to get experience. I hope that after a certain point you'll use libraries, though; I've gone the route of rolling my own everything in other languages, and it gets tedious. Plus Benryves gets angry at you. Wink

5. That's what I figured. Smile

6. Yes. Any 8-bit to 8-bit register load is a single byte, whereas loading an immediate (a number) to an 8-bit register is 2 bytes. Loading an immediate to a 16-bit register is 3 byte, 1 for the opcode and 2 for the value. There is no 16-bit to 16-bit register load other than ex de,hl (which is 1 byte) and push r16a \ pop r16b, which is of course two bytes and quite a few cycles. As far as writing good code, it's good to start to get a sense for how opcode size figures into your program. Another good one that's key is that jr blah is 2 bytes, jr condition,blah is 2 bytes, jp blah and jp condition, blah are both 3 bytes, and bcall() and call are both 3 bytes.
Ok, I've looked through your program a little, and I must say: you did a good job!
There are a few optimizations possible though. Although I reaize some of them involve tricks and techniques you haven't come across yet.
P.S. Sorry for the upparcase mnemomics, it's just my way of coding. Very Happy

Code:
   b_call(_ClrLCDFull)
   ld   a, 0

could be changed to XOR A, to save 1 byte.

Code:
   ld   (CurRow), a            ;CurRow is y
   ld   (CurCol), a            ;CurCol is x
   ld   hl, 0

What would you think of:

Code:
    LD HL, 0
    LD (CurRow), HL

Moving on:

Code:
   ld   (AppBackUpScreen), hl         ;position of "character" (a 'u').  (AppBackUpScreen) = x, (AppBackUpScreen+1) = y. 
   ld   (AppBackUpScreen+2), hl          ;position of "thing to catch" (an 'o'). 
   ld   (AppBackUpScreen+4), hl         ;score 
   ld   hl, 3 
   ld   (AppBackUpScreen+5), hl         ;lives 
   ld   a, 7 
   ld   (AppBackUpScreen+1), a         ;constant y pos of 'u'

There are many successive bytes in memory you reset here. Your code took 19 bytes...

Code:
    LD HL, VariableSetup
    LD DE, AppBackupScreen
    LD BC, 7
    LDIR
VariableSetup:    .DB 0, 7, 0, 0, 0, 0, 3

This takes up 17 bytes.

Code:
   ld   hl, 0 
   push   hl 

I'm not exactly sure what you're using HL for, but I guess it involves a countdown for the character to move a place down. I'd recommend using an interrupt service for that, but I think you're not familiar with that, so this could be a future optimization. Smile

Code:
   scf                           ;set and clear carry flag to make sure sbc hl, de is accurate 
   ccf 

As kerm said, OR A works much better for resetting carry.

Code:
   jp   nc, incr_o                  ;if hl is greater than $400 (the carry flag is not triggered by subtracting $400 from hl), jump to incr_o 

I guess you mean $500?

Code:
moveleft: 
   ld   a, (AppBackUpScreen)      ;load the player's x coord into the a register 
   cp   0     jr   z, disp                  ;if 'u'x is equal to 0, jump to display routine without decrementing the x coordinate to prevent it from going offscreen 

OR A, again, would work best.

Code:
   pop   hl 
   ld   de, $120               ;increment hl more than usual, the b_calls _PutC and _ClrLCDFull at the disp label will take a lot of time        add   hl, de 
   push   hl 

Would be redundand if you were using interrupts. Smile

Code:
   ld   a, 0

Again, XOR A saves you space.

Overall, you did a wonderful job, really!
An idea for the score displaying mechanism:

Code:
    LD HL, $0B00
    LD (CurRow), HL
    LD L, A
    LD H, 0
    b_call(_DispHL)

It should do, but b_call(_DispHL) takes up 5 characters on the screen, which would interfere with you're game screen. I don't see any other place to display the score though. Smile
Kerm: I know that I'll have to use libs eventually. I dragged my feet with c for a long time, but I came around eventually. Idk if it will ever happen in z80 though because, like I said, a lot of my users will be too lazy/ignorant to download a shell.
And anyways, I wouldn't want to get on Ben Ryves's nerves. Before I even knew cemetech existed, I stumbled across his personal webpage and some of the projects he's finished amazed me (especially the z80 computer). I don't like getting on the nerves of awesome people.

arriopolis:
Thank you for all the helpful remarks =)
1/2. Cool, easy to understand
3. This was crazy helpful and I would have continued to do stuff the stupid way had you not pointed this out. Imagine me writing a big project and initializing 30 or 40 vars like that. Ouch.
If I'm going to copy the data at the VariableSetup label to AppBackUpScreen, wouldn't it just be better to have code like:

Code:


ux     .equ     VariableSetup
uy     .equ     VariableSetup+1
;etc

;main code goes here

VariableSetup:    .DB 0, 7, 0, 0, 0, 0, 3


4. I'm aware of interrupts, but I don't know how to use them yet. New post time in my questions thread!!! Very Happy

5/6. Got those too =)

7. Oops!! I wanted to make the delay longer, but I forgot to update it in the comments!

8-10. Acknowleged and remembered!

11. As for the score display system, I was already aware of the b_call(_DispHL), but I want the score to be displayed vertically in the same column where lives are displayed:


Code:

 ________________
|               0| <---score
|               0|
|               5|
| o              |
|               u|
|               u| <--- Lives remaining
|               u|
|   u            |



So I will have to come up with a function to convert that int to a string (Which I would like to do on my own Smile)
Hehe, you preempted my suggestion. Smile I wouldn't try to mess with interrupts for a good long while; there's a lot to understand with ports and the underlying hardware if you want to properly understand what you're implementing rather than copy-pasting code.
  
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 2 of 2
» 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