-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
agon_graphics.asm
245 lines (226 loc) · 5.06 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
;
; Title: BBC Basic for AGON - Graphics stuff
; Author: Dean Belfield
; Created: 12/05/2023
; Last Updated: 07/06/2023
;
; Modinfo:
; 07/06/2023: Modified to run in ADL mode
.ASSUME ADL = 1
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
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 4, (IX+sysvar_vpd_pflags)
CALL EXPRI
EXX
VDU 16H ; Mode change
VDU L
MOSCALL mos_sysvars
$$: BIT 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
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 1, (IX+sysvar_vpd_pflags)
VDU 23
VDU 0
VDU vdp_scrchar
VDU (VDU_BUFFER+0)
VDU (VDU_BUFFER+1)
VDU (VDU_BUFFER+2)
VDU (VDU_BUFFER+3)
$$: BIT 1, (IX+sysvar_vpd_pflags)
JR Z, $B ; Wait for the result
LD 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
DEC A ; Set A to FFh
$$: POP IX
JP INKEY1 ; Jump back to the GET command
; 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 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 2, (IX+sysvar_vpd_pflags)
JR Z, $B ; Wait for the result
;
; Return the data as a 1 byte index
;
LD 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