SCREEN1 = SYSVAR @ JSROM

Anything QL Software or Programming Related.
tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: SCREEN1 = SYSVAR @ JSROM

Post by tcat »

Hi,

This is functional Bresenham algo for Line, I coded for Oberon system.

Code: Select all

  PROCEDURE Line*(col, x, y, x0, y0, mode: INTEGER);
    VAR w, h, x1, y1, d, u: INTEGER;
  BEGIN
    w := x0-x; h := y0-y;
    IF w >= 0 THEN IF h >= 0 THEN (*north-east*) d := 1 ELSE (*south-east*) d := -1; u := y0; y0 := y; y := u END
    ELSIF (*w < 0*) h >= 0 THEN (*north-west*) d := -1; u := x0; x0 := x; x := u 
    ELSE (*south-west*) d := 1; u := x0; x0 := x; x := u; u := y0; y0 := y; y := u END ;
    w := ABS(w); h := ABS(h);
    IF w = 0 THEN (*D.*)ReplConst(col, x, y, 1, h, mode)
    ELSIF h = 0 THEN (*D.*)ReplConst(col, x, y, w, 1, mode)
    ELSIF h < w THEN x1 := x+w; u := (h-w) DIV 2;
      IF d = -1 THEN INC(y, h) END ;
      WHILE x < x1 DO
        Dot(col, x, y, mode); INC(x);
        IF u < 0 THEN INC(u, h) ELSE INC(u, h-w); INC(y, d) END
      END
    ELSE (*h > w*) y1 := y+h; u := (w-h) DIV 2;
      IF d = -1 THEN INC(x, w) END ;
      WHILE y < y1 DO
        Dot(col, x, y, mode); INC(y);
        IF u < 0 THEN INC(u, w) ELSE INC(u, w-h); INC(x, d) END
      END
    END
  END Line;
I have now tried to recode in assembly, one quadrant only, EDIT actually one octant.
Bresenham Line algo
Bresenham Line algo
My assembly follows the above closely, in effort to avoid errors, I use same vars, where possibly stack should be used instead. Comparing my code to `DRAW' in `DIY Toolkit' leaves a lot room for optimisation, simply cannot get it that short so far.

Code: Select all

line     lea      vars,a1           ;save vars
         move.w   d1,(a1)+          ;x
         move.w   d2,(a1)+          ;y
         move.w   d3,(a1)+          ;col
         move.w   d4,(a1)+          ;x0
         move.w   d5,(a1)+          ;y0
         move.w   #1,10(a1)         ;d=1, south-east quadrant
         sub.w    d1,d4             ;d4=x0-x, width
         sub.w    d2,d5             ;d5=y0-y, height
         move.w   d4,(a1)           ;w=d4
         move.w   d5,2(a1)          ;h=d5
         add.w    d1,d4             ;d4=x+w
         move.w   d4,4(a1)          ;x1=d4
         move.w   (a1),d4           ;d4=w
         sub.w    d4,d5             ;d5=h-w
         asr.w    #1,d5             ;d5=(h-w)/2
         move.w   d5,8(a1)          ;u=d5
         lea      vars,a1           ;restore vars
loop     move.w   (a1),d1           ;d1=x
         move.w   2(a1),d2          ;d2=y
         move.w   4(a1),d3          ;d3=col
         move.w   14(a1),d4         ;d4=x1
         cmp.w    d1,d4             ;x>=x1?
         bls.s    exit              ;yes, exit
         bsr      plot4             ;put pixel at x,y,col=0,2,4,6
         addq.w   #1,(a1)           ;x=x+1
         move.w   12(a1),d5         ;d5=h
         tst.w    18(a1)            ;u<0?
         bpl.s    uplus             ;no, uplus
uminus   add.w    d5,18(a1)         ;u=u+h, yes uminus
         bra.s    loop
uplus    move.w   10(a1),d4         ;d4=w
         sub.w    d4,d5             ;d5=h-w
         add.w    d5,18(a1)         ;u=u+h-w
         move.w   20(a1),d4         ;d4=d
         add.w    d4,2(a1)          ;y=y+d
         bra.s    loop

