Hello, I am trying to write a piece of code that uses one-bit-per-pixel mode and a routine to clear the screen. But I cannot figure out what is causing only the first few lines to be cleared.


Code:
#include "includes\ti84pce.inc"
.assume ADL=1
.org userMem-2
.db tExtTok,tAsm84CeCmp
 call _homeup
 call _RunIndicOff
 ld a,lcdBpp1 ; setup 1bpp mode
 ld (mpLcdCtrl),a
 
 ld hl,mpLcdPalette ; setup the palette
 ld bc,$FFFF ; 1 - black, 0 - white
 ld (hl),bc
 inc hl
 inc hl
 ld bc,0
 ld (hl),bc
 call CLR
loop: ;loop until button press
 call _GetCSC
 or a
 cp a, skEnter
 jr nz,loop
 
 ld a,lcdBpp16
 ld (mpLcdCtrl),a
 ret
CLR:
 ld bc, 320*240/8
 ld hl, vRam
CLR_loop:
 ld (hl),$0
 inc hl
 dec bc
 ld a,b
 sub a,c
 or a
 jr nz, CLR_loop
 ret
 
The exit condition check for CLR_loop is incorrect. As written, it will exit the loop when b-c=0, aka. b=c. 320*240/8=$2580, so this will happen after writing $80-$25=$5B=91 bytes (2 full rows plus 8 pixels on the 3rd). The common exit condition logic that I think you're looking for is ld a,b \ or a,c.

For the record, there's a much faster way to fill a block of memory with a value using ldir:

Code:
CLR:
 ld hl,vRam
 ld de,vRam+1
 ld bc,320*240/8-1
 ld (hl),$0
 ldir
 ret
Runer112 wrote:
The exit condition check for CLR_loop is incorrect. As written, it will exit the loop when b-c=0, aka. b=c. 320*240/8=$2580, so this will happen after writing $80-$25=$5B=91 bytes (2 full rows plus 8 pixels on the 3rd). The common exit condition logic that I think you're looking for is ld a,b \ or a,c.

For the record, there's a much faster way to fill a block of memory with a value using ldir:

Code:
CLR:
 ld hl,vRam
 ld de,vRam+1
 ld bc,320*240/8-1
 ld (hl),$0
 ldir
 ret

Thank you! That makes sense. Could you please explain what the backslash does in this line
Runer112 wrote:
ld a,b \ or a,c
Many assemblers treat a backslash as if it were a line break, so that's just a quick way to type out a sequence of a few instructions in one line.
  
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 1 of 1
» 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