Author Topic: Example Z80 assembly programs (was:ASM source code)  (Read 76241 times)

0 Members and 1 Guest are viewing this topic.

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.332
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2247
  • Likes Given: 3477
Re: ASM source code
« Reply #125 on: 12:10, 29 August 13 »
New example:

http://www.cpctech.org.uk/source/comp_spr.asm

This example shows what I call "compressed sprites".

I have a "large" sprite which has many areas that are fully transparent. Normally we would waste time masking these areas if a standard masking sprite routine was used for the whole sprite. (e.g. we don't split it into smaller sprites and just draw those).

In the code there are 2 draw functions. One shows the sprite itself (I am no graphics artist ;). It moves and you can see it masked over the screen. The other draws pixels for the control codes so that you can see where it recognises fully transparent, masked, fully opaque and end of line conditions.

Turn it on to see the difference.

There are other ways to compress sprites, this is one example.
The code is not optimised, and this method may not be the fastest but it shows how to draw large sprites in this way.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.332
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2247
  • Likes Given: 3477
Re: ASM source code
« Reply #126 on: 11:43, 30 August 13 »
New example:

http://www.cpctech.org.uk/source/cpl_spr.asm

This example shows what I call "compiled sprites".

In the code there are 3 sprites. For each of these there is 1 drawing function. Within the function you will see the instructions for masking, writing opaque pixels and for skipping fully transparent pixels and for moving to the next line. The code is not optimised - I also think there is a bug in the code generation meaning the pixels are not correct but it's enough for this example so you can see what a sprite of this type looks like.

NOTE: If I wanted to have pre-shifted sprites, I would need more functions. If I want more sprites I also need more functions. The advantage of this method is that it's faster to draw a sprite but at the expense of needing more ram to store the drawing routines. - More useful if you are making a game for cpcay cartridge OR mixing hard and software sprites in a plus game.

My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.332
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2247
  • Likes Given: 3477
Re: ASM source code
« Reply #127 on: 11:46, 30 August 13 »
I think now I have shown the methods to draw sprites on a cpc:

I have covered:
- preshifted sprites
- compiled sprites
- compressed sprites
- masked sprites
- xor sprites
- "mode 3 sprites"/bitplanes sprites. (I think I did an example of this???) hmmm.. not sure now ;)

I haven't show enough  methods for erasing sprites yet.
So far shown:
- storing background to restore it back
- using XOR to redraw the sprite to erase it in addition to drawing it.

My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline redbox

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.751
  • Country: gb
    • redbox
  • Liked: 326
  • Likes Given: 267
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #128 on: 17:15, 22 October 13 »
Here's a "sprite" routine I've just written to add to the mix...

The problem I was having is that if you compress "big" sprites (e.g. logos, status bars etc - mainly the type of thing you want to draw to the screen once and drawing it isn't time critical) with Exomizer or similar then you have to decompress them to RAM first before drawing them on the screen (due to the CPC's video addressing format) which is kind of self-defeating.

Therefore, I wrote a routine that only compresses data within a set boundary, i.e. one horizontal screen line of the sprite.  Then on decompression we can draw it directly to the screen without using any kind of buffer whatsoever.

