I was messing around with the DCS GUI API, and I started to want to make a Tic-Tac-Toe program that would run in a window within DCS.
My first step was to write a Tic-Tac-Toe program, because I've never written one before. It wouldn't be hard.
Then I made it grayscale. Because I wanted to.
So, I wrote some code and made some graphics, and tested it, but it's not working like it should.
Here's the code:
Code:
It crashes when it runs EraseGray, I'm certain of it.
EraseGray] is a subroutine that is supposed to erase certain parts of the temporary graphics, because I wanted the spots that were taken to not be gray. It is designed to reset the bits in the temporary graphics that are to be turned off. The reason it involves 3 extra subroutines is because different bits need to be reset for each column. It also attempts to get the offset to the temporary data by factoring in cursorX and cursorY.
TTT_Gray:
TTT_Gray2:
Both are 32*32.
Could anyone help me debug it? I can't get it to work...
My first step was to write a Tic-Tac-Toe program, because I've never written one before. It wouldn't be hard.
Then I made it grayscale. Because I wanted to.
So, I wrote some code and made some graphics, and tested it, but it's not working like it should.
Here's the code:
Code:
.nolist
#include "ion.inc"
#include "ti83plus.inc"
.list
.org progstart-2
.db $BB,$6D
xor a ;should be "ret" if using Ion libs
jr nc,begin
.db "Title",0
begin:
ld hl,ttt_gray
ld de,ttt_temp1
ld bc,ttt_gray-ttt_temp1
ldir
b_call(_grbufclr)
xor a
ld l,a
ld ix,ttt_temp1
ld c,4
ld b,32
call ilsprite
call fastcopy
startGame:
wait1:
xor a
ld l,a
ld ix,ttt_temp2
ld c,4
ld b,32
call ilsprite
call fastcopy
b_call(_getcsc)
or a
jr z,wait1
xor a
ld (cursorX),a
ld (cursorY),a
call erasegray
b_call(_grbufclr)
xor a
ld l,a
ld ix,ttt_temp1
ld c,4
ld b,32
call ilsprite
wait2:
xor a
ld l,a
ld ix,ttt_temp2
ld c,4
ld b,32
call ilsprite
call fastcopy
b_call(_getcsc)
or a
jr z,wait2
ret
eraseGray:
ld a,(cursorY)
ld l,a
ld h,0
ld d,h
ld e,l
add hl,hl
add hl,hl
add hl,de
add hl,hl
add hl,de
add hl,hl
add hl,hl
ld de,ttt_temp1
add hl,de
ld a,(cursorX)
or a
jp z,egFirst
cp 1
jp z,egSecond
egThird:
ld b,2
eg3Loop1:
push bc
ld b,10
eg3Loop2:
ld a,(hl)
and %11111100
ld (hl),a
inc hl
ld a,(hl)
and %00000000
ld (hl),a
inc hl
inc hl
inc hl
djnz eg3Loop2
pop bc
ld de,88
add hl,de
djnz eg3Loop2
ret
egSecond:
ld b,2
eg2Loop1:
push bc
ld b,10
eg2Loop2:
ld a,(hl)
and %11100000
ld (hl),a
inc hl
ld a,(hl)
and %00000111
ld (hl),a
inc hl
inc hl
inc hl
djnz eg2Loop2
pop bc
ld de,88
add hl,de
djnz eg2Loop2
ret
egFirst:
ld b,2
eg1Loop1:
push bc
ld b,10
eg1Loop2:
ld a,(hl)
and %00000000
ld (hl),a
inc hl
ld a,(hl)
and %00111111
ld (hl),a
inc hl
inc hl
inc hl
djnz eg1Loop2
pop bc
ld de,88
add hl,de
djnz eg1Loop2
ret
;================== Functions exactly like iputsprite ==================
isprite:
ld e,l
ld h,$00
ld d,h
add hl,de
add hl,de
add hl,hl
add hl,hl ;Find the Y displacement offset
ld e,a
and $07 ;Find the bit number
ld c,a
srl e
srl e
srl e
add hl,de ;Find the X displacement offset
ld de,plotsscreen
add hl,de
ispriteLoop1:
ld d,(ix) ;loads image byte into D
ld e,$00
ld a,c
or a
jr z,ispriteSkip1
ispriteLoop2:
srl d ;rotate to give out smooth moving
rr e
dec a
jr nz,ispriteLoop2
ispriteSkip1:
ld a,(hl)
xor d
ld (hl),a
inc hl
ld a,(hl)
xor e
ld (hl),a ;copy to buffer using XOR logic
ld de,$0B
add hl,de
inc ix ;Set for next byte of image
djnz ispriteLoop1
ret
fastCopy:
di
exx
ld a,$80 ; 7
out ($10),a ; 11
out ($20),a ; 11 Sets first two bits to zero to slow calc down if 83pse/84xx
ld hl,plotsscreen-12-(-(768)+1) ; 10
ld a,$20 ; 7
ld c,a ; 4
inc hl ; 6 waste
dec hl ; 6 waste
fastCopyAgain:
ld b,64 ; 7
inc c ; 4
ld de,-(12*64)+1 ; 10
out ($10),a ; 11
add hl,de ; 11
ld de,10 ; 10
fastCopyLoop:
add hl,de ; 11
inc hl ; 6 waste
inc hl ; 6 waste
inc de ; 6
ld a,(hl) ; 7
out ($11),a ; 11
dec de ; 6
djnz fastCopyLoop ; 13/8
ld a,c ; 4
cp $2B+1 ; 7
jr nz,fastCopyAgain ; 10/1
exx
ret
;-----------Ion Large Sprite-----------
;Input: ix->sprite
; a=x
; l=y
; b=height (in pixels)
; c=width (in bytes, e.g. 2 would be 16)
;Output: nothing
; All registers are destroyed except bc', de', hl'
ilsprite:
di
ex af,af'
ld a,c
push af
ex af,af'
ld e,l
ld h,$00
ld d,h
add hl,de
add hl,de
add hl,hl
add hl,hl
ld e,a
and $07
ld c,a
srl e
srl e
srl e
add hl,de
ld de,gbuf
add hl,de
ilspriteLoop1:
push hl
ilspriteLoop2:
ld d,(ix)
ld e,$00
ld a,c
or a
jr z,ilspriteSkip1
ilspriteLoop3:
srl d
rr e
dec a
jr nz,ilspriteLoop3
ilspriteSkip1:
ld a,(hl)
xor d
ld (hl),a
inc hl
ld a,(hl)
xor e
ld (hl),a
inc ix
ex af,af'
dec a
push af
ex af,af'
pop af
jr nz,ilspriteLoop2
pop hl
pop af
push af
ex af,af'
ld de,$0C
add hl,de
djnz ilspriteLoop1
pop af
ret
cursorX: .db 0
cursorY: .db 0
ttt_temp2:
.db $FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF
.db $FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF
.db $FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF,$00,$00,$00,$00,$FF,$DF,$FB,$FF
.db $FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF
.db $FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF
.db $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$DF,$FB,$FF,$00,$00,$00,$00,$FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF
.db $FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF
.db $FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF,$FF,$DF,$FB,$FF
ttt_gray:
.db $AA,$B5,$56,$AA,$55,$6A,$AD,$55,$AA,$B5,$56,$AA,$55,$6A,$AD,$55
.db $AA,$B5,$56,$AA,$55,$6A,$AD,$55,$AA,$B5,$56,$AA,$55,$6A,$AD,$55
.db $AA,$B5,$56,$AA,$55,$6A,$AD,$55,$FF,$FF,$FF,$FF,$AA,$B5,$56,$AA
.db $55,$6A,$AD,$55,$AA,$B5,$56,$AA,$55,$6A,$AD,$55,$AA,$B5,$56,$AA
.db $55,$6A,$AD,$55,$AA,$B5,$56,$AA,$55,$6A,$AD,$55,$AA,$B5,$56,$AA
.db $55,$6A,$AD,$55,$FF,$FF,$FF,$FF,$AA,$B5,$56,$AA,$55,$6A,$AD,$55
.db $AA,$B5,$56,$AA,$55,$6A,$AD,$55,$AA,$B5,$56,$AA,$55,$6A,$AD,$55
.db $AA,$B5,$56,$AA,$55,$6A,$AD,$55,$AA,$B5,$56,$AA,$55,$6A,$AD,$55
ttt_mat:
.db 0,0,0
.db 0,0,0
.db 0,0,0
spr_X:
.db %10000001
.db %01000010
.db %00100100
.db %00011000
.db %00011000
.db %00100100
.db %01000010
.db %10000001
spr_O:
.db %00111100
.db %01000010
.db %10000001
.db %10000001
.db %10000001
.db %10000001
.db %01000010
.db %00111100
spr_blank:
.db 0,0,0,0,0,0,0,0,0
.end
.end
EraseGray] is a subroutine that is supposed to erase certain parts of the temporary graphics, because I wanted the spots that were taken to not be gray. It is designed to reset the bits in the temporary graphics that are to be turned off. The reason it involves 3 extra subroutines is because different bits need to be reset for each column. It also attempts to get the offset to the temporary data by factoring in cursorX and cursorY.
TTT_Gray:
TTT_Gray2:
Both are 32*32.
Could anyone help me debug it? I can't get it to work...