-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrect.asm
More file actions
187 lines (162 loc) · 3.35 KB
/
Copy pathrect.asm
File metadata and controls
187 lines (162 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
include 'include/ez80.inc'
include 'include/tiformat.inc'
include 'include/ti84pceg.inc'
format ti executable 'DEMO'
RECT_WIDTH := 10
RECT_HEIGHT := 10
RECT_COLOR_I := 135
; Start of program code
call ti.RunIndicOff ; turn off run indicator
di ; disable interrupts
create1555palette:
ld hl,ti.mpLcdPalette ; mmio address of lcd palette
ld b,0
.loop:
ld d,b
ld a,b
and a,192
srl d
rra
ld e,a
ld a,31
and a,b
or a,e
ld (hl),a
inc hl
ld (hl),d
inc hl
inc b
jr nz,.loop
call ti.boot.ClearVRAM ; set all of vram to index 255 (white)
ld a,ti.lcdBpp8
ld (ti.mpLcdCtrl),a ; enable 8bpp mode
main_loop:
di
ld hl,ti.DI_Mode ; register for keypad mode
ld (hl),2 ; set single scan mode
xor a,a
scan_wait:
cp a,(hl) ; wait for keypad idle mode
jr nz,scan_wait
; Read data registers here as needed
ld a,(ti.kbdG1)
bit ti.kbit2nd,a
call nz,center_rectangle ; center the rectangle if [2nd] is pressed
ld a,(ti.kbdG6)
bit ti.kbitClear,a
jp nz,exit_prgm ; exit the program if [CLEAR] is pressed
ld a,(ti.kbdG7)
push af
bit ti.kbitUp,a
call nz,request_up ; is [UP] pressed?
pop af
push af
bit ti.kbitRight,a
call nz,request_right ; is [RIGHT] pressed?
pop af
push af
bit ti.kbitLeft,a
call nz,request_left ; is [LEFT] pressed?
pop af
push af
bit ti.kbitDown,a
call nz,request_down ; is [DOWN] pressed?
pop af
or a,a
call nz,redraw_screen ; if any key is pressed, update the screen
jp main_loop
request_up:
ld a,0
yPos := $ - 1
dec a
ret z ; return if @ 1
ld (yPos),a
ret
request_right:
ld hl,0
xPos := $ - 3
inc hl
ld de,ti.lcdWidth
or a,a
sbc hl,de
add hl,de
ret z ; return if @ 319
ld (xPos),hl
ret
request_left:
ld hl,(xPos)
dec hl
add hl,de
; The purpose of these instructions is to perform a subtraction and check if the result is zero.
; The or a, a is used to set the zero flag, and then sbc hl, de subtracts de from hl with the carry flag acting as a borrow.
; The subsequent ret z instruction checks the zero flag and returns from the subroutine if the result of the subtraction was zero
or a,a
sbc hl,de
ret z ; return if @ 1
ld (xPos),hl
ret
request_down:
ld a,(yPos)
inc a
cp a,ti.lcdHeight
ret z ; return if @ 239
ld (yPos),a
ret
center_rectangle:
ld hl,ti.lcdWidth / 2
ld (xPos),hl
ld hl,ti.lcdHeight / 2
ld (yPos),hl
ret
redraw_screen:
ld hl,ti.vRam
ld bc,ti.lcdWidth * ti.lcdHeight
ld a,$cc
call ti.MemSet ; set the LCD background
ld a,RECT_COLOR_I ; change the color of the rectangle
ld (draw_rectangle.color),a
ld de,(xPos)
ld hl,(yPos)
ld a,RECT_WIDTH
ld bc,RECT_HEIGHT
; jp draw_rectangle
;----------------------------------------
; draw_rectangle
; inputs:
; de = x
; l = y
; bc = width
; a = height
; rcolor = color of rectangle
; this routine can be greatly optimized!
;----------------------------------------
draw_rectangle:
ld h,ti.lcdWidth / 2 ; h = 160
mlt hl ; 160 * y
add hl,hl ; hl * 2
add hl,de ; add x coordinate
ld de,ti.vRam
add hl,de ; offset vRam
dec bc ; for ldir
.loop:
ld (hl),0
.color := $ - 1
push hl
pop de
inc de
push bc
ldir ; draw line
pop bc
ld de,ti.lcdWidth
add hl,de ; move down
sbc hl,bc
dec a
jr nz,.loop
ret
exit_prgm:
call ti.ClrScrn
ld a,ti.lcdBpp16
ld (ti.mpLcdCtrl),a
call ti.DrawStatusBar
ei ; reset screen back to normal
ret ; return to os