06-19-2010, 08:12 PM
I am working in this routine pixel-precise.
It is ripped from microhobby and wos forum.
Modified by me. I need help to complete the paint attributes method, because in asm my routine works fine, baut when I passed t sub It fails.
Here is the code.
Modified 20-June-2010 included colour ripped by wos
Modified 21-June-2010 included attributes in the same sub.
Now are two independent subs methods:
1.-PlotChar(file,column,CharAdr)
PlotCharPaint(file,column,atribute)
2.- PlotChat(file,column,CharAdr,atrib)
Probably, this is the last update for this routine.
Modified 2010-07-09 including fastcall and all asm routines embebed. The on ly problem is because the rets in atributes process make me save three bytes in printer buffer. Also I can not use Ubyte in fastcall because I do not understand how it works.
It is ripped from microhobby and wos forum.
Modified by me. I need help to complete the paint attributes method, because in asm my routine works fine, baut when I passed t sub It fails.
Here is the code.
Modified 20-June-2010 included colour ripped by wos
Modified 21-June-2010 included attributes in the same sub.
Now are two independent subs methods:
1.-PlotChar(file,column,CharAdr)
PlotCharPaint(file,column,atribute)
2.- PlotChat(file,column,CharAdr,atrib)
Probably, this is the last update for this routine.
Modified 2010-07-09 including fastcall and all asm routines embebed. The on ly problem is because the rets in atributes process make me save three bytes in printer buffer. Also I can not use Ubyte in fastcall because I do not understand how it works.
Code:
'==========================
'=plotchat=v3.100709=======
'==========================
'ripped from microhobby and
'wos forum
'thx to britlion lcd boriel
'--------------------------
border 6
cls
'demo of PlotChar
Dim YoF,YoC As Ubyte
YoF=50:YoC=70
YoCharAdr=@manwen
PlotChar(100,200,YoCharAdr)
PlotCharPaint(100,200,01101001b)
'---
dim w as ubyte
w=0
'---
PlotChat((256*32)+512,@manwen,01101001b)
do
'char paper7 = 00111010b
PlotChat(w,@manwen,00110010b)
asm
halt
;slow movement
end asm
PlotChat(w,@manwen,00111010b)
w=w+1
' YoF=YoF+1
loop until w>255
end
'=fin======================
FUNCTION FASTCALL PlotChat(paramHL AS Uinteger,paramDE AS Uinteger,paramBC AS Uinteger)
asm
;hl-atr de-coord bc-graf
ld b,h ;pilla atr,0
ld c,l ;BFActual(0)
pop hl ;recup ret
pop de ;pilla p2-coord
ex (sp),hl ;pilla p3-graf
;---
;bc-atr de-coord bc-graf
;--------------------------
;### primera parte
;--------------------------
;para:
; ld hl,16384
; ld (hl),a
; jr para
;el atributo viene en L
;en de debe estar manwen
;en bc estan las coords b-row c-col
;descartamos a=pareado del atributo
;---
;enterramos las coords
ld a,c
ld (23500),a
ld a,b
ld (23501),a
;enterramos el atrib para luego
ld a,l
ld (23502),a
;---
;comment halt for thrust the movement
halt
prixoratr:
;--------------------
;entrada e=dirmemLB 22
; d=dirmemHB 256*X
; H=pareja del atributo
; L=atributo 33
; b=coord row 256*X
; c=coord colum 11
; a=se queda a cero
; 1er byte de la figura?
;--------------------
; ld e,(IX+7) ;file
; ld d,(IX+5) ;colum
; ld l,(IX+8) ;lowbyte charadr
; ld h,(IX+9) ;highbyte charadr
ex de,hl
ld d,b
ld e,c
ld b,8
bucbyt2:
ld a,(hl)
;byte del carac
push bc
;guar cont bytes
ld b,8
bucbit2:
push bc
;guar cont bits
rla
;desplaza un bit
jr nc,noplot2
;si era 0 no pinta
ld b,d
;b=y ;aki va d
ld c,e
;c=x ;aki va e
push de
;guar regs
push hl
push af
;aki jamas un halt enlentece mucho
call co2 ;hace plot c,b
;pero plotw de mh63
pop af
;recup byte car
pop hl
;recup dir del byte
pop de
;recup coords
noplot2:
inc e
;inc x
pop bc
;recup cont bits
djnz bucbit2
;prox bit
inc d
;dec y
pop bc
;recup cont bytes
inc hl
;dir del byte
;dec hl ;dir del byte
ld a,248
;a=-8
add a,e
;resta 8 a x
ld e,a
djnz bucbyt2
;prox byte
;dec d
;dec d
;dec d
;dec d
;dec d
;dec d
;dec d
;dec d
ret
;============
;MH63PLOTW
;============
; screen 010VVsss vvvHHHHH
; coords VVxxxvvv HHHHHsss
; objeto 010VVvvv xxxHHHHH sss
; xxx son despreciados
;------------------------
co2:
ld b,d
ld c,e
LD H,40h ;0100-0000 = 16384
LD A,B ;b=x=fila VVxxxvvv
AND 7 ;0000-0vvv
ADD A,H ;0100-0vvv
LD H,A ;aseguramos H
;intermedio
SRL B ;0VVxxxvv
SRL B ;00VVxxxv
SRL B ;000VVxxx
LD A,B ;000VVxxx
AND 24 ;000VV000
ADD A,H ;010VVvvv
LD H,A ;desprecias xxx de la vertical
;fin del primer trabajo B
;---
LD A,B ;000VVxxx
AND 7 ;00000xxx
RRCA ;x00000xx
RRCA ;xx00000x
RRCA ;xxx00000
LD L,A ;
LD A,C ;c=y=colum HHHHHsss
AND 7 ;00000sss
LD B,A ;B=00000sss ;el bit
;---
SRL C ;0HHHHHss
SRL C ;00HHHHHs
SRL C ;000HHHHH
LD A,C ;000HHHHH
ADD A,L ;xxxHHHHH
LD L,A ;la horizontal
;---inicio bucle inversor
INC B ;B=00000sss + 1
XOR A ;A=00000000
SCF ;F=xxxx-xxx1
c12:
RRA ;A=1000-0000
DJNZ c12
; limpiamos A = 0000-0000
; buscamos un pixel
; el SFC mete un 1 al principio
; y RRA corre B veces hacia der ese 1
XOR (HL) ;orea A con dfbyte
LD (HL),A ;para no borrar ant
XOR (HL) ;en negro pone punto blanco
; OR (HL) ;hace over sobre punto negro
;RET
;-----------------
priatr2:
;Ripped from Wos-Turkwel
; ld c,(IX+7)
; ld b,(IX+5)
; ld a,(IX+11)
;desentierro coords
push hl
ld hl,23500
ld c,(hl)
inc hl
ld b,(hl)
;desenterramos el atrib
inc hl
ld a,(hl)
pop hl
;use alongside the print_char routine to set Attribute values automatically.......
;on entry BC uses exactly the same Y\X values as the print_char routine and A holds the Atrribute Value to be used.
;
;NB If you don't want to use A this way then set up something like ld a,(nnnn) at the start of the print_attribute routine
;instead and that way you can use your own "Sytem Variable" for printing each time
;
;suggested use: ld a,"A"
; ld bc,184*256+249
; push bc
; call print_char
; pop bc
; ld a,128+64+5
; call print_attribute
; ret
;
;alternatively you can integrate this into the print_char routine by looking after BC and A...it doesn't matter which way
;round you use it...char\attributes or attributes\char
print_attributew:
ld d,0
ld e,a
;transfer Attribute Byte to e for easier use
ld a,b
cp 192
ret nc
;check Y position and exit if off bottom of screen
push bc
;save off Y and X values for later
and 248
ld h,22
ld l,a
add hl,hl
add hl,hl
srl c
srl c
srl c
ld b,d
add hl,bc
;calculate the correct Attribute Address for the Y\X values
ld (hl),e
;set the Attribute - this is ALWAYS set no matter what the valid Y\X values used
pop bc
;get the Y and X values back into BC
call print_attribute2
;call the subroutine to see if an adjacent Horizontal Attribute needs to be set
;
ld a,b
cp 184
ret nc
;check to see if we are at Vertical character 23 - if so then no need to set adjacent Vertical Attribute & Exit routine
and 7
ret z
;and don't set the adjacent Vertical Attribute if there's no need to & Exit routine
ld a,l
add a,32
ld l,a
ld a,d
adc a,h
ld h,a
ld (hl),e
;set the Attribute address to the line below - and set the adjacent Vertical Attribute
;
;drop through now into adjacent Horizontal Attribute subroutine - all RETs will now Exit the routine completely
;
print_attribute2w:
ld a,c
cp 248
ret nc
;check to see if we are at Horizontal character 31 - if so then no need to set adjacent Horizontal Attribute
and 7
ret z
;and don't set the adjacent Horizontal Attribute if there's no need to
inc l
ld (hl),e
dec l
;increment the Attribute address - set the adjacent horizontal Attribute - then set the Attribute Address back
ret
end asm
end function
'fin del fastcall plotchat
'==========================
FUNCTION FASTCALL PlotChar(ROWparamHL AS Uinteger,COLparamDE AS Uinteger,ADRparamBC AS Uinteger)
asm
;hl-atr de-coord bc-graf
ld b,h ;pilla atr,0
ld c,l ;BFActual(0)
pop hl ;recup retorno
pop de ;pilla p2-coord
ex (sp),hl ;pilla p3-graf
;---
;bc-atr de-coord bc-graf
;--------------------------
;### primera parte
;--------------------------
;---entrada----------------
;ROWparamHL bring C uinteger
;COLparamDE bring E uinteger
;ADRparamBC bring hl uinteger
;--------------------------
prixor:
;--------------------
;entrada e=columnaDF
; d=filaDF
; hl=dirmem figura
; a=primer byte de figura
;
;--------------------
ld d,c ;row
;ld e,e ;col
;change order row x col
;hl ya viene predicho
;ld l,(IX+8) ;lowbyte charadr
;ld h,(IX+9) ;highbyte charadr
ld b,8
bucbyt:
ld a,(hl)
;byte del carac
push bc
;guar cont bytes
ld b,8
bucbit:
push bc
;guar cont bits
rla
;desplaza un bit
jr nc,noplot
;si era 0 no pinta
ld b,d
;b=y ;aki va d
ld c,e
;c=x ;aki va e
push de
;guar regs
push hl
push af
;aki jamas un halt enlentece mucho
call co ;hace plot c,b
;pero plotw de mh63
pop af
;recup byte car
pop hl
;recup dir del byte
pop de
;recup coords
noplot:
inc e
;inc x
pop bc
;recup cont bits
djnz bucbit
;prox bit
inc d
;dec y
pop bc
;recup cont bytes
inc hl
;dir del byte
;dec hl ;dir del byte
ld a,248
;a=-8
add a,e
;resta 8 a x
ld e,a
djnz bucbyt
;prox byte
;dec d
;dec d
;dec d
;dec d
;dec d
;dec d
;dec d
;dec d
ret
;============
;MH63PLOTW
;============
; screen 010VVsss vvvHHHHH
; coords VVxxxvvv HHHHHsss
; objeto 010VVvvv xxxHHHHH sss
; xxx son despreciados
;------------------------
co:
ld b,d
ld c,e
LD H,40h ;0100-0000 = 16384
LD A,B ;b=x=fila VVxxxvvv
AND 7 ;0000-0vvv
ADD A,H ;0100-0vvv
LD H,A ;aseguramos H
;intermedio
SRL B ;0VVxxxvv
SRL B ;00VVxxxv
SRL B ;000VVxxx
LD A,B ;000VVxxx
AND 24 ;000VV000
ADD A,H ;010VVvvv
LD H,A ;desprecias xxx de la vertical
;fin del primer trabajo B
;---
LD A,B ;000VVxxx
AND 7 ;00000xxx
RRCA ;x00000xx
RRCA ;xx00000x
RRCA ;xxx00000
LD L,A ;
LD A,C ;c=y=colum HHHHHsss
AND 7 ;00000sss
LD B,A ;B=00000sss ;el bit
;---
SRL C ;0HHHHHss
SRL C ;00HHHHHs
SRL C ;000HHHHH
LD A,C ;000HHHHH
ADD A,L ;xxxHHHHH
LD L,A ;la horizontal
;---inicio bucle inversor
INC B ;B=00000sss + 1
XOR A ;A=00000000
SCF ;F=xxxx-xxx1
c1:
RRA ;A=1000-0000
DJNZ c1
; limpiamos A = 0000-0000
; buscamos un pixel
; el SFC mete un 1 al principio
; y RRA corre B veces hacia der ese 1
XOR (HL) ;orea A con dfbyte
LD (HL),A ;para no borrar ant
XOR (HL) ;en negro pone punto blanco
; OR (HL) ;hace over sobre punto negro
ret
end asm
end function
'fin del fastcall plotchar
'==========================
sub PlotCharViaSub(row as ubyte,colum as ubyte, charadr as uinteger)
asm
halt
prixor3:
;--------------------
;entrada e=columnaDF
; d=filaDF
; hl=dirmem figura
; a=primer byte de figura
;
;--------------------
ld e,(IX+7) ;row
ld d,(IX+5) ;colum
ld l,(IX+8) ;lowbyte charadr
ld h,(IX+9) ;highbyte charadr
ld b,8
bucbyt3:
ld a,(hl)
;byte del carac
push bc
;guar cont bytes
ld b,8
bucbit3:
push bc
;guar cont bits
rla
;desplaza un bit
jr nc,noplot3
;si era 0 no pinta
ld b,d
;b=y ;aki va d
ld c,e
;c=x ;aki va e
push de
;guar regs
push hl
push af
;aki jamas un halt enlentece mucho
call co ;hace plot c,b
;pero plotw de mh63
pop af
;recup byte car
pop hl
;recup dir del byte
pop de
;recup coords
noplot3:
inc e
;inc x
pop bc
;recup cont bits
djnz bucbit3
;prox bit
inc d
;dec y
pop bc
;recup cont bytes
inc hl
;dir del byte
;dec hl ;dir del byte
ld a,248
;a=-8
add a,e
;resta 8 a x
ld e,a
djnz bucbyt3
;prox byte
;dec d
;dec d
;dec d
;dec d
;dec d
;dec d
;dec d
;dec d
ret
;============
;MH63PLOTW
;============
; screen 010VVsss vvvHHHHH
; coords VVxxxvvv HHHHHsss
; objeto 010VVvvv xxxHHHHH sss
; xxx son despreciados
;------------------------
co3:
ld b,d
ld c,e
LD H,40h ;0100-0000 = 16384
LD A,B ;b=x=fila VVxxxvvv
AND 7 ;0000-0vvv
ADD A,H ;0100-0vvv
LD H,A ;aseguramos H
;intermedio
SRL B ;0VVxxxvv
SRL B ;00VVxxxv
SRL B ;000VVxxx
LD A,B ;000VVxxx
AND 24 ;000VV000
ADD A,H ;010VVvvv
LD H,A ;desprecias xxx de la vertical
;fin del primer trabajo B
;---
LD A,B ;000VVxxx
AND 7 ;00000xxx
RRCA ;x00000xx
RRCA ;xx00000x
RRCA ;xxx00000
LD L,A ;
LD A,C ;c=y=colum HHHHHsss
AND 7 ;00000sss
LD B,A ;B=00000sss ;el bit
;---
SRL C ;0HHHHHss
SRL C ;00HHHHHs
SRL C ;000HHHHH
LD A,C ;000HHHHH
ADD A,L ;xxxHHHHH
LD L,A ;la horizontal
;---inicio bucle inversor
INC B ;B=00000sss + 1
XOR A ;A=00000000
SCF ;F=xxxx-xxx1
c13:
RRA ;A=1000-0000
DJNZ c13
; limpiamos A = 0000-0000
; buscamos un pixel
; el SFC mete un 1 al principio
; y RRA corre B veces hacia der ese 1
XOR (HL) ;orea A con dfbyte
LD (HL),A ;para no borrar ant
XOR (HL) ;en negro pone punto blanco
; OR (HL) ;hace over sobre punto negro
RET
end asm
end sub
'==========================
FUNCTION FASTCALL PlotCharPaint(ROWparamHL AS Uinteger,COLparamDE AS Uinteger,ATRparamBC AS Uinteger)
asm
;hl-atr de-coord bc-graf
ld b,h ;pilla atr,0
ld c,l ;BFActual(0)
pop hl ;recup retorno
pop de ;pilla p2-coord
ex (sp),hl ;pilla p3-graf
;---
;bc-atr de-coord bc-graf
;--------------------------
;### primera parte
;--------------------------
;---entrada----------------
;ROWparamHL bring C uinteger
;COLparamDE bring E uinteger
;ATRparamBC bring hl uinteger
;--------------------------
priatr:
;Ripped from Wos-Turkwel
ld b,c
ld c,e
ld a,l ;atr ok
;use alongside the print_char routine to set Attribute values automatically.......
;on entry BC uses exactly the same Y\X values as the print_char routine and A holds the Atrribute Value to be used.
;
;NB If you don't want to use A this way then set up something like ld a,(nnnn) at the start of the print_attribute routine
;instead and that way you can use your own "Sytem Variable" for printing each time
;
;suggested use: ld a,"A"
; ld bc,184*256+249
; push bc
; call print_char
; pop bc
; ld a,128+64+5
; call print_attribute
; ret
;
;alternatively you can integrate this into the print_char routine by looking after BC and A...it doesn't matter which way
;round you use it...char\attributes or attributes\char
print_attribute:
ld d,0
ld e,a
;transfer Attribute Byte to e for easier use
ld a,b
cp 192
ret nc
;check Y position and exit if off bottom of screen
push bc
;save off Y and X values for later
and 248
ld h,22
ld l,a
add hl,hl
add hl,hl
srl c
srl c
srl c
ld b,d
add hl,bc
;calculate the correct Attribute Address for the Y\X values
ld (hl),e
;set the Attribute - this is ALWAYS set no matter what the valid Y\X values used
pop bc
;get the Y and X values back into BC
call print_attribute2
;call the subroutine to see if an adjacent Horizontal Attribute needs to be set
;
ld a,b
cp 184
ret nc
;check to see if we are at Vertical character 23 - if so then no need to set adjacent Vertical Attribute & Exit routine
and 7
ret z
;and don't set the adjacent Vertical Attribute if there's no need to & Exit routine
ld a,l
add a,32
ld l,a
ld a,d
adc a,h
ld h,a
ld (hl),e
;set the Attribute address to the line below - and set the adjacent Vertical Attribute
;
;drop through now into adjacent Horizontal Attribute subroutine - all RETs will now Exit the routine completely
;
print_attribute2:
ld a,c
cp 248
ret nc
;check to see if we are at Horizontal character 31 - if so then no need to set adjacent Horizontal Attribute
and 7
ret z
;and don't set the adjacent Horizontal Attribute if there's no need to
inc l
ld (hl),e
dec l
;increment the Attribute address - set the adjacent horizontal Attribute - then set the Attribute Address back
ret
end asm
end function
'==========================
'-----------------
'------
manwen:
asm
db 00011000b
db 00001010b
db 01111110b
db 01011000b
db 00011000b
db 00111100b
db 00100100b
db 00000000b
end asm
'---
'==========================