View difference between Paste ID: xFriqcbC and 9HMtZ1pq
SHOW: | | - or go back to the newest paste.
1
; Compile this with:
2
;       spasm <blah>.z80 <blah>.8xp -I path/to/Z80-Optimized-Routines
3
; Z80-Optimized-Routines can be found at https://github.com/Zeda/Z80-Optimized-Routines
4
;
5
6
;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
7
; Define some vars
8
;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
9
#define spritetmp   8000h   ; needed for the bigsprite routine. 8000h has 256 bytes of scrap ram, we use 4
10
#define db .db              ; syntax comaptibility
11
#define dw .dw              ; syntax comaptibility
12
plotSScreen = 9340h         ; a.k.a. the graph screen
13
gbuf        = plotSScreen   ; using plotSScreen as our gbuf
14
_GetCSC     = 4018h         ; TI-OS bcall
15
coords      = 8004h         ;we'll store our coords here
16
17
;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
18
; TI Program header
19
;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
20
.db $BB, $6D
21
.org $9D95
22
23-
    di      ; don't let the OS interfere
23+
    di      ; don't let the OS interrupts interfere
24
25
;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
26
; set up the key port. Reset the low bit to poll for arrows and next bit for
27
; Enter through Clear
28
;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
29
    ld a,%11111100
30
    out (1),a
31
32
;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
33
; clear the gbuf
34
;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
35
    ld hl,gbuf
36
    xor a       ; shortcut to set A to 0
37
    ld b,a      ; now B is 0, but because we are DJNZing, this is basically 256
38
clr_loop:
39
    ld (hl),a
40
    inc hl
41
    ld (hl),a
42
    inc hl
43
    ld (hl),a
44
    inc hl
45
    djnz clr_loop
46
47
    ; init our coords
48
    ; note that B is already 0
49
    ld c,b
50
51
draw_sprite:
52
    ld (coords),bc
53
    ; we'll draw the sprite XORed, copy the buffer to the LCD, then re-XOR it
54
    ; XORing twice basically does nothing to the screen, but by displaying
55
    ; after the first XOR, the LCD shows the sprite.
56
    ld hl, 0808h    ; (H,L) = (height, width)
57
    ld de,sprite    ; pointer to the sprite
58
    call bigsprite_XOR
59
60
    call gbuf_to_lcd_6MHz   ; show the screen before we remove the sprite
61-
    call getKey
61+
62-
    or a    ; shortcut to check if A is 0
62+
63
    ld hl, 0808h    ; (H,L) = (height, width)
64-
    cp 15   ; clear button
64+
65
    call bigsprite_XOR
66-
    cp 5    ; arrows are 1-4, so make sure it isn't bigger then 4
66+
67-
    jr nc,main_loop
67+
68
    ; read from the key port
69-
    ld bc,(coords)  ; restore coords
69+
    in a,(1)
70
    inc a   ; no key presses ==> 0xFF, adding 1 makes it 0 and sets the z flag
71-
    dec a   ; down = 1, so this would set it to 0
71+
72-
    jr z,move_down
72+
    dec a
73-
    dec a   ; left = 2, so this would set it to 0
73+
74-
    jr z,move_left
74+
    bit 6,a ; check if clear is pressed
75-
    dec a   ; right = 3, so this would set it to 0
75+
76-
    jr z,move_right
76+
77-
    dec a   ; up = 0, so this would set it to 0
77+
78-
    ; jr z,move_right
78+
79
    ; We'll need A, so store it in H
80-
    or c    ; make sure C isn't 0. A is already 0, so this is a cheat
80+
    rra
81
    ld h,a
82
    call nc,move_down
83
    rr h
84
    call nc,move_left
85
    rr h
86
    call nc,move_right
87
    rr h
88
    call nc,move_up
89
    jr draw_sprite
90
91
move_up:
92
    ld a,c
93
    or a    ; make sure C isn't 0
94
    ret z
95
    dec c
96
    ret
97
98
move_down:
99
    ld a,c
100-
    or b    ; make sure B isn't 0. A is already 0, so this is a cheat
100+
101
    ret z
102
    inc c
103
    ret
104
105
move_right:
106
    ld a,b
107
    cp 88
108
    ret z
109
    inc b
110
    ret
111
112
move_left:
113
    ld a,b
114
    or b
115
    ret z
116
    dec b
117
    ret
118
119
;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
120
; This is a common subroutine that is required for the bigsprite routines.
121
;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
122
call_ix:
123
    jp (ix)
124
125
;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
126
; Our sprite data
127
;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
128
sprite:
129
    .db %00111100
130
    .db %01000010
131
    .db %10000001
132
    .db %10000001
133
    .db %10000001
134
    .db %10000001
135
    .db %01000010
136
    .db %00111100
137
138
;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
139
; Includes
140
;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
141
#include "ti8x/gfx/bigsprite_XOR.z80"
142
#include "ti8x/gfx/gbuf_to_lcd_6MHz.z80"
143
#include "ti8x/utility/getKey.z80"
144
145