Omnimaga
Calculator Community => TI Calculators => ASM => Topic started by: Yeong on October 30, 2011, 09:08:07 am
-
In my opinion, this should work. After I compile it, it worked for while and it sharted to go haywire and crashed my calc. What did I do wrong?
.org userMem-2
.db $BB, $6D
BCALL ClrLCDFull
CALL INITCOOR
LD HL,PIE
BCALL PutS
LOOP:
BCALL getKey
CP kUp
CALL Z,GOUP
CP kDown
CALL Z,GODOWN
CP kRight
CALL Z, GORIGHT
CP kLeft
CALL Z,GOLEFT
CP kClear
RET Z
BCALL ClrLCDFull
CALL INITCOOR
LD HL,PIE
BCALL PutS
JR LOOP
PIE:
.db "pi_symbol",0
COOR:
.db 0,0
INITCOOR:
LD HL,COOR
LD A,(HL)
LD (CURROW),A
LD HL,COOR+1
LD A,(HL)
LD (CURCOL),A
RET
GOUP:
LD HL,COOR
LD A,(HL)
DEC A
LD (HL),A
RET
GODOWN:
LD HL,COOR
LD A,(HL)
INC A
LD (HL),A
RET
GOLEFT
LD HL,COOR+1
LD A,(HL)
DEC A
LD (HL),A
RET
GORIGHT:
LD HL,COOR+1
LD A,(HL)
INC A
LD (HL),A
RET
-
In my opinion, this should work. After I compile it, it worked for while and it sharted to go haywire and crashed my calc. What did I do wrong?
.org userMem-2
.db $BB, $6D
BCALL ClrLCDFull
CALL INITCOOR
LD HL,PIE
BCALL PutS
LOOP:
BCALL getKey
CP kUp
CALL Z,GOUP
CP kDown
CALL Z,GODOWN
CP kRight
CALL Z, GORIGHT
CP kLeft
CALL Z,GOLEFT
CP kClear
RET Z
BCALL ClrLCDFull
CALL INITCOOR
LD HL,PIE
BCALL PutS
JR LOOP
PIE:
.db "pi_symbol",0
COOR:
.db 0,0
INITCOOR:
LD HL,COOR
LD A,(HL)
LD (CURROW),A
LD HL,COOR+1
LD A,(HL)
LD (CURCOL),A
RET
GOUP:
LD HL,COOR
LD A,(HL)
DEC A
LD (HL),A
RET
GODOWN:
LD HL,COOR
LD A,(HL)
INC A
LD (HL),A
RET
GOLEFT
LD HL,COOR+1
LD A,(HL)
DEC A
LD (HL),A
RET
GORIGHT:
LD HL,COOR+1
LD A,(HL)
INC A
LD (HL),A
RET
You forgot a :
There is supposed to be a : after GOLEFT
Even though I don't know shit about asm XD
-
(note: we talked on IRC XD)
Here is a version that is a little more optimised. I could do another optimisation, but that would probably just cause some confusion XD And it only saves 2 bytes, anyway...
Loop:
bcall(_ClrScrnFull) ;Clears the homescreen
ld hl,(Coor)
ld (CurRow),hl
ld hl,PIE
bcall(_PutS)
bcall(_getkey)
ld hl,(Coor) ;obtains the current cursor coordinates (l=row, h=col)
ld d,h \ ld e,l
TestRightKey:
dec a ;if a was 1, it becomes 0 and sets the z flag
jr nz,TestLeftKey
inc d
TestLeftKey:
dec a
jr nz,TestUpKey
dec d
TestUpKey:
dec a
jr nz,TestDownKey
dec e
TestDownKey:
dec a
jr nz,TestClearKey
inc e
TestClearKey:
;At this point, "a" has been decremented 4 times, so we test kClear-4
cp kClear-4 \ ret z
CheckBounds:
ld a,e \ and 7
ld l,a
ld a,d \ cp 8
jr nc,NotOutOfXBound
ld h,d
NotOutOfXBound
ld (Coor),hl
jr Loop
PIE:
.db "pi_symbol",0
Coor:
.dw 0
-
In my opinion, this should work. After I compile it, it worked for while and it sharted to go haywire and crashed my calc. What did I do wrong?
.org userMem-2
.db $BB, $6D
BCALL ClrLCDFull
CALL INITCOOR
LD HL,PIE
BCALL PutS
LOOP:
BCALL getKey
CP kUp
CALL Z,GOUP
CP kDown
CALL Z,GODOWN
CP kRight
CALL Z, GORIGHT
CP kLeft
CALL Z,GOLEFT
CP kClear
RET Z
BCALL ClrLCDFull
CALL INITCOOR
LD HL,PIE
BCALL PutS
JR LOOP
PIE:
.db "pi_symbol",0
COOR:
.db 0,0
INITCOOR:
LD HL,COOR
LD A,(HL)
LD (CURROW),A
LD HL,COOR+1
LD A,(HL)
LD (CURCOL),A
RET
GOUP:
LD HL,COOR
LD A,(HL)
DEC A
LD (HL),A
RET
GODOWN:
LD HL,COOR
LD A,(HL)
INC A
LD (HL),A
RET
GOLEFT
LD HL,COOR+1
LD A,(HL)
DEC A
LD (HL),A
RET
GORIGHT:
LD HL,COOR+1
LD A,(HL)
INC A
LD (HL),A
RET
You forgot a :
There is supposed to be a : after GOLEFT
Even though I don't know shit about asm XD
That was a typo <_<
I do have a colon after that because otherwise, Mimas won't let me compile
(note: we talked on IRC XD)
Here is a version that is a little more optimised. I could do another optimisation, but that would probably just cause some confusion XD And it only saves 2 bytes, anyway...
Loop:
bcall(_ClrScrnFull) ;Clears the homescreen
ld hl,(Coor)
ld (CurRow),hl
ld hl,PIE
bcall(_PutS)
bcall(_getkey)
ld hl,(Coor) ;obtains the current cursor coordinates (l=row, h=col)
ld d,h \ ld e,l
TestRightKey:
dec a ;if a was 1, it becomes 0 and sets the z flag
jr nz,TestLeftKey
inc d
TestLeftKey:
dec a
jr nz,TestUpKey
dec d
TestUpKey:
dec a
jr nz,TestDownKey
dec e
TestDownKey:
dec a
jr nz,TestClearKey
inc e
TestClearKey:
;At this point, "a" has been decremented 4 times, so we test kClear-4
cp kClear-4 \ ret z
CheckBounds:
ld a,e \ and 7
ld l,a
ld a,d \ cp 8
jr nc,NotOutOfXBound
ld h,d
NotOutOfXBound
ld (Coor),hl
jr Loop
PIE:
.db "pi_symbol",0
Coor:
.dw 0
What is .dw?
-
.dw sets a little-endian word (2 bytes) I don't know if Mimas supports that, if not, do .db 0,0
For example, .dw 5 is 0500 in memory
-
You can do "inc (hl)" btw.
http://www.ticalc.org/pub/text/z80/z80_reference.txt
-
Ok, so it's been a few months since i've touched z80, but i think you could do something like this:
cp 3 ;check if we are going horizontally or vertically, i might have this backwards
jr c,skip
inc hl
skip:
rla
rla
jr nc,skip2 ;if no carry (ie. down or right was pressed)
dec (hl)
jr skip3
skip2:
inc (hl)
skip3:
Here are your equates:
kDown .equ 04h
kUp .equ 03h
kLeft .equ 02h
kRight .equ 01h
10000000 right
01000000 left
11000000 up
00100000 down
after first shift we have:
00 r
10 l
10 u
01 d
which is more usable, as with r/d we need to increment and with l/u we need to decrement. Now another shift lets us use the carry flag. To do boundary checking, you could just use b instead of acting directly on hl:
ld b,1
cp 3
jr c,skip
inc hl
skip:
rla
rla
jr nc,skip2
dec b
dec b
skip2:
ld a,(hl)
add a,b
;boundary checking
ld (hl),a
You'd probably also want to test that a>0 & a<5, or at least that a isn't 0. I'm not sure if the code i gave you will actually work as i just wrote it off the top of my head, but maybe it'll give you something to think about even if it's completely useless :)
EDIT: Oh, and of course you would ld hl,Coor beforehand (vs ld hl,(Coor)).
EDIT2: Ah! And one more thing, i'd check for kClear before the other tests.
EDIT3: I imagine you've already discussed it, but the problem with your original code is probably your calls. You check a key, change the value of "a", then return to check for another key. You are almost certainly calling multiple labels at a time at each keypress (especially since many of the X/Y values match the getkey values)