Putting an image in the screen?

Página 5/5
1 | 2 | 3 | 4 |

Por commodorejohn

Expert (92)

Imagen del commodorejohn

20-01-2011, 21:10

I do the exact same thing - I can't really learn much with a hand-holding language like BASIC, so I just spend a lot of time banging out assembler and fiddling around in a debugger until I start to get things working Wink

Por Metalion

Paragon (1622)

Imagen del Metalion

21-01-2011, 08:15

Another problem is that assembly has an extremely high addictive value Smile When something works I feel a rush. Knowing that you are actually really saying the right things to the machine. I have never had so much fun in programming a machine before. When working in assembly I understand why I had bought that MSX Wink

You have no idea how much I understand and agree with those words !!!!
I feel exactly the same thing when working in assembly LOL!
It is indeed very addictive ... And very rewarding.

Keep up the good work, and keep asking questions around, we will be there ... Wink

Por Daemos

Paragon (2044)

Imagen del Daemos

22-01-2011, 17:34

Thank you so much for the good words and advice all.

I will post my newest code soon but before that a small question to the moderators. The code is 600 lines orso by now. Still allowed to copy paste such amount of code in a reply??

Por Daemos

Paragon (2044)

Imagen del Daemos

24-01-2011, 21:50

Here it is Smile The little paint program. All ideas welcome. How can I be more efficient etc. What can be done to make the code more nice and tidy. Advices on making better calls. Just trow your comments at me.

        ORG   &HC000
CHMOD:  EQU   &H5F
DISSCR: EQU   &H41
ENASCR: EQU   &H44



;screen mode 5

        LD    A,5
        CALL  CHMOD
        CALL  DISSCR

;zet backdrop color
        DI
        LD    A,&B00000000
        OUT   (&H99),A
        LD    A,7+128
        EI
        OUT   (&H99),A

;make whole vram black

        DI

        LD    A,36
        OUT   (&H99),A
        LD    A,17+128
        OUT   (&H99),A

        XOR   A
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A

;set points
        XOR   A
        OUT   (&H9B),A
        LD    A,1
        OUT   (&H9B),A
        LD    A,255
        OUT   (&H9B),A
        LD    A,3
        OUT   (&H9B),A

;coordinaten geset
;set color

        LD    A,&B00010001
        OUT   (&H9B),A
;done? execute command

        LD    A,&B11000000
        OUT   (&H99),A
        LD    A,46+128
        OUT   (&H99),A
        EI

        CALL  VWAIT
        CALL  VENA
        JP    LOOP
;wait until finished



VWAIT:  DI
        LD    A,2
        OUT   (&H99),A
        LD    A,15+128
        OUT   (&H99),A
        NOP
        IN    A,(&H99)
        LD    C,A
        XOR   A
        OUT   (&H99),A
        LD    A,15+128
        OUT   (&H99),A
        EI

        RR    C

        JR    C,VWAIT
        RET

;difference between Vwait and this one is the loop type

CMDR:   DI
        LD    A,2
        OUT   (&H99),A
        LD    A,15+128
        OUT   (&H99),A
        NOP
        IN    A,(&H99)
        LD    C,A
        XOR   A
        OUT   (&H99),A
        LD    A,15+128
        OUT   (&H99),A
        EI

        RR    C

        RET


;activate the screen and start the main loop

VENA:
        LD    HL,LINES
        CALL  LDRAW

        CALL  ENASCR

        LD    HL,COLOR
        LD    C,(HL)
        CALL  DRAW
        RET

;reset the color to initial value


CRESET:
        PUSH  HL
        LD    HL,COLOR
        LD    (HL),0
        POP   HL
        RET

;fetch color from ram and check maximum not reached? increment color for both pixels by 1 otherwise reset



SETCLR:
        PUSH  HL
        LD    HL,COLOR
        LD    C,(HL)
        LD    A,C
        LD    C,17
        ADD   C
        LD    C,A
        LD    A,255
        LD    (HL),C
        POP   HL
        CP    C
        CALL  Z,CRESET


        RET

;fetch color from RAM and put in C

GETCLR:
        PUSH  HL
        LD    HL,COLOR
        LD    C,(HL)
        POP   HL


        RET

;fetch blocksize in DE


GETBLS:

        PUSH  HL
        LD    HL,BLOCKS
        LD    D,(HL)
        INC   HL
        LD    E,(HL)
        POP   HL

        RET



;normaal ligt de block in
;midden maar nu brengen wij
;deze op de 0 positie ivm
;het verplaatsen middels de pijltjes
;toetsen


;draw the colored block into PAGE 3 of the VRAM
DRAW:

        CALL  VWAIT ;other command still executed?
        CALL  GETCLR
        CALL  GETBLS ;get the blocksize in dots


        DI
        LD    A,36
        OUT   (&H99),A
        LD    A,17+128
        OUT   (&H99),A

        XOR   A
        OUT   (&H9B),A
        OUT   (&H9B),A
        OUT   (&H9B),A
        LD    A,2
        OUT   (&H9B),A
        LD    A,D
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A
        LD    A,E
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A

