Author |
Message |
|
JacobdeHaan
Member
Joined: 10 Jul 2003 Posts: 165
|
Posted: 14 Nov 2003 03:03:55 am Post subject: |
|
|
Well, I'm trying to get this program to count up all the pixels currently on the screen. I'm clearing the screen, then drawing a sprite to the screen and trying to get it to count up, but it isn't working. I realize my code is probably unoptimized, but all I want now is to get it to work.
Here you go:
Code: #define TI83P
.nolist
#include "ion.inc"
#ifdef TI83P
.org ProgStart - 2
.db $BB, $6D
#else ; Basic Header
.org progstart ; /
#endif ; /
ret ; /
jr nc,init ; /
.db "Dots",0 ; Name displayed in ION
init:
ld hl, $0000
ld (dots), hl
bcall(_grbufclr)
ld b,8
ld l, $00
xor a
ld ix, smith
call ionPutSprite
call ionfastcopy
ld hl, grbuf
loop:
;768
ld a, (hl)
bit 7, a
jr z, off ;if off, then...
ld a, (dots);else...
inc a
ld (dots), a
off:
inc hl
ld a,h
cp $96
jr nz, loop
ld a,l
cp $41
jr nz, loop
ld hl, $0000
ld hl, (dots)
bcall(_disphl)
bcall(_getkey)
ret ;Exit program
smith:
.DB %10111101
.DB %11111111
.DB %00111100
.DB %10100101
.DB %01000010
.DB %01000010
.DB %00111100
.DB %00100100
dots:
.db $00
.end ;End of code
|
|
Back to top |
|
|
sgm
Calc Guru
Joined: 04 Sep 2003 Posts: 1265
|
Posted: 14 Nov 2003 08:53:25 pm Post subject: |
|
|
I optimized it anyway. Maybe that fixed the bug.
Code: init:
sbc hl,hl ;ld hl,$0000
ld (dots),hl
bcall(_grbufclr)
ld b,8
xor a ;ld l,$00
ld l, a ;xor a
ld ix, smith
call ionPutSprite
call ionfastcopy
ld de, grbuf ;ld hl, grbuf
ld hl, dots ;
ld bc,768 ;
loop:
;768
ld a, (de)
and a ;bit 7, a
jp p, off ;jr z, off
;else
inc (hl) ;ld a,(dots)
;inc a
;ld (dots),a
off:
inc de ;inc hl
dec bc
ld a,b
or c
jr nz, loop
; What you had will break on the TI-83 because the graph
; buffer is in a different location.
; ld a,h
; cp $96
; jr nz, loop
; ld a,l
; cp $41
; jr nz, loop
; I don't understand why you would zero HL only to load it with
; (dots) immediately afterwards. And anyway, isn't (dots)
; a byte variable?
ld hl,(dots)
bcall(_disphl)
bcall(_getkey)
ret
smith:
.DB %10111101
.DB %11111111
.DB %00111100
.DB %10100101
.DB %01000010
.DB %01000010
.DB %00111100
.DB %00100100
dots:
.db $00
Last edited by Guest on 14 Nov 2003 08:57:27 pm; edited 1 time in total |
|
Back to top |
|
|
JacobdeHaan
Member
Joined: 10 Jul 2003 Posts: 165
|
Posted: 15 Nov 2003 12:09:54 am Post subject: |
|
|
Thanks a lot, there a quite a few tricks in there that I will be able to learn from.
Fortunantely, it runs fine, just like my version.
Unfortunantely, it runs fine, just like my version.
Does my logic make sense to you, cause when I run the current version, _dispHL is giving me 3, not 32. |
|
Back to top |
|
|
JacobdeHaan
Member
Joined: 10 Jul 2003 Posts: 165
|
Posted: 15 Nov 2003 12:41:45 am Post subject: |
|
|
All right!!!!
Thanks a ton Σ. You didn't fix the bug, but you gave me the encouragement to finish this. Stupid as I am, when I increased my reading spot on the graph buffer, I though it would only increase by a bit, but instead it goes by a byte! So when I was reading only the first bit, I was ignoring the last seven, so I just edited it to do "bit" on each (bit 7, a; bit 6,a; bit 5, a...) and it now works. Because you know so much about optimizing, could you do that for my program right know?
Here it is:
Code: init:
sbc hl,hl ;ld hl,$0000
ld (dots),hl
bcall(_grbufclr)
ld b,8
xor a ;ld l,$00
ld l, a ;xor a
ld ix, smith
call ionPutSprite
call ionfastcopy
ld de, grbuf ;ld hl, grbuf
ld hl, dots ;
ld bc,768 ;
loop:
;768
ld a, (de)
bit 7, a
call nz, inchl
bit 6, a
call nz, inchl
bit 5, a
call nz, inchl
bit 4, a
call nz, inchl
bit 3, a
call nz, inchl
bit 2, a
call nz, inchl
bit 1, a
call nz, inchl
bit 0, a
call nz, inchl
off:
inc de ;inc hl
dec bc
ld a,b
or c
jr nz, loop
; What you had will break on the TI-83 because the graph
; buffer is in a different location.
; ld a,h
; cp $96
; jr nz, loop
; ld a,l
; cp $41
; jr nz, loop
; I don't understand why you would zero HL only to load it with
; (dots) immediately afterwards. And anyway, isn't (dots)
; a byte variable?
;sorry, I just thought I had to "clear out" hl before displaying it in
;case anything was already in it
ld hl,(dots)
bcall(_disphl)
bcall(_getkey)
ret
inchl:
inc (hl)
ret
smith:
.DB %10111101
.DB %11111111
.DB %00111100
.DB %10100101
.DB %01000010
.DB %01000010
.DB %00111100
.DB %00100100
dots:
.db $00
|
|
Back to top |
|
|
sgm
Calc Guru
Joined: 04 Sep 2003 Posts: 1265
|
Posted: 15 Nov 2003 02:39:48 am Post subject: |
|
|
Trust me, the shift and rotate instructions are the monochrome graphics programmer's best friends.
Oh yeah, you should not do LD HL,(dots), since this will put (dots) into L and (dots+1) into H, which will skew the results of DispHL. What should be done is
;Smallest code (5 bytes, ~27 clocks)
LD HL,(dots)
LD H,0
;Fastest code (6 bytes, ~24 clocks
LD A,(code)
LD L,A
LD H,0
Last edited by Guest on 15 Nov 2003 02:40:46 am; edited 1 time in total |
|
Back to top |
|
|
Justin W. Shattered Silence
Advanced Member
Joined: 24 May 2003 Posts: 429
|
Posted: 15 Nov 2003 01:19:20 pm Post subject: |
|
|
Actually, sigma if there are less than 255 pixels on, which is the case in this small program, he could simply
;16cc and 4 bytes
ld hl,dots
inc (hl)
Last edited by Guest on 15 Nov 2003 01:21:11 pm; edited 1 time in total |
|
Back to top |
|
|
sgm
Calc Guru
Joined: 04 Sep 2003 Posts: 1265
|
Posted: 15 Nov 2003 08:03:38 pm Post subject: |
|
|
Er...
Me wrote: Oh yeah, you should not do LD HL,(dots), since this will put (dots) into L and (dots+1) into H, which will skew the results of DispHL. What should be done is
Last edited by Guest on 15 Nov 2003 08:04:23 pm; edited 1 time in total |
|
Back to top |
|
|
Justin W. Shattered Silence
Advanced Member
Joined: 24 May 2003 Posts: 429
|
Posted: 15 Nov 2003 11:06:50 pm Post subject: |
|
|
Sorry my bad. I wasn't paying attention to what line of code you were referring to. |
|
Back to top |
|
|
JacobdeHaan
Member
Joined: 10 Jul 2003 Posts: 165
|
Posted: 19 Nov 2003 07:42:22 pm Post subject: |
|
|
So, can anyone make this routine run any faster, or is it as optimized as it will get? |
|
Back to top |
|
|
sgm
Calc Guru
Joined: 04 Sep 2003 Posts: 1265
|
Posted: 20 Nov 2003 12:56:26 pm Post subject: |
|
|
Does it even work yet? |
|
Back to top |
|
|
tr1p1ea
Elite
Joined: 03 Aug 2003 Posts: 870
|
Posted: 20 Nov 2003 03:38:46 pm Post subject: |
|
|
Here is a version that 'should' work. It isnt optimised as i wanted the method to be clear. It is basically the same method as above but it will count ALL of the pixels on the screen, save the result to a 16-bit variable and of course display the result:
Code: .nolist
#include "ion.inc"
.list
#ifdef TI83P
.org progstart-2
.db $BB,$6D
#else
.org progstart
#endif
ret
jr nc,begin
.db "PixelCount",0
begin:
Init:
ld hl,0
ld (Dots),hl
Main:
bcall(_grBufClr)
call DrawSpr
call CountPoints
call DisplayResult
bcall(_getkey)
Quit:
bcall(_clrlcdfull)
ret
DrawSpr:
ld b,8
ld l,28
ld a,44
ld ix,Smith
call ionPutSprite
call ionFastCopy
ret
CountPoints:
ld bc,0
ld de,gBuf
CountLoop:
ld a,(de)
bit 7,a
call nz,IncCounter
bit 6,a
call nz,IncCounter
bit 5,a
call nz,IncCounter
bit 4,a
call nz,IncCounter
bit 3,a
call nz,IncCounter
bit 2,a
call nz,IncCounter
bit 1,a
call nz,IncCounter
bit 0,a
call nz,IncCounter
ld hl,768
sbc hl,bc
ret z
inc bc
inc de
jp CountLoop
IncCounter:
ld hl,(Dots)
inc hl
ld (Dots),hl
ret
DisplayResult:
ld hl,(0*256)+79
ld (pencol),hl
ld hl,(Dots)
bcall(_setxxxxop2)
bcall(_op2toop1)
ld a,4
bcall(_dispop1a)
ret
Smith:
.DB %10111101
.DB %11111111
.DB %00111100
.DB %10100101
.DB %01000010
.DB %01000010
.DB %00111100
.DB %00100100
Dots:
.dw $00
.end
END
Enjoy .
Last edited by Guest on 20 Nov 2003 06:05:53 pm; edited 1 time in total |
|
Back to top |
|
|
JacobdeHaan
Member
Joined: 10 Jul 2003 Posts: 165
|
Posted: 20 Nov 2003 08:44:14 pm Post subject: |
|
|
sigma wrote: Does it even work yet?
Yes. My game using it will be released this weekend, when I can get the menu and high scores working. |
|
Back to top |
|
|
|