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:
.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 $FF,$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_temp1:
   .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_gray2:
   .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 $FF,$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
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...
If you want an interesting tic tac toe game, not just the boring kind, check this out: http://www.puzzlesgames.co.uk/
Why are you including Ion routines instead of simply calling them? Did you change them at all? I'm trying to see if there's a problem in eraseGray right now.
I'm working in nostub right now--it's just Ion compatible. This way, I can edit the routines to do whatever I want them to.

But other than that, I honestly don't know Neutral .
In each of three loops, you pop bc then djnz, but you never repush bc. That means you'll be popping something you never pushed. Obviously you can't push bc before the djnz, so you'll have to figure out something else. See what I mean?
Ahhh...I was jr'ing to the wrong label. Thanks Kerm!

EDIT: I've already gotten the offset, and I added 40 bytes to hl, which was originally pointing to ttt_temp1. Would I just add 88 to get the same offset to ttt_temp2? Both are 128 bytes, a 32*32 sprite.
  
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