[A83] GreyScale routine, I think I got it ^_^


[Prev][Next][Index][Thread]

[A83] GreyScale routine, I think I got it ^_^




Ok, After reading Tijl Coosemans idea about every other pixel displaying, I 
got to tinkering with fastcopy, and came up with this.  Just a warning, when 
i tried it on virtual TI it looked bad, but on my calc it looked fine, maybe 
it's because i have old batteries, but this is the functions i came up with, 
if any of you guys have a suggestion, or some way to speed it up, i would 
like to hear it.  here we go:

;greyscale fast copy
;heavily based off of ION fastCopy.
;Call this, then call fastCopy2 later in the program.
;Virtual TI has it so it doesn't look correct, but as far as i've tested, 
with low energy, their isn't any lines that you can see(tested on my own 
ti-83, looked fine.)  Also, it uses up all of the saferam, I've tried making 
some local area for it, but it bloated it alot, and i decided that this might 
just work anyways.

fastCopyG:
    di                  ; 4
    ld  a,$80               ; 7
    out ($10),a             ; 11
    ld  hl,gbuf-12-(-(12*64)+1)     ; 10
    exx                 ; 4
    ld  hl,SafeRam1-12-(-(12*64)+1) ; 10
    exx                 ; 4
    ld  a,$20               ; 7
    ld  c,a             ; 4
fastCopyAgainG:
    ld  b,64                ; 7
    inc c               ; 4
    ld  de,-(12*64)+1           ; 10
    out ($10),a             ; 11
    add hl,de               ; 11
    exx                 ; 4
    ld  de,-(12*64)+1           ; 10
    add hl,de               ; 11
    ld  de,10               ; 10
    exx                 ; 4
    ld  de,10               ; 10
fastCopyLoopG:
    add hl,de               ; 11
    inc hl              ; 6
    inc hl              ; 6
    ld  a,(hl)              ; 7
    exx                 ; 4
    ld b,%10101010              ; 7  I and these 2 together, then add the 2 
resulting
    and b                   ; 4  numbers and that is what i display ^_^
    ld c,a                  ; 4
    add hl,de               ; 11
    inc hl              ; 6
    inc hl              ; 6
    ld  a,(hl)              ; 7
    ld b,%01010101              ; 7
    and b                   ; 4
    add a,c                 ; 4
    exx                 ; 4
    out ($11),a             ; 11
    djnz    fastCopyLoopG           ; 13/8
    ld  a,c             ; 4
    cp  $2B+1               ; 7
    jr  nz,fastCopyAgainG       ; 10/1
    ret                 ; 10

fastCopy2:
    di
    ld  a,$80               ; 7
    out ($10),a             ; 11
    ld  hl,SafeRam1-12-(-(12*64)+1) ; 10
    exx                 ; 4
    ld  hl,gbuf-12-(-(12*64)+1)     ; 10
    exx                 ; 4
    ld  a,$20               ; 7
    ld  c,a             ; 4
    jp fastCopyAgain1           ; 10

You can see that i have 2 calls, they basically just flips the 2 pictures 
around.  But i've tried it on my ti-83, using a version of Asm guru's mouse 
moving program(i'll copy and paste it later on) and it looked rather nice, a 
nice 3 scale grey scale.  So, if anyone can help me improve on it, i would 
like too see how, and if anyone uses it in a game(I doubt people will, but 
there goes my self confidence) please give me credit ^_^.  Ok, here is my 
little sample program, and i would like to hear how well it worked on peoples 
calcs(i made the greyscale routines in a file called greys.asm):

#define DefaultXSpriteHeight 8    ; This is the default for the sprite height
#define No_Mod_X

    .nolist
    #include "ion.inc"
    #DEFINE mse_x SafeRam2
    #DEFINE mse_y SafeRam2+1

    .list   

#ifdef TI83P
    .org progstart-2
    .db $BB,$6D
#else       
    .org progstart
#endif
    xor a   
    jr nc,Start
    .db "Sprite demo",0

Start:
         ld a,10        ;Initial X & Y coords of mouse.
         ld (mse_x),a   
         ld a,10
         ld (mse_y),a
         jp moveloop

moveloop:
        call putmse         ;Call putmse
getky:              ;routine getkey
     call FastCopy1
         ld a,0ffh
         out (1),a
         ld a,0feh
         out (1),a
         in a,(1)
         cp 253         ;If key Left. NOTE: I didn't bother
         jp z,left      ;Goto Left       with key equates.
         cp 251         ;If key right...
         jp z,right         ;Goto Right
         cp 254         ;If key Up...
         jp z,up        ;Goto up
         cp 247         ;If key down...

         jp z,down      ;Goto Down
         ld a,0ffh
         out (1),a 
         ld a,0fdh
         out (1),a
         in a,(1)
         cp 191         ;If the key clear...
         jp z,quit      ;...quit.
     call FastCopy2
         jp getky       ;Repeat.

left:
     call FastCopy2
         call putmse
         ld a,(mse_x)   ;Load XCoord Variable into A
         dec a      ;Decrease A
         ld (mse_x),a   ;Load back into mse_x
         jp moveloop    ;goto moveloop
right:
     call FastCopy2
         call putmse
         ld a,(mse_x)   ;Load XCoord Variable into A
         inc a      ;Increase A
         ld (mse_x),a   ;Load back into mse_x
         jp moveloop    ;goto moveloop
down:          
     call FastCopy2
         call putmse
         ld a,(mse_y)   ;Load YCoord Variable into A
         dec a      ;Decrease A
         ld (mse_y),a   ;Load back into mse_y
         jp moveloop    ;goto moveloop
up: 
     call FastCopy2
         call putmse
         ld a,(mse_y)   ;Load YCoord Variable into A
         inc a      ;Increase A

         ld (mse_y),a   ;Load back into mse_y
         jp moveloop    ;goto moveloop
putmse:
         ld a,(mse_x)
         ld b,a 
         ld a,(mse_y)
     ld c,a
         ld hl,mouse    ;Load sprite name to bc
         call PutSprClpXOR
     ld hl,PLOTSSCREEN
     ld de,SafeRam1
     ld bc,768
     ldir
         ld a,(mse_x)
         ld b,a 
         ld a,(mse_y)
     ld c,a
         ld hl,mouse2
         call PutSprClpXOR
         ret

quit:
         ret

mouse:      ; Here is the sprite for the mouse.  0=off, 1=on.
    .db %01000000

    .db %01100000
    .db %01110000
    .db %01111000
    .db %01111100
    .db %01111000
    .db %01111100
    .db %01011000

mouse2:     ; here we are coloring the parts we want to be shaded since we 
are using xor, and this will turn it off
    .db %00000000
    .db %00000000
    .db %00100000
    .db %00110000
    .db %00111000
    .db %00110000
    .db %00011000
    .db %00000000


.INCLUDE SPR21X.INC
.Include greys.asm
.END
end