; All complete
exit     clr.l    d0                ;No error code
         rts                        ;Return to BASIC

; Variables
vars
x        ds.w     1                 ;$00
y        ds.w     1                 ;$02
col      ds.w     1                 ;$04
x0       ds.w     1                 ;$06
y0       ds.w     1                 ;$08
w        ds.w     1                 ;$0a
h        ds.w     1                 ;$0c
x1       ds.w     1                 ;$0e
y1       ds.w     1                 ;$10
u        ds.w     1                 ;$12
d        ds.w     1                 ;$14
         dc.w     1

         end
Tomas


tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: SCREEN1 = SYSVAR @ JSROM

Post by tcat »

Hi,

This is what I have coded so far. With BLOCK I can attempt circle fill, elipse fill, sort of scan line fill. Line being more complicated code, cannot get it short so far.
How do I set stipple colour in assembly?

Code: Select all


; Simple graph primitives mode 4/8
; ===================================
; (c)2019 tcat <thomas.kral@email.cz>
; version 1.0

; From CALL in SuperBASIC

; PLOT    - CALL [start],[x],[y],[col]
; MODE    - CALL [start+2],[mode]
; BLOCK   - CALL [start+4],[x],[y],[col],[w],[h]
; LINE    - CALL [start+8],[x],[y],[col],[x0],[y0]
; CIRCLE  - CALL [start+12],[x],[y],[col],[r]
; on entry        D1=X, D2=Y, D4=X0, D5=Y0
;                 D1=0,8 mode 4/8 (bit3)
;                 D4=width, D5=height
;                 D3=Colour, D4=radius
; on exit         [start+16].L=debug output

; NOTE 
; QL screen is organised by words in 4/8 modes
; 512x256, 8 pixels per word, 128/64 bytes/words per line
; 256x256, 4 pixels per word, ditto
; Routines tested under SuperBASIC, to be later run without QDOS
;  making use of 2nd VRAM, requires real QL h/w, may not work emulated

start    bra.s    plot              ;$00
         bra.s    mode              ;$02
         bra      block             ;$04
         bra      line              ;$08
         bra      circle            ;$0c
out      ds.l     1                 ;$10
dctl     dc.b     %00000000         ;Display control copy
         ;bit7=$20000/$28000
         ;bit3=mode4/8
         ;bit1=blank

...
Tomas


User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: SCREEN1 = SYSVAR @ JSROM

Post by NormanDunbar »



Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: SCREEN1 = SYSVAR @ JSROM

Post by tcat »

Hi,

Yes a little. However, I may need for plain QDOS w/ no GD2 colour map. I realised I somehow miss the trick QDOS makes. In SuperBASIC, some commands take colour as three attributes, background, constrast(XOR), stipple. Can be also entered as a single byte.

Now what tricks we play at machine code level to achieve above?

Many thanks.
Tomas


User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: SCREEN1 = SYSVAR @ JSROM

Post by NormanDunbar »

From Jan Jones:

COMPOSITE

In order to pass the colour information to QDOS, SuperBASIC has to combine the three components into one composite colour. The composite colour is one byte long:

Bit Value
0 1 Bit pattern of main colour
1 2
2 4
3 8 Bitwise XOR of main colour with contrast colour.
4 16
5 32
6 64 Bit pattern of stipple
7 128

So, to get the numerical value of a composite colour,

From zero, add 1 if main colour contains blue + 2 if main colour contains red + 4 if main colour contains green.

Then add 8 if contrast is different by blue + 16 if contrast is different by red + 32 if contrast is different by green.

Finally add 0 for dots or 64 for horizontal stripes or 128 for vertical stripes or 192 for checks.

For example, green and white horizontal stripes is 01 011 100 64 + 16 + 8 + 4 = 92
Horizontal stripes 111 ^ ^ 100 (white) (green)
Green Yellow with black dots is 00 110 110 32 + 16 + 4 + 2 = 54 dots 000 ^ ^ 110 (black) (yellow) yellow

Or, working backwards, from colour 147 = 128 + 16 + 2 + 1 = 10010011 Main colour is 011 = magenta Contrast is 010 ^ ^ 011 = 001 = blue Stipple is 10 = vertical stripes