;set first color

        LD    A,C
        OUT   (&H9B),A



;execute command

        LD    A,&B11110000
        OUT   (&H99),A
        LD    A,46+128
        OUT   (&H99),A
        EI

;transport the color into the block
DWLOOP:

        CALL  GETCLR

        DI
        LD    A,C
        OUT   (&H99),A
        LD    A,44+128
        OUT   (&H99),A
        EI

        PUSH  BC
        CALL  CMDR ;command finished?
        POP   BC

        JR    C,DWLOOP

;wait until space key is released

KHOLD:  LD    HL,&HFBED
        LD    A,(HL)
        BIT   0,A
        JR    Z,KHOLD

        CALL  BLMOVE
        RET

;draw 2 in the screen
;this command is executed BEFORE screen gets enabled on init
;has to wait for itself
;B=X B=Y


LDRAW:

        LD    B,(HL)
        INC   HL
        LD    C,(HL)
        INC   HL
        PUSH  BC
        LD    B,(HL)
        INC   HL
        LD    C,(HL)
        INC   HL
;set registers

        DI
        LD    A,40
        OUT   (&H99),A
        LD    A,17+128
        OUT   (&H99),A


        LD    A,B
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A

        LD    A,C
        OUT   (&H9B),A
        LD    A,C
        OUT   (&H9B),A

        POP   BC

        LD    A,36
        OUT   (&H99),A
        LD    A,17+128
        OUT   (&H99),A

        LD    A,B
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A

        LD    A,C
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A

;all set execute

        LD    A,4
        OUT   (&H99),A
        LD    A,44+128
        OUT   (&H99),A

        LD    A,&B01110000
        OUT   (&H99),A
        LD    A,46+128
        OUT   (&H99),A
;wait until finished

        CALL  VWAIT

;finished??

        LD    A,(HL)
        CP    255
        RET   Z

        JP    LDRAW


;remove block from Vram first so that we can do a new clean write

BLDEL:

;fetch coordinates and size from ram
        LD    IX,BLOCKS
        LD    B,(IX)
        INC   IX
        LD    C,(IX)
        PUSH  BC

        LD    IX,POSX
        LD    IY,POSY
        LD    B,(IX)
        LD    C,(IY)

;set coordinates
        LD    A,36
        OUT   (&H99),A
        LD    A,17+128
        OUT   (&H99),A

        LD    A,B
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A

        LD    A,C
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A
;size
        POP   BC

        LD    A,B
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A

        LD    A,C
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A

;color

        XOR   A
        OUT   (&H9B),A


;execute

        LD    A,&B10000000
        OUT   (&H99),A
        LD    A,46+128
        OUT   (&H99),A
        EI

        CALL  VWAIT
        RET


;Write block into current position in PAGE 0
;basicly make a copy from the allready exsistant block in PAGE 3

BLMOVE:

;fetch coordinates first from RAM
;furthermore set the coordinates in PAGE 3 to fetch from in startx,starty


        LD    IX,STARTX
        LD    IY,STARTY
        LD    B,(IX)
        LD    C,(IY)
        LD    IX,POSX
        LD    IY,POSY
        LD    D,(IX)
        LD    E,(IY)

        DI
        LD    A,32
        OUT   (&H99),A
        LD    A,17+128
        OUT   (&H99),A


        LD    A,B
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A

        LD    A,C
        OUT   (&H9B),A
        LD    A,2
        OUT   (&H9B),A
;set position
;also get blocksize

        LD    IX,BLOCKS
        LD    B,(IX)
        INC   IX
        LD    C,(IX)

        LD    A,D
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A

        LD    A,E
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A
;set blocksize

        LD    A,B
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A

        LD    A,C
        OUT   (&H9B),A
        XOR   A
        OUT   (&H9B),A
;all set GO!!!

        LD    A,&B10010000
        OUT   (&H99),A
        LD    A,46+128
        OUT   (&H99),A

        EI


        HALT ;Dunno but it runs much softer and smoother on the screen like this

        RET

;Check BC value on min and max. reset these values if exceeding

VMAX:

;fetch data first

        LD    IX,POSX
        LD    B,(IX)
        LD    IY,POSY
        LD    C,(IY)

        LD    A,B
        CP    218
        JR    Z,XMAX
        CP    16
        JR    Z,XMIN

        LD    A,C
        CP    192
        JR    Z,YMAX
        CP    0
        JR    Z,YMIN

        JR    XYMAX
XMAX:
        LD    (IX),217
        JR    VMAX
XMIN:
        LD    (IX),17
        JR    VMAX
YMAX:
        LD    (IY),191
        JR    VMAX
YMIN:
        LD    (IY),1
        JR    VMAX
XYMAX:

        RET

;detect keys a and z on the keyboard and do a blocksize change

SETBLS:
        PUSH  HL
        LD    HL,&HFBE7
        LD    A,(HL)
        BIT   6,A
        CALL  Z,BLSUP
        LD    HL,&HFBEA
        LD    A,(HL)
        BIT   7,A
        CALL  Z,BLSDWN
        POP   HL

        RET