It works nicely and in the example provided the saving is 17% over the original.  The routines demonstrate simple repetition based compression and are descriptive (i.e. not optimised) so feel free to adapt to your purpose/speed requirements.

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1011
  • Likes Given: 926
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #129 on: 15:15, 24 October 13 »
I typed in a tape turboload and turbosave routine. (It's not soooo turboish, but provides colour striped border)

This program originally comes from the Spanish CPC mag. "Amstrad Personal" no. 09.

Code: [Select]
        ;;    TURBOSAVE - TURBOLOAD for tapes
        ;;    Typed-in and slightly modified
        ;;    by Devilmarkus
        ;;    Found in "Amstrad Personal" no. 09
        ;;    Original author: Pedro M. Cuenca
        ;;    To SAVE a file to tape:
        ;;    |TURBOSAVE,<start>,<length>
        ;;    To LOAD a file from tape:
        ;;    |TURBOLOAD,<start>,<length>

color2    equ 85
color1    equ 80

org        &8000

        ld        bc, table
        ld        hl, space
        jp        &bcd1

table:
        defw        name
        JP        rsave
        JP        rload

name:
        db        "TURBOSAV","E"+&80
        db        "TURBOLOA","D"+&80
        db        0

space:
        defs        4

rsave:
        cp        2
        ret        nz
        ld        l,(ix+0)
        ld        h,(ix+1)
        inc        hl
        ld        (length),hl
        ld        l,(ix+2)
        ld        h,(ix+3)
        ld        (address),hl
        jp        saveroutine

rload:
        cp        2
        ret        nz
        ld        l,(ix+0)
        ld        h,(ix+1)
        ;inc        hl
        ld        (length),hl
        ld        l,(ix+2)
        ld        h,(ix+3)
        ld        (address),hl
        jp        loadroutine

saveroutine:
        di
        ex        af,af'
        push        af
        ex        af,af'
        exx
        push        bc
        ld        bc,&f610
        out        (c),c
        exx
        ld        b,3

retar:
        ld        hl, 0

buc1:
        dec        hl
        ld        a,h
        or        l
        jr        nz,buc1
        djnz        retar
        ld        bc,&7f10
        ld        a,color2
        out        (c),c
        out        (c),a
        call        savecab
        ld        hl,(address)
        ld        de,(length)
        call        save
        exx
        ld        c,0
        out        (c),c
        pop        bc
        exx
        ex        af,af'
        pop        af
        ex        af,af'
        ei
        ret

save:
        ld        a,(hl)
        call        sbyte
        inc        hl
        dec        de
        ld        a,d
        or        e
        jr        nz,save
        ret

sbyte:
        ld        b,8

sbuc:
        exx
        rra
        jr        c,bit1

bit0:
        ld        hl,100
        ld        (stime1),hl
        ld        (stime2),hl
        jr        sig

bit1:
        ld        hl,25
        ld        (stime1),hl
        ld        (stime2),hl
        jr        sig

sig:
        ex        af,af'
        ld        a,%00110000
        out        (c),a
        ld        a,&10
        out        (&7f),a
        ld        a,color1
        out        (&7f),a
        defb        &21

stime1:
        defw        0

        reto1:
        dec        hl
        ld        a,h
        or        l
        jr        nz, reto1
        ld        a,%00010000
        out        (c),a
        ld        a,&10
        out        (&7f),a
        ld        a,color2
        out        (&7f),a
        defb        &21

stime2:
        defw        0

        reto2:
        dec        hl
        ld        a,h
        or        l
        jr        nz, reto2
        ex        af,af'
        exx
        djnz        sbuc
        ret

savecab:
        ld        b,128
cabuc:
        push        bc
        ld        a, &aa
        call        sbyte
        pop        bc
        djnz        cabuc
        ld        b,1
        exx
        jp        bit0
        ret

loadroutine:
        di
        ex        af,af'
        push        af
        ex        af,af'
        exx
        push        bc
        ld        bc,&f610
        out        (c),c
        ld        b,&f5
        exx

fallo:
        ld        b,3
        retarl
        ld        hl,0
buc1l:
        dec        hl
        ld        a,h
        or        l
        jr        nz, buc1l
        djnz        retarl
        ld        bc,&7f10
        ld        a,color2
        out        (c),c
        out        (c),a
        call        loadcab
        ld        hl,(address)
        ld        de,(length)
        call        load
        jr        c,fallo
        exx
        ld        bc, &f600
        out        (c),c
        pop        bc
        exx
        ex        af,af'
        pop        af
        ex        af,af'
        ei
        ret

loadcab:
        ld        b,128

loopcab:
        call        lbyte
        jr        c, loadcab
        cp        &aa
        jr        nz,loadcab
        djnz        loopcab
        call        w_bajo
        jp        w_alto

load:
        call        lbyte
        ret        c
        ld        (hl),a
        inc        hl
        dec        de
        ld        a,d
        or        e
        jr        nz,load
        ret

lbyte:
        push        bc
        ld        b,8

lbuc:
        ex        af,af'
        call        w_bajo
        jr        c,error
        call        w_alto
        jr        c,error
        ld        a,(talto)
        cp        40
        jr        c,es1

es0:
        ld        a,(tbajo)
        cp        40
        jr        c,error
        ex        af,af'
        or        a
        jr        salida

es1:
        ld        a,(tbajo)
        cp        40
        jr        nc, error
        ex        af,af'
        scf

salida:
        rra
        djnz        lbuc
        or        a
        pop        bc
        ret

error:
        ex        af,af'
        scf
        pop        bc
        ret

w_bajo:
        ld        a,&10
        out        (&7f),a
        ld        a,color2
        out        (&7f),a
        exx
        ld        hl, talto
        ld        (hl),1
bucalto:
        in        a,(c)
        rla
        jr        c,s1
        inc        (hl)
        jr        z,n0
        jr        bucalto

w_alto:
        ld        a,&10
        out        (&7f),a
        ld        a,color1
        out        (&7f),a
        exx
        ld        hl, tbajo
        ld        (hl),1

bucbajo:
        in        a,(c)
        rla
        jr        nc, s1
        inc        (hl)
        jr        z, n0
        jr        bucbajo

s1:
        or        a
        exx
        ret

n0:
        scf
        exx
        ret

address:        defs 2
length:        defs 2
talto:        defs 1
tbajo:        defs 1

For the non-ASM coders (BASIC only):
Code: [Select]
10 AD=&8000:L=&01C7
20 READ a:POKE AD+P,a
30 P=P+1:IF P=L THEN END
40 GOTO 20
50 DATA &01,&09,&80,&21,&24,&80,&C3,&D1,&BC,&11,&80,&C3,&28,&80,&C3,&41
60 DATA &80,&54,&55,&52,&42,&4F,&53,&41,&56,&C5,&54,&55,&52,&42,&4F,&4C
70 DATA &4F,&41,&C4,&00,&00,&00,&00,&00,&FE,&02,&C0,&DD,&6E,&00,&DD,&66
80 DATA &01,&23,&22,&C3,&81,&DD,&6E,&02,&DD,&66,&03,&22,&C1,&81,&C3,&59
90 DATA &80,&FE,&02,&C0,&DD,&6E,&00,&DD,&66,&01,&22,&C3,&81,&DD,&6E,&02
100 DATA &DD,&66,&03,&22,&C1,&81,&C3,&FA,&80,&F3,&08,&F5,&08,&D9,&C5,&01
110 DATA &10,&F6,&ED,&49,&D9,&06,&03,&21,&00,&00,&2B,&7C,&B5,&20,&FB,&10
120 DATA &F6,&01,&10,&7F,&3E,&55,&ED,&49,&ED,&79,&CD,&E8,&80,&2A,&C1,&81
130 DATA &ED,&5B,&C3,&81,&CD,&93,&80,&D9,&0E,&00,&ED,&49,&C1,&D9,&08,&F1
140 DATA &08,&FB,&C9,&7E,&CD,&9E,&80,&23,&1B,&7A,&B3,&20,&F6,&C9,&06,&08
150 DATA &D9,&1F,&38,&0B,&21,&64,&00,&22,&C8,&80,&22,&DC,&80,&18,&0B,&21
160 DATA &19,&00,&22,&C8,&80,&22,&DC,&80,&18,&00,&08,&3E,&30,&ED,&79,&3E
170 DATA &10,&D3,&7F,&3E,&50,&D3,&7F,&21,&00,&00,&2B,&7C,&B5,&20,&FB,&3E
180 DATA &10,&ED,&79,&3E,&10,&D3,&7F,&3E,&55,&D3,&7F,&21,&00,&00,&2B,&7C
190 DATA &B5,&20,&FB,&08,&D9,&10,&B9,&C9,&06,&80,&C5,&3E,&AA,&CD,&9E,&80
200 DATA &C1,&10,&F7,&06,&01,&D9,&C3,&A4,&80,&C9,&F3,&08,&F5,&08,&D9,&C5
210 DATA &01,&10,&F6,&ED,&49,&06,&F5,&D9,&06,&03,&21,&00,&00,&2B,&7C,&B5
220 DATA &20,&FB,&10,&F6,&01,&10,&7F,&3E,&55,&ED,&49,&ED,&79,&CD,&39,&81
230 DATA &2A,&C1,&81,&ED,&5B,&C3,&81,&CD,&4C,&81,&38,&DC,&D9,&01,&00,&F6
240 DATA &ED,&49,&C1,&D9,&08,&F1,&08,&FB,&C9,&06,&80,&CD,&58,&81,&38,&F9
250 DATA &FE,&AA,&20,&F5,&10,&F5,&CD,&8B,&81,&C3,&A3,&81,&CD,&58,&81,&D8
260 DATA &77,&23,&1B,&7A,&B3,&20,&F5,&C9,&C5,&06,&08,&08,&CD,&8B,&81,&38
270 DATA &26,&CD,&A3,&81,&38,&21,&3A,&C5,&81,&FE,&28,&38,&0B,&3A,&C6,&81
280 DATA &FE,&28,&38,&13,&08,&B7,&18,&09,&3A,&C6,&81,&FE,&28,&30,&08,&08
290 DATA &37,&1F,&10,&D7,&B7,&C1,&C9,&08,&37,&C1,&C9,&3E,&10,&D3,&7F,&3E
300 DATA &55,&D3,&7F,&D9,&21,&C5,&81,&36,&01,&ED,&78,&17,&38,&1D,&34,&28
310 DATA &1D,&18,&F6,&3E,&10,&D3,&7F,&3E,&50,&D3,&7F,&D9,&21,&C6,&81,&36
320 DATA &01,&ED,&78,&17,&30,&05,&34,&28,&05,&18,&F6,&B7,&D9,&C9,&37,&D9
330 DATA &C9,&00,&00,&00,&00,&00,&00

Have fun with it!

Attachment: Original listing. Thanks to SyX for sharing it!
« Last Edit: 15:22, 24 October 13 by Devilmarkus »
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.332
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2247
  • Likes Given: 3477
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.721
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 957
  • Likes Given: 1678
Re: ASM source code
« Reply #131 on: 10:19, 07 January 14 »
I think now I have shown the methods to draw sprites on a cpc:

I have covered:
- preshifted sprites
- compiled sprites
- compressed sprites
- masked sprites
- xor sprites
- "mode 3 sprites"/bitplanes sprites. (I think I did an example of this???) hmmm.. not sure now ;)

I haven't show enough  methods for erasing sprites yet.
So far shown:
- storing background to restore it back
- using XOR to redraw the sprite to erase it in addition to drawing it.

Not directly relating to Sprites, though I noticed the article on Collision Detection looks in need of a tune up. ACU had an article on this in it's early days along with example, though the example (as lengthy as it is), relies on using the character set in conjunction with it's graphical position, I'm not sure how difficult it would be to upgrade it to graphical sprite for the collision detection.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.332
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2247
  • Likes Given: 3477
Re: ASM source code
« Reply #132 on: 11:02, 07 January 14 »
Not directly relating to Sprites, though I noticed the article on Collision Detection looks in need of a tune up. ACU had an article on this in it's early days along with example, though the example (as lengthy as it is), relies on using the character set in conjunction with it's graphical position, I'm not sure how difficult it would be to upgrade it to graphical sprite for the collision detection.
I used exact collision on Balloonacy using a mask.

I do plan to write up box based collision which is most commonly used. LOL, I laughed when I read that link of mine.

Busy with other projects for the moment.
« Last Edit: 11:04, 07 January 14 by arnoldemu »
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.721
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 957
  • Likes Given: 1678
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #133 on: 11:56, 13 January 14 »
I used exact collision on Balloonacy using a mask.

I do plan to write up box based collision which is most commonly used. LOL, I laughed when I read that link of mine.

Busy with other projects for the moment.

I'm having a look at the bits and pieces I've made for putting together for a game, though I'm having issues with the collision detection. For the main character I'm using a routine to draw a triangular shape on screen using a series of Lines and wasn't sure if a test for colour check would be sufficient enough to provide an accurate collision detection given the angled nature of the character doesn't have square edges facing what it needs to attack.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.721
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 957
  • Likes Given: 1678
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #134 on: 12:56, 03 May 14 »
Tenuously linked post ahead!

If you're interested, here's the horizontal star-scroller from the XOR cracktros...
Just assmeble in WinAPE/Maxam and CALL &A000 to see what it does. If you're using WinAPE, then it's best to keep the boot-screen up, so you can see that it doesn't affect the text on screen while it runs.

For better results, try changing the background colours to #00 (BLACK) and inks 1 & 3 to #26 (BRIGHT WHITE) and 13 (WHITE) respectively. It gives a slight impression of a star-trail as it moves across the screen.

Code: [Select]
org #a000

.inflp    call stars
    jp inflp

.stars    ld de,#0000
    ld hl,here2
    ld b,25
.loop1    ld a,(hl)
    ld e,a
    inc hl
    ld a,(hl)
    ld d,a
    dec hl
    ld a,(de)
    cp #fe
    jr nz,jump1
    xor a
    ld (de),a
