-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheSketch.z
209 lines (186 loc) · 3.94 KB
/
eSketch.z
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
;
; Simple Etch-a-Sketch for the TRS-80 Model-1
;
; Author : Andy johnson
; Date : 2020/08/28
;
; Version : 1.0
; Model-I Calls
Cls: equ 01c9h ; Clears the screen
Screen: equ 3c00h ; Screen start
Glif: equ 20h ; Space character
KbScan: equ 002bh ; Same as INKEY$ (Basic)
SetXmin:equ 0 ; X Coordinate Minimum
SetXMax:equ 127d ; X Coordinate Maximun (127)
SetYMin:equ SetXmin ; Y = X minimum (0) for Set
SetYMax:equ 44d ; Max is 47 but, save last line
SetCall:equ 150h ; To be loaded to HL
SetOn: equ 80h ; Turn SET() on
SetOff: equ 01h ; Turn RESET() on
SetEnd: equ 188ch ; RST will call this and find )+
MsgPos: equ 3fc0h ; last line
Delay: equ 0060h ; Delays for BC*14.65 microseconds
org 8000h ; Origin
;Variables
Mesg: db " -------------- Arrows to move, (Q)uit, (C)lear --------------",0
QMsg: db " ------------------------ Quitting !!! -----------------------",0
OutMsg: db "Press <Enter>",0
; Coordinates and SET() flag
XCoord: ds 1
YCoord: ds 1
SetFlg: ds 1
Init:
call Cls ; Clear the screen
ld a,65 ; Start in the middle of the screen
ld (XCoord), a ; save X
ld a,23
ld (YCoord), a ; save Y
ld bc,Mesg ; Print instructions at bottom of screen
call PrintMsg
Start:
; This simulates a blinking block by turning it on and off
ld a,SetOff ; hide the block
ld (SetFlg),a
call Grafix
ld bc,2048d ; delay before off
call Delay ; destroys bc
ld a,SetOn ; show the block
ld (SetFlg),a
call Grafix
call GetKey ; Get keyboard input
; Did we quit?
cp 43h
call z,ClearDisp ; Clear to message line
cp 51h ; Press Q
jr nz,Start
ld bc,QMsg ; Print the Quit message
call PrintMsg
ld bc,2048d ; delay before off
call Delay ; destroys bc
call Cls ; Clear the screen
ld bc,OutMsg ;Display "Press Enter"
call PrintMsg
ret
; Uses SET/RESET to draw based on SET FLAG
Grafix:
ld a,(SetFlg) ; Set the SET() flag
ld h,a ; Store in H for SET routine
ld a,(XCoord) ; Set X
ld b,a
ld a,(YCoord) ; Set Y
; Push these before call (Required by SET)
push hl
push bc
; Use SET/RESET. HL and BC are parameters
ld hl,SetEnd
jp SetCall
ret
; Get a key from the keyboard and do something
; Assumes Q is Quit
GetKey:
call KbScan
;up key
cp 5bh
call z,Up
;down key
cp 0ah
call z,Down
;right key
cp 9h
call z,Right
;left key
cp 8h
call z,Left
ret
; Key Actions
Up:
push af ; Save A and Flags
push bc ; Save BC pair
ld a,(YCoord) ; Get X Coordinate
dec a ; add 1
cp SetYMin ; We hit the edge
jr nz,USkip
inc a
USkip:
ld (YCoord),a ; Save it
pop bc ; Restore BC
pop af ; Restore A and Flags
ret
Down:
push af ; Save A and Flags
push bc ; Save BC pair
ld a,(YCoord) ; Get X Coordinate
inc a ; add 1
cp SetYMax ; We hit the edge
jr nz,DSkip
dec a ; sub 1 if edge
DSkip:
ld (YCoord),a ; Save it
pop bc ; Restore BC
pop af ; Restore A and Flags
ret
Left:
push af ; Save A and Flags
push bc ; Save BC pair
ld a,(XCoord) ; Get X Coordinate
dec a ; sub 1
cp SetXMin ; We hit the edge
jr nz,LSkip
inc a ; add 1 if edge
LSkip:
ld (XCoord),a ; Save it
pop bc ; Restore BC
pop af ; Restore A and Flags
ret ; Return
Right:
push af ; Save A and Flags
push bc ; Save BC pair
ld a,(XCoord) ; Get X Coordinate
inc a ; add 1
cp SetXMax ; We hit the edge
jr nz,RSkip
dec a ; sub 1 if edge
RSkip:
ld (XCoord),a ; Save it
pop bc ; Restore BC
pop af ; Restore A and Flags
ret ; Return
; Prints a message to the Message line
PrintMsg:
ld hl,MsgPos
push hl
ld a,40
; Clear the message line
Cloop:
ld (hl),' '
inc hl
dec a
jr nz,Cloop
pop hl
; and write the messag
Mloop:
ld a,(bc)
or a
ret z
ld (hl),a
inc bc
inc hl
jr Mloop
; Clear to message line
ClearDisp:
push a
push hl
push de
push bc
ld hl,Screen ; Start of Screen
ld de,Screen+1 ; Start + 1: will copy Glif from HL
ld bc,3c0h ; one line before message line
ld (hl),Glif ; put the Glif at start of screen
ldir ; (L)oa(d), (I)ncrement, (R)epeat
pop bc
pop de
pop hl
pop a
ret
; Nothing below this line
end Init