Here's the code for that horizontal line drawer I've been working on:

Code:
xpos .equ appbackupscreen
ypos .equ appbackupscreen+1
len .equ appbackupscreen+2
   call ClrScreen
   ld ix,xpos
   ld (ix),0
   ld (ix+1),0
   ld (ix+2),8
   call HorizLine
   bcall(_GrBufCpy)
   ret
;start of horizontal line routine.
;Inputs:
;x location: xpos
;y location: ypos
;Length: len
;Outputs:
;A line, leftmost pixel on (xpos,ypos), length equal to len.
;Need to call _GrBufCpy to actually display the line.
;Destroys:

HorizLine:
   ld hl,(ypos)
   ld h,0
   add hl,hl
   add hl,hl
   ld d,h
   ld e,l
   add hl,hl
   add hl,de      ;HL=ypos*12
   ld de,(xpos)
   ld a,e         ;A=xpos
   and %00000111  ;A=xpos%8, the bit we need
   srl e
   srl e
   srl e          ;E=xpos//8
   ld d,0
   add hl,de      ;HL=ypos*12+xpos//8, the byte we need
   ld de,(len-1)  ;Gets (len) into D
   add a,d        ;Check to see if can be drawn in 1 byte
   cp 9
   jr nc,HNotInAByte ;a>8
   jr c,HInAByte  ;a<=8
HInAByte:
   sub d          ;Get back the original A
   ld b,d
   ld e,1
HLoop1:
   sla e
   djnz HLoop1
   push af
   ld a,e
   sub 1
   ld e,a
   pop af         ;E-=1
   ;After this operation, E has the lower D bits as 1
   cpl
   add a,9
   sub d
   or a
   jr z,HAIsZero
   ld b,a         ;B=8-A-D
HLoop2:
   sla e
   djnz HLoop2
HAIsZero:
   ld a,e
   ld de,PlotSScreen
   add hl,de
   ld (hl),a
   ret
HNotInAByte:
   ret
   
ClrScreen:
   ;Clears the screen.
sp_save .equ AppBackupScreen
   ld (sp_save),sp
   di
   ld sp,PlotSScreen+768
   ld b,64
   ld hl,0

ClrLoop:
   push hl
   push hl
   push hl
   push hl
   push hl
   push hl
   push hl
   push hl
   push hl
   push hl
   push hl
   push hl
   djnz ClrLoop

   ld sp,(sp_save)
   ei
   bcall(_GrBufCpy)
   ret

Currently it'd draw anything that can be drawn in 1 byte of writes.
About your clear routine, why not just loop over each byte and set it to 0. Something like this

Code:
set_zero:
    ld hl, 768
    ld de, plotsscreen
loop:
    xor a
    ld (de), a
    dec hl ;unfortunately inc and dec dont change flags if used on 16 bit registers
    ld a, h
    or l ; these 2 lines check if hl is 0
    jr loop
; end


Have you learned about ldir yet?

ldir copies over BC amount of bytes from (hl) to (de) incrementing hl and de aswell.

What would happen if perhaps you set the first byte of plotsscreen to 0 and copied over 767 bytes from plotsscreen to plotsscreen+1 ? Not going to provide sample code to see if you can do it yourself.
Tbh the only reason why is because SP is really fast. Yes, it's bad for readability, but it's, well, cool. 😉
And now the routine is done! And I've already refactored, and optimized, the code. Routine is only 154 bytes large. 🙂

Code:
xpos .equ appbackupscreen
ypos .equ appbackupscreen+1
len .equ appbackupscreen+2

   ld bc,767
   ld hl,PlotSScreen
   ld de,PlotSScreen+1
   ld (hl),0
   ldir
   ld ix,xpos
   ld (ix),2
   ld (ix+1),0
   ld (ix+2),5
   call HorizLine
   ld (ix),5
   ld (ix+1),2
   ld (ix+2),10
   call HorizLine
   ld (ix),7
   ld (ix+1),4
   ld (ix+2),10
   call HorizLine
   bcall(_GrBufCpy)
   ret
;start of horizontal line routine.
;Inputs:
;x location: xpos
;y location: ypos
;Length: len
;Outputs:
;A line, leftmost pixel on (xpos,ypos), length equal to len.
;Need to call _GrBufCpy to actually display the line.
;Destroys: all, including (appbackupscreen) to (appbackupscreen+3)

HorizLine:
   ld hl,(ypos)
   ld h,0
   add hl,hl
   add hl,hl
   ld d,h
   ld e,l
   add hl,hl
   add hl,de      ;HL=ypos*12
   ld de,(xpos)
   ld a,e         ;A=xpos
   and %00000111  ;A=xpos%8, the bit we need
   srl e
   srl e
   srl e          ;E=xpos//8
   ld d,0
   add hl,de      ;HL=ypos*12+xpos//8, the byte we need
   ld de,PlotSScreen
   add hl,de
   ld de,(len-1)  ;Gets (len) into D
   add a,d        ;Check to see if can be drawn in 1 byte
   ;cp 17
   ;jr nc,HNotInTwoBytes ;a>16
   cp 8
   jr nc,HNotInAByte ;a>7
   ;If a<=7...
HInAByte:
   sub d          ;Get back the original A
   ld b,d
   ld e,1
HLoop1:
   sla e
   djnz HLoop1
   push af
   ld a,e
   sub 1          ;E-=1
   ld e,a
   pop af
   ;After this operation, E has the lower D bits as 1
   cpl
   add a,9
   sub d
   or a
   jr z,HAIsZero
   ld b,a         ;B=8-A-D
HLoop2:
   sla e
   djnz HLoop2
HAIsZero:
   ld (hl),e
   ret
HNotInAByte:
   ld (len-1),a
   sub d          ;Get back original A
   or a
   jr z,HIf1      ;If A=0
   cpl
   add a,9        ;A=8-A
   ld b,a
   cpl
   add a,d
   ld d,a         ;D=D-A-1
   ld a,1
HLoop3:
   sla a
   djnz HLoop3
   sub 1
   ;After this, the lower B bits of A are set to one.
   ld (hl),a
HIf1:
   ld a,(len-1)   ;Get (len-1) into A
   cp 17
   jr nc,HIf1Cond1
   push de
   ld de,1
   add hl,de      ;HL+=1
   pop de         ;Get D back
   ld a,d
   jr HIf1End
HIf1Cond1:
   ld a,d
   srl a
   srl a
   srl a
   push de
   ld de,1
   ;Loop: just write $FF to (hl) until d is less than 8.
HLoop6:
   add hl,de
   ld (hl),$FF
   sub 1
   jr nz,HLoop6
   add hl,de
   pop de
   ld a,d
   and %00000111
   ld d,a
HIf1End:
   or a
   ld a,$80       ;Flags are unchanged
   jr z,HDIsZero
   ld b,d
HLoop4:
   sra a
   djnz HLoop4
   ;The upper B bits of A are set to one.
HDIsZero:
   ld (hl),a
   ret

I used an LDIR there to save space.
The code's still very buggy, darn. â˜šī¸

Now onto sprites!
Psst: Nibbles game is in the works!
https://ourl.ca/22897 for more details.
Planned features:
12*16 screen. (4*4 pixels to one block)
Yeah, that's about it...

EDIT: After rethinking things, perhaps a guessing game could be easier to code.
  
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 2 of 2
» 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