.jump1    inc de
    ld a,d
    cp #00
    jr nz,jump2
    push hl
    ld hl,#c000
    add hl,de
    ex de,hl
    pop hl
.jump2    ld a,(de)
    cp #00
    jr nz,jump3
    ld a,#fe
    ld (de),a
.jump3    ld a,e
    ld (hl),a
    inc hl
    ld a,d
    ld (hl),a
    inc hl
    djnz loop1

    ld hl,here3
    ld b,25
.loop2    ld a,(hl)
    ld e,a
    inc hl
    ld a,(hl)
    ld d,a
    dec hl
    ld a,(de)
    cp #fe
    jr nz,jump4
    xor a
    ld (de),a
.jump4    inc de
    inc de
    ld a,d
    cp #00
    jr nz,jump5
    push hl
    ld hl,#c000
    add hl,de
    ex de,hl
    pop hl
.jump5    ld a,(de)
    cp #00
    jr nz,jump6
    ld a,#fe
    ld (de),a
.jump6    ld a,e
    ld (hl),a
    inc hl
    ld a,d
    ld (hl),a
    inc hl
    djnz loop2

    call #bd19
    ret

.here2
db #00,#c0,#55,#c0,#c0,#c0,#f4,#c0
db #68,#c1,#a9,#c1,#20,#c2,#55,#c2
db #82,#c2,#e0,#c2,#4a,#c3,#a0,#c3
db #d9,#c3,#49,#c4,#a0,#c4,#d9,#c4
db #48,#c5,#65,#c5,#c6,#c5,#fa,#c5
db #85,#c6,#d5,#c6,#20,#c7,#49,#c7
db #a0,#c7

.here3
db #30,#d0,#90,#d8,#a0,#f0,#10,#d1
db #7a,#e1,#a0,#e9,#00,#ca,#30,#d2
db #b0,#e2,#e0,#ea,#50,#d3,#75,#db
db #e0,#f3,#20,#d4,#a0,#cc,#e9,#dc
db #0a,#ed,#65,#dd,#a9,#d5,#15,#f6
db #85,#ee,#a5,#ee,#ff,#ce,#4a,#e7
db #b0,#ef

(P.S. The code isn't originally mine, so I'm not trying to steal the glory here or anything!)


This is pretty much the kind of thing I want to eventually implement in the other thread I made which deals with 16 bit numbers, though this approach seems more simplified compared to what I'm trying to do in the other thread.
I cut this program down by removing the second loop that points to here3 which gives me something closer to what I'm looking for, though the stars move left->right across the screen and I'm after right->left instead. I was able to do that by changing the inc de to dec de at the loop1 label, though the program only goes so far and then it crashes, looks like the program is writing to sensitive memory locations.
It looks like this routine is designed to simply move pixels across an entire screen, I was thinking of implementing different size playing fields which made become an issue for this, otherwise would anyone know what's happening with this routine?  :'(
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline Xifos

  • CPC6128
  • ****
  • Posts: 176
  • Country: fr
  • Liked: 233
  • Likes Given: 230
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #135 on: 20:19, 03 May 14 »
Hi,

 :)

