-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
agon_graphics.asm
262 lines (241 loc) · 5.47 KB
/
agon_graphics.asm
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
;
; Title: BBC Basic for AGON - Graphics stuff
; Author: Dean Belfield
; Created: 07/08/2022
; Last Updated: 19/05/2023
;
; Modinfo:
; 19/08/2022: Added GETSCHR, POINT
; 15/02/2023: Fixed COLOUR, GCOL
; 23/02/2023: Fixed MODE
; 04/03/2023: Updated POINT to return colour index, not RGB
; 12/03/2023: Palette change now supports COLOUR l, p syntax
; 21/03/2023: Now uses vdp defines
; 19/05/2023: Refactored GETSCHR for OSBYTE_87
.ASSUME ADL = 0
INCLUDE "equs.inc"
INCLUDE "macros.inc"
INCLUDE "mos_api.inc" ; In MOS/src
SEGMENT CODE
XDEF CLG
XDEF CLRSCN
XDEF MODE
XDEF COLOUR
XDEF GCOL
XDEF MOVE
XDEF PLOT
XDEF DRAW
XDEF POINT
XDEF GETSCHR
XDEF GETSCHR_1
XREF OSWRCH
XREF ASC_TO_NUMBER
XREF EXTERR
XREF EXPRI
XREF COMMA
XREF XEQ
XREF NXT
XREF BRAKET
XREF COUNT0
XREF CRTONULL
XREF NULLTOCR
XREF CRLF
XREF EXPR_W2
XREF INKEY1
; CLG: clears the graphics area
;
CLG: VDU 10h
JP XEQ
; CLS: clears the text area
;
CLRSCN: LD A, 0Ch
JP OSWRCH
; MODE n: Set video mode
;
MODE: PUSH IX ; Get the system vars in IX
MOSCALL mos_sysvars ; Reset the semaphore
RES.LIL 4, (IX+sysvar_vpd_pflags)
CALL EXPRI
EXX
VDU 16H ; Mode change
VDU L
MOSCALL mos_sysvars
$$: BIT.LIL 4, (IX+sysvar_vpd_pflags)
JR Z, $B ; Wait for the result
POP IX
JP XEQ
; GET(x,y): Get the ASCII code of a character on screen
;
GETSCHR: INC IY
CALL EXPRI ; Get X coordinate
EXX
PUSH HL ; Stack X
CALL COMMA
CALL EXPRI ; Get Y coordinate
EXX
CALL BRAKET ; Closing bracket
POP DE ; Pop X back into DE
CALL GETSCHR_1
JP INKEY1
;
; Fetch a character from the screen
; - DE: X coordinate
; - HL: Y coordinate
; Returns
; - A: The character or FFh if no match
; - F: C if match, otherwise NC
;
GETSCHR_1: PUSH IX ; Get the system vars in IX
MOSCALL mos_sysvars ; Reset the semaphore
RES.LIL 1, (IX+sysvar_vpd_pflags)
VDU 23
VDU 0
VDU vdp_scrchar
VDU E
VDU D
VDU L
VDU H
$$: BIT.LIL 1, (IX+sysvar_vpd_pflags)
JR Z, $B ; Wait for the result
LD.LIL A, (IX+sysvar_scrchar) ; Fetch the result in A
OR A ; Check for 00h
SCF ; C = character map
JR NZ, $F ; We have a character, so skip next bit
XOR A ; Clear carry
$$: POP IX
RET
; POINT(x,y): Get the pixel colour of a point on screen
;
POINT: CALL EXPRI ; Get X coordinate
EXX
LD (VDU_BUFFER+0), HL
CALL COMMA
CALL EXPRI ; Get Y coordinate
EXX
LD (VDU_BUFFER+2), HL
CALL BRAKET ; Closing bracket
;
PUSH IX ; Get the system vars in IX
MOSCALL mos_sysvars ; Reset the semaphore
RES.LIL 2, (IX+sysvar_vpd_pflags)
VDU 23
VDU 0
VDU vdp_scrpixel
VDU (VDU_BUFFER+0)
VDU (VDU_BUFFER+1)
VDU (VDU_BUFFER+2)
VDU (VDU_BUFFER+3)
$$: BIT.LIL 2, (IX+sysvar_vpd_pflags)
JR Z, $B ; Wait for the result
;
; Return the data as a 1 byte index
;
LD.LIL L, (IX+(sysvar_scrpixelIndex))
POP IX
JP COUNT0
; COLOUR colour
; COLOUR L,P
; COLOUR L,R,G,B
;
COLOUR: CALL EXPRI ; The colour / mode
EXX
LD A, L
LD (VDU_BUFFER+0), A ; Store first parameter
CALL NXT ; Are there any more parameters?
CP ','
JR Z, COLOUR_1 ; Yes, so we're doing a palette change next
;
VDU 11h ; Just set the colour
VDU (VDU_BUFFER+0)
JP XEQ
;
COLOUR_1: CALL COMMA
CALL EXPRI ; Parse R (OR P)
EXX
LD A, L
LD (VDU_BUFFER+1), A
CALL NXT ; Are there any more parameters?
CP ','
JR Z, COLOUR_2 ; Yes, so we're doing COLOUR L,R,G,B
;
VDU 13h ; VDU:COLOUR
VDU (VDU_BUFFER+0) ; Logical Colour
VDU (VDU_BUFFER+1) ; Palette Colour
VDU 0 ; RGB set to 0
VDU 0
VDU 0
JP XEQ
;
COLOUR_2: CALL COMMA
CALL EXPRI ; Parse G
EXX
LD A, L
LD (VDU_BUFFER+2), A
CALL COMMA
CALL EXPRI ; Parse B
EXX
LD A, L
LD (VDU_BUFFER+3), A
VDU 13h ; VDU:COLOUR
VDU (VDU_BUFFER+0) ; Logical Colour
VDU FFh ; Physical Colour (-1 for RGB mode)
VDU (VDU_BUFFER+1) ; R
VDU (VDU_BUFFER+2) ; G
VDU (VDU_BUFFER+3) ; B
JP XEQ
; GCOL mode,colour
;
GCOL: CALL EXPRI ; Parse MODE
EXX
LD A, L
LD (VDU_BUFFER+0), A
CALL COMMA
;
CALL EXPRI ; Parse Colour
EXX
LD A, L
LD (VDU_BUFFER+1), A
;
VDU 12h ; VDU:GCOL
VDU (VDU_BUFFER+0) ; Mode
VDU (VDU_BUFFER+1) ; Colour
JP XEQ
; PLOT mode,x,y
;
PLOT: CALL EXPRI ; Parse mode
EXX
PUSH HL ; Push mode (L) onto stack
CALL COMMA
CALL EXPR_W2 ; Parse X and Y
POP BC ; Pop mode (C) off stack
PLOT_1: VDU 19H ; VDU code for PLOT
VDU C ; C: Mode
VDU E ; DE: X
VDU D
VDU L ; HL: Y
VDU H
JP XEQ
; MOVE x,y
;
MOVE: CALL EXPR_W2 ; Parse X and Y
LD C, 04H ; Plot mode 04H (Move)
JR PLOT_1 ; Plot
; DRAW x1,y1
; DRAW x1,y1,x2,y2
;
DRAW: CALL EXPR_W2 ; Get X1 and Y1
CALL NXT ; Are there any more parameters?
CP ','
LD C, 05h ; Code for LINE
JR NZ, PLOT_1 ; No, so just do DRAW x1,y1
VDU 19h ; Move to the first coordinates
VDU 04h
VDU E
VDU D
VDU L
VDU H
CALL COMMA
PUSH BC
CALL EXPR_W2 ; Get X2 and Y2
POP BC
JR PLOT_1 ; Now DRAW the line to those positions