Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using PutcharLcd
#1
I was testing the Putchar Lcd´s routine and I think It´s very handly and work right for my games. Perhaps is not the fastest, but I´m happy with the facilities of modifying its code. Big Grin
Code:
'=========================== '= putchar lcd compiuter = '= version 1.100603 <-date = '=========================== '#include <sinclair.bas> '#include <memcopy.bas> '#include <keys.bas> '#include <print42.bas> '#include <attr.bas> '--- cls border 5 '------------------------------------- sub putcharLcd1x1(x as Uinteger,y as Uinteger,adr as Uinteger) dim scr as Uinteger dim a as Uinteger a=peek(@linebuffer+y) scr=(a<<5)+x+16384 poke ubyte scr,peek(adr) poke ubyte scr+256,peek(adr+1) poke ubyte scr+512,peek(adr+2) poke ubyte scr+768,peek(adr+3) poke ubyte scr+1024,peek(adr+4) poke ubyte scr+1280,peek(adr+5) poke ubyte scr+1536,peek(adr+6) poke ubyte scr+1792,peek(adr+7) poke ubyte 22528+x+(y<<5),peek (adr+8) End sub '------------------------------------------- sub putcharLcd1x2(x as Uinteger,y as Uinteger,adr as Uinteger) dim scr as Uinteger dim a as Uinteger a=peek(@linebuffer+y) scr=(a<<5)+x+16384 poke ubyte scr,peek(adr) poke ubyte scr+256,peek(adr+1) poke ubyte scr+512,peek(adr+2) poke ubyte scr+768,peek(adr+3) poke ubyte scr+1024,peek(adr+4) poke ubyte scr+1280,peek(adr+5) poke ubyte scr+1536,peek(adr+6) poke ubyte scr+1792,peek(adr+7) poke ubyte 22528+x+(y<<5),peek (adr+8) x=x+1 a=peek(@linebuffer+y) scr=(a<<5)+x+16384 poke ubyte scr,peek(adr+9) poke ubyte scr+256,peek(adr+10) poke ubyte scr+512,peek(adr+11) poke ubyte scr+768,peek(adr+12) poke ubyte scr+1024,peek(adr+13) poke ubyte scr+1280,peek(adr+14) poke ubyte scr+1536,peek(adr+15) poke ubyte scr+1792,peek(adr+16) poke ubyte 22528+x+(y<<5),peek (adr+17) End sub '------------------------------------------- sub putcharLcd2x1(x as Uinteger,y as Uinteger,adr as Uinteger) dim scr as Uinteger dim a as Uinteger a=peek(@linebuffer+y) scr=(a<<5)+x+16384 poke ubyte scr,peek(adr) poke ubyte scr+256,peek(adr+1) poke ubyte scr+512,peek(adr+2) poke ubyte scr+768,peek(adr+3) poke ubyte scr+1024,peek(adr+4) poke ubyte scr+1280,peek(adr+5) poke ubyte scr+1536,peek(adr+6) poke ubyte scr+1792,peek(adr+7) poke ubyte 22528+x+(y<<5),peek (adr+8) y=y+1 a=peek(@linebuffer+y) scr=(a<<5)+x+16384 poke ubyte scr,peek(adr+9) poke ubyte scr+256,peek(adr+10) poke ubyte scr+512,peek(adr+11) poke ubyte scr+768,peek(adr+12) poke ubyte scr+1024,peek(adr+13) poke ubyte scr+1280,peek(adr+14) poke ubyte scr+1536,peek(adr+15) poke ubyte scr+1792,peek(adr+16) poke ubyte 22528+x+(y<<5),peek (adr+17) End sub '------------------------------------------- sub putcharLcd2x2(x as Uinteger,y as Uinteger,adr as Uinteger) dim scr as Uinteger dim a as Uinteger a=peek(@linebuffer+y) scr=(a<<5)+x+16384 poke ubyte scr,peek(adr) poke ubyte scr+256,peek(adr+1) poke ubyte scr+512,peek(adr+2) poke ubyte scr+768,peek(adr+3) poke ubyte scr+1024,peek(adr+4) poke ubyte scr+1280,peek(adr+5) poke ubyte scr+1536,peek(adr+6) poke ubyte scr+1792,peek(adr+7) poke ubyte 22528+x+(y<<5),peek (adr+8) x=x+1 a=peek(@linebuffer+y) scr=(a<<5)+x+16384 poke ubyte scr,peek(adr+9) poke ubyte scr+256,peek(adr+10) poke ubyte scr+512,peek(adr+11) poke ubyte scr+768,peek(adr+12) poke ubyte scr+1024,peek(adr+13) poke ubyte scr+1280,peek(adr+14) poke ubyte scr+1536,peek(adr+15) poke ubyte scr+1792,peek(adr+16) poke ubyte 22528+x+(y<<5),peek (adr+17) x=x-1 y=y+1 a=peek(@linebuffer+y) scr=(a<<5)+x+16384 poke ubyte scr,peek(adr+18) poke ubyte scr+256,peek(adr+19) poke ubyte scr+512,peek(adr+20) poke ubyte scr+768,peek(adr+21) poke ubyte scr+1024,peek(adr+22) poke ubyte scr+1280,peek(adr+23) poke ubyte scr+1536,peek(adr+24) poke ubyte scr+1792,peek(adr+25) poke ubyte 22528+x+(y<<5),peek (adr+26) x=x+1 a=peek(@linebuffer+y) scr=(a<<5)+x+16384 poke ubyte scr,peek(adr+27) poke ubyte scr+256,peek(adr+28) poke ubyte scr+512,peek(adr+29) poke ubyte scr+768,peek(adr+30) poke ubyte scr+1024,peek(adr+31) poke ubyte scr+1280,peek(adr+32) poke ubyte scr+1536,peek(adr+33) poke ubyte scr+1792,peek(adr+34) poke ubyte 22528+x+(y<<5),peek (adr+35) End sub '---next will be probably putcharlcd1x3 '--- linebuffer: asm defb 0,1,2,3,4,5,6,7,64,65,66,67,68,69,70,71,128,129,130,131,132,133,134,135 end asm '-------------------------- start: dim x,y as ubyte dim adr as Uinteger adr=@gfx1a x=1 y=1 putcharLcd1x1(x,y,adr) adr=@gfx1a x=1 y=3 putcharLcd1x2(x,y,adr) adr=@gfx1a x=1 y=5 putcharLcd2x1(x,y,adr) adr=@gfx1a x=1 y=8 putcharLcd2x2(x,y,adr) '---fin--- END '---------------------------------------- gfx1a: ASM DEFB 0,8,8,8,8,8,8,0,00010001B DEFB 0,60,4,4,60,32,60,0,00011001B DEFB 0,60,4,4,60,4,60,0,00100001B DEFB 0,36,36,36,60,4,4,0,00101001B END ASM '-----------------------------------------
Reply
#2
I'm happy you like it and make your own experiments based on my code. Looking forward to see your games.
Games are the best adverts for ZXBC.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply
#3
I thought my screen address code was faster?


Looking this over, I can see a case for ASM code. And isn't putchar 2X2 the same as putTile?

Course, I just glanced at it. I might have the wrong idea altogether!
Reply
#4
I think your code is probably best. But perhaps for basic things this code is very simple, and is better than traditional print.
I guess future versions of this routines add height, wide, activity, phase, direction, collision, addr_way_to_go and others parameters in the fastcalls or subs, perhaps using ix+0 and looping all the chars(wide x height).
We´re making proves, trying the best for every case.
Make our contributions.
Reply
#5
I will later change it to use the ASM screen/attribute adress calculation. PutCharLcd2x2 is not the same as puttile because PutTile writes two bytes in one go, using a different data format, but this routine puts only one byte, so the Format is similar to UDG. So Put Char uses 4x 4 UDG Blocks+Attribute.
I will pack my stuff for the Sinclair QL meeting in Prottes (near Vienna), then switch my Development PC on, and change the PutChar to use ASM parts to calculate the adresses.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply
#6
It seems very strange to me to want to put data in 9 byte blocks. Firstly it's highly inconvenient, when putting screen data, to break out every 8 bytes for an attribute. FAR better to do all of one, and then the other. Also, this limits your graphics to the colour specified...
Reply
#7
Try this... Attribute is now handed over in sub header
Code:
FUNCTION scrAddress(x as uByte, y as uByte) as Uinteger asm ;' This fn returns the address into HL of the screen address ;' x,y in character grid notation. ;' Original code was extracted by BloodBaz - Adapted for ZX BASiC by Britlion from Na_TH_AN's fourspriter ;' x Arrives in A, y is in stack. and 31 ld l,a ld a,(IX+7) ;' Y value ld d,a and 24 add a,64 ld h,a ld a,d and 7 rrca rrca rrca or l ld l,a end asm END FUNCTION FUNCTION attrAddress(x as uByte, y as uByte) as uInteger ';; This function returns the memory address of the Character Position ';; x,y in the attribute screen memory. ';; Adapted from code by Jonathan Cauldwell - Adapted for ZX BASiC by Britlion from Na_TH_AN's fourspriter asm ld a,(IX+7) ;ypos rrca rrca rrca ;' Multiply by 32 ld l,a ;' Pass to L and 3 ;' Mask with 00000011 add a,88 ;' 88 * 256 = 22528 - start of attributes. ld h,a ;' Put it in the High Byte ld a,l ;' We get y value *32 and 224 ;' Mask with 11100000 ld l,a ;' Put it in L ld a,(IX+5) ;' xpos add a,l ;' Add it to the Low byte ld l,a ;' Put it back in L, and we're done. HL=Address. end asm END FUNCTION sub putchar(x as Ubyte,y as Ubyte,attribute as ubyte,adr as Uinteger) dim scr as uinteger dim attradr as uinteger scr=scrAddress(x,y) attradr=attrAddress(x,y) poke ubyte scr,peek(adr) poke ubyte scr+256,peek(adr+1) poke ubyte scr+512,peek(adr+2) poke ubyte scr+768,peek(adr+3) poke ubyte scr+1024,peek(adr+4) poke ubyte scr+1280,peek(adr+5) poke ubyte scr+1536,peek(adr+6) poke ubyte scr+1792,peek(adr+7) poke ubyte attradr,attribute End sub dim x,y,atr as ubyte dim adr as Uinteger adr=32768 poke 32768,%00000000 poke 32769,%01111110 poke 32770,%01000010 poke 32771,%01010010 poke 32772,%01001010 poke 32773,%01000010 poke 32774,%01111110 poke 32775,%00000000 atr=0 for y=0 to 23 for x=0 to 31 putchar(x,y,atr,adr) atr=atr+1 next x next y
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply
#8
I'll be using a slightly modified version of yours in the game we are currently developing (I need the attribute/ASCII code being supplied as parameters to make everything work together). Credit will be given.

Thanks Smile
Reply
#9
na_th_an Wrote:I'll be using a slightly modified version of yours in the game we are currently developing (I need the attribute/ASCII code being supplied as parameters to make everything work together). Credit will be given.

Thanks Smile
You are welcome! Credits are allways welcome too...

Edit: Functions for Scr/Attr Address calculation are from Britlion.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)