FAQ  •  Register  •  Login

clearbox

<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Tue Apr 17, 2012 1:30 am

clearbox

I've added a partial clear screen routine (clearBox.bas) to the library. It does what it says - clears a defined rectangle of the screen. Good for clearing out the bits you don't want, such as the game board, but leave the status bit alone.

http://www.boriel.com/wiki/en/index.php ... C:ClearBox
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Tue Apr 17, 2012 8:42 am

Re: clearbox

This comes very handy.
Just a little request: If you make comments in Assembly, please do not use the ";" character, but the sequence ";' " because as you can see, the syntax highlighter of the Wiki (and BorIDE) highlighs some comment words as keywords. Using the sequence prevents it from highlighting them. This is just a cosmetic issue.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Tue Apr 17, 2012 11:32 am

Re: clearbox

Bit ugly, but I see the logic. I still maintain it's a fail on the part of those bits of software, though :)
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Tue Apr 17, 2012 8:36 pm

Re: clearbox

britlion wrote:Bit ugly, but I see the logic. I still maintain it's a fail on the part of those bits of software, though :)

In fact the lexer does not know what is Assembler and what is BASIC. Standard lexers can recognise only one syntax, and ZX BASIC has two types of REM characters, which confuse ANY lexer. So the only solution is to use this sequenze in ASM.
Talking about it: ASM command SUB opens also a fold point in BorIDE, so I'm not a fan of using same keywords for BASIC as they are used by Assembler. Instead of SUB I would use PROCEDURE or PROC.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue Apr 17, 2012 9:14 pm

Re: clearbox

The ZX BASIC lexer uses the Regular Expression:
  Code:
([']|[Rr][Ee][Mm][ \t])
to match a comment line.

The ASM / END ASM sequence is a bit special (the lexer enters another state which I guess simple syntax-highlighters doesn't do).
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Wed Apr 18, 2012 8:34 am

Re: clearbox

boriel wrote:The ZX BASIC lexer uses the Regular Expression:
  Code:
([']|[Rr][Ee][Mm][ \t])
to match a comment line.

The ASM / END ASM sequence is a bit special (the lexer enters another state which I guess simple syntax-highlighters doesn't do).

Yes, thats what I mean. It is something special as ";" has a different meaning in BASIC than ASM.
Can you add the ability to recognise '-REM char also in Assembly blocks too? I know that it is used in EX AF,AF' too... Now it produces illegal character error.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

BCH

Posts: 2

Joined: Mon Feb 18, 2013 5:47 pm

Post Thu Feb 21, 2013 9:57 pm

Re: clearbox

I've expanded the routine so it can also save and restore portions of the screen:

  Code:
CLS
 
FOR n=1 TO 300
PRINT n;
NEXT n
 
screenBox(2,3,18,11,2,35000)

pause 0


screenBox (2,3,18,11,1,35000)

pause 0

cls

screenBox (3,11,18,11,3,35000)

screenBox (4,9,18,11,3,35000)


pause 0

end

SUB screenBox(x AS UBYTE, y AS UBYTE, width AS UBYTE, height AS UBYTE, mode AS ubyte, address AS uinteger)
 
ASM
   
   push de
   ld d, (ix+15)
   ld e, (ix+14)
   ld (counter),de

   ld a, (IX+13)
   ld (modeflag),a
   pop de
   
     ld b,(IX+5)   
     ld c,(IX+7)   
   
   ld a, c         
   AND 24      
   OR 64      
   ld h, a      
   ld a, c      
   AND 7      
   rra         
   rra         
   rra         
   rra         
   add a, b   
   ld l, a      
 
   ld b, (IX+11)   
   ld c,(IX+9)           
 
   
   resbox_outer_loop:
       XOR a
       push bc                
       push hl                
       ld d, 8                
 

            resbox_mid_loop:
              ld e,l                               
                ld b,c                               
         
               ld a,(modeflag)
               sub 2
               jp z,saveMode
               
               ld a,(modeflag)
               sub 3
               jp z,restoreMode
               
               ld a,0
               clearMode:
               ld (hl),a                        
               inc l                           
               djnz clearMode
               jp goOn
               
            saveMode:
               push de
               ld de, (counter)
               saveBox_inner_loop:
               ld a,(hl)                        
               ld (de),a
               inc l                           
               inc de
               djnz saveBox_inner_loop               
               ld (counter),de
               pop de
               jp goOn
               
            restoreMode:
               push de
               ld de, (counter)
               resbox_inner_loop:
               ld a,(de)                        
               ld (hl),a
               inc l                           
               inc de
               djnz resbox_inner_loop               
               ld (counter),de
               pop de
               
 
          goOn:
    
           ld l,e                            
           inc h                               
         dec d
      
          jp nz, resbox_mid_loop           
    
         pop hl                         
         pop bc                         
   
         ld a, 32                         
         add a, l                      
         ld l, a          
         jp nc, resbox_row_skip    
 
      ld a, 8           
      add a, h      
      ld h, a          

resbox_row_skip:
djnz resbox_outer_loop

END ASM
END SUB

ASM

counter:
   defb 000,000

modeflag:
   defb 000

end asm


It adds 2 new parameters: mode (1=clear, 2=save, 3=restore) and address (where the data will be saved to/restore from)

Cheers!

Return to Documentation

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO