0 Members and 2 Guests are viewing this topic.
.org userMem-2.db $BB, $6D BCALL ClrLCDFull CALL INITCOOR LD HL,PIE BCALL PutSLOOP: 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 LOOPPIE:.db "pi_symbol",0COOR:.db 0,0INITCOOR: LD HL,COOR LD A,(HL) LD (CURROW),A LD HL,COOR+1 LD A,(HL) LD (CURCOL),A RETGOUP: LD HL,COOR LD A,(HL) DEC A LD (HL),A RETGODOWN: LD HL,COOR LD A,(HL) INC A LD (HL),A RETGOLEFT LD HL,COOR+1 LD A,(HL) DEC A LD (HL),A RETGORIGHT: 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?Code: [Select].org userMem-2.db $BB, $6D BCALL ClrLCDFull CALL INITCOOR LD HL,PIE BCALL PutSLOOP: 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 LOOPPIE:.db "pi_symbol",0COOR:.db 0,0INITCOOR: LD HL,COOR LD A,(HL) LD (CURROW),A LD HL,COOR+1 LD A,(HL) LD (CURCOL),A RETGOUP: LD HL,COOR LD A,(HL) DEC A LD (HL),A RETGODOWN: LD HL,COOR LD A,(HL) INC A LD (HL),A RETGOLEFT LD HL,COOR+1 LD A,(HL) DEC A LD (HL),A RETGORIGHT: LD HL,COOR+1 LD A,(HL) INC A LD (HL),A RET
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,lTestRightKey: dec a ;if a was 1, it becomes 0 and sets the z flag jr nz,TestLeftKey inc dTestLeftKey: dec a jr nz,TestUpKey dec dTestUpKey: dec a jr nz,TestDownKey dec eTestDownKey: dec a jr nz,TestClearKey inc eTestClearKey:;At this point, "a" has been decremented 4 times, so we test kClear-4 cp kClear-4 \ ret zCheckBounds: ld a,e \ and 7 ld l,a ld a,d \ cp 8 jr nc,NotOutOfXBound ld h,dNotOutOfXBound ld (Coor),hl jr LoopPIE:.db "pi_symbol",0Coor:.dw 0
Quote from: yeongJIN_COOL on October 30, 2011, 09:08:07 amIn 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?Code: [Select].org userMem-2.db $BB, $6D BCALL ClrLCDFull CALL INITCOOR LD HL,PIE BCALL PutSLOOP: 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 LOOPPIE:.db "pi_symbol",0COOR:.db 0,0INITCOOR: LD HL,COOR LD A,(HL) LD (CURROW),A LD HL,COOR+1 LD A,(HL) LD (CURCOL),A RETGOUP: LD HL,COOR LD A,(HL) DEC A LD (HL),A RETGODOWN: LD HL,COOR LD A,(HL) INC A LD (HL),A RETGOLEFT LD HL,COOR+1 LD A,(HL) DEC A LD (HL),A RETGORIGHT: LD HL,COOR+1 LD A,(HL) INC A LD (HL),A RETYou forgot a :There is supposed to be a : after GOLEFTEven though I don't know shit about asm
(note: we talked on IRC )Here is a version that is a little more optimised. I could do another optimisation, but that would probably just cause some confusion And it only saves 2 bytes, anyway...Code: [Select]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,lTestRightKey: dec a ;if a was 1, it becomes 0 and sets the z flag jr nz,TestLeftKey inc dTestLeftKey: dec a jr nz,TestUpKey dec dTestUpKey: dec a jr nz,TestDownKey dec eTestDownKey: dec a jr nz,TestClearKey inc eTestClearKey:;At this point, "a" has been decremented 4 times, so we test kClear-4 cp kClear-4 \ ret zCheckBounds: ld a,e \ and 7 ld l,a ld a,d \ cp 8 jr nc,NotOutOfXBound ld h,dNotOutOfXBound ld (Coor),hl jr LoopPIE:.db "pi_symbol",0Coor:.dw 0
cp 3 ;check if we are going horizontally or vertically, i might have this backwards jr c,skip inc hlskip: rla rla jr nc,skip2 ;if no carry (ie. down or right was pressed) dec (hl) jr skip3skip2: inc (hl)skip3:
ld b,1 cp 3 jr c,skip inc hlskip: rla rla jr nc,skip2 dec b dec bskip2: ld a,(hl) add a,b;boundary checking ld (hl),a