if you look at that :

inc de
ld a,d
cp #0
jr nz,jump2

The test is on de=&0000 (when reaching the end of video memory (&C000 to &FFFF), so &FFFF+1.
If you change to dec de to have stars going the other direction, it cannot work anymore.
You should check if de=&BFFF (d=&BF), and set it to FFFF, maybe...

Offline TFM

  • Visit the mysteries of the CPC at www.futureos.de
  • Supporter
  • 6128 Plus
  • *
  • Posts: 9.899
  • Country: aq
  • Space Chicken for FutureOS is free!
    • index.php?action=treasury
    • FutureOS - The revolution on CPC!
  • Liked: 1976
  • Likes Given: 4650
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #136 on: 02:37, 04 May 14 »
inc deld a,dcp #0jr nz,jump2



inc de
ld a,d
or a,a
jr nz,jump2



Makes it 1 us more quick :)
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Offline Executioner

  • Supporter
  • 6128 Plus
  • *
  • Posts: 783
  • Country: au
  • WinAPE Developer
    • WinAPE
  • Liked: 391
  • Likes Given: 60
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #137 on: 14:54, 04 May 14 »
if you look at that :

inc de
ld a,d
cp #0
jr nz,jump2

The test is on de=&0000 (when reaching the end of video memory (&C000 to &FFFF), so &FFFF+1.
If you change to dec de to have stars going the other direction, it cannot work anymore.
You should check if de=&BFFF (d=&BF), and set it to FFFF, maybe...

Except that doesn't check DE for 0, only D. To check DE for 0, simply change to:

dec de
ld a,d
or e
jr nz,jump2

If you want to check when DE goes to #FFFF, use:

ld a,d
or e
dec de
jr nz,jump2

Offline Xifos

  • CPC6128
  • ****
  • Posts: 176
  • Country: fr
  • Liked: 233
  • Likes Given: 230
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #138 on: 18:51, 04 May 14 »
Sorry, i did not make it clear, i was refering to the stars routine AMSDOS was wondering about...
This routine plots stars by setting bytes into video memory, increasing addresses, and testing when addresses go to &FFFF+1 (0) to set them to &c000.
AMSDOS changed it to decrease addresses (but it went crashing), so the test has to be done on DE going to &BFFF...
And the routine he posted is only testing D rather than DE...
 ;)

Offline Executioner

  • Supporter
  • 6128 Plus
  • *
  • Posts: 783
  • Country: au
  • WinAPE Developer
    • WinAPE
  • Liked: 391
  • Likes Given: 60
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #139 on: 08:37, 05 May 14 »
so the test has to be done on DE going to &BFFF...

Sorry, my mistake. The test for zero works only if you're incrementing past #ffff. ie. D becomes 0 next.

To test going the other way, simply use:

dec de
bit 6,d
jr nz,jump2

(ie. DE goes from #c000 to #bfff, this is the point when D drops below %11000000 to %10111111, all other high memory screen addresses have bit 6 set).

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.721
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 957
  • Likes Given: 1678
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #140 on: 03:11, 07 May 14 »
Thanks for the antidotes guys  :)  The end result appears to be the same, though it's good to see some refined code.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.332
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2247
  • Likes Given: 3477
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #141 on: 16:51, 24 May 14 »
New example code:

http://www.cpctech.org.uk/source/backbuff.asm

&4000-&7fff contains a copy of the screen from &c000-&ffff but without the sprites.
This shows how you can erase sprites using this back buffer.

another way to erase sprites.

http://www.cpctech.org.uk/source/scrlchk.asm

This example performs continuous chunky scroll using hardware. If we had a pixel by pixel scroll it would run at a rate of 1 pixel per frame in mode 1, but because we don't on cpc, it delays for 8 frames then scrolls.

In addition it shows how to convert from our sprite coordinates to a screen address on a hardware scrolling screen, and the draws a striped rectangle for a sprite. Also, it highlights the problem area in red so you can see where it is and how it moves with a horizontal scroll.

http://www.cpctech.org.uk/source/scrlvrt.asm

Smoother vertical hardware scrolling using R5 of the CRTC but without rupture/splitting. Same method used in Legend of Kage.
« Last Edit: 16:56, 24 May 14 by arnoldemu »
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.332
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2247
  • Likes Given: 3477
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #142 on: 19:21, 24 May 14 »
New example code:

http://www.cpctech.org.uk/source/scrlv1.asm

This shows how to avoid the problem area when hardware vertical scrolling. The problem area is highlighted. A screen width of 32 is chosen because &400/32 gives no remainder. See how the problem area remains on the right side of the screen.

My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.332
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2247
  • Likes Given: 3477
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #143 on: 20:21, 24 May 14 »
New example code

http://www.cpctech.org.uk/source/scrlh1.asm

This example shows how to avoid the problem area when scrolling horizontally.

For a screen of width 40, and if we want to scroll 3 screens in width, then the maximum height the screen can be is 22
lines.

We must choose our screen dimensions carefully to both have horizontal scrolling AND to avoid the problem area. in addition the scroll can't be continuous there is a minimum and maximum range.

This method is used by Action Force.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.332
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2247
  • Likes Given: 3477
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #144 on: 18:23, 25 May 14 »
New example code:

http://www.cpctech.org.uk/source/scrltile.asm

This example shows how to scroll a tile map horizontally.

The scroll is in a single direction and continuous.

It is meant to be simple so you can see how to setup a tile map, setup the tiles, how the tile map is queried for the tiles, how the tiles are drawn.

My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.721
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 957
  • Likes Given: 1678
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #145 on: 01:00, 01 June 14 »
New example code:

http://www.cpctech.org.uk/source/scrltile.asm

This example shows how to scroll a tile map horizontally.

The scroll is in a single direction and continuous.

It is meant to be simple so you can see how to setup a tile map, setup the tiles, how the tile map is queried for the tiles, how the tiles are drawn.


This code seems to be a bit beyond me and the Winape Assembler.  :(
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.332
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2247
  • Likes Given: 3477
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #146 on: 11:13, 01 June 14 »

This code seems to be a bit beyond me and the Winape Assembler.  :(
I use pasmo assembler. Build using amsdos command line option and put into a dsk file. Or use binary and load into winape debugger and call from basic.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.721
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 957
  • Likes Given: 1678
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #147 on: 12:00, 01 June 14 »
I use pasmo assembler. Build using amsdos command line option and put into a dsk file. Or use binary and load into winape debugger and call from basic.


Ok I see that Assembler is included with the CPC BASIC 3 distribution.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.721
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 957
  • Likes Given: 1678
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #148 on: 11:27, 31 January 15 »
I've been having a look at this routine for running BASIC programs through Assembly:


http://cpctech.cpc-live.com/source/runbas.asm


but I'm unable to get it to work, even with the address for KL ROM SELECT. Probably because I didn't have the variables setup.


Questions:


1) Could it be made to work in Winape Assembler?


2) Could a BASIC program be included with it? Something with Variables (not 10 PRINT"HELLO WORLD", 20 GOTO 10), doesn't have to be big.


3) I was looking at a 12Kb BASIC Game, but was studying what those Addresses did in Memory, not sure if it's recommended due to the nature of the program?


4) I though this method could be used to load a BASIC program using Headerless loader and then execute this using this method, but only really makes sense to apply it for a larger program. Any thoughts?
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline Urusergi

  • CPC6128
  • ****
  • Posts: 176
  • Country: es
  • Liked: 264
  • Likes Given: 1212
Re: Example Z80 assembly programs (was:ASM source code)
« Reply #149 on: 16:52, 24 March 18 »
Hi @AMSDOS

This question has been a long time, but if you want I can try to help you.
Send me that basic program and we take a look, if you still need to solve the problem.