You can, of course, generate this composite colour for yourself as long as you use it as a single colour parameter only. After a little thought and experiment, you can achieve some truly terrible colours!


HTH.

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: SCREEN1 = SYSVAR @ JSROM

Post by tcat »

Hi Norm,

Thank you, this explains that nicely.

2-bit colour, 8 pixels per screen word, mode 4 = 512 pixels on line
GR (no B)

Code: Select all

7654321076543210
GGGGGGGGRRRRRRRR
3-bit colour, 4 pixels per screen word, mode 8 = 256 pixels on line
GRB + Flash

Code: Select all

7654321076543210
GFGFGFGFRBRBRBRB
So I have 2 or 3 bits maximum, to write to display buffer for a single pixel, composite colour takes 7 bits per pixel. Apologies, it is still not clear as where do I write those extra 4 bits in assembly to get stipple XOR colour for a pixel?

Later I wish to to draw to both screens{1,2}, with QDOS dissabled, when the SuperBASIC interpreter is stopped.

Many thanks so far
Tomas


User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: SCREEN1 = SYSVAR @ JSROM

Post by NormanDunbar »

Hi Tomas,

The composite colours are sent to the traps to change the paper/ink/strip.

It looks like you are trying to plot pixels directly into the screen RAM. In which case, you would need to work out the required dot pattern and colours, then plot those pixels.

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: SCREEN1 = SYSVAR @ JSROM

Post by tcat »

Hi,

I wish to code character printing routine. An uneasy task so it seems. I believe it should take an ascii code of the character to be printed, x y origin, colour, and a pointer to font structure.

How do we define QL fonts?
Are they fixed width, or variable, so each char defines its width?

Many thanks
Tomas


User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: SCREEN1 = SYSVAR @ JSROM

Post by tofro »

tcat wrote:Hi,

I wish to code character printing routine. An uneasy task so it seems. I believe it should take an ascii code of the character to be printed, x y origin, colour, and a pointer to font structure.

How do we define QL fonts?
Are they fixed width, or variable, so each char defines its width?

Many thanks
Tomas
Tomas,

some design decisions to make here, basically a trade-off between achievable speed and feature set/usability

Do you want to implement
  • optional "transparent" printing (i.e. background "shines through")?
  • XOR mode (this and the above would give support like "OVER" does in BASIC)
  • Various font sizes (CSIZE support)
  • STRIP support (different background from PAPER for printing)
  • proportional spacing (not supported by standard QL fonts)?
  • Re-use the original QL font format at all (which has a foreground and a background color)?
  • ...
Character print routines can vary widely in complexity - The original QL went the "complex" way, that is why it is so slow - it simply needs to take all those options into account before even plotting a single pixel.

The most simple way to actually implement character printing would be, IMHO, the following:
  1. Restrict yourself to available print positions that are word-aligned in screen memory (i.e. 8 pixels in mode 4, 4 in mode 8).
  2. Don't stick with the QL font format, but rather prepare the font like you would see it on-screen (i.e. pre-defined foreground and background color). You don't need to stick with QL character sizes as well - 8 x 8 is easily possible then.
If you do it like that, printing a character is simply finding the proper memory adress of the character from the font and plotting it directly on screen, scanline per scanline. No bells, no whistles. (You'd basically program a very rudimentary sprite engine)

Once you got that working, evolve from there.

Tobias
Last edited by tofro on Mon Jun 03, 2019 1:36 pm, edited 1 time in total.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: SCREEN1 = SYSVAR @ JSROM

Post by tcat »

Hi Tobias,

Thank you, feeling overwhelmed by outlined QL logic, how complex it is, and what it all does behind scenes. I will follow simple path, that is a simple fixed font no scaling.

That means, defining a raster say 8x8 (or bigger?). I can already visualise a lot of `dc.b %xxxxxxxx' statements in my assembly. I will probably set only font colour, for mode write over.

Just an idea, I could actually borrow some fonts from Speccy, or QL just by printing them onto the screen, and then capture that screen memory, to have the raster, possible?

Many thanks
Tomas


Post Reply