This is my first post, Don't really use forums much so I hope this is the right place to ask this stuff.
Background:
I'm a freshman in college, Have been messing around with TI-BASIC since Sophmore year of high school. Besides TI-BASIC I can program Java, C++, BATCH, the normal stuff. At my college, we are not allowed to use programmable calculators for quizzes and tests, so my trusty TI hasn't gotten much love recently. So about a week ago I decided that I was going to finally learn z80 assembly! (I actually own a TI84+ CE, but I figured that there would be a lot more resources online for z80 asm, so I decided to learn that).
The first few days were terrible. I couldn't get anything to work from any of the resources I found (Mostly Learn TI-83 asm in 28 days), But not too long ago I found an online z80 assembler at clrhome.org/ And that made it easy to write code and move to my TI-83+ emulator.
So I've been following the 28 days tutorial and a using a few other resources and The following mess of code is the result of me trying to use what i've learned so far. I know its probably terrible and the only way for me to get better is for more experienced programmers to tell me how why I suck.
So Heres my code, you press the up and down arrow keys to increase or decrease an 8-bit number, Then you press enter to save that number, then you select a new number, and it adds those 2 numbers together. Tear it apart, Tell me what I should of done and why, Tell me what exactly I did wrong wherever it applys. Thanks
Code:
Background:
I'm a freshman in college, Have been messing around with TI-BASIC since Sophmore year of high school. Besides TI-BASIC I can program Java, C++, BATCH, the normal stuff. At my college, we are not allowed to use programmable calculators for quizzes and tests, so my trusty TI hasn't gotten much love recently. So about a week ago I decided that I was going to finally learn z80 assembly! (I actually own a TI84+ CE, but I figured that there would be a lot more resources online for z80 asm, so I decided to learn that).
The first few days were terrible. I couldn't get anything to work from any of the resources I found (Mostly Learn TI-83 asm in 28 days), But not too long ago I found an online z80 assembler at clrhome.org/ And that made it easy to write code and move to my TI-83+ emulator.
So I've been following the 28 days tutorial and a using a few other resources and The following mess of code is the result of me trying to use what i've learned so far. I know its probably terrible and the only way for me to get better is for more experienced programmers to tell me how why I suck.
So Heres my code, you press the up and down arrow keys to increase or decrease an 8-bit number, Then you press enter to save that number, then you select a new number, and it adds those 2 numbers together. Tear it apart, Tell me what I should of done and why, Tell me what exactly I did wrong wherever it applys. Thanks
Code:
; Learning ASM Day 4
; Exercise using:
; 1. Getting User Input
; 2. Displaying Number
; 3. The Stack (Only a lil bit)
#include "ti83plus.inc"
#define progStart $9D95
#define number 0
.org progStart-2
.db $BB,$6D
bcall(_RunIndicOff)
bcall(_ClrLCDFull)
ld DE,0
ld (CurRow),DE
ld c,number
ld b,1 ;B is a counter for how many numbers to add, 2
PreLoop:
push de
call DisplayNumber
pop de
KeyLoop: ;Repeat until Correct Button Pressed
bcall(_GetCSC)
cp skUp
call z,Increase
cp skDown
call z,Decrease
cp skEnter
jr z,StoreNumber
jr KeyLoop
Increase:
ld a,c
cp 255
ret z ;If number is 255 dont increase
inc c
push de
call DisplayNumber
pop de
ret
Decrease:
ld a,c
cp 0 ;If number is 0 dont decease
ret z
dec c
push de
call DisplayNumber
pop de
ret
StoreNumber:
bcall(_NewLine)
ld a,b
cp 0 ;If this is the Second number
jr z,Finish ;Goto End
dec b
ld d,c ;Store Current Numer in D
ld c,number ;reset c
jr PreLoop
Finish:
ld a,d ;Put first number in A
add a,c ;add first and 2nd numbers
ld c,a
call DisplayNumber
ret
DisplayNumber: ;Sets Cursor all the way left and displays HL
ld H,0
ld a,H
ld (CurCol),a
ld L,c
bcall(_DispHL)
ret