Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 127 users online: 3 members, 87 guests and 37 bots. Members: gbl08ma, joao_fragoso16, stefan bauwens. Bots: VoilaBot (4), Spinn3r (1), Magpie Crawler (4), VoilaBot (8), Googlebot (20).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
|
| Author |
Message |
|
KermMartian

Site Admin

Joined: 14 Mar 2005 Posts: 55886 Location: Earth, Sol, Milky Way
|
Posted: 16 Nov 2011 05:49:20 pm Post subject: |
|
|
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.
5. That's what I figured.
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. _________________
 |
|
| Back to top |
|
|
arriopolis
New Member

Joined: 29 Mar 2011 Posts: 92
|
Posted: 16 Nov 2011 05:52:18 pm Post subject: |
|
|
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.
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.
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.
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.  |
|
| Back to top |
|
|
Rascherite

New Member

Joined: 09 Nov 2011 Posts: 93 Location: Under a heaping pile of saxophones
|
Posted: 16 Nov 2011 06:36:39 pm Post subject: |
|
|
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!!!
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 ) |
|
| Back to top |
|
|
KermMartian

Site Admin

Joined: 14 Mar 2005 Posts: 55886 Location: Earth, Sol, Milky Way
|
Posted: 16 Nov 2011 07:56:22 pm Post subject: |
|
|
Hehe, you preempted my suggestion. 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. _________________
 |
|
| Back to top |
|
|
|
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
|
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
|
© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.036230 seconds.
|