Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 258
» Latest member: manuelzo75
» Forum threads: 1,074
» Forum posts: 6,434

Full Statistics

Online Users
There are currently 295 online users.
» 0 Member(s) | 292 Guest(s)
Applebot, Bing, Google

Latest Threads
.tap file code not execut...
Forum: Help & Support
Last Post: Zoran
04-28-2025, 10:59 AM
» Replies: 4
» Views: 255
Exit from more than one l...
Forum: Wishlist
Last Post: Duefectu
04-23-2025, 10:06 PM
» Replies: 3
» Views: 274
put small ASM programs li...
Forum: How-To & Tutorials
Last Post: Zoran
04-18-2025, 02:02 PM
» Replies: 6
» Views: 1,556
Creating +3 Menus - Loadi...
Forum: Help & Support
Last Post: merlinkv
04-16-2025, 02:08 PM
» Replies: 6
» Views: 528
Randomize not very random...
Forum: Help & Support
Last Post: Zoran
04-08-2025, 10:40 AM
» Replies: 4
» Views: 427
Scope rules
Forum: Bug Reports
Last Post: Zoran
04-04-2025, 09:46 AM
» Replies: 2
» Views: 298
Using constants not allow...
Forum: Bug Reports
Last Post: baltasarq
03-19-2025, 10:00 PM
» Replies: 8
» Views: 1,049
404 page not found
Forum: Documentation
Last Post: boriel
03-08-2025, 07:16 PM
» Replies: 5
» Views: 2,875
Spectrum keywords codes
Forum: Bug Reports
Last Post: boriel
03-08-2025, 11:00 AM
» Replies: 1
» Views: 412
ZXodus][Engine
Forum: ZX Basic Compiler
Last Post: boriel
02-19-2025, 11:43 PM
» Replies: 69
» Views: 213,687

 
  BritLion's Putchars
Posted by: britlion - 06-04-2010, 05:35 PM - Forum: How-To & Tutorials - Replies (39)

LCD play with this.

The question is, this doesn't do attributes right now. How would you want that handled?

1> Assume it's at the end of the data block? (So if you use putchars for one character, it's the 9th byte. For a 2X2 block, it's the 65th, 66th, 67th and 68th...
2> A separate putAttribs function that works the same way
3> Leave it up to the user to do print at y,x, over 1, paper x, ink y;"<space>"

Something else?

I haven't tested mine against yours, I'm just assuming because of code efficiency, this is faster screen handling.
Edit: See below for test results

Edit: Fixed a bug - in BLPutCharNextThird add HL,DE and POP DE were backwards. Thanks to Compiuter for reporting this.

Edit: Shaved a few clock cycles off the graphics printing, and added a paint sub

Edit: Added a paintData sub

Code:
SUB paint (x as uByte,y as uByte, width as uByte, height as uByte, attribute as ubyte)
    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. Change this if you are working with a buffer or somesuch.
    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.
    
    push HL            ; save address
    LD A, (IX+13)      ; attribute
    LD DE,32
    LD c,(IX+11)       ; height
    
    BLPaintHeightLoop:
    LD b,(IX+9)        ; width
    
    BLPaintWidthLoop:
    LD (HL),a          ; paint a character
    INC L              ; Move to the right (Note that we only would have to inc H if we are crossing from the right edge to the left, and we shouldn't be needing to do that)
    DJNZ BLPaintWidthLoop
    
    BLPaintWidthExitLoop:
    POP HL             ; recover our left edge
    DEC C
    JR Z, BLPaintHeightExitLoop
    
    ADD HL,DE          ; move 32 down
    PUSH HL            ; save it again
    JP BLPaintHeightLoop

    BLPaintHeightExitLoop:
    
    end asm
END SUB

SUB paintData (x as uByte,y as uByte, width as uByte, height as uByte, address as uInteger)
    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. Change this if you are working with a buffer or somesuch.
    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.
    
    push HL            ; save address
    LD D, (IX+13)
    LD E, (IX+12)
    LD c,(IX+11)       ; height
    
    BLPaintDataHeightLoop:
    LD b,(IX+9)        ; width
    
    BLPaintDataWidthLoop:
    LD a,(DE)
    LD (HL),a          ; paint a character
    INC L              ; Move to the right (Note that we only would have to inc H if we are crossing from the right edge to the left, and we shouldn't be needing to do that)
    INC DE
    DJNZ BLPaintDataWidthLoop
                        
    
    BLPaintDataWidthExitLoop:
    POP HL             ; recover our left edge
    DEC C
    JR Z, BLPaintDataHeightExitLoop
    PUSH DE
    LD DE,32
    ADD HL,DE          ; move 32 down
    POP DE
    PUSH HL            ; save it again
    JP BLPaintDataHeightLoop

    BLPaintDataHeightExitLoop:
    
    end asm
END SUB  
    
    SUB putChars(x as uByte,y as uByte, width as uByte, height as uByte, dataAddress as uInteger)
    asm
    BLPutChar:
             LD      a,(IX+5)
             ;AND     31
             ld      l,a
             ld      a,(IX+7) ; Y value
             ld      d,a
             AND     24
             add     a,64 ; 256 byte "page" for screen - 256*64=16384. Change this if you are working with a screen address elsewhere, such as a buffer.
             ld      h,a
             ld      a,d
             AND     7
             rrca
             rrca
             rrca
             OR      l
             ld      l,a

    PUSH HL ; save our address

    LD E,(IX+12) ; data address
    LD D,(IX+13)
    LD B,(IX+9) ; width
    PUSH BC ; save our column count

    BLPutCharColumnLoop:

    LD B,(IX+11) ; height

    BLPutCharInColumnLoop:
  
    ; gets screen address in HL, and bytes address in DE. Copies the 8 bytes to the screen
    ld a,(DE) ; First Row
    LD (HL),a
    
    INC DE
    INC H
    ld a,(DE)
    LD (HL),a ; second Row
    
    INC DE
    INC H
    ld a,(DE)
    LD (HL),a ; Third Row
    
    INC DE
    INC H
    ld a,(DE)
    LD (HL),a ; Fourth Row
    
    INC DE
    INC H
    ld a,(DE)
    LD (HL),a ; Fifth Row
    
    INC DE
    INC H
    ld a,(DE)
    LD (HL),a ; Sixth Row
    
    INC DE
    INC H
    ld a,(DE)
    LD (HL),a ; Seventh Row
    
    INC DE
    INC H
    ld a,(DE)
    LD (HL),a ; Eigth Row
    
    INC DE ; Move to next data item.
    
    DEC B
    JR Z,BLPutCharNextColumn
    ;The following code calculates the address of the next line down below current HL address.
    PUSH DE ; save DE
             ld   a,l  
             and  224  
             cp   224  
             jp   z,BLPutCharNextThird

    BLPutCharSameThird:
             ld   de,-1760
             ;and  a        
             add  hl,de      
             POP DE ; get our data point back.
             jp BLPutCharInColumnLoop

    BLPutCharNextThird:
             ld   de,32      
             ;and  a
             add  hl,de  
             POP DE ; get our data point back.
    JP BLPutCharInColumnLoop

    BLPutCharNextColumn:
    POP BC
    POP HL
    DEC B
    JP Z, BLPutCharsEnd

    INC L   ; Note this would normally be Increase HL - but block painting should never need to increase H, since that would wrap around.
    PUSH HL
    PUSH BC
    JP BLPutCharColumnLoop

BLPutCharsEnd:
    end asm

    END SUB

    goto start

    datapoint:
asm
defb 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
defb 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
defb 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
defb 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
end asm

    start:
    cls
    putChars(10,10,3,3,@datapoint)
    paint(10,10,3,3,79)

Print this item

  New beta release 1.2.6r1603
Posted by: boriel - 06-03-2010, 11:37 PM - Forum: Bug Reports - Replies (3)

Hi

This beta release, 1.2.6r1603 adds the following:

  • #preprocessor directives into ASM BLOCKS are allowed again.
  • New command-line option, --enable-break that will make your program stoppable pressing BREAK (as in BASIC). This might be useful for debugging purposes, as the ROM error message will print the source line where break was pressed.
  • For loops scheme is now 10 T-states faster per loop.
  • PLOT, DRAW and CIRCLE are now 1% faster (better than nothing).
  • Array accesses are now 50-100% faster (thanks to Britlion for suggesting this).
  • Multi-line comments /' ... '/ now allowed (see Wiki), and also line comments after line break

If interested, please, download as always at <!-- m --><a class="postlink" href="http://www.boriel.com/files/zxb">http://www.boriel.com/files/zxb</a><!-- m -->
Intensive testing is needed.

Print this item

  Assembler shortcut
Posted by: britlion - 06-03-2010, 05:45 PM - Forum: Wishlist - Replies (1)

Not sure where else to put this - Not really a bug, per se, as an efficiency; I mentioned it elsewhere but I think it got lost.

With a sub that pokes memory based on labels:

eg:

Code:
SUB pokethis(data as uByte)
poke @label+1,data
return

label:
asm
LD A,00
end asm

Seems to produce assembler that does this:
Code:
ld hl, __LABEL__BLPutCharHeight
inc hl

Can the compiler not shortcut that to
Code:
ld hl, __LABEL__BLPutCharHeight+N ?
and work out at assembly time where that should be, thus producing shorter and faster code for what is, after all, a constant?

(or is there something clever in the optimizer that spots that sort of thing - load followed by incs or fixed adds?)

Print this item

  Unnecessary Push/Pop
Posted by: britlion - 06-03-2010, 05:41 PM - Forum: Bug Reports - Replies (3)

Not sure why the .asm ends up this way, but each time it pulls a parameter in a sub or function it seems to do this:

Code:
push hl
ld a, (ix+11)
pop hl

Why stack the HL register before loading the A register each time, and then unstack it immediately afterwards?

Print this item

  SyntaxError: invalid syntax in zxb.py (Resolved)
Posted by: ccowley - 06-03-2010, 12:13 PM - Forum: Help & Support - Replies (2)

I've just downloaded ZX BASIC from the zxbasic-latest-version.zip link to give it a try. I have Python 3.1.2 installed on a Windows 7 box.

Running zxb.py gives the following error:-

Code:
File "C:\Users\Chris\speccy\zxbasic\zxb.py", line 60
    print m # IGNORE # line directives as PASMO does not support them
          ^
SyntaxError: invalid syntax

I guess I must be doing something wrong, but what?

EDIT: Resolved. I uninstalled Python 3.1.2 and installed Python 2.6 instead. The zxbasic website says "you will need the python interpreter version 2.5 or higher installed on your system" - this should probably be amended to point out to non-python programmers (like me) that actually Python 3.x is no good as it's not backwardly compatible with v2.x.

Print this item

  Using PutcharLcd
Posted by: compiuter - 06-02-2010, 10:42 PM - Forum: How-To & Tutorials - Replies (8)

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
'-----------------------------------------

Print this item

  Proportional pixel-precise printing anywhere on screen
Posted by: LCD - 06-02-2010, 01:11 PM - Forum: How-To & Tutorials - Replies (5)

Finally it works now and does not crash in a SUB. I love this routine! It will be included in BorIDE code library.

Code:
' Proportional printing anywhere on screen.
' Original routine by Christoph Odenthal (Odin)
' ZXBC modification by Leszek Chmielewski (LCD)
' Thanks to Boriel and Britlion for help and hints

dim text$
text$="This is a test for ZX Spectrum proportional print!"
dim x as ubyte
dim y as ubyte
dim spacesize as ubyte
dim xgap as ubyte

x=0
y=168
spacesize=2
xgap=0

propprint(x,y,spacesize,xgap,text$)

sub propprint(x as ubyte,y as ubyte,spacesize as ubyte, xgap as ubyte,txt$ as string)
dim b$ as string '
b$=txt$+chr(0)
poke Uinteger @PropPrintTxtadr,PEEK(Uinteger, @b$)+2 'textadr
poke @PropPrintTxtadr+2,x
poke @PropPrintTxtadr+3,y
poke @PropPrintTxtadr+4,spacesize
poke @PropPrintTxtadr+5,xgap
PropPrint:
Asm
;' --------------------------------
;'  Free Size N Place Text Print
;' --------------------------------
;' (c) 14.09.2002 C.Odenthal
;'
;' Last Modifications: 15.10.2002
;' Modification for Boriels ZXBC
;' By Leszek Chmielewski 02.06.2010
;' --------------------------------
;' ORG 32000
;' DUMP 45000
;' --------------------------------
;' Entry point
;' --------------------------------
Start:
    JR Start2
;' --------------------------------
;' Parameter
;' --------------------------------
end asm
PropPrintTxtadr:
asm
text_addr:
   DEFW 0 ;' Addr of text
x_pos:
   DEFB 4 ;' Pos of text
y_pos:
   DEFB 4
spc_size:
   DEFB 3 ;' Width of space char
x_gap:
   DEFB 1 ;' Gap between chars
y_gap:
   DEFB 1 ;' Gap between lines
end_symb:
   DEFB 0 ;' End of line char code
x_start:
   DEFB 0 ;' Start of window
y_start:
   DEFB 0
x_end:
   DEFB 255 ;' End of window
y_end:
   DEFB 191
x_zoom:
   DEFB 1 ;' Zooming factor
y_zoom:
   DEFB 1

;' --------------------------------
;' Main routine
;' --------------------------------

Start2:
   LD A,(x_pos) ;' Calc. scr addr.
   LD B,A
   LD A,(y_pos)
   LD C,A
   CALL PosToScr
   LD (scr_ad),DE ;' Store scr addr.
   LD A,L
   LD (pix_pos),A
   LD A,(end_symb) ;' Get line ending char
   LD (poke_here+1),A ;' Poke it into memory below
   LD HL,(text_addr)
Main_Loop:
   LD A,(HL);' Get char
poke_here:
   CP 0 ;' End of text? (poked!)
   JP Z,Exit1
   INC HL
   PUSH HL
   CP 32 ;' Replace ctrl chars
   JP NC,No_Ctrl
   LD A,32
No_Ctrl:
   CALL Copy_Chr ;' Copy char-gfx to work-buffer
   CALL Measure ;' Measure left rim + width
   PUSH BC ;' (Save results)
   LD A,C ;' No pixel set in char?
   AND A
   JP Z,Space_Chr
   LD A,(pix_pos);' size+bitpos (=1..15)
   ADD A,C
   CP 9 ;' > 8 ?
   JP NC,Overlap ;' Char overlaps
;' Calculate 8 bit rotation
   LD A,(pix_pos) ;' bitpos-l_rim (=-7..7)
   SUB B
   AND A ;' = 0 ?
   JP Z,PrintIt8
   JP C,Neg_8 ;' < 0 ?
;' --------------------------------
   CP 5 ;' Not in 1..4 ?
   JP NC,Left_8
;' --------------------------------
   LD B,A
   CALL Chr_Rgt8 ;' Rotate right 8 bit
   JP PrintIt8
;' --------------------------------
Left_8:
   NEG ;' = 8 - A
   ADD A,8
   LD B,A
   CALL Chr_Left8 ;' Rotate left 8 bit
   JP PrintIt8
;' --------------------------------
Neg_8:
   NEG
   CP 5 ;' Not in 1..4 ?
   JP NC,Right_8
;' --------------------------------
   LD B,A
   CALL Chr_Left8 ;' Rotate left 8 bit
   JP PrintIt8
;' --------------------------------
Right_8:
   NEG ;' = 8 - A
   ADD A,8
   LD B,A
   CALL Chr_Rgt8 ;' Rotate right 8 bit
   JP PrintIt8
;' --------------------------------
;' Calculate 16 bit rotation
;' --------------------------------
Overlap:
   LD A,(pix_pos);' bitpos-l_rim (=-7..7)
   SUB B
   AND A ;' = 0 ?
   JP Z,PrintIt8
;' --------------------------------
   LD B,A
   CALL Chr_Rgt16 ;' Rotate right 16 bit
PrintIt16:
   LD DE,(scr_ad);' Check for screen end
   LD A,E
   AND 31
   CP 31 ;' (2nd byte outside ?)
   JP Z,Outside
   CALL Print16 ;' Display char (16 bit)
   JP Next_Loc
;' --------------------------------
PrintIt8:
   LD DE,(scr_ad);' Display char (8 bit)
   CALL Print8
   JP Next_Loc
;' --------------------------------
Space_Chr:
   LD A,(spc_size);' Skip pixels
   LD DE,(scr_ad);' Get screen addr.
   POP BC ;' Throw away values
   LD B,0
   LD C,A
   JP Next_Loc2
;' --------------------------------
Next_Loc:
   POP BC ;' Move to next char location
Next_Loc2:
   LD A,(pix_pos);' =bitpos+x_gap+size
   LD L,A
   LD A,(x_gap)
   ADD A,L
   ADD A ,C
   LD L ,A
   AND 7 ;' New pix_pos
   LD (pix_pos),A
   LD H,0 ;' =result/8
   SRL L
   SRL L
   SRL L
   ADD HL,DE ;' New byte pos
   LD A ,E ;' Check for screen end
   AND 31
   LD E,A
   LD A,L
   AND 31
   CP E ;' New pos smaller than old ?
   JP C ,Exit2 ;' -> End of printing
   LD (scr_ad),HL ;' Store new scr ad.
   POP HL ;' Restore text pointer
   JP Main_Loop
;' --------------------------------
Outside:
   POP BC ;' Stop printing
   POP HL ;' Char not printed!
   DEC HL
   JP Exit1
;' --------------------------------
Exit2:
   POP HL ;' Return nr of printed chars
Exit1:
   LD DE,(text_addr)
   XOR A
   SBC HL,DE
   LD B,H ;' Return value in BC to Basic
   LD C,L
     jp PropPrintTxtadr2
;' --------------------------------
;' Calc. scr adr from x,y
;' --------------------------------
;' In : B  = x / C = y (preserved)
;' Out: DE = scr adr / L = pixpos
;' Usd: A, BC, DE, L
;' --------------------------------
PosToScr:
   LD A,C ;' Range check
   CP 185
   JP C,ValOk
   LD C,184
ValOk:
   LD A,B ;' Pix pos
   AND 7
   LD L,A
   LD E,B
   SRL E
   SRL E
   SRL E
   LD A,C ;' Scr pos
   AND 7
   LD D,A
   LD A,C
   AND 56
   RLA
   RLA
   OR E
   LD E,A
   LD A,C
   AND 192
   RRA
   RRA
   RRA
   OR D
   OR 64
   LD D,A
   RET
;' --------------------------------
;' Copy char into buffer
;' --------------------------------
;' In : A = Char
;' Out: -
;' Usd: A, HL, DE, BC
;' --------------------------------
Copy_Chr:
   LD DE,(23606);' SysVar CHARS
   LD H,0
   LD L,A
   ADD HL,HL ;' * 8
   ADD HL,HL
   ADD HL,HL
   ADD HL,DE ;' + Chartable
   EX DE,HL
   LD HL,Chr_Buf
   LD B,8
Copy_Loop:
   LD A,(DE);' Double to 16 pixel/row
   INC DE
   LD (HL),A ;' Low-byte in memory!
   INC HL
   LD (HL),0 ;' High-byte in memory!
   INC HL
   DJNZ Copy_Loop
   RET
;' --------------------------------
;' Measure left border and width
;' --------------------------------
;' In : -
;' Out: B = left rim / C = width
;' Usd: A, HL, BC
;' --------------------------------
Measure:
   LD HL,Chr_Buf ;' "OR" together all 8 bytes
   LD B,8
   XOR A
Msr_Loop:
   OR (HL)
   INC HL
   INC HL
   DJNZ Msr_Loop
   LD BC,0
   AND A ;' Check if zero
   RET Z
Msr_Loop2:
   INC B ;' Measure left border
   RLCA
   JP NC,Msr_Loop2
   RRCA
   DEC B
   LD C,9 ;' Measure width
Msr_Loop3:
   DEC C
   RRCA
   JP NC,Msr_Loop3
   RET
;' --------------------------------
;' Move char to left, 8 bit
;' --------------------------------
;' In : B = Nr of bits to shift
;' Out: -
;' Usd: A, B, HL
;' --------------------------------
Chr_Left8:
   PUSH BC
   LD HL,Chr_Buf ;' Rotate char left 8 bit
   LD C,B ;' 1st row
   LD A,(HL )
Chr_LLp1:
   RLCA
   DJNZ Chr_LLp1
   LD (HL),A
   LD B,C
   INC HL
   INC HL
   LD C,B ;' 2nd row
   LD A,(HL)
Chr_LLp2:
   RLCA
   DJNZ Chr_LLp2
   LD (HL),A
   LD B,C
   INC HL
   INC HL
   LD C,B ;' 3rd row
   LD A ,(HL)
Chr_LLp3:
   RLCA
   DJNZ Chr_LLp3
   LD (HL),A
   LD B,C
   INC HL
   INC HL
   LD C,B ;' 4th row
   LD A,(HL)
Chr_LLp4:
   RLCA
   DJNZ Chr_LLp4
   LD (HL),A
   LD B,C
   INC HL
   INC HL
   LD C,B ;' 5th row
   LD A,(HL)
Chr_LLp5:
   RLCA
   DJNZ Chr_LLp5
   LD (HL),A
   LD B,C
   INC HL
   INC HL
   LD C,B ;' 6th row
   LD A,(HL)
Chr_LLp6:
   RLCA
   DJNZ Chr_LLp6
   LD (HL),A
   LD B,C
   INC HL
   INC HL
   LD C,B ;' 7th row
   LD A,(HL)
Chr_LLp7:
   RLCA
   DJNZ Chr_LLp7
   LD (HL),A
   LD B,C
   INC HL
   INC HL
   LD C,B ;' 8th row
   LD A,(HL)
Chr_LLp8:
   RLCA
   DJNZ Chr_LLp8
   LD (HL),A
   LD B,C
   POP BC
   RET
;' --------------------------------
;' Move char to right, 8 bit
;' --------------------------------
;' In : B = Nr of bits to shift
;' Out: -
;' Usd: A, B, HL
;' --------------------------------
Chr_Rgt8:
   PUSH BC
   LD HL,Chr_Buf ;' Rotate char right 8 bit
   LD C,B ;' 1st row
   LD A,(HL)
Chr_RLp1:
   RRCA
   DJNZ Chr_RLp1
   LD (HL),A
   LD B,C
   INC HL
   INC HL
   LD C,B ;' 2nd row
   LD A,(HL)
Chr_RLp2:
   RRCA
   DJNZ Chr_RLp2
   LD (HL),A
   LD B,C
   INC HL
   INC HL
   LD C,B ;' 3rd row
   LD A,(HL)
Chr_RLp3:
   RRCA
   DJNZ Chr_RLp3
   LD (HL),A
   LD B,C
   INC HL
   INC HL
   LD C,B ;' 4th row
   LD A,(HL)
Chr_RLp4:
   RRCA
   DJNZ Chr_RLp4
   LD (HL),A
   LD B,C
   INC HL
   INC HL
   LD C,B ;' 5th row
   LD A,(HL)
Chr_RLp5:
   RRCA
   DJNZ Chr_RLp5
   LD (HL),A
   LD B,C
   INC HL
   INC HL
   LD C,B ;' 6th row
   LD A ,(HL )
Chr_RLp6:
   RRCA
   DJNZ Chr_RLp6
   LD (HL),A
   LD B,C
   INC HL
   INC HL
   LD C,B ;' 7th row
   LD A,(HL)
Chr_RLp7:
   RRCA
   DJNZ Chr_RLp7
   LD (HL),A
   LD B,C
   INC HL
   INC HL
   LD C,B ;' 8th row
   LD A,(HL)
Chr_RLp8:
   RRCA
   DJNZ Chr_RLp8
   LD (HL),A
   LD B,C
   POP BC
   RET
;' --------------------------------
;' Move char to right 16 bit
;' --------------------------------
;' In : B = Nr of bits to shift
;' Out:
;' Usd: A, B, HL
;' --------------------------------
Chr_Rgt16:
   LD HL,(Chr_Buf);' Rotate char right 16 bit
   LD A,B ;' 1st row
Chr_R2Lp1:
   SRL L
   RR H ;' Insert carry
   DJNZ Chr_R2Lp1
   LD B,A
   LD (Chr_Buf),HL
   LD HL,(Chr_Buf+2);' 2nd row
   LD A,B
Chr_R2Lp2:
   SRL L
   RR H ;' Insert carry
   DJNZ Chr_R2Lp2
   LD B,A
   LD (Chr_Buf+2),HL
   LD HL,(Chr_Buf+4);' 3rd row
   LD A,B
Chr_R2Lp3:
   SRL L
   RR H ;' Insert carry
   DJNZ Chr_R2Lp3
   LD B,A
   LD (Chr_Buf+4),HL
   LD HL,(Chr_Buf+6);' 4th row
   LD A,B
Chr_R2Lp4:
   SRL L
   RR H ;' Insert carry
   DJNZ Chr_R2Lp4
   LD B,A
   LD (Chr_Buf+6),HL
   LD HL,(Chr_Buf+8);' 5th row
   LD A,B
Chr_R2Lp5:
   SRL L
   RR H ;' Insert carry
   DJNZ Chr_R2Lp5
   LD B,A
   LD (Chr_Buf+8),HL
   LD HL,(Chr_Buf+10);' 6th row
   LD A,B
Chr_R2Lp6:
   SRL L
   RR H ;' Insert carry
   DJNZ Chr_R2Lp6
   LD B,A
   LD (Chr_Buf+10),HL
   LD HL,(Chr_Buf+12);' 7th row
   LD A,B
Chr_R2Lp7:
   SRL L
   RR H ;' Insert carry
   DJNZ Chr_R2Lp7
   LD B,A
   LD (Chr_Buf+12),HL
   LD HL,(Chr_Buf+14);' 8th row
   LD A,B
Chr_R2Lp8:
   SRL L
   RR H ;'Insert carry
   DJNZ Chr_R2Lp8
   LD B,A
   LD (Chr_Buf+14),HL
   RET
;' --------------------------------
;' Print 8 bit wide char on screen
;' --------------------------------
;' In : DE = screen adr.
;' Out: -
;' Usd: A, HL, DE, B
;' --------------------------------
Print8:
   LD HL,Chr_Buf
   PUSH DE ;' save scr ad.
   EX DE,HL
   LD B,8 ;' 8 lines
Prt8_L:
   LD A,(DE);' set 1 byte
   XOR (HL)
   LD (HL),A
   INC DE ;' skip 1 byte
   INC DE ;' next byte
   INC H ;' calc. next line
   LD A,H
   AND 7
   JP NZ,Prt8_C
   LD A,L
   ADD A,32
   LD L,A
   JR C,Prt8_C
   LD A,H
   SUB 8
   LD H,A
Prt8_C:
   DJNZ Prt8_L ;' next round
   POP DE ;' restore scr ad.
   RET
;'--------------------------------
;' Print 16 bit wide char on screen
;' --------------------------------
;' In : DE = screen adr.
;' Out: -
;' Usd: A, HL, DE, B
;' --------------------------------
Print16:
   LD HL,Chr_Buf
   PUSH DE ;' save scr ad.
   EX DE,HL
   LD B,8 ;' 8 lines
Prt16_L:
   LD A,(DE);' set 1 byte
   XOR (HL)
   LD (HL),A
   INC HL ;' next scr pos
   INC DE ;' next byte
   LD A,(DE);' set 1 byte
   XOR (HL)
   LD (HL),A
   DEC HL ;' prev scr pos
   INC DE ;' next byte
   INC H ;' calc. next line
   LD A,H
   AND 7
   JP NZ,Prt16_C
   LD A,L
   ADD A,32
   LD L,A
   JR C,Prt16_C
   LD A,H
   SUB 8
   LD H,A
Prt16_C:
   DJNZ Prt16_L ;' next round
   POP DE ;' restore scr ad.
   RET
;' --------------------------------
;'  Variables
;' --------------------------------
Chr_Buf:
   DEFS 16
scr_ad:
   DEFW 0
pix_pos:
   DEFB 0
;' -----------------
PropPrintTxtadr2:
end asm
end sub

Print this item

  POKE STRING and @string$
Posted by: LCD - 06-01-2010, 11:30 PM - Forum: Help & Support - Replies (17)

Just converted the Proportional text routine to a SUB, so it won't crash at exit, but I ran into some problems.
I remember, I asked about it, but the thread was closed then, but you promised to look at this: POKE and PEEK STRING do not work, and something else: @a$ does not return the correct adress of the string stored in a$. It returns a adress, but peeking memory in emulator reveals that the text stored in string is not at the adress. Testing @variable reveals that the adress of normal ubyte variables is correct.
Is this a bug or "feature"? If it is a feature, how to find out the adress of a string stored in Variable?

Print this item

  Compiler Returncode
Posted by: LCD - 05-31-2010, 05:57 PM - Forum: Wishlist - Replies (11)

Hi Boriel, I have noticed that your compiler exits with returncode Zero if no errors was found, One if Errors found, but also One if a warning was generated, and the compilation was otherwise successfull. Can you change this?
0=No errors
1=Warnings, compilation was OK.
2=Error, compilation failed
Or:
0=No Errors or just warnings
1=Error, compilation failed.
The BorIDE does now mark Warning and error lines. It can start the emulator after compilation, but if a warning was issued, it still missinterprets it as compilation fail.

Print this item

  PutTile16x16 Pixels + Attributes
Posted by: LCD - 05-29-2010, 10:12 AM - Forum: How-To & Tutorials - Replies (26)

This will put Tiles of 2x2 characters with attributes on screen, and is not restricted to use a particular number of tiles, as it uses a memory pointer to the adress of tile in memory, and it is almost fast enough for games (until someone will write a ASM version)
Note: Lines(23) is used for screen adress calculation. I used only 24 bytes for this table (without bAND function I need a Table for this). not using a array but InLine ASM DEFB data can save 3 bytes.
POKE and PEEK UINTEGER use two-Byte transfer, so this is much faster than transfer of a single byte.
Screen adress calculation is splited (so variable A had to be created) because of a calculation problem. Usualy I would write these lines:

Code:
a=peek(@lines+y+3)
scr=(a<<5)+x+16384
as:
Code:
scr=peek(@lines+y+3)<<5+x+16384
but it does not work (yet)
also if y is not uinteger but ubyte type, scr value is calculated wrong, so even if y is in range of ubyte, do not change it as binary shifts on Ubyte also results in a ubyte.

Code:
Dim lines(23) As uByte => { _
    0,1,2,3,4,5,6,7,64,65,66,67,68,69,70,71,128,129,130,131,132,133,134,135 }
sub puttile(x as Uinteger,y as Uinteger,adr as Uinteger)
    dim scr as Uinteger
    dim a as Uinteger
    a=peek(@lines+y+3)
    scr=(a<<5)+x+16384
    poke Uinteger scr,peek(Uinteger,adr)
    poke Uinteger scr+256,peek(Uinteger,adr+2)
    poke Uinteger scr+512,peek(Uinteger,adr+4)
    poke Uinteger scr+768,peek(Uinteger,adr+6)
    poke Uinteger scr+1024,peek(Uinteger,adr+8)
    poke Uinteger scr+1280,peek(Uinteger,adr+10)
    poke Uinteger scr+1536,peek(Uinteger,adr+12)
    poke Uinteger scr+1792,peek(Uinteger,adr+14)
    poke Uinteger 22528+x+(y<<5),peek(Uinteger,adr+32)
    a=peek(@lines+y+4)
    scr=(a<<5)+x+16384
    poke Uinteger scr,peek(Uinteger,adr+16)
    poke Uinteger scr+256,peek(Uinteger,adr+18)
    poke Uinteger scr+512,peek(Uinteger,adr+20)
    poke Uinteger scr+768,peek(Uinteger,adr+22)
    poke Uinteger scr+1024,peek(Uinteger,adr+24)
    poke Uinteger scr+1280,peek(Uinteger,adr+26)
    poke Uinteger scr+1536,peek(Uinteger,adr+28)
    poke Uinteger scr+1792,peek(Uinteger,adr+30)
    poke Uinteger 22560+x+(y<<5),peek(Uinteger,adr+34)
End sub

dim x,y as ubyte
dim adr as Uinteger
adr=0
for y=0 to 11
    for x=0 to 15
        puttile(x<<1,y<<1,adr)
        'adr=adr+36
    next x
next y
end

Print this item