BLSUP:
        LD    HL,BLOCKS
        LD    A,(HL)
        CP    18
        RET   Z
        ADD   A,2
        LD    (HL),A
        INC   HL
        LD    A,(HL)
        ADD   A,2
        LD    (HL),A
        CALL  DRAW
        CALL  DELH

        RET


BLSDWN:

        LD    HL,BLOCKS
        LD    A,(HL)
        CP    2
        RET   Z


        PUSH  HL
        CALL  BLDEL
        POP   HL

        LD    A,(HL)
        SUB   2
        LD    (HL),A
        INC   HL
        LD    A,(HL)
        SUB   2
        LD    (HL),A

        CALL  DRAW
        CALL  DELH


        RET

;wait until a or z release

DELH:

        LD    HL,&HFBE7
        LD    A,(HL)
        BIT   6,A
        JR    Z,DELH
        LD    HL,&HFBEA
        LD    A,(HL)
        BIT   7,A
        JR    Z,DELH
        RET


;detect shift key and set draw bit

KSHIFT:

        PUSH  HL
        LD    HL,&HFBEB
        LD    A,(HL)
        BIT   0,A
        POP   HL
        RET


;main program contantly polling what to do

LOOP:
        CALL  SETBLS

        LD    HL,&HFBED
        LD    A,(HL)
        BIT   0,A
        CALL  Z,SETCLR
        LD    A,(HL)
        BIT   0,A
        CALL  Z,DRAW

        XOR   &B11111111

        JR    Z,KEY

;remove old block

        CALL  KSHIFT
        CALL  NZ,BLDEL

;arrow key pressed??? fetch coordinates first

        LD    IX,POSX
        LD    B,(IX)
        LD    IY,POSY
        LD    C,(IY)

;to right

        XOR   A
        LD    D,(HL)
        SLA   D
        RL    A
        LD    B,A
        LD    A,(POSX)
        SUB   B
        LD    (IX),A

;down

        XOR   A
        SLA   D
        RL    A
        LD    C,A
        LD    A,(IY)
        SUB   C
        LD    (IY),A

;up

        LD    C,(IY)
        XOR   A
        SLA   D
        RL    A
        ADD   C
        LD    (IY),A


;left

        LD    B,(IX)
        XOR   A
        SLA   D
        RL    A
        ADD   B
        LD    (IX),A

;check maximum value and place the block

        CALL  VMAX
        CALL  BLMOVE



;check for escape key

KEY:

        LD    HL,&HFBEC
        LD    A,(HL)
        BIT   2,A
        JR    Z,STOPP
        JR    LOOP

;set screen 0 and exit program
STOPP:

        LD    A,0
        CALL  CHMOD

        RET


;all kinds of predefined stuff


STARTX: DB    0
STARTY: DB    0
POSX:   DB    100
POSY:   DB    100
COLOR:  DB    17
LINES:  DB    16,0,218,0,16,210,218,0
        DB    255
BLOCKS: DB    8,8





        END

Por ARTRAG

Enlighted (6923)

Imagen del ARTRAG

24-01-2011, 22:39

If I correctly understand you want to do a software sprite, i.e. you need to move an object on the screen using a mix of logical and byte copy while restoring the background

The more efficient way (in screen 5) is:
a) hold the whole background in page 3
b) hold the "sprite" frames in page 2 (use 0 as transparent color)
c) use pages 0 and 1 as double buffer

The steps are more or less these:

initialize the whole background coping it from page 3 to page 0 and to 1
display page 0
copy a sprite frame from page 2 to page 1 at (x1,y1) using logical copy

main_loop:
display page 1
copy a square of background from page 3 to page 0 at (x0,y0) using byte copy to remove the sprite
update x0,y0
copy the sprite from page 2 to page 0 at (x0,y0) using logical copy (TPSET)

display page 0
copy a square of background from page 3 to page 1 at (x1,y1) using byte copy to remove the sprite
update x1,y1
copy the sprite from page 2 to page 1 at (x1,y1) using logical copy (TPSET)

goto main_loop

Is this what you was trying to do ?

Some variations are possible according to e.g. the fact you cannot spend the whole page 3 to store the background (in this case you have to copy somewhere the area where you are going to place the sprite before coping it) or to the fact your background is black or just monocrome (in this case you can restore it just using a filled box rather than a copy), but the main idea for software sprites and double buffering stays the same.

Por Daemos

Paragon (2044)

Imagen del Daemos

24-01-2011, 23:43

Ok lets see how to awnser on this. That is indeed what I will start doing in the next step so basicly you are thinking ahead of me Wink The next step is indeed no more using black pixels as the backround but an actual image. Your awnser was very helpfull though because I was starting to ask myself how this would be possible indeed. So was I trying to do what you explained here? Yes and no Tongue I am indeed doing some kind of sprite move but I wasn't going that deep yet. Wink

This program does nothing more but copying a colored block around the screen and is even capable of drawing lines and stuff. So its like a painting program purely build for VDP practice. I am wondering if some of the coding can be more tight and efficient.

You have just shed much light on the matters here thats for sure. This VDP stuff is really amazing.

Página 5/5
1 | 2 | 3 | 4 |