; Program Name: PCSE Ball ; Author: Christopher Mitchell ; Version: .1 ; Date: February 2013 .nolist ;#include "ti83plus.inc" ;#include "dcs7.inc" ;------------------------------- #define equ .equ #define EQU .equ #define end .end #define END .end userMemC .equ $A60B lfsrseed1 .equ $8000 balls .equ $8001 nballs .equ 10 _cphlde .equ 400Ch ;Banked Call Equates/Macros ;----------------------------------------------- rBR_CALL equ 28h BRT_JUMP0 equ 50h #define bcall(xxxx) rst 28h \ .dw xxxx #define b_call(xxxx) rst 28h \ .dw xxxx #define bjump(xxxx) call 50h \ .dw xxxx .list .org userMemC-2 .db $EF,$69 Init: ld a,r ld (lfsrseed1),a ld a,1 out ($20),a ;set 15MHz ld b,nballs ld hl,balls ld de,8 ;starting x ;ld c,5 ;starting y InitSetupLoop: ld (hl),e ;x inc hl ld (hl),d ;x inc hl push hl call LFSR_PRNG pop hl and $02 dec a ld (hl),a ;x velocity inc hl push hl call LFSR_PRNG pop hl cp 240-16 jr c,InitSetupLoop_XOK and $7f InitSetupLoop_XOK: ld (hl),a ;y inc hl push hl call LFSR_PRNG pop hl and $02 dec a ld (hl),a ;y velocity inc hl push hl ld hl,20 add hl,de pop de ex de,hl ld a,10 add a,c ld c,a djnz InitSetupLoop InitClearScreen: ld hl,$10B8 ; BGR mode, increment order ld a,$03 call SetLCDRegister call FullScreenWindow ld e,$0f ; e holds the upper and lower bytes of some colors we'll paint OuterColorLoop: call FullScreenColor ;takes color in e ld a,$10 add a,e ld e,a cp $0f jr nz,OuterColorLoop BallTime: ld b,nballs ld hl,balls BallTimeLoop: push hl ld e,(hl) inc hl ld d,(hl) inc hl push hl ex de,hl ld a,$52 ;"Vertical" = X for us call SetLCDRegister ld a,$21 ;"Vertical" = X for us call SetLCDRegister push hl ld de,15 add hl,de ld a,$53 ;"Vertical" = X for us call SetLCDRegister pop hl pop de ld a,(de) ld e,a ld d,0 cp $ff jr nz,BallTimeLoop_CheckReverse ld d,$ff BallTimeLoop_CheckReverse: add hl,de pop de ex de,hl ld (hl),e inc hl ld (hl),d inc hl push hl ld hl,320-16 or a ;cphlde sbc hl,de add hl,de jr z,BallTimeLoop_DoXFlip ld a,e or d jr nz,BallTimeLoop_NoXFlip BallTimeLoop_DoXFlip: pop hl ld c,(hl) xor a sub c ld (hl),a push hl BallTimeLoop_NoXFlip: pop hl inc hl push hl ld e,(hl) inc hl push hl ex de,hl ld h,0 ; ld a,$50 ;"Horizontal" = Y for us ; call SetLCDRegister ld a,$20 ;"Horizontal" = Y for us call SetLCDRegister ; push hl ; ld de,15 ; add hl,de ; ld a,$51 ;"Horizontal" = Y for us ; call SetLCDRegister ; pop hl pop de ld a,(de) add a,l pop de ex de,hl ld (hl),a inc hl push hl cp 240-16 jr z,BallTimeLoop_DoYFlip or a jr nz,BallTimeLoop_NoYFlip BallTimeLoop_DoYFlip: pop hl ld c,(hl) xor a sub c ld (hl),a push hl BallTimeLoop_NoYFlip: pop hl inc hl push hl ld a,$22 ld c,$10 \ out (c),0 \ out (c),a push bc ld bc,$0011 ; 16*16 ld hl,RedBall BallRender1: outi jp nz,BallRender1 BallRender2: outi jp nz,BallRender2 pop bc pop hl dec b ld a,b jp nz,BallTimeLoop ld a,$ff out (1),a nop \ nop ld a,$fd out (1),a nop \ nop in a,(1) inc a jp z,BallTime call FullScreenWindow ld e,$ff call FullScreenColor ld hl,$1038 ; BGR mode, increment order ld a,$03 call SetLCDRegister xor a out ($20),a ;set 6MHz bcall(54F4h) ;redraw the status area bcall(454Fh) ;homeup ld hl,credit_text bcall(4501h) ;puts bcall(4525h) ;newline ret FullScreenWindow: ld hl,$0000 ld a,$50 call SetLCDRegister ;Horizontal Start ld hl,239 inc a ;ld a,$51 call SetLCDRegister ;Horizontal End ld hl,$0000 inc a ;ld a,$52 call SetLCDRegister ;Vertical Start ld hl,319 inc a ;ld a,$53 call SetLCDRegister ;Vertical End ld hl,0 ld a,$20 call SetLCDRegister ;Y pos inc a ;ld a,$21 ;jp SetLCDRegister ;X pos SetLCDRegister: out ($10),a \ out ($10),a ld c,$11 out (c),h out (c),l ret FullScreenColor: ;takes color in e ld hl,0 ld a,$20 call SetLCDRegister ;Y pos ld a,$21 call SetLCDRegister ;X pos ld a,$22 out ($10),a \ out ($10),a ld c,(320*240/2)/256 ClearLoop: ld b,0 InnerClearLoop: ld a,e out ($11),a \ out ($11),a out ($11),a \ out ($11),a djnz InnerClearLoop dec c jr nz,InnerClearLoop ret LFSR_PRNG: ld hl,lfsrseed1 ld a,(hl) rrca ld (hl),a jp nc,+_ xor %00111000 ld (hl),a _: set 6,a ret credit_text: .db "By Kerm Martian",0 RedBall: .db $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff .db $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff .db $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$00,$00,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff .db $ff,$ff,$ff,$ff,$ff,$ff,$00,$00,$e8,$e4,$ff,$ff,$ff,$ff,$ff,$ff,$e8,$e4,$e8,$e4,$e8,$e4,$00,$00,$00,$00,$ff,$ff,$ff,$ff,$ff,$ff .db $ff,$ff,$ff,$ff,$00,$00,$e8,$e4,$ff,$ff,$ff,$ff,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$00,$00,$ff,$ff,$ff,$ff .db $ff,$ff,$00,$00,$e8,$e4,$e8,$e4,$ff,$ff,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$00,$00,$ff,$ff,$ff,$ff .db $ff,$ff,$00,$00,$e8,$e4,$e8,$e4,$ff,$ff,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$88,$02,$00,$00,$ff,$ff .db $ff,$ff,$00,$00,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$88,$02,$00,$00,$ff,$ff .db $ff,$ff,$00,$00,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$88,$02,$88,$02,$00,$00,$ff,$ff .db $ff,$ff,$00,$00,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$88,$02,$88,$02,$88,$02,$00,$00,$ff,$ff .db $ff,$ff,$00,$00,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$e8,$e4,$88,$02,$88,$02,$88,$02,$00,$00,$ff,$ff,$ff,$ff .db $ff,$ff,$ff,$ff,$ff,$ff,$00,$00,$e8,$e4,$e8,$e4,$e8,$e4,$88,$02,$88,$02,$88,$02,$88,$02,$88,$02,$00,$00,$ff,$ff,$ff,$ff,$ff,$ff .db $ff,$ff,$ff,$ff,$ff,$ff,$00,$00,$88,$02,$88,$02,$88,$02,$88,$02,$88,$02,$88,$02,$88,$02,$00,$00,$00,$00,$ff,$ff,$ff,$ff,$ff,$ff .db $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$00,$00,$00,$00,$88,$02,$88,$02,$88,$02,$88,$02,$00,$00,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff .db $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$00,$00,$00,$00,$00,$00,$00,$00,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff .db $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff