@@ -256,6 +256,100 @@ __CLS_SCR:
256256 ENDP
257257
258258#line 10 "plot.asm"
259+ #line 1 "attr.asm"
260+
261+ ; Attribute routines
262+ ; vim:ts=4:et:sw:
263+
264+
265+
266+
267+ #line 1 "const.asm"
268+
269+ ; Global constants
270+
271+ P_FLAG EQU 23697
272+ FLAGS2 EQU 23681
273+ ATTR_P EQU 23693 ; permanet ATTRIBUTES
274+ ATTR_T EQU 23695 ; temporary ATTRIBUTES
275+ CHARS EQU 23606 ; Pointer to ROM/RAM Charset
276+ UDG EQU 23675 ; Pointer to UDG Charset
277+ MEM0 EQU 5C92h ; Temporary memory buffer used by ROM chars
278+
279+ #line 8 "attr.asm"
280+
281+
282+ __ATTR_ADDR:
283+ ; calc start address in DE (as (32 * d) + e)
284+ ; Contributed by Santiago Romero at http://www.speccy.org
285+ ld h , 0 ; 7 T-States
286+ ld a , d ; 4 T-States
287+ add a , a ; a * 2 ; 4 T-States
288+ add a , a ; a * 4 ; 4 T-States
289+ ld l , a ; HL = A * 4 ; 4 T-States
290+
291+ add hl , hl ; HL = A * 8 ; 15 T-States
292+ add hl , hl ; HL = A * 16 ; 15 T-States
293+ add hl , hl ; HL = A * 32 ; 15 T-States
294+
295+ ld d , 18h ; DE = 6144 + E. Note: 6144 is the screen size (before attr zone)
296+ add hl , de
297+
298+ ld de , (SCREEN_ADDR) ; Adds the screen address
299+ add hl , de
300+
301+ ; Return current screen address in HL
302+ ret
303+
304+
305+ ; Sets the attribute at a given screen coordinate (D, E).
306+ ; The attribute is taken from the ATTR_T memory variable
307+ ; Used by PRINT routines
308+ SET_ATTR:
309+
310+ ; Checks for valid coords
311+ call __IN_SCREEN
312+ ret nc
313+
314+ __SET_ATTR:
315+ ; Internal __FASTCALL__ Entry used by printing routines
316+ PROC
317+
318+ call __ATTR_ADDR
319+
320+ __SET_ATTR2: ; Sets attr from ATTR_T to (HL) which points to the scr address
321+ ld de , (ATTR_T) ; E = ATTR_T, D = MASK_T
322+
323+ ld a , d
324+ and (hl)
325+ ld c , a ; C = current screen color, masked
326+
327+ ld a , d
328+ cpl ; Negate mask
329+ and e ; Mask current attributes
330+ or c ; Mix them
331+ ld (hl) , a ; Store result in screen
332+
333+ ret
334+
335+ ENDP
336+
337+
338+ ; Sets the attribute at a given screen pixel address in hl
339+ ; HL contains the address in RAM for a given pixel (not a coordinate)
340+ SET_PIXEL_ADDR_ATTR:
341+ ;; gets ATTR position with offset given in SCREEN_ADDR
342+ ld a , h
343+ rrca
344+ rrca
345+ rrca
346+ and 3
347+ or 18h
348+ ld h , a
349+ ld de , (SCREEN_ADDR)
350+ add hl , de ;; Final screen addr
351+ jp __SET_ATTR2
352+ #line 11 "plot.asm"
259353
260354PLOT:
261355 PROC
@@ -313,21 +407,7 @@ __PLOT_OVER1:
313407 LOCAL __PLOT_END
314408__PLOT_END:
315409 ld (hl) , a
316-
317- ;; gets ATTR position with offset given in SCREEN_ADDR
318- ld a , h
319- rrca
320- rrca
321- rrca
322- and 3
323- or 18h
324- ld h , a
325- ld de , (SCREEN_ADDR)
326- add hl , de ;; Final screen addr
327-
328- LOCAL PO_ATTR_2
329- PO_ATTR_2 EQU 0BE4h ; Another entry to PO_ATTR
330- jp PO_ATTR_2 ; This will update attr accordingly. Beware, uses IY
410+ jp SET_PIXEL_ADDR_ATTR
331411
332412__PLOT_ERR:
333413 jp __OUT_OF_SCREEN_ERR ; Spent 3 bytes, but saves 3 T-States at (#1)
0